Debian Codegraph @

src/Gui/Dialogs/DlgCheckableMessageBox.h

raw
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation ([email protected])
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #ifndef CHECKABLEMESSAGEBOX_H
31 #define CHECKABLEMESSAGEBOX_H
32
33 #include <QDialog>
34 #include <QDialogButtonBox>
35 #include <QMessageBox>
36 #include <FCGlobal.h>
37
38 namespace Gui
39 {
40 namespace Dialog
41 {
42
43 struct DlgCheckableMessageBoxPrivate;
44
45 /* A messagebox suitable for questions with a
46 * "Do not ask me again" checkbox. Emulates the QMessageBox API with
47 * static conveniences. */
48
49 class GuiExport DlgCheckableMessageBox: public QDialog
50 {
51 Q_OBJECT
52 Q_PROPERTY(QString text READ text WRITE setText) // clazy:exclude=qproperty-without-notify
53 Q_PROPERTY(
54 QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap
55 ) // clazy:exclude=qproperty-without-notify
56 Q_PROPERTY(bool isChecked READ isChecked WRITE setChecked) // clazy:exclude=qproperty-without-notify
57 // Q_PROPERTY(QString prefEntry WRITE setPrefEntry) // Must have a READ accessor!
58 Q_PROPERTY(
59 QString checkBoxText READ checkBoxText WRITE setCheckBoxText
60 ) // clazy:exclude=qproperty-without-notify
61 Q_PROPERTY(
62 QDialogButtonBox::StandardButtons buttons READ standardButtons WRITE setStandardButtons
63 ) // clazy:exclude=qproperty-without-notify
64 Q_PROPERTY(
65 QDialogButtonBox::StandardButton defaultButton READ defaultButton WRITE setDefaultButton
66 ) // clazy:exclude=qproperty-without-notify
67 public:
68 explicit DlgCheckableMessageBox(QWidget* parent);
69 ~DlgCheckableMessageBox() override;
70
71 static QDialogButtonBox::StandardButton question(
72 QWidget* parent,
73 const QString& title,
74 const QString& question,
75 const QString& checkBoxText,
76 bool* checkBoxSetting,
77 QDialogButtonBox::StandardButtons buttons = QDialogButtonBox::Yes | QDialogButtonBox::No,
78 QDialogButtonBox::StandardButton defaultButton = QDialogButtonBox::No
79 );
80
81 QString text() const;
82 void setText(const QString&);
83
84 void setPrefEntry(const QString& entry);
85
86 void setPrefPath(const QString& path);
87
88 void accept() override;
89 void reject() override;
90
91 bool isChecked() const;
92 void setChecked(bool s);
93
94 QString checkBoxText() const;
95 void setCheckBoxText(const QString&);
96
97 QDialogButtonBox::StandardButtons standardButtons() const;
98 void setStandardButtons(QDialogButtonBox::StandardButtons s);
99
100 QDialogButtonBox::StandardButton defaultButton() const;
101 void setDefaultButton(QDialogButtonBox::StandardButton s);
102
103 // see static QMessageBox::standardPixmap()
104 QPixmap iconPixmap() const;
105 void setIconPixmap(const QPixmap& p);
106
107 // Query the result
108 QAbstractButton* clickedButton() const;
109 QDialogButtonBox::StandardButton clickedStandardButton() const;
110
111 // Conversion convenience
112 static QMessageBox::StandardButton dialogButtonBoxToMessageBoxButton(
113 QDialogButtonBox::StandardButton
114 );
115
116 /// convenient show method
117 /// It shows a dialog with header and message provided and a checkbox in check state with the
118 /// message provided. It uses a parameter in path "User parameter:BaseApp/CheckMessages" derived
119 /// from the header test, defaulting to false, to store the status of the checkbox, when the
120 /// user exits the modal dialog.
121 static void showMessage(
122 const QString& header,
123 const QString& message,
124 bool check = false,
125 const QString& checkText = tr("Don't show me again")
126 );
127
128 /// Same as showMessage above, but it checks the specific preference path and parameter
129 /// provided, defaulting to entryDefault value if the parameter is not present.
130 static void showMessage(
131 const QString& header,
132 const QString& message,
133 const QString& prefPath,
134 const QString& paramEntry,
135 bool entryDefault = false,
136 bool check = false,
137 const QString& checkText = QStringLiteral("Don't show me again")
138 );
139
140 private Q_SLOTS:
141 void slotClicked(QAbstractButton* b);
142
143 private:
144 DlgCheckableMessageBoxPrivate* m_d;
145 QByteArray paramEntry;
146 QString prefPath;
147 };
148
149 } // namespace Dialog
150 } // namespace Gui
151
152 #endif // CHECKABLEMESSAGEBOX_H