diff options
author | Ivan Komissarov <ABBAPOH@gmail.com> | 2012-06-28 21:04:54 +0400 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-13 19:28:31 +0200 |
commit | 252bad7c589e03d3e12df02354b00a84d8e3159a (patch) | |
tree | 9e572c1704028e4c0d343c63801f4a5d0e8a9627 /src/widgets/widgets/qtabbar.cpp | |
parent | 91e86688fc119e1bb67fd40ab30101015ddb638b (diff) |
Add useful signals to QTabBar and QTabWidget
In this patch we introduce tabBarClicked and tabBarDoubleClicked to get
a finer grained information on the user interaction with the tab bar.
Done-with: kevin.ottens@kdab.com
Change-Id: I7be76a556ca09186e98f2e076fe2512d6c5e6773
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'src/widgets/widgets/qtabbar.cpp')
-rw-r--r-- | src/widgets/widgets/qtabbar.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index b975035dcf..aa7677869c 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -329,6 +329,26 @@ void QTabBar::initStyleOption(QStyleOptionTab *option, int tabIndex) const \sa moveTab() */ +/*! + \fn void QTabBar::tabBarClicked(int index) + + This signal is emitted when user clicks on a tab at an \a index. + + \a index is the index of a clicked tab, or -1 if no tab is under the cursor. + + \since 5.2 +*/ + +/*! + \fn void QTabBar::tabBarDoubleClicked(int index) + + This signal is emitted when the user double clicks on a tab at \a index. + + \a index refers to the tab clicked, or -1 if no tab is under the cursor. + + \since 5.2 +*/ + int QTabBarPrivate::extraWidth() const { Q_Q(const QTabBar); @@ -1703,11 +1723,37 @@ void QTabBarPrivate::moveTab(int index, int offset) q_func()->update(); } + +/*! + \reimp +*/ +void QTabBar::mouseDoubleClickEvent(QMouseEvent *event) +{ + Q_D(QTabBar); + + const QPoint pos = event->pos(); + const bool isEventInCornerButtons = (!d->leftB->isHidden() && d->leftB->geometry().contains(pos)) + || (!d->rightB->isHidden() && d->rightB->geometry().contains(pos)); + if (!isEventInCornerButtons) { + const int index = tabAt(pos); + emit tabBarDoubleClicked(index); + } +} + /*!\reimp */ void QTabBar::mousePressEvent(QMouseEvent *event) { Q_D(QTabBar); + + const QPoint pos = event->pos(); + const bool isEventInCornerButtons = (!d->leftB->isHidden() && d->leftB->geometry().contains(pos)) + || (!d->rightB->isHidden() && d->rightB->geometry().contains(pos)); + if (!isEventInCornerButtons) { + const int index = d->indexAtPos(pos); + emit tabBarClicked(index); + } + if (event->button() != Qt::LeftButton) { event->ignore(); return; |