1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-24 04:36:34 +01:00

ComboTabBar: Add possibility to change base color from stylesheets

This commit is contained in:
David Rosca 2018-01-08 16:49:48 +01:00
parent c62b41d3d7
commit 50d1bb6d96
4 changed files with 36 additions and 2 deletions

View File

@ -1,6 +1,6 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "proxystyle.h"
#include "combotabbar.h"
#include <QPainter>
#include <QStyleOption>
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<TabBarHelper*>(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();

View File

@ -1,6 +1,6 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
*
* 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;

View File

@ -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);

View File

@ -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;