From 246adbfb0bf9115241638bcbf2674940bb9432e7 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sun, 31 Dec 2017 23:11:25 +0100 Subject: [PATCH] ComboTabBar: Add support for drawing drop indicator It's just a solid line now, should be improved later. --- src/lib/tabwidget/combotabbar.cpp | 36 +++++++++++++++++++++++++++++++ src/lib/tabwidget/combotabbar.h | 13 +++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/lib/tabwidget/combotabbar.cpp b/src/lib/tabwidget/combotabbar.cpp index aa574581e..22608d74f 100644 --- a/src/lib/tabwidget/combotabbar.cpp +++ b/src/lib/tabwidget/combotabbar.cpp @@ -799,6 +799,17 @@ void ComboTabBar::setUsesScrollButtons(bool useButtons) m_mainTabBarWidget->setUsesScrollButtons(useButtons); } +void ComboTabBar::showDropIndicator(int index, DropIndicatorPosition position) +{ + localTabBar(index)->showDropIndicator(toLocalIndex(index), position); +} + +void ComboTabBar::clearDropIndicator() +{ + m_mainTabBar->clearDropIndicator(); + m_pinnedTabBar->clearDropIndicator(); +} + bool ComboTabBar::isDragInProgress() const { return m_mainTabBar->isDragInProgress() || m_pinnedTabBar->isDragInProgress(); @@ -1041,6 +1052,19 @@ void TabBarHelper::useFastTabSizeHint(bool enabled) m_useFastTabSizeHint = enabled; } +void TabBarHelper::showDropIndicator(int index, ComboTabBar::DropIndicatorPosition position) +{ + m_dropIndicatorIndex = index; + m_dropIndicatorPosition = position; + update(); +} + +void TabBarHelper::clearDropIndicator() +{ + m_dropIndicatorIndex = -1; + update(); +} + bool TabBarHelper::isDisplayedOnViewPort(int globalLeft, int globalRight) { bool isVisible = true; @@ -1209,6 +1233,18 @@ void TabBarHelper::paintEvent(QPaintEvent* event) p.drawControl(QStyle::CE_TabBarTab, tab); } + + // Draw drop indicator + if (m_dropIndicatorIndex != -1) { + p.setPen(QPen(palette().text(), 3)); + QRect r = tabRect(m_dropIndicatorIndex); + if (m_dropIndicatorPosition == ComboTabBar::BeforeTab) { + r.moveLeft(r.x() - 1); + p.drawLine(r.topLeft(), r.bottomLeft()); + } else { + p.drawLine(r.topRight(), r.bottomRight()); + } + } } void TabBarHelper::mousePressEvent(QMouseEvent* event) diff --git a/src/lib/tabwidget/combotabbar.h b/src/lib/tabwidget/combotabbar.h index ce567c621..cdb2aa695 100644 --- a/src/lib/tabwidget/combotabbar.h +++ b/src/lib/tabwidget/combotabbar.h @@ -52,6 +52,11 @@ public: ExtraReservedWidth }; + enum DropIndicatorPosition { + BeforeTab, + AfterTab + }; + explicit ComboTabBar(QWidget* parent = 0); int addTab(const QString &text); @@ -136,6 +141,9 @@ public: bool usesScrollButtons() const; void setUsesScrollButtons(bool useButtons); + void showDropIndicator(int index, DropIndicatorPosition position); + void clearDropIndicator(); + bool isDragInProgress() const; bool isScrollInProgress() const; bool isMainBarOverflowed() const; @@ -234,6 +242,9 @@ public: void setScrollArea(QScrollArea* scrollArea); void useFastTabSizeHint(bool enabled); + void showDropIndicator(int index, ComboTabBar::DropIndicatorPosition position); + void clearDropIndicator(); + bool isDisplayedOnViewPort(int globalLeft, int globalRight); bool isDragInProgress() const; @@ -266,6 +277,8 @@ private: bool m_activeTabBar; bool m_isPinnedTabBar; bool m_useFastTabSizeHint; + int m_dropIndicatorIndex = -1; + ComboTabBar::DropIndicatorPosition m_dropIndicatorPosition; }; class FALKON_EXPORT TabScrollBar : public QScrollBar