styles/qwindowsstyle.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/****************************************************************************-
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/****************************************************************************
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qwindowsstyle_p.h" -
43#include "qwindowsstyle_p_p.h" -
44 -
45#if !defined(QT_NO_STYLE_WINDOWS) || defined(QT_PLUGIN) -
46 -
47#include <private/qsystemlibrary_p.h> -
48#include "qapplication.h" -
49#include "qbitmap.h" -
50#include "qdrawutil.h" // for now -
51#include "qevent.h" -
52#include "qmenu.h" -
53#include "qmenubar.h" -
54#include <private/qmenubar_p.h> -
55#include "qpaintengine.h" -
56#include "qpainter.h" -
57#include "qrubberband.h" -
58#include "qstyleoption.h" -
59#include "qtabbar.h" -
60#include "qwidget.h" -
61#include "qdebug.h" -
62#include "qmainwindow.h" -
63#include "qfile.h" -
64#include "qtextstream.h" -
65#include "qpixmapcache.h" -
66#include "qwizard.h" -
67#include "qlistview.h" -
68#include <private/qmath_p.h> -
69#include <qmath.h> -
70#include <qpa/qplatformtheme.h> -
71#include <private/qguiapplication_p.h> -
72 -
73#include <private/qstylehelper_p.h> -
74#include <private/qstyleanimation_p.h> -
75 -
76QT_BEGIN_NAMESPACE -
77 -
78#if defined(Q_OS_WIN) -
79 -
80QT_BEGIN_INCLUDE_NAMESPACE -
81#include "qt_windows.h" -
82QT_END_INCLUDE_NAMESPACE -
83# ifndef COLOR_GRADIENTACTIVECAPTION -
84# define COLOR_GRADIENTACTIVECAPTION 27 -
85# endif -
86# ifndef COLOR_GRADIENTINACTIVECAPTION -
87# define COLOR_GRADIENTINACTIVECAPTION 28 -
88# endif -
89 -
90 -
91typedef struct -
92{ -
93 DWORD cbSize; -
94 HICON hIcon; -
95 int iSysImageIndex; -
96 int iIcon; -
97 WCHAR szPath[MAX_PATH]; -
98} QSHSTOCKICONINFO; -
99 -
100#define _SHGFI_SMALLICON 0x000000001 -
101#define _SHGFI_LARGEICON 0x000000000 -
102#define _SHGFI_ICON 0x000000100 -
103#define _SIID_SHIELD 77 -
104 -
105typedef HRESULT (WINAPI *PtrSHGetStockIconInfo)(int siid, int uFlags, QSHSTOCKICONINFO *psii); -
106static PtrSHGetStockIconInfo pSHGetStockIconInfo = 0; -
107 -
108Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &); -
109Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon); -
110#endif //Q_OS_WIN -
111 -
112QT_BEGIN_INCLUDE_NAMESPACE -
113#include <limits.h> -
114QT_END_INCLUDE_NAMESPACE -
115 -
116enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight }; -
117 -
118/* -
119 \internal -
120*/ -
121QWindowsStylePrivate::QWindowsStylePrivate() -
122 : alt_down(false), menuBarTimer(0) -
123{ -
124#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) -
125 if ((QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA -
126 && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))) { -
127 QSystemLibrary shellLib(QLatin1String("shell32")); -
128 pSHGetStockIconInfo = (PtrSHGetStockIconInfo)shellLib.resolve("SHGetStockIconInfo"); -
129 } -
130#endif -
131} -
132 -
133// Returns true if the toplevel parent of \a widget has seen the Alt-key -
134bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const -
135{ -
136 widget = widget->window(); -
137 return seenAlt.contains(widget); -
138} -
139 -
140/*! -
141 \reimp -
142*/ -
143bool QWindowsStyle::eventFilter(QObject *o, QEvent *e) -
144{ -
145 // Records Alt- and Focus events -
146 if (!o->isWidgetType()) -
147 return QObject::eventFilter(o, e); -
148 -
149 QWidget *widget = qobject_cast<QWidget*>(o); -
150 Q_D(QWindowsStyle); -
151 switch(e->type()) { -
152 case QEvent::KeyPress: -
153 if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt) { -
154 widget = widget->window(); -
155 -
156 // Alt has been pressed - find all widgets that care -
157 QList<QWidget *> l = widget->findChildren<QWidget *>(); -
158 for (int pos=0 ; pos < l.size() ; ++pos) { -
159 QWidget *w = l.at(pos); -
160 if (w->isWindow() || !w->isVisible() || -
161 w->style()->styleHint(SH_UnderlineShortcut, 0, w)) -
162 l.removeAt(pos); -
163 } -
164 // Update states before repainting -
165 d->seenAlt.append(widget); -
166 d->alt_down = true; -
167 -
168 // Repaint all relevant widgets -
169 for (int pos = 0; pos < l.size(); ++pos) -
170 l.at(pos)->update(); -
171 } -
172 break; -
173 case QEvent::KeyRelease: -
174 if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) { -
175 widget = widget->window(); -
176 -
177 // Update state and repaint the menu bars. -
178 d->alt_down = false; -
179#ifndef QT_NO_MENUBAR -
180 QList<QMenuBar *> l = widget->findChildren<QMenuBar *>(); -
181 for (int i = 0; i < l.size(); ++i) -
182 l.at(i)->update(); -
183#endif -
184 } -
185 break; -
186 case QEvent::Close: -
187 // Reset widget when closing -
188 d->seenAlt.removeAll(widget); -
189 d->seenAlt.removeAll(widget->window()); -
190 break; -
191 default: -
192 break; -
193 } -
194 return QCommonStyle::eventFilter(o, e); -
195} -
196 -
197/*! -
198 \class QWindowsStyle -
199 \brief The QWindowsStyle class provides a Microsoft Windows-like look and feel. -
200 -
201 \ingroup appearance -
202 \inmodule QtWidgets -
203 \internal -
204 -
205 This style is Qt's default GUI style on Windows. -
206 -
207 \image qwindowsstyle.png -
208 \sa QWindowsVistaStyle, QMacStyle, QFusionStyle -
209*/ -
210 -
211/*! -
212 Constructs a QWindowsStyle object. -
213*/ -
214QWindowsStyle::QWindowsStyle() : QCommonStyle(*new QWindowsStylePrivate) -
215{ -
216} -
217 -
218/*! -
219 \internal -
220 -
221 Constructs a QWindowsStyle object. -
222*/ -
223QWindowsStyle::QWindowsStyle(QWindowsStylePrivate &dd) : QCommonStyle(dd) -
224{ -
225} -
226 -
227 -
228/*! Destroys the QWindowsStyle object. */ -
229QWindowsStyle::~QWindowsStyle() -
230{ -
231} -
232 -
233#ifdef Q_OS_WIN -
234static inline QRgb colorref2qrgb(COLORREF col) -
235{ -
236 return qRgb(GetRValue(col), GetGValue(col), GetBValue(col)); -
237} -
238#endif -
239 -
240/*! \reimp */ -
241void QWindowsStyle::polish(QApplication *app) -
242{ -
243 QCommonStyle::polish(app); -
244 QWindowsStylePrivate *d = const_cast<QWindowsStylePrivate*>(d_func()); -
245 // We only need the overhead when shortcuts are sometimes hidden -
246 if (!proxy()->styleHint(SH_UnderlineShortcut, 0) && app) -
247 app->installEventFilter(this); -
248 -
249 d->activeCaptionColor = app->palette().highlight().color(); -
250 d->activeGradientCaptionColor = app->palette().highlight() .color(); -
251 d->inactiveCaptionColor = app->palette().dark().color(); -
252 d->inactiveGradientCaptionColor = app->palette().dark().color(); -
253 d->inactiveCaptionText = app->palette().background().color(); -
254 -
255#if defined(Q_OS_WIN) //fetch native title bar colors -
256 if(app->desktopSettingsAware()){ -
257 DWORD activeCaption = GetSysColor(COLOR_ACTIVECAPTION); -
258 DWORD gradientActiveCaption = GetSysColor(COLOR_GRADIENTACTIVECAPTION); -
259 DWORD inactiveCaption = GetSysColor(COLOR_INACTIVECAPTION); -
260 DWORD gradientInactiveCaption = GetSysColor(COLOR_GRADIENTINACTIVECAPTION); -
261 DWORD inactiveCaptionText = GetSysColor(COLOR_INACTIVECAPTIONTEXT); -
262 d->activeCaptionColor = colorref2qrgb(activeCaption); -
263 d->activeGradientCaptionColor = colorref2qrgb(gradientActiveCaption); -
264 d->inactiveCaptionColor = colorref2qrgb(inactiveCaption); -
265 d->inactiveGradientCaptionColor = colorref2qrgb(gradientInactiveCaption); -
266 d->inactiveCaptionText = colorref2qrgb(inactiveCaptionText); -
267 } -
268#endif -
269} -
270 -
271/*! \reimp */ -
272void QWindowsStyle::unpolish(QApplication *app) -
273{ -
274 QCommonStyle::unpolish(app); -
275 app->removeEventFilter(this); -
276} -
277 -
278/*! \reimp */ -
279void QWindowsStyle::polish(QWidget *widget) -
280{ -
281 QCommonStyle::polish(widget); -
282} -
283 -
284/*! \reimp */ -
285void QWindowsStyle::unpolish(QWidget *widget) -
286{ -
287 QCommonStyle::unpolish(widget); -
288} -
289 -
290/*! -
291 \reimp -
292*/ -
293void QWindowsStyle::polish(QPalette &pal) -
294{ -
295 QCommonStyle::polish(pal); -
296} -
297 -
298/*! -
299 \reimp -
300*/ -
301int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const -
302{ -
303 int ret; -
304 -
305 switch (pm) { -
306 case PM_ButtonDefaultIndicator: -
307 case PM_ButtonShiftHorizontal: -
308 case PM_ButtonShiftVertical: -
309 case PM_MenuHMargin: -
310 case PM_MenuVMargin: -
311 ret = 1; -
312 break; -
313 case PM_DockWidgetSeparatorExtent: -
314 ret = int(QStyleHelper::dpiScaled(4.)); -
315 break; -
316#ifndef QT_NO_TABBAR -
317 case PM_TabBarTabShiftHorizontal: -
318 ret = 0; -
319 break; -
320 case PM_TabBarTabShiftVertical: -
321 ret = 2; -
322 break; -
323#endif -
324 case PM_MaximumDragDistance: -
325 ret = QCommonStyle::pixelMetric(PM_MaximumDragDistance); -
326 if (ret == -1) -
327 ret = 60; -
328 break; -
329 -
330#ifndef QT_NO_SLIDER -
331 case PM_SliderLength: -
332 ret = int(QStyleHelper::dpiScaled(11.)); -
333 break; -
334 -
335 // Returns the number of pixels to use for the business part of the -
336 // slider (i.e., the non-tickmark portion). The remaining space is shared -
337 // equally between the tickmark regions. -
338 case PM_SliderControlThickness: -
339 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { -
340 int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width(); -
341 int ticks = sl->tickPosition; -
342 int n = 0; -
343 if (ticks & QSlider::TicksAbove) -
344 ++n; -
345 if (ticks & QSlider::TicksBelow) -
346 ++n; -
347 if (!n) { -
348 ret = space; -
349 break; -
350 } -
351 -
352 int thick = 6; // Magic constant to get 5 + 16 + 5 -
353 if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks) -
354 thick += proxy()->pixelMetric(PM_SliderLength, sl, widget) / 4; -
355 -
356 space -= thick; -
357 if (space > 0) -
358 thick += (space * 2) / (n + 2); -
359 ret = thick; -
360 } else { -
361 ret = 0; -
362 } -
363 break; -
364#endif // QT_NO_SLIDER -
365 -
366#ifndef QT_NO_MENU -
367 case PM_MenuBarHMargin: -
368 ret = 0; -
369 break; -
370 -
371 case PM_MenuBarVMargin: -
372 ret = 0; -
373 break; -
374 -
375 case PM_MenuBarPanelWidth: -
376 ret = 0; -
377 break; -
378 -
379 case PM_SmallIconSize: -
380 ret = int(QStyleHelper::dpiScaled(16.)); -
381 break; -
382 -
383 case PM_LargeIconSize: -
384 ret = int(QStyleHelper::dpiScaled(32.)); -
385 break; -
386 -
387 case PM_IconViewIconSize: -
388 ret = proxy()->pixelMetric(PM_LargeIconSize, opt, widget); -
389 break; -
390 -
391 case PM_DockWidgetTitleMargin: -
392 ret = int(QStyleHelper::dpiScaled(2.)); -
393 break; -
394 case PM_DockWidgetTitleBarButtonMargin: -
395 ret = int(QStyleHelper::dpiScaled(4.)); -
396 break; -
397#if defined(Q_WS_WIN) -
398 case PM_DockWidgetFrameWidth: -
399#if defined(Q_OS_WINCE) -
400 ret = GetSystemMetrics(SM_CXDLGFRAME); -
401#else -
402 ret = GetSystemMetrics(SM_CXFRAME); -
403#endif -
404 break; -
405#else -
406 case PM_DockWidgetFrameWidth: -
407 ret = 4; -
408 break; -
409#endif // Q_WS_WIN -
410 break;
dead code: break;
-
411 -
412#endif // QT_NO_MENU -
413 -
414 -
415#if defined(Q_OS_WIN) -
416 case PM_TitleBarHeight: -
417 if (widget && (widget->windowType() == Qt::Tool)) { -
418 // MS always use one less than they say -
419#if defined(Q_OS_WINCE) -
420 ret = GetSystemMetrics(SM_CYCAPTION) - 1; -
421#else -
422 ret = GetSystemMetrics(SM_CYSMCAPTION) - 1; -
423#endif -
424 } else { -
425 ret = GetSystemMetrics(SM_CYCAPTION) - 1; -
426 } -
427 -
428 break; -
429 -
430 case PM_ScrollBarExtent: -
431 { -
432#ifndef Q_OS_WINCE -
433 NONCLIENTMETRICS ncm; -
434 ncm.cbSize = FIELD_OFFSET(NONCLIENTMETRICS, lfMessageFont) + sizeof(LOGFONT); -
435 if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0)) -
436 ret = qMax(ncm.iScrollHeight, ncm.iScrollWidth); -
437 else -
438#endif -
439 ret = QCommonStyle::pixelMetric(pm, opt, widget); -
440 } -
441 break; -
442#endif // Q_OS_WIN -
443 -
444 case PM_SplitterWidth: -
445 ret = qMax(4, QApplication::globalStrut().width()); -
446 break; -
447 -
448#if defined(Q_OS_WIN) -
449 case PM_MdiSubWindowFrameWidth: -
450#if defined(Q_OS_WINCE) -
451 ret = GetSystemMetrics(SM_CYDLGFRAME); -
452#else -
453 ret = GetSystemMetrics(SM_CYFRAME); -
454#endif -
455 break; -
456#endif -
457 case PM_ToolBarItemMargin: -
458 ret = 1; -
459 break; -
460 case PM_ToolBarItemSpacing: -
461 ret = 0; -
462 break; -
463 case PM_ToolBarHandleExtent: -
464 ret = int(QStyleHelper::dpiScaled(10.)); -
465 break; -
466 default: -
467 ret = QCommonStyle::pixelMetric(pm, opt, widget); -
468 break; -
469 } -
470 -
471 return ret; -
472} -
473 -
474/*! -
475 \reimp -
476 */ -
477QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, -
478 const QWidget *widget) const -
479{ -
480#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) -
481 QPixmap desktopIcon; -
482 switch(standardPixmap) { -
483 case SP_DriveCDIcon: -
484 case SP_DriveDVDIcon: -
485 case SP_DriveNetIcon: -
486 case SP_DriveHDIcon: -
487 case SP_DriveFDIcon: -
488 case SP_FileIcon: -
489 case SP_FileLinkIcon: -
490 case SP_DirLinkIcon: -
491 case SP_DirClosedIcon: -
492 case SP_DesktopIcon: -
493 case SP_ComputerIcon: -
494 case SP_DirOpenIcon: -
495 case SP_FileDialogNewFolder: -
496 case SP_DirHomeIcon: -
497 case SP_TrashIcon: -
498 case SP_VistaShield: -
499 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { -
500 QPlatformTheme::StandardPixmap sp = static_cast<QPlatformTheme::StandardPixmap>(standardPixmap); -
501 desktopIcon = theme->standardPixmap(sp, QSizeF(16, 16)); -
502 } -
503 break; -
504 case SP_MessageBoxInformation: -
505 case SP_MessageBoxWarning: -
506 case SP_MessageBoxCritical: -
507 case SP_MessageBoxQuestion: -
508 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { -
509 QPlatformTheme::StandardPixmap sp = static_cast<QPlatformTheme::StandardPixmap>(standardPixmap); -
510 desktopIcon = theme->standardPixmap(sp, QSizeF()); -
511 } -
512 break; -
513 default: -
514 break; -
515 } -
516 if (!desktopIcon.isNull()) { -
517 return desktopIcon; -
518 } -
519#endif -
520 return QCommonStyle::standardPixmap(standardPixmap, opt, widget); -
521} -
522 -
523/*! \reimp */ -
524int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget, -
525 QStyleHintReturn *returnData) const -
526{ -
527 int ret = 0; -
528 -
529 switch (hint) { -
530 case SH_EtchDisabledText: -
531 case SH_Slider_SnapToValue: -
532 case SH_PrintDialog_RightAlignButtons: -
533 case SH_FontDialog_SelectAssociatedText: -
534 case SH_Menu_AllowActiveAndDisabled: -
535 case SH_MenuBar_AltKeyNavigation: -
536 case SH_MenuBar_MouseTracking: -
537 case SH_Menu_MouseTracking: -
538 case SH_ComboBox_ListMouseTracking: -
539 case SH_ScrollBar_StopMouseOverSlider: -
540 case SH_MainWindow_SpaceBelowMenuBar: -
541 ret = 1; -
542 -
543 break; -
544 case SH_ItemView_ShowDecorationSelected: -
545#ifndef QT_NO_LISTVIEW -
546 if (qobject_cast<const QListView*>(widget)) -
547 ret = 1; -
548#endif -
549 break; -
550 case SH_ItemView_ChangeHighlightOnFocus: -
551 ret = 1; -
552 break; -
553 case SH_ToolBox_SelectedPageTitleBold: -
554 ret = 0; -
555 break; -
556 -
557#if defined(Q_OS_WIN) -
558 case SH_UnderlineShortcut: -
559 { -
560 ret = 1; -
561 BOOL cues = false; -
562 SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0); -
563 ret = int(cues); -
564 // Do nothing if we always paint underlines -
565 Q_D(const QWindowsStyle); -
566 if (!ret && widget && d) { -
567#ifndef QT_NO_MENUBAR -
568 const QMenuBar *menuBar = qobject_cast<const QMenuBar *>(widget); -
569 if (!menuBar && qobject_cast<const QMenu *>(widget)) { -
570 QWidget *w = QApplication::activeWindow(); -
571 if (w && w != widget) -
572 menuBar = w->findChild<QMenuBar *>(); -
573 } -
574 // If we paint a menu bar draw underlines if is in the keyboardState -
575 if (menuBar) { -
576 if (menuBar->d_func()->keyboardState || d->altDown()) -
577 ret = 1; -
578 // Otherwise draw underlines if the toplevel widget has seen an alt-press -
579 } else -
580#endif // QT_NO_MENUBAR -
581 if (d->hasSeenAlt(widget)) { -
582 ret = 1; -
583 } -
584 } -
585 break; -
586 } -
587#endif -
588#ifndef QT_NO_RUBBERBAND -
589 case SH_RubberBand_Mask: -
590 if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) { -
591 ret = 0; -
592 if (rbOpt->shape == QRubberBand::Rectangle) { -
593 ret = true; -
594 if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) { -
595 mask->region = opt->rect; -
596 int size = 1; -
597 if (widget && widget->isWindow()) -
598 size = 4; -
599 mask->region -= opt->rect.adjusted(size, size, -size, -size); -
600 } -
601 } -
602 } -
603 break; -
604#endif // QT_NO_RUBBERBAND -
605 case SH_LineEdit_PasswordCharacter: -
606 { -
607#ifdef Q_OS_WIN -
608 if (widget && (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))) { -
609 const QFontMetrics &fm = widget->fontMetrics(); -
610 if (fm.inFont(QChar(0x25CF))) -
611 ret = 0x25CF; -
612 else if (fm.inFont(QChar(0x2022))) -
613 ret = 0x2022; -
614 } -
615#endif -
616 if (!ret) -
617 ret = '*'; -
618 } -
619 break; -
620#ifndef QT_NO_WIZARD -
621 case SH_WizardStyle: -
622 ret = QWizard::ModernStyle; -
623 break; -
624#endif -
625 case SH_ItemView_ArrowKeysNavigateIntoChildren: -
626 ret = true; -
627 break; -
628 case SH_DialogButtonBox_ButtonsHaveIcons: -
629 ret = 0; -
630 break; -
631 default: -
632 ret = QCommonStyle::styleHint(hint, opt, widget, returnData); -
633 break; -
634 } -
635 return ret; -
636} -
637 -
638/*! \reimp */ -
639void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, -
640 const QWidget *w) const -
641{ -
642 // Used to restore across fallthrough cases. Currently only used in PE_IndicatorCheckBox -
643 bool doRestore = false; -
644 -
645 switch (pe) { -
646#ifndef QT_NO_TOOLBAR -
647 case PE_IndicatorToolBarSeparator: -
648 { -
649 QRect rect = opt->rect; -
650 const int margin = 2; -
651 QPen oldPen = p->pen(); -
652 if(opt->state & State_Horizontal){ -
653 const int offset = rect.width()/2; -
654 p->setPen(QPen(opt->palette.dark().color())); -
655 p->drawLine(rect.bottomLeft().x() + offset, -
656 rect.bottomLeft().y() - margin, -
657 rect.topLeft().x() + offset, -
658 rect.topLeft().y() + margin); -
659 p->setPen(QPen(opt->palette.light().color())); -
660 p->drawLine(rect.bottomLeft().x() + offset + 1, -
661 rect.bottomLeft().y() - margin, -
662 rect.topLeft().x() + offset + 1, -
663 rect.topLeft().y() + margin); -
664 } -
665 else{ //Draw vertical separator -
666 const int offset = rect.height()/2; -
667 p->setPen(QPen(opt->palette.dark().color())); -
668 p->drawLine(rect.topLeft().x() + margin , -
669 rect.topLeft().y() + offset, -
670 rect.topRight().x() - margin, -
671 rect.topRight().y() + offset); -
672 p->setPen(QPen(opt->palette.light().color())); -
673 p->drawLine(rect.topLeft().x() + margin , -
674 rect.topLeft().y() + offset + 1, -
675 rect.topRight().x() - margin, -
676 rect.topRight().y() + offset + 1); -
677 } -
678 p->setPen(oldPen); -
679 } -
680 break; -
681 case PE_IndicatorToolBarHandle: -
682 p->save(); -
683 p->translate(opt->rect.x(), opt->rect.y()); -
684 if (opt->state & State_Horizontal) { -
685 int x = opt->rect.width() / 2 - 4; -
686 if (opt->direction == Qt::RightToLeft) -
687 x -= 2; -
688 if (opt->rect.height() > 4) { -
689 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4, -
690 opt->palette, false, 1, 0); -
691 qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4, -
692 opt->palette, false, 1, 0); -
693 } -
694 } else { -
695 if (opt->rect.width() > 4) { -
696 int y = opt->rect.height() / 2 - 4; -
697 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3, -
698 opt->palette, false, 1, 0); -
699 qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3, -
700 opt->palette, false, 1, 0); -
701 } -
702 } -
703 p->restore(); -
704 break; -
705 -
706#endif // QT_NO_TOOLBAR -
707 case PE_FrameButtonTool: -
708 case PE_PanelButtonTool: { -
709 QPen oldPen = p->pen(); -
710#ifndef QT_NO_DOCKWIDGET -
711 if (w && w->inherits("QDockWidgetTitleButton")) { -
712 if (const QWidget *dw = w->parentWidget()) -
713 if (dw->isWindow()){ -
714 qDrawWinButton(p, opt->rect.adjusted(1, 1, 0, 0), opt->palette, opt->state & (State_Sunken | State_On), -
715 &opt->palette.button()); -
716 -
717 return; -
718 } -
719 } -
720#endif // QT_NO_DOCKWIDGET -
721 QBrush fill; -
722 bool stippled; -
723 bool panel = (pe == PE_PanelButtonTool); -
724 if ((!(opt->state & State_Sunken )) -
725 && (!(opt->state & State_Enabled) -
726 || !(opt->state & State_MouseOver && opt->state & State_AutoRaise)) -
727 && (opt->state & State_On)) { -
728 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern); -
729 stippled = true; -
730 } else { -
731 fill = opt->palette.brush(QPalette::Button); -
732 stippled = false; -
733 } -
734 -
735 if (opt->state & (State_Raised | State_Sunken | State_On)) { -
736 if (opt->state & State_AutoRaise) { -
737 if(opt->state & (State_Enabled | State_Sunken | State_On)){ -
738 if (panel) -
739 qDrawShadePanel(p, opt->rect, opt->palette, -
740 opt->state & (State_Sunken | State_On), 1, &fill); -
741 else -
742 qDrawShadeRect(p, opt->rect, opt->palette, -
743 opt->state & (State_Sunken | State_On), 1); -
744 } -
745 if (stippled) { -
746 p->setPen(opt->palette.button().color()); -
747 p->drawRect(opt->rect.adjusted(1,1,-2,-2)); -
748 } -
749 } else { -
750 qDrawWinButton(p, opt->rect, opt->palette, -
751 opt->state & (State_Sunken | State_On), panel ? &fill : 0); -
752 } -
753 } else { -
754 p->fillRect(opt->rect, fill); -
755 } -
756 p->setPen(oldPen); -
757 break; } -
758 case PE_PanelButtonCommand: -
759 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { -
760 QBrush fill; -
761 State flags = opt->state; -
762 QPalette pal = opt->palette; -
763 QRect r = opt->rect; -
764 if (! (flags & State_Sunken) && (flags & State_On)) -
765 fill = QBrush(pal.light().color(), Qt::Dense4Pattern); -
766 else -
767 fill = pal.brush(QPalette::Button); -
768 -
769 if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) { -
770 p->setPen(pal.dark().color()); -
771 p->setBrush(fill); -
772 p->drawRect(r.adjusted(0, 0, -1, -1)); -
773 } else if (flags & (State_Raised | State_On | State_Sunken)) { -
774 qDrawWinButton(p, r, pal, flags & (State_Sunken | State_On), -
775 &fill); -
776 } else { -
777 p->fillRect(r, fill); -
778 } -
779 } -
780 break; -
781 case PE_FrameDefaultButton: { -
782 QPen oldPen = p->pen(); -
783 p->setPen(opt->palette.shadow().color()); -
784 QRect rect = opt->rect; -
785 rect.adjust(0, 0, -1, -1); -
786 p->drawRect(rect); -
787 p->setPen(oldPen); -
788 break; -
789 } -
790 case PE_IndicatorCheckBox: { -
791 QBrush fill; -
792 if (opt->state & State_NoChange) -
793 fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern); -
794 else if (opt->state & State_Sunken) -
795 fill = opt->palette.button(); -
796 else if (opt->state & State_Enabled) -
797 fill = opt->palette.base(); -
798 else -
799 fill = opt->palette.background(); -
800 p->save(); -
801 doRestore = true; -
802 qDrawWinPanel(p, opt->rect, opt->palette, true, &fill); -
803 if (opt->state & State_NoChange) -
804 p->setPen(opt->palette.dark().color()); -
805 else -
806 p->setPen(opt->palette.text().color()); -
807 } // Fall through! -
808 case PE_IndicatorViewItemCheck: -
809 if (!doRestore) { -
810 p->save(); -
811 doRestore = true; -
812 } -
813 if (pe == PE_IndicatorViewItemCheck) { -
814 const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt); -
815 p->setPen(itemViewOpt -
816 && itemViewOpt->showDecorationSelected -
817 && opt->state & State_Selected -
818 ? opt->palette.highlightedText().color() -
819 : opt->palette.text().color()); -
820 if (opt->state & State_NoChange) -
821 p->setBrush(opt->palette.brush(QPalette::Button)); -
822 p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11); -
823 } -
824 if (!(opt->state & State_Off)) { -
825 QLineF lines[7]; -
826 int i, xx, yy; -
827 xx = opt->rect.x() + 3; -
828 yy = opt->rect.y() + 5; -
829 for (i = 0; i < 3; ++i) { -
830 lines[i] = QLineF(xx, yy, xx, yy + 2); -
831 ++xx; -
832 ++yy; -
833 } -
834 yy -= 2; -
835 for (i = 3; i < 7; ++i) { -
836 lines[i] = QLineF(xx, yy, xx, yy + 2); -
837 ++xx; -
838 --yy; -
839 } -
840 p->drawLines(lines, 7); -
841 } -
842 if (doRestore) -
843 p->restore(); -
844 break; -
845 case PE_FrameFocusRect: -
846 if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) { -
847 //### check for d->alt_down -
848 if (!(fropt->state & State_KeyboardFocusChange) && !proxy()->styleHint(SH_UnderlineShortcut, opt)) -
849 return; -
850 QRect r = opt->rect; -
851 p->save(); -
852 p->setBackgroundMode(Qt::TransparentMode); -
853 QColor bg_col = fropt->backgroundColor; -
854 if (!bg_col.isValid()) -
855 bg_col = p->background().color(); -
856 // Create an "XOR" color. -
857 QColor patternCol((bg_col.red() ^ 0xff) & 0xff, -
858 (bg_col.green() ^ 0xff) & 0xff, -
859 (bg_col.blue() ^ 0xff) & 0xff); -
860 p->setBrush(QBrush(patternCol, Qt::Dense4Pattern)); -
861 p->setBrushOrigin(r.topLeft()); -
862 p->setPen(Qt::NoPen); -
863 p->drawRect(r.left(), r.top(), r.width(), 1); // Top -
864 p->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom -
865 p->drawRect(r.left(), r.top(), 1, r.height()); // Left -
866 p->drawRect(r.right(), r.top(), 1, r.height()); // Right -
867 p->restore(); -
868 } -
869 break; -
870 case PE_IndicatorRadioButton: -
871 { -
872#define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint)) -
873 static const QPoint pts1[] = { // dark lines -
874 QPoint(1, 9), QPoint(1, 8), QPoint(0, 7), QPoint(0, 4), QPoint(1, 3), QPoint(1, 2), -
875 QPoint(2, 1), QPoint(3, 1), QPoint(4, 0), QPoint(7, 0), QPoint(8, 1), QPoint(9, 1) -
876 }; -
877 static const QPoint pts2[] = { // black lines -
878 QPoint(2, 8), QPoint(1, 7), QPoint(1, 4), QPoint(2, 3), QPoint(2, 2), QPoint(3, 2), -
879 QPoint(4, 1), QPoint(7, 1), QPoint(8, 2), QPoint(9, 2) -
880 }; -
881 static const QPoint pts3[] = { // background lines -
882 QPoint(2, 9), QPoint(3, 9), QPoint(4, 10), QPoint(7, 10), QPoint(8, 9), QPoint(9, 9), -
883 QPoint(9, 8), QPoint(10, 7), QPoint(10, 4), QPoint(9, 3) -
884 }; -
885 static const QPoint pts4[] = { // white lines -
886 QPoint(2, 10), QPoint(3, 10), QPoint(4, 11), QPoint(7, 11), QPoint(8, 10), -
887 QPoint(9, 10), QPoint(10, 9), QPoint(10, 8), QPoint(11, 7), QPoint(11, 4), -
888 QPoint(10, 3), QPoint(10, 2) -
889 }; -
890 static const QPoint pts5[] = { // inner fill -
891 QPoint(4, 2), QPoint(7, 2), QPoint(9, 4), QPoint(9, 7), QPoint(7, 9), QPoint(4, 9), -
892 QPoint(2, 7), QPoint(2, 4) -
893 }; -
894 -
895 // make sure the indicator is square -
896 QRect ir = opt->rect; -
897 -
898 if (opt->rect.width() < opt->rect.height()) { -
899 ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2); -
900 ir.setHeight(opt->rect.width()); -
901 } else if (opt->rect.height() < opt->rect.width()) { -
902 ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2); -
903 ir.setWidth(opt->rect.height()); -
904 } -
905 -
906 p->save(); -
907 p->setRenderHint(QPainter::Qt4CompatiblePainting); -
908 bool down = opt->state & State_Sunken; -
909 bool enabled = opt->state & State_Enabled; -
910 bool on = opt->state & State_On; -
911 QPolygon a; -
912 -
913 //center when rect is larger than indicator size -
914 int xOffset = 0; -
915 int yOffset = 0; -
916 int indicatorWidth = proxy()->pixelMetric(PM_ExclusiveIndicatorWidth); -
917 int indicatorHeight = proxy()->pixelMetric(PM_ExclusiveIndicatorWidth); -
918 if (ir.width() > indicatorWidth) -
919 xOffset += (ir.width() - indicatorWidth)/2; -
920 if (ir.height() > indicatorHeight) -
921 yOffset += (ir.height() - indicatorHeight)/2; -
922 p->translate(xOffset, yOffset); -
923 -
924 p->translate(ir.x(), ir.y()); -
925 -
926 p->setPen(opt->palette.dark().color()); -
927 p->drawPolyline(pts1, PTSARRLEN(pts1)); -
928 -
929 p->setPen(opt->palette.shadow().color()); -
930 p->drawPolyline(pts2, PTSARRLEN(pts2)); -
931 -
932 p->setPen(opt->palette.midlight().color()); -
933 p->drawPolyline(pts3, PTSARRLEN(pts3)); -
934 -
935 p->setPen(opt->palette.light().color()); -
936 p->drawPolyline(pts4, PTSARRLEN(pts4)); -
937 -
938 QColor fillColor = (down || !enabled) -
939 ? opt->palette.button().color() -
940 : opt->palette.base().color(); -
941 p->setPen(fillColor); -
942 p->setBrush(fillColor) ; -
943 p->drawPolygon(pts5, PTSARRLEN(pts5)); -
944 -
945 p->translate(-ir.x(), -ir.y()); // restore translate -
946 -
947 if (on) { -
948 p->setPen(Qt::NoPen); -
949 p->setBrush(opt->palette.text()); -
950 p->drawRect(ir.x() + 5, ir.y() + 4, 2, 4); -
951 p->drawRect(ir.x() + 4, ir.y() + 5, 4, 2); -
952 } -
953 p->restore(); -
954 break; -
955 } -
956#ifndef QT_NO_FRAME -
957 case PE_Frame: -
958 case PE_FrameMenu: -
959 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { -
960 if (frame->lineWidth == 2 || pe == PE_Frame) { -
961 QPalette popupPal = frame->palette; -
962 if (pe == PE_FrameMenu) { -
963 popupPal.setColor(QPalette::Light, frame->palette.background().color()); -
964 popupPal.setColor(QPalette::Midlight, frame->palette.light().color()); -
965 } -
966 if (pe == PE_Frame && (frame->state & State_Raised)) -
967 qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken); -
968 else if (pe == PE_Frame && (frame->state & State_Sunken)) -
969 { -
970 popupPal.setColor(QPalette::Midlight, frame->palette.background().color()); -
971 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken); -
972 } -
973 else -
974 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken); -
975 } else { -
976 QCommonStyle::drawPrimitive(pe, opt, p, w); -
977 } -
978 } else { -
979 QPalette popupPal = opt->palette; -
980 popupPal.setColor(QPalette::Light, opt->palette.background().color()); -
981 popupPal.setColor(QPalette::Midlight, opt->palette.light().color()); -
982 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken); -
983 } -
984 break; -
985#endif // QT_NO_FRAME -
986 case PE_FrameButtonBevel: -
987 case PE_PanelButtonBevel: { -
988 QBrush fill; -
989 bool panel = pe != PE_FrameButtonBevel; -
990 p->setBrushOrigin(opt->rect.topLeft()); -
991 if (!(opt->state & State_Sunken) && (opt->state & State_On)) -
992 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern); -
993 else -
994 fill = opt->palette.brush(QPalette::Button); -
995 -
996 if (opt->state & (State_Raised | State_On | State_Sunken)) { -
997 qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On), -
998 panel ? &fill : 0); -
999 } else { -
1000 if (panel) -
1001 p->fillRect(opt->rect, fill); -
1002 else -
1003 p->drawRect(opt->rect); -
1004 } -
1005 break; } -
1006 case PE_FrameWindow: { -
1007 QPalette popupPal = opt->palette; -
1008 popupPal.setColor(QPalette::Light, opt->palette.background().color()); -
1009 popupPal.setColor(QPalette::Midlight, opt->palette.light().color()); -
1010 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken); -
1011 break; } -
1012#ifndef QT_NO_DOCKWIDGET -
1013 case PE_IndicatorDockWidgetResizeHandle: -
1014 break; -
1015 case PE_FrameDockWidget: -
1016 if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) { -
1017 proxy()->drawPrimitive(QStyle::PE_FrameWindow, opt, p, w); -
1018 } -
1019 break; -
1020#endif // QT_NO_DOCKWIDGET -
1021 -
1022 case PE_FrameStatusBarItem: -
1023 qDrawShadePanel(p, opt->rect, opt->palette, true, 1, 0); -
1024 break; -
1025 -
1026 case PE_IndicatorProgressChunk: -
1027 { -
1028 bool vertical = false, inverted = false; -
1029 if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) { -
1030 vertical = (pb2->orientation == Qt::Vertical); -
1031 inverted = pb2->invertedAppearance; -
1032 } -
1033 -
1034 int space = 2; -
1035 int chunksize = proxy()->pixelMetric(PM_ProgressBarChunkWidth, opt, w) - space; -
1036 if (!vertical) { -
1037 if (opt->rect.width() <= chunksize) -
1038 space = 0; -
1039 -
1040 if (inverted) -
1041 p->fillRect(opt->rect.x() + space, opt->rect.y(), opt->rect.width() - space, opt->rect.height(), -
1042 opt->palette.brush(QPalette::Highlight)); -
1043 else -
1044 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width() - space, opt->rect.height(), -
1045 opt->palette.brush(QPalette::Highlight)); -
1046 } else { -
1047 if (opt->rect.height() <= chunksize) -
1048 space = 0; -
1049 -
1050 if (inverted) -
1051 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height() - space, -
1052 opt->palette.brush(QPalette::Highlight)); -
1053 else -
1054 p->fillRect(opt->rect.x(), opt->rect.y() + space, opt->rect.width(), opt->rect.height() - space, -
1055 opt->palette.brush(QPalette::Highlight)); -
1056 } -
1057 } -
1058 break; -
1059 -
1060 case PE_FrameTabWidget: { -
1061 qDrawWinButton(p, opt->rect, opt->palette, false, 0); -
1062 break; -
1063 } -
1064 default: -
1065 QCommonStyle::drawPrimitive(pe, opt, p, w); -
1066 } -
1067} -
1068 -
1069/*! \reimp */ -
1070void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p, -
1071 const QWidget *widget) const -
1072{ -
1073 switch (ce) { -
1074#ifndef QT_NO_RUBBERBAND -
1075 case CE_RubberBand: -
1076 if (qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) { -
1077 // ### workaround for slow general painter path -
1078 QPixmap tiledPixmap(16, 16); -
1079 QPainter pixmapPainter(&tiledPixmap); -
1080 pixmapPainter.setPen(Qt::NoPen); -
1081 pixmapPainter.setBrush(Qt::Dense4Pattern); -
1082 pixmapPainter.setBackground(Qt::white); -
1083 pixmapPainter.setBackgroundMode(Qt::OpaqueMode); -
1084 pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height()); -
1085 pixmapPainter.end(); -
1086 tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage()); -
1087 p->save(); -
1088 QRect r = opt->rect; -
1089 QStyleHintReturnMask mask; -
1090 if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask)) -
1091 p->setClipRegion(mask.region); -
1092 p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap); -
1093 p->restore(); -
1094 return; -
1095 } -
1096 break; -
1097#endif // QT_NO_RUBBERBAND -
1098 -
1099#if !defined(QT_NO_MENU) && !defined(QT_NO_MAINWINDOW) -
1100 case CE_MenuBarEmptyArea: -
1101 if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) { -
1102 p->fillRect(opt->rect, opt->palette.button()); -
1103 QPen oldPen = p->pen(); -
1104 p->setPen(QPen(opt->palette.dark().color())); -
1105 p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight()); -
1106 p->setPen(oldPen); -
1107 } -
1108 break; -
1109#endif -
1110#ifndef QT_NO_MENU -
1111 case CE_MenuItem: -
1112 if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { -
1113 int x, y, w, h; -
1114 menuitem->rect.getRect(&x, &y, &w, &h); -
1115 int tab = menuitem->tabWidth; -
1116 bool dis = !(menuitem->state & State_Enabled); -
1117 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable -
1118 ? menuitem->checked : false; -
1119 bool act = menuitem->state & State_Selected; -
1120 -
1121 // windows always has a check column, regardless whether we have an icon or not -
1122 int checkcol = qMax<int>(menuitem->maxIconWidth, QWindowsStylePrivate::windowsCheckMarkWidth); -
1123 -
1124 QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button); -
1125 p->fillRect(menuitem->rect.adjusted(0, 0, -1, 0), fill); -
1126 -
1127 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){ -
1128 int yoff = y-1 + h / 2; -
1129 p->setPen(menuitem->palette.dark().color()); -
1130 p->drawLine(x + 2, yoff, x + w - 4, yoff); -
1131 p->setPen(menuitem->palette.light().color()); -
1132 p->drawLine(x + 2, yoff + 1, x + w - 4, yoff + 1); -
1133 return; -
1134 } -
1135 -
1136 QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height())); -
1137 if (!menuitem->icon.isNull() && checked) { -
1138 if (act) { -
1139 qDrawShadePanel(p, vCheckRect, -
1140 menuitem->palette, true, 1, -
1141 &menuitem->palette.brush(QPalette::Button)); -
1142 } else { -
1143 QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern); -
1144 qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill); -
1145 } -
1146 } else if (!act) { -
1147 p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button)); -
1148 } -
1149 -
1150 // On Windows Style, if we have a checkable item and an icon we -
1151 // draw the icon recessed to indicate an item is checked. If we -
1152 // have no icon, we draw a checkmark instead. -
1153 if (!menuitem->icon.isNull()) { -
1154 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; -
1155 if (act && !dis) -
1156 mode = QIcon::Active; -
1157 QPixmap pixmap; -
1158 if (checked) -
1159 pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode, QIcon::On); -
1160 else -
1161 pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode); -
1162 int pixw = pixmap.width(); -
1163 int pixh = pixmap.height(); -
1164 if (act && !dis && !checked) -
1165 qDrawShadePanel(p, vCheckRect, menuitem->palette, false, 1, -
1166 &menuitem->palette.brush(QPalette::Button)); -
1167 QRect pmr(0, 0, pixw, pixh); -
1168 pmr.moveCenter(vCheckRect.center()); -
1169 p->setPen(menuitem->palette.text().color()); -
1170 p->drawPixmap(pmr.topLeft(), pixmap); -
1171 } else if (checked) { -
1172 QStyleOptionMenuItem newMi = *menuitem; -
1173 newMi.state = State_None; -
1174 if (!dis) -
1175 newMi.state |= State_Enabled; -
1176 if (act) -
1177 newMi.state |= State_On; -
1178 newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + QWindowsStylePrivate::windowsItemFrame, -
1179 menuitem->rect.y() + QWindowsStylePrivate::windowsItemFrame, -
1180 checkcol - 2 * QWindowsStylePrivate::windowsItemFrame, -
1181 menuitem->rect.height() - 2 * QWindowsStylePrivate::windowsItemFrame)); -
1182 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget); -
1183 } -
1184 p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color()); -
1185 -
1186 QColor discol; -
1187 if (dis) { -
1188 discol = menuitem->palette.text().color(); -
1189 p->setPen(discol); -
1190 } -
1191 -
1192 int xm = int(QWindowsStylePrivate::windowsItemFrame) + checkcol + int(QWindowsStylePrivate::windowsItemHMargin); -
1193 int xpos = menuitem->rect.x() + xm; -
1194 QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin, -
1195 w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin); -
1196 QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect); -
1197 QString s = menuitem->text; -
1198 if (!s.isEmpty()) { // draw text -
1199 p->save(); -
1200 int t = s.indexOf(QLatin1Char('\t')); -
1201 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; -
1202 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget)) -
1203 text_flags |= Qt::TextHideMnemonic; -
1204 text_flags |= Qt::AlignLeft; -
1205 if (t >= 0) { -
1206 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect, -
1207 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom()))); -
1208 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) { -
1209 p->setPen(menuitem->palette.light().color()); -
1210 p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1)); -
1211 p->setPen(discol); -
1212 } -
1213 p->drawText(vShortcutRect, text_flags, s.mid(t + 1)); -
1214 s = s.left(t); -
1215 } -
1216 QFont font = menuitem->font; -
1217 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem) -
1218 font.setBold(true); -
1219 p->setFont(font); -
1220 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) { -
1221 p->setPen(menuitem->palette.light().color()); -
1222 p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t)); -
1223 p->setPen(discol); -
1224 } -
1225 p->drawText(vTextRect, text_flags, s.left(t)); -
1226 p->restore(); -
1227 } -
1228 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow -
1229 int dim = (h - 2 * QWindowsStylePrivate::windowsItemFrame) / 2; -
1230 PrimitiveElement arrow; -
1231 arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight; -
1232 xpos = x + w - QWindowsStylePrivate::windowsArrowHMargin - QWindowsStylePrivate::windowsItemFrame - dim; -
1233 QRect vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim)); -
1234 QStyleOptionMenuItem newMI = *menuitem; -
1235 newMI.rect = vSubMenuRect; -
1236 newMI.state = dis ? State_None : State_Enabled; -
1237 if (act) -
1238 newMI.palette.setColor(QPalette::ButtonText, -
1239 newMI.palette.highlightedText().color()); -
1240 proxy()->drawPrimitive(arrow, &newMI, p, widget); -
1241 } -
1242 -
1243 } -
1244 break; -
1245#endif // QT_NO_MENU -
1246#ifndef QT_NO_MENUBAR -
1247 case CE_MenuBarItem: -
1248 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { -
1249 bool active = mbi->state & State_Selected; -
1250 bool hasFocus = mbi->state & State_HasFocus; -
1251 bool down = mbi->state & State_Sunken; -
1252 QStyleOptionMenuItem newMbi = *mbi; -
1253 p->fillRect(mbi->rect, mbi->palette.brush(QPalette::Button)); -
1254 if (active || hasFocus) { -
1255 QBrush b = mbi->palette.brush(QPalette::Button); -
1256 if (active && down) -
1257 p->setBrushOrigin(p->brushOrigin() + QPoint(1, 1)); -
1258 if (active && hasFocus) -
1259 qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(), -
1260 mbi->rect.height(), mbi->palette, active && down, 1, 0, &b); -
1261 if (active && down) { -
1262 newMbi.rect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, mbi, widget), -
1263 proxy()->pixelMetric(PM_ButtonShiftVertical, mbi, widget)); -
1264 p->setBrushOrigin(p->brushOrigin() - QPoint(1, 1)); -
1265 } -
1266 } -
1267 QCommonStyle::drawControl(ce, &newMbi, p, widget); -
1268 } -
1269 break; -
1270#endif // QT_NO_MENUBAR -
1271#ifndef QT_NO_TABBAR -
1272 case CE_TabBarTabShape: -
1273 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { -
1274 bool rtlHorTabs = (tab->direction == Qt::RightToLeft -
1275 && (tab->shape == QTabBar::RoundedNorth -
1276 || tab->shape == QTabBar::RoundedSouth)); -
1277 bool selected = tab->state & State_Selected; -
1278 bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End) -
1279 || (rtlHorTabs -
1280 && tab->position == QStyleOptionTab::Beginning)); -
1281 bool firstTab = ((!rtlHorTabs -
1282 && tab->position == QStyleOptionTab::Beginning) -
1283 || (rtlHorTabs -
1284 && tab->position == QStyleOptionTab::End)); -
1285 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab; -
1286 bool previousSelected = -
1287 ((!rtlHorTabs -
1288 && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected) -
1289 || (rtlHorTabs -
1290 && tab->selectedPosition == QStyleOptionTab::NextIsSelected)); -
1291 bool nextSelected = -
1292 ((!rtlHorTabs -
1293 && tab->selectedPosition == QStyleOptionTab::NextIsSelected) -
1294 || (rtlHorTabs -
1295 && tab->selectedPosition -
1296 == QStyleOptionTab::PreviousIsSelected)); -
1297 int tabBarAlignment = proxy()->styleHint(SH_TabBar_Alignment, tab, widget); -
1298 bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft) -
1299 || (rtlHorTabs -
1300 && tabBarAlignment == Qt::AlignRight); -
1301 -
1302 bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight) -
1303 || (rtlHorTabs -
1304 && tabBarAlignment == Qt::AlignLeft); -
1305 -
1306 QColor light = tab->palette.light().color(); -
1307 QColor dark = tab->palette.dark().color(); -
1308 QColor shadow = tab->palette.shadow().color(); -
1309 int borderThinkness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget); -
1310 if (selected) -
1311 borderThinkness /= 2; -
1312 QRect r2(opt->rect); -
1313 int x1 = r2.left(); -
1314 int x2 = r2.right(); -
1315 int y1 = r2.top(); -
1316 int y2 = r2.bottom(); -
1317 switch (tab->shape) { -
1318 default: -
1319 QCommonStyle::drawControl(ce, tab, p, widget); -
1320 break; -
1321 case QTabBar::RoundedNorth: { -
1322 if (!selected) { -
1323 y1 += 2; -
1324 x1 += onlyOne || firstTab ? borderThinkness : 0; -
1325 x2 -= onlyOne || lastTab ? borderThinkness : 0; -
1326 } -
1327 -
1328 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.background()); -
1329 -
1330 // Delete border -
1331 if (selected) { -
1332 p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.background()); -
1333 p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.background()); -
1334 } -
1335 // Left -
1336 if (firstTab || selected || onlyOne || !previousSelected) { -
1337 p->setPen(light); -
1338 p->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness)); -
1339 p->drawPoint(x1 + 1, y1 + 1); -
1340 } -
1341 // Top -
1342 { -
1343 int beg = x1 + (previousSelected ? 0 : 2); -
1344 int end = x2 - (nextSelected ? 0 : 2); -
1345 p->setPen(light); -
1346 p->drawLine(beg, y1, end, y1); -
1347 } -
1348 // Right -
1349 if (lastTab || selected || onlyOne || !nextSelected) { -
1350 p->setPen(shadow); -
1351 p->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness)); -
1352 p->drawPoint(x2 - 1, y1 + 1); -
1353 p->setPen(dark); -
1354 p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness)); -
1355 } -
1356 break; } -
1357 case QTabBar::RoundedSouth: { -
1358 if (!selected) { -
1359 y2 -= 2; -
1360 x1 += firstTab ? borderThinkness : 0; -
1361 x2 -= lastTab ? borderThinkness : 0; -
1362 } -
1363 -
1364 p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background()); -
1365 -
1366 // Delete border -
1367 if (selected) { -
1368 p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.background()); -
1369 p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.background()); -
1370 } -
1371 // Left -
1372 if (firstTab || selected || onlyOne || !previousSelected) { -
1373 p->setPen(light); -
1374 p->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness)); -
1375 p->drawPoint(x1 + 1, y2 - 1); -
1376 } -
1377 // Bottom -
1378 { -
1379 int beg = x1 + (previousSelected ? 0 : 2); -
1380 int end = x2 - (nextSelected ? 0 : 2); -
1381 p->setPen(shadow); -
1382 p->drawLine(beg, y2, end, y2); -
1383 p->setPen(dark); -
1384 p->drawLine(beg, y2 - 1, end, y2 - 1); -
1385 } -
1386 // Right -
1387 if (lastTab || selected || onlyOne || !nextSelected) { -
1388 p->setPen(shadow); -
1389 p->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness)); -
1390 p->drawPoint(x2 - 1, y2 - 1); -
1391 p->setPen(dark); -
1392 p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness)); -
1393 } -
1394 break; } -
1395 case QTabBar::RoundedWest: { -
1396 if (!selected) { -
1397 x1 += 2; -
1398 y1 += firstTab ? borderThinkness : 0; -
1399 y2 -= lastTab ? borderThinkness : 0; -
1400 } -
1401 -
1402 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.background()); -
1403 -
1404 // Delete border -
1405 if (selected) { -
1406 p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.background()); -
1407 p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.background()); -
1408 } -
1409 // Top -
1410 if (firstTab || selected || onlyOne || !previousSelected) { -
1411 p->setPen(light); -
1412 p->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1); -
1413 p->drawPoint(x1 + 1, y1 + 1); -
1414 } -
1415 // Left -
1416 { -
1417 int beg = y1 + (previousSelected ? 0 : 2); -
1418 int end = y2 - (nextSelected ? 0 : 2); -
1419 p->setPen(light); -
1420 p->drawLine(x1, beg, x1, end); -
1421 } -
1422 // Bottom -
1423 if (lastTab || selected || onlyOne || !nextSelected) { -
1424 p->setPen(shadow); -
1425 p->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2); -
1426 p->drawPoint(x1 + 2, y2 - 1); -
1427 p->setPen(dark); -
1428 p->drawLine(x1 + 3, y2 - 1, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1); -
1429 p->drawPoint(x1 + 1, y2 - 1); -
1430 p->drawPoint(x1 + 2, y2); -
1431 } -
1432 break; } -
1433 case QTabBar::RoundedEast: { -
1434 if (!selected) { -
1435 x2 -= 2; -
1436 y1 += firstTab ? borderThinkness : 0; -
1437 y2 -= lastTab ? borderThinkness : 0; -
1438 } -
1439 -
1440 p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background()); -
1441 -
1442 // Delete border -
1443 if (selected) { -
1444 p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.background()); -
1445 p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.background()); -
1446 } -
1447 // Top -
1448 if (firstTab || selected || onlyOne || !previousSelected) { -
1449 p->setPen(light); -
1450 p->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1); -
1451 p->drawPoint(x2 - 1, y1 + 1); -
1452 } -
1453 // Right -
1454 { -
1455 int beg = y1 + (previousSelected ? 0 : 2); -
1456 int end = y2 - (nextSelected ? 0 : 2); -
1457 p->setPen(shadow); -
1458 p->drawLine(x2, beg, x2, end); -
1459 p->setPen(dark); -
1460 p->drawLine(x2 - 1, beg, x2 - 1, end); -
1461 } -
1462 // Bottom -
1463 if (lastTab || selected || onlyOne || !nextSelected) { -
1464 p->setPen(shadow); -
1465 p->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2); -
1466 p->drawPoint(x2 - 1, y2 - 1); -
1467 p->setPen(dark); -
1468 p->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1); -
1469 } -
1470 break; } -
1471 } -
1472 } -
1473 break; -
1474#endif // QT_NO_TABBAR -
1475 case CE_ToolBoxTabShape: -
1476 qDrawShadePanel(p, opt->rect, opt->palette, -
1477 opt->state & (State_Sunken | State_On), 1, -
1478 &opt->palette.brush(QPalette::Button)); -
1479 break; -
1480#ifndef QT_NO_SPLITTER -
1481 case CE_Splitter: -
1482 p->eraseRect(opt->rect); -
1483 break; -
1484#endif // QT_NO_SPLITTER -
1485#ifndef QT_NO_SCROLLBAR -
1486 case CE_ScrollBarSubLine: -
1487 case CE_ScrollBarAddLine: { -
1488 if ((opt->state & State_Sunken)) { -
1489 p->setPen(opt->palette.dark().color()); -
1490 p->setBrush(opt->palette.brush(QPalette::Button)); -
1491 p->drawRect(opt->rect.adjusted(0, 0, -1, -1)); -
1492 } else { -
1493 QStyleOption buttonOpt = *opt; -
1494 if (!(buttonOpt.state & State_Sunken)) -
1495 buttonOpt.state |= State_Raised; -
1496 QPalette pal(opt->palette); -
1497 pal.setColor(QPalette::Button, opt->palette.light().color()); -
1498 pal.setColor(QPalette::Light, opt->palette.button().color()); -
1499 qDrawWinButton(p, opt->rect, pal, opt->state & (State_Sunken | State_On), -
1500 &opt->palette.brush(QPalette::Button)); -
1501 } -
1502 PrimitiveElement arrow; -
1503 if (opt->state & State_Horizontal) { -
1504 if (ce == CE_ScrollBarAddLine) -
1505 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft; -
1506 else -
1507 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight; -
1508 } else { -
1509 if (ce == CE_ScrollBarAddLine) -
1510 arrow = PE_IndicatorArrowDown; -
1511 else -
1512 arrow = PE_IndicatorArrowUp; -
1513 } -
1514 QStyleOption arrowOpt = *opt; -
1515 arrowOpt.rect = opt->rect.adjusted(4, 4, -4, -4); -
1516 proxy()->drawPrimitive(arrow, &arrowOpt, p, widget); -
1517 break; } -
1518 case CE_ScrollBarAddPage: -
1519 case CE_ScrollBarSubPage: { -
1520 QBrush br; -
1521 QBrush bg = p->background(); -
1522 Qt::BGMode bg_mode = p->backgroundMode(); -
1523 p->setPen(Qt::NoPen); -
1524 p->setBackgroundMode(Qt::OpaqueMode); -
1525 -
1526 if (opt->state & State_Sunken) { -
1527 br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern); -
1528 p->setBackground(opt->palette.dark().color()); -
1529 p->setBrush(br); -
1530 } else { -
1531 QPixmap pm = opt->palette.brush(QPalette::Light).texture(); -
1532 br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern); -
1533 p->setBackground(opt->palette.background().color()); -
1534 p->setBrush(br); -
1535 } -
1536 p->drawRect(opt->rect); -
1537 p->setBackground(bg); -
1538 p->setBackgroundMode(bg_mode); -
1539 break; } -
1540 case CE_ScrollBarSlider: -
1541 if (!(opt->state & State_Enabled)) { -
1542 QPixmap pm = opt->palette.brush(QPalette::Light).texture(); -
1543 QBrush br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern); -
1544 p->setPen(Qt::NoPen); -
1545 p->setBrush(br); -
1546 p->setBackgroundMode(Qt::OpaqueMode); -
1547 p->drawRect(opt->rect); -
1548 } else { -
1549 QStyleOptionButton buttonOpt; -
1550 buttonOpt.QStyleOption::operator=(*opt); -
1551 buttonOpt.state = State_Enabled | State_Raised; -
1552 -
1553 QPalette pal(opt->palette); -
1554 pal.setColor(QPalette::Button, opt->palette.light().color()); -
1555 pal.setColor(QPalette::Light, opt->palette.button().color()); -
1556 qDrawWinButton(p, opt->rect, pal, false, &opt->palette.brush(QPalette::Button)); -
1557 } -
1558 break; -
1559#endif // QT_NO_SCROLLBAR -
1560 case CE_HeaderSection: { -
1561 QBrush fill; -
1562 if (opt->state & State_On) -
1563 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern); -
1564 else -
1565 fill = opt->palette.brush(QPalette::Button); -
1566 -
1567 if (opt->state & (State_Raised | State_Sunken)) { -
1568 qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill); -
1569 } else { -
1570 p->fillRect(opt->rect, fill); -
1571 } -
1572 break; } -
1573#ifndef QT_NO_TOOLBAR -
1574 case CE_ToolBar: -
1575 if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) { -
1576 // Reserve the beveled appearance only for mainwindow toolbars -
1577 if (!(widget && qobject_cast<const QMainWindow*> (widget->parentWidget()))) -
1578 break; -
1579 -
1580 QRect rect = opt->rect; -
1581 bool paintLeftBorder = true; -
1582 bool paintRightBorder = true; -
1583 bool paintBottomBorder = true; -
1584 -
1585 switch (toolbar->toolBarArea){ -
1586 case Qt::BottomToolBarArea : -
1587 switch(toolbar->positionOfLine){ -
1588 case QStyleOptionToolBar::Beginning: -
1589 case QStyleOptionToolBar::OnlyOne: -
1590 paintBottomBorder = false; -
1591 default: -
1592 break; -
1593 } -
1594 case Qt::TopToolBarArea : -
1595 switch(toolbar->positionWithinLine){ -
1596 case QStyleOptionToolBar::Beginning: -
1597 paintLeftBorder = false; -
1598 break; -
1599 case QStyleOptionToolBar::End: -
1600 paintRightBorder = false; -
1601 break; -
1602 case QStyleOptionToolBar::OnlyOne: -
1603 paintRightBorder = false; -
1604 paintLeftBorder = false; -
1605 default: -
1606 break; -
1607 } -
1608 if(opt->direction == Qt::RightToLeft){ //reverse layout changes the order of Beginning/end -
1609 bool tmp = paintLeftBorder; -
1610 paintRightBorder=paintLeftBorder; -
1611 paintLeftBorder=tmp; -
1612 } -
1613 break; -
1614 case Qt::RightToolBarArea : -
1615 switch (toolbar->positionOfLine){ -
1616 case QStyleOptionToolBar::Beginning: -
1617 case QStyleOptionToolBar::OnlyOne: -
1618 paintRightBorder = false; -
1619 break; -
1620 default: -
1621 break; -
1622 } -
1623 break; -
1624 case Qt::LeftToolBarArea : -
1625 switch (toolbar->positionOfLine){ -
1626 case QStyleOptionToolBar::Beginning: -
1627 case QStyleOptionToolBar::OnlyOne: -
1628 paintLeftBorder = false; -
1629 break; -
1630 default: -
1631 break; -
1632 } -
1633 break; -
1634 default: -
1635 break; -
1636 } -
1637 -
1638 -
1639 //draw top border -
1640 p->setPen(QPen(opt->palette.light().color())); -
1641 p->drawLine(rect.topLeft().x(), -
1642 rect.topLeft().y(), -
1643 rect.topRight().x(), -
1644 rect.topRight().y()); -
1645 -
1646 if (paintLeftBorder){ -
1647 p->setPen(QPen(opt->palette.light().color())); -
1648 p->drawLine(rect.topLeft().x(), -
1649 rect.topLeft().y(), -
1650 rect.bottomLeft().x(), -
1651 rect.bottomLeft().y()); -
1652 } -
1653 -
1654 if (paintRightBorder){ -
1655 p->setPen(QPen(opt->palette.dark().color())); -
1656 p->drawLine(rect.topRight().x(), -
1657 rect.topRight().y(), -
1658 rect.bottomRight().x(), -
1659 rect.bottomRight().y()); -
1660 } -
1661 -
1662 if (paintBottomBorder){ -
1663 p->setPen(QPen(opt->palette.dark().color())); -
1664 p->drawLine(rect.bottomLeft().x(), -
1665 rect.bottomLeft().y(), -
1666 rect.bottomRight().x(), -
1667 rect.bottomRight().y()); -
1668 } -
1669 } -
1670 break; -
1671 -
1672 -
1673#endif // QT_NO_TOOLBAR -
1674 -
1675 case CE_ProgressBarContents: -
1676 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { -
1677 QRect rect = pb->rect; -
1678 if (!rect.isValid()) -
1679 return; -
1680 -
1681 bool vertical = false; -
1682 bool inverted = false; -
1683 -
1684 // Get extra style options if version 2 -
1685 const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt); -
1686 if (pb2) { -
1687 vertical = (pb2->orientation == Qt::Vertical); -
1688 inverted = pb2->invertedAppearance; -
1689 } -
1690 QMatrix m; -
1691 if (vertical) { -
1692 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width()); // flip width and height -
1693 m.rotate(90); -
1694 m.translate(0, -(rect.height() + rect.y()*2)); -
1695 } -
1696 QPalette pal2 = pb->palette; -
1697 // Correct the highlight color if it is the same as the background -
1698 if (pal2.highlight() == pal2.background()) -
1699 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active, -
1700 QPalette::Highlight)); -
1701 bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical); -
1702 if (inverted) -
1703 reverse = !reverse; -
1704 int w = rect.width(); -
1705 Q_D(const QWindowsStyle); -
1706 if (pb->minimum == 0 && pb->maximum == 0) { -
1707 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget); -
1708 QStyleOptionProgressBarV2 pbBits = *pb; -
1709 Q_ASSERT(unit_width >0); -
1710 -
1711 pbBits.rect = rect; -
1712 pbBits.palette = pal2; -
1713 -
1714 int step = 0; -
1715 int chunkCount = w / unit_width + 1; -
1716 if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject))) -
1717 step = (animation->animationStep() / 3) % chunkCount; -
1718 else -
1719 d->startAnimation(new QProgressStyleAnimation(d->animationFps, opt->styleObject)); -
1720 int chunksInRow = 5; -
1721 int myY = pbBits.rect.y(); -
1722 int myHeight = pbBits.rect.height(); -
1723 int chunksToDraw = chunksInRow; -
1724 -
1725 if(step > chunkCount - 5)chunksToDraw = (chunkCount - step); -
1726 p->save(); -
1727 p->setClipRect(m.mapRect(QRectF(rect)).toRect()); -
1728 -
1729 int x0 = reverse ? rect.left() + rect.width() - unit_width*(step) - unit_width : rect.left() + unit_width * step; -
1730 int x = 0; -
1731 -
1732 for (int i = 0; i < chunksToDraw ; ++i) { -
1733 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight); -
1734 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect(); -
1735 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget); -
1736 x += reverse ? -unit_width : unit_width; -
1737 } -
1738 //Draw wrap-around chunks -
1739 if( step > chunkCount-5){ -
1740 x0 = reverse ? rect.left() + rect.width() - unit_width : rect.left() ; -
1741 x = 0; -
1742 int chunksToDraw = step - (chunkCount - chunksInRow); -
1743 for (int i = 0; i < chunksToDraw ; ++i) { -
1744 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight); -
1745 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect(); -
1746 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget); -
1747 x += reverse ? -unit_width : unit_width; -
1748 } -
1749 } -
1750 p->restore(); //restore state -
1751 } -
1752 else { -
1753 d->stopAnimation(opt->styleObject); -
1754 QCommonStyle::drawControl(ce, opt, p, widget); -
1755 } -
1756 } -
1757 break; -
1758 -
1759#ifndef QT_NO_DOCKWIDGET -
1760 case CE_DockWidgetTitle: -
1761 -
1762 if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) { -
1763 Q_D(const QWindowsStyle); -
1764 -
1765 const QStyleOptionDockWidgetV2 *v2 -
1766 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt); -
1767 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar; -
1768 -
1769 QRect rect = dwOpt->rect; -
1770 QRect r = rect; -
1771 -
1772 if (verticalTitleBar) { -
1773 QSize s = r.size(); -
1774 s.transpose(); -
1775 r.setSize(s); -
1776 -
1777 p->save(); -
1778 p->translate(r.left(), r.top() + r.width()); -
1779 p->rotate(-90); -
1780 p->translate(-r.left(), -r.top()); -
1781 } -
1782 -
1783 bool floating = false; -
1784 bool active = dwOpt->state & State_Active; -
1785 QColor inactiveCaptionTextColor = d->inactiveCaptionText; -
1786 if (dwOpt->movable) { -
1787 QColor left, right; -
1788 -
1789 //Titlebar gradient -
1790 if (widget && widget->isWindow()) { -
1791 floating = true; -
1792 if (active) { -
1793 left = d->activeCaptionColor; -
1794 right = d->activeGradientCaptionColor; -
1795 } else { -
1796 left = d->inactiveCaptionColor; -
1797 right = d->inactiveGradientCaptionColor; -
1798 } -
1799 QBrush fillBrush(left); -
1800 if (left != right) { -
1801 QPoint p1(r.x(), r.top() + r.height()/2); -
1802 QPoint p2(rect.right(), r.top() + r.height()/2); -
1803 QLinearGradient lg(p1, p2); -
1804 lg.setColorAt(0, left); -
1805 lg.setColorAt(1, right); -
1806 fillBrush = lg; -
1807 } -
1808 p->fillRect(r.adjusted(0, 0, 0, -3), fillBrush); -
1809 } -
1810 } -
1811 if (!dwOpt->title.isEmpty()) { -
1812 QFont oldFont = p->font(); -
1813 if (floating) { -
1814 QFont font = oldFont; -
1815 font.setBold(true); -
1816 p->setFont(font); -
1817 } -
1818 QPalette palette = dwOpt->palette; -
1819 palette.setColor(QPalette::Window, inactiveCaptionTextColor); -
1820 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, opt, widget); -
1821 if (verticalTitleBar) { -
1822 titleRect = QRect(r.left() + rect.bottom() -
1823 - titleRect.bottom(), -
1824 r.top() + titleRect.left() - rect.left(), -
1825 titleRect.height(), titleRect.width()); -
1826 } -
1827 proxy()->drawItemText(p, titleRect, -
1828 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, palette, -
1829 dwOpt->state & State_Enabled, dwOpt->title, -
1830 floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText); -
1831 p->setFont(oldFont); -
1832 } -
1833 if (verticalTitleBar) -
1834 p->restore(); -
1835 } -
1836 return; -
1837#endif // QT_NO_DOCKWIDGET -
1838 default: -
1839 QCommonStyle::drawControl(ce, opt, p, widget); -
1840 } -
1841} -
1842 -
1843/*! \reimp */ -
1844QRect QWindowsStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const -
1845{ -
1846 QRect r; -
1847 switch (sr) { -
1848 case SE_SliderFocusRect: -
1849 case SE_ToolBoxTabContents: -
1850 r = visualRect(opt->direction, opt->rect, opt->rect); -
1851 break; -
1852 case SE_DockWidgetTitleBarText: { -
1853 r = QCommonStyle::subElementRect(sr, opt, w); -
1854 const QStyleOptionDockWidgetV2 *v2 -
1855 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt); -
1856 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar; -
1857 int m = proxy()->pixelMetric(PM_DockWidgetTitleMargin, opt, w); -
1858 if (verticalTitleBar) { -
1859 r.adjust(0, 0, 0, -m); -
1860 } else { -
1861 if (opt->direction == Qt::LeftToRight) -
1862 r.adjust(m, 0, 0, 0); -
1863 else -
1864 r.adjust(0, 0, -m, 0); -
1865 } -
1866 break; -
1867 } -
1868 case SE_ProgressBarContents: -
1869 r = QCommonStyle::subElementRect(SE_ProgressBarGroove, opt, w); -
1870 r.adjust(3, 3, -3, -3); -
1871 break; -
1872 default: -
1873 r = QCommonStyle::subElementRect(sr, opt, w); -
1874 } -
1875 return r; -
1876} -
1877 -
1878 -
1879/*! \reimp */ -
1880void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, -
1881 QPainter *p, const QWidget *widget) const -
1882{ -
1883 switch (cc) { -
1884#ifndef QT_NO_SLIDER -
1885 case CC_Slider: -
1886 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { -
1887 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget); -
1888 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget); -
1889 int ticks = slider->tickPosition; -
1890 QRect groove = proxy()->subControlRect(CC_Slider, slider, SC_SliderGroove, widget); -
1891 QRect handle = proxy()->subControlRect(CC_Slider, slider, SC_SliderHandle, widget); -
1892 -
1893 if ((slider->subControls & SC_SliderGroove) && groove.isValid()) { -
1894 int mid = thickness / 2; -
1895 -
1896 if (ticks & QSlider::TicksAbove) -
1897 mid += len / 8; -
1898 if (ticks & QSlider::TicksBelow) -
1899 mid -= len / 8; -
1900 -
1901 p->setPen(slider->palette.shadow().color()); -
1902 if (slider->orientation == Qt::Horizontal) { -
1903 qDrawWinPanel(p, groove.x(), groove.y() + mid - 2, -
1904 groove.width(), 4, slider->palette, true); -
1905 p->drawLine(groove.x() + 1, groove.y() + mid - 1, -
1906 groove.x() + groove.width() - 3, groove.y() + mid - 1); -
1907 } else { -
1908 qDrawWinPanel(p, groove.x() + mid - 2, groove.y(), -
1909 4, groove.height(), slider->palette, true); -
1910 p->drawLine(groove.x() + mid - 1, groove.y() + 1, -
1911 groove.x() + mid - 1, groove.y() + groove.height() - 3); -
1912 } -
1913 } -
1914 -
1915 if (slider->subControls & SC_SliderTickmarks) { -
1916 QStyleOptionSlider tmpSlider = *slider; -
1917 tmpSlider.subControls = SC_SliderTickmarks; -
1918 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget); -
1919 } -
1920 -
1921 if (slider->subControls & SC_SliderHandle) { -
1922 // 4444440 -
1923 // 4333310 -
1924 // 4322210 -
1925 // 4322210 -
1926 // 4322210 -
1927 // 4322210 -
1928 // *43210* -
1929 // **410** -
1930 // ***0*** -
1931 const QColor c0 = slider->palette.shadow().color(); -
1932 const QColor c1 = slider->palette.dark().color(); -
1933 // const QColor c2 = g.button(); -
1934 const QColor c3 = slider->palette.midlight().color(); -
1935 const QColor c4 = slider->palette.light().color(); -
1936 QBrush handleBrush; -
1937 -
1938 if (slider->state & State_Enabled) { -
1939 handleBrush = slider->palette.color(QPalette::Button); -
1940 } else { -
1941 handleBrush = QBrush(slider->palette.color(QPalette::Button), -
1942 Qt::Dense4Pattern); -
1943 } -
1944 -
1945 -
1946 int x = handle.x(), y = handle.y(), -
1947 wi = handle.width(), he = handle.height(); -
1948 -
1949 int x1 = x; -
1950 int x2 = x+wi-1; -
1951 int y1 = y; -
1952 int y2 = y+he-1; -
1953 -
1954 Qt::Orientation orient = slider->orientation; -
1955 bool tickAbove = slider->tickPosition == QSlider::TicksAbove; -
1956 bool tickBelow = slider->tickPosition == QSlider::TicksBelow; -
1957 -
1958 if (slider->state & State_HasFocus) { -
1959 QStyleOptionFocusRect fropt; -
1960 fropt.QStyleOption::operator=(*slider); -
1961 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget); -
1962 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget); -
1963 } -
1964 -
1965 if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) { -
1966 Qt::BGMode oldMode = p->backgroundMode(); -
1967 p->setBackgroundMode(Qt::OpaqueMode); -
1968 qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false, -
1969 &handleBrush); -
1970 p->setBackgroundMode(oldMode); -
1971 return; -
1972 } -
1973 -
1974 QSliderDirection dir; -
1975 -
1976 if (orient == Qt::Horizontal) -
1977 if (tickAbove) -
1978 dir = SlUp; -
1979 else -
1980 dir = SlDown; -
1981 else -
1982 if (tickAbove) -
1983 dir = SlLeft; -
1984 else -
1985 dir = SlRight; -
1986 -
1987 QPolygon a; -
1988 -
1989 int d = 0; -
1990 switch (dir) { -
1991 case SlUp: -
1992 y1 = y1 + wi/2; -
1993 d = (wi + 1) / 2 - 1; -
1994 a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d); -
1995 break; -
1996 case SlDown: -
1997 y2 = y2 - wi/2; -
1998 d = (wi + 1) / 2 - 1; -
1999 a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1); -
2000 break; -
2001 case SlLeft: -
2002 d = (he + 1) / 2 - 1; -
2003 x1 = x1 + he/2; -
2004 a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1); -
2005 break; -
2006 case SlRight: -
2007 d = (he + 1) / 2 - 1; -
2008 x2 = x2 - he/2; -
2009 a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1); -
2010 break; -
2011 } -
2012 -
2013 QBrush oldBrush = p->brush(); -
2014 bool oldQt4CompatiblePainting = p->testRenderHint(QPainter::Qt4CompatiblePainting); -
2015 p->setPen(Qt::NoPen); -
2016 p->setBrush(handleBrush); -
2017 p->setRenderHint(QPainter::Qt4CompatiblePainting); -
2018 Qt::BGMode oldMode = p->backgroundMode(); -
2019 p->setBackgroundMode(Qt::OpaqueMode); -
2020 p->drawRect(x1, y1, x2-x1+1, y2-y1+1); -
2021 p->drawPolygon(a); -
2022 p->setBrush(oldBrush); -
2023 p->setBackgroundMode(oldMode); -
2024 -
2025 if (dir != SlUp) { -
2026 p->setPen(c4); -
2027 p->drawLine(x1, y1, x2, y1); -
2028 p->setPen(c3); -
2029 p->drawLine(x1, y1+1, x2, y1+1); -
2030 } -
2031 if (dir != SlLeft) { -
2032 p->setPen(c3); -
2033 p->drawLine(x1+1, y1+1, x1+1, y2); -
2034 p->setPen(c4); -
2035 p->drawLine(x1, y1, x1, y2); -
2036 } -
2037 if (dir != SlRight) { -
2038 p->setPen(c0); -
2039 p->drawLine(x2, y1, x2, y2); -
2040 p->setPen(c1); -
2041 p->drawLine(x2-1, y1+1, x2-1, y2-1); -
2042 } -
2043 if (dir != SlDown) { -
2044 p->setPen(c0); -
2045 p->drawLine(x1, y2, x2, y2); -
2046 p->setPen(c1); -
2047 p->drawLine(x1+1, y2-1, x2-1, y2-1); -
2048 } -
2049 -
2050 switch (dir) { -
2051 case SlUp: -
2052 p->setPen(c4); -
2053 p->drawLine(x1, y1, x1+d, y1-d); -
2054 p->setPen(c0); -
2055 d = wi - d - 1; -
2056 p->drawLine(x2, y1, x2-d, y1-d); -
2057 d--; -
2058 p->setPen(c3); -
2059 p->drawLine(x1+1, y1, x1+1+d, y1-d); -
2060 p->setPen(c1); -
2061 p->drawLine(x2-1, y1, x2-1-d, y1-d); -
2062 break; -
2063 case SlDown: -
2064 p->setPen(c4); -
2065 p->drawLine(x1, y2, x1+d, y2+d); -
2066 p->setPen(c0); -
2067 d = wi - d - 1; -
2068 p->drawLine(x2, y2, x2-d, y2+d); -
2069 d--; -
2070 p->setPen(c3); -
2071 p->drawLine(x1+1, y2, x1+1+d, y2+d); -
2072 p->setPen(c1); -
2073 p->drawLine(x2-1, y2, x2-1-d, y2+d); -
2074 break; -
2075 case SlLeft: -
2076 p->setPen(c4); -
2077 p->drawLine(x1, y1, x1-d, y1+d); -
2078 p->setPen(c0); -
2079 d = he - d - 1; -
2080 p->drawLine(x1, y2, x1-d, y2-d); -
2081 d--; -
2082 p->setPen(c3); -
2083 p->drawLine(x1, y1+1, x1-d, y1+1+d); -
2084 p->setPen(c1); -
2085 p->drawLine(x1, y2-1, x1-d, y2-1-d); -
2086 break; -
2087 case SlRight: -
2088 p->setPen(c4); -
2089 p->drawLine(x2, y1, x2+d, y1+d); -
2090 p->setPen(c0); -
2091 d = he - d - 1; -
2092 p->drawLine(x2, y2, x2+d, y2-d); -
2093 d--; -
2094 p->setPen(c3); -
2095 p->drawLine(x2, y1+1, x2+d, y1+1+d); -
2096 p->setPen(c1); -
2097 p->drawLine(x2, y2-1, x2+d, y2-1-d); -
2098 break; -
2099 } -
2100 p->setRenderHint(QPainter::Qt4CompatiblePainting, oldQt4CompatiblePainting); -
2101 } -
2102 } -
2103 break; -
2104#endif // QT_NO_SLIDER -
2105#ifndef QT_NO_SCROLLBAR -
2106 case CC_ScrollBar: -
2107 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { -
2108 QStyleOptionSlider newScrollbar = *scrollbar; -
2109 if (scrollbar->minimum == scrollbar->maximum) -
2110 newScrollbar.state &= ~State_Enabled; //do not draw the slider. -
2111 QCommonStyle::drawComplexControl(cc, &newScrollbar, p, widget); -
2112 } -
2113 break; -
2114#endif // QT_NO_SCROLLBAR -
2115#ifndef QT_NO_COMBOBOX -
2116 case CC_ComboBox: -
2117 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { -
2118 QBrush editBrush = cmb->palette.brush(QPalette::Base); -
2119 if ((cmb->subControls & SC_ComboBoxFrame)) { -
2120 if (cmb->frame) { -
2121 QPalette shadePal = opt->palette; -
2122 shadePal.setColor(QPalette::Midlight, shadePal.button().color()); -
2123 qDrawWinPanel(p, opt->rect, shadePal, true, &editBrush); -
2124 } -
2125 else { -
2126 p->fillRect(opt->rect, editBrush); -
2127 } -
2128 } -
2129 if (cmb->subControls & SC_ComboBoxArrow) { -
2130 State flags = State_None; -
2131 -
2132 QRect ar = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget); -
2133 bool sunkenArrow = cmb->activeSubControls == SC_ComboBoxArrow -
2134 && cmb->state & State_Sunken; -
2135 if (sunkenArrow) { -
2136 p->setPen(cmb->palette.dark().color()); -
2137 p->setBrush(cmb->palette.brush(QPalette::Button)); -
2138 p->drawRect(ar.adjusted(0,0,-1,-1)); -
2139 } else { -
2140 // Make qDrawWinButton use the right colors for drawing the shade of the button -
2141 QPalette pal(cmb->palette); -
2142 pal.setColor(QPalette::Button, cmb->palette.light().color()); -
2143 pal.setColor(QPalette::Light, cmb->palette.button().color()); -
2144 qDrawWinButton(p, ar, pal, false, -
2145 &cmb->palette.brush(QPalette::Button)); -
2146 } -
2147 -
2148 ar.adjust(2, 2, -2, -2); -
2149 if (opt->state & State_Enabled) -
2150 flags |= State_Enabled; -
2151 if (opt->state & State_HasFocus) -
2152 flags |= State_HasFocus; -
2153 -
2154 if (sunkenArrow) -
2155 flags |= State_Sunken; -
2156 QStyleOption arrowOpt(0); -
2157 arrowOpt.rect = ar.adjusted(1, 1, -1, -1); -
2158 arrowOpt.palette = cmb->palette; -
2159 arrowOpt.state = flags; -
2160 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget); -
2161 } -
2162 -
2163 if (cmb->subControls & SC_ComboBoxEditField) { -
2164 QRect re = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget); -
2165 if (cmb->state & State_HasFocus && !cmb->editable) -
2166 p->fillRect(re.x(), re.y(), re.width(), re.height(), -
2167 cmb->palette.brush(QPalette::Highlight)); -
2168 -
2169 if (cmb->state & State_HasFocus) { -
2170 p->setPen(cmb->palette.highlightedText().color()); -
2171 p->setBackground(cmb->palette.highlight()); -
2172 -
2173 } else { -
2174 p->setPen(cmb->palette.text().color()); -
2175 p->setBackground(cmb->palette.background()); -
2176 } -
2177 -
2178 if (cmb->state & State_HasFocus && !cmb->editable) { -
2179 QStyleOptionFocusRect focus; -
2180 focus.QStyleOption::operator=(*cmb); -
2181 focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget); -
2182 focus.state |= State_FocusAtBorder; -
2183 focus.backgroundColor = cmb->palette.highlight().color(); -
2184 proxy()->drawPrimitive(PE_FrameFocusRect, &focus, p, widget); -
2185 } -
2186 } -
2187 } -
2188 break; -
2189#endif // QT_NO_COMBOBOX -
2190#ifndef QT_NO_SPINBOX -
2191 case CC_SpinBox: -
2192 if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { -
2193 QStyleOptionSpinBox copy = *sb; -
2194 PrimitiveElement pe; -
2195 bool enabled = opt->state & State_Enabled; -
2196 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) { -
2197 QBrush editBrush = sb->palette.brush(QPalette::Base); -
2198 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget); -
2199 QPalette shadePal = sb->palette; -
2200 shadePal.setColor(QPalette::Midlight, shadePal.button().color()); -
2201 qDrawWinPanel(p, r, shadePal, true, &editBrush); -
2202 } -
2203 -
2204 QPalette shadePal(opt->palette); -
2205 shadePal.setColor(QPalette::Button, opt->palette.light().color()); -
2206 shadePal.setColor(QPalette::Light, opt->palette.button().color()); -
2207 -
2208 if (sb->subControls & SC_SpinBoxUp) { -
2209 copy.subControls = SC_SpinBoxUp; -
2210 QPalette pal2 = sb->palette; -
2211 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) { -
2212 pal2.setCurrentColorGroup(QPalette::Disabled); -
2213 copy.state &= ~State_Enabled; -
2214 } -
2215 -
2216 copy.palette = pal2; -
2217 -
2218 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) { -
2219 copy.state |= State_On; -
2220 copy.state |= State_Sunken; -
2221 } else { -
2222 copy.state |= State_Raised; -
2223 copy.state &= ~State_Sunken; -
2224 } -
2225 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus -
2226 : PE_IndicatorSpinUp); -
2227 -
2228 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget); -
2229 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On), -
2230 &copy.palette.brush(QPalette::Button)); -
2231 copy.rect.adjust(4, 1, -5, -1); -
2232 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) -
2233 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) ) -
2234 { -
2235 QStyleOptionSpinBox lightCopy = copy; -
2236 lightCopy.rect.adjust(1, 1, 1, 1); -
2237 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light()); -
2238 proxy()->drawPrimitive(pe, &lightCopy, p, widget); -
2239 } -
2240 proxy()->drawPrimitive(pe, &copy, p, widget); -
2241 } -
2242 -
2243 if (sb->subControls & SC_SpinBoxDown) { -
2244 copy.subControls = SC_SpinBoxDown; -
2245 copy.state = sb->state; -
2246 QPalette pal2 = sb->palette; -
2247 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) { -
2248 pal2.setCurrentColorGroup(QPalette::Disabled); -
2249 copy.state &= ~State_Enabled; -
2250 } -
2251 copy.palette = pal2; -
2252 -
2253 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) { -
2254 copy.state |= State_On; -
2255 copy.state |= State_Sunken; -
2256 } else { -
2257 copy.state |= State_Raised; -
2258 copy.state &= ~State_Sunken; -
2259 } -
2260 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus -
2261 : PE_IndicatorSpinDown); -
2262 -
2263 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget); -
2264 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On), -
2265 &copy.palette.brush(QPalette::Button)); -
2266 copy.rect.adjust(4, 0, -5, -1); -
2267 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) -
2268 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) ) -
2269 { -
2270 QStyleOptionSpinBox lightCopy = copy; -
2271 lightCopy.rect.adjust(1, 1, 1, 1); -
2272 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light()); -
2273 proxy()->drawPrimitive(pe, &lightCopy, p, widget); -
2274 } -
2275 proxy()->drawPrimitive(pe, &copy, p, widget); -
2276 } -
2277 } -
2278 break; -
2279#endif // QT_NO_SPINBOX -
2280 -
2281 default: -
2282 QCommonStyle::drawComplexControl(cc, opt, p, widget); -
2283 } -
2284} -
2285 -
2286/*! \reimp */ -
2287QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, -
2288 const QSize &csz, const QWidget *widget) const -
2289{ -
2290 QSize sz(csz); -
2291 switch (ct) { -
2292 case CT_PushButton: -
2293 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { -
2294 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget); -
2295 int w = sz.width(), -
2296 h = sz.height(); -
2297 int defwidth = 0; -
2298 if (btn->features & QStyleOptionButton::AutoDefaultButton) -
2299 defwidth = 2 * proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget); -
2300 int minwidth = int(QStyleHelper::dpiScaled(75.)); -
2301 int minheight = int(QStyleHelper::dpiScaled(23.)); -
2302 -
2303#ifndef QT_QWS_SMALL_PUSHBUTTON -
2304 if (w < minwidth + defwidth && !btn->text.isEmpty()) -
2305 w = minwidth + defwidth; -
2306 if (h < minheight + defwidth) -
2307 h = minheight + defwidth; -
2308#endif -
2309 sz = QSize(w, h); -
2310 } -
2311 break; -
2312#ifndef QT_NO_MENU -
2313 case CT_MenuItem: -
2314 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { -
2315 int w = sz.width(); -
2316 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget); -
2317 -
2318 if (mi->menuItemType == QStyleOptionMenuItem::Separator) { -
2319 sz = QSize(10, QWindowsStylePrivate::windowsSepHeight); -
2320 } -
2321 else if (mi->icon.isNull()) { -
2322 sz.setHeight(sz.height() - 2); -
2323 w -= 6; -
2324 } -
2325 -
2326 if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull()) { -
2327 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget); -
2328 sz.setHeight(qMax(sz.height(), -
2329 mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() -
2330 + 2 * QWindowsStylePrivate::windowsItemFrame)); -
2331 } -
2332 int maxpmw = mi->maxIconWidth; -
2333 int tabSpacing = 20; -
2334 if (mi->text.contains(QLatin1Char('\t'))) -
2335 w += tabSpacing; -
2336 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu) -
2337 w += 2 * QWindowsStylePrivate::windowsArrowHMargin; -
2338 else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) { -
2339 // adjust the font and add the difference in size. -
2340 // it would be better if the font could be adjusted in the initStyleOption qmenu func!! -
2341 QFontMetrics fm(mi->font); -
2342 QFont fontBold = mi->font; -
2343 fontBold.setBold(true); -
2344 QFontMetrics fmBold(fontBold); -
2345 w += fmBold.width(mi->text) - fm.width(mi->text); -
2346 } -
2347 -
2348 int checkcol = qMax<int>(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth); // Windows always shows a check column -
2349 w += checkcol; -
2350 w += int(QWindowsStylePrivate::windowsRightBorder) + 10; -
2351 sz.setWidth(w); -
2352 } -
2353 break; -
2354#endif // QT_NO_MENU -
2355#ifndef QT_NO_MENUBAR -
2356 case CT_MenuBarItem: -
2357 if (!sz.isEmpty()) -
2358 sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2); -
2359 break; -
2360#endif -
2361 // Otherwise, fall through -
2362 case CT_ToolButton: -
2363 if (qstyleoption_cast<const QStyleOptionToolButton *>(opt)) -
2364 return sz += QSize(7, 6); -
2365 // Otherwise, fall through -
2366 -
2367 default: -
2368 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget); -
2369 } -
2370 return sz; -
2371} -
2372 -
2373/*! -
2374 \reimp -
2375*/ -
2376QIcon QWindowsStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *option, -
2377 const QWidget *widget) const -
2378{ -
2379 return QCommonStyle::standardIcon(standardIcon, option, widget); -
2380} -
2381 -
2382 -
2383 -
2384QT_END_NAMESPACE -
2385 -
2386#endif // QT_NO_STYLE_WINDOWS -
2387 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial