/
scrollareawidget.h
136 lines (107 loc) · 3.89 KB
/
scrollareawidget.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
/** @file scrollareawidget.h Scrollable area.
*
* @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_SCROLLAREAWIDGET_H
#define DENG_CLIENT_SCROLLAREAWIDGET_H
#include "guiwidget.h"
/**
* Scrollable area.
*/
class ScrollAreaWidget : public GuiWidget
{
Q_OBJECT
public:
enum Origin {
Top, ///< Scroll position 0 is at the top.
Bottom ///< Scroll position 0 is at the bottom.
};
public:
ScrollAreaWidget(de::String const &name = "");
void setOrigin(Origin origin);
Origin origin() const;
void setIndicatorUv(de::Rectanglef const &uv);
void setIndicatorUv(de::Vector2f const &uvPoint);
void setContentWidth(int width);
void setContentWidth(de::Rule const &width);
void setContentHeight(int height);
void setContentHeight(de::Rule const &height);
void setContentSize(de::Vector2i const &size);
void modifyContentWidth(int delta);
void modifyContentHeight(int delta);
int contentWidth() const;
int contentHeight() const;
de::RuleRectangle const &contentRule() const;
de::ScalarRule &scrollPositionX() const;
de::ScalarRule &scrollPositionY() const;
de::Rule const &maximumScrollX() const;
de::Rule const &maximumScrollY() const;
de::Rectanglei viewport() const;
de::Vector2i viewportSize() const;
/**
* Returns the amount of space between the top edge of the widget and the
* top edge of the content.
*/
int topMargin() const;
int rightMargin() const;
/**
* Returns the current scroll XY position, with 0 being the top/left corner
* and maximumScroll() being the bottom right position.
*/
de::Vector2i scrollPosition() const;
virtual de::Vector2i scrollPageSize() const;
/**
* Returns the maximum scroll position. The scrollMaxChanged() signal
* is emitted whenever the maximum changes.
*/
de::Vector2i maximumScroll() const;
/**
* Scrolls the view to a specified position. Position (0,0) means the top
* left corner is visible at the top left corner of the ScrollAreaWidget.
*
* @param to Scroll position.
*/
void scroll(de::Vector2i const &to, de::TimeDelta span = 0);
void scrollX(int to, de::TimeDelta span = 0);
void scrollY(int to, de::TimeDelta span = 0);
/**
* Determines if the history view is at the bottom, showing the latest entry.
*/
bool isAtBottom() const;
/**
* Enables or disables scrolling with Page Up/Down keys.
*
* @param enabled @c true to enable Page Up/Down.
*/
void enablePageKeys(bool enabled);
void glMakeScrollIndicatorGeometry(DefaultVertexBuf::Builder &verts);
// Events.
void update();
void preDrawChildren();
void postDrawChildren();
bool handleEvent(de::Event const &event);
public slots:
void scrollToTop(de::TimeDelta span = .3f);
/**
* Moves the scroll offset of the widget to the bottom of the content.
*/
void scrollToBottom(de::TimeDelta span = .3f);
void scrollToLeft(de::TimeDelta span = .3f);
void scrollToRight(de::TimeDelta span = .3f);
private:
DENG2_PRIVATE(d)
};
#endif // DENG_CLIENT_SCROLLAREAWIDGET_H