diff ui/certificateitemwidget.cpp @ 1109:6594e8e63a25

(issue115) Add tooltips and fix manual changes handling
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 15 Sep 2014 19:02:17 +0200
parents 9bb9932bb819
children ad4fc3649ffb
line wrap: on
line diff
--- a/ui/certificateitemwidget.cpp	Mon Sep 15 17:47:12 2014 +0200
+++ b/ui/certificateitemwidget.cpp	Mon Sep 15 19:02:17 2014 +0200
@@ -20,11 +20,15 @@
     mButton(btn)
 {
     mCertificate = cert;
-    mState = state;
-    /* We carry the state explicitly to be better prepared for future
-     * changes */
+    mOriginalState = state;
     btn->setCheckable(true);
-    btn->setChecked(!state);
+    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();
 }
 
@@ -56,41 +60,6 @@
     layout->addWidget(mButton);
     mButton->setFixedSize(64, 64);
     mButton->setIconSize(QSize(48, 48));
-    /*
-    if (mCertificate.isInstallCert()) {
-        mComboBox->addItem(QIcon(":/img/security-high.png"), QString(), mInstallLabel);
-        mComboBox->addItem(QIcon(":/img/security-low.png"), QString(), mRemoveLabel);
-        if (mState) {
-            mComboBox->setCurrentIndex(0);
-            mComboBox->setToolTip(tr("This certificate is currently installed."));
-        }
-        else {
-            mComboBox->setCurrentIndex(1);
-            mComboBox->setToolTip(tr("This certificate is currently not installed."));
-        }
-        layout->addWidget(mComboBox);
-    }
-    else if (!mCertificate.isInstallCert() && !mEditable){
-        QImage *img = new QImage(":/img/trash-empty.png");
-        QLabel *imgLabel = new QLabel;
-        imgLabel->setPixmap(QPixmap::fromImage(*img));
-        imgLabel->setFixedSize(64, 64);
-        imgLabel->setMargin(8);
-        imgLabel->setToolTip(tr("This certificate was uninstalled."));
-        layout->addWidget(imgLabel);
-    }
-    else {
-        mComboBox->addItem(QIcon(":/img/trash-empty.png"), QString(), tr("uninstall"));
-        mComboBox->addItem(QIcon(":/img/security-medium.png"), QString(), tr("keep"));
-        mComboBox->setToolTip(tr("This certificate is currently installed."));
-        if (mState)
-            mComboBox->setCurrentIndex(0);
-        else {
-            mComboBox->setCurrentIndex(1);
-        }
-        layout->addWidget(mComboBox);
-    }
-    */
     layout->addWidget(mLabel);
     this->setLayout(layout);
 }
@@ -101,22 +70,22 @@
         return true;
     }
 
-    /*
-    const QString currentString = mComboBox->currentData().toString();
-
-    if (!mCertificate.isInstallCert()) {
-        return currentString == tr("uninstall");
-    }
-
-    return currentString == mInstallLabel;
-    */
-    return mState;
+    return !mButton->isChecked();
 }
 
 void CertificateItemWidget::setState(bool state)
 {
-    mState = state;
+    /* The internal state we get here is inverted for Ui reasons the logic
+     * is if a certificate is selected for installation the button
+     * is disabled (as this is the default) Only those that are
+     * unselected have the enabled button. */
+    mButton->blockSignals(true); // code did this and not the user
     mButton->setChecked(!state);
+    mButton->blockSignals(false);
+    if (mButton->isEnabled()) {
+        mButton->setToolTip(mButton->property(!state ? "ToolTip_On" :
+                    "ToolTip_Off").toString());
+    }
 }
 
 Certificate CertificateItemWidget::certificate()
@@ -126,6 +95,7 @@
 
 void CertificateItemWidget::currentStateChanged(bool state)
 {
-    mState = !state;
-    emit stateChanged(mState, mCertificate);
+    mButton->setToolTip(mButton->property(state ? "ToolTip_On" :
+                "ToolTip_Off").toString());
+    emit stateChanged(state, mCertificate);
 }

http://wald.intevation.org/projects/trustbridge/