source: trunk/src/gui/widgets/qtabbar_p.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 8.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
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 qt-info@nokia.com.
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
70QT_BEGIN_NAMESPACE
71
72class QTabBarPrivate : public QWidgetPrivate
73{
74 Q_DECLARE_PUBLIC(QTabBar)
75public:
76 QTabBarPrivate()
77 :currentIndex(-1), pressedIndex(-1), shape(QTabBar::RoundedNorth), layoutDirty(false),
78 drawBase(true), scrollOffset(0), elideModeSetByUser(false), 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 &current)
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
168 QSize minimumTabSizeHint(int index);
169
170 QToolButton* rightB; // right or bottom
171 QToolButton* leftB; // left or top
172
173 void _q_scrollTabs();
174 void _q_closeTab();
175 void moveTab(int index, int offset);
176 void moveTabFinished(int index);
177 QRect hoverRect;
178
179 void refresh();
180 void layoutTabs();
181 void layoutWidgets(int start = 0);
182 void layoutTab(int index);
183 void updateMacBorderMetrics();
184 void setupMovableTab();
185
186 void makeVisible(int index);
187 QSize iconSize;
188 Qt::TextElideMode elideMode;
189 bool elideModeSetByUser;
190 bool useScrollButtons;
191 bool useScrollButtonsSetByUser;
192
193 bool expanding;
194 bool closeButtonOnTabs;
195 QTabBar::SelectionBehavior selectionBehaviorOnRemove;
196
197 QPoint dragStartPosition;
198 bool paintWithOffsets;
199 bool movable;
200 bool dragInProgress;
201 bool documentMode;
202
203 QWidget *movingTab;
204#ifdef Q_WS_MAC
205 int previousPressedIndex;
206#endif
207 // shared by tabwidget and qtabbar
208 static void initStyleBaseOption(QStyleOptionTabBarBaseV2 *optTabBase, QTabBar *tabbar, QSize size)
209 {
210 QStyleOptionTab tabOverlap;
211 tabOverlap.shape = tabbar->shape();
212 int overlap = tabbar->style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, &tabOverlap, tabbar);
213 QWidget *theParent = tabbar->parentWidget();
214 optTabBase->init(tabbar);
215 optTabBase->shape = tabbar->shape();
216 optTabBase->documentMode = tabbar->documentMode();
217 if (theParent && overlap > 0) {
218 QRect rect;
219 switch (tabOverlap.shape) {
220 case QTabBar::RoundedNorth:
221 case QTabBar::TriangularNorth:
222 rect.setRect(0, size.height()-overlap, size.width(), overlap);
223 break;
224 case QTabBar::RoundedSouth:
225 case QTabBar::TriangularSouth:
226 rect.setRect(0, 0, size.width(), overlap);
227 break;
228 case QTabBar::RoundedEast:
229 case QTabBar::TriangularEast:
230 rect.setRect(0, 0, overlap, size.height());
231 break;
232 case QTabBar::RoundedWest:
233 case QTabBar::TriangularWest:
234 rect.setRect(size.width() - overlap, 0, overlap, size.height());
235 break;
236 }
237 optTabBase->rect = rect;
238 }
239 }
240
241};
242
243class CloseButton : public QAbstractButton
244{
245 Q_OBJECT
246
247public:
248 CloseButton(QWidget *parent = 0);
249
250 QSize sizeHint() const;
251 inline QSize minimumSizeHint() const
252 { return sizeHint(); }
253 void enterEvent(QEvent *event);
254 void leaveEvent(QEvent *event);
255 void paintEvent(QPaintEvent *event);
256};
257
258
259QT_END_NAMESPACE
260
261#endif
262
263#endif
Note: See TracBrowser for help on using the repository browser.