diff --git a/src/knewpassworddialog.h b/src/knewpassworddialog.h --- a/src/knewpassworddialog.h +++ b/src/knewpassworddialog.h @@ -94,16 +94,31 @@ QString prompt() const; /** - * Sets the pixmap that appears next to the prompt in the dialog. The default pixmap represent a simple key. + * Sets the icon that appears next to the prompt in the dialog. The default icon represents a simple key. + * @since 5.63 + */ + void setIcon(const QIcon &icon); + + /** + * Returns the icon that appears next to the prompt in the dialog. The default icon represents a simple key. + * @since 5.63 + */ + QIcon icon() const; + + /** + * Sets the pixmap that appears next to the prompt in the dialog. The default pixmap represents a simple key. * * the recommended size is KIconLoader::SizeHuge + * + * @deprecated since 5.63 use setIcon() */ - void setPixmap(const QPixmap &); + KWIDGETSADDONS_DEPRECATED void setPixmap(const QPixmap &); /** * Returns the pixmap that appears next to the prompt in the dialog + * @deprecated since 5.63 use setIcon() */ - QPixmap pixmap() const; + KWIDGETSADDONS_DEPRECATED QPixmap pixmap() const; /** * Allow empty passwords? - Default: true diff --git a/src/knewpassworddialog.cpp b/src/knewpassworddialog.cpp --- a/src/knewpassworddialog.cpp +++ b/src/knewpassworddialog.cpp @@ -44,18 +44,16 @@ KNewPasswordDialog *q; QString pass; + QIcon icon; Ui::KNewPasswordDialog ui; }; void KNewPasswordDialog::KNewPasswordDialogPrivate::init() { ui.setupUi(q); + q->setIcon(QIcon::fromTheme(QStringLiteral("dialog-password"))); - QStyleOption option; - option.initFrom(q); - const int iconSize = q->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, q); - ui.labelIcon->setPixmap(QIcon::fromTheme(QStringLiteral("dialog-password")).pixmap(iconSize, iconSize)); ui.statusMsgWidget->hide(); connect(ui.pwdWidget, SIGNAL(passwordStatusChanged()), q, SLOT(_k_passwordStatusChanged())); @@ -119,6 +117,21 @@ return d->ui.labelPrompt->text(); } +void KNewPasswordDialog::setIcon(const QIcon &icon) +{ + d->icon = icon; + QStyleOption option; + option.initFrom(this); + const int iconSize = style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, this); + d->ui.labelIcon->setPixmap(icon.pixmap(iconSize, iconSize)); + d->ui.labelIcon->setFixedSize(d->ui.labelIcon->sizeHint()); +} + +QIcon KNewPasswordDialog::icon() const +{ + return d->icon; +} + void KNewPasswordDialog::setPixmap(const QPixmap &pixmap) { d->ui.labelIcon->setPixmap(pixmap); diff --git a/src/kpassworddialog.h b/src/kpassworddialog.h --- a/src/kpassworddialog.h +++ b/src/kpassworddialog.h @@ -147,14 +147,26 @@ */ QString prompt() const; + /** + * Set the icon that appears next to the prompt. + * @since 5.63 + */ + void setIcon(const QIcon &icon); + + /** + * Returns the icon that appears next to the prompt. + */ + QIcon icon() const; + /** * set an image that appears next to the prompt. + * @deprecated since 5.63 use setIcon() */ - void setPixmap(const QPixmap &); + KWIDGETSADDONS_DEPRECATED void setPixmap(const QPixmap &); /** - * + * @deprecated since 5.63 use icon() */ - QPixmap pixmap() const; + KWIDGETSADDONS_DEPRECATED QPixmap pixmap() const; /** * Adds a comment line to the dialog. diff --git a/src/kpassworddialog.cpp b/src/kpassworddialog.cpp --- a/src/kpassworddialog.cpp +++ b/src/kpassworddialog.cpp @@ -38,7 +38,6 @@ KPasswordDialogPrivate(KPasswordDialog *q) : q(q), userEditCombo(nullptr), - pixmapLabel(nullptr), commentRow(0) {} @@ -52,7 +51,7 @@ Ui_KPasswordDialog ui; QMap knownLogins; QComboBox *userEditCombo; - QLabel *pixmapLabel; + QIcon icon; KPasswordDialogFlags m_flags; unsigned int commentRow; }; @@ -123,30 +122,32 @@ QRect desktop = QApplication::desktop()->screenGeometry(q->topLevelWidget()); q->setMinimumWidth(qMin(1000, qMax(q->sizeHint().width(), desktop.width() / 4))); + q->setIcon(QIcon::fromTheme(QStringLiteral("dialog-password"))); +} + +void KPasswordDialog::setIcon(const QIcon &icon) +{ + d->icon = icon; + QStyleOption option; - option.initFrom(q); - const int iconSize = q->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, q); - q->setPixmap(QIcon::fromTheme(QStringLiteral("dialog-password")).pixmap(iconSize)); + option.initFrom(this); + const int iconSize = style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, this); + d->ui.pixmapLabel->setPixmap(icon.pixmap(iconSize)); } -void KPasswordDialog::setPixmap(const QPixmap &pixmap) +QIcon KPasswordDialog::icon() const { - if (!d->pixmapLabel) { - d->pixmapLabel = new QLabel(this); - d->pixmapLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop); - d->ui.hboxLayout->insertWidget(0, d->pixmapLabel); - } + return d->icon; +} - d->pixmapLabel->setPixmap(pixmap); +void KPasswordDialog::setPixmap(const QPixmap &pixmap) +{ + d->ui.pixmapLabel->setPixmap(pixmap); } QPixmap KPasswordDialog::pixmap() const { - if (!d->pixmapLabel) { - return QPixmap(); - } - - return *d->pixmapLabel->pixmap(); + return *d->ui.pixmapLabel->pixmap(); } void KPasswordDialog::setUsername(const QString &user) diff --git a/src/kpassworddialog.ui b/src/kpassworddialog.ui --- a/src/kpassworddialog.ui +++ b/src/kpassworddialog.ui @@ -14,6 +14,13 @@ + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + +