diff options
author | Ivan Komissarov <ABBAPOH@gmail.com> | 2012-07-10 15:57:36 +0400 |
---|---|---|
committer | Ivan Komissarov <ABBAPOH@gmail.com> | 2014-08-06 15:19:22 +0200 |
commit | 54ca39afec6c3a175da085a704772b28f42bc274 (patch) | |
tree | ddd4b9baebad197794dd3cd88908b719fa0ed260 /src/widgets/widgets/qtabbar.cpp | |
parent | e3e2e6877499ac6a151691e79d51850b9dad8941 (diff) |
Add the QTabBar::changeCurrentOnDrag property.
This property indicates that the current tab will change whilst dragging
over the tabbar
[ChangeLog][QtWidgets][QTabBar] Added changeCurrentOnDrag property.
Change-Id: Ib7d5a7613c9cd8432b84c523f66c02cd6c3c3c81
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets/widgets/qtabbar.cpp')
-rw-r--r-- | src/widgets/widgets/qtabbar.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index e8fdc65711..1d33a9bf3a 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -588,6 +588,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); @@ -1527,6 +1537,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); } @@ -2045,6 +2075,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 @@ -2307,6 +2352,32 @@ void QTabBar::setAutoHide(bool hide) } /*! + \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 |