From 6797433e39be6e930a397f50ecb420e2ed588a20 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sat, 19 Apr 2014 18:47:44 +0200 Subject: [PATCH] [ComboTabBar] Fixed tabAt() on scroll buttons --- src/lib/tabwidget/combotabbar.cpp | 14 ++++++-------- src/lib/tabwidget/combotabbar.h | 5 +++++ src/lib/tabwidget/tabbar.cpp | 19 +++++++++++-------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/lib/tabwidget/combotabbar.cpp b/src/lib/tabwidget/combotabbar.cpp index b30b0cc1b..02103f5f2 100644 --- a/src/lib/tabwidget/combotabbar.cpp +++ b/src/lib/tabwidget/combotabbar.cpp @@ -215,26 +215,24 @@ QRect ComboTabBar::tabRect(int index) const int ComboTabBar::tabAt(const QPoint &pos) const { - int index = m_pinnedTabBarWidget->tabAt(m_pinnedTabBarWidget->mapFromParent(pos)); + if (!qobject_cast(QApplication::widgetAt(mapToGlobal(pos)))) + return -1; - if (index != -1) { + int index = m_pinnedTabBarWidget->tabAt(m_pinnedTabBarWidget->mapFromParent(pos)); + if (index != -1) return index; - } index = m_mainTabBarWidget->tabAt(m_mainTabBarWidget->mapFromParent(pos)); - - if (index != -1) { + if (index != -1) index += pinnedTabsCount(); - } return index; } bool ComboTabBar::emptyArea(const QPoint &pos) const { - if (tabAt(pos) != -1) { + if (tabAt(pos) != -1) return false; - } return qobject_cast(QApplication::widgetAt(mapToGlobal(pos))); } diff --git a/src/lib/tabwidget/combotabbar.h b/src/lib/tabwidget/combotabbar.h index ad1d7119d..2765f24bd 100644 --- a/src/lib/tabwidget/combotabbar.h +++ b/src/lib/tabwidget/combotabbar.h @@ -69,7 +69,12 @@ public: void setTabTextColor(int index, const QColor &color); QRect tabRect(int index) const; + + // Returns tab index at pos, or -1 int tabAt(const QPoint &pos) const; + + // Returns true if there is an empty area at pos + // (returns false if there are buttons or other widgets on the pos) bool emptyArea(const QPoint &pos) const; int mainTabBarCurrentIndex() const; diff --git a/src/lib/tabwidget/tabbar.cpp b/src/lib/tabwidget/tabbar.cpp index 52f80fbf6..1610ad7d2 100644 --- a/src/lib/tabwidget/tabbar.cpp +++ b/src/lib/tabwidget/tabbar.cpp @@ -644,14 +644,17 @@ void TabBar::mouseReleaseEvent(QMouseEvent* event) return; } - int id = tabAt(event->pos()); - if (id != -1 && event->button() == Qt::MiddleButton) { - m_tabWidget->closeTab(id); - return; - } - if (id == -1 && event->button() == Qt::MiddleButton) { - m_tabWidget->addView(QUrl(), Qz::NT_SelectedTabAtTheEnd, true); - return; + if (event->button() == Qt::MiddleButton) { + if (emptyArea(event->pos())) { + m_tabWidget->addView(QUrl(), Qz::NT_SelectedTabAtTheEnd, true); + return; + } + + int id = tabAt(event->pos()); + if (id != -1) { + m_tabWidget->closeTab(id); + return; + } } ComboTabBar::mouseReleaseEvent(event);