Commit 71d2c9aa authored by Ronan's avatar Ronan
Browse files

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

parent 9200f973
......@@ -52,15 +52,26 @@ 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);
// -----------------------------------------------------------------------------
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::moveCodec (int source, int destination) {
moveRow(QModelIndex(), source, QModelIndex(), destination);
}
// -----------------------------------------------------------------------------
bool AbstractCodecsModel::moveRows (
const QModelIndex &source_parent,
int source_row,
......@@ -70,40 +81,38 @@ bool AbstractCodecsModel::moveRows (
) {
int limit = source_row + count - 1;
if (source_row < 0 || count < 0 || limit >= m_codecs.count())
return false;
{
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) {
for (int i = source_row; i <= limit; ++i)
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, destination_child + i);
m_codecs.move(source_row + i - source_row, destination_child + i - source_row);
}
endRemoveRows();
endMoveRows();
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) {
QVariantMap map;
......
......@@ -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
}
},
State {
when: dragArea.held
PropertyChanges {
target: content
color: CodecsViewerStyle.attribute.background.color.hovered
}
PropertyChanges {
target: dragArea
PropertyChanges {
target: content
color: CodecsViewerStyle.attribute.background.color.hovered
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 {
......
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