/
panelwidget.h
156 lines (125 loc) · 4.18 KB
/
panelwidget.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
/** @file panelwidget.h
*
* @authors Copyright (c) 2013-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 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 Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef LIBAPPFW_PANELWIDGET_H
#define LIBAPPFW_PANELWIDGET_H
#include "../ui/defs.h"
#include "../ScrollAreaWidget"
namespace de {
/**
* Panel that can be opened or closed.
*
* A panel always has a single child as the content widget. This content widget
* may in turn contain several widgets, though. The size of the content widget
* determines the size of the panel. The user must define the position of the
* panel.
*
* Initially panels are in the closed state. They can be opened once the
* content widget has been set.
*
* @ingroup guiWidgets
*/
class LIBAPPFW_PUBLIC PanelWidget : public GuiWidget
{
Q_OBJECT
public:
DENG2_DEFINE_AUDIENCE2(AboutToOpen, void panelAboutToOpen(PanelWidget &))
/**
* Audience to be notified when the panel is closing.
*/
DENG2_DEFINE_AUDIENCE2(Close, void panelBeingClosed(PanelWidget &))
enum AnimationStyle { Bouncy, Smooth };
public:
PanelWidget(String const &name = String());
void setWaitForContentReady(bool yes);
void setAnimationStyle(AnimationStyle style);
/**
* Enables or disables mouse event eating. The default is that a panel eats
* events that hit it.
* @param yes @c true to enable.
*/
void setEatMouseEvents(bool yes);
/**
* Sets the size policy for the secondary dimension. For instance, for a
* panel that opens horizontally, this determines what is done to the
* widget height.
*
* - ui::Expand (the default) means that the widget automatically uses the
* content's size for the secondary dimension.
* - ui::Fixed means that the user is expected to define the panel's secondary
* dimension and the panel does not touch it.
*
* @param policy Size policy.
*/
void setSizePolicy(ui::SizePolicy policy);
/**
* Sets the content widget of the panel. If there is an earlier content
* widget, it will be destroyed.
*
* @param content Content widget. PanelWidget takes ownership.
* @a content becomes a child of the panel.
*/
void setContent(GuiWidget *content);
GuiWidget &content() const;
GuiWidget *takeContent();
/**
* Sets the opening direction of the panel.
*
* @param dir Opening direction.
*/
void setOpeningDirection(ui::Direction dir);
ui::Direction openingDirection() const;
bool isOpen() const;
bool isOpeningOrClosing() const;
void close(TimeDelta delayBeforeClosing);
// Events.
void viewResized() override;
void update() override;
bool handleEvent(Event const &event) override;
public slots:
/**
* Opens the panel, positioning it appropriately so that is anchored to the
* position specified with setAnchor().
*/
virtual void open();
/**
* Closes the panel. The widget is dismissed once the closing animation
* completes.
*/
void close();
void openOrClose();
/**
* Immediately hides the panel.
*/
void dismiss();
signals:
void opened();
void closed();
void dismissed();
protected:
void glInit();
void glDeinit();
void drawContent();
void glMakeGeometry(GuiVertexBuilder &verts);
virtual void preparePanelForOpening();
virtual void panelClosing();
virtual void panelDismissed();
private:
DENG2_PRIVATE(d)
};
} // namespace de
#endif // LIBAPPFW_PANELWIDGET_H