From 71d2c9aa4444ed1cdcc32a2259ff5af356ade4f7 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 5 Apr 2017 15:47:21 +0200 Subject: [PATCH] feat(src/components/codecs/AbstractCodecsModel): in progress --- .../components/codecs/AbstractCodecsModel.cpp | 81 ++++++++++--------- .../components/codecs/AbstractCodecsModel.hpp | 12 +-- .../modules/Linphone/Codecs/CodecsViewer.qml | 53 ++++++++---- .../Styles/Codecs/CodecsViewerStyle.qml | 2 +- 4 files changed, 88 insertions(+), 60 deletions(-) diff --git a/linphone-desktop/src/components/codecs/AbstractCodecsModel.cpp b/linphone-desktop/src/components/codecs/AbstractCodecsModel.cpp index 18409b2ae..20724dc89 100644 --- a/linphone-desktop/src/components/codecs/AbstractCodecsModel.cpp +++ b/linphone-desktop/src/components/codecs/AbstractCodecsModel.cpp @@ -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 &codec) { diff --git a/linphone-desktop/src/components/codecs/AbstractCodecsModel.hpp b/linphone-desktop/src/components/codecs/AbstractCodecsModel.hpp index 35e8b6b72..448d813d1 100644 --- a/linphone-desktop/src/components/codecs/AbstractCodecsModel.hpp +++ b/linphone-desktop/src/components/codecs/AbstractCodecsModel.hpp @@ -45,13 +45,10 @@ 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 - ); + 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 &codec); private: diff --git a/linphone-desktop/ui/modules/Linphone/Codecs/CodecsViewer.qml b/linphone-desktop/ui/modules/Linphone/Codecs/CodecsViewer.qml index 5d20ac2bf..009381f14 100644 --- a/linphone-desktop/ui/modules/Linphone/Codecs/CodecsViewer.qml +++ b/linphone-desktop/ui/modules/Linphone/Codecs/CodecsViewer.qml @@ -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 + } } - } + ] } } } diff --git a/linphone-desktop/ui/modules/Linphone/Styles/Codecs/CodecsViewerStyle.qml b/linphone-desktop/ui/modules/Linphone/Styles/Codecs/CodecsViewerStyle.qml index 4957781f0..dfc0bc966 100644 --- a/linphone-desktop/ui/modules/Linphone/Styles/Codecs/CodecsViewerStyle.qml +++ b/linphone-desktop/ui/modules/Linphone/Styles/Codecs/CodecsViewerStyle.qml @@ -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 {