From b08eff07d9cd370df286ec1c1821596794cbcc81 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Fri, 19 May 2023 12:54:48 +0300 Subject: [PATCH] Cleanup code and event is handled (#1189) IB-7615 Signed-off-by: Raul Metsma --- client/dialogs/AddRecipients.cpp | 6 +- client/widgets/AddressItem.cpp | 61 +++++----- client/widgets/AddressItem.h | 19 +--- client/widgets/AddressItem.ui | 187 +++++++++++++------------------ 4 files changed, 121 insertions(+), 152 deletions(-) diff --git a/client/dialogs/AddRecipients.cpp b/client/dialogs/AddRecipients.cpp index a9bf937e1..3e6da00fd 100644 --- a/client/dialogs/AddRecipients.cpp +++ b/client/dialogs/AddRecipients.cpp @@ -201,7 +201,7 @@ AddressItem * AddRecipients::addRecipientToLeftPane(const QSslCertificate& cert) leftList.insert(cert, leftItem); ui->leftPane->addWidget(leftItem); bool contains = rightList.contains(cert); - leftItem->disable(contains); + leftItem->setDisabled(contains); leftItem->showButton(contains ? AddressItem::Added : AddressItem::Add); connect(leftItem, &AddressItem::add, this, [this](Item *item) { @@ -258,7 +258,7 @@ bool AddRecipients::addRecipientToRightPane(const CKey &key, bool update) void AddRecipients::addRecipientToRightPane(AddressItem *leftItem, bool update) { if(addRecipientToRightPane(leftItem->getKey(), update)) { - leftItem->disable(true); + leftItem->setDisabled(true); leftItem->showButton(AddressItem::Added); } } @@ -332,7 +332,7 @@ void AddRecipients::removeRecipientFromRightPane(Item *toRemove) auto *rightItem = qobject_cast(toRemove); if(auto it = leftList.find(rightItem->getKey().cert); it != leftList.end()) { - it.value()->disable(false); + it.value()->setDisabled(false); it.value()->showButton(AddressItem::Add); } rightList.removeAll(rightItem->getKey().cert); diff --git a/client/widgets/AddressItem.cpp b/client/widgets/AddressItem.cpp index 15352eeca..a6ebccf65 100644 --- a/client/widgets/AddressItem.cpp +++ b/client/widgets/AddressItem.cpp @@ -20,6 +20,7 @@ #include "AddressItem.h" #include "ui_AddressItem.h" +#include "CryptoDoc.h" #include "DateTime.h" #include "SslCertificate.h" #include "Styles.h" @@ -27,11 +28,20 @@ using namespace ria::qdigidoc4; +class AddressItem::Private: public Ui::AddressItem +{ +public: + QString code; + CKey key; + QString label; + bool yourself = false; +}; + AddressItem::AddressItem(CKey k, QWidget *parent, bool showIcon) : Item(parent) - , ui(new Ui::AddressItem) - , key(std::move(k)) + , ui(new Private) { + ui->key = std::move(k); ui->setupUi(this); if(showIcon) ui->icon->load(QStringLiteral(":/images/icon_Krypto_small.svg")); @@ -43,21 +53,19 @@ AddressItem::AddressItem(CKey k, QWidget *parent, bool showIcon) ui->remove->setIcons(QStringLiteral("/images/icon_remove.svg"), QStringLiteral("/images/icon_remove_hover.svg"), QStringLiteral("/images/icon_remove_pressed.svg"), 17, 17); - ui->remove->init(LabelButton::White, QString(), 0); + ui->remove->init(LabelButton::White, {}, 0); connect(ui->add, &QToolButton::clicked, this, [this]{ emit add(this);}); connect(ui->remove, &LabelButton::clicked, this, [this]{ emit remove(this);}); ui->add->setFont(Styles::font(Styles::Condensed, 12)); - ui->added->setFont(Styles::font(Styles::Condensed, 12)); - - ui->add->hide(); - ui->added->hide(); - ui->added->setDisabled(true); - - code = SslCertificate(key.cert).personalCode().toHtmlEscaped(); - name = (!key.cert.subjectInfo("GN").isEmpty() && !key.cert.subjectInfo("SN").isEmpty() ? - key.cert.subjectInfo("GN").join(' ') + " " + key.cert.subjectInfo("SN").join(' ') : - key.cert.subjectInfo("CN").join(' ')).toHtmlEscaped(); + ui->added->setFont(ui->add->font()); + + ui->code = SslCertificate(ui->key.cert).personalCode().toHtmlEscaped(); + ui->label = (!ui->key.cert.subjectInfo("GN").isEmpty() && !ui->key.cert.subjectInfo("SN").isEmpty() ? + ui->key.cert.subjectInfo("GN").join(' ') + " " + ui->key.cert.subjectInfo("SN").join(' ') : + ui->key.cert.subjectInfo("CN").join(' ')).toHtmlEscaped(); + if(ui->label.isEmpty()) + ui->label = ui->key.recipient; setIdType(); showButton(AddressItem::Remove); } @@ -78,28 +86,24 @@ void AddressItem::changeEvent(QEvent* event) QWidget::changeEvent(event); } -void AddressItem::disable(bool disable) -{ - setStyleSheet(QStringLiteral("border: solid rgba(217, 217, 216, 0.45); border-width: 0px 0px 1px 0px;" - "background-color: %1; color: #000000; text-decoration: none solid rgb(0, 0, 0);") - .arg(disable ? QStringLiteral("#F0F0F0") : QStringLiteral("#FFFFFF"))); -} - bool AddressItem::eventFilter(QObject *o, QEvent *e) { if((o == ui->name || o == ui->idType) && e->type() == QEvent::MouseButtonRelease) - (new KeyDialog(key, this))->open(); + { + (new KeyDialog(ui->key, this))->open(); + return true; + } return Item::eventFilter(o, e); } const CKey& AddressItem::getKey() const { - return key; + return ui->key; } void AddressItem::idChanged(const SslCertificate &cert) { - yourself = !cert.isNull() && key.cert == cert; + ui->yourself = !cert.isNull() && ui->key.cert == cert; setName(); } @@ -119,12 +123,13 @@ QWidget* AddressItem::lastTabWidget() void AddressItem::mouseReleaseEvent(QMouseEvent * /*event*/) { - (new KeyDialog(key, this))->open(); + (new KeyDialog(ui->key, this))->open(); } void AddressItem::setName() { - ui->name->setText(QStringLiteral("%1 %2").arg(name, yourself ? code + tr(" (Yourself)") : code)); + ui->name->setText(QStringLiteral("%1 %2") + .arg(ui->label, ui->yourself ? ui->code + tr(" (Yourself)") : ui->code)); } void AddressItem::showButton(ShowToolButton show) @@ -141,8 +146,12 @@ void AddressItem::stateChange(ContainerState state) void AddressItem::setIdType() { + ui->idType->setHidden(ui->key.cert.isNull()); + if(ui->key.cert.isNull()) + return; + QString str; - SslCertificate cert(key.cert); + SslCertificate cert(ui->key.cert); SslCertificate::CertType type = cert.type(); if(type & SslCertificate::DigiIDType) str = tr("digi-ID"); diff --git a/client/widgets/AddressItem.h b/client/widgets/AddressItem.h index 92e98166f..a7792abb9 100644 --- a/client/widgets/AddressItem.h +++ b/client/widgets/AddressItem.h @@ -21,11 +21,7 @@ #include "widgets/Item.h" -#include "CryptoDoc.h" - -namespace Ui { -class AddressItem; -} +class CKey; class AddressItem final : public Item { @@ -37,13 +33,12 @@ class AddressItem final : public Item None, Remove, Add, - Added + Added, }; - explicit AddressItem(CKey k, QWidget *parent = nullptr, bool showIcon = false); + explicit AddressItem(CKey k, QWidget *parent = {}, bool showIcon = false); ~AddressItem() final; - void disable(bool disable); const CKey& getKey() const; void idChanged(const SslCertificate &cert) final; void initTabOrder(QWidget *item) final; @@ -58,10 +53,6 @@ class AddressItem final : public Item void setName(); void setIdType(); - Ui::AddressItem *ui; - - QString code; - CKey key; - QString name; - bool yourself = false; + class Private; + Private *ui; }; diff --git a/client/widgets/AddressItem.ui b/client/widgets/AddressItem.ui index 9ec68b91d..ecbe557e1 100644 --- a/client/widgets/AddressItem.ui +++ b/client/widgets/AddressItem.ui @@ -19,7 +19,6 @@ 14 - 50 false false false @@ -29,29 +28,52 @@ PointingHandCursor - border: solid rgba(217, 217, 216, 0.45); + #AddressItem { +border: solid rgba(217, 217, 216, 0.45); border-width: 0px 0px 1px 0px; -background-color: #ffffff; +background-color: #FFFFFF; color: #000000; -text-decoration: none solid rgb(0, 0, 0); +} +#AddressItem:disabled { +background-color: #F0F0F0; +} +QToolButton { +border-radius: 2px; +border: none; +color: #006EB5; +} +QToolButton:pressed { +color: #FFFFFF; +background-color: #006EB5; +} +QToolButton:hover:!pressed { +border: 1px solid #006EB5; +color: #006EB5; +} +QToolButton:disabled { +color: #727679; +} - - - 8 - + 0 - 0 + 5 0 - 2 + 7 + + + 8 + + + 0 - + @@ -70,71 +92,52 @@ text-decoration: none solid rgb(0, 0, 0); - - - - 0 + + + + + Roboto + 14 + false + false + + + + Qt::TabFocus + + + border: none; + + + MARI MAASIKAS MUSTIKAS 48405050123 (Sina ise) + + + true - - 0 + + + + + + + Roboto + 11 + false + false + - - 5 + + Qt::TabFocus - - 0 + + color: #727679;border: none; - - 5 + + ID-card - - - - - Roboto - 14 - false - false - - - - Qt::TabFocus - - - border: none; - - - MARI MAASIKAS MUSTIKAS 48405050123 (Sina ise) - - - true - - - - - - - - Roboto - 11 - false - false - - - - Qt::TabFocus - - - color: #727679;border: none; - - - ID-card - - - - + - + @@ -170,8 +173,11 @@ text-decoration: none solid rgb(0, 0, 0); - + + + false + 0 @@ -187,30 +193,12 @@ text-decoration: none solid rgb(0, 0, 0); Added - - QToolButton { - border-radius: 2px; - border: none; - color: #006EB5; -} -QToolButton:pressed { - color: #FFFFFF; - background-color: #006EB5; -} -QToolButton:hover:!pressed { - border: 1px solid #006EB5; - color: #006EB5; -} -QToolButton:disabled { - color: #727679; -} - ADDED - + @@ -230,25 +218,6 @@ QToolButton:disabled { Add - - QToolButton { - border-radius: 2px; - border: none; - color: #006EB5; -} -QToolButton:pressed { - color: #FFFFFF; - background-color: #006EB5; -} -QToolButton:hover:!pressed { - border: 1px solid #006EB5; - color: #006EB5; -} -QToolButton:disabled { - color: #727679; - background-color: #BEDBED; -} - ADD