]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Make FolderStatusDelegate::paint less horrible to read
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 4 May 2023 02:25:01 +0000 (10:25 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 8 May 2023 12:04:56 +0000 (20:04 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/folderstatusdelegate.cpp

index 1a6f54abc11b913bfcef4fb41da8a3df7df58981..8895cd40f2537a85feceaeeadf0077e09d389383 100644 (file)
@@ -199,9 +199,8 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
 
     auto optionsButtonVisualRect = optionsButtonRect(option.rect, option.direction);
 
-    QPixmap pm = statusIcon.pixmap(iconSize, iconSize, syncEnabled ? QIcon::Normal : QIcon::Disabled);
-    painter->drawPixmap(QStyle::visualRect(option.direction, option.rect, iconRect).left(),
-        iconRect.top(), pm);
+    const auto statusPixmap = statusIcon.pixmap(iconSize, iconSize, syncEnabled ? QIcon::Normal : QIcon::Disabled);
+    painter->drawPixmap(QStyle::visualRect(option.direction, option.rect, iconRect).left(), iconRect.top(), statusPixmap);
 
     // only show the warning icon if the sync is running. Otherwise its
     // encoded in the status icon.
@@ -213,22 +212,22 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
         warnRect.setHeight(16);
 
         QIcon warnIcon(":/client/theme/warning");
-        const auto pm = warnIcon.pixmap(16, 16, syncEnabled ? QIcon::Normal : QIcon::Disabled);
+        const auto warnPixmap = warnIcon.pixmap(16, 16, syncEnabled ? QIcon::Normal : QIcon::Disabled);
         warnRect = QStyle::visualRect(option.direction, option.rect, warnRect);
-        painter->drawPixmap(QPoint(warnRect.left(), warnRect.top()), pm);
+        painter->drawPixmap(QPoint(warnRect.left(), warnRect.top()), warnPixmap);
     }
 
     auto palette = option.palette;
 
-    auto cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
-    if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) {
-        cg = QPalette::Inactive;
+    auto colourGroup = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
+    if (colourGroup == QPalette::Normal && !(option.state & QStyle::State_Active)) {
+        colourGroup = QPalette::Inactive;
     }
 
     if (option.state & QStyle::State_Selected) {
-        painter->setPen(palette.color(cg, QPalette::HighlightedText));
+        painter->setPen(palette.color(colourGroup, QPalette::HighlightedText));
     } else {
-        painter->setPen(palette.color(cg, QPalette::Text));
+        painter->setPen(palette.color(colourGroup, QPalette::Text));
     }
 
     const auto elidedAlias = aliasFm.elidedText(aliasText, Qt::ElideRight, aliasRect.width());
@@ -245,13 +244,13 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
         painter->drawText(QStyle::visualRect(option.direction, option.rect, localPathRect), textAlign, elidedPathText);
     }
 
-    auto h = iconRect.bottom() + margin;
+    auto textBoxTop = iconRect.bottom() + margin;
 
     // paint an error overlay if there is an error string or conflict string
     auto drawTextBox = [&](const QStringList &texts, QColor color) {
         auto rect = localPathRect;
         rect.setLeft(iconRect.left());
-        rect.setTop(h);
+        rect.setTop(textBoxTop);
         rect.setHeight(texts.count() * subFm.height() + 2 * margin);
         rect.setRight(option.rect.right() - margin);
 
@@ -268,15 +267,14 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
             rect.width() - 2 * margin,
             subFm.height());
 
-        foreach (QString eText, texts) {
-            painter->drawText(QStyle::visualRect(option.direction, option.rect, textRect), textAlign,
-                subFm.elidedText(eText, Qt::ElideLeft, textRect.width()));
+        for (const auto &eText : texts) {
+            painter->drawText(QStyle::visualRect(option.direction, option.rect, textRect), textAlign, subFm.elidedText(eText, Qt::ElideLeft, textRect.width()));
             textRect.translate(0, textRect.height());
         }
         // restore previous state
         painter->restore();
 
-        h = rect.bottom() + margin;
+        textBoxTop = rect.bottom() + margin;
     };
 
     if (!conflictTexts.isEmpty()) {
@@ -298,35 +296,32 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
         painter->save();
 
         // Overall Progress Bar.
-        QRect pBRect;
-        pBRect.setTop(remotePathRect.top());
-        pBRect.setLeft(nextToIcon);
-        pBRect.setHeight(barHeight);
-        pBRect.setWidth(overallWidth - 2 * margin);
+        QRect progressBarRect;
+        progressBarRect.setTop(remotePathRect.top());
+        progressBarRect.setLeft(nextToIcon);
+        progressBarRect.setHeight(barHeight);
+        progressBarRect.setWidth(overallWidth - 2 * margin);
 
-        QStyleOptionProgressBar pBarOpt;
+        QStyleOptionProgressBar progressBarOpt;
 
-        pBarOpt.state = option.state | QStyle::State_Horizontal;
-        pBarOpt.minimum = 0;
-        pBarOpt.maximum = 100;
-        pBarOpt.progress = overallPercent;
-        pBarOpt.orientation = Qt::Horizontal;
-        pBarOpt.rect = QStyle::visualRect(option.direction, option.rect, pBRect);
-        QApplication::style()->drawControl(QStyle::CE_ProgressBar, &pBarOpt, painter, option.widget);
+        progressBarOpt.state = option.state | QStyle::State_Horizontal;
+        progressBarOpt.minimum = 0;
+        progressBarOpt.maximum = 100;
+        progressBarOpt.progress = overallPercent;
+        progressBarOpt.orientation = Qt::Horizontal;
+        progressBarOpt.rect = QStyle::visualRect(option.direction, option.rect, progressBarRect);
+        QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOpt, painter, option.widget);
 
 
         // Overall Progress Text
         QRect overallProgressRect;
-        overallProgressRect.setTop(pBRect.bottom() + margin);
+        overallProgressRect.setTop(progressBarRect.bottom() + margin);
         overallProgressRect.setHeight(fileNameTextHeight);
-        overallProgressRect.setLeft(pBRect.left());
-        overallProgressRect.setWidth(pBRect.width());
+        overallProgressRect.setLeft(progressBarRect.left());
+        overallProgressRect.setWidth(progressBarRect.width());
         painter->setFont(progressFont);
 
-        painter->drawText(QStyle::visualRect(option.direction, option.rect, overallProgressRect),
-            Qt::AlignLeft | Qt::AlignVCenter, overallString);
-        // painter->drawRect(overallProgressRect);
-
+        painter->drawText(QStyle::visualRect(option.direction, option.rect, overallProgressRect), Qt::AlignLeft | Qt::AlignVCenter, overallString);
         painter->restore();
     }
 
@@ -341,8 +336,8 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
         btnOpt.subControls = QStyle::SC_ToolButton;
         btnOpt.rect = optionsButtonVisualRect;
         btnOpt.icon = _iconMore;
-        const auto e = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize);
-        btnOpt.iconSize = QSize(e,e);
+        const auto buttonSize = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize);
+        btnOpt.iconSize = QSize(buttonSize, buttonSize);
         QApplication::style()->drawComplexControl(QStyle::CC_ToolButton, &btnOpt, painter);
     }
 }