1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 17:25:13 +03:00

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
This commit is contained in:
Damjan Adamic 2014-04-20 18:27:28 +02:00
parent 0e7b420b71
commit a8c828f105
5 changed files with 72 additions and 38 deletions

View file

@ -55,6 +55,7 @@ void InputsPanel::update()
// i -> mixer number
QByteArray qba;
ExposlistWidget->clear();
firstLine = true;
int curDest = -1;
for (int i=0; i<C9X_MAX_EXPOS; i++) {
@ -66,20 +67,61 @@ void InputsPanel::update()
while (curDest<(int)md->chn-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 (curDest<inputsCount-1) {
curDest++;
AddInputLine(-curDest-1);
}
lock = false;
}
bool InputsPanel::AddInputLine(int dest, const ExpoData * md)
{
bool new_ch;
QString str = getInputText(dest, &new_ch);
QListWidgetItem *itm = new QListWidgetItem(str);
QByteArray qba(1, (quint8)dest);
if (md) qba.append((const char*)md, sizeof(ExpoData));
itm->setData(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 (curDest<inputsCount-1) {
curDest++;
QString str = getInputStr(model, curDest);
qba.clear();
qba.append((quint8)-curDest-1);
QListWidgetItem *itm = new QListWidgetItem(str);
itm->setData(Qt::UserRole,qba); // add new expo
ExposlistWidget->addItem(itm);
}
lock = false;
return Qt::escape(str).replace(" ", "&nbsp;");
}
bool InputsPanel::gm_insertExpo(int idx)
{
if (idx<0 || idx>=C9X_MAX_EXPOS || model.expoData[C9X_MAX_EXPOS-1].mode > 0) {

View file

@ -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<int> createExpoListFromSelected();
void setSelectedByExpoList(QList<int> list);
void pasteExpoMimeData(const QMimeData * mimeData, int destIdx);
bool AddInputLine(int dest, const ExpoData * md = 0);
QString getInputText(int dest, bool * new_ch);
};

View file

@ -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();

View file

@ -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; i<firmware->getCapability(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 = "<b>" + str + "</b>";
}
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);
}

View file

@ -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);