Falkon Develop
Cross-platform Qt-based web browser
proxystyle.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "proxystyle.h"
19#include "combotabbar.h"
20
21#include <QPainter>
22#include <QStyleOption>
23
25 : QProxyStyle()
26 , m_TabBarTabHSpace(-1)
27{
28}
29
30int ProxyStyle::styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const
31{
32 switch (hint) {
33 case QStyle::SH_Menu_Scrollable:
34 return int(true);
35
36 case QStyle::SH_TabBar_Alignment:
37 return Qt::AlignLeft;
38
39 case QStyle::SH_TabBar_CloseButtonPosition:
40 if (qobject_cast<const TabBarHelper*>(widget)) {
41 return QTabBar::RightSide;
42 }
43 break;
44
45 default:
46 break;
47 }
48
49 return QProxyStyle::styleHint(hint, option, widget, returnData);
50}
51
52int ProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const
53{
54 switch (metric) {
55 case PM_TabBarTabHSpace:
56 if (m_TabBarTabHSpace == -1) {
57 m_TabBarTabHSpace = qMin(QProxyStyle::pixelMetric(PM_TabBarTabHSpace, option, widget), 14);
58 }
59 return m_TabBarTabHSpace;
60
61 default:
62 return QProxyStyle::pixelMetric(metric, option, widget);
63 }
64}
65
66void ProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
67{
68 if (element == PE_FrameTabBarBase) {
69 auto *tabBar = qobject_cast<TabBarHelper*>(option->styleObject);
70 if (tabBar && tabBar->baseColor().isValid()) {
71 painter->setPen(QPen(tabBar->baseColor(), 0));
72 painter->drawLine(option->rect.topLeft(), option->rect.topRight());
73 return;
74 }
75 }
76
77 QProxyStyle::drawPrimitive(element, option, painter, widget);
78}
79
80QString ProxyStyle::name() const
81{
82 return baseStyle()->objectName();
83}
int styleHint(StyleHint hint, const QStyleOption *option=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const override
Definition: proxystyle.cpp:30
QString name() const
Definition: proxystyle.cpp:80
int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const override
Definition: proxystyle.cpp:52
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=nullptr) const override
Definition: proxystyle.cpp:66