From fc7b23b86a5d577f5f167a3ca008b6642fccb57a Mon Sep 17 00:00:00 2001 From: Sune Vuorela Date: Thu, 30 Mar 2023 22:00:28 +0200 Subject: [PATCH] Split implementation --- part/signaturepartutils.cpp | 104 ++++++++++++++++-------------------- part/signaturepartutils.h | 20 +++++++ 2 files changed, 66 insertions(+), 58 deletions(-) diff --git a/part/signaturepartutils.cpp b/part/signaturepartutils.cpp index 2f5210662..a39fcc618 100644 --- a/part/signaturepartutils.cpp +++ b/part/signaturepartutils.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -29,63 +28,6 @@ namespace SignaturePartUtils { -class KeyDelegate : public QStyledItemDelegate -{ -public: - using QStyledItemDelegate::QStyledItemDelegate; - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const final - { - auto style = option.widget ? option.widget->style() : QApplication::style(); - - QStyledItemDelegate::paint(painter, option, QModelIndex()); // paint the background but without any text on it. - - if (option.state & QStyle::State_Selected) { - painter->setPen(option.palette.color(QPalette::HighlightedText)); - } else { - painter->setPen(option.palette.color(QPalette::Text)); - } - - auto textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &option); - int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, &option, option.widget) + 1; - textRect.adjust(textMargin, 0, -textMargin, 0); - - QRect topHalf {textRect.x(), textRect.y(), textRect.width(), textRect.height() / 2}; - QRect bottomHalf {textRect.x(), textRect.y() + textRect.height() / 2, textRect.width(), textRect.height() / 2}; - - style->drawItemText(painter, topHalf, (option.displayAlignment & Qt::AlignVertical_Mask) | Qt::AlignLeft, option.palette, true, index.data(Qt::DisplayRole).toString()); - style->drawItemText(painter, bottomHalf, (option.displayAlignment & Qt::AlignVertical_Mask) | Qt::AlignRight, option.palette, true, index.data(Qt::UserRole + 1).toString()); - style->drawItemText(painter, bottomHalf, (option.displayAlignment & Qt::AlignVertical_Mask) | Qt::AlignLeft, option.palette, true, index.data(Qt::UserRole).toString()); - } - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const final - { - auto baseSize = QStyledItemDelegate::sizeHint(option, index); - baseSize.setHeight(baseSize.height() * 2); - return baseSize; - } -}; - -class SelectCertificateDialog : public QDialog -{ -public: - QComboBox *combo; - - SelectCertificateDialog(QWidget *parent) - : QDialog(parent) - { - setWindowTitle(i18n("Select certificate to sign with")); - auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); - connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); - combo = new QComboBox(); - combo->setItemDelegate(new KeyDelegate); - auto layout = new QVBoxLayout(); - layout->addWidget(new QLabel(i18n("Certificates:"))); - layout->addWidget(combo); - layout->addWidget(buttonBox); - setLayout(layout); - } -}; - std::optional getCertificateAndPasswordForSigning(PageView *pageView, Okular::Document *doc) { const Okular::CertificateStore *certStore = doc->certificateStore(); @@ -208,4 +150,50 @@ void signUnsignedSignature(const Okular::FormFieldSignature *form, PageView *pag } } +SelectCertificateDialog::SelectCertificateDialog(QWidget *parent) + : QDialog(parent) +{ + setWindowTitle(i18n("Select certificate to sign with")); + auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + combo = new QComboBox(); + combo->setItemDelegate(new KeyDelegate); + auto layout = new QVBoxLayout(); + layout->addWidget(new QLabel(i18n("Certificates:"))); + layout->addWidget(combo); + layout->addWidget(buttonBox); + setLayout(layout); +} + +QSize KeyDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + auto baseSize = QStyledItemDelegate::sizeHint(option, index); + baseSize.setHeight(baseSize.height() * 2); + return baseSize; +} + +void KeyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + auto style = option.widget ? option.widget->style() : QApplication::style(); + + QStyledItemDelegate::paint(painter, option, QModelIndex()); // paint the background but without any text on it. + + if (option.state & QStyle::State_Selected) { + painter->setPen(option.palette.color(QPalette::HighlightedText)); + } else { + painter->setPen(option.palette.color(QPalette::Text)); + } + + auto textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &option); + int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, &option, option.widget) + 1; + textRect.adjust(textMargin, 0, -textMargin, 0); + + QRect topHalf {textRect.x(), textRect.y(), textRect.width(), textRect.height() / 2}; + QRect bottomHalf {textRect.x(), textRect.y() + textRect.height() / 2, textRect.width(), textRect.height() / 2}; + + style->drawItemText(painter, topHalf, (option.displayAlignment & Qt::AlignVertical_Mask) | Qt::AlignLeft, option.palette, true, index.data(Qt::DisplayRole).toString()); + style->drawItemText(painter, bottomHalf, (option.displayAlignment & Qt::AlignVertical_Mask) | Qt::AlignRight, option.palette, true, index.data(Qt::UserRole + 1).toString()); + style->drawItemText(painter, bottomHalf, (option.displayAlignment & Qt::AlignVertical_Mask) | Qt::AlignLeft, option.palette, true, index.data(Qt::UserRole).toString()); +} } diff --git a/part/signaturepartutils.h b/part/signaturepartutils.h index be78dbf2a..5e335a1a8 100644 --- a/part/signaturepartutils.h +++ b/part/signaturepartutils.h @@ -7,12 +7,15 @@ #ifndef OKULAR_SIGNATUREPARTUTILS_H #define OKULAR_SIGNATUREPARTUTILS_H +#include +#include #include #include #include "gui/signatureguiutils.h" class PageView; +class QComboBox; namespace SignaturePartUtils { @@ -30,6 +33,23 @@ std::optional getCertificateAndPasswordForSigning(PageView * QString getFileNameForNewSignedFile(PageView *pageView, Okular::Document *doc); void signUnsignedSignature(const Okular::FormFieldSignature *form, PageView *pageView, Okular::Document *doc); +class KeyDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + using QStyledItemDelegate::QStyledItemDelegate; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const final; + QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const final; +}; + +class SelectCertificateDialog : public QDialog +{ + Q_OBJECT +public: + QComboBox *combo; + + explicit SelectCertificateDialog(QWidget *parent); +}; } #endif