summaryrefslogtreecommitdiff
path: root/src/VBox/Frontends/VirtualBox/src/extensions/QIMessageBox.h
blob: db3b6712840ad8da4b0db18a7eafd8f87cd87ffa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* $Id$ */
/** @file
 * VBox Qt GUI - Qt extensions: QIMessageBox class declaration.
 */

/*
 * Copyright (C) 2006-2022 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 */

#ifndef FEQT_INCLUDED_SRC_extensions_QIMessageBox_h
#define FEQT_INCLUDED_SRC_extensions_QIMessageBox_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

/* Qt includes: */
#include <QMessageBox>

/* GUI includes: */
#include "QIDialog.h"
#include "UILibraryDefs.h"

/* Forward declarations: */
class QCheckBox;
class QLabel;
class QPushButton;
class QIArrowSplitter;
class QIDialogButtonBox;
class QIRichTextLabel;


/** Button types. */
enum AlertButton
{
    AlertButton_NoButton      =  0x0,  /* 00000000 00000000 */
    AlertButton_Ok            =  0x1,  /* 00000000 00000001 */
    AlertButton_Cancel        =  0x2,  /* 00000000 00000010 */
    AlertButton_Choice1       =  0x4,  /* 00000000 00000100 */
    AlertButton_Choice2       =  0x8,  /* 00000000 00001000 */
    AlertButton_Copy          = 0x10,  /* 00000000 00010000 */
    AlertButton_Help          = 0x11,  /* 00000000 00010001 */
    AlertButtonMask           = 0xFF   /* 00000000 11111111 */
};


/** Button options. */
enum AlertButtonOption
{
    AlertButtonOption_Default = 0x100, /* 00000001 00000000 */
    AlertButtonOption_Escape  = 0x200, /* 00000010 00000000 */
    AlertButtonOptionMask     = 0x300  /* 00000011 00000000 */
};


/** Alert options. */
enum AlertOption
{
    AlertOption_AutoConfirmed = 0x400, /* 00000100 00000000 */
    AlertOption_CheckBox      = 0x800, /* 00001000 00000000 */
    AlertOptionMask           = 0xFC00 /* 11111100 00000000 */
};


/** Icon types. */
enum AlertIconType
{
    AlertIconType_NoIcon         = QMessageBox::NoIcon,
    AlertIconType_Information    = QMessageBox::Information,
    AlertIconType_Warning        = QMessageBox::Warning,
    AlertIconType_Critical       = QMessageBox::Critical,
    AlertIconType_Question       = QMessageBox::Question,
    AlertIconType_GuruMeditation
};


/** QIDialog extension representing GUI alerts. */
class SHARED_LIBRARY_STUFF QIMessageBox : public QIDialog
{
    Q_OBJECT;

public:

    /** Constructs message-box passing @a pParent to the base-class.
      * @param  strTitle    Brings the title.
      * @param  strMessage  Brings the message.
      * @param  strMessage  Brings the help keyword for context sensitive help
      * @param  iconType    Brings the icon-type.
      * @param  iButton1    Brings the integer-code for the 1st button.
      * @param  iButton2    Brings the integer-code for the 2nd button.
      * @param  iButton3    Brings the integer-code for the 3rd button. */
    QIMessageBox(const QString &strTitle, const QString &strMessage, AlertIconType iconType,
                 int iButton1 = 0, int iButton2 = 0, int iButton3 = 0, QWidget *pParent = 0,
                 const QString &strHelpKeyword = QString());

    /** Defines details-text. */
    void setDetailsText(const QString &strText);

    /** Returns whether flag is checked. */
    bool flagChecked() const;
    /** Defines whether flag is @a fChecked. */
    void setFlagChecked(bool fChecked);
    /** Defines @a strFlagText. */
    void setFlagText(const QString &strFlagText);

    /** Defines @a iButton @a strText. */
    void setButtonText(int iButton, const QString &strText);

protected:

    /** Handles polish @a pEvent. */
    virtual void polishEvent(QShowEvent *pEvent) RT_OVERRIDE;

    /** Handles close @a pEvent. */
    virtual void closeEvent(QCloseEvent *pEvent) RT_OVERRIDE;

private slots:

    /** Updates dialog size: */
    void sltUpdateSize();

    /** Copy details-text. */
    void sltCopy() const;

    /** Closes dialog like user would press the Cancel button. */
    virtual void reject() RT_OVERRIDE;

    /** Closes dialog like user would press the 1st button. */
    void sltDone1() { m_fDone = true; done(m_iButton1 & AlertButtonMask); }
    /** Closes dialog like user would press the 2nd button. */
    void sltDone2() { m_fDone = true; done(m_iButton2 & AlertButtonMask); }
    /** Closes dialog like user would press the 3rd button. */
    void sltDone3() { m_fDone = true; done(m_iButton3 & AlertButtonMask); }

private:

    /** Prepares all. */
    void prepare();

    /** Prepares focus. */
    void prepareFocus();

    /** Push-button factory. */
    QPushButton *createButton(int iButton);

    /** Visibility update routine for details-container. */
    void updateDetailsContainer();
    /** Visibility update routine for check-box. */
    void updateCheckBox();

    /** Generates standard pixmap for passed @a iconType using @a pWidget as hint. */
    static QPixmap standardPixmap(AlertIconType iconType, QWidget *pWidget = 0);

    /** Compresses @a strText with ellipsis on the basis of certain logic. */
    static QString compressLongWords(QString strText);

    /** Holds the title. */
    QString m_strTitle;

    /** Holds the icon-type. */
    AlertIconType m_iconType;
    /** Holds the icon-label instance. */
    QLabel *m_pLabelIcon;

    /** Holds the message. */
    QString m_strMessage;
    /** Holds the message-label instance. */
    QIRichTextLabel *m_pLabelText;

    /** Holds the flag check-box instance. */
    QCheckBox *m_pFlagCheckBox;

    /** Holds the flag details-container instance. */
    QIArrowSplitter *m_pDetailsContainer;

    /** Holds the integer-code for the 1st button. */
    int m_iButton1;
    /** Holds the integer-code for the 2nd button. */
    int m_iButton2;
    /** Holds the integer-code for the 3rd button. */
    int m_iButton3;
    /** Holds the integer-code of the cancel-button. */
    int m_iButtonEsc;
    /** Holds the 1st button instance. */
    QPushButton *m_pButton1;
    /** Holds the 2nd button instance. */
    QPushButton *m_pButton2;
    /** Holds the 3rd button instance. */
    QPushButton *m_pButton3;
    /** Holds the help-button instance. */
    QPushButton  *m_pButtonHelp;

    /** Holds the button-box instance. */
    QIDialogButtonBox *m_pButtonBox;

    /** Holds the help keyword string. */
    QString m_strHelpKeyword;

    /** Defines whether message was accepted. */
    bool m_fDone : 1;
};


#endif /* !FEQT_INCLUDED_SRC_extensions_QIMessageBox_h */