diff options
Diffstat (limited to 'src/widgets/widgets/qtabbar.cpp')
-rw-r--r-- | src/widgets/widgets/qtabbar.cpp | 141 |
1 files changed, 122 insertions, 19 deletions
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index 789ec2f6fd..982cc40b3d 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -1,40 +1,32 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtWidgets module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -588,6 +580,16 @@ void QTabBarPrivate::makeVisible(int index) } } +void QTabBarPrivate::killSwitchTabTimer() +{ + Q_Q(QTabBar); + if (switchTabTimerId) { + q->killTimer(switchTabTimerId); + switchTabTimerId = 0; + } + switchTabCurrentIndex = -1; +} + void QTabBarPrivate::layoutTab(int index) { Q_Q(QTabBar); @@ -632,6 +634,14 @@ void QTabBarPrivate::layoutWidgets(int start) } } +void QTabBarPrivate::autoHideTabs() +{ + Q_Q(QTabBar); + + if (autoHide) + q->setVisible(q->count() > 1); +} + void QTabBarPrivate::_q_closeTab() { Q_Q(QTabBar); @@ -861,6 +871,7 @@ int QTabBar::insertTab(int index, const QIcon& icon, const QString &text) } tabInserted(index); + d->autoHideTabs(); return index; } @@ -936,6 +947,7 @@ void QTabBar::removeTab(int index) setCurrentIndex(d->currentIndex - 1); } d->refresh(); + d->autoHideTabs(); tabRemoved(index); } } @@ -1517,6 +1529,26 @@ bool QTabBar::event(QEvent *event) } else if (event->type() == QEvent::Move) { d->updateMacBorderMetrics(); return QWidget::event(event); + +#ifndef QT_NO_DRAGANDDROP + } else if (event->type() == QEvent::DragEnter) { + if (d->changeCurrentOnDrag) + event->accept(); + } else if (event->type() == QEvent::DragMove) { + if (d->changeCurrentOnDrag) { + const int tabIndex = tabAt(static_cast<QDragMoveEvent *>(event)->pos()); + if (isTabEnabled(tabIndex) && d->switchTabCurrentIndex != tabIndex) { + d->switchTabCurrentIndex = tabIndex; + if (d->switchTabTimerId) + killTimer(d->switchTabTimerId); + d->switchTabTimerId = startTimer(style()->styleHint(QStyle::SH_TabBar_ChangeCurrentDelay)); + } + event->ignore(); + } + } else if (event->type() == QEvent::DragLeave || event->type() == QEvent::Drop) { + d->killSwitchTabTimer(); + event->ignore(); +#endif } return QWidget::event(event); } @@ -2035,6 +2067,21 @@ void QTabBar::changeEvent(QEvent *event) } /*! + \reimp +*/ +void QTabBar::timerEvent(QTimerEvent *event) +{ + Q_D(QTabBar); + if (event->timerId() == d->switchTabTimerId) { + killTimer(d->switchTabTimerId); + d->switchTabTimerId = 0; + setCurrentIndex(d->switchTabCurrentIndex); + d->switchTabCurrentIndex = -1; + } + QWidget::timerEvent(event); +} + +/*! \property QTabBar::elideMode \brief how to elide text in the tab bar \since 4.2 @@ -2267,6 +2314,62 @@ void QTabBar::setDocumentMode(bool enabled) } /*! + \property QTabBar::autoHide + \brief If true, the tab bar is automatically hidden when it contains less + than 2 tabs. + \since 5.4 + + By default, this property is false. + + \sa QWidget::visible +*/ + +bool QTabBar::autoHide() const +{ + Q_D(const QTabBar); + return d->autoHide; +} + +void QTabBar::setAutoHide(bool hide) +{ + Q_D(QTabBar); + if (d->autoHide == hide) + return; + + d->autoHide = hide; + if (hide) + d->autoHideTabs(); + else + setVisible(true); +} + +/*! + \property QTabBar::changeCurrentOnDrag + \brief If true, then the current tab is automatically changed when dragging + over the tabbar. + \since 5.4 + + \note You should also set acceptDrops property to true to make this feature + work. + + By default, this property is false. +*/ + +bool QTabBar::changeCurrentOnDrag() const +{ + Q_D(const QTabBar); + return d->changeCurrentOnDrag; +} + +void QTabBar::setChangeCurrentOnDrag(bool change) +{ + Q_D(QTabBar); + d->changeCurrentOnDrag = change; + if (!change) + d->killSwitchTabTimer(); +} + +/*! Sets \a widget on the tab \a index. The widget is placed on the left or right hand side depending upon the \a position. \since 4.5 |