UBDockPalette.h 5.43 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * 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 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 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 18 19 20 21 22 23 24 25 26
#ifndef UBDOCKPALETTE_H
#define UBDOCKPALETTE_H

#include <QWidget>
#include <QMouseEvent>
#include <QBrush>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QEvent>
#include <QTime>
#include <QPoint>
#include <QPixmap>
shibakaneki's avatar
shibakaneki committed
27 28
#include <QMap>
#include <QStackedWidget>
29 30
#include <QVBoxLayout>
#include <QVector>
shibakaneki's avatar
shibakaneki committed
31 32

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

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

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

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

Ivan Ilin's avatar
Ivan Ilin committed
54 55
class UBDockPalette;

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

public:

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

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
74 75
    int mVerticalOffset;
    bool mFlotable;
Ivan Ilin's avatar
Ivan Ilin committed
76 77
};

78 79 80 81 82 83 84 85 86

typedef enum
{
    eUBDockPaletteType_LEFT,
    eUBDockPaletteType_RIGHT,
    eUBDockPaletteType_NAVIGATOR,
} eUBDockPaletteType;


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

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

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

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

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

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

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

115
    void connectSignals();
116

117 118
    bool switchMode(eUBDockPaletteWidgetMode mode);

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

Ivan Ilin's avatar
Ivan Ilin committed
121 122 123 124 125 126
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;}

127 128
    eUBDockPaletteType paletteType(){return mPaletteType;}

129
public slots:
130 131
    void onShowTabWidget(UBDockPaletteWidget* widget);
    void onHideTabWidget(UBDockPaletteWidget* widget);
Claudio Valerio's avatar
Claudio Valerio committed
132
    void onAllDownloadsFinished();
Claudio Valerio's avatar
Claudio Valerio committed
133 134 135 136

protected:
    virtual int border();
    virtual int radius();
137
    virtual int customMargin();
Claudio Valerio's avatar
Claudio Valerio committed
138 139 140 141 142 143
    virtual void updateMaxWidth();
    virtual void resizeEvent(QResizeEvent *event);
    virtual int collapseWidth();

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

179 180
private slots:
    void onToolbarPosUpdated();
181
    void onResizeRequest(QResizeEvent* event);
Claudio Valerio's avatar
Claudio Valerio committed
182 183

private:
184 185 186
    void tabClicked(int tabIndex);
    int tabSpacing();
    void toggleCollapseExpand();
Ivan Ilin's avatar
Ivan Ilin committed
187 188 189 190
    void moveTabs();
    void resizeTabs();

private:
191
    eUBDockPaletteType mPaletteType;
192
    UBTabDockPalette *mTabPalette;
Claudio Valerio's avatar
Claudio Valerio committed
193 194 195
};

#endif // UBDOCKPALETTE_H