comparison ui/certificateitemwidget.cpp @ 638:9d806f140bd5 trustbridge-refactor

Added state and editable flag to certificate list items.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 24 Jun 2014 16:59:52 +0200
parents 566ee111e331
children 9c3e7754b76b
comparison
equal deleted inserted replaced
628:3a9c0f38bbad 638:9d806f140bd5
10 #include <QHBoxLayout> 10 #include <QHBoxLayout>
11 #include <QDebug> 11 #include <QDebug>
12 12
13 CertificateItemWidget::CertificateItemWidget( 13 CertificateItemWidget::CertificateItemWidget(
14 QWidget *parent, 14 QWidget *parent,
15 const Certificate &cert) : QWidget(parent) 15 const Certificate &cert,
16 bool state,
17 bool editable) : QWidget(parent)
16 { 18 {
17 mCertificate = cert; 19 mCertificate = cert;
20 mState = state;
21 mEditable = editable;
18 setupGUI(); 22 setupGUI();
19 } 23 }
20 24
21 void CertificateItemWidget::setupGUI() 25 void CertificateItemWidget::setupGUI()
22 { 26 {
24 mComboBox = new QComboBox; 28 mComboBox = new QComboBox;
25 mComboBox->setFixedWidth(46); 29 mComboBox->setFixedWidth(46);
26 connect(mComboBox, SIGNAL(currentIndexChanged(int)), 30 connect(mComboBox, SIGNAL(currentIndexChanged(int)),
27 this, SLOT(currentStateChanged(int))); 31 this, SLOT(currentStateChanged(int)));
28 32
33 QHBoxLayout *layout = new QHBoxLayout;
29 if (mCertificate.isInstallCert()) { 34 if (mCertificate.isInstallCert()) {
30 mComboBox->addItem(QIcon(":/img/list-add.png"), tr("add"), QVariant("true")); 35 mComboBox->addItem(QIcon(":/img/list-add.png"), tr("add"), QVariant("true"));
31 mComboBox->addItem(QIcon(":/img/list-remove.png"), 36 mComboBox->addItem(QIcon(":/img/list-remove.png"),
32 tr("remove"), QVariant("false")); 37 tr("remove"), QVariant("false"));
38 if (mState)
39 mComboBox->setCurrentIndex(0);
40 else {
41 mComboBox->setCurrentIndex(1);
42 }
43 layout->addWidget(mComboBox);
44 }
45 else if (!mCertificate.isInstallCert() && !mEditable){
46 QImage *img = new QImage(":/img/list-remove.png");
47 QLabel *imgLabel = new QLabel;
48 imgLabel->setPixmap(QPixmap::fromImage(*img));
49 imgLabel->setFixedSize(25, 25);
50 imgLabel->setMargin(5);
51 layout->addWidget(imgLabel);
33 } 52 }
34 else { 53 else {
35 mComboBox->addItem(QIcon(":/img/list-add.png"), tr("add"), QVariant("true")); 54 mComboBox->addItem(QIcon(":/img/list-add.png"), tr("add"), QVariant("true"));
36 mComboBox->addItem(QIcon(":/img/list-remove.png"), 55 mComboBox->addItem(QIcon(":/img/list-remove.png"),
37 tr("remove"), QVariant("false")); 56 tr("remove"), QVariant("false"));
57 if (mState)
58 mComboBox->setCurrentIndex(0);
59 else {
60 mComboBox->setCurrentIndex(1);
61 }
62 layout->addWidget(mComboBox);
38 } 63 }
39 QHBoxLayout *layout = new QHBoxLayout;
40 layout->addWidget(mComboBox);
41 layout->addWidget(mLabel); 64 layout->addWidget(mLabel);
42 this->setLayout(layout); 65 this->setLayout(layout);
43 } 66 }
44 67
45 bool CertificateItemWidget::state() 68 bool CertificateItemWidget::state()
46 { 69 {
47 return mComboBox->currentData().toBool(); 70 return mComboBox->currentData().toBool();
71 }
72
73 void CertificateItemWidget::setState(bool state)
74 {
75 disconnect(mComboBox, SIGNAL(currentIndexChanged(int)),
76 this, SLOT(currentStateChanged(int)));
77
78 if (state) {
79 mComboBox->setCurrentIndex(0);
80 }
81 else {
82 mComboBox->setCurrentIndex(1);
83 }
84 connect(mComboBox, SIGNAL(currentIndexChanged(int)),
85 this, SLOT(currentStateChanged(int)));
48 } 86 }
49 87
50 Certificate CertificateItemWidget::certificate() 88 Certificate CertificateItemWidget::certificate()
51 { 89 {
52 return mCertificate; 90 return mCertificate;

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