1 | /** $Id: VBoxAquaStyle.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Qt GUI - VBox Variation on the QAquaStyle.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include "VBoxDefs.h"
|
---|
19 | #include "VBoxAquaStyle.h"
|
---|
20 | #include <qapplication.h>
|
---|
21 | #include <qtoolbutton.h>
|
---|
22 | #include <qpushbutton.h>
|
---|
23 | #include <qpainter.h>
|
---|
24 | #include <qpixmap.h>
|
---|
25 |
|
---|
26 |
|
---|
27 | VBoxAquaStyle *VBoxAquaStyle::sInstance;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Create a VBoxAquaStyle wrapper overloading the specified QAquaStyle instance.
|
---|
31 | * @param parent QAquaStyle instance.
|
---|
32 | */
|
---|
33 | VBoxAquaStyle::VBoxAquaStyle(QStyle *parent)
|
---|
34 | : QStyle(),
|
---|
35 | mparent(parent)
|
---|
36 | {
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Create a VBoxAquaStyle wrapper overloading the specified QAquaStyle instance.
|
---|
41 | * @param parent QAquaStyle instance.
|
---|
42 | */
|
---|
43 | VBoxAquaStyle::VBoxAquaStyle(QStyle &parent)
|
---|
44 | : QStyle(),
|
---|
45 | mparent(&parent)
|
---|
46 | {
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * The main purpose here is to make sure the global
|
---|
51 | * instance doesn't die on us.
|
---|
52 | */
|
---|
53 | VBoxAquaStyle::~VBoxAquaStyle()
|
---|
54 | {
|
---|
55 | //fprintf(stderr, "~VBoxAquaStyle\n");
|
---|
56 | if (this == sInstance)
|
---|
57 | sInstance = NULL;
|
---|
58 | mparent = NULL;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Get the global VBoxAquaStyle instance.
|
---|
63 | */
|
---|
64 | /* static */VBoxAquaStyle &VBoxAquaStyle::VBoxAquaStyle::instance()
|
---|
65 | {
|
---|
66 | if (!sInstance)
|
---|
67 | sInstance = new VBoxAquaStyle(QApplication::style());
|
---|
68 | return *sInstance;
|
---|
69 | }
|
---|
70 |
|
---|
71 | // The QStyle bits we modify the behaviour of.
|
---|
72 |
|
---|
73 | void VBoxAquaStyle::drawComplexControl( ComplexControl control, QPainter *p, const QWidget *widget,
|
---|
74 | const QRect &r, const QColorGroup &cg, SFlags how/* = Style_Default*/,
|
---|
75 | SCFlags sub/* = (uint)SC_All*/, SCFlags subActive/* = SC_None*/,
|
---|
76 | const QStyleOption &foo/* = QStyleOption::Default*/ ) const
|
---|
77 | {
|
---|
78 | //fprintf(stderr, "drawComplexControl %p %x", widget, control);
|
---|
79 | if ( control == CC_ToolButton )
|
---|
80 | {
|
---|
81 | /*
|
---|
82 | * This is for the ugly tool bar buttons.
|
---|
83 | * We just drop the frame unless they are pressed down.
|
---|
84 | */
|
---|
85 | QToolButton *toolbutton = (QToolButton *)widget;
|
---|
86 | //if (toolbutton->isDown()) fprintf(stderr, " down");
|
---|
87 | if (!toolbutton->isDown())
|
---|
88 | {
|
---|
89 | if (toolbutton->hasFocus() && !toolbutton->focusProxy())
|
---|
90 | {
|
---|
91 | QRect fr = toolbutton->rect();
|
---|
92 | fr.addCoords(3, 3, -3, -3);
|
---|
93 | drawPrimitive(PE_FocusRect, p, fr, cg);
|
---|
94 | }
|
---|
95 | //fprintf(stderr, "\n");
|
---|
96 | return;
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | /* fallback */
|
---|
101 | mparent->drawComplexControl( control, p, widget, r, cg, how, sub, subActive, foo );
|
---|
102 | //fprintf(stderr, "\n");
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | // The QStyle proxying
|
---|
107 |
|
---|
108 | void VBoxAquaStyle::polish( QWidget *w )
|
---|
109 | {
|
---|
110 | //fprintf(stderr, "polish %p\n", w);
|
---|
111 | mparent->polish( w );
|
---|
112 | }
|
---|
113 |
|
---|
114 | void VBoxAquaStyle::unPolish( QWidget *w )
|
---|
115 | {
|
---|
116 | //fprintf(stderr, "unPolish %p\n", w);
|
---|
117 | mparent->unPolish( w );
|
---|
118 | }
|
---|
119 |
|
---|
120 | void VBoxAquaStyle::polish( QApplication *app )
|
---|
121 | {
|
---|
122 | mparent->polish( app );
|
---|
123 | }
|
---|
124 |
|
---|
125 | void VBoxAquaStyle::unPolish( QApplication *app )
|
---|
126 | {
|
---|
127 | mparent->unPolish( app );
|
---|
128 | }
|
---|
129 |
|
---|
130 | void VBoxAquaStyle::polish( QPalette &p )
|
---|
131 | {
|
---|
132 | mparent->polish( p );
|
---|
133 | }
|
---|
134 |
|
---|
135 | void VBoxAquaStyle::polishPopupMenu( QPopupMenu *m )
|
---|
136 | {
|
---|
137 | mparent->polishPopupMenu( m );
|
---|
138 | }
|
---|
139 |
|
---|
140 | QRect VBoxAquaStyle::itemRect( QPainter *p, const QRect &r, int flags, bool enabled,
|
---|
141 | const QPixmap *pixmap, const QString &text, int len/* = -1*/ ) const
|
---|
142 | {
|
---|
143 | return mparent->itemRect( p, r, flags, enabled, pixmap, text, len );
|
---|
144 | }
|
---|
145 |
|
---|
146 | void VBoxAquaStyle::drawItem( QPainter *p, const QRect &r, int flags, const QColorGroup &g, bool enabled,
|
---|
147 | const QPixmap *pixmap, const QString &text, int len/* = -1*/, const QColor *penColor/* = 0*/ ) const
|
---|
148 | {
|
---|
149 | //fprintf(stderr, "drawItem %p\n", pixmap);
|
---|
150 | mparent->drawItem( p, r, flags, g, enabled, pixmap, text, len, penColor );
|
---|
151 | }
|
---|
152 |
|
---|
153 | void VBoxAquaStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r, const QColorGroup &cg,
|
---|
154 | SFlags flags/* = Style_Default*/, const QStyleOption &foo/* = QStyleOption::Default*/ ) const
|
---|
155 | {
|
---|
156 | //fprintf(stderr, "drawPrimitive %x\n", pe);
|
---|
157 | mparent->drawPrimitive( pe, p, r, cg, flags, foo);
|
---|
158 | }
|
---|
159 |
|
---|
160 | void VBoxAquaStyle::drawControl( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r,
|
---|
161 | const QColorGroup &cg, SFlags how/* = Style_Default*/, const QStyleOption &foo/* = QStyleOption::Default*/ ) const
|
---|
162 | {
|
---|
163 | //fprintf(stderr, "drawControl %p %x\n", widget, element);
|
---|
164 | mparent->drawControl( element, p, widget, r, cg, how, foo );
|
---|
165 | }
|
---|
166 |
|
---|
167 | void VBoxAquaStyle::drawControlMask( ControlElement element, QPainter *p, const QWidget *widget,
|
---|
168 | const QRect &r, const QStyleOption &foo/* = QStyleOption::Default*/ ) const
|
---|
169 | {
|
---|
170 | //fprintf(stderr, "drawControlMask %p %x\n", widget, element);
|
---|
171 | mparent->drawControlMask( element, p, widget, r, foo);
|
---|
172 | }
|
---|
173 |
|
---|
174 | QRect VBoxAquaStyle::subRect( SubRect r, const QWidget *widget ) const
|
---|
175 | {
|
---|
176 | //fprintf(stderr, "subRect %p", widget);
|
---|
177 | QRect rct = mparent->subRect( r, widget );
|
---|
178 | //fprintf(stderr, " rct(%d,%d,%d,%d)\n", rct.topLeft().x(), rct.topLeft().y(), rct.bottomRight().x(),rct.bottomRight().y());
|
---|
179 | return rct;
|
---|
180 | }
|
---|
181 |
|
---|
182 | int VBoxAquaStyle::pixelMetric( PixelMetric metric, const QWidget *widget/* = 0*/ ) const
|
---|
183 | {
|
---|
184 | return mparent->pixelMetric( metric, widget );
|
---|
185 | }
|
---|
186 |
|
---|
187 | QSize VBoxAquaStyle::sizeFromContents( ContentsType contents, const QWidget *widget, const QSize &contentsSize,
|
---|
188 | const QStyleOption &foo/* = QStyleOption::Default*/ ) const
|
---|
189 | {
|
---|
190 | return mparent->sizeFromContents( contents, widget, contentsSize, foo );
|
---|
191 | }
|
---|
192 |
|
---|
193 | int VBoxAquaStyle::styleHint( StyleHint stylehint, const QWidget *widget/* = 0*/,
|
---|
194 | const QStyleOption &foo/* = QStyleOption::Default*/,
|
---|
195 | QStyleHintReturn* returnData/* = 0*/) const
|
---|
196 | {
|
---|
197 | return mparent->styleHint( stylehint, widget, foo, returnData );
|
---|
198 | }
|
---|
199 |
|
---|
200 | QPixmap VBoxAquaStyle::stylePixmap( StylePixmap stylepixmap, const QWidget *widget/* = 0*/,
|
---|
201 | const QStyleOption &foo/* = QStyleOption::Default*/ ) const
|
---|
202 | {
|
---|
203 | return mparent->stylePixmap( stylepixmap, widget, foo );
|
---|
204 | }
|
---|
205 |
|
---|
206 |
|
---|
207 | void VBoxAquaStyle::drawComplexControlMask( ComplexControl control, QPainter *p, const QWidget *widget, const QRect &r,
|
---|
208 | const QStyleOption &foo/* = QStyleOption::Default*/ ) const
|
---|
209 | {
|
---|
210 | //fprintf(stderr, "drawComplexControl %p %x\n", widget, control);
|
---|
211 | mparent->drawComplexControlMask( control, p, widget, r, foo );
|
---|
212 | }
|
---|
213 |
|
---|
214 | QRect VBoxAquaStyle::querySubControlMetrics( ComplexControl control, const QWidget *widget,
|
---|
215 | SubControl sc, const QStyleOption &foo/* = QStyleOption::Default*/ ) const
|
---|
216 | {
|
---|
217 | //fprintf(stderr, "querySubControlMetrics %p %x\n", widget, control);
|
---|
218 | return mparent->querySubControlMetrics( control, widget, sc, foo );
|
---|
219 | }
|
---|
220 |
|
---|
221 | QStyle::SubControl VBoxAquaStyle::querySubControl( ComplexControl control, const QWidget *widget, const QPoint &pos,
|
---|
222 | const QStyleOption &foo/* = QStyleOption::Default*/ ) const
|
---|
223 | {
|
---|
224 | //fprintf(stderr, "querySubControl %p %x\n", widget, control);
|
---|
225 | return mparent->querySubControl( control, widget, pos, foo );
|
---|
226 | }
|
---|
227 |
|
---|