forked from qt-creator/qt-creator
Fix usage of deprecated API QMessageBox::standardIcon
Instead use the style to get the icon and get the pixmap from there. Emulates what QMessageBox::setIcon(QMessageBox::Icon) does. Change-Id: Ic20d55070d510773eb194dc695689954b4862a2f Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
#include <QStyle>
|
||||
|
||||
/*!
|
||||
\class Utils::CheckableMessageBox
|
||||
@@ -107,6 +108,7 @@ public:
|
||||
QCheckBox *checkBox = nullptr;
|
||||
QDialogButtonBox *buttonBox = nullptr;
|
||||
QAbstractButton *clickedButton = nullptr;
|
||||
QMessageBox::Icon icon = QMessageBox::NoIcon;
|
||||
};
|
||||
|
||||
CheckableMessageBox::CheckableMessageBox(QWidget *parent) :
|
||||
@@ -148,17 +150,53 @@ void CheckableMessageBox::setText(const QString &t)
|
||||
d->messageLabel->setText(t);
|
||||
}
|
||||
|
||||
QPixmap CheckableMessageBox::iconPixmap() const
|
||||
QMessageBox::Icon CheckableMessageBox::icon() const
|
||||
{
|
||||
if (const QPixmap *p = d->pixmapLabel->pixmap())
|
||||
return QPixmap(*p);
|
||||
return d->icon;
|
||||
}
|
||||
|
||||
// See QMessageBoxPrivate::standardIcon
|
||||
static QPixmap pixmapForIcon(QMessageBox::Icon icon, QWidget *w)
|
||||
{
|
||||
const QStyle *style = w ? w->style() : QApplication::style();
|
||||
const int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, nullptr, w);
|
||||
QIcon tmpIcon;
|
||||
switch (icon) {
|
||||
case QMessageBox::Information:
|
||||
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, nullptr, w);
|
||||
break;
|
||||
case QMessageBox::Warning:
|
||||
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, nullptr, w);
|
||||
break;
|
||||
case QMessageBox::Critical:
|
||||
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, nullptr, w);
|
||||
break;
|
||||
case QMessageBox::Question:
|
||||
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, nullptr, w);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!tmpIcon.isNull()) {
|
||||
QWindow *window = nullptr;
|
||||
if (w) {
|
||||
window = w->windowHandle();
|
||||
if (!window) {
|
||||
if (const QWidget *nativeParent = w->nativeParentWidget())
|
||||
window = nativeParent->windowHandle();
|
||||
}
|
||||
}
|
||||
return tmpIcon.pixmap(window, QSize(iconSize, iconSize));
|
||||
}
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
void CheckableMessageBox::setIconPixmap(const QPixmap &p)
|
||||
void CheckableMessageBox::setIcon(QMessageBox::Icon icon)
|
||||
{
|
||||
d->pixmapLabel->setPixmap(p);
|
||||
d->pixmapLabel->setVisible(!p.isNull());
|
||||
d->icon = icon;
|
||||
const QPixmap pixmap = pixmapForIcon(icon, this);
|
||||
d->pixmapLabel->setPixmap(pixmap);
|
||||
d->pixmapLabel->setVisible(!pixmap.isNull());
|
||||
}
|
||||
|
||||
bool CheckableMessageBox::isChecked() const
|
||||
@@ -239,7 +277,7 @@ CheckableMessageBox::question(QWidget *parent,
|
||||
{
|
||||
CheckableMessageBox mb(parent);
|
||||
mb.setWindowTitle(title);
|
||||
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
|
||||
mb.setIcon(QMessageBox::Question);
|
||||
mb.setText(question);
|
||||
mb.setCheckBoxText(checkBoxText);
|
||||
mb.setChecked(*checkBoxSetting);
|
||||
@@ -261,7 +299,7 @@ CheckableMessageBox::information(QWidget *parent,
|
||||
{
|
||||
CheckableMessageBox mb(parent);
|
||||
mb.setWindowTitle(title);
|
||||
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Information));
|
||||
mb.setIcon(QMessageBox::Information);
|
||||
mb.setText(text);
|
||||
mb.setCheckBoxText(checkBoxText);
|
||||
mb.setChecked(*checkBoxSetting);
|
||||
@@ -297,9 +335,7 @@ void initDoNotAskAgainMessageBox(CheckableMessageBox &messageBox, const QString
|
||||
DoNotAskAgainType type)
|
||||
{
|
||||
messageBox.setWindowTitle(title);
|
||||
messageBox.setIconPixmap(QMessageBox::standardIcon(type == Information
|
||||
? QMessageBox::Information
|
||||
: QMessageBox::Question));
|
||||
messageBox.setIcon(type == Information ? QMessageBox::Information : QMessageBox::Question);
|
||||
messageBox.setText(text);
|
||||
messageBox.setCheckBoxVisible(true);
|
||||
messageBox.setCheckBoxText(type == Information ? CheckableMessageBox::msgDoNotShowAgain()
|
||||
|
||||
@@ -42,7 +42,7 @@ class QTCREATOR_UTILS_EXPORT CheckableMessageBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap)
|
||||
Q_PROPERTY(QMessageBox::Icon icon READ icon WRITE setIcon)
|
||||
Q_PROPERTY(bool isChecked READ isChecked WRITE setChecked)
|
||||
Q_PROPERTY(QString checkBoxText READ checkBoxText WRITE setCheckBoxText)
|
||||
Q_PROPERTY(QDialogButtonBox::StandardButtons buttons READ standardButtons WRITE setStandardButtons)
|
||||
@@ -109,9 +109,8 @@ public:
|
||||
QDialogButtonBox::StandardButton defaultButton() const;
|
||||
void setDefaultButton(QDialogButtonBox::StandardButton s);
|
||||
|
||||
// See static QMessageBox::standardPixmap()
|
||||
QPixmap iconPixmap() const;
|
||||
void setIconPixmap (const QPixmap &p);
|
||||
QMessageBox::Icon icon() const;
|
||||
void setIcon(QMessageBox::Icon icon);
|
||||
|
||||
// Query the result
|
||||
QAbstractButton *clickedButton() const;
|
||||
|
||||
@@ -537,7 +537,7 @@ bool EditorManagerPrivate::skipOpeningBigTextFile(const QString &filePath)
|
||||
messageBox.setText(text);
|
||||
messageBox.setStandardButtons(QDialogButtonBox::Yes|QDialogButtonBox::No);
|
||||
messageBox.setDefaultButton(QDialogButtonBox::No);
|
||||
messageBox.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
|
||||
messageBox.setIcon(QMessageBox::Question);
|
||||
messageBox.setCheckBoxVisible(true);
|
||||
messageBox.setCheckBoxText(CheckableMessageBox::msgDoNotAskAgain());
|
||||
messageBox.exec();
|
||||
|
||||
@@ -569,7 +569,7 @@ VcsBaseSubmitEditor::PromptSubmitResult
|
||||
const QString commitName = plugin->commitDisplayName();
|
||||
mb.setWindowTitle(tr("Close %1 %2 Editor")
|
||||
.arg(plugin->versionControl()->displayName(), commitName));
|
||||
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
|
||||
mb.setIcon(QMessageBox::Question);
|
||||
QString message;
|
||||
if (canCommit) {
|
||||
message = tr("What do you want to do with these changes?");
|
||||
|
||||
Reference in New Issue
Block a user