1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtGui module of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
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.
57
#include "private/qwidget_p.h"
60
#include <qtoolbutton.h>
62
#include <qvariantanimation.h>
66
#define ANIMATION_DURATION 250
68
#include <qstyleoption.h>
72
class QTabBarPrivate : public QWidgetPrivate
74
Q_DECLARE_PUBLIC(QTabBar)
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)
82
, previousPressedIndex(-1)
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
99
#endif //QT_NO_ANIMATION
101
bool operator==(const Tab &other) const { return &other == this; }
105
#ifndef QT_NO_TOOLTIP
108
#ifndef QT_NO_WHATSTHIS
119
QWidget *rightWidget;
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); }
129
void updateCurrentValue(const QVariant ¤t)
130
{ priv->moveTab(priv->tabList.indexOf(*tab), current.toInt()); }
132
void updateState(State, State newState)
133
{ if (newState == Stopped) priv->moveTabFinished(priv->tabList.indexOf(*tab)); }
135
//these are needed for the callbacks
137
QTabBarPrivate *priv;
140
void startAnimation(QTabBarPrivate *priv, int duration) {
142
animation = new TabBarAnimation(this, priv);
143
animation->setStartValue(dragOffset);
144
animation->setEndValue(0);
145
animation->setDuration(duration);
149
void startAnimation(QTabBarPrivate *priv, int duration)
150
{ Q_UNUSED(duration); priv->moveTabFinished(priv->tabList.indexOf(*this)); }
151
#endif //QT_NO_ANIMATION
155
int calculateNewPosition(int from, int to, int index) const;
156
void slide(int from, int to);
158
int extraWidth() const;
161
const Tab *at(int index) const;
163
int indexAtPos(const QPoint &p) const;
165
inline bool validIndex(int index) const { return index >= 0 && index < tabList.count(); }
166
void setCurrentNextEnabledIndex(int offset);
168
QToolButton* rightB; // right or bottom
169
QToolButton* leftB; // left or top
171
void _q_scrollTabs();
173
void moveTab(int index, int offset);
174
void moveTabFinished(int index);
179
void layoutWidgets(int start = 0);
180
void layoutTab(int index);
181
void updateMacBorderMetrics();
182
void setupMovableTab();
184
void makeVisible(int index);
186
Qt::TextElideMode elideMode;
187
bool elideModeSetByUser;
188
bool useScrollButtons;
189
bool useScrollButtonsSetByUser;
192
bool closeButtonOnTabs;
193
QTabBar::SelectionBehavior selectionBehaviorOnRemove;
195
QPoint dragStartPosition;
196
bool paintWithOffsets;
203
int previousPressedIndex;
205
// shared by tabwidget and qtabbar
206
static void initStyleBaseOption(QStyleOptionTabBarBaseV2 *optTabBase, QTabBar *tabbar, QSize size)
208
QStyleOptionTab tabOverlap;
209
tabOverlap.shape = tabbar->shape();
210
int overlap = tabbar->style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, &tabOverlap, tabbar);
211
QWidget *theParent = tabbar->parentWidget();
212
optTabBase->init(tabbar);
213
optTabBase->shape = tabbar->shape();
214
optTabBase->documentMode = tabbar->documentMode();
215
if (theParent && overlap > 0) {
217
switch (tabOverlap.shape) {
218
case QTabBar::RoundedNorth:
219
case QTabBar::TriangularNorth:
220
rect.setRect(0, size.height()-overlap, size.width(), overlap);
222
case QTabBar::RoundedSouth:
223
case QTabBar::TriangularSouth:
224
rect.setRect(0, 0, size.width(), overlap);
226
case QTabBar::RoundedEast:
227
case QTabBar::TriangularEast:
228
rect.setRect(0, 0, overlap, size.height());
230
case QTabBar::RoundedWest:
231
case QTabBar::TriangularWest:
232
rect.setRect(size.width() - overlap, 0, overlap, size.height());
235
optTabBase->rect = rect;
241
class CloseButton : public QAbstractButton
246
CloseButton(QWidget *parent = 0);
248
QSize sizeHint() const;
249
inline QSize minimumSizeHint() const
250
{ return sizeHint(); }
251
void enterEvent(QEvent *event);
252
void leaveEvent(QEvent *event);
253
void paintEvent(QPaintEvent *event);