Qt 4.8
qtabbar_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
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.
16 **
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.
24 **
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.
28 **
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.
36 **
37 **
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 
71 
73 {
75 public:
77  :currentIndex(-1), pressedIndex(-1), shape(QTabBar::RoundedNorth), layoutDirty(false),
79  selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false),
80  dragInProgress(false), documentMode(false), movingTab(0)
81 #ifdef Q_WS_MAC
83 #endif
84  {}
85 
90  bool drawBase;
92 
93  struct Tab {
94  inline Tab(const QIcon &ico, const QString &txt)
95  : enabled(true) , shortcutId(0), text(txt), icon(ico),
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;
105 #ifndef QT_NO_TOOLTIP
107 #endif
108 #ifndef QT_NO_WHATSTHIS
110 #endif
115 
120  int lastTab;
122 
123 #ifndef QT_NO_ANIMATION
124  ~Tab() { delete animation; }
126  TabBarAnimation(Tab *t, QTabBarPrivate *_priv) : tab(t), priv(_priv)
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
138  } *animation;
139 
141  if (!animation)
142  animation = new TabBarAnimation(this, priv);
143  animation->setStartValue(dragOffset);
145  animation->setDuration(duration);
146  animation->start();
147  }
148 #else
150  { Q_UNUSED(duration); priv->moveTabFinished(priv->tabList.indexOf(*this)); }
151 #endif //QT_NO_ANIMATION
152  };
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 
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);
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);
192 
193  bool expanding;
196 
199  bool movable;
202 
204 #ifdef Q_WS_MAC
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) {
222  rect.setRect(0, size.height()-overlap, size.width(), overlap);
223  break;
226  rect.setRect(0, 0, size.width(), overlap);
227  break;
230  rect.setRect(0, 0, overlap, size.height());
231  break;
234  rect.setRect(size.width() - overlap, 0, overlap, size.height());
235  break;
236  }
237  optTabBase->rect = rect;
238  }
239  }
240 
241 };
242 
244 {
245  Q_OBJECT
246 
247 public:
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 
260 
261 #endif
262 
263 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
void moveTab(int index, int offset)
em>Reimplemented Function
Definition: qtabbar.cpp:1768
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void setupMovableTab()
Definition: qtabbar.cpp:1896
bool validIndex(int index) const
Definition: qtabbar_p.h:165
void updateMacBorderMetrics()
Definition: qtabbar.cpp:85
void _q_closeTab()
Definition: qtabbar.cpp:655
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void moveTabFinished(int index)
em>Reimplemented Function
Definition: qtabbar.cpp:1936
QToolButton * rightB
Definition: qtabbar_p.h:170
QWidget * rightWidget
Definition: qtabbar_p.h:119
QRect hoverRect
Definition: qtabbar_p.h:177
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
void updateCurrentValue(const QVariant &current)
This pure virtual function is called every time the animation&#39;s current value changes.
Definition: qtabbar_p.h:129
TextElideMode
Definition: qnamespace.h:263
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int previousPressedIndex
Definition: qtabbar_p.h:205
void setCurrentNextEnabledIndex(int offset)
em>Reimplemented Function
Definition: qtabbar.cpp:2027
void setEasingCurve(const QEasingCurve &easing)
void startAnimation(QTabBarPrivate *priv, int duration)
Definition: qtabbar_p.h:140
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
void init(const QWidget *w)
Use initFrom(widget) instead.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int indexAtPos(const QPoint &p) const
Definition: qtabbar.cpp:395
The QTabBar class provides a tab bar, e.g.
Definition: qtabbar.h:59
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setEndValue(const QVariant &value)
QTabBar::SelectionBehavior selectionBehaviorOnRemove
Definition: qtabbar_p.h:195
int extraWidth() const
Definition: qtabbar.cpp:354
QWidget * movingTab
Definition: qtabbar_p.h:203
QTabBar::Shape shape
the tab shape used to draw the tab; by default QTabBar::RoundedNorth
Definition: qstyleoption.h:316
QToolButton * leftB
Definition: qtabbar_p.h:171
void setStartValue(const QVariant &value)
QStyle * style() const
Definition: qwidget.cpp:2742
QPoint dragStartPosition
Definition: qtabbar_p.h:197
Tab(const QIcon &ico, const QString &txt)
Definition: qtabbar_p.h:94
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void setDuration(int msecs)
bool useScrollButtons
Definition: qtabbar_p.h:190
bool layoutDirty
Definition: qtabbar_p.h:89
QTabBar::Shape shape
Definition: qtabbar_p.h:88
int width() const
Returns the width.
Definition: qsize.h:126
bool paintWithOffsets
Definition: qtabbar_p.h:198
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Shape
This enum type lists the built-in shapes supported by QTabBar.
Definition: qtabbar.h:81
bool documentMode
whether the tabbar is in document mode.
Definition: qstyleoption.h:239
TabBarAnimation(Tab *t, QTabBarPrivate *_priv)
Definition: qtabbar_p.h:126
The QVariantAnimation class provides an abstract base class for animations.
bool operator==(const Tab &other) const
Returns true if tab other is equal to this tab; otherwise returns false.
Definition: qtabbar_p.h:101
QTabBarPrivate::Tab::TabBarAnimation * animation
QList< Tab > tabList
Definition: qtabbar_p.h:153
void slide(int from, int to)
Definition: qtabbar.cpp:1750
int calculateNewPosition(int from, int to, int index) const
Definition: qtabbar.cpp:1654
The State element defines configurations of objects and properties.
QSize minimumTabSizeHint(int index)
Definition: qtabbar.cpp:1373
bool useScrollButtonsSetByUser
Definition: qtabbar_p.h:191
void refresh()
Definition: qtabbar.cpp:720
#define Q_OBJECT
Definition: qobjectdefs.h:157
void layoutTabs()
Definition: qtabbar.cpp:406
bool documentMode
Whether or not the tab bar is rendered in a mode suitable for the main window.
Definition: qtabbar.h:75
SelectionBehavior
This enum type lists the behavior of QTabBar when a tab is removed and the tab being removed is also ...
Definition: qtabbar.h:94
bool dragInProgress
Definition: qtabbar_p.h:200
The QStyleOptionTabBarBaseV2 class is used to describe the base of a tab bar, i.e.
Definition: qstyleoption.h:235
int pressedIndex
Definition: qtabbar_p.h:87
Shape shape
the shape of the tabs in the tab bar
Definition: qtabbar.h:64
bool closeButtonOnTabs
Definition: qtabbar_p.h:194
QSize minimumSizeHint() const
Definition: qtabbar_p.h:251
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
Tab * at(int index)
Definition: qtabbar.cpp:385
static void initStyleBaseOption(QStyleOptionTabBarBaseV2 *optTabBase, QTabBar *tabbar, QSize size)
Definition: qtabbar_p.h:208
bool documentMode
Definition: qtabbar_p.h:201
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int currentIndex
Definition: qtabbar_p.h:86
QTabBar::Shape shape
the shape of the tab bar
Definition: qstyleoption.h:224
void layoutWidgets(int start=0)
Definition: qtabbar.cpp:647
Qt::TextElideMode elideMode
Definition: qtabbar_p.h:188
quint16 index
void updateState(State, State newState)
Definition: qtabbar_p.h:132
The QStyleOptionTab class is used to describe the parameters for drawing a tab bar.
Definition: qstyleoption.h:304
QSize iconSize
Definition: qtabbar_p.h:187
void _q_scrollTabs()
Definition: qtabbar.cpp:678
void layoutTab(int index)
Definition: qtabbar.cpp:611
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool elideModeSetByUser
Definition: qtabbar_p.h:189
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition: qtoolbutton.h:59
int duration() const
QWidget * leftWidget
Definition: qtabbar_p.h:118
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
bool event(QEvent *event)
Reimplemented Function
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
int scrollOffset
Definition: qtabbar_p.h:91
void makeVisible(int index)
Definition: qtabbar.cpp:585
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60