/
dialogwidget.h
161 lines (135 loc) · 4.57 KB
/
dialogwidget.h
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
/** @file dialogwidget.h Popup dialog.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef DENG_CLIENT_DIALOGWIDGET_H
#define DENG_CLIENT_DIALOGWIDGET_H
#include "popupwidget.h"
#include "scrollareawidget.h"
#include "menuwidget.h"
class GuiRootWidget;
/**
* Popup dialog.
*
* The content area of a dialog is scrollable. A menu with buttons is placed in
* the bottom of the dialog, for the actions available to the user.
*
* The contents of the dialog should be placed under the scroll area returned
* by DialogWidget::content() and positioned in relation to its content rule.
* When the dialog is set up, one must define the size of the content scroll
* area (width and height rules).
*
* Note that when a widget is added to the content area, the dialog
* automatically applies certain common style parameters (margins, backgrounds,
* etc.).
*/
class DialogWidget : public PopupWidget
{
Q_OBJECT
public:
/**
* Modality of the dialog. By default, dialogs are modal, meaning that
* while they are open, no events can get past the dialog.
*/
enum Modality {
Modal,
NonModal
};
enum RoleFlag {
None = 0,
Default = 0x1, ///< Pressing Space or Enter will activate this.
Accept = 0x2,
Reject = 0x4,
Yes = 0x8,
No = 0x10,
Action = 0x20
};
Q_DECLARE_FLAGS(RoleFlags, RoleFlag)
/**
* All buttons in a dialog must be ButtonItem instances or instances of
* derived classes.
*
* The DialogButtonItem typedef is provided for convenience.
*/
class ButtonItem : public ui::ActionItem
{
public:
/**
* Button with the role's default label and action.
* @param flags Role flags for the button.
* @param label Label for the button. If empty, the default label will be used.
*/
ButtonItem(RoleFlags flags, de::String const &label = "");
/**
* Button with custom action.
* @param flags Role flags for the button.
* @param label Label for the button. If empty, the default label will be used.
*/
ButtonItem(RoleFlags flags, de::String const &label, de::Action *action);
RoleFlags role() const { return _role; }
private:
RoleFlags _role;
};
public:
DialogWidget(de::String const &name = "");
Modality modality() const;
ScrollAreaWidget &area();
MenuWidget &buttons();
/**
* Shows the dialog and blocks execution until the dialog is closed --
* another event loop is started for event processing. Call either accept()
* or reject() to dismiss the dialog.
*
* @param root Root where to execute the dialog.
*
* @return Result code.
*/
int exec(GuiRootWidget &root);
/**
* Opens the dialog as non-modal. The dialog must already be added to the
* widget tree. Use accept() or reject() to close the dialog.
*/
void open();
// Events.
void update();
bool handleEvent(de::Event const &event);
public slots:
void accept(int result = 1);
void reject(int result = 0);
signals:
void accepted(int result);
void rejected(int result);
protected:
void preparePopupForOpening();
/**
* Derived classes can override this to do additional tasks before
* execution of the dialog begins. DialogWidget::prepare() must be called
* from the overridding methods.
*/
virtual void prepare();
/**
* Handles any tasks needed when the dialog is closing.
* DialogWidget::finish() must be called from overridding methods.
*
* @param result Result code.
*/
virtual void finish(int result);
private:
DENG2_PRIVATE(d)
};
typedef DialogWidget::ButtonItem DialogButtonItem;
Q_DECLARE_OPERATORS_FOR_FLAGS(DialogWidget::RoleFlags)
#endif // DENG_CLIENT_DIALOGWIDGET_H