Commit 71d2c9aa authored by Ronan Abhamon's avatar Ronan Abhamon

feat(src/components/codecs/AbstractCodecsModel): in progress

parent 9200f973
...@@ -52,15 +52,26 @@ QVariant AbstractCodecsModel::data (const QModelIndex &index, int role) const { ...@@ -52,15 +52,26 @@ QVariant AbstractCodecsModel::data (const QModelIndex &index, int role) const {
return QVariant(); return QVariant();
} }
bool AbstractCodecsModel::moveRow ( // -----------------------------------------------------------------------------
const QModelIndex &source_parent,
int source_row, void AbstractCodecsModel::enableCodec (int id, bool status) {
const QModelIndex &destination_parent, Q_ASSERT(id >= 0 && id < m_codecs.count());
int destination_child
) { QVariantMap &map = m_codecs[id];
return moveRows(source_parent, source_row, 1, destination_parent, destination_child); shared_ptr<linphone::PayloadType> codec = map.value("__codec").value<shared_ptr<linphone::PayloadType> >();
codec->enable(status);
map["enabled"] = status;
emit dataChanged(index(id, 0), index(id, 0));
}
void AbstractCodecsModel::moveCodec (int source, int destination) {
moveRow(QModelIndex(), source, QModelIndex(), destination);
} }
// -----------------------------------------------------------------------------
bool AbstractCodecsModel::moveRows ( bool AbstractCodecsModel::moveRows (
const QModelIndex &source_parent, const QModelIndex &source_parent,
int source_row, int source_row,
...@@ -70,40 +81,38 @@ bool AbstractCodecsModel::moveRows ( ...@@ -70,40 +81,38 @@ bool AbstractCodecsModel::moveRows (
) { ) {
int limit = source_row + count - 1; int limit = source_row + count - 1;
if (source_row < 0 || count < 0 || limit >= m_codecs.count()) {
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; return false;
}
beginMoveRows(source_parent, source_row, limit, destination_parent, destination_child); beginMoveRows(source_parent, source_row, limit, destination_parent, destination_child);
if (destination_child < source_row) { if (destination_child > source_row) {
for (int i = source_row; i <= limit; ++i) --destination_child;
for (int i = source_row; i <= limit; ++i) {
m_codecs.move(source_row, destination_child + i - source_row); m_codecs.move(source_row, destination_child + i - source_row);
}
} else { } else {
for (int i = source_row; i <= limit; ++i) for (int i = source_row; i <= limit; ++i)
m_codecs.move(source_row, destination_child + i); m_codecs.move(source_row + i - source_row, destination_child + i - source_row);
} }
endRemoveRows(); endMoveRows();
return true; return true;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void AbstractCodecsModel::enableCodec (int id, bool status) {
Q_ASSERT(id >= 0 && id < m_codecs.count());
QVariantMap &map = m_codecs[id];
shared_ptr<linphone::PayloadType> codec = map.value("__codec").value<shared_ptr<linphone::PayloadType> >();
codec->enable(status);
map["enabled"] = status;
emit dataChanged(index(id, 0), index(id, 0));
}
// -----------------------------------------------------------------------------
void AbstractCodecsModel::addCodec (std::shared_ptr<linphone::PayloadType> &codec) { void AbstractCodecsModel::addCodec (std::shared_ptr<linphone::PayloadType> &codec) {
QVariantMap map; QVariantMap map;
......
...@@ -45,13 +45,10 @@ public: ...@@ -45,13 +45,10 @@ public:
QHash<int, QByteArray> roleNames () const override; QHash<int, QByteArray> roleNames () const override;
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool moveRow ( Q_INVOKABLE void enableCodec (int id, bool status);
const QModelIndex &source_parent, Q_INVOKABLE void moveCodec (int source, int destination);
int source_row,
const QModelIndex &destination_parent,
int destination_child
);
protected:
bool moveRows ( bool moveRows (
const QModelIndex &source_parent, const QModelIndex &source_parent,
int source_row, int source_row,
...@@ -60,9 +57,6 @@ public: ...@@ -60,9 +57,6 @@ public:
int destination_child int destination_child
) override; ) override;
void enableCodec (int id, bool status);
protected:
void addCodec (std::shared_ptr<linphone::PayloadType> &codec); void addCodec (std::shared_ptr<linphone::PayloadType> &codec);
private: private:
......
...@@ -70,7 +70,6 @@ Column { ...@@ -70,7 +70,6 @@ Column {
anchors { anchors {
left: parent.left left: parent.left
leftMargin: CodecsViewerStyle.leftMargin
right: parent.right right: parent.right
} }
...@@ -93,8 +92,8 @@ Column { ...@@ -93,8 +92,8 @@ Column {
drag { drag {
axis: Drag.YAxis axis: Drag.YAxis
maximumY: (view.count - index) * height - height maximumY: (view.count - index) * height - height / 2
minimumY: -index * height minimumY: -index * height - height / 2
target: held ? content : undefined target: held ? content : undefined
} }
...@@ -104,7 +103,7 @@ Column { ...@@ -104,7 +103,7 @@ Column {
onPressed: held = true onPressed: held = true
onReleased: { onReleased: {
held = false held = false
console.log('toto', content.y) view.model.moveCodec(index, index + 1 + content.y / height)
content.y = 0 content.y = 0
} }
...@@ -116,13 +115,20 @@ Column { ...@@ -116,13 +115,20 @@ Column {
Drag.hotSpot.x: width / 2 Drag.hotSpot.x: width / 2
Drag.hotSpot.y: height / 2 Drag.hotSpot.y: height / 2
anchors {
left: parent.left
right: parent.right
}
color: CodecsViewerStyle.attribute.background.color.normal color: CodecsViewerStyle.attribute.background.color.normal
height: dragArea.height height: dragArea.height
width: dragArea.width
RowLayout { RowLayout {
anchors.fill: parent anchors {
fill: parent
leftMargin: CodecsViewerStyle.leftMargin
}
spacing: CodecsViewerStyle.column.spacing spacing: CodecsViewerStyle.column.spacing
...@@ -141,7 +147,7 @@ Column { ...@@ -141,7 +147,7 @@ Column {
text: $codec.clockRate text: $codec.clockRate
} }
CodecAttribute { TextField {
Layout.preferredWidth: CodecsViewerStyle.column.bitrateWidth Layout.preferredWidth: CodecsViewerStyle.column.bitrateWidth
text: $codec.bitrate text: $codec.bitrate
} }
...@@ -153,7 +159,6 @@ Column { ...@@ -153,7 +159,6 @@ Column {
Switch { Switch {
Layout.fillWidth: true Layout.fillWidth: true
Layout.leftMargin: 10
checked: $codec.enabled checked: $codec.enabled
...@@ -175,14 +180,34 @@ Column { ...@@ -175,14 +180,34 @@ Column {
// Animations/States codec. // Animations/States codec.
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
states: State { states: [
when: mouseArea.containsMouse State {
when: mouseArea.containsMouse && !dragArea.held
PropertyChanges { PropertyChanges {
target: content target: content
color: CodecsViewerStyle.attribute.background.color.hovered
}
},
State {
when: dragArea.held
PropertyChanges {
target: content
color: CodecsViewerStyle.attribute.background.color.hovered color: CodecsViewerStyle.attribute.background.color.hovered
} }
PropertyChanges {
target: dragArea
opacity: 0.5
z: Constants.zMax
}
} }
]
} }
} }
} }
...@@ -34,7 +34,7 @@ QtObject { ...@@ -34,7 +34,7 @@ QtObject {
property int encoderDescriptionWidth: 280 property int encoderDescriptionWidth: 280
property int mimeWidth: 100 property int mimeWidth: 100
property int recvFmtpWidth: 200 property int recvFmtpWidth: 200
property int spacing: 5 property int spacing: 10
} }
property QtObject legend: QtObject { property QtObject legend: QtObject {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment