28
28
#include < QPen>
29
29
#include < QStyleOption>
30
30
31
- RDStyle::RDStyle (ColorScheme scheme) : QProxyStyle ()
31
+ RDStyle::RDStyle (ColorScheme scheme) : RDTweakedNativeStyle ()
32
32
{
33
33
}
34
34
@@ -38,262 +38,40 @@ RDStyle::~RDStyle()
38
38
39
39
QRect RDStyle::subElementRect (SubElement element, const QStyleOption *opt, const QWidget *widget) const
40
40
{
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);
54
42
}
55
43
56
44
QSize RDStyle::sizeFromContents (ContentsType type, const QStyleOption *opt, const QSize &size,
57
45
const QWidget *widget) const
58
46
{
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);
70
48
}
71
49
72
50
int RDStyle::pixelMetric (PixelMetric metric, const QStyleOption *opt, const QWidget *widget) const
73
51
{
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);
82
53
}
83
54
84
55
QIcon RDStyle::standardIcon (StandardPixmap standardIcon, const QStyleOption *opt,
85
56
const QWidget *widget) const
86
57
{
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);
95
59
}
96
60
97
61
void RDStyle::drawComplexControl (ComplexControl control, const QStyleOptionComplex *opt,
98
62
QPainter *p, const QWidget *widget) const
99
63
{
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);
146
65
}
147
66
148
67
void RDStyle::drawPrimitive (PrimitiveElement element, const QStyleOption *opt, QPainter *p,
149
68
const QWidget *widget) const
150
69
{
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);
293
71
}
294
72
295
73
void RDStyle::drawControl (ControlElement control, const QStyleOption *opt, QPainter *p,
296
74
const QWidget *widget) const
297
75
{
298
- QProxyStyle ::drawControl (control, opt, p, widget);
76
+ RDTweakedNativeStyle ::drawControl (control, opt, p, widget);
299
77
}
0 commit comments