1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QTABBAR_P_H
|
---|
43 | #define QTABBAR_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "qtabbar.h"
|
---|
57 | #include "private/qwidget_p.h"
|
---|
58 |
|
---|
59 | #include <qicon.h>
|
---|
60 | #include <qtoolbutton.h>
|
---|
61 | #include <qdebug.h>
|
---|
62 | #include <qvariantanimation.h>
|
---|
63 |
|
---|
64 | #ifndef QT_NO_TABBAR
|
---|
65 |
|
---|
66 | #define ANIMATION_DURATION 250
|
---|
67 |
|
---|
68 | #include <qstyleoption.h>
|
---|
69 |
|
---|
70 | QT_BEGIN_NAMESPACE
|
---|
71 |
|
---|
72 | class QTabBarPrivate : public QWidgetPrivate
|
---|
73 | {
|
---|
74 | Q_DECLARE_PUBLIC(QTabBar)
|
---|
75 | public:
|
---|
76 | QTabBarPrivate()
|
---|
77 | :currentIndex(-1), pressedIndex(-1), shape(QTabBar::RoundedNorth), layoutDirty(false),
|
---|
78 | drawBase(true), scrollOffset(0), useScrollButtonsSetByUser(false) , expanding(true), closeButtonOnTabs(false),
|
---|
79 | selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false),
|
---|
80 | dragInProgress(false), documentMode(false), movingTab(0)
|
---|
81 | #ifdef Q_WS_MAC
|
---|
82 | , previousPressedIndex(-1)
|
---|
83 | #endif
|
---|
84 | {}
|
---|
85 |
|
---|
86 | int currentIndex;
|
---|
87 | int pressedIndex;
|
---|
88 | QTabBar::Shape shape;
|
---|
89 | bool layoutDirty;
|
---|
90 | bool drawBase;
|
---|
91 | int scrollOffset;
|
---|
92 |
|
---|
93 | struct Tab {
|
---|
94 | inline Tab(const QIcon &ico, const QString &txt)
|
---|
95 | : enabled(true) , shortcutId(0), text(txt), icon(ico),
|
---|
96 | leftWidget(0), rightWidget(0), lastTab(-1), dragOffset(0)
|
---|
97 | #ifndef QT_NO_ANIMATION
|
---|
98 | , animation(0)
|
---|
99 | #endif //QT_NO_ANIMATION
|
---|
100 | {}
|
---|
101 | bool operator==(const Tab &other) const { return &other == this; }
|
---|
102 | bool enabled;
|
---|
103 | int shortcutId;
|
---|
104 | QString text;
|
---|
105 | #ifndef QT_NO_TOOLTIP
|
---|
106 | QString toolTip;
|
---|
107 | #endif
|
---|
108 | #ifndef QT_NO_WHATSTHIS
|
---|
109 | QString whatsThis;
|
---|
110 | #endif
|
---|
111 | QIcon icon;
|
---|
112 | QRect rect;
|
---|
113 | QRect minRect;
|
---|
114 | QRect maxRect;
|
---|
115 |
|
---|
116 | QColor textColor;
|
---|
117 | QVariant data;
|
---|
118 | QWidget *leftWidget;
|
---|
119 | QWidget *rightWidget;
|
---|
120 | int lastTab;
|
---|
121 | int dragOffset;
|
---|
122 |
|
---|
123 | #ifndef QT_NO_ANIMATION
|
---|
124 | ~Tab() { delete animation; }
|
---|
125 | struct TabBarAnimation : public QVariantAnimation {
|
---|
126 | TabBarAnimation(Tab *t, QTabBarPrivate *_priv) : tab(t), priv(_priv)
|
---|
127 | { setEasingCurve(QEasingCurve::InOutQuad); }
|
---|
128 |
|
---|
129 | void updateCurrentValue(const QVariant ¤t)
|
---|
130 | { priv->moveTab(priv->tabList.indexOf(*tab), current.toInt()); }
|
---|
131 |
|
---|
132 | void updateState(State, State newState)
|
---|
133 | { if (newState == Stopped) priv->moveTabFinished(priv->tabList.indexOf(*tab)); }
|
---|
134 | private:
|
---|
135 | //these are needed for the callbacks
|
---|
136 | Tab *tab;
|
---|
137 | QTabBarPrivate *priv;
|
---|
138 | } *animation;
|
---|
139 |
|
---|
140 | void startAnimation(QTabBarPrivate *priv, int duration) {
|
---|
141 | if (!animation)
|
---|
142 | animation = new TabBarAnimation(this, priv);
|
---|
143 | animation->setStartValue(dragOffset);
|
---|
144 | animation->setEndValue(0);
|
---|
145 | animation->setDuration(duration);
|
---|
146 | animation->start();
|
---|
147 | }
|
---|
148 | #else
|
---|
149 | void startAnimation(QTabBarPrivate *priv, int duration)
|
---|
150 | { Q_UNUSED(duration); priv->moveTabFinished(priv->tabList.indexOf(*this)); }
|
---|
151 | #endif //QT_NO_ANIMATION
|
---|
152 | };
|
---|
153 | QList<Tab> tabList;
|
---|
154 |
|
---|
155 | int calculateNewPosition(int from, int to, int index) const;
|
---|
156 | void slide(int from, int to);
|
---|
157 | void init();
|
---|
158 | int extraWidth() const;
|
---|
159 |
|
---|
160 | Tab *at(int index);
|
---|
161 | const Tab *at(int index) const;
|
---|
162 |
|
---|
163 | int indexAtPos(const QPoint &p) const;
|
---|
164 |
|
---|
165 | inline bool validIndex(int index) const { return index >= 0 && index < tabList.count(); }
|
---|
166 | void setCurrentNextEnabledIndex(int offset);
|
---|
167 |
|
---|
|
---|