styles/qwindowsstyle.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight }; -
12 -
13 -
14 -
15 -
16QWindowsStylePrivate::QWindowsStylePrivate() -
17 : alt_down(false), menuBarTimer(0) -
18{ -
19 -
20 -
21 -
22 -
23 -
24 -
25 -
26}
-
27 -
28 -
29bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const -
30{ -
31 widget = widget->window(); -
32 return seenAlt.contains(widget);
-
33} -
34 -
35 -
36 -
37 -
38bool QWindowsStyle::eventFilter(QObject *o, QEvent *e) -
39{ -
40 -
41 if (!o->isWidgetType())
-
42 return QObject::eventFilter(o, e);
-
43 -
44 QWidget *widget = qobject_cast<QWidget*>(o); -
45 QWindowsStylePrivate * const d = d_func(); -
46 switch(e->type()) { -
47 case QEvent::KeyPress: -
48 if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt) {
-
49 widget = widget->window(); -
50 -
51 -
52 QList<QWidget *> l = widget->findChildren<QWidget *>(); -
53 for (int pos=0 ; pos < l.size() ; ++pos) {
-
54 QWidget *w = l.at(pos); -
55 if (w->isWindow() || !w->isVisible() ||
-
56 w->style()->styleHint(SH_UnderlineShortcut, 0, w))
-
57 l.removeAt(pos);
-
58 }
-
59 -
60 d->seenAlt.append(widget); -
61 d->alt_down = true; -
62 -
63 -
64 for (int pos = 0; pos < l.size(); ++pos)
-
65 l.at(pos)->update();
-
66 }
-
67 break;
-
68 case QEvent::KeyRelease: -
69 if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) {
-
70 widget = widget->window(); -
71 -
72 -
73 d->alt_down = false; -
74 -
75 QList<QMenuBar *> l = widget->findChildren<QMenuBar *>(); -
76 for (int i = 0; i < l.size(); ++i)
-
77 l.at(i)->update();
-
78 -
79 }
-
80 break;
-
81 case QEvent::Close: -
82 -
83 d->seenAlt.removeAll(widget); -
84 d->seenAlt.removeAll(widget->window()); -
85 break;
-
86 default: -
87 break;
-
88 } -
89 return QCommonStyle::eventFilter(o, e);
-
90} -
91QWindowsStyle::QWindowsStyle() : QCommonStyle(*new QWindowsStylePrivate) -
92{ -
93}
-
94 -
95 -
96 -
97 -
98 -
99 -
100QWindowsStyle::QWindowsStyle(QWindowsStylePrivate &dd) : QCommonStyle(dd) -
101{ -
102}
-
103 -
104 -
105 -
106QWindowsStyle::~QWindowsStyle() -
107{ -
108} -
109void QWindowsStyle::polish(QApplication *app) -
110{ -
111 QCommonStyle::polish(app); -
112 QWindowsStylePrivate *d = const_cast<QWindowsStylePrivate*>(d_func()); -
113 -
114 if (!proxy()->styleHint(SH_UnderlineShortcut, 0) && app)
-
115 app->installEventFilter(this);
-
116 -
117 d->activeCaptionColor = app->palette().highlight().color(); -
118 d->activeGradientCaptionColor = app->palette().highlight() .color(); -
119 d->inactiveCaptionColor = app->palette().dark().color(); -
120 d->inactiveGradientCaptionColor = app->palette().dark().color(); -
121 d->inactiveCaptionText = app->palette().background().color(); -
122}
-
123 -
124 -
125void QWindowsStyle::unpolish(QApplication *app) -
126{ -
127 QCommonStyle::unpolish(app); -
128 app->removeEventFilter(this); -
129}
-
130 -
131 -
132void QWindowsStyle::polish(QWidget *widget) -
133{ -
134 QCommonStyle::polish(widget); -
135}
-
136 -
137 -
138void QWindowsStyle::unpolish(QWidget *widget) -
139{ -
140 QCommonStyle::unpolish(widget); -
141}
-
142 -
143 -
144 -
145 -
146void QWindowsStyle::polish(QPalette &pal) -
147{ -
148 QCommonStyle::polish(pal); -
149}
-
150 -
151 -
152 -
153 -
154int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const -
155{ -
156 int ret; -
157 -
158 switch (pm) { -
159 case PM_ButtonDefaultIndicator: -
160 case PM_ButtonShiftHorizontal: -
161 case PM_ButtonShiftVertical: -
162 case PM_MenuHMargin: -
163 case PM_MenuVMargin: -
164 ret = 1; -
165 break;
-
166 case PM_DockWidgetSeparatorExtent: -
167 ret = int(QStyleHelper::dpiScaled(4.)); -
168 break;
-
169 -
170 case PM_TabBarTabShiftHorizontal: -
171 ret = 0; -
172 break;
-
173 case PM_TabBarTabShiftVertical: -
174 ret = 2; -
175 break;
-
176 -
177 case PM_MaximumDragDistance: -
178 ret = QCommonStyle::pixelMetric(PM_MaximumDragDistance); -
179 if (ret == -1)
-
180 ret = 60;
-
181 break;
-
182 -
183 -
184 case PM_SliderLength: -
185 ret = int(QStyleHelper::dpiScaled(11.)); -
186 break;
-
187 -
188 -
189 -
190 -
191 case PM_SliderControlThickness: -
192 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
-
193 int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
-
194 int ticks = sl->tickPosition; -
195 int n = 0; -
196 if (ticks & QSlider::TicksAbove)
-
197 ++n;
-
198 if (ticks & QSlider::TicksBelow)
-
199 ++n;
-
200 if (!n) {
-
201 ret = space; -
202 break;
-
203 } -
204 -
205 int thick = 6; -
206 if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)
-
207 thick += proxy()->pixelMetric(PM_SliderLength, sl, widget) / 4;
-
208 -
209 space -= thick; -
210 if (space > 0)
-
211 thick += (space * 2) / (n + 2);
-
212 ret = thick; -
213 } else {
-
214 ret = 0; -
215 }
-
216 break;
-
217 -
218 -
219 -
220 case PM_MenuBarHMargin: -
221 ret = 0; -
222 break;
-
223 -
224 case PM_MenuBarVMargin: -
225 ret = 0; -
226 break;
-
227 -
228 case PM_MenuBarPanelWidth: -
229 ret = 0; -
230 break;
-
231 -
232 case PM_SmallIconSize: -
233 ret = int(QStyleHelper::dpiScaled(16.)); -
234 break;
-
235 -
236 case PM_LargeIconSize: -
237 ret = int(QStyleHelper::dpiScaled(32.)); -
238 break;
-
239 -
240 case PM_IconViewIconSize: -
241 ret = proxy()->pixelMetric(PM_LargeIconSize, opt, widget); -
242 break;
-
243 -
244 case PM_DockWidgetTitleMargin: -
245 ret = int(QStyleHelper::dpiScaled(2.)); -
246 break;
-
247 case PM_DockWidgetTitleBarButtonMargin: -
248 ret = int(QStyleHelper::dpiScaled(4.)); -
249 break;
-
250 case PM_DockWidgetFrameWidth: -
251 ret = 4; -
252 break;
-
253 -
254 break;
dead code: break;
-
255 case PM_SplitterWidth: -
256 ret = qMax(4, QApplication::globalStrut().width()); -
257 break;
-
258 case PM_ToolBarItemMargin: -
259 ret = 1; -
260 break;
-
261 case PM_ToolBarItemSpacing: -
262 ret = 0; -
263 break;
-
264 case PM_ToolBarHandleExtent: -
265 ret = int(QStyleHelper::dpiScaled(10.)); -
266 break;
-
267 default: -
268 ret = QCommonStyle::pixelMetric(pm, opt, widget); -
269 break;
-
270 } -
271 -
272 return ret;
-
273} -
274 -
275 -
276 -
277 -
278QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, -
279 const QWidget *widget) const -
280{ -
281 return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
-
282} -
283 -
284 -
285int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget, -
286 QStyleHintReturn *returnData) const -
287{ -
288 int ret = 0; -
289 -
290 switch (hint) { -
291 case SH_EtchDisabledText: -
292 case SH_Slider_SnapToValue: -
293 case SH_PrintDialog_RightAlignButtons: -
294 case SH_FontDialog_SelectAssociatedText: -
295 case SH_Menu_AllowActiveAndDisabled: -
296 case SH_MenuBar_AltKeyNavigation: -
297 case SH_MenuBar_MouseTracking: -
298 case SH_Menu_MouseTracking: -
299 case SH_ComboBox_ListMouseTracking: -
300 case SH_ScrollBar_StopMouseOverSlider: -
301 case SH_MainWindow_SpaceBelowMenuBar: -
302 ret = 1; -
303 -
304 break;
-
305 case SH_ItemView_ShowDecorationSelected: -
306 -
307 if (qobject_cast<const QListView*>(widget))
-
308 ret = 1;
-
309 -
310 break;
-
311 case SH_ItemView_ChangeHighlightOnFocus: -
312 ret = 1; -
313 break;
-
314 case SH_ToolBox_SelectedPageTitleBold: -
315 ret = 0; -
316 break;
-
317 case SH_RubberBand_Mask: -
318 if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
-
319 ret = 0; -
320 if (rbOpt->shape == QRubberBand::Rectangle) {
-
321 ret = true; -
322 if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) {
-
323 mask->region = opt->rect; -
324 int size = 1; -
325 if (widget && widget->isWindow())
-
326 size = 4;
-
327 mask->region -= opt->rect.adjusted(size, size, -size, -size); -
328 }
-
329 }
-
330 }
-
331 break;
-
332 -
333 case SH_LineEdit_PasswordCharacter: -
334 { -
335 if (!ret)
-
336 ret = '*';
-
337 } -
338 break;
-
339 -
340 case SH_WizardStyle: -
341 ret = QWizard::ModernStyle; -
342 break;
-
343 -
344 case SH_ItemView_ArrowKeysNavigateIntoChildren: -
345 ret = true; -
346 break;
-
347 case SH_DialogButtonBox_ButtonsHaveIcons: -
348 ret = 0; -
349 break;
-
350 default: -
351 ret = QCommonStyle::styleHint(hint, opt, widget, returnData); -
352 break;
-
353 } -
354 return ret;
-
355} -
356 -
357 -
358void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, -
359 const QWidget *w) const -
360{ -
361 -
362 bool doRestore = false; -
363 -
364 switch (pe) { -
365 -
366 case PE_IndicatorToolBarSeparator: -
367 { -
368 QRect rect = opt->rect; -
369 const int margin = 2; -
370 QPen oldPen = p->pen(); -
371 if(opt->state & State_Horizontal){
-
372 const int offset = rect.width()/2; -
373 p->setPen(QPen(opt->palette.dark().color())); -
374 p->drawLine(rect.bottomLeft().x() + offset, -
375 rect.bottomLeft().y() - margin, -
376 rect.topLeft().x() + offset, -
377 rect.topLeft().y() + margin); -
378 p->setPen(QPen(opt->palette.light().color())); -
379 p->drawLine(rect.bottomLeft().x() + offset + 1, -
380 rect.bottomLeft().y() - margin, -
381 rect.topLeft().x() + offset + 1, -
382 rect.topLeft().y() + margin); -
383 }
-
384 else{ -
385 const int offset = rect.height()/2; -
386 p->setPen(QPen(opt->palette.dark().color())); -
387 p->drawLine(rect.topLeft().x() + margin , -
388 rect.topLeft().y() + offset, -
389 rect.topRight().x() - margin, -
390 rect.topRight().y() + offset); -
391 p->setPen(QPen(opt->palette.light().color())); -
392 p->drawLine(rect.topLeft().x() + margin , -
393 rect.topLeft().y() + offset + 1, -
394 rect.topRight().x() - margin, -
395 rect.topRight().y() + offset + 1); -
396 }
-
397 p->setPen(oldPen); -
398 } -
399 break;
-
400 case PE_IndicatorToolBarHandle: -
401 p->save(); -
402 p->translate(opt->rect.x(), opt->rect.y()); -
403 if (opt->state & State_Horizontal) {
-
404 int x = opt->rect.width() / 2 - 4; -
405 if (opt->direction == Qt::RightToLeft)
-
406 x -= 2;
-
407 if (opt->rect.height() > 4) {
-
408 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4, -
409 opt->palette, false, 1, 0); -
410 qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4, -
411 opt->palette, false, 1, 0); -
412 }
-
413 } else {
-
414 if (opt->rect.width() > 4) {
-
415 int y = opt->rect.height() / 2 - 4; -
416 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3, -
417 opt->palette, false, 1, 0); -
418 qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3, -
419 opt->palette, false, 1, 0); -
420 }
-
421 }
-
422 p->restore(); -
423 break;
-
424 -
425 -
426 case PE_FrameButtonTool: -
427 case PE_PanelButtonTool: { -
428 QPen oldPen = p->pen(); -
429 -
430 if (w && w->inherits("QDockWidgetTitleButton")) {
-
431 if (const QWidget *dw = w->parentWidget())
-
432 if (dw->isWindow()){
-
433 qDrawWinButton(p, opt->rect.adjusted(1, 1, 0, 0), opt->palette, opt->state & (State_Sunken | State_On), -
434 &opt->palette.button()); -
435 -
436 return;
-
437 } -
438 }
-
439 -
440 QBrush fill; -
441 bool stippled; -
442 bool panel = (pe == PE_PanelButtonTool); -
443 if ((!(opt->state & State_Sunken ))
-
444 && (!(opt->state & State_Enabled)
-
445 || !(opt->state & State_MouseOver && opt->state & State_AutoRaise))
-
446 && (opt->state & State_On)) {
-
447 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern); -
448 stippled = true; -
449 } else {
-
450 fill = opt->palette.brush(QPalette::Button); -
451 stippled = false; -
452 }
-
453 -
454 if (opt->state & (State_Raised | State_Sunken | State_On)) {
-
455 if (opt->state & State_AutoRaise) {
-
456 if(opt->state & (State_Enabled | State_Sunken | State_On)){
-
457 if (panel)
-
458 qDrawShadePanel(p, opt->rect, opt->palette, -
459 opt->state & (State_Sunken | State_On), 1, &fill);
-
460 else -
461 qDrawShadeRect(p, opt->rect, opt->palette, -
462 opt->state & (State_Sunken | State_On), 1);
-
463 } -
464 if (stippled) {
-
465 p->setPen(opt->palette.button().color()); -
466 p->drawRect(opt->rect.adjusted(1,1,-2,-2)); -
467 }
-
468 } else {
-
469 qDrawWinButton(p, opt->rect, opt->palette, -
470 opt->state & (State_Sunken | State_On), panel ? &fill : 0); -
471 }
-
472 } else { -
473 p->fillRect(opt->rect, fill); -
474 }
-
475 p->setPen(oldPen); -
476 break; }
-
477 case PE_PanelButtonCommand: -
478 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
-
479 QBrush fill; -
480 State flags = opt->state; -
481 QPalette pal = opt->palette; -
482 QRect r = opt->rect; -
483 if (! (flags & State_Sunken) && (flags & State_On))
-
484 fill = QBrush(pal.light().color(), Qt::Dense4Pattern);
-
485 else -
486 fill = pal.brush(QPalette::Button);
-
487 -
488 if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {
-
489 p->setPen(pal.dark().color()); -
490 p->setBrush(fill); -
491 p->drawRect(r.adjusted(0, 0, -1, -1)); -
492 } else if (flags & (State_Raised | State_On | State_Sunken)) {
-
493 qDrawWinButton(p, r, pal, flags & (State_Sunken | State_On), -
494 &fill); -
495 } else {
-
496 p->fillRect(r, fill); -
497 }
-
498 } -
499 break;
-
500 case PE_FrameDefaultButton: { -
501 QPen oldPen = p->pen(); -
502 p->setPen(opt->palette.shadow().color()); -
503 QRect rect = opt->rect; -
504 rect.adjust(0, 0, -1, -1); -
505 p->drawRect(rect); -
506 p->setPen(oldPen); -
507 break;
-
508 } -
509 case PE_IndicatorCheckBox: { -
510 QBrush fill; -
511 if (opt->state & State_NoChange)
-
512 fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern);
-
513 else if (opt->state & State_Sunken)
-
514 fill = opt->palette.button();
-
515 else if (opt->state & State_Enabled)
-
516 fill = opt->palette.base();
-
517 else -
518 fill = opt->palette.background();
-
519 p->save(); -
520 doRestore = true; -
521 qDrawWinPanel(p, opt->rect, opt->palette, true, &fill); -
522 if (opt->state & State_NoChange)
-
523 p->setPen(opt->palette.dark().color());
-
524 else -
525 p->setPen(opt->palette.text().color());
-
526 } -
527 case PE_IndicatorViewItemCheck:
-
528 if (!doRestore) {
-
529 p->save(); -
530 doRestore = true; -
531 }
-
532 if (pe == PE_IndicatorViewItemCheck) {
-
533 const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt); -
534 p->setPen(itemViewOpt -
535 && itemViewOpt->showDecorationSelected -
536 && opt->state & State_Selected -
537 ? opt->palette.highlightedText().color() -
538 : opt->palette.text().color()); -
539 if (opt->state & State_NoChange)
-
540 p->setBrush(opt->palette.brush(QPalette::Button));
-
541 p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11); -
542 }
-
543 if (!(opt->state & State_Off)) {
-
544 QLineF lines[7]; -
545 int i, xx, yy; -
546 xx = opt->rect.x() + 3; -
547 yy = opt->rect.y() + 5; -
548 for (i = 0; i < 3; ++i) {
-
549 lines[i] = QLineF(xx, yy, xx, yy + 2); -
550 ++xx; -
551 ++yy; -
552 }
-
553 yy -= 2; -
554 for (i = 3; i < 7; ++i) {
-
555 lines[i] = QLineF(xx, yy, xx, yy + 2); -
556 ++xx; -
557 --yy; -
558 }
-
559 p->drawLines(lines, 7); -
560 }
-
561 if (doRestore)
-
562 p->restore();
-
563 break;
-
564 case PE_FrameFocusRect: -
565 if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
-
566 -
567 if (!(fropt->state & State_KeyboardFocusChange) && !proxy()->styleHint(SH_UnderlineShortcut, opt))
-
568 return;
-
569 QRect r = opt->rect; -
570 p->save(); -
571 p->setBackgroundMode(Qt::TransparentMode); -
572 QColor bg_col = fropt->backgroundColor; -
573 if (!bg_col.isValid())
-
574 bg_col = p->background().color();
-
575 -
576 QColor patternCol((bg_col.red() ^ 0xff) & 0xff, -
577 (bg_col.green() ^ 0xff) & 0xff, -
578 (bg_col.blue() ^ 0xff) & 0xff); -
579 p->setBrush(QBrush(patternCol, Qt::Dense4Pattern)); -
580 p->setBrushOrigin(r.topLeft()); -
581 p->setPen(Qt::NoPen); -
582 p->drawRect(r.left(), r.top(), r.width(), 1); -
583 p->drawRect(r.left(), r.bottom(), r.width(), 1); -
584 p->drawRect(r.left(), r.top(), 1, r.height()); -
585 p->drawRect(r.right(), r.top(), 1, r.height()); -
586 p->restore(); -
587 }
-
588 break;
-
589 case PE_IndicatorRadioButton: -
590 { -
591 -
592 static const QPoint pts1[] = { -
593 QPoint(1, 9), QPoint(1, 8), QPoint(0, 7), QPoint(0, 4), QPoint(1, 3), QPoint(1, 2), -
594 QPoint(2, 1), QPoint(3, 1), QPoint(4, 0), QPoint(7, 0), QPoint(8, 1), QPoint(9, 1) -
595 }; -
596 static const QPoint pts2[] = { -
597 QPoint(2, 8), QPoint(1, 7), QPoint(1, 4), QPoint(2, 3), QPoint(2, 2), QPoint(3, 2), -
598 QPoint(4, 1), QPoint(7, 1), QPoint(8, 2), QPoint(9, 2) -
599 }; -
600 static const QPoint pts3[] = { -
601 QPoint(2, 9), QPoint(3, 9), QPoint(4, 10), QPoint(7, 10), QPoint(8, 9), QPoint(9, 9), -
602 QPoint(9, 8), QPoint(10, 7), QPoint(10, 4), QPoint(9, 3) -
603 }; -
604 static const QPoint pts4[] = { -
605 QPoint(2, 10), QPoint(3, 10), QPoint(4, 11), QPoint(7, 11), QPoint(8, 10), -
606 QPoint(9, 10), QPoint(10, 9), QPoint(10, 8), QPoint(11, 7), QPoint(11, 4), -
607 QPoint(10, 3), QPoint(10, 2) -
608 }; -
609 static const QPoint pts5[] = { -
610 QPoint(4, 2), QPoint(7, 2), QPoint(9, 4), QPoint(9, 7), QPoint(7, 9), QPoint(4, 9), -
611 QPoint(2, 7), QPoint(2, 4) -
612 }; -
613 -
614 -
615 QRect ir = opt->rect; -
616 -
617 if (opt->rect.width() < opt->rect.height()) {
-
618 ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2); -
619 ir.setHeight(opt->rect.width()); -
620 } else if (opt->rect.height() < opt->rect.width()) {
-
621 ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2); -
622 ir.setWidth(opt->rect.height()); -
623 }
-
624 -
625 p->save(); -
626 p->setRenderHint(QPainter::Qt4CompatiblePainting); -
627 bool down = opt->state & State_Sunken; -
628 bool enabled = opt->state & State_Enabled; -
629 bool on = opt->state & State_On; -
630 QPolygon a; -
631 -
632 -
633 int xOffset = 0; -
634 int yOffset = 0; -
635 int indicatorWidth = proxy()->pixelMetric(PM_ExclusiveIndicatorWidth); -
636 int indicatorHeight = proxy()->pixelMetric(PM_ExclusiveIndicatorWidth); -
637 if (ir.width() > indicatorWidth)
-
638 xOffset += (ir.width() - indicatorWidth)/2;
-
639 if (ir.height() > indicatorHeight)
-
640 yOffset += (ir.height() - indicatorHeight)/2;
-
641 p->translate(xOffset, yOffset); -
642 -
643 p->translate(ir.x(), ir.y()); -
644 -
645 p->setPen(opt->palette.dark().color()); -
646 p->drawPolyline(pts1, sizeof(pts1)/(sizeof(QPoint))); -
647 -
648 p->setPen(opt->palette.shadow().color()); -
649 p->drawPolyline(pts2, sizeof(pts2)/(sizeof(QPoint))); -
650 -
651 p->setPen(opt->palette.midlight().color()); -
652 p->drawPolyline(pts3, sizeof(pts3)/(sizeof(QPoint))); -
653 -
654 p->setPen(opt->palette.light().color()); -
655 p->drawPolyline(pts4, sizeof(pts4)/(sizeof(QPoint))); -
656 -
657 QColor fillColor = (down || !enabled)
-
658 ? opt->palette.button().color() -
659 : opt->palette.base().color(); -
660 p->setPen(fillColor); -
661 p->setBrush(fillColor) ; -
662 p->drawPolygon(pts5, sizeof(pts5)/(sizeof(QPoint))); -
663 -
664 p->translate(-ir.x(), -ir.y()); -
665 -
666 if (on) {
-
667 p->setPen(Qt::NoPen); -
668 p->setBrush(opt->palette.text()); -
669 p->drawRect(ir.x() + 5, ir.y() + 4, 2, 4); -
670 p->drawRect(ir.x() + 4, ir.y() + 5, 4, 2); -
671 }
-
672 p->restore(); -
673 break;
-
674 } -
675 -
676 case PE_Frame: -
677 case PE_FrameMenu: -
678 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
-
679 if (frame->lineWidth == 2 || pe == PE_Frame) {
-
680 QPalette popupPal = frame->palette; -
681 if (pe == PE_FrameMenu) {
-
682 popupPal.setColor(QPalette::Light, frame->palette.background().color()); -
683 popupPal.setColor(QPalette::Midlight, frame->palette.light().color()); -
684 }
-
685 if (pe == PE_Frame && (frame->state & State_Raised))
-
686 qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken);
-
687 else if (pe == PE_Frame && (frame->state & State_Sunken))
-
688 { -
689 popupPal.setColor(QPalette::Midlight, frame->palette.background().color()); -
690 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken); -
691 }
-
692 else -
693 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
-
694 } else { -
695 QCommonStyle::drawPrimitive(pe, opt, p, w); -
696 }
-
697 } else { -
698 QPalette popupPal = opt->palette; -
699 popupPal.setColor(QPalette::Light, opt->palette.background().color()); -
700 popupPal.setColor(QPalette::Midlight, opt->palette.light().color()); -
701 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken); -
702 }
-
703 break;
-
704 -
705 case PE_FrameButtonBevel: -
706 case PE_PanelButtonBevel: { -
707 QBrush fill; -
708 bool panel = pe != PE_FrameButtonBevel; -
709 p->setBrushOrigin(opt->rect.topLeft()); -
710 if (!(opt->state & State_Sunken) && (opt->state & State_On))
-
711 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
-
712 else -
713 fill = opt->palette.brush(QPalette::Button);
-
714 -
715 if (opt->state & (State_Raised | State_On | State_Sunken)) {
-
716 qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On), -
717 panel ? &fill : 0); -
718 } else {
-
719 if (panel)
-
720 p->fillRect(opt->rect, fill);
-
721 else -
722 p->drawRect(opt->rect);
-
723 } -
724 break; }
-
725 case PE_FrameWindow: { -
726 QPalette popupPal = opt->palette; -
727 popupPal.setColor(QPalette::Light, opt->palette.background().color()); -
728 popupPal.setColor(QPalette::Midlight, opt->palette.light().color()); -
729 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken); -
730 break; }
-
731 -
732 case PE_IndicatorDockWidgetResizeHandle: -
733 break;
-
734 case PE_FrameDockWidget: -
735 if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
-
736 proxy()->drawPrimitive(QStyle::PE_FrameWindow, opt, p, w); -
737 }
-
738 break;
-
739 -
740 -
741 case PE_FrameStatusBarItem: -
742 qDrawShadePanel(p, opt->rect, opt->palette, true, 1, 0); -
743 break;
-
744 -
745 case PE_IndicatorProgressChunk: -
746 { -
747 bool vertical = false, inverted = false; -
748 if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) {
-
749 vertical = (pb2->orientation == Qt::Vertical); -
750 inverted = pb2->invertedAppearance; -
751 }
-
752 -
753 int space = 2; -
754 int chunksize = proxy()->pixelMetric(PM_ProgressBarChunkWidth, opt, w) - space; -
755 if (!vertical) {
-
756 if (opt->rect.width() <= chunksize)
-
757 space = 0;
-
758 -
759 if (inverted)
-
760 p->fillRect(opt->rect.x() + space, opt->rect.y(), opt->rect.width() - space, opt->rect.height(), -
761 opt->palette.brush(QPalette::Highlight));
-
762 else -
763 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width() - space, opt->rect.height(), -
764 opt->palette.brush(QPalette::Highlight));
-
765 } else { -
766 if (opt->rect.height() <= chunksize)
-
767 space = 0;
-
768 -
769 if (inverted)
-
770 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height() - space, -
771 opt->palette.brush(QPalette::Highlight));
-
772 else -
773 p->fillRect(opt->rect.x(), opt->rect.y() + space, opt->rect.width(), opt->rect.height() - space, -
774 opt->palette.brush(QPalette::Highlight));
-
775 } -
776 } -
777 break;
-
778 -
779 case PE_FrameTabWidget: { -
780 qDrawWinButton(p, opt->rect, opt->palette, false, 0); -
781 break;
-
782 } -
783 default: -
784 QCommonStyle::drawPrimitive(pe, opt, p, w); -
785 }
-
786}
-
787 -
788 -
789void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p, -
790 const QWidget *widget) const -
791{ -
792 switch (ce) { -
793 -
794 case CE_RubberBand: -
795 if (qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
-
796 -
797 QPixmap tiledPixmap(16, 16); -
798 QPainter pixmapPainter(&tiledPixmap); -
799 pixmapPainter.setPen(Qt::NoPen); -
800 pixmapPainter.setBrush(Qt::Dense4Pattern); -
801 pixmapPainter.setBackground(Qt::white); -
802 pixmapPainter.setBackgroundMode(Qt::OpaqueMode); -
803 pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height()); -
804 pixmapPainter.end(); -
805 tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage()); -
806 p->save(); -
807 QRect r = opt->rect; -
808 QStyleHintReturnMask mask; -
809 if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
-
810 p->setClipRegion(mask.region);
-
811 p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap); -
812 p->restore(); -
813 return;
-
814 } -
815 break;
-
816 -
817 -
818 -
819 case CE_MenuBarEmptyArea: -
820 if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
-
821 p->fillRect(opt->rect, opt->palette.button()); -
822 QPen oldPen = p->pen(); -
823 p->setPen(QPen(opt->palette.dark().color())); -
824 p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight()); -
825 p->setPen(oldPen); -
826 }
-
827 break;
-
828 -
829 -
830 case CE_MenuItem: -
831 if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
-
832 int x, y, w, h; -
833 menuitem->rect.getRect(&x, &y, &w, &h); -
834 int tab = menuitem->tabWidth; -
835 bool dis = !(menuitem->state & State_Enabled); -
836 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
-
837 ? menuitem->checked : false; -
838 bool act = menuitem->state & State_Selected; -
839 -
840 -
841 int checkcol = qMax<int>(menuitem->maxIconWidth, QWindowsStylePrivate::windowsCheckMarkWidth); -
842 -
843 QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button); -
844 p->fillRect(menuitem->rect.adjusted(0, 0, -1, 0), fill); -
845 -
846 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){
-
847 int yoff = y-1 + h / 2; -
848 p->setPen(menuitem->palette.dark().color()); -
849 p->drawLine(x + 2, yoff, x + w - 4, yoff); -
850 p->setPen(menuitem->palette.light().color()); -
851 p->drawLine(x + 2, yoff + 1, x + w - 4, yoff + 1); -
852 return;
-
853 } -
854 -
855 QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height())); -
856 if (!menuitem->icon.isNull() && checked) {
-
857 if (act) {
-
858 qDrawShadePanel(p, vCheckRect, -
859 menuitem->palette, true, 1, -
860 &menuitem->palette.brush(QPalette::Button)); -
861 } else {
-
862 QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern); -
863 qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill); -
864 }
-
865 } else if (!act) {
-
866 p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button)); -
867 }
-
868 -
869 -
870 -
871 -
872 if (!menuitem->icon.isNull()) {
-
873 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
-
874 if (act && !dis)
-
875 mode = QIcon::Active;
-
876 QPixmap pixmap; -
877 if (checked)
-
878 pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode, QIcon::On);
-
879 else -
880 pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode);
-
881 int pixw = pixmap.width(); -
882 int pixh = pixmap.height(); -
883 if (act && !dis && !checked)
-
884 qDrawShadePanel(p, vCheckRect, menuitem->palette, false, 1, -
885 &menuitem->palette.brush(QPalette::Button));
-
886 QRect pmr(0, 0, pixw, pixh); -
887 pmr.moveCenter(vCheckRect.center()); -
888 p->setPen(menuitem->palette.text().color()); -
889 p->drawPixmap(pmr.topLeft(), pixmap); -
890 } else if (checked) {
-
891 QStyleOptionMenuItem newMi = *menuitem; -
892 newMi.state = State_None; -
893 if (!dis)
-
894 newMi.state |= State_Enabled;
-
895 if (act)
-
896 newMi.state |= State_On;
-
897 newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + QWindowsStylePrivate::windowsItemFrame, -
898 menuitem->rect.y() + QWindowsStylePrivate::windowsItemFrame, -
899 checkcol - 2 * QWindowsStylePrivate::windowsItemFrame, -
900 menuitem->rect.height() - 2 * QWindowsStylePrivate::windowsItemFrame)); -
901 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget); -
902 }
-
903 p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color()); -
904 -
905 QColor discol; -
906 if (dis) {
-
907 discol = menuitem->palette.text().color(); -
908 p->setPen(discol); -
909 }
-
910 -
911 int xm = int(QWindowsStylePrivate::windowsItemFrame) + checkcol + int(QWindowsStylePrivate::windowsItemHMargin); -
912 int xpos = menuitem->rect.x() + xm; -
913 QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin, -
914 w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin); -
915 QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect); -
916 QString s = menuitem->text; -
917 if (!s.isEmpty()) {
-
918 p->save(); -
919 int t = s.indexOf(QLatin1Char('\t')); -
920 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; -
921 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
-
922 text_flags |= Qt::TextHideMnemonic;
-
923 text_flags |= Qt::AlignLeft; -
924 if (t >= 0) {
-
925 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect, -
926 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom()))); -
927 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
-
928 p->setPen(menuitem->palette.light().color()); -
929 p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1)); -
930 p->setPen(discol); -
931 }
-
932 p->drawText(vShortcutRect, text_flags, s.mid(t + 1)); -
933 s = s.left(t); -
934 }
-
935 QFont font = menuitem->font; -
936 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
-
937 font.setBold(true);
-
938 p->setFont(font); -
939 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
-
940 p->setPen(menuitem->palette.light().color()); -
941 p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t)); -
942 p->setPen(discol); -
943 }
-
944 p->drawText(vTextRect, text_flags, s.left(t)); -
945 p->restore(); -
946 }
-
947 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {
-
948 int dim = (h - 2 * QWindowsStylePrivate::windowsItemFrame) / 2; -
949 PrimitiveElement arrow; -
950 arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
-
951 xpos = x + w - QWindowsStylePrivate::windowsArrowHMargin - QWindowsStylePrivate::windowsItemFrame - dim; -
952 QRect vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim)); -
953 QStyleOptionMenuItem newMI = *menuitem; -
954 newMI.rect = vSubMenuRect; -
955 newMI.state = dis ? State_None : State_Enabled;
-
956 if (act)
-
957 newMI.palette.setColor(QPalette::ButtonText, -
958 newMI.palette.highlightedText().color());
-
959 proxy()->drawPrimitive(arrow, &newMI, p, widget); -
960 }
-
961 -
962 }
-
963 break;
-
964 -
965 -
966 case CE_MenuBarItem: -
967 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
-
968 bool active = mbi->state & State_Selected; -
969 bool hasFocus = mbi->state & State_HasFocus; -
970 bool down = mbi->state & State_Sunken; -
971 QStyleOptionMenuItem newMbi = *mbi; -
972 p->fillRect(mbi->rect, mbi->palette.brush(QPalette::Button)); -
973 if (active || hasFocus) {
-
974 QBrush b = mbi->palette.brush(QPalette::Button); -
975 if (active && down)
-
976 p->setBrushOrigin(p->brushOrigin() + QPoint(1, 1));
-
977 if (active && hasFocus)
-
978 qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(), -
979 mbi->rect.height(), mbi->palette, active && down, 1, 0, &b);
-
980 if (active && down) {
-
981 newMbi.rect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, mbi, widget), -
982 proxy()->pixelMetric(PM_ButtonShiftVertical, mbi, widget)); -
983 p->setBrushOrigin(p->brushOrigin() - QPoint(1, 1)); -
984 }
-
985 }
-
986 QCommonStyle::drawControl(ce, &newMbi, p, widget); -
987 }
-
988 break;
-
989 -
990 -
991 case CE_TabBarTabShape: -
992 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
-
993 bool rtlHorTabs = (tab->direction == Qt::RightToLeft
-
994 && (tab->shape == QTabBar::RoundedNorth
-
995 || tab->shape == QTabBar::RoundedSouth));
-
996 bool selected = tab->state & State_Selected; -
997 bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
-
998 || (rtlHorTabs
-
999 && tab->position == QStyleOptionTab::Beginning));
-
1000 bool firstTab = ((!rtlHorTabs
-
1001 && tab->position == QStyleOptionTab::Beginning)
-
1002 || (rtlHorTabs
-
1003 && tab->position == QStyleOptionTab::End));
-
1004 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab; -
1005 bool previousSelected = -
1006 ((!rtlHorTabs
-
1007 && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
-
1008 || (rtlHorTabs
-
1009 && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
-
1010 bool nextSelected = -
1011 ((!rtlHorTabs
-
1012 && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
-
1013 || (rtlHorTabs
-
1014 && tab->selectedPosition -
1015 == QStyleOptionTab::PreviousIsSelected));
-
1016 int tabBarAlignment = proxy()->styleHint(SH_TabBar_Alignment, tab, widget); -
1017 bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
-
1018 || (rtlHorTabs
-
1019 && tabBarAlignment == Qt::AlignRight);
-
1020 -
1021 bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
-
1022 || (rtlHorTabs
-
1023 && tabBarAlignment == Qt::AlignLeft);
-
1024 -
1025 QColor light = tab->palette.light().color(); -
1026 QColor dark = tab->palette.dark().color(); -
1027 QColor shadow = tab->palette.shadow().color(); -
1028 int borderThinkness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget); -
1029 if (selected)
-
1030 borderThinkness /= 2;
-
1031 QRect r2(opt->rect); -
1032 int x1 = r2.left(); -
1033 int x2 = r2.right(); -
1034 int y1 = r2.top(); -
1035 int y2 = r2.bottom(); -
1036 switch (tab->shape) { -
1037 default: -
1038 QCommonStyle::drawControl(ce, tab, p, widget); -
1039 break;
-
1040 case QTabBar::RoundedNorth: { -
1041 if (!selected) {
-
1042 y1 += 2; -
1043 x1 += onlyOne || firstTab ? borderThinkness : 0;
-
1044 x2 -= onlyOne || lastTab ? borderThinkness : 0;
-
1045 }
-
1046 -
1047 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.background()); -
1048 -
1049 -
1050 if (selected) {
-
1051 p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.background()); -
1052 p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.background()); -
1053 }
-
1054 -
1055 if (firstTab || selected || onlyOne || !previousSelected) {
-
1056 p->setPen(light); -
1057 p->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness)); -
1058 p->drawPoint(x1 + 1, y1 + 1); -
1059 }
-
1060 -
1061 { -
1062 int beg = x1 + (previousSelected ? 0 : 2);
-
1063 int end = x2 - (nextSelected ? 0 : 2);
-
1064 p->setPen(light); -
1065 p->drawLine(beg, y1, end, y1); -
1066 } -
1067 -
1068 if (lastTab || selected || onlyOne || !nextSelected) {
-
1069 p->setPen(shadow); -
1070 p->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness)); -
1071 p->drawPoint(x2 - 1, y1 + 1); -
1072 p->setPen(dark); -
1073 p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness)); -
1074 }
-
1075 break; }
-
1076 case QTabBar::RoundedSouth: { -
1077 if (!selected) {
-
1078 y2 -= 2; -
1079 x1 += firstTab ? borderThinkness : 0;
-
1080 x2 -= lastTab ? borderThinkness : 0;
-
1081 }
-
1082 -
1083 p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background()); -
1084 -
1085 -
1086 if (selected) {
-
1087 p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.background()); -
1088 p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.background()); -
1089 }
-
1090 -
1091 if (firstTab || selected || onlyOne || !previousSelected) {
-
1092 p->setPen(light); -
1093 p->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness)); -
1094 p->drawPoint(x1 + 1, y2 - 1); -
1095 }
-
1096 -
1097 { -
1098 int beg = x1 + (previousSelected ? 0 : 2);
-
1099 int end = x2 - (nextSelected ? 0 : 2);
-
1100 p->setPen(shadow); -
1101 p->drawLine(beg, y2, end, y2); -
1102 p->setPen(dark); -
1103 p->drawLine(beg, y2 - 1, end, y2 - 1); -
1104 } -
1105 -
1106 if (lastTab || selected || onlyOne || !nextSelected) {
-
1107 p->setPen(shadow); -
1108 p->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness)); -
1109 p->drawPoint(x2 - 1, y2 - 1); -
1110 p->setPen(dark); -
1111 p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness)); -
1112 }
-
1113 break; }
-
1114 case QTabBar::RoundedWest: { -
1115 if (!selected) {
-
1116 x1 += 2; -
1117 y1 += firstTab ? borderThinkness : 0;
-
1118 y2 -= lastTab ? borderThinkness : 0;
-
1119 }
-
1120 -
1121 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.background()); -
1122 -
1123 -
1124 if (selected) {
-
1125 p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.background()); -
1126 p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.background()); -
1127 }
-
1128 -
1129 if (firstTab || selected || onlyOne || !previousSelected) {
-
1130 p->setPen(light); -
1131 p->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1); -
1132 p->drawPoint(x1 + 1, y1 + 1); -
1133 }
-
1134 -
1135 { -
1136 int beg = y1 + (previousSelected ? 0 : 2);
-
1137 int end = y2 - (nextSelected ? 0 : 2);
-
1138 p->setPen(light); -
1139 p->drawLine(x1, beg, x1, end); -
1140 } -
1141 -
1142 if (lastTab || selected || onlyOne || !nextSelected) {
-
1143 p->setPen(shadow); -
1144 p->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2); -
1145 p->drawPoint(x1 + 2, y2 - 1); -
1146 p->setPen(dark); -
1147 p->drawLine(x1 + 3, y2 - 1, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1); -
1148 p->drawPoint(x1 + 1, y2 - 1); -
1149 p->drawPoint(x1 + 2, y2); -
1150 }
-
1151 break; }
-
1152 case QTabBar::RoundedEast: { -
1153 if (!selected) {
-
1154 x2 -= 2; -
1155 y1 += firstTab ? borderThinkness : 0;
-
1156 y2 -= lastTab ? borderThinkness : 0;
-
1157 }
-
1158 -
1159 p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background()); -
1160 -
1161 -
1162 if (selected) {
-
1163 p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.background()); -
1164 p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.background()); -
1165 }
-
1166 -
1167 if (firstTab || selected || onlyOne || !previousSelected) {
-
1168 p->setPen(light); -
1169 p->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1); -
1170 p->drawPoint(x2 - 1, y1 + 1); -
1171 }
-
1172 -
1173 { -
1174 int beg = y1 + (previousSelected ? 0 : 2);
-
1175 int end = y2 - (nextSelected ? 0 : 2);
-
1176 p->setPen(shadow); -
1177 p->drawLine(x2, beg, x2, end); -
1178 p->setPen(dark); -
1179 p->drawLine(x2 - 1, beg, x2 - 1, end); -
1180 } -
1181 -
1182 if (lastTab || selected || onlyOne || !nextSelected) {
-
1183 p->setPen(shadow); -
1184 p->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2); -
1185 p->drawPoint(x2 - 1, y2 - 1); -
1186 p->setPen(dark); -
1187 p->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1); -
1188 }
-
1189 break; }
-
1190 } -
1191 }
-
1192 break;
-
1193 -
1194 case CE_ToolBoxTabShape: -
1195 qDrawShadePanel(p, opt->rect, opt->palette, -
1196 opt->state & (State_Sunken | State_On), 1, -
1197 &opt->palette.brush(QPalette::Button)); -
1198 break;
-
1199 -
1200 case CE_Splitter: -
1201 p->eraseRect(opt->rect); -
1202 break;
-
1203 -
1204 -
1205 case CE_ScrollBarSubLine: -
1206 case CE_ScrollBarAddLine: { -
1207 if ((opt->state & State_Sunken)) {
-
1208 p->setPen(opt->palette.dark().color()); -
1209 p->setBrush(opt->palette.brush(QPalette::Button)); -
1210 p->drawRect(opt->rect.adjusted(0, 0, -1, -1)); -
1211 } else {
-
1212 QStyleOption buttonOpt = *opt; -
1213 if (!(buttonOpt.state & State_Sunken))
-
1214 buttonOpt.state |= State_Raised;
-
1215 QPalette pal(opt->palette); -
1216 pal.setColor(QPalette::Button, opt->palette.light().color()); -
1217 pal.setColor(QPalette::Light, opt->palette.button().color()); -
1218 qDrawWinButton(p, opt->rect, pal, opt->state & (State_Sunken | State_On), -
1219 &opt->palette.brush(QPalette::Button)); -
1220 }
-
1221 PrimitiveElement arrow; -
1222 if (opt->state & State_Horizontal) {
-
1223 if (ce == CE_ScrollBarAddLine)
-
1224 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
-
1225 else -
1226 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
-
1227 } else { -
1228 if (ce == CE_ScrollBarAddLine)
-
1229 arrow = PE_IndicatorArrowDown;
-
1230 else -
1231 arrow = PE_IndicatorArrowUp;
-
1232 } -
1233 QStyleOption arrowOpt = *opt; -
1234 arrowOpt.rect = opt->rect.adjusted(4, 4, -4, -4); -
1235 proxy()->drawPrimitive(arrow, &arrowOpt, p, widget); -
1236 break; }
-
1237 case CE_ScrollBarAddPage: -
1238 case CE_ScrollBarSubPage: { -
1239 QBrush br; -
1240 QBrush bg = p->background(); -
1241 Qt::BGMode bg_mode = p->backgroundMode(); -
1242 p->setPen(Qt::NoPen); -
1243 p->setBackgroundMode(Qt::OpaqueMode); -
1244 -
1245 if (opt->state & State_Sunken) {
-
1246 br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern); -
1247 p->setBackground(opt->palette.dark().color()); -
1248 p->setBrush(br); -
1249 } else {
-
1250 QPixmap pm = opt->palette.brush(QPalette::Light).texture(); -
1251 br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
-
1252 p->setBackground(opt->palette.background().color()); -
1253 p->setBrush(br); -
1254 }
-
1255 p->drawRect(opt->rect); -
1256 p->setBackground(bg); -
1257 p->setBackgroundMode(bg_mode); -
1258 break; }
-
1259 case CE_ScrollBarSlider: -
1260 if (!(opt->state & State_Enabled)) {
-
1261 QPixmap pm = opt->palette.brush(QPalette::Light).texture(); -
1262 QBrush br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
-
1263 p->setPen(Qt::NoPen); -
1264 p->setBrush(br); -
1265 p->setBackgroundMode(Qt::OpaqueMode); -
1266 p->drawRect(opt->rect); -
1267 } else {
-
1268 QStyleOptionButton buttonOpt; -
1269 buttonOpt.QStyleOption::operator=(*opt); -
1270 buttonOpt.state = State_Enabled | State_Raised; -
1271 -
1272 QPalette pal(opt->palette); -
1273 pal.setColor(QPalette::Button, opt->palette.light().color()); -
1274 pal.setColor(QPalette::Light, opt->palette.button().color()); -
1275 qDrawWinButton(p, opt->rect, pal, false, &opt->palette.brush(QPalette::Button)); -
1276 }
-
1277 break;
-
1278 -
1279 case CE_HeaderSection: { -
1280 QBrush fill; -
1281 if (opt->state & State_On)
-
1282 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
-
1283 else -
1284 fill = opt->palette.brush(QPalette::Button);
-
1285 -
1286 if (opt->state & (State_Raised | State_Sunken)) {
-
1287 qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill); -
1288 } else {
-
1289 p->fillRect(opt->rect, fill); -
1290 }
-
1291 break; }
-
1292 -
1293 case CE_ToolBar: -
1294 if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
-
1295 -
1296 if (!(widget && qobject_cast<const QMainWindow*> (widget->parentWidget())))
-
1297 break;
-
1298 -
1299 QRect rect = opt->rect; -
1300 bool paintLeftBorder = true; -
1301 bool paintRightBorder = true; -
1302 bool paintBottomBorder = true; -
1303 -
1304 switch (toolbar->toolBarArea){ -
1305 case Qt::BottomToolBarArea : -
1306 switch(toolbar->positionOfLine){ -
1307 case QStyleOptionToolBar::Beginning: -
1308 case QStyleOptionToolBar::OnlyOne: -
1309 paintBottomBorder = false; -
1310 default: -
1311 break;
-
1312 } -
1313 case Qt::TopToolBarArea :
-
1314 switch(toolbar->positionWithinLine){ -
1315 case QStyleOptionToolBar::Beginning: -
1316 paintLeftBorder = false; -
1317 break;
-
1318 case QStyleOptionToolBar::End: -
1319 paintRightBorder = false; -
1320 break;
-
1321 case QStyleOptionToolBar::OnlyOne: -
1322 paintRightBorder = false; -
1323 paintLeftBorder = false; -
1324 default: -
1325 break;
-
1326 } -
1327 if(opt->direction == Qt::RightToLeft){
-
1328 bool tmp = paintLeftBorder; -
1329 paintRightBorder=paintLeftBorder; -
1330 paintLeftBorder=tmp; -
1331 }
-
1332 break;
-
1333 case Qt::RightToolBarArea : -
1334 switch (toolbar->positionOfLine){ -
1335 case QStyleOptionToolBar::Beginning: -
1336 case QStyleOptionToolBar::OnlyOne: -
1337 paintRightBorder = false; -
1338 break;
-
1339 default: -
1340 break;
-
1341 } -
1342 break;
-
1343 case Qt::LeftToolBarArea : -
1344 switch (toolbar->positionOfLine){ -
1345 case QStyleOptionToolBar::Beginning: -
1346 case QStyleOptionToolBar::OnlyOne: -
1347 paintLeftBorder = false; -
1348 break;
-
1349 default: -
1350 break;
-
1351 } -
1352 break;
-
1353 default: -
1354 break;
-
1355 } -
1356 -
1357 -
1358 -
1359 p->setPen(QPen(opt->palette.light().color())); -
1360 p->drawLine(rect.topLeft().x(), -
1361 rect.topLeft().y(), -
1362 rect.topRight().x(), -
1363 rect.topRight().y()); -
1364 -
1365 if (paintLeftBorder){
-
1366 p->setPen(QPen(opt->palette.light().color())); -
1367 p->drawLine(rect.topLeft().x(), -
1368 rect.topLeft().y(), -
1369 rect.bottomLeft().x(), -
1370 rect.bottomLeft().y()); -
1371 }
-
1372 -
1373 if (paintRightBorder){
-
1374 p->setPen(QPen(opt->palette.dark().color())); -
1375 p->drawLine(rect.topRight().x(), -
1376 rect.topRight().y(), -
1377 rect.bottomRight().x(), -
1378 rect.bottomRight().y()); -
1379 }
-
1380 -
1381 if (paintBottomBorder){
-
1382 p->setPen(QPen(opt->palette.dark().color())); -
1383 p->drawLine(rect.bottomLeft().x(), -
1384 rect.bottomLeft().y(), -
1385 rect.bottomRight().x(), -
1386 rect.bottomRight().y()); -
1387 }
-
1388 }
-
1389 break;
-
1390 -
1391 -
1392 -
1393 -
1394 case CE_ProgressBarContents: -
1395 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
-
1396 QRect rect = pb->rect; -
1397 if (!rect.isValid())
-
1398 return;
-
1399 -
1400 bool vertical = false; -
1401 bool inverted = false; -
1402 -
1403 -
1404 const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt); -
1405 if (pb2) {
-
1406 vertical = (pb2->orientation == Qt::Vertical); -
1407 inverted = pb2->invertedAppearance; -
1408 }
-
1409 QMatrix m; -
1410 if (vertical) {
-
1411 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width()); -
1412 m.rotate(90); -
1413 m.translate(0, -(rect.height() + rect.y()*2)); -
1414 }
-
1415 QPalette pal2 = pb->palette; -
1416 -
1417 if (pal2.highlight() == pal2.background())
-
1418 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active, -
1419 QPalette::Highlight));
-
1420 bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
-
1421 if (inverted)
-
1422 reverse = !reverse;
-
1423 int w = rect.width(); -
1424 const QWindowsStylePrivate * const d = d_func(); -
1425 if (pb->minimum == 0 && pb->maximum == 0) {
-
1426 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget); -
1427 QStyleOptionProgressBarV2 pbBits = *pb; -
1428 qt_noop(); -
1429 -
1430 pbBits.rect = rect; -
1431 pbBits.palette = pal2; -
1432 -
1433 int step = 0; -
1434 int chunkCount = w / unit_width + 1; -
1435 if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject)))
-
1436 step = (animation->animationStep() / 3) % chunkCount;
-
1437 else -
1438 d->startAnimation(new QProgressStyleAnimation(d->animationFps, opt->styleObject));
-
1439 int chunksInRow = 5; -
1440 int myY = pbBits.rect.y(); -
1441 int myHeight = pbBits.rect.height(); -
1442 int chunksToDraw = chunksInRow; -
1443 -
1444 if(step > chunkCount - 5)chunksToDraw = (chunkCount - step);
-
1445 p->save(); -
1446 p->setClipRect(m.mapRect(QRectF(rect)).toRect()); -
1447 -
1448 int x0 = reverse ? rect.left() + rect.width() - unit_width*(step) - unit_width : rect.left() + unit_width * step;
-
1449 int x = 0; -
1450 -
1451 for (int i = 0; i < chunksToDraw ; ++i) {
-
1452 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight); -
1453 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect(); -
1454 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget); -
1455 x += reverse ? -unit_width : unit_width;
-
1456 }
-
1457 -
1458 if( step > chunkCount-5){
-
1459 x0 = reverse ? rect.left() + rect.width() - unit_width : rect.left() ;
-
1460 x = 0; -
1461 int chunksToDraw = step - (chunkCount - chunksInRow); -
1462 for (int i = 0; i < chunksToDraw ; ++i) {
-
1463 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight); -
1464 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect(); -
1465 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget); -
1466 x += reverse ? -unit_width : unit_width;
-
1467 }
-
1468 }
-
1469 p->restore(); -
1470 }
-
1471 else { -
1472 d->stopAnimation(opt->styleObject); -
1473 QCommonStyle::drawControl(ce, opt, p, widget); -
1474 }
-
1475 } -
1476 break;
-
1477 -
1478 -
1479 case CE_DockWidgetTitle: -
1480 -
1481 if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
-
1482 const QWindowsStylePrivate * const d = d_func(); -
1483 -
1484 const QStyleOptionDockWidgetV2 *v2 -
1485 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt); -
1486 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
-
1487 -
1488 QRect rect = dwOpt->rect; -
1489 QRect r = rect; -
1490 -
1491 if (verticalTitleBar) {
-
1492 QSize s = r.size(); -
1493 s.transpose(); -
1494 r.setSize(s); -
1495 -
1496 p->save(); -
1497 p->translate(r.left(), r.top() + r.width()); -
1498 p->rotate(-90); -
1499 p->translate(-r.left(), -r.top()); -
1500 }
-
1501 -
1502 bool floating = false; -
1503 bool active = dwOpt->state & State_Active; -
1504 QColor inactiveCaptionTextColor = d->inactiveCaptionText; -
1505 if (dwOpt->movable) {
-
1506 QColor left, right; -
1507 -
1508 -
1509 if (widget && widget->isWindow()) {
-
1510 floating = true; -
1511 if (active) {
-
1512 left = d->activeCaptionColor; -
1513 right = d->activeGradientCaptionColor; -
1514 } else {
-
1515 left = d->inactiveCaptionColor; -
1516 right = d->inactiveGradientCaptionColor; -
1517 }
-
1518 QBrush fillBrush(left); -
1519 if (left != right) {
-
1520 QPoint p1(r.x(), r.top() + r.height()/2); -
1521 QPoint p2(rect.right(), r.top() + r.height()/2); -
1522 QLinearGradient lg(p1, p2); -
1523 lg.setColorAt(0, left); -
1524 lg.setColorAt(1, right); -
1525 fillBrush = lg; -
1526 }
-
1527 p->fillRect(r.adjusted(0, 0, 0, -3), fillBrush); -
1528 }
-
1529 }
-
1530 if (!dwOpt->title.isEmpty()) {
-
1531 QFont oldFont = p->font(); -
1532 if (floating) {
-
1533 QFont font = oldFont; -
1534 font.setBold(true); -
1535 p->setFont(font); -
1536 }
-
1537 QPalette palette = dwOpt->palette; -
1538 palette.setColor(QPalette::Window, inactiveCaptionTextColor); -
1539 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, opt, widget); -
1540 if (verticalTitleBar) {
-
1541 titleRect = QRect(r.left() + rect.bottom() -
1542 - titleRect.bottom(), -
1543 r.top() + titleRect.left() - rect.left(), -
1544 titleRect.height(), titleRect.width()); -
1545 }
-
1546 proxy()->drawItemText(p, titleRect, -
1547 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, palette, -
1548 dwOpt->state & State_Enabled, dwOpt->title, -
1549 floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText); -
1550 p->setFont(oldFont); -
1551 }
-
1552 if (verticalTitleBar)
-
1553 p->restore();
-
1554 }
-
1555 return;
-
1556 -
1557 default: -
1558 QCommonStyle::drawControl(ce, opt, p, widget); -
1559 }
-
1560}
-
1561 -
1562 -
1563QRect QWindowsStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const -
1564{ -
1565 QRect r; -
1566 switch (sr) { -
1567 case SE_SliderFocusRect: -
1568 case SE_ToolBoxTabContents: -
1569 r = visualRect(opt->direction, opt->rect, opt->rect); -
1570 break;
-
1571 case SE_DockWidgetTitleBarText: { -
1572 r = QCommonStyle::subElementRect(sr, opt, w); -
1573 const QStyleOptionDockWidgetV2 *v2 -
1574 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt); -
1575 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
-
1576 int m = proxy()->pixelMetric(PM_DockWidgetTitleMargin, opt, w); -
1577 if (verticalTitleBar) {
-
1578 r.adjust(0, 0, 0, -m); -
1579 } else {
-
1580 if (opt->direction == Qt::LeftToRight)
-
1581 r.adjust(m, 0, 0, 0);
-
1582 else -
1583 r.adjust(0, 0, -m, 0);
-
1584 } -
1585 break;
-
1586 } -
1587 case SE_ProgressBarContents: -
1588 r = QCommonStyle::subElementRect(SE_ProgressBarGroove, opt, w); -
1589 r.adjust(3, 3, -3, -3); -
1590 break;
-
1591 default: -
1592 r = QCommonStyle::subElementRect(sr, opt, w); -
1593 }
-
1594 return r;
-
1595} -
1596 -
1597 -
1598 -
1599void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, -
1600 QPainter *p, const QWidget *widget) const -
1601{ -
1602 switch (cc) { -
1603 -
1604 case CC_Slider: -
1605 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
-
1606 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget); -
1607 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget); -
1608 int ticks = slider->tickPosition; -
1609 QRect groove = proxy()->subControlRect(CC_Slider, slider, SC_SliderGroove, widget); -
1610 QRect handle = proxy()->subControlRect(CC_Slider, slider, SC_SliderHandle, widget); -
1611 -
1612 if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
-
1613 int mid = thickness / 2; -
1614 -
1615 if (ticks & QSlider::TicksAbove)
-
1616 mid += len / 8;
-
1617 if (ticks & QSlider::TicksBelow)
-
1618 mid -= len / 8;
-
1619 -
1620 p->setPen(slider->palette.shadow().color()); -
1621 if (slider->orientation == Qt::Horizontal) {
-
1622 qDrawWinPanel(p, groove.x(), groove.y() + mid - 2, -
1623 groove.width(), 4, slider->palette, true); -
1624 p->drawLine(groove.x() + 1, groove.y() + mid - 1, -
1625 groove.x() + groove.width() - 3, groove.y() + mid - 1); -
1626 } else {
-
1627 qDrawWinPanel(p, groove.x() + mid - 2, groove.y(), -
1628 4, groove.height(), slider->palette, true); -
1629 p->drawLine(groove.x() + mid - 1, groove.y() + 1, -
1630 groove.x() + mid - 1, groove.y() + groove.height() - 3); -
1631 }
-
1632 } -
1633 -
1634 if (slider->subControls & SC_SliderTickmarks) {
-
1635 QStyleOptionSlider tmpSlider = *slider; -
1636 tmpSlider.subControls = SC_SliderTickmarks; -
1637 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget); -
1638 }
-
1639 -
1640 if (slider->subControls & SC_SliderHandle) {
-
1641 const QColor c0 = slider->palette.shadow().color(); -
1642 const QColor c1 = slider->palette.dark().color(); -
1643 -
1644 const QColor c3 = slider->palette.midlight().color(); -
1645 const QColor c4 = slider->palette.light().color(); -
1646 QBrush handleBrush; -
1647 -
1648 if (slider->state & State_Enabled) {
-
1649 handleBrush = slider->palette.color(QPalette::Button); -
1650 } else {
-
1651 handleBrush = QBrush(slider->palette.color(QPalette::Button), -
1652 Qt::Dense4Pattern); -
1653 }
-
1654 -
1655 -
1656 int x = handle.x(), y = handle.y(), -
1657 wi = handle.width(), he = handle.height(); -
1658 -
1659 int x1 = x; -
1660 int x2 = x+wi-1; -
1661 int y1 = y; -
1662 int y2 = y+he-1; -
1663 -
1664 Qt::Orientation orient = slider->orientation; -
1665 bool tickAbove = slider->tickPosition == QSlider::TicksAbove; -
1666 bool tickBelow = slider->tickPosition == QSlider::TicksBelow; -
1667 -
1668 if (slider->state & State_HasFocus) {
-
1669 QStyleOptionFocusRect fropt; -
1670 fropt.QStyleOption::operator=(*slider); -
1671 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget); -
1672 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget); -
1673 }
-
1674 -
1675 if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
-
1676 Qt::BGMode oldMode = p->backgroundMode(); -
1677 p->setBackgroundMode(Qt::OpaqueMode); -
1678 qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false, -
1679 &handleBrush); -
1680 p->setBackgroundMode(oldMode); -
1681 return;
-
1682 } -
1683 -
1684 QSliderDirection dir; -
1685 -
1686 if (orient == Qt::Horizontal)
-
1687 if (tickAbove)
-
1688 dir = SlUp;
-
1689 else -
1690 dir = SlDown;
-
1691 else -
1692 if (tickAbove)
-
1693 dir = SlLeft;
-
1694 else -
1695 dir = SlRight;
-
1696 -
1697 QPolygon a; -
1698 -
1699 int d = 0; -
1700 switch (dir) { -
1701 case SlUp: -
1702 y1 = y1 + wi/2; -
1703 d = (wi + 1) / 2 - 1; -
1704 a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d); -
1705 break;
-
1706 case SlDown: -
1707 y2 = y2 - wi/2; -
1708 d = (wi + 1) / 2 - 1; -
1709 a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1); -
1710 break;
-
1711 case SlLeft: -
1712 d = (he + 1) / 2 - 1; -
1713 x1 = x1 + he/2; -
1714 a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1); -
1715 break;
-
1716 case SlRight: -
1717 d = (he + 1) / 2 - 1; -
1718 x2 = x2 - he/2; -
1719 a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1); -
1720 break;
-
1721 } -
1722 -
1723 QBrush oldBrush = p->brush(); -
1724 bool oldQt4CompatiblePainting = p->testRenderHint(QPainter::Qt4CompatiblePainting); -
1725 p->setPen(Qt::NoPen); -
1726 p->setBrush(handleBrush); -
1727 p->setRenderHint(QPainter::Qt4CompatiblePainting); -
1728 Qt::BGMode oldMode = p->backgroundMode(); -
1729 p->setBackgroundMode(Qt::OpaqueMode); -
1730 p->drawRect(x1, y1, x2-x1+1, y2-y1+1); -
1731 p->drawPolygon(a); -
1732 p->setBrush(oldBrush); -
1733 p->setBackgroundMode(oldMode); -
1734 -
1735 if (dir != SlUp) {
-
1736 p->setPen(c4); -
1737 p->drawLine(x1, y1, x2, y1); -
1738 p->setPen(c3); -
1739 p->drawLine(x1, y1+1, x2, y1+1); -
1740 }
-
1741 if (dir != SlLeft) {
-
1742 p->setPen(c3); -
1743 p->drawLine(x1+1, y1+1, x1+1, y2); -
1744 p->setPen(c4); -
1745 p->drawLine(x1, y1, x1, y2); -
1746 }
-
1747 if (dir != SlRight) {
-
1748 p->setPen(c0); -
1749 p->drawLine(x2, y1, x2, y2); -
1750 p->setPen(c1); -
1751 p->drawLine(x2-1, y1+1, x2-1, y2-1); -
1752 }
-
1753 if (dir != SlDown) {
-
1754 p->setPen(c0); -
1755 p->drawLine(x1, y2, x2, y2); -
1756 p->setPen(c1); -
1757 p->drawLine(x1+1, y2-1, x2-1, y2-1); -
1758 }
-
1759 -
1760 switch (dir) { -
1761 case SlUp: -
1762 p->setPen(c4); -
1763 p->drawLine(x1, y1, x1+d, y1-d); -
1764 p->setPen(c0); -
1765 d = wi - d - 1; -
1766 p->drawLine(x2, y1, x2-d, y1-d); -
1767 d--; -
1768 p->setPen(c3); -
1769 p->drawLine(x1+1, y1, x1+1+d, y1-d); -
1770 p->setPen(c1); -
1771 p->drawLine(x2-1, y1, x2-1-d, y1-d); -
1772 break;
-
1773 case SlDown: -
1774 p->setPen(c4); -
1775 p->drawLine(x1, y2, x1+d, y2+d); -
1776 p->setPen(c0); -
1777 d = wi - d - 1; -
1778 p->drawLine(x2, y2, x2-d, y2+d); -
1779 d--; -
1780 p->setPen(c3); -
1781 p->drawLine(x1+1, y2, x1+1+d, y2+d); -
1782 p->setPen(c1); -
1783 p->drawLine(x2-1, y2, x2-1-d, y2+d); -
1784 break;
-
1785 case SlLeft: -
1786 p->setPen(c4); -
1787 p->drawLine(x1, y1, x1-d, y1+d); -
1788 p->setPen(c0); -
1789 d = he - d - 1; -
1790 p->drawLine(x1, y2, x1-d, y2-d); -
1791 d--; -
1792 p->setPen(c3); -
1793 p->drawLine(x1, y1+1, x1-d, y1+1+d); -
1794 p->setPen(c1); -
1795 p->drawLine(x1, y2-1, x1-d, y2-1-d); -
1796 break;
-
1797 case SlRight: -
1798 p->setPen(c4); -
1799 p->drawLine(x2, y1, x2+d, y1+d); -
1800 p->setPen(c0); -
1801 d = he - d - 1; -
1802 p->drawLine(x2, y2, x2+d, y2-d); -
1803 d--; -
1804 p->setPen(c3); -
1805 p->drawLine(x2, y1+1, x2+d, y1+1+d); -
1806 p->setPen(c1); -
1807 p->drawLine(x2, y2-1, x2+d, y2-1-d); -
1808 break;
-
1809 } -
1810 p->setRenderHint(QPainter::Qt4CompatiblePainting, oldQt4CompatiblePainting); -
1811 }
-
1812 }
-
1813 break;
-
1814 -
1815 -
1816 case CC_ScrollBar: -
1817 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
-
1818 QStyleOptionSlider newScrollbar = *scrollbar; -
1819 if (scrollbar->minimum == scrollbar->maximum)
-
1820 newScrollbar.state &= ~State_Enabled;
-
1821 QCommonStyle::drawComplexControl(cc, &newScrollbar, p, widget); -
1822 }
-
1823 break;
-
1824 -
1825 -
1826 case CC_ComboBox: -
1827 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
-
1828 QBrush editBrush = cmb->palette.brush(QPalette::Base); -
1829 if ((cmb->subControls & SC_ComboBoxFrame)) {
-
1830 if (cmb->frame) {
-
1831 QPalette shadePal = opt->palette; -
1832 shadePal.setColor(QPalette::Midlight, shadePal.button().color()); -
1833 qDrawWinPanel(p, opt->rect, shadePal, true, &editBrush); -
1834 }
-
1835 else { -
1836 p->fillRect(opt->rect, editBrush); -
1837 }
-
1838 } -
1839 if (cmb->subControls & SC_ComboBoxArrow) {
-
1840 State flags = State_None; -
1841 -
1842 QRect ar = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget); -
1843 bool sunkenArrow = cmb->activeSubControls == SC_ComboBoxArrow
-
1844 && cmb->state & State_Sunken;
-
1845 if (sunkenArrow) {
-
1846 p->setPen(cmb->palette.dark().color()); -
1847 p->setBrush(cmb->palette.brush(QPalette::Button)); -
1848 p->drawRect(ar.adjusted(0,0,-1,-1)); -
1849 } else {
-
1850 -
1851 QPalette pal(cmb->palette); -
1852 pal.setColor(QPalette::Button, cmb->palette.light().color()); -
1853 pal.setColor(QPalette::Light, cmb->palette.button().color()); -
1854 qDrawWinButton(p, ar, pal, false, -
1855 &cmb->palette.brush(QPalette::Button)); -
1856 }
-
1857 -
1858 ar.adjust(2, 2, -2, -2); -
1859 if (opt->state & State_Enabled)
-
1860 flags |= State_Enabled;
-
1861 if (opt->state & State_HasFocus)
-
1862 flags |= State_HasFocus;
-
1863 -
1864 if (sunkenArrow)
-
1865 flags |= State_Sunken;
-
1866 QStyleOption arrowOpt(0); -
1867 arrowOpt.rect = ar.adjusted(1, 1, -1, -1); -
1868 arrowOpt.palette = cmb->palette; -
1869 arrowOpt.state = flags; -
1870 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget); -
1871 }
-
1872 -
1873 if (cmb->subControls & SC_ComboBoxEditField) {
-
1874 QRect re = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget); -
1875 if (cmb->state & State_HasFocus && !cmb->editable)
-
1876 p->fillRect(re.x(), re.y(), re.width(), re.height(), -
1877 cmb->palette.brush(QPalette::Highlight));
-
1878 -
1879 if (cmb->state & State_HasFocus) {
-
1880 p->setPen(cmb->palette.highlightedText().color()); -
1881 p->setBackground(cmb->palette.highlight()); -
1882 -
1883 } else {
-
1884 p->setPen(cmb->palette.text().color()); -
1885 p->setBackground(cmb->palette.background()); -
1886 }
-
1887 -
1888 if (cmb->state & State_HasFocus && !cmb->editable) {
-
1889 QStyleOptionFocusRect focus; -
1890 focus.QStyleOption::operator=(*cmb); -
1891 focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget); -
1892 focus.state |= State_FocusAtBorder; -
1893 focus.backgroundColor = cmb->palette.highlight().color(); -
1894 proxy()->drawPrimitive(PE_FrameFocusRect, &focus, p, widget); -
1895 }
-
1896 }
-
1897 }
-
1898 break;
-
1899 -
1900 -
1901 case CC_SpinBox: -
1902 if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
-
1903 QStyleOptionSpinBox copy = *sb; -
1904 PrimitiveElement pe; -
1905 bool enabled = opt->state & State_Enabled; -
1906 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
-
1907 QBrush editBrush = sb->palette.brush(QPalette::Base); -
1908 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget); -
1909 QPalette shadePal = sb->palette; -
1910 shadePal.setColor(QPalette::Midlight, shadePal.button().color()); -
1911 qDrawWinPanel(p, r, shadePal, true, &editBrush); -
1912 }
-
1913 -
1914 QPalette shadePal(opt->palette); -
1915 shadePal.setColor(QPalette::Button, opt->palette.light().color()); -
1916 shadePal.setColor(QPalette::Light, opt->palette.button().color()); -
1917 -
1918 if (sb->subControls & SC_SpinBoxUp) {
-
1919 copy.subControls = SC_SpinBoxUp; -
1920 QPalette pal2 = sb->palette; -
1921 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
-
1922 pal2.setCurrentColorGroup(QPalette::Disabled); -
1923 copy.state &= ~State_Enabled; -
1924 }
-
1925 -
1926 copy.palette = pal2; -
1927 -
1928 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
-
1929 copy.state |= State_On; -
1930 copy.state |= State_Sunken; -
1931 } else {
-
1932 copy.state |= State_Raised; -
1933 copy.state &= ~State_Sunken; -
1934 }
-
1935 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
-
1936 : PE_IndicatorSpinUp); -
1937 -
1938 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget); -
1939 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On), -
1940 &copy.palette.brush(QPalette::Button)); -
1941 copy.rect.adjust(4, 1, -5, -1); -
1942 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled))
-
1943 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
-
1944 { -
1945 QStyleOptionSpinBox lightCopy = copy; -
1946 lightCopy.rect.adjust(1, 1, 1, 1); -
1947 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light()); -
1948 proxy()->drawPrimitive(pe, &lightCopy, p, widget); -
1949 }
-
1950 proxy()->drawPrimitive(pe, &copy, p, widget); -
1951 }
-
1952 -
1953 if (sb->subControls & SC_SpinBoxDown) {
-
1954 copy.subControls = SC_SpinBoxDown; -
1955 copy.state = sb->state; -
1956 QPalette pal2 = sb->palette; -
1957 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
-
1958 pal2.setCurrentColorGroup(QPalette::Disabled); -
1959 copy.state &= ~State_Enabled; -
1960 }
-
1961 copy.palette = pal2; -
1962 -
1963 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
-
1964 copy.state |= State_On; -
1965 copy.state |= State_Sunken; -
1966 } else {
-
1967 copy.state |= State_Raised; -
1968 copy.state &= ~State_Sunken; -
1969 }
-
1970 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
-
1971 : PE_IndicatorSpinDown); -
1972 -
1973 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget); -
1974 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On), -
1975 &copy.palette.brush(QPalette::Button)); -
1976 copy.rect.adjust(4, 0, -5, -1); -
1977 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled))
-
1978 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
-
1979 { -
1980 QStyleOptionSpinBox lightCopy = copy; -
1981 lightCopy.rect.adjust(1, 1, 1, 1); -
1982 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light()); -
1983 proxy()->drawPrimitive(pe, &lightCopy, p, widget); -
1984 }
-
1985 proxy()->drawPrimitive(pe, &copy, p, widget); -
1986 }
-
1987 }
-
1988 break;
-
1989 -
1990 -
1991 default: -
1992 QCommonStyle::drawComplexControl(cc, opt, p, widget); -
1993 }
-
1994}
-
1995 -
1996 -
1997QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, -
1998 const QSize &csz, const QWidget *widget) const -
1999{ -
2000 QSize sz(csz); -
2001 switch (ct) { -
2002 case CT_PushButton: -
2003 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
-
2004 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget); -
2005 int w = sz.width(), -
2006 h = sz.height(); -
2007 int defwidth = 0; -
2008 if (btn->features & QStyleOptionButton::AutoDefaultButton)
-
2009 defwidth = 2 * proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
-
2010 int minwidth = int(QStyleHelper::dpiScaled(75.)); -
2011 int minheight = int(QStyleHelper::dpiScaled(23.)); -
2012 -
2013 -
2014 if (w < minwidth + defwidth && !btn->text.isEmpty())
-
2015 w = minwidth + defwidth;
-
2016 if (h < minheight + defwidth)
-
2017 h = minheight + defwidth;
-
2018 -
2019 sz = QSize(w, h); -
2020 }
-
2021 break;
-
2022 -
2023 case CT_MenuItem: -
2024 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
-
2025 int w = sz.width(); -
2026 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget); -
2027 -
2028 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
-
2029 sz = QSize(10, QWindowsStylePrivate::windowsSepHeight); -
2030 }
-
2031 else if (mi->icon.isNull()) {
-
2032 sz.setHeight(sz.height() - 2); -
2033 w -= 6; -
2034 }
-
2035 -
2036 if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull()) {
-
2037 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget); -
2038 sz.setHeight(qMax(sz.height(), -
2039 mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() -
2040 + 2 * QWindowsStylePrivate::windowsItemFrame)); -
2041 }
-
2042 int maxpmw = mi->maxIconWidth; -
2043 int tabSpacing = 20; -
2044 if (mi->text.contains(QLatin1Char('\t')))
-
2045 w += tabSpacing;
-
2046 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
-
2047 w += 2 * QWindowsStylePrivate::windowsArrowHMargin;
-
2048 else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) {
-
2049 -
2050 -
2051 QFontMetrics fm(mi->font); -
2052 QFont fontBold = mi->font; -
2053 fontBold.setBold(true); -
2054 QFontMetrics fmBold(fontBold); -
2055 w += fmBold.width(mi->text) - fm.width(mi->text); -
2056 }
-
2057 -
2058 int checkcol = qMax<int>(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth); -
2059 w += checkcol; -
2060 w += int(QWindowsStylePrivate::windowsRightBorder) + 10; -
2061 sz.setWidth(w); -
2062 }
-
2063 break;
-
2064 -
2065 -
2066 case CT_MenuBarItem: -
2067 if (!sz.isEmpty())
-
2068 sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2);
-
2069 break;
-
2070 -
2071 -
2072 case CT_ToolButton: -
2073 if (qstyleoption_cast<const QStyleOptionToolButton *>(opt))
-
2074 return sz += QSize(7, 6);
-
2075 -
2076 -
2077 default:
-
2078 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget); -
2079 }
-
2080 return sz;
-
2081} -
2082 -
2083 -
2084 -
2085 -
2086QIcon QWindowsStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *option, -
2087 const QWidget *widget) const -
2088{ -
2089 return QCommonStyle::standardIcon(standardIcon, option, widget);
-
2090} -
2091 -
2092 -
2093 -
2094 -
2095 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial