mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-23 22:58:15 +00:00
feat(src/components/codecs/AbstractCodecsModel): in progress
This commit is contained in:
parent
9200f97306
commit
71d2c9aa44
4 changed files with 88 additions and 60 deletions
|
|
@ -52,42 +52,6 @@ QVariant AbstractCodecsModel::data (const QModelIndex &index, int role) const {
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
bool AbstractCodecsModel::moveRow (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
) {
|
||||
return moveRows(source_parent, source_row, 1, destination_parent, destination_child);
|
||||
}
|
||||
|
||||
bool AbstractCodecsModel::moveRows (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
int count,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
) {
|
||||
int limit = source_row + count - 1;
|
||||
|
||||
if (source_row < 0 || count < 0 || limit >= m_codecs.count())
|
||||
return false;
|
||||
|
||||
beginMoveRows(source_parent, source_row, limit, destination_parent, destination_child);
|
||||
|
||||
if (destination_child < source_row) {
|
||||
for (int i = source_row; i <= limit; ++i)
|
||||
m_codecs.move(source_row, destination_child + i - source_row);
|
||||
} else {
|
||||
for (int i = source_row; i <= limit; ++i)
|
||||
m_codecs.move(source_row, destination_child + i);
|
||||
}
|
||||
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void AbstractCodecsModel::enableCodec (int id, bool status) {
|
||||
|
|
@ -102,6 +66,51 @@ void AbstractCodecsModel::enableCodec (int id, bool status) {
|
|||
emit dataChanged(index(id, 0), index(id, 0));
|
||||
}
|
||||
|
||||
void AbstractCodecsModel::moveCodec (int source, int destination) {
|
||||
moveRow(QModelIndex(), source, QModelIndex(), destination);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool AbstractCodecsModel::moveRows (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
int count,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
) {
|
||||
int limit = source_row + count - 1;
|
||||
|
||||
{
|
||||
int n_codecs = m_codecs.count();
|
||||
if (
|
||||
source_row < 0 ||
|
||||
destination_child < 0 ||
|
||||
count < 0 ||
|
||||
destination_child > n_codecs ||
|
||||
limit >= n_codecs ||
|
||||
(source_row <= destination_child && source_row + count >= destination_child)
|
||||
)
|
||||
return false;
|
||||
}
|
||||
|
||||
beginMoveRows(source_parent, source_row, limit, destination_parent, destination_child);
|
||||
|
||||
if (destination_child > source_row) {
|
||||
--destination_child;
|
||||
for (int i = source_row; i <= limit; ++i) {
|
||||
m_codecs.move(source_row, destination_child + i - source_row);
|
||||
}
|
||||
} else {
|
||||
for (int i = source_row; i <= limit; ++i)
|
||||
m_codecs.move(source_row + i - source_row, destination_child + i - source_row);
|
||||
}
|
||||
|
||||
endMoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void AbstractCodecsModel::addCodec (std::shared_ptr<linphone::PayloadType> &codec) {
|
||||
|
|
|
|||
|
|
@ -45,13 +45,10 @@ public:
|
|||
QHash<int, QByteArray> roleNames () const override;
|
||||
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
bool moveRow (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
const QModelIndex &destination_parent,
|
||||
int destination_child
|
||||
);
|
||||
Q_INVOKABLE void enableCodec (int id, bool status);
|
||||
Q_INVOKABLE void moveCodec (int source, int destination);
|
||||
|
||||
protected:
|
||||
bool moveRows (
|
||||
const QModelIndex &source_parent,
|
||||
int source_row,
|
||||
|
|
@ -60,9 +57,6 @@ public:
|
|||
int destination_child
|
||||
) override;
|
||||
|
||||
void enableCodec (int id, bool status);
|
||||
|
||||
protected:
|
||||
void addCodec (std::shared_ptr<linphone::PayloadType> &codec);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ Column {
|
|||
|
||||
anchors {
|
||||
left: parent.left
|
||||
leftMargin: CodecsViewerStyle.leftMargin
|
||||
right: parent.right
|
||||
}
|
||||
|
||||
|
|
@ -93,8 +92,8 @@ Column {
|
|||
drag {
|
||||
axis: Drag.YAxis
|
||||
|
||||
maximumY: (view.count - index) * height - height
|
||||
minimumY: -index * height
|
||||
maximumY: (view.count - index) * height - height / 2
|
||||
minimumY: -index * height - height / 2
|
||||
|
||||
target: held ? content : undefined
|
||||
}
|
||||
|
|
@ -104,7 +103,7 @@ Column {
|
|||
onPressed: held = true
|
||||
onReleased: {
|
||||
held = false
|
||||
console.log('toto', content.y)
|
||||
view.model.moveCodec(index, index + 1 + content.y / height)
|
||||
content.y = 0
|
||||
}
|
||||
|
||||
|
|
@ -116,13 +115,20 @@ Column {
|
|||
Drag.hotSpot.x: width / 2
|
||||
Drag.hotSpot.y: height / 2
|
||||
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
|
||||
color: CodecsViewerStyle.attribute.background.color.normal
|
||||
|
||||
height: dragArea.height
|
||||
width: dragArea.width
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
anchors {
|
||||
fill: parent
|
||||
leftMargin: CodecsViewerStyle.leftMargin
|
||||
}
|
||||
|
||||
spacing: CodecsViewerStyle.column.spacing
|
||||
|
||||
|
|
@ -141,7 +147,7 @@ Column {
|
|||
text: $codec.clockRate
|
||||
}
|
||||
|
||||
CodecAttribute {
|
||||
TextField {
|
||||
Layout.preferredWidth: CodecsViewerStyle.column.bitrateWidth
|
||||
text: $codec.bitrate
|
||||
}
|
||||
|
|
@ -153,7 +159,6 @@ Column {
|
|||
|
||||
Switch {
|
||||
Layout.fillWidth: true
|
||||
Layout.leftMargin: 10
|
||||
|
||||
checked: $codec.enabled
|
||||
|
||||
|
|
@ -175,14 +180,34 @@ Column {
|
|||
// Animations/States codec.
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
states: State {
|
||||
when: mouseArea.containsMouse
|
||||
states: [
|
||||
State {
|
||||
when: mouseArea.containsMouse && !dragArea.held
|
||||
|
||||
PropertyChanges {
|
||||
target: content
|
||||
color: CodecsViewerStyle.attribute.background.color.hovered
|
||||
PropertyChanges {
|
||||
target: content
|
||||
|
||||
color: CodecsViewerStyle.attribute.background.color.hovered
|
||||
}
|
||||
},
|
||||
|
||||
State {
|
||||
when: dragArea.held
|
||||
|
||||
PropertyChanges {
|
||||
target: content
|
||||
|
||||
color: CodecsViewerStyle.attribute.background.color.hovered
|
||||
}
|
||||
|
||||
PropertyChanges {
|
||||
target: dragArea
|
||||
|
||||
opacity: 0.5
|
||||
z: Constants.zMax
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ QtObject {
|
|||
property int encoderDescriptionWidth: 280
|
||||
property int mimeWidth: 100
|
||||
property int recvFmtpWidth: 200
|
||||
property int spacing: 5
|
||||
property int spacing: 10
|
||||
}
|
||||
|
||||
property QtObject legend: QtObject {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue