Seamly2D
Code documentation
checkablemessagebox.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** All rights reserved. This program and the accompanying materials are made
7 ** available under the terms of the GNU Lesser General Public License (LGPL)
8 ** version 2.1 which accompanies this distribution, and is available at
9 ** http://www.gnu.org/licenses/lgpl-2.1.html
10 **
11 ** This library is distributed in the hope that it will be useful, but WITHOUT
12 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 ** for more details.
15 **
16 ****************************************************************************/
17 
18 #ifndef CHECKABLEMESSAGEBOX_H
19 #define CHECKABLEMESSAGEBOX_H
20 
21 #include <qcompilerdetection.h>
22 #include <QDialog>
23 #include <QDialogButtonBox>
24 #include <QFlags>
25 #include <QMessageBox>
26 #include <QMetaObject>
27 #include <QObject>
28 #include <QPixmap>
29 #include <QString>
30 #include <QtGlobal>
31 
32 class QSettings;
33 
34 namespace Utils
35 {
36 
38 
39 class CheckableMessageBox : public QDialog
40 {
41  Q_OBJECT
42  Q_PROPERTY(QString text READ text WRITE setText)
43  //Q_PROPERTY(QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap)
44  Q_PROPERTY(bool isChecked READ isChecked WRITE setChecked)
45  Q_PROPERTY(QString checkBoxText READ checkBoxText WRITE setCheckBoxText)
46  Q_PROPERTY(QDialogButtonBox::StandardButtons buttons READ standardButtons WRITE setStandardButtons)
47  Q_PROPERTY(QDialogButtonBox::StandardButton defaultButton READ defaultButton WRITE setDefaultButton)
48 
49 public:
50  explicit CheckableMessageBox(QWidget *parent);
51  virtual ~CheckableMessageBox() Q_DECL_OVERRIDE;
52 
53  static QDialogButtonBox::StandardButton
54  question(QWidget *parent,
55  const QString &title,
56  const QString &question,
57  const QString &checkBoxText,
58  bool *checkBoxSetting,
59  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Yes|QDialogButtonBox::No,
60  QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No);
61 
62  static QDialogButtonBox::StandardButton
63  information(QWidget *parent,
64  const QString &title,
65  const QString &text,
66  const QString &checkBoxText,
67  bool *checkBoxSetting,
68  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok,
69  QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton);
70 
71  static QDialogButtonBox::StandardButton
72  doNotAskAgainQuestion(QWidget *parent,
73  const QString &title,
74  const QString &text,
75  QSettings *settings,
76  const QString &settingsSubKey,
77  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Yes|QDialogButtonBox::No,
78  QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No,
79  QDialogButtonBox::StandardButton acceptButton = QDialogButtonBox::Yes);
80 
81  static QDialogButtonBox::StandardButton
82  doNotShowAgainInformation(QWidget *parent,
83  const QString &title,
84  const QString &text,
85  QSettings *settings,
86  const QString &settingsSubKey,
87  QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Ok,
88  QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::NoButton);
89 
90  QString text() const;
91  void setText(const QString &);
92 
93  bool isChecked() const;
94  void setChecked(bool s);
95 
96  QString checkBoxText() const;
97  void setCheckBoxText(const QString &);
98 
99  bool isCheckBoxVisible() const;
100  void setCheckBoxVisible(bool);
101 
102  QDialogButtonBox::StandardButtons standardButtons() const;
103  void setStandardButtons(QDialogButtonBox::StandardButtons s);
104  QPushButton *button(QDialogButtonBox::StandardButton b) const;
105  QPushButton *addButton(const QString &text, QDialogButtonBox::ButtonRole role);
106 
107  QDialogButtonBox::StandardButton defaultButton() const;
108  void setDefaultButton(QDialogButtonBox::StandardButton s);
109 
110  // See static QMessageBox::standardPixmap()
111  //QPixmap iconPixmap() const;
112  void setIconPixmap (const QPixmap &p);
113 
114  // Query the result
115  QAbstractButton *clickedButton() const;
116  QDialogButtonBox::StandardButton clickedStandardButton() const;
117 
118  // Conversion convenience
119  static QMessageBox::StandardButton dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton);
120  static void resetAllDoNotAskAgainQuestions(QSettings *settings);
121  static bool hasSuppressedQuestions(QSettings *settings);
122  static QString msgDoNotAskAgain();
123  static QString msgDoNotShowAgain();
124 
125 private slots:
126  void slotClicked(QAbstractButton *b);
127 
128 private:
129  Q_DISABLE_COPY(CheckableMessageBox)
132 
133  static bool askAgain(QSettings *settings, const QString &settingsSubKey);
134  static void initDoNotAskAgainMessageBox(CheckableMessageBox &messageBox, const QString &title,
135  const QString &text, QDialogButtonBox::StandardButtons buttons,
136  QDialogButtonBox::StandardButton defaultButton,
137  DoNotAskAgainType type);
138  static void doNotAskAgain(QSettings *settings, const QString &settingsSubKey);
139 };
140 
141 } // namespace Utils
142 
143 #endif // CHECKABLEMESSAGEBOX_H
The CheckableMessageBox class implements a message box suitable for questions with a "Do not ask me a...
static QDialogButtonBox::StandardButton doNotAskAgainQuestion(QWidget *parent, const QString &title, const QString &text, QSettings *settings, const QString &settingsSubKey, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Yes|QDialogButtonBox::No, QDialogButtonBox::StandardButton defaultButton=QDialogButtonBox::No, QDialogButtonBox::StandardButton acceptButton=QDialogButtonBox::Yes)
Shows a message box with given title and text, and a \gui {Do not ask again} check box.
static QMessageBox::StandardButton dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton)
static QString msgDoNotShowAgain()
Returns the standard \gui {Do not show again} check box text.
CheckableMessageBoxPrivate * d
QDialogButtonBox::StandardButtons buttons
QPushButton * button(QDialogButtonBox::StandardButton b) const
virtual ~CheckableMessageBox() Q_DECL_OVERRIDE
void setStandardButtons(QDialogButtonBox::StandardButtons s)
void slotClicked(QAbstractButton *b)
static void doNotAskAgain(QSettings *settings, const QString &settingsSubKey)
static void resetAllDoNotAskAgainQuestions(QSettings *settings)
Resets all suppression settings for doNotAskAgainQuestion() found in settings, so all these message b...
QDialogButtonBox::StandardButton clickedStandardButton() const
static QDialogButtonBox::StandardButton doNotShowAgainInformation(QWidget *parent, const QString &title, const QString &text, QSettings *settings, const QString &settingsSubKey, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton=QDialogButtonBox::NoButton)
Shows a message box with given title and text, and a \gui {Do not show again} check box.
void setCheckBoxText(const QString &)
static void initDoNotAskAgainMessageBox(CheckableMessageBox &messageBox, const QString &title, const QString &text, QDialogButtonBox::StandardButtons buttons, QDialogButtonBox::StandardButton defaultButton, DoNotAskAgainType type)
static bool hasSuppressedQuestions(QSettings *settings)
Returns whether any message boxes from doNotAskAgainQuestion() are suppressed in the settings.
static bool askAgain(QSettings *settings, const QString &settingsSubKey)
void setIconPixmap(const QPixmap &p)
static QString msgDoNotAskAgain()
Returns the standard \gui {Do not ask again} check box text.
QDialogButtonBox::StandardButtons standardButtons() const
static QDialogButtonBox::StandardButton question(QWidget *parent, const QString &title, const QString &question, const QString &checkBoxText, bool *checkBoxSetting, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Yes|QDialogButtonBox::No, QDialogButtonBox::StandardButton defaultButton=QDialogButtonBox::No)
QDialogButtonBox::StandardButton defaultButton
QPushButton * addButton(const QString &text, QDialogButtonBox::ButtonRole role)
QAbstractButton * clickedButton() const
void setDefaultButton(QDialogButtonBox::StandardButton s)
static QDialogButtonBox::StandardButton information(QWidget *parent, const QString &title, const QString &text, const QString &checkBoxText, bool *checkBoxSetting, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton=QDialogButtonBox::NoButton)