Mercurial > trustbridge
diff ui/certificateitemwidget.cpp @ 1106:6f7b7d88f048
(issue115) Rework CertificateListWidgets to have a ToolButton instead of a combobox
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 15 Sep 2014 17:43:56 +0200 |
parents | 2b3526ef2d69 |
children | 9bb9932bb819 |
line wrap: on
line diff
--- a/ui/certificateitemwidget.cpp Mon Sep 15 17:43:02 2014 +0200 +++ b/ui/certificateitemwidget.cpp Mon Sep 15 17:43:56 2014 +0200 @@ -10,46 +10,27 @@ #include <QHBoxLayout> #include <QDebug> #include <QStyleFactory> +#include <QToolButton> CertificateItemWidget::CertificateItemWidget(QWidget *parent, const Certificate &cert, bool state, - bool editable, - const QString &installLabel, - const QString &removeLabel) : + QToolButton *btn) : QWidget(parent), - mInstallLabel (installLabel), - mRemoveLabel (removeLabel) + mButton(btn) { - if (mInstallLabel.isEmpty()) { - mInstallLabel = tr("Install"); - } - if (mRemoveLabel.isEmpty()) { - mRemoveLabel = tr("Remove"); - } mCertificate = cert; mState = state; - mEditable = editable; + /* We carry the state explicitly to be better prepared for future + * changes */ + btn->setCheckable(true); + btn->setChecked(!state); 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; - mComboBox = new IconOnlyTextPopupBox; - QStyle *fusionStyle = QStyleFactory::create("Fusion"); - if (!fusionStyle) { - qDebug() << "Failed to create fusion style"; - } else { - mComboBox->setStyle(fusionStyle); - } - - mComboBox->setIconSize(QSize(32, 32)); - mComboBox->setFixedWidth(64); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); @@ -67,18 +48,22 @@ mLabel->setTextInteractionFlags( Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); - mComboBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - connect(mComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(currentStateChanged(int))); + mButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + connect(mButton, SIGNAL(toggled (bool)), + this, SLOT(currentStateChanged(bool))); QHBoxLayout *layout = new QHBoxLayout; + 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.")); @@ -105,16 +90,18 @@ } layout->addWidget(mComboBox); } + */ layout->addWidget(mLabel); this->setLayout(layout); } bool CertificateItemWidget::state() { - if (!mEditable) { + if (!mButton->isEnabled()) { return true; } + /* const QString currentString = mComboBox->currentData().toString(); if (!mCertificate.isInstallCert()) { @@ -122,21 +109,14 @@ } return currentString == mInstallLabel; + */ + return mState; } void CertificateItemWidget::setState(bool state) { - disconnect(mComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(currentStateChanged(int))); - - if (state) { - mComboBox->setCurrentIndex(0); - } - else { - mComboBox->setCurrentIndex(1); - } - connect(mComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(currentStateChanged(int))); + mState = state; + mButton->setChecked(!state); } Certificate* CertificateItemWidget::certificate() @@ -144,22 +124,8 @@ return &mCertificate; } -void CertificateItemWidget::currentStateChanged(int) +void CertificateItemWidget::currentStateChanged(bool state) { - bool state = !mComboBox->currentIndex(); - emit stateChanged(state, mCertificate); + mState = !state; + emit stateChanged(mState, 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(); -}