From 37797ea0b1f5256b341333207be1c47cbfa8fd5a Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 5 Apr 2017 12:07:22 +0200 Subject: [PATCH] feat(src/components/codecs/CodecsModel): in progress --- .../src/components/codecs/CodecsModel.cpp | 36 ++++ .../src/components/codecs/CodecsModel.hpp | 15 ++ .../modules/Linphone/Codecs/CodecsViewer.qml | 196 ++++++++---------- 3 files changed, 140 insertions(+), 107 deletions(-) diff --git a/linphone-desktop/src/components/codecs/CodecsModel.cpp b/linphone-desktop/src/components/codecs/CodecsModel.cpp index 341f36c8d..c43429d9e 100644 --- a/linphone-desktop/src/components/codecs/CodecsModel.cpp +++ b/linphone-desktop/src/components/codecs/CodecsModel.cpp @@ -85,6 +85,42 @@ QVariant CodecsModel::data (const QModelIndex &index, int role) const { return QVariant(); } +bool CodecsModel::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 CodecsModel::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 CodecsModel::enableCodec (int id, bool status) { diff --git a/linphone-desktop/src/components/codecs/CodecsModel.hpp b/linphone-desktop/src/components/codecs/CodecsModel.hpp index e7fdb25d6..c7446e02d 100644 --- a/linphone-desktop/src/components/codecs/CodecsModel.hpp +++ b/linphone-desktop/src/components/codecs/CodecsModel.hpp @@ -53,6 +53,21 @@ public: QHash 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 + ); + + bool moveRows ( + const QModelIndex &source_parent, + int source_row, + int count, + const QModelIndex &destination_parent, + int destination_child + ) override; + void enableCodec (int id, bool status); private: diff --git a/linphone-desktop/ui/modules/Linphone/Codecs/CodecsViewer.qml b/linphone-desktop/ui/modules/Linphone/Codecs/CodecsViewer.qml index eb8788798..5d20ac2bf 100644 --- a/linphone-desktop/ui/modules/Linphone/Codecs/CodecsViewer.qml +++ b/linphone-desktop/ui/modules/Linphone/Codecs/CodecsViewer.qml @@ -8,7 +8,7 @@ import Linphone.Styles 1.0 // ============================================================================= Column { - property alias model: visualModel.model + property alias model: view.model // --------------------------------------------------------------------------- // Header. @@ -76,129 +76,111 @@ Column { height: count * CodecsViewerStyle.attribute.height - model: DelegateModel { - id: visualModel + // ----------------------------------------------------------------------- + // One codec. + // ----------------------------------------------------------------------- - // ----------------------------------------------------------------------- - // One codec. - // ----------------------------------------------------------------------- + delegate: MouseArea { + id: dragArea - delegate: MouseArea { - id: dragArea + property bool held: false - property bool held: false + anchors { + left: parent.left + right: parent.right + } - anchors { - left: parent.left - right: parent.right - } + drag { + axis: Drag.YAxis - drag { - axis: Drag.YAxis + maximumY: (view.count - index) * height - height + minimumY: -index * height - maximumY: (view.count - DelegateModel.itemsIndex) * height - height - minimumY: -DelegateModel.itemsIndex * height + target: held ? content : undefined + } - target: held ? content : undefined - } + height: CodecsViewerStyle.attribute.height - height: CodecsViewerStyle.attribute.height + onPressed: held = true + onReleased: { + held = false + console.log('toto', content.y) + content.y = 0 + } - onPressed: held = true - onReleased: { - held = false + Rectangle { + id: content - content.y = 0 - } + Drag.active: dragArea.held + Drag.source: dragArea + Drag.hotSpot.x: width / 2 + Drag.hotSpot.y: height / 2 - Rectangle { - id: content + color: CodecsViewerStyle.attribute.background.color.normal - Drag.active: dragArea.held - Drag.source: dragArea - Drag.hotSpot.x: width / 2 - Drag.hotSpot.y: height / 2 - - color: CodecsViewerStyle.attribute.background.color.normal - - height: dragArea.height - width: dragArea.width - - RowLayout { - anchors.fill: parent - - spacing: CodecsViewerStyle.column.spacing - - CodecAttribute { - Layout.preferredWidth: CodecsViewerStyle.column.mimeWidth - text: $codec.mime - } - - CodecAttribute { - Layout.preferredWidth: CodecsViewerStyle.column.encoderDescriptionWidth - text: $codec.encoderDescription - } - - CodecAttribute { - Layout.preferredWidth: CodecsViewerStyle.column.clockRateWidth - text: $codec.clockRate - } - - CodecAttribute { - Layout.preferredWidth: CodecsViewerStyle.column.bitrateWidth - text: $codec.bitrate - } - - TextField { - Layout.preferredWidth: CodecsViewerStyle.column.recvFmtpWidth - text: $codec.recvFmtp - } - - Switch { - Layout.fillWidth: true - Layout.leftMargin: 10 - - checked: $codec.enabled - - onClicked: visualModel.model.enableCodec(index, !checked) - } - } - } - - DropArea { - anchors { - fill: parent - margins: CodecsViewerStyle.attribute.dropArea.margins - } - - onEntered: { - visualModel.items.move( - drag.source.DelegateModel.itemsIndex, - dragArea.DelegateModel.itemsIndex - ) - } - } - - MouseArea { - id: mouseArea + height: dragArea.height + width: dragArea.width + RowLayout { anchors.fill: parent - hoverEnabled: true - onPressed: mouse.accepted = false - } + spacing: CodecsViewerStyle.column.spacing - // --------------------------------------------------------------------- - // Animations/States codec. - // --------------------------------------------------------------------- - - states: State { - when: mouseArea.containsMouse - - PropertyChanges { - target: content - color: CodecsViewerStyle.attribute.background.color.hovered + CodecAttribute { + Layout.preferredWidth: CodecsViewerStyle.column.mimeWidth + text: $codec.mime } + + CodecAttribute { + Layout.preferredWidth: CodecsViewerStyle.column.encoderDescriptionWidth + text: $codec.encoderDescription + } + + CodecAttribute { + Layout.preferredWidth: CodecsViewerStyle.column.clockRateWidth + text: $codec.clockRate + } + + CodecAttribute { + Layout.preferredWidth: CodecsViewerStyle.column.bitrateWidth + text: $codec.bitrate + } + + TextField { + Layout.preferredWidth: CodecsViewerStyle.column.recvFmtpWidth + text: $codec.recvFmtp + } + + Switch { + Layout.fillWidth: true + Layout.leftMargin: 10 + + checked: $codec.enabled + + onClicked: view.model.enableCodec(index, !checked) + } + } + } + + MouseArea { + id: mouseArea + + anchors.fill: parent + hoverEnabled: true + + onPressed: mouse.accepted = false + } + + // --------------------------------------------------------------------- + // Animations/States codec. + // --------------------------------------------------------------------- + + states: State { + when: mouseArea.containsMouse + + PropertyChanges { + target: content + color: CodecsViewerStyle.attribute.background.color.hovered } } }