UBDockPalette.h 5.64 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1 2 3
/*
 * 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
Claudio Valerio's avatar
Claudio Valerio committed
4
 * the Free Software Foundation, either version 2 of the License, or
Claudio Valerio's avatar
Claudio Valerio committed
5 6 7 8 9 10 11 12 13 14
 * (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/>.
 */
Claudio Valerio's avatar
Claudio Valerio committed
15 16 17
#ifndef UBDOCKPALETTE_H
#define UBDOCKPALETTE_H

Claudio Valerio's avatar
Claudio Valerio committed
18 19
class UBDocumentProxy;

Claudio Valerio's avatar
Claudio Valerio committed
20 21 22 23 24 25 26 27 28
#include <QWidget>
#include <QMouseEvent>
#include <QBrush>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QEvent>
#include <QTime>
#include <QPoint>
#include <QPixmap>
shibakaneki's avatar
shibakaneki committed
29 30
#include <QMap>
#include <QStackedWidget>
31 32
#include <QVBoxLayout>
#include <QVector>
shibakaneki's avatar
shibakaneki committed
33 34

#include "UBDockPaletteWidget.h"
Claudio Valerio's avatar
Claudio Valerio committed
35

Ivan Ilin's avatar
Ivan Ilin committed
36
#define TABSIZE	    50       //Height of the tab of the palette
37
#define CLICKTIME   1000000  //Clicktime to expand or collapse palette
Claudio Valerio's avatar
Claudio Valerio committed
38 39 40 41 42 43 44 45 46 47 48 49

/**
 * \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;

50 51 52 53 54 55
typedef enum
{
    eUBDockTabOrientation_Up,   /** Up tabs */
    eUBDockTabOrientation_Down  /** Down tabs */
}eUBDockTabOrientation;

Ivan Ilin's avatar
Ivan Ilin committed
56 57
class UBDockPalette;

58
class UBTabDockPalette : public QWidget
Ivan Ilin's avatar
Ivan Ilin committed
59 60 61 62 63 64
{
    Q_OBJECT
    friend class UBDockPalette;

public:

65 66
    UBTabDockPalette(UBDockPalette *dockPalette, QWidget *parent = 0);
    ~UBTabDockPalette();
Ivan Ilin's avatar
Ivan Ilin committed
67 68 69 70 71 72 73 74 75

protected:
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseMoveEvent(QMouseEvent *event);
    virtual void mouseReleaseEvent(QMouseEvent *event);
    virtual void paintEvent(QPaintEvent *event);

private:
    UBDockPalette *dock;
Ivan Ilin's avatar
Ivan Ilin committed
76 77
    int mVerticalOffset;
    bool mFlotable;
Ivan Ilin's avatar
Ivan Ilin committed
78 79
};

80 81 82 83

typedef enum
{
    eUBDockPaletteType_LEFT,
84
    eUBDockPaletteType_RIGHT
85 86 87
} eUBDockPaletteType;


Claudio Valerio's avatar
Claudio Valerio committed
88 89
class UBDockPalette : public QWidget
{
90
    Q_OBJECT
91
    friend class UBTabDockPalette;
Ivan Ilin's avatar
Ivan Ilin committed
92

Claudio Valerio's avatar
Claudio Valerio committed
93
public:
94
    UBDockPalette(eUBDockPaletteType paletteType, QWidget* parent=0, const char* name="UBDockPalette");
Claudio Valerio's avatar
Claudio Valerio committed
95 96 97 98
    ~UBDockPalette();

    eUBDockOrientation orientation();
    void setOrientation(eUBDockOrientation orientation);
99
    void setTabsOrientation(eUBDockTabOrientation orientation);
100
    void showTabWidget(int tabIndex);
Ivan Ilin's avatar
Ivan Ilin committed
101
    QRect getTabPaletteRect();
Claudio Valerio's avatar
Claudio Valerio committed
102

Ivan Ilin's avatar
Ivan Ilin committed
103 104 105
    virtual void assignParent(QWidget *widget);
    virtual void setVisible(bool visible);

Claudio Valerio's avatar
Claudio Valerio committed
106 107 108 109 110
    virtual void paintEvent(QPaintEvent *event);
    virtual void enterEvent(QEvent *);
    virtual void leaveEvent(QEvent *);

    void setBackgroundBrush(const QBrush& brush);
111
    void registerWidget(UBDockPaletteWidget* widget);
112

113
    void addTab(UBDockPaletteWidget* widget);
114
    void removeTab(UBDockPaletteWidget* widget);
115

116
    void connectSignals();
117

118 119
    bool switchMode(eUBDockPaletteWidgetMode mode);

Claudio Valerio's avatar
Claudio Valerio committed
120 121
    eUBDockPaletteWidgetMode mCurrentMode;

Ivan Ilin's avatar
Ivan Ilin committed
122
    QVector<UBDockPaletteWidget*> GetWidgetsList() { return mRegisteredWidgets; }
123

Ivan Ilin's avatar
Ivan Ilin committed
124 125 126 127 128 129
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;}

130 131
    eUBDockPaletteType paletteType(){return mPaletteType;}

132
public slots:
133 134
    void onShowTabWidget(UBDockPaletteWidget* widget);
    void onHideTabWidget(UBDockPaletteWidget* widget);
Claudio Valerio's avatar
Claudio Valerio committed
135
    void onAllDownloadsFinished();
Claudio Valerio's avatar
Claudio Valerio committed
136
    virtual void onDocumentSet(UBDocumentProxy* documentProxy);
Claudio Valerio's avatar
Claudio Valerio committed
137 138 139 140

protected:
    virtual int border();
    virtual int radius();
141
    virtual int customMargin();
Claudio Valerio's avatar
Claudio Valerio committed
142 143 144 145 146 147
    virtual void updateMaxWidth();
    virtual void resizeEvent(QResizeEvent *event);
    virtual int collapseWidth();

    /** The current dock orientation */
    eUBDockOrientation mOrientation;
148
    /** The current background brush */
Claudio Valerio's avatar
Claudio Valerio committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
    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;
166 167 168 169
    /** The tab orientation */
    eUBDockTabOrientation mTabsOrientation;
    /** The h position of the tab */
    int mHTab;
shibakaneki's avatar
shibakaneki committed
170 171
    /** The stacked widget */
    QStackedWidget* mpStackWidget;
172 173 174 175
    /** The layout */
    QVBoxLayout* mpLayout;
    /** The current tab index */
    int mCurrentTab;
176
    /** The visible tab widgets */
177
    QVector<UBDockPaletteWidget*> mTabWidgets;
178 179
    /** The current widget */
    QVector<UBDockPaletteWidget*> mRegisteredWidgets;
shibakaneki's avatar
shibakaneki committed
180 181
    /** The current tab widget */
    QString mCrntTabWidget;
Claudio Valerio's avatar
Claudio Valerio committed
182 183
    /** Last opened tab index depending on mode */
    QMap<eUBDockPaletteWidgetMode,int> mLastOpenedTabForMode;
184

185 186
private slots:
    void onToolbarPosUpdated();
187
    void onResizeRequest(QResizeEvent* event);
Claudio Valerio's avatar
Claudio Valerio committed
188 189

private:
190 191 192
    void tabClicked(int tabIndex);
    int tabSpacing();
    void toggleCollapseExpand();
Ivan Ilin's avatar
Ivan Ilin committed
193 194 195 196
    void moveTabs();
    void resizeTabs();

private:
197
    eUBDockPaletteType mPaletteType;
198
    UBTabDockPalette *mTabPalette;
Claudio Valerio's avatar
Claudio Valerio committed
199 200 201
};

#endif // UBDOCKPALETTE_H