Commit 37797ea0 authored by Ronan Abhamon's avatar Ronan Abhamon

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

parent cf938262
......@@ -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) {
......
......@@ -53,6 +53,21 @@ 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
);
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:
......
......@@ -8,7 +8,7 @@ import Linphone.Styles 1.0
// =============================================================================
Column {
property alias model: visualModel.model
property alias model: view.model
// ---------------------------------------------------------------------------
// Header.
......@@ -76,9 +76,6 @@ Column {
height: count * CodecsViewerStyle.attribute.height
model: DelegateModel {
id: visualModel
// -----------------------------------------------------------------------
// One codec.
// -----------------------------------------------------------------------
......@@ -96,8 +93,8 @@ Column {
drag {
axis: Drag.YAxis
maximumY: (view.count - DelegateModel.itemsIndex) * height - height
minimumY: -DelegateModel.itemsIndex * height
maximumY: (view.count - index) * height - height
minimumY: -index * height
target: held ? content : undefined
}
......@@ -107,7 +104,7 @@ Column {
onPressed: held = true
onReleased: {
held = false
console.log('toto', content.y)
content.y = 0
}
......@@ -160,23 +157,9 @@ Column {
checked: $codec.enabled
onClicked: visualModel.model.enableCodec(index, !checked)
}
onClicked: view.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 {
......@@ -202,5 +185,4 @@ Column {
}
}
}
}
}
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