1 | /* $Id: QIMessageBox.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QIMessageBox class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_extensions_QIMessageBox_h
|
---|
29 | #define FEQT_INCLUDED_SRC_extensions_QIMessageBox_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QMessageBox>
|
---|
36 |
|
---|
37 | /* GUI includes: */
|
---|
38 | #include "QIDialog.h"
|
---|
39 | #include "UILibraryDefs.h"
|
---|
40 |
|
---|
41 | /* Forward declarations: */
|
---|
42 | class QCheckBox;
|
---|
43 | class QLabel;
|
---|
44 | class QPushButton;
|
---|
45 | class QIArrowSplitter;
|
---|
46 | class QIDialogButtonBox;
|
---|
47 | class QIRichTextLabel;
|
---|
48 |
|
---|
49 |
|
---|
50 | /** Button types. */
|
---|
51 | enum AlertButton
|
---|
52 | {
|
---|
53 | AlertButton_NoButton = 0x0, /* 00000000 00000000 */
|
---|
54 | AlertButton_Ok = 0x1, /* 00000000 00000001 */
|
---|
55 | AlertButton_Cancel = 0x2, /* 00000000 00000010 */
|
---|
56 | AlertButton_Choice1 = 0x4, /* 00000000 00000100 */
|
---|
57 | AlertButton_Choice2 = 0x8, /* 00000000 00001000 */
|
---|
58 | AlertButton_Copy = 0x10, /* 00000000 00010000 */
|
---|
59 | AlertButton_Help = 0x11, /* 00000000 00010001 */
|
---|
60 | AlertButtonMask = 0xFF /* 00000000 11111111 */
|
---|
61 | };
|
---|
62 |
|
---|
63 |
|
---|
64 | /** Button options. */
|
---|
65 | enum AlertButtonOption
|
---|
66 | {
|
---|
67 | AlertButtonOption_Default = 0x100, /* 00000001 00000000 */
|
---|
68 | AlertButtonOption_Escape = 0x200, /* 00000010 00000000 */
|
---|
69 | AlertButtonOptionMask = 0x300 /* 00000011 00000000 */
|
---|
70 | };
|
---|
71 |
|
---|
72 |
|
---|
73 | /** Alert options. */
|
---|
74 | enum AlertOption
|
---|
75 | {
|
---|
76 | AlertOption_AutoConfirmed = 0x400, /* 00000100 00000000 */
|
---|
77 | AlertOption_CheckBox = 0x800, /* 00001000 00000000 */
|
---|
78 | AlertOptionMask = 0xFC00 /* 11111100 00000000 */
|
---|
79 | };
|
---|
80 |
|
---|
81 |
|
---|
82 | /** Icon types. */
|
---|
83 | enum AlertIconType
|
---|
84 | {
|
---|
85 | AlertIconType_NoIcon = QMessageBox::NoIcon,
|
---|
86 | AlertIconType_Information = QMessageBox::Information,
|
---|
87 | AlertIconType_Warning = QMessageBox::Warning,
|
---|
88 | AlertIconType_Critical = QMessageBox::Critical,
|
---|
89 | AlertIconType_Question = QMessageBox::Question,
|
---|
90 | AlertIconType_GuruMeditation
|
---|
91 | };
|
---|
92 |
|
---|
93 |
|
---|
94 | /** QIDialog extension representing GUI alerts. */
|
---|
95 | class SHARED_LIBRARY_STUFF QIMessageBox : public QIDialog
|
---|
96 | {
|
---|
97 | Q_OBJECT;
|
---|
98 |
|
---|
99 | public:
|
---|
100 |
|
---|
101 | /** Constructs message-box passing @a pParent to the base-class.
|
---|
102 | * @param strTitle Brings the title.
|
---|
103 | * @param strMessage Brings the message.
|
---|
104 | * @param strMessage Brings the help keyword for context sensitive help
|
---|
105 | * @param iconType Brings the icon-type.
|
---|
106 | * @param iButton1 Brings the integer-code for the 1st button.
|
---|
107 | * @param iButton2 Brings the integer-code for the 2nd button.
|
---|
108 | * @param iButton3 Brings the integer-code for the 3rd button. */
|
---|
109 | QIMessageBox(const QString &strTitle, const QString &strMessage, AlertIconType iconType,
|
---|
110 | int iButton1 = 0, int iButton2 = 0, int iButton3 = 0, QWidget *pParent = 0,
|
---|
111 | const QString &strHelpKeyword = QString());
|
---|
112 |
|
---|
113 | /** Defines details-text. */
|
---|
114 | void setDetailsText(const QString &strText);
|
---|
115 |
|
---|
116 | /** Returns whether flag is checked. */
|
---|
117 | bool flagChecked() const;
|
---|
118 | /** Defines whether flag is @a fChecked. */
|
---|
119 | void setFlagChecked(bool fChecked);
|
---|
120 | /** Defines @a strFlagText. */
|
---|
121 | void setFlagText(const QString &strFlagText);
|
---|
122 |
|
---|
123 | /** Defines @a iButton @a strText. */
|
---|
124 | void setButtonText(int iButton, const QString &strText);
|
---|
125 |
|
---|
126 | protected:
|
---|
127 |
|
---|
128 | /** Handles polish @a pEvent. */
|
---|
129 | virtual void polishEvent(QShowEvent *pEvent) RT_OVERRIDE;
|
---|
130 |
|
---|
131 | /** Handles close @a pEvent. */
|
---|
132 | virtual void closeEvent(QCloseEvent *pEvent) RT_OVERRIDE;
|
---|
133 |
|
---|
134 | private slots:
|
---|
135 |
|
---|
136 | /** Updates dialog size: */
|
---|
137 | void sltUpdateSize();
|
---|
138 |
|
---|
139 | /** Copy details-text. */
|
---|
140 | void sltCopy() const;
|
---|
141 |
|
---|
142 | /** Closes dialog like user would press the Cancel button. */
|
---|
143 | virtual void reject() RT_OVERRIDE;
|
---|
144 |
|
---|
145 | /** Closes dialog like user would press the 1st button. */
|
---|
146 | void sltDone1() { m_fDone = true; done(m_iButton1 & AlertButtonMask); }
|
---|
147 | /** Closes dialog like user would press the 2nd button. */
|
---|
148 | void sltDone2() { m_fDone = true; done(m_iButton2 & AlertButtonMask); }
|
---|
149 | /** Closes dialog like user would press the 3rd button. */
|
---|
150 | void sltDone3() { m_fDone = true; done(m_iButton3 & AlertButtonMask); }
|
---|
151 |
|
---|
152 | private:
|
---|
153 |
|
---|
154 | /** Prepares all. */
|
---|
155 | void prepare();
|
---|
156 |
|
---|
157 | /** Prepares focus. */
|
---|
158 | void prepareFocus();
|
---|
159 |
|
---|
160 | /** Push-button factory. */
|
---|
161 | QPushButton *createButton(int iButton);
|
---|
162 |
|
---|
163 | /** Visibility update routine for details-container. */
|
---|
164 | void updateDetailsContainer();
|
---|
165 | /** Visibility update routine for check-box. */
|
---|
166 | void updateCheckBox();
|
---|
167 |
|
---|
168 | /** Generates standard pixmap for passed @a iconType using @a pWidget as hint. */
|
---|
169 | static QPixmap standardPixmap(AlertIconType iconType, QWidget *pWidget = 0);
|
---|
170 |
|
---|
171 | /** Compresses @a strText with ellipsis on the basis of certain logic. */
|
---|
172 | static QString compressLongWords(QString strText);
|
---|
173 |
|
---|
174 | /** Holds the title. */
|
---|
175 | QString m_strTitle;
|
---|
176 |
|
---|
177 | /** Holds the icon-type. */
|
---|
178 | AlertIconType m_iconType;
|
---|
179 | /** Holds the icon-label instance. */
|
---|
180 | QLabel *m_pLabelIcon;
|
---|
181 |
|
---|
182 | /** Holds the message. */
|
---|
183 | QString m_strMessage;
|
---|
184 | /** Holds the message-label instance. */
|
---|
185 | QIRichTextLabel *m_pLabelText;
|
---|
186 |
|
---|
187 | /** Holds the flag check-box instance. */
|
---|
188 | QCheckBox *m_pFlagCheckBox;
|
---|
189 |
|
---|
190 | /** Holds the flag details-container instance. */
|
---|
191 | QIArrowSplitter *m_pDetailsContainer;
|
---|
192 |
|
---|
193 | /** Holds the integer-code for the 1st button. */
|
---|
194 | int m_iButton1;
|
---|
195 | /** Holds the integer-code for the 2nd button. */
|
---|
196 | int m_iButton2;
|
---|
197 | /** Holds the integer-code for the 3rd button. */
|
---|
198 | int m_iButton3;
|
---|
199 | /** Holds the integer-code of the cancel-button. */
|
---|
200 | int m_iButtonEsc;
|
---|
201 | /** Holds the 1st button instance. */
|
---|
202 | QPushButton *m_pButton1;
|
---|
203 | /** Holds the 2nd button instance. */
|
---|
204 | QPushButton *m_pButton2;
|
---|
205 | /** Holds the 3rd button instance. */
|
---|
206 | QPushButton *m_pButton3;
|
---|
207 | /** Holds the help-button instance. */
|
---|
208 | QPushButton *m_pButtonHelp;
|
---|
209 |
|
---|
210 | /** Holds the button-box instance. */
|
---|
211 | QIDialogButtonBox *m_pButtonBox;
|
---|
212 |
|
---|
213 | /** Holds the help keyword string. */
|
---|
214 | QString m_strHelpKeyword;
|
---|
215 |
|
---|
216 | /** Defines whether message was accepted. */
|
---|
217 | bool m_fDone : 1;
|
---|
218 | };
|
---|
219 |
|
---|
220 |
|
---|
221 | #endif /* !FEQT_INCLUDED_SRC_extensions_QIMessageBox_h */
|
---|