From: Christian Kamm Date: Wed, 12 Jul 2017 12:50:51 +0000 (+0200) Subject: AccountSettings: Draw a box to indicate pending conflicts X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~704^2^2~35 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7979342edffa97190f538061279f979dcb396717;p=nextcloud-desktop.git AccountSettings: Draw a box to indicate pending conflicts --- diff --git a/src/gui/folderstatusdelegate.cpp b/src/gui/folderstatusdelegate.cpp index 1d9389374..0c9e5ad39 100644 --- a/src/gui/folderstatusdelegate.cpp +++ b/src/gui/folderstatusdelegate.cpp @@ -76,12 +76,18 @@ QSize FolderStatusDelegate::sizeHint(const QStyleOptionViewItem &option, // calc height int h = rootFolderHeightWithoutErrors(fm, aliasFm); + // this already includes the bottom margin + // add some space to show an conflict indicator. + int margin = fm.height() / 4; + if (!qvariant_cast(index.data(FolderConflictMsg)).isEmpty()) { + QStringList msgs = qvariant_cast(index.data(FolderConflictMsg)); + h += margin + 2 * margin + msgs.count() * fm.height(); + } // add some space to show an error condition. if (!qvariant_cast(index.data(FolderErrorMsg)).isEmpty()) { - int margin = fm.height() / 4; QStringList errMsgs = qvariant_cast(index.data(FolderErrorMsg)); - h += margin + errMsgs.count() * fm.height(); + h += margin + 2 * margin + errMsgs.count() * fm.height(); } return QSize(0, h); @@ -98,7 +104,7 @@ int FolderStatusDelegate::rootFolderHeightWithoutErrors(const QFontMetrics &fm, h += fm.height(); // local path h += margin; // between local and remote path h += fm.height(); // remote path - h += aliasMargin; // bottom margin + h += margin; // bottom margin return h; } @@ -151,6 +157,7 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem & QString aliasText = qvariant_cast(index.data(HeaderRole)); QString pathText = qvariant_cast(index.data(FolderPathRole)); QString remotePath = qvariant_cast(index.data(FolderSecondPathRole)); + QStringList conflictTexts = qvariant_cast(index.data(FolderConflictMsg)); QStringList errorTexts = qvariant_cast(index.data(FolderErrorMsg)); int overallPercent = qvariant_cast(index.data(SyncProgressOverallPercent)); @@ -252,37 +259,40 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem & textAlign, elidedPathText); } - // paint an error overlay if there is an error string + int h = iconRect.bottom() + margin; - int h = iconRect.bottom(); - if (!errorTexts.isEmpty()) { - h += margin; - QRect errorRect = localPathRect; - errorRect.setLeft(iconRect.left()); - errorRect.setTop(h); - errorRect.setHeight(errorTexts.count() * subFm.height() + 2 * margin); - errorRect.setRight(option.rect.right() - margin); + // paint an error overlay if there is an error string or conflict string + auto drawTextBox = [&](const QStringList &texts, QColor color) { + QRect rect = localPathRect; + rect.setLeft(iconRect.left()); + rect.setTop(h); + rect.setHeight(texts.count() * subFm.height() + 2 * margin); + rect.setRight(option.rect.right() - margin); - painter->setBrush(QColor(0xbb, 0x4d, 0x4d)); + painter->setBrush(color); painter->setPen(QColor(0xaa, 0xaa, 0xaa)); - painter->drawRoundedRect(QStyle::visualRect(option.direction, option.rect, errorRect), + painter->drawRoundedRect(QStyle::visualRect(option.direction, option.rect, rect), 4, 4); painter->setPen(Qt::white); painter->setFont(errorFont); - QRect errorTextRect(errorRect.left() + margin, - errorRect.top() + margin, - errorRect.width() - 2 * margin, + QRect textRect(rect.left() + margin, + rect.top() + margin, + rect.width() - 2 * margin, subFm.height()); - foreach (QString eText, errorTexts) { - painter->drawText(QStyle::visualRect(option.direction, option.rect, errorTextRect), textAlign, - subFm.elidedText(eText, Qt::ElideLeft, errorTextRect.width())); - errorTextRect.translate(0, errorTextRect.height()); + foreach (QString eText, texts) { + painter->drawText(QStyle::visualRect(option.direction, option.rect, textRect), textAlign, + subFm.elidedText(eText, Qt::ElideLeft, textRect.width())); + textRect.translate(0, textRect.height()); } - h = errorRect.bottom(); - } - h += margin; + h = rect.bottom() + margin; + }; + + if (!conflictTexts.isEmpty()) + drawTextBox(conflictTexts, QColor(0xba, 0xba, 0x4d)); + if (!errorTexts.isEmpty()) + drawTextBox(errorTexts, QColor(0xbb, 0x4d, 0x4d)); // Sync File Progress Bar: Show it if syncFile is not empty. if (showProgess) { diff --git a/src/gui/folderstatusdelegate.h b/src/gui/folderstatusdelegate.h index a3fd5b71d..213c822dd 100644 --- a/src/gui/folderstatusdelegate.h +++ b/src/gui/folderstatusdelegate.h @@ -33,6 +33,7 @@ public: HeaderRole, FolderPathRole, // for a SubFolder it's the complete path FolderSecondPathRole, + FolderConflictMsg, FolderErrorMsg, FolderSyncPaused, FolderStatusIconRole, diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 7d443b641..ac32dc865 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -226,6 +226,10 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const return f->shortGuiLocalPath(); case FolderStatusDelegate::FolderSecondPathRole: return f->remotePath(); + case FolderStatusDelegate::FolderConflictMsg: + return (f->syncResult().numNewConflictItems() + f->syncResult().numOldConflictItems() > 0) + ? QStringList(tr("There are unresolved conflicts. Click for details.")) + : QStringList(); case FolderStatusDelegate::FolderErrorMsg: return f->syncResult().errorStrings(); case FolderStatusDelegate::SyncRunning: