From b4f3b5962e196774b3cdc3975d2909e000c8bc75 Mon Sep 17 00:00:00 2001 From: nowrep Date: Mon, 23 Dec 2013 21:24:41 +0100 Subject: [PATCH] [ComboTabBar] Fix tabAt when pos is on right/left scroll buttons --- src/lib/tools/combotabbar.cpp | 22 ++++++++++++++++------ src/lib/tools/combotabbar.h | 2 ++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/lib/tools/combotabbar.cpp b/src/lib/tools/combotabbar.cpp index 5ab692415..3f967a93c 100644 --- a/src/lib/tools/combotabbar.cpp +++ b/src/lib/tools/combotabbar.cpp @@ -197,17 +197,18 @@ QRect ComboTabBar::tabRect(int index) const int ComboTabBar::tabAt(const QPoint &pos) const { - QWidget* that = const_cast(this); - int index = -1; - if (m_mainTabBarWidget->rect().contains(m_mainTabBarWidget->mapFromGlobal(QCursor::pos()))) { - index = m_mainTabBar->tabAt(m_mainTabBar->mapFrom(that, pos)); + + const QPoint globalPos = mapToGlobal(pos); + + if (m_mainTabBarWidget->hasTabBarAt(m_mainTabBarWidget->mapFromGlobal(globalPos))) { + index = m_mainTabBar->tabAt(m_mainTabBar->mapFromGlobal(globalPos)); if (index != -1) { index += pinnedTabsCount(); } } - else if (m_pinnedTabBarWidget->rect().contains(m_pinnedTabBarWidget->mapFromGlobal(QCursor::pos()))) { - index = m_pinnedTabBar->tabAt(m_pinnedTabBar->mapFrom(that, pos)); + else if (m_pinnedTabBarWidget->hasTabBarAt(m_pinnedTabBarWidget->mapFromGlobal(globalPos))) { + index = m_pinnedTabBar->tabAt(m_pinnedTabBar->mapFromGlobal(globalPos)); } return index; @@ -1365,6 +1366,15 @@ void TabBarScrollWidget::setUsesScrollButtons(bool useButtons) } } +bool TabBarScrollWidget::hasTabBarAt(const QPoint &pos) const +{ + if (m_leftScrollButton->rect().contains(pos) || m_rightScrollButton->rect().contains(pos)) { + return false; + } + + return m_scrollArea->rect().contains(pos); +} + void TabBarScrollWidget::setContainersName(const QString &name) { m_leftContainer->setObjectName(name); diff --git a/src/lib/tools/combotabbar.h b/src/lib/tools/combotabbar.h index 499ec9c51..31568316a 100644 --- a/src/lib/tools/combotabbar.h +++ b/src/lib/tools/combotabbar.h @@ -265,6 +265,8 @@ public: bool usesScrollButtons() const; void setUsesScrollButtons(bool useButtons); + bool hasTabBarAt(const QPoint &pos) const; + void setContainersName(const QString &name); void enableBluredBackground(bool enable);