Skip to content

Commit

Permalink
feat: allowed set a expected icon size for DDialog::setIcon
Browse files Browse the repository at this point in the history
linuxdeepin/internal-discussion#495

Change-Id: Ie781218474e86686f54b2149d86cb1eb669cf20d
  • Loading branch information
BLumia committed Dec 13, 2018
1 parent 56ff4ef commit a4d2aa0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/widgets/ddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,9 @@ void DDialog::setMessage(const QString &message)

/*!
* \~chinese \brief 设置对话框图标
*
* \~chinese 注意:该接口将会在未来版本中废弃,
* 请使用 setIcon(const QIcon &icon, const QSize &expectedSize) 这个重载。
*/
void DDialog::setIcon(const QIcon &icon)
{
Expand All @@ -910,6 +913,26 @@ void DDialog::setIcon(const QIcon &icon)
}
}

/*!
* \~chinese \brief 设置对话框图标
*
* \~chinese 为对话框设置图标,同时可以指定一个期望的图标大小。
*/
void DDialog::setIcon(const QIcon &icon, const QSize &expectedSize)
{
D_D(DDialog);

d->icon = icon;

if (icon.isNull()) {
return;
}

QSize actualSize = expectedSize.isValid() ? expectedSize : QSize(64, 64);
QPixmap pixmap = icon.pixmap(actualSize);
setIconPixmap(pixmap);
}

/*!
* \~chinese \brief 设置对话框位图图标
*/
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/ddialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public Q_SLOTS:
void setButtonIcon(int index, const QIcon &icon);
void setTitle(const QString &title);
void setMessage(const QString& message);
void setIcon(const QIcon &icon);
void setIcon(const QIcon &icon) Q_DECL_DEPRECATED;
void setIcon(const QIcon &icon, const QSize &expectedSize);
void setIconPixmap(const QPixmap &iconPixmap);
void setTextFormat(Qt::TextFormat textFormat);
void setOnButtonClickedClose(bool onButtonClickedClose);
Expand Down

0 comments on commit a4d2aa0

Please sign in to comment.