Skip to content

Commit 9a78215

Browse files
committed
Fork RDStyle to RDTweakedNativeStyle
* The idea is tha this style won't change the palette and will just do some minimal additions/changes to whatever the native style is, to work around some rough spots.
1 parent 6cedd37 commit 9a78215

File tree

7 files changed

+387
-231
lines changed

7 files changed

+387
-231
lines changed

qrenderdoc/Styles/RDStyle/RDStyle.cpp

Lines changed: 8 additions & 230 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <QPen>
2929
#include <QStyleOption>
3030

31-
RDStyle::RDStyle(ColorScheme scheme) : QProxyStyle()
31+
RDStyle::RDStyle(ColorScheme scheme) : RDTweakedNativeStyle()
3232
{
3333
}
3434

@@ -38,262 +38,40 @@ RDStyle::~RDStyle()
3838

3939
QRect RDStyle::subElementRect(SubElement element, const QStyleOption *opt, const QWidget *widget) const
4040
{
41-
QRect ret = QProxyStyle::subElementRect(element, opt, widget);
42-
43-
if(element == QStyle::SE_DockWidgetCloseButton || element == QStyle::SE_DockWidgetFloatButton)
44-
{
45-
int width = pixelMetric(QStyle::PM_TabCloseIndicatorWidth, opt, widget);
46-
int height = pixelMetric(QStyle::PM_TabCloseIndicatorHeight, opt, widget);
47-
48-
QPoint c = ret.center();
49-
ret.setSize(QSize(width, height));
50-
ret.moveCenter(c);
51-
}
52-
53-
return ret;
41+
return RDTweakedNativeStyle::subElementRect(element, opt, widget);
5442
}
5543

5644
QSize RDStyle::sizeFromContents(ContentsType type, const QStyleOption *opt, const QSize &size,
5745
const QWidget *widget) const
5846
{
59-
QSize sz = size;
60-
61-
// Toolbuttons are always at least icon sized, for consistency.
62-
if(type == QStyle::CT_ToolButton)
63-
{
64-
const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(opt);
65-
if(toolbutton)
66-
sz = sz.expandedTo(toolbutton->iconSize);
67-
}
68-
69-
return QProxyStyle::sizeFromContents(type, opt, sz, widget);
47+
return RDTweakedNativeStyle::sizeFromContents(type, opt, size, widget);
7048
}
7149

7250
int RDStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QWidget *widget) const
7351
{
74-
// toolbuttons don't shift their text when clicked.
75-
if(metric == QStyle::PM_ButtonShiftHorizontal || metric == QStyle::PM_ButtonShiftVertical)
76-
{
77-
if(opt && (opt->state & State_AutoRaise))
78-
return 0;
79-
}
80-
81-
return QProxyStyle::pixelMetric(metric, opt, widget);
52+
return RDTweakedNativeStyle::pixelMetric(metric, opt, widget);
8253
}
8354

8455
QIcon RDStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *opt,
8556
const QWidget *widget) const
8657
{
87-
if(standardIcon == QStyle::SP_TitleBarCloseButton)
88-
{
89-
int sz = pixelMetric(QStyle::PM_SmallIconSize);
90-
91-
return QIcon(QPixmap(QSize(sz, sz)));
92-
}
93-
94-
return QProxyStyle::standardIcon(standardIcon, opt, widget);
58+
return RDTweakedNativeStyle::standardIcon(standardIcon, opt, widget);
9559
}
9660

9761
void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *opt,
9862
QPainter *p, const QWidget *widget) const
9963
{
100-
// autoraise toolbuttons are rendered flat with a semi-transparent highlight to show their state.
101-
if(control == QStyle::CC_ToolButton && (opt->state & State_AutoRaise))
102-
{
103-
QRect dropdown = subControlRect(control, opt, SC_ToolButtonMenu, widget);
104-
105-
QPen oldPen = p->pen();
106-
QColor backCol = opt->palette.color(QPalette::Normal, QPalette::Highlight);
107-
108-
backCol.setAlphaF(0.2);
109-
QStyle::State masked = opt->state & (State_On | State_MouseOver);
110-
111-
// when the mouse is over, make it a little stronger
112-
if(masked && (masked & State_MouseOver))
113-
backCol.setAlphaF(0.4);
114-
115-
if(masked)
116-
{
117-
QRect rect = opt->rect.adjusted(0, 0, -1, -1);
118-
p->setPen(opt->palette.color(QPalette::Shadow));
119-
p->drawRect(rect);
120-
p->fillRect(rect, QBrush(backCol));
121-
}
122-
123-
p->setPen(oldPen);
124-
125-
const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(opt);
126-
127-
QStyleOptionToolButton labelTextIcon = *toolbutton;
128-
labelTextIcon.rect = subControlRect(control, opt, SC_ToolButton, widget);
129-
130-
// draw the label text/icon
131-
drawControl(CE_ToolButtonLabel, &labelTextIcon, p, widget);
132-
133-
// draw the menu arrow, if there is one
134-
if((toolbutton->subControls & SC_ToolButtonMenu) ||
135-
(toolbutton->features & QStyleOptionToolButton::HasMenu))
136-
{
137-
QStyleOptionToolButton menu = *toolbutton;
138-
menu.rect = subControlRect(control, opt, SC_ToolButtonMenu, widget);
139-
drawPrimitive(PE_IndicatorArrowDown, &menu, p, widget);
140-
}
141-
142-
return;
143-
}
144-
145-
return QProxyStyle::drawComplexControl(control, opt, p, widget);
64+
return RDTweakedNativeStyle::drawComplexControl(control, opt, p, widget);
14665
}
14766

14867
void RDStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *opt, QPainter *p,
14968
const QWidget *widget) const
15069
{
151-
if(element == QStyle::PE_IndicatorBranch)
152-
{
153-
QPen oldPen = p->pen();
154-
155-
if(opt->state & State_Children)
156-
{
157-
bool aa = p->testRenderHint(QPainter::Antialiasing);
158-
p->setRenderHint(QPainter::Antialiasing);
159-
160-
QColor col = opt->palette.color(QPalette::Dark);
161-
162-
if(opt->state & State_MouseOver)
163-
{
164-
QColor highlightCol = opt->palette.color(QPalette::Highlight);
165-
166-
col.setRedF(col.redF() * 0.6 + highlightCol.redF() * 0.4);
167-
col.setGreenF(col.greenF() * 0.6 + highlightCol.greenF() * 0.4);
168-
col.setBlueF(col.blueF() * 0.6 + highlightCol.blueF() * 0.4);
169-
}
170-
171-
p->setPen(QPen(col, 2.0));
172-
173-
QPainterPath path;
174-
175-
QPolygonF poly;
176-
177-
QRectF rect = opt->rect;
178-
179-
{
180-
qreal newdim = qMin(14.0, qMin(rect.height(), rect.width()));
181-
QPointF c = rect.center();
182-
rect.setTop(c.y() - newdim / 2);
183-
rect.setLeft(c.x() - newdim / 2);
184-
rect.setWidth(newdim);
185-
rect.setHeight(newdim);
186-
}
187-
188-
rect = rect.adjusted(2, 2, -2, -2);
189-
190-
if(opt->state & State_Open)
191-
{
192-
QPointF pt = rect.center();
193-
pt.setX(rect.left());
194-
poly << pt;
195-
196-
pt = rect.center();
197-
pt.setY(rect.bottom());
198-
poly << pt;
199-
200-
pt = rect.center();
201-
pt.setX(rect.right());
202-
poly << pt;
203-
204-
path.addPolygon(poly);
205-
206-
p->drawPath(path);
207-
}
208-
else
209-
{
210-
QPointF pt = rect.center();
211-
pt.setY(rect.top());
212-
poly << pt;
213-
214-
pt = rect.center();
215-
pt.setX(rect.right());
216-
poly << pt;
217-
218-
pt = rect.center();
219-
pt.setY(rect.bottom());
220-
poly << pt;
221-
222-
path.addPolygon(poly);
223-
224-
p->drawPath(path);
225-
}
226-
227-
if(!aa)
228-
p->setRenderHint(QPainter::Antialiasing, false);
229-
}
230-
else if(opt->state & (State_Sibling | State_Item))
231-
{
232-
p->setPen(QPen(opt->palette.color(QPalette::Midlight), 1.0));
233-
234-
int bottomY = opt->rect.center().y();
235-
236-
if(opt->state & State_Sibling)
237-
bottomY = opt->rect.bottom();
238-
239-
p->drawLine(QLine(opt->rect.center().x(), opt->rect.top(), opt->rect.center().x(), bottomY));
240-
241-
if(opt->state & State_Item)
242-
p->drawLine(opt->rect.center(), QPoint(opt->rect.right(), opt->rect.center().y()));
243-
}
244-
p->setPen(oldPen);
245-
return;
246-
}
247-
else if(element == PE_IndicatorTabClose)
248-
{
249-
QPen oldPen = p->pen();
250-
bool aa = p->testRenderHint(QPainter::Antialiasing);
251-
p->setRenderHint(QPainter::Antialiasing);
252-
253-
QColor col = opt->palette.color(QPalette::Text);
254-
255-
QRectF rect = opt->rect.adjusted(1, 1, -1, -1);
256-
257-
if(opt->state & (QStyle::State_Raised | QStyle::State_Sunken | QStyle::State_MouseOver))
258-
{
259-
QPointF c = rect.center();
260-
qreal radius = rect.width() / 2.0;
261-
262-
col = opt->palette.color(QPalette::Base);
263-
264-
QPainterPath path;
265-
266-
path.addEllipse(c, radius, radius);
267-
268-
QColor fillCol = QColor(Qt::red).darker(120);
269-
270-
if(opt->state & QStyle::State_Sunken)
271-
fillCol = fillCol.darker(120);
272-
273-
p->fillPath(path, fillCol);
274-
}
275-
276-
p->setPen(QPen(col, 1.5));
277-
278-
QPointF c = rect.center();
279-
280-
qreal crossrad = rect.width() / 4.0;
281-
282-
p->drawLine(c + QPointF(-crossrad, -crossrad), c + QPointF(crossrad, crossrad));
283-
p->drawLine(c + QPointF(-crossrad, crossrad), c + QPointF(crossrad, -crossrad));
284-
285-
p->setPen(oldPen);
286-
if(!aa)
287-
p->setRenderHint(QPainter::Antialiasing, false);
288-
289-
return;
290-
}
291-
292-
QProxyStyle::drawPrimitive(element, opt, p, widget);
70+
RDTweakedNativeStyle::drawPrimitive(element, opt, p, widget);
29371
}
29472

29573
void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPainter *p,
29674
const QWidget *widget) const
29775
{
298-
QProxyStyle::drawControl(control, opt, p, widget);
76+
RDTweakedNativeStyle::drawControl(control, opt, p, widget);
29977
}

qrenderdoc/Styles/RDStyle/RDStyle.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626

2727
#include <QPalette>
2828
#include <QProxyStyle>
29+
#include "Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.h"
2930

30-
class RDStyle : public QProxyStyle
31+
class RDStyle : public RDTweakedNativeStyle
3132
{
3233
private:
3334
Q_OBJECT

0 commit comments

Comments
 (0)