[PATCH] (issue146) Always draw certificate item buttons as unchecked

Wald Commits scm-commit at wald.intevation.org
Wed Sep 24 16:27:11 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1411568727 -7200
# Node ID ad4fc3649ffb644d758beafa111e8012e257ead1
# Parent  7da9ec20eae4af2c1dc869b3b8db4eaa9e488181
(issue146) Always draw certificate item buttons as unchecked

diff -r 7da9ec20eae4 -r ad4fc3649ffb ui/certificateitemwidget.cpp
--- a/ui/certificateitemwidget.cpp	Wed Sep 24 15:49:27 2014 +0200
+++ b/ui/certificateitemwidget.cpp	Wed Sep 24 16:25:27 2014 +0200
@@ -11,6 +11,27 @@
 #include <QDebug>
 #include <QStyleFactory>
 #include <QToolButton>
+#include <QSignalBlocker>
+
+void CheckLessToolBtn::paintEvent(QPaintEvent * pe) {
+
+    /* Hack to always paint the button as if it were
+     * not checked. */
+    bool oldchecked = isChecked();
+    QIcon oldIcon = icon();
+    QIcon tmpIcon;
+    if (isEnabled())
+        tmpIcon = QIcon(oldIcon.pixmap(QSize(48, 48), QIcon::Normal, oldchecked ? QIcon::On : QIcon::Off));
+    else {
+        tmpIcon = QIcon(oldIcon.pixmap(QSize(48, 48), QIcon::Disabled, oldchecked ? QIcon::On : QIcon::Off));
+    }
+    QSignalBlocker blk(this);
+    setChecked(false);
+    setIcon(tmpIcon);
+    QToolButton::paintEvent(pe);
+    setIcon(oldIcon);
+    setChecked(oldchecked);
+}
 
 CertificateItemWidget::CertificateItemWidget(QWidget *parent,
                                              const Certificate &cert,
@@ -22,12 +43,12 @@
     mCertificate = cert;
     mOriginalState = state;
     btn->setCheckable(true);
-    btn->setStyleSheet("QToolButton:Checked{"
+/*    btn->setStyleSheet("QToolButton:Checked{"
          "border: 1px solid #8f8f91;"
          "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
                                            "stop: 0 #f6f7fa, stop: 1 #dadbde);"
     "}"
-    );
+    );*/
     setState(state);
     setupGUI();
 }
diff -r 7da9ec20eae4 -r ad4fc3649ffb ui/certificateitemwidget.h
--- a/ui/certificateitemwidget.h	Wed Sep 24 15:49:27 2014 +0200
+++ b/ui/certificateitemwidget.h	Wed Sep 24 16:25:27 2014 +0200
@@ -14,10 +14,14 @@
  */
 #include <QWidget>
 #include <QLabel>
+#include <QToolButton>
 
 #include "certificate.h"
 
-class QToolButton;
+class CheckLessToolBtn : public QToolButton
+{
+    void paintEvent(QPaintEvent * pe);
+};
 
 class CertificateItemWidget : public QWidget
 {
diff -r 7da9ec20eae4 -r ad4fc3649ffb ui/mainwindow.cpp
--- a/ui/mainwindow.cpp	Wed Sep 24 15:49:27 2014 +0200
+++ b/ui/mainwindow.cpp	Wed Sep 24 16:25:27 2014 +0200
@@ -33,6 +33,7 @@
 #include <QDesktopServices>
 
 #include "certificatelist.h"
+#include "certificateitemwidget.h"
 #include "downloader.h"
 #include "helpdialog.h"
 #include "aboutdialog.h"
@@ -1256,7 +1257,7 @@
             bool state = !mPreviouslyUnselected.contains(cert.base64Line());
             if (cert.isInstallCert()) {
                 oldInstallCerts.append(cert);
-                QToolButton* actionBtn = new QToolButton();
+                CheckLessToolBtn* actionBtn = new CheckLessToolBtn();
                 QIcon btnIcon;
                 if (!state) {
                     btnIcon.addFile(":/img/cert-to-be-installed-good-48.png", QSize(48, 48), QIcon::Normal, QIcon::Off);
@@ -1274,7 +1275,7 @@
             }
             else {
                 oldRemoveCerts.append(cert);
-                QToolButton* actionBtn = new QToolButton();
+                CheckLessToolBtn* actionBtn = new CheckLessToolBtn();
                 QIcon btnIcon;
                 actionBtn->setProperty("ToolTip_Off", tr("Certificate will be removed."));
                 actionBtn->setProperty("ToolTip_On", tr("Certificate has not been removed."));
@@ -1299,7 +1300,7 @@
                 if (mInstalledList.getCertificates().contains(cert)) {
                     // Was in the old list.
                     oldInstallCerts.append(cert);
-                    QToolButton* actionBtn = new QToolButton();
+                    CheckLessToolBtn* actionBtn = new CheckLessToolBtn();
                     QIcon btnIcon;
                     actionBtn->setProperty("ToolTip_Off", tr("Certificate is installed."));
                     actionBtn->setProperty("ToolTip_On", tr("Certifcate is not installed."));
@@ -1311,7 +1312,7 @@
                 else {
                     // Is a brand new certificate
                     newInstallCerts.append(cert);
-                    QToolButton* actionBtn = new QToolButton();
+                    CheckLessToolBtn* actionBtn = new CheckLessToolBtn();
                     QIcon btnIcon;
                     actionBtn->setProperty("ToolTip_Off", tr("Certificate will be installed."));
                     actionBtn->setProperty("ToolTip_On", tr("Certificate will not be installed."));
@@ -1327,7 +1328,7 @@
                     // Was in the old list.
                     oldRemoveCerts.append(cert);
                     // Is removed, so set editable to false.
-                    QToolButton* actionBtn = new QToolButton();
+                    CheckLessToolBtn* actionBtn = new CheckLessToolBtn();
                     QIcon btnIcon;
                     actionBtn->setProperty("ToolTip_Off", tr("Certificate will be removed."));
                     actionBtn->setProperty("ToolTip_On", tr("Certificate has not been removed."));
@@ -1345,7 +1346,7 @@
                     // Was in the old list with status "install" and now has the
                     // status "remove".
                     newRemoveCerts.append(cert);
-                    QToolButton* actionBtn = new QToolButton();
+                    CheckLessToolBtn* actionBtn = new CheckLessToolBtn();
                     QIcon btnIcon;
                     actionBtn->setProperty("ToolTip_Off", tr("Certificate will be removed."));
                     actionBtn->setProperty("ToolTip_On", tr("Certificate will not be removed."));


More information about the Trustbridge-commits mailing list