Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtabbar_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QTABBAR_P_H
5#define QTABBAR_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19#include "qtabbar.h"
20#include "private/qwidget_p.h"
21
22#include <qicon.h>
23#include <qtoolbutton.h>
24#include <qdebug.h>
25#if QT_CONFIG(animation)
26#include <qvariantanimation.h>
27#endif
28
29#define ANIMATION_DURATION 250
30
31#include <qstyleoption.h>
32#include <utility>
33
35
37
39{
40public:
41 explicit QMovableTabWidget(QWidget *parent = nullptr);
42 void setPixmap(const QPixmap &pixmap);
43
44protected:
45 void paintEvent(QPaintEvent *e) override;
46
47private:
48 QPixmap m_pixmap;
49};
50
51class Q_WIDGETS_EXPORT QTabBarPrivate : public QWidgetPrivate
52{
53 Q_DECLARE_PUBLIC(QTabBar)
54public:
56 : layoutDirty(false), drawBase(true), elideModeSetByUser(false), useScrollButtons(false),
57 useScrollButtonsSetByUser(false), expanding(true), closeButtonOnTabs(false),
58 paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false),
59 autoHide(false), changeCurrentOnDrag(false)
60 {}
62 {
63 qDeleteAll(tabList);
64 }
65
68 QPoint mousePosition = {-1, -1};
69#if QT_CONFIG(wheelevent)
70 QPoint accumulatedAngleDelta;
71#endif
73 QToolButton* rightB = nullptr; // right or bottom
74 QToolButton* leftB = nullptr; // left or top
75 QMovableTabWidget *movingTab = nullptr;
76 int hoverIndex = -1;
77 int switchTabCurrentIndex = -1;
78 int switchTabTimerId = 0;
82 Qt::MouseButtons mouseButtons = Qt::NoButton;
83
84 int currentIndex = -1;
85 int pressedIndex = -1;
86 int firstVisible = 0;
87 int lastVisible = -1;
88 int scrollOffset = 0;
89
90 bool layoutDirty : 1;
91 bool drawBase : 1;
95 bool expanding : 1;
98 bool movable : 1;
100 bool documentMode : 1;
101 bool autoHide : 1;
103
104 struct Tab {
105 inline Tab(const QIcon &ico, const QString &txt)
106 : text(txt), icon(ico), enabled(true), visible(true)
107 {
108 }
109 /*
110 Tabs are managed by instance; they are not the same even
111 if all properties are the same.
112 */
114
116#if QT_CONFIG(tooltip)
117 QString toolTip;
118#endif
119#if QT_CONFIG(whatsthis)
120 QString whatsThis;
121#endif
122#if QT_CONFIG(accessibility)
123 QString accessibleName;
124#endif
129
132 QWidget *leftWidget = nullptr;
133 QWidget *rightWidget = nullptr;
134 int shortcutId = 0;
135 int lastTab = -1;
136 int dragOffset = 0;
139
140#if QT_CONFIG(animation)
141 struct TabBarAnimation : public QVariantAnimation {
142 TabBarAnimation(Tab *t, QTabBarPrivate *_priv) : tab(t), priv(_priv)
144
145 void updateCurrentValue(const QVariant &current) override;
146
147 void updateState(State newState, State) override;
148 private:
149 //these are needed for the callbacks
150 Tab *tab;
152 };
153 std::unique_ptr<TabBarAnimation> animation;
154
155 void startAnimation(QTabBarPrivate *priv, int duration) {
156 if (!priv->isAnimated()) {
157 priv->moveTabFinished(priv->tabList.indexOf(this));
158 return;
159 }
160 if (!animation)
161 animation = std::make_unique<TabBarAnimation>(this, priv);
162 animation->setStartValue(dragOffset);
164 animation->setDuration(duration);
165 animation->start();
166 }
167#else
168 void startAnimation(QTabBarPrivate *priv, int duration)
169 { Q_UNUSED(duration); priv->moveTabFinished(priv->tabList.indexOf(this)); }
170#endif // animation
171 };
172 QList<Tab*> tabList;
173 mutable QHash<QString, QSize> textSizes;
174
175 void calculateFirstLastVisible(int index, bool visible, bool remove);
176 int selectNewCurrentIndexFrom(int currentIndex);
177 int calculateNewPosition(int from, int to, int index) const;
178 void slide(int from, int to);
179 void init();
180
181 inline Tab *at(int index) { return tabList.value(index, nullptr); }
182 inline const Tab *at(int index) const { return tabList.value(index, nullptr); }
183
184 int indexAtPos(const QPoint &p) const;
185
186 inline bool isAnimated() const { Q_Q(const QTabBar); return q->style()->styleHint(QStyle::SH_Widget_Animation_Duration, nullptr, q) > 0; }
187 inline bool validIndex(int index) const { return index >= 0 && index < tabList.size(); }
188 void setCurrentNextEnabledIndex(int offset);
189
190 void scrollTabs();
191 void closeTab();
192 void moveTab(int index, int offset);
193 void moveTabFinished(int index);
194
195 void refresh();
196 void layoutTabs();
197 void layoutWidgets(int start = 0);
198 void layoutTab(int index);
199 void updateMacBorderMetrics();
201 void setupMovableTab();
202 void autoHideTabs();
203 QRect normalizedScrollRect(int index = -1);
204 int hoveredTabIndex() const;
205
206 void initBasicStyleOption(QStyleOptionTab *option, int tabIndex) const;
207
208 void makeVisible(int index);
209
210 // shared by tabwidget and qtabbar
211 static void initStyleBaseOption(QStyleOptionTabBarBase *optTabBase, QTabBar *tabbar, QSize size)
212 {
213 QStyleOptionTab tabOverlap;
214 tabOverlap.shape = tabbar->shape();
215 int overlap = tabbar->style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, &tabOverlap, tabbar);
216 QWidget *theParent = tabbar->parentWidget();
217 optTabBase->initFrom(tabbar);
218 optTabBase->shape = tabbar->shape();
219 optTabBase->documentMode = tabbar->documentMode();
220 if (theParent && overlap > 0) {
221 QRect rect;
222 switch (tabOverlap.shape) {
225 rect.setRect(0, size.height()-overlap, size.width(), overlap);
226 break;
229 rect.setRect(0, 0, size.width(), overlap);
230 break;
233 rect.setRect(0, 0, overlap, size.height());
234 break;
237 rect.setRect(size.width() - overlap, 0, overlap, size.height());
238 break;
239 }
240 optTabBase->rect = rect;
241 }
242 }
243
244 void killSwitchTabTimer();
245
246};
247
248constexpr inline bool verticalTabs(QTabBar::Shape shape) noexcept
249{
250 return shape == QTabBar::RoundedWest
251 || shape == QTabBar::RoundedEast
252 || shape == QTabBar::TriangularWest
253 || shape == QTabBar::TriangularEast;
254}
255
257
258#endif
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
void paintEvent(QPaintEvent *e) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
Definition qtabbar.cpp:67
void setPixmap(const QPixmap &pixmap)
Definition qtabbar.cpp:61
QMovableTabWidget(QWidget *parent=nullptr)
Definition qtabbar.cpp:56
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr void setRect(int x, int y, int w, int h) noexcept
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given widt...
Definition qrect.h:346
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
@ SH_Widget_Animation_Duration
Definition qstyle.h:700
@ PM_TabBarBaseOverlap
Definition qstyle.h:443
bool useScrollButtonsSetByUser
Definition qtabbar_p.h:94
bool changeCurrentOnDrag
Definition qtabbar_p.h:102
QRect hoverRect
Definition qtabbar_p.h:66
Tab * at(int index)
Definition qtabbar_p.h:181
bool validIndex(int index) const
Definition qtabbar_p.h:187
bool elideModeSetByUser
Definition qtabbar_p.h:92
bool closeButtonOnTabs
Definition qtabbar_p.h:96
QPoint dragStartPosition
Definition qtabbar_p.h:67
bool isAnimated() const
Definition qtabbar_p.h:186
bool useScrollButtons
Definition qtabbar_p.h:93
bool paintWithOffsets
Definition qtabbar_p.h:97
QHash< QString, QSize > textSizes
Definition qtabbar_p.h:173
const Tab * at(int index) const
Definition qtabbar_p.h:182
static void initStyleBaseOption(QStyleOptionTabBarBase *optTabBase, QTabBar *tabbar, QSize size)
Definition qtabbar_p.h:211
bool dragInProgress
Definition qtabbar_p.h:99
QList< Tab * > tabList
Definition qtabbar_p.h:172
bool isTabInMacUnifiedToolbarArea() const
The QTabBar class provides a tab bar, e.g.
Definition qtabbar.h:19
SelectionBehavior
Definition qtabbar.h:52
@ SelectRightTab
Definition qtabbar.h:54
Shape
This enum type lists the built-in shapes supported by QTabBar.
Definition qtabbar.h:42
@ RoundedSouth
Definition qtabbar.h:42
@ RoundedNorth
Definition qtabbar.h:42
@ TriangularEast
Definition qtabbar.h:43
@ RoundedWest
Definition qtabbar.h:42
@ TriangularSouth
Definition qtabbar.h:43
@ RoundedEast
Definition qtabbar.h:42
@ TriangularWest
Definition qtabbar.h:43
@ TriangularNorth
Definition qtabbar.h:43
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition qtoolbutton.h:20
\inmodule QtCore
void setStartValue(const QVariant &value)
void setDuration(int msecs)
void setEndValue(const QVariant &value)
\inmodule QtCore
Definition qvariant.h:65
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
QString text
qDeleteAll(list.begin(), list.end())
rect
[4]
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
Combined button and popup list for selecting options.
@ NoButton
Definition qnamespace.h:57
TextElideMode
Definition qnamespace.h:188
@ ElideNone
Definition qnamespace.h:192
static const QMetaObjectPrivate * priv(const uint *data)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLuint start
GLenum GLuint GLintptr offset
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
GLuint GLenum option
constexpr bool verticalTabs(QTabBar::Shape shape) noexcept
Definition qtabbar_p.h:248
#define QT_REQUIRE_CONFIG(feature)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
#define Q_UNUSED(x)
unsigned int uint
Definition qtypes.h:34
settings remove("monkey")
QPropertyAnimation animation
[0]
animation setEasingCurve(QEasingCurve::InOutQuad)
Text files * txt
widget render & pixmap
Tab(const QIcon &ico, const QString &txt)
Definition qtabbar_p.h:105
void startAnimation(QTabBarPrivate *priv, int duration)
Definition qtabbar_p.h:168