comparison 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
comparison
equal deleted inserted replaced
1108:9bb9932bb819 1109:6594e8e63a25
18 QToolButton *btn) : 18 QToolButton *btn) :
19 QWidget(parent), 19 QWidget(parent),
20 mButton(btn) 20 mButton(btn)
21 { 21 {
22 mCertificate = cert; 22 mCertificate = cert;
23 mState = state; 23 mOriginalState = state;
24 /* We carry the state explicitly to be better prepared for future
25 * changes */
26 btn->setCheckable(true); 24 btn->setCheckable(true);
27 btn->setChecked(!state); 25 btn->setStyleSheet("QToolButton:Checked{"
26 "border: 1px solid #8f8f91;"
27 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
28 "stop: 0 #f6f7fa, stop: 1 #dadbde);"
29 "}"
30 );
31 setState(state);
28 setupGUI(); 32 setupGUI();
29 } 33 }
30 34
31 void CertificateItemWidget::setupGUI() 35 void CertificateItemWidget::setupGUI()
32 { 36 {
54 58
55 QHBoxLayout *layout = new QHBoxLayout; 59 QHBoxLayout *layout = new QHBoxLayout;
56 layout->addWidget(mButton); 60 layout->addWidget(mButton);
57 mButton->setFixedSize(64, 64); 61 mButton->setFixedSize(64, 64);
58 mButton->setIconSize(QSize(48, 48)); 62 mButton->setIconSize(QSize(48, 48));
59 /*
60 if (mCertificate.isInstallCert()) {
61 mComboBox->addItem(QIcon(":/img/security-high.png"), QString(), mInstallLabel);
62 mComboBox->addItem(QIcon(":/img/security-low.png"), QString(), mRemoveLabel);
63 if (mState) {
64 mComboBox->setCurrentIndex(0);
65 mComboBox->setToolTip(tr("This certificate is currently installed."));
66 }
67 else {
68 mComboBox->setCurrentIndex(1);
69 mComboBox->setToolTip(tr("This certificate is currently not installed."));
70 }
71 layout->addWidget(mComboBox);
72 }
73 else if (!mCertificate.isInstallCert() && !mEditable){
74 QImage *img = new QImage(":/img/trash-empty.png");
75 QLabel *imgLabel = new QLabel;
76 imgLabel->setPixmap(QPixmap::fromImage(*img));
77 imgLabel->setFixedSize(64, 64);
78 imgLabel->setMargin(8);
79 imgLabel->setToolTip(tr("This certificate was uninstalled."));
80 layout->addWidget(imgLabel);
81 }
82 else {
83 mComboBox->addItem(QIcon(":/img/trash-empty.png"), QString(), tr("uninstall"));
84 mComboBox->addItem(QIcon(":/img/security-medium.png"), QString(), tr("keep"));
85 mComboBox->setToolTip(tr("This certificate is currently installed."));
86 if (mState)
87 mComboBox->setCurrentIndex(0);
88 else {
89 mComboBox->setCurrentIndex(1);
90 }
91 layout->addWidget(mComboBox);
92 }
93 */
94 layout->addWidget(mLabel); 63 layout->addWidget(mLabel);
95 this->setLayout(layout); 64 this->setLayout(layout);
96 } 65 }
97 66
98 bool CertificateItemWidget::state() 67 bool CertificateItemWidget::state()
99 { 68 {
100 if (!mButton->isEnabled()) { 69 if (!mButton->isEnabled()) {
101 return true; 70 return true;
102 } 71 }
103 72
104 /* 73 return !mButton->isChecked();
105 const QString currentString = mComboBox->currentData().toString();
106
107 if (!mCertificate.isInstallCert()) {
108 return currentString == tr("uninstall");
109 }
110
111 return currentString == mInstallLabel;
112 */
113 return mState;
114 } 74 }
115 75
116 void CertificateItemWidget::setState(bool state) 76 void CertificateItemWidget::setState(bool state)
117 { 77 {
118 mState = state; 78 /* The internal state we get here is inverted for Ui reasons the logic
79 * is if a certificate is selected for installation the button
80 * is disabled (as this is the default) Only those that are
81 * unselected have the enabled button. */
82 mButton->blockSignals(true); // code did this and not the user
119 mButton->setChecked(!state); 83 mButton->setChecked(!state);
84 mButton->blockSignals(false);
85 if (mButton->isEnabled()) {
86 mButton->setToolTip(mButton->property(!state ? "ToolTip_On" :
87 "ToolTip_Off").toString());
88 }
120 } 89 }
121 90
122 Certificate CertificateItemWidget::certificate() 91 Certificate CertificateItemWidget::certificate()
123 { 92 {
124 return mCertificate; 93 return mCertificate;
125 } 94 }
126 95
127 void CertificateItemWidget::currentStateChanged(bool state) 96 void CertificateItemWidget::currentStateChanged(bool state)
128 { 97 {
129 mState = !state; 98 mButton->setToolTip(mButton->property(state ? "ToolTip_On" :
130 emit stateChanged(mState, mCertificate); 99 "ToolTip_Off").toString());
100 emit stateChanged(state, mCertificate);
131 } 101 }

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