|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qcommonstyle.h" |
|
43 #include "qcommonstyle_p.h" |
|
44 |
|
45 #include <qfile.h> |
|
46 #include <qapplication.h> |
|
47 #include <qbitmap.h> |
|
48 #include <qcache.h> |
|
49 #include <qdockwidget.h> |
|
50 #include <qdrawutil.h> |
|
51 #include <qdialogbuttonbox.h> |
|
52 #include <qformlayout.h> |
|
53 #include <qgroupbox.h> |
|
54 #include <qmath.h> |
|
55 #include <qmenu.h> |
|
56 #include <qpainter.h> |
|
57 #include <qpaintengine.h> |
|
58 #include <qpainterpath.h> |
|
59 #include <qslider.h> |
|
60 #include <qstyleoption.h> |
|
61 #include <qtabbar.h> |
|
62 #include <qtabwidget.h> |
|
63 #include <qtoolbar.h> |
|
64 #include <qtoolbutton.h> |
|
65 #include <qrubberband.h> |
|
66 #include <private/qcommonstylepixmaps_p.h> |
|
67 #include <private/qmath_p.h> |
|
68 #include <private/qstylehelper_p.h> |
|
69 #include <qdebug.h> |
|
70 #include <qtextformat.h> |
|
71 #include <qwizard.h> |
|
72 #include <qtabbar.h> |
|
73 #include <qfileinfo.h> |
|
74 #include <qdir.h> |
|
75 #include <qsettings.h> |
|
76 #include <qpixmapcache.h> |
|
77 #include <private/qguiplatformplugin_p.h> |
|
78 |
|
79 #include <limits.h> |
|
80 |
|
81 #ifndef QT_NO_ITEMVIEWS |
|
82 # include "private/qtextengine_p.h" |
|
83 #endif |
|
84 |
|
85 #ifdef Q_WS_X11 |
|
86 # include <private/qt_x11_p.h> |
|
87 #elif defined(Q_WS_MAC) |
|
88 # include <private/qt_cocoa_helpers_mac_p.h> |
|
89 #endif |
|
90 |
|
91 QT_BEGIN_NAMESPACE |
|
92 |
|
93 /*! |
|
94 \class QCommonStyle |
|
95 \brief The QCommonStyle class encapsulates the common Look and Feel of a GUI. |
|
96 |
|
97 \ingroup appearance |
|
98 |
|
99 This abstract class implements some of the widget's look and feel |
|
100 that is common to all GUI styles provided and shipped as part of |
|
101 Qt. |
|
102 |
|
103 Since QCommonStyle inherits QStyle, all of its functions are fully documented |
|
104 in the QStyle documentation. |
|
105 \omit |
|
106 , although the |
|
107 extra functions that QCommonStyle provides, e.g. |
|
108 drawComplexControl(), drawControl(), drawPrimitive(), |
|
109 hitTestComplexControl(), subControlRect(), sizeFromContents(), and |
|
110 subElementRect() are documented here. |
|
111 \endomit |
|
112 |
|
113 \sa QStyle, QMotifStyle, QWindowsStyle |
|
114 */ |
|
115 |
|
116 /*! |
|
117 Constructs a QCommonStyle. |
|
118 */ |
|
119 QCommonStyle::QCommonStyle() |
|
120 : QStyle(*new QCommonStylePrivate) |
|
121 { } |
|
122 |
|
123 /*! \internal |
|
124 */ |
|
125 QCommonStyle::QCommonStyle(QCommonStylePrivate &dd) |
|
126 : QStyle(dd) |
|
127 { } |
|
128 |
|
129 /*! |
|
130 Destroys the style. |
|
131 */ |
|
132 QCommonStyle::~QCommonStyle() |
|
133 { } |
|
134 |
|
135 |
|
136 /*! |
|
137 \reimp |
|
138 */ |
|
139 void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, |
|
140 const QWidget *widget) const |
|
141 { |
|
142 Q_D(const QCommonStyle); |
|
143 switch (pe) { |
|
144 case PE_FrameButtonBevel: |
|
145 case PE_FrameButtonTool: |
|
146 qDrawShadeRect(p, opt->rect, opt->palette, |
|
147 opt->state & (State_Sunken | State_On), 1, 0); |
|
148 break; |
|
149 case PE_PanelButtonCommand: |
|
150 case PE_PanelButtonBevel: |
|
151 case PE_PanelButtonTool: |
|
152 case PE_IndicatorButtonDropDown: |
|
153 qDrawShadePanel(p, opt->rect, opt->palette, |
|
154 opt->state & (State_Sunken | State_On), 1, |
|
155 &opt->palette.brush(QPalette::Button)); |
|
156 break; |
|
157 case PE_IndicatorViewItemCheck: |
|
158 proxy()->drawPrimitive(PE_IndicatorCheckBox, opt, p, widget); |
|
159 break; |
|
160 case PE_IndicatorCheckBox: |
|
161 if (opt->state & State_NoChange) { |
|
162 p->setPen(opt->palette.foreground().color()); |
|
163 p->fillRect(opt->rect, opt->palette.brush(QPalette::Button)); |
|
164 p->drawRect(opt->rect); |
|
165 p->drawLine(opt->rect.topLeft(), opt->rect.bottomRight()); |
|
166 } else { |
|
167 qDrawShadePanel(p, opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height(), |
|
168 opt->palette, opt->state & (State_Sunken | State_On), 1, |
|
169 &opt->palette.brush(QPalette::Button)); |
|
170 } |
|
171 break; |
|
172 case PE_IndicatorRadioButton: { |
|
173 QRect ir = opt->rect; |
|
174 p->setPen(opt->palette.dark().color()); |
|
175 p->drawArc(opt->rect, 0, 5760); |
|
176 if (opt->state & (State_Sunken | State_On)) { |
|
177 ir.adjust(2, 2, -2, -2); |
|
178 p->setBrush(opt->palette.foreground()); |
|
179 p->drawEllipse(ir); |
|
180 } |
|
181 break; } |
|
182 case PE_FrameFocusRect: |
|
183 if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) { |
|
184 QColor bg = fropt->backgroundColor; |
|
185 QPen oldPen = p->pen(); |
|
186 if (bg.isValid()) { |
|
187 int h, s, v; |
|
188 bg.getHsv(&h, &s, &v); |
|
189 if (v >= 128) |
|
190 p->setPen(Qt::black); |
|
191 else |
|
192 p->setPen(Qt::white); |
|
193 } else { |
|
194 p->setPen(opt->palette.foreground().color()); |
|
195 } |
|
196 QRect focusRect = opt->rect.adjusted(1, 1, -1, -1); |
|
197 p->drawRect(focusRect.adjusted(0, 0, -1, -1)); //draw pen inclusive |
|
198 p->setPen(oldPen); |
|
199 } |
|
200 break; |
|
201 case PE_IndicatorMenuCheckMark: { |
|
202 const int markW = opt->rect.width() > 7 ? 7 : opt->rect.width(); |
|
203 const int markH = markW; |
|
204 int posX = opt->rect.x() + (opt->rect.width() - markW)/2 + 1; |
|
205 int posY = opt->rect.y() + (opt->rect.height() - markH)/2; |
|
206 |
|
207 QVector<QLineF> a; |
|
208 a.reserve(markH); |
|
209 |
|
210 int i, xx, yy; |
|
211 xx = posX; |
|
212 yy = 3 + posY; |
|
213 for (i = 0; i < markW/2; ++i) { |
|
214 a << QLineF(xx, yy, xx, yy + 2); |
|
215 ++xx; |
|
216 ++yy; |
|
217 } |
|
218 yy -= 2; |
|
219 for (; i < markH; ++i) { |
|
220 a << QLineF(xx, yy, xx, yy + 2); |
|
221 ++xx; |
|
222 --yy; |
|
223 } |
|
224 if (!(opt->state & State_Enabled) && !(opt->state & State_On)) { |
|
225 int pnt; |
|
226 p->setPen(opt->palette.highlightedText().color()); |
|
227 QPoint offset(1, 1); |
|
228 for (pnt = 0; pnt < a.size(); ++pnt) |
|
229 a[pnt].translate(offset.x(), offset.y()); |
|
230 p->drawLines(a); |
|
231 for (pnt = 0; pnt < a.size(); ++pnt) |
|
232 a[pnt].translate(offset.x(), offset.y()); |
|
233 } |
|
234 p->setPen(opt->palette.text().color()); |
|
235 p->drawLines(a); |
|
236 break; } |
|
237 case PE_Frame: |
|
238 case PE_FrameMenu: |
|
239 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { |
|
240 if (pe == PE_FrameMenu || (frame->state & State_Sunken) || (frame->state & State_Raised)) { |
|
241 qDrawShadePanel(p, frame->rect, frame->palette, frame->state & State_Sunken, |
|
242 frame->lineWidth); |
|
243 } else { |
|
244 qDrawPlainRect(p, frame->rect, frame->palette.foreground().color(), frame->lineWidth); |
|
245 } |
|
246 } |
|
247 break; |
|
248 #ifndef QT_NO_TOOLBAR |
|
249 case PE_PanelMenuBar: |
|
250 if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) |
|
251 break; |
|
252 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)){ |
|
253 qDrawShadePanel(p, frame->rect, frame->palette, false, frame->lineWidth, |
|
254 &frame->palette.brush(QPalette::Button)); |
|
255 |
|
256 } |
|
257 else if (const QStyleOptionToolBar *frame = qstyleoption_cast<const QStyleOptionToolBar *>(opt)){ |
|
258 qDrawShadePanel(p, frame->rect, frame->palette, false, frame->lineWidth, |
|
259 &frame->palette.brush(QPalette::Button)); |
|
260 } |
|
261 |
|
262 break; |
|
263 case PE_PanelMenu: |
|
264 break; |
|
265 case PE_PanelToolBar: |
|
266 break; |
|
267 #endif // QT_NO_TOOLBAR |
|
268 #ifndef QT_NO_PROGRESSBAR |
|
269 case PE_IndicatorProgressChunk: |
|
270 { |
|
271 bool vertical = false; |
|
272 if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) |
|
273 vertical = (pb2->orientation == Qt::Vertical); |
|
274 if (!vertical) { |
|
275 p->fillRect(opt->rect.x(), opt->rect.y() + 3, opt->rect.width() -2, opt->rect.height() - 6, |
|
276 opt->palette.brush(QPalette::Highlight)); |
|
277 } else { |
|
278 p->fillRect(opt->rect.x() + 2, opt->rect.y(), opt->rect.width() -6, opt->rect.height() - 2, |
|
279 opt->palette.brush(QPalette::Highlight)); |
|
280 } |
|
281 } |
|
282 break; |
|
283 #endif // QT_NO_PROGRESSBAR |
|
284 #ifdef QT3_SUPPORT |
|
285 case PE_Q3CheckListController: |
|
286 #ifndef QT_NO_IMAGEFORMAT_XPM |
|
287 p->drawPixmap(opt->rect.topLeft(), QPixmap(check_list_controller_xpm)); |
|
288 #endif |
|
289 break; |
|
290 case PE_Q3CheckListExclusiveIndicator: |
|
291 if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) { |
|
292 if (lv->items.isEmpty()) |
|
293 return; |
|
294 int x = lv->rect.x(), |
|
295 y = lv->rect.y(); |
|
296 #define INTARRLEN(x) sizeof(x)/(sizeof(int)*2) |
|
297 static const int pts1[] = { // dark lines |
|
298 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 }; |
|
299 static const int pts2[] = { // black lines |
|
300 2,8, 1,7, 1,4, 2,3, 2,2, 3,2, 4,1, 7,1, 8,2, 9,2 }; |
|
301 static const int pts3[] = { // background lines |
|
302 2,9, 3,9, 4,10, 7,10, 8,9, 9,9, 9,8, 10,7, 10,4, 9,3 }; |
|
303 static const int pts4[] = { // white lines |
|
304 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7, |
|
305 11,4, 10,3, 10,2 }; |
|
306 // static const int pts5[] = { // inner fill |
|
307 // 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 }; |
|
308 //QPolygon a; |
|
309 |
|
310 if (lv->state & State_Enabled) |
|
311 p->setPen(lv->palette.text().color()); |
|
312 else |
|
313 p->setPen(QPen(lv->viewportPalette.color(QPalette::Disabled, QPalette::Text))); |
|
314 QPolygon a(INTARRLEN(pts1), pts1); |
|
315 a.translate(x, y); |
|
316 //p->setPen(pal.dark()); |
|
317 p->drawPolyline(a); |
|
318 a.setPoints(INTARRLEN(pts2), pts2); |
|
319 a.translate(x, y); |
|
320 p->drawPolyline(a); |
|
321 a.setPoints(INTARRLEN(pts3), pts3); |
|
322 a.translate(x, y); |
|
323 // p->setPen(black); |
|
324 p->drawPolyline(a); |
|
325 a.setPoints(INTARRLEN(pts4), pts4); |
|
326 a.translate(x, y); |
|
327 // p->setPen(blue); |
|
328 p->drawPolyline(a); |
|
329 // a.setPoints(INTARRLEN(pts5), pts5); |
|
330 // a.translate(x, y); |
|
331 // QColor fillColor = isDown() ? g.background() : g.base(); |
|
332 // p->setPen(fillColor); |
|
333 // p->setBrush(fillColor); |
|
334 // p->drawPolygon(a); |
|
335 if (opt->state & State_On) { |
|
336 p->setPen(Qt::NoPen); |
|
337 p->setBrush(opt->palette.text()); |
|
338 p->drawRect(x + 5, y + 4, 2, 4); |
|
339 p->drawRect(x + 4, y + 5, 4, 2); |
|
340 } |
|
341 #undef INTARRLEN |
|
342 } |
|
343 break; |
|
344 case PE_Q3CheckListIndicator: |
|
345 if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) { |
|
346 if(lv->items.isEmpty()) |
|
347 break; |
|
348 QStyleOptionQ3ListViewItem item = lv->items.at(0); |
|
349 int x = lv->rect.x(), |
|
350 y = lv->rect.y(), |
|
351 w = lv->rect.width(), |
|
352 h = lv->rect.width(), |
|
353 marg = lv->itemMargin; |
|
354 |
|
355 if (lv->state & State_Enabled) |
|
356 p->setPen(QPen(lv->palette.text().color(), 2)); |
|
357 else |
|
358 p->setPen(QPen(lv->viewportPalette.color(QPalette::Disabled, QPalette::Text), 2)); |
|
359 if (opt->state & State_Selected && !lv->rootIsDecorated |
|
360 && !(item.features & QStyleOptionQ3ListViewItem::ParentControl)) { |
|
361 p->fillRect(0, 0, x + marg + w + 4, item.height, |
|
362 lv->palette.brush(QPalette::Highlight)); |
|
363 if (item.state & State_Enabled) |
|
364 p->setPen(QPen(lv->palette.highlightedText().color(), 2)); |
|
365 } |
|
366 |
|
367 if (lv->state & State_NoChange) |
|
368 p->setBrush(lv->palette.brush(QPalette::Button)); |
|
369 p->drawRect(x + marg, y + 2, w - 4, h - 4); |
|
370 ///////////////////// |
|
371 ++x; |
|
372 ++y; |
|
373 if (lv->state & State_On || lv->state & State_NoChange) { |
|
374 QLineF lines[7]; |
|
375 int i, |
|
376 xx = x + 1 + marg, |
|
377 yy = y + 5; |
|
378 for (i = 0; i < 3; ++i) { |
|
379 lines[i] = QLineF(xx, yy, xx, yy + 2); |
|
380 ++xx; |
|
381 ++yy; |
|
382 } |
|
383 yy -= 2; |
|
384 for (i = 3; i < 7; ++i) { |
|
385 lines[i] = QLineF(xx, yy, xx, yy + 2); |
|
386 ++xx; |
|
387 --yy; |
|
388 } |
|
389 p->drawLines(lines, 7); |
|
390 } |
|
391 } |
|
392 break; |
|
393 #endif // QT3_SUPPORT |
|
394 case PE_IndicatorBranch: { |
|
395 int mid_h = opt->rect.x() + opt->rect.width() / 2; |
|
396 int mid_v = opt->rect.y() + opt->rect.height() / 2; |
|
397 int bef_h = mid_h; |
|
398 int bef_v = mid_v; |
|
399 int aft_h = mid_h; |
|
400 int aft_v = mid_v; |
|
401 #ifndef QT_NO_IMAGEFORMAT_XPM |
|
402 static const int decoration_size = 9; |
|
403 static QPixmap open(tree_branch_open_xpm); |
|
404 static QPixmap closed(tree_branch_closed_xpm); |
|
405 if (opt->state & State_Children) { |
|
406 int delta = decoration_size / 2; |
|
407 bef_h -= delta; |
|
408 bef_v -= delta; |
|
409 aft_h += delta; |
|
410 aft_v += delta; |
|
411 p->drawPixmap(bef_h, bef_v, opt->state & State_Open ? open : closed); |
|
412 } |
|
413 #endif // QT_NO_IMAGEFORMAT_XPM |
|
414 if (opt->state & State_Item) { |
|
415 if (opt->direction == Qt::RightToLeft) |
|
416 p->drawLine(opt->rect.left(), mid_v, bef_h, mid_v); |
|
417 else |
|
418 p->drawLine(aft_h, mid_v, opt->rect.right(), mid_v); |
|
419 } |
|
420 if (opt->state & State_Sibling) |
|
421 p->drawLine(mid_h, aft_v, mid_h, opt->rect.bottom()); |
|
422 if (opt->state & (State_Open | State_Children | State_Item | State_Sibling)) |
|
423 p->drawLine(mid_h, opt->rect.y(), mid_h, bef_v); |
|
424 break; } |
|
425 #ifdef QT3_SUPPORT |
|
426 case PE_Q3Separator: |
|
427 qDrawShadeLine(p, opt->rect.left(), opt->rect.top(), opt->rect.right(), opt->rect.bottom(), |
|
428 opt->palette, opt->state & State_Sunken, 1, 0); |
|
429 break; |
|
430 #endif // QT3_SUPPORT |
|
431 case PE_FrameStatusBarItem: |
|
432 qDrawShadeRect(p, opt->rect, opt->palette, true, 1, 0, 0); |
|
433 break; |
|
434 case PE_IndicatorHeaderArrow: |
|
435 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { |
|
436 QPen oldPen = p->pen(); |
|
437 if (header->sortIndicator & QStyleOptionHeader::SortUp) { |
|
438 QPolygon pa(3); |
|
439 p->setPen(QPen(opt->palette.light(), 0)); |
|
440 p->drawLine(opt->rect.x() + opt->rect.width(), opt->rect.y(), |
|
441 opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()); |
|
442 p->setPen(QPen(opt->palette.dark(), 0)); |
|
443 pa.setPoint(0, opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()); |
|
444 pa.setPoint(1, opt->rect.x(), opt->rect.y()); |
|
445 pa.setPoint(2, opt->rect.x() + opt->rect.width(), opt->rect.y()); |
|
446 p->drawPolyline(pa); |
|
447 } else if (header->sortIndicator & QStyleOptionHeader::SortDown) { |
|
448 QPolygon pa(3); |
|
449 p->setPen(QPen(opt->palette.light(), 0)); |
|
450 pa.setPoint(0, opt->rect.x(), opt->rect.y() + opt->rect.height()); |
|
451 pa.setPoint(1, opt->rect.x() + opt->rect.width(), opt->rect.y() + opt->rect.height()); |
|
452 pa.setPoint(2, opt->rect.x() + opt->rect.width() / 2, opt->rect.y()); |
|
453 p->drawPolyline(pa); |
|
454 p->setPen(QPen(opt->palette.dark(), 0)); |
|
455 p->drawLine(opt->rect.x(), opt->rect.y() + opt->rect.height(), |
|
456 opt->rect.x() + opt->rect.width() / 2, opt->rect.y()); |
|
457 } |
|
458 p->setPen(oldPen); |
|
459 } |
|
460 break; |
|
461 #ifndef QT_NO_TABBAR |
|
462 case PE_FrameTabBarBase: |
|
463 if (const QStyleOptionTabBarBase *tbb |
|
464 = qstyleoption_cast<const QStyleOptionTabBarBase *>(opt)) { |
|
465 p->save(); |
|
466 switch (tbb->shape) { |
|
467 case QTabBar::RoundedNorth: |
|
468 case QTabBar::TriangularNorth: |
|
469 p->setPen(QPen(tbb->palette.light(), 0)); |
|
470 p->drawLine(tbb->rect.topLeft(), tbb->rect.topRight()); |
|
471 break; |
|
472 case QTabBar::RoundedWest: |
|
473 case QTabBar::TriangularWest: |
|
474 p->setPen(QPen(tbb->palette.light(), 0)); |
|
475 p->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft()); |
|
476 break; |
|
477 case QTabBar::RoundedSouth: |
|
478 case QTabBar::TriangularSouth: |
|
479 p->setPen(QPen(tbb->palette.shadow(), 0)); |
|
480 p->drawLine(tbb->rect.left(), tbb->rect.bottom(), |
|
481 tbb->rect.right(), tbb->rect.bottom()); |
|
482 p->setPen(QPen(tbb->palette.dark(), 0)); |
|
483 p->drawLine(tbb->rect.left(), tbb->rect.bottom() - 1, |
|
484 tbb->rect.right() - 1, tbb->rect.bottom() - 1); |
|
485 break; |
|
486 case QTabBar::RoundedEast: |
|
487 case QTabBar::TriangularEast: |
|
488 p->setPen(QPen(tbb->palette.dark(), 0)); |
|
489 p->drawLine(tbb->rect.topRight(), tbb->rect.bottomRight()); |
|
490 break; |
|
491 } |
|
492 p->restore(); |
|
493 } |
|
494 break; |
|
495 case PE_IndicatorTabClose: { |
|
496 if (d->tabBarcloseButtonIcon.isNull()) { |
|
497 d->tabBarcloseButtonIcon.addPixmap(QPixmap( |
|
498 QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-closetab-16.png")), |
|
499 QIcon::Normal, QIcon::Off); |
|
500 d->tabBarcloseButtonIcon.addPixmap(QPixmap( |
|
501 QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-closetab-down-16.png")), |
|
502 QIcon::Normal, QIcon::On); |
|
503 d->tabBarcloseButtonIcon.addPixmap(QPixmap( |
|
504 QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-closetab-hover-16.png")), |
|
505 QIcon::Active, QIcon::Off); |
|
506 } |
|
507 |
|
508 int size = proxy()->pixelMetric(QStyle::PM_SmallIconSize); |
|
509 QIcon::Mode mode = opt->state & State_Enabled ? |
|
510 (opt->state & State_Raised ? QIcon::Active : QIcon::Normal) |
|
511 : QIcon::Disabled; |
|
512 if (!(opt->state & State_Raised) |
|
513 && !(opt->state & State_Sunken) |
|
514 && !(opt->state & QStyle::State_Selected)) |
|
515 mode = QIcon::Disabled; |
|
516 |
|
517 QIcon::State state = opt->state & State_Sunken ? QIcon::On : QIcon::Off; |
|
518 QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(size, mode, state); |
|
519 proxy()->drawItemPixmap(p, opt->rect, Qt::AlignCenter, pixmap); |
|
520 break; |
|
521 } |
|
522 #endif // QT_NO_TABBAR |
|
523 case PE_FrameTabWidget: |
|
524 case PE_FrameWindow: |
|
525 qDrawWinPanel(p, opt->rect, opt->palette, false, 0); |
|
526 break; |
|
527 case PE_FrameLineEdit: |
|
528 proxy()->drawPrimitive(PE_Frame, opt, p, widget); |
|
529 break; |
|
530 #ifndef QT_NO_GROUPBOX |
|
531 case PE_FrameGroupBox: |
|
532 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { |
|
533 const QStyleOptionFrameV2 *frame2 = qstyleoption_cast<const QStyleOptionFrameV2 *>(opt); |
|
534 if (frame2 && (frame2->features & QStyleOptionFrameV2::Flat)) { |
|
535 QRect fr = frame->rect; |
|
536 QPoint p1(fr.x(), fr.y() + 1); |
|
537 QPoint p2(fr.x() + fr.width(), p1.y()); |
|
538 qDrawShadeLine(p, p1, p2, frame->palette, true, |
|
539 frame->lineWidth, frame->midLineWidth); |
|
540 } else { |
|
541 qDrawShadeRect(p, frame->rect.x(), frame->rect.y(), frame->rect.width(), |
|
542 frame->rect.height(), frame->palette, true, |
|
543 frame->lineWidth, frame->midLineWidth); |
|
544 } |
|
545 } |
|
546 break; |
|
547 #endif // QT_NO_GROUPBOX |
|
548 #ifndef QT_NO_DOCKWIDGET |
|
549 case PE_FrameDockWidget: |
|
550 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { |
|
551 int lw = frame->lineWidth; |
|
552 if (lw <= 0) |
|
553 lw = proxy()->pixelMetric(PM_DockWidgetFrameWidth); |
|
554 |
|
555 qDrawShadePanel(p, frame->rect, frame->palette, false, lw); |
|
556 } |
|
557 break; |
|
558 #endif // QT_NO_DOCKWIDGET |
|
559 #ifndef QT_NO_TOOLBAR |
|
560 case PE_IndicatorToolBarHandle: |
|
561 p->save(); |
|
562 p->translate(opt->rect.x(), opt->rect.y()); |
|
563 if (opt->state & State_Horizontal) { |
|
564 int x = opt->rect.width() / 3; |
|
565 if (opt->direction == Qt::RightToLeft) |
|
566 x -= 2; |
|
567 if (opt->rect.height() > 4) { |
|
568 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4, |
|
569 opt->palette, false, 1, 0); |
|
570 qDrawShadePanel(p, x+3, 2, 3, opt->rect.height() - 4, |
|
571 opt->palette, false, 1, 0); |
|
572 } |
|
573 } else { |
|
574 if (opt->rect.width() > 4) { |
|
575 int y = opt->rect.height() / 3; |
|
576 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3, |
|
577 opt->palette, false, 1, 0); |
|
578 qDrawShadePanel(p, 2, y+3, opt->rect.width() - 4, 3, |
|
579 opt->palette, false, 1, 0); |
|
580 } |
|
581 } |
|
582 p->restore(); |
|
583 break; |
|
584 case PE_Q3DockWindowSeparator: |
|
585 proxy()->drawPrimitive(PE_IndicatorToolBarSeparator, opt, p, widget); |
|
586 break; |
|
587 case PE_IndicatorToolBarSeparator: |
|
588 { |
|
589 QPoint p1, p2; |
|
590 if (opt->state & State_Horizontal) { |
|
591 p1 = QPoint(opt->rect.width()/2, 0); |
|
592 p2 = QPoint(p1.x(), opt->rect.height()); |
|
593 } else { |
|
594 p1 = QPoint(0, opt->rect.height()/2); |
|
595 p2 = QPoint(opt->rect.width(), p1.y()); |
|
596 } |
|
597 qDrawShadeLine(p, p1, p2, opt->palette, 1, 1, 0); |
|
598 break; |
|
599 } |
|
600 #endif // QT_NO_TOOLBAR |
|
601 #ifndef QT_NO_SPINBOX |
|
602 case PE_IndicatorSpinPlus: |
|
603 case PE_IndicatorSpinMinus: { |
|
604 QRect r = opt->rect; |
|
605 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget); |
|
606 QRect br = r.adjusted(fw, fw, -fw, -fw); |
|
607 |
|
608 int offset = (opt->state & State_Sunken) ? 1 : 0; |
|
609 int step = (br.width() + 4) / 5; |
|
610 p->fillRect(br.x() + offset, br.y() + offset +br.height() / 2 - step / 2, |
|
611 br.width(), step, |
|
612 opt->palette.buttonText()); |
|
613 if (pe == PE_IndicatorSpinPlus) |
|
614 p->fillRect(br.x() + br.width() / 2 - step / 2 + offset, br.y() + offset, |
|
615 step, br.height(), |
|
616 opt->palette.buttonText()); |
|
617 |
|
618 break; } |
|
619 case PE_IndicatorSpinUp: |
|
620 case PE_IndicatorSpinDown: { |
|
621 QRect r = opt->rect; |
|
622 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget); |
|
623 // QRect br = r.adjusted(fw, fw, -fw, -fw); |
|
624 int x = r.x(), y = r.y(), w = r.width(), h = r.height(); |
|
625 int sw = w-4; |
|
626 if (sw < 3) |
|
627 break; |
|
628 else if (!(sw & 1)) |
|
629 sw--; |
|
630 sw -= (sw / 7) * 2; // Empty border |
|
631 int sh = sw/2 + 2; // Must have empty row at foot of arrow |
|
632 |
|
633 int sx = x + w / 2 - sw / 2; |
|
634 int sy = y + h / 2 - sh / 2; |
|
635 |
|
636 if (pe == PE_IndicatorSpinUp && fw) |
|
637 --sy; |
|
638 |
|
639 QPolygon a; |
|
640 if (pe == PE_IndicatorSpinDown) |
|
641 a.setPoints(3, 0, 1, sw-1, 1, sh-2, sh-1); |
|
642 else |
|
643 a.setPoints(3, 0, sh-1, sw-1, sh-1, sh-2, 1); |
|
644 int bsx = 0; |
|
645 int bsy = 0; |
|
646 if (opt->state & State_Sunken) { |
|
647 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal); |
|
648 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical); |
|
649 } |
|
650 p->save(); |
|
651 p->translate(sx + bsx, sy + bsy); |
|
652 p->setPen(opt->palette.buttonText().color()); |
|
653 p->setBrush(opt->palette.buttonText()); |
|
654 p->drawPolygon(a); |
|
655 p->restore(); |
|
656 break; } |
|
657 #endif // QT_NO_SPINBOX |
|
658 case PE_PanelTipLabel: { |
|
659 QBrush oldBrush = p->brush(); |
|
660 QPen oldPen = p->pen(); |
|
661 p->setPen(QPen(opt->palette.toolTipText(), 0)); |
|
662 p->setBrush(opt->palette.toolTipBase()); |
|
663 p->drawRect(opt->rect.adjusted(0, 0, -1, -1)); |
|
664 p->setPen(oldPen); |
|
665 p->setBrush(oldBrush); |
|
666 break; |
|
667 } |
|
668 #ifndef QT_NO_TABBAR |
|
669 case PE_IndicatorTabTear: |
|
670 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { |
|
671 bool rtl = tab->direction == Qt::RightToLeft; |
|
672 QRect rect = tab->rect; |
|
673 QPainterPath path; |
|
674 |
|
675 rect.setTop(rect.top() + ((tab->state & State_Selected) ? 1 : 3)); |
|
676 rect.setBottom(rect.bottom() - ((tab->state & State_Selected) ? 0 : 2)); |
|
677 |
|
678 path.moveTo(QPoint(rtl ? rect.right() : rect.left(), rect.top())); |
|
679 int count = 4; |
|
680 for(int jags = 1; jags <= count; ++jags, rtl = !rtl) |
|
681 path.lineTo(QPoint(rtl ? rect.left() : rect.right(), rect.top() + jags * rect.height()/count)); |
|
682 |
|
683 p->setPen(QPen(tab->palette.light(), qreal(.8))); |
|
684 p->setBrush(tab->palette.background()); |
|
685 p->setRenderHint(QPainter::Antialiasing); |
|
686 p->drawPath(path); |
|
687 } |
|
688 break; |
|
689 #endif // QT_NO_TABBAR |
|
690 #ifndef QT_NO_LINEEDIT |
|
691 case PE_PanelLineEdit: |
|
692 if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { |
|
693 p->fillRect(panel->rect.adjusted(panel->lineWidth, panel->lineWidth, -panel->lineWidth, -panel->lineWidth), |
|
694 panel->palette.brush(QPalette::Base)); |
|
695 |
|
696 if (panel->lineWidth > 0) |
|
697 proxy()->drawPrimitive(PE_FrameLineEdit, panel, p, widget); |
|
698 } |
|
699 break; |
|
700 #endif // QT_NO_LINEEDIT |
|
701 #ifndef QT_NO_COLUMNVIEW |
|
702 case PE_IndicatorColumnViewArrow: { |
|
703 if (const QStyleOptionViewItem *viewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) { |
|
704 bool reverse = (viewOpt->direction == Qt::RightToLeft); |
|
705 p->save(); |
|
706 QPainterPath path; |
|
707 int x = viewOpt->rect.x() + 1; |
|
708 int offset = (viewOpt->rect.height() / 3); |
|
709 int height = (viewOpt->rect.height()) - offset * 2; |
|
710 if (height % 2 == 1) |
|
711 --height; |
|
712 int x2 = x + height - 1; |
|
713 if (reverse) { |
|
714 x = viewOpt->rect.x() + viewOpt->rect.width() - 1; |
|
715 x2 = x - height + 1; |
|
716 } |
|
717 path.moveTo(x, viewOpt->rect.y() + offset); |
|
718 path.lineTo(x, viewOpt->rect.y() + offset + height); |
|
719 path.lineTo(x2, viewOpt->rect.y() + offset+height/2); |
|
720 path.closeSubpath(); |
|
721 if (viewOpt->state & QStyle::State_Selected ) { |
|
722 if (viewOpt->showDecorationSelected) { |
|
723 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::HighlightedText); |
|
724 p->setPen(color); |
|
725 p->setBrush(color); |
|
726 } else { |
|
727 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::WindowText); |
|
728 p->setPen(color); |
|
729 p->setBrush(color); |
|
730 } |
|
731 |
|
732 } else { |
|
733 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Mid); |
|
734 p->setPen(color); |
|
735 p->setBrush(color); |
|
736 } |
|
737 p->drawPath(path); |
|
738 |
|
739 // draw the vertical and top triangle line |
|
740 if (!(viewOpt->state & QStyle::State_Selected)) { |
|
741 QPainterPath lines; |
|
742 lines.moveTo(x, viewOpt->rect.y() + offset); |
|
743 lines.lineTo(x, viewOpt->rect.y() + offset + height); |
|
744 lines.moveTo(x, viewOpt->rect.y() + offset); |
|
745 lines.lineTo(x2, viewOpt->rect.y() + offset+height/2); |
|
746 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Dark); |
|
747 p->setPen(color); |
|
748 p->drawPath(lines); |
|
749 } |
|
750 p->restore(); |
|
751 } |
|
752 break; } |
|
753 #endif //QT_NO_COLUMNVIEW |
|
754 case PE_IndicatorItemViewItemDrop: { |
|
755 QRect rect = opt->rect; |
|
756 if (opt->rect.height() == 0) |
|
757 p->drawLine(rect.topLeft(), rect.topRight()); |
|
758 else |
|
759 p->drawRect(rect); |
|
760 break; } |
|
761 #ifndef QT_NO_ITEMVIEWS |
|
762 case PE_PanelItemViewRow: |
|
763 if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { |
|
764 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled |
|
765 ? QPalette::Normal : QPalette::Disabled; |
|
766 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active)) |
|
767 cg = QPalette::Inactive; |
|
768 |
|
769 if ((vopt->state & QStyle::State_Selected) && proxy()->styleHint(QStyle::SH_ItemView_ShowDecorationSelected, opt, widget)) |
|
770 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight)); |
|
771 else if (vopt->features & QStyleOptionViewItemV2::Alternate) |
|
772 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::AlternateBase)); |
|
773 } |
|
774 break; |
|
775 case PE_PanelItemViewItem: |
|
776 if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { |
|
777 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled |
|
778 ? QPalette::Normal : QPalette::Disabled; |
|
779 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active)) |
|
780 cg = QPalette::Inactive; |
|
781 |
|
782 if (vopt->showDecorationSelected && (vopt->state & QStyle::State_Selected)) { |
|
783 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight)); |
|
784 } else { |
|
785 if (vopt->backgroundBrush.style() != Qt::NoBrush) { |
|
786 QPointF oldBO = p->brushOrigin(); |
|
787 p->setBrushOrigin(vopt->rect.topLeft()); |
|
788 p->fillRect(vopt->rect, vopt->backgroundBrush); |
|
789 p->setBrushOrigin(oldBO); |
|
790 } |
|
791 |
|
792 if (vopt->state & QStyle::State_Selected) { |
|
793 QRect textRect = subElementRect(QStyle::SE_ItemViewItemText, opt, widget); |
|
794 p->fillRect(textRect, vopt->palette.brush(cg, QPalette::Highlight)); |
|
795 } |
|
796 } |
|
797 } |
|
798 break; |
|
799 #endif //QT_NO_ITEMVIEWS |
|
800 case PE_PanelScrollAreaCorner: { |
|
801 const QBrush brush(opt->palette.brush(QPalette::Window)); |
|
802 p->fillRect(opt->rect, brush); |
|
803 } break; |
|
804 default: |
|
805 break; |
|
806 } |
|
807 } |
|
808 |
|
809 #ifndef QT_NO_TOOLBUTTON |
|
810 static void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbutton, |
|
811 const QRect &rect, QPainter *painter, const QWidget *widget = 0) |
|
812 { |
|
813 QStyle::PrimitiveElement pe; |
|
814 switch (toolbutton->arrowType) { |
|
815 case Qt::LeftArrow: |
|
816 pe = QStyle::PE_IndicatorArrowLeft; |
|
817 break; |
|
818 case Qt::RightArrow: |
|
819 pe = QStyle::PE_IndicatorArrowRight; |
|
820 break; |
|
821 case Qt::UpArrow: |
|
822 pe = QStyle::PE_IndicatorArrowUp; |
|
823 break; |
|
824 case Qt::DownArrow: |
|
825 pe = QStyle::PE_IndicatorArrowDown; |
|
826 break; |
|
827 default: |
|
828 return; |
|
829 } |
|
830 QStyleOption arrowOpt; |
|
831 arrowOpt.rect = rect; |
|
832 arrowOpt.palette = toolbutton->palette; |
|
833 arrowOpt.state = toolbutton->state; |
|
834 style->drawPrimitive(pe, &arrowOpt, painter, widget); |
|
835 } |
|
836 #endif // QT_NO_TOOLBUTTON |
|
837 |
|
838 #ifndef QT_NO_ITEMVIEWS |
|
839 |
|
840 QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItemV4 *option, int role) const |
|
841 { |
|
842 Q_Q(const QCommonStyle); |
|
843 |
|
844 const QWidget *widget = option->widget; |
|
845 switch (role) { |
|
846 case Qt::CheckStateRole: |
|
847 if (option->features & QStyleOptionViewItemV2::HasCheckIndicator) |
|
848 return QSize(q->pixelMetric(QStyle::PM_IndicatorWidth, option, widget), |
|
849 q->pixelMetric(QStyle::PM_IndicatorHeight, option, widget)); |
|
850 break; |
|
851 case Qt::DisplayRole: |
|
852 if (option->features & QStyleOptionViewItemV2::HasDisplay) { |
|
853 QTextOption textOption; |
|
854 textOption.setWrapMode(QTextOption::WordWrap); |
|
855 QTextLayout textLayout; |
|
856 textLayout.setTextOption(textOption); |
|
857 textLayout.setFont(option->font); |
|
858 textLayout.setText(option->text); |
|
859 const bool wrapText = option->features & QStyleOptionViewItemV2::WrapText; |
|
860 const int textMargin = q->pixelMetric(QStyle::PM_FocusFrameHMargin, option, widget) + 1; |
|
861 QRect bounds = option->rect; |
|
862 switch (option->decorationPosition) { |
|
863 case QStyleOptionViewItem::Left: |
|
864 case QStyleOptionViewItem::Right: |
|
865 bounds.setWidth(wrapText && bounds.isValid() ? bounds.width() - 2 * textMargin : QFIXED_MAX); |
|
866 break; |
|
867 case QStyleOptionViewItem::Top: |
|
868 case QStyleOptionViewItem::Bottom: |
|
869 bounds.setWidth(wrapText ? option->decorationSize.width() : QFIXED_MAX); |
|
870 break; |
|
871 default: |
|
872 break; |
|
873 } |
|
874 |
|
875 qreal height = 0, widthUsed = 0; |
|
876 textLayout.beginLayout(); |
|
877 while (true) { |
|
878 QTextLine line = textLayout.createLine(); |
|
879 if (!line.isValid()) |
|
880 break; |
|
881 line.setLineWidth(bounds.width()); |
|
882 line.setPosition(QPointF(0, height)); |
|
883 height += line.height(); |
|
884 widthUsed = qMax(widthUsed, line.naturalTextWidth()); |
|
885 } |
|
886 textLayout.endLayout(); |
|
887 const QSize size(qCeil(widthUsed), qCeil(height)); |
|
888 return QSize(size.width() + 2 * textMargin, size.height()); |
|
889 } |
|
890 break; |
|
891 case Qt::DecorationRole: |
|
892 if (option->features & QStyleOptionViewItemV2::HasDecoration) { |
|
893 return option->decorationSize; |
|
894 } |
|
895 break; |
|
896 default: |
|
897 break; |
|
898 } |
|
899 |
|
900 return QSize(0, 0); |
|
901 } |
|
902 |
|
903 static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth) |
|
904 { |
|
905 qreal height = 0; |
|
906 qreal widthUsed = 0; |
|
907 textLayout.beginLayout(); |
|
908 while (true) { |
|
909 QTextLine line = textLayout.createLine(); |
|
910 if (!line.isValid()) |
|
911 break; |
|
912 line.setLineWidth(lineWidth); |
|
913 line.setPosition(QPointF(0, height)); |
|
914 height += line.height(); |
|
915 widthUsed = qMax(widthUsed, line.naturalTextWidth()); |
|
916 } |
|
917 textLayout.endLayout(); |
|
918 return QSizeF(widthUsed, height); |
|
919 } |
|
920 |
|
921 void QCommonStylePrivate::viewItemDrawText(QPainter *p, const QStyleOptionViewItemV4 *option, const QRect &rect) const |
|
922 { |
|
923 Q_Q(const QCommonStyle); |
|
924 const QWidget *widget = option->widget; |
|
925 const int textMargin = q->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, widget) + 1; |
|
926 |
|
927 QRect textRect = rect.adjusted(textMargin, 0, -textMargin, 0); // remove width padding |
|
928 const bool wrapText = option->features & QStyleOptionViewItemV2::WrapText; |
|
929 QTextOption textOption; |
|
930 textOption.setWrapMode(wrapText ? QTextOption::WordWrap : QTextOption::ManualWrap); |
|
931 textOption.setTextDirection(option->direction); |
|
932 textOption.setAlignment(QStyle::visualAlignment(option->direction, option->displayAlignment)); |
|
933 QTextLayout textLayout; |
|
934 textLayout.setTextOption(textOption); |
|
935 textLayout.setFont(option->font); |
|
936 textLayout.setText(option->text); |
|
937 |
|
938 QSizeF textLayoutSize = viewItemTextLayout(textLayout, textRect.width()); |
|
939 |
|
940 QString elidedText; |
|
941 qreal height = 0; |
|
942 qreal width = 0; |
|
943 int elidedIndex = -1; |
|
944 const int lineCount = textLayout.lineCount(); |
|
945 for (int j = 0; j < lineCount; ++j) { |
|
946 const QTextLine line = textLayout.lineAt(j); |
|
947 if (j + 1 <= lineCount - 1) { |
|
948 const QTextLine nextLine = textLayout.lineAt(j + 1); |
|
949 if ((nextLine.y() + nextLine.height()) > textRect.height()) { |
|
950 int start = line.textStart(); |
|
951 int length = line.textLength() + nextLine.textLength(); |
|
952 const QStackTextEngine engine(textLayout.text().mid(start, length), option->font); |
|
953 elidedText = engine.elidedText(option->textElideMode, textRect.width()); |
|
954 height += line.height(); |
|
955 width = textRect.width(); |
|
956 elidedIndex = j; |
|
957 break; |
|
958 } |
|
959 } |
|
960 if (line.naturalTextWidth() > textRect.width()) { |
|
961 int start = line.textStart(); |
|
962 int length = line.textLength(); |
|
963 const QStackTextEngine engine(textLayout.text().mid(start, length), option->font); |
|
964 elidedText = engine.elidedText(option->textElideMode, textRect.width()); |
|
965 height += line.height(); |
|
966 width = textRect.width(); |
|
967 elidedIndex = j; |
|
968 break; |
|
969 } |
|
970 width = qMax<qreal>(width, line.width()); |
|
971 height += line.height(); |
|
972 } |
|
973 |
|
974 const QRect layoutRect = QStyle::alignedRect(option->direction, option->displayAlignment, |
|
975 QSize(int(width), int(height)), textRect); |
|
976 const QPointF position = layoutRect.topLeft(); |
|
977 for (int i = 0; i < lineCount; ++i) { |
|
978 const QTextLine line = textLayout.lineAt(i); |
|
979 if (i == elidedIndex) { |
|
980 qreal x = position.x() + line.x(); |
|
981 qreal y = position.y() + line.y() + line.ascent(); |
|
982 p->save(); |
|
983 p->setFont(option->font); |
|
984 p->drawText(int(x), int(y), elidedText); |
|
985 p->restore(); |
|
986 break; |
|
987 } |
|
988 line.draw(p, position); |
|
989 } |
|
990 } |
|
991 |
|
992 /*! \internal |
|
993 compute the position for the different component of an item (pixmap, text, checkbox) |
|
994 |
|
995 Set sizehint to false to layout the elements inside opt->rect. Set sizehint to true to ignore |
|
996 opt->rect and return rectangles in infinite space |
|
997 |
|
998 Code duplicated in QItemDelegate::doLayout |
|
999 */ |
|
1000 void QCommonStylePrivate::viewItemLayout(const QStyleOptionViewItemV4 *opt, QRect *checkRect, |
|
1001 QRect *pixmapRect, QRect *textRect, bool sizehint) const |
|
1002 { |
|
1003 Q_Q(const QCommonStyle); |
|
1004 Q_ASSERT(checkRect && pixmapRect && textRect); |
|
1005 *pixmapRect = QRect(QPoint(0, 0), viewItemSize(opt, Qt::DecorationRole)); |
|
1006 *textRect = QRect(QPoint(0, 0), viewItemSize(opt, Qt::DisplayRole)); |
|
1007 *checkRect = QRect(QPoint(0, 0), viewItemSize(opt, Qt::CheckStateRole)); |
|
1008 |
|
1009 const QWidget *widget = opt->widget; |
|
1010 const bool hasCheck = checkRect->isValid(); |
|
1011 const bool hasPixmap = pixmapRect->isValid(); |
|
1012 const bool hasText = textRect->isValid(); |
|
1013 const int textMargin = hasText ? q->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0; |
|
1014 const int pixmapMargin = hasPixmap ? q->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0; |
|
1015 const int checkMargin = hasCheck ? q->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, widget) + 1 : 0; |
|
1016 int x = opt->rect.left(); |
|
1017 int y = opt->rect.top(); |
|
1018 int w, h; |
|
1019 |
|
1020 if (textRect->height() == 0 && (!hasPixmap || !sizehint)) { |
|
1021 //if there is no text, we still want to have a decent height for the item sizeHint and the editor size |
|
1022 textRect->setHeight(opt->fontMetrics.height()); |
|
1023 } |
|
1024 |
|
1025 QSize pm(0, 0); |
|
1026 if (hasPixmap) { |
|
1027 pm = pixmapRect->size(); |
|
1028 pm.rwidth() += 2 * pixmapMargin; |
|
1029 } |
|
1030 if (sizehint) { |
|
1031 h = qMax(checkRect->height(), qMax(textRect->height(), pm.height())); |
|
1032 if (opt->decorationPosition == QStyleOptionViewItem::Left |
|
1033 || opt->decorationPosition == QStyleOptionViewItem::Right) { |
|
1034 w = textRect->width() + pm.width(); |
|
1035 } else { |
|
1036 w = qMax(textRect->width(), pm.width()); |
|
1037 } |
|
1038 } else { |
|
1039 w = opt->rect.width(); |
|
1040 h = opt->rect.height(); |
|
1041 } |
|
1042 |
|
1043 int cw = 0; |
|
1044 QRect check; |
|
1045 if (hasCheck) { |
|
1046 cw = checkRect->width() + 2 * checkMargin; |
|
1047 if (sizehint) w += cw; |
|
1048 if (opt->direction == Qt::RightToLeft) { |
|
1049 check.setRect(x + w - cw, y, cw, h); |
|
1050 } else { |
|
1051 check.setRect(x, y, cw, h); |
|
1052 } |
|
1053 } |
|
1054 |
|
1055 QRect display; |
|
1056 QRect decoration; |
|
1057 switch (opt->decorationPosition) { |
|
1058 case QStyleOptionViewItem::Top: { |
|
1059 if (hasPixmap) |
|
1060 pm.setHeight(pm.height() + pixmapMargin); // add space |
|
1061 h = sizehint ? textRect->height() : h - pm.height(); |
|
1062 |
|
1063 if (opt->direction == Qt::RightToLeft) { |
|
1064 decoration.setRect(x, y, w - cw, pm.height()); |
|
1065 display.setRect(x, y + pm.height(), w - cw, h); |
|
1066 } else { |
|
1067 decoration.setRect(x + cw, y, w - cw, pm.height()); |
|
1068 display.setRect(x + cw, y + pm.height(), w - cw, h); |
|
1069 } |
|
1070 break; } |
|
1071 case QStyleOptionViewItem::Bottom: { |
|
1072 if (hasText) |
|
1073 textRect->setHeight(textRect->height() + textMargin); // add space |
|
1074 h = sizehint ? textRect->height() + pm.height() : h; |
|
1075 |
|
1076 if (opt->direction == Qt::RightToLeft) { |
|
1077 display.setRect(x, y, w - cw, textRect->height()); |
|
1078 decoration.setRect(x, y + textRect->height(), w - cw, h - textRect->height()); |
|
1079 } else { |
|
1080 display.setRect(x + cw, y, w - cw, textRect->height()); |
|
1081 decoration.setRect(x + cw, y + textRect->height(), w - cw, h - textRect->height()); |
|
1082 } |
|
1083 break; } |
|
1084 case QStyleOptionViewItem::Left: { |
|
1085 if (opt->direction == Qt::LeftToRight) { |
|
1086 decoration.setRect(x + cw, y, pm.width(), h); |
|
1087 display.setRect(decoration.right() + 1, y, w - pm.width() - cw, h); |
|
1088 } else { |
|
1089 display.setRect(x, y, w - pm.width() - cw, h); |
|
1090 decoration.setRect(display.right() + 1, y, pm.width(), h); |
|
1091 } |
|
1092 break; } |
|
1093 case QStyleOptionViewItem::Right: { |
|
1094 if (opt->direction == Qt::LeftToRight) { |
|
1095 display.setRect(x + cw, y, w - pm.width() - cw, h); |
|
1096 decoration.setRect(display.right() + 1, y, pm.width(), h); |
|
1097 } else { |
|
1098 decoration.setRect(x, y, pm.width(), h); |
|
1099 display.setRect(decoration.right() + 1, y, w - pm.width() - cw, h); |
|
1100 } |
|
1101 break; } |
|
1102 default: |
|
1103 qWarning("doLayout: decoration position is invalid"); |
|
1104 decoration = *pixmapRect; |
|
1105 break; |
|
1106 } |
|
1107 |
|
1108 if (!sizehint) { // we only need to do the internal layout if we are going to paint |
|
1109 *checkRect = QStyle::alignedRect(opt->direction, Qt::AlignCenter, |
|
1110 checkRect->size(), check); |
|
1111 *pixmapRect = QStyle::alignedRect(opt->direction, opt->decorationAlignment, |
|
1112 pixmapRect->size(), decoration); |
|
1113 // the text takes up all available space, unless the decoration is not shown as selected |
|
1114 if (opt->showDecorationSelected) |
|
1115 *textRect = display; |
|
1116 else |
|
1117 *textRect = QStyle::alignedRect(opt->direction, opt->displayAlignment, |
|
1118 textRect->size().boundedTo(display.size()), display); |
|
1119 } else { |
|
1120 *checkRect = check; |
|
1121 *pixmapRect = decoration; |
|
1122 *textRect = display; |
|
1123 } |
|
1124 } |
|
1125 #endif // QT_NO_ITEMVIEWS |
|
1126 |
|
1127 |
|
1128 #ifndef QT_NO_TABBAR |
|
1129 /*! \internal |
|
1130 Compute the textRect and the pixmapRect from the opt rect |
|
1131 |
|
1132 Uses the same computation than in QTabBar::tabSizeHint |
|
1133 */ |
|
1134 void QCommonStylePrivate::tabLayout(const QStyleOptionTabV3 *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const |
|
1135 { |
|
1136 Q_ASSERT(textRect); |
|
1137 Q_ASSERT(iconRect); |
|
1138 QRect tr = opt->rect; |
|
1139 bool verticalTabs = opt->shape == QTabBar::RoundedEast |
|
1140 || opt->shape == QTabBar::RoundedWest |
|
1141 || opt->shape == QTabBar::TriangularEast |
|
1142 || opt->shape == QTabBar::TriangularWest; |
|
1143 if (verticalTabs) |
|
1144 tr.setRect(0, 0, tr.height(), tr.width()); //0, 0 as we will have a translate transform |
|
1145 |
|
1146 int verticalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftVertical, opt, widget); |
|
1147 int horizontalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, opt, widget); |
|
1148 int hpadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2; |
|
1149 int vpadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabVSpace, opt, widget) / 2; |
|
1150 if (opt->shape == QTabBar::RoundedSouth || opt->shape == QTabBar::TriangularSouth) |
|
1151 verticalShift = -verticalShift; |
|
1152 tr.adjust(hpadding, verticalShift - vpadding, horizontalShift - hpadding, vpadding); |
|
1153 bool selected = opt->state & QStyle::State_Selected; |
|
1154 if (selected) { |
|
1155 tr.setTop(tr.top() - verticalShift); |
|
1156 tr.setRight(tr.right() - horizontalShift); |
|
1157 } |
|
1158 |
|
1159 // left widget |
|
1160 if (!opt->leftButtonSize.isEmpty()) { |
|
1161 tr.setLeft(tr.left() + 4 + |
|
1162 (verticalTabs ? opt->leftButtonSize.height() : opt->leftButtonSize.width())); |
|
1163 } |
|
1164 // right widget |
|
1165 if (!opt->rightButtonSize.isEmpty()) { |
|
1166 tr.setRight(tr.right() - 4 - |
|
1167 (verticalTabs ? opt->rightButtonSize.height() : opt->rightButtonSize.width())); |
|
1168 } |
|
1169 |
|
1170 // icon |
|
1171 if (!opt->icon.isNull()) { |
|
1172 QSize iconSize = opt->iconSize; |
|
1173 if (!iconSize.isValid()) { |
|
1174 int iconExtent = proxyStyle->pixelMetric(QStyle::PM_SmallIconSize); |
|
1175 iconSize = QSize(iconExtent, iconExtent); |
|
1176 } |
|
1177 QSize tabIconSize = opt->icon.actualSize(iconSize, |
|
1178 (opt->state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled, |
|
1179 (opt->state & QStyle::State_Selected) ? QIcon::On : QIcon::Off ); |
|
1180 |
|
1181 *iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2, |
|
1182 tabIconSize.width(), tabIconSize .height()); |
|
1183 if (!verticalTabs) |
|
1184 *iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect); |
|
1185 tr.setLeft(tr.left() + tabIconSize.width() + 4); |
|
1186 } |
|
1187 |
|
1188 if (!verticalTabs) |
|
1189 tr = proxyStyle->visualRect(opt->direction, opt->rect, tr); |
|
1190 |
|
1191 *textRect = tr; |
|
1192 } |
|
1193 #endif //QT_NO_TABBAR |
|
1194 |
|
1195 |
|
1196 /*! |
|
1197 \reimp |
|
1198 */ |
|
1199 void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, |
|
1200 QPainter *p, const QWidget *widget) const |
|
1201 { |
|
1202 Q_D(const QCommonStyle); |
|
1203 switch (element) { |
|
1204 |
|
1205 case CE_PushButton: |
|
1206 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
1207 proxy()->drawControl(CE_PushButtonBevel, btn, p, widget); |
|
1208 QStyleOptionButton subopt = *btn; |
|
1209 subopt.rect = subElementRect(SE_PushButtonContents, btn, widget); |
|
1210 proxy()->drawControl(CE_PushButtonLabel, &subopt, p, widget); |
|
1211 if (btn->state & State_HasFocus) { |
|
1212 QStyleOptionFocusRect fropt; |
|
1213 fropt.QStyleOption::operator=(*btn); |
|
1214 fropt.rect = subElementRect(SE_PushButtonFocusRect, btn, widget); |
|
1215 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget); |
|
1216 } |
|
1217 } |
|
1218 break; |
|
1219 case CE_PushButtonBevel: |
|
1220 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
1221 QRect br = btn->rect; |
|
1222 int dbi = proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget); |
|
1223 if (btn->features & QStyleOptionButton::DefaultButton) |
|
1224 proxy()->drawPrimitive(PE_FrameDefaultButton, opt, p, widget); |
|
1225 if (btn->features & QStyleOptionButton::AutoDefaultButton) |
|
1226 br.setCoords(br.left() + dbi, br.top() + dbi, br.right() - dbi, br.bottom() - dbi); |
|
1227 if (!(btn->features & (QStyleOptionButton::Flat | QStyleOptionButton::CommandLinkButton)) |
|
1228 || btn->state & (State_Sunken | State_On) |
|
1229 || (btn->features & QStyleOptionButton::CommandLinkButton && btn->state & State_MouseOver)) { |
|
1230 QStyleOptionButton tmpBtn = *btn; |
|
1231 tmpBtn.rect = br; |
|
1232 proxy()->drawPrimitive(PE_PanelButtonCommand, &tmpBtn, p, widget); |
|
1233 } |
|
1234 if (btn->features & QStyleOptionButton::HasMenu) { |
|
1235 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, btn, widget); |
|
1236 QRect ir = btn->rect; |
|
1237 QStyleOptionButton newBtn = *btn; |
|
1238 newBtn.rect = QRect(ir.right() - mbi + 2, ir.height()/2 - mbi/2 + 3, mbi - 6, mbi - 6); |
|
1239 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget); |
|
1240 } |
|
1241 } |
|
1242 break; |
|
1243 case CE_PushButtonLabel: |
|
1244 if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
1245 QRect textRect = button->rect; |
|
1246 uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic; |
|
1247 if (!proxy()->styleHint(SH_UnderlineShortcut, button, widget)) |
|
1248 tf |= Qt::TextHideMnemonic; |
|
1249 |
|
1250 if (!button->icon.isNull()) { |
|
1251 //Center both icon and text |
|
1252 QRect iconRect; |
|
1253 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; |
|
1254 if (mode == QIcon::Normal && button->state & State_HasFocus) |
|
1255 mode = QIcon::Active; |
|
1256 QIcon::State state = QIcon::Off; |
|
1257 if (button->state & State_On) |
|
1258 state = QIcon::On; |
|
1259 |
|
1260 QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state); |
|
1261 int labelWidth = pixmap.width(); |
|
1262 int labelHeight = pixmap.height(); |
|
1263 int iconSpacing = 4;//### 4 is currently hardcoded in QPushButton::sizeHint() |
|
1264 int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width(); |
|
1265 if (!button->text.isEmpty()) |
|
1266 labelWidth += (textWidth + iconSpacing); |
|
1267 |
|
1268 iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2, |
|
1269 textRect.y() + (textRect.height() - labelHeight) / 2, |
|
1270 pixmap.width(), pixmap.height()); |
|
1271 |
|
1272 iconRect = visualRect(button->direction, textRect, iconRect); |
|
1273 |
|
1274 tf |= Qt::AlignLeft; //left align, we adjust the text-rect instead |
|
1275 |
|
1276 if (button->direction == Qt::RightToLeft) |
|
1277 textRect.setRight(iconRect.left() - iconSpacing); |
|
1278 else |
|
1279 textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing); |
|
1280 |
|
1281 if (button->state & (State_On | State_Sunken)) |
|
1282 iconRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget), |
|
1283 proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget)); |
|
1284 p->drawPixmap(iconRect, pixmap); |
|
1285 } else { |
|
1286 tf |= Qt::AlignHCenter; |
|
1287 } |
|
1288 if (button->state & (State_On | State_Sunken)) |
|
1289 textRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget), |
|
1290 proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget)); |
|
1291 |
|
1292 if (button->features & QStyleOptionButton::HasMenu) { |
|
1293 int indicatorSize = proxy()->pixelMetric(PM_MenuButtonIndicator, button, widget); |
|
1294 if (button->direction == Qt::LeftToRight) |
|
1295 textRect = textRect.adjusted(0, 0, -indicatorSize, 0); |
|
1296 else |
|
1297 textRect = textRect.adjusted(indicatorSize, 0, 0, 0); |
|
1298 } |
|
1299 proxy()->drawItemText(p, textRect, tf, button->palette, (button->state & State_Enabled), |
|
1300 button->text, QPalette::ButtonText); |
|
1301 } |
|
1302 break; |
|
1303 case CE_RadioButton: |
|
1304 case CE_CheckBox: |
|
1305 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
1306 bool isRadio = (element == CE_RadioButton); |
|
1307 QStyleOptionButton subopt = *btn; |
|
1308 subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator |
|
1309 : SE_CheckBoxIndicator, btn, widget); |
|
1310 proxy()->drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox, |
|
1311 &subopt, p, widget); |
|
1312 subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents |
|
1313 : SE_CheckBoxContents, btn, widget); |
|
1314 proxy()->drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, p, widget); |
|
1315 if (btn->state & State_HasFocus) { |
|
1316 QStyleOptionFocusRect fropt; |
|
1317 fropt.QStyleOption::operator=(*btn); |
|
1318 fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect |
|
1319 : SE_CheckBoxFocusRect, btn, widget); |
|
1320 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget); |
|
1321 } |
|
1322 } |
|
1323 break; |
|
1324 case CE_RadioButtonLabel: |
|
1325 case CE_CheckBoxLabel: |
|
1326 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
1327 uint alignment = visualAlignment(btn->direction, Qt::AlignLeft | Qt::AlignVCenter); |
|
1328 |
|
1329 if (!proxy()->styleHint(SH_UnderlineShortcut, btn, widget)) |
|
1330 alignment |= Qt::TextHideMnemonic; |
|
1331 QPixmap pix; |
|
1332 QRect textRect = btn->rect; |
|
1333 if (!btn->icon.isNull()) { |
|
1334 pix = btn->icon.pixmap(btn->iconSize, btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled); |
|
1335 proxy()->drawItemPixmap(p, btn->rect, alignment, pix); |
|
1336 if (btn->direction == Qt::RightToLeft) |
|
1337 textRect.setRight(textRect.right() - btn->iconSize.width() - 4); |
|
1338 else |
|
1339 textRect.setLeft(textRect.left() + btn->iconSize.width() + 4); |
|
1340 } |
|
1341 if (!btn->text.isEmpty()){ |
|
1342 proxy()->drawItemText(p, textRect, alignment | Qt::TextShowMnemonic, |
|
1343 btn->palette, btn->state & State_Enabled, btn->text, QPalette::WindowText); |
|
1344 } |
|
1345 } |
|
1346 break; |
|
1347 #ifndef QT_NO_MENU |
|
1348 case CE_MenuScroller: { |
|
1349 p->fillRect(opt->rect, opt->palette.background()); |
|
1350 QStyleOption arrowOpt = *opt; |
|
1351 arrowOpt.state |= State_Enabled; |
|
1352 proxy()->drawPrimitive(((opt->state & State_DownArrow) ? PE_IndicatorArrowDown : PE_IndicatorArrowUp), |
|
1353 &arrowOpt, p, widget); |
|
1354 break; } |
|
1355 case CE_MenuTearoff: |
|
1356 if (opt->state & State_Selected) |
|
1357 p->fillRect(opt->rect, opt->palette.brush(QPalette::Highlight)); |
|
1358 else |
|
1359 p->fillRect(opt->rect, opt->palette.brush(QPalette::Button)); |
|
1360 p->setPen(QPen(opt->palette.dark().color(), 1, Qt::DashLine)); |
|
1361 p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2 - 1, |
|
1362 opt->rect.x() + opt->rect.width() - 4, |
|
1363 opt->rect.y() + opt->rect.height() / 2 - 1); |
|
1364 p->setPen(QPen(opt->palette.light().color(), 1, Qt::DashLine)); |
|
1365 p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2, |
|
1366 opt->rect.x() + opt->rect.width() - 4, opt->rect.y() + opt->rect.height() / 2); |
|
1367 break; |
|
1368 #endif // QT_NO_MENU |
|
1369 #ifndef QT_NO_MENUBAR |
|
1370 case CE_MenuBarItem: |
|
1371 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { |
|
1372 uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip |
|
1373 | Qt::TextSingleLine; |
|
1374 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget)) |
|
1375 alignment |= Qt::TextHideMnemonic; |
|
1376 QPixmap pix = mbi->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), (mbi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); |
|
1377 if (!pix.isNull()) |
|
1378 proxy()->drawItemPixmap(p,mbi->rect, alignment, pix); |
|
1379 else |
|
1380 proxy()->drawItemText(p, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled, |
|
1381 mbi->text, QPalette::ButtonText); |
|
1382 } |
|
1383 break; |
|
1384 case CE_MenuBarEmptyArea: |
|
1385 if (widget && !widget->testAttribute(Qt::WA_NoSystemBackground)) |
|
1386 p->eraseRect(opt->rect); |
|
1387 break; |
|
1388 #endif // QT_NO_MENUBAR |
|
1389 #ifndef QT_NO_PROGRESSBAR |
|
1390 case CE_ProgressBar: |
|
1391 if (const QStyleOptionProgressBar *pb |
|
1392 = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { |
|
1393 QStyleOptionProgressBarV2 subopt = *pb; |
|
1394 subopt.rect = subElementRect(SE_ProgressBarGroove, pb, widget); |
|
1395 proxy()->drawControl(CE_ProgressBarGroove, &subopt, p, widget); |
|
1396 subopt.rect = subElementRect(SE_ProgressBarContents, pb, widget); |
|
1397 proxy()->drawControl(CE_ProgressBarContents, &subopt, p, widget); |
|
1398 if (pb->textVisible) { |
|
1399 subopt.rect = subElementRect(SE_ProgressBarLabel, pb, widget); |
|
1400 proxy()->drawControl(CE_ProgressBarLabel, &subopt, p, widget); |
|
1401 } |
|
1402 } |
|
1403 break; |
|
1404 case CE_ProgressBarGroove: |
|
1405 qDrawShadePanel(p, opt->rect, opt->palette, true, 1, |
|
1406 &opt->palette.brush(QPalette::Window)); |
|
1407 break; |
|
1408 case CE_ProgressBarLabel: |
|
1409 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { |
|
1410 bool vertical = false; |
|
1411 if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) { |
|
1412 vertical = (pb2->orientation == Qt::Vertical); |
|
1413 } |
|
1414 if (!vertical) { |
|
1415 QPalette::ColorRole textRole = QPalette::NoRole; |
|
1416 if ((pb->textAlignment & Qt::AlignCenter) && pb->textVisible |
|
1417 && ((qint64(pb->progress) - qint64(pb->minimum)) * 2 >= (qint64(pb->maximum) - qint64(pb->minimum)))) { |
|
1418 textRole = QPalette::HighlightedText; |
|
1419 //Draw text shadow, This will increase readability when the background of same color |
|
1420 QRect shadowRect(pb->rect); |
|
1421 shadowRect.translate(1,1); |
|
1422 QColor shadowColor = (pb->palette.color(textRole).value() <= 128) |
|
1423 ? QColor(255,255,255,160) : QColor(0,0,0,160); |
|
1424 QPalette shadowPalette = pb->palette; |
|
1425 shadowPalette.setColor(textRole, shadowColor); |
|
1426 proxy()->drawItemText(p, shadowRect, Qt::AlignCenter | Qt::TextSingleLine, shadowPalette, |
|
1427 pb->state & State_Enabled, pb->text, textRole); |
|
1428 } |
|
1429 proxy()->drawItemText(p, pb->rect, Qt::AlignCenter | Qt::TextSingleLine, pb->palette, |
|
1430 pb->state & State_Enabled, pb->text, textRole); |
|
1431 } |
|
1432 } |
|
1433 break; |
|
1434 case CE_ProgressBarContents: |
|
1435 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { |
|
1436 |
|
1437 QRect rect = pb->rect; |
|
1438 bool vertical = false; |
|
1439 bool inverted = false; |
|
1440 qint64 minimum = qint64(pb->minimum); |
|
1441 qint64 maximum = qint64(pb->maximum); |
|
1442 qint64 progress = qint64(pb->progress); |
|
1443 |
|
1444 // Get extra style options if version 2 |
|
1445 const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt); |
|
1446 if (pb2) { |
|
1447 vertical = (pb2->orientation == Qt::Vertical); |
|
1448 inverted = pb2->invertedAppearance; |
|
1449 } |
|
1450 QMatrix m; |
|
1451 |
|
1452 if (vertical) { |
|
1453 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width()); // flip width and height |
|
1454 m.rotate(90); |
|
1455 m.translate(0, -(rect.height() + rect.y()*2)); |
|
1456 } |
|
1457 |
|
1458 QPalette pal2 = pb->palette; |
|
1459 // Correct the highlight color if it is the same as the background |
|
1460 if (pal2.highlight() == pal2.background()) |
|
1461 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active, |
|
1462 QPalette::Highlight)); |
|
1463 bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical); |
|
1464 if (inverted) |
|
1465 reverse = !reverse; |
|
1466 int w = rect.width(); |
|
1467 if (pb->minimum == 0 && pb->maximum == 0) { |
|
1468 // draw busy indicator |
|
1469 int x = (progress - minimum) % (w * 2); |
|
1470 if (x > w) |
|
1471 x = 2 * w - x; |
|
1472 x = reverse ? rect.right() - x : x + rect.x(); |
|
1473 p->setPen(QPen(pal2.highlight().color(), 4)); |
|
1474 p->drawLine(x, rect.y(), x, rect.height()); |
|
1475 } else { |
|
1476 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget); |
|
1477 if (!unit_width) |
|
1478 return; |
|
1479 |
|
1480 int u; |
|
1481 if (unit_width > 1) |
|
1482 u = ((rect.width() + unit_width) / unit_width); |
|
1483 else |
|
1484 u = w / unit_width; |
|
1485 qint64 p_v = progress - minimum; |
|
1486 qint64 t_s = (maximum - minimum) ? (maximum - minimum) : qint64(1); |
|
1487 |
|
1488 if (u > 0 && p_v >= INT_MAX / u && t_s >= u) { |
|
1489 // scale down to something usable. |
|
1490 p_v /= u; |
|
1491 t_s /= u; |
|
1492 } |
|
1493 |
|
1494 // nu < tnu, if last chunk is only a partial chunk |
|
1495 int tnu, nu; |
|
1496 tnu = nu = p_v * u / t_s; |
|
1497 |
|
1498 if (nu * unit_width > w) |
|
1499 --nu; |
|
1500 |
|
1501 // Draw nu units out of a possible u of unit_width |
|
1502 // width, each a rectangle bordered by background |
|
1503 // color, all in a sunken panel with a percentage text |
|
1504 // display at the end. |
|
1505 int x = 0; |
|
1506 int x0 = reverse ? rect.right() - ((unit_width > 1) ? unit_width : 0) |
|
1507 : rect.x(); |
|
1508 |
|
1509 QStyleOptionProgressBarV2 pbBits = *pb; |
|
1510 pbBits.rect = rect; |
|
1511 pbBits.palette = pal2; |
|
1512 int myY = pbBits.rect.y(); |
|
1513 int myHeight = pbBits.rect.height(); |
|
1514 pbBits.state = State_None; |
|
1515 for (int i = 0; i < nu; ++i) { |
|
1516 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight); |
|
1517 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect(); |
|
1518 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget); |
|
1519 x += reverse ? -unit_width : unit_width; |
|
1520 } |
|
1521 |
|
1522 // Draw the last partial chunk to fill up the |
|
1523 // progress bar entirely |
|
1524 if (nu < tnu) { |
|
1525 int pixels_left = w - (nu * unit_width); |
|
1526 int offset = reverse ? x0 + x + unit_width-pixels_left : x0 + x; |
|
1527 pbBits.rect.setRect(offset, myY, pixels_left, myHeight); |
|
1528 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect(); |
|
1529 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget); |
|
1530 } |
|
1531 } |
|
1532 } |
|
1533 break; |
|
1534 #endif // QT_NO_PROGRESSBAR |
|
1535 case CE_HeaderLabel: |
|
1536 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { |
|
1537 QRect rect = header->rect; |
|
1538 if (!header->icon.isNull()) { |
|
1539 QPixmap pixmap |
|
1540 = header->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), (header->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); |
|
1541 int pixw = pixmap.width(); |
|
1542 |
|
1543 QRect aligned = alignedRect(header->direction, QFlag(header->iconAlignment), pixmap.size(), rect); |
|
1544 QRect inter = aligned.intersected(rect); |
|
1545 p->drawPixmap(inter.x(), inter.y(), pixmap, inter.x() - aligned.x(), inter.y() - aligned.y(), inter.width(), inter.height()); |
|
1546 |
|
1547 if (header->direction == Qt::LeftToRight) |
|
1548 rect.setLeft(rect.left() + pixw + 2); |
|
1549 else |
|
1550 rect.setRight(rect.right() - pixw - 2); |
|
1551 } |
|
1552 if (header->state & QStyle::State_On) { |
|
1553 QFont fnt = p->font(); |
|
1554 fnt.setBold(true); |
|
1555 p->setFont(fnt); |
|
1556 } |
|
1557 proxy()->drawItemText(p, rect, header->textAlignment, header->palette, |
|
1558 (header->state & State_Enabled), header->text, QPalette::ButtonText); |
|
1559 } |
|
1560 break; |
|
1561 #ifndef QT_NO_TOOLBUTTON |
|
1562 case CE_ToolButtonLabel: |
|
1563 if (const QStyleOptionToolButton *toolbutton |
|
1564 = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) { |
|
1565 QRect rect = toolbutton->rect; |
|
1566 int shiftX = 0; |
|
1567 int shiftY = 0; |
|
1568 if (toolbutton->state & (State_Sunken | State_On)) { |
|
1569 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, toolbutton, widget); |
|
1570 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, toolbutton, widget); |
|
1571 } |
|
1572 // Arrow type always overrules and is always shown |
|
1573 bool hasArrow = toolbutton->features & QStyleOptionToolButton::Arrow; |
|
1574 if (((!hasArrow && toolbutton->icon.isNull()) && !toolbutton->text.isEmpty()) |
|
1575 || toolbutton->toolButtonStyle == Qt::ToolButtonTextOnly) { |
|
1576 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic; |
|
1577 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget)) |
|
1578 alignment |= Qt::TextHideMnemonic; |
|
1579 rect.translate(shiftX, shiftY); |
|
1580 p->setFont(toolbutton->font); |
|
1581 proxy()->drawItemText(p, rect, alignment, toolbutton->palette, |
|
1582 opt->state & State_Enabled, toolbutton->text, |
|
1583 QPalette::ButtonText); |
|
1584 } else { |
|
1585 QPixmap pm; |
|
1586 QSize pmSize = toolbutton->iconSize; |
|
1587 if (!toolbutton->icon.isNull()) { |
|
1588 QIcon::State state = toolbutton->state & State_On ? QIcon::On : QIcon::Off; |
|
1589 QIcon::Mode mode; |
|
1590 if (!(toolbutton->state & State_Enabled)) |
|
1591 mode = QIcon::Disabled; |
|
1592 else if ((opt->state & State_MouseOver) && (opt->state & State_AutoRaise)) |
|
1593 mode = QIcon::Active; |
|
1594 else |
|
1595 mode = QIcon::Normal; |
|
1596 pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize), |
|
1597 mode, state); |
|
1598 pmSize = pm.size(); |
|
1599 } |
|
1600 |
|
1601 if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) { |
|
1602 p->setFont(toolbutton->font); |
|
1603 QRect pr = rect, |
|
1604 tr = rect; |
|
1605 int alignment = Qt::TextShowMnemonic; |
|
1606 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget)) |
|
1607 alignment |= Qt::TextHideMnemonic; |
|
1608 |
|
1609 if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) { |
|
1610 pr.setHeight(pmSize.height() + 6); |
|
1611 tr.adjust(0, pr.height() - 1, 0, -2); |
|
1612 pr.translate(shiftX, shiftY); |
|
1613 if (!hasArrow) { |
|
1614 proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pm); |
|
1615 } else { |
|
1616 drawArrow(this, toolbutton, pr, p, widget); |
|
1617 } |
|
1618 alignment |= Qt::AlignCenter; |
|
1619 } else { |
|
1620 pr.setWidth(pmSize.width() + 8); |
|
1621 tr.adjust(pr.width(), 0, 0, 0); |
|
1622 pr.translate(shiftX, shiftY); |
|
1623 if (!hasArrow) { |
|
1624 proxy()->drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, pr), Qt::AlignCenter, pm); |
|
1625 } else { |
|
1626 drawArrow(this, toolbutton, pr, p, widget); |
|
1627 } |
|
1628 alignment |= Qt::AlignLeft | Qt::AlignVCenter; |
|
1629 } |
|
1630 tr.translate(shiftX, shiftY); |
|
1631 proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette, |
|
1632 toolbutton->state & State_Enabled, toolbutton->text, |
|
1633 QPalette::ButtonText); |
|
1634 } else { |
|
1635 rect.translate(shiftX, shiftY); |
|
1636 if (hasArrow) { |
|
1637 drawArrow(this, toolbutton, rect, p, widget); |
|
1638 } else { |
|
1639 proxy()->drawItemPixmap(p, rect, Qt::AlignCenter, pm); |
|
1640 } |
|
1641 } |
|
1642 } |
|
1643 } |
|
1644 break; |
|
1645 #endif // QT_NO_TOOLBUTTON |
|
1646 #ifndef QT_NO_TOOLBOX |
|
1647 case CE_ToolBoxTab: |
|
1648 if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) { |
|
1649 proxy()->drawControl(CE_ToolBoxTabShape, tb, p, widget); |
|
1650 proxy()->drawControl(CE_ToolBoxTabLabel, tb, p, widget); |
|
1651 } |
|
1652 break; |
|
1653 case CE_ToolBoxTabShape: |
|
1654 if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) { |
|
1655 int d = 20 + tb->rect.height() - 3; |
|
1656 QPolygon a(7); |
|
1657 if (tb->direction != Qt::RightToLeft) { |
|
1658 a.setPoint(0, -1, tb->rect.height() + 1); |
|
1659 a.setPoint(1, -1, 1); |
|
1660 a.setPoint(2, tb->rect.width() - d, 1); |
|
1661 a.setPoint(3, tb->rect.width() - 20, tb->rect.height() - 2); |
|
1662 a.setPoint(4, tb->rect.width() - 1, tb->rect.height() - 2); |
|
1663 a.setPoint(5, tb->rect.width() - 1, tb->rect.height() + 1); |
|
1664 a.setPoint(6, -1, tb->rect.height() + 1); |
|
1665 } else { |
|
1666 a.setPoint(0, tb->rect.width(), tb->rect.height() + 1); |
|
1667 a.setPoint(1, tb->rect.width(), 1); |
|
1668 a.setPoint(2, d - 1, 1); |
|
1669 a.setPoint(3, 20 - 1, tb->rect.height() - 2); |
|
1670 a.setPoint(4, 0, tb->rect.height() - 2); |
|
1671 a.setPoint(5, 0, tb->rect.height() + 1); |
|
1672 a.setPoint(6, tb->rect.width(), tb->rect.height() + 1); |
|
1673 } |
|
1674 |
|
1675 p->setPen(tb->palette.mid().color().darker(150)); |
|
1676 p->drawPolygon(a); |
|
1677 p->setPen(tb->palette.light().color()); |
|
1678 if (tb->direction != Qt::RightToLeft) { |
|
1679 p->drawLine(0, 2, tb->rect.width() - d, 2); |
|
1680 p->drawLine(tb->rect.width() - d - 1, 2, tb->rect.width() - 21, tb->rect.height() - 1); |
|
1681 p->drawLine(tb->rect.width() - 20, tb->rect.height() - 1, |
|
1682 tb->rect.width(), tb->rect.height() - 1); |
|
1683 } else { |
|
1684 p->drawLine(tb->rect.width() - 1, 2, d - 1, 2); |
|
1685 p->drawLine(d, 2, 20, tb->rect.height() - 1); |
|
1686 p->drawLine(19, tb->rect.height() - 1, |
|
1687 -1, tb->rect.height() - 1); |
|
1688 } |
|
1689 p->setBrush(Qt::NoBrush); |
|
1690 } |
|
1691 break; |
|
1692 #endif // QT_NO_TOOLBOX |
|
1693 #ifndef QT_NO_TABBAR |
|
1694 case CE_TabBarTab: |
|
1695 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { |
|
1696 proxy()->drawControl(CE_TabBarTabShape, tab, p, widget); |
|
1697 proxy()->drawControl(CE_TabBarTabLabel, tab, p, widget); |
|
1698 } |
|
1699 break; |
|
1700 case CE_TabBarTabShape: |
|
1701 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { |
|
1702 p->save(); |
|
1703 |
|
1704 QRect rect(tab->rect); |
|
1705 bool selected = tab->state & State_Selected; |
|
1706 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab; |
|
1707 int tabOverlap = onlyOne ? 0 : proxy()->pixelMetric(PM_TabBarTabOverlap, opt, widget); |
|
1708 |
|
1709 if (!selected) { |
|
1710 switch (tab->shape) { |
|
1711 case QTabBar::TriangularNorth: |
|
1712 rect.adjust(0, 0, 0, -tabOverlap); |
|
1713 if(!selected) |
|
1714 rect.adjust(1, 1, -1, 0); |
|
1715 break; |
|
1716 case QTabBar::TriangularSouth: |
|
1717 rect.adjust(0, tabOverlap, 0, 0); |
|
1718 if(!selected) |
|
1719 rect.adjust(1, 0, -1, -1); |
|
1720 break; |
|
1721 case QTabBar::TriangularEast: |
|
1722 rect.adjust(tabOverlap, 0, 0, 0); |
|
1723 if(!selected) |
|
1724 rect.adjust(0, 1, -1, -1); |
|
1725 break; |
|
1726 case QTabBar::TriangularWest: |
|
1727 rect.adjust(0, 0, -tabOverlap, 0); |
|
1728 if(!selected) |
|
1729 rect.adjust(1, 1, 0, -1); |
|
1730 break; |
|
1731 default: |
|
1732 break; |
|
1733 } |
|
1734 } |
|
1735 |
|
1736 p->setPen(QPen(tab->palette.foreground(), 0)); |
|
1737 if (selected) { |
|
1738 p->setBrush(tab->palette.base()); |
|
1739 } else { |
|
1740 if (widget && widget->parentWidget()) |
|
1741 p->setBrush(widget->parentWidget()->palette().background()); |
|
1742 else |
|
1743 p->setBrush(tab->palette.background()); |
|
1744 } |
|
1745 |
|
1746 int y; |
|
1747 int x; |
|
1748 QPolygon a(10); |
|
1749 switch (tab->shape) { |
|
1750 case QTabBar::TriangularNorth: |
|
1751 case QTabBar::TriangularSouth: { |
|
1752 a.setPoint(0, 0, -1); |
|
1753 a.setPoint(1, 0, 0); |
|
1754 y = rect.height() - 2; |
|
1755 x = y / 3; |
|
1756 a.setPoint(2, x++, y - 1); |
|
1757 ++x; |
|
1758 a.setPoint(3, x++, y++); |
|
1759 a.setPoint(4, x, y); |
|
1760 |
|
1761 int i; |
|
1762 int right = rect.width() - 1; |
|
1763 for (i = 0; i < 5; ++i) |
|
1764 a.setPoint(9 - i, right - a.point(i).x(), a.point(i).y()); |
|
1765 if (tab->shape == QTabBar::TriangularNorth) |
|
1766 for (i = 0; i < 10; ++i) |
|
1767 a.setPoint(i, a.point(i).x(), rect.height() - 1 - a.point(i).y()); |
|
1768 |
|
1769 a.translate(rect.left(), rect.top()); |
|
1770 p->setRenderHint(QPainter::Antialiasing); |
|
1771 p->translate(0, 0.5); |
|
1772 |
|
1773 QPainterPath path; |
|
1774 path.addPolygon(a); |
|
1775 p->drawPath(path); |
|
1776 break; } |
|
1777 case QTabBar::TriangularEast: |
|
1778 case QTabBar::TriangularWest: { |
|
1779 a.setPoint(0, -1, 0); |
|
1780 a.setPoint(1, 0, 0); |
|
1781 x = rect.width() - 2; |
|
1782 y = x / 3; |
|
1783 a.setPoint(2, x - 1, y++); |
|
1784 ++y; |
|
1785 a.setPoint(3, x++, y++); |
|
1786 a.setPoint(4, x, y); |
|
1787 int i; |
|
1788 int bottom = rect.height() - 1; |
|
1789 for (i = 0; i < 5; ++i) |
|
1790 a.setPoint(9 - i, a.point(i).x(), bottom - a.point(i).y()); |
|
1791 if (tab->shape == QTabBar::TriangularWest) |
|
1792 for (i = 0; i < 10; ++i) |
|
1793 a.setPoint(i, rect.width() - 1 - a.point(i).x(), a.point(i).y()); |
|
1794 a.translate(rect.left(), rect.top()); |
|
1795 p->setRenderHint(QPainter::Antialiasing); |
|
1796 p->translate(0.5, 0); |
|
1797 QPainterPath path; |
|
1798 path.addPolygon(a); |
|
1799 p->drawPath(path); |
|
1800 break; } |
|
1801 default: |
|
1802 break; |
|
1803 } |
|
1804 p->restore(); |
|
1805 } |
|
1806 break; |
|
1807 case CE_ToolBoxTabLabel: |
|
1808 if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) { |
|
1809 bool enabled = tb->state & State_Enabled; |
|
1810 bool selected = tb->state & State_Selected; |
|
1811 QPixmap pm = tb->icon.pixmap(proxy()->pixelMetric(QStyle::PM_SmallIconSize, tb, widget), |
|
1812 enabled ? QIcon::Normal : QIcon::Disabled); |
|
1813 |
|
1814 QRect cr = subElementRect(QStyle::SE_ToolBoxTabContents, tb, widget); |
|
1815 QRect tr, ir; |
|
1816 int ih = 0; |
|
1817 if (pm.isNull()) { |
|
1818 tr = cr; |
|
1819 tr.adjust(4, 0, -8, 0); |
|
1820 } else { |
|
1821 int iw = pm.width() + 4; |
|
1822 ih = pm.height(); |
|
1823 ir = QRect(cr.left() + 4, cr.top(), iw + 2, ih); |
|
1824 tr = QRect(ir.right(), cr.top(), cr.width() - ir.right() - 4, cr.height()); |
|
1825 } |
|
1826 |
|
1827 if (selected && proxy()->styleHint(QStyle::SH_ToolBox_SelectedPageTitleBold, tb, widget)) { |
|
1828 QFont f(p->font()); |
|
1829 f.setBold(true); |
|
1830 p->setFont(f); |
|
1831 } |
|
1832 |
|
1833 QString txt = tb->fontMetrics.elidedText(tb->text, Qt::ElideRight, tr.width()); |
|
1834 |
|
1835 if (ih) |
|
1836 p->drawPixmap(ir.left(), (tb->rect.height() - ih) / 2, pm); |
|
1837 |
|
1838 int alignment = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic; |
|
1839 if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, tb, widget)) |
|
1840 alignment |= Qt::TextHideMnemonic; |
|
1841 proxy()->drawItemText(p, tr, alignment, tb->palette, enabled, txt, QPalette::ButtonText); |
|
1842 |
|
1843 if (!txt.isEmpty() && opt->state & State_HasFocus) { |
|
1844 QStyleOptionFocusRect opt; |
|
1845 opt.rect = tr; |
|
1846 opt.palette = tb->palette; |
|
1847 opt.state = QStyle::State_None; |
|
1848 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, widget); |
|
1849 } |
|
1850 } |
|
1851 break; |
|
1852 case CE_TabBarTabLabel: |
|
1853 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { |
|
1854 QStyleOptionTabV3 tabV2(*tab); |
|
1855 QRect tr = tabV2.rect; |
|
1856 bool verticalTabs = tabV2.shape == QTabBar::RoundedEast |
|
1857 || tabV2.shape == QTabBar::RoundedWest |
|
1858 || tabV2.shape == QTabBar::TriangularEast |
|
1859 || tabV2.shape == QTabBar::TriangularWest; |
|
1860 |
|
1861 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic; |
|
1862 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget)) |
|
1863 alignment |= Qt::TextHideMnemonic; |
|
1864 |
|
1865 if (verticalTabs) { |
|
1866 p->save(); |
|
1867 int newX, newY, newRot; |
|
1868 if (tabV2.shape == QTabBar::RoundedEast || tabV2.shape == QTabBar::TriangularEast) { |
|
1869 newX = tr.width() + tr.x(); |
|
1870 newY = tr.y(); |
|
1871 newRot = 90; |
|
1872 } else { |
|
1873 newX = tr.x(); |
|
1874 newY = tr.y() + tr.height(); |
|
1875 newRot = -90; |
|
1876 } |
|
1877 QTransform m = QTransform::fromTranslate(newX, newY); |
|
1878 m.rotate(newRot); |
|
1879 p->setTransform(m, true); |
|
1880 } |
|
1881 QRect iconRect; |
|
1882 d->tabLayout(&tabV2, widget, &tr, &iconRect); |
|
1883 tr = proxy()->subElementRect(SE_TabBarTabText, opt, widget); //we compute tr twice because the style may override subElementRect |
|
1884 |
|
1885 if (!tabV2.icon.isNull()) { |
|
1886 QPixmap tabIcon = tabV2.icon.pixmap(tabV2.iconSize, |
|
1887 (tabV2.state & State_Enabled) ? QIcon::Normal |
|
1888 : QIcon::Disabled, |
|
1889 (tabV2.state & State_Selected) ? QIcon::On |
|
1890 : QIcon::Off); |
|
1891 p->drawPixmap(iconRect.x(), iconRect.y(), tabIcon); |
|
1892 } |
|
1893 |
|
1894 proxy()->drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text, QPalette::WindowText); |
|
1895 if (verticalTabs) |
|
1896 p->restore(); |
|
1897 |
|
1898 if (tabV2.state & State_HasFocus) { |
|
1899 const int OFFSET = 1 + pixelMetric(PM_DefaultFrameWidth); |
|
1900 |
|
1901 int x1, x2; |
|
1902 x1 = tabV2.rect.left(); |
|
1903 x2 = tabV2.rect.right() - 1; |
|
1904 |
|
1905 QStyleOptionFocusRect fropt; |
|
1906 fropt.QStyleOption::operator=(*tab); |
|
1907 fropt.rect.setRect(x1 + 1 + OFFSET, tabV2.rect.y() + OFFSET, |
|
1908 x2 - x1 - 2*OFFSET, tabV2.rect.height() - 2*OFFSET); |
|
1909 drawPrimitive(PE_FrameFocusRect, &fropt, p, widget); |
|
1910 } |
|
1911 } |
|
1912 break; |
|
1913 #endif // QT_NO_TABBAR |
|
1914 #ifndef QT_NO_SIZEGRIP |
|
1915 case CE_SizeGrip: { |
|
1916 p->save(); |
|
1917 int x, y, w, h; |
|
1918 opt->rect.getRect(&x, &y, &w, &h); |
|
1919 |
|
1920 int sw = qMin(h, w); |
|
1921 if (h > w) |
|
1922 p->translate(0, h - w); |
|
1923 else |
|
1924 p->translate(w - h, 0); |
|
1925 |
|
1926 int sx = x; |
|
1927 int sy = y; |
|
1928 int s = sw / 3; |
|
1929 |
|
1930 Qt::Corner corner; |
|
1931 if (const QStyleOptionSizeGrip *sgOpt = qstyleoption_cast<const QStyleOptionSizeGrip *>(opt)) |
|
1932 corner = sgOpt->corner; |
|
1933 else if (opt->direction == Qt::RightToLeft) |
|
1934 corner = Qt::BottomLeftCorner; |
|
1935 else |
|
1936 corner = Qt::BottomRightCorner; |
|
1937 |
|
1938 if (corner == Qt::BottomLeftCorner) { |
|
1939 sx = x + sw; |
|
1940 for (int i = 0; i < 4; ++i) { |
|
1941 p->setPen(QPen(opt->palette.light().color(), 1)); |
|
1942 p->drawLine(x, sy - 1 , sx + 1, sw); |
|
1943 p->setPen(QPen(opt->palette.dark().color(), 1)); |
|
1944 p->drawLine(x, sy, sx, sw); |
|
1945 p->setPen(QPen(opt->palette.dark().color(), 1)); |
|
1946 p->drawLine(x, sy + 1, sx - 1, sw); |
|
1947 sx -= s; |
|
1948 sy += s; |
|
1949 } |
|
1950 } else if (corner == Qt::BottomRightCorner) { |
|
1951 for (int i = 0; i < 4; ++i) { |
|
1952 p->setPen(QPen(opt->palette.light().color(), 1)); |
|
1953 p->drawLine(sx - 1, sw, sw, sy - 1); |
|
1954 p->setPen(QPen(opt->palette.dark().color(), 1)); |
|
1955 p->drawLine(sx, sw, sw, sy); |
|
1956 p->setPen(QPen(opt->palette.dark().color(), 1)); |
|
1957 p->drawLine(sx + 1, sw, sw, sy + 1); |
|
1958 sx += s; |
|
1959 sy += s; |
|
1960 } |
|
1961 } else if (corner == Qt::TopRightCorner) { |
|
1962 sy = y + sw; |
|
1963 for (int i = 0; i < 4; ++i) { |
|
1964 p->setPen(QPen(opt->palette.light().color(), 1)); |
|
1965 p->drawLine(sx - 1, y, sw, sy + 1); |
|
1966 p->setPen(QPen(opt->palette.dark().color(), 1)); |
|
1967 p->drawLine(sx, y, sw, sy); |
|
1968 p->setPen(QPen(opt->palette.dark().color(), 1)); |
|
1969 p->drawLine(sx + 1, y, sw, sy - 1); |
|
1970 sx += s; |
|
1971 sy -= s; |
|
1972 } |
|
1973 } else if (corner == Qt::TopLeftCorner) { |
|
1974 for (int i = 0; i < 4; ++i) { |
|
1975 p->setPen(QPen(opt->palette.light().color(), 1)); |
|
1976 p->drawLine(x, sy - 1, sx - 1, y); |
|
1977 p->setPen(QPen(opt->palette.dark().color(), 1)); |
|
1978 p->drawLine(x, sy, sx, y); |
|
1979 p->setPen(QPen(opt->palette.dark().color(), 1)); |
|
1980 p->drawLine(x, sy + 1, sx + 1, y); |
|
1981 sx += s; |
|
1982 sy += s; |
|
1983 } |
|
1984 } |
|
1985 p->restore(); |
|
1986 break; } |
|
1987 #endif // QT_NO_SIZEGRIP |
|
1988 #ifndef QT_NO_RUBBERBAND |
|
1989 case CE_RubberBand: { |
|
1990 if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) { |
|
1991 QPixmap tiledPixmap(16, 16); |
|
1992 QPainter pixmapPainter(&tiledPixmap); |
|
1993 pixmapPainter.setPen(Qt::NoPen); |
|
1994 pixmapPainter.setBrush(Qt::Dense4Pattern); |
|
1995 pixmapPainter.setBackground(QBrush(opt->palette.base())); |
|
1996 pixmapPainter.setBackgroundMode(Qt::OpaqueMode); |
|
1997 pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height()); |
|
1998 pixmapPainter.end(); |
|
1999 // ### workaround for borked XRENDER |
|
2000 tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage()); |
|
2001 |
|
2002 p->save(); |
|
2003 QRect r = opt->rect; |
|
2004 QStyleHintReturnMask mask; |
|
2005 if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask)) |
|
2006 p->setClipRegion(mask.region); |
|
2007 p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap); |
|
2008 p->setPen(opt->palette.color(QPalette::Active, QPalette::WindowText)); |
|
2009 p->setBrush(Qt::NoBrush); |
|
2010 p->drawRect(r.adjusted(0, 0, -1, -1)); |
|
2011 if (rbOpt->shape == QRubberBand::Rectangle) |
|
2012 p->drawRect(r.adjusted(3, 3, -4, -4)); |
|
2013 p->restore(); |
|
2014 } |
|
2015 break; } |
|
2016 #endif // QT_NO_RUBBERBAND |
|
2017 #ifndef QT_NO_DOCKWIDGET |
|
2018 case CE_DockWidgetTitle: |
|
2019 if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) { |
|
2020 QRect r = dwOpt->rect.adjusted(0, 0, -1, -1); |
|
2021 if (dwOpt->movable) { |
|
2022 p->setPen(dwOpt->palette.color(QPalette::Dark)); |
|
2023 p->drawRect(r); |
|
2024 } |
|
2025 |
|
2026 if (!dwOpt->title.isEmpty()) { |
|
2027 const QStyleOptionDockWidgetV2 *v2 |
|
2028 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt); |
|
2029 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar; |
|
2030 |
|
2031 if (verticalTitleBar) { |
|
2032 QSize s = r.size(); |
|
2033 s.transpose(); |
|
2034 r.setSize(s); |
|
2035 |
|
2036 p->save(); |
|
2037 p->translate(r.left(), r.top() + r.width()); |
|
2038 p->rotate(-90); |
|
2039 p->translate(-r.left(), -r.top()); |
|
2040 } |
|
2041 |
|
2042 const int indent = p->fontMetrics().descent(); |
|
2043 proxy()->drawItemText(p, r.adjusted(indent + 1, 1, -indent - 1, -1), |
|
2044 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, dwOpt->palette, |
|
2045 dwOpt->state & State_Enabled, dwOpt->title, |
|
2046 QPalette::WindowText); |
|
2047 |
|
2048 if (verticalTitleBar) |
|
2049 p->restore(); |
|
2050 } |
|
2051 } |
|
2052 break; |
|
2053 #endif // QT_NO_DOCKWIDGET |
|
2054 case CE_Header: |
|
2055 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { |
|
2056 QRegion clipRegion = p->clipRegion(); |
|
2057 p->setClipRect(opt->rect); |
|
2058 proxy()->drawControl(CE_HeaderSection, header, p, widget); |
|
2059 QStyleOptionHeader subopt = *header; |
|
2060 subopt.rect = subElementRect(SE_HeaderLabel, header, widget); |
|
2061 if (subopt.rect.isValid()) |
|
2062 proxy()->drawControl(CE_HeaderLabel, &subopt, p, widget); |
|
2063 if (header->sortIndicator != QStyleOptionHeader::None) { |
|
2064 subopt.rect = subElementRect(SE_HeaderArrow, opt, widget); |
|
2065 proxy()->drawPrimitive(PE_IndicatorHeaderArrow, &subopt, p, widget); |
|
2066 } |
|
2067 p->setClipRegion(clipRegion); |
|
2068 } |
|
2069 break; |
|
2070 case CE_FocusFrame: |
|
2071 p->fillRect(opt->rect, opt->palette.foreground()); |
|
2072 break; |
|
2073 case CE_HeaderSection: |
|
2074 qDrawShadePanel(p, opt->rect, opt->palette, |
|
2075 opt->state & State_Sunken, 1, |
|
2076 &opt->palette.brush(QPalette::Button)); |
|
2077 break; |
|
2078 case CE_HeaderEmptyArea: |
|
2079 p->fillRect(opt->rect, opt->palette.background()); |
|
2080 break; |
|
2081 #ifndef QT_NO_COMBOBOX |
|
2082 case CE_ComboBoxLabel: |
|
2083 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { |
|
2084 QRect editRect = proxy()->subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget); |
|
2085 p->save(); |
|
2086 p->setClipRect(editRect); |
|
2087 if (!cb->currentIcon.isNull()) { |
|
2088 QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal |
|
2089 : QIcon::Disabled; |
|
2090 QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode); |
|
2091 QRect iconRect(editRect); |
|
2092 iconRect.setWidth(cb->iconSize.width() + 4); |
|
2093 iconRect = alignedRect(cb->direction, |
|
2094 Qt::AlignLeft | Qt::AlignVCenter, |
|
2095 iconRect.size(), editRect); |
|
2096 if (cb->editable) |
|
2097 p->fillRect(iconRect, opt->palette.brush(QPalette::Base)); |
|
2098 proxy()->drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap); |
|
2099 |
|
2100 if (cb->direction == Qt::RightToLeft) |
|
2101 editRect.translate(-4 - cb->iconSize.width(), 0); |
|
2102 else |
|
2103 editRect.translate(cb->iconSize.width() + 4, 0); |
|
2104 } |
|
2105 if (!cb->currentText.isEmpty() && !cb->editable) { |
|
2106 proxy()->drawItemText(p, editRect.adjusted(1, 0, -1, 0), |
|
2107 visualAlignment(cb->direction, Qt::AlignLeft | Qt::AlignVCenter), |
|
2108 cb->palette, cb->state & State_Enabled, cb->currentText); |
|
2109 } |
|
2110 p->restore(); |
|
2111 } |
|
2112 break; |
|
2113 #endif // QT_NO_COMBOBOX |
|
2114 #ifndef QT_NO_TOOLBAR |
|
2115 case CE_ToolBar: |
|
2116 if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) { |
|
2117 // Compatibility with styles that use PE_PanelToolBar |
|
2118 QStyleOptionFrame frame; |
|
2119 frame.QStyleOption::operator=(*toolBar); |
|
2120 frame.lineWidth = toolBar->lineWidth; |
|
2121 frame.midLineWidth = toolBar->midLineWidth; |
|
2122 proxy()->drawPrimitive(PE_PanelToolBar, opt, p, widget); |
|
2123 |
|
2124 if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) |
|
2125 break; |
|
2126 qDrawShadePanel(p, toolBar->rect, toolBar->palette, false, toolBar->lineWidth, |
|
2127 &toolBar->palette.brush(QPalette::Button)); |
|
2128 } |
|
2129 break; |
|
2130 #endif // QT_NO_TOOLBAR |
|
2131 case CE_ColumnViewGrip: { |
|
2132 // draw background gradients |
|
2133 QLinearGradient g(0, 0, opt->rect.width(), 0); |
|
2134 g.setColorAt(0, opt->palette.color(QPalette::Active, QPalette::Mid)); |
|
2135 g.setColorAt(0.5, Qt::white); |
|
2136 p->fillRect(QRect(0, 0, opt->rect.width(), opt->rect.height()), g); |
|
2137 |
|
2138 // draw the two lines |
|
2139 QPen pen(p->pen()); |
|
2140 pen.setWidth(opt->rect.width()/20); |
|
2141 pen.setColor(opt->palette.color(QPalette::Active, QPalette::Dark)); |
|
2142 p->setPen(pen); |
|
2143 |
|
2144 int line1starting = opt->rect.width()*8 / 20; |
|
2145 int line2starting = opt->rect.width()*13 / 20; |
|
2146 int top = opt->rect.height()*20/75; |
|
2147 int bottom = opt->rect.height() - 1 - top; |
|
2148 p->drawLine(line1starting, top, line1starting, bottom); |
|
2149 p->drawLine(line2starting, top, line2starting, bottom); |
|
2150 } |
|
2151 break; |
|
2152 |
|
2153 #ifndef QT_NO_ITEMVIEWS |
|
2154 case CE_ItemViewItem: |
|
2155 if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { |
|
2156 p->save(); |
|
2157 p->setClipRect(opt->rect); |
|
2158 |
|
2159 QRect checkRect = subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget); |
|
2160 QRect iconRect = subElementRect(SE_ItemViewItemDecoration, vopt, widget); |
|
2161 QRect textRect = subElementRect(SE_ItemViewItemText, vopt, widget); |
|
2162 |
|
2163 // draw the background |
|
2164 proxy()->drawPrimitive(PE_PanelItemViewItem, opt, p, widget); |
|
2165 |
|
2166 // draw the check mark |
|
2167 if (vopt->features & QStyleOptionViewItemV2::HasCheckIndicator) { |
|
2168 QStyleOptionViewItemV4 option(*vopt); |
|
2169 option.rect = checkRect; |
|
2170 option.state = option.state & ~QStyle::State_HasFocus; |
|
2171 |
|
2172 switch (vopt->checkState) { |
|
2173 case Qt::Unchecked: |
|
2174 option.state |= QStyle::State_Off; |
|
2175 break; |
|
2176 case Qt::PartiallyChecked: |
|
2177 option.state |= QStyle::State_NoChange; |
|
2178 break; |
|
2179 case Qt::Checked: |
|
2180 option.state |= QStyle::State_On; |
|
2181 break; |
|
2182 } |
|
2183 proxy()->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &option, p, widget); |
|
2184 } |
|
2185 |
|
2186 // draw the icon |
|
2187 QIcon::Mode mode = QIcon::Normal; |
|
2188 if (!(vopt->state & QStyle::State_Enabled)) |
|
2189 mode = QIcon::Disabled; |
|
2190 else if (vopt->state & QStyle::State_Selected) |
|
2191 mode = QIcon::Selected; |
|
2192 QIcon::State state = vopt->state & QStyle::State_Open ? QIcon::On : QIcon::Off; |
|
2193 vopt->icon.paint(p, iconRect, vopt->decorationAlignment, mode, state); |
|
2194 |
|
2195 // draw the text |
|
2196 if (!vopt->text.isEmpty()) { |
|
2197 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled |
|
2198 ? QPalette::Normal : QPalette::Disabled; |
|
2199 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active)) |
|
2200 cg = QPalette::Inactive; |
|
2201 |
|
2202 if (vopt->state & QStyle::State_Selected) { |
|
2203 p->setPen(vopt->palette.color(cg, QPalette::HighlightedText)); |
|
2204 } else { |
|
2205 p->setPen(vopt->palette.color(cg, QPalette::Text)); |
|
2206 } |
|
2207 if (vopt->state & QStyle::State_Editing) { |
|
2208 p->setPen(vopt->palette.color(cg, QPalette::Text)); |
|
2209 p->drawRect(textRect.adjusted(0, 0, -1, -1)); |
|
2210 } |
|
2211 |
|
2212 d->viewItemDrawText(p, vopt, textRect); |
|
2213 } |
|
2214 |
|
2215 // draw the focus rect |
|
2216 if (vopt->state & QStyle::State_HasFocus) { |
|
2217 QStyleOptionFocusRect o; |
|
2218 o.QStyleOption::operator=(*vopt); |
|
2219 o.rect = subElementRect(SE_ItemViewItemFocusRect, vopt, widget); |
|
2220 o.state |= QStyle::State_KeyboardFocusChange; |
|
2221 o.state |= QStyle::State_Item; |
|
2222 QPalette::ColorGroup cg = (vopt->state & QStyle::State_Enabled) |
|
2223 ? QPalette::Normal : QPalette::Disabled; |
|
2224 o.backgroundColor = vopt->palette.color(cg, (vopt->state & QStyle::State_Selected) |
|
2225 ? QPalette::Highlight : QPalette::Window); |
|
2226 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, p, widget); |
|
2227 } |
|
2228 |
|
2229 p->restore(); |
|
2230 } |
|
2231 break; |
|
2232 |
|
2233 #endif // QT_NO_ITEMVIEWS |
|
2234 #ifndef QT_NO_FRAME |
|
2235 case CE_ShapedFrame: |
|
2236 if (const QStyleOptionFrameV3 *f = qstyleoption_cast<const QStyleOptionFrameV3 *>(opt)) { |
|
2237 int frameShape = f->frameShape; |
|
2238 int frameShadow = QFrame::Plain; |
|
2239 if (f->state & QStyle::State_Sunken) { |
|
2240 frameShadow = QFrame::Sunken; |
|
2241 } else if (f->state & QStyle::State_Raised) { |
|
2242 frameShadow = QFrame::Raised; |
|
2243 } |
|
2244 |
|
2245 int lw = f->lineWidth; |
|
2246 int mlw = f->midLineWidth; |
|
2247 QPalette::ColorRole foregroundRole = QPalette::WindowText; |
|
2248 if (widget) |
|
2249 foregroundRole = widget->foregroundRole(); |
|
2250 |
|
2251 switch (frameShape) { |
|
2252 case QFrame::Box: |
|
2253 if (frameShadow == QFrame::Plain) { |
|
2254 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw); |
|
2255 } else { |
|
2256 qDrawShadeRect(p, f->rect, f->palette, frameShadow == QFrame::Sunken, lw, mlw); |
|
2257 } |
|
2258 break; |
|
2259 case QFrame::StyledPanel: |
|
2260 //keep the compatibility with Qt 4.4 if there is a proxy style. |
|
2261 //be sure to call drawPrimitive(QStyle::PE_Frame) on the proxy style |
|
2262 if (widget) { |
|
2263 widget->style()->drawPrimitive(QStyle::PE_Frame, opt, p, widget); |
|
2264 } else { |
|
2265 proxy()->drawPrimitive(QStyle::PE_Frame, opt, p, widget); |
|
2266 } |
|
2267 break; |
|
2268 case QFrame::Panel: |
|
2269 if (frameShadow == QFrame::Plain) { |
|
2270 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw); |
|
2271 } else { |
|
2272 qDrawShadePanel(p, f->rect, f->palette, frameShadow == QFrame::Sunken, lw); |
|
2273 } |
|
2274 break; |
|
2275 case QFrame::WinPanel: |
|
2276 if (frameShadow == QFrame::Plain) { |
|
2277 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw); |
|
2278 } else { |
|
2279 qDrawWinPanel(p, f->rect, f->palette, frameShadow == QFrame::Sunken); |
|
2280 } |
|
2281 break; |
|
2282 case QFrame::HLine: |
|
2283 case QFrame::VLine: { |
|
2284 QPoint p1, p2; |
|
2285 if (frameShape == QFrame::HLine) { |
|
2286 p1 = QPoint(opt->rect.x(), opt->rect.height() / 2); |
|
2287 p2 = QPoint(opt->rect.x() + opt->rect.width(), p1.y()); |
|
2288 } else { |
|
2289 p1 = QPoint(opt->rect.x()+opt->rect.width() / 2, 0); |
|
2290 p2 = QPoint(p1.x(), opt->rect.height()); |
|
2291 } |
|
2292 if (frameShadow == QFrame::Plain) { |
|
2293 QPen oldPen = p->pen(); |
|
2294 p->setPen(QPen(opt->palette.brush(foregroundRole), lw)); |
|
2295 p->drawLine(p1, p2); |
|
2296 p->setPen(oldPen); |
|
2297 } else { |
|
2298 qDrawShadeLine(p, p1, p2, f->palette, frameShadow == QFrame::Sunken, lw, mlw); |
|
2299 } |
|
2300 break; |
|
2301 } |
|
2302 } |
|
2303 } |
|
2304 break; |
|
2305 #endif |
|
2306 default: |
|
2307 break; |
|
2308 } |
|
2309 } |
|
2310 |
|
2311 /*! |
|
2312 \reimp |
|
2313 */ |
|
2314 QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, |
|
2315 const QWidget *widget) const |
|
2316 { |
|
2317 Q_D(const QCommonStyle); |
|
2318 QRect r; |
|
2319 switch (sr) { |
|
2320 case SE_PushButtonContents: |
|
2321 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
2322 int dx1, dx2; |
|
2323 dx1 = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget); |
|
2324 if (btn->features & QStyleOptionButton::AutoDefaultButton) |
|
2325 dx1 += proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget); |
|
2326 dx2 = dx1 * 2; |
|
2327 r.setRect(opt->rect.x() + dx1, opt->rect.y() + dx1, opt->rect.width() - dx2, |
|
2328 opt->rect.height() - dx2); |
|
2329 r = visualRect(opt->direction, opt->rect, r); |
|
2330 } |
|
2331 break; |
|
2332 case SE_PushButtonFocusRect: |
|
2333 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
2334 int dbw1 = 0, dbw2 = 0; |
|
2335 if (btn->features & QStyleOptionButton::AutoDefaultButton){ |
|
2336 dbw1 = proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget); |
|
2337 dbw2 = dbw1 * 2; |
|
2338 } |
|
2339 |
|
2340 int dfw1 = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget) + 1, |
|
2341 dfw2 = dfw1 * 2; |
|
2342 |
|
2343 r.setRect(btn->rect.x() + dfw1 + dbw1, btn->rect.y() + dfw1 + dbw1, |
|
2344 btn->rect.width() - dfw2 - dbw2, btn->rect.height()- dfw2 - dbw2); |
|
2345 r = visualRect(opt->direction, opt->rect, r); |
|
2346 } |
|
2347 break; |
|
2348 case SE_CheckBoxIndicator: |
|
2349 { |
|
2350 int h = proxy()->pixelMetric(PM_IndicatorHeight, opt, widget); |
|
2351 r.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - h) / 2), |
|
2352 proxy()->pixelMetric(PM_IndicatorWidth, opt, widget), h); |
|
2353 r = visualRect(opt->direction, opt->rect, r); |
|
2354 } |
|
2355 break; |
|
2356 |
|
2357 case SE_CheckBoxContents: |
|
2358 { |
|
2359 // Deal with the logical first, then convert it back to screen coords. |
|
2360 QRect ir = visualRect(opt->direction, opt->rect, |
|
2361 subElementRect(SE_CheckBoxIndicator, opt, widget)); |
|
2362 int spacing = proxy()->pixelMetric(PM_CheckBoxLabelSpacing, opt, widget); |
|
2363 r.setRect(ir.right() + spacing, opt->rect.y(), opt->rect.width() - ir.width() - spacing, |
|
2364 opt->rect.height()); |
|
2365 r = visualRect(opt->direction, opt->rect, r); |
|
2366 } |
|
2367 break; |
|
2368 |
|
2369 case SE_CheckBoxFocusRect: |
|
2370 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
2371 if (btn->icon.isNull() && btn->text.isEmpty()) { |
|
2372 r = subElementRect(SE_CheckBoxIndicator, opt, widget); |
|
2373 r.adjust(1, 1, -1, -1); |
|
2374 break; |
|
2375 } |
|
2376 // As above, deal with the logical first, then convert it back to screen coords. |
|
2377 QRect cr = visualRect(btn->direction, btn->rect, |
|
2378 subElementRect(SE_CheckBoxContents, btn, widget)); |
|
2379 |
|
2380 QRect iconRect, textRect; |
|
2381 if (!btn->text.isEmpty()) { |
|
2382 textRect = itemTextRect(opt->fontMetrics, cr, Qt::AlignAbsolute | Qt::AlignLeft |
|
2383 | Qt::AlignVCenter | Qt::TextShowMnemonic, |
|
2384 btn->state & State_Enabled, btn->text); |
|
2385 } |
|
2386 if (!btn->icon.isNull()) { |
|
2387 iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter |
|
2388 | Qt::TextShowMnemonic, |
|
2389 btn->icon.pixmap(btn->iconSize, QIcon::Normal)); |
|
2390 if (!textRect.isEmpty()) |
|
2391 textRect.translate(iconRect.right() + 4, 0); |
|
2392 } |
|
2393 r = iconRect | textRect; |
|
2394 r.adjust(-3, -2, 3, 2); |
|
2395 r = r.intersected(btn->rect); |
|
2396 r = visualRect(btn->direction, btn->rect, r); |
|
2397 } |
|
2398 break; |
|
2399 |
|
2400 case SE_RadioButtonIndicator: |
|
2401 { |
|
2402 int h = proxy()->pixelMetric(PM_ExclusiveIndicatorHeight, opt, widget); |
|
2403 r.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - h) / 2), |
|
2404 proxy()->pixelMetric(PM_ExclusiveIndicatorWidth, opt, widget), h); |
|
2405 r = visualRect(opt->direction, opt->rect, r); |
|
2406 } |
|
2407 break; |
|
2408 |
|
2409 case SE_RadioButtonContents: |
|
2410 { |
|
2411 QRect ir = visualRect(opt->direction, opt->rect, |
|
2412 subElementRect(SE_RadioButtonIndicator, opt, widget)); |
|
2413 int spacing = proxy()->pixelMetric(PM_RadioButtonLabelSpacing, opt, widget); |
|
2414 r.setRect(ir.left() + ir.width() + spacing, opt->rect.y(), opt->rect.width() - ir.width() - spacing, |
|
2415 opt->rect.height()); |
|
2416 r = visualRect(opt->direction, opt->rect, r); |
|
2417 break; |
|
2418 } |
|
2419 |
|
2420 case SE_RadioButtonFocusRect: |
|
2421 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
2422 if (btn->icon.isNull() && btn->text.isEmpty()) { |
|
2423 r = subElementRect(SE_RadioButtonIndicator, opt, widget); |
|
2424 r.adjust(1, 1, -1, -1); |
|
2425 break; |
|
2426 } |
|
2427 QRect cr = visualRect(btn->direction, btn->rect, |
|
2428 subElementRect(SE_RadioButtonContents, opt, widget)); |
|
2429 |
|
2430 QRect iconRect, textRect; |
|
2431 if (!btn->text.isEmpty()){ |
|
2432 textRect = itemTextRect(opt->fontMetrics, cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter |
|
2433 | Qt::TextShowMnemonic, btn->state & State_Enabled, btn->text); |
|
2434 } |
|
2435 if (!btn->icon.isNull()) { |
|
2436 iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, |
|
2437 btn->icon.pixmap(btn->iconSize, QIcon::Normal)); |
|
2438 if (!textRect.isEmpty()) |
|
2439 textRect.translate(iconRect.right() + 4, 0); |
|
2440 } |
|
2441 r = iconRect | textRect; |
|
2442 r.adjust(-3, -2, 3, 2); |
|
2443 r = r.intersected(btn->rect); |
|
2444 r = visualRect(btn->direction, btn->rect, r); |
|
2445 } |
|
2446 break; |
|
2447 #ifndef QT_NO_SLIDER |
|
2448 case SE_SliderFocusRect: |
|
2449 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
2450 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget); |
|
2451 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget); |
|
2452 if (slider->orientation == Qt::Horizontal) |
|
2453 r.setRect(0, tickOffset - 1, slider->rect.width(), thickness + 2); |
|
2454 else |
|
2455 r.setRect(tickOffset - 1, 0, thickness + 2, slider->rect.height()); |
|
2456 r = r.intersected(slider->rect); |
|
2457 r = visualRect(opt->direction, opt->rect, r); |
|
2458 } |
|
2459 break; |
|
2460 #endif // QT_NO_SLIDER |
|
2461 #ifndef QT_NO_PROGRESSBAR |
|
2462 case SE_ProgressBarGroove: |
|
2463 case SE_ProgressBarContents: |
|
2464 case SE_ProgressBarLabel: |
|
2465 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { |
|
2466 int textw = 0; |
|
2467 bool vertical = false; |
|
2468 if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) { |
|
2469 vertical = (pb2->orientation == Qt::Vertical); |
|
2470 } |
|
2471 if (!vertical) { |
|
2472 if (pb->textVisible) |
|
2473 textw = qMax(pb->fontMetrics.width(pb->text), pb->fontMetrics.width(QLatin1String("100%"))) + 6; |
|
2474 } |
|
2475 |
|
2476 if ((pb->textAlignment & Qt::AlignCenter) == 0) { |
|
2477 if (sr != SE_ProgressBarLabel) |
|
2478 r.setCoords(pb->rect.left(), pb->rect.top(), |
|
2479 pb->rect.right() - textw, pb->rect.bottom()); |
|
2480 else |
|
2481 r.setCoords(pb->rect.right() - textw, pb->rect.top(), |
|
2482 pb->rect.right(), pb->rect.bottom()); |
|
2483 } else { |
|
2484 r = pb->rect; |
|
2485 } |
|
2486 r = visualRect(pb->direction, pb->rect, r); |
|
2487 } |
|
2488 break; |
|
2489 #endif // QT_NO_PROGRESSBAR |
|
2490 #ifdef QT3_SUPPORT |
|
2491 case SE_Q3DockWindowHandleRect: |
|
2492 if (const QStyleOptionQ3DockWindow *dw = qstyleoption_cast<const QStyleOptionQ3DockWindow *>(opt)) { |
|
2493 if (!dw->docked || !dw->closeEnabled) |
|
2494 r.setRect(0, 0, dw->rect.width(), dw->rect.height()); |
|
2495 else { |
|
2496 if (dw->state & State_Horizontal) |
|
2497 r.setRect(0, 15, dw->rect.width(), dw->rect.height() - 15); |
|
2498 else |
|
2499 r.setRect(0, 1, dw->rect.width() - 15, dw->rect.height() - 1); |
|
2500 } |
|
2501 r = visualRect(opt->direction, opt->rect, r); |
|
2502 } |
|
2503 break; |
|
2504 #endif // QT3_SUPPORT |
|
2505 #ifndef QT_NO_COMBOBOX |
|
2506 case SE_ComboBoxFocusRect: |
|
2507 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { |
|
2508 int margin = cb->frame ? 3 : 0; |
|
2509 r.setRect(opt->rect.left() + margin, opt->rect.top() + margin, |
|
2510 opt->rect.width() - 2*margin - 16, opt->rect.height() - 2*margin); |
|
2511 r = visualRect(opt->direction, opt->rect, r); |
|
2512 } |
|
2513 break; |
|
2514 #endif // QT_NO_COMBOBOX |
|
2515 #ifndef QT_NO_TOOLBOX |
|
2516 case SE_ToolBoxTabContents: |
|
2517 r = opt->rect; |
|
2518 r.adjust(0, 0, -30, 0); |
|
2519 break; |
|
2520 #endif // QT_NO_TOOLBOX |
|
2521 case SE_HeaderLabel: { |
|
2522 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget); |
|
2523 r.setRect(opt->rect.x() + margin, opt->rect.y() + margin, |
|
2524 opt->rect.width() - margin * 2, opt->rect.height() - margin * 2); |
|
2525 |
|
2526 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { |
|
2527 // Subtract width needed for arrow, if there is one |
|
2528 if (header->sortIndicator != QStyleOptionHeader::None) { |
|
2529 if (opt->state & State_Horizontal) |
|
2530 r.setWidth(r.width() - (opt->rect.height() / 2) - (margin * 2)); |
|
2531 else |
|
2532 r.setHeight(r.height() - (opt->rect.width() / 2) - (margin * 2)); |
|
2533 } |
|
2534 } |
|
2535 r = visualRect(opt->direction, opt->rect, r); |
|
2536 break; } |
|
2537 case SE_HeaderArrow: { |
|
2538 int h = opt->rect.height(); |
|
2539 int w = opt->rect.width(); |
|
2540 int x = opt->rect.x(); |
|
2541 int y = opt->rect.y(); |
|
2542 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget); |
|
2543 |
|
2544 if (opt->state & State_Horizontal) { |
|
2545 int horiz_size = h / 2; |
|
2546 r.setRect(x + w - margin * 2 - horiz_size, y + 5, |
|
2547 horiz_size, h - margin * 2 - 5); |
|
2548 } else { |
|
2549 int vert_size = w / 2; |
|
2550 r.setRect(x + 5, y + h - margin * 2 - vert_size, |
|
2551 w - margin * 2 - 5, vert_size); |
|
2552 } |
|
2553 r = visualRect(opt->direction, opt->rect, r); |
|
2554 break; } |
|
2555 |
|
2556 case SE_RadioButtonClickRect: |
|
2557 r = subElementRect(SE_RadioButtonFocusRect, opt, widget); |
|
2558 r |= subElementRect(SE_RadioButtonIndicator, opt, widget); |
|
2559 break; |
|
2560 case SE_CheckBoxClickRect: |
|
2561 r = subElementRect(SE_CheckBoxFocusRect, opt, widget); |
|
2562 r |= subElementRect(SE_CheckBoxIndicator, opt, widget); |
|
2563 break; |
|
2564 #ifndef QT_NO_TABWIDGET |
|
2565 case SE_TabWidgetTabBar: |
|
2566 if (const QStyleOptionTabWidgetFrame *twf |
|
2567 = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { |
|
2568 r.setSize(twf->tabBarSize); |
|
2569 const uint alingMask = Qt::AlignLeft | Qt::AlignRight | Qt::AlignHCenter; |
|
2570 switch (twf->shape) { |
|
2571 case QTabBar::RoundedNorth: |
|
2572 case QTabBar::TriangularNorth: |
|
2573 // Constrain the size now, otherwise, center could get off the page |
|
2574 // This of course repeated for all the other directions |
|
2575 r.setWidth(qMin(r.width(), twf->rect.width() |
|
2576 - twf->leftCornerWidgetSize.width() |
|
2577 - twf->rightCornerWidgetSize.width())); |
|
2578 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) { |
|
2579 default: |
|
2580 case Qt::AlignLeft: |
|
2581 r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(), 0)); |
|
2582 break; |
|
2583 case Qt::AlignHCenter: |
|
2584 r.moveTopLeft(QPoint(twf->rect.center().x() - qRound(r.width() / 2.0f) |
|
2585 + (twf->leftCornerWidgetSize.width() / 2) |
|
2586 - (twf->rightCornerWidgetSize.width() / 2), 0)); |
|
2587 break; |
|
2588 case Qt::AlignRight: |
|
2589 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width() |
|
2590 - twf->rightCornerWidgetSize.width(), 0)); |
|
2591 break; |
|
2592 } |
|
2593 r = visualRect(twf->direction, twf->rect, r); |
|
2594 break; |
|
2595 case QTabBar::RoundedSouth: |
|
2596 case QTabBar::TriangularSouth: |
|
2597 r.setWidth(qMin(r.width(), twf->rect.width() |
|
2598 - twf->leftCornerWidgetSize.width() |
|
2599 - twf->rightCornerWidgetSize.width())); |
|
2600 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) { |
|
2601 default: |
|
2602 case Qt::AlignLeft: |
|
2603 r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(), |
|
2604 twf->rect.height() - twf->tabBarSize.height())); |
|
2605 break; |
|
2606 case Qt::AlignHCenter: |
|
2607 r.moveTopLeft(QPoint(twf->rect.center().x() - qRound(r.width() / 2.0f) |
|
2608 + (twf->leftCornerWidgetSize.width() / 2) |
|
2609 - (twf->rightCornerWidgetSize.width() / 2), |
|
2610 twf->rect.height() - twf->tabBarSize.height())); |
|
2611 break; |
|
2612 case Qt::AlignRight: |
|
2613 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width() |
|
2614 - twf->rightCornerWidgetSize.width(), |
|
2615 twf->rect.height() - twf->tabBarSize.height())); |
|
2616 break; |
|
2617 } |
|
2618 r = visualRect(twf->direction, twf->rect, r); |
|
2619 break; |
|
2620 case QTabBar::RoundedEast: |
|
2621 case QTabBar::TriangularEast: |
|
2622 r.setHeight(qMin(r.height(), twf->rect.height() |
|
2623 - twf->leftCornerWidgetSize.height() |
|
2624 - twf->rightCornerWidgetSize.height())); |
|
2625 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) { |
|
2626 default: |
|
2627 case Qt::AlignLeft: |
|
2628 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(), |
|
2629 twf->leftCornerWidgetSize.height())); |
|
2630 break; |
|
2631 case Qt::AlignHCenter: |
|
2632 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(), |
|
2633 twf->rect.center().y() - r.height() / 2)); |
|
2634 break; |
|
2635 case Qt::AlignRight: |
|
2636 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(), |
|
2637 twf->rect.height() - twf->tabBarSize.height() |
|
2638 - twf->rightCornerWidgetSize.height())); |
|
2639 break; |
|
2640 } |
|
2641 break; |
|
2642 case QTabBar::RoundedWest: |
|
2643 case QTabBar::TriangularWest: |
|
2644 r.setHeight(qMin(r.height(), twf->rect.height() |
|
2645 - twf->leftCornerWidgetSize.height() |
|
2646 - twf->rightCornerWidgetSize.height())); |
|
2647 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) { |
|
2648 default: |
|
2649 case Qt::AlignLeft: |
|
2650 r.moveTopLeft(QPoint(0, twf->leftCornerWidgetSize.height())); |
|
2651 break; |
|
2652 case Qt::AlignHCenter: |
|
2653 r.moveTopLeft(QPoint(0, twf->rect.center().y() - r.height() / 2)); |
|
2654 break; |
|
2655 case Qt::AlignRight: |
|
2656 r.moveTopLeft(QPoint(0, twf->rect.height() - twf->tabBarSize.height() |
|
2657 - twf->rightCornerWidgetSize.height())); |
|
2658 break; |
|
2659 } |
|
2660 break; |
|
2661 } |
|
2662 } |
|
2663 break; |
|
2664 case SE_TabWidgetTabPane: |
|
2665 case SE_TabWidgetTabContents: |
|
2666 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { |
|
2667 QStyleOptionTab tabopt; |
|
2668 tabopt.shape = twf->shape; |
|
2669 int overlap = proxy()->pixelMetric(PM_TabBarBaseOverlap, &tabopt, widget); |
|
2670 if (twf->lineWidth == 0) |
|
2671 overlap = 0; |
|
2672 switch (twf->shape) { |
|
2673 case QTabBar::RoundedNorth: |
|
2674 case QTabBar::TriangularNorth: |
|
2675 r = QRect(QPoint(0,qMax(twf->tabBarSize.height() - overlap, 0)), |
|
2676 QSize(twf->rect.width(), qMin(twf->rect.height() - twf->tabBarSize.height() + overlap, twf->rect.height()))); |
|
2677 break; |
|
2678 case QTabBar::RoundedSouth: |
|
2679 case QTabBar::TriangularSouth: |
|
2680 r = QRect(QPoint(0,0), QSize(twf->rect.width(), qMin(twf->rect.height() - twf->tabBarSize.height() + overlap, twf->rect.height()))); |
|
2681 break; |
|
2682 case QTabBar::RoundedEast: |
|
2683 case QTabBar::TriangularEast: |
|
2684 r = QRect(QPoint(0, 0), QSize(qMin(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.width()), twf->rect.height())); |
|
2685 break; |
|
2686 case QTabBar::RoundedWest: |
|
2687 case QTabBar::TriangularWest: |
|
2688 r = QRect(QPoint(qMax(twf->tabBarSize.width() - overlap, 0), 0), |
|
2689 QSize(qMin(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.width()), twf->rect.height())); |
|
2690 break; |
|
2691 } |
|
2692 if (sr == SE_TabWidgetTabContents && twf->lineWidth > 0) |
|
2693 r.adjust(2, 2, -2, -2); |
|
2694 } |
|
2695 break; |
|
2696 case SE_TabWidgetLeftCorner: |
|
2697 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { |
|
2698 QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf, widget); |
|
2699 switch (twf->shape) { |
|
2700 case QTabBar::RoundedNorth: |
|
2701 case QTabBar::TriangularNorth: |
|
2702 r = QRect(QPoint(paneRect.x(), paneRect.y() - twf->leftCornerWidgetSize.height()), |
|
2703 twf->leftCornerWidgetSize); |
|
2704 break; |
|
2705 case QTabBar::RoundedSouth: |
|
2706 case QTabBar::TriangularSouth: |
|
2707 r = QRect(QPoint(paneRect.x(), paneRect.height()), twf->leftCornerWidgetSize); |
|
2708 break; |
|
2709 default: |
|
2710 break; |
|
2711 } |
|
2712 r = visualRect(twf->direction, twf->rect, r); |
|
2713 } |
|
2714 break; |
|
2715 case SE_TabWidgetRightCorner: |
|
2716 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { |
|
2717 QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf, widget); |
|
2718 switch (twf->shape) { |
|
2719 case QTabBar::RoundedNorth: |
|
2720 case QTabBar::TriangularNorth: |
|
2721 r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(), |
|
2722 paneRect.y() - twf->rightCornerWidgetSize.height()), |
|
2723 twf->rightCornerWidgetSize); |
|
2724 break; |
|
2725 case QTabBar::RoundedSouth: |
|
2726 case QTabBar::TriangularSouth: |
|
2727 r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(), |
|
2728 paneRect.height()), twf->rightCornerWidgetSize); |
|
2729 break; |
|
2730 default: |
|
2731 break; |
|
2732 } |
|
2733 r = visualRect(twf->direction, twf->rect, r); |
|
2734 } |
|
2735 break; |
|
2736 case SE_TabBarTabText: |
|
2737 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { |
|
2738 QStyleOptionTabV3 tabV3(*tab); |
|
2739 QRect dummyIconRect; |
|
2740 d->tabLayout(&tabV3, widget, &r, &dummyIconRect); |
|
2741 } |
|
2742 break; |
|
2743 case SE_TabBarTabLeftButton: |
|
2744 case SE_TabBarTabRightButton: |
|
2745 if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(opt)) { |
|
2746 bool selected = tab->state & State_Selected; |
|
2747 int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget); |
|
2748 int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget); |
|
2749 int hpadding = proxy()->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2; |
|
2750 hpadding = qMax(hpadding, 4); //workaround KStyle returning 0 because they workaround an old bug in Qt |
|
2751 |
|
2752 bool verticalTabs = tab->shape == QTabBar::RoundedEast |
|
2753 || tab->shape == QTabBar::RoundedWest |
|
2754 || tab->shape == QTabBar::TriangularEast |
|
2755 || tab->shape == QTabBar::TriangularWest; |
|
2756 |
|
2757 QRect tr = tab->rect; |
|
2758 if (tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::TriangularSouth) |
|
2759 verticalShift = -verticalShift; |
|
2760 if (verticalTabs) { |
|
2761 qSwap(horizontalShift, verticalShift); |
|
2762 horizontalShift *= -1; |
|
2763 verticalShift *= -1; |
|
2764 } |
|
2765 if (tab->shape == QTabBar::RoundedWest || tab->shape == QTabBar::TriangularWest) |
|
2766 horizontalShift = -horizontalShift; |
|
2767 |
|
2768 tr.adjust(0, 0, horizontalShift, verticalShift); |
|
2769 if (selected) |
|
2770 { |
|
2771 tr.setBottom(tr.bottom() - verticalShift); |
|
2772 tr.setRight(tr.right() - horizontalShift); |
|
2773 } |
|
2774 |
|
2775 QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize; |
|
2776 int w = size.width(); |
|
2777 int h = size.height(); |
|
2778 int midHeight = static_cast<int>(qCeil(float(tr.height() - h) / 2)); |
|
2779 int midWidth = ((tr.width() - w) / 2); |
|
2780 |
|
2781 bool atTheTop = true; |
|
2782 switch (tab->shape) { |
|
2783 case QTabBar::RoundedWest: |
|
2784 case QTabBar::TriangularWest: |
|
2785 atTheTop = (sr == SE_TabBarTabLeftButton); |
|
2786 break; |
|
2787 case QTabBar::RoundedEast: |
|
2788 case QTabBar::TriangularEast: |
|
2789 atTheTop = (sr == SE_TabBarTabRightButton); |
|
2790 break; |
|
2791 default: |
|
2792 if (sr == SE_TabBarTabLeftButton) |
|
2793 r = QRect(tab->rect.x() + hpadding, midHeight, w, h); |
|
2794 else |
|
2795 r = QRect(tab->rect.right() - w - hpadding, midHeight, w, h); |
|
2796 r = visualRect(tab->direction, tab->rect, r); |
|
2797 } |
|
2798 if (verticalTabs) { |
|
2799 if (atTheTop) |
|
2800 r = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h); |
|
2801 else |
|
2802 r = QRect(midWidth, tr.y() + hpadding, w, h); |
|
2803 } |
|
2804 } |
|
2805 |
|
2806 break; |
|
2807 #endif // QT_NO_TABWIDGET |
|
2808 #ifndef QT_NO_TABBAR |
|
2809 case SE_TabBarTearIndicator: |
|
2810 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { |
|
2811 switch (tab->shape) { |
|
2812 case QTabBar::RoundedNorth: |
|
2813 case QTabBar::TriangularNorth: |
|
2814 case QTabBar::RoundedSouth: |
|
2815 case QTabBar::TriangularSouth: |
|
2816 r.setRect(tab->rect.left(), tab->rect.top(), 4, opt->rect.height()); |
|
2817 break; |
|
2818 case QTabBar::RoundedWest: |
|
2819 case QTabBar::TriangularWest: |
|
2820 case QTabBar::RoundedEast: |
|
2821 case QTabBar::TriangularEast: |
|
2822 r.setRect(tab->rect.left(), tab->rect.top(), opt->rect.width(), 4); |
|
2823 break; |
|
2824 default: |
|
2825 break; |
|
2826 } |
|
2827 r = visualRect(opt->direction, opt->rect, r); |
|
2828 } |
|
2829 break; |
|
2830 #endif |
|
2831 case SE_TreeViewDisclosureItem: |
|
2832 r = opt->rect; |
|
2833 break; |
|
2834 case SE_LineEditContents: |
|
2835 if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { |
|
2836 r = f->rect.adjusted(f->lineWidth, f->lineWidth, -f->lineWidth, -f->lineWidth); |
|
2837 r = visualRect(opt->direction, opt->rect, r); |
|
2838 } |
|
2839 break; |
|
2840 case SE_FrameContents: |
|
2841 if (const QStyleOptionFrameV2 *f = qstyleoption_cast<const QStyleOptionFrameV2 *>(opt)) { |
|
2842 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, f, widget); |
|
2843 r = opt->rect.adjusted(fw, fw, -fw, -fw); |
|
2844 r = visualRect(opt->direction, opt->rect, r); |
|
2845 } |
|
2846 break; |
|
2847 case SE_ShapedFrameContents: |
|
2848 if (const QStyleOptionFrameV3 *f = qstyleoption_cast<const QStyleOptionFrameV3 *>(opt)) { |
|
2849 int frameShape = f->frameShape; |
|
2850 int frameShadow = QFrame::Plain; |
|
2851 if (f->state & QStyle::State_Sunken) { |
|
2852 frameShadow = QFrame::Sunken; |
|
2853 } else if (f->state & QStyle::State_Raised) { |
|
2854 frameShadow = QFrame::Raised; |
|
2855 } |
|
2856 |
|
2857 int frameWidth = 0; |
|
2858 |
|
2859 switch (frameShape) { |
|
2860 case QFrame::NoFrame: |
|
2861 frameWidth = 0; |
|
2862 break; |
|
2863 |
|
2864 case QFrame::Box: |
|
2865 case QFrame::HLine: |
|
2866 case QFrame::VLine: |
|
2867 switch (frameShadow) { |
|
2868 case QFrame::Plain: |
|
2869 frameWidth = f->lineWidth; |
|
2870 break; |
|
2871 case QFrame::Raised: |
|
2872 case QFrame::Sunken: |
|
2873 frameWidth = (short)(f->lineWidth*2 + f->midLineWidth); |
|
2874 break; |
|
2875 } |
|
2876 break; |
|
2877 |
|
2878 case QFrame::StyledPanel: |
|
2879 //keep the compatibility with Qt 4.4 if there is a proxy style. |
|
2880 //be sure to call drawPrimitive(QStyle::SE_FrameContents) on the proxy style |
|
2881 if (widget) |
|
2882 return widget->style()->subElementRect(QStyle::SE_FrameContents, opt, widget); |
|
2883 else |
|
2884 return subElementRect(QStyle::SE_FrameContents, opt, widget); |
|
2885 break; |
|
2886 |
|
2887 case QFrame::WinPanel: |
|
2888 frameWidth = 2; |
|
2889 break; |
|
2890 |
|
2891 case QFrame::Panel: |
|
2892 switch (frameShadow) { |
|
2893 case QFrame::Plain: |
|
2894 case QFrame::Raised: |
|
2895 case QFrame::Sunken: |
|
2896 frameWidth = f->lineWidth; |
|
2897 break; |
|
2898 } |
|
2899 break; |
|
2900 } |
|
2901 r = f->rect.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth); |
|
2902 } |
|
2903 break; |
|
2904 #ifndef QT_NO_DOCKWIDGET |
|
2905 case SE_DockWidgetCloseButton: |
|
2906 case SE_DockWidgetFloatButton: |
|
2907 case SE_DockWidgetTitleBarText: |
|
2908 case SE_DockWidgetIcon: { |
|
2909 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, opt, widget); |
|
2910 int buttonMargin = proxy()->pixelMetric(PM_DockWidgetTitleBarButtonMargin, opt, widget); |
|
2911 int margin = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, opt, widget); |
|
2912 QRect rect = opt->rect; |
|
2913 |
|
2914 const QStyleOptionDockWidget *dwOpt |
|
2915 = qstyleoption_cast<const QStyleOptionDockWidget*>(opt); |
|
2916 bool canClose = dwOpt == 0 ? true : dwOpt->closable; |
|
2917 bool canFloat = dwOpt == 0 ? false : dwOpt->floatable; |
|
2918 const QStyleOptionDockWidgetV2 *v2 |
|
2919 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt); |
|
2920 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar; |
|
2921 |
|
2922 // If this is a vertical titlebar, we transpose and work as if it was |
|
2923 // horizontal, then transpose again. |
|
2924 |
|
2925 if (verticalTitleBar) { |
|
2926 QSize size = rect.size(); |
|
2927 size.transpose(); |
|
2928 rect.setSize(size); |
|
2929 } |
|
2930 |
|
2931 do { |
|
2932 |
|
2933 int right = rect.right(); |
|
2934 int left = rect.left(); |
|
2935 |
|
2936 QRect closeRect; |
|
2937 if (canClose) { |
|
2938 QSize sz = standardIcon(QStyle::SP_TitleBarCloseButton, |
|
2939 opt, widget).actualSize(QSize(iconSize, iconSize)); |
|
2940 sz += QSize(buttonMargin, buttonMargin); |
|
2941 if (verticalTitleBar) |
|
2942 sz.transpose(); |
|
2943 closeRect = QRect(right - sz.width(), |
|
2944 rect.center().y() - sz.height()/2, |
|
2945 sz.width(), sz.height()); |
|
2946 right = closeRect.left() - 1; |
|
2947 } |
|
2948 if (sr == SE_DockWidgetCloseButton) { |
|
2949 r = closeRect; |
|
2950 break; |
|
2951 } |
|
2952 |
|
2953 QRect floatRect; |
|
2954 if (canFloat) { |
|
2955 QSize sz = standardIcon(QStyle::SP_TitleBarNormalButton, |
|
2956 opt, widget).actualSize(QSize(iconSize, iconSize)); |
|
2957 sz += QSize(buttonMargin, buttonMargin); |
|
2958 if (verticalTitleBar) |
|
2959 sz.transpose(); |
|
2960 floatRect = QRect(right - sz.width(), |
|
2961 rect.center().y() - sz.height()/2, |
|
2962 sz.width(), sz.height()); |
|
2963 right = floatRect.left() - 1; |
|
2964 } |
|
2965 if (sr == SE_DockWidgetFloatButton) { |
|
2966 r = floatRect; |
|
2967 break; |
|
2968 } |
|
2969 |
|
2970 QRect iconRect; |
|
2971 if (const QDockWidget *dw = qobject_cast<const QDockWidget*>(widget)) { |
|
2972 QIcon icon; |
|
2973 if (dw->isFloating()) |
|
2974 icon = dw->windowIcon(); |
|
2975 if (!icon.isNull() |
|
2976 && icon.cacheKey() != QApplication::windowIcon().cacheKey()) { |
|
2977 QSize sz = icon.actualSize(QSize(r.height(), r.height())); |
|
2978 if (verticalTitleBar) |
|
2979 sz.transpose(); |
|
2980 iconRect = QRect(left, rect.center().y() - sz.height()/2, |
|
2981 sz.width(), sz.height()); |
|
2982 left = iconRect.right() + margin; |
|
2983 } |
|
2984 } |
|
2985 if (sr == SE_DockWidgetIcon) { |
|
2986 r = iconRect; |
|
2987 break; |
|
2988 } |
|
2989 |
|
2990 QRect textRect = QRect(left, rect.top(), |
|
2991 right - left, rect.height()); |
|
2992 if (sr == SE_DockWidgetTitleBarText) { |
|
2993 r = textRect; |
|
2994 break; |
|
2995 } |
|
2996 |
|
2997 } while (false); |
|
2998 |
|
2999 if (verticalTitleBar) { |
|
3000 r = QRect(rect.left() + r.top() - rect.top(), |
|
3001 rect.top() + rect.right() - r.right(), |
|
3002 r.height(), r.width()); |
|
3003 } else { |
|
3004 r = visualRect(opt->direction, rect, r); |
|
3005 } |
|
3006 break; |
|
3007 } |
|
3008 #endif |
|
3009 #ifndef QT_NO_ITEMVIEWS |
|
3010 case SE_ItemViewItemCheckIndicator: |
|
3011 if (!qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { |
|
3012 r = subElementRect(SE_CheckBoxIndicator, opt, widget); |
|
3013 break; |
|
3014 } |
|
3015 case SE_ItemViewItemDecoration: |
|
3016 case SE_ItemViewItemText: |
|
3017 case SE_ItemViewItemFocusRect: |
|
3018 if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { |
|
3019 if (!d->isViewItemCached(*vopt)) { |
|
3020 d->viewItemLayout(vopt, &d->checkRect, &d->decorationRect, &d->displayRect, false); |
|
3021 if (d->cachedOption) { |
|
3022 delete d->cachedOption; |
|
3023 d->cachedOption = 0; |
|
3024 } |
|
3025 d->cachedOption = new QStyleOptionViewItemV4(*vopt); |
|
3026 } |
|
3027 if (sr == SE_ViewItemCheckIndicator) |
|
3028 r = d->checkRect; |
|
3029 else if (sr == SE_ItemViewItemDecoration) |
|
3030 r = d->decorationRect; |
|
3031 else if (sr == SE_ItemViewItemText || sr == SE_ItemViewItemFocusRect) |
|
3032 r = d->displayRect; |
|
3033 } |
|
3034 break; |
|
3035 #endif //QT_NO_ITEMVIEWS |
|
3036 #ifndef QT_NO_TOOLBAR |
|
3037 case SE_ToolBarHandle: |
|
3038 if (const QStyleOptionToolBar *tbopt = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) { |
|
3039 if (tbopt->features & QStyleOptionToolBar::Movable) { |
|
3040 ///we need to access the widget here because the style option doesn't |
|
3041 //have all the information we need (ie. the layout's margin) |
|
3042 const QToolBar *tb = qobject_cast<const QToolBar*>(widget); |
|
3043 const int margin = tb && tb->layout() ? tb->layout()->margin() : 2; |
|
3044 const int handleExtent = pixelMetric(QStyle::PM_ToolBarHandleExtent, opt, tb); |
|
3045 if (tbopt->state & QStyle::State_Horizontal) { |
|
3046 r = QRect(margin, margin, handleExtent, tbopt->rect.height() - 2*margin); |
|
3047 r = QStyle::visualRect(tbopt->direction, tbopt->rect, r); |
|
3048 } else { |
|
3049 r = QRect(margin, margin, tbopt->rect.width() - 2*margin, handleExtent); |
|
3050 } |
|
3051 } |
|
3052 } |
|
3053 break; |
|
3054 #endif //QT_NO_TOOLBAR |
|
3055 default: |
|
3056 break; |
|
3057 } |
|
3058 return r; |
|
3059 } |
|
3060 |
|
3061 #ifndef QT_NO_DIAL |
|
3062 |
|
3063 static QPolygonF calcArrow(const QStyleOptionSlider *dial, qreal &a) |
|
3064 { |
|
3065 int width = dial->rect.width(); |
|
3066 int height = dial->rect.height(); |
|
3067 int r = qMin(width, height) / 2; |
|
3068 int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition); |
|
3069 |
|
3070 if (dial->maximum == dial->minimum) |
|
3071 a = Q_PI / 2; |
|
3072 else if (dial->dialWrapping) |
|
3073 a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI |
|
3074 / (dial->maximum - dial->minimum); |
|
3075 else |
|
3076 a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI |
|
3077 / (dial->maximum - dial->minimum)) / 6; |
|
3078 |
|
3079 int xc = width / 2; |
|
3080 int yc = height / 2; |
|
3081 |
|
3082 int len = r - QStyleHelper::calcBigLineSize(r) - 5; |
|
3083 if (len < 5) |
|
3084 len = 5; |
|
3085 int back = len / 2; |
|
3086 |
|
3087 QPolygonF arrow(3); |
|
3088 arrow[0] = QPointF(0.5 + xc + len * qCos(a), |
|
3089 0.5 + yc - len * qSin(a)); |
|
3090 arrow[1] = QPointF(0.5 + xc + back * qCos(a + Q_PI * 5 / 6), |
|
3091 0.5 + yc - back * qSin(a + Q_PI * 5 / 6)); |
|
3092 arrow[2] = QPointF(0.5 + xc + back * qCos(a - Q_PI * 5 / 6), |
|
3093 0.5 + yc - back * qSin(a - Q_PI * 5 / 6)); |
|
3094 return arrow; |
|
3095 } |
|
3096 |
|
3097 #endif // QT_NO_DIAL |
|
3098 |
|
3099 /*! |
|
3100 \reimp |
|
3101 */ |
|
3102 void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, |
|
3103 QPainter *p, const QWidget *widget) const |
|
3104 { |
|
3105 switch (cc) { |
|
3106 #ifndef QT_NO_SLIDER |
|
3107 case CC_Slider: |
|
3108 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
3109 if (slider->subControls == SC_SliderTickmarks) { |
|
3110 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget); |
|
3111 int ticks = slider->tickPosition; |
|
3112 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget); |
|
3113 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget); |
|
3114 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget); |
|
3115 int interval = slider->tickInterval; |
|
3116 if (interval <= 0) { |
|
3117 interval = slider->singleStep; |
|
3118 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval, |
|
3119 available) |
|
3120 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, |
|
3121 0, available) < 3) |
|
3122 interval = slider->pageStep; |
|
3123 } |
|
3124 if (!interval) |
|
3125 interval = 1; |
|
3126 int fudge = len / 2; |
|
3127 int pos; |
|
3128 // Since there is no subrect for tickmarks do a translation here. |
|
3129 p->save(); |
|
3130 p->translate(slider->rect.x(), slider->rect.y()); |
|
3131 p->setPen(slider->palette.foreground().color()); |
|
3132 int v = slider->minimum; |
|
3133 while (v <= slider->maximum + 1) { |
|
3134 if (v == slider->maximum + 1 && interval == 1) |
|
3135 break; |
|
3136 const int v_ = qMin(v, slider->maximum); |
|
3137 pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, |
|
3138 v_, available) + fudge; |
|
3139 if (slider->orientation == Qt::Horizontal) { |
|
3140 if (ticks & QSlider::TicksAbove) |
|
3141 p->drawLine(pos, 0, pos, tickOffset - 2); |
|
3142 if (ticks & QSlider::TicksBelow) |
|
3143 p->drawLine(pos, tickOffset + thickness + 1, pos, |
|
3144 slider->rect.height()-1); |
|
3145 } else { |
|
3146 if (ticks & QSlider::TicksAbove) |
|
3147 p->drawLine(0, pos, tickOffset - 2, pos); |
|
3148 if (ticks & QSlider::TicksBelow) |
|
3149 p->drawLine(tickOffset + thickness + 1, pos, |
|
3150 slider->rect.width()-1, pos); |
|
3151 } |
|
3152 // in the case where maximum is max int |
|
3153 int nextInterval = v + interval; |
|
3154 if (nextInterval < v) |
|
3155 break; |
|
3156 v = nextInterval; |
|
3157 } |
|
3158 p->restore(); |
|
3159 } |
|
3160 } |
|
3161 break; |
|
3162 #endif // QT_NO_SLIDER |
|
3163 #ifndef QT_NO_SCROLLBAR |
|
3164 case CC_ScrollBar: |
|
3165 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
3166 // Make a copy here and reset it for each primitive. |
|
3167 QStyleOptionSlider newScrollbar = *scrollbar; |
|
3168 State saveFlags = scrollbar->state; |
|
3169 |
|
3170 if (scrollbar->subControls & SC_ScrollBarSubLine) { |
|
3171 newScrollbar.state = saveFlags; |
|
3172 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSubLine, widget); |
|
3173 if (newScrollbar.rect.isValid()) { |
|
3174 if (!(scrollbar->activeSubControls & SC_ScrollBarSubLine)) |
|
3175 newScrollbar.state &= ~(State_Sunken | State_MouseOver); |
|
3176 proxy()->drawControl(CE_ScrollBarSubLine, &newScrollbar, p, widget); |
|
3177 } |
|
3178 } |
|
3179 if (scrollbar->subControls & SC_ScrollBarAddLine) { |
|
3180 newScrollbar.rect = scrollbar->rect; |
|
3181 newScrollbar.state = saveFlags; |
|
3182 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarAddLine, widget); |
|
3183 if (newScrollbar.rect.isValid()) { |
|
3184 if (!(scrollbar->activeSubControls & SC_ScrollBarAddLine)) |
|
3185 newScrollbar.state &= ~(State_Sunken | State_MouseOver); |
|
3186 proxy()->drawControl(CE_ScrollBarAddLine, &newScrollbar, p, widget); |
|
3187 } |
|
3188 } |
|
3189 if (scrollbar->subControls & SC_ScrollBarSubPage) { |
|
3190 newScrollbar.rect = scrollbar->rect; |
|
3191 newScrollbar.state = saveFlags; |
|
3192 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSubPage, widget); |
|
3193 if (newScrollbar.rect.isValid()) { |
|
3194 if (!(scrollbar->activeSubControls & SC_ScrollBarSubPage)) |
|
3195 newScrollbar.state &= ~(State_Sunken | State_MouseOver); |
|
3196 proxy()->drawControl(CE_ScrollBarSubPage, &newScrollbar, p, widget); |
|
3197 } |
|
3198 } |
|
3199 if (scrollbar->subControls & SC_ScrollBarAddPage) { |
|
3200 newScrollbar.rect = scrollbar->rect; |
|
3201 newScrollbar.state = saveFlags; |
|
3202 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarAddPage, widget); |
|
3203 if (newScrollbar.rect.isValid()) { |
|
3204 if (!(scrollbar->activeSubControls & SC_ScrollBarAddPage)) |
|
3205 newScrollbar.state &= ~(State_Sunken | State_MouseOver); |
|
3206 proxy()->drawControl(CE_ScrollBarAddPage, &newScrollbar, p, widget); |
|
3207 } |
|
3208 } |
|
3209 if (scrollbar->subControls & SC_ScrollBarFirst) { |
|
3210 newScrollbar.rect = scrollbar->rect; |
|
3211 newScrollbar.state = saveFlags; |
|
3212 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarFirst, widget); |
|
3213 if (newScrollbar.rect.isValid()) { |
|
3214 if (!(scrollbar->activeSubControls & SC_ScrollBarFirst)) |
|
3215 newScrollbar.state &= ~(State_Sunken | State_MouseOver); |
|
3216 proxy()->drawControl(CE_ScrollBarFirst, &newScrollbar, p, widget); |
|
3217 } |
|
3218 } |
|
3219 if (scrollbar->subControls & SC_ScrollBarLast) { |
|
3220 newScrollbar.rect = scrollbar->rect; |
|
3221 newScrollbar.state = saveFlags; |
|
3222 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarLast, widget); |
|
3223 if (newScrollbar.rect.isValid()) { |
|
3224 if (!(scrollbar->activeSubControls & SC_ScrollBarLast)) |
|
3225 newScrollbar.state &= ~(State_Sunken | State_MouseOver); |
|
3226 proxy()->drawControl(CE_ScrollBarLast, &newScrollbar, p, widget); |
|
3227 } |
|
3228 } |
|
3229 if (scrollbar->subControls & SC_ScrollBarSlider) { |
|
3230 newScrollbar.rect = scrollbar->rect; |
|
3231 newScrollbar.state = saveFlags; |
|
3232 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSlider, widget); |
|
3233 if (newScrollbar.rect.isValid()) { |
|
3234 if (!(scrollbar->activeSubControls & SC_ScrollBarSlider)) |
|
3235 newScrollbar.state &= ~(State_Sunken | State_MouseOver); |
|
3236 proxy()->drawControl(CE_ScrollBarSlider, &newScrollbar, p, widget); |
|
3237 |
|
3238 if (scrollbar->state & State_HasFocus) { |
|
3239 QStyleOptionFocusRect fropt; |
|
3240 fropt.QStyleOption::operator=(newScrollbar); |
|
3241 fropt.rect.setRect(newScrollbar.rect.x() + 2, newScrollbar.rect.y() + 2, |
|
3242 newScrollbar.rect.width() - 5, |
|
3243 newScrollbar.rect.height() - 5); |
|
3244 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget); |
|
3245 } |
|
3246 } |
|
3247 } |
|
3248 } |
|
3249 break; |
|
3250 #endif // QT_NO_SCROLLBAR |
|
3251 #ifdef QT3_SUPPORT |
|
3252 case CC_Q3ListView: |
|
3253 if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) { |
|
3254 if (lv->subControls & SC_Q3ListView) |
|
3255 p->fillRect(lv->rect, lv->viewportPalette.brush(lv->viewportBGRole)); |
|
3256 } |
|
3257 break; |
|
3258 #endif // QT3_SUPPORT |
|
3259 #ifndef QT_NO_SPINBOX |
|
3260 case CC_SpinBox: |
|
3261 if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { |
|
3262 QStyleOptionSpinBox copy = *sb; |
|
3263 PrimitiveElement pe; |
|
3264 |
|
3265 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) { |
|
3266 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget); |
|
3267 qDrawWinPanel(p, r, sb->palette, true); |
|
3268 } |
|
3269 |
|
3270 if (sb->subControls & SC_SpinBoxUp) { |
|
3271 copy.subControls = SC_SpinBoxUp; |
|
3272 QPalette pal2 = sb->palette; |
|
3273 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) { |
|
3274 pal2.setCurrentColorGroup(QPalette::Disabled); |
|
3275 copy.state &= ~State_Enabled; |
|
3276 } |
|
3277 |
|
3278 copy.palette = pal2; |
|
3279 |
|
3280 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) { |
|
3281 copy.state |= State_On; |
|
3282 copy.state |= State_Sunken; |
|
3283 } else { |
|
3284 copy.state |= State_Raised; |
|
3285 copy.state &= ~State_Sunken; |
|
3286 } |
|
3287 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus |
|
3288 : PE_IndicatorSpinUp); |
|
3289 |
|
3290 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget); |
|
3291 proxy()->drawPrimitive(PE_PanelButtonBevel, ©, p, widget); |
|
3292 copy.rect.adjust(3, 0, -4, 0); |
|
3293 proxy()->drawPrimitive(pe, ©, p, widget); |
|
3294 } |
|
3295 |
|
3296 if (sb->subControls & SC_SpinBoxDown) { |
|
3297 copy.subControls = SC_SpinBoxDown; |
|
3298 copy.state = sb->state; |
|
3299 QPalette pal2 = sb->palette; |
|
3300 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) { |
|
3301 pal2.setCurrentColorGroup(QPalette::Disabled); |
|
3302 copy.state &= ~State_Enabled; |
|
3303 } |
|
3304 copy.palette = pal2; |
|
3305 |
|
3306 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) { |
|
3307 copy.state |= State_On; |
|
3308 copy.state |= State_Sunken; |
|
3309 } else { |
|
3310 copy.state |= State_Raised; |
|
3311 copy.state &= ~State_Sunken; |
|
3312 } |
|
3313 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus |
|
3314 : PE_IndicatorSpinDown); |
|
3315 |
|
3316 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget); |
|
3317 proxy()->drawPrimitive(PE_PanelButtonBevel, ©, p, widget); |
|
3318 copy.rect.adjust(3, 0, -4, 0); |
|
3319 proxy()->drawPrimitive(pe, ©, p, widget); |
|
3320 } |
|
3321 } |
|
3322 break; |
|
3323 #endif // QT_NO_SPINBOX |
|
3324 #ifndef QT_NO_TOOLBUTTON |
|
3325 case CC_ToolButton: |
|
3326 if (const QStyleOptionToolButton *toolbutton |
|
3327 = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) { |
|
3328 QRect button, menuarea; |
|
3329 button = proxy()->subControlRect(cc, toolbutton, SC_ToolButton, widget); |
|
3330 menuarea = proxy()->subControlRect(cc, toolbutton, SC_ToolButtonMenu, widget); |
|
3331 |
|
3332 State bflags = toolbutton->state & ~State_Sunken; |
|
3333 |
|
3334 if (bflags & State_AutoRaise) { |
|
3335 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled)) { |
|
3336 bflags &= ~State_Raised; |
|
3337 } |
|
3338 } |
|
3339 State mflags = bflags; |
|
3340 if (toolbutton->state & State_Sunken) { |
|
3341 if (toolbutton->activeSubControls & SC_ToolButton) |
|
3342 bflags |= State_Sunken; |
|
3343 mflags |= State_Sunken; |
|
3344 } |
|
3345 |
|
3346 QStyleOption tool(0); |
|
3347 tool.palette = toolbutton->palette; |
|
3348 if (toolbutton->subControls & SC_ToolButton) { |
|
3349 if (bflags & (State_Sunken | State_On | State_Raised)) { |
|
3350 tool.rect = button; |
|
3351 tool.state = bflags; |
|
3352 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); |
|
3353 } |
|
3354 } |
|
3355 |
|
3356 if (toolbutton->state & State_HasFocus) { |
|
3357 QStyleOptionFocusRect fr; |
|
3358 fr.QStyleOption::operator=(*toolbutton); |
|
3359 fr.rect.adjust(3, 3, -3, -3); |
|
3360 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup) |
|
3361 fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, |
|
3362 toolbutton, widget), 0); |
|
3363 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, p, widget); |
|
3364 } |
|
3365 QStyleOptionToolButton label = *toolbutton; |
|
3366 label.state = bflags; |
|
3367 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget); |
|
3368 label.rect = button.adjusted(fw, fw, -fw, -fw); |
|
3369 proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget); |
|
3370 |
|
3371 if (toolbutton->subControls & SC_ToolButtonMenu) { |
|
3372 tool.rect = menuarea; |
|
3373 tool.state = mflags; |
|
3374 if (mflags & (State_Sunken | State_On | State_Raised)) |
|
3375 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, p, widget); |
|
3376 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, p, widget); |
|
3377 } else if (toolbutton->features & QStyleOptionToolButton::HasMenu) { |
|
3378 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget); |
|
3379 QRect ir = toolbutton->rect; |
|
3380 QStyleOptionToolButton newBtn = *toolbutton; |
|
3381 newBtn.rect = QRect(ir.right() + 5 - mbi, ir.y() + ir.height() - mbi + 4, mbi - 6, mbi - 6); |
|
3382 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget); |
|
3383 } |
|
3384 } |
|
3385 break; |
|
3386 #endif // QT_NO_TOOLBUTTON |
|
3387 case CC_TitleBar: |
|
3388 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) { |
|
3389 QRect ir; |
|
3390 if (opt->subControls & SC_TitleBarLabel) { |
|
3391 QColor left = tb->palette.highlight().color(); |
|
3392 QColor right = tb->palette.base().color(); |
|
3393 |
|
3394 QBrush fillBrush(left); |
|
3395 if (left != right) { |
|
3396 QPoint p1(tb->rect.x(), tb->rect.top() + tb->rect.height()/2); |
|
3397 QPoint p2(tb->rect.right(), tb->rect.top() + tb->rect.height()/2); |
|
3398 QLinearGradient lg(p1, p2); |
|
3399 lg.setColorAt(0, left); |
|
3400 lg.setColorAt(1, right); |
|
3401 fillBrush = lg; |
|
3402 } |
|
3403 |
|
3404 p->fillRect(opt->rect, fillBrush); |
|
3405 |
|
3406 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget); |
|
3407 |
|
3408 p->setPen(tb->palette.highlightedText().color()); |
|
3409 p->drawText(ir.x() + 2, ir.y(), ir.width() - 2, ir.height(), |
|
3410 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text); |
|
3411 } |
|
3412 |
|
3413 bool down = false; |
|
3414 QPixmap pm; |
|
3415 |
|
3416 QStyleOption tool(0); |
|
3417 tool.palette = tb->palette; |
|
3418 if (tb->subControls & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) { |
|
3419 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarCloseButton, widget); |
|
3420 down = tb->activeSubControls & SC_TitleBarCloseButton && (opt->state & State_Sunken); |
|
3421 if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool |
|
3422 #ifndef QT_NO_DOCKWIDGET |
|
3423 || qobject_cast<const QDockWidget *>(widget) |
|
3424 #endif |
|
3425 ) |
|
3426 pm = standardIcon(SP_DockWidgetCloseButton, &tool, widget).pixmap(10, 10); |
|
3427 else |
|
3428 pm = standardIcon(SP_TitleBarCloseButton, &tool, widget).pixmap(10, 10); |
|
3429 tool.rect = ir; |
|
3430 tool.state = down ? State_Sunken : State_Raised; |
|
3431 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); |
|
3432 |
|
3433 p->save(); |
|
3434 if (down) |
|
3435 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget), |
|
3436 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget)); |
|
3437 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm); |
|
3438 p->restore(); |
|
3439 } |
|
3440 |
|
3441 if (tb->subControls & SC_TitleBarMaxButton |
|
3442 && tb->titleBarFlags & Qt::WindowMaximizeButtonHint |
|
3443 && !(tb->titleBarState & Qt::WindowMaximized)) { |
|
3444 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMaxButton, widget); |
|
3445 |
|
3446 down = tb->activeSubControls & SC_TitleBarMaxButton && (opt->state & State_Sunken); |
|
3447 pm = standardIcon(SP_TitleBarMaxButton, &tool, widget).pixmap(10, 10); |
|
3448 tool.rect = ir; |
|
3449 tool.state = down ? State_Sunken : State_Raised; |
|
3450 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); |
|
3451 |
|
3452 p->save(); |
|
3453 if (down) |
|
3454 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget), |
|
3455 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget)); |
|
3456 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm); |
|
3457 p->restore(); |
|
3458 } |
|
3459 |
|
3460 if (tb->subControls & SC_TitleBarMinButton |
|
3461 && tb->titleBarFlags & Qt::WindowMinimizeButtonHint |
|
3462 && !(tb->titleBarState & Qt::WindowMinimized)) { |
|
3463 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMinButton, widget); |
|
3464 down = tb->activeSubControls & SC_TitleBarMinButton && (opt->state & State_Sunken); |
|
3465 pm = standardIcon(SP_TitleBarMinButton, &tool, widget).pixmap(10, 10); |
|
3466 tool.rect = ir; |
|
3467 tool.state = down ? State_Sunken : State_Raised; |
|
3468 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); |
|
3469 |
|
3470 p->save(); |
|
3471 if (down) |
|
3472 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget), |
|
3473 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget)); |
|
3474 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm); |
|
3475 p->restore(); |
|
3476 } |
|
3477 |
|
3478 bool drawNormalButton = (tb->subControls & SC_TitleBarNormalButton) |
|
3479 && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint) |
|
3480 && (tb->titleBarState & Qt::WindowMinimized)) |
|
3481 || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint) |
|
3482 && (tb->titleBarState & Qt::WindowMaximized))); |
|
3483 |
|
3484 if (drawNormalButton) { |
|
3485 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarNormalButton, widget); |
|
3486 down = tb->activeSubControls & SC_TitleBarNormalButton && (opt->state & State_Sunken); |
|
3487 pm = standardIcon(SP_TitleBarNormalButton, &tool, widget).pixmap(10, 10); |
|
3488 tool.rect = ir; |
|
3489 tool.state = down ? State_Sunken : State_Raised; |
|
3490 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); |
|
3491 |
|
3492 p->save(); |
|
3493 if (down) |
|
3494 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget), |
|
3495 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget)); |
|
3496 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm); |
|
3497 p->restore(); |
|
3498 } |
|
3499 |
|
3500 if (tb->subControls & SC_TitleBarShadeButton |
|
3501 && tb->titleBarFlags & Qt::WindowShadeButtonHint |
|
3502 && !(tb->titleBarState & Qt::WindowMinimized)) { |
|
3503 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarShadeButton, widget); |
|
3504 down = (tb->activeSubControls & SC_TitleBarShadeButton && (opt->state & State_Sunken)); |
|
3505 pm = standardIcon(SP_TitleBarShadeButton, &tool, widget).pixmap(10, 10); |
|
3506 tool.rect = ir; |
|
3507 tool.state = down ? State_Sunken : State_Raised; |
|
3508 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); |
|
3509 p->save(); |
|
3510 if (down) |
|
3511 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget), |
|
3512 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget)); |
|
3513 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm); |
|
3514 p->restore(); |
|
3515 } |
|
3516 |
|
3517 if (tb->subControls & SC_TitleBarUnshadeButton |
|
3518 && tb->titleBarFlags & Qt::WindowShadeButtonHint |
|
3519 && tb->titleBarState & Qt::WindowMinimized) { |
|
3520 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarUnshadeButton, widget); |
|
3521 |
|
3522 down = tb->activeSubControls & SC_TitleBarUnshadeButton && (opt->state & State_Sunken); |
|
3523 pm = standardIcon(SP_TitleBarUnshadeButton, &tool, widget).pixmap(10, 10); |
|
3524 tool.rect = ir; |
|
3525 tool.state = down ? State_Sunken : State_Raised; |
|
3526 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); |
|
3527 p->save(); |
|
3528 if (down) |
|
3529 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget), |
|
3530 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget)); |
|
3531 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm); |
|
3532 p->restore(); |
|
3533 } |
|
3534 if (tb->subControls & SC_TitleBarContextHelpButton |
|
3535 && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) { |
|
3536 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarContextHelpButton, widget); |
|
3537 |
|
3538 down = tb->activeSubControls & SC_TitleBarContextHelpButton && (opt->state & State_Sunken); |
|
3539 pm = standardIcon(SP_TitleBarContextHelpButton, &tool, widget).pixmap(10, 10); |
|
3540 tool.rect = ir; |
|
3541 tool.state = down ? State_Sunken : State_Raised; |
|
3542 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget); |
|
3543 p->save(); |
|
3544 if (down) |
|
3545 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget), |
|
3546 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget)); |
|
3547 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm); |
|
3548 p->restore(); |
|
3549 } |
|
3550 if (tb->subControls & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) { |
|
3551 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarSysMenu, widget); |
|
3552 if (!tb->icon.isNull()) { |
|
3553 tb->icon.paint(p, ir); |
|
3554 } else { |
|
3555 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, tb, widget); |
|
3556 pm = standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(iconSize, iconSize); |
|
3557 tool.rect = ir; |
|
3558 p->save(); |
|
3559 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm); |
|
3560 p->restore(); |
|
3561 } |
|
3562 } |
|
3563 } |
|
3564 break; |
|
3565 #ifndef QT_NO_DIAL |
|
3566 case CC_Dial: |
|
3567 if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
3568 // OK, this is more a port of things over |
|
3569 p->save(); |
|
3570 |
|
3571 // avoid dithering |
|
3572 if (p->paintEngine()->hasFeature(QPaintEngine::Antialiasing)) |
|
3573 p->setRenderHint(QPainter::Antialiasing); |
|
3574 |
|
3575 int width = dial->rect.width(); |
|
3576 int height = dial->rect.height(); |
|
3577 qreal r = qMin(width, height) / 2; |
|
3578 qreal d_ = r / 6; |
|
3579 qreal dx = dial->rect.x() + d_ + (width - 2 * r) / 2 + 1; |
|
3580 qreal dy = dial->rect.y() + d_ + (height - 2 * r) / 2 + 1; |
|
3581 QRect br = QRect(int(dx), int(dy), int(r * 2 - 2 * d_ - 2), int(r * 2 - 2 * d_ - 2)); |
|
3582 |
|
3583 QPalette pal = opt->palette; |
|
3584 // draw notches |
|
3585 if (dial->subControls & QStyle::SC_DialTickmarks) { |
|
3586 p->setPen(pal.foreground().color()); |
|
3587 p->drawLines(QStyleHelper::calcLines(dial)); |
|
3588 } |
|
3589 |
|
3590 if (dial->state & State_Enabled) { |
|
3591 p->setBrush(pal.brush(QPalette::ColorRole(proxy()->styleHint(SH_Dial_BackgroundRole, |
|
3592 dial, widget)))); |
|
3593 p->setPen(Qt::NoPen); |
|
3594 p->drawEllipse(br); |
|
3595 p->setBrush(Qt::NoBrush); |
|
3596 } |
|
3597 p->setPen(QPen(pal.dark().color())); |
|
3598 p->drawArc(br, 60 * 16, 180 * 16); |
|
3599 p->setPen(QPen(pal.light().color())); |
|
3600 p->drawArc(br, 240 * 16, 180 * 16); |
|
3601 |
|
3602 qreal a; |
|
3603 QPolygonF arrow(calcArrow(dial, a)); |
|
3604 |
|
3605 p->setPen(Qt::NoPen); |
|
3606 p->setBrush(pal.button()); |
|
3607 p->drawPolygon(arrow); |
|
3608 |
|
3609 a = QStyleHelper::angle(QPointF(width / 2, height / 2), arrow[0]); |
|
3610 p->setBrush(Qt::NoBrush); |
|
3611 |
|
3612 if (a <= 0 || a > 200) { |
|
3613 p->setPen(pal.light().color()); |
|
3614 p->drawLine(arrow[2], arrow[0]); |
|
3615 p->drawLine(arrow[1], arrow[2]); |
|
3616 p->setPen(pal.dark().color()); |
|
3617 p->drawLine(arrow[0], arrow[1]); |
|
3618 } else if (a > 0 && a < 45) { |
|
3619 p->setPen(pal.light().color()); |
|
3620 p->drawLine(arrow[2], arrow[0]); |
|
3621 p->setPen(pal.dark().color()); |
|
3622 p->drawLine(arrow[1], arrow[2]); |
|
3623 p->drawLine(arrow[0], arrow[1]); |
|
3624 } else if (a >= 45 && a < 135) { |
|
3625 p->setPen(pal.dark().color()); |
|
3626 p->drawLine(arrow[2], arrow[0]); |
|
3627 p->drawLine(arrow[1], arrow[2]); |
|
3628 p->setPen(pal.light().color()); |
|
3629 p->drawLine(arrow[0], arrow[1]); |
|
3630 } else if (a >= 135 && a < 200) { |
|
3631 p->setPen(pal.dark().color()); |
|
3632 p->drawLine(arrow[2], arrow[0]); |
|
3633 p->setPen(pal.light().color()); |
|
3634 p->drawLine(arrow[0], arrow[1]); |
|
3635 p->drawLine(arrow[1], arrow[2]); |
|
3636 } |
|
3637 |
|
3638 // draw focus rect around the dial |
|
3639 QStyleOptionFocusRect fropt; |
|
3640 fropt.rect = dial->rect; |
|
3641 fropt.state = dial->state; |
|
3642 fropt.palette = dial->palette; |
|
3643 if (fropt.state & QStyle::State_HasFocus) { |
|
3644 br.adjust(0, 0, 2, 2); |
|
3645 if (dial->subControls & SC_DialTickmarks) { |
|
3646 int r = qMin(width, height) / 2; |
|
3647 br.translate(-r / 6, - r / 6); |
|
3648 br.setWidth(br.width() + r / 3); |
|
3649 br.setHeight(br.height() + r / 3); |
|
3650 } |
|
3651 fropt.rect = br.adjusted(-2, -2, 2, 2); |
|
3652 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &fropt, p, widget); |
|
3653 } |
|
3654 p->restore(); |
|
3655 } |
|
3656 break; |
|
3657 #endif // QT_NO_DIAL |
|
3658 #ifndef QT_NO_GROUPBOX |
|
3659 case CC_GroupBox: |
|
3660 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) { |
|
3661 // Draw frame |
|
3662 QRect textRect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxLabel, widget); |
|
3663 QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxCheckBox, widget); |
|
3664 if (groupBox->subControls & QStyle::SC_GroupBoxFrame) { |
|
3665 QStyleOptionFrameV2 frame; |
|
3666 frame.QStyleOption::operator=(*groupBox); |
|
3667 frame.features = groupBox->features; |
|
3668 frame.lineWidth = groupBox->lineWidth; |
|
3669 frame.midLineWidth = groupBox->midLineWidth; |
|
3670 frame.rect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxFrame, widget); |
|
3671 p->save(); |
|
3672 QRegion region(groupBox->rect); |
|
3673 if (!groupBox->text.isEmpty()) { |
|
3674 bool ltr = groupBox->direction == Qt::LeftToRight; |
|
3675 QRect finalRect; |
|
3676 if (groupBox->subControls & QStyle::SC_GroupBoxCheckBox) { |
|
3677 finalRect = checkBoxRect.united(textRect); |
|
3678 finalRect.adjust(ltr ? -4 : 0, 0, ltr ? 0 : 4, 0); |
|
3679 } else { |
|
3680 finalRect = textRect; |
|
3681 } |
|
3682 region -= finalRect; |
|
3683 } |
|
3684 p->setClipRegion(region); |
|
3685 proxy()->drawPrimitive(PE_FrameGroupBox, &frame, p, widget); |
|
3686 p->restore(); |
|
3687 } |
|
3688 |
|
3689 // Draw title |
|
3690 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) { |
|
3691 QColor textColor = groupBox->textColor; |
|
3692 if (textColor.isValid()) |
|
3693 p->setPen(textColor); |
|
3694 int alignment = int(groupBox->textAlignment); |
|
3695 if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, opt, widget)) |
|
3696 alignment |= Qt::TextHideMnemonic; |
|
3697 |
|
3698 proxy()->drawItemText(p, textRect, Qt::TextShowMnemonic | Qt::AlignHCenter | alignment, |
|
3699 groupBox->palette, groupBox->state & State_Enabled, groupBox->text, |
|
3700 textColor.isValid() ? QPalette::NoRole : QPalette::WindowText); |
|
3701 |
|
3702 if (groupBox->state & State_HasFocus) { |
|
3703 QStyleOptionFocusRect fropt; |
|
3704 fropt.QStyleOption::operator=(*groupBox); |
|
3705 fropt.rect = textRect; |
|
3706 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget); |
|
3707 } |
|
3708 } |
|
3709 |
|
3710 // Draw checkbox |
|
3711 if (groupBox->subControls & SC_GroupBoxCheckBox) { |
|
3712 QStyleOptionButton box; |
|
3713 box.QStyleOption::operator=(*groupBox); |
|
3714 box.rect = checkBoxRect; |
|
3715 proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, p, widget); |
|
3716 } |
|
3717 } |
|
3718 break; |
|
3719 #endif // QT_NO_GROUPBOX |
|
3720 #ifndef QT_NO_WORKSPACE |
|
3721 case CC_MdiControls: |
|
3722 { |
|
3723 QStyleOptionButton btnOpt; |
|
3724 btnOpt.QStyleOption::operator=(*opt); |
|
3725 btnOpt.state &= ~State_MouseOver; |
|
3726 int bsx = 0; |
|
3727 int bsy = 0; |
|
3728 if (opt->subControls & QStyle::SC_MdiCloseButton) { |
|
3729 if (opt->activeSubControls & QStyle::SC_MdiCloseButton && (opt->state & State_Sunken)) { |
|
3730 btnOpt.state |= State_Sunken; |
|
3731 btnOpt.state &= ~State_Raised; |
|
3732 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal); |
|
3733 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical); |
|
3734 } else { |
|
3735 btnOpt.state |= State_Raised; |
|
3736 btnOpt.state &= ~State_Sunken; |
|
3737 bsx = 0; |
|
3738 bsy = 0; |
|
3739 } |
|
3740 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiCloseButton, widget); |
|
3741 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget); |
|
3742 QPixmap pm = standardIcon(SP_TitleBarCloseButton).pixmap(16, 16); |
|
3743 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm); |
|
3744 } |
|
3745 if (opt->subControls & QStyle::SC_MdiNormalButton) { |
|
3746 if (opt->activeSubControls & QStyle::SC_MdiNormalButton && (opt->state & State_Sunken)) { |
|
3747 btnOpt.state |= State_Sunken; |
|
3748 btnOpt.state &= ~State_Raised; |
|
3749 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal); |
|
3750 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical); |
|
3751 } else { |
|
3752 btnOpt.state |= State_Raised; |
|
3753 btnOpt.state &= ~State_Sunken; |
|
3754 bsx = 0; |
|
3755 bsy = 0; |
|
3756 } |
|
3757 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiNormalButton, widget); |
|
3758 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget); |
|
3759 QPixmap pm = standardIcon(SP_TitleBarNormalButton).pixmap(16, 16); |
|
3760 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm); |
|
3761 } |
|
3762 if (opt->subControls & QStyle::SC_MdiMinButton) { |
|
3763 if (opt->activeSubControls & QStyle::SC_MdiMinButton && (opt->state & State_Sunken)) { |
|
3764 btnOpt.state |= State_Sunken; |
|
3765 btnOpt.state &= ~State_Raised; |
|
3766 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal); |
|
3767 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical); |
|
3768 } else { |
|
3769 btnOpt.state |= State_Raised; |
|
3770 btnOpt.state &= ~State_Sunken; |
|
3771 bsx = 0; |
|
3772 bsy = 0; |
|
3773 } |
|
3774 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiMinButton, widget); |
|
3775 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget); |
|
3776 QPixmap pm = standardIcon(SP_TitleBarMinButton).pixmap(16, 16); |
|
3777 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm); |
|
3778 } |
|
3779 } |
|
3780 break; |
|
3781 #endif // QT_NO_WORKSPACE |
|
3782 |
|
3783 default: |
|
3784 qWarning("QCommonStyle::drawComplexControl: Control %d not handled", cc); |
|
3785 } |
|
3786 } |
|
3787 |
|
3788 /*! |
|
3789 \reimp |
|
3790 */ |
|
3791 QStyle::SubControl QCommonStyle::hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, |
|
3792 const QPoint &pt, const QWidget *widget) const |
|
3793 { |
|
3794 SubControl sc = SC_None; |
|
3795 switch (cc) { |
|
3796 #ifndef QT_NO_SLIDER |
|
3797 case CC_Slider: |
|
3798 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
3799 QRect r = proxy()->subControlRect(cc, slider, SC_SliderHandle, widget); |
|
3800 if (r.isValid() && r.contains(pt)) { |
|
3801 sc = SC_SliderHandle; |
|
3802 } else { |
|
3803 r = proxy()->subControlRect(cc, slider, SC_SliderGroove ,widget); |
|
3804 if (r.isValid() && r.contains(pt)) |
|
3805 sc = SC_SliderGroove; |
|
3806 } |
|
3807 } |
|
3808 break; |
|
3809 #endif // QT_NO_SLIDER |
|
3810 #ifndef QT_NO_SCROLLBAR |
|
3811 case CC_ScrollBar: |
|
3812 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
3813 QRect r; |
|
3814 uint ctrl = SC_ScrollBarAddLine; |
|
3815 while (ctrl <= SC_ScrollBarGroove) { |
|
3816 r = proxy()->subControlRect(cc, scrollbar, QStyle::SubControl(ctrl), widget); |
|
3817 if (r.isValid() && r.contains(pt)) { |
|
3818 sc = QStyle::SubControl(ctrl); |
|
3819 break; |
|
3820 } |
|
3821 ctrl <<= 1; |
|
3822 } |
|
3823 } |
|
3824 break; |
|
3825 #endif // QT_NO_SCROLLBAR |
|
3826 #ifndef QT_NO_TOOLBUTTON |
|
3827 case CC_ToolButton: |
|
3828 if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) { |
|
3829 QRect r; |
|
3830 uint ctrl = SC_ToolButton; |
|
3831 while (ctrl <= SC_ToolButtonMenu) { |
|
3832 r = proxy()->subControlRect(cc, toolbutton, QStyle::SubControl(ctrl), widget); |
|
3833 if (r.isValid() && r.contains(pt)) { |
|
3834 sc = QStyle::SubControl(ctrl); |
|
3835 break; |
|
3836 } |
|
3837 ctrl <<= 1; |
|
3838 } |
|
3839 } |
|
3840 break; |
|
3841 #endif // QT_NO_TOOLBUTTON |
|
3842 #ifdef QT3_SUPPORT |
|
3843 case CC_Q3ListView: |
|
3844 if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) { |
|
3845 if (pt.x() >= 0 && pt.x() < lv->treeStepSize) |
|
3846 sc = SC_Q3ListViewExpand; |
|
3847 } |
|
3848 break; |
|
3849 #endif // QT3_SUPPORT |
|
3850 #ifndef QT_NO_SPINBOX |
|
3851 case CC_SpinBox: |
|
3852 if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { |
|
3853 QRect r; |
|
3854 uint ctrl = SC_SpinBoxUp; |
|
3855 while (ctrl <= SC_SpinBoxEditField) { |
|
3856 r = proxy()->subControlRect(cc, spinbox, QStyle::SubControl(ctrl), widget); |
|
3857 if (r.isValid() && r.contains(pt)) { |
|
3858 sc = QStyle::SubControl(ctrl); |
|
3859 break; |
|
3860 } |
|
3861 ctrl <<= 1; |
|
3862 } |
|
3863 } |
|
3864 break; |
|
3865 #endif // QT_NO_SPINBOX |
|
3866 case CC_TitleBar: |
|
3867 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) { |
|
3868 QRect r; |
|
3869 uint ctrl = SC_TitleBarSysMenu; |
|
3870 |
|
3871 while (ctrl <= SC_TitleBarLabel) { |
|
3872 r = proxy()->subControlRect(cc, tb, QStyle::SubControl(ctrl), widget); |
|
3873 if (r.isValid() && r.contains(pt)) { |
|
3874 sc = QStyle::SubControl(ctrl); |
|
3875 break; |
|
3876 } |
|
3877 ctrl <<= 1; |
|
3878 } |
|
3879 } |
|
3880 break; |
|
3881 #ifndef QT_NO_COMBOBOX |
|
3882 case CC_ComboBox: |
|
3883 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { |
|
3884 QRect r; |
|
3885 uint ctrl = SC_ComboBoxArrow; // Start here and go down. |
|
3886 while (ctrl > 0) { |
|
3887 r = proxy()->subControlRect(cc, cb, QStyle::SubControl(ctrl), widget); |
|
3888 if (r.isValid() && r.contains(pt)) { |
|
3889 sc = QStyle::SubControl(ctrl); |
|
3890 break; |
|
3891 } |
|
3892 ctrl >>= 1; |
|
3893 } |
|
3894 } |
|
3895 break; |
|
3896 #endif // QT_NO_COMBOBOX |
|
3897 #ifndef QT_NO_GROUPBOX |
|
3898 case CC_GroupBox: |
|
3899 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) { |
|
3900 QRect r; |
|
3901 uint ctrl = SC_GroupBoxCheckBox; |
|
3902 while (ctrl <= SC_GroupBoxFrame) { |
|
3903 r = proxy()->subControlRect(cc, groupBox, QStyle::SubControl(ctrl), widget); |
|
3904 if (r.isValid() && r.contains(pt)) { |
|
3905 sc = QStyle::SubControl(ctrl); |
|
3906 break; |
|
3907 } |
|
3908 ctrl <<= 1; |
|
3909 } |
|
3910 } |
|
3911 break; |
|
3912 #endif // QT_NO_GROUPBOX |
|
3913 case CC_MdiControls: |
|
3914 { |
|
3915 QRect r; |
|
3916 uint ctrl = SC_MdiMinButton; |
|
3917 while (ctrl <= SC_MdiCloseButton) { |
|
3918 r = proxy()->subControlRect(CC_MdiControls, opt, QStyle::SubControl(ctrl), widget); |
|
3919 if (r.isValid() && r.contains(pt) && (opt->subControls & ctrl)) { |
|
3920 sc = QStyle::SubControl(ctrl); |
|
3921 return sc; |
|
3922 } |
|
3923 ctrl <<= 1; |
|
3924 } |
|
3925 } |
|
3926 break; |
|
3927 default: |
|
3928 qWarning("QCommonStyle::hitTestComplexControl: Case %d not handled", cc); |
|
3929 } |
|
3930 return sc; |
|
3931 } |
|
3932 |
|
3933 /*! |
|
3934 \reimp |
|
3935 */ |
|
3936 QRect QCommonStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, |
|
3937 SubControl sc, const QWidget *widget) const |
|
3938 { |
|
3939 QRect ret; |
|
3940 switch (cc) { |
|
3941 #ifndef QT_NO_SLIDER |
|
3942 case CC_Slider: |
|
3943 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
3944 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget); |
|
3945 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget); |
|
3946 |
|
3947 switch (sc) { |
|
3948 case SC_SliderHandle: { |
|
3949 int sliderPos = 0; |
|
3950 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget); |
|
3951 bool horizontal = slider->orientation == Qt::Horizontal; |
|
3952 sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum, |
|
3953 slider->sliderPosition, |
|
3954 (horizontal ? slider->rect.width() |
|
3955 : slider->rect.height()) - len, |
|
3956 slider->upsideDown); |
|
3957 if (horizontal) |
|
3958 ret.setRect(slider->rect.x() + sliderPos, slider->rect.y() + tickOffset, len, thickness); |
|
3959 else |
|
3960 ret.setRect(slider->rect.x() + tickOffset, slider->rect.y() + sliderPos, thickness, len); |
|
3961 break; } |
|
3962 case SC_SliderGroove: |
|
3963 if (slider->orientation == Qt::Horizontal) |
|
3964 ret.setRect(slider->rect.x(), slider->rect.y() + tickOffset, |
|
3965 slider->rect.width(), thickness); |
|
3966 else |
|
3967 ret.setRect(slider->rect.x() + tickOffset, slider->rect.y(), |
|
3968 thickness, slider->rect.height()); |
|
3969 break; |
|
3970 default: |
|
3971 break; |
|
3972 } |
|
3973 ret = visualRect(slider->direction, slider->rect, ret); |
|
3974 } |
|
3975 break; |
|
3976 #endif // QT_NO_SLIDER |
|
3977 #ifndef QT_NO_SCROLLBAR |
|
3978 case CC_ScrollBar: |
|
3979 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
3980 const QRect scrollBarRect = scrollbar->rect; |
|
3981 int sbextent = proxy()->pixelMetric(PM_ScrollBarExtent, scrollbar, widget); |
|
3982 int maxlen = ((scrollbar->orientation == Qt::Horizontal) ? |
|
3983 scrollBarRect.width() : scrollBarRect.height()) - (sbextent * 2); |
|
3984 int sliderlen; |
|
3985 |
|
3986 // calculate slider length |
|
3987 if (scrollbar->maximum != scrollbar->minimum) { |
|
3988 uint range = scrollbar->maximum - scrollbar->minimum; |
|
3989 sliderlen = (qint64(scrollbar->pageStep) * maxlen) / (range + scrollbar->pageStep); |
|
3990 |
|
3991 int slidermin = proxy()->pixelMetric(PM_ScrollBarSliderMin, scrollbar, widget); |
|
3992 if (sliderlen < slidermin || range > INT_MAX / 2) |
|
3993 sliderlen = slidermin; |
|
3994 if (sliderlen > maxlen) |
|
3995 sliderlen = maxlen; |
|
3996 } else { |
|
3997 sliderlen = maxlen; |
|
3998 } |
|
3999 |
|
4000 int sliderstart = sbextent + sliderPositionFromValue(scrollbar->minimum, |
|
4001 scrollbar->maximum, |
|
4002 scrollbar->sliderPosition, |
|
4003 maxlen - sliderlen, |
|
4004 scrollbar->upsideDown); |
|
4005 |
|
4006 switch (sc) { |
|
4007 case SC_ScrollBarSubLine: // top/left button |
|
4008 if (scrollbar->orientation == Qt::Horizontal) { |
|
4009 int buttonWidth = qMin(scrollBarRect.width() / 2, sbextent); |
|
4010 ret.setRect(0, 0, buttonWidth, scrollBarRect.height()); |
|
4011 } else { |
|
4012 int buttonHeight = qMin(scrollBarRect.height() / 2, sbextent); |
|
4013 ret.setRect(0, 0, scrollBarRect.width(), buttonHeight); |
|
4014 } |
|
4015 break; |
|
4016 case SC_ScrollBarAddLine: // bottom/right button |
|
4017 if (scrollbar->orientation == Qt::Horizontal) { |
|
4018 int buttonWidth = qMin(scrollBarRect.width()/2, sbextent); |
|
4019 ret.setRect(scrollBarRect.width() - buttonWidth, 0, buttonWidth, scrollBarRect.height()); |
|
4020 } else { |
|
4021 int buttonHeight = qMin(scrollBarRect.height()/2, sbextent); |
|
4022 ret.setRect(0, scrollBarRect.height() - buttonHeight, scrollBarRect.width(), buttonHeight); |
|
4023 } |
|
4024 break; |
|
4025 case SC_ScrollBarSubPage: // between top/left button and slider |
|
4026 if (scrollbar->orientation == Qt::Horizontal) |
|
4027 ret.setRect(sbextent, 0, sliderstart - sbextent, scrollBarRect.height()); |
|
4028 else |
|
4029 ret.setRect(0, sbextent, scrollBarRect.width(), sliderstart - sbextent); |
|
4030 break; |
|
4031 case SC_ScrollBarAddPage: // between bottom/right button and slider |
|
4032 if (scrollbar->orientation == Qt::Horizontal) |
|
4033 ret.setRect(sliderstart + sliderlen, 0, |
|
4034 maxlen - sliderstart - sliderlen + sbextent, scrollBarRect.height()); |
|
4035 else |
|
4036 ret.setRect(0, sliderstart + sliderlen, scrollBarRect.width(), |
|
4037 maxlen - sliderstart - sliderlen + sbextent); |
|
4038 break; |
|
4039 case SC_ScrollBarGroove: |
|
4040 if (scrollbar->orientation == Qt::Horizontal) |
|
4041 ret.setRect(sbextent, 0, scrollBarRect.width() - sbextent * 2, |
|
4042 scrollBarRect.height()); |
|
4043 else |
|
4044 ret.setRect(0, sbextent, scrollBarRect.width(), |
|
4045 scrollBarRect.height() - sbextent * 2); |
|
4046 break; |
|
4047 case SC_ScrollBarSlider: |
|
4048 if (scrollbar->orientation == Qt::Horizontal) |
|
4049 ret.setRect(sliderstart, 0, sliderlen, scrollBarRect.height()); |
|
4050 else |
|
4051 ret.setRect(0, sliderstart, scrollBarRect.width(), sliderlen); |
|
4052 break; |
|
4053 default: |
|
4054 break; |
|
4055 } |
|
4056 ret = visualRect(scrollbar->direction, scrollBarRect, ret); |
|
4057 } |
|
4058 break; |
|
4059 #endif // QT_NO_SCROLLBAR |
|
4060 #ifndef QT_NO_SPINBOX |
|
4061 case CC_SpinBox: |
|
4062 if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { |
|
4063 QSize bs; |
|
4064 int fw = spinbox->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0; |
|
4065 bs.setHeight(qMax(8, spinbox->rect.height()/2 - fw)); |
|
4066 // 1.6 -approximate golden mean |
|
4067 bs.setWidth(qMax(16, qMin(bs.height() * 8 / 5, spinbox->rect.width() / 4))); |
|
4068 bs = bs.expandedTo(QApplication::globalStrut()); |
|
4069 int y = fw + spinbox->rect.y(); |
|
4070 int x, lx, rx; |
|
4071 x = spinbox->rect.x() + spinbox->rect.width() - fw - bs.width(); |
|
4072 lx = fw; |
|
4073 rx = x - fw; |
|
4074 switch (sc) { |
|
4075 case SC_SpinBoxUp: |
|
4076 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) |
|
4077 return QRect(); |
|
4078 ret = QRect(x, y, bs.width(), bs.height()); |
|
4079 break; |
|
4080 case SC_SpinBoxDown: |
|
4081 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) |
|
4082 return QRect(); |
|
4083 |
|
4084 ret = QRect(x, y + bs.height(), bs.width(), bs.height()); |
|
4085 break; |
|
4086 case SC_SpinBoxEditField: |
|
4087 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) { |
|
4088 ret = QRect(lx, fw, spinbox->rect.width() - 2*fw, spinbox->rect.height() - 2*fw); |
|
4089 } else { |
|
4090 ret = QRect(lx, fw, rx, spinbox->rect.height() - 2*fw); |
|
4091 } |
|
4092 break; |
|
4093 case SC_SpinBoxFrame: |
|
4094 ret = spinbox->rect; |
|
4095 default: |
|
4096 break; |
|
4097 } |
|
4098 ret = visualRect(spinbox->direction, spinbox->rect, ret); |
|
4099 } |
|
4100 break; |
|
4101 #endif // Qt_NO_SPINBOX |
|
4102 #ifndef QT_NO_TOOLBUTTON |
|
4103 case CC_ToolButton: |
|
4104 if (const QStyleOptionToolButton *tb = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) { |
|
4105 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, tb, widget); |
|
4106 ret = tb->rect; |
|
4107 switch (sc) { |
|
4108 case SC_ToolButton: |
|
4109 if ((tb->features |
|
4110 & (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay)) |
|
4111 == QStyleOptionToolButton::MenuButtonPopup) |
|
4112 ret.adjust(0, 0, -mbi, 0); |
|
4113 break; |
|
4114 case SC_ToolButtonMenu: |
|
4115 if ((tb->features |
|
4116 & (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay)) |
|
4117 == QStyleOptionToolButton::MenuButtonPopup) |
|
4118 ret.adjust(ret.width() - mbi, 0, 0, 0); |
|
4119 break; |
|
4120 default: |
|
4121 break; |
|
4122 } |
|
4123 ret = visualRect(tb->direction, tb->rect, ret); |
|
4124 } |
|
4125 break; |
|
4126 #endif // QT_NO_TOOLBUTTON |
|
4127 #ifndef QT_NO_COMBOBOX |
|
4128 case CC_ComboBox: |
|
4129 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { |
|
4130 int x = cb->rect.x(), |
|
4131 y = cb->rect.y(), |
|
4132 wi = cb->rect.width(), |
|
4133 he = cb->rect.height(); |
|
4134 int xpos = x; |
|
4135 int margin = cb->frame ? 3 : 0; |
|
4136 int bmarg = cb->frame ? 2 : 0; |
|
4137 xpos += wi - bmarg - 16; |
|
4138 |
|
4139 |
|
4140 switch (sc) { |
|
4141 case SC_ComboBoxFrame: |
|
4142 ret = cb->rect; |
|
4143 break; |
|
4144 case SC_ComboBoxArrow: |
|
4145 ret.setRect(xpos, y + bmarg, 16, he - 2*bmarg); |
|
4146 break; |
|
4147 case SC_ComboBoxEditField: |
|
4148 ret.setRect(x + margin, y + margin, wi - 2 * margin - 16, he - 2 * margin); |
|
4149 break; |
|
4150 case SC_ComboBoxListBoxPopup: |
|
4151 ret = cb->rect; |
|
4152 break; |
|
4153 default: |
|
4154 break; |
|
4155 } |
|
4156 ret = visualRect(cb->direction, cb->rect, ret); |
|
4157 } |
|
4158 break; |
|
4159 #endif // QT_NO_COMBOBOX |
|
4160 case CC_TitleBar: |
|
4161 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) { |
|
4162 const int controlMargin = 2; |
|
4163 const int controlHeight = tb->rect.height() - controlMargin *2; |
|
4164 const int delta = controlHeight + controlMargin; |
|
4165 int offset = 0; |
|
4166 |
|
4167 bool isMinimized = tb->titleBarState & Qt::WindowMinimized; |
|
4168 bool isMaximized = tb->titleBarState & Qt::WindowMaximized; |
|
4169 |
|
4170 switch (sc) { |
|
4171 case SC_TitleBarLabel: |
|
4172 if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) { |
|
4173 ret = tb->rect; |
|
4174 if (tb->titleBarFlags & Qt::WindowSystemMenuHint) |
|
4175 ret.adjust(delta, 0, -delta, 0); |
|
4176 if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint) |
|
4177 ret.adjust(0, 0, -delta, 0); |
|
4178 if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint) |
|
4179 ret.adjust(0, 0, -delta, 0); |
|
4180 if (tb->titleBarFlags & Qt::WindowShadeButtonHint) |
|
4181 ret.adjust(0, 0, -delta, 0); |
|
4182 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint) |
|
4183 ret.adjust(0, 0, -delta, 0); |
|
4184 } |
|
4185 break; |
|
4186 case SC_TitleBarContextHelpButton: |
|
4187 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint) |
|
4188 offset += delta; |
|
4189 case SC_TitleBarMinButton: |
|
4190 if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)) |
|
4191 offset += delta; |
|
4192 else if (sc == SC_TitleBarMinButton) |
|
4193 break; |
|
4194 case SC_TitleBarNormalButton: |
|
4195 if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)) |
|
4196 offset += delta; |
|
4197 else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)) |
|
4198 offset += delta; |
|
4199 else if (sc == SC_TitleBarNormalButton) |
|
4200 break; |
|
4201 case SC_TitleBarMaxButton: |
|
4202 if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)) |
|
4203 offset += delta; |
|
4204 else if (sc == SC_TitleBarMaxButton) |
|
4205 break; |
|
4206 case SC_TitleBarShadeButton: |
|
4207 if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint)) |
|
4208 offset += delta; |
|
4209 else if (sc == SC_TitleBarShadeButton) |
|
4210 break; |
|
4211 case SC_TitleBarUnshadeButton: |
|
4212 if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint)) |
|
4213 offset += delta; |
|
4214 else if (sc == SC_TitleBarUnshadeButton) |
|
4215 break; |
|
4216 case SC_TitleBarCloseButton: |
|
4217 if (tb->titleBarFlags & Qt::WindowSystemMenuHint) |
|
4218 offset += delta; |
|
4219 else if (sc == SC_TitleBarCloseButton) |
|
4220 break; |
|
4221 ret.setRect(tb->rect.right() - offset, tb->rect.top() + controlMargin, |
|
4222 controlHeight, controlHeight); |
|
4223 break; |
|
4224 case SC_TitleBarSysMenu: |
|
4225 if (tb->titleBarFlags & Qt::WindowSystemMenuHint) { |
|
4226 ret.setRect(tb->rect.left() + controlMargin, tb->rect.top() + controlMargin, |
|
4227 controlHeight, controlHeight); |
|
4228 } |
|
4229 break; |
|
4230 default: |
|
4231 break; |
|
4232 } |
|
4233 ret = visualRect(tb->direction, tb->rect, ret); |
|
4234 } |
|
4235 break; |
|
4236 #ifndef QT_NO_GROUPBOX |
|
4237 case CC_GroupBox: { |
|
4238 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) { |
|
4239 switch (sc) { |
|
4240 case SC_GroupBoxFrame: |
|
4241 // FALL THROUGH |
|
4242 case SC_GroupBoxContents: { |
|
4243 int topMargin = 0; |
|
4244 int topHeight = 0; |
|
4245 int verticalAlignment = proxy()->styleHint(SH_GroupBox_TextLabelVerticalAlignment, groupBox, widget); |
|
4246 if (groupBox->text.size() || (groupBox->subControls & QStyle::SC_GroupBoxCheckBox)) { |
|
4247 topHeight = groupBox->fontMetrics.height(); |
|
4248 if (verticalAlignment & Qt::AlignVCenter) |
|
4249 topMargin = topHeight / 2; |
|
4250 else if (verticalAlignment & Qt::AlignTop) |
|
4251 topMargin = topHeight; |
|
4252 } |
|
4253 |
|
4254 QRect frameRect = groupBox->rect; |
|
4255 frameRect.setTop(topMargin); |
|
4256 |
|
4257 if (sc == SC_GroupBoxFrame) { |
|
4258 ret = frameRect; |
|
4259 break; |
|
4260 } |
|
4261 |
|
4262 int frameWidth = 0; |
|
4263 if (!(widget && widget->inherits("Q3GroupBox")) |
|
4264 && ((groupBox->features & QStyleOptionFrameV2::Flat) == 0)) { |
|
4265 frameWidth = proxy()->pixelMetric(PM_DefaultFrameWidth, groupBox, widget); |
|
4266 } |
|
4267 ret = frameRect.adjusted(frameWidth, frameWidth + topHeight - topMargin, |
|
4268 -frameWidth, -frameWidth); |
|
4269 break; |
|
4270 } |
|
4271 case SC_GroupBoxCheckBox: |
|
4272 // FALL THROUGH |
|
4273 case SC_GroupBoxLabel: { |
|
4274 QFontMetrics fontMetrics = groupBox->fontMetrics; |
|
4275 int h = fontMetrics.height(); |
|
4276 int tw = fontMetrics.size(Qt::TextShowMnemonic, groupBox->text + QLatin1Char(' ')).width(); |
|
4277 int marg = (groupBox->features & QStyleOptionFrameV2::Flat) ? 0 : 8; |
|
4278 ret = groupBox->rect.adjusted(marg, 0, -marg, 0); |
|
4279 ret.setHeight(h); |
|
4280 |
|
4281 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget); |
|
4282 int indicatorSpace = proxy()->pixelMetric(PM_CheckBoxLabelSpacing, opt, widget) - 1; |
|
4283 bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox; |
|
4284 int checkBoxSize = hasCheckBox ? (indicatorWidth + indicatorSpace) : 0; |
|
4285 |
|
4286 // Adjusted rect for label + indicatorWidth + indicatorSpace |
|
4287 QRect totalRect = alignedRect(groupBox->direction, groupBox->textAlignment, |
|
4288 QSize(tw + checkBoxSize, h), ret); |
|
4289 |
|
4290 // Adjust totalRect if checkbox is set |
|
4291 if (hasCheckBox) { |
|
4292 bool ltr = groupBox->direction == Qt::LeftToRight; |
|
4293 int left = 0; |
|
4294 // Adjust for check box |
|
4295 if (sc == SC_GroupBoxCheckBox) { |
|
4296 int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, opt, widget); |
|
4297 left = ltr ? totalRect.left() : (totalRect.right() - indicatorWidth); |
|
4298 int top = totalRect.top() + (fontMetrics.height() - indicatorHeight) / 2; |
|
4299 totalRect.setRect(left, top, indicatorWidth, indicatorHeight); |
|
4300 // Adjust for label |
|
4301 } else { |
|
4302 left = ltr ? (totalRect.left() + checkBoxSize - 2) : totalRect.left(); |
|
4303 totalRect.setRect(left, totalRect.top(), |
|
4304 totalRect.width() - checkBoxSize, totalRect.height()); |
|
4305 } |
|
4306 } |
|
4307 ret = totalRect; |
|
4308 break; |
|
4309 } |
|
4310 default: |
|
4311 break; |
|
4312 } |
|
4313 } |
|
4314 break; |
|
4315 } |
|
4316 #endif // QT_NO_GROUPBOX |
|
4317 #ifndef QT_NO_WORKSPACE |
|
4318 case CC_MdiControls: |
|
4319 { |
|
4320 int numSubControls = 0; |
|
4321 if (opt->subControls & SC_MdiCloseButton) |
|
4322 ++numSubControls; |
|
4323 if (opt->subControls & SC_MdiMinButton) |
|
4324 ++numSubControls; |
|
4325 if (opt->subControls & SC_MdiNormalButton) |
|
4326 ++numSubControls; |
|
4327 if (numSubControls == 0) |
|
4328 break; |
|
4329 |
|
4330 int buttonWidth = opt->rect.width()/ numSubControls - 1; |
|
4331 int offset = 0; |
|
4332 switch (sc) { |
|
4333 case SC_MdiCloseButton: |
|
4334 // Only one sub control, no offset needed. |
|
4335 if (numSubControls == 1) |
|
4336 break; |
|
4337 offset += buttonWidth + 2; |
|
4338 //FALL THROUGH |
|
4339 case SC_MdiNormalButton: |
|
4340 // No offset needed if |
|
4341 // 1) There's only one sub control |
|
4342 // 2) We have a close button and a normal button (offset already added in SC_MdiClose) |
|
4343 if (numSubControls == 1 || (numSubControls == 2 && !(opt->subControls & SC_MdiMinButton))) |
|
4344 break; |
|
4345 if (opt->subControls & SC_MdiNormalButton) |
|
4346 offset += buttonWidth; |
|
4347 break; |
|
4348 default: |
|
4349 break; |
|
4350 } |
|
4351 |
|
4352 // Subtract one pixel if we only have one sub control. At this point |
|
4353 // buttonWidth is the actual width + 1 pixel margin, but we don't want the |
|
4354 // margin when there are no other controllers. |
|
4355 if (numSubControls == 1) |
|
4356 --buttonWidth; |
|
4357 ret = QRect(offset, 0, buttonWidth, opt->rect.height()); |
|
4358 break; |
|
4359 } |
|
4360 #endif // QT_NO_WORKSPACE |
|
4361 default: |
|
4362 qWarning("QCommonStyle::subControlRect: Case %d not handled", cc); |
|
4363 } |
|
4364 return ret; |
|
4365 } |
|
4366 |
|
4367 /*! \reimp */ |
|
4368 int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWidget *widget) const |
|
4369 { |
|
4370 int ret; |
|
4371 |
|
4372 switch (m) { |
|
4373 case PM_FocusFrameVMargin: |
|
4374 case PM_FocusFrameHMargin: |
|
4375 ret = 2; |
|
4376 break; |
|
4377 case PM_MenuBarVMargin: |
|
4378 case PM_MenuBarHMargin: |
|
4379 ret = 0; |
|
4380 break; |
|
4381 case PM_DialogButtonsSeparator: |
|
4382 ret = int(QStyleHelper::dpiScaled(5.)); |
|
4383 break; |
|
4384 case PM_DialogButtonsButtonWidth: |
|
4385 ret = int(QStyleHelper::dpiScaled(70.)); |
|
4386 break; |
|
4387 case PM_DialogButtonsButtonHeight: |
|
4388 ret = int(QStyleHelper::dpiScaled(30.)); |
|
4389 break; |
|
4390 case PM_CheckListControllerSize: |
|
4391 case PM_CheckListButtonSize: |
|
4392 ret = int(QStyleHelper::dpiScaled(16.)); |
|
4393 break; |
|
4394 case PM_TitleBarHeight: { |
|
4395 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) { |
|
4396 if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool) { |
|
4397 ret = qMax(widget ? widget->fontMetrics().height() : opt->fontMetrics.height(), 16); |
|
4398 #ifndef QT_NO_DOCKWIDGET |
|
4399 } else if (qobject_cast<const QDockWidget*>(widget)) { |
|
4400 ret = qMax(widget->fontMetrics().height(), int(QStyleHelper::dpiScaled(13))); |
|
4401 #endif |
|
4402 } else { |
|
4403 ret = qMax(widget ? widget->fontMetrics().height() : opt->fontMetrics.height(), 18); |
|
4404 } |
|
4405 } else { |
|
4406 ret = int(QStyleHelper::dpiScaled(18.)); |
|
4407 } |
|
4408 |
|
4409 break; } |
|
4410 case PM_ScrollBarSliderMin: |
|
4411 ret = int(QStyleHelper::dpiScaled(9.)); |
|
4412 break; |
|
4413 |
|
4414 case PM_ButtonMargin: |
|
4415 ret = int(QStyleHelper::dpiScaled(6.)); |
|
4416 break; |
|
4417 |
|
4418 case PM_DockWidgetTitleBarButtonMargin: |
|
4419 ret = int(QStyleHelper::dpiScaled(2.)); |
|
4420 break; |
|
4421 |
|
4422 case PM_ButtonDefaultIndicator: |
|
4423 ret = 0; |
|
4424 break; |
|
4425 |
|
4426 case PM_MenuButtonIndicator: |
|
4427 ret = int(QStyleHelper::dpiScaled(12.)); |
|
4428 break; |
|
4429 |
|
4430 case PM_ButtonShiftHorizontal: |
|
4431 case PM_ButtonShiftVertical: |
|
4432 |
|
4433 case PM_DefaultFrameWidth: |
|
4434 ret = 2; |
|
4435 break; |
|
4436 |
|
4437 case PM_ComboBoxFrameWidth: |
|
4438 case PM_SpinBoxFrameWidth: |
|
4439 case PM_MenuPanelWidth: |
|
4440 case PM_TabBarBaseOverlap: |
|
4441 case PM_TabBarBaseHeight: |
|
4442 ret = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget); |
|
4443 break; |
|
4444 |
|
4445 case PM_MdiSubWindowFrameWidth: |
|
4446 ret = int(QStyleHelper::dpiScaled(4.)); |
|
4447 break; |
|
4448 |
|
4449 case PM_MdiSubWindowMinimizedWidth: |
|
4450 ret = int(QStyleHelper::dpiScaled(196.)); |
|
4451 break; |
|
4452 |
|
4453 #ifndef QT_NO_SCROLLBAR |
|
4454 case PM_ScrollBarExtent: |
|
4455 if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
4456 int s = sb->orientation == Qt::Horizontal ? |
|
4457 QApplication::globalStrut().height() |
|
4458 : QApplication::globalStrut().width(); |
|
4459 ret = qMax(16, s); |
|
4460 } else { |
|
4461 ret = int(QStyleHelper::dpiScaled(16.)); |
|
4462 } |
|
4463 break; |
|
4464 #endif |
|
4465 case PM_MaximumDragDistance: |
|
4466 ret = -1; |
|
4467 break; |
|
4468 |
|
4469 #ifndef QT_NO_SLIDER |
|
4470 case PM_SliderThickness: |
|
4471 ret = int(QStyleHelper::dpiScaled(16.)); |
|
4472 break; |
|
4473 |
|
4474 case PM_SliderTickmarkOffset: |
|
4475 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
4476 int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() |
|
4477 : sl->rect.width(); |
|
4478 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, sl, widget); |
|
4479 int ticks = sl->tickPosition; |
|
4480 |
|
4481 if (ticks == QSlider::TicksBothSides) |
|
4482 ret = (space - thickness) / 2; |
|
4483 else if (ticks == QSlider::TicksAbove) |
|
4484 ret = space - thickness; |
|
4485 else |
|
4486 ret = 0; |
|
4487 } else { |
|
4488 ret = 0; |
|
4489 } |
|
4490 break; |
|
4491 |
|
4492 case PM_SliderSpaceAvailable: |
|
4493 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
4494 if (sl->orientation == Qt::Horizontal) |
|
4495 ret = sl->rect.width() - proxy()->pixelMetric(PM_SliderLength, sl, widget); |
|
4496 else |
|
4497 ret = sl->rect.height() - proxy()->pixelMetric(PM_SliderLength, sl, widget); |
|
4498 } else { |
|
4499 ret = 0; |
|
4500 } |
|
4501 break; |
|
4502 #endif // QT_NO_SLIDER |
|
4503 #ifndef QT_NO_DOCKWIDGET |
|
4504 case PM_DockWidgetSeparatorExtent: |
|
4505 ret = int(QStyleHelper::dpiScaled(6.)); |
|
4506 break; |
|
4507 |
|
4508 case PM_DockWidgetHandleExtent: |
|
4509 ret = int(QStyleHelper::dpiScaled(8.)); |
|
4510 break; |
|
4511 case PM_DockWidgetTitleMargin: |
|
4512 ret = 0; |
|
4513 break; |
|
4514 case PM_DockWidgetFrameWidth: |
|
4515 ret = 1; |
|
4516 break; |
|
4517 #endif // QT_NO_DOCKWIDGET |
|
4518 |
|
4519 case PM_SpinBoxSliderHeight: |
|
4520 case PM_MenuBarPanelWidth: |
|
4521 ret = 2; |
|
4522 break; |
|
4523 |
|
4524 case PM_MenuBarItemSpacing: |
|
4525 ret = 0; |
|
4526 break; |
|
4527 |
|
4528 #ifndef QT_NO_TOOLBAR |
|
4529 case PM_ToolBarFrameWidth: |
|
4530 ret = 1; |
|
4531 break; |
|
4532 |
|
4533 case PM_ToolBarItemMargin: |
|
4534 ret = 0; |
|
4535 break; |
|
4536 |
|
4537 case PM_ToolBarItemSpacing: |
|
4538 ret = int(QStyleHelper::dpiScaled(4.)); |
|
4539 break; |
|
4540 |
|
4541 case PM_ToolBarHandleExtent: |
|
4542 ret = int(QStyleHelper::dpiScaled(8.)); |
|
4543 break; |
|
4544 |
|
4545 case PM_ToolBarSeparatorExtent: |
|
4546 ret = int(QStyleHelper::dpiScaled(6.)); |
|
4547 break; |
|
4548 |
|
4549 case PM_ToolBarExtensionExtent: |
|
4550 ret = int(QStyleHelper::dpiScaled(12.)); |
|
4551 break; |
|
4552 #endif // QT_NO_TOOLBAR |
|
4553 |
|
4554 #ifndef QT_NO_TABBAR |
|
4555 case PM_TabBarTabOverlap: |
|
4556 ret = 3; |
|
4557 break; |
|
4558 |
|
4559 case PM_TabBarTabHSpace: |
|
4560 ret = int(QStyleHelper::dpiScaled(24.)); |
|
4561 break; |
|
4562 |
|
4563 case PM_TabBarTabShiftHorizontal: |
|
4564 ret = 0; |
|
4565 break; |
|
4566 |
|
4567 case PM_TabBarTabShiftVertical: |
|
4568 ret = 2; |
|
4569 break; |
|
4570 |
|
4571 case PM_TabBarTabVSpace: { |
|
4572 const QStyleOptionTab *tb = qstyleoption_cast<const QStyleOptionTab *>(opt); |
|
4573 if (tb && (tb->shape == QTabBar::RoundedNorth || tb->shape == QTabBar::RoundedSouth |
|
4574 || tb->shape == QTabBar::RoundedWest || tb->shape == QTabBar::RoundedEast)) |
|
4575 ret = 8; |
|
4576 else |
|
4577 if(tb && (tb->shape == QTabBar::TriangularWest || tb->shape == QTabBar::TriangularEast)) |
|
4578 ret = 3; |
|
4579 else |
|
4580 ret = 2; |
|
4581 break; } |
|
4582 #endif |
|
4583 |
|
4584 case PM_ProgressBarChunkWidth: |
|
4585 ret = 9; |
|
4586 break; |
|
4587 |
|
4588 case PM_IndicatorWidth: |
|
4589 ret = int(QStyleHelper::dpiScaled(13.)); |
|
4590 break; |
|
4591 |
|
4592 case PM_IndicatorHeight: |
|
4593 ret = int(QStyleHelper::dpiScaled(13.)); |
|
4594 break; |
|
4595 |
|
4596 case PM_ExclusiveIndicatorWidth: |
|
4597 ret = int(QStyleHelper::dpiScaled(12.)); |
|
4598 break; |
|
4599 |
|
4600 case PM_ExclusiveIndicatorHeight: |
|
4601 ret = int(QStyleHelper::dpiScaled(12.)); |
|
4602 break; |
|
4603 |
|
4604 case PM_MenuTearoffHeight: |
|
4605 ret = int(QStyleHelper::dpiScaled(10.)); |
|
4606 break; |
|
4607 |
|
4608 case PM_MenuScrollerHeight: |
|
4609 ret = int(QStyleHelper::dpiScaled(10.)); |
|
4610 break; |
|
4611 |
|
4612 case PM_MenuDesktopFrameWidth: |
|
4613 case PM_MenuHMargin: |
|
4614 case PM_MenuVMargin: |
|
4615 ret = 0; |
|
4616 break; |
|
4617 |
|
4618 case PM_HeaderMargin: |
|
4619 ret = int(QStyleHelper::dpiScaled(4.)); |
|
4620 break; |
|
4621 case PM_HeaderMarkSize: |
|
4622 ret = int(QStyleHelper::dpiScaled(32.)); |
|
4623 break; |
|
4624 case PM_HeaderGripMargin: |
|
4625 ret = int(QStyleHelper::dpiScaled(4.)); |
|
4626 break; |
|
4627 case PM_TabBarScrollButtonWidth: |
|
4628 ret = int(QStyleHelper::dpiScaled(16.)); |
|
4629 break; |
|
4630 case PM_LayoutLeftMargin: |
|
4631 case PM_LayoutTopMargin: |
|
4632 case PM_LayoutRightMargin: |
|
4633 case PM_LayoutBottomMargin: |
|
4634 { |
|
4635 bool isWindow = false; |
|
4636 if (opt) { |
|
4637 isWindow = (opt->state & State_Window); |
|
4638 } else if (widget) { |
|
4639 isWindow = widget->isWindow(); |
|
4640 } |
|
4641 ret = proxy()->pixelMetric(isWindow ? PM_DefaultTopLevelMargin : PM_DefaultChildMargin); |
|
4642 } |
|
4643 break; |
|
4644 case PM_LayoutHorizontalSpacing: |
|
4645 case PM_LayoutVerticalSpacing: |
|
4646 ret = proxy()->pixelMetric(PM_DefaultLayoutSpacing); |
|
4647 break; |
|
4648 |
|
4649 case PM_DefaultTopLevelMargin: |
|
4650 ret = int(QStyleHelper::dpiScaled(11.)); |
|
4651 break; |
|
4652 case PM_DefaultChildMargin: |
|
4653 ret = int(QStyleHelper::dpiScaled(9.)); |
|
4654 break; |
|
4655 case PM_DefaultLayoutSpacing: |
|
4656 ret = int(QStyleHelper::dpiScaled(6.)); |
|
4657 break; |
|
4658 |
|
4659 case PM_ToolBarIconSize: |
|
4660 ret = qt_guiPlatformPlugin()->platformHint(QGuiPlatformPlugin::PH_ToolBarIconSize); |
|
4661 if (!ret) |
|
4662 ret = int(QStyleHelper::dpiScaled(24.)); |
|
4663 break; |
|
4664 |
|
4665 case PM_TabBarIconSize: |
|
4666 case PM_ListViewIconSize: |
|
4667 ret = proxy()->pixelMetric(PM_SmallIconSize, opt, widget); |
|
4668 break; |
|
4669 |
|
4670 case PM_ButtonIconSize: |
|
4671 case PM_SmallIconSize: |
|
4672 ret = int(QStyleHelper::dpiScaled(16.)); |
|
4673 break; |
|
4674 case PM_IconViewIconSize: |
|
4675 ret = proxy()->pixelMetric(PM_LargeIconSize, opt, widget); |
|
4676 break; |
|
4677 |
|
4678 case PM_LargeIconSize: |
|
4679 ret = int(QStyleHelper::dpiScaled(32.)); |
|
4680 break; |
|
4681 |
|
4682 case PM_ToolTipLabelFrameWidth: |
|
4683 ret = 1; |
|
4684 break; |
|
4685 case PM_CheckBoxLabelSpacing: |
|
4686 case PM_RadioButtonLabelSpacing: |
|
4687 ret = int(QStyleHelper::dpiScaled(6.)); |
|
4688 break; |
|
4689 case PM_SizeGripSize: |
|
4690 ret = int(QStyleHelper::dpiScaled(13.)); |
|
4691 break; |
|
4692 case PM_MessageBoxIconSize: |
|
4693 #ifdef Q_WS_MAC |
|
4694 if (QApplication::desktopSettingsAware()) { |
|
4695 ret = 64; // No DPI scaling, it's handled elsewhere. |
|
4696 } else |
|
4697 #endif |
|
4698 { |
|
4699 ret = int(QStyleHelper::dpiScaled(32.)); |
|
4700 } |
|
4701 break; |
|
4702 case PM_TextCursorWidth: |
|
4703 ret = 1; |
|
4704 break; |
|
4705 case PM_TabBar_ScrollButtonOverlap: |
|
4706 ret = 1; |
|
4707 break; |
|
4708 case PM_TabCloseIndicatorWidth: |
|
4709 case PM_TabCloseIndicatorHeight: |
|
4710 ret = int(QStyleHelper::dpiScaled(16.)); |
|
4711 break; |
|
4712 case PM_ScrollView_ScrollBarSpacing: |
|
4713 ret = 2 * proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget); |
|
4714 break; |
|
4715 case PM_SubMenuOverlap: |
|
4716 ret = -proxy()->pixelMetric(QStyle::PM_MenuPanelWidth, opt, widget); |
|
4717 break; |
|
4718 default: |
|
4719 ret = 0; |
|
4720 break; |
|
4721 } |
|
4722 |
|
4723 return ret; |
|
4724 } |
|
4725 |
|
4726 /*! |
|
4727 \reimp |
|
4728 */ |
|
4729 QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, |
|
4730 const QSize &csz, const QWidget *widget) const |
|
4731 { |
|
4732 Q_D(const QCommonStyle); |
|
4733 QSize sz(csz); |
|
4734 switch (ct) { |
|
4735 case CT_PushButton: |
|
4736 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
4737 int w = csz.width(), |
|
4738 h = csz.height(), |
|
4739 bm = proxy()->pixelMetric(PM_ButtonMargin, btn, widget), |
|
4740 fw = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget) * 2; |
|
4741 w += bm + fw; |
|
4742 h += bm + fw; |
|
4743 if (btn->features & QStyleOptionButton::AutoDefaultButton){ |
|
4744 int dbw = proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget) * 2; |
|
4745 w += dbw; |
|
4746 h += dbw; |
|
4747 } |
|
4748 sz = QSize(w, h); |
|
4749 } |
|
4750 break; |
|
4751 case CT_RadioButton: |
|
4752 case CT_CheckBox: |
|
4753 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
4754 bool isRadio = (ct == CT_RadioButton); |
|
4755 |
|
4756 int w = proxy()->pixelMetric(isRadio ? PM_ExclusiveIndicatorWidth |
|
4757 : PM_IndicatorWidth, btn, widget); |
|
4758 int h = proxy()->pixelMetric(isRadio ? PM_ExclusiveIndicatorHeight |
|
4759 : PM_IndicatorHeight, btn, widget); |
|
4760 |
|
4761 int margins = 0; |
|
4762 // we add 4 pixels for label margins |
|
4763 if (btn->icon.isNull() || !btn->text.isEmpty()) |
|
4764 margins = 4 + proxy()->pixelMetric(isRadio ? PM_RadioButtonLabelSpacing |
|
4765 : PM_CheckBoxLabelSpacing, opt, widget); |
|
4766 sz += QSize(w + margins, 4); |
|
4767 sz.setHeight(qMax(sz.height(), h)); |
|
4768 } |
|
4769 break; |
|
4770 #ifndef QT_NO_MENU |
|
4771 case CT_MenuItem: |
|
4772 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { |
|
4773 bool checkable = mi->menuHasCheckableItems; |
|
4774 int maxpmw = mi->maxIconWidth; |
|
4775 int w = sz.width(), h = sz.height(); |
|
4776 if (mi->menuItemType == QStyleOptionMenuItem::Separator) { |
|
4777 w = 10; |
|
4778 h = 2; |
|
4779 } else { |
|
4780 h = mi->fontMetrics.height() + 8; |
|
4781 if (!mi->icon.isNull()) { |
|
4782 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize); |
|
4783 h = qMax(h, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4); |
|
4784 } |
|
4785 } |
|
4786 if (mi->text.contains(QLatin1Char('\t'))) |
|
4787 w += 12; |
|
4788 if (maxpmw > 0) |
|
4789 w += maxpmw + 6; |
|
4790 if (checkable && maxpmw < 20) |
|
4791 w += 20 - maxpmw; |
|
4792 if (checkable || maxpmw > 0) |
|
4793 w += 2; |
|
4794 w += 12; |
|
4795 sz = QSize(w, h); |
|
4796 } |
|
4797 break; |
|
4798 #endif // QT_NO_MENU |
|
4799 #ifndef QT_NO_TOOLBUTTON |
|
4800 case CT_ToolButton: |
|
4801 sz = QSize(sz.width() + 6, sz.height() + 5); |
|
4802 break; |
|
4803 #endif // QT_NO_TOOLBUTTON |
|
4804 #ifndef QT_NO_COMBOBOX |
|
4805 case CT_ComboBox: |
|
4806 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { |
|
4807 int fw = cmb->frame ? proxy()->pixelMetric(PM_ComboBoxFrameWidth, opt, widget) * 2 : 0; |
|
4808 const int textMargins = 2*(proxy()->pixelMetric(PM_FocusFrameHMargin) + 1); |
|
4809 // QItemDelegate::sizeHint expands the textMargins two times, thus the 2*textMargins... |
|
4810 int other = qMax(23, 2*textMargins + proxy()->pixelMetric(QStyle::PM_ScrollBarExtent, opt, widget)); |
|
4811 sz = QSize(sz.width() + fw + other, sz.height() + fw); |
|
4812 } |
|
4813 break; |
|
4814 #endif // QT_NO_COMBOBOX |
|
4815 case CT_HeaderSection: |
|
4816 if (const QStyleOptionHeader *hdr = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { |
|
4817 bool nullIcon = hdr->icon.isNull(); |
|
4818 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, hdr, widget); |
|
4819 int iconSize = nullIcon ? 0 : proxy()->pixelMetric(QStyle::PM_SmallIconSize, hdr, widget); |
|
4820 QSize txt = hdr->fontMetrics.size(0, hdr->text); |
|
4821 sz.setHeight(margin + qMax(iconSize, txt.height()) + margin); |
|
4822 sz.setWidth((nullIcon ? 0 : margin) + iconSize |
|
4823 + (hdr->text.isNull() ? 0 : margin) + txt.width() + margin); |
|
4824 } |
|
4825 break; |
|
4826 case CT_TabWidget: |
|
4827 sz += QSize(4, 4); |
|
4828 break; |
|
4829 case CT_LineEdit: |
|
4830 if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt)) |
|
4831 sz += QSize(2*f->lineWidth, 2*f->lineWidth); |
|
4832 break; |
|
4833 #ifndef QT_NO_GROUPBOX |
|
4834 case CT_GroupBox: |
|
4835 if (const QGroupBox *grb = static_cast<const QGroupBox *>(widget)) |
|
4836 sz += QSize(!grb->isFlat() ? 16 : 0, 0); |
|
4837 break; |
|
4838 #endif // QT_NO_GROUPBOX |
|
4839 case CT_MdiControls: |
|
4840 if (const QStyleOptionComplex *styleOpt = qstyleoption_cast<const QStyleOptionComplex *>(opt)) { |
|
4841 int width = 1; |
|
4842 if (styleOpt->subControls & SC_MdiMinButton) |
|
4843 width += 16 + 1; |
|
4844 if (styleOpt->subControls & SC_MdiNormalButton) |
|
4845 width += 16 + 1; |
|
4846 if (styleOpt->subControls & SC_MdiCloseButton) |
|
4847 width += 16 + 1; |
|
4848 sz = QSize(width, 16); |
|
4849 } else { |
|
4850 sz = QSize(52, 16); |
|
4851 } |
|
4852 break; |
|
4853 #ifndef QT_NO_ITEMVIEWS |
|
4854 case CT_ItemViewItem: |
|
4855 if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { |
|
4856 QRect decorationRect, displayRect, checkRect; |
|
4857 d->viewItemLayout(vopt, &checkRect, &decorationRect, &displayRect, true); |
|
4858 sz = (decorationRect|displayRect|checkRect).size(); |
|
4859 } |
|
4860 break; |
|
4861 #endif // QT_NO_ITEMVIEWS |
|
4862 case CT_ScrollBar: |
|
4863 case CT_MenuBar: |
|
4864 case CT_Menu: |
|
4865 case CT_MenuBarItem: |
|
4866 case CT_Q3Header: |
|
4867 case CT_Slider: |
|
4868 case CT_ProgressBar: |
|
4869 case CT_TabBarTab: |
|
4870 // just return the contentsSize for now |
|
4871 // fall through intended |
|
4872 default: |
|
4873 break; |
|
4874 } |
|
4875 return sz; |
|
4876 } |
|
4877 |
|
4878 |
|
4879 /*! \reimp */ |
|
4880 int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *widget, |
|
4881 QStyleHintReturn *hret) const |
|
4882 { |
|
4883 int ret = 0; |
|
4884 |
|
4885 switch (sh) { |
|
4886 case SH_Menu_KeyboardSearch: |
|
4887 ret = false; |
|
4888 break; |
|
4889 case SH_Slider_AbsoluteSetButtons: |
|
4890 ret = Qt::MidButton; |
|
4891 break; |
|
4892 case SH_Slider_PageSetButtons: |
|
4893 ret = Qt::LeftButton; |
|
4894 break; |
|
4895 case SH_ScrollBar_ContextMenu: |
|
4896 ret = true; |
|
4897 break; |
|
4898 case SH_DialogButtons_DefaultButton: // This value not used anywhere. |
|
4899 ret = QDialogButtonBox::AcceptRole; |
|
4900 break; |
|
4901 #ifndef QT_NO_GROUPBOX |
|
4902 case SH_GroupBox_TextLabelVerticalAlignment: |
|
4903 ret = Qt::AlignVCenter; |
|
4904 break; |
|
4905 |
|
4906 case SH_GroupBox_TextLabelColor: |
|
4907 ret = opt ? int(opt->palette.color(QPalette::Text).rgba()) : 0; |
|
4908 break; |
|
4909 #endif // QT_NO_GROUPBOX |
|
4910 |
|
4911 case SH_Q3ListViewExpand_SelectMouseType: |
|
4912 case SH_TabBar_SelectMouseType: |
|
4913 ret = QEvent::MouseButtonPress; |
|
4914 break; |
|
4915 |
|
4916 #ifdef QT3_SUPPORT |
|
4917 case SH_GUIStyle: |
|
4918 ret = Qt::WindowsStyle; |
|
4919 break; |
|
4920 #endif |
|
4921 |
|
4922 case SH_TabBar_Alignment: |
|
4923 case SH_Header_ArrowAlignment: |
|
4924 ret = Qt::AlignLeft; |
|
4925 break; |
|
4926 |
|
4927 case SH_TitleBar_AutoRaise: |
|
4928 ret = false; |
|
4929 break; |
|
4930 |
|
4931 case SH_Menu_SubMenuPopupDelay: |
|
4932 ret = 256; |
|
4933 break; |
|
4934 |
|
4935 case SH_ProgressDialog_TextLabelAlignment: |
|
4936 ret = Qt::AlignCenter; |
|
4937 break; |
|
4938 |
|
4939 case SH_BlinkCursorWhenTextSelected: |
|
4940 ret = 1; |
|
4941 break; |
|
4942 |
|
4943 case SH_Table_GridLineColor: |
|
4944 if (opt) |
|
4945 ret = opt->palette.color(QPalette::Mid).rgb(); |
|
4946 else |
|
4947 ret = -1; |
|
4948 break; |
|
4949 case SH_LineEdit_PasswordCharacter: { |
|
4950 const QFontMetrics &fm = opt ? opt->fontMetrics |
|
4951 : (widget ? widget->fontMetrics() : QFontMetrics(QFont())); |
|
4952 ret = 0; |
|
4953 if (fm.inFont(QChar(0x25CF))) { |
|
4954 ret = 0x25CF; |
|
4955 } else if (fm.inFont(QChar(0x2022))) { |
|
4956 ret = 0x2022; |
|
4957 } else { |
|
4958 ret = '*'; |
|
4959 } |
|
4960 break; |
|
4961 } |
|
4962 |
|
4963 |
|
4964 case SH_ToolBox_SelectedPageTitleBold: |
|
4965 ret = 1; |
|
4966 break; |
|
4967 |
|
4968 case SH_UnderlineShortcut: |
|
4969 ret = 1; |
|
4970 break; |
|
4971 |
|
4972 case SH_SpinBox_ClickAutoRepeatRate: |
|
4973 ret = 150; |
|
4974 break; |
|
4975 |
|
4976 case SH_SpinBox_ClickAutoRepeatThreshold: |
|
4977 ret = 500; |
|
4978 break; |
|
4979 |
|
4980 case SH_SpinBox_KeyPressAutoRepeatRate: |
|
4981 ret = 75; |
|
4982 break; |
|
4983 |
|
4984 case SH_Menu_SelectionWrap: |
|
4985 ret = true; |
|
4986 break; |
|
4987 |
|
4988 case SH_Menu_FillScreenWithScroll: |
|
4989 ret = true; |
|
4990 break; |
|
4991 |
|
4992 case SH_ToolTipLabel_Opacity: |
|
4993 ret = 255; |
|
4994 break; |
|
4995 |
|
4996 case SH_Button_FocusPolicy: |
|
4997 ret = Qt::StrongFocus; |
|
4998 break; |
|
4999 |
|
5000 case SH_MenuBar_DismissOnSecondClick: |
|
5001 ret = 1; |
|
5002 break; |
|
5003 |
|
5004 case SH_MessageBox_UseBorderForButtonSpacing: |
|
5005 ret = 0; |
|
5006 break; |
|
5007 |
|
5008 case SH_ToolButton_PopupDelay: |
|
5009 ret = 600; |
|
5010 break; |
|
5011 |
|
5012 case SH_FocusFrame_Mask: |
|
5013 ret = 1; |
|
5014 if (widget) { |
|
5015 if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(hret)) { |
|
5016 mask->region = widget->rect(); |
|
5017 int vmargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin), |
|
5018 hmargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin); |
|
5019 mask->region -= QRect(widget->rect().adjusted(hmargin, vmargin, -hmargin, -vmargin)); |
|
5020 } |
|
5021 } |
|
5022 break; |
|
5023 #ifndef QT_NO_RUBBERBAND |
|
5024 case SH_RubberBand_Mask: |
|
5025 if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) { |
|
5026 ret = 0; |
|
5027 if (rbOpt->shape == QRubberBand::Rectangle) { |
|
5028 ret = true; |
|
5029 if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(hret)) { |
|
5030 mask->region = opt->rect; |
|
5031 int margin = proxy()->pixelMetric(PM_DefaultFrameWidth) * 2; |
|
5032 mask->region -= opt->rect.adjusted(margin, margin, -margin, -margin); |
|
5033 } |
|
5034 } |
|
5035 } |
|
5036 break; |
|
5037 #endif // QT_NO_RUBBERBAND |
|
5038 case SH_SpinControls_DisableOnBounds: |
|
5039 ret = 1; |
|
5040 break; |
|
5041 |
|
5042 case SH_Dial_BackgroundRole: |
|
5043 ret = QPalette::Window; |
|
5044 break; |
|
5045 |
|
5046 case SH_ComboBox_LayoutDirection: |
|
5047 ret = opt ? opt->direction : Qt::LeftToRight; |
|
5048 break; |
|
5049 |
|
5050 case SH_ItemView_EllipsisLocation: |
|
5051 ret = Qt::AlignTrailing; |
|
5052 break; |
|
5053 |
|
5054 case SH_ItemView_ShowDecorationSelected: |
|
5055 ret = false; |
|
5056 break; |
|
5057 |
|
5058 case SH_ItemView_ActivateItemOnSingleClick: |
|
5059 ret = qt_guiPlatformPlugin()->platformHint(QGuiPlatformPlugin::PH_ItemView_ActivateItemOnSingleClick); |
|
5060 break; |
|
5061 |
|
5062 case SH_TitleBar_ModifyNotification: |
|
5063 ret = true; |
|
5064 break; |
|
5065 case SH_ScrollBar_RollBetweenButtons: |
|
5066 ret = false; |
|
5067 break; |
|
5068 case SH_TabBar_ElideMode: |
|
5069 ret = Qt::ElideNone; |
|
5070 break; |
|
5071 case SH_DialogButtonLayout: |
|
5072 ret = QDialogButtonBox::WinLayout; |
|
5073 #ifdef Q_WS_X11 |
|
5074 if (X11->desktopEnvironment == DE_KDE) |
|
5075 ret = QDialogButtonBox::KdeLayout; |
|
5076 else if (X11->desktopEnvironment == DE_GNOME) |
|
5077 ret = QDialogButtonBox::GnomeLayout; |
|
5078 #endif |
|
5079 break; |
|
5080 case SH_ComboBox_PopupFrameStyle: |
|
5081 ret = QFrame::StyledPanel | QFrame::Plain; |
|
5082 break; |
|
5083 case SH_MessageBox_TextInteractionFlags: |
|
5084 ret = Qt::LinksAccessibleByMouse; |
|
5085 break; |
|
5086 case SH_DialogButtonBox_ButtonsHaveIcons: |
|
5087 #ifdef Q_WS_X11 |
|
5088 return true; |
|
5089 #endif |
|
5090 ret = 0; |
|
5091 break; |
|
5092 case SH_SpellCheckUnderlineStyle: |
|
5093 ret = QTextCharFormat::WaveUnderline; |
|
5094 break; |
|
5095 case SH_MessageBox_CenterButtons: |
|
5096 ret = true; |
|
5097 break; |
|
5098 case SH_ItemView_MovementWithoutUpdatingSelection: |
|
5099 ret = true; |
|
5100 break; |
|
5101 case SH_FocusFrame_AboveWidget: |
|
5102 ret = false; |
|
5103 break; |
|
5104 #ifndef QT_NO_TABWIDGET |
|
5105 case SH_TabWidget_DefaultTabPosition: |
|
5106 ret = QTabWidget::North; |
|
5107 break; |
|
5108 #endif |
|
5109 case SH_ToolBar_Movable: |
|
5110 ret = true; |
|
5111 break; |
|
5112 case SH_TextControl_FocusIndicatorTextCharFormat: |
|
5113 ret = true; |
|
5114 if (QStyleHintReturnVariant *vret = qstyleoption_cast<QStyleHintReturnVariant*>(hret)) { |
|
5115 QPen outline(opt->palette.color(QPalette::Text), 1, Qt::DotLine); |
|
5116 QTextCharFormat fmt; |
|
5117 fmt.setProperty(QTextFormat::OutlinePen, outline); |
|
5118 vret->variant = fmt; |
|
5119 } |
|
5120 break; |
|
5121 #ifndef QT_NO_WIZARD |
|
5122 case SH_WizardStyle: |
|
5123 ret = QWizard::ClassicStyle; |
|
5124 break; |
|
5125 #endif |
|
5126 case SH_FormLayoutWrapPolicy: |
|
5127 ret = QFormLayout::DontWrapRows; |
|
5128 break; |
|
5129 case SH_FormLayoutFieldGrowthPolicy: |
|
5130 ret = QFormLayout::AllNonFixedFieldsGrow; |
|
5131 break; |
|
5132 case SH_FormLayoutFormAlignment: |
|
5133 ret = Qt::AlignLeft | Qt::AlignTop; |
|
5134 break; |
|
5135 case SH_FormLayoutLabelAlignment: |
|
5136 ret = Qt::AlignLeft; |
|
5137 break; |
|
5138 case SH_ItemView_ArrowKeysNavigateIntoChildren: |
|
5139 ret = false; |
|
5140 break; |
|
5141 case SH_ItemView_DrawDelegateFrame: |
|
5142 ret = 0; |
|
5143 break; |
|
5144 #ifndef QT_NO_TABBAR |
|
5145 case SH_TabBar_CloseButtonPosition: |
|
5146 ret = QTabBar::RightSide; |
|
5147 break; |
|
5148 #endif |
|
5149 case SH_DockWidget_ButtonsHaveFrame: |
|
5150 ret = true; |
|
5151 break; |
|
5152 case SH_ToolButtonStyle: |
|
5153 ret = qt_guiPlatformPlugin()->platformHint(QGuiPlatformPlugin::PH_ToolButtonStyle); |
|
5154 break; |
|
5155 case SH_RequestSoftwareInputPanel: |
|
5156 ret = RSIP_OnMouseClickAndAlreadyFocused; |
|
5157 break; |
|
5158 default: |
|
5159 ret = 0; |
|
5160 break; |
|
5161 } |
|
5162 |
|
5163 return ret; |
|
5164 } |
|
5165 |
|
5166 /*! \reimp */ |
|
5167 QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option, |
|
5168 const QWidget *widget) const |
|
5169 { |
|
5170 const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QApplication::isRightToLeft()); |
|
5171 #ifdef QT_NO_IMAGEFORMAT_PNG |
|
5172 Q_UNUSED(widget); |
|
5173 Q_UNUSED(sp); |
|
5174 #else |
|
5175 QPixmap pixmap; |
|
5176 |
|
5177 if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) { |
|
5178 switch (sp) { |
|
5179 case SP_DialogYesButton: |
|
5180 case SP_DialogOkButton: |
|
5181 pixmap = QIcon::fromTheme(QLatin1String("dialog-ok")).pixmap(16); |
|
5182 break; |
|
5183 case SP_DialogApplyButton: |
|
5184 pixmap = QIcon::fromTheme(QLatin1String("dialog-ok-apply")).pixmap(16); |
|
5185 break; |
|
5186 case SP_DialogDiscardButton: |
|
5187 pixmap = QIcon::fromTheme(QLatin1String("edit-delete")).pixmap(16); |
|
5188 break; |
|
5189 case SP_DialogCloseButton: |
|
5190 pixmap = QIcon::fromTheme(QLatin1String("dialog-close")).pixmap(16); |
|
5191 break; |
|
5192 case SP_DirHomeIcon: |
|
5193 pixmap = QIcon::fromTheme(QLatin1String("user-home")).pixmap(16); |
|
5194 break; |
|
5195 case SP_MessageBoxInformation: |
|
5196 pixmap = QIcon::fromTheme(QLatin1String("messagebox_info")).pixmap(16); |
|
5197 break; |
|
5198 case SP_MessageBoxWarning: |
|
5199 pixmap = QIcon::fromTheme(QLatin1String("messagebox_warning")).pixmap(16); |
|
5200 break; |
|
5201 case SP_MessageBoxCritical: |
|
5202 pixmap = QIcon::fromTheme(QLatin1String("messagebox_critical")).pixmap(16); |
|
5203 break; |
|
5204 case SP_MessageBoxQuestion: |
|
5205 pixmap = QIcon::fromTheme(QLatin1String("help")).pixmap(16); |
|
5206 break; |
|
5207 case SP_DialogOpenButton: |
|
5208 case SP_DirOpenIcon: |
|
5209 pixmap = QIcon::fromTheme(QLatin1String("folder-open")).pixmap(16); |
|
5210 break; |
|
5211 case SP_FileIcon: |
|
5212 pixmap = QIcon::fromTheme(QLatin1String("text-x-generic"), |
|
5213 QIcon::fromTheme(QLatin1String("empty"))).pixmap(16); |
|
5214 break; |
|
5215 case SP_DirClosedIcon: |
|
5216 case SP_DirIcon: |
|
5217 pixmap = QIcon::fromTheme(QLatin1String("folder")).pixmap(16); |
|
5218 break; |
|
5219 case SP_DriveFDIcon: |
|
5220 pixmap = QIcon::fromTheme(QLatin1String("media-floppy"), |
|
5221 QIcon::fromTheme(QLatin1String("3floppy_unmount"))).pixmap(16); |
|
5222 break; |
|
5223 case SP_ComputerIcon: |
|
5224 pixmap = QIcon::fromTheme(QLatin1String("computer"), |
|
5225 QIcon::fromTheme(QLatin1String("system"))).pixmap(16); |
|
5226 break; |
|
5227 case SP_DesktopIcon: |
|
5228 pixmap = QIcon::fromTheme(QLatin1String("user-desktop"), |
|
5229 QIcon::fromTheme(QLatin1String("desktop"))).pixmap(16); |
|
5230 break; |
|
5231 case SP_TrashIcon: |
|
5232 pixmap = QIcon::fromTheme(QLatin1String("user-trash"), |
|
5233 QIcon::fromTheme(QLatin1String("trashcan_empty"))).pixmap(16); |
|
5234 break; |
|
5235 case SP_DriveCDIcon: |
|
5236 case SP_DriveDVDIcon: |
|
5237 pixmap = QIcon::fromTheme(QLatin1String("media-optical"), |
|
5238 QIcon::fromTheme(QLatin1String("cdrom_unmount"))).pixmap(16); |
|
5239 break; |
|
5240 case SP_DriveHDIcon: |
|
5241 pixmap = QIcon::fromTheme(QLatin1String("drive-harddisk"), |
|
5242 QIcon::fromTheme(QLatin1String("hdd_unmount"))).pixmap(16); |
|
5243 break; |
|
5244 case SP_FileDialogToParent: |
|
5245 pixmap = QIcon::fromTheme(QLatin1String("go-up"), |
|
5246 QIcon::fromTheme(QLatin1String("up"))).pixmap(16); |
|
5247 break; |
|
5248 case SP_FileDialogNewFolder: |
|
5249 pixmap = QIcon::fromTheme(QLatin1String("folder_new")).pixmap(16); |
|
5250 break; |
|
5251 case SP_ArrowUp: |
|
5252 pixmap = QIcon::fromTheme(QLatin1String("go-up"), |
|
5253 QIcon::fromTheme(QLatin1String("up"))).pixmap(16); |
|
5254 break; |
|
5255 case SP_ArrowDown: |
|
5256 pixmap = QIcon::fromTheme(QLatin1String("go-down"), |
|
5257 QIcon::fromTheme(QLatin1String("down"))).pixmap(16); |
|
5258 break; |
|
5259 case SP_ArrowRight: |
|
5260 pixmap = QIcon::fromTheme(QLatin1String("go-next"), |
|
5261 QIcon::fromTheme(QLatin1String("forward"))).pixmap(16); |
|
5262 break; |
|
5263 case SP_ArrowLeft: |
|
5264 pixmap = QIcon::fromTheme(QLatin1String("go-previous"), |
|
5265 QIcon::fromTheme(QLatin1String("back"))).pixmap(16); |
|
5266 break; |
|
5267 case SP_FileDialogDetailedView: |
|
5268 pixmap = QIcon::fromTheme(QLatin1String("view_detailed")).pixmap(16); |
|
5269 break; |
|
5270 case SP_FileDialogListView: |
|
5271 pixmap = QIcon::fromTheme(QLatin1String("view_icon")).pixmap(16); |
|
5272 break; |
|
5273 case SP_BrowserReload: |
|
5274 pixmap = QIcon::fromTheme(QLatin1String("reload")).pixmap(16); |
|
5275 break; |
|
5276 case SP_BrowserStop: |
|
5277 pixmap = QIcon::fromTheme(QLatin1String("process-stop")).pixmap(16); |
|
5278 break; |
|
5279 case SP_MediaPlay: |
|
5280 pixmap = QIcon::fromTheme(QLatin1String("media-playback-start")).pixmap(16); |
|
5281 break; |
|
5282 case SP_MediaPause: |
|
5283 pixmap = QIcon::fromTheme(QLatin1String("media-playback-pause")).pixmap(16); |
|
5284 break; |
|
5285 case SP_MediaStop: |
|
5286 pixmap = QIcon::fromTheme(QLatin1String("media-playback-stop")).pixmap(16); |
|
5287 break; |
|
5288 case SP_MediaSeekForward: |
|
5289 pixmap = QIcon::fromTheme(QLatin1String("media-seek-forward")).pixmap(16); |
|
5290 break; |
|
5291 case SP_MediaSeekBackward: |
|
5292 pixmap = QIcon::fromTheme(QLatin1String("media-seek-backward")).pixmap(16); |
|
5293 break; |
|
5294 case SP_MediaSkipForward: |
|
5295 pixmap = QIcon::fromTheme(QLatin1String("media-skip-backward")).pixmap(16); |
|
5296 break; |
|
5297 case SP_MediaSkipBackward: |
|
5298 pixmap = QIcon::fromTheme(QLatin1String("media-skip-backward")).pixmap(16); |
|
5299 break; |
|
5300 case SP_DialogResetButton: |
|
5301 pixmap = QIcon::fromTheme(QLatin1String("edit-clear")).pixmap(24); |
|
5302 break; |
|
5303 case SP_DialogHelpButton: |
|
5304 pixmap = QIcon::fromTheme(QLatin1String("help-contents")).pixmap(24); |
|
5305 break; |
|
5306 case SP_DialogNoButton: |
|
5307 case SP_DialogCancelButton: |
|
5308 pixmap = QIcon::fromTheme(QLatin1String("dialog-cancel"), |
|
5309 QIcon::fromTheme(QLatin1String("process-stop"))).pixmap(24); |
|
5310 break; |
|
5311 case SP_DialogSaveButton: |
|
5312 pixmap = QIcon::fromTheme(QLatin1String("document-save")).pixmap(24); |
|
5313 break; |
|
5314 case SP_FileLinkIcon: |
|
5315 pixmap = QIcon::fromTheme(QLatin1String("emblem-symbolic-link")).pixmap(16); |
|
5316 if (!pixmap.isNull()) { |
|
5317 QPixmap fileIcon = QIcon::fromTheme(QLatin1String("text-x-generic")).pixmap(16); |
|
5318 if (fileIcon.isNull()) |
|
5319 fileIcon = QIcon::fromTheme(QLatin1String("empty")).pixmap(16); |
|
5320 if (!fileIcon.isNull()) { |
|
5321 QPainter painter(&fileIcon); |
|
5322 painter.drawPixmap(0, 0, 16, 16, pixmap); |
|
5323 return fileIcon; |
|
5324 } |
|
5325 } |
|
5326 break; |
|
5327 case SP_DirLinkIcon: |
|
5328 pixmap = QIcon::fromTheme(QLatin1String("emblem-symbolic-link")).pixmap(16); |
|
5329 if (!pixmap.isNull()) { |
|
5330 QPixmap dirIcon = QIcon::fromTheme(QLatin1String("folder")).pixmap(16); |
|
5331 if (!dirIcon.isNull()) { |
|
5332 QPainter painter(&dirIcon); |
|
5333 painter.drawPixmap(0, 0, 16, 16, pixmap); |
|
5334 return dirIcon; |
|
5335 } |
|
5336 } |
|
5337 break; |
|
5338 default: |
|
5339 break; |
|
5340 } |
|
5341 } |
|
5342 |
|
5343 if (!pixmap.isNull()) |
|
5344 return pixmap; |
|
5345 #endif //QT_NO_IMAGEFORMAT_PNG |
|
5346 switch (sp) { |
|
5347 #ifndef QT_NO_IMAGEFORMAT_XPM |
|
5348 case SP_ToolBarHorizontalExtensionButton: |
|
5349 if (rtl) { |
|
5350 QImage im(tb_extension_arrow_h_xpm); |
|
5351 im = im.convertToFormat(QImage::Format_ARGB32).mirrored(true, false); |
|
5352 return QPixmap::fromImage(im); |
|
5353 } |
|
5354 return QPixmap(tb_extension_arrow_h_xpm); |
|
5355 case SP_ToolBarVerticalExtensionButton: |
|
5356 return QPixmap(tb_extension_arrow_v_xpm); |
|
5357 case SP_FileDialogStart: |
|
5358 return QPixmap(filedialog_start_xpm); |
|
5359 case SP_FileDialogEnd: |
|
5360 return QPixmap(filedialog_end_xpm); |
|
5361 #endif |
|
5362 #ifndef QT_NO_IMAGEFORMAT_PNG |
|
5363 case SP_CommandLink: |
|
5364 case SP_ArrowForward: |
|
5365 if (rtl) |
|
5366 return proxy()->standardPixmap(SP_ArrowLeft, option, widget); |
|
5367 return proxy()->standardPixmap(SP_ArrowRight, option, widget); |
|
5368 case SP_ArrowBack: |
|
5369 if (rtl) |
|
5370 return proxy()->standardPixmap(SP_ArrowRight, option, widget); |
|
5371 return proxy()->standardPixmap(SP_ArrowLeft, option, widget); |
|
5372 case SP_ArrowLeft: |
|
5373 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/left-16.png")); |
|
5374 case SP_ArrowRight: |
|
5375 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/right-16.png")); |
|
5376 case SP_ArrowUp: |
|
5377 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/up-16.png")); |
|
5378 case SP_ArrowDown: |
|
5379 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/down-16.png")); |
|
5380 case SP_FileDialogToParent: |
|
5381 return proxy()->standardPixmap(SP_ArrowUp, option, widget); |
|
5382 case SP_FileDialogNewFolder: |
|
5383 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/newdirectory-16.png")); |
|
5384 case SP_FileDialogDetailedView: |
|
5385 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/viewdetailed-16.png")); |
|
5386 case SP_FileDialogInfoView: |
|
5387 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/fileinfo-16.png")); |
|
5388 case SP_FileDialogContentsView: |
|
5389 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/filecontents-16.png")); |
|
5390 case SP_FileDialogListView: |
|
5391 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/viewlist-16.png")); |
|
5392 case SP_FileDialogBack: |
|
5393 return proxy()->standardPixmap(SP_ArrowBack, option, widget); |
|
5394 case SP_DriveHDIcon: |
|
5395 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/harddrive-16.png")); |
|
5396 case SP_TrashIcon: |
|
5397 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/trash-16.png")); |
|
5398 case SP_DriveFDIcon: |
|
5399 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/floppy-16.png")); |
|
5400 case SP_DriveNetIcon: |
|
5401 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/networkdrive-16.png")); |
|
5402 case SP_DesktopIcon: |
|
5403 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/desktop-16.png")); |
|
5404 case SP_ComputerIcon: |
|
5405 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/computer-16.png")); |
|
5406 case SP_DriveCDIcon: |
|
5407 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/cdr-16.png")); |
|
5408 case SP_DriveDVDIcon: |
|
5409 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/dvd-16.png")); |
|
5410 case SP_DirHomeIcon: |
|
5411 case SP_DirOpenIcon: |
|
5412 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/diropen-16.png")); |
|
5413 case SP_DirIcon: |
|
5414 case SP_DirClosedIcon: |
|
5415 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/dirclosed-16.png")); |
|
5416 case SP_DirLinkIcon: |
|
5417 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/dirlink-16.png")); |
|
5418 case SP_FileIcon: |
|
5419 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/file-16.png")); |
|
5420 case SP_FileLinkIcon: |
|
5421 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/filelink-16.png")); |
|
5422 case SP_DialogOkButton: |
|
5423 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-ok-16.png")); |
|
5424 case SP_DialogCancelButton: |
|
5425 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-cancel-16.png")); |
|
5426 case SP_DialogHelpButton: |
|
5427 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-help-16.png")); |
|
5428 case SP_DialogOpenButton: |
|
5429 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-open-16.png")); |
|
5430 case SP_DialogSaveButton: |
|
5431 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-save-16.png")); |
|
5432 case SP_DialogCloseButton: |
|
5433 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-close-16.png")); |
|
5434 case SP_DialogApplyButton: |
|
5435 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-apply-16.png")); |
|
5436 case SP_DialogResetButton: |
|
5437 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-clear-16.png")); |
|
5438 case SP_DialogDiscardButton: |
|
5439 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-delete-16.png")); |
|
5440 case SP_DialogYesButton: |
|
5441 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-yes-16.png")); |
|
5442 case SP_DialogNoButton: |
|
5443 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-no-16.png")); |
|
5444 case SP_BrowserReload: |
|
5445 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/refresh-24.png")); |
|
5446 case SP_BrowserStop: |
|
5447 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/stop-24.png")); |
|
5448 case SP_MediaPlay: |
|
5449 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/media-play-32.png")); |
|
5450 case SP_MediaPause: |
|
5451 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/media-pause-32.png")); |
|
5452 case SP_MediaStop: |
|
5453 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/media-stop-32.png")); |
|
5454 case SP_MediaSeekForward: |
|
5455 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/media-seek-forward-32.png")); |
|
5456 case SP_MediaSeekBackward: |
|
5457 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/media-seek-backward-32.png")); |
|
5458 case SP_MediaSkipForward: |
|
5459 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/media-skip-forward-32.png")); |
|
5460 case SP_MediaSkipBackward: |
|
5461 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/media-skip-backward-32.png")); |
|
5462 case SP_MediaVolume: |
|
5463 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/media-volume-16.png")); |
|
5464 case SP_MediaVolumeMuted: |
|
5465 return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/media-volume-muted-16.png")); |
|
5466 #endif // QT_NO_IMAGEFORMAT_PNG |
|
5467 default: |
|
5468 break; |
|
5469 } |
|
5470 return QPixmap(); |
|
5471 } |
|
5472 |
|
5473 /*! |
|
5474 \internal |
|
5475 */ |
|
5476 QIcon QCommonStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, |
|
5477 const QWidget *widget) const |
|
5478 { |
|
5479 QIcon icon; |
|
5480 const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QApplication::isRightToLeft()); |
|
5481 if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) { |
|
5482 switch (standardIcon) { |
|
5483 case SP_DirHomeIcon: |
|
5484 icon = QIcon::fromTheme(QLatin1String("user-home")); |
|
5485 break; |
|
5486 case SP_MessageBoxInformation: |
|
5487 icon = QIcon::fromTheme(QLatin1String("dialog-information")); |
|
5488 break; |
|
5489 case SP_MessageBoxWarning: |
|
5490 icon = QIcon::fromTheme(QLatin1String("dialog-warning")); |
|
5491 break; |
|
5492 case SP_MessageBoxCritical: |
|
5493 icon = QIcon::fromTheme(QLatin1String("dialog-error")); |
|
5494 break; |
|
5495 case SP_MessageBoxQuestion: |
|
5496 icon = QIcon::fromTheme(QLatin1String("dialog-question")); |
|
5497 break; |
|
5498 case SP_DialogOpenButton: |
|
5499 case SP_DirOpenIcon: |
|
5500 icon = QIcon::fromTheme(QLatin1String("folder-open")); |
|
5501 break; |
|
5502 case SP_DialogSaveButton: |
|
5503 icon = QIcon::fromTheme(QLatin1String("document-save")); |
|
5504 break; |
|
5505 case SP_DialogApplyButton: |
|
5506 icon = QIcon::fromTheme(QLatin1String("dialog-ok-apply")); |
|
5507 break; |
|
5508 case SP_DialogYesButton: |
|
5509 case SP_DialogOkButton: |
|
5510 icon = QIcon::fromTheme(QLatin1String("dialog-ok")); |
|
5511 break; |
|
5512 case SP_DialogDiscardButton: |
|
5513 icon = QIcon::fromTheme(QLatin1String("edit-delete")); |
|
5514 break; |
|
5515 case SP_DialogResetButton: |
|
5516 icon = QIcon::fromTheme(QLatin1String("edit-clear")); |
|
5517 break; |
|
5518 case SP_DialogHelpButton: |
|
5519 icon = QIcon::fromTheme(QLatin1String("help-contents")); |
|
5520 break; |
|
5521 case SP_FileIcon: |
|
5522 icon = QIcon::fromTheme(QLatin1String("text-x-generic")); |
|
5523 break; |
|
5524 case SP_DirClosedIcon: |
|
5525 case SP_DirIcon: |
|
5526 icon = QIcon::fromTheme(QLatin1String("folder")); |
|
5527 break; |
|
5528 case SP_DriveFDIcon: |
|
5529 icon = QIcon::fromTheme(QLatin1String("floppy_unmount")); |
|
5530 break; |
|
5531 case SP_ComputerIcon: |
|
5532 icon = QIcon::fromTheme(QLatin1String("computer"), |
|
5533 QIcon::fromTheme(QLatin1String("system"))); |
|
5534 break; |
|
5535 case SP_DesktopIcon: |
|
5536 icon = QIcon::fromTheme(QLatin1String("user-desktop")); |
|
5537 break; |
|
5538 case SP_TrashIcon: |
|
5539 icon = QIcon::fromTheme(QLatin1String("user-trash")); |
|
5540 break; |
|
5541 case SP_DriveCDIcon: |
|
5542 case SP_DriveDVDIcon: |
|
5543 icon = QIcon::fromTheme(QLatin1String("media-optical")); |
|
5544 break; |
|
5545 case SP_DriveHDIcon: |
|
5546 icon = QIcon::fromTheme(QLatin1String("drive-harddisk")); |
|
5547 break; |
|
5548 case SP_FileDialogToParent: |
|
5549 icon = QIcon::fromTheme(QLatin1String("go-up")); |
|
5550 break; |
|
5551 case SP_FileDialogNewFolder: |
|
5552 icon = QIcon::fromTheme(QLatin1String("folder-new")); |
|
5553 break; |
|
5554 case SP_ArrowUp: |
|
5555 icon = QIcon::fromTheme(QLatin1String("go-up")); |
|
5556 break; |
|
5557 case SP_ArrowDown: |
|
5558 icon = QIcon::fromTheme(QLatin1String("go-down")); |
|
5559 break; |
|
5560 case SP_ArrowRight: |
|
5561 icon = QIcon::fromTheme(QLatin1String("go-next")); |
|
5562 break; |
|
5563 case SP_ArrowLeft: |
|
5564 icon = QIcon::fromTheme(QLatin1String("go-previous")); |
|
5565 break; |
|
5566 case SP_DialogCancelButton: |
|
5567 icon = QIcon::fromTheme(QLatin1String("dialog-cancel"), |
|
5568 QIcon::fromTheme(QLatin1String("process-stop"))); |
|
5569 break; |
|
5570 case SP_DialogCloseButton: |
|
5571 icon = QIcon::fromTheme(QLatin1String("window-close")); |
|
5572 break; |
|
5573 case SP_FileDialogDetailedView: |
|
5574 icon = QIcon::fromTheme(QLatin1String("view-list-details")); |
|
5575 break; |
|
5576 case SP_FileDialogListView: |
|
5577 icon = QIcon::fromTheme(QLatin1String("view-list-icons")); |
|
5578 break; |
|
5579 case SP_BrowserReload: |
|
5580 icon = QIcon::fromTheme(QLatin1String("view-refresh")); |
|
5581 break; |
|
5582 case SP_BrowserStop: |
|
5583 icon = QIcon::fromTheme(QLatin1String("process-stop")); |
|
5584 break; |
|
5585 case SP_MediaPlay: |
|
5586 icon = QIcon::fromTheme(QLatin1String("media-playback-start")); |
|
5587 break; |
|
5588 case SP_MediaPause: |
|
5589 icon = QIcon::fromTheme(QLatin1String("media-playback-pause")); |
|
5590 break; |
|
5591 case SP_MediaStop: |
|
5592 icon = QIcon::fromTheme(QLatin1String("media-playback-stop")); |
|
5593 break; |
|
5594 case SP_MediaSeekForward: |
|
5595 icon = QIcon::fromTheme(QLatin1String("media-seek-forward")); |
|
5596 break; |
|
5597 case SP_MediaSeekBackward: |
|
5598 icon = QIcon::fromTheme(QLatin1String("media-seek-backward")); |
|
5599 break; |
|
5600 case SP_MediaSkipForward: |
|
5601 icon = QIcon::fromTheme(QLatin1String("media-skip-forward")); |
|
5602 break; |
|
5603 case SP_MediaSkipBackward: |
|
5604 icon = QIcon::fromTheme(QLatin1String("media-skip-backward")); |
|
5605 break; |
|
5606 case SP_MediaVolume: |
|
5607 icon = QIcon::fromTheme(QLatin1String("audio-volume-medium")); |
|
5608 break; |
|
5609 case SP_MediaVolumeMuted: |
|
5610 icon = QIcon::fromTheme(QLatin1String("audio-volume-muted")); |
|
5611 break; |
|
5612 case SP_ArrowForward: |
|
5613 if (rtl) |
|
5614 return standardIconImplementation(SP_ArrowLeft, option, widget); |
|
5615 return standardIconImplementation(SP_ArrowRight, option, widget); |
|
5616 case SP_ArrowBack: |
|
5617 if (rtl) |
|
5618 return standardIconImplementation(SP_ArrowRight, option, widget); |
|
5619 return standardIconImplementation(SP_ArrowLeft, option, widget); |
|
5620 case SP_FileLinkIcon: |
|
5621 { |
|
5622 QIcon linkIcon = QIcon::fromTheme(QLatin1String("emblem-symbolic-link")); |
|
5623 if (!linkIcon.isNull()) { |
|
5624 QIcon baseIcon = standardIconImplementation(SP_FileIcon, option, widget); |
|
5625 const QList<QSize> sizes = baseIcon.availableSizes(QIcon::Normal, QIcon::Off); |
|
5626 for (int i = 0 ; i < sizes.size() ; ++i) { |
|
5627 int size = sizes[i].width(); |
|
5628 QPixmap basePixmap = baseIcon.pixmap(size); |
|
5629 QPixmap linkPixmap = linkIcon.pixmap(size/2); |
|
5630 QPainter painter(&basePixmap); |
|
5631 painter.drawPixmap(size/2, size/2, linkPixmap); |
|
5632 icon.addPixmap(basePixmap); |
|
5633 } |
|
5634 } |
|
5635 } |
|
5636 break; |
|
5637 case SP_DirLinkIcon: |
|
5638 { |
|
5639 QIcon linkIcon = QIcon::fromTheme(QLatin1String("emblem-symbolic-link")); |
|
5640 if (!linkIcon.isNull()) { |
|
5641 QIcon baseIcon = standardIconImplementation(SP_DirIcon, option, widget); |
|
5642 const QList<QSize> sizes = baseIcon.availableSizes(QIcon::Normal, QIcon::Off); |
|
5643 for (int i = 0 ; i < sizes.size() ; ++i) { |
|
5644 int size = sizes[i].width(); |
|
5645 QPixmap basePixmap = baseIcon.pixmap(size); |
|
5646 QPixmap linkPixmap = linkIcon.pixmap(size/2); |
|
5647 QPainter painter(&basePixmap); |
|
5648 painter.drawPixmap(size/2, size/2, linkPixmap); |
|
5649 icon.addPixmap(basePixmap); |
|
5650 } |
|
5651 } |
|
5652 } |
|
5653 break; |
|
5654 default: |
|
5655 break; |
|
5656 } |
|
5657 } // if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) |
|
5658 if (!icon.isNull()) |
|
5659 return icon; |
|
5660 #if defined(Q_WS_MAC) |
|
5661 if (QApplication::desktopSettingsAware()) { |
|
5662 OSType iconType = 0; |
|
5663 switch (standardIcon) { |
|
5664 case QStyle::SP_MessageBoxQuestion: |
|
5665 case QStyle::SP_MessageBoxInformation: |
|
5666 case QStyle::SP_MessageBoxWarning: |
|
5667 case QStyle::SP_MessageBoxCritical: |
|
5668 iconType = kGenericApplicationIcon; |
|
5669 break; |
|
5670 case SP_DesktopIcon: |
|
5671 iconType = kDesktopIcon; |
|
5672 break; |
|
5673 case SP_TrashIcon: |
|
5674 iconType = kTrashIcon; |
|
5675 break; |
|
5676 case SP_ComputerIcon: |
|
5677 iconType = kComputerIcon; |
|
5678 break; |
|
5679 case SP_DriveFDIcon: |
|
5680 iconType = kGenericFloppyIcon; |
|
5681 break; |
|
5682 case SP_DriveHDIcon: |
|
5683 iconType = kGenericHardDiskIcon; |
|
5684 break; |
|
5685 case SP_DriveCDIcon: |
|
5686 case SP_DriveDVDIcon: |
|
5687 iconType = kGenericCDROMIcon; |
|
5688 break; |
|
5689 case SP_DriveNetIcon: |
|
5690 iconType = kGenericNetworkIcon; |
|
5691 break; |
|
5692 case SP_DirOpenIcon: |
|
5693 iconType = kOpenFolderIcon; |
|
5694 break; |
|
5695 case SP_DirClosedIcon: |
|
5696 case SP_DirLinkIcon: |
|
5697 iconType = kGenericFolderIcon; |
|
5698 break; |
|
5699 case SP_FileLinkIcon: |
|
5700 case SP_FileIcon: |
|
5701 iconType = kGenericDocumentIcon; |
|
5702 break; |
|
5703 case SP_DirIcon: { |
|
5704 // A rather special case |
|
5705 QIcon closeIcon = QStyle::standardIcon(SP_DirClosedIcon, option, widget); |
|
5706 QIcon openIcon = QStyle::standardIcon(SP_DirOpenIcon, option, widget); |
|
5707 closeIcon.addPixmap(openIcon.pixmap(16, 16), QIcon::Normal, QIcon::On); |
|
5708 closeIcon.addPixmap(openIcon.pixmap(32, 32), QIcon::Normal, QIcon::On); |
|
5709 closeIcon.addPixmap(openIcon.pixmap(64, 64), QIcon::Normal, QIcon::On); |
|
5710 closeIcon.addPixmap(openIcon.pixmap(128, 128), QIcon::Normal, QIcon::On); |
|
5711 return closeIcon; |
|
5712 } |
|
5713 case SP_TitleBarNormalButton: |
|
5714 case SP_TitleBarCloseButton: { |
|
5715 QIcon titleBarIcon; |
|
5716 if (standardIcon == SP_TitleBarCloseButton) { |
|
5717 titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-16.png")); |
|
5718 titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); |
|
5719 } else { |
|
5720 titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-16.png")); |
|
5721 titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); |
|
5722 } |
|
5723 return titleBarIcon; |
|
5724 } |
|
5725 default: |
|
5726 break; |
|
5727 } |
|
5728 if (iconType != 0) { |
|
5729 QIcon retIcon; |
|
5730 IconRef icon; |
|
5731 IconRef overlayIcon = 0; |
|
5732 if (iconType != kGenericApplicationIcon) { |
|
5733 GetIconRef(kOnSystemDisk, kSystemIconsCreator, iconType, &icon); |
|
5734 } else { |
|
5735 FSRef fsRef; |
|
5736 ProcessSerialNumber psn = { 0, kCurrentProcess }; |
|
5737 GetProcessBundleLocation(&psn, &fsRef); |
|
5738 GetIconRefFromFileInfo(&fsRef, 0, 0, 0, 0, kIconServicesNormalUsageFlag, &icon, 0); |
|
5739 if (standardIcon == SP_MessageBoxCritical) { |
|
5740 overlayIcon = icon; |
|
5741 GetIconRef(kOnSystemDisk, kSystemIconsCreator, kAlertCautionIcon, &icon); |
|
5742 } |
|
5743 } |
|
5744 if (icon) { |
|
5745 qt_mac_constructQIconFromIconRef(icon, overlayIcon, &retIcon, standardIcon); |
|
5746 ReleaseIconRef(icon); |
|
5747 } |
|
5748 if (overlayIcon) |
|
5749 ReleaseIconRef(overlayIcon); |
|
5750 return retIcon; |
|
5751 } |
|
5752 } // if (QApplication::desktopSettingsAware()) |
|
5753 #endif // Q_WS_MAC |
|
5754 |
|
5755 switch (standardIcon) { |
|
5756 #ifndef QT_NO_IMAGEFORMAT_PNG |
|
5757 case SP_FileDialogNewFolder: |
|
5758 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/newdirectory-16.png")); |
|
5759 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/newdirectory-32.png")); |
|
5760 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/newdirectory-128.png")); |
|
5761 break; |
|
5762 case SP_FileDialogBack: |
|
5763 return standardIconImplementation(SP_ArrowBack, option, widget); |
|
5764 case SP_FileDialogToParent: |
|
5765 return standardIconImplementation(SP_ArrowUp, option, widget); |
|
5766 case SP_FileDialogDetailedView: |
|
5767 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/viewdetailed-16.png")); |
|
5768 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/viewdetailed-32.png")); |
|
5769 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/viewdetailed-128.png")); |
|
5770 break; |
|
5771 case SP_FileDialogInfoView: |
|
5772 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/fileinfo-16.png")); |
|
5773 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/fileinfo-32.png")); |
|
5774 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/fileinfo-128.png")); |
|
5775 break; |
|
5776 case SP_FileDialogContentsView: |
|
5777 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/filecontents-16.png")); |
|
5778 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/filecontents-32.png")); |
|
5779 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/filecontents-128.png")); |
|
5780 break; |
|
5781 case SP_FileDialogListView: |
|
5782 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/viewlist-16.png")); |
|
5783 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/viewlist-32.png")); |
|
5784 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/viewlist-128.png")); |
|
5785 break; |
|
5786 case SP_DialogOkButton: |
|
5787 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-ok-16.png")); |
|
5788 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-ok-32.png")); |
|
5789 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-ok-128.png")); |
|
5790 break; |
|
5791 case SP_DialogCancelButton: |
|
5792 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-cancel-16.png")); |
|
5793 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-cancel-32.png")); |
|
5794 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-cancel-128.png")); |
|
5795 break; |
|
5796 case SP_DialogHelpButton: |
|
5797 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-help-16.png")); |
|
5798 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-help-32.png")); |
|
5799 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-help-128.png")); |
|
5800 break; |
|
5801 case SP_DialogOpenButton: |
|
5802 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-open-16.png")); |
|
5803 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-open-32.png")); |
|
5804 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-open-128.png")); |
|
5805 break; |
|
5806 case SP_DialogSaveButton: |
|
5807 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-save-16.png")); |
|
5808 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-save-32.png")); |
|
5809 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-save-128.png")); |
|
5810 break; |
|
5811 case SP_DialogCloseButton: |
|
5812 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-close-16.png")); |
|
5813 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-close-32.png")); |
|
5814 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-close-128.png")); |
|
5815 break; |
|
5816 case SP_DialogApplyButton: |
|
5817 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-apply-16.png")); |
|
5818 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-apply-32.png")); |
|
5819 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-apply-128.png")); |
|
5820 break; |
|
5821 case SP_DialogResetButton: |
|
5822 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-clear-16.png")); |
|
5823 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-clear-32.png")); |
|
5824 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-clear-128.png")); |
|
5825 break; |
|
5826 case SP_DialogDiscardButton: |
|
5827 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-delete-16.png")); |
|
5828 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-delete-32.png")); |
|
5829 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-delete-128.png")); |
|
5830 break; |
|
5831 case SP_DialogYesButton: |
|
5832 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-yes-16.png")); |
|
5833 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-yes-32.png")); |
|
5834 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-yes-128.png")); |
|
5835 break; |
|
5836 case SP_DialogNoButton: |
|
5837 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-no-16.png")); |
|
5838 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-no-32.png")); |
|
5839 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/standardbutton-no-128.png")); |
|
5840 break; |
|
5841 case SP_ArrowForward: |
|
5842 if (rtl) |
|
5843 return standardIconImplementation(SP_ArrowLeft, option, widget); |
|
5844 return standardIconImplementation(SP_ArrowRight, option, widget); |
|
5845 case SP_ArrowBack: |
|
5846 if (rtl) |
|
5847 return standardIconImplementation(SP_ArrowRight, option, widget); |
|
5848 return standardIconImplementation(SP_ArrowLeft, option, widget); |
|
5849 case SP_ArrowLeft: |
|
5850 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/left-16.png")); |
|
5851 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/left-32.png")); |
|
5852 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/left-128.png")); |
|
5853 break; |
|
5854 case SP_ArrowRight: |
|
5855 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/right-16.png")); |
|
5856 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/right-32.png")); |
|
5857 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/right-128.png")); |
|
5858 break; |
|
5859 case SP_ArrowUp: |
|
5860 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/up-16.png")); |
|
5861 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/up-32.png")); |
|
5862 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/up-128.png")); |
|
5863 break; |
|
5864 case SP_ArrowDown: |
|
5865 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/down-16.png")); |
|
5866 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/down-32.png")); |
|
5867 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/down-128.png")); |
|
5868 break; |
|
5869 case SP_DirHomeIcon: |
|
5870 case SP_DirIcon: |
|
5871 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/dirclosed-16.png"), |
|
5872 QSize(), QIcon::Normal, QIcon::Off); |
|
5873 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/diropen-16.png"), |
|
5874 QSize(), QIcon::Normal, QIcon::On); |
|
5875 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/dirclosed-32.png"), |
|
5876 QSize(32, 32), QIcon::Normal, QIcon::Off); |
|
5877 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/diropen-32.png"), |
|
5878 QSize(32, 32), QIcon::Normal, QIcon::On); |
|
5879 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/dirclosed-128.png"), |
|
5880 QSize(128, 128), QIcon::Normal, QIcon::Off); |
|
5881 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/diropen-128.png"), |
|
5882 QSize(128, 128), QIcon::Normal, QIcon::On); |
|
5883 break; |
|
5884 case SP_DriveCDIcon: |
|
5885 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/cdr-16.png")); |
|
5886 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/cdr-32.png")); |
|
5887 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/cdr-128.png")); |
|
5888 break; |
|
5889 case SP_DriveDVDIcon: |
|
5890 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/dvd-16.png")); |
|
5891 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/dvd-32.png")); |
|
5892 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/dvd-128.png")); |
|
5893 break; |
|
5894 case SP_FileIcon: |
|
5895 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/file-16.png")); |
|
5896 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/file-32.png")); |
|
5897 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/file-128.png")); |
|
5898 break; |
|
5899 case SP_FileLinkIcon: |
|
5900 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/filelink-16.png")); |
|
5901 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/filelink-32.png")); |
|
5902 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/filelink-128.png")); |
|
5903 break; |
|
5904 case SP_TrashIcon: |
|
5905 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/trash-16.png")); |
|
5906 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/trash-32.png")); |
|
5907 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/trash-128.png")); |
|
5908 break; |
|
5909 case SP_BrowserReload: |
|
5910 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/refresh-24.png")); |
|
5911 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/refresh-32.png")); |
|
5912 break; |
|
5913 case SP_BrowserStop: |
|
5914 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/stop-24.png")); |
|
5915 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/stop-32.png")); |
|
5916 break; |
|
5917 case SP_MediaPlay: |
|
5918 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-play-16.png")); |
|
5919 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-play-32.png")); |
|
5920 break; |
|
5921 case SP_MediaPause: |
|
5922 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-pause-16.png")); |
|
5923 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-pause-32.png")); |
|
5924 break; |
|
5925 case SP_MediaStop: |
|
5926 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-stop-16.png")); |
|
5927 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-stop-32.png")); |
|
5928 break; |
|
5929 case SP_MediaSeekForward: |
|
5930 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-seek-forward-16.png")); |
|
5931 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-seek-forward-32.png")); |
|
5932 break; |
|
5933 case SP_MediaSeekBackward: |
|
5934 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-seek-backward-16.png")); |
|
5935 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-seek-backward-32.png")); |
|
5936 break; |
|
5937 case SP_MediaSkipForward: |
|
5938 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-skip-forward-16.png")); |
|
5939 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-skip-forward-32.png")); |
|
5940 break; |
|
5941 case SP_MediaSkipBackward: |
|
5942 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-skip-backward-16.png")); |
|
5943 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-skip-backward-32.png")); |
|
5944 break; |
|
5945 case SP_MediaVolume: |
|
5946 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-volume-16.png")); |
|
5947 break; |
|
5948 case SP_MediaVolumeMuted: |
|
5949 icon.addFile(QLatin1String(":/trolltech/styles/commonstyle/images/media-volume-muted-16.png")); |
|
5950 break; |
|
5951 #endif // QT_NO_IMAGEFORMAT_PNG |
|
5952 default: |
|
5953 icon.addPixmap(proxy()->standardPixmap(standardIcon, option, widget)); |
|
5954 break; |
|
5955 } |
|
5956 return icon; |
|
5957 } |
|
5958 |
|
5959 static inline uint qt_intensity(uint r, uint g, uint b) |
|
5960 { |
|
5961 // 30% red, 59% green, 11% blue |
|
5962 return (77 * r + 150 * g + 28 * b) / 255; |
|
5963 } |
|
5964 |
|
5965 /*! \reimp */ |
|
5966 QPixmap QCommonStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, |
|
5967 const QStyleOption *opt) const |
|
5968 { |
|
5969 switch (iconMode) { |
|
5970 case QIcon::Disabled: { |
|
5971 QImage im = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); |
|
5972 |
|
5973 // Create a colortable based on the background (black -> bg -> white) |
|
5974 QColor bg = opt->palette.color(QPalette::Disabled, QPalette::Window); |
|
5975 int red = bg.red(); |
|
5976 int green = bg.green(); |
|
5977 int blue = bg.blue(); |
|
5978 uchar reds[256], greens[256], blues[256]; |
|
5979 for (int i=0; i<128; ++i) { |
|
5980 reds[i] = uchar((red * (i<<1)) >> 8); |
|
5981 greens[i] = uchar((green * (i<<1)) >> 8); |
|
5982 blues[i] = uchar((blue * (i<<1)) >> 8); |
|
5983 } |
|
5984 for (int i=0; i<128; ++i) { |
|
5985 reds[i+128] = uchar(qMin(red + (i << 1), 255)); |
|
5986 greens[i+128] = uchar(qMin(green + (i << 1), 255)); |
|
5987 blues[i+128] = uchar(qMin(blue + (i << 1), 255)); |
|
5988 } |
|
5989 |
|
5990 int intensity = qt_intensity(red, green, blue); |
|
5991 const int factor = 191; |
|
5992 |
|
5993 // High intensity colors needs dark shifting in the color table, while |
|
5994 // low intensity colors needs light shifting. This is to increase the |
|
5995 // percieved contrast. |
|
5996 if ((red - factor > green && red - factor > blue) |
|
5997 || (green - factor > red && green - factor > blue) |
|
5998 || (blue - factor > red && blue - factor > green)) |
|
5999 intensity = qMin(255, intensity + 91); |
|
6000 else if (intensity <= 128) |
|
6001 intensity -= 51; |
|
6002 |
|
6003 for (int y=0; y<im.height(); ++y) { |
|
6004 QRgb *scanLine = (QRgb*)im.scanLine(y); |
|
6005 for (int x=0; x<im.width(); ++x) { |
|
6006 QRgb pixel = *scanLine; |
|
6007 // Calculate color table index, taking intensity adjustment |
|
6008 // and a magic offset into account. |
|
6009 uint ci = uint(qGray(pixel)/3 + (130 - intensity / 3)); |
|
6010 *scanLine = qRgba(reds[ci], greens[ci], blues[ci], qAlpha(pixel)); |
|
6011 ++scanLine; |
|
6012 } |
|
6013 } |
|
6014 |
|
6015 return QPixmap::fromImage(im); |
|
6016 } |
|
6017 case QIcon::Selected: { |
|
6018 QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied); |
|
6019 QColor color = opt->palette.color(QPalette::Normal, QPalette::Highlight); |
|
6020 color.setAlphaF(qreal(0.3)); |
|
6021 QPainter painter(&img); |
|
6022 painter.setCompositionMode(QPainter::CompositionMode_SourceAtop); |
|
6023 painter.fillRect(0, 0, img.width(), img.height(), color); |
|
6024 painter.end(); |
|
6025 return QPixmap::fromImage(img); } |
|
6026 case QIcon::Active: |
|
6027 return pixmap; |
|
6028 default: |
|
6029 break; |
|
6030 } |
|
6031 return pixmap; |
|
6032 } |
|
6033 |
|
6034 /*! |
|
6035 \reimp |
|
6036 */ |
|
6037 void QCommonStyle::polish(QPalette &pal) |
|
6038 { |
|
6039 QStyle::polish(pal); |
|
6040 } |
|
6041 |
|
6042 /*! |
|
6043 \reimp |
|
6044 */ |
|
6045 void QCommonStyle::polish(QWidget *widget) |
|
6046 { |
|
6047 QStyle::polish(widget); |
|
6048 } |
|
6049 |
|
6050 /*! |
|
6051 \reimp |
|
6052 */ |
|
6053 void QCommonStyle::unpolish(QWidget *widget) |
|
6054 { |
|
6055 QStyle::unpolish(widget); |
|
6056 } |
|
6057 |
|
6058 /*! |
|
6059 \reimp |
|
6060 */ |
|
6061 void QCommonStyle::polish(QApplication *app) |
|
6062 { |
|
6063 QStyle::polish(app); |
|
6064 } |
|
6065 |
|
6066 /*! |
|
6067 \reimp |
|
6068 */ |
|
6069 void QCommonStyle::unpolish(QApplication *application) |
|
6070 { |
|
6071 Q_D(const QCommonStyle); |
|
6072 d->tabBarcloseButtonIcon = QIcon(); |
|
6073 QStyle::unpolish(application); |
|
6074 } |
|
6075 |
|
6076 |
|
6077 QT_END_NAMESPACE |