From 50d1bb6d9676ad8919995f7231aeb33060d015c0 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 8 Jan 2018 16:49:48 +0100 Subject: [PATCH] ComboTabBar: Add possibility to change base color from stylesheets --- src/lib/app/proxystyle.cpp | 20 +++++++++++++++++++- src/lib/app/proxystyle.h | 3 ++- src/lib/tabwidget/combotabbar.cpp | 10 ++++++++++ src/lib/tabwidget/combotabbar.h | 5 +++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/lib/app/proxystyle.cpp b/src/lib/app/proxystyle.cpp index fdcef5bcc..2b8f88560 100644 --- a/src/lib/app/proxystyle.cpp +++ b/src/lib/app/proxystyle.cpp @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,6 +16,10 @@ * along with this program. If not, see . * ============================================================ */ #include "proxystyle.h" +#include "combotabbar.h" + +#include +#include ProxyStyle::ProxyStyle() : QProxyStyle() @@ -56,6 +60,20 @@ int ProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, cons } } +void ProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const +{ + if (element == PE_FrameTabBarBase) { + TabBarHelper *tabBar = qobject_cast(option->styleObject); + if (tabBar && tabBar->baseColor().isValid()) { + painter->setPen(QPen(tabBar->baseColor(), 0)); + painter->drawLine(option->rect.topLeft(), option->rect.topRight()); + return; + } + } + + QProxyStyle::drawPrimitive(element, option, painter, widget); +} + QString ProxyStyle::name() const { return baseStyle()->objectName(); diff --git a/src/lib/app/proxystyle.h b/src/lib/app/proxystyle.h index 4473e2eff..f2b3513e4 100644 --- a/src/lib/app/proxystyle.h +++ b/src/lib/app/proxystyle.h @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ public: int styleHint(StyleHint hint, const QStyleOption* option = 0, const QWidget* widget = 0, QStyleHintReturn* returnData = 0) const; int pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const; + void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const override; QString name() const; diff --git a/src/lib/tabwidget/combotabbar.cpp b/src/lib/tabwidget/combotabbar.cpp index b8e7a4467..73f2c57e5 100644 --- a/src/lib/tabwidget/combotabbar.cpp +++ b/src/lib/tabwidget/combotabbar.cpp @@ -1015,6 +1015,16 @@ void TabBarHelper::setTabPadding(int padding) m_tabPadding = padding; } +QColor TabBarHelper::baseColor() const +{ + return m_baseColor; +} + +void TabBarHelper::setBaseColor(const QColor &color) +{ + m_baseColor = color; +} + void TabBarHelper::setTabButton(int index, QTabBar::ButtonPosition position, QWidget* widget) { QTabBar::setTabButton(index, position, widget); diff --git a/src/lib/tabwidget/combotabbar.h b/src/lib/tabwidget/combotabbar.h index 96c22c98d..5e7d6593a 100644 --- a/src/lib/tabwidget/combotabbar.h +++ b/src/lib/tabwidget/combotabbar.h @@ -229,6 +229,7 @@ class FALKON_EXPORT TabBarHelper : public QTabBar { Q_OBJECT Q_PROPERTY(int tabPadding READ tabPadding WRITE setTabPadding) + Q_PROPERTY(QColor baseColor READ baseColor WRITE setBaseColor) public: explicit TabBarHelper(bool isPinnedTabBar, ComboTabBar* comboTabBar); @@ -236,6 +237,9 @@ public: int tabPadding() const; void setTabPadding(int padding); + QColor baseColor() const; + void setBaseColor(const QColor &color); + void setTabButton(int index, QTabBar::ButtonPosition position, QWidget* widget); QSize tabSizeHint(int index) const; @@ -277,6 +281,7 @@ private: QScrollArea* m_scrollArea; int m_tabPadding = -1; + QColor m_baseColor; int m_pressedIndex; bool m_dragInProgress; QPoint m_dragStartPosition;