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
/*
* 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/>.
*/
#ifndef UBDOCKPALETTE_H
#define UBDOCKPALETTE_H
#include <QWidget>
#include <QMouseEvent>
#include <QBrush>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QEvent>
#include <QTime>
#include <QPoint>
#include <QPixmap>
#include <QMap>
#include <QStackedWidget>
#include <QVBoxLayout>
#include <QVector>
#include "UBDockPaletteWidget.h"
#define TABSIZE 50 //Height of the tab of the palette
#define CLICKTIME 1000000 //Clicktime to expand or collapse palette
/**
* \brief The dock positions
*/
typedef enum
{
eUBDockOrientation_Left, /** Left dock */
eUBDockOrientation_Right, /** Right dock */
eUBDockOrientation_Top, /** [to be implemented]Top dock */
eUBDockOrientation_Bottom /** [to be implemented]Bottom dock */
}eUBDockOrientation;
typedef enum
{
eUBDockTabOrientation_Up, /** Up tabs */
eUBDockTabOrientation_Down /** Down tabs */
}eUBDockTabOrientation;
class UBDockPalette;
class UBTabDockPalette : public QWidget
{
Q_OBJECT
friend class UBDockPalette;
public:
UBTabDockPalette(UBDockPalette *dockPalette, QWidget *parent = 0);
~UBTabDockPalette();
protected:
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void paintEvent(QPaintEvent *event);
private:
UBDockPalette *dock;
int mVerticalOffset;
bool mFlotable;
};
typedef enum
{
eUBDockPaletteType_LEFT,
eUBDockPaletteType_RIGHT
} eUBDockPaletteType;
class UBDockPalette : public QWidget
{
Q_OBJECT
friend class UBTabDockPalette;
public:
UBDockPalette(eUBDockPaletteType paletteType, QWidget* parent=0, const char* name="UBDockPalette");
~UBDockPalette();
eUBDockOrientation orientation();
void setOrientation(eUBDockOrientation orientation);
void setTabsOrientation(eUBDockTabOrientation orientation);
void showTabWidget(int tabIndex);
QRect getTabPaletteRect();
virtual void assignParent(QWidget *widget);
virtual void setVisible(bool visible);
virtual void paintEvent(QPaintEvent *event);
virtual void enterEvent(QEvent *);
virtual void leaveEvent(QEvent *);
void setBackgroundBrush(const QBrush& brush);
void registerWidget(UBDockPaletteWidget* widget);
void addTab(UBDockPaletteWidget* widget);
void removeTab(UBDockPaletteWidget* widget);
void connectSignals();
bool switchMode(eUBDockPaletteWidgetMode mode);
eUBDockPaletteWidgetMode mCurrentMode;
QVector<UBDockPaletteWidget*> GetWidgetsList() { return mRegisteredWidgets; }
public:
bool isTabFlotable() {return mTabPalette->mFlotable;}
void setTabFlotable(bool newFlotable) {mTabPalette->mFlotable = newFlotable;}
int getAdditionalVOffset() const {return mTabPalette->mVerticalOffset;}
void setAdditionalVOffset(int newOffset) {mTabPalette->mVerticalOffset = newOffset;}
eUBDockPaletteType paletteType(){return mPaletteType;}
public slots:
void onShowTabWidget(UBDockPaletteWidget* widget);
void onHideTabWidget(UBDockPaletteWidget* widget);
void onAllDownloadsFinished();
protected:
virtual int border();
virtual int radius();
virtual int customMargin();
virtual void updateMaxWidth();
virtual void resizeEvent(QResizeEvent *event);
virtual int collapseWidth();
/** The current dock orientation */
eUBDockOrientation mOrientation;
/** The current background brush */
QBrush mBackgroundBrush;
/** The preferred width */
int mPreferredWidth;
/** The preferred height */
int mPreferredHeight;
/** A flag used to allow the resize */
bool mCanResize;
/** A flag indicating if the palette has been resized between a click and a release */
bool mResized;
/** The width that trig the collapse */
int mCollapseWidth;
/** The last width of the palette */
int mLastWidth;
/** The click time*/
QTime mClickTime;
/** The mouse pressed position */
QPoint mMousePressPos;
/** The tab orientation */
eUBDockTabOrientation mTabsOrientation;
/** The h position of the tab */
int mHTab;
/** The stacked widget */
QStackedWidget* mpStackWidget;
/** The layout */
QVBoxLayout* mpLayout;
/** The current tab index */
int mCurrentTab;
/** The visible tab widgets */
QVector<UBDockPaletteWidget*> mTabWidgets;
/** The current widget */
QVector<UBDockPaletteWidget*> mRegisteredWidgets;
/** The current tab widget */
QString mCrntTabWidget;
/** Last opened tab index depending on mode */
QMap<eUBDockPaletteWidgetMode,int> mLastOpenedTabForMode;
private slots:
void onToolbarPosUpdated();
void onResizeRequest(QResizeEvent* event);
private:
void tabClicked(int tabIndex);
int tabSpacing();
void toggleCollapseExpand();
void moveTabs();
void resizeTabs();
private:
eUBDockPaletteType mPaletteType;
UBTabDockPalette *mTabPalette;
};
#endif // UBDOCKPALETTE_H