| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** 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 are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department 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 <qtimeline.h>
|
|---|
| 62 | #include <qhash.h>
|
|---|
| 63 | #include <qdebug.h>
|
|---|
| 64 |
|
|---|
| 65 | #ifndef QT_NO_TABBAR
|
|---|
| 66 |
|
|---|
| 67 | #define ANIMATION_DURATION 250
|
|---|
| 68 |
|
|---|
| 69 | #include <qstyleoption.h>
|
|---|
| 70 |
|
|---|
| 71 | QT_BEGIN_NAMESPACE
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | class QTabBarPrivate : public QWidgetPrivate
|
|---|
| 75 | {
|
|---|
| 76 | Q_DECLARE_PUBLIC(QTabBar)
|
|---|
| 77 | public:
|
|---|
| 78 | QTabBarPrivate()
|
|---|
| 79 | :currentIndex(-1), pressedIndex(-1),
|
|---|
| 80 | shape(QTabBar::RoundedNorth),
|
|---|
| 81 | layoutDirty(false), drawBase(true), scrollOffset(0), expanding(true), closeButtonOnTabs(false), selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false) {}
|
|---|
| 82 |
|
|---|
| 83 | int currentIndex;
|
|---|
| 84 | int pressedIndex;
|
|---|
| 85 | QTabBar::Shape shape;
|
|---|
| 86 | bool layoutDirty;
|
|---|
| 87 | bool drawBase;
|
|---|
| 88 | int scrollOffset;
|
|---|
| 89 |
|
|---|
| 90 | struct Tab {
|
|---|
| 91 | inline Tab(const QIcon &ico, const QString &txt)
|
|---|
| 92 | : enabled(true)
|
|---|
| 93 | , shortcutId(0)
|
|---|
| 94 | , text(txt)
|
|---|
| 95 | , icon(ico)
|
|---|
| 96 | , leftWidget(0)
|
|---|
| 97 | , rightWidget(0)
|
|---|
| 98 | , lastTab(-1)
|
|---|
| 99 | , timeLine(0)
|
|---|
| 100 | , dragOffset(0)
|
|---|
| 101 | , hidLeft(false)
|
|---|
| 102 | , hidRight(false)
|
|---|
| 103 | {}
|
|---|
| 104 | bool enabled;
|
|---|
| 105 | int shortcutId;
|
|---|
| 106 | QString text;
|
|---|
| 107 | #ifndef QT_NO_TOOLTIP
|
|---|
| 108 | QString toolTip;
|
|---|
| 109 | #endif
|
|---|
| 110 | #ifndef QT_NO_WHATSTHIS
|
|---|
| 111 | QString whatsThis;
|
|---|
| 112 | #endif
|
|---|
| 113 | QIcon icon;
|
|---|
| 114 | QRect rect;
|
|---|
| 115 | QRect minRect;
|
|---|
| 116 | QRect maxRect;
|
|---|
| 117 |
|
|---|
| 118 | QColor textColor;
|
|---|
| 119 | QVariant data;
|
|---|
| 120 | QWidget *leftWidget;
|
|---|
| 121 | QWidget *rightWidget;
|
|---|
| 122 | int lastTab;
|
|---|
| 123 |
|
|---|
| 124 | QTimeLine *timeLine;
|
|---|
| 125 | int dragOffset;
|
|---|
| 126 | QPixmap animatingCache;
|
|---|
| 127 | bool hidLeft;
|
|---|
| 128 | bool hidRight;
|
|---|
| 129 |
|
|---|
| 130 | void makeTimeLine(QWidget *q) {
|
|---|
| 131 | if (timeLine)
|
|---|
| 132 | return;
|
|---|
| 133 | timeLine = new QTimeLine(ANIMATION_DURATION, q);
|
|---|
| 134 | q->connect(timeLine, SIGNAL(frameChanged(int)), q, SLOT(_q_moveTab(int)));
|
|---|
| 135 | q->connect(timeLine, SIGNAL(finished()), q, SLOT(_q_moveTabFinished()));
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | void hideWidgets() {
|
|---|
| 139 | if (!hidRight && rightWidget) {
|
|---|
| 140 | hidRight = rightWidget->isVisible();
|
|---|
| 141 | rightWidget->hide();
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | if (!hidLeft && leftWidget) {
|
|---|
| 145 | hidLeft = leftWidget->isVisible();
|
|---|
| 146 | leftWidget->hide();
|
|---|
| 147 | }
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | void unHideWidgets() {
|
|---|
| 151 | if (leftWidget && hidLeft)
|
|---|
| 152 | leftWidget->show();
|
|---|
| 153 | hidLeft = false;
|
|---|
| 154 | if (rightWidget && hidRight)
|
|---|
| 155 | rightWidget->show();
|
|---|
| 156 | hidRight = false;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | };
|
|---|
| 160 | QList<Tab> tabList;
|
|---|
| 161 | QHash<QTimeLine*, int> animations;
|
|---|
| 162 |
|
|---|
| 163 | int calculateNewPosition(int from, int to, int index) const;
|
|---|
| 164 | void slide(int from, int to);
|
|---|
| 165 | void init();
|
|---|
| 166 | int extraWidth() const;
|
|---|
| 167 |
|
|---|
| 168 | Tab *at(int index);
|
|---|
| 169 | const Tab *at(int index) const;
|
|---|
| 170 |
|
|---|
| 171 | int indexAtPos(const QPoint &p) const;
|
|---|
| 172 |
|
|---|
| 173 | inline bool validIndex(int index) const { return index >= 0 && index < tabList.count(); }
|
|---|
| 174 |
|
|---|
| 175 | QSize minimumTabSizeHint(int index);
|
|---|
| 176 |
|
|---|
| 177 | QToolButton* rightB; // right or bottom
|
|---|
| 178 | QToolButton* leftB; // left or top
|
|---|
| 179 |
|
|---|
| 180 | void _q_scrollTabs();
|
|---|
| 181 | void _q_closeTab();
|
|---|
| 182 | void _q_moveTab(int);
|
|---|
| 183 | void _q_moveTabFinished();
|
|---|
| 184 | void _q_moveTabFinished(int offset);
|
|---|
| 185 | QRect hoverRect;
|
|---|
| 186 |
|
|---|
| 187 | void grabCache(int start, int end, bool unhide);
|
|---|
| 188 | void refresh();
|
|---|
| 189 | void layoutTabs();
|
|---|
| 190 | void layoutWidgets(int index = -1);
|
|---|
| 191 | void layoutTab(int index);
|
|---|
| 192 | void updateMacBorderMetrics();
|
|---|
| 193 |
|
|---|
| 194 | void makeVisible(int index);
|
|---|
| 195 | QSize iconSize;
|
|---|
| 196 | Qt::TextElideMode elideMode;
|
|---|
| 197 | bool useScrollButtons;
|
|---|
| 198 |
|
|---|
| 199 | bool expanding;
|
|---|
| 200 | bool closeButtonOnTabs;
|
|---|
| 201 | QTabBar::SelectionBehavior selectionBehaviorOnRemove;
|
|---|
| 202 |
|
|---|
| 203 | QPoint dragStartPosition;
|
|---|
| 204 | bool paintWithOffsets;
|
|---|
| 205 | bool movable;
|
|---|
| 206 | bool dragInProgress;
|
|---|
| 207 | bool documentMode;
|
|---|
| 208 |
|
|---|
| 209 | // shared by tabwidget and qtabbar
|
|---|
| 210 | static void initStyleBaseOption(QStyleOptionTabBarBaseV2 *optTabBase, QTabBar *tabbar, QSize size)
|
|---|
| 211 | {
|
|---|
| 212 | QStyleOptionTab tabOverlap;
|
|---|
| 213 | tabOverlap.shape = tabbar->shape();
|
|---|
| 214 | int overlap = tabbar->style()->pixelMetric(QStyle::PM_TabBarBaseOverlap, &tabOverlap, tabbar);
|
|---|
| 215 | QWidget *theParent = tabbar->parentWidget();
|
|---|
| 216 | optTabBase->init(tabbar);
|
|---|
| 217 | optTabBase->shape = tabbar->shape();
|
|---|
| 218 | optTabBase->documentMode = tabbar->documentMode();
|
|---|
| 219 | if (theParent && overlap > 0) {
|
|---|
| 220 | QRect rect;
|
|---|
| 221 | switch (tabOverlap.shape) {
|
|---|
| 222 | case QTabBar::RoundedNorth:
|
|---|
| 223 | case QTabBar::TriangularNorth:
|
|---|
| 224 | rect.setRect(0, size.height()-overlap, size.width(), overlap);
|
|---|
| 225 | break;
|
|---|
| 226 | case QTabBar::RoundedSouth:
|
|---|
| 227 | case QTabBar::TriangularSouth:
|
|---|
| 228 | rect.setRect(0, 0, size.width(), overlap);
|
|---|
| 229 | break;
|
|---|
| 230 | case QTabBar::RoundedEast:
|
|---|
| 231 | case QTabBar::TriangularEast:
|
|---|
| 232 | rect.setRect(0, 0, overlap, size.height());
|
|---|
| 233 | break;
|
|---|
| 234 | case QTabBar::RoundedWest:
|
|---|
| 235 | case QTabBar::TriangularWest:
|
|---|
| 236 | rect.setRect(size.width() - overlap, 0, overlap, size.height());
|
|---|
| 237 | break;
|
|---|
| 238 | }
|
|---|
| 239 | optTabBase->rect = rect;
|
|---|
| 240 | }
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | };
|
|---|
| 244 |
|
|---|
| 245 | class CloseButton : public QAbstractButton
|
|---|
| 246 | {
|
|---|
| 247 | Q_OBJECT
|
|---|
| 248 |
|
|---|
| 249 | public:
|
|---|
| 250 | CloseButton(QWidget *parent = 0);
|
|---|
| 251 |
|
|---|
| 252 | QSize sizeHint() const;
|
|---|
| 253 | inline QSize minimumSizeHint() const
|
|---|
| 254 | { return sizeHint(); }
|
|---|
| 255 | void enterEvent(QEvent *event);
|
|---|
| 256 | void leaveEvent(QEvent *event);
|
|---|
| 257 | void paintEvent(QPaintEvent *event);
|
|---|
| 258 | };
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 | QT_END_NAMESPACE
|
|---|
| 262 |
|
|---|
| 263 | #endif
|
|---|
| 264 |
|
|---|
| 265 | #endif
|
|---|