Mercurial > trustbridge
comparison ui/certificateitemwidget.cpp @ 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 | 973a7ce19658 |
children | 86c9ff4cfb02 |
comparison
equal
deleted
inserted
replaced
700:bf87feccb26c | 701:31c3d2bc9880 |
---|---|
7 */ | 7 */ |
8 #include "certificateitemwidget.h" | 8 #include "certificateitemwidget.h" |
9 | 9 |
10 #include <QHBoxLayout> | 10 #include <QHBoxLayout> |
11 #include <QDebug> | 11 #include <QDebug> |
12 #include <QStyleFactory> | |
12 | 13 |
13 CertificateItemWidget::CertificateItemWidget(QWidget *parent, | 14 CertificateItemWidget::CertificateItemWidget(QWidget *parent, |
14 const Certificate &cert, | 15 const Certificate &cert, |
15 bool state, | 16 bool state, |
16 bool editable, | 17 bool editable, |
24 mState = state; | 25 mState = state; |
25 mEditable = editable; | 26 mEditable = editable; |
26 setupGUI(); | 27 setupGUI(); |
27 } | 28 } |
28 | 29 |
30 | |
31 /* We use the label as data to hide it in the normal dropdown menu and only | |
32 * show it when the popup is shown.*/ | |
33 | |
29 void CertificateItemWidget::setupGUI() | 34 void CertificateItemWidget::setupGUI() |
30 { | 35 { |
31 mLabel = new QLabel(mCertificate.subjectCN()); | 36 mLabel = new QLabel(mCertificate.subjectCN()); |
32 mComboBox = new QComboBox; | 37 mComboBox = new IconOnlyTextPopupBox; |
38 QStyle *fusionStyle = QStyleFactory::create("Fusion"); | |
39 if (!fusionStyle) { | |
40 qDebug() << "Failed to create fusion style"; | |
41 } else { | |
42 mComboBox->setStyle(fusionStyle); | |
43 } | |
44 | |
33 mComboBox->setFixedWidth(46); | 45 mComboBox->setFixedWidth(46); |
46 | |
47 mLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
48 mComboBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); | |
34 connect(mComboBox, SIGNAL(currentIndexChanged(int)), | 49 connect(mComboBox, SIGNAL(currentIndexChanged(int)), |
35 this, SLOT(currentStateChanged(int))); | 50 this, SLOT(currentStateChanged(int))); |
36 | 51 |
37 QHBoxLayout *layout = new QHBoxLayout; | 52 QHBoxLayout *layout = new QHBoxLayout; |
38 if (mCertificate.isInstallCert()) { | 53 if (mCertificate.isInstallCert()) { |
39 mComboBox->addItem(QIcon(":/img/security-high.png"), mInstallLabel, QVariant("true")); | 54 mComboBox->addItem(QIcon(":/img/security-high.png"), QString(), mInstallLabel); |
40 mComboBox->addItem(QIcon(":/img/security-low.png"), mRemoveLabel, QVariant("false")); | 55 mComboBox->addItem(QIcon(":/img/security-low.png"), QString(), mRemoveLabel); |
41 if (mState) | 56 if (mState) |
42 mComboBox->setCurrentIndex(0); | 57 mComboBox->setCurrentIndex(0); |
43 else { | 58 else { |
44 mComboBox->setCurrentIndex(1); | 59 mComboBox->setCurrentIndex(1); |
45 } | 60 } |
70 bool CertificateItemWidget::state() | 85 bool CertificateItemWidget::state() |
71 { | 86 { |
72 if (!mEditable) { | 87 if (!mEditable) { |
73 return true; | 88 return true; |
74 } | 89 } |
75 return mComboBox->currentData().toBool(); | 90 |
91 const QString currentString = mComboBox->currentData().toString(); | |
92 | |
93 if (!mCertificate.isInstallCert()) { | |
94 return currentString == tr("uninstall"); | |
95 } | |
96 | |
97 return currentString == mInstallLabel; | |
76 } | 98 } |
77 | 99 |
78 void CertificateItemWidget::setState(bool state) | 100 void CertificateItemWidget::setState(bool state) |
79 { | 101 { |
80 disconnect(mComboBox, SIGNAL(currentIndexChanged(int)), | 102 disconnect(mComboBox, SIGNAL(currentIndexChanged(int)), |
98 void CertificateItemWidget::currentStateChanged(int) | 120 void CertificateItemWidget::currentStateChanged(int) |
99 { | 121 { |
100 bool state = mComboBox->currentData().toBool(); | 122 bool state = mComboBox->currentData().toBool(); |
101 emit stateChanged(state, mCertificate); | 123 emit stateChanged(state, mCertificate); |
102 } | 124 } |
125 | |
126 void IconOnlyTextPopupBox::showPopup() { | |
127 for (int i = 0; i < count(); i++) { | |
128 setItemText(i, itemData(i).toString()); | |
129 } | |
130 QComboBox::showPopup(); | |
131 } | |
132 | |
133 void IconOnlyTextPopupBox::hidePopup() { | |
134 for (int i = 0; i < count(); i++) { | |
135 setItemText(i, QString()); | |
136 } | |
137 QComboBox::hidePopup(); | |
138 } |