/
panelwidget.h
133 lines (111 loc) · 3.66 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
/** @file panelwidget.h
*
* @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_PANELWIDGET_H
#define DENG_CLIENT_PANELWIDGET_H
#include "../uidefs.h"
#include "scrollareawidget.h"
/**
* 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.
*/
class PanelWidget : public GuiWidget
{
Q_OBJECT
public:
/**
* Audience to be notified when the panel is closing.
*/
DENG2_DEFINE_AUDIENCE(Close, void panelBeingClosed(PanelWidget &))
public:
PanelWidget(de::String const &name = "");
/**
* 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;
void close(de::TimeDelta delayBeforeClosing);
// Events.
void viewResized();
void update();
void preDrawChildren();
void postDrawChildren();
bool handleEvent(de::Event const &event);
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();
/**
* Immediately hides the panel.
*/
void dismiss();
signals:
void opened();
void closed();
void dismissed();
protected:
void glInit();
void glDeinit();
void drawContent();
void glMakeGeometry(DefaultVertexBuf::Builder &verts);
virtual void preparePanelForOpening();
virtual void panelClosing();
virtual void panelDismissed();
private:
DENG2_PRIVATE(d)
};
#endif // DENG_CLIENT_PANELWIDGET_H