changeset 701:31c3d2bc9880

(Issue22) Fix painting problems with fixed size in windows style. We now use fusion style also on Windows for the combobox to let it be shown in the same way as we do on GNU/Linux.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 02 Jul 2014 11:26:42 +0200
parents bf87feccb26c
children 9dea3d895f53
files ui/certificateitemwidget.cpp ui/certificateitemwidget.h
diffstat 2 files changed, 52 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ui/certificateitemwidget.cpp	Wed Jul 02 10:53:43 2014 +0200
+++ b/ui/certificateitemwidget.cpp	Wed Jul 02 11:26:42 2014 +0200
@@ -9,6 +9,7 @@
 
 #include <QHBoxLayout>
 #include <QDebug>
+#include <QStyleFactory>
 
 CertificateItemWidget::CertificateItemWidget(QWidget *parent,
                                              const Certificate &cert,
@@ -26,18 +27,32 @@
     setupGUI();
 }
 
+
+/* We use the label as data to hide it in the normal dropdown menu and only
+ * show it when the popup is shown.*/
+
 void CertificateItemWidget::setupGUI()
 {
     mLabel = new QLabel(mCertificate.subjectCN());
-    mComboBox = new QComboBox;
+    mComboBox = new IconOnlyTextPopupBox;
+    QStyle *fusionStyle = QStyleFactory::create("Fusion");
+    if (!fusionStyle) {
+        qDebug() << "Failed to create fusion style";
+    } else {
+        mComboBox->setStyle(fusionStyle);
+    }
+
     mComboBox->setFixedWidth(46);
+
+    mLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    mComboBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
     connect(mComboBox, SIGNAL(currentIndexChanged(int)),
         this, SLOT(currentStateChanged(int)));
 
     QHBoxLayout *layout = new QHBoxLayout;
     if (mCertificate.isInstallCert()) {
-        mComboBox->addItem(QIcon(":/img/security-high.png"), mInstallLabel, QVariant("true"));
-        mComboBox->addItem(QIcon(":/img/security-low.png"), mRemoveLabel, QVariant("false"));
+        mComboBox->addItem(QIcon(":/img/security-high.png"), QString(), mInstallLabel);
+        mComboBox->addItem(QIcon(":/img/security-low.png"), QString(), mRemoveLabel);
         if (mState)
             mComboBox->setCurrentIndex(0);
         else {
@@ -72,7 +87,14 @@
     if (!mEditable) {
         return true;
     }
-    return mComboBox->currentData().toBool();
+
+    const QString currentString = mComboBox->currentData().toString();
+
+    if (!mCertificate.isInstallCert()) {
+        return currentString == tr("uninstall");
+    }
+
+    return currentString == mInstallLabel;
 }
 
 void CertificateItemWidget::setState(bool state)
@@ -100,3 +122,17 @@
     bool state = mComboBox->currentData().toBool();
     emit stateChanged(state, mCertificate);
 }
+
+void IconOnlyTextPopupBox::showPopup() {
+    for (int i = 0; i < count(); i++) {
+        setItemText(i, itemData(i).toString());
+    }
+    QComboBox::showPopup();
+}
+
+void IconOnlyTextPopupBox::hidePopup() {
+    for (int i = 0; i < count(); i++) {
+        setItemText(i, QString());
+    }
+    QComboBox::hidePopup();
+}
--- a/ui/certificateitemwidget.h	Wed Jul 02 10:53:43 2014 +0200
+++ b/ui/certificateitemwidget.h	Wed Jul 02 11:26:42 2014 +0200
@@ -17,6 +17,17 @@
 #include <QComboBox>
 
 #include "certificate.h"
+/** @brief A combo box that shows the text only in the popup
+ *
+ * The text shown is the data set as Qt::UserRole
+ */
+class IconOnlyTextPopupBox : public QComboBox
+{
+protected:
+    virtual void showPopup();
+    virtual void hidePopup();
+};
+
 
 class CertificateItemWidget : public QWidget
 {
@@ -41,7 +52,7 @@
     bool mState;
     bool mEditable;
     QLabel *mLabel;
-    QComboBox *mComboBox;
+    IconOnlyTextPopupBox *mComboBox;
     QString mInstallLabel;
     QString mRemoveLabel;
 

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