From a8c828f105f51225c40c8fa58b08db8f37053cb8 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Sun, 20 Apr 2014 18:27:28 +0200 Subject: [PATCH] Corrected list items width (long items were wrapping) Refactored inputs tab, same system as mixes tab (grouping of lines) Fixed incorrect spacing for first list item --- companion/src/modeledit/inputs.cpp | 79 +++++++++++++++++--------- companion/src/modeledit/inputs.h | 3 + companion/src/modeledit/mixerslist.cpp | 3 +- companion/src/modeledit/mixes.cpp | 24 +++++--- companion/src/modeledit/mixes.h | 1 + 5 files changed, 72 insertions(+), 38 deletions(-) diff --git a/companion/src/modeledit/inputs.cpp b/companion/src/modeledit/inputs.cpp index a3cece6c1..1d05a96d9 100644 --- a/companion/src/modeledit/inputs.cpp +++ b/companion/src/modeledit/inputs.cpp @@ -55,6 +55,7 @@ void InputsPanel::update() // i -> mixer number QByteArray qba; ExposlistWidget->clear(); + firstLine = true; int curDest = -1; for (int i=0; ichn-1) { curDest++; - str = getInputStr(model, curDest); - qba.clear(); - qba.append((quint8)-curDest-1); - QListWidgetItem *itm = new QListWidgetItem(str); - itm->setData(Qt::UserRole,qba); - ExposlistWidget->addItem(itm); + AddInputLine(-curDest-1); + } + if (AddInputLine(i, md)) { + curDest++; } - if (curDest!=(int)md->chn) { + } + + while (curDestsetData(Qt::UserRole, qba); +#if MIX_ROW_HEIGHT_INCREASE > 0 + if (new_ch && !firstLine) { + //increase size of this row + itm->setData(GroupHeaderRole, 1); + } +#endif + ExposlistWidget->addItem(itm); + firstLine = false; + //qDebug() << "InputsPanel::AddInputLine(): dest" << dest << "text" << str; + return new_ch; +} + + +QString InputsPanel::getInputText(int dest, bool * new_ch) +{ + QString str; + if (new_ch) *new_ch = 0; + if (dest < 0) { + str = getInputStr(model, -dest-1); + if (new_ch) *new_ch = 1; + } + else { + ExpoData *md = &model.expoData[dest]; + + if ((dest == 0) || (model.expoData[dest-1].chn != md->chn)) { + if (new_ch) *new_ch = 1; if (firmware->getCapability(VirtualInputs)) str = QString("%1").arg(getInputStr(model, md->chn), -8, ' '); else str = getInputStr(model, md->chn); - curDest = md->chn; } else { if (firmware->getCapability(VirtualInputs)) @@ -117,29 +159,10 @@ void InputsPanel::update() QString expoName = md->name; if (!expoName.isEmpty()) str += QString(" [%1]").arg(expoName); } - - qba.clear(); - qba.append((quint8)i); - qba.append((const char*)md, sizeof(ExpoData)); - QListWidgetItem *itm = new QListWidgetItem(str); - itm->setData(Qt::UserRole,qba); // expo number - ExposlistWidget->addItem(itm); //(str); } - - while (curDestsetData(Qt::UserRole,qba); // add new expo - ExposlistWidget->addItem(itm); - } - - lock = false; + return Qt::escape(str).replace(" ", " "); } - bool InputsPanel::gm_insertExpo(int idx) { if (idx<0 || idx>=C9X_MAX_EXPOS || model.expoData[C9X_MAX_EXPOS-1].mode > 0) { diff --git a/companion/src/modeledit/inputs.h b/companion/src/modeledit/inputs.h index 393901b2c..00ff4273a 100644 --- a/companion/src/modeledit/inputs.h +++ b/companion/src/modeledit/inputs.h @@ -33,6 +33,7 @@ class InputsPanel : public ModelPanel private: bool expoInserted; MixersList *ExposlistWidget; + bool firstLine; int getExpoIndex(unsigned int dch); bool gm_insertExpo(int idx); @@ -43,6 +44,8 @@ class InputsPanel : public ModelPanel QList createExpoListFromSelected(); void setSelectedByExpoList(QList list); void pasteExpoMimeData(const QMimeData * mimeData, int destIdx); + bool AddInputLine(int dest, const ExpoData * md = 0); + QString getInputText(int dest, bool * new_ch); }; diff --git a/companion/src/modeledit/mixerslist.cpp b/companion/src/modeledit/mixerslist.cpp index da9292cfe..8da5028b5 100644 --- a/companion/src/modeledit/mixerslist.cpp +++ b/companion/src/modeledit/mixerslist.cpp @@ -102,7 +102,7 @@ QSize MixersDelegate::sizeHint ( const QStyleOptionViewItem & option, const QMod height = doc.size().height() + MIX_ROW_HEIGHT_INCREASE; } //qDebug() << "MixersDelegate::sizeHint() options.rect " << options.rect; - //qDebug() << "MixersDelegate::sizeHint() result " << QSize(doc.idealWidth(), height); + //qDebug() << "MixersDelegate::sizeHint() result " << QSize(doc.idealWidth(), height) << options.rect.width(); return QSize(doc.idealWidth(), height); } @@ -111,7 +111,6 @@ void MixersDelegate::SetupDocument(QTextDocument & doc, const QStyleOptionViewIt //setup html document doc.setHtml(options.text); doc.setDefaultFont(options.font); - doc.setTextWidth(options.rect.width()); //minimize margins (default margins look ugly) QTextFrame *tf = doc.rootFrame(); diff --git a/companion/src/modeledit/mixes.cpp b/companion/src/modeledit/mixes.cpp index eeb2564a4..fe69d3db0 100644 --- a/companion/src/modeledit/mixes.cpp +++ b/companion/src/modeledit/mixes.cpp @@ -57,7 +57,7 @@ QString MixesPanel::getChannelLabel(int curDest) name.append(" "); str += name.left(8); } - return str; + return Qt::escape(str); } void MixesPanel::update() @@ -66,6 +66,7 @@ void MixesPanel::update() // i -> mixer number QByteArray qba; MixerlistWidget->clear(); + firstLine = true; unsigned int curDest = 0; int i; unsigned int outputs = firmware->getCapability(Outputs); @@ -73,7 +74,10 @@ void MixesPanel::update() for (i=0; igetCapability(Mixes); i++) { MixData *md = &model.mixData[i]; // qDebug() << "md->destCh: " << md->destCh; - if (md->destCh==0 || md->destCh>outputs) continue; + if (md->destCh==0 || md->destCh>outputs) { + qDebug() << "WARNING: possible mixer corrupiton at i" << i << "destCh" << md->destCh; + continue; + } QString str = ""; while (curDest < md->destCh-1) { curDest++; @@ -94,19 +98,20 @@ bool MixesPanel::AddMixerLine(int dest, const MixData * md) { bool new_ch; QString str = getMixerText(dest, &new_ch); - QListWidgetItem *itm = new QListWidgetItem(); + QListWidgetItem *itm = new QListWidgetItem(str); QByteArray qba(1, (quint8)dest); if (md) qba.append((const char*)md, sizeof(MixData)); itm->setData(Qt::UserRole, qba); #if MIX_ROW_HEIGHT_INCREASE > 0 - if ((new_ch && (dest > 0)) || (dest < 0)) { + //if ((new_ch && (dest > 0)) || (dest < -1)) { + if (new_ch && ! firstLine ) { //increase size of this row itm->setData(GroupHeaderRole, 1); } #endif MixerlistWidget->addItem(itm); - itm->setText(str); - //qDebug() << "MixesPanel::AddMixerLine(): " << str; + firstLine = false; + // qDebug() << "MixesPanel::AddMixerLine(): dest" << dest << "text" << str; return new_ch; } @@ -120,6 +125,7 @@ QString MixesPanel::getMixerText(int dest, bool * new_ch) if (-dest == (int)highlightedSource) { str = "" + str + ""; } + if (new_ch) *new_ch = 1; } else { MixData *md = &model.mixData[dest]; @@ -333,7 +339,7 @@ void MixesPanel::mixersCopy() void MixesPanel::pasteMixerMimeData(const QMimeData * mimeData, int destIdx) { - //qDebug() << "void MixesPanel::pasteMixerMimeData" << mimeData->formats(); + qDebug() << "void MixesPanel::pasteMixerMimeData" << destIdx; if(mimeData->hasFormat("application/x-companion-mix")) { int idx; // mixer index int dch; @@ -346,6 +352,7 @@ void MixesPanel::pasteMixerMimeData(const QMimeData * mimeData, int destIdx) dch = model.mixData[idx].destCh; } + qDebug() << "void MixesPanel::pasteMixerMimeData() dch" << dch; QByteArray mxData = mimeData->data("application/x-companion-mix"); int i = 0; @@ -358,6 +365,7 @@ void MixesPanel::pasteMixerMimeData(const QMimeData * mimeData, int destIdx) MixData *md = &model.mixData[idx]; memcpy(md,mxData.mid(i,sizeof(MixData)).constData(),sizeof(MixData)); md->destCh = dch; + qDebug() << "void MixesPanel::pasteMixerMimeData() dch1" << dch; i += sizeof(MixData); } @@ -468,7 +476,7 @@ void MixesPanel::mixerlistWidget_customContextMenuRequested(QPoint pos) 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; + qDebug() << "MixesPanel::mimeMixerDropped()" << index << data; pasteMixerMimeData(data, idx); } diff --git a/companion/src/modeledit/mixes.h b/companion/src/modeledit/mixes.h index dcf3e8052..09876bb5f 100644 --- a/companion/src/modeledit/mixes.h +++ b/companion/src/modeledit/mixes.h @@ -43,6 +43,7 @@ class MixesPanel : public ModelPanel MixersList *MixerlistWidget; bool mixInserted; unsigned int highlightedSource; + bool firstLine; int getMixerIndex(unsigned int dch); bool gm_insertMix(int idx);