From b1332c6494c55fcab456f086fa5f49a7a6915e33 Mon Sep 17 00:00:00 2001 From: 3djc Date: Thu, 22 Sep 2016 07:43:24 +0200 Subject: [PATCH] Port to next work by Elecpower: https://github.com/opentx/opentx/pull/3838 --- companion/src/modeledit/mixerslist.cpp | 24 ++++++++++++++----- companion/src/modeledit/mixerslist.h | 1 + companion/src/modeledit/mixes.cpp | 33 ++++++++++++++++---------- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/companion/src/modeledit/mixerslist.cpp b/companion/src/modeledit/mixerslist.cpp index f1a368a03..879383075 100644 --- a/companion/src/modeledit/mixerslist.cpp +++ b/companion/src/modeledit/mixerslist.cpp @@ -26,12 +26,24 @@ QStringList MixersList::mimeTypes () const { QStringList types; if (expo) types << "application/x-companion-expo-item"; - else types << "application/x-companion-mix-item"; + else types << "application/x-companion-mix-item"; return types; } +void MixersList::dropEvent(QDropEvent *event) +{ + QList list; + foreach(QListWidgetItem *item, selectedItems()) { + int idx= item->data(Qt::UserRole).toByteArray().at(0); + if(idx >= 0) list << idx; + } + if (list.count()<1) return; + event->acceptProposedAction(); + dropMimeData(indexAt(event->pos()).row(),event->mimeData(),event->dropAction()); +} + bool MixersList::dropMimeData( int index, const QMimeData * data, Qt::DropAction action ) -{ +{ // qDebug() << "MixersList::dropMimeData() index:" << index << "formats" << data->formats(); QByteArray dropData = data->data(expo ? "application/x-companion-expo-item" : "application/x-companion-mix-item"); if (dropData.isNull() ) return false; @@ -52,7 +64,7 @@ bool MixersList::dropMimeData( int index, const QMimeData * data, Qt::DropAction QMimeData *mimeData = new QMimeData; mimeData->setData(expo ? "application/x-companion-expo" : "application/x-companion-mix", qba); emit mimeDropped(index, mimeData, action); - delete mimeData; //is this correct? is mimeData freed elswere?? + delete mimeData; //is this correct? is mimeData freed elswere?? } return true; @@ -105,7 +117,7 @@ QSize MixersDelegate::sizeHint ( const QStyleOptionViewItem & option, const QMod //qDebug() << "MixersDelegate::sizeHint() UserRole-> " << index.model()->data(index, Qt::UserRole + 2); int height = doc.size().height(); if ( index.model()->data(index, Qt::UserRole + 2).toInt() > 0 ) { - //qDebug() << "MixersDelegate::sizeHint() detected channel head"; + //qDebug() << "MixersDelegate::sizeHint() detected channel head"; height = doc.size().height() + MIX_ROW_HEIGHT_INCREASE; } //qDebug() << "MixersDelegate::sizeHint() options.rect " << options.rect; @@ -121,7 +133,7 @@ void MixersDelegate::SetupDocument(QTextDocument & doc, const QStyleOptionViewIt //minimize margins (default margins look ugly) QTextFrame *tf = doc.rootFrame(); - QTextFrameFormat tff = tf->frameFormat(); + QTextFrameFormat tff = tf->frameFormat(); tff.setMargin(0); - tf->setFrameFormat(tff); + tf->setFrameFormat(tff); } diff --git a/companion/src/modeledit/mixerslist.h b/companion/src/modeledit/mixerslist.h index 07854c2bd..0dda2a5ca 100644 --- a/companion/src/modeledit/mixerslist.h +++ b/companion/src/modeledit/mixerslist.h @@ -13,6 +13,7 @@ class MixersList : public QListWidget public: explicit MixersList(QWidget *parent, bool expo); void keyPressEvent(QKeyEvent *event); + void dropEvent(QDropEvent *event); signals: void mimeDropped(int index, const QMimeData *data, Qt::DropAction action); diff --git a/companion/src/modeledit/mixes.cpp b/companion/src/modeledit/mixes.cpp index d7c3a3313..c1930e9f1 100644 --- a/companion/src/modeledit/mixes.cpp +++ b/companion/src/modeledit/mixes.cpp @@ -3,7 +3,7 @@ MixesPanel::MixesPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware): ModelPanel(parent, model, generalSettings, firmware), - mixInserted(false), + mixInserted(false), highlightedSource(0), modelPrinter(firmware, generalSettings, model) { @@ -76,7 +76,7 @@ void MixesPanel::update() @note Mixer lines are now HTML formated in order to support bold text. - @param[in] dest defines which mixer line to create. + @param[in] dest defines which mixer line to create. If dest < 0 then create empty channel slotr fo channel -dest ( dest=-2 -> CH2) if dest >=0 then create used channel based on model mix data from slot dest (dest=4 -> model mix[4]) @@ -94,11 +94,11 @@ bool MixesPanel::AddMixerLine(int dest) MixData *md = &model->mixData[dest]; qba.append((const char*)md, sizeof(MixData)); } - itm->setData(Qt::UserRole, qba); + itm->setData(Qt::UserRole, qba); #if MIX_ROW_HEIGHT_INCREASE > 0 if (new_ch && !firstLine) { //increase size of this row - itm->setData(GroupHeaderRole, 1); + itm->setData(GroupHeaderRole, 1); } #endif MixerlistWidget->addItem(itm); @@ -110,11 +110,11 @@ bool MixesPanel::AddMixerLine(int dest) /** @brief Returns HTML formated mixer representation - @param[in] dest defines which mixer line to create. + @param[in] dest defines which mixer line to create. If dest < 0 then create empty channel slot for channel -dest ( dest=-2 -> CH2) if dest >=0 then create used channel based on model mix data from slot dest (dest=4 -> model mix[4]) - @retval string mixer line in HTML + @retval string mixer line in HTML */ QString MixesPanel::getMixerText(int dest, bool * new_ch) { @@ -187,7 +187,7 @@ void MixesPanel::gm_openMix(int index) model->mixData[index] = mixd; emit modified(); update(); - } + } else { if (mixInserted) { gm_deleteMix(index); @@ -215,7 +215,7 @@ void MixesPanel::mixerlistWidget_doubleClicked(QModelIndex index) if (!gm_insertMix(idx)) return; model->mixData[idx].destCh = i; mixInserted = true; - } + } else { mixInserted = false; } @@ -355,7 +355,7 @@ void MixesPanel::mixerOpen() if (!gm_insertMix(idx)) return; model->mixData[idx].destCh = i; mixInserted = true; - } + } else { mixInserted = false; } @@ -393,7 +393,7 @@ void MixesPanel::mixerAdd() if (!gm_insertMix(index)) return; model->mixData[index].destCh = i; mixInserted = true; - } + } else { index++; if (!gm_insertMix(index)) return; @@ -428,11 +428,18 @@ void MixesPanel::mixerlistWidget_customContextMenuRequested(QPoint pos) contextMenu.exec(globalPos); } -void MixesPanel::mimeMixerDropped(int index, const QMimeData *data, Qt::DropAction /*action*/) +void MixesPanel::mimeMixerDropped(int index, const QMimeData *data, Qt::DropAction action) { int idx= MixerlistWidget->item(index > 0 ? index-1 : 0)->data(Qt::UserRole).toByteArray().at(0); //qDebug() << "MixesPanel::mimeMixerDropped()" << index << data; - pasteMixerMimeData(data, idx); + if (action==Qt::CopyAction) { + pasteMixerMimeData(data, idx); + } + else if (action==Qt::MoveAction) { + QList list = createMixListFromSelected(); + mixersDeleteList(list); + pasteMixerMimeData(data, idx); + } } void MixesPanel::mixesEdited() @@ -469,7 +476,7 @@ int MixesPanel::gm_moveMix(int idx, bool dir) //true=inc=down false=dec=up if (idx == 0 && !dir) { //special case: topmost mixer moving up if (src.destCh > 1) src.destCh--; - return idx; + return idx; } int tdx = dir ? idx+1 : idx-1;