author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
child 37 | 758a864f9613 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
/* |
|
43 |
Note: The qdoc comments for QMacStyle are contained in |
|
44 |
.../doc/src/qstyles.qdoc. |
|
45 |
*/ |
|
46 |
||
47 |
#include "qmacstyle_mac.h" |
|
48 |
||
49 |
#if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) |
|
50 |
#define QMAC_QAQUASTYLE_SIZE_CONSTRAIN |
|
51 |
//#define DEBUG_SIZE_CONSTRAINT |
|
52 |
||
53 |
#include <private/qapplication_p.h> |
|
54 |
#include <private/qcombobox_p.h> |
|
55 |
#include <private/qmacstylepixmaps_mac_p.h> |
|
56 |
#include <private/qpaintengine_mac_p.h> |
|
57 |
#include <private/qpainter_p.h> |
|
58 |
#include <private/qprintengine_mac_p.h> |
|
59 |
#include <qapplication.h> |
|
60 |
#include <qbitmap.h> |
|
61 |
#include <qcheckbox.h> |
|
62 |
#include <qcombobox.h> |
|
63 |
#include <qdialogbuttonbox.h> |
|
64 |
#include <qdockwidget.h> |
|
65 |
#include <qevent.h> |
|
66 |
#include <qfocusframe.h> |
|
67 |
#include <qformlayout.h> |
|
68 |
#include <qgroupbox.h> |
|
69 |
#include <qhash.h> |
|
70 |
#include <qheaderview.h> |
|
71 |
#include <qlayout.h> |
|
72 |
#include <qlineedit.h> |
|
73 |
#include <qlistview.h> |
|
74 |
#include <qmainwindow.h> |
|
75 |
#include <qmap.h> |
|
76 |
#include <qmenubar.h> |
|
77 |
#include <qpaintdevice.h> |
|
78 |
#include <qpainter.h> |
|
79 |
#include <qpixmapcache.h> |
|
80 |
#include <qpointer.h> |
|
81 |
#include <qprogressbar.h> |
|
82 |
#include <qpushbutton.h> |
|
83 |
#include <qradiobutton.h> |
|
84 |
#include <qrubberband.h> |
|
85 |
#include <qsizegrip.h> |
|
86 |
#include <qspinbox.h> |
|
87 |
#include <qsplitter.h> |
|
88 |
#include <qstyleoption.h> |
|
89 |
#include <qtextedit.h> |
|
90 |
#include <qtextstream.h> |
|
91 |
#include <qtoolbar.h> |
|
92 |
#include <qtoolbutton.h> |
|
93 |
#include <qtreeview.h> |
|
94 |
#include <qtableview.h> |
|
95 |
#include <qwizard.h> |
|
96 |
#include <qdebug.h> |
|
97 |
#include <qlibrary.h> |
|
98 |
#include <qdatetimeedit.h> |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
99 |
#include <qmath.h> |
0 | 100 |
#include <QtGui/qgraphicsproxywidget.h> |
101 |
#include <QtGui/qgraphicsview.h> |
|
102 |
#include <private/qt_cocoa_helpers_mac_p.h> |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
103 |
#include "qmacstyle_mac_p.h" |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
104 |
#include <private/qstylehelper_p.h> |
0 | 105 |
|
106 |
QT_BEGIN_NAMESPACE |
|
107 |
||
108 |
// The following constants are used for adjusting the size |
|
109 |
// of push buttons so that they are drawn inside their bounds. |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
110 |
const int QMacStylePrivate::PushButtonLeftOffset = 6; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
111 |
const int QMacStylePrivate::PushButtonTopOffset = 4; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
112 |
const int QMacStylePrivate::PushButtonRightOffset = 12; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
113 |
const int QMacStylePrivate::PushButtonBottomOffset = 12; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
114 |
const int QMacStylePrivate::MiniButtonH = 26; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
115 |
const int QMacStylePrivate::SmallButtonH = 30; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
116 |
const int QMacStylePrivate::BevelButtonW = 50; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
117 |
const int QMacStylePrivate::BevelButtonH = 22; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
118 |
const int QMacStylePrivate::PushButtonContentPadding = 6; |
0 | 119 |
|
120 |
// These colors specify the titlebar gradient colors on |
|
121 |
// Leopard. Ideally we should get them from the system. |
|
122 |
static const QColor titlebarGradientActiveBegin(220, 220, 220); |
|
123 |
static const QColor titlebarGradientActiveEnd(151, 151, 151); |
|
124 |
static const QColor titlebarSeparatorLineActive(111, 111, 111); |
|
125 |
static const QColor titlebarGradientInactiveBegin(241, 241, 241); |
|
126 |
static const QColor titlebarGradientInactiveEnd(207, 207, 207); |
|
127 |
static const QColor titlebarSeparatorLineInactive(131, 131, 131); |
|
128 |
||
129 |
// Gradient colors used for the dock widget title bar and |
|
130 |
// non-unifed tool bar bacground. |
|
131 |
static const QColor mainWindowGradientBegin(240, 240, 240); |
|
132 |
static const QColor mainWindowGradientEnd(200, 200, 200); |
|
133 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
134 |
static const int DisclosureOffset = 4; |
0 | 135 |
|
136 |
// Resolve these at run-time, since the functions was moved in Leopard. |
|
137 |
typedef HIRect * (*PtrHIShapeGetBounds)(HIShapeRef, HIRect *); |
|
138 |
static PtrHIShapeGetBounds ptrHIShapeGetBounds = 0; |
|
139 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
140 |
static int closeButtonSize = 12; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
141 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
142 |
extern QRegion qt_mac_convert_mac_region(RgnHandle); //qregion_mac.cpp |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
143 |
|
0 | 144 |
static bool isVerticalTabs(const QTabBar::Shape shape) { |
145 |
return (shape == QTabBar::RoundedEast |
|
146 |
|| shape == QTabBar::TriangularEast |
|
147 |
|| shape == QTabBar::RoundedWest |
|
148 |
|| shape == QTabBar::TriangularWest); |
|
149 |
} |
|
150 |
||
151 |
void drawTabCloseButton(QPainter *p, bool hover, bool active, bool selected) |
|
152 |
{ |
|
153 |
// draw background circle |
|
154 |
p->setRenderHints(QPainter::Antialiasing); |
|
155 |
QRect rect(0, 0, closeButtonSize, closeButtonSize); |
|
156 |
QColor background; |
|
157 |
if (hover) { |
|
158 |
background = QColor(124, 124, 124); |
|
159 |
} else { |
|
160 |
if (active) { |
|
161 |
if (selected) |
|
162 |
background = QColor(104, 104, 104); |
|
163 |
else |
|
164 |
background = QColor(83, 83, 83); |
|
165 |
} else { |
|
166 |
if (selected) |
|
167 |
background = QColor(144, 144, 144); |
|
168 |
else |
|
169 |
background = QColor(114, 114, 114); |
|
170 |
} |
|
171 |
} |
|
172 |
p->setPen(Qt::transparent); |
|
173 |
p->setBrush(background); |
|
174 |
p->drawEllipse(rect); |
|
175 |
||
176 |
// draw cross |
|
177 |
int min = 3; |
|
178 |
int max = 9; |
|
179 |
QPen crossPen; |
|
180 |
crossPen.setColor(QColor(194, 194, 194)); |
|
181 |
crossPen.setWidthF(1.3); |
|
182 |
crossPen.setCapStyle(Qt::FlatCap); |
|
183 |
p->setPen(crossPen); |
|
184 |
p->drawLine(min, min, max, max); |
|
185 |
p->drawLine(min, max, max, min); |
|
186 |
} |
|
187 |
||
188 |
QRect rotateTabPainter(QPainter *p, QTabBar::Shape shape, QRect tabRect) |
|
189 |
{ |
|
190 |
if (isVerticalTabs(shape)) { |
|
191 |
int newX, newY, newRot; |
|
192 |
if (shape == QTabBar::RoundedEast |
|
193 |
|| shape == QTabBar::TriangularEast) { |
|
194 |
newX = tabRect.width(); |
|
195 |
newY = tabRect.y(); |
|
196 |
newRot = 90; |
|
197 |
} else { |
|
198 |
newX = 0; |
|
199 |
newY = tabRect.y() + tabRect.height(); |
|
200 |
newRot = -90; |
|
201 |
} |
|
202 |
tabRect.setRect(0, 0, tabRect.height(), tabRect.width()); |
|
203 |
QMatrix m; |
|
204 |
m.translate(newX, newY); |
|
205 |
m.rotate(newRot); |
|
206 |
p->setMatrix(m, true); |
|
207 |
} |
|
208 |
return tabRect; |
|
209 |
} |
|
210 |
||
211 |
void drawTabShape(QPainter *p, const QStyleOptionTabV3 *tabOpt) |
|
212 |
{ |
|
213 |
QRect r = tabOpt->rect; |
|
214 |
p->translate(tabOpt->rect.x(), tabOpt->rect.y()); |
|
215 |
r.moveLeft(0); |
|
216 |
r.moveTop(0); |
|
217 |
QRect tabRect = rotateTabPainter(p, tabOpt->shape, r); |
|
218 |
||
219 |
int width = tabRect.width(); |
|
220 |
int height = 20; |
|
221 |
bool active = (tabOpt->state & QStyle::State_Active); |
|
222 |
bool selected = (tabOpt->state & QStyle::State_Selected); |
|
223 |
||
224 |
if (selected) { |
|
225 |
QRect rect(1, 0, width - 2, height); |
|
226 |
||
227 |
// fill body |
|
228 |
if (active) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
229 |
int d = (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) ? 16 : 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
230 |
p->fillRect(rect, QColor(151 + d, 151 + d, 151 + d)); |
0 | 231 |
} else { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
232 |
int d = (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) ? 9 : 0; |
0 | 233 |
QLinearGradient gradient(rect.topLeft(), rect.bottomLeft()); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
234 |
gradient.setColorAt(0, QColor(207 + d, 207 + d, 207 + d)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
235 |
gradient.setColorAt(0.5, QColor(206 + d, 206 + d, 206 + d)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
236 |
gradient.setColorAt(1, QColor(201 + d, 201 + d, 201 + d)); |
0 | 237 |
p->fillRect(rect, gradient); |
238 |
} |
|
239 |
||
240 |
// draw border |
|
241 |
QColor borderSides; |
|
242 |
QColor borderBottom; |
|
243 |
if (active) { |
|
244 |
borderSides = QColor(88, 88, 88); |
|
245 |
borderBottom = QColor(88, 88, 88); |
|
246 |
} else { |
|
247 |
borderSides = QColor(121, 121, 121); |
|
248 |
borderBottom = QColor(116, 116, 116); |
|
249 |
} |
|
250 |
||
251 |
p->setPen(borderSides); |
|
252 |
||
253 |
int bottom = height; |
|
254 |
// left line |
|
255 |
p->drawLine(0, 1, 0, bottom-2); |
|
256 |
// right line |
|
257 |
p->drawLine(width-1, 1, width-1, bottom-2); |
|
258 |
||
259 |
// bottom line |
|
260 |
if (active) { |
|
261 |
p->setPen(QColor(168, 168, 168)); |
|
262 |
p->drawLine(3, bottom-1, width-3, bottom-1); |
|
263 |
} |
|
264 |
p->setPen(borderBottom); |
|
265 |
p->drawLine(2, bottom, width-2, bottom); |
|
266 |
||
267 |
int w = 3; |
|
268 |
QRectF rectangleLeft(1, height - w, w, w); |
|
269 |
QRectF rectangleRight(width - 2, height - 1, w, w); |
|
270 |
int startAngle = 180 * 16; |
|
271 |
int spanAngle = 90 * 16; |
|
272 |
p->setRenderHint(QPainter::Antialiasing); |
|
273 |
p->drawArc(rectangleLeft, startAngle, spanAngle); |
|
274 |
p->drawArc(rectangleRight, startAngle, -spanAngle); |
|
275 |
} else { |
|
276 |
// when the mouse is over non selected tabs they get a new color |
|
277 |
bool hover = (tabOpt->state & QStyle::State_MouseOver); |
|
278 |
if (hover) { |
|
279 |
QRect rect(1, 2, width - 1, height - 1); |
|
280 |
p->fillRect(rect, QColor(110, 110, 110)); |
|
281 |
} |
|
282 |
||
283 |
// seperator lines between tabs |
|
284 |
bool west = (tabOpt->shape == QTabBar::RoundedWest || tabOpt->shape == QTabBar::TriangularWest); |
|
285 |
bool drawOnRight = !west; |
|
286 |
if ((!drawOnRight && tabOpt->selectedPosition != QStyleOptionTab::NextIsSelected) |
|
287 |
|| (drawOnRight && tabOpt->selectedPosition != QStyleOptionTab::NextIsSelected)) { |
|
288 |
QColor borderColor; |
|
289 |
QColor borderHighlightColor; |
|
290 |
if (active) { |
|
291 |
borderColor = QColor(64, 64, 64); |
|
292 |
borderHighlightColor = QColor(140, 140, 140); |
|
293 |
} else { |
|
294 |
borderColor = QColor(135, 135, 135); |
|
295 |
borderHighlightColor = QColor(178, 178, 178); |
|
296 |
} |
|
297 |
||
298 |
int x = drawOnRight ? width : 0; |
|
299 |
||
300 |
// tab seperator line |
|
301 |
p->setPen(borderColor); |
|
302 |
p->drawLine(x, 2, x, height + 1); |
|
303 |
||
304 |
// tab seperator highlight |
|
305 |
p->setPen(borderHighlightColor); |
|
306 |
p->drawLine(x-1, 2, x-1, height + 1); |
|
307 |
p->drawLine(x+1, 2, x+1, height + 1); |
|
308 |
} |
|
309 |
} |
|
310 |
} |
|
311 |
||
312 |
void drawTabBase(QPainter *p, const QStyleOptionTabBarBaseV2 *tbb, const QWidget *w) |
|
313 |
{ |
|
314 |
QRect r = tbb->rect; |
|
315 |
if (isVerticalTabs(tbb->shape)) { |
|
316 |
r.setWidth(w->width()); |
|
317 |
} else { |
|
318 |
r.setHeight(w->height()); |
|
319 |
} |
|
320 |
QRect tabRect = rotateTabPainter(p, tbb->shape, r); |
|
321 |
int width = tabRect.width(); |
|
322 |
int height = tabRect.height(); |
|
323 |
bool active = (tbb->state & QStyle::State_Active); |
|
324 |
||
325 |
// top border lines |
|
326 |
QColor borderHighlightTop; |
|
327 |
QColor borderTop; |
|
328 |
if (active) { |
|
329 |
borderTop = QColor(64, 64, 64); |
|
330 |
borderHighlightTop = QColor(174, 174, 174); |
|
331 |
} else { |
|
332 |
borderTop = QColor(135, 135, 135); |
|
333 |
borderHighlightTop = QColor(207, 207, 207); |
|
334 |
} |
|
335 |
p->setPen(borderHighlightTop); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
336 |
p->drawLine(tabRect.x(), 0, width, 0); |
0 | 337 |
p->setPen(borderTop); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
338 |
p->drawLine(tabRect.x(), 1, width, 1); |
0 | 339 |
|
340 |
// center block |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
341 |
QRect centralRect(tabRect.x(), 2, width, height - 2); |
0 | 342 |
if (active) { |
343 |
QColor mainColor = QColor(120, 120, 120); |
|
344 |
p->fillRect(centralRect, mainColor); |
|
345 |
} else { |
|
346 |
QLinearGradient gradient(centralRect.topLeft(), centralRect.bottomLeft()); |
|
347 |
gradient.setColorAt(0, QColor(165, 165, 165)); |
|
348 |
gradient.setColorAt(0.5, QColor(164, 164, 164)); |
|
349 |
gradient.setColorAt(1, QColor(158, 158, 158)); |
|
350 |
p->fillRect(centralRect, gradient); |
|
351 |
} |
|
352 |
||
353 |
// bottom border lines |
|
354 |
QColor borderHighlightBottom; |
|
355 |
QColor borderBottom; |
|
356 |
if (active) { |
|
357 |
borderHighlightBottom = QColor(153, 153, 153); |
|
358 |
borderBottom = QColor(64, 64, 64); |
|
359 |
} else { |
|
360 |
borderHighlightBottom = QColor(177, 177, 177); |
|
361 |
borderBottom = QColor(127, 127, 127); |
|
362 |
} |
|
363 |
p->setPen(borderHighlightBottom); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
364 |
p->drawLine(tabRect.x(), height - 2, width, height - 2); |
0 | 365 |
p->setPen(borderBottom); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
366 |
p->drawLine(tabRect.x(), height - 1, width, height - 1); |
0 | 367 |
} |
368 |
||
369 |
static int getControlSize(const QStyleOption *option, const QWidget *widget) |
|
370 |
{ |
|
371 |
if (option) { |
|
372 |
if (option->state & (QStyle::State_Small | QStyle::State_Mini)) |
|
373 |
return (option->state & QStyle::State_Mini) ? QAquaSizeMini : QAquaSizeSmall; |
|
374 |
} else if (widget) { |
|
375 |
switch (QMacStyle::widgetSizePolicy(widget)) { |
|
376 |
case QMacStyle::SizeSmall: |
|
377 |
return QAquaSizeSmall; |
|
378 |
case QMacStyle::SizeMini: |
|
379 |
return QAquaSizeMini; |
|
380 |
default: |
|
381 |
break; |
|
382 |
} |
|
383 |
} |
|
384 |
return QAquaSizeLarge; |
|
385 |
} |
|
386 |
||
387 |
||
388 |
static inline bool isTreeView(const QWidget *widget) |
|
389 |
{ |
|
390 |
return (widget && widget->parentWidget() && |
|
391 |
(qobject_cast<const QTreeView *>(widget->parentWidget()) |
|
392 |
#ifdef QT3_SUPPORT |
|
393 |
|| widget->parentWidget()->inherits("Q3ListView") |
|
394 |
#endif |
|
395 |
)); |
|
396 |
} |
|
397 |
||
398 |
QString qt_mac_removeMnemonics(const QString &original) |
|
399 |
{ |
|
400 |
QString returnText(original.size(), 0); |
|
401 |
int finalDest = 0; |
|
402 |
int currPos = 0; |
|
403 |
int l = original.length(); |
|
404 |
while (l) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
405 |
if (original.at(currPos) == QLatin1Char('&') |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
406 |
&& (l == 1 || original.at(currPos + 1) != QLatin1Char('&'))) { |
0 | 407 |
++currPos; |
408 |
--l; |
|
409 |
if (l == 0) |
|
410 |
break; |
|
411 |
} |
|
412 |
returnText[finalDest] = original.at(currPos); |
|
413 |
++currPos; |
|
414 |
++finalDest; |
|
415 |
--l; |
|
416 |
} |
|
417 |
returnText.truncate(finalDest); |
|
418 |
return returnText; |
|
419 |
} |
|
420 |
||
421 |
static inline ThemeTabDirection getTabDirection(QTabBar::Shape shape) |
|
422 |
{ |
|
423 |
ThemeTabDirection ttd; |
|
424 |
switch (shape) { |
|
425 |
case QTabBar::RoundedSouth: |
|
426 |
case QTabBar::TriangularSouth: |
|
427 |
ttd = kThemeTabSouth; |
|
428 |
break; |
|
429 |
default: // Added to remove the warning, since all values are taken care of, really! |
|
430 |
case QTabBar::RoundedNorth: |
|
431 |
case QTabBar::TriangularNorth: |
|
432 |
ttd = kThemeTabNorth; |
|
433 |
break; |
|
434 |
case QTabBar::RoundedWest: |
|
435 |
case QTabBar::TriangularWest: |
|
436 |
ttd = kThemeTabWest; |
|
437 |
break; |
|
438 |
case QTabBar::RoundedEast: |
|
439 |
case QTabBar::TriangularEast: |
|
440 |
ttd = kThemeTabEast; |
|
441 |
break; |
|
442 |
} |
|
443 |
return ttd; |
|
444 |
} |
|
445 |
||
446 |
QT_BEGIN_INCLUDE_NAMESPACE |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
447 |
#include "moc_qmacstyle_mac.cpp" |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
448 |
#include "moc_qmacstyle_mac_p.cpp" |
0 | 449 |
QT_END_INCLUDE_NAMESPACE |
450 |
||
451 |
/***************************************************************************** |
|
452 |
External functions |
|
453 |
*****************************************************************************/ |
|
454 |
extern CGContextRef qt_mac_cg_context(const QPaintDevice *); //qpaintdevice_mac.cpp |
|
455 |
extern QRegion qt_mac_convert_mac_region(HIShapeRef); //qregion_mac.cpp |
|
456 |
void qt_mac_dispose_rgn(RgnHandle r); //qregion_mac.cpp |
|
457 |
extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp |
|
458 |
||
459 |
/***************************************************************************** |
|
460 |
QMacCGStyle globals |
|
461 |
*****************************************************************************/ |
|
462 |
const int qt_mac_hitheme_version = 0; //the HITheme version we speak |
|
463 |
const int macItemFrame = 2; // menu item frame width |
|
464 |
const int macItemHMargin = 3; // menu item hor text margin |
|
465 |
const int macItemVMargin = 2; // menu item ver text margin |
|
466 |
const int macRightBorder = 12; // right border on mac |
|
467 |
const ThemeWindowType QtWinType = kThemeDocumentWindow; // Window type we use for QTitleBar. |
|
468 |
QPixmap *qt_mac_backgroundPattern = 0; // stores the standard widget background. |
|
469 |
||
470 |
/***************************************************************************** |
|
471 |
QMacCGStyle utility functions |
|
472 |
*****************************************************************************/ |
|
473 |
static inline int qt_mac_hitheme_tab_version() |
|
474 |
{ |
|
475 |
return 1; |
|
476 |
} |
|
477 |
||
478 |
static inline HIRect qt_hirectForQRect(const QRect &convertRect, const QRect &rect = QRect()) |
|
479 |
{ |
|
480 |
return CGRectMake(convertRect.x() + rect.x(), convertRect.y() + rect.y(), |
|
481 |
convertRect.width() - rect.width(), convertRect.height() - rect.height()); |
|
482 |
} |
|
483 |
||
484 |
static inline const QRect qt_qrectForHIRect(const HIRect &hirect) |
|
485 |
{ |
|
486 |
return QRect(QPoint(int(hirect.origin.x), int(hirect.origin.y)), |
|
487 |
QSize(int(hirect.size.width), int(hirect.size.height))); |
|
488 |
} |
|
489 |
||
490 |
inline bool qt_mac_is_metal(const QWidget *w) |
|
491 |
{ |
|
492 |
for (; w; w = w->parentWidget()) { |
|
493 |
if (w->testAttribute(Qt::WA_MacBrushedMetal)) |
|
494 |
return true; |
|
495 |
if (w->isWindow() && w->testAttribute(Qt::WA_WState_Created)) { // If not created will fall through to the opaque check and be fine anyway. |
|
496 |
return macWindowIsTextured(qt_mac_window_for(w)); |
|
497 |
} |
|
498 |
if (w->d_func()->isOpaque) |
|
499 |
break; |
|
500 |
} |
|
501 |
return false; |
|
502 |
} |
|
503 |
||
504 |
static int qt_mac_aqua_get_metric(ThemeMetric met) |
|
505 |
{ |
|
506 |
SInt32 ret; |
|
507 |
GetThemeMetric(met, &ret); |
|
508 |
return ret; |
|
509 |
} |
|
510 |
||
511 |
static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg, QSize szHint, |
|
512 |
QAquaWidgetSize sz) |
|
513 |
{ |
|
514 |
QSize ret(-1, -1); |
|
515 |
if (sz != QAquaSizeSmall && sz != QAquaSizeLarge && sz != QAquaSizeMini) { |
|
516 |
qDebug("Not sure how to return this..."); |
|
517 |
return ret; |
|
518 |
} |
|
519 |
if ((widg && widg->testAttribute(Qt::WA_SetFont)) || !QApplication::desktopSettingsAware()) { |
|
520 |
// If you're using a custom font and it's bigger than the default font, |
|
521 |
// then no constraints for you. If you are smaller, we can try to help you out |
|
522 |
QFont font = qt_app_fonts_hash()->value(widg->metaObject()->className(), QFont()); |
|
523 |
if (widg->font().pointSize() > font.pointSize()) |
|
524 |
return ret; |
|
525 |
} |
|
526 |
||
527 |
if (ct == QStyle::CT_CustomBase && widg) { |
|
528 |
if (qobject_cast<const QPushButton *>(widg)) |
|
529 |
ct = QStyle::CT_PushButton; |
|
530 |
else if (qobject_cast<const QRadioButton *>(widg)) |
|
531 |
ct = QStyle::CT_RadioButton; |
|
532 |
else if (qobject_cast<const QCheckBox *>(widg)) |
|
533 |
ct = QStyle::CT_CheckBox; |
|
534 |
else if (qobject_cast<const QComboBox *>(widg)) |
|
535 |
ct = QStyle::CT_ComboBox; |
|
536 |
else if (qobject_cast<const QToolButton *>(widg)) |
|
537 |
ct = QStyle::CT_ToolButton; |
|
538 |
else if (qobject_cast<const QSlider *>(widg)) |
|
539 |
ct = QStyle::CT_Slider; |
|
540 |
else if (qobject_cast<const QProgressBar *>(widg)) |
|
541 |
ct = QStyle::CT_ProgressBar; |
|
542 |
else if (qobject_cast<const QLineEdit *>(widg)) |
|
543 |
ct = QStyle::CT_LineEdit; |
|
544 |
else if (qobject_cast<const QHeaderView *>(widg) |
|
545 |
#ifdef QT3_SUPPORT |
|
546 |
|| widg->inherits("Q3Header") |
|
547 |
#endif |
|
548 |
) |
|
549 |
ct = QStyle::CT_HeaderSection; |
|
550 |
else if (qobject_cast<const QMenuBar *>(widg) |
|
551 |
#ifdef QT3_SUPPORT |
|
552 |
|| widg->inherits("Q3MenuBar") |
|
553 |
#endif |
|
554 |
) |
|
555 |
ct = QStyle::CT_MenuBar; |
|
556 |
else if (qobject_cast<const QSizeGrip *>(widg)) |
|
557 |
ct = QStyle::CT_SizeGrip; |
|
558 |
else |
|
559 |
return ret; |
|
560 |
} |
|
561 |
||
562 |
switch (ct) { |
|
563 |
case QStyle::CT_PushButton: { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
564 |
const QPushButton *psh = qobject_cast<const QPushButton *>(widg); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
565 |
// If this comparison is false, then the widget was not a push button. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
566 |
// This is bad and there's very little we can do since we were requested to find a |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
567 |
// sensible size for a widget that pretends to be a QPushButton but is not. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
568 |
if(psh) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
569 |
QString buttonText = qt_mac_removeMnemonics(psh->text()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
570 |
if (buttonText.contains(QLatin1Char('\n'))) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
571 |
ret = QSize(-1, -1); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
572 |
else if (sz == QAquaSizeLarge) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
573 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricPushButtonHeight)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
574 |
else if (sz == QAquaSizeSmall) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
575 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricSmallPushButtonHeight)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
576 |
else if (sz == QAquaSizeMini) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
577 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricMiniPushButtonHeight)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
578 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
579 |
if (!psh->icon().isNull()){ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
580 |
// If the button got an icon, and the icon is larger than the |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
581 |
// button, we can't decide on a default size |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
582 |
ret.setWidth(-1); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
583 |
if (ret.height() < psh->iconSize().height()) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
584 |
ret.setHeight(-1); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
585 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
586 |
else if (buttonText == QLatin1String("OK") || buttonText == QLatin1String("Cancel")){ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
587 |
// Aqua Style guidelines restrict the size of OK and Cancel buttons to 68 pixels. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
588 |
// However, this doesn't work for German, therefore only do it for English, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
589 |
// I suppose it would be better to do some sort of lookups for languages |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
590 |
// that like to have really long words. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
591 |
ret.setWidth(77 - 8); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
592 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
593 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
594 |
// The only sensible thing to do is to return whatever the style suggests... |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
595 |
if (sz == QAquaSizeLarge) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
596 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricPushButtonHeight)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
597 |
else if (sz == QAquaSizeSmall) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
598 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricSmallPushButtonHeight)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
599 |
else if (sz == QAquaSizeMini) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
600 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricMiniPushButtonHeight)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
601 |
else |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
602 |
// Since there's no default size we return the large size... |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
603 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricPushButtonHeight)); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
604 |
} |
0 | 605 |
#if 0 //Not sure we are applying the rules correctly for RadioButtons/CheckBoxes --Sam |
606 |
} else if (ct == QStyle::CT_RadioButton) { |
|
607 |
QRadioButton *rdo = static_cast<QRadioButton *>(widg); |
|
608 |
// Exception for case where multiline radio button text requires no size constrainment |
|
609 |
if (rdo->text().find('\n') != -1) |
|
610 |
return ret; |
|
611 |
if (sz == QAquaSizeLarge) |
|
612 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricRadioButtonHeight)); |
|
613 |
else if (sz == QAquaSizeSmall) |
|
614 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricSmallRadioButtonHeight)); |
|
615 |
else if (sz == QAquaSizeMini) |
|
616 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricMiniRadioButtonHeight)); |
|
617 |
} else if (ct == QStyle::CT_CheckBox) { |
|
618 |
if (sz == QAquaSizeLarge) |
|
619 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricCheckBoxHeight)); |
|
620 |
else if (sz == QAquaSizeSmall) |
|
621 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricSmallCheckBoxHeight)); |
|
622 |
else if (sz == QAquaSizeMini) |
|
623 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricMiniCheckBoxHeight)); |
|
624 |
#endif |
|
625 |
break; |
|
626 |
} |
|
627 |
case QStyle::CT_SizeGrip: |
|
628 |
if (sz == QAquaSizeLarge || sz == QAquaSizeSmall) { |
|
629 |
HIRect r; |
|
630 |
HIPoint p = { 0, 0 }; |
|
631 |
HIThemeGrowBoxDrawInfo gbi; |
|
632 |
gbi.version = 0; |
|
633 |
gbi.state = kThemeStateActive; |
|
634 |
gbi.kind = kHIThemeGrowBoxKindNormal; |
|
635 |
gbi.direction = QApplication::isRightToLeft() ? kThemeGrowLeft | kThemeGrowDown |
|
636 |
: kThemeGrowRight | kThemeGrowDown; |
|
637 |
gbi.size = sz == QAquaSizeSmall ? kHIThemeGrowBoxSizeSmall : kHIThemeGrowBoxSizeNormal; |
|
638 |
if (HIThemeGetGrowBoxBounds(&p, &gbi, &r) == noErr) |
|
639 |
ret = QSize(r.size.width, r.size.height); |
|
640 |
} |
|
641 |
break; |
|
642 |
case QStyle::CT_ComboBox: |
|
643 |
switch (sz) { |
|
644 |
case QAquaSizeLarge: |
|
645 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricPopupButtonHeight)); |
|
646 |
break; |
|
647 |
case QAquaSizeSmall: |
|
648 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricSmallPopupButtonHeight)); |
|
649 |
break; |
|
650 |
case QAquaSizeMini: |
|
651 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricMiniPopupButtonHeight)); |
|
652 |
break; |
|
653 |
default: |
|
654 |
break; |
|
655 |
} |
|
656 |
break; |
|
657 |
case QStyle::CT_ToolButton: |
|
658 |
if (sz == QAquaSizeSmall) { |
|
659 |
int width = 0, height = 0; |
|
660 |
if (szHint == QSize(-1, -1)) { //just 'guess'.. |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
661 |
const QToolButton *bt = qobject_cast<const QToolButton *>(widg); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
662 |
// If this conversion fails then the widget was not what it claimed to be. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
663 |
if(bt) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
664 |
if (!bt->icon().isNull()) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
665 |
QSize iconSize = bt->iconSize(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
666 |
QSize pmSize = bt->icon().actualSize(QSize(32, 32), QIcon::Normal); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
667 |
width = qMax(width, qMax(iconSize.width(), pmSize.width())); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
668 |
height = qMax(height, qMax(iconSize.height(), pmSize.height())); |
0 | 669 |
} |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
670 |
if (!bt->text().isNull() && bt->toolButtonStyle() != Qt::ToolButtonIconOnly) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
671 |
int text_width = bt->fontMetrics().width(bt->text()), |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
672 |
text_height = bt->fontMetrics().height(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
673 |
if (bt->toolButtonStyle() == Qt::ToolButtonTextUnderIcon) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
674 |
width = qMax(width, text_width); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
675 |
height += text_height; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
676 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
677 |
width += text_width; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
678 |
width = qMax(height, text_height); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
679 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
680 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
681 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
682 |
// Let's return the size hint... |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
683 |
width = szHint.width(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
684 |
height = szHint.height(); |
0 | 685 |
} |
686 |
} else { |
|
687 |
width = szHint.width(); |
|
688 |
height = szHint.height(); |
|
689 |
} |
|
690 |
width = qMax(20, width + 5); //border |
|
691 |
height = qMax(20, height + 5); //border |
|
692 |
ret = QSize(width, height); |
|
693 |
} |
|
694 |
break; |
|
695 |
case QStyle::CT_Slider: { |
|
696 |
int w = -1; |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
697 |
const QSlider *sld = qobject_cast<const QSlider *>(widg); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
698 |
// If this conversion fails then the widget was not what it claimed to be. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
699 |
if(sld) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
700 |
if (sz == QAquaSizeLarge) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
701 |
if (sld->orientation() == Qt::Horizontal) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
702 |
w = qt_mac_aqua_get_metric(kThemeMetricHSliderHeight); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
703 |
if (sld->tickPosition() != QSlider::NoTicks) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
704 |
w += qt_mac_aqua_get_metric(kThemeMetricHSliderTickHeight); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
705 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
706 |
w = qt_mac_aqua_get_metric(kThemeMetricVSliderWidth); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
707 |
if (sld->tickPosition() != QSlider::NoTicks) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
708 |
w += qt_mac_aqua_get_metric(kThemeMetricVSliderTickWidth); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
709 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
710 |
} else if (sz == QAquaSizeSmall) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
711 |
if (sld->orientation() == Qt::Horizontal) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
712 |
w = qt_mac_aqua_get_metric(kThemeMetricSmallHSliderHeight); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
713 |
if (sld->tickPosition() != QSlider::NoTicks) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
714 |
w += qt_mac_aqua_get_metric(kThemeMetricSmallHSliderTickHeight); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
715 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
716 |
w = qt_mac_aqua_get_metric(kThemeMetricSmallVSliderWidth); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
717 |
if (sld->tickPosition() != QSlider::NoTicks) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
718 |
w += qt_mac_aqua_get_metric(kThemeMetricSmallVSliderTickWidth); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
719 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
720 |
} else if (sz == QAquaSizeMini) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
721 |
if (sld->orientation() == Qt::Horizontal) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
722 |
w = qt_mac_aqua_get_metric(kThemeMetricMiniHSliderHeight); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
723 |
if (sld->tickPosition() != QSlider::NoTicks) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
724 |
w += qt_mac_aqua_get_metric(kThemeMetricMiniHSliderTickHeight); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
725 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
726 |
w = qt_mac_aqua_get_metric(kThemeMetricMiniVSliderWidth); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
727 |
if (sld->tickPosition() != QSlider::NoTicks) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
728 |
w += qt_mac_aqua_get_metric(kThemeMetricMiniVSliderTickWidth); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
729 |
} |
0 | 730 |
} |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
731 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
732 |
// This is tricky, we were requested to find a size for a slider which is not |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
733 |
// a slider. We don't know if this is vertical or horizontal or if we need to |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
734 |
// have tick marks or not. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
735 |
// For this case we will return an horizontal slider without tick marks. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
736 |
w = qt_mac_aqua_get_metric(kThemeMetricHSliderHeight); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
737 |
w += qt_mac_aqua_get_metric(kThemeMetricHSliderTickHeight); |
0 | 738 |
} |
739 |
if (sld->orientation() == Qt::Horizontal) |
|
740 |
ret.setHeight(w); |
|
741 |
else |
|
742 |
ret.setWidth(w); |
|
743 |
break; |
|
744 |
} |
|
745 |
case QStyle::CT_ProgressBar: { |
|
746 |
int finalValue = -1; |
|
747 |
Qt::Orientation orient = Qt::Horizontal; |
|
748 |
if (const QProgressBar *pb = qobject_cast<const QProgressBar *>(widg)) |
|
749 |
orient = pb->orientation(); |
|
750 |
||
751 |
if (sz == QAquaSizeLarge) |
|
752 |
finalValue = qt_mac_aqua_get_metric(kThemeMetricLargeProgressBarThickness) |
|
753 |
+ qt_mac_aqua_get_metric(kThemeMetricProgressBarShadowOutset); |
|
754 |
else |
|
755 |
finalValue = qt_mac_aqua_get_metric(kThemeMetricNormalProgressBarThickness) |
|
756 |
+ qt_mac_aqua_get_metric(kThemeMetricSmallProgressBarShadowOutset); |
|
757 |
if (orient == Qt::Horizontal) |
|
758 |
ret.setHeight(finalValue); |
|
759 |
else |
|
760 |
ret.setWidth(finalValue); |
|
761 |
break; |
|
762 |
} |
|
763 |
case QStyle::CT_LineEdit: |
|
764 |
if (!widg || !qobject_cast<QComboBox *>(widg->parentWidget())) { |
|
765 |
//should I take into account the font dimentions of the lineedit? -Sam |
|
766 |
if (sz == QAquaSizeLarge) |
|
767 |
ret = QSize(-1, 22); |
|
768 |
else |
|
769 |
ret = QSize(-1, 19); |
|
770 |
} |
|
771 |
break; |
|
772 |
case QStyle::CT_HeaderSection: |
|
773 |
if (isTreeView(widg)) |
|
774 |
ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricListHeaderHeight)); |
|
775 |
break; |
|
776 |
case QStyle::CT_MenuBar: |
|
777 |
if (sz == QAquaSizeLarge) { |
|
778 |
#ifndef QT_MAC_USE_COCOA |
|
779 |
SInt16 size; |
|
780 |
if (!GetThemeMenuBarHeight(&size)) |
|
781 |
ret = QSize(-1, size); |
|
782 |
#else |
|
783 |
ret = QSize(-1, [[NSApp mainMenu] menuBarHeight]); |
|
784 |
// In the qt_mac_set_native_menubar(false) case, |
|
785 |
// we come it here with a zero-height main menu, |
|
786 |
// preventing the in-window menu from displaying. |
|
787 |
// Use 22 pixels for the height, by observation. |
|
788 |
if (ret.height() <= 0) |
|
789 |
ret.setHeight(22); |
|
790 |
#endif |
|
791 |
} |
|
792 |
break; |
|
793 |
default: |
|
794 |
break; |
|
795 |
} |
|
796 |
return ret; |
|
797 |
} |
|
798 |
||
799 |
||
800 |
#if defined(QMAC_QAQUASTYLE_SIZE_CONSTRAIN) || defined(DEBUG_SIZE_CONSTRAINT) |
|
801 |
static QAquaWidgetSize qt_aqua_guess_size(const QWidget *widg, QSize large, QSize small, QSize mini) |
|
802 |
{ |
|
803 |
if (large == QSize(-1, -1)) { |
|
804 |
if (small != QSize(-1, -1)) |
|
805 |
return QAquaSizeSmall; |
|
806 |
if (mini != QSize(-1, -1)) |
|
807 |
return QAquaSizeMini; |
|
808 |
return QAquaSizeUnknown; |
|
809 |
} else if (small == QSize(-1, -1)) { |
|
810 |
if (mini != QSize(-1, -1)) |
|
811 |
return QAquaSizeMini; |
|
812 |
return QAquaSizeLarge; |
|
813 |
} else if (mini == QSize(-1, -1)) { |
|
814 |
return QAquaSizeLarge; |
|
815 |
} |
|
816 |
||
817 |
#ifndef QT_NO_MAINWINDOW |
|
818 |
if (qobject_cast<QDockWidget *>(widg->window()) || !qgetenv("QWIDGET_ALL_SMALL").isNull()) { |
|
819 |
//if (small.width() != -1 || small.height() != -1) |
|
820 |
return QAquaSizeSmall; |
|
821 |
} else if (!qgetenv("QWIDGET_ALL_MINI").isNull()) { |
|
822 |
return QAquaSizeMini; |
|
823 |
} |
|
824 |
#endif |
|
825 |
||
826 |
#if 0 |
|
827 |
/* Figure out which size we're closer to, I just hacked this in, I haven't |
|
828 |
tested it as it would probably look pretty strange to have some widgets |
|
829 |
big and some widgets small in the same window?? -Sam */ |
|
830 |
int large_delta=0; |
|
831 |
if (large.width() != -1) { |
|
832 |
int delta = large.width() - widg->width(); |
|
833 |
large_delta += delta * delta; |
|
834 |
} |
|
835 |
if (large.height() != -1) { |
|
836 |
int delta = large.height() - widg->height(); |
|
837 |
large_delta += delta * delta; |
|
838 |
} |
|
839 |
int small_delta=0; |
|
840 |
if (small.width() != -1) { |
|
841 |
int delta = small.width() - widg->width(); |
|
842 |
small_delta += delta * delta; |
|
843 |
} |
|
844 |
if (small.height() != -1) { |
|
845 |
int delta = small.height() - widg->height(); |
|
846 |
small_delta += delta * delta; |
|
847 |
} |
|
848 |
int mini_delta=0; |
|
849 |
if (mini.width() != -1) { |
|
850 |
int delta = mini.width() - widg->width(); |
|
851 |
mini_delta += delta * delta; |
|
852 |
} |
|
853 |
if (mini.height() != -1) { |
|
854 |
int delta = mini.height() - widg->height(); |
|
855 |
mini_delta += delta * delta; |
|
856 |
} |
|
857 |
if (mini_delta < small_delta && mini_delta < large_delta) |
|
858 |
return QAquaSizeMini; |
|
859 |
else if (small_delta < large_delta) |
|
860 |
return QAquaSizeSmall; |
|
861 |
#endif |
|
862 |
return QAquaSizeLarge; |
|
863 |
} |
|
864 |
#endif |
|
865 |
||
866 |
QAquaWidgetSize QMacStylePrivate::aquaSizeConstrain(const QStyleOption *option, const QWidget *widg, |
|
867 |
QStyle::ContentsType ct, QSize szHint, QSize *insz) const |
|
868 |
{ |
|
869 |
#if defined(QMAC_QAQUASTYLE_SIZE_CONSTRAIN) || defined(DEBUG_SIZE_CONSTRAINT) |
|
870 |
if (option) { |
|
871 |
if (option->state & QStyle::State_Small) |
|
872 |
return QAquaSizeSmall; |
|
873 |
if (option->state & QStyle::State_Mini) |
|
874 |
return QAquaSizeMini; |
|
875 |
} |
|
876 |
||
877 |
if (!widg) { |
|
878 |
if (insz) |
|
879 |
*insz = QSize(); |
|
880 |
if (!qgetenv("QWIDGET_ALL_SMALL").isNull()) |
|
881 |
return QAquaSizeSmall; |
|
882 |
if (!qgetenv("QWIDGET_ALL_MINI").isNull()) |
|
883 |
return QAquaSizeMini; |
|
884 |
return QAquaSizeUnknown; |
|
885 |
} |
|
886 |
QSize large = qt_aqua_get_known_size(ct, widg, szHint, QAquaSizeLarge), |
|
887 |
small = qt_aqua_get_known_size(ct, widg, szHint, QAquaSizeSmall), |
|
888 |
mini = qt_aqua_get_known_size(ct, widg, szHint, QAquaSizeMini); |
|
889 |
bool guess_size = false; |
|
890 |
QAquaWidgetSize ret = QAquaSizeUnknown; |
|
891 |
QMacStyle::WidgetSizePolicy wsp = q->widgetSizePolicy(widg); |
|
892 |
if (wsp == QMacStyle::SizeDefault) |
|
893 |
guess_size = true; |
|
894 |
else if (wsp == QMacStyle::SizeMini) |
|
895 |
ret = QAquaSizeMini; |
|
896 |
else if (wsp == QMacStyle::SizeSmall) |
|
897 |
ret = QAquaSizeSmall; |
|
898 |
else if (wsp == QMacStyle::SizeLarge) |
|
899 |
ret = QAquaSizeLarge; |
|
900 |
if (guess_size) |
|
901 |
ret = qt_aqua_guess_size(widg, large, small, mini); |
|
902 |
||
903 |
QSize *sz = 0; |
|
904 |
if (ret == QAquaSizeSmall) |
|
905 |
sz = &small; |
|
906 |
else if (ret == QAquaSizeLarge) |
|
907 |
sz = &large; |
|
908 |
else if (ret == QAquaSizeMini) |
|
909 |
sz = &mini; |
|
910 |
if (insz) |
|
911 |
*insz = sz ? *sz : QSize(-1, -1); |
|
912 |
#ifdef DEBUG_SIZE_CONSTRAINT |
|
913 |
if (sz) { |
|
914 |
const char *size_desc = "Unknown"; |
|
915 |
if (sz == &small) |
|
916 |
size_desc = "Small"; |
|
917 |
else if (sz == &large) |
|
918 |
size_desc = "Large"; |
|
919 |
else if (sz == &mini) |
|
920 |
size_desc = "Mini"; |
|
921 |
qDebug("%s - %s: %s taken (%d, %d) [%d, %d]", |
|
922 |
widg ? widg->objectName().toLatin1().constData() : "*Unknown*", |
|
923 |
widg ? widg->metaObject()->className() : "*Unknown*", size_desc, widg->width(), widg->height(), |
|
924 |
sz->width(), sz->height()); |
|
925 |
} |
|
926 |
#endif |
|
927 |
return ret; |
|
928 |
#else |
|
929 |
if (insz) |
|
930 |
*insz = QSize(); |
|
931 |
Q_UNUSED(widg); |
|
932 |
Q_UNUSED(ct); |
|
933 |
Q_UNUSED(szHint); |
|
934 |
return QAquaSizeUnknown; |
|
935 |
#endif |
|
936 |
} |
|
937 |
||
938 |
/** |
|
939 |
Returns the free space awailable for contents inside the |
|
940 |
button (and not the size of the contents itself) |
|
941 |
*/ |
|
942 |
HIRect QMacStylePrivate::pushButtonContentBounds(const QStyleOptionButton *btn, |
|
943 |
const HIThemeButtonDrawInfo *bdi) const |
|
944 |
{ |
|
945 |
HIRect outerBounds = qt_hirectForQRect(btn->rect); |
|
946 |
// Adjust the bounds to correct for |
|
947 |
// carbon not calculating the content bounds fully correct |
|
948 |
if (bdi->kind == kThemePushButton || bdi->kind == kThemePushButtonSmall){ |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
949 |
outerBounds.origin.y += QMacStylePrivate::PushButtonTopOffset; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
950 |
outerBounds.size.height -= QMacStylePrivate::PushButtonBottomOffset; |
0 | 951 |
} else if (bdi->kind == kThemePushButtonMini) { |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
952 |
outerBounds.origin.y += QMacStylePrivate::PushButtonTopOffset; |
0 | 953 |
} |
954 |
||
955 |
HIRect contentBounds; |
|
956 |
HIThemeGetButtonContentBounds(&outerBounds, bdi, &contentBounds); |
|
957 |
return contentBounds; |
|
958 |
} |
|
959 |
||
960 |
/** |
|
961 |
Calculates the size of the button contents. |
|
962 |
This includes both the text and the icon. |
|
963 |
*/ |
|
964 |
QSize QMacStylePrivate::pushButtonSizeFromContents(const QStyleOptionButton *btn) const |
|
965 |
{ |
|
966 |
QSize csz(0, 0); |
|
967 |
QSize iconSize = btn->icon.isNull() ? QSize(0, 0) |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
968 |
: (btn->iconSize + QSize(QMacStylePrivate::PushButtonContentPadding, 0)); |
0 | 969 |
QRect textRect = btn->text.isEmpty() ? QRect(0, 0, 1, 1) |
970 |
: btn->fontMetrics.boundingRect(QRect(), Qt::AlignCenter, btn->text); |
|
971 |
csz.setWidth(iconSize.width() + textRect.width() |
|
972 |
+ ((btn->features & QStyleOptionButton::HasMenu) |
|
973 |
? q->proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, 0) : 0)); |
|
974 |
csz.setHeight(qMax(iconSize.height(), textRect.height())); |
|
975 |
return csz; |
|
976 |
} |
|
977 |
||
978 |
/** |
|
979 |
Checks if the actual contents of btn fits inside the free content bounds of |
|
980 |
'buttonKindToCheck'. Meant as a helper function for 'initHIThemePushButton' |
|
981 |
for determining which button kind to use for drawing. |
|
982 |
*/ |
|
983 |
bool QMacStylePrivate::contentFitsInPushButton(const QStyleOptionButton *btn, |
|
984 |
HIThemeButtonDrawInfo *bdi, |
|
985 |
ThemeButtonKind buttonKindToCheck) const |
|
986 |
{ |
|
987 |
ThemeButtonKind tmp = bdi->kind; |
|
988 |
bdi->kind = buttonKindToCheck; |
|
989 |
QSize contentSize = pushButtonSizeFromContents(btn); |
|
990 |
QRect freeContentRect = qt_qrectForHIRect(pushButtonContentBounds(btn, bdi)); |
|
991 |
bdi->kind = tmp; |
|
992 |
return freeContentRect.contains(QRect(freeContentRect.x(), freeContentRect.y(), |
|
993 |
contentSize.width(), contentSize.height())); |
|
994 |
} |
|
995 |
||
996 |
/** |
|
997 |
Creates a HIThemeButtonDrawInfo structure that specifies the correct button |
|
998 |
kind and other details to use for drawing the given push button. Which |
|
999 |
button kind depends on the size of the button, the size of the contents, |
|
1000 |
explicit user style settings, etc. |
|
1001 |
*/ |
|
1002 |
void QMacStylePrivate::initHIThemePushButton(const QStyleOptionButton *btn, |
|
1003 |
const QWidget *widget, |
|
1004 |
const ThemeDrawState tds, |
|
1005 |
HIThemeButtonDrawInfo *bdi) const |
|
1006 |
{ |
|
1007 |
bool drawColorless = btn->palette.currentColorGroup() == QPalette::Active; |
|
1008 |
ThemeDrawState tdsModified = tds; |
|
1009 |
if (btn->state & QStyle::State_On) |
|
1010 |
tdsModified = kThemeStatePressed; |
|
1011 |
bdi->version = qt_mac_hitheme_version; |
|
1012 |
bdi->state = tdsModified; |
|
1013 |
bdi->value = kThemeButtonOff; |
|
1014 |
||
1015 |
if (drawColorless && tdsModified == kThemeStateInactive) |
|
1016 |
bdi->state = kThemeStateActive; |
|
1017 |
if (btn->state & QStyle::State_HasFocus) |
|
1018 |
bdi->adornment = kThemeAdornmentFocus; |
|
1019 |
else |
|
1020 |
bdi->adornment = kThemeAdornmentNone; |
|
1021 |
||
1022 |
||
1023 |
if (btn->features & (QStyleOptionButton::Flat)) { |
|
1024 |
bdi->kind = kThemeBevelButton; |
|
1025 |
} else { |
|
1026 |
switch (aquaSizeConstrain(btn, widget)) { |
|
1027 |
case QAquaSizeSmall: |
|
1028 |
bdi->kind = kThemePushButtonSmall; |
|
1029 |
break; |
|
1030 |
case QAquaSizeMini: |
|
1031 |
bdi->kind = kThemePushButtonMini; |
|
1032 |
break; |
|
1033 |
case QAquaSizeLarge: |
|
1034 |
// ... We should honor if the user is explicit about using the |
|
1035 |
// large button. But right now Qt will specify the large button |
|
1036 |
// as default rather than QAquaSizeUnknown. |
|
1037 |
// So we treat it like QAquaSizeUnknown |
|
1038 |
// to get the dynamic choosing of button kind. |
|
1039 |
case QAquaSizeUnknown: |
|
1040 |
// Choose the button kind that closest match the button rect, but at the |
|
1041 |
// same time displays the button contents without clipping. |
|
1042 |
bdi->kind = kThemeBevelButton; |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1043 |
if (btn->rect.width() >= QMacStylePrivate::BevelButtonW && btn->rect.height() >= QMacStylePrivate::BevelButtonH){ |
0 | 1044 |
if (widget && widget->testAttribute(Qt::WA_MacVariableSize)) { |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1045 |
if (btn->rect.height() <= QMacStylePrivate::MiniButtonH){ |
0 | 1046 |
if (contentFitsInPushButton(btn, bdi, kThemePushButtonMini)) |
1047 |
bdi->kind = kThemePushButtonMini; |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1048 |
} else if (btn->rect.height() <= QMacStylePrivate::SmallButtonH){ |
0 | 1049 |
if (contentFitsInPushButton(btn, bdi, kThemePushButtonSmall)) |
1050 |
bdi->kind = kThemePushButtonSmall; |
|
1051 |
} else if (contentFitsInPushButton(btn, bdi, kThemePushButton)) { |
|
1052 |
bdi->kind = kThemePushButton; |
|
1053 |
} |
|
1054 |
} else { |
|
1055 |
bdi->kind = kThemePushButton; |
|
1056 |
} |
|
1057 |
} |
|
1058 |
} |
|
1059 |
} |
|
1060 |
} |
|
1061 |
||
1062 |
/** |
|
1063 |
Creates a HIThemeButtonDrawInfo structure that specifies the correct button |
|
1064 |
kind and other details to use for drawing the given combobox. Which button |
|
1065 |
kind depends on the size of the combo, wether or not it is editable, |
|
1066 |
explicit user style settings, etc. |
|
1067 |
*/ |
|
1068 |
void QMacStylePrivate::initComboboxBdi(const QStyleOptionComboBox *combo, HIThemeButtonDrawInfo *bdi, |
|
1069 |
const QWidget *widget, const ThemeDrawState &tds) |
|
1070 |
{ |
|
1071 |
bdi->version = qt_mac_hitheme_version; |
|
1072 |
bdi->adornment = kThemeAdornmentArrowLeftArrow; |
|
1073 |
bdi->value = kThemeButtonOff; |
|
1074 |
if (combo->state & QStyle::State_HasFocus) |
|
1075 |
bdi->adornment = kThemeAdornmentFocus; |
|
1076 |
bool drawColorless = combo->palette.currentColorGroup() == QPalette::Active && tds == kThemeStateInactive; |
|
1077 |
if (combo->activeSubControls & QStyle::SC_ComboBoxArrow) |
|
1078 |
bdi->state = kThemeStatePressed; |
|
1079 |
else if (drawColorless) |
|
1080 |
bdi->state = kThemeStateActive; |
|
1081 |
else |
|
1082 |
bdi->state = tds; |
|
1083 |
||
1084 |
QAquaWidgetSize aSize = aquaSizeConstrain(combo, widget); |
|
1085 |
switch (aSize) { |
|
1086 |
case QAquaSizeMini: |
|
1087 |
bdi->kind = combo->editable ? ThemeButtonKind(kThemeComboBoxMini) |
|
1088 |
: ThemeButtonKind(kThemePopupButtonMini); |
|
1089 |
break; |
|
1090 |
case QAquaSizeSmall: |
|
1091 |
bdi->kind = combo->editable ? ThemeButtonKind(kThemeComboBoxSmall) |
|
1092 |
: ThemeButtonKind(kThemePopupButtonSmall); |
|
1093 |
break; |
|
1094 |
case QAquaSizeUnknown: |
|
1095 |
case QAquaSizeLarge: |
|
1096 |
// Unless the user explicitly specified large buttons, determine the |
|
1097 |
// kind by looking at the combox size. |
|
1098 |
// ... specifying small and mini-buttons it not a current feature of |
|
1099 |
// Qt (e.g. QWidget::getAttribute(WA_ButtonSize)). But when it is, add |
|
1100 |
// an extra check here before using the mini and small buttons. |
|
1101 |
int h = combo->rect.size().height(); |
|
1102 |
if (combo->editable){ |
|
1103 |
if (h < 21) |
|
1104 |
bdi->kind = kThemeComboBoxMini; |
|
1105 |
else if (h < 26) |
|
1106 |
bdi->kind = kThemeComboBoxSmall; |
|
1107 |
else |
|
1108 |
bdi->kind = kThemeComboBox; |
|
1109 |
} else { |
|
1110 |
// Even if we specify that we want the kThemePopupButton, Carbon |
|
1111 |
// will use the kThemePopupButtonSmall if the size matches. So we |
|
1112 |
// do the same size check explicit to have the size of the inner |
|
1113 |
// text field be correct. Therefore, do this even if the user specifies |
|
1114 |
// the use of LargeButtons explicit. |
|
1115 |
if (h < 21) |
|
1116 |
bdi->kind = kThemePopupButtonMini; |
|
1117 |
else if (h < 26) |
|
1118 |
bdi->kind = kThemePopupButtonSmall; |
|
1119 |
else |
|
1120 |
bdi->kind = kThemePopupButton; |
|
1121 |
} |
|
1122 |
break; |
|
1123 |
} |
|
1124 |
} |
|
1125 |
||
1126 |
/** |
|
1127 |
Carbon draws comboboxes (and other views) outside the rect given as argument. Use this function to obtain |
|
1128 |
the corresponding inner rect for drawing the same combobox so that it stays inside the given outerBounds. |
|
1129 |
*/ |
|
1130 |
HIRect QMacStylePrivate::comboboxInnerBounds(const HIRect &outerBounds, int buttonKind) |
|
1131 |
{ |
|
1132 |
HIRect innerBounds = outerBounds; |
|
1133 |
// Carbon draw parts of the view outside the rect. |
|
1134 |
// So make the rect a bit smaller to compensate |
|
1135 |
// (I wish HIThemeGetButtonBackgroundBounds worked) |
|
1136 |
switch (buttonKind){ |
|
1137 |
case kThemePopupButton: |
|
1138 |
innerBounds.origin.x += 2; |
|
1139 |
innerBounds.origin.y += 3; |
|
1140 |
innerBounds.size.width -= 5; |
|
1141 |
innerBounds.size.height -= 6; |
|
1142 |
break; |
|
1143 |
case kThemePopupButtonSmall: |
|
1144 |
innerBounds.origin.x += 3; |
|
1145 |
innerBounds.origin.y += 3; |
|
1146 |
innerBounds.size.width -= 6; |
|
1147 |
innerBounds.size.height -= 7; |
|
1148 |
break; |
|
1149 |
case kThemePopupButtonMini: |
|
1150 |
innerBounds.origin.x += 2; |
|
1151 |
innerBounds.origin.y += 2; |
|
1152 |
innerBounds.size.width -= 5; |
|
1153 |
innerBounds.size.height -= 6; |
|
1154 |
break; |
|
1155 |
case kThemeComboBox: |
|
1156 |
innerBounds.origin.x += 3; |
|
1157 |
innerBounds.origin.y += 3; |
|
1158 |
innerBounds.size.width -= 6; |
|
1159 |
innerBounds.size.height -= 6; |
|
1160 |
break; |
|
1161 |
case kThemeComboBoxSmall: |
|
1162 |
innerBounds.origin.x += 3; |
|
1163 |
innerBounds.origin.y += 3; |
|
1164 |
innerBounds.size.width -= 7; |
|
1165 |
innerBounds.size.height -= 8; |
|
1166 |
break; |
|
1167 |
case kThemeComboBoxMini: |
|
1168 |
innerBounds.origin.x += 3; |
|
1169 |
innerBounds.origin.y += 3; |
|
1170 |
innerBounds.size.width -= 4; |
|
1171 |
innerBounds.size.height -= 8; |
|
1172 |
break; |
|
1173 |
default: |
|
1174 |
break; |
|
1175 |
} |
|
1176 |
return innerBounds; |
|
1177 |
} |
|
1178 |
||
1179 |
/** |
|
1180 |
Inside a combobox Qt places a line edit widget. The size of this widget should depend on the kind |
|
1181 |
of combobox we choose to draw. This function calculates and returns this size. |
|
1182 |
*/ |
|
1183 |
QRect QMacStylePrivate::comboboxEditBounds(const QRect &outerBounds, const HIThemeButtonDrawInfo &bdi) |
|
1184 |
{ |
|
1185 |
QRect ret = outerBounds; |
|
1186 |
switch (bdi.kind){ |
|
1187 |
case kThemeComboBox: |
|
1188 |
ret.adjust(5, 8, -21, -4); |
|
1189 |
break; |
|
1190 |
case kThemeComboBoxSmall: |
|
1191 |
ret.adjust(4, 5, -18, 0); |
|
1192 |
ret.setHeight(16); |
|
1193 |
break; |
|
1194 |
case kThemeComboBoxMini: |
|
1195 |
ret.adjust(4, 5, -16, 0); |
|
1196 |
ret.setHeight(13); |
|
1197 |
break; |
|
1198 |
case kThemePopupButton: |
|
1199 |
ret.adjust(10, 3, -23, -3); |
|
1200 |
break; |
|
1201 |
case kThemePopupButtonSmall: |
|
1202 |
ret.adjust(9, 3, -20, -3); |
|
1203 |
break; |
|
1204 |
case kThemePopupButtonMini: |
|
1205 |
ret.adjust(8, 3, -19, 0); |
|
1206 |
ret.setHeight(13); |
|
1207 |
break; |
|
1208 |
} |
|
1209 |
return ret; |
|
1210 |
} |
|
1211 |
||
1212 |
/** |
|
1213 |
Carbon comboboxes don't scale (sight). If the size of the combo suggest a scaled version, |
|
1214 |
create it manually by drawing a small Carbon combo onto a pixmap (use pixmap cache), chop |
|
1215 |
it up, and copy it back onto the widget. Othervise, draw the combobox supplied by Carbon directly. |
|
1216 |
*/ |
|
1217 |
void QMacStylePrivate::drawCombobox(const HIRect &outerBounds, const HIThemeButtonDrawInfo &bdi, QPainter *p) |
|
1218 |
{ |
|
1219 |
if (!(bdi.kind == kThemeComboBox && outerBounds.size.height > 28)){ |
|
1220 |
// We have an unscaled combobox, or popup-button; use Carbon directly. |
|
1221 |
HIRect innerBounds = QMacStylePrivate::comboboxInnerBounds(outerBounds, bdi.kind); |
|
1222 |
HIThemeDrawButton(&innerBounds, &bdi, QMacCGContext(p), kHIThemeOrientationNormal, 0); |
|
1223 |
} else { |
|
1224 |
QPixmap buffer; |
|
1225 |
QString key = QString(QLatin1String("$qt_cbox%1-%2")).arg(int(bdi.state)).arg(int(bdi.adornment)); |
|
1226 |
if (!QPixmapCache::find(key, buffer)) { |
|
1227 |
HIRect innerBoundsSmallCombo = {{3, 3}, {29, 25}}; |
|
1228 |
buffer = QPixmap(35, 28); |
|
1229 |
buffer.fill(Qt::transparent); |
|
1230 |
QPainter buffPainter(&buffer); |
|
1231 |
HIThemeDrawButton(&innerBoundsSmallCombo, &bdi, QMacCGContext(&buffPainter), kHIThemeOrientationNormal, 0); |
|
1232 |
buffPainter.end(); |
|
1233 |
QPixmapCache::insert(key, buffer); |
|
1234 |
} |
|
1235 |
||
1236 |
const int bwidth = 20; |
|
1237 |
const int fwidth = 10; |
|
1238 |
const int fheight = 10; |
|
1239 |
int w = qRound(outerBounds.size.width); |
|
1240 |
int h = qRound(outerBounds.size.height); |
|
1241 |
int bstart = w - bwidth; |
|
1242 |
int blower = fheight + 1; |
|
1243 |
int flower = h - fheight; |
|
1244 |
int sheight = flower - fheight; |
|
1245 |
int center = qRound(outerBounds.size.height + outerBounds.origin.y) / 2; |
|
1246 |
||
1247 |
// Draw upper and lower gap |
|
1248 |
p->drawPixmap(fwidth, 0, bstart - fwidth, fheight, buffer, fwidth, 0, 1, fheight); |
|
1249 |
p->drawPixmap(fwidth, flower, bstart - fwidth, fheight, buffer, fwidth, buffer.height() - fheight, 1, fheight); |
|
1250 |
// Draw left and right gap. Right gap is drawn top and bottom separatly |
|
1251 |
p->drawPixmap(0, fheight, fwidth, sheight, buffer, 0, fheight, fwidth, 1); |
|
1252 |
p->drawPixmap(bstart, fheight, bwidth, center - fheight, buffer, buffer.width() - bwidth, fheight - 1, bwidth, 1); |
|
1253 |
p->drawPixmap(bstart, center, bwidth, sheight / 2, buffer, buffer.width() - bwidth, fheight + 6, bwidth, 1); |
|
1254 |
// Draw arrow |
|
1255 |
p->drawPixmap(bstart, center - 4, bwidth - 3, 6, buffer, buffer.width() - bwidth, fheight, bwidth - 3, 6); |
|
1256 |
// Draw corners |
|
1257 |
p->drawPixmap(0, 0, fwidth, fheight, buffer, 0, 0, fwidth, fheight); |
|
1258 |
p->drawPixmap(bstart, 0, bwidth, fheight, buffer, buffer.width() - bwidth, 0, bwidth, fheight); |
|
1259 |
p->drawPixmap(0, flower, fwidth, fheight, buffer, 0, buffer.height() - fheight, fwidth, fheight); |
|
1260 |
p->drawPixmap(bstart, h - blower, bwidth, blower, buffer, buffer.width() - bwidth, buffer.height() - blower, bwidth, blower); |
|
1261 |
} |
|
1262 |
} |
|
1263 |
||
1264 |
/** |
|
1265 |
Carbon tableheaders don't scale (sight). So create it manually by drawing a small Carbon header |
|
1266 |
onto a pixmap (use pixmap cache), chop it up, and copy it back onto the widget. |
|
1267 |
*/ |
|
1268 |
void QMacStylePrivate::drawTableHeader(const HIRect &outerBounds, |
|
1269 |
bool drawTopBorder, bool drawLeftBorder, const HIThemeButtonDrawInfo &bdi, QPainter *p) |
|
1270 |
{ |
|
1271 |
static SInt32 headerHeight = 0; |
|
1272 |
static OSStatus err = GetThemeMetric(kThemeMetricListHeaderHeight, &headerHeight); |
|
1273 |
Q_UNUSED(err); |
|
1274 |
||
1275 |
QPixmap buffer; |
|
1276 |
QString key = QString(QLatin1String("$qt_tableh%1-%2-%3")).arg(int(bdi.state)).arg(int(bdi.adornment)).arg(int(bdi.value)); |
|
1277 |
if (!QPixmapCache::find(key, buffer)) { |
|
1278 |
HIRect headerNormalRect = {{0., 0.}, {16., CGFloat(headerHeight)}}; |
|
1279 |
buffer = QPixmap(headerNormalRect.size.width, headerNormalRect.size.height); |
|
1280 |
buffer.fill(Qt::transparent); |
|
1281 |
QPainter buffPainter(&buffer); |
|
1282 |
HIThemeDrawButton(&headerNormalRect, &bdi, QMacCGContext(&buffPainter), kHIThemeOrientationNormal, 0); |
|
1283 |
buffPainter.end(); |
|
1284 |
QPixmapCache::insert(key, buffer); |
|
1285 |
} |
|
1286 |
const int buttonw = qRound(outerBounds.size.width); |
|
1287 |
const int buttonh = qRound(outerBounds.size.height); |
|
1288 |
const int framew = 1; |
|
1289 |
const int frameh_n = 4; |
|
1290 |
const int frameh_s = 3; |
|
1291 |
const int transh = buffer.height() - frameh_n - frameh_s; |
|
1292 |
int center = buttonh - frameh_s - int(transh / 2.0f) + 1; // Align bottom; |
|
1293 |
||
1294 |
int skipTopBorder = 0; |
|
1295 |
if (!drawTopBorder) |
|
1296 |
skipTopBorder = 1; |
|
1297 |
||
1298 |
p->translate(outerBounds.origin.x, outerBounds.origin.y); |
|
1299 |
||
1300 |
p->drawPixmap(QRect(QRect(0, -skipTopBorder, buttonw - framew , frameh_n)), buffer, QRect(framew, 0, 1, frameh_n)); |
|
1301 |
p->drawPixmap(QRect(0, buttonh - frameh_s, buttonw - framew, frameh_s), buffer, QRect(framew, buffer.height() - frameh_s, 1, frameh_s)); |
|
1302 |
// Draw upper and lower center blocks |
|
1303 |
p->drawPixmap(QRect(0, frameh_n - skipTopBorder, buttonw - framew, center - frameh_n + skipTopBorder), buffer, QRect(framew, frameh_n, 1, 1)); |
|
1304 |
p->drawPixmap(QRect(0, center, buttonw - framew, buttonh - center - frameh_s), buffer, QRect(framew, buffer.height() - frameh_s, 1, 1)); |
|
1305 |
// Draw right center block borders |
|
1306 |
p->drawPixmap(QRect(buttonw - framew, frameh_n - skipTopBorder, framew, center - frameh_n), buffer, QRect(buffer.width() - framew, frameh_n, framew, 1)); |
|
1307 |
p->drawPixmap(QRect(buttonw - framew, center, framew, buttonh - center - 1), buffer, QRect(buffer.width() - framew, buffer.height() - frameh_s, framew, 1)); |
|
1308 |
// Draw right corners |
|
1309 |
p->drawPixmap(QRect(buttonw - framew, -skipTopBorder, framew, frameh_n), buffer, QRect(buffer.width() - framew, 0, framew, frameh_n)); |
|
1310 |
p->drawPixmap(QRect(buttonw - framew, buttonh - frameh_s, framew, frameh_s), buffer, QRect(buffer.width() - framew, buffer.height() - frameh_s, framew, frameh_s)); |
|
1311 |
// Draw center transition block |
|
1312 |
p->drawPixmap(QRect(0, center - qRound(transh / 2.0f), buttonw - framew, buffer.height() - frameh_n - frameh_s), buffer, QRect(framew, frameh_n + 1, 1, transh)); |
|
1313 |
// Draw right center transition block border |
|
1314 |
p->drawPixmap(QRect(buttonw - framew, center - qRound(transh / 2.0f), framew, buffer.height() - frameh_n - frameh_s), buffer, QRect(buffer.width() - framew, frameh_n + 1, framew, transh)); |
|
1315 |
if (drawLeftBorder){ |
|
1316 |
// Draw left center block borders |
|
1317 |
p->drawPixmap(QRect(0, frameh_n - skipTopBorder, framew, center - frameh_n + skipTopBorder), buffer, QRect(0, frameh_n, framew, 1)); |
|
1318 |
p->drawPixmap(QRect(0, center, framew, buttonh - center - 1), buffer, QRect(0, buffer.height() - frameh_s, framew, 1)); |
|
1319 |
// Draw left corners |
|
1320 |
p->drawPixmap(QRect(0, -skipTopBorder, framew, frameh_n), buffer, QRect(0, 0, framew, frameh_n)); |
|
1321 |
p->drawPixmap(QRect(0, buttonh - frameh_s, framew, frameh_s), buffer, QRect(0, buffer.height() - frameh_s, framew, frameh_s)); |
|
1322 |
// Draw left center transition block border |
|
1323 |
p->drawPixmap(QRect(0, center - qRound(transh / 2.0f), framew, buffer.height() - frameh_n - frameh_s), buffer, QRect(0, frameh_n + 1, framew, transh)); |
|
1324 |
} |
|
1325 |
||
1326 |
p->translate(-outerBounds.origin.x, -outerBounds.origin.y); |
|
1327 |
} |
|
1328 |
||
1329 |
/* |
|
1330 |
Returns cutoff sizes for scroll bars. |
|
1331 |
thumbIndicatorCutoff is the smallest size where the thumb indicator is drawn. |
|
1332 |
scrollButtonsCutoff is the smallest size where the up/down buttons is drawn. |
|
1333 |
*/ |
|
1334 |
enum ScrollBarCutoffType { thumbIndicatorCutoff = 0, scrollButtonsCutoff = 1 }; |
|
1335 |
static int scrollButtonsCutoffSize(ScrollBarCutoffType cutoffType, QMacStyle::WidgetSizePolicy widgetSize) |
|
1336 |
{ |
|
1337 |
// Mini scroll bars do not exist as of version 10.4. |
|
1338 |
if (widgetSize == QMacStyle::SizeMini) |
|
1339 |
return 0; |
|
1340 |
||
1341 |
const int sizeIndex = (widgetSize == QMacStyle::SizeSmall) ? 1 : 0; |
|
1342 |
static const int sizeTable[2][2] = { { 61, 56 }, { 49, 44 } }; |
|
1343 |
return sizeTable[sizeIndex][cutoffType]; |
|
1344 |
} |
|
1345 |
||
1346 |
void QMacStylePrivate::getSliderInfo(QStyle::ComplexControl cc, const QStyleOptionSlider *slider, |
|
1347 |
HIThemeTrackDrawInfo *tdi, const QWidget *needToRemoveMe) |
|
1348 |
{ |
|
1349 |
memset(tdi, 0, sizeof(HIThemeTrackDrawInfo)); // We don't get it all for some reason or another... |
|
1350 |
tdi->version = qt_mac_hitheme_version; |
|
1351 |
tdi->reserved = 0; |
|
1352 |
tdi->filler1 = 0; |
|
1353 |
bool isScrollbar = (cc == QStyle::CC_ScrollBar); |
|
1354 |
switch (aquaSizeConstrain(0, needToRemoveMe)) { |
|
1355 |
case QAquaSizeUnknown: |
|
1356 |
case QAquaSizeLarge: |
|
1357 |
if (isScrollbar) |
|
1358 |
tdi->kind = kThemeMediumScrollBar; |
|
1359 |
else |
|
1360 |
tdi->kind = kThemeMediumSlider; |
|
1361 |
break; |
|
1362 |
case QAquaSizeMini: |
|
1363 |
if (isScrollbar) |
|
1364 |
tdi->kind = kThemeSmallScrollBar; // should be kThemeMiniScrollBar, but not implemented |
|
1365 |
else |
|
1366 |
tdi->kind = kThemeMiniSlider; |
|
1367 |
break; |
|
1368 |
case QAquaSizeSmall: |
|
1369 |
if (isScrollbar) |
|
1370 |
tdi->kind = kThemeSmallScrollBar; |
|
1371 |
else |
|
1372 |
tdi->kind = kThemeSmallSlider; |
|
1373 |
break; |
|
1374 |
} |
|
1375 |
tdi->bounds = qt_hirectForQRect(slider->rect); |
|
1376 |
tdi->min = slider->minimum; |
|
1377 |
tdi->max = slider->maximum; |
|
1378 |
tdi->value = slider->sliderPosition; |
|
1379 |
tdi->attributes = kThemeTrackShowThumb; |
|
1380 |
if (slider->upsideDown) |
|
1381 |
tdi->attributes |= kThemeTrackRightToLeft; |
|
1382 |
if (slider->orientation == Qt::Horizontal) { |
|
1383 |
tdi->attributes |= kThemeTrackHorizontal; |
|
1384 |
if (isScrollbar && slider->direction == Qt::RightToLeft) { |
|
1385 |
if (!slider->upsideDown) |
|
1386 |
tdi->attributes |= kThemeTrackRightToLeft; |
|
1387 |
else |
|
1388 |
tdi->attributes &= ~kThemeTrackRightToLeft; |
|
1389 |
} |
|
1390 |
} |
|
1391 |
||
1392 |
// Tiger broke reverse scroll bars so put them back and "fake it" |
|
1393 |
if (isScrollbar && (tdi->attributes & kThemeTrackRightToLeft)) { |
|
1394 |
tdi->attributes &= ~kThemeTrackRightToLeft; |
|
1395 |
tdi->value = tdi->max - slider->sliderPosition; |
|
1396 |
} |
|
1397 |
||
1398 |
tdi->enableState = (slider->state & QStyle::State_Enabled) ? kThemeTrackActive |
|
1399 |
: kThemeTrackDisabled; |
|
1400 |
if (!(slider->state & QStyle::State_Active)) |
|
1401 |
tdi->enableState = kThemeTrackInactive; |
|
1402 |
if (!isScrollbar) { |
|
1403 |
if (slider->state & QStyle::QStyle::State_HasFocus) |
|
1404 |
tdi->attributes |= kThemeTrackHasFocus; |
|
1405 |
if (slider->tickPosition == QSlider::NoTicks || slider->tickPosition == QSlider::TicksBothSides) |
|
1406 |
tdi->trackInfo.slider.thumbDir = kThemeThumbPlain; |
|
1407 |
else if (slider->tickPosition == QSlider::TicksAbove) |
|
1408 |
tdi->trackInfo.slider.thumbDir = kThemeThumbUpward; |
|
1409 |
else |
|
1410 |
tdi->trackInfo.slider.thumbDir = kThemeThumbDownward; |
|
1411 |
} else { |
|
1412 |
tdi->trackInfo.scrollbar.viewsize = slider->pageStep; |
|
1413 |
} |
|
1414 |
} |
|
1415 |
#endif |
|
1416 |
||
1417 |
QMacStylePrivate::QMacStylePrivate(QMacStyle *style) |
|
1418 |
: timerID(-1), progressFrame(0), q(style), mouseDown(false) |
|
1419 |
{ |
|
1420 |
defaultButtonStart = CFAbsoluteTimeGetCurrent(); |
|
1421 |
memset(&buttonState, 0, sizeof(ButtonState)); |
|
1422 |
||
1423 |
if (ptrHIShapeGetBounds == 0) { |
|
1424 |
QLibrary library(QLatin1String("/System/Library/Frameworks/Carbon.framework/Carbon")); |
|
1425 |
library.setLoadHints(QLibrary::ExportExternalSymbolsHint); |
|
1426 |
ptrHIShapeGetBounds = reinterpret_cast<PtrHIShapeGetBounds>(library.resolve("HIShapeGetBounds")); |
|
1427 |
} |
|
1428 |
||
1429 |
} |
|
1430 |
||
1431 |
bool QMacStylePrivate::animatable(QMacStylePrivate::Animates as, const QWidget *w) const |
|
1432 |
{ |
|
1433 |
if (as == AquaPushButton) { |
|
1434 |
QPushButton *pb = const_cast<QPushButton *>(static_cast<const QPushButton *>(w)); |
|
1435 |
if (w->window()->isActiveWindow() && pb && !mouseDown) { |
|
1436 |
if (static_cast<const QPushButton *>(w) != defaultButton) { |
|
1437 |
// Changed on its own, update the value. |
|
1438 |
const_cast<QMacStylePrivate *>(this)->stopAnimate(as, defaultButton); |
|
1439 |
const_cast<QMacStylePrivate *>(this)->startAnimate(as, pb); |
|
1440 |
} |
|
1441 |
return true; |
|
1442 |
} |
|
1443 |
} else if (as == AquaProgressBar) { |
|
1444 |
if (progressBars.contains((const_cast<QWidget *>(w)))) |
|
1445 |
return true; |
|
1446 |
} |
|
1447 |
return false; |
|
1448 |
} |
|
1449 |
||
1450 |
void QMacStylePrivate::stopAnimate(QMacStylePrivate::Animates as, QWidget *w) |
|
1451 |
{ |
|
1452 |
if (as == AquaPushButton && defaultButton) { |
|
1453 |
QPushButton *tmp = defaultButton; |
|
1454 |
defaultButton = 0; |
|
1455 |
tmp->update(); |
|
1456 |
} else if (as == AquaProgressBar) { |
|
1457 |
progressBars.removeAll(w); |
|
1458 |
} |
|
1459 |
} |
|
1460 |
||
1461 |
void QMacStylePrivate::startAnimate(QMacStylePrivate::Animates as, QWidget *w) |
|
1462 |
{ |
|
1463 |
if (as == AquaPushButton) |
|
1464 |
defaultButton = static_cast<QPushButton *>(w); |
|
1465 |
else if (as == AquaProgressBar) |
|
1466 |
progressBars.append(w); |
|
1467 |
startAnimationTimer(); |
|
1468 |
} |
|
1469 |
||
1470 |
void QMacStylePrivate::startAnimationTimer() |
|
1471 |
{ |
|
1472 |
if ((defaultButton || !progressBars.isEmpty()) && timerID <= -1) |
|
1473 |
timerID = startTimer(animateSpeed(AquaListViewItemOpen)); |
|
1474 |
} |
|
1475 |
||
1476 |
bool QMacStylePrivate::addWidget(QWidget *w) |
|
1477 |
{ |
|
1478 |
//already knew of it |
|
1479 |
if (static_cast<QPushButton*>(w) == defaultButton |
|
1480 |
|| progressBars.contains(static_cast<QProgressBar*>(w))) |
|
1481 |
return false; |
|
1482 |
||
1483 |
if (QPushButton *btn = qobject_cast<QPushButton *>(w)) { |
|
1484 |
btn->installEventFilter(this); |
|
1485 |
if (btn->isDefault() || (btn->autoDefault() && btn->hasFocus())) |
|
1486 |
startAnimate(AquaPushButton, btn); |
|
1487 |
return true; |
|
1488 |
} else { |
|
1489 |
bool isProgressBar = (qobject_cast<QProgressBar *>(w) |
|
1490 |
#ifdef QT3_SUPPORT |
|
1491 |
|| w->inherits("Q3ProgressBar") |
|
1492 |
#endif |
|
1493 |
); |
|
1494 |
if (isProgressBar) { |
|
1495 |
w->installEventFilter(this); |
|
1496 |
startAnimate(AquaProgressBar, w); |
|
1497 |
return true; |
|
1498 |
} |
|
1499 |
} |
|
1500 |
if (w->isWindow()) { |
|
1501 |
w->installEventFilter(this); |
|
1502 |
return true; |
|
1503 |
} |
|
1504 |
return false; |
|
1505 |
} |
|
1506 |
||
1507 |
void QMacStylePrivate::removeWidget(QWidget *w) |
|
1508 |
{ |
|
1509 |
QPushButton *btn = qobject_cast<QPushButton *>(w); |
|
1510 |
if (btn && btn == defaultButton) { |
|
1511 |
stopAnimate(AquaPushButton, btn); |
|
1512 |
} else if (qobject_cast<QProgressBar *>(w) |
|
1513 |
#ifdef QT3_SUPPORT |
|
1514 |
|| w->inherits("Q3ProgressBar") |
|
1515 |
#endif |
|
1516 |
) { |
|
1517 |
stopAnimate(AquaProgressBar, w); |
|
1518 |
} |
|
1519 |
} |
|
1520 |
||
1521 |
ThemeDrawState QMacStylePrivate::getDrawState(QStyle::State flags) |
|
1522 |
{ |
|
1523 |
ThemeDrawState tds = kThemeStateActive; |
|
1524 |
if (flags & QStyle::State_Sunken) { |
|
1525 |
tds = kThemeStatePressed; |
|
1526 |
} else if (flags & QStyle::State_Active) { |
|
1527 |
if (!(flags & QStyle::State_Enabled)) |
|
1528 |
tds = kThemeStateUnavailable; |
|
1529 |
} else { |
|
1530 |
if (flags & QStyle::State_Enabled) |
|
1531 |
tds = kThemeStateInactive; |
|
1532 |
else |
|
1533 |
tds = kThemeStateUnavailableInactive; |
|
1534 |
} |
|
1535 |
return tds; |
|
1536 |
} |
|
1537 |
||
1538 |
void QMacStylePrivate::timerEvent(QTimerEvent *) |
|
1539 |
{ |
|
1540 |
int animated = 0; |
|
1541 |
if (defaultButton && defaultButton->isEnabled() && defaultButton->window()->isActiveWindow() |
|
1542 |
&& defaultButton->isVisibleTo(0) && (defaultButton->isDefault() |
|
1543 |
|| (defaultButton->autoDefault() && defaultButton->hasFocus())) |
|
1544 |
&& doAnimate(AquaPushButton)) { |
|
1545 |
++animated; |
|
1546 |
defaultButton->update(); |
|
1547 |
} |
|
1548 |
if (!progressBars.isEmpty()) { |
|
1549 |
int i = 0; |
|
1550 |
while (i < progressBars.size()) { |
|
1551 |
QWidget *maybeProgress = progressBars.at(i); |
|
1552 |
if (!maybeProgress) { |
|
1553 |
progressBars.removeAt(i); |
|
1554 |
} else { |
|
1555 |
if (QProgressBar *pb = qobject_cast<QProgressBar *>(maybeProgress)) { |
|
1556 |
if (pb->maximum() == 0 || pb->value() > 0 |
|
1557 |
&& pb->value() < pb->maximum()) { |
|
1558 |
if (doAnimate(AquaProgressBar)) |
|
1559 |
pb->update(); |
|
1560 |
} |
|
1561 |
} |
|
1562 |
#ifdef QT3_SUPPORT |
|
1563 |
else { |
|
1564 |
// Watch me now... |
|
1565 |
QVariant progress = maybeProgress->property("progress"); |
|
1566 |
QVariant totalSteps = maybeProgress->property("totalSteps"); |
|
1567 |
if (progress.isValid() && totalSteps.isValid()) { |
|
1568 |
int intProgress = progress.toInt(); |
|
1569 |
int intTotalSteps = totalSteps.toInt(); |
|
1570 |
if (intTotalSteps == 0 || intProgress > 0 && intProgress < intTotalSteps) { |
|
1571 |
if (doAnimate(AquaProgressBar)) |
|
1572 |
maybeProgress->update(); |
|
1573 |
} |
|
1574 |
} |
|
1575 |
} |
|
1576 |
#endif |
|
1577 |
++i; |
|
1578 |
} |
|
1579 |
} |
|
1580 |
if (i > 0) { |
|
1581 |
++progressFrame; |
|
1582 |
animated += i; |
|
1583 |
} |
|
1584 |
} |
|
1585 |
if (animated <= 0) { |
|
1586 |
killTimer(timerID); |
|
1587 |
timerID = -1; |
|
1588 |
} |
|
1589 |
} |
|
1590 |
||
1591 |
bool QMacStylePrivate::eventFilter(QObject *o, QEvent *e) |
|
1592 |
{ |
|
1593 |
//animate |
|
1594 |
if (QProgressBar *pb = qobject_cast<QProgressBar *>(o)) { |
|
1595 |
switch (e->type()) { |
|
1596 |
default: |
|
1597 |
break; |
|
1598 |
case QEvent::Show: |
|
1599 |
if (!progressBars.contains(pb)) |
|
1600 |
startAnimate(AquaProgressBar, pb); |
|
1601 |
break; |
|
1602 |
case QEvent::Destroy: |
|
1603 |
case QEvent::Hide: |
|
1604 |
progressBars.removeAll(pb); |
|
1605 |
} |
|
1606 |
} else if (QPushButton *btn = qobject_cast<QPushButton *>(o)) { |
|
1607 |
switch (e->type()) { |
|
1608 |
default: |
|
1609 |
break; |
|
1610 |
case QEvent::FocusIn: |
|
1611 |
if (btn->autoDefault()) |
|
1612 |
startAnimate(AquaPushButton, btn); |
|
1613 |
break; |
|
1614 |
case QEvent::Destroy: |
|
1615 |
case QEvent::Hide: |
|
1616 |
if (btn == defaultButton) |
|
1617 |
stopAnimate(AquaPushButton, btn); |
|
1618 |
break; |
|
1619 |
case QEvent::MouseButtonPress: |
|
1620 |
// It is very confusing to keep the button pulsing, so just stop the animation. |
|
1621 |
if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton) |
|
1622 |
mouseDown = true; |
|
1623 |
stopAnimate(AquaPushButton, btn); |
|
1624 |
break; |
|
1625 |
case QEvent::MouseButtonRelease: |
|
1626 |
if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton) |
|
1627 |
mouseDown = false; |
|
1628 |
// fall through |
|
1629 |
case QEvent::FocusOut: |
|
1630 |
case QEvent::Show: |
|
1631 |
case QEvent::WindowActivate: { |
|
1632 |
QList<QPushButton *> list = qFindChildren<QPushButton *>(btn->window()); |
|
1633 |
for (int i = 0; i < list.size(); ++i) { |
|
1634 |
QPushButton *pBtn = list.at(i); |
|
1635 |
if ((e->type() == QEvent::FocusOut |
|
1636 |
&& (pBtn->isDefault() || (pBtn->autoDefault() && pBtn->hasFocus())) |
|
1637 |
&& pBtn != btn) |
|
1638 |
|| ((e->type() == QEvent::Show || e->type() == QEvent::MouseButtonRelease |
|
1639 |
|| e->type() == QEvent::WindowActivate) |
|
1640 |
&& pBtn->isDefault())) { |
|
1641 |
if (pBtn->window()->isActiveWindow()) { |
|
1642 |
startAnimate(AquaPushButton, pBtn); |
|
1643 |
} |
|
1644 |
break; |
|
1645 |
} |
|
1646 |
} |
|
1647 |
break; } |
|
1648 |
} |
|
1649 |
} |
|
1650 |
return false; |
|
1651 |
} |
|
1652 |
||
1653 |
bool QMacStylePrivate::doAnimate(QMacStylePrivate::Animates as) |
|
1654 |
{ |
|
1655 |
if (as == AquaPushButton) { |
|
1656 |
} else if (as == AquaProgressBar) { |
|
1657 |
// something for later... |
|
1658 |
} else if (as == AquaListViewItemOpen) { |
|
1659 |
// To be revived later... |
|
1660 |
} |
|
1661 |
return true; |
|
1662 |
} |
|
1663 |
||
1664 |
void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonDrawInfo *bdi, |
|
1665 |
QPainter *p, const QStyleOption *opt) const |
|
1666 |
{ |
|
1667 |
int xoff = 0, |
|
1668 |
yoff = 0, |
|
1669 |
extraWidth = 0, |
|
1670 |
extraHeight = 0, |
|
1671 |
finalyoff = 0; |
|
1672 |
||
1673 |
const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt); |
|
1674 |
int width = int(macRect.size.width) + extraWidth; |
|
1675 |
int height = int(macRect.size.height) + extraHeight; |
|
1676 |
||
1677 |
if (width <= 0 || height <= 0) |
|
1678 |
return; // nothing to draw |
|
1679 |
||
1680 |
QString key = QLatin1String("$qt_mac_style_ctb_") + QString::number(bdi->kind) + QLatin1Char('_') |
|
1681 |
+ QString::number(bdi->value) + QLatin1Char('_') + QString::number(width) |
|
1682 |
+ QLatin1Char('_') + QString::number(height); |
|
1683 |
QPixmap pm; |
|
1684 |
if (!QPixmapCache::find(key, pm)) { |
|
1685 |
QPixmap activePixmap(width, height); |
|
1686 |
activePixmap.fill(Qt::transparent); |
|
1687 |
{ |
|
1688 |
if (combo){ |
|
1689 |
// Carbon combos don't scale. Therefore we draw it |
|
1690 |
// ourselves, if a scaled version is needed. |
|
1691 |
QPainter tmpPainter(&activePixmap); |
|
1692 |
QMacStylePrivate::drawCombobox(macRect, *bdi, &tmpPainter); |
|
1693 |
} |
|
1694 |
else { |
|
1695 |
QMacCGContext cg(&activePixmap); |
|
1696 |
HIRect newRect = CGRectMake(xoff, yoff, macRect.size.width, macRect.size.height); |
|
1697 |
HIThemeDrawButton(&newRect, bdi, cg, kHIThemeOrientationNormal, 0); |
|
1698 |
} |
|
1699 |
} |
|
1700 |
||
1701 |
if (!combo && bdi->value == kThemeButtonOff) { |
|
1702 |
pm = activePixmap; |
|
1703 |
} else if (combo) { |
|
1704 |
QImage image = activePixmap.toImage(); |
|
1705 |
||
1706 |
for (int y = 0; y < height; ++y) { |
|
1707 |
QRgb *scanLine = reinterpret_cast<QRgb *>(image.scanLine(y)); |
|
1708 |
||
1709 |
for (int x = 0; x < width; ++x) { |
|
1710 |
QRgb &pixel = scanLine[x]; |
|
1711 |
||
1712 |
int darkest = qRed(pixel); |
|
1713 |
int mid = qGreen(pixel); |
|
1714 |
int lightest = qBlue(pixel); |
|
1715 |
||
1716 |
if (darkest > mid) |
|
1717 |
qSwap(darkest, mid); |
|
1718 |
if (mid > lightest) |
|
1719 |
qSwap(mid, lightest); |
|
1720 |
if (darkest > mid) |
|
1721 |
qSwap(darkest, mid); |
|
1722 |
||
1723 |
int gray = (mid + 2 * lightest) / 3; |
|
1724 |
pixel = qRgba(gray, gray, gray, qAlpha(pixel)); |
|
1725 |
} |
|
1726 |
} |
|
1727 |
pm = QPixmap::fromImage(image); |
|
1728 |
} else { |
|
1729 |
QImage activeImage = activePixmap.toImage(); |
|
1730 |
QImage colorlessImage; |
|
1731 |
{ |
|
1732 |
QPixmap colorlessPixmap(width, height); |
|
1733 |
colorlessPixmap.fill(Qt::transparent); |
|
1734 |
||
1735 |
QMacCGContext cg(&colorlessPixmap); |
|
1736 |
HIRect newRect = CGRectMake(xoff, yoff, macRect.size.width, macRect.size.height); |
|
1737 |
int oldValue = bdi->value; |
|
1738 |
bdi->value = kThemeButtonOff; |
|
1739 |
HIThemeDrawButton(&newRect, bdi, cg, kHIThemeOrientationNormal, 0); |
|
1740 |
bdi->value = oldValue; |
|
1741 |
colorlessImage = colorlessPixmap.toImage(); |
|
1742 |
} |
|
1743 |
||
1744 |
for (int y = 0; y < height; ++y) { |
|
1745 |
QRgb *colorlessScanLine = reinterpret_cast<QRgb *>(colorlessImage.scanLine(y)); |
|
1746 |
const QRgb *activeScanLine = reinterpret_cast<const QRgb *>(activeImage.scanLine(y)); |
|
1747 |
||
1748 |
for (int x = 0; x < width; ++x) { |
|
1749 |
QRgb &colorlessPixel = colorlessScanLine[x]; |
|
1750 |
QRgb activePixel = activeScanLine[x]; |
|
1751 |
||
1752 |
if (activePixel != colorlessPixel) { |
|
1753 |
int max = qMax(qMax(qRed(activePixel), qGreen(activePixel)), |
|
1754 |
qBlue(activePixel)); |
|
1755 |
QRgb newPixel = qRgba(max, max, max, qAlpha(activePixel)); |
|
1756 |
if (qGray(newPixel) < qGray(colorlessPixel) |
|
1757 |
|| qAlpha(newPixel) > qAlpha(colorlessPixel)) |
|
1758 |
colorlessPixel = newPixel; |
|
1759 |
} |
|
1760 |
} |
|
1761 |
} |
|
1762 |
pm = QPixmap::fromImage(colorlessImage); |
|
1763 |
} |
|
1764 |
QPixmapCache::insert(key, pm); |
|
1765 |
} |
|
1766 |
p->drawPixmap(int(macRect.origin.x), int(macRect.origin.y) + finalyoff, width, height, pm); |
|
1767 |
} |
|
1768 |
||
1769 |
QMacStyle::QMacStyle() |
|
1770 |
: QWindowsStyle() |
|
1771 |
{ |
|
1772 |
d = new QMacStylePrivate(this); |
|
1773 |
} |
|
1774 |
||
1775 |
QMacStyle::~QMacStyle() |
|
1776 |
{ |
|
1777 |
delete qt_mac_backgroundPattern; |
|
1778 |
qt_mac_backgroundPattern = 0; |
|
1779 |
delete d; |
|
1780 |
} |
|
1781 |
||
1782 |
/*! \internal |
|
1783 |
Generates the standard widget background pattern. |
|
1784 |
*/ |
|
1785 |
QPixmap QMacStylePrivate::generateBackgroundPattern() const |
|
1786 |
{ |
|
1787 |
QPixmap px(4, 4); |
|
1788 |
QMacCGContext cg(&px); |
|
1789 |
HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationNormal); |
|
1790 |
const CGRect cgRect = CGRectMake(0, 0, px.width(), px.height()); |
|
1791 |
CGContextFillRect(cg, cgRect); |
|
1792 |
return px; |
|
1793 |
} |
|
1794 |
||
1795 |
/*! \internal |
|
1796 |
Fills the given \a rect with the pattern stored in \a brush. As an optimization, |
|
1797 |
HIThemeSetFill us used directly if we are filling with the standard background. |
|
1798 |
*/ |
|
1799 |
void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush) |
|
1800 |
{ |
|
1801 |
QPoint dummy; |
|
1802 |
const QPaintDevice *target = painter->device(); |
|
1803 |
const QPaintDevice *redirected = QPainter::redirected(target, &dummy); |
|
1804 |
const bool usePainter = redirected && redirected != target; |
|
1805 |
||
1806 |
if (!usePainter && qt_mac_backgroundPattern |
|
1807 |
&& qt_mac_backgroundPattern->cacheKey() == brush.texture().cacheKey()) { |
|
1808 |
||
1809 |
painter->setClipRegion(rgn); |
|
1810 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1811 |
QCFType<CGContextRef> cg = qt_mac_cg_context(target); |
0 | 1812 |
CGContextSaveGState(cg); |
1813 |
HIThemeSetFill(kThemeBrushDialogBackgroundActive, 0, cg, kHIThemeOrientationInverted); |
|
1814 |
||
1815 |
const QVector<QRect> &rects = rgn.rects(); |
|
1816 |
for (int i = 0; i < rects.size(); ++i) { |
|
1817 |
const QRect rect(rects.at(i)); |
|
1818 |
// Anchor the pattern to the top so it stays put when the window is resized. |
|
1819 |
CGContextSetPatternPhase(cg, CGSizeMake(rect.width(), rect.height())); |
|
1820 |
CGRect mac_rect = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()); |
|
1821 |
CGContextFillRect(cg, mac_rect); |
|
1822 |
} |
|
1823 |
||
1824 |
CGContextRestoreGState(cg); |
|
1825 |
} else { |
|
1826 |
const QRect rect(rgn.boundingRect()); |
|
1827 |
painter->setClipRegion(rgn); |
|
1828 |
painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); |
|
1829 |
} |
|
1830 |
} |
|
1831 |
||
1832 |
void QMacStyle::polish(QPalette &pal) |
|
1833 |
{ |
|
1834 |
if (!qt_mac_backgroundPattern) { |
|
1835 |
if (!qApp) |
|
1836 |
return; |
|
1837 |
qt_mac_backgroundPattern = new QPixmap(d->generateBackgroundPattern()); |
|
1838 |
} |
|
1839 |
||
1840 |
QColor pc(Qt::black); |
|
1841 |
pc = qcolorForTheme(kThemeBrushDialogBackgroundActive); |
|
1842 |
QBrush background(pc, *qt_mac_backgroundPattern); |
|
1843 |
pal.setBrush(QPalette::All, QPalette::Window, background); |
|
1844 |
pal.setBrush(QPalette::All, QPalette::Button, background); |
|
1845 |
||
1846 |
QCFString theme; |
|
1847 |
const OSErr err = CopyThemeIdentifier(&theme); |
|
1848 |
if (err == noErr && CFStringCompare(theme, kThemeAppearanceAquaGraphite, 0) == kCFCompareEqualTo) { |
|
1849 |
pal.setBrush(QPalette::All, QPalette::AlternateBase, QColor(240, 240, 240)); |
|
1850 |
} else { |
|
1851 |
pal.setBrush(QPalette::All, QPalette::AlternateBase, QColor(237, 243, 254)); |
|
1852 |
} |
|
1853 |
} |
|
1854 |
||
1855 |
void QMacStyle::polish(QApplication *) |
|
1856 |
{ |
|
1857 |
} |
|
1858 |
||
1859 |
void QMacStyle::unpolish(QApplication *) |
|
1860 |
{ |
|
1861 |
} |
|
1862 |
||
1863 |
void QMacStyle::polish(QWidget* w) |
|
1864 |
{ |
|
1865 |
d->addWidget(w); |
|
1866 |
if (qt_mac_is_metal(w) && !w->testAttribute(Qt::WA_SetPalette)) { |
|
1867 |
// Set a clear brush so that the metal shines through. |
|
1868 |
QPalette pal = w->palette(); |
|
1869 |
QBrush background(Qt::transparent); |
|
1870 |
pal.setBrush(QPalette::All, QPalette::Window, background); |
|
1871 |
pal.setBrush(QPalette::All, QPalette::Button, background); |
|
1872 |
w->setPalette(pal); |
|
1873 |
w->setAttribute(Qt::WA_SetPalette, false); |
|
1874 |
} |
|
1875 |
||
1876 |
if (qobject_cast<QMenu*>(w) || qobject_cast<QComboBoxPrivateContainer *>(w)) { |
|
1877 |
w->setWindowOpacity(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 ? 0.985 : 0.94); |
|
1878 |
if (!w->testAttribute(Qt::WA_SetPalette)) { |
|
1879 |
QPixmap px(64, 64); |
|
1880 |
px.fill(Qt::white); |
|
1881 |
HIThemeMenuDrawInfo mtinfo; |
|
1882 |
mtinfo.version = qt_mac_hitheme_version; |
|
1883 |
mtinfo.menuType = kThemeMenuTypePopUp; |
|
1884 |
HIRect rect = CGRectMake(0, 0, px.width(), px.height()); |
|
1885 |
HIThemeDrawMenuBackground(&rect, &mtinfo, QCFType<CGContextRef>(qt_mac_cg_context(&px)), |
|
1886 |
kHIThemeOrientationNormal); |
|
1887 |
QPalette pal = w->palette(); |
|
1888 |
QBrush background(px); |
|
1889 |
pal.setBrush(QPalette::All, QPalette::Window, background); |
|
1890 |
pal.setBrush(QPalette::All, QPalette::Button, background); |
|
1891 |
w->setPalette(pal); |
|
1892 |
w->setAttribute(Qt::WA_SetPalette, false); |
|
1893 |
} |
|
1894 |
} |
|
1895 |
||
1896 |
if (QTabBar *tb = qobject_cast<QTabBar*>(w)) { |
|
1897 |
if (tb->documentMode()) { |
|
1898 |
w->setAttribute(Qt::WA_Hover); |
|
1899 |
w->setFont(qt_app_fonts_hash()->value("QSmallFont", QFont())); |
|
1900 |
QPalette p = w->palette(); |
|
1901 |
p.setColor(QPalette::WindowText, QColor(17, 17, 17)); |
|
1902 |
w->setPalette(p); |
|
1903 |
} |
|
1904 |
} |
|
1905 |
||
1906 |
QWindowsStyle::polish(w); |
|
1907 |
||
1908 |
if (QRubberBand *rubber = qobject_cast<QRubberBand*>(w)) { |
|
1909 |
rubber->setWindowOpacity(0.25); |
|
1910 |
rubber->setAttribute(Qt::WA_PaintOnScreen, false); |
|
1911 |
rubber->setAttribute(Qt::WA_NoSystemBackground, false); |
|
1912 |
} |
|
1913 |
} |
|
1914 |
||
1915 |
void QMacStyle::unpolish(QWidget* w) |
|
1916 |
{ |
|
1917 |
d->removeWidget(w); |
|
1918 |
if ((qobject_cast<QMenu*>(w) || qt_mac_is_metal(w)) && !w->testAttribute(Qt::WA_SetPalette)) { |
|
1919 |
QPalette pal = qApp->palette(w); |
|
1920 |
w->setPalette(pal); |
|
1921 |
w->setAttribute(Qt::WA_SetPalette, false); |
|
1922 |
w->setWindowOpacity(1.0); |
|
1923 |
} |
|
1924 |
||
1925 |
if (QComboBox *combo = qobject_cast<QComboBox *>(w)) { |
|
1926 |
if (!combo->isEditable()) { |
|
1927 |
if (QWidget *widget = combo->findChild<QComboBoxPrivateContainer *>()) |
|
1928 |
widget->setWindowOpacity(1.0); |
|
1929 |
} |
|
1930 |
} |
|
1931 |
||
1932 |
if (QRubberBand *rubber = ::qobject_cast<QRubberBand*>(w)) { |
|
1933 |
rubber->setWindowOpacity(1.0); |
|
1934 |
rubber->setAttribute(Qt::WA_PaintOnScreen, true); |
|
1935 |
rubber->setAttribute(Qt::WA_NoSystemBackground, true); |
|
1936 |
} |
|
1937 |
||
1938 |
if (QFocusFrame *frame = qobject_cast<QFocusFrame *>(w)) { |
|
1939 |
frame->setAttribute(Qt::WA_NoSystemBackground, true); |
|
1940 |
frame->setAutoFillBackground(true); |
|
1941 |
} |
|
1942 |
QWindowsStyle::unpolish(w); |
|
1943 |
} |
|
1944 |
||
1945 |
int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QWidget *widget) const |
|
1946 |
{ |
|
1947 |
int controlSize = getControlSize(opt, widget); |
|
1948 |
SInt32 ret = 0; |
|
1949 |
||
1950 |
switch (metric) { |
|
1951 |
case PM_TabCloseIndicatorWidth: |
|
1952 |
case PM_TabCloseIndicatorHeight: |
|
1953 |
ret = closeButtonSize; |
|
1954 |
break; |
|
1955 |
case PM_ToolBarIconSize: |
|
1956 |
ret = proxy()->pixelMetric(PM_LargeIconSize); |
|
1957 |
break; |
|
1958 |
case PM_FocusFrameVMargin: |
|
1959 |
case PM_FocusFrameHMargin: |
|
1960 |
GetThemeMetric(kThemeMetricFocusRectOutset, &ret); |
|
1961 |
break; |
|
1962 |
case PM_DialogButtonsSeparator: |
|
1963 |
ret = -5; |
|
1964 |
break; |
|
1965 |
case PM_DialogButtonsButtonHeight: { |
|
1966 |
QSize sz; |
|
1967 |
ret = d->aquaSizeConstrain(opt, 0, QStyle::CT_PushButton, QSize(-1, -1), &sz); |
|
1968 |
if (sz == QSize(-1, -1)) |
|
1969 |
ret = 32; |
|
1970 |
else |
|
1971 |
ret = sz.height(); |
|
1972 |
break; } |
|
1973 |
case PM_CheckListButtonSize: { |
|
1974 |
switch (d->aquaSizeConstrain(opt, widget)) { |
|
1975 |
case QAquaSizeUnknown: |
|
1976 |
case QAquaSizeLarge: |
|
1977 |
GetThemeMetric(kThemeMetricCheckBoxWidth, &ret); |
|
1978 |
break; |
|
1979 |
case QAquaSizeMini: |
|
1980 |
GetThemeMetric(kThemeMetricMiniCheckBoxWidth, &ret); |
|
1981 |
break; |
|
1982 |
case QAquaSizeSmall: |
|
1983 |
GetThemeMetric(kThemeMetricSmallCheckBoxWidth, &ret); |
|
1984 |
break; |
|
1985 |
} |
|
1986 |
break; } |
|
1987 |
case PM_DialogButtonsButtonWidth: { |
|
1988 |
QSize sz; |
|
1989 |
ret = d->aquaSizeConstrain(opt, 0, QStyle::CT_PushButton, QSize(-1, -1), &sz); |
|
1990 |
if (sz == QSize(-1, -1)) |
|
1991 |
ret = 70; |
|
1992 |
else |
|
1993 |
ret = sz.width(); |
|
1994 |
break; } |
|
1995 |
||
1996 |
case PM_MenuBarHMargin: |
|
1997 |
ret = 8; |
|
1998 |
break; |
|
1999 |
||
2000 |
case PM_MenuBarVMargin: |
|
2001 |
ret = 0; |
|
2002 |
break; |
|
2003 |
||
2004 |
case QStyle::PM_MenuDesktopFrameWidth: |
|
2005 |
ret = 5; |
|
2006 |
break; |
|
2007 |
||
2008 |
case PM_CheckBoxLabelSpacing: |
|
2009 |
case PM_RadioButtonLabelSpacing: |
|
2010 |
ret = 2; |
|
2011 |
break; |
|
2012 |
case PM_MenuScrollerHeight: |
|
2013 |
#if 0 |
|
2014 |
SInt16 ash, asw; |
|
2015 |
GetThemeMenuItemExtra(kThemeMenuItemScrollUpArrow, &ash, &asw); |
|
2016 |
ret = ash; |
|
2017 |
#else |
|
2018 |
ret = 15; // I hate having magic numbers in here... |
|
2019 |
#endif |
|
2020 |
break; |
|
2021 |
case PM_DefaultFrameWidth: |
|
2022 |
#ifndef QT_NO_MAINWINDOW |
|
2023 |
if (widget && (widget->isWindow() || !widget->parentWidget() |
|
2024 |
|| (qobject_cast<const QMainWindow*>(widget->parentWidget()) |
|
2025 |
&& static_cast<QMainWindow *>(widget->parentWidget())->centralWidget() == widget)) |
|
2026 |
&& (qobject_cast<const QAbstractScrollArea *>(widget) |
|
2027 |
#ifdef QT3_SUPPORT |
|
2028 |
|| widget->inherits("QScrollView") |
|
2029 |
#endif |
|
2030 |
|| widget->inherits("QWorkspaceChild"))) |
|
2031 |
ret = 0; |
|
2032 |
else |
|
2033 |
#endif |
|
2034 |
// The combo box popup has no frame. |
|
2035 |
if (qstyleoption_cast<const QStyleOptionComboBox *>(opt) != 0) |
|
2036 |
ret = 0; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2037 |
// Frame of mac style line edits is two pixels on top and one on the bottom |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2038 |
else if (qobject_cast<const QLineEdit *>(widget) != 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2039 |
ret = 2; |
0 | 2040 |
else |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2041 |
ret = 1; |
0 | 2042 |
break; |
2043 |
case PM_MaximumDragDistance: |
|
2044 |
ret = -1; |
|
2045 |
break; |
|
2046 |
case PM_ScrollBarSliderMin: |
|
2047 |
ret = 24; |
|
2048 |
break; |
|
2049 |
case PM_SpinBoxFrameWidth: |
|
2050 |
GetThemeMetric(kThemeMetricEditTextFrameOutset, &ret); |
|
2051 |
switch (d->aquaSizeConstrain(opt, widget)) { |
|
2052 |
default: |
|
2053 |
ret += 2; |
|
2054 |
break; |
|
2055 |
case QAquaSizeMini: |
|
2056 |
ret += 1; |
|
2057 |
break; |
|
2058 |
} |
|
2059 |
break; |
|
2060 |
case PM_ButtonShiftHorizontal: |
|
2061 |
case PM_ButtonShiftVertical: |
|
2062 |
ret = 0; |
|
2063 |
break; |
|
2064 |
case PM_SliderLength: |
|
2065 |
ret = 17; |
|
2066 |
break; |
|
2067 |
case PM_ButtonDefaultIndicator: |
|
2068 |
ret = 0; |
|
2069 |
break; |
|
2070 |
case PM_TitleBarHeight: |
|
2071 |
if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) { |
|
2072 |
HIThemeWindowDrawInfo wdi; |
|
2073 |
wdi.version = qt_mac_hitheme_version; |
|
2074 |
wdi.state = kThemeStateActive; |
|
2075 |
wdi.windowType = QtWinType; |
|
2076 |
if (tb->titleBarState) |
|
2077 |
wdi.attributes = kThemeWindowHasFullZoom | kThemeWindowHasCloseBox |
|
2078 |
| kThemeWindowHasCollapseBox; |
|
2079 |
else if (tb->titleBarFlags & Qt::WindowSystemMenuHint) |
|
2080 |
wdi.attributes = kThemeWindowHasCloseBox; |
|
2081 |
else |
|
2082 |
wdi.attributes = 0; |
|
2083 |
wdi.titleHeight = tb->rect.height(); |
|
2084 |
wdi.titleWidth = tb->rect.width(); |
|
2085 |
QCFType<HIShapeRef> region; |
|
2086 |
HIRect hirect = qt_hirectForQRect(tb->rect); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2087 |
if (hirect.size.width <= 0) |
0 | 2088 |
hirect.size.width = 100; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2089 |
if (hirect.size.height <= 0) |
0 | 2090 |
hirect.size.height = 30; |
2091 |
||
2092 |
HIThemeGetWindowShape(&hirect, &wdi, kWindowTitleBarRgn, ®ion); |
|
2093 |
HIRect rect; |
|
2094 |
ptrHIShapeGetBounds(region, &rect); |
|
2095 |
ret = int(rect.size.height); |
|
2096 |
ret += 4; |
|
2097 |
} |
|
2098 |
break; |
|
2099 |
case PM_TabBarTabVSpace: |
|
2100 |
ret = 4; |
|
2101 |
break; |
|
2102 |
case PM_TabBarTabShiftHorizontal: |
|
2103 |
case PM_TabBarTabShiftVertical: |
|
2104 |
ret = 0; |
|
2105 |
break; |
|
2106 |
case PM_TabBarBaseHeight: |
|
2107 |
ret = 0; |
|
2108 |
break; |
|
2109 |
case PM_TabBarTabOverlap: |
|
2110 |
ret = 0; |
|
2111 |
break; |
|
2112 |
case PM_TabBarBaseOverlap: |
|
2113 |
switch (d->aquaSizeConstrain(opt, widget)) { |
|
2114 |
case QAquaSizeUnknown: |
|
2115 |
case QAquaSizeLarge: |
|
2116 |
ret = 11; |
|
2117 |
break; |
|
2118 |
case QAquaSizeSmall: |
|
2119 |
ret = 8; |
|
2120 |
break; |
|
2121 |
case QAquaSizeMini: |
|
2122 |
ret = 7; |
|
2123 |
break; |
|
2124 |
} |
|
2125 |
break; |
|
2126 |
case PM_ScrollBarExtent: { |
|
2127 |
switch (d->aquaSizeConstrain(opt, widget)) { |
|
2128 |
case QAquaSizeUnknown: |
|
2129 |
case QAquaSizeLarge: |
|
2130 |
GetThemeMetric(kThemeMetricScrollBarWidth, &ret); |
|
2131 |
break; |
|
2132 |
case QAquaSizeMini: |
|
2133 |
case QAquaSizeSmall: |
|
2134 |
GetThemeMetric(kThemeMetricSmallScrollBarWidth, &ret); |
|
2135 |
break; |
|
2136 |
} |
|
2137 |
break; } |
|
2138 |
case PM_IndicatorHeight: { |
|
2139 |
switch (d->aquaSizeConstrain(opt, widget)) { |
|
2140 |
case QAquaSizeUnknown: |
|
2141 |
case QAquaSizeLarge: |
|
2142 |
GetThemeMetric(kThemeMetricCheckBoxHeight, &ret); |
|
2143 |
break; |
|
2144 |
case QAquaSizeMini: |
|
2145 |
GetThemeMetric(kThemeMetricMiniCheckBoxHeight, &ret); |
|
2146 |
break; |
|
2147 |
case QAquaSizeSmall: |
|
2148 |
GetThemeMetric(kThemeMetricSmallCheckBoxHeight, &ret); |
|
2149 |
break; |
|
2150 |
} |
|
2151 |
break; } |
|
2152 |
case PM_IndicatorWidth: { |
|
2153 |
switch (d->aquaSizeConstrain(opt, widget)) { |
|
2154 |
case QAquaSizeUnknown: |
|
2155 |
case QAquaSizeLarge: |
|
2156 |
GetThemeMetric(kThemeMetricCheckBoxWidth, &ret); |
|
2157 |
break; |
|
2158 |
case QAquaSizeMini: |
|
2159 |
GetThemeMetric(kThemeMetricMiniCheckBoxWidth, &ret); |
|
2160 |
break; |
|
2161 |
case QAquaSizeSmall: |
|
2162 |
GetThemeMetric(kThemeMetricSmallCheckBoxWidth, &ret); |
|
2163 |
break; |
|
2164 |
} |
|
2165 |
++ret; |
|
2166 |
break; } |
|
2167 |
case PM_ExclusiveIndicatorHeight: { |
|
2168 |
switch (d->aquaSizeConstrain(opt, widget)) { |
|
2169 |
case QAquaSizeUnknown: |
|
2170 |
case QAquaSizeLarge: |
|
2171 |
GetThemeMetric(kThemeMetricRadioButtonHeight, &ret); |
|
2172 |
break; |
|
2173 |
case QAquaSizeMini: |
|
2174 |
GetThemeMetric(kThemeMetricMiniRadioButtonHeight, &ret); |
|
2175 |
break; |
|
2176 |
case QAquaSizeSmall: |
|
2177 |
GetThemeMetric(kThemeMetricSmallRadioButtonHeight, &ret); |
|
2178 |
break; |
|
2179 |
} |
|
2180 |
break; } |
|
2181 |
case PM_ExclusiveIndicatorWidth: { |
|
2182 |
switch (d->aquaSizeConstrain(opt, widget)) { |
|
2183 |
case QAquaSizeUnknown: |
|
2184 |
case QAquaSizeLarge: |
|
2185 |
GetThemeMetric(kThemeMetricRadioButtonWidth, &ret); |
|
2186 |
break; |
|
2187 |
case QAquaSizeMini: |
|
2188 |
GetThemeMetric(kThemeMetricMiniRadioButtonWidth, &ret); |
|
2189 |
break; |
|
2190 |
case QAquaSizeSmall: |
|
2191 |
GetThemeMetric(kThemeMetricSmallRadioButtonWidth, &ret); |
|
2192 |
break; |
|
2193 |
} |
|
2194 |
++ret; |
|
2195 |
break; } |
|
2196 |
case PM_MenuVMargin: |
|
2197 |
ret = 4; |
|
2198 |
break; |
|
2199 |
case PM_MenuPanelWidth: |
|
2200 |
ret = 0; |
|
2201 |
break; |
|
2202 |
case PM_ToolTipLabelFrameWidth: |
|
2203 |
ret = 0; |
|
2204 |
break; |
|
2205 |
case PM_SizeGripSize: { |
|
2206 |
QAquaWidgetSize aSize; |
|
2207 |
if (widget && widget->window()->windowType() == Qt::Tool) |
|
2208 |
aSize = QAquaSizeSmall; |
|
2209 |
else |
|
2210 |
aSize = QAquaSizeLarge; |
|
2211 |
const QSize size = qt_aqua_get_known_size(CT_SizeGrip, widget, QSize(), aSize); |
|
2212 |
ret = size.width(); |
|
2213 |
break; } |
|
2214 |
case PM_MdiSubWindowFrameWidth: |
|
2215 |
ret = 1; |
|
2216 |
break; |
|
2217 |
case PM_DockWidgetFrameWidth: |
|
2218 |
ret = 2; |
|
2219 |
break; |
|
2220 |
case PM_DockWidgetTitleMargin: |
|
2221 |
ret = 0; |
|
2222 |
break; |
|
2223 |
case PM_DockWidgetSeparatorExtent: |
|
2224 |
ret = 1; |
|
2225 |
break; |
|
2226 |
case PM_ToolBarHandleExtent: |
|
2227 |
ret = 11; |
|
2228 |
break; |
|
2229 |
case PM_ToolBarItemMargin: |
|
2230 |
ret = 0; |
|
2231 |
break; |
|
2232 |
case PM_ToolBarItemSpacing: |
|
2233 |
ret = 4; |
|
2234 |
break; |
|
2235 |
case PM_SplitterWidth: |
|
2236 |
ret = qMax(7, QApplication::globalStrut().width()); |
|
2237 |
break; |
|
2238 |
case PM_LayoutLeftMargin: |
|
2239 |
case PM_LayoutTopMargin: |
|
2240 |
case PM_LayoutRightMargin: |
|
2241 |
case PM_LayoutBottomMargin: |
|
2242 |
{ |
|
2243 |
bool isWindow = false; |
|
2244 |
if (opt) { |
|
2245 |
isWindow = (opt->state & State_Window); |
|
2246 |
} else if (widget) { |
|
2247 |
isWindow = widget->isWindow(); |
|
2248 |
} |
|
2249 |
||
2250 |
if (isWindow) { |
|
2251 |
bool isMetal = widget && widget->testAttribute(Qt::WA_MacBrushedMetal); |
|
2252 |
if (isMetal) { |
|
2253 |
if (metric == PM_LayoutTopMargin) { |
|
2254 |
return_SIZE(9 /* AHIG */, 6 /* guess */, 6 /* guess */); |
|
2255 |
} else if (metric == PM_LayoutBottomMargin) { |
|
2256 |
return_SIZE(18 /* AHIG */, 15 /* guess */, 13 /* guess */); |
|
2257 |
} else { |
|
2258 |
return_SIZE(14 /* AHIG */, 11 /* guess */, 9 /* guess */); |
|
2259 |
} |
|
2260 |
} else { |
|
2261 |
/* |
|
2262 |
AHIG would have (20, 8, 10) here but that makes |
|
2263 |
no sense. It would also have 14 for the top margin |
|
2264 |
but this contradicts both Builder and most |
|
2265 |
applications. |
|
2266 |
*/ |
|
2267 |
return_SIZE(20, 10, 10); // AHIG |
|
2268 |
} |
|
2269 |
} else { |
|
2270 |
// hack to detect QTabWidget |
|
2271 |
if (widget && widget->parentWidget() |
|
2272 |
&& widget->parentWidget()->sizePolicy().controlType() == QSizePolicy::TabWidget) { |
|
2273 |
if (metric == PM_LayoutTopMargin) { |
|
2274 |
/* |
|
2275 |
Builder would have 14 (= 20 - 6) instead of 12, |
|
2276 |
but that makes the tab look disproportionate. |
|
2277 |
*/ |
|
2278 |
return_SIZE(12, 6, 6); // guess |
|
2279 |
} else { |
|
2280 |
return_SIZE(20 /* Builder */, 8 /* guess */, 8 /* guess */); |
|
2281 |
} |
|
2282 |
} else { |
|
2283 |
/* |
|
2284 |
Child margins are highly inconsistent in AHIG and Builder. |
|
2285 |
*/ |
|
2286 |
return_SIZE(12, 8, 6); // guess |
|
2287 |
} |
|
2288 |
} |
|
2289 |
} |
|
2290 |
case PM_LayoutHorizontalSpacing: |
|
2291 |
case PM_LayoutVerticalSpacing: |
|
2292 |
return -1; |
|
2293 |
case QStyle::PM_TabBarTabHSpace: |
|
2294 |
switch (d->aquaSizeConstrain(opt, widget)) { |
|
2295 |
case QAquaSizeLarge: |
|
2296 |
case QAquaSizeUnknown: |
|
2297 |
ret = QWindowsStyle::pixelMetric(metric, opt, widget); |
|
2298 |
break; |
|
2299 |
case QAquaSizeSmall: |
|
2300 |
ret = 20; |
|
2301 |
break; |
|
2302 |
case QAquaSizeMini: |
|
2303 |
ret = 16; |
|
2304 |
break; |
|
2305 |
} |
|
2306 |
break; |
|
2307 |
case PM_MenuHMargin: |
|
2308 |
ret = 0; |
|
2309 |
break; |
|
2310 |
case PM_ToolBarFrameWidth: |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2311 |
ret = 1; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2312 |
if (widget) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2313 |
if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(widget->parent())) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2314 |
if (mainWindow->unifiedTitleAndToolBarOnMac()) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2315 |
ret = 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2316 |
} |
0 | 2317 |
break; |
2318 |
default: |
|
2319 |
ret = QWindowsStyle::pixelMetric(metric, opt, widget); |
|
2320 |
break; |
|
2321 |
} |
|
2322 |
return ret; |
|
2323 |
} |
|
2324 |
||
2325 |
QPalette QMacStyle::standardPalette() const |
|
2326 |
{ |
|
2327 |
QPalette pal = QWindowsStyle::standardPalette(); |
|
2328 |
pal.setColor(QPalette::Disabled, QPalette::Dark, QColor(191, 191, 191)); |
|
2329 |
pal.setColor(QPalette::Active, QPalette::Dark, QColor(191, 191, 191)); |
|
2330 |
pal.setColor(QPalette::Inactive, QPalette::Dark, QColor(191, 191, 191)); |
|
2331 |
return pal; |
|
2332 |
} |
|
2333 |
||
2334 |
int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w, |
|
2335 |
QStyleHintReturn *hret) const |
|
2336 |
{ |
|
2337 |
SInt32 ret = 0; |
|
2338 |
switch (sh) { |
|
2339 |
case SH_Menu_SelectionWrap: |
|
2340 |
ret = false; |
|
2341 |
break; |
|
2342 |
case SH_Menu_KeyboardSearch: |
|
2343 |
ret = true; |
|
2344 |
break; |
|
2345 |
case SH_Menu_SpaceActivatesItem: |
|
2346 |
ret = true; |
|
2347 |
break; |
|
2348 |
case SH_Slider_AbsoluteSetButtons: |
|
2349 |
ret = Qt::LeftButton|Qt::MidButton; |
|
2350 |
break; |
|
2351 |
case SH_Slider_PageSetButtons: |
|
2352 |
ret = 0; |
|
2353 |
break; |
|
2354 |
case SH_ScrollBar_ContextMenu: |
|
2355 |
ret = false; |
|
2356 |
break; |
|
2357 |
case SH_TitleBar_AutoRaise: |
|
2358 |
ret = true; |
|
2359 |
break; |
|
2360 |
case SH_Menu_AllowActiveAndDisabled: |
|
2361 |
ret = false; |
|
2362 |
break; |
|
2363 |
case SH_Menu_SubMenuPopupDelay: |
|
2364 |
ret = 100; |
|
2365 |
break; |
|
2366 |
case SH_ScrollBar_LeftClickAbsolutePosition: { |
|
2367 |
extern bool qt_scrollbar_jump_to_pos; //qapplication_mac.cpp |
|
2368 |
if(QApplication::keyboardModifiers() & Qt::AltModifier) |
|
2369 |
ret = !qt_scrollbar_jump_to_pos; |
|
2370 |
else |
|
2371 |
ret = qt_scrollbar_jump_to_pos; |
|
2372 |
break; } |
|
2373 |
case SH_TabBar_PreferNoArrows: |
|
2374 |
ret = true; |
|
2375 |
break; |
|
2376 |
case SH_LineEdit_PasswordCharacter: |
|
2377 |
ret = kBulletUnicode; |
|
2378 |
break; |
|
2379 |
/* |
|
2380 |
case SH_DialogButtons_DefaultButton: |
|
2381 |
ret = QDialogButtons::Reject; |
|
2382 |
break; |
|
2383 |
*/ |
|
2384 |
case SH_Menu_SloppySubMenus: |
|
2385 |
ret = true; |
|
2386 |
break; |
|
2387 |
case SH_GroupBox_TextLabelVerticalAlignment: |
|
2388 |
ret = Qt::AlignTop; |
|
2389 |
break; |
|
2390 |
case SH_ScrollView_FrameOnlyAroundContents: |
|
2391 |
if (w && (w->isWindow() || !w->parentWidget() || w->parentWidget()->isWindow()) |
|
2392 |
&& (w->inherits("QWorkspaceChild") |
|
2393 |
#ifdef QT3_SUPPORT |
|
2394 |
|| w->inherits("QScrollView") |
|
2395 |
#endif |
|
2396 |
)) |
|
2397 |
ret = true; |
|
2398 |
else |
|
2399 |
ret = QWindowsStyle::styleHint(sh, opt, w, hret); |
|
2400 |
break; |
|
2401 |
case SH_Menu_FillScreenWithScroll: |
|
2402 |
ret = false; |
|
2403 |
break; |
|
2404 |
case SH_Menu_Scrollable: |
|
2405 |
ret = true; |
|
2406 |
break; |
|
2407 |
case SH_RichText_FullWidthSelection: |
|
2408 |
ret = true; |
|
2409 |
break; |
|
2410 |
case SH_BlinkCursorWhenTextSelected: |
|
2411 |
ret = false; |
|
2412 |
break; |
|
2413 |
case SH_ScrollBar_StopMouseOverSlider: |
|
2414 |
ret = true; |
|
2415 |
break; |
|
2416 |
case SH_Q3ListViewExpand_SelectMouseType: |
|
2417 |
ret = QEvent::MouseButtonRelease; |
|
2418 |
break; |
|
2419 |
case SH_TabBar_SelectMouseType: |
|
2420 |
if (const QStyleOptionTabBarBaseV2 *opt2 = qstyleoption_cast<const QStyleOptionTabBarBaseV2 *>(opt)) { |
|
2421 |
ret = opt2->documentMode ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease; |
|
2422 |
} else { |
|
2423 |
ret = QEvent::MouseButtonRelease; |
|
2424 |
} |
|
2425 |
break; |
|
2426 |
case SH_ComboBox_Popup: |
|
2427 |
if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) |
|
2428 |
ret = !cmb->editable; |
|
2429 |
else |
|
2430 |
ret = 0; |
|
2431 |
break; |
|
2432 |
case SH_Workspace_FillSpaceOnMaximize: |
|
2433 |
ret = true; |
|
2434 |
break; |
|
2435 |
case SH_Widget_ShareActivation: |
|
2436 |
ret = true; |
|
2437 |
break; |
|
2438 |
case SH_Header_ArrowAlignment: |
|
2439 |
ret = Qt::AlignRight; |
|
2440 |
break; |
|
2441 |
case SH_TabBar_Alignment: { |
|
2442 |
if (const QTabWidget *tab = qobject_cast<const QTabWidget*>(w)) { |
|
2443 |
if (tab->documentMode()) { |
|
2444 |
ret = Qt::AlignLeft; |
|
2445 |
break; |
|
2446 |
} |
|
2447 |
} |
|
2448 |
if (const QTabBar *tab = qobject_cast<const QTabBar*>(w)) { |
|
2449 |
if (tab->documentMode()) { |
|
2450 |
ret = Qt::AlignLeft; |
|
2451 |
break; |
|
2452 |
} |
|
2453 |
} |
|
2454 |
ret = Qt::AlignCenter; |
|
2455 |
} break; |
|
2456 |
case SH_UnderlineShortcut: |
|
2457 |
ret = false; |
|
2458 |
break; |
|
2459 |
case SH_ToolTipLabel_Opacity: |
|
2460 |
ret = 242; // About 95% |
|
2461 |
break; |
|
2462 |
case SH_Button_FocusPolicy: |
|
2463 |
ret = Qt::TabFocus; |
|
2464 |
break; |
|
2465 |
case SH_EtchDisabledText: |
|
2466 |
ret = false; |
|
2467 |
break; |
|
2468 |
case SH_FocusFrame_Mask: { |
|
2469 |
ret = true; |
|
2470 |
if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(hret)) { |
|
2471 |
const uchar fillR = 192, fillG = 191, fillB = 190; |
|
2472 |
QImage img; |
|
2473 |
||
2474 |
QSize pixmapSize = opt->rect.size(); |
|
2475 |
if (pixmapSize.isValid()) { |
|
2476 |
QPixmap pix(pixmapSize); |
|
2477 |
pix.fill(QColor(fillR, fillG, fillB)); |
|
2478 |
QPainter pix_paint(&pix); |
|
2479 |
proxy()->drawControl(CE_FocusFrame, opt, &pix_paint, w); |
|
2480 |
pix_paint.end(); |
|
2481 |
img = pix.toImage(); |
|
2482 |
} |
|
2483 |
||
2484 |
const QRgb *sptr = (QRgb*)img.bits(), *srow; |
|
2485 |
const int sbpl = img.bytesPerLine(); |
|
2486 |
const int w = sbpl/4, h = img.height(); |
|
2487 |
||
2488 |
QImage img_mask(img.width(), img.height(), QImage::Format_ARGB32); |
|
2489 |
QRgb *dptr = (QRgb*)img_mask.bits(), *drow; |
|
2490 |
const int dbpl = img_mask.bytesPerLine(); |
|
2491 |
||
2492 |
for (int y = 0; y < h; ++y) { |
|
2493 |
srow = sptr+((y*sbpl)/4); |
|
2494 |
drow = dptr+((y*dbpl)/4); |
|
2495 |
for (int x = 0; x < w; ++x) { |
|
2496 |
const int diff = (((qRed(*srow)-fillR)*(qRed(*srow)-fillR)) + |
|
2497 |
((qGreen(*srow)-fillG)*((qGreen(*srow)-fillG))) + |
|
2498 |
((qBlue(*srow)-fillB)*((qBlue(*srow)-fillB)))); |
|
2499 |
(*drow++) = (diff < 100) ? 0xffffffff : 0xff000000; |
|
2500 |
++srow; |
|
2501 |
} |
|
2502 |
} |
|
2503 |
QBitmap qmask = QBitmap::fromImage(img_mask); |
|
2504 |
mask->region = QRegion(qmask); |
|
2505 |
} |
|
2506 |
break; } |
|
2507 |
case SH_TitleBar_NoBorder: |
|
2508 |
ret = 1; |
|
2509 |
break; |
|
2510 |
case SH_RubberBand_Mask: |
|
2511 |
ret = 0; |
|
2512 |
break; |
|
2513 |
case SH_ComboBox_LayoutDirection: |
|
2514 |
ret = Qt::LeftToRight; |
|
2515 |
break; |
|
2516 |
case SH_ItemView_EllipsisLocation: |
|
2517 |
ret = Qt::AlignHCenter; |
|
2518 |
break; |
|
2519 |
case SH_ItemView_ShowDecorationSelected: |
|
2520 |
ret = true; |
|
2521 |
break; |
|
2522 |
case SH_TitleBar_ModifyNotification: |
|
2523 |
ret = false; |
|
2524 |
break; |
|
2525 |
case SH_ScrollBar_RollBetweenButtons: |
|
2526 |
ret = true; |
|
2527 |
break; |
|
2528 |
case SH_WindowFrame_Mask: |
|
2529 |
ret = 1; |
|
2530 |
if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask *>(hret)) { |
|
2531 |
mask->region = opt->rect; |
|
2532 |
mask->region -= QRect(opt->rect.left(), opt->rect.top(), 5, 1); |
|
2533 |
mask->region -= QRect(opt->rect.left(), opt->rect.top() + 1, 3, 1); |
|
2534 |
mask->region -= QRect(opt->rect.left(), opt->rect.top() + 2, 2, 1); |
|
2535 |
mask->region -= QRect(opt->rect.left(), opt->rect.top() + 3, 1, 2); |
|
2536 |
||
2537 |
mask->region -= QRect(opt->rect.right() - 4, opt->rect.top(), 5, 1); |
|
2538 |
mask->region -= QRect(opt->rect.right() - 2, opt->rect.top() + 1, 3, 1); |
|
2539 |
mask->region -= QRect(opt->rect.right() - 1, opt->rect.top() + 2, 2, 1); |
|
2540 |
mask->region -= QRect(opt->rect.right() , opt->rect.top() + 3, 1, 2); |
|
2541 |
} |
|
2542 |
break; |
|
2543 |
case SH_TabBar_ElideMode: |
|
2544 |
ret = Qt::ElideRight; |
|
2545 |
break; |
|
2546 |
case SH_DialogButtonLayout: |
|
2547 |
ret = QDialogButtonBox::MacLayout; |
|
2548 |
break; |
|
2549 |
case SH_FormLayoutWrapPolicy: |
|
2550 |
ret = QFormLayout::DontWrapRows; |
|
2551 |
break; |
|
2552 |
case SH_FormLayoutFieldGrowthPolicy: |
|
2553 |
ret = QFormLayout::FieldsStayAtSizeHint; |
|
2554 |
break; |
|
2555 |
case SH_FormLayoutFormAlignment: |
|
2556 |
ret = Qt::AlignHCenter | Qt::AlignTop; |
|
2557 |
break; |
|
2558 |
case SH_FormLayoutLabelAlignment: |
|
2559 |
ret = Qt::AlignRight; |
|
2560 |
break; |
|
2561 |
case SH_ComboBox_PopupFrameStyle: |
|
2562 |
ret = QFrame::NoFrame | QFrame::Plain; |
|
2563 |
break; |
|
2564 |
case SH_MessageBox_TextInteractionFlags: |
|
2565 |
ret = Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse | Qt::TextSelectableByKeyboard; |
|
2566 |
break; |
|
2567 |
case SH_SpellCheckUnderlineStyle: |
|
2568 |
ret = QTextCharFormat::DashUnderline; |
|
2569 |
break; |
|
2570 |
case SH_MessageBox_CenterButtons: |
|
2571 |
ret = false; |
|
2572 |
break; |
|
2573 |
case SH_MenuBar_AltKeyNavigation: |
|
2574 |
ret = false; |
|
2575 |
break; |
|
2576 |
case SH_ItemView_MovementWithoutUpdatingSelection: |
|
2577 |
ret = false; |
|
2578 |
break; |
|
2579 |
case SH_FocusFrame_AboveWidget: |
|
2580 |
ret = true; |
|
2581 |
break; |
|
2582 |
case SH_WizardStyle: |
|
2583 |
ret = QWizard::MacStyle; |
|
2584 |
break; |
|
2585 |
case SH_ItemView_ArrowKeysNavigateIntoChildren: |
|
2586 |
ret = false; |
|
2587 |
break; |
|
2588 |
case SH_Menu_FlashTriggeredItem: |
|
2589 |
ret = true; |
|
2590 |
break; |
|
2591 |
case SH_Menu_FadeOutOnHide: |
|
2592 |
ret = true; |
|
2593 |
break; |
|
2594 |
case SH_Menu_Mask: |
|
2595 |
if (opt) { |
|
2596 |
if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(hret)) { |
|
2597 |
ret = true; |
|
2598 |
HIRect menuRect = CGRectMake(opt->rect.x(), opt->rect.y() + 4, |
|
2599 |
opt->rect.width(), opt->rect.height() - 8); |
|
2600 |
HIThemeMenuDrawInfo mdi; |
|
2601 |
mdi.version = 0; |
|
2602 |
if (w && qobject_cast<QMenu *>(w->parentWidget())) |
|
2603 |
mdi.menuType = kThemeMenuTypeHierarchical; |
|
2604 |
else |
|
2605 |
mdi.menuType = kThemeMenuTypePopUp; |
|
2606 |
QCFType<HIShapeRef> shape; |
|
2607 |
HIThemeGetMenuBackgroundShape(&menuRect, &mdi, &shape); |
|
2608 |
mask->region = QRegion::fromHIShapeRef(shape); |
|
2609 |
} |
|
2610 |
} |
|
2611 |
break; |
|
2612 |
case SH_ItemView_PaintAlternatingRowColorsForEmptyArea: |
|
2613 |
ret = true; |
|
2614 |
break; |
|
2615 |
case SH_TabBar_CloseButtonPosition: |
|
2616 |
ret = QTabBar::LeftSide; |
|
2617 |
break; |
|
2618 |
case SH_DockWidget_ButtonsHaveFrame: |
|
2619 |
ret = false; |
|
2620 |
break; |
|
2621 |
default: |
|
2622 |
ret = QWindowsStyle::styleHint(sh, opt, w, hret); |
|
2623 |
break; |
|
2624 |
} |
|
2625 |
return ret; |
|
2626 |
} |
|
2627 |
||
2628 |
QPixmap QMacStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, |
|
2629 |
const QStyleOption *opt) const |
|
2630 |
{ |
|
2631 |
switch (iconMode) { |
|
2632 |
case QIcon::Disabled: { |
|
2633 |
QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); |
|
2634 |
int imgh = img.height(); |
|
2635 |
int imgw = img.width(); |
|
2636 |
QRgb pixel; |
|
2637 |
for (int y = 0; y < imgh; ++y) { |
|
2638 |
for (int x = 0; x < imgw; ++x) { |
|
2639 |
pixel = img.pixel(x, y); |
|
2640 |
img.setPixel(x, y, qRgba(qRed(pixel), qGreen(pixel), qBlue(pixel), |
|
2641 |
qAlpha(pixel) / 2)); |
|
2642 |
} |
|
2643 |
} |
|
2644 |
return QPixmap::fromImage(img); |
|
2645 |
} |
|
2646 |
default: |
|
2647 |
; |
|
2648 |
} |
|
2649 |
return QWindowsStyle::generatedIconPixmap(iconMode, pixmap, opt); |
|
2650 |
} |
|
2651 |
||
2652 |
||
2653 |
QPixmap QMacStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, |
|
2654 |
const QWidget *widget) const |
|
2655 |
{ |
|
2656 |
// The default implementation of QStyle::standardIconImplementation() is to call standardPixmap() |
|
2657 |
// I don't want infinite recursion so if we do get in that situation, just return the Window's |
|
2658 |
// standard pixmap instead (since there is no mac-specific icon then). This should be fine until |
|
2659 |
// someone changes how Windows standard |
|
2660 |
// pixmap works. |
|
2661 |
static bool recursionGuard = false; |
|
2662 |
||
2663 |
if (recursionGuard) |
|
2664 |
return QWindowsStyle::standardPixmap(standardPixmap, opt, widget); |
|
2665 |
||
2666 |
recursionGuard = true; |
|
2667 |
QIcon icon = standardIconImplementation(standardPixmap, opt, widget); |
|
2668 |
recursionGuard = false; |
|
2669 |
int size; |
|
2670 |
switch (standardPixmap) { |
|
2671 |
default: |
|
2672 |
size = 32; |
|
2673 |
break; |
|
2674 |
case SP_MessageBoxCritical: |
|
2675 |
case SP_MessageBoxQuestion: |
|
2676 |
case SP_MessageBoxInformation: |
|
2677 |
case SP_MessageBoxWarning: |
|
2678 |
size = 64; |
|
2679 |
break; |
|
2680 |
} |
|
2681 |
return icon.pixmap(size, size); |
|
2682 |
} |
|
2683 |
||
2684 |
void QMacStyle::setFocusRectPolicy(QWidget *w, FocusRectPolicy policy) |
|
2685 |
{ |
|
2686 |
switch (policy) { |
|
2687 |
case FocusDefault: |
|
2688 |
break; |
|
2689 |
case FocusEnabled: |
|
2690 |
case FocusDisabled: |
|
2691 |
w->setAttribute(Qt::WA_MacShowFocusRect, policy == FocusEnabled); |
|
2692 |
break; |
|
2693 |
} |
|
2694 |
} |
|
2695 |
||
2696 |
QMacStyle::FocusRectPolicy QMacStyle::focusRectPolicy(const QWidget *w) |
|
2697 |
{ |
|
2698 |
return w->testAttribute(Qt::WA_MacShowFocusRect) ? FocusEnabled : FocusDisabled; |
|
2699 |
} |
|
2700 |
||
2701 |
void QMacStyle::setWidgetSizePolicy(const QWidget *widget, WidgetSizePolicy policy) |
|
2702 |
{ |
|
2703 |
QWidget *wadget = const_cast<QWidget *>(widget); |
|
2704 |
wadget->setAttribute(Qt::WA_MacNormalSize, policy == SizeLarge); |
|
2705 |
wadget->setAttribute(Qt::WA_MacSmallSize, policy == SizeSmall); |
|
2706 |
wadget->setAttribute(Qt::WA_MacMiniSize, policy == SizeMini); |
|
2707 |
} |
|
2708 |
||
2709 |
QMacStyle::WidgetSizePolicy QMacStyle::widgetSizePolicy(const QWidget *widget) |
|
2710 |
{ |
|
2711 |
while (widget) { |
|
2712 |
if (widget->testAttribute(Qt::WA_MacMiniSize)) { |
|
2713 |
return SizeMini; |
|
2714 |
} else if (widget->testAttribute(Qt::WA_MacSmallSize)) { |
|
2715 |
return SizeSmall; |
|
2716 |
} else if (widget->testAttribute(Qt::WA_MacNormalSize)) { |
|
2717 |
return SizeLarge; |
|
2718 |
} |
|
2719 |
widget = widget->parentWidget(); |
|
2720 |
} |
|
2721 |
return SizeDefault; |
|
2722 |
} |
|
2723 |
||
2724 |
void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, |
|
2725 |
const QWidget *w) const |
|
2726 |
{ |
|
2727 |
ThemeDrawState tds = d->getDrawState(opt->state); |
|
2728 |
QMacCGContext cg(p); |
|
2729 |
switch (pe) { |
|
2730 |
case PE_IndicatorArrowUp: |
|
2731 |
case PE_IndicatorArrowDown: |
|
2732 |
case PE_IndicatorArrowRight: |
|
2733 |
case PE_IndicatorArrowLeft: { |
|
2734 |
p->save(); |
|
2735 |
p->setRenderHint(QPainter::Antialiasing); |
|
2736 |
int xOffset = opt->direction == Qt::LeftToRight ? 2 : -1; |
|
2737 |
QMatrix matrix; |
|
2738 |
matrix.translate(opt->rect.center().x() + xOffset, opt->rect.center().y() + 2); |
|
2739 |
QPainterPath path; |
|
2740 |
switch(pe) { |
|
2741 |
default: |
|
2742 |
case PE_IndicatorArrowDown: |
|
2743 |
break; |
|
2744 |
case PE_IndicatorArrowUp: |
|
2745 |
matrix.rotate(180); |
|
2746 |
break; |
|
2747 |
case PE_IndicatorArrowLeft: |
|
2748 |
matrix.rotate(90); |
|
2749 |
break; |
|
2750 |
case PE_IndicatorArrowRight: |
|
2751 |
matrix.rotate(-90); |
|
2752 |
break; |
|
2753 |
} |
|
2754 |
path.moveTo(0, 5); |
|
2755 |
path.lineTo(-4, -3); |
|
2756 |
path.lineTo(4, -3); |
|
2757 |
p->setMatrix(matrix); |
|
2758 |
p->setPen(Qt::NoPen); |
|
2759 |
p->setBrush(QColor(0, 0, 0, 135)); |
|
2760 |
p->drawPath(path); |
|
2761 |
p->restore(); |
|
2762 |
break; } |
|
2763 |
case PE_FrameTabBarBase: |
|
2764 |
if (const QStyleOptionTabBarBaseV2 *tbb |
|
2765 |
= qstyleoption_cast<const QStyleOptionTabBarBaseV2 *>(opt)) { |
|
2766 |
if (tbb->documentMode) { |
|
2767 |
p->save(); |
|
2768 |
drawTabBase(p, tbb, w); |
|
2769 |
p->restore(); |
|
2770 |
return; |
|
2771 |
} |
|
2772 |
||
2773 |
QRegion region(tbb->rect); |
|
2774 |
region -= tbb->tabBarRect; |
|
2775 |
p->save(); |
|
2776 |
p->setClipRegion(region); |
|
2777 |
QStyleOptionTabWidgetFrame twf; |
|
2778 |
twf.QStyleOption::operator=(*tbb); |
|
2779 |
twf.shape = tbb->shape; |
|
2780 |
switch (getTabDirection(twf.shape)) { |
|
2781 |
case kThemeTabNorth: |
|
2782 |
twf.rect = twf.rect.adjusted(0, 0, 0, 10); |
|
2783 |
break; |
|
2784 |
case kThemeTabSouth: |
|
2785 |
twf.rect = twf.rect.adjusted(0, -10, 0, 0); |
|
2786 |
break; |
|
2787 |
case kThemeTabWest: |
|
2788 |
twf.rect = twf.rect.adjusted(0, 0, 10, 0); |
|
2789 |
break; |
|
2790 |
case kThemeTabEast: |
|
2791 |
twf.rect = twf.rect.adjusted(0, -10, 0, 0); |
|
2792 |
break; |
|
2793 |
} |
|
2794 |
proxy()->drawPrimitive(PE_FrameTabWidget, &twf, p, w); |
|
2795 |
p->restore(); |
|
2796 |
} |
|
2797 |
break; |
|
2798 |
case PE_PanelTipLabel: |
|
2799 |
p->fillRect(opt->rect, opt->palette.brush(QPalette::ToolTipBase)); |
|
2800 |
break; |
|
2801 |
case PE_FrameGroupBox: |
|
2802 |
if (const QStyleOptionFrame *groupBox = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { |
|
2803 |
const QStyleOptionFrameV2 *frame2 = qstyleoption_cast<const QStyleOptionFrameV2 *>(opt); |
|
2804 |
if (frame2 && frame2->features & QStyleOptionFrameV2::Flat) { |
|
2805 |
QWindowsStyle::drawPrimitive(pe, groupBox, p, w); |
|
2806 |
} else { |
|
2807 |
HIThemeGroupBoxDrawInfo gdi; |
|
2808 |
gdi.version = qt_mac_hitheme_version; |
|
2809 |
gdi.state = tds; |
|
2810 |
if (w && qobject_cast<QGroupBox *>(w->parentWidget())) |
|
2811 |
gdi.kind = kHIThemeGroupBoxKindSecondary; |
|
2812 |
else |
|
2813 |
gdi.kind = kHIThemeGroupBoxKindPrimary; |
|
2814 |
HIRect hirect = qt_hirectForQRect(opt->rect); |
|
2815 |
HIThemeDrawGroupBox(&hirect, &gdi, cg, kHIThemeOrientationNormal); |
|
2816 |
} |
|
2817 |
} |
|
2818 |
break; |
|
2819 |
case PE_IndicatorToolBarSeparator: { |
|
2820 |
QPainterPath path; |
|
2821 |
if (opt->state & State_Horizontal) { |
|
2822 |
int xpoint = opt->rect.center().x(); |
|
2823 |
path.moveTo(xpoint + 0.5, opt->rect.top() + 1); |
|
2824 |
path.lineTo(xpoint + 0.5, opt->rect.bottom()); |
|
2825 |
} else { |
|
2826 |
int ypoint = opt->rect.center().y(); |
|
2827 |
path.moveTo(opt->rect.left() + 2 , ypoint + 0.5); |
|
2828 |
path.lineTo(opt->rect.right() + 1, ypoint + 0.5); |
|
2829 |
} |
|
2830 |
QPainterPathStroker theStroker; |
|
2831 |
theStroker.setCapStyle(Qt::FlatCap); |
|
2832 |
theStroker.setDashPattern(QVector<qreal>() << 1 << 2); |
|
2833 |
path = theStroker.createStroke(path); |
|
2834 |
p->fillPath(path, QColor(0, 0, 0, 119)); |
|
2835 |
} |
|
2836 |
break; |
|
2837 |
case PE_FrameWindow: |
|
2838 |
break; |
|
2839 |
case PE_IndicatorDockWidgetResizeHandle: { |
|
2840 |
// The docwidget resize handle is drawn as a one-pixel wide line. |
|
2841 |
p->save(); |
|
2842 |
if (opt->state & State_Horizontal) { |
|
2843 |
p->setPen(QColor(160, 160, 160)); |
|
2844 |
p->drawLine(opt->rect.topLeft(), opt->rect.topRight()); |
|
2845 |
} else { |
|
2846 |
p->setPen(QColor(145, 145, 145)); |
|
2847 |
p->drawLine(opt->rect.topRight(), opt->rect.bottomRight()); |
|
2848 |
} |
|
2849 |
p->restore(); |
|
2850 |
} break; |
|
2851 |
case PE_IndicatorToolBarHandle: { |
|
2852 |
p->save(); |
|
2853 |
QPainterPath path; |
|
2854 |
int x = opt->rect.x() + 6; |
|
2855 |
int y = opt->rect.y() + 5; |
|
2856 |
static const int RectHeight = 2; |
|
2857 |
if (opt->state & State_Horizontal) { |
|
2858 |
while (y < opt->rect.height() - RectHeight - 6) { |
|
2859 |
path.moveTo(x, y); |
|
2860 |
path.addRect(x, y, RectHeight, RectHeight); |
|
2861 |
y += 6; |
|
2862 |
} |
|
2863 |
} else { |
|
2864 |
while (x < opt->rect.width() - RectHeight - 6) { |
|
2865 |
path.moveTo(x, y); |
|
2866 |
path.addRect(x, y, RectHeight, RectHeight); |
|
2867 |
x += 6; |
|
2868 |
} |
|
2869 |
} |
|
2870 |
p->setPen(Qt::NoPen); |
|
2871 |
QColor dark = opt->palette.dark().color(); |
|
2872 |
dark.setAlphaF(0.75); |
|
2873 |
QColor light = opt->palette.light().color(); |
|
2874 |
light.setAlphaF(0.6); |
|
2875 |
p->fillPath(path, light); |
|
2876 |
p->save(); |
|
2877 |
p->translate(1, 1); |
|
2878 |
p->fillPath(path, dark); |
|
2879 |
p->restore(); |
|
2880 |
p->translate(3, 3); |
|
2881 |
p->fillPath(path, light); |
|
2882 |
p->translate(1, 1); |
|
2883 |
p->fillPath(path, dark); |
|
2884 |
p->restore(); |
|
2885 |
||
2886 |
break; |
|
2887 |
} |
|
2888 |
case PE_IndicatorHeaderArrow: |
|
2889 |
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { |
|
2890 |
// In HITheme, up is down, down is up and hamburgers eat people. |
|
2891 |
if (header->sortIndicator != QStyleOptionHeader::None) |
|
2892 |
proxy()->drawPrimitive( |
|
2893 |
(header->sortIndicator == QStyleOptionHeader::SortDown) ? |
|
2894 |
PE_IndicatorArrowUp : PE_IndicatorArrowDown, header, p, w); |
|
2895 |
} |
|
2896 |
break; |
|
2897 |
case PE_IndicatorMenuCheckMark: { |
|
2898 |
const int checkw = 8; |
|
2899 |
const int checkh = 8; |
|
2900 |
const int xoff = qMax(0, (opt->rect.width() - checkw) / 2); |
|
2901 |
const int yoff = qMax(0, (opt->rect.width() - checkh) / 2); |
|
2902 |
const int x1 = xoff + opt->rect.x(); |
|
2903 |
const int y1 = yoff + opt->rect.y() + checkw/2; |
|
2904 |
const int x2 = xoff + opt->rect.x() + checkw/4; |
|
2905 |
const int y2 = yoff + opt->rect.y() + checkh; |
|
2906 |
const int x3 = xoff + opt->rect.x() + checkw; |
|
2907 |
const int y3 = yoff + opt->rect.y(); |
|
2908 |
||
2909 |
QVector<QLineF> a(2); |
|
2910 |
a << QLineF(x1, y1, x2, y2); |
|
2911 |
a << QLineF(x2, y2, x3, y3); |
|
2912 |
if (opt->palette.currentColorGroup() == QPalette::Active) |
|
2913 |
p->setPen(QPen(Qt::white, 3)); |
|
2914 |
else |
|
2915 |
p->setPen(QPen(QColor(100, 100, 100), 3)); |
|
2916 |
p->save(); |
|
2917 |
p->setRenderHint(QPainter::Antialiasing); |
|
2918 |
p->drawLines(a); |
|
2919 |
p->restore(); |
|
2920 |
break; } |
|
2921 |
case PE_IndicatorViewItemCheck: |
|
2922 |
case PE_Q3CheckListExclusiveIndicator: |
|
2923 |
case PE_Q3CheckListIndicator: |
|
2924 |
case PE_IndicatorRadioButton: |
|
2925 |
case PE_IndicatorCheckBox: { |
|
2926 |
bool drawColorless = (!(opt->state & State_Active)) |
|
2927 |
&& opt->palette.currentColorGroup() == QPalette::Active; |
|
2928 |
HIThemeButtonDrawInfo bdi; |
|
2929 |
bdi.version = qt_mac_hitheme_version; |
|
2930 |
bdi.state = tds; |
|
2931 |
if (drawColorless && tds == kThemeStateInactive) |
|
2932 |
bdi.state = kThemeStateActive; |
|
2933 |
bdi.adornment = kThemeDrawIndicatorOnly; |
|
2934 |
if (opt->state & State_HasFocus) |
|
2935 |
bdi.adornment |= kThemeAdornmentFocus; |
|
2936 |
bool isRadioButton = (pe == PE_Q3CheckListExclusiveIndicator |
|
2937 |
|| pe == PE_IndicatorRadioButton); |
|
2938 |
switch (d->aquaSizeConstrain(opt, w)) { |
|
2939 |
case QAquaSizeUnknown: |
|
2940 |
case QAquaSizeLarge: |
|
2941 |
if (isRadioButton) |
|
2942 |
bdi.kind = kThemeRadioButton; |
|
2943 |
else |
|
2944 |
bdi.kind = kThemeCheckBox; |
|
2945 |
break; |
|
2946 |
case QAquaSizeMini: |
|
2947 |
if (isRadioButton) |
|
2948 |
bdi.kind = kThemeMiniRadioButton; |
|
2949 |
else |
|
2950 |
bdi.kind = kThemeMiniCheckBox; |
|
2951 |
break; |
|
2952 |
case QAquaSizeSmall: |
|
2953 |
if (isRadioButton) |
|
2954 |
bdi.kind = kThemeSmallRadioButton; |
|
2955 |
else |
|
2956 |
bdi.kind = kThemeSmallCheckBox; |
|
2957 |
break; |
|
2958 |
} |
|
2959 |
if (opt->state & State_NoChange) |
|
2960 |
bdi.value = kThemeButtonMixed; |
|
2961 |
else if (opt->state & State_On) |
|
2962 |
bdi.value = kThemeButtonOn; |
|
2963 |
else |
|
2964 |
bdi.value = kThemeButtonOff; |
|
2965 |
HIRect macRect; |
|
2966 |
if (pe == PE_Q3CheckListExclusiveIndicator || pe == PE_Q3CheckListIndicator) |
|
2967 |
macRect = qt_hirectForQRect(opt->rect); |
|
2968 |
else |
|
2969 |
macRect = qt_hirectForQRect(opt->rect); |
|
2970 |
if (!drawColorless) |
|
2971 |
HIThemeDrawButton(&macRect, &bdi, cg, kHIThemeOrientationNormal, 0); |
|
2972 |
else |
|
2973 |
d->drawColorlessButton(macRect, &bdi, p, opt); |
|
2974 |
break; } |
|
2975 |
case PE_FrameFocusRect: |
|
2976 |
// Use the our own focus widget stuff. |
|
2977 |
break; |
|
2978 |
case PE_IndicatorBranch: { |
|
2979 |
if (!(opt->state & State_Children)) |
|
2980 |
break; |
|
2981 |
HIThemeButtonDrawInfo bi; |
|
2982 |
bi.version = qt_mac_hitheme_version; |
|
2983 |
bi.state = tds; |
|
2984 |
if (tds == kThemeStateInactive && opt->palette.currentColorGroup() == QPalette::Active) |
|
2985 |
bi.state = kThemeStateActive; |
|
2986 |
if (opt->state & State_Sunken) |
|
2987 |
bi.state |= kThemeStatePressed; |
|
2988 |
bi.kind = kThemeDisclosureButton; |
|
2989 |
if (opt->state & State_Open) |
|
2990 |
bi.value = kThemeDisclosureDown; |
|
2991 |
else |
|
2992 |
bi.value = opt->direction == Qt::LeftToRight ? kThemeDisclosureRight : kThemeDisclosureLeft; |
|
2993 |
bi.adornment = kThemeAdornmentNone; |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
2994 |
HIRect hirect = qt_hirectForQRect(opt->rect.adjusted(DisclosureOffset,0,-DisclosureOffset,0)); |
0 | 2995 |
HIThemeDrawButton(&hirect, &bi, cg, kHIThemeOrientationNormal, 0); |
2996 |
break; } |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2997 |
|
0 | 2998 |
case PE_Frame: { |
2999 |
QPen oldPen = p->pen(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3000 |
p->setPen(opt->palette.base().color().darker(140)); |
0 | 3001 |
p->drawRect(opt->rect.adjusted(0, 0, -1, -1)); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3002 |
p->setPen(opt->palette.base().color().darker(180)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3003 |
p->drawLine(opt->rect.topLeft(), opt->rect.topRight()); |
0 | 3004 |
p->setPen(oldPen); |
3005 |
break; } |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3006 |
|
0 | 3007 |
case PE_FrameLineEdit: |
3008 |
if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { |
|
3009 |
if (frame->state & State_Sunken) { |
|
3010 |
QColor baseColor(frame->palette.background().color()); |
|
3011 |
HIThemeFrameDrawInfo fdi; |
|
3012 |
fdi.version = qt_mac_hitheme_version; |
|
3013 |
fdi.state = tds; |
|
3014 |
SInt32 frame_size; |
|
3015 |
if (pe == PE_FrameLineEdit) { |
|
3016 |
fdi.kind = kHIThemeFrameTextFieldSquare; |
|
3017 |
GetThemeMetric(kThemeMetricEditTextFrameOutset, &frame_size); |
|
3018 |
if ((frame->state & State_ReadOnly) || !(frame->state & State_Enabled)) |
|
3019 |
fdi.state = kThemeStateInactive; |
|
3020 |
} else { |
|
3021 |
baseColor = QColor(150, 150, 150); //hardcoded since no query function --Sam |
|
3022 |
fdi.kind = kHIThemeFrameListBox; |
|
3023 |
GetThemeMetric(kThemeMetricListBoxFrameOutset, &frame_size); |
|
3024 |
} |
|
3025 |
fdi.isFocused = (frame->state & State_HasFocus); |
|
3026 |
int lw = frame->lineWidth; |
|
3027 |
if (lw <= 0) |
|
3028 |
lw = proxy()->pixelMetric(PM_DefaultFrameWidth, frame, w); |
|
3029 |
{ //clear to base color |
|
3030 |
p->save(); |
|
3031 |
p->setPen(QPen(baseColor, lw)); |
|
3032 |
p->setBrush(Qt::NoBrush); |
|
3033 |
p->drawRect(frame->rect); |
|
3034 |
p->restore(); |
|
3035 |
} |
|
3036 |
HIRect hirect = qt_hirectForQRect(frame->rect, |
|
3037 |
QRect(frame_size, frame_size, |
|
3038 |
frame_size * 2, frame_size * 2)); |
|
3039 |
||
3040 |
HIThemeDrawFrame(&hirect, &fdi, cg, kHIThemeOrientationNormal); |
|
3041 |
} else { |
|
3042 |
QWindowsStyle::drawPrimitive(pe, opt, p, w); |
|
3043 |
} |
|
3044 |
} |
|
3045 |
break; |
|
3046 |
case PE_PanelLineEdit: |
|
3047 |
QWindowsStyle::drawPrimitive(pe, opt, p, w); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3048 |
// Draw the focus frame for widgets other than QLineEdit (e.g. for line edits in Webkit). |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3049 |
// Focus frame is drawn outside the rectangle passed in the option-rect. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3050 |
if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3051 |
if ((opt->state & State_HasFocus) && !qobject_cast<const QLineEdit*>(w)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3052 |
int vmargin = pixelMetric(QStyle::PM_FocusFrameVMargin); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3053 |
int hmargin = pixelMetric(QStyle::PM_FocusFrameHMargin); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3054 |
QStyleOptionFrame focusFrame = *panel; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3055 |
focusFrame.rect = panel->rect.adjusted(-hmargin, -vmargin, hmargin, vmargin); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3056 |
drawControl(CE_FocusFrame, &focusFrame, p, w); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3057 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3058 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3059 |
|
0 | 3060 |
break; |
3061 |
case PE_FrameTabWidget: |
|
3062 |
if (const QStyleOptionTabWidgetFrame *twf |
|
3063 |
= qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { |
|
3064 |
HIRect hirect = qt_hirectForQRect(twf->rect); |
|
3065 |
HIThemeTabPaneDrawInfo tpdi; |
|
3066 |
tpdi.version = qt_mac_hitheme_tab_version(); |
|
3067 |
tpdi.state = tds; |
|
3068 |
tpdi.direction = getTabDirection(twf->shape); |
|
3069 |
tpdi.size = kHIThemeTabSizeNormal; |
|
3070 |
tpdi.kind = kHIThemeTabKindNormal; |
|
3071 |
tpdi.adornment = kHIThemeTabPaneAdornmentNormal; |
|
3072 |
HIThemeDrawTabPane(&hirect, &tpdi, cg, kHIThemeOrientationNormal); |
|
3073 |
} |
|
3074 |
break; |
|
3075 |
case PE_PanelScrollAreaCorner: { |
|
3076 |
const QBrush brush(qApp->palette().brush(QPalette::Base)); |
|
3077 |
p->fillRect(opt->rect, brush); |
|
3078 |
p->setPen(QPen(QColor(217, 217, 217))); |
|
3079 |
p->drawLine(opt->rect.topLeft(), opt->rect.topRight()); |
|
3080 |
p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft()); |
|
3081 |
} break; |
|
3082 |
case PE_FrameStatusBarItem: |
|
3083 |
break; |
|
3084 |
case PE_IndicatorTabClose: { |
|
3085 |
bool hover = (opt->state & State_MouseOver); |
|
3086 |
bool selected = (opt->state & State_Selected); |
|
3087 |
bool active = (opt->state & State_Active); |
|
3088 |
drawTabCloseButton(p, hover, active, selected); |
|
3089 |
} break; |
|
3090 |
case PE_PanelStatusBar: { |
|
3091 |
if (QSysInfo::MacintoshVersion <= QSysInfo::MV_10_4) { |
|
3092 |
QWindowsStyle::drawPrimitive(pe, opt, p, w); |
|
3093 |
break; |
|
3094 |
} |
|
3095 |
// Use the Leopard style only if the status bar is the status bar for a |
|
3096 |
// QMainWindow with a unifed toolbar. |
|
3097 |
if (w == 0 || w->parent() == 0 || qobject_cast<QMainWindow *>(w->parent()) == 0 || |
|
3098 |
qobject_cast<QMainWindow *>(w->parent())->unifiedTitleAndToolBarOnMac() == false ) { |
|
3099 |
QWindowsStyle::drawPrimitive(pe, opt, p, w); |
|
3100 |
break; |
|
3101 |
} |
|
3102 |
||
3103 |
// Fill the status bar with the titlebar gradient. |
|
3104 |
QLinearGradient linearGrad(0, opt->rect.top(), 0, opt->rect.bottom()); |
|
3105 |
if (opt->state & QStyle::State_Active) { |
|
3106 |
linearGrad.setColorAt(0, titlebarGradientActiveBegin); |
|
3107 |
linearGrad.setColorAt(1, titlebarGradientActiveEnd); |
|
3108 |
} else { |
|
3109 |
linearGrad.setColorAt(0, titlebarGradientInactiveBegin); |
|
3110 |
linearGrad.setColorAt(1, titlebarGradientInactiveEnd); |
|
3111 |
} |
|
3112 |
p->fillRect(opt->rect, linearGrad); |
|
3113 |
||
3114 |
// Draw the black separator line at the top of the status bar. |
|
3115 |
if (opt->state & QStyle::State_Active) |
|
3116 |
p->setPen(titlebarSeparatorLineActive); |
|
3117 |
else |
|
3118 |
p->setPen(titlebarSeparatorLineInactive); |
|
3119 |
p->drawLine(opt->rect.left(), opt->rect.top(), opt->rect.right(), opt->rect.top()); |
|
3120 |
||
3121 |
break; |
|
3122 |
} |
|
3123 |
||
3124 |
default: |
|
3125 |
QWindowsStyle::drawPrimitive(pe, opt, p, w); |
|
3126 |
break; |
|
3127 |
} |
|
3128 |
} |
|
3129 |
||
3130 |
static inline QPixmap darkenPixmap(const QPixmap &pixmap) |
|
3131 |
{ |
|
3132 |
QImage img = pixmap.toImage().convertToFormat(QImage::Format_ARGB32); |
|
3133 |
int imgh = img.height(); |
|
3134 |
int imgw = img.width(); |
|
3135 |
int h, s, v, a; |
|
3136 |
QRgb pixel; |
|
3137 |
for (int y = 0; y < imgh; ++y) { |
|
3138 |
for (int x = 0; x < imgw; ++x) { |
|
3139 |
pixel = img.pixel(x, y); |
|
3140 |
a = qAlpha(pixel); |
|
3141 |
QColor hsvColor(pixel); |
|
3142 |
hsvColor.getHsv(&h, &s, &v); |
|
3143 |
s = qMin(100, s * 2); |
|
3144 |
v = v / 2; |
|
3145 |
hsvColor.setHsv(h, s, v); |
|
3146 |
pixel = hsvColor.rgb(); |
|
3147 |
img.setPixel(x, y, qRgba(qRed(pixel), qGreen(pixel), qBlue(pixel), a)); |
|
3148 |
} |
|
3149 |
} |
|
3150 |
return QPixmap::fromImage(img); |
|
3151 |
} |
|
3152 |
||
3153 |
||
3154 |
||
3155 |
void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p, |
|
3156 |
const QWidget *w) const |
|
3157 |
{ |
|
3158 |
ThemeDrawState tds = d->getDrawState(opt->state); |
|
3159 |
QMacCGContext cg(p); |
|
3160 |
switch (ce) { |
|
3161 |
case CE_HeaderSection: |
|
3162 |
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { |
|
3163 |
HIThemeButtonDrawInfo bdi; |
|
3164 |
bdi.version = qt_mac_hitheme_version; |
|
3165 |
State flags = header->state; |
|
3166 |
QRect ir = header->rect; |
|
3167 |
bdi.kind = kThemeListHeaderButton; |
|
3168 |
bdi.adornment = kThemeAdornmentNone; |
|
3169 |
bdi.state = kThemeStateActive; |
|
3170 |
||
3171 |
if (flags & State_On) |
|
3172 |
bdi.value = kThemeButtonOn; |
|
3173 |
else |
|
3174 |
bdi.value = kThemeButtonOff; |
|
3175 |
||
3176 |
if (header->orientation == Qt::Horizontal){ |
|
3177 |
switch (header->position) { |
|
3178 |
case QStyleOptionHeader::Beginning: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3179 |
ir.adjust(-1, -1, 0, 0); |
0 | 3180 |
break; |
3181 |
case QStyleOptionHeader::Middle: |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3182 |
ir.adjust(-1, -1, 0, 0); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3183 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3184 |
case QStyleOptionHeader::OnlyOneSection: |
0 | 3185 |
case QStyleOptionHeader::End: |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
3186 |
ir.adjust(-1, -1, 1, 0); |
0 | 3187 |
break; |
3188 |
default: |
|
3189 |
break; |
|
3190 |
} |
|
3191 |
||
3192 |
if (header->position != QStyleOptionHeader::Beginning |
|
3193 |
&& header->position != QStyleOptionHeader::OnlyOneSection) { |
|
3194 |
bdi.adornment = header->direction == Qt::LeftToRight |
|
3195 |
? kThemeAdornmentHeaderButtonLeftNeighborSelected |
|
3196 |
: kThemeAdornmentHeaderButtonRightNeighborSelected; |
|
3197 |
} |
|
3198 |
} |
|
3199 |
||
3200 |
if (flags & State_Active) { |
|
3201 |
if (!(flags & State_Enabled)) |
|
3202 |
bdi.state = kThemeStateUnavailable; |
|
3203 |
else if (flags & State_Sunken) |
|
3204 |
bdi.state = kThemeStatePressed; |
|
3205 |
} else { |
|
3206 |
if (flags & State_Enabled) |
|
3207 |
bdi.state = kThemeStateInactive; |
|
3208 |
else |
|
3209 |
bdi.state = kThemeStateUnavailableInactive; |
|
3210 |
} |
|
3211 |
||
3212 |
if (header->sortIndicator != QStyleOptionHeader::None) { |
|
3213 |
bdi.value = kThemeButtonOn; |
|
3214 |
if (header->sortIndicator == QStyleOptionHeader::SortDown) |
|
3215 |
bdi.adornment = kThemeAdornmentHeaderButtonSortUp; |
|
3216 |
} |
|
3217 |
if (flags & State_HasFocus) |
|
3218 |
bdi.adornment = kThemeAdornmentFocus; |
|
3219 |
||
3220 |
ir = visualRect(header->direction, header->rect, ir); |
|
3221 |
HIRect bounds = qt_hirectForQRect(ir); |
|
3222 |
||
3223 |
bool noVerticalHeader = true; |
|
3224 |
if (w) |
|
3225 |
if (const QTableView *table = qobject_cast<const QTableView *>(w->parentWidget())) |
|
3226 |
noVerticalHeader = !table->verticalHeader()->isVisible(); |
|
3227 |
||
3228 |
bool drawTopBorder = header->orientation == Qt::Horizontal; |
|
3229 |
bool drawLeftBorder = header->orientation == Qt::Vertical |
|
3230 |
|| header->position == QStyleOptionHeader::OnlyOneSection |
|
3231 |
|| (header->position == QStyleOptionHeader::Beginning && noVerticalHeader); |
|
3232 |
d->drawTableHeader(bounds, drawTopBorder, drawLeftBorder, bdi, p); |
|
3233 |
} |
|
3234 |
break; |
|
3235 |
case CE_HeaderLabel: |
|
3236 |
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) { |
|
3237 |
QRect textr = header->rect; |
|
3238 |
if (!header->icon.isNull()) { |
|
3239 |
QIcon::Mode mode = QIcon::Disabled; |
|
3240 |
if (opt->state & State_Enabled) |
|
3241 |
mode = QIcon::Normal; |
|
3242 |
QPixmap pixmap = header->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), mode); |
|
3243 |
||
3244 |
QRect pixr = header->rect; |
|
3245 |
pixr.setY(header->rect.center().y() - (pixmap.height() - 1) / 2); |
|
3246 |
proxy()->drawItemPixmap(p, pixr, Qt::AlignVCenter, pixmap); |
|
3247 |
textr.translate(pixmap.width() + 2, 0); |
|
3248 |
} |
|
3249 |
||
3250 |
proxy()->drawItemText(p, textr, header->textAlignment | Qt::AlignVCenter, header->palette, |
|
3251 |
header->state & State_Enabled, header->text, QPalette::ButtonText); |
|
3252 |
} |
|
3253 |
break; |
|
3254 |
case CE_ToolButtonLabel: |
|
3255 |
if (const QStyleOptionToolButton *tb = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) { |
|
3256 |
QStyleOptionToolButton myTb = *tb; |
|
3257 |
myTb.state &= ~State_AutoRaise; |
|
3258 |
if (w && qobject_cast<QToolBar *>(w->parentWidget())) { |
|
3259 |
QRect cr = tb->rect; |
|
3260 |
int shiftX = 0; |
|
3261 |
int shiftY = 0; |
|
3262 |
bool needText = false; |
|
3263 |
int alignment = 0; |
|
3264 |
bool down = tb->state & (State_Sunken | State_On); |
|
3265 |
if (down) { |
|
3266 |
shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, w); |
|
3267 |
shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, tb, w); |
|
3268 |
} |
|
3269 |
// The down state is special for QToolButtons in a toolbar on the Mac |
|
3270 |
// The text is a bit bolder and gets a drop shadow and the icons are also darkened. |
|
3271 |
// This doesn't really fit into any particular case in QIcon, so we |
|
3272 |
// do the majority of the work ourselves. |
|
3273 |
if (!(tb->features & QStyleOptionToolButton::Arrow)) { |
|
3274 |
Qt::ToolButtonStyle tbstyle = tb->toolButtonStyle; |
|
3275 |
if (tb->icon.isNull() && !tb->text.isEmpty()) |
|
3276 |
tbstyle = Qt::ToolButtonTextOnly; |
|
3277 |
||
3278 |
switch (tbstyle) { |
|
3279 |
case Qt::ToolButtonTextOnly: { |
|
3280 |
needText = true; |
|
3281 |
alignment = Qt::AlignCenter; |
|
3282 |
break; } |
|
3283 |
case Qt::ToolButtonIconOnly: |
|
3284 |
case Qt::ToolButtonTextBesideIcon: |
|
3285 |
case Qt::ToolButtonTextUnderIcon: { |
|
3286 |
QRect pr = cr; |
|
3287 |
QIcon::Mode iconMode = (tb->state & State_Enabled) ? QIcon::Normal |
|
3288 |
: QIcon::Disabled; |
|
3289 |
QIcon::State iconState = (tb->state & State_On) ? QIcon::On |
|
3290 |
: QIcon::Off; |
|
3291 |
QPixmap pixmap = tb->icon.pixmap(tb->rect.size().boundedTo(tb->iconSize), iconMode, iconState); |
|
3292 |
||
3293 |
// Draw the text if it's needed. |
|
3294 |
if (tb->toolButtonStyle != Qt::ToolButtonIconOnly) { |
|
3295 |
needText = true; |
|
3296 |
if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3297 |
QMainWindow *mw = qobject_cast<QMainWindow *>(w->window()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3298 |
if (mw && mw->unifiedTitleAndToolBarOnMac()) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3299 |
pr.setHeight(pixmap.size().height()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3300 |
cr.adjust(0, pr.bottom() + 1, 0, 1); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3301 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3302 |
pr.setHeight(pixmap.size().height() + 6); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3303 |
cr.adjust(0, pr.bottom(), 0, -3); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3304 |
} |
0 | 3305 |
alignment |= Qt::AlignCenter; |
3306 |
} else { |
|
3307 |
pr.setWidth(pixmap.width() + 8); |
|
3308 |
cr.adjust(pr.right(), 0, 0, 0); |
|
3309 |
alignment |= Qt::AlignLeft | Qt::AlignVCenter; |
|
3310 |
} |
|
3311 |
} |
|
3312 |
if (opt->state & State_Sunken) { |
|
3313 |
pr.translate(shiftX, shiftY); |
|
3314 |
pixmap = darkenPixmap(pixmap); |
|
3315 |
} |
|
3316 |
proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pixmap); |
|
3317 |
break; } |
|
3318 |
default: |
|
3319 |
Q_ASSERT(false); |
|
3320 |
break; |
|
3321 |
} |
|
3322 |
||
3323 |
if (needText) { |
|
3324 |
QPalette pal = tb->palette; |
|
3325 |
QPalette::ColorRole role = QPalette::NoRole; |
|
3326 |
if (down) |
|
3327 |
cr.translate(shiftX, shiftY); |
|
3328 |
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 |
|
3329 |
&& (tbstyle == Qt::ToolButtonTextOnly |
|
3330 |
|| (tbstyle != Qt::ToolButtonTextOnly && !down))) { |
|
3331 |
QPen pen = p->pen(); |
|
3332 |
QColor light = down ? Qt::black : Qt::white; |
|
3333 |
light.setAlphaF(0.375f); |
|
3334 |
p->setPen(light); |
|
3335 |
p->drawText(cr.adjusted(0, 1, 0, 1), alignment, tb->text); |
|
3336 |
p->setPen(pen); |
|
3337 |
if (down && tbstyle == Qt::ToolButtonTextOnly) { |
|
3338 |
pal = QApplication::palette("QMenu"); |
|
3339 |
pal.setCurrentColorGroup(tb->palette.currentColorGroup()); |
|
3340 |
role = QPalette::HighlightedText; |
|
3341 |
} |
|
3342 |
} |
|
3343 |
drawItemText(p, cr, alignment, pal, |
|
3344 |
tb->state & State_Enabled, tb->text, role); |
|
3345 |
if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5 && |
|
3346 |
(tb->state & State_Sunken)) { |
|
3347 |
// Draw a "drop shadow" in earlier versions. |
|
3348 |
drawItemText(p, cr.adjusted(0, 1, 0, 1), alignment, |
|
3349 |
tb->palette, tb->state & State_Enabled, tb->text); |
|
3350 |
} |
|
3351 |
} |
|
3352 |
} else { |
|
3353 |
QWindowsStyle::drawControl(ce, &myTb, p, w); |
|
3354 |
} |
|
3355 |
} else { |
|
3356 |
QWindowsStyle::drawControl(ce, &myTb, p, w); |
|
3357 |
} |
|
3358 |
} |
|
3359 |
break; |
|
3360 |
case CE_ToolBoxTabShape: |
|
3361 |
QCommonStyle::drawControl(ce, opt, p, w); |
|
3362 |
break; |
|
3363 |
case CE_PushButtonBevel: |
|
3364 |
if (const QStyleOptionButton *btn = ::qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
3365 |
if (!(btn->state & (State_Raised | State_Sunken | State_On))) |
|
3366 |
break; |
|
3367 |
||
3368 |
if (btn->features & QStyleOptionButton::CommandLinkButton) { |
|
3369 |
QWindowsStyle::drawControl(ce, opt, p, w); |
|
3370 |
break; |
|
3371 |
} |
|
3372 |
||
3373 |
HIThemeButtonDrawInfo bdi; |
|
3374 |
d->initHIThemePushButton(btn, w, tds, &bdi); |
|
3375 |
if (btn->features & QStyleOptionButton::DefaultButton |
|
3376 |
&& d->animatable(QMacStylePrivate::AquaPushButton, w)) { |
|
3377 |
bdi.adornment |= kThemeAdornmentDefault; |
|
3378 |
bdi.animation.time.start = d->defaultButtonStart; |
|
3379 |
bdi.animation.time.current = CFAbsoluteTimeGetCurrent(); |
|
3380 |
if (d->timerID <= -1) |
|
3381 |
QMetaObject::invokeMethod(d, "startAnimationTimer", Qt::QueuedConnection); |
|
3382 |
} |
|
3383 |
// Unlike Carbon, we want the button to always be drawn inside its bounds. |
|
3384 |
// Therefore, make the button a bit smaller, so that even if it got focus, |
|
3385 |
// the focus 'shadow' will be inside. |
|
3386 |
HIRect newRect = qt_hirectForQRect(btn->rect); |
|
3387 |
if (bdi.kind == kThemePushButton || bdi.kind == kThemePushButtonSmall) { |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3388 |
newRect.origin.x += QMacStylePrivate::PushButtonLeftOffset; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3389 |
newRect.origin.y += QMacStylePrivate::PushButtonTopOffset; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3390 |
newRect.size.width -= QMacStylePrivate::PushButtonRightOffset; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3391 |
newRect.size.height -= QMacStylePrivate::PushButtonBottomOffset; |
0 | 3392 |
} else if (bdi.kind == kThemePushButtonMini) { |
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3393 |
newRect.origin.x += QMacStylePrivate::PushButtonLeftOffset - 2; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3394 |
newRect.origin.y += QMacStylePrivate::PushButtonTopOffset; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3395 |
newRect.size.width -= QMacStylePrivate::PushButtonRightOffset - 4; |
0 | 3396 |
} |
3397 |
HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0); |
|
3398 |
||
3399 |
if (btn->features & QStyleOptionButton::HasMenu) { |
|
3400 |
int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w); |
|
3401 |
QRect ir = btn->rect; |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3402 |
HIRect arrowRect = CGRectMake(ir.right() - mbi - QMacStylePrivate::PushButtonRightOffset, |
0 | 3403 |
ir.height() / 2 - 4, mbi, ir.height() / 2); |
3404 |
bool drawColorless = btn->palette.currentColorGroup() == QPalette::Active; |
|
3405 |
if (drawColorless && tds == kThemeStateInactive) |
|
3406 |
tds = kThemeStateActive; |
|
3407 |
||
3408 |
HIThemePopupArrowDrawInfo pdi; |
|
3409 |
pdi.version = qt_mac_hitheme_version; |
|
3410 |
pdi.state = tds; |
|
3411 |
pdi.orientation = kThemeArrowDown; |
|
3412 |
if (arrowRect.size.width < 8.) |
|
3413 |
pdi.size = kThemeArrow5pt; |
|
3414 |
else |
|
3415 |
pdi.size = kThemeArrow9pt; |
|
3416 |
HIThemeDrawPopupArrow(&arrowRect, &pdi, cg, kHIThemeOrientationNormal); |
|
3417 |
} |
|
3418 |
} |
|
3419 |
break; |
|
3420 |
case CE_PushButtonLabel: |
|
3421 |
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
3422 |
// We really don't want the label to be drawn the same as on |
|
3423 |
// windows style if it has an icon and text, then it should be more like a |
|
3424 |
// tab. So, cheat a little here. However, if it *is* only an icon |
|
3425 |
// the windows style works great, so just use that implementation. |
|
3426 |
bool hasMenu = btn->features & QStyleOptionButton::HasMenu; |
|
3427 |
bool hasIcon = !btn->icon.isNull(); |
|
3428 |
bool hasText = !btn->text.isEmpty(); |
|
3429 |
if (!hasIcon && !hasMenu) { |
|
3430 |
// ### this is really overly difficult, simplify. |
|
3431 |
// It basically tries to get the right font for "small" and "mini" icons. |
|
3432 |
QFont oldFont = p->font(); |
|
3433 |
QFont newFont = qt_app_fonts_hash()->value("QPushButton", QFont()); |
|
3434 |
ThemeFontID themeId = kThemePushButtonFont; |
|
3435 |
if (oldFont == newFont) { // Yes, use HITheme to draw the text for small sizes. |
|
3436 |
switch (d->aquaSizeConstrain(opt, w)) { |
|
3437 |
default: |
|
3438 |
break; |
|
3439 |
case QAquaSizeSmall: |
|
3440 |
themeId = kThemeSmallSystemFont; |
|
3441 |
break; |
|
3442 |
case QAquaSizeMini: |
|
3443 |
themeId = kThemeMiniSystemFont; |
|
3444 |
break; |
|
3445 |
} |
|
3446 |
} |
|
3447 |
if (themeId == kThemePushButtonFont) { |
|
3448 |
QWindowsStyle::drawControl(ce, btn, p, w); |
|
3449 |
} else { |
|
3450 |
p->save(); |
|
3451 |
CGContextSetShouldAntialias(cg, true); |
|
3452 |
CGContextSetShouldSmoothFonts(cg, true); |
|
3453 |
HIThemeTextInfo tti; |
|
3454 |
tti.version = qt_mac_hitheme_version; |
|
3455 |
tti.state = tds; |
|
3456 |
QColor textColor = btn->palette.buttonText().color(); |
|
3457 |
CGFloat colorComp[] = { textColor.redF(), textColor.greenF(), |
|
3458 |
textColor.blueF(), textColor.alphaF() }; |
|
3459 |
CGContextSetFillColorSpace(cg, QCoreGraphicsPaintEngine::macGenericColorSpace()); |
|
3460 |
CGContextSetFillColor(cg, colorComp); |
|
3461 |
tti.fontID = themeId; |
|
3462 |
tti.horizontalFlushness = kHIThemeTextHorizontalFlushCenter; |
|
3463 |
tti.verticalFlushness = kHIThemeTextVerticalFlushCenter; |
|
3464 |
tti.options = kHIThemeTextBoxOptionNone; |
|
3465 |
tti.truncationPosition = kHIThemeTextTruncationNone; |
|
3466 |
tti.truncationMaxLines = 1 + btn->text.count(QLatin1Char('\n')); |
|
3467 |
QCFString buttonText = qt_mac_removeMnemonics(btn->text); |
|
3468 |
QRect r = btn->rect; |
|
3469 |
HIRect bounds = qt_hirectForQRect(r); |
|
3470 |
HIThemeDrawTextBox(buttonText, &bounds, &tti, |
|
3471 |
cg, kHIThemeOrientationNormal); |
|
3472 |
p->restore(); |
|
3473 |
} |
|
3474 |
} else { |
|
3475 |
if (hasIcon && !hasText) { |
|
3476 |
QWindowsStyle::drawControl(ce, btn, p, w); |
|
3477 |
} else { |
|
3478 |
QRect freeContentRect = btn->rect; |
|
3479 |
QRect textRect = itemTextRect( |
|
3480 |
btn->fontMetrics, freeContentRect, Qt::AlignCenter, btn->state & State_Enabled, btn->text); |
|
3481 |
if (hasMenu) |
|
3482 |
textRect.adjust(-1, 0, -1, 0); |
|
3483 |
// Draw the icon: |
|
3484 |
if (hasIcon) { |
|
3485 |
int contentW = textRect.width(); |
|
3486 |
if (hasMenu) |
|
3487 |
contentW += proxy()->pixelMetric(PM_MenuButtonIndicator) + 4; |
|
3488 |
QIcon::Mode mode = btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; |
|
3489 |
if (mode == QIcon::Normal && btn->state & State_HasFocus) |
|
3490 |
mode = QIcon::Active; |
|
3491 |
// Decide if the icon is should be on or off: |
|
3492 |
QIcon::State state = QIcon::Off; |
|
3493 |
if (btn->state & State_On) |
|
3494 |
state = QIcon::On; |
|
3495 |
QPixmap pixmap = btn->icon.pixmap(btn->iconSize, mode, state); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3496 |
contentW += pixmap.width() + QMacStylePrivate::PushButtonContentPadding; |
0 | 3497 |
int iconLeftOffset = freeContentRect.x() + (freeContentRect.width() - contentW) / 2; |
3498 |
int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmap.height()) / 2; |
|
3499 |
QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmap.width(), pixmap.height()); |
|
3500 |
QRect visualIconDestRect = visualRect(btn->direction, freeContentRect, iconDestRect); |
|
3501 |
proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap); |
|
3502 |
int newOffset = iconDestRect.x() + iconDestRect.width() |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
3503 |
+ QMacStylePrivate::PushButtonContentPadding - textRect.x(); |
0 | 3504 |
textRect.adjust(newOffset, 0, newOffset, 0); |
3505 |
} |
|
3506 |
// Draw the text: |
|
3507 |
if (hasText) { |
|
3508 |
textRect = visualRect(btn->direction, freeContentRect, textRect); |
|
3509 |
proxy()->drawItemText(p, textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, btn->palette, |
|
3510 |
(btn->state & State_Enabled), btn->text, QPalette::ButtonText); |
|
3511 |
} |
|
3512 |
} |
|
3513 |
} |
|
3514 |
} |
|
3515 |
break; |
|
3516 |
case CE_ComboBoxLabel: |
|
3517 |
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { |
|
3518 |
QStyleOptionComboBox comboCopy = *cb; |
|
3519 |
comboCopy.direction = Qt::LeftToRight; |
|
3520 |
QWindowsStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p, w); |
|
3521 |
} |
|
3522 |
break; |
|
3523 |
case CE_TabBarTabShape: |
|
3524 |
if (const QStyleOptionTab *tabOpt = qstyleoption_cast<const QStyleOptionTab *>(opt)) { |
|
3525 |
||
3526 |
if (const QStyleOptionTabV3 *tabOptV3 = qstyleoption_cast<const QStyleOptionTabV3 *>(opt)) { |
|
3527 |
if (tabOptV3->documentMode) { |
|
3528 |
p->save(); |
|
3529 |
QRect tabRect = tabOptV3->rect; |
|
3530 |
drawTabShape(p, tabOptV3); |
|
3531 |
p->restore(); |
|
3532 |
return; |
|
3533 |
} |
|
3534 |
} |
|
3535 |
HIThemeTabDrawInfo tdi; |
|
3536 |
tdi.version = 1; |
|
3537 |
tdi.style = kThemeTabNonFront; |
|
3538 |
tdi.direction = getTabDirection(tabOpt->shape); |
|
3539 |
switch (d->aquaSizeConstrain(opt, w)) { |
|
3540 |
default: |
|
3541 |
case QAquaSizeUnknown: |
|
3542 |
case QAquaSizeLarge: |
|
3543 |
tdi.size = kHIThemeTabSizeNormal; |
|
3544 |
break; |
|
3545 |
case QAquaSizeSmall: |
|
3546 |
tdi.size = kHIThemeTabSizeSmall; |
|
3547 |
break; |
|
3548 |
case QAquaSizeMini: |
|
3549 |
tdi.size = kHIThemeTabSizeMini; |
|
3550 |
break; |
|
3551 |
} |
|
3552 |
bool verticalTabs = tdi.direction == kThemeTabWest || tdi.direction == kThemeTabEast; |
|
3553 |
QRect tabRect = tabOpt->rect; |
|
3554 |
||
3555 |
bool selected = tabOpt->state & State_Selected; |
|
3556 |
if (selected) { |
|
3557 |
if (!(tabOpt->state & State_Active)) |
|
3558 |
tdi.style = kThemeTabFrontUnavailable; |
|
3559 |
else if (!(tabOpt->state & State_Enabled)) |
|
3560 |
tdi.style = kThemeTabFrontInactive; |
|
3561 |
else |
|
3562 |
tdi.style = kThemeTabFront; |
|
3563 |
} else if (!(tabOpt->state & State_Active)) { |
|
3564 |
tdi.style = kThemeTabNonFrontUnavailable; |
|
3565 |
} else if (!(tabOpt->state & State_Enabled)) { |
|
3566 |
tdi.style = kThemeTabNonFrontInactive; |
|
3567 |
} else if (tabOpt->state & State_Sunken) { |
|
3568 |
tdi.style = kThemeTabFrontInactive; // (should be kThemeTabNonFrontPressed) |
|
3569 |
} |
|
3570 |
if (tabOpt->state & State_HasFocus) |
|
3571 |
tdi.adornment = kHIThemeTabAdornmentFocus; |
|
3572 |
else |
|
3573 |
tdi.adornment = kHIThemeTabAdornmentNone; |
|
3574 |
tdi.kind = kHIThemeTabKindNormal; |
|
3575 |
if (!verticalTabs) |
|
3576 |
tabRect.setY(tabRect.y() - 1); |
|
3577 |
else |
|
3578 |
tabRect.setX(tabRect.x() - 1); |
|
3579 |
QStyleOptionTab::TabPosition tp = tabOpt->position; |
|
3580 |
QStyleOptionTab::SelectedPosition sp = tabOpt->selectedPosition; |
|
3581 |
if (tabOpt->direction == Qt::RightToLeft && !verticalTabs) { |
|
3582 |
if (sp == QStyleOptionTab::NextIsSelected) |
|
3583 |
sp = QStyleOptionTab::PreviousIsSelected; |
|
3584 |
else if (sp == QStyleOptionTab::PreviousIsSelected) |
|
3585 |
sp = QStyleOptionTab::NextIsSelected; |
|
3586 |
switch (tp) { |
|
3587 |
case QStyleOptionTab::Beginning: |
|
3588 |
tp = QStyleOptionTab::End; |
|
3589 |
break; |
|
3590 |
case QStyleOptionTab::End: |
|
3591 |
tp = QStyleOptionTab::Beginning; |
|
3592 |
break; |
|
3593 |
default: |
|
3594 |
break; |
|
3595 |
} |
|
3596 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3597 |
bool stretchTabs = (!verticalTabs && tabRect.height() > 22 || verticalTabs && tabRect.width() > 22); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3598 |
|
0 | 3599 |
switch (tp) { |
3600 |
case QStyleOptionTab::Beginning: |
|
3601 |
tdi.position = kHIThemeTabPositionFirst; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3602 |
if (sp != QStyleOptionTab::NextIsSelected || stretchTabs) |
0 | 3603 |
tdi.adornment |= kHIThemeTabAdornmentTrailingSeparator; |
3604 |
break; |
|
3605 |
case QStyleOptionTab::Middle: |
|
3606 |
tdi.position = kHIThemeTabPositionMiddle; |
|
3607 |
if (selected) |
|
3608 |
tdi.adornment |= kHIThemeTabAdornmentLeadingSeparator; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3609 |
if (sp != QStyleOptionTab::NextIsSelected || stretchTabs) // Also when we're selected. |
0 | 3610 |
tdi.adornment |= kHIThemeTabAdornmentTrailingSeparator; |
3611 |
break; |
|
3612 |
case QStyleOptionTab::End: |
|
3613 |
tdi.position = kHIThemeTabPositionLast; |
|
3614 |
if (selected) |
|
3615 |
tdi.adornment |= kHIThemeTabAdornmentLeadingSeparator; |
|
3616 |
break; |
|
3617 |
case QStyleOptionTab::OnlyOneTab: |
|
3618 |
tdi.position = kHIThemeTabPositionOnly; |
|
3619 |
break; |
|
3620 |
} |
|
3621 |
// HITheme doesn't stretch its tabs. Therefore we have to cheat and do the job ourselves. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3622 |
if (stretchTabs) { |
0 | 3623 |
HIRect hirect = CGRectMake(0, 0, 23, 23); |
3624 |
QPixmap pm(23, 23); |
|
3625 |
pm.fill(Qt::transparent); |
|
3626 |
{ |
|
3627 |
QMacCGContext pmcg(&pm); |
|
3628 |
HIThemeDrawTab(&hirect, &tdi, pmcg, kHIThemeOrientationNormal, 0); |
|
3629 |
} |
|
3630 |
QStyleHelper::drawBorderPixmap(pm, p, tabRect, 7, 7, 7, 7); |
|
3631 |
} else { |
|
3632 |
HIRect hirect = qt_hirectForQRect(tabRect); |
|
3633 |
HIThemeDrawTab(&hirect, &tdi, cg, kHIThemeOrientationNormal, 0); |
|
3634 |
} |
|
3635 |
} |
|
3636 |
break; |
|
3637 |
case CE_TabBarTabLabel: |
|
3638 |
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { |
|
3639 |
QStyleOptionTabV3 myTab = *tab; |
|
3640 |
ThemeTabDirection ttd = getTabDirection(myTab.shape); |
|
3641 |
bool verticalTabs = ttd == kThemeTabWest || ttd == kThemeTabEast; |
|
3642 |
||
3643 |
// Check to see if we use have the same as the system font |
|
3644 |
// (QComboMenuItem is internal and should never be seen by the |
|
3645 |
// outside world, unless they read the source, in which case, it's |
|
3646 |
// their own fault). |
|
3647 |
bool nonDefaultFont = p->font() != qt_app_fonts_hash()->value("QComboMenuItem"); |
|
3648 |
if (verticalTabs || nonDefaultFont || !tab->icon.isNull() |
|
3649 |
|| !myTab.leftButtonSize.isNull() || !myTab.rightButtonSize.isNull()) { |
|
3650 |
int heightOffset = 0; |
|
3651 |
if (verticalTabs) { |
|
3652 |
heightOffset = -1; |
|
3653 |
} else if (nonDefaultFont) { |
|
3654 |
if (p->fontMetrics().height() == myTab.rect.height()) |
|
3655 |
heightOffset = 2; |
|
3656 |
} |
|
3657 |
myTab.rect.setHeight(myTab.rect.height() + heightOffset); |
|
3658 |
||
3659 |
if (myTab.documentMode) { |
|
3660 |
p->save(); |
|
3661 |
rotateTabPainter(p, myTab.shape, myTab.rect); |
|
3662 |
||
3663 |
QPalette np = tab->palette; |
|
3664 |
np.setColor(QPalette::WindowText, QColor(255, 255, 255, 75)); |
|
3665 |
QRect nr = subElementRect(SE_TabBarTabText, opt, w); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3666 |
nr.moveTop(-1); |
0 | 3667 |
int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextHideMnemonic; |
3668 |
proxy()->drawItemText(p, nr, alignment, np, tab->state & State_Enabled, |
|
3669 |
tab->text, QPalette::WindowText); |
|
3670 |
p->restore(); |
|
3671 |
} |
|
3672 |
||
3673 |
QCommonStyle::drawControl(ce, &myTab, p, w); |
|
3674 |
} else { |
|
3675 |
p->save(); |
|
3676 |
CGContextSetShouldAntialias(cg, true); |
|
3677 |
CGContextSetShouldSmoothFonts(cg, true); |
|
3678 |
HIThemeTextInfo tti; |
|
3679 |
tti.version = qt_mac_hitheme_version; |
|
3680 |
tti.state = tds; |
|
3681 |
QColor textColor = myTab.palette.windowText().color(); |
|
3682 |
CGFloat colorComp[] = { textColor.redF(), textColor.greenF(), |
|
3683 |
textColor.blueF(), textColor.alphaF() }; |
|
3684 |
CGContextSetFillColorSpace(cg, QCoreGraphicsPaintEngine::macGenericColorSpace()); |
|
3685 |
CGContextSetFillColor(cg, colorComp); |
|
3686 |
switch (d->aquaSizeConstrain(opt, w)) { |
|
3687 |
default: |
|
3688 |
case QAquaSizeUnknown: |
|
3689 |
case QAquaSizeLarge: |
|
3690 |
tti.fontID = kThemeSystemFont; |
|
3691 |
break; |
|
3692 |
case QAquaSizeSmall: |
|
3693 |
tti.fontID = kThemeSmallSystemFont; |
|
3694 |
break; |
|
3695 |
case QAquaSizeMini: |
|
3696 |
tti.fontID = kThemeMiniSystemFont; |
|
3697 |
break; |
|
3698 |
} |
|
3699 |
tti.horizontalFlushness = kHIThemeTextHorizontalFlushCenter; |
|
3700 |
tti.verticalFlushness = kHIThemeTextVerticalFlushCenter; |
|
3701 |
tti.options = verticalTabs ? kHIThemeTextBoxOptionStronglyVertical : kHIThemeTextBoxOptionNone; |
|
3702 |
tti.truncationPosition = kHIThemeTextTruncationNone; |
|
3703 |
tti.truncationMaxLines = 1 + myTab.text.count(QLatin1Char('\n')); |
|
3704 |
QCFString tabText = qt_mac_removeMnemonics(myTab.text); |
|
3705 |
QRect r = myTab.rect.adjusted(0, 0, 0, -1); |
|
3706 |
HIRect bounds = qt_hirectForQRect(r); |
|
3707 |
HIThemeDrawTextBox(tabText, &bounds, &tti, cg, kHIThemeOrientationNormal); |
|
3708 |
p->restore(); |
|
3709 |
} |
|
3710 |
} |
|
3711 |
break; |
|
3712 |
case CE_DockWidgetTitle: |
|
3713 |
if (const QDockWidget *dockWidget = qobject_cast<const QDockWidget *>(w)) { |
|
3714 |
bool floating = dockWidget->isFloating(); |
|
3715 |
if (floating) { |
|
3716 |
ThemeDrawState tds = d->getDrawState(opt->state); |
|
3717 |
HIThemeWindowDrawInfo wdi; |
|
3718 |
wdi.version = qt_mac_hitheme_version; |
|
3719 |
wdi.state = tds; |
|
3720 |
wdi.windowType = kThemeMovableDialogWindow; |
|
3721 |
wdi.titleHeight = opt->rect.height(); |
|
3722 |
wdi.titleWidth = opt->rect.width(); |
|
3723 |
wdi.attributes = 0; |
|
3724 |
||
3725 |
HIRect titleBarRect; |
|
3726 |
HIRect tmpRect = qt_hirectForQRect(opt->rect); |
|
3727 |
{ |
|
3728 |
QCFType<HIShapeRef> titleRegion; |
|
3729 |
QRect newr = opt->rect.adjusted(0, 0, 2, 0); |
|
3730 |
HIThemeGetWindowShape(&tmpRect, &wdi, kWindowTitleBarRgn, &titleRegion); |
|
3731 |
ptrHIShapeGetBounds(titleRegion, &tmpRect); |
|
3732 |
newr.translate(newr.x() - int(tmpRect.origin.x), newr.y() - int(tmpRect.origin.y)); |
|
3733 |
titleBarRect = qt_hirectForQRect(newr); |
|
3734 |
} |
|
3735 |
QMacCGContext cg(p); |
|
3736 |
HIThemeDrawWindowFrame(&titleBarRect, &wdi, cg, kHIThemeOrientationNormal, 0); |
|
3737 |
} else { |
|
3738 |
// fill title bar background |
|
3739 |
QLinearGradient linearGrad(0, opt->rect.top(), 0, opt->rect.bottom()); |
|
3740 |
linearGrad.setColorAt(0, mainWindowGradientBegin); |
|
3741 |
linearGrad.setColorAt(1, mainWindowGradientEnd); |
|
3742 |
p->fillRect(opt->rect, linearGrad); |
|
3743 |
||
3744 |
// draw horizontal lines at top and bottom |
|
3745 |
p->save(); |
|
3746 |
p->setPen(mainWindowGradientBegin.lighter(114)); |
|
3747 |
p->drawLine(opt->rect.topLeft(), opt->rect.topRight()); |
|
3748 |
p->setPen(mainWindowGradientEnd.darker(114)); |
|
3749 |
p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight()); |
|
3750 |
p->restore(); |
|
3751 |
} |
|
3752 |
} |
|
3753 |
||
3754 |
// Draw the text... |
|
3755 |
if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) { |
|
3756 |
if (!dwOpt->title.isEmpty()) { |
|
3757 |
const QStyleOptionDockWidgetV2 *v2 |
|
3758 |
= qstyleoption_cast<const QStyleOptionDockWidgetV2*>(dwOpt); |
|
3759 |
bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar; |
|
3760 |
||
3761 |
QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, opt, w); |
|
3762 |
if (verticalTitleBar) { |
|
3763 |
QRect rect = dwOpt->rect; |
|
3764 |
QRect r = rect; |
|
3765 |
QSize s = r.size(); |
|
3766 |
s.transpose(); |
|
3767 |
r.setSize(s); |
|
3768 |
||
3769 |
titleRect = QRect(r.left() + rect.bottom() |
|
3770 |
- titleRect.bottom(), |
|
3771 |
r.top() + titleRect.left() - rect.left(), |
|
3772 |
titleRect.height(), titleRect.width()); |
|
3773 |
||
3774 |
p->translate(r.left(), r.top() + r.width()); |
|
3775 |
p->rotate(-90); |
|
3776 |
p->translate(-r.left(), -r.top()); |
|
3777 |
} |
|
3778 |
||
3779 |
QFont oldFont = p->font(); |
|
3780 |
p->setFont(qt_app_fonts_hash()->value("QToolButton", p->font())); |
|
3781 |
QString text = p->fontMetrics().elidedText(dwOpt->title, Qt::ElideRight, |
|
3782 |
titleRect.width()); |
|
3783 |
drawItemText(p, titleRect, |
|
3784 |
Qt::AlignCenter | Qt::TextShowMnemonic, dwOpt->palette, |
|
3785 |
dwOpt->state & State_Enabled, text, |
|
3786 |
QPalette::WindowText); |
|
3787 |
p->setFont(oldFont); |
|
3788 |
} |
|
3789 |
} |
|
3790 |
break; |
|
3791 |
case CE_FocusFrame: { |
|
3792 |
int xOff = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, w) + 1; |
|
3793 |
int yOff = proxy()->pixelMetric(PM_FocusFrameVMargin, opt, w) + 1; |
|
3794 |
HIRect hirect = CGRectMake(xOff+opt->rect.x(), yOff+opt->rect.y(), opt->rect.width() - 2 * xOff, |
|
3795 |
opt->rect.height() - 2 * yOff); |
|
3796 |
HIThemeDrawFocusRect(&hirect, true, QMacCGContext(p), kHIThemeOrientationNormal); |
|
3797 |
break; } |
|
3798 |
case CE_MenuItem: |
|
3799 |
case CE_MenuEmptyArea: |
|
3800 |
if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { |
|
3801 |
p->fillRect(mi->rect, opt->palette.background()); |
|
3802 |
QAquaWidgetSize widgetSize = d->aquaSizeConstrain(opt, w); |
|
3803 |
int tabwidth = mi->tabWidth; |
|
3804 |
int maxpmw = mi->maxIconWidth; |
|
3805 |
bool active = mi->state & State_Selected; |
|
3806 |
bool enabled = mi->state & State_Enabled; |
|
3807 |
HIRect menuRect = qt_hirectForQRect(mi->menuRect); |
|
3808 |
HIRect itemRect = qt_hirectForQRect(mi->rect); |
|
3809 |
HIThemeMenuItemDrawInfo mdi; |
|
3810 |
mdi.version = qt_mac_hitheme_version; |
|
3811 |
mdi.itemType = kThemeMenuItemPlain; |
|
3812 |
if (!mi->icon.isNull()) |
|
3813 |
mdi.itemType |= kThemeMenuItemHasIcon; |
|
3814 |
if (mi->menuItemType == QStyleOptionMenuItem::SubMenu) |
|
3815 |
mdi.itemType |= kThemeMenuItemHierarchical | kThemeMenuItemHierBackground; |
|
3816 |
else |
|
3817 |
mdi.itemType |= kThemeMenuItemPopUpBackground; |
|
3818 |
if (enabled) |
|
3819 |
mdi.state = kThemeMenuActive; |
|
3820 |
else |
|
3821 |
mdi.state = kThemeMenuDisabled; |
|
3822 |
if (active) |
|
3823 |
mdi.state |= kThemeMenuSelected; |
|
3824 |
QRect contentRect; |
|
3825 |
if (mi->menuItemType == QStyleOptionMenuItem::Separator) { |
|
3826 |
// First arg should be &menurect, but wacky stuff happens then. |
|
3827 |
HIThemeDrawMenuSeparator(&itemRect, &itemRect, &mdi, |
|
3828 |
cg, kHIThemeOrientationNormal); |
|
3829 |
break; |
|
3830 |
} else { |
|
3831 |
HIRect cr; |
|
3832 |
bool needAlpha = mi->palette.color(QPalette::Button) == Qt::transparent; |
|
3833 |
if (needAlpha) { |
|
3834 |
needAlpha = true; |
|
3835 |
CGContextSaveGState(cg); |
|
3836 |
CGContextSetAlpha(cg, 0.0); |
|
3837 |
} |
|
3838 |
HIThemeDrawMenuItem(&menuRect, &itemRect, &mdi, |
|
3839 |
cg, kHIThemeOrientationNormal, &cr); |
|
3840 |
if (needAlpha) |
|
3841 |
CGContextRestoreGState(cg); |
|
3842 |
if (ce == CE_MenuEmptyArea) |
|
3843 |
break; |
|
3844 |
contentRect = qt_qrectForHIRect(cr); |
|
3845 |
} |
|
3846 |
int xpos = contentRect.x() + 18; |
|
3847 |
int checkcol = maxpmw; |
|
3848 |
if (!enabled) |
|
3849 |
p->setPen(mi->palette.text().color()); |
|
3850 |
else if (active) |
|
3851 |
p->setPen(mi->palette.highlightedText().color()); |
|
3852 |
else |
|
3853 |
p->setPen(mi->palette.buttonText().color()); |
|
3854 |
||
3855 |
if (mi->checked) { |
|
3856 |
// Use the HIThemeTextInfo foo to draw the check mark correctly, if we do it, |
|
3857 |
// we somehow need to use a special encoding as it doesn't look right with our |
|
3858 |
// drawText(). |
|
3859 |
p->save(); |
|
3860 |
CGContextSetShouldAntialias(cg, true); |
|
3861 |
CGContextSetShouldSmoothFonts(cg, true); |
|
3862 |
QColor textColor = p->pen().color(); |
|
3863 |
CGFloat colorComp[] = { textColor.redF(), textColor.greenF(), |
|
3864 |
textColor.blueF(), textColor.alphaF() }; |
|
3865 |
CGContextSetFillColorSpace(cg, QCoreGraphicsPaintEngine::macGenericColorSpace()); |
|
3866 |
CGContextSetFillColor(cg, colorComp); |
|
3867 |
HIThemeTextInfo tti; |
|
3868 |
tti.version = qt_mac_hitheme_version; |
|
3869 |
tti.state = tds; |
|
3870 |
if (active && enabled) |
|
3871 |
tti.state = kThemeStatePressed; |
|
3872 |
switch (widgetSize) { |
|
3873 |
case QAquaSizeUnknown: |
|
3874 |
case QAquaSizeLarge: |
|
3875 |
tti.fontID = kThemeMenuItemMarkFont; |
|
3876 |
break; |
|
3877 |
case QAquaSizeSmall: |
|
3878 |
tti.fontID = kThemeSmallSystemFont; |
|
3879 |
break; |
|
3880 |
case QAquaSizeMini: |
|
3881 |
tti.fontID = kThemeMiniSystemFont; |
|
3882 |
break; |
|
3883 |
} |
|
3884 |
tti.horizontalFlushness = kHIThemeTextHorizontalFlushLeft; |
|
3885 |
tti.verticalFlushness = kHIThemeTextVerticalFlushCenter; |
|
3886 |
tti.options = kHIThemeTextBoxOptionNone; |
|
3887 |
tti.truncationPosition = kHIThemeTextTruncationNone; |
|
3888 |
tti.truncationMaxLines = 1; |
|
3889 |
QCFString checkmark; |
|
3890 |
#if 0 |
|
3891 |
if (mi->checkType == QStyleOptionMenuItem::Exclusive) |
|
3892 |
checkmark = QString(QChar(kDiamondUnicode)); |
|
3893 |
else |
|
3894 |
#endif |
|
3895 |
checkmark = QString(QChar(kCheckUnicode)); |
|
3896 |
int mw = checkcol + macItemFrame; |
|
3897 |
int mh = contentRect.height() - 2 * macItemFrame; |
|
3898 |
int xp = contentRect.x(); |
|
3899 |
xp += macItemFrame; |
|
3900 |
CGFloat outWidth, outHeight, outBaseline; |
|
3901 |
HIThemeGetTextDimensions(checkmark, 0, &tti, &outWidth, &outHeight, |
|
3902 |
&outBaseline); |
|
3903 |
if (widgetSize == QAquaSizeMini) |
|
3904 |
outBaseline += 1; |
|
3905 |
QRect r(xp, contentRect.y(), mw, mh); |
|
3906 |
r.translate(0, p->fontMetrics().ascent() - int(outBaseline) + 1); |
|
3907 |
HIRect bounds = qt_hirectForQRect(r); |
|
3908 |
HIThemeDrawTextBox(checkmark, &bounds, &tti, |
|
3909 |
cg, kHIThemeOrientationNormal); |
|
3910 |
p->restore(); |
|
3911 |
} |
|
3912 |
if (!mi->icon.isNull()) { |
|
3913 |
QIcon::Mode mode = (mi->state & State_Enabled) ? QIcon::Normal |
|
3914 |
: QIcon::Disabled; |
|
3915 |
// Always be normal or disabled to follow the Mac style. |
|
3916 |
int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize); |
|
3917 |
QSize iconSize(smallIconSize, smallIconSize); |
|
3918 |
if (const QComboBox *comboBox = qobject_cast<const QComboBox *>(w)) { |
|
3919 |
iconSize = comboBox->iconSize(); |
|
3920 |
} |
|
3921 |
QPixmap pixmap = mi->icon.pixmap(iconSize, mode); |
|
3922 |
int pixw = pixmap.width(); |
|
3923 |
int pixh = pixmap.height(); |
|
3924 |
QRect cr(xpos, contentRect.y(), checkcol, contentRect.height()); |
|
3925 |
QRect pmr(0, 0, pixw, pixh); |
|
3926 |
pmr.moveCenter(cr.center()); |
|
3927 |
p->drawPixmap(pmr.topLeft(), pixmap); |
|
3928 |
xpos += pixw + 6; |
|
3929 |
} |
|
3930 |
||
3931 |
QString s = mi->text; |
|
3932 |
if (!s.isEmpty()) { |
|
3933 |
int t = s.indexOf(QLatin1Char('\t')); |
|
3934 |
int text_flags = Qt::AlignRight | Qt::AlignVCenter | Qt::TextHideMnemonic |
|
3935 |
| Qt::TextSingleLine | Qt::AlignAbsolute; |
|
3936 |
int yPos = contentRect.y(); |
|
3937 |
if (widgetSize == QAquaSizeMini) |
|
3938 |
yPos += 1; |
|
3939 |
p->save(); |
|
3940 |
if (t >= 0) { |
|
3941 |
p->setFont(qt_app_fonts_hash()->value("QMenuItem", p->font())); |
|
3942 |
int xp = contentRect.right() - tabwidth - macRightBorder |
|
3943 |
- macItemHMargin - macItemFrame + 1; |
|
3944 |
p->drawText(xp, yPos, tabwidth, contentRect.height(), text_flags, |
|
3945 |
s.mid(t + 1)); |
|
3946 |
s = s.left(t); |
|
3947 |
} |
|
3948 |
||
3949 |
const int xm = macItemFrame + maxpmw + macItemHMargin; |
|
3950 |
QFont myFont = mi->font; |
|
3951 |
// myFont may not have any "hard" flags set. We override |
|
3952 |
// the point size so that when it is resolved against the device, this font will win. |
|
3953 |
// This is mainly to handle cases where someone sets the font on the window |
|
3954 |
// and then the combo inherits it and passes it onward. At that point the resolve mask |
|
3955 |
// is very, very weak. This makes it stonger. |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3956 |
myFont.setPointSizeF(QFontInfo(mi->font).pointSizeF()); |
0 | 3957 |
p->setFont(myFont); |
3958 |
p->drawText(xpos, yPos, contentRect.width() - xm - tabwidth + 1, |
|
3959 |
contentRect.height(), text_flags ^ Qt::AlignRight, s); |
|
3960 |
p->restore(); |
|
3961 |
} |
|
3962 |
} |
|
3963 |
break; |
|
3964 |
case CE_MenuHMargin: |
|
3965 |
case CE_MenuVMargin: |
|
3966 |
case CE_MenuTearoff: |
|
3967 |
case CE_MenuScroller: |
|
3968 |
if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { |
|
3969 |
p->fillRect(mi->rect, opt->palette.background()); |
|
3970 |
||
3971 |
HIRect menuRect = qt_hirectForQRect(mi->menuRect); |
|
3972 |
HIRect itemRect = qt_hirectForQRect(mi->rect); |
|
3973 |
HIThemeMenuItemDrawInfo mdi; |
|
3974 |
mdi.version = qt_mac_hitheme_version; |
|
3975 |
if (!(opt->state & State_Enabled)) |
|
3976 |
mdi.state = kThemeMenuDisabled; |
|
3977 |
else if (opt->state & State_Selected) |
|
3978 |
mdi.state = kThemeMenuSelected; |
|
3979 |
else |
|
3980 |
mdi.state = kThemeMenuActive; |
|
3981 |
if (ce == CE_MenuScroller) { |
|
3982 |
if (opt->state & State_DownArrow) |
|
3983 |
mdi.itemType = kThemeMenuItemScrollDownArrow; |
|
3984 |
else |
|
3985 |
mdi.itemType = kThemeMenuItemScrollUpArrow; |
|
3986 |
} else { |
|
3987 |
mdi.itemType = kThemeMenuItemPlain; |
|
3988 |
} |
|
3989 |
HIThemeDrawMenuItem(&menuRect, &itemRect, &mdi, |
|
3990 |
cg, |
|
3991 |
kHIThemeOrientationNormal, 0); |
|
3992 |
if (ce == CE_MenuTearoff) { |
|
3993 |
p->setPen(QPen(mi->palette.dark().color(), 1, Qt::DashLine)); |
|
3994 |
p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2 - 1, |
|
3995 |
mi->rect.x() + mi->rect.width() - 4, |
|
3996 |
mi->rect.y() + mi->rect.height() / 2 - 1); |
|
3997 |
p->setPen(QPen(mi->palette.light().color(), 1, Qt::DashLine)); |
|
3998 |
p->drawLine(mi->rect.x() + 2, mi->rect.y() + mi->rect.height() / 2, |
|
3999 |
mi->rect.x() + mi->rect.width() - 4, |
|
4000 |
mi->rect.y() + mi->rect.height() / 2); |
|
4001 |
} |
|
4002 |
} |
|
4003 |
break; |
|
4004 |
case CE_MenuBarItem: |
|
4005 |
if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { |
|
4006 |
HIRect menuRect = qt_hirectForQRect(mi->menuRect); |
|
4007 |
HIRect itemRect = qt_hirectForQRect(mi->rect); |
|
4008 |
||
4009 |
if ((opt->state & State_Selected) && (opt->state & State_Enabled) && (opt->state & State_Sunken)){ |
|
4010 |
// Draw a selected menu item background: |
|
4011 |
HIThemeMenuItemDrawInfo mdi; |
|
4012 |
mdi.version = qt_mac_hitheme_version; |
|
4013 |
mdi.state = kThemeMenuSelected; |
|
4014 |
mdi.itemType = kThemeMenuItemPlain; |
|
4015 |
HIThemeDrawMenuItem(&menuRect, &itemRect, &mdi, cg, kHIThemeOrientationNormal, 0); |
|
4016 |
} else { |
|
4017 |
// Draw the toolbar background: |
|
4018 |
HIThemeMenuBarDrawInfo bdi; |
|
4019 |
bdi.version = qt_mac_hitheme_version; |
|
4020 |
bdi.state = kThemeMenuBarNormal; |
|
4021 |
bdi.attributes = 0; |
|
4022 |
HIRect hirect = qt_hirectForQRect(mi->rect); |
|
4023 |
HIThemeDrawMenuBarBackground(&menuRect, &bdi, cg, kHIThemeOrientationNormal); |
|
4024 |
} |
|
4025 |
||
4026 |
if (!mi->icon.isNull()) { |
|
4027 |
drawItemPixmap(p, mi->rect, |
|
4028 |
Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip |
|
4029 |
| Qt::TextSingleLine, |
|
4030 |
mi->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), |
|
4031 |
(mi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled)); |
|
4032 |
} else { |
|
4033 |
drawItemText(p, mi->rect, |
|
4034 |
Qt::AlignCenter | Qt::TextHideMnemonic | Qt::TextDontClip |
|
4035 |
| Qt::TextSingleLine, |
|
4036 |
mi->palette, mi->state & State_Enabled, |
|
4037 |
mi->text, QPalette::ButtonText); |
|
4038 |
} |
|
4039 |
} |
|
4040 |
break; |
|
4041 |
case CE_MenuBarEmptyArea: |
|
4042 |
if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { |
|
4043 |
HIThemeMenuBarDrawInfo bdi; |
|
4044 |
bdi.version = qt_mac_hitheme_version; |
|
4045 |
bdi.state = kThemeMenuBarNormal; |
|
4046 |
bdi.attributes = 0; |
|
4047 |
HIRect hirect = qt_hirectForQRect(mi->rect); |
|
4048 |
HIThemeDrawMenuBarBackground(&hirect, &bdi, cg, |
|
4049 |
kHIThemeOrientationNormal); |
|
4050 |
break; |
|
4051 |
} |
|
4052 |
case CE_ProgressBarContents: |
|
4053 |
if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { |
|
4054 |
HIThemeTrackDrawInfo tdi; |
|
4055 |
tdi.version = qt_mac_hitheme_version; |
|
4056 |
tdi.reserved = 0; |
|
4057 |
bool isIndeterminate = (pb->minimum == 0 && pb->maximum == 0); |
|
4058 |
bool vertical = false; |
|
4059 |
bool inverted = false; |
|
4060 |
if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) { |
|
4061 |
vertical = (pb2->orientation == Qt::Vertical); |
|
4062 |
inverted = pb2->invertedAppearance; |
|
4063 |
} |
|
4064 |
bool reverse = (!vertical && (pb->direction == Qt::RightToLeft)); |
|
4065 |
if (inverted) |
|
4066 |
reverse = !reverse; |
|
4067 |
switch (d->aquaSizeConstrain(opt, w)) { |
|
4068 |
case QAquaSizeUnknown: |
|
4069 |
case QAquaSizeLarge: |
|
4070 |
tdi.kind = !isIndeterminate ? kThemeLargeProgressBar |
|
4071 |
: kThemeLargeIndeterminateBar; |
|
4072 |
break; |
|
4073 |
case QAquaSizeMini: |
|
4074 |
case QAquaSizeSmall: |
|
4075 |
tdi.kind = !isIndeterminate ? kThemeProgressBar : kThemeIndeterminateBar; |
|
4076 |
break; |
|
4077 |
} |
|
4078 |
tdi.bounds = qt_hirectForQRect(pb->rect); |
|
4079 |
tdi.max = pb->maximum; |
|
4080 |
tdi.min = pb->minimum; |
|
4081 |
tdi.value = pb->progress; |
|
4082 |
tdi.attributes = vertical ? 0 : kThemeTrackHorizontal; |
|
4083 |
tdi.trackInfo.progress.phase = d->progressFrame; |
|
4084 |
if (!(pb->state & State_Active)) |
|
4085 |
tdi.enableState = kThemeTrackInactive; |
|
4086 |
else if (!(pb->state & State_Enabled)) |
|
4087 |
tdi.enableState = kThemeTrackDisabled; |
|
4088 |
else |
|
4089 |
tdi.enableState = kThemeTrackActive; |
|
4090 |
HIThemeOrientation drawOrientation = kHIThemeOrientationNormal; |
|
4091 |
if (reverse) { |
|
4092 |
if (vertical) { |
|
4093 |
drawOrientation = kHIThemeOrientationInverted; |
|
4094 |
} else { |
|
4095 |
CGContextSaveGState(cg); |
|
4096 |
CGContextTranslateCTM(cg, pb->rect.width(), 0); |
|
4097 |
CGContextScaleCTM(cg, -1, 1); |
|
4098 |
} |
|
4099 |
} |
|
4100 |
HIThemeDrawTrack(&tdi, 0, cg, drawOrientation); |
|
4101 |
if (reverse && !vertical) |
|
4102 |
CGContextRestoreGState(cg); |
|
4103 |
} |
|
4104 |
break; |
|
4105 |
case CE_ProgressBarLabel: |
|
4106 |
case CE_ProgressBarGroove: |
|
4107 |
break; |
|
4108 |
case CE_SizeGrip: { |
|
4109 |
if (w && w->testAttribute(Qt::WA_MacOpaqueSizeGrip)) { |
|
4110 |
HIThemeGrowBoxDrawInfo gdi; |
|
4111 |
gdi.version = qt_mac_hitheme_version; |
|
4112 |
gdi.state = tds; |
|
4113 |
gdi.kind = kHIThemeGrowBoxKindNormal; |
|
4114 |
gdi.direction = kThemeGrowRight | kThemeGrowDown; |
|
4115 |
gdi.size = kHIThemeGrowBoxSizeNormal; |
|
4116 |
HIPoint pt = CGPointMake(opt->rect.x(), opt->rect.y()); |
|
4117 |
HIThemeDrawGrowBox(&pt, &gdi, cg, kHIThemeOrientationNormal); |
|
4118 |
} else { |
|
4119 |
// It isn't possible to draw a transparent size grip with the |
|
4120 |
// native API, so we do it ourselves here. |
|
4121 |
const bool metal = qt_mac_is_metal(w); |
|
4122 |
QPen lineColor = metal ? QColor(236, 236, 236) : QColor(82, 82, 82, 192); |
|
4123 |
QPen metalHighlight = QColor(5, 5, 5, 192); |
|
4124 |
lineColor.setWidth(1); |
|
4125 |
p->save(); |
|
4126 |
p->setRenderHint(QPainter::Antialiasing); |
|
4127 |
p->setPen(lineColor); |
|
4128 |
const Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : qApp->layoutDirection(); |
|
4129 |
const int NumLines = metal ? 4 : 3; |
|
4130 |
for (int l = 0; l < NumLines; ++l) { |
|
4131 |
const int offset = (l * 4 + (metal ? 2 : 3)); |
|
4132 |
QPoint start, end; |
|
4133 |
if (layoutDirection == Qt::LeftToRight) { |
|
4134 |
start = QPoint(opt->rect.width() - offset, opt->rect.height() - 1); |
|
4135 |
end = QPoint(opt->rect.width() - 1, opt->rect.height() - offset); |
|
4136 |
} else { |
|
4137 |
start = QPoint(offset, opt->rect.height() - 1); |
|
4138 |
end = QPoint(1, opt->rect.height() - offset); |
|
4139 |
} |
|
4140 |
p->drawLine(start, end); |
|
4141 |
if (metal) { |
|
4142 |
p->setPen(metalHighlight); |
|
4143 |
p->setRenderHint(QPainter::Antialiasing, false); |
|
4144 |
p->drawLine(start + QPoint(0, -1), end + QPoint(0, -1)); |
|
4145 |
p->setRenderHint(QPainter::Antialiasing, true); |
|
4146 |
p->setPen(lineColor); |
|
4147 |
} |
|
4148 |
} |
|
4149 |
p->restore(); |
|
4150 |
} |
|
4151 |
break; |
|
4152 |
} |
|
4153 |
case CE_Splitter: { |
|
4154 |
HIThemeSplitterDrawInfo sdi; |
|
4155 |
sdi.version = qt_mac_hitheme_version; |
|
4156 |
sdi.state = tds; |
|
4157 |
sdi.adornment = qt_mac_is_metal(w) ? kHIThemeSplitterAdornmentMetal |
|
4158 |
: kHIThemeSplitterAdornmentNone; |
|
4159 |
HIRect hirect = qt_hirectForQRect(opt->rect); |
|
4160 |
HIThemeDrawPaneSplitter(&hirect, &sdi, cg, kHIThemeOrientationNormal); |
|
4161 |
break; } |
|
4162 |
case CE_RubberBand: |
|
4163 |
if (const QStyleOptionRubberBand *rubber = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) { |
|
4164 |
QColor fillColor(opt->palette.color(QPalette::Disabled, QPalette::Highlight)); |
|
4165 |
if (!rubber->opaque) { |
|
4166 |
QColor strokeColor; |
|
4167 |
// I retrieved these colors from the Carbon-Dev mailing list |
|
4168 |
strokeColor.setHsvF(0, 0, 0.86, 1.0); |
|
4169 |
fillColor.setHsvF(0, 0, 0.53, 0.25); |
|
4170 |
if (opt->rect.width() * opt->rect.height() <= 3) { |
|
4171 |
p->fillRect(opt->rect, strokeColor); |
|
4172 |
} else { |
|
4173 |
QPen oldPen = p->pen(); |
|
4174 |
QBrush oldBrush = p->brush(); |
|
4175 |
QPen pen(strokeColor); |
|
4176 |
p->setPen(pen); |
|
4177 |
p->setBrush(fillColor); |
|
4178 |
p->drawRect(opt->rect.adjusted(0, 0, -1, -1)); |
|
4179 |
p->setPen(oldPen); |
|
4180 |
p->setBrush(oldBrush); |
|
4181 |
} |
|
4182 |
} else { |
|
4183 |
p->fillRect(opt->rect, fillColor); |
|
4184 |
} |
|
4185 |
} |
|
4186 |
break; |
|
4187 |
case CE_ToolBar: { |
|
4188 |
// For unified tool bars, draw nothing. |
|
4189 |
if (w) { |
|
4190 |
if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(w->window())) { |
|
4191 |
if (mainWindow->unifiedTitleAndToolBarOnMac()) |
|
4192 |
break; |
|
4193 |
} |
|
4194 |
} |
|
4195 |
||
4196 |
// draw background gradient |
|
4197 |
QLinearGradient linearGrad; |
|
4198 |
if (opt->state & State_Horizontal) |
|
4199 |
linearGrad = QLinearGradient(0, opt->rect.top(), 0, opt->rect.bottom()); |
|
4200 |
else |
|
4201 |
linearGrad = QLinearGradient(opt->rect.left(), 0, opt->rect.right(), 0); |
|
4202 |
||
4203 |
linearGrad.setColorAt(0, mainWindowGradientBegin); |
|
4204 |
linearGrad.setColorAt(1, mainWindowGradientEnd); |
|
4205 |
p->fillRect(opt->rect, linearGrad); |
|
4206 |
||
4207 |
p->save(); |
|
4208 |
if (opt->state & State_Horizontal) { |
|
4209 |
p->setPen(mainWindowGradientBegin.lighter(114)); |
|
4210 |
p->drawLine(opt->rect.topLeft(), opt->rect.topRight()); |
|
4211 |
p->setPen(mainWindowGradientEnd.darker(114)); |
|
4212 |
p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight()); |
|
4213 |
||
4214 |
} else { |
|
4215 |
p->setPen(mainWindowGradientBegin.lighter(114)); |
|
4216 |
p->drawLine(opt->rect.topLeft(), opt->rect.bottomLeft()); |
|
4217 |
p->setPen(mainWindowGradientEnd.darker(114)); |
|
4218 |
p->drawLine(opt->rect.topRight(), opt->rect.bottomRight()); |
|
4219 |
} |
|
4220 |
p->restore(); |
|
4221 |
||
4222 |
||
4223 |
} break; |
|
4224 |
default: |
|
4225 |
QWindowsStyle::drawControl(ce, opt, p, w); |
|
4226 |
break; |
|
4227 |
} |
|
4228 |
} |
|
4229 |
||
4230 |
static void setLayoutItemMargins(int left, int top, int right, int bottom, QRect *rect, Qt::LayoutDirection dir) |
|
4231 |
{ |
|
4232 |
if (dir == Qt::RightToLeft) { |
|
4233 |
rect->adjust(-right, top, -left, bottom); |
|
4234 |
} else { |
|
4235 |
rect->adjust(left, top, right, bottom); |
|
4236 |
} |
|
4237 |
} |
|
4238 |
||
4239 |
QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, |
|
4240 |
const QWidget *widget) const |
|
4241 |
{ |
|
4242 |
QRect rect; |
|
4243 |
int controlSize = getControlSize(opt, widget); |
|
4244 |
||
4245 |
switch (sr) { |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4246 |
case SE_ItemViewItemText: |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4247 |
if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4248 |
int fw = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, widget); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4249 |
// We add the focusframeargin between icon and text in commonstyle |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4250 |
rect = QCommonStyle::subElementRect(sr, opt, widget); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4251 |
if (vopt->features & QStyleOptionViewItemV2::HasDecoration) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4252 |
rect.adjust(-fw, 0, 0, 0); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4253 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4254 |
break; |
0 | 4255 |
case SE_ToolBoxTabContents: |
4256 |
rect = QCommonStyle::subElementRect(sr, opt, widget); |
|
4257 |
break; |
|
4258 |
case SE_PushButtonContents: |
|
4259 |
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
4260 |
// Unlike Carbon, we want the button to always be drawn inside its bounds. |
|
4261 |
// Therefore, the button is a bit smaller, so that even if it got focus, |
|
4262 |
// the focus 'shadow' will be inside. Adjust the content rect likewise. |
|
4263 |
HIThemeButtonDrawInfo bdi; |
|
4264 |
d->initHIThemePushButton(btn, widget, d->getDrawState(opt->state), &bdi); |
|
4265 |
HIRect contentRect = d->pushButtonContentBounds(btn, &bdi); |
|
4266 |
rect = qt_qrectForHIRect(contentRect); |
|
4267 |
} |
|
4268 |
break; |
|
4269 |
case SE_HeaderLabel: |
|
4270 |
if (qstyleoption_cast<const QStyleOptionHeader *>(opt)) { |
|
4271 |
rect = QWindowsStyle::subElementRect(sr, opt, widget); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4272 |
if (widget && widget->height() <= 22){ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4273 |
// We need to allow the text a bit more space when the header is |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4274 |
// small, otherwise it gets clipped: |
0 | 4275 |
rect.setY(0); |
4276 |
rect.setHeight(widget->height()); |
|
4277 |
} |
|
4278 |
} |
|
4279 |
break; |
|
4280 |
case SE_ProgressBarGroove: |
|
4281 |
case SE_ProgressBarLabel: |
|
4282 |
break; |
|
4283 |
case SE_ProgressBarContents: |
|
4284 |
rect = opt->rect; |
|
4285 |
break; |
|
4286 |
case SE_TreeViewDisclosureItem: { |
|
4287 |
HIRect inRect = CGRectMake(opt->rect.x(), opt->rect.y(), |
|
4288 |
opt->rect.width(), opt->rect.height()); |
|
4289 |
HIThemeButtonDrawInfo bdi; |
|
4290 |
bdi.version = qt_mac_hitheme_version; |
|
4291 |
bdi.state = kThemeStateActive; |
|
4292 |
bdi.kind = kThemeDisclosureButton; |
|
4293 |
bdi.value = kThemeDisclosureRight; |
|
4294 |
bdi.adornment = kThemeAdornmentNone; |
|
4295 |
HIRect contentRect; |
|
4296 |
HIThemeGetButtonContentBounds(&inRect, &bdi, &contentRect); |
|
4297 |
QCFType<HIShapeRef> shape; |
|
4298 |
HIRect outRect; |
|
4299 |
HIThemeGetButtonShape(&inRect, &bdi, &shape); |
|
4300 |
ptrHIShapeGetBounds(shape, &outRect); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4301 |
rect = QRect(int(outRect.origin.x + DisclosureOffset), int(outRect.origin.y), |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4302 |
int(contentRect.origin.x - outRect.origin.x + DisclosureOffset), |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
4303 |
int(outRect.size.height)); |
0 | 4304 |
break; |
4305 |
} |
|
4306 |
case SE_TabWidgetLeftCorner: |
|
4307 |
if (const QStyleOptionTabWidgetFrame *twf |
|
4308 |
= qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { |
|
4309 |
switch (twf->shape) { |
|
4310 |
case QTabBar::RoundedNorth: |
|
4311 |
case QTabBar::TriangularNorth: |
|
4312 |
rect = QRect(QPoint(0, 0), twf->leftCornerWidgetSize); |
|
4313 |
break; |
|
4314 |
case QTabBar::RoundedSouth: |
|
4315 |
case QTabBar::TriangularSouth: |
|
4316 |
rect = QRect(QPoint(0, twf->rect.height() - twf->leftCornerWidgetSize.height()), |
|
4317 |
twf->leftCornerWidgetSize); |
|
4318 |
break; |
|
4319 |
default: |
|
4320 |
break; |
|
4321 |
} |
|
4322 |
rect = visualRect(twf->direction, twf->rect, rect); |
|
4323 |
} |
|
4324 |
break; |
|
4325 |
case SE_TabWidgetRightCorner: |
|
4326 |
if (const QStyleOptionTabWidgetFrame *twf |
|
4327 |
= qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { |
|
4328 |
switch (twf->shape) { |
|
4329 |
case QTabBar::RoundedNorth: |
|
4330 |
case QTabBar::TriangularNorth: |
|
4331 |
rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(), 0), |
|
4332 |
twf->rightCornerWidgetSize); |
|
4333 |
break; |
|
4334 |
case QTabBar::RoundedSouth: |
|
4335 |
case QTabBar::TriangularSouth: |
|
4336 |
rect = QRect(QPoint(twf->rect.width() - twf->rightCornerWidgetSize.width(), |
|
4337 |
twf->rect.height() - twf->rightCornerWidgetSize.height()), |
|
4338 |
twf->rightCornerWidgetSize); |
|
4339 |
break; |
|
4340 |
default: |
|
4341 |
break; |
|
4342 |
} |
|
4343 |
rect = visualRect(twf->direction, twf->rect, rect); |
|
4344 |
} |
|
4345 |
break; |
|
4346 |
case SE_TabWidgetTabContents: |
|
4347 |
rect = QWindowsStyle::subElementRect(sr, opt, widget); |
|
4348 |
if (const QStyleOptionTabWidgetFrame *twf |
|
4349 |
= qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { |
|
4350 |
if (twf->lineWidth != 0) { |
|
4351 |
switch (getTabDirection(twf->shape)) { |
|
4352 |
case kThemeTabNorth: |
|
4353 |
rect.adjust(+1, +14, -1, -1); |
|
4354 |
break; |
|
4355 |
case kThemeTabSouth: |
|
4356 |
rect.adjust(+1, +1, -1, -14); |
|
4357 |
break; |
|
4358 |
case kThemeTabWest: |
|
4359 |
rect.adjust(+14, +1, -1, -1); |
|
4360 |
break; |
|
4361 |
case kThemeTabEast: |
|
4362 |
rect.adjust(+1, +1, -14, -1); |
|
4363 |
} |
|
4364 |
} |
|
4365 |
} |
|
4366 |
break; |
|
4367 |
case SE_LineEditContents: |
|
4368 |
rect = QWindowsStyle::subElementRect(sr, opt, widget); |
|
4369 |
if(widget->parentWidget() && qobject_cast<const QComboBox*>(widget->parentWidget())) |
|
4370 |
rect.adjust(-1, -2, 0, 0); |
|
4371 |
else |
|
4372 |
rect.adjust(-1, 0, 0, +1); |
|
4373 |
break; |
|
4374 |
case SE_CheckBoxLayoutItem: |
|
4375 |
rect = opt->rect; |
|
4376 |
if (controlSize == QAquaSizeLarge) { |
|
4377 |
setLayoutItemMargins(+2, +3, -9, -4, &rect, opt->direction); |
|
4378 |
} else if (controlSize == QAquaSizeSmall) { |
|
4379 |
setLayoutItemMargins(+1, +5, 0 /* fix */, -6, &rect, opt->direction); |
|
4380 |
} else { |
|
4381 |
setLayoutItemMargins(0, +7, 0 /* fix */, -6, &rect, opt->direction); |
|
4382 |
} |
|
4383 |
break; |
|
4384 |
case SE_ComboBoxLayoutItem: |
|
4385 |
if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) { |
|
4386 |
// Do nothing, because QToolbar needs the entire widget rect. |
|
4387 |
// Otherwise it will be clipped. Equivalent to |
|
4388 |
// widget->setAttribute(Qt::WA_LayoutUsesWidgetRect), but without |
|
4389 |
// all the hassle. |
|
4390 |
} else { |
|
4391 |
rect = opt->rect; |
|
4392 |
if (controlSize == QAquaSizeLarge) { |
|
4393 |
rect.adjust(+3, +2, -3, -4); |
|
4394 |
} else if (controlSize == QAquaSizeSmall) { |
|
4395 |
setLayoutItemMargins(+2, +1, -3, -4, &rect, opt->direction); |
|
4396 |
} else { |
|
4397 |
setLayoutItemMargins(+1, 0, -2, 0, &rect, opt->direction); |
|
4398 |
} |
|
4399 |
} |
|
4400 |
break; |
|
4401 |
case SE_LabelLayoutItem: |
|
4402 |
rect = opt->rect; |
|
4403 |
setLayoutItemMargins(+1, 0 /* SHOULD be -1, done for alignment */, 0, 0 /* SHOULD be -1, done for alignment */, &rect, opt->direction); |
|
4404 |
break; |
|
4405 |
case SE_ProgressBarLayoutItem: { |
|
4406 |
rect = opt->rect; |
|
4407 |
int bottom = SIZE(3, 8, 8); |
|
4408 |
if (opt->state & State_Horizontal) { |
|
4409 |
rect.adjust(0, +1, 0, -bottom); |
|
4410 |
} else { |
|
4411 |
setLayoutItemMargins(+1, 0, -bottom, 0, &rect, opt->direction); |
|
4412 |
} |
|
4413 |
break; |
|
4414 |
} |
|
4415 |
case SE_PushButtonLayoutItem: |
|
4416 |
if (const QStyleOptionButton *buttonOpt |
|
4417 |
= qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
4418 |
if ((buttonOpt->features & QStyleOptionButton::Flat)) |
|
4419 |
break; // leave rect alone |
|
4420 |
} |
|
4421 |
rect = opt->rect; |
|
4422 |
if (controlSize == QAquaSizeLarge) { |
|
4423 |
rect.adjust(+6, +4, -6, -8); |
|
4424 |
} else if (controlSize == QAquaSizeSmall) { |
|
4425 |
rect.adjust(+5, +4, -5, -6); |
|
4426 |
} else { |
|
4427 |
rect.adjust(+1, 0, -1, -2); |
|
4428 |
} |
|
4429 |
break; |
|
4430 |
case SE_RadioButtonLayoutItem: |
|
4431 |
rect = opt->rect; |
|
4432 |
if (controlSize == QAquaSizeLarge) { |
|
4433 |
setLayoutItemMargins(+2, +2 /* SHOULD BE +3, done for alignment */, |
|
4434 |
0, -4 /* SHOULD BE -3, done for alignment */, &rect, opt->direction); |
|
4435 |
} else if (controlSize == QAquaSizeSmall) { |
|
4436 |
rect.adjust(0, +6, 0 /* fix */, -5); |
|
4437 |
} else { |
|
4438 |
rect.adjust(0, +6, 0 /* fix */, -7); |
|
4439 |
} |
|
4440 |
break; |
|
4441 |
case SE_SliderLayoutItem: |
|
4442 |
if (const QStyleOptionSlider *sliderOpt |
|
4443 |
= qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
4444 |
rect = opt->rect; |
|
4445 |
if (sliderOpt->tickPosition == QSlider::NoTicks) { |
|
4446 |
int above = SIZE(3, 0, 2); |
|
4447 |
int below = SIZE(4, 3, 0); |
|
4448 |
if (sliderOpt->orientation == Qt::Horizontal) { |
|
4449 |
rect.adjust(0, +above, 0, -below); |
|
4450 |
} else { |
|
4451 |
rect.adjust(+above, 0, -below, 0); //### Seems that QSlider flip the position of the ticks in reverse mode. |
|
4452 |
} |
|
4453 |
} else if (sliderOpt->tickPosition == QSlider::TicksAbove) { |
|
4454 |
int below = SIZE(3, 2, 0); |
|
4455 |
if (sliderOpt->orientation == Qt::Horizontal) { |
|
4456 |
rect.setHeight(rect.height() - below); |
|
4457 |
} else { |
|
4458 |
rect.setWidth(rect.width() - below); |
|
4459 |
} |
|
4460 |
} else if (sliderOpt->tickPosition == QSlider::TicksBelow) { |
|
4461 |
int above = SIZE(3, 2, 0); |
|
4462 |
if (sliderOpt->orientation == Qt::Horizontal) { |
|
4463 |
rect.setTop(rect.top() + above); |
|
4464 |
} else { |
|
4465 |
rect.setLeft(rect.left() + above); |
|
4466 |
} |
|
4467 |
} |
|
4468 |
} |
|
4469 |
break; |
|
4470 |
case SE_FrameLayoutItem: |
|
4471 |
// hack because QStyleOptionFrameV2 doesn't have a frameStyle member |
|
4472 |
if (const QFrame *frame = qobject_cast<const QFrame *>(widget)) { |
|
4473 |
rect = opt->rect; |
|
4474 |
switch (frame->frameStyle() & QFrame::Shape_Mask) { |
|
4475 |
case QFrame::HLine: |
|
4476 |
rect.adjust(0, +1, 0, -1); |
|
4477 |
break; |
|
4478 |
case QFrame::VLine: |
|
4479 |
rect.adjust(+1, 0, -1, 0); |
|
4480 |
break; |
|
4481 |
default: |
|
4482 |
; |
|
4483 |
} |
|
4484 |
} |
|
4485 |
break; |
|
4486 |
case SE_GroupBoxLayoutItem: |
|
4487 |
rect = opt->rect; |
|
4488 |
if (const QStyleOptionGroupBox *groupBoxOpt = |
|
4489 |
qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) { |
|
4490 |
/* |
|
4491 |
AHIG is very inconsistent when it comes to group boxes. |
|
4492 |
Basically, we make sure that (non-checkable) group boxes |
|
4493 |
and tab widgets look good when laid out side by side. |
|
4494 |
*/ |
|
4495 |
if (groupBoxOpt->subControls & (QStyle::SC_GroupBoxCheckBox |
|
4496 |
| QStyle::SC_GroupBoxLabel)) { |
|
4497 |
int delta; |
|
4498 |
if (groupBoxOpt->subControls & QStyle::SC_GroupBoxCheckBox) { |
|
4499 |
delta = SIZE(8, 4, 4); // guess |
|
4500 |
} else { |
|
4501 |
delta = SIZE(15, 12, 12); // guess |
|
4502 |
} |
|
4503 |
rect.setTop(rect.top() + delta); |
|
4504 |
} |
|
4505 |
} |
|
4506 |
rect.setBottom(rect.bottom() - 1); |
|
4507 |
break; |
|
4508 |
case SE_TabWidgetLayoutItem: |
|
4509 |
if (const QStyleOptionTabWidgetFrame *tabWidgetOpt = |
|
4510 |
qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) { |
|
4511 |
/* |
|
4512 |
AHIG specifies "12 or 14" as the distance from the window |
|
4513 |
edge. We choose 14 and since the default top margin is 20, |
|
4514 |
the overlap is 6. |
|
4515 |
*/ |
|
4516 |
rect = tabWidgetOpt->rect; |
|
4517 |
if (tabWidgetOpt->shape == QTabBar::RoundedNorth) |
|
4518 |
rect.setTop(rect.top() + SIZE(6 /* AHIG */, 3 /* guess */, 2 /* AHIG */)); |
|
4519 |
} |
|
4520 |
break; |
|
4521 |
default: |
|
4522 |
rect = QWindowsStyle::subElementRect(sr, opt, widget); |
|
4523 |
break; |
|
4524 |
} |
|
4525 |
return rect; |
|
4526 |
} |
|
4527 |
||
4528 |
static inline void drawToolbarButtonArrow(const QRect &toolButtonRect, ThemeDrawState tds, CGContextRef cg) |
|
4529 |
{ |
|
4530 |
QRect arrowRect = QRect(toolButtonRect.right() - 9, toolButtonRect.bottom() - 9, 7, 5); |
|
4531 |
HIThemePopupArrowDrawInfo padi; |
|
4532 |
padi.version = qt_mac_hitheme_version; |
|
4533 |
padi.state = tds; |
|
4534 |
padi.orientation = kThemeArrowDown; |
|
4535 |
padi.size = kThemeArrow7pt; |
|
4536 |
HIRect hirect = qt_hirectForQRect(arrowRect); |
|
4537 |
HIThemeDrawPopupArrow(&hirect, &padi, cg, kHIThemeOrientationNormal); |
|
4538 |
} |
|
4539 |
||
4540 |
void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, |
|
4541 |
const QWidget *widget) const |
|
4542 |
{ |
|
4543 |
ThemeDrawState tds = d->getDrawState(opt->state); |
|
4544 |
QMacCGContext cg(p); |
|
4545 |
switch (cc) { |
|
4546 |
case CC_Slider: |
|
4547 |
case CC_ScrollBar: |
|
4548 |
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
4549 |
HIThemeTrackDrawInfo tdi; |
|
4550 |
d->getSliderInfo(cc, slider, &tdi, widget); |
|
4551 |
if (slider->state & State_Sunken) { |
|
4552 |
if (cc == CC_Slider) { |
|
4553 |
if (slider->activeSubControls == SC_SliderHandle) |
|
4554 |
tdi.trackInfo.slider.pressState = kThemeThumbPressed; |
|
4555 |
else if (slider->activeSubControls == SC_SliderGroove) |
|
4556 |
tdi.trackInfo.slider.pressState = kThemeLeftTrackPressed; |
|
4557 |
} else { |
|
4558 |
if (slider->activeSubControls == SC_ScrollBarSubLine |
|
4559 |
|| slider->activeSubControls == SC_ScrollBarAddLine) { |
|
4560 |
// This test looks complex but it basically boils down |
|
4561 |
// to the following: The "RTL look" on the mac also |
|
4562 |
// changed the directions of the controls, that's not |
|
4563 |
// what people expect (an arrow is an arrow), so we |
|
4564 |
// kind of fake and say the opposite button is hit. |
|
4565 |
// This works great, up until 10.4 which broke the |
|
4566 |
// scroll bars, so I also have actually do something |
|
4567 |
// similar when I have an upside down scroll bar |
|
4568 |
// because on Tiger I only "fake" the reverse stuff. |
|
4569 |
bool reverseHorizontal = (slider->direction == Qt::RightToLeft |
|
4570 |
&& slider->orientation == Qt::Horizontal); |
|
4571 |
if ((reverseHorizontal |
|
4572 |
&& slider->activeSubControls == SC_ScrollBarAddLine) |
|
4573 |
|| (!reverseHorizontal |
|
4574 |
&& slider->activeSubControls == SC_ScrollBarSubLine)) { |
|
4575 |
tdi.trackInfo.scrollbar.pressState = kThemeRightInsideArrowPressed |
|
4576 |
| kThemeLeftOutsideArrowPressed; |
|
4577 |
} else { |
|
4578 |
tdi.trackInfo.scrollbar.pressState = kThemeLeftInsideArrowPressed |
|
4579 |
| kThemeRightOutsideArrowPressed; |
|
4580 |
} |
|
4581 |
} else if (slider->activeSubControls == SC_ScrollBarAddPage) { |
|
4582 |
tdi.trackInfo.scrollbar.pressState = kThemeRightTrackPressed; |
|
4583 |
} else if (slider->activeSubControls == SC_ScrollBarSubPage) { |
|
4584 |
tdi.trackInfo.scrollbar.pressState = kThemeLeftTrackPressed; |
|
4585 |
} else if (slider->activeSubControls == SC_ScrollBarSlider) { |
|
4586 |
tdi.trackInfo.scrollbar.pressState = kThemeThumbPressed; |
|
4587 |
} |
|
4588 |
} |
|
4589 |
} |
|
4590 |
HIRect macRect; |
|
4591 |
bool tracking = slider->sliderPosition == slider->sliderValue; |
|
4592 |
if (!tracking) { |
|
4593 |
// Small optimization, the same as q->subControlRect |
|
4594 |
QCFType<HIShapeRef> shape; |
|
4595 |
HIThemeGetTrackThumbShape(&tdi, &shape); |
|
4596 |
ptrHIShapeGetBounds(shape, &macRect); |
|
4597 |
tdi.value = slider->sliderValue; |
|
4598 |
} |
|
4599 |
||
4600 |
// Remove controls from the scroll bar if it is to short to draw them correctly. |
|
4601 |
// This is done in two stages: first the thumb indicator is removed when it is |
|
4602 |
// no longer possible to move it, second the up/down buttons are removed when |
|
4603 |
// there is not enough space for them. |
|
4604 |
if (cc == CC_ScrollBar) { |
|
4605 |
const int scrollBarLength = (slider->orientation == Qt::Horizontal) |
|
4606 |
? slider->rect.width() : slider->rect.height(); |
|
4607 |
const QMacStyle::WidgetSizePolicy sizePolicy = widgetSizePolicy(widget); |
|
4608 |
if (scrollBarLength < scrollButtonsCutoffSize(thumbIndicatorCutoff, sizePolicy)) |
|
4609 |
tdi.attributes &= ~kThemeTrackShowThumb; |
|
4610 |
if (scrollBarLength < scrollButtonsCutoffSize(scrollButtonsCutoff, sizePolicy)) |
|
4611 |
tdi.enableState = kThemeTrackNothingToScroll; |
|
4612 |
} |
|
4613 |
||
4614 |
HIThemeDrawTrack(&tdi, tracking ? 0 : &macRect, cg, |
|
4615 |
kHIThemeOrientationNormal); |
|
4616 |
if (cc == CC_Slider && slider->subControls & SC_SliderTickmarks) { |
|
4617 |
if (qt_mac_is_metal(widget)) { |
|
4618 |
if (tdi.enableState == kThemeTrackInactive) |
|
4619 |
tdi.enableState = kThemeTrackActive; // Looks more Cocoa-like |
|
4620 |
} |
|
4621 |
int interval = slider->tickInterval; |
|
4622 |
if (interval == 0) { |
|
4623 |
interval = slider->pageStep; |
|
4624 |
if (interval == 0) |
|
4625 |
interval = slider->singleStep; |
|
4626 |
if (interval == 0) |
|
4627 |
interval = 1; |
|
4628 |
} |
|
4629 |
int numMarks = 1 + ((slider->maximum - slider->minimum) / interval); |
|
4630 |
||
4631 |
if (tdi.trackInfo.slider.thumbDir == kThemeThumbPlain) { |
|
4632 |
// They asked for both, so we'll give it to them. |
|
4633 |
tdi.trackInfo.slider.thumbDir = kThemeThumbDownward; |
|
4634 |
HIThemeDrawTrackTickMarks(&tdi, numMarks, |
|
4635 |
cg, |
|
4636 |
kHIThemeOrientationNormal); |
|
4637 |
tdi.trackInfo.slider.thumbDir = kThemeThumbUpward; |
|
4638 |
HIThemeDrawTrackTickMarks(&tdi, numMarks, |
|
4639 |
cg, |
|
4640 |
kHIThemeOrientationNormal); |
|
4641 |
} else { |
|
4642 |
HIThemeDrawTrackTickMarks(&tdi, numMarks, |
|
4643 |
cg, |
|
4644 |
kHIThemeOrientationNormal); |
|
4645 |
||
4646 |
} |
|
4647 |
} |
|
4648 |
} |
|
4649 |
break; |
|
4650 |
case CC_Q3ListView: |
|
4651 |
if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) { |
|
4652 |
if (lv->subControls & SC_Q3ListView) |
|
4653 |
QWindowsStyle::drawComplexControl(cc, lv, p, widget); |
|
4654 |
if (lv->subControls & (SC_Q3ListViewBranch | SC_Q3ListViewExpand)) { |
|
4655 |
int y = lv->rect.y(); |
|
4656 |
int h = lv->rect.height(); |
|
4657 |
int x = lv->rect.right() - 10; |
|
4658 |
for (int i = 1; i < lv->items.size() && y < h; ++i) { |
|
4659 |
QStyleOptionQ3ListViewItem item = lv->items.at(i); |
|
4660 |
if (y + item.height > 0 && (item.childCount > 0 |
|
4661 |
|| (item.features & (QStyleOptionQ3ListViewItem::Expandable |
|
4662 |
| QStyleOptionQ3ListViewItem::Visible)) |
|
4663 |
== (QStyleOptionQ3ListViewItem::Expandable |
|
4664 |
| QStyleOptionQ3ListViewItem::Visible))) { |
|
4665 |
QStyleOption treeOpt(0); |
|
4666 |
treeOpt.rect.setRect(x, y + item.height / 2 - 4, 9, 9); |
|
4667 |
treeOpt.palette = lv->palette; |
|
4668 |
treeOpt.state = lv->state; |
|
4669 |
treeOpt.state |= State_Children; |
|
4670 |
if (item.state & State_Open) |
|
4671 |
treeOpt.state |= State_Open; |
|
4672 |
proxy()->drawPrimitive(PE_IndicatorBranch, &treeOpt, p, widget); |
|
4673 |
} |
|
4674 |
y += item.totalHeight; |
|
4675 |
} |
|
4676 |
} |
|
4677 |
} |
|
4678 |
break; |
|
4679 |
case CC_SpinBox: |
|
4680 |
if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { |
|
4681 |
QStyleOptionSpinBox newSB = *sb; |
|
4682 |
if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) { |
|
4683 |
SInt32 frame_size; |
|
4684 |
GetThemeMetric(kThemeMetricEditTextFrameOutset, &frame_size); |
|
4685 |
||
4686 |
QRect lineeditRect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxEditField, widget); |
|
4687 |
lineeditRect.adjust(-frame_size, -frame_size, +frame_size, +frame_size); |
|
4688 |
||
4689 |
HIThemeFrameDrawInfo fdi; |
|
4690 |
fdi.version = qt_mac_hitheme_version; |
|
4691 |
fdi.state = kThemeStateInactive; |
|
4692 |
fdi.kind = kHIThemeFrameTextFieldSquare; |
|
4693 |
fdi.isFocused = false; |
|
4694 |
HIRect hirect = qt_hirectForQRect(lineeditRect); |
|
4695 |
HIThemeDrawFrame(&hirect, &fdi, cg, kHIThemeOrientationNormal); |
|
4696 |
} |
|
4697 |
if (sb->subControls & (SC_SpinBoxUp | SC_SpinBoxDown)) { |
|
4698 |
HIThemeButtonDrawInfo bdi; |
|
4699 |
bdi.version = qt_mac_hitheme_version; |
|
4700 |
QAquaWidgetSize aquaSize = d->aquaSizeConstrain(opt, widget); |
|
4701 |
switch (aquaSize) { |
|
4702 |
case QAquaSizeUnknown: |
|
4703 |
case QAquaSizeLarge: |
|
4704 |
bdi.kind = kThemeIncDecButton; |
|
4705 |
break; |
|
4706 |
case QAquaSizeMini: |
|
4707 |
bdi.kind = kThemeIncDecButtonMini; |
|
4708 |
break; |
|
4709 |
case QAquaSizeSmall: |
|
4710 |
bdi.kind = kThemeIncDecButtonSmall; |
|
4711 |
break; |
|
4712 |
} |
|
4713 |
if (!(sb->stepEnabled & (QAbstractSpinBox::StepUpEnabled |
|
4714 |
| QAbstractSpinBox::StepDownEnabled))) |
|
4715 |
tds = kThemeStateUnavailable; |
|
4716 |
if (sb->activeSubControls == SC_SpinBoxDown |
|
4717 |
&& (sb->state & State_Sunken)) |
|
4718 |
tds = kThemeStatePressedDown; |
|
4719 |
else if (sb->activeSubControls == SC_SpinBoxUp |
|
4720 |
&& (sb->state & State_Sunken)) |
|
4721 |
tds = kThemeStatePressedUp; |
|
4722 |
bdi.state = tds; |
|
4723 |
if (!(sb->state & State_Active) |
|
4724 |
&& sb->palette.currentColorGroup() == QPalette::Active |
|
4725 |
&& tds == kThemeStateInactive) |
|
4726 |
bdi.state = kThemeStateActive; |
|
4727 |
bdi.value = kThemeButtonOff; |
|
4728 |
bdi.adornment = kThemeAdornmentNone; |
|
4729 |
||
4730 |
QRect updown = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget); |
|
4731 |
||
4732 |
updown |= proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget); |
|
4733 |
HIRect newRect = qt_hirectForQRect(updown); |
|
4734 |
QRect off_rct; |
|
4735 |
HIRect outRect; |
|
4736 |
HIThemeGetButtonBackgroundBounds(&newRect, &bdi, &outRect); |
|
4737 |
off_rct.setRect(int(newRect.origin.x - outRect.origin.x), |
|
4738 |
int(newRect.origin.y - outRect.origin.y), |
|
4739 |
int(outRect.size.width - newRect.size.width), |
|
4740 |
int(outRect.size.height - newRect.size.height)); |
|
4741 |
||
4742 |
newRect = qt_hirectForQRect(updown, off_rct); |
|
4743 |
HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0); |
|
4744 |
} |
|
4745 |
} |
|
4746 |
break; |
|
4747 |
case CC_ComboBox: |
|
4748 |
if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)){ |
|
4749 |
HIThemeButtonDrawInfo bdi; |
|
4750 |
d->initComboboxBdi(combo, &bdi, widget, d->getDrawState(opt->state)); |
|
4751 |
bool drawColorless = combo->palette.currentColorGroup() == QPalette::Active && tds == kThemeStateInactive; |
|
4752 |
if (!drawColorless) |
|
4753 |
QMacStylePrivate::drawCombobox(qt_hirectForQRect(combo->rect), bdi, p); |
|
4754 |
else |
|
4755 |
d->drawColorlessButton(qt_hirectForQRect(combo->rect), &bdi, p, opt); |
|
4756 |
} |
|
4757 |
break; |
|
4758 |
case CC_TitleBar: |
|
4759 |
if (const QStyleOptionTitleBar *titlebar |
|
4760 |
= qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) { |
|
4761 |
if (titlebar->state & State_Active) { |
|
4762 |
if (titlebar->titleBarState & State_Active) |
|
4763 |
tds = kThemeStateActive; |
|
4764 |
else |
|
4765 |
tds = kThemeStateInactive; |
|
4766 |
} else { |
|
4767 |
tds = kThemeStateInactive; |
|
4768 |
} |
|
4769 |
||
4770 |
HIThemeWindowDrawInfo wdi; |
|
4771 |
wdi.version = qt_mac_hitheme_version; |
|
4772 |
wdi.state = tds; |
|
4773 |
wdi.windowType = QtWinType; |
|
4774 |
wdi.titleHeight = titlebar->rect.height(); |
|
4775 |
wdi.titleWidth = titlebar->rect.width(); |
|
4776 |
wdi.attributes = kThemeWindowHasTitleText; |
|
4777 |
// It seems HIThemeDrawTitleBarWidget is not able to draw a dirty |
|
4778 |
// close button, so use HIThemeDrawWindowFrame instead. |
|
4779 |
if (widget && widget->isWindowModified() && titlebar->subControls & SC_TitleBarCloseButton) |
|
4780 |
wdi.attributes |= kThemeWindowHasCloseBox | kThemeWindowHasDirty; |
|
4781 |
||
4782 |
HIRect titleBarRect; |
|
4783 |
HIRect tmpRect = qt_hirectForQRect(titlebar->rect); |
|
4784 |
{ |
|
4785 |
QCFType<HIShapeRef> titleRegion; |
|
4786 |
QRect newr = titlebar->rect.adjusted(0, 0, 2, 0); |
|
4787 |
HIThemeGetWindowShape(&tmpRect, &wdi, kWindowTitleBarRgn, &titleRegion); |
|
4788 |
ptrHIShapeGetBounds(titleRegion, &tmpRect); |
|
4789 |
newr.translate(newr.x() - int(tmpRect.origin.x), newr.y() - int(tmpRect.origin.y)); |
|
4790 |
titleBarRect = qt_hirectForQRect(newr); |
|
4791 |
} |
|
4792 |
HIThemeDrawWindowFrame(&titleBarRect, &wdi, cg, kHIThemeOrientationNormal, 0); |
|
4793 |
if (titlebar->subControls & (SC_TitleBarCloseButton |
|
4794 |
| SC_TitleBarMaxButton |
|
4795 |
| SC_TitleBarMinButton |
|
4796 |
| SC_TitleBarNormalButton)) { |
|
4797 |
HIThemeWindowWidgetDrawInfo wwdi; |
|
4798 |
wwdi.version = qt_mac_hitheme_version; |
|
4799 |
wwdi.widgetState = tds; |
|
4800 |
if (titlebar->state & State_MouseOver) |
|
4801 |
wwdi.widgetState = kThemeStateRollover; |
|
4802 |
wwdi.windowType = QtWinType; |
|
4803 |
wwdi.attributes = wdi.attributes | kThemeWindowHasFullZoom | kThemeWindowHasCloseBox | kThemeWindowHasCollapseBox; |
|
4804 |
wwdi.windowState = wdi.state; |
|
4805 |
wwdi.titleHeight = wdi.titleHeight; |
|
4806 |
wwdi.titleWidth = wdi.titleWidth; |
|
4807 |
ThemeDrawState savedControlState = wwdi.widgetState; |
|
4808 |
uint sc = SC_TitleBarMinButton; |
|
4809 |
ThemeTitleBarWidget tbw = kThemeWidgetCollapseBox; |
|
4810 |
bool active = titlebar->state & State_Active; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4811 |
if (qMacVersion() < QSysInfo::MV_10_6) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4812 |
int border = 2; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4813 |
titleBarRect.origin.x += border; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4814 |
titleBarRect.origin.y -= border; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4815 |
} |
0 | 4816 |
|
4817 |
while (sc <= SC_TitleBarCloseButton) { |
|
4818 |
if (sc & titlebar->subControls) { |
|
4819 |
uint tmp = sc; |
|
4820 |
wwdi.widgetState = savedControlState; |
|
4821 |
wwdi.widgetType = tbw; |
|
4822 |
if (sc == SC_TitleBarMinButton) |
|
4823 |
tmp |= SC_TitleBarNormalButton; |
|
4824 |
if (active && (titlebar->activeSubControls & tmp) |
|
4825 |
&& (titlebar->state & State_Sunken)) |
|
4826 |
wwdi.widgetState = kThemeStatePressed; |
|
4827 |
// Draw all sub controllers except the dirty close button |
|
4828 |
// (it is already handled by HIThemeDrawWindowFrame). |
|
4829 |
if (!(widget && widget->isWindowModified() && tbw == kThemeWidgetCloseBox)) { |
|
4830 |
HIThemeDrawTitleBarWidget(&titleBarRect, &wwdi, cg, kHIThemeOrientationNormal); |
|
4831 |
p->paintEngine()->syncState(); |
|
4832 |
} |
|
4833 |
} |
|
4834 |
sc = sc << 1; |
|
4835 |
tbw = tbw >> 1; |
|
4836 |
} |
|
4837 |
} |
|
4838 |
p->paintEngine()->syncState(); |
|
4839 |
if (titlebar->subControls & SC_TitleBarLabel) { |
|
4840 |
int iw = 0; |
|
4841 |
if (!titlebar->icon.isNull()) { |
|
4842 |
QCFType<HIShapeRef> titleRegion2; |
|
4843 |
HIThemeGetWindowShape(&titleBarRect, &wdi, kWindowTitleProxyIconRgn, |
|
4844 |
&titleRegion2); |
|
4845 |
ptrHIShapeGetBounds(titleRegion2, &tmpRect); |
|
4846 |
if (tmpRect.size.width != 1) { |
|
4847 |
int iconExtent = proxy()->pixelMetric(PM_SmallIconSize); |
|
4848 |
iw = titlebar->icon.actualSize(QSize(iconExtent, iconExtent)).width(); |
|
4849 |
} |
|
4850 |
} |
|
4851 |
if (!titlebar->text.isEmpty()) { |
|
4852 |
p->save(); |
|
4853 |
QCFType<HIShapeRef> titleRegion3; |
|
4854 |
HIThemeGetWindowShape(&titleBarRect, &wdi, kWindowTitleTextRgn, &titleRegion3); |
|
4855 |
ptrHIShapeGetBounds(titleRegion3, &tmpRect); |
|
4856 |
p->setClipRect(qt_qrectForHIRect(tmpRect)); |
|
4857 |
QRect br = p->clipRegion().boundingRect(); |
|
4858 |
int x = br.x(), |
|
4859 |
y = br.y() + (titlebar->rect.height() / 2 - p->fontMetrics().height() / 2); |
|
4860 |
if (br.width() <= (p->fontMetrics().width(titlebar->text) + iw * 2)) |
|
4861 |
x += iw; |
|
4862 |
else |
|
4863 |
x += br.width() / 2 - p->fontMetrics().width(titlebar->text) / 2; |
|
4864 |
if (iw) |
|
4865 |
p->drawPixmap(x - iw, y, |
|
4866 |
titlebar->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), QIcon::Normal)); |
|
4867 |
drawItemText(p, br, Qt::AlignCenter, opt->palette, tds == kThemeStateActive, |
|
4868 |
titlebar->text, QPalette::Text); |
|
4869 |
p->restore(); |
|
4870 |
} |
|
4871 |
} |
|
4872 |
} |
|
4873 |
break; |
|
4874 |
case CC_GroupBox: |
|
4875 |
if (const QStyleOptionGroupBox *groupBox |
|
4876 |
= qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) { |
|
4877 |
||
4878 |
QStyleOptionGroupBox groupBoxCopy(*groupBox); |
|
4879 |
if ((widget && !widget->testAttribute(Qt::WA_SetFont)) |
|
4880 |
&& QApplication::desktopSettingsAware()) |
|
4881 |
groupBoxCopy.subControls = groupBoxCopy.subControls & ~SC_GroupBoxLabel; |
|
4882 |
QWindowsStyle::drawComplexControl(cc, &groupBoxCopy, p, widget); |
|
4883 |
if (groupBoxCopy.subControls != groupBox->subControls) { |
|
4884 |
bool checkable = groupBox->subControls & SC_GroupBoxCheckBox; |
|
4885 |
p->save(); |
|
4886 |
CGContextSetShouldAntialias(cg, true); |
|
4887 |
CGContextSetShouldSmoothFonts(cg, true); |
|
4888 |
HIThemeTextInfo tti; |
|
4889 |
tti.version = qt_mac_hitheme_version; |
|
4890 |
tti.state = tds; |
|
4891 |
QColor textColor = groupBox->palette.windowText().color(); |
|
4892 |
CGFloat colorComp[] = { textColor.redF(), textColor.greenF(), |
|
4893 |
textColor.blueF(), textColor.alphaF() }; |
|
4894 |
CGContextSetFillColorSpace(cg, QCoreGraphicsPaintEngine::macGenericColorSpace()); |
|
4895 |
CGContextSetFillColor(cg, colorComp); |
|
4896 |
tti.fontID = checkable ? kThemeSystemFont : kThemeSmallSystemFont; |
|
4897 |
tti.horizontalFlushness = kHIThemeTextHorizontalFlushCenter; |
|
4898 |
tti.verticalFlushness = kHIThemeTextVerticalFlushCenter; |
|
4899 |
tti.options = kHIThemeTextBoxOptionNone; |
|
4900 |
tti.truncationPosition = kHIThemeTextTruncationNone; |
|
4901 |
tti.truncationMaxLines = 1 + groupBox->text.count(QLatin1Char('\n')); |
|
4902 |
QCFString groupText = qt_mac_removeMnemonics(groupBox->text); |
|
4903 |
QRect r = proxy()->subControlRect(CC_GroupBox, groupBox, SC_GroupBoxLabel, widget); |
|
4904 |
HIRect bounds = qt_hirectForQRect(r); |
|
4905 |
HIThemeDrawTextBox(groupText, &bounds, &tti, cg, kHIThemeOrientationNormal); |
|
4906 |
p->restore(); |
|
4907 |
} |
|
4908 |
} |
|
4909 |
break; |
|
4910 |
case CC_ToolButton: |
|
4911 |
if (const QStyleOptionToolButton *tb |
|
4912 |
= qstyleoption_cast<const QStyleOptionToolButton *>(opt)) { |
|
4913 |
if (widget && qobject_cast<QToolBar *>(widget->parentWidget())) { |
|
4914 |
if (tb->subControls & SC_ToolButtonMenu) { |
|
4915 |
QStyleOption arrowOpt(0); |
|
4916 |
arrowOpt.rect = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget); |
|
4917 |
arrowOpt.rect.setY(arrowOpt.rect.y() + arrowOpt.rect.height() / 2); |
|
4918 |
arrowOpt.rect.setHeight(arrowOpt.rect.height() / 2); |
|
4919 |
arrowOpt.state = tb->state; |
|
4920 |
arrowOpt.palette = tb->palette; |
|
4921 |
proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget); |
|
4922 |
} else if ((tb->features & QStyleOptionToolButton::HasMenu) |
|
4923 |
&& (tb->toolButtonStyle != Qt::ToolButtonTextOnly && !tb->icon.isNull())) { |
|
4924 |
drawToolbarButtonArrow(tb->rect, tds, cg); |
|
4925 |
} |
|
4926 |
if (tb->state & State_On) { |
|
4927 |
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { |
|
4928 |
static QPixmap pm(QLatin1String(":/trolltech/mac/style/images/leopard-unified-toolbar-on.png")); |
|
4929 |
p->setRenderHint(QPainter::SmoothPixmapTransform); |
|
4930 |
QStyleHelper::drawBorderPixmap(pm, p, tb->rect, 2, 2, 2, 2); |
|
4931 |
} else { |
|
4932 |
QPen oldPen = p->pen(); |
|
4933 |
p->setPen(QColor(0, 0, 0, 0x3a)); |
|
4934 |
p->fillRect(tb->rect.adjusted(1, 1, -1, -1), QColor(0, 0, 0, 0x12)); |
|
4935 |
p->drawLine(tb->rect.left() + 1, tb->rect.top(), |
|
4936 |
tb->rect.right() - 1, tb->rect.top()); |
|
4937 |
p->drawLine(tb->rect.left() + 1, tb->rect.bottom(), |
|
4938 |
tb->rect.right() - 1, tb->rect.bottom()); |
|
4939 |
p->drawLine(tb->rect.topLeft(), tb->rect.bottomLeft()); |
|
4940 |
p->drawLine(tb->rect.topRight(), tb->rect.bottomRight()); |
|
4941 |
p->setPen(oldPen); |
|
4942 |
} |
|
4943 |
} |
|
4944 |
proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget); |
|
4945 |
} else { |
|
4946 |
ThemeButtonKind bkind = kThemeBevelButton; |
|
4947 |
switch (d->aquaSizeConstrain(opt, widget)) { |
|
4948 |
case QAquaSizeUnknown: |
|
4949 |
case QAquaSizeLarge: |
|
4950 |
bkind = kThemeBevelButton; |
|
4951 |
break; |
|
4952 |
case QAquaSizeMini: |
|
4953 |
case QAquaSizeSmall: |
|
4954 |
bkind = kThemeSmallBevelButton; |
|
4955 |
break; |
|
4956 |
} |
|
4957 |
||
4958 |
QRect button, menuarea; |
|
4959 |
button = proxy()->subControlRect(cc, tb, SC_ToolButton, widget); |
|
4960 |
menuarea = proxy()->subControlRect(cc, tb, SC_ToolButtonMenu, widget); |
|
4961 |
State bflags = tb->state, |
|
4962 |
mflags = tb->state; |
|
4963 |
if (tb->subControls & SC_ToolButton) |
|
4964 |
bflags |= State_Sunken; |
|
4965 |
if (tb->subControls & SC_ToolButtonMenu) |
|
4966 |
mflags |= State_Sunken; |
|
4967 |
||
4968 |
if (tb->subControls & SC_ToolButton) { |
|
4969 |
if (bflags & (State_Sunken | State_On | State_Raised)) { |
|
4970 |
HIThemeButtonDrawInfo bdi; |
|
4971 |
bdi.version = qt_mac_hitheme_version; |
|
4972 |
bdi.state = tds; |
|
4973 |
bdi.adornment = kThemeAdornmentNone; |
|
4974 |
bdi.kind = bkind; |
|
4975 |
bdi.value = kThemeButtonOff; |
|
4976 |
if (tb->state & State_HasFocus) |
|
4977 |
bdi.adornment = kThemeAdornmentFocus; |
|
4978 |
if (tb->state & State_Sunken) |
|
4979 |
bdi.state = kThemeStatePressed; |
|
4980 |
if (tb->state & State_On) |
|
4981 |
bdi.value = kThemeButtonOn; |
|
4982 |
||
4983 |
QRect off_rct(0, 0, 0, 0); |
|
4984 |
HIRect myRect, macRect; |
|
4985 |
myRect = CGRectMake(tb->rect.x(), tb->rect.y(), |
|
4986 |
tb->rect.width(), tb->rect.height()); |
|
4987 |
HIThemeGetButtonBackgroundBounds(&myRect, &bdi, &macRect); |
|
4988 |
off_rct.setRect(int(myRect.origin.x - macRect.origin.x), |
|
4989 |
int(myRect.origin.y - macRect.origin.y), |
|
4990 |
int(macRect.size.width - myRect.size.width), |
|
4991 |
int(macRect.size.height - myRect.size.height)); |
|
4992 |
||
4993 |
myRect = qt_hirectForQRect(button, off_rct); |
|
4994 |
HIThemeDrawButton(&myRect, &bdi, cg, kHIThemeOrientationNormal, 0); |
|
4995 |
} |
|
4996 |
} |
|
4997 |
||
4998 |
if (tb->subControls & SC_ToolButtonMenu) { |
|
4999 |
HIThemeButtonDrawInfo bdi; |
|
5000 |
bdi.version = qt_mac_hitheme_version; |
|
5001 |
bdi.state = tds; |
|
5002 |
bdi.value = kThemeButtonOff; |
|
5003 |
bdi.adornment = kThemeAdornmentNone; |
|
5004 |
bdi.kind = bkind; |
|
5005 |
if (tb->state & State_HasFocus) |
|
5006 |
bdi.adornment = kThemeAdornmentFocus; |
|
5007 |
if (tb->state & (State_On | State_Sunken) |
|
5008 |
|| (tb->activeSubControls & SC_ToolButtonMenu)) |
|
5009 |
bdi.state = kThemeStatePressed; |
|
5010 |
HIRect hirect = qt_hirectForQRect(menuarea); |
|
5011 |
HIThemeDrawButton(&hirect, &bdi, cg, kHIThemeOrientationNormal, 0); |
|
5012 |
QRect r(menuarea.x() + ((menuarea.width() / 2) - 3), menuarea.height() - 8, 8, 8); |
|
5013 |
HIThemePopupArrowDrawInfo padi; |
|
5014 |
padi.version = qt_mac_hitheme_version; |
|
5015 |
padi.state = tds; |
|
5016 |
padi.orientation = kThemeArrowDown; |
|
5017 |
padi.size = kThemeArrow7pt; |
|
5018 |
hirect = qt_hirectForQRect(r); |
|
5019 |
HIThemeDrawPopupArrow(&hirect, &padi, cg, kHIThemeOrientationNormal); |
|
5020 |
} else if (tb->features & QStyleOptionToolButton::HasMenu) { |
|
5021 |
drawToolbarButtonArrow(tb->rect, tds, cg); |
|
5022 |
} |
|
5023 |
QRect buttonRect = proxy()->subControlRect(CC_ToolButton, tb, SC_ToolButton, widget); |
|
5024 |
int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget); |
|
5025 |
QStyleOptionToolButton label = *tb; |
|
5026 |
label.rect = buttonRect.adjusted(fw, fw, -fw, -fw); |
|
5027 |
proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget); |
|
5028 |
} |
|
5029 |
} |
|
5030 |
break; |
|
5031 |
case CC_Dial: |
|
5032 |
if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt)) |
|
5033 |
QStyleHelper::drawDial(dial, p); |
|
5034 |
break; |
|
5035 |
default: |
|
5036 |
QWindowsStyle::drawComplexControl(cc, opt, p, widget); |
|
5037 |
break; |
|
5038 |
} |
|
5039 |
} |
|
5040 |
||
5041 |
QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc, |
|
5042 |
const QStyleOptionComplex *opt, |
|
5043 |
const QPoint &pt, const QWidget *widget) const |
|
5044 |
{ |
|
5045 |
SubControl sc = QStyle::SC_None; |
|
5046 |
switch (cc) { |
|
5047 |
case CC_ComboBox: |
|
5048 |
if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { |
|
5049 |
sc = QWindowsStyle::hitTestComplexControl(cc, cmb, pt, widget); |
|
5050 |
if (!cmb->editable && sc != QStyle::SC_None) |
|
5051 |
sc = SC_ComboBoxArrow; // A bit of a lie, but what we want |
|
5052 |
} |
|
5053 |
break; |
|
5054 |
case CC_Slider: |
|
5055 |
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
5056 |
HIThemeTrackDrawInfo tdi; |
|
5057 |
d->getSliderInfo(cc, slider, &tdi, widget); |
|
5058 |
ControlPartCode part; |
|
5059 |
HIPoint pos = CGPointMake(pt.x(), pt.y()); |
|
5060 |
if (HIThemeHitTestTrack(&tdi, &pos, &part)) { |
|
5061 |
if (part == kControlPageUpPart || part == kControlPageDownPart) |
|
5062 |
sc = SC_SliderGroove; |
|
5063 |
else |
|
5064 |
sc = SC_SliderHandle; |
|
5065 |
} |
|
5066 |
} |
|
5067 |
break; |
|
5068 |
case CC_ScrollBar: |
|
5069 |
if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
5070 |
HIScrollBarTrackInfo sbi; |
|
5071 |
sbi.version = qt_mac_hitheme_version; |
|
5072 |
if (!(sb->state & State_Active)) |
|
5073 |
sbi.enableState = kThemeTrackInactive; |
|
5074 |
else if (sb->state & State_Enabled) |
|
5075 |
sbi.enableState = kThemeTrackActive; |
|
5076 |
else |
|
5077 |
sbi.enableState = kThemeTrackDisabled; |
|
5078 |
||
5079 |
// The arrow buttons are not drawn if the scroll bar is to short, |
|
5080 |
// exclude them from the hit test. |
|
5081 |
const int scrollBarLength = (sb->orientation == Qt::Horizontal) |
|
5082 |
? sb->rect.width() : sb->rect.height(); |
|
5083 |
if (scrollBarLength < scrollButtonsCutoffSize(scrollButtonsCutoff, widgetSizePolicy(widget))) |
|
5084 |
sbi.enableState = kThemeTrackNothingToScroll; |
|
5085 |
||
5086 |
sbi.viewsize = sb->pageStep; |
|
5087 |
HIPoint pos = CGPointMake(pt.x(), pt.y()); |
|
5088 |
||
5089 |
HIRect macSBRect = qt_hirectForQRect(sb->rect); |
|
5090 |
ControlPartCode part; |
|
5091 |
bool reverseHorizontal = (sb->direction == Qt::RightToLeft |
|
5092 |
&& sb->orientation == Qt::Horizontal |
|
5093 |
&& (!sb->upsideDown || |
|
5094 |
(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4 |
|
5095 |
&& sb->upsideDown))); |
|
5096 |
if (HIThemeHitTestScrollBarArrows(&macSBRect, &sbi, sb->orientation == Qt::Horizontal, |
|
5097 |
&pos, 0, &part)) { |
|
5098 |
if (part == kControlUpButtonPart) |
|
5099 |
sc = reverseHorizontal ? SC_ScrollBarAddLine : SC_ScrollBarSubLine; |
|
5100 |
else if (part == kControlDownButtonPart) |
|
5101 |
sc = reverseHorizontal ? SC_ScrollBarSubLine : SC_ScrollBarAddLine; |
|
5102 |
} else { |
|
5103 |
HIThemeTrackDrawInfo tdi; |
|
5104 |
d->getSliderInfo(cc, sb, &tdi, widget); |
|
5105 |
if(tdi.enableState == kThemeTrackInactive) |
|
5106 |
tdi.enableState = kThemeTrackActive; |
|
5107 |
if (HIThemeHitTestTrack(&tdi, &pos, &part)) { |
|
5108 |
if (part == kControlPageUpPart) |
|
5109 |
sc = reverseHorizontal ? SC_ScrollBarAddPage |
|
5110 |
: SC_ScrollBarSubPage; |
|
5111 |
else if (part == kControlPageDownPart) |
|
5112 |
sc = reverseHorizontal ? SC_ScrollBarSubPage |
|
5113 |
: SC_ScrollBarAddPage; |
|
5114 |
else |
|
5115 |
sc = SC_ScrollBarSlider; |
|
5116 |
} |
|
5117 |
} |
|
5118 |
} |
|
5119 |
break; |
|
5120 |
/* |
|
5121 |
I don't know why, but we only get kWindowContentRgn here, which isn't what we want at all. |
|
5122 |
It would be very nice if this would work. |
|
5123 |
case QStyle::CC_TitleBar: |
|
5124 |
if (const QStyleOptionTitleBar *tbar = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) { |
|
5125 |
HIThemeWindowDrawInfo wdi; |
|
5126 |
memset(&wdi, 0, sizeof(wdi)); |
|
5127 |
wdi.version = qt_mac_hitheme_version; |
|
5128 |
wdi.state = kThemeStateActive; |
|
5129 |
wdi.windowType = QtWinType; |
|
5130 |
wdi.titleWidth = tbar->rect.width(); |
|
5131 |
wdi.titleHeight = tbar->rect.height(); |
|
5132 |
if (tbar->titleBarState) |
|
5133 |
wdi.attributes |= kThemeWindowHasFullZoom | kThemeWindowHasCloseBox |
|
5134 |
| kThemeWindowHasCollapseBox; |
|
5135 |
else if (tbar->titleBarFlags & Qt::WindowSystemMenuHint) |
|
5136 |
wdi.attributes |= kThemeWindowHasCloseBox; |
|
5137 |
QRect tmpRect = tbar->rect; |
|
5138 |
tmpRect.setHeight(tmpRect.height() + 100); |
|
5139 |
HIRect hirect = qt_hirectForQRect(tmpRect); |
|
5140 |
WindowRegionCode hit; |
|
5141 |
HIPoint hipt = CGPointMake(pt.x(), pt.y()); |
|
5142 |
if (HIThemeGetWindowRegionHit(&hirect, &wdi, &hipt, &hit)) { |
|
5143 |
switch (hit) { |
|
5144 |
case kWindowCloseBoxRgn: |
|
5145 |
sc = QStyle::SC_TitleBarCloseButton; |
|
5146 |
break; |
|
5147 |
case kWindowCollapseBoxRgn: |
|
5148 |
sc = QStyle::SC_TitleBarMinButton; |
|
5149 |
break; |
|
5150 |
case kWindowZoomBoxRgn: |
|
5151 |
sc = QStyle::SC_TitleBarMaxButton; |
|
5152 |
break; |
|
5153 |
case kWindowTitleTextRgn: |
|
5154 |
sc = QStyle::SC_TitleBarLabel; |
|
5155 |
break; |
|
5156 |
default: |
|
5157 |
qDebug("got something else %d", hit); |
|
5158 |
break; |
|
5159 |
} |
|
5160 |
} |
|
5161 |
} |
|
5162 |
break; |
|
5163 |
*/ |
|
5164 |
default: |
|
5165 |
sc = QWindowsStyle::hitTestComplexControl(cc, opt, pt, widget); |
|
5166 |
break; |
|
5167 |
} |
|
5168 |
return sc; |
|
5169 |
} |
|
5170 |
||
5171 |
QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, |
|
5172 |
const QWidget *widget) const |
|
5173 |
{ |
|
5174 |
QRect ret; |
|
5175 |
switch (cc) { |
|
5176 |
case CC_Slider: |
|
5177 |
case CC_ScrollBar: |
|
5178 |
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
5179 |
HIThemeTrackDrawInfo tdi; |
|
5180 |
d->getSliderInfo(cc, slider, &tdi, widget); |
|
5181 |
HIRect macRect; |
|
5182 |
QCFType<HIShapeRef> shape; |
|
5183 |
bool scrollBar = cc == CC_ScrollBar; |
|
5184 |
if ((scrollBar && sc == SC_ScrollBarSlider) |
|
5185 |
|| (!scrollBar && sc == SC_SliderHandle)) { |
|
5186 |
HIThemeGetTrackThumbShape(&tdi, &shape); |
|
5187 |
ptrHIShapeGetBounds(shape, &macRect); |
|
5188 |
} else if (!scrollBar && sc == SC_SliderGroove) { |
|
5189 |
HIThemeGetTrackBounds(&tdi, &macRect); |
|
5190 |
} else if (sc == SC_ScrollBarGroove) { // Only scroll bar parts available... |
|
5191 |
HIThemeGetTrackDragRect(&tdi, &macRect); |
|
5192 |
} else { |
|
5193 |
ControlPartCode cpc; |
|
5194 |
if (sc == SC_ScrollBarSubPage || sc == SC_ScrollBarAddPage) { |
|
5195 |
cpc = sc == SC_ScrollBarSubPage ? kControlPageDownPart |
|
5196 |
: kControlPageUpPart; |
|
5197 |
} else { |
|
5198 |
cpc = sc == SC_ScrollBarSubLine ? kControlUpButtonPart |
|
5199 |
: kControlDownButtonPart; |
|
5200 |
if (slider->direction == Qt::RightToLeft |
|
5201 |
&& slider->orientation == Qt::Horizontal) { |
|
5202 |
if (cpc == kControlDownButtonPart) |
|
5203 |
cpc = kControlUpButtonPart; |
|
5204 |
else if (cpc == kControlUpButtonPart) |
|
5205 |
cpc = kControlDownButtonPart; |
|
5206 |
} |
|
5207 |
} |
|
5208 |
HIThemeGetTrackPartBounds(&tdi, cpc, &macRect); |
|
5209 |
} |
|
5210 |
ret = qt_qrectForHIRect(macRect); |
|
5211 |
||
5212 |
// Tweak: the dark line between the sub/add line buttons belong to only one of the buttons |
|
5213 |
// when doing hit-testing, but both of them have to repaint it. Extend the rect to cover |
|
5214 |
// the line in the cases where HIThemeGetTrackPartBounds returns a rect that doesn't. |
|
5215 |
if (slider->orientation == Qt::Horizontal) { |
|
5216 |
if (slider->direction == Qt::LeftToRight && sc == SC_ScrollBarSubLine) |
|
5217 |
ret.adjust(0, 0, 1, 0); |
|
5218 |
else if (slider->direction == Qt::RightToLeft && sc == SC_ScrollBarAddLine) |
|
5219 |
ret.adjust(-1, 0, 1, 0); |
|
5220 |
} else if (sc == SC_ScrollBarAddLine) { |
|
5221 |
ret.adjust(0, -1, 0, 1); |
|
5222 |
} |
|
5223 |
} |
|
5224 |
break; |
|
5225 |
case CC_TitleBar: |
|
5226 |
if (const QStyleOptionTitleBar *titlebar |
|
5227 |
= qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) { |
|
5228 |
HIThemeWindowDrawInfo wdi; |
|
5229 |
memset(&wdi, 0, sizeof(wdi)); |
|
5230 |
wdi.version = qt_mac_hitheme_version; |
|
5231 |
wdi.state = kThemeStateActive; |
|
5232 |
wdi.windowType = QtWinType; |
|
5233 |
wdi.titleHeight = titlebar->rect.height(); |
|
5234 |
wdi.titleWidth = titlebar->rect.width(); |
|
5235 |
wdi.attributes = kThemeWindowHasTitleText; |
|
5236 |
if (titlebar->subControls & SC_TitleBarCloseButton) |
|
5237 |
wdi.attributes |= kThemeWindowHasCloseBox; |
|
5238 |
if (titlebar->subControls & SC_TitleBarMaxButton |
|
5239 |
| SC_TitleBarNormalButton) |
|
5240 |
wdi.attributes |= kThemeWindowHasFullZoom; |
|
5241 |
if (titlebar->subControls & SC_TitleBarMinButton) |
|
5242 |
wdi.attributes |= kThemeWindowHasCollapseBox; |
|
5243 |
WindowRegionCode wrc = kWindowGlobalPortRgn; |
|
5244 |
||
5245 |
if (sc == SC_TitleBarCloseButton) |
|
5246 |
wrc = kWindowCloseBoxRgn; |
|
5247 |
else if (sc == SC_TitleBarMinButton) |
|
5248 |
wrc = kWindowCollapseBoxRgn; |
|
5249 |
else if (sc == SC_TitleBarMaxButton) |
|
5250 |
wrc = kWindowZoomBoxRgn; |
|
5251 |
else if (sc == SC_TitleBarLabel) |
|
5252 |
wrc = kWindowTitleTextRgn; |
|
5253 |
else if (sc == SC_TitleBarSysMenu) |
|
5254 |
ret.setRect(-1024, -1024, 10, proxy()->pixelMetric(PM_TitleBarHeight, |
|
5255 |
titlebar, widget)); |
|
5256 |
if (wrc != kWindowGlobalPortRgn) { |
|
5257 |
QCFType<HIShapeRef> region; |
|
5258 |
QRect tmpRect = titlebar->rect; |
|
5259 |
HIRect titleRect = qt_hirectForQRect(tmpRect); |
|
5260 |
HIThemeGetWindowShape(&titleRect, &wdi, kWindowTitleBarRgn, ®ion); |
|
5261 |
ptrHIShapeGetBounds(region, &titleRect); |
|
5262 |
CFRelease(region); |
|
5263 |
tmpRect.translate(tmpRect.x() - int(titleRect.origin.x), |
|
5264 |
tmpRect.y() - int(titleRect.origin.y)); |
|
5265 |
titleRect = qt_hirectForQRect(tmpRect); |
|
5266 |
HIThemeGetWindowShape(&titleRect, &wdi, wrc, ®ion); |
|
5267 |
ptrHIShapeGetBounds(region, &titleRect); |
|
5268 |
ret = qt_qrectForHIRect(titleRect); |
|
5269 |
} |
|
5270 |
} |
|
5271 |
break; |
|
5272 |
case CC_ComboBox: |
|
5273 |
if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { |
|
5274 |
HIThemeButtonDrawInfo bdi; |
|
5275 |
d->initComboboxBdi(combo, &bdi, widget, d->getDrawState(opt->state)); |
|
5276 |
||
5277 |
switch (sc) { |
|
5278 |
case SC_ComboBoxEditField:{ |
|
5279 |
ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); |
|
5280 |
// hack to posistion the edit feld correctly for QDateTimeEdits |
|
5281 |
// in calendarPopup mode. |
|
5282 |
if (qobject_cast<const QDateTimeEdit *>(widget)) { |
|
5283 |
ret.moveTop(ret.top() - 2); |
|
5284 |
ret.setHeight(ret.height() +1); |
|
5285 |
} |
|
5286 |
break; } |
|
5287 |
case SC_ComboBoxArrow:{ |
|
5288 |
ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); |
|
5289 |
ret.setX(ret.x() + ret.width()); |
|
5290 |
ret.setWidth(combo->rect.right() - ret.right()); |
|
5291 |
break; } |
|
5292 |
case SC_ComboBoxListBoxPopup:{ |
|
5293 |
if (combo->editable) { |
|
5294 |
HIRect inner = QMacStylePrivate::comboboxInnerBounds(qt_hirectForQRect(combo->rect), bdi.kind); |
|
5295 |
QRect editRect = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); |
|
5296 |
const int comboTop = combo->rect.top(); |
|
5297 |
ret = QRect(qRound(inner.origin.x), |
|
5298 |
comboTop, |
|
5299 |
qRound(inner.origin.x - combo->rect.left() + inner.size.width), |
|
5300 |
editRect.bottom() - comboTop + 2); |
|
5301 |
} else { |
|
5302 |
QRect editRect = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi); |
|
5303 |
ret = QRect(combo->rect.x() + 4 - 11, |
|
5304 |
combo->rect.y() + 1, |
|
5305 |
editRect.width() + 10 + 11, |
|
5306 |
1); |
|
5307 |
} |
|
5308 |
break; } |
|
5309 |
default: |
|
5310 |
break; |
|
5311 |
} |
|
5312 |
} |
|
5313 |
break; |
|
5314 |
case CC_GroupBox: |
|
5315 |
if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) { |
|
5316 |
bool checkable = groupBox->subControls & SC_GroupBoxCheckBox; |
|
5317 |
bool flat = (groupBox->features & QStyleOptionFrameV2::Flat); |
|
5318 |
bool hasNoText = !checkable && groupBox->text.isEmpty(); |
|
5319 |
switch (sc) { |
|
5320 |
case SC_GroupBoxLabel: |
|
5321 |
case SC_GroupBoxCheckBox: { |
|
5322 |
// Cheat and use the smaller font if we need to |
|
5323 |
bool checkable = groupBox->subControls & SC_GroupBoxCheckBox; |
|
5324 |
bool fontIsSet = (widget && widget->testAttribute(Qt::WA_SetFont) |
|
5325 |
|| !QApplication::desktopSettingsAware()); |
|
5326 |
int tw; |
|
5327 |
int h; |
|
5328 |
int margin = flat || hasNoText ? 0 : 12; |
|
5329 |
ret = groupBox->rect.adjusted(margin, 0, -margin, 0); |
|
5330 |
||
5331 |
if (!fontIsSet) { |
|
5332 |
HIThemeTextInfo tti; |
|
5333 |
tti.version = qt_mac_hitheme_version; |
|
5334 |
tti.state = kThemeStateActive; |
|
5335 |
tti.fontID = checkable ? kThemeSystemFont : kThemeSmallSystemFont; |
|
5336 |
tti.horizontalFlushness = kHIThemeTextHorizontalFlushCenter; |
|
5337 |
tti.verticalFlushness = kHIThemeTextVerticalFlushCenter; |
|
5338 |
tti.options = kHIThemeTextBoxOptionNone; |
|
5339 |
tti.truncationPosition = kHIThemeTextTruncationNone; |
|
5340 |
tti.truncationMaxLines = 1 + groupBox->text.count(QLatin1Char('\n')); |
|
5341 |
CGFloat width; |
|
5342 |
CGFloat height; |
|
5343 |
QCFString groupText = qt_mac_removeMnemonics(groupBox->text); |
|
5344 |
HIThemeGetTextDimensions(groupText, 0, &tti, &width, &height, 0); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
5345 |
tw = qRound(width); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
5346 |
h = qCeil(height); |
0 | 5347 |
} else { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
5348 |
QFontMetricsF fm = QFontMetricsF(groupBox->fontMetrics); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
5349 |
h = qCeil(fm.height()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
5350 |
tw = qCeil(fm.size(Qt::TextShowMnemonic, groupBox->text).width()); |
0 | 5351 |
} |
5352 |
ret.setHeight(h); |
|
5353 |
||
5354 |
QRect labelRect = alignedRect(groupBox->direction, groupBox->textAlignment, |
|
5355 |
QSize(tw, h), ret); |
|
5356 |
int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget); |
|
5357 |
bool rtl = groupBox->direction == Qt::RightToLeft; |
|
5358 |
if (sc == SC_GroupBoxLabel) { |
|
5359 |
if (checkable) { |
|
5360 |
int newSum = indicatorWidth + 1; |
|
5361 |
int newLeft = labelRect.left() + (rtl ? -newSum : newSum); |
|
5362 |
labelRect.moveLeft(newLeft); |
|
5363 |
} else if (flat) { |
|
5364 |
int newLeft = labelRect.left() - (rtl ? 3 : -3); |
|
5365 |
labelRect.moveLeft(newLeft); |
|
5366 |
labelRect.moveTop(labelRect.top() + 3); |
|
5367 |
} else { |
|
5368 |
int newLeft = labelRect.left() - (rtl ? 3 : 2); |
|
5369 |
labelRect.moveLeft(newLeft); |
|
5370 |
labelRect.moveTop(labelRect.top() + 5); |
|
5371 |
} |
|
5372 |
ret = labelRect; |
|
5373 |
} |
|
5374 |
||
5375 |
if (sc == SC_GroupBoxCheckBox) { |
|
5376 |
int left = rtl ? labelRect.right() - indicatorWidth : labelRect.left(); |
|
5377 |
ret.setRect(left, ret.top(), |
|
5378 |
indicatorWidth, proxy()->pixelMetric(PM_IndicatorHeight, opt, widget)); |
|
5379 |
} |
|
5380 |
break; |
|
5381 |
} |
|
5382 |
case SC_GroupBoxContents: |
|
5383 |
case SC_GroupBoxFrame: { |
|
5384 |
if (flat) { |
|
5385 |
ret = QWindowsStyle::subControlRect(cc, groupBox, sc, widget); |
|
5386 |
break; |
|
5387 |
} |
|
5388 |
QFontMetrics fm = groupBox->fontMetrics; |
|
5389 |
bool checkable = groupBox->subControls & SC_GroupBoxCheckBox; |
|
5390 |
int yOffset = 3; |
|
5391 |
if (!checkable) { |
|
5392 |
if (widget && !widget->testAttribute(Qt::WA_SetFont) |
|
5393 |
&& QApplication::desktopSettingsAware()) |
|
5394 |
fm = QFontMetrics(qt_app_fonts_hash()->value("QSmallFont", QFont())); |
|
5395 |
yOffset = 5; |
|
5396 |
if (hasNoText) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
5397 |
yOffset = -qCeil(QFontMetricsF(fm).height()); |
0 | 5398 |
} |
5399 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
5400 |
ret = opt->rect.adjusted(0, qCeil(QFontMetricsF(fm).height()) + yOffset, 0, 0); |
0 | 5401 |
if (sc == SC_GroupBoxContents) |
5402 |
ret.adjust(3, 3, -3, -4); // guess |
|
5403 |
} |
|
5404 |
break; |
|
5405 |
default: |
|
5406 |
ret = QWindowsStyle::subControlRect(cc, groupBox, sc, widget); |
|
5407 |
break; |
|
5408 |
} |
|
5409 |
} |
|
5410 |
break; |
|
5411 |
case CC_SpinBox: |
|
5412 |
if (const QStyleOptionSpinBox *spin = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { |
|
5413 |
QAquaWidgetSize aquaSize = d->aquaSizeConstrain(spin, widget); |
|
5414 |
int spinner_w; |
|
5415 |
int spinBoxSep; |
|
5416 |
int fw = proxy()->pixelMetric(PM_SpinBoxFrameWidth, spin, widget); |
|
5417 |
switch (aquaSize) { |
|
5418 |
default: |
|
5419 |
case QAquaSizeUnknown: |
|
5420 |
case QAquaSizeLarge: |
|
5421 |
spinner_w = 14; |
|
5422 |
spinBoxSep = 2; |
|
5423 |
break; |
|
5424 |
case QAquaSizeSmall: |
|
5425 |
spinner_w = 12; |
|
5426 |
spinBoxSep = 2; |
|
5427 |
break; |
|
5428 |
case QAquaSizeMini: |
|
5429 |
spinner_w = 10; |
|
5430 |
spinBoxSep = 1; |
|
5431 |
break; |
|
5432 |
} |
|
5433 |
||
5434 |
switch (sc) { |
|
5435 |
case SC_SpinBoxUp: |
|
5436 |
case SC_SpinBoxDown: { |
|
5437 |
if (spin->buttonSymbols == QAbstractSpinBox::NoButtons) |
|
5438 |
break; |
|
5439 |
||
5440 |
const int y = fw; |
|
5441 |
const int x = spin->rect.width() - spinner_w; |
|
5442 |
ret.setRect(x + spin->rect.x(), y + spin->rect.y(), spinner_w, spin->rect.height() - y * 2); |
|
5443 |
HIThemeButtonDrawInfo bdi; |
|
5444 |
bdi.version = qt_mac_hitheme_version; |
|
5445 |
bdi.kind = kThemeIncDecButton; |
|
5446 |
int hackTranslateX; |
|
5447 |
switch (aquaSize) { |
|
5448 |
default: |
|
5449 |
case QAquaSizeUnknown: |
|
5450 |
case QAquaSizeLarge: |
|
5451 |
bdi.kind = kThemeIncDecButton; |
|
5452 |
hackTranslateX = 0; |
|
5453 |
break; |
|
5454 |
case QAquaSizeSmall: |
|
5455 |
bdi.kind = kThemeIncDecButtonSmall; |
|
5456 |
hackTranslateX = -2; |
|
5457 |
break; |
|
5458 |
case QAquaSizeMini: |
|
5459 |
bdi.kind = kThemeIncDecButtonMini; |
|
5460 |
hackTranslateX = -1; |
|
5461 |
break; |
|
5462 |
} |
|
5463 |
bdi.state = kThemeStateActive; |
|
5464 |
bdi.value = kThemeButtonOff; |
|
5465 |
bdi.adornment = kThemeAdornmentNone; |
|
5466 |
HIRect hirect = qt_hirectForQRect(ret); |
|
5467 |
||
5468 |
HIRect outRect; |
|
5469 |
HIThemeGetButtonBackgroundBounds(&hirect, &bdi, &outRect); |
|
5470 |
ret = qt_qrectForHIRect(outRect); |
|
5471 |
switch (sc) { |
|
5472 |
case SC_SpinBoxUp: |
|
5473 |
ret.setHeight(ret.height() / 2); |
|
5474 |
break; |
|
5475 |
case SC_SpinBoxDown: |
|
5476 |
ret.setY(ret.y() + ret.height() / 2); |
|
5477 |
break; |
|
5478 |
default: |
|
5479 |
Q_ASSERT(0); |
|
5480 |
break; |
|
5481 |
} |
|
5482 |
ret.translate(hackTranslateX, 0); // hack: position the buttons correctly (weird that we need this) |
|
5483 |
ret = visualRect(spin->direction, spin->rect, ret); |
|
5484 |
break; |
|
5485 |
} |
|
5486 |
case SC_SpinBoxEditField: |
|
5487 |
if (spin->buttonSymbols == QAbstractSpinBox::NoButtons) { |
|
5488 |
ret.setRect(fw, fw, |
|
5489 |
spin->rect.width() - fw * 2, |
|
5490 |
spin->rect.height() - fw * 2); |
|
5491 |
} else { |
|
5492 |
ret.setRect(fw, fw, |
|
5493 |
spin->rect.width() - fw * 2 - spinBoxSep - spinner_w, |
|
5494 |
spin->rect.height() - fw * 2); |
|
5495 |
} |
|
5496 |
ret = visualRect(spin->direction, spin->rect, ret); |
|
5497 |
break; |
|
5498 |
default: |
|
5499 |
ret = QWindowsStyle::subControlRect(cc, spin, sc, widget); |
|
5500 |
break; |
|
5501 |
} |
|
5502 |
} |
|
5503 |
break; |
|
5504 |
case CC_ToolButton: |
|
5505 |
ret = QWindowsStyle::subControlRect(cc, opt, sc, widget); |
|
5506 |
if (sc == SC_ToolButtonMenu && widget && !qobject_cast<QToolBar*>(widget->parentWidget())) { |
|
5507 |
ret.adjust(-1, 0, 0, 0); |
|
5508 |
} |
|
5509 |
break; |
|
5510 |
default: |
|
5511 |
ret = QWindowsStyle::subControlRect(cc, opt, sc, widget); |
|
5512 |
break; |
|
5513 |
} |
|
5514 |
return ret; |
|
5515 |
} |
|
5516 |
||
5517 |
QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, |
|
5518 |
const QSize &csz, const QWidget *widget) const |
|
5519 |
{ |
|
5520 |
QSize sz(csz); |
|
5521 |
bool useAquaGuideline = true; |
|
5522 |
||
5523 |
switch (ct) { |
|
5524 |
case QStyle::CT_SpinBox: |
|
5525 |
// hack to work around horrible sizeHint() code in QAbstractSpinBox |
|
5526 |
sz.setHeight(sz.height() - 3); |
|
5527 |
break; |
|
5528 |
case QStyle::CT_TabBarTab: |
|
5529 |
if (const QStyleOptionTabV3 *tab = qstyleoption_cast<const QStyleOptionTabV3 *>(opt)) { |
|
5530 |
const QAquaWidgetSize AquaSize = d->aquaSizeConstrain(opt, widget); |
|
5531 |
const bool differentFont = (widget && widget->testAttribute(Qt::WA_SetFont)) |
|
5532 |
|| !QApplication::desktopSettingsAware(); |
|
5533 |
ThemeTabDirection ttd = getTabDirection(tab->shape); |
|
5534 |
bool vertTabs = ttd == kThemeTabWest || ttd == kThemeTabEast; |
|
5535 |
if (vertTabs) |
|
5536 |
sz.transpose(); |
|
5537 |
int defaultTabHeight; |
|
5538 |
int defaultExtraSpace = proxy()->pixelMetric(PM_TabBarTabHSpace, tab, widget); // Remove spurious gcc warning (AFAIK) |
|
5539 |
QFontMetrics fm = opt->fontMetrics; |
|
5540 |
switch (AquaSize) { |
|
5541 |
case QAquaSizeUnknown: |
|
5542 |
case QAquaSizeLarge: |
|
5543 |
if (tab->documentMode) |
|
5544 |
defaultTabHeight = 23; |
|
5545 |
else |
|
5546 |
defaultTabHeight = 21; |
|
5547 |
break; |
|
5548 |
case QAquaSizeSmall: |
|
5549 |
defaultTabHeight = 18; |
|
5550 |
break; |
|
5551 |
case QAquaSizeMini: |
|
5552 |
defaultTabHeight = 16; |
|
5553 |
break; |
|
5554 |
} |
|
5555 |
bool setWidth = false; |
|
5556 |
if (differentFont || !tab->icon.isNull()) { |
|
5557 |
sz.rheight() = qMax(defaultTabHeight, sz.height()); |
|
5558 |
} else { |
|
5559 |
QSize textSize = fm.size(Qt::TextShowMnemonic, tab->text); |
|
5560 |
sz.rheight() = qMax(defaultTabHeight, textSize.height()); |
|
5561 |
sz.rwidth() = textSize.width() + defaultExtraSpace; |
|
5562 |
setWidth = true; |
|
5563 |
} |
|
5564 |
||
5565 |
if (vertTabs) |
|
5566 |
sz.transpose(); |
|
5567 |
||
5568 |
int maxWidgetHeight = qMax(tab->leftButtonSize.height(), tab->rightButtonSize.height()); |
|
5569 |
int maxWidgetWidth = qMax(tab->leftButtonSize.width(), tab->rightButtonSize.width()); |
|
5570 |
||
5571 |
int widgetWidth = 0; |
|
5572 |
int widgetHeight = 0; |
|
5573 |
int padding = 0; |
|
5574 |
if (tab->leftButtonSize.isValid()) { |
|
5575 |
padding += 8; |
|
5576 |
widgetWidth += tab->leftButtonSize.width(); |
|
5577 |
widgetHeight += tab->leftButtonSize.height(); |
|
5578 |
} |
|
5579 |
if (tab->rightButtonSize.isValid()) { |
|
5580 |
padding += 8; |
|
5581 |
widgetWidth += tab->rightButtonSize.width(); |
|
5582 |
widgetHeight += tab->rightButtonSize.height(); |
|
5583 |
} |
|
5584 |
||
5585 |
if (vertTabs) { |
|
5586 |
sz.setHeight(sz.height() + widgetHeight + padding); |
|
5587 |
sz.setWidth(qMax(sz.width(), maxWidgetWidth)); |
|
5588 |
} else { |
|
5589 |
if (setWidth) |
|
5590 |
sz.setWidth(sz.width() + widgetWidth + padding); |
|
5591 |
sz.setHeight(qMax(sz.height(), maxWidgetHeight)); |
|
5592 |
} |
|
5593 |
} |
|
5594 |
break; |
|
5595 |
case QStyle::CT_PushButton: |
|
5596 |
// By default, we fit the contents inside a normal rounded push button. |
|
5597 |
// Do this by add enough space around the contents so that rounded |
|
5598 |
// borders (including highlighting when active) will show. |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5599 |
sz.rwidth() += QMacStylePrivate::PushButtonLeftOffset + QMacStylePrivate::PushButtonRightOffset + 12; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5600 |
sz.rheight() += QMacStylePrivate::PushButtonTopOffset + QMacStylePrivate::PushButtonBottomOffset; |
0 | 5601 |
break; |
5602 |
case QStyle::CT_MenuItem: |
|
5603 |
if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { |
|
5604 |
int maxpmw = mi->maxIconWidth; |
|
5605 |
const QComboBox *comboBox = qobject_cast<const QComboBox *>(widget); |
|
5606 |
int w = sz.width(), |
|
5607 |
h = sz.height(); |
|
5608 |
if (mi->menuItemType == QStyleOptionMenuItem::Separator) { |
|
5609 |
w = 10; |
|
5610 |
SInt16 ash; |
|
5611 |
GetThemeMenuSeparatorHeight(&ash); |
|
5612 |
h = ash; |
|
5613 |
} else { |
|
5614 |
h = mi->fontMetrics.height() + 2; |
|
5615 |
if (!mi->icon.isNull()) { |
|
5616 |
if (comboBox) { |
|
5617 |
const QSize &iconSize = comboBox->iconSize(); |
|
5618 |
h = qMax(h, iconSize.height() + 4); |
|
5619 |
maxpmw = qMax(maxpmw, iconSize.width()); |
|
5620 |
} else { |
|
5621 |
int iconExtent = proxy()->pixelMetric(PM_SmallIconSize); |
|
5622 |
h = qMax(h, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4); |
|
5623 |
} |
|
5624 |
} |
|
5625 |
} |
|
5626 |
if (mi->text.contains(QLatin1Char('\t'))) |
|
5627 |
w += 12; |
|
5628 |
if (mi->menuItemType == QStyleOptionMenuItem::SubMenu) |
|
5629 |
w += 20; |
|
5630 |
if (maxpmw) |
|
5631 |
w += maxpmw + 6; |
|
5632 |
// add space for a check. All items have place for a check too. |
|
5633 |
w += 20; |
|
5634 |
if (comboBox && comboBox->isVisible()) { |
|
5635 |
QStyleOptionComboBox cmb; |
|
5636 |
cmb.initFrom(comboBox); |
|
5637 |
cmb.editable = false; |
|
5638 |
cmb.subControls = QStyle::SC_ComboBoxEditField; |
|
5639 |
cmb.activeSubControls = QStyle::SC_None; |
|
5640 |
w = qMax(w, subControlRect(QStyle::CC_ComboBox, &cmb, |
|
5641 |
QStyle::SC_ComboBoxEditField, |
|
5642 |
comboBox).width()); |
|
5643 |
} else { |
|
5644 |
w += 12; |
|
5645 |
} |
|
5646 |
sz = QSize(w, h); |
|
5647 |
} |
|
5648 |
break; |
|
5649 |
case CT_ToolButton: |
|
5650 |
if (widget && qobject_cast<const QToolBar *>(widget->parentWidget())) { |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5651 |
if (QMainWindow * mainWindow = qobject_cast<QMainWindow *>(widget->parent())) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5652 |
if (mainWindow->unifiedTitleAndToolBarOnMac()) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5653 |
sz.rwidth() += 4; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5654 |
if (sz.height() <= 32) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5655 |
// Workaround strange HIToolBar bug when getting constraints. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5656 |
sz.rheight() += 1; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5657 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5658 |
return sz; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
5659 |
} |
0 | 5660 |
} |
5661 |
} |
|
5662 |
sz.rwidth() += 10; |
|
5663 |
sz.rheight() += 10; |
|
5664 |
return sz; |
|
5665 |
case CT_ComboBox: |
|
5666 |
sz.rwidth() += 50; |
|
5667 |
break; |
|
5668 |
case CT_Menu: { |
|
5669 |
QStyleHintReturnMask menuMask; |
|
5670 |
QStyleOption myOption = *opt; |
|
5671 |
myOption.rect.setSize(sz); |
|
5672 |
if (proxy()->styleHint(SH_Menu_Mask, &myOption, widget, &menuMask)) { |
|
5673 |
sz = menuMask.region.boundingRect().size(); |
|
5674 |
} |
|
5675 |
break; } |
|
5676 |
case CT_HeaderSection:{ |
|
5677 |
const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt); |
|
5678 |
sz = QWindowsStyle::sizeFromContents(ct, opt, csz, widget); |
|
5679 |
if (header->text.contains(QLatin1Char('\n'))) |
|
5680 |
useAquaGuideline = false; |
|
5681 |
break; } |
|
5682 |
case CT_ScrollBar : |
|
5683 |
// Make sure that the scroll bar is large enough to display the thumb indicator. |
|
5684 |
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { |
|
5685 |
const int minimumSize = scrollButtonsCutoffSize(thumbIndicatorCutoff, widgetSizePolicy(widget)); |
|
5686 |
if (slider->orientation == Qt::Horizontal) |
|
5687 |
sz = sz.expandedTo(QSize(minimumSize, sz.height())); |
|
5688 |
else |
|
5689 |
sz = sz.expandedTo(QSize(sz.width(), minimumSize)); |
|
5690 |
} |
|
5691 |
break; |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5692 |
case CT_ItemViewItem: |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5693 |
if (const QStyleOptionViewItemV4 *vopt = qstyleoption_cast<const QStyleOptionViewItemV4 *>(opt)) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5694 |
sz = QCommonStyle::sizeFromContents(ct, vopt, csz, widget); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5695 |
sz.setHeight(sz.height() + 2); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5696 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5697 |
break; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
5698 |
|
0 | 5699 |
default: |
5700 |
sz = QWindowsStyle::sizeFromContents(ct, opt, csz, widget); |
|
5701 |
} |
|
5702 |
||
5703 |
if (useAquaGuideline){ |
|
5704 |
QSize macsz; |
|
5705 |
if (d->aquaSizeConstrain(opt, widget, ct, sz, &macsz) != QAquaSizeUnknown) { |
|
5706 |
if (macsz.width() != -1) |
|
5707 |
sz.setWidth(macsz.width()); |
|
5708 |
if (macsz.height() != -1) |
|
5709 |
sz.setHeight(macsz.height()); |
|
5710 |
} |
|
5711 |
} |
|
5712 |
||
5713 |
// The sizes that Carbon and the guidelines gives us excludes the focus frame. |
|
5714 |
// We compensate for this by adding some extra space here to make room for the frame when drawing: |
|
5715 |
if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)){ |
|
5716 |
QAquaWidgetSize widgetSize = d->aquaSizeConstrain(opt, widget); |
|
5717 |
int bkind = 0; |
|
5718 |
switch (widgetSize) { |
|
5719 |
default: |
|
5720 |
case QAquaSizeLarge: |
|
5721 |
bkind = combo->editable ? kThemeComboBox : kThemePopupButton; |
|
5722 |
break; |
|
5723 |
case QAquaSizeSmall: |
|
5724 |
bkind = combo->editable ? int(kThemeComboBoxSmall) : int(kThemePopupButtonSmall); |
|
5725 |
break; |
|
5726 |
case QAquaSizeMini: |
|
5727 |
bkind = combo->editable ? kThemeComboBoxMini : kThemePopupButtonMini; |
|
5728 |
break; |
|
5729 |
} |
|
5730 |
HIRect tmpRect = {{0, 0}, {0, 0}}; |
|
5731 |
HIRect diffRect = QMacStylePrivate::comboboxInnerBounds(tmpRect, bkind); |
|
5732 |
sz.rwidth() -= qRound(diffRect.size.width); |
|
5733 |
sz.rheight() -= qRound(diffRect.size.height); |
|
5734 |
} else if (ct == CT_PushButton || ct == CT_ToolButton){ |
|
5735 |
ThemeButtonKind bkind; |
|
5736 |
QAquaWidgetSize widgetSize = d->aquaSizeConstrain(opt, widget); |
|
5737 |
switch (ct) { |
|
5738 |
default: |
|
5739 |
case CT_PushButton: |
|
5740 |
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { |
|
5741 |
if (btn->features & QStyleOptionButton::CommandLinkButton) { |
|
5742 |
return QWindowsStyle::sizeFromContents(ct, opt, sz, widget); |
|
5743 |
} |
|
5744 |
} |
|
5745 |
||
5746 |
switch (widgetSize) { |
|
5747 |
default: |
|
5748 |
case QAquaSizeLarge: |
|
5749 |
bkind = kThemePushButton; |
|
5750 |
break; |
|
5751 |
case QAquaSizeSmall: |
|
5752 |
bkind = kThemePushButtonSmall; |
|
5753 |
break; |
|
5754 |
case QAquaSizeMini: |
|
5755 |
bkind = kThemePushButtonMini; |
|
5756 |
break; |
|
5757 |
} |
|
5758 |
break; |
|
5759 |
case CT_ToolButton: |
|
5760 |
switch (widgetSize) { |
|
5761 |
default: |
|
5762 |
case QAquaSizeLarge: |
|
5763 |
bkind = kThemeLargeBevelButton; |
|
5764 |
break; |
|
5765 |
case QAquaSizeMini: |
|
5766 |
case QAquaSizeSmall: |
|
5767 |
bkind = kThemeSmallBevelButton; |
|
5768 |
} |
|
5769 |
break; |
|
5770 |
} |
|
5771 |
||
5772 |
HIThemeButtonDrawInfo bdi; |
|
5773 |
bdi.version = qt_mac_hitheme_version; |
|
5774 |
bdi.state = kThemeStateActive; |
|
5775 |
bdi.kind = bkind; |
|
5776 |
bdi.value = kThemeButtonOff; |
|
5777 |
bdi.adornment = kThemeAdornmentNone; |
|
5778 |
HIRect macRect, myRect; |
|
5779 |
myRect = CGRectMake(0, 0, sz.width(), sz.height()); |
|
5780 |
HIThemeGetButtonBackgroundBounds(&myRect, &bdi, &macRect); |
|
5781 |
// Mini buttons only return their actual size in HIThemeGetButtonBackgroundBounds, so help them out a bit (guess), |
|
5782 |
if (bkind == kThemePushButtonMini) |
|
5783 |
macRect.size.height += 8.; |
|
5784 |
else if (bkind == kThemePushButtonSmall) |
|
5785 |
macRect.size.height -= 10; |
|
5786 |
sz.setWidth(sz.width() + int(macRect.size.width - myRect.size.width)); |
|
5787 |
sz.setHeight(sz.height() + int(macRect.size.height - myRect.size.height)); |
|
5788 |
} |
|
5789 |
return sz; |
|
5790 |
} |
|
5791 |
||
5792 |
void QMacStyle::drawItemText(QPainter *p, const QRect &r, int flags, const QPalette &pal, |
|
5793 |
bool enabled, const QString &text, QPalette::ColorRole textRole) const |
|
5794 |
{ |
|
5795 |
if(flags & Qt::TextShowMnemonic) |
|
5796 |
flags |= Qt::TextHideMnemonic; |
|
5797 |
QWindowsStyle::drawItemText(p, r, flags, pal, enabled, text, textRole); |
|
5798 |
} |
|
5799 |
||
5800 |
bool QMacStyle::event(QEvent *e) |
|
5801 |
{ |
|
5802 |
if(e->type() == QEvent::FocusIn) { |
|
5803 |
QWidget *f = 0; |
|
5804 |
QWidget *focusWidget = QApplication::focusWidget(); |
|
5805 |
#ifndef QT_NO_GRAPHICSVIEW |
|
5806 |
if (QGraphicsView *graphicsView = qobject_cast<QGraphicsView *>(focusWidget)) { |
|
5807 |
QGraphicsItem *focusItem = graphicsView->scene() ? graphicsView->scene()->focusItem() : 0; |
|
5808 |
if (focusItem && focusItem->type() == QGraphicsProxyWidget::Type) { |
|
5809 |
QGraphicsProxyWidget *proxy = static_cast<QGraphicsProxyWidget *>(focusItem); |
|
5810 |
if (proxy->widget()) |
|
5811 |
focusWidget = proxy->widget()->focusWidget(); |
|
5812 |
} |
|
5813 |
} |
|
5814 |
#endif |
|
5815 |
if (focusWidget && focusWidget->testAttribute(Qt::WA_MacShowFocusRect)) { |
|
5816 |
f = focusWidget; |
|
5817 |
QWidget *top = f->parentWidget(); |
|
5818 |
while (top && !top->isWindow() && !(top->windowType() == Qt::SubWindow)) |
|
5819 |
top = top->parentWidget(); |
|
5820 |
#ifndef QT_NO_MAINWINDOW |
|
5821 |
if (qobject_cast<QMainWindow *>(top)) { |
|
5822 |
QWidget *central = static_cast<QMainWindow *>(top)->centralWidget(); |
|
5823 |
for (const QWidget *par = f; par; par = par->parentWidget()) { |
|
5824 |
if (par == central) { |
|
5825 |
top = central; |
|
5826 |
break; |
|
5827 |
} |
|
5828 |
if (par->isWindow()) |
|
5829 |
break; |
|
5830 |
} |
|
5831 |
} |
|
5832 |
#endif |
|
5833 |
} |
|
5834 |
if (f) { |
|
5835 |
if(!d->focusWidget) |
|
5836 |
d->focusWidget = new QFocusFrame(f); |
|
5837 |
d->focusWidget->setWidget(f); |
|
5838 |
} else if(d->focusWidget) { |
|
5839 |
d->focusWidget->setWidget(0); |
|
5840 |
} |
|
5841 |
} else if(e->type() == QEvent::FocusOut) { |
|
5842 |
if(d->focusWidget) |
|
5843 |
d->focusWidget->setWidget(0); |
|
5844 |
} |
|
5845 |
return false; |
|
5846 |
} |
|
5847 |
||
5848 |
QIcon QMacStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt, |
|
5849 |
const QWidget *widget) const |
|
5850 |
{ |
|
5851 |
switch (standardIcon) { |
|
5852 |
default: |
|
5853 |
return QWindowsStyle::standardIconImplementation(standardIcon, opt, widget); |
|
5854 |
case SP_ToolBarHorizontalExtensionButton: |
|
5855 |
case SP_ToolBarVerticalExtensionButton: { |
|
5856 |
QPixmap pixmap(qt_mac_toolbar_ext); |
|
5857 |
if (standardIcon == SP_ToolBarVerticalExtensionButton) { |
|
5858 |
QPixmap pix2(pixmap.height(), pixmap.width()); |
|
5859 |
pix2.fill(Qt::transparent); |
|
5860 |
QPainter p(&pix2); |
|
5861 |
p.translate(pix2.width(), 0); |
|
5862 |
p.rotate(90); |
|
5863 |
p.drawPixmap(0, 0, pixmap); |
|
5864 |
return pix2; |
|
5865 |
} |
|
5866 |
return pixmap; |
|
5867 |
} |
|
5868 |
} |
|
5869 |
} |
|
5870 |
||
5871 |
int QMacStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1, |
|
5872 |
QSizePolicy::ControlType control2, |
|
5873 |
Qt::Orientation orientation, |
|
5874 |
const QStyleOption *option, |
|
5875 |
const QWidget *widget) const |
|
5876 |
{ |
|
5877 |
const int ButtonMask = QSizePolicy::ButtonBox | QSizePolicy::PushButton; |
|
5878 |
bool isMetal = (widget && widget->testAttribute(Qt::WA_MacBrushedMetal)); |
|
5879 |
int controlSize = getControlSize(option, widget); |
|
5880 |
||
5881 |
if (control2 == QSizePolicy::ButtonBox) { |
|
5882 |
/* |
|
5883 |
AHIG seems to prefer a 12-pixel margin between group |
|
5884 |
boxes and the row of buttons. The 20 pixel comes from |
|
5885 |
Builder. |
|
5886 |
*/ |
|
5887 |
if (isMetal // (AHIG, guess, guess) |
|
5888 |
|| (control1 & (QSizePolicy::Frame // guess |
|
5889 |
| QSizePolicy::GroupBox // (AHIG, guess, guess) |
|
5890 |
| QSizePolicy::TabWidget // guess |
|
5891 |
| ButtonMask))) { // AHIG |
|
5892 |
return_SIZE(14, 8, 8); |
|
5893 |
} else if (control1 == QSizePolicy::LineEdit) { |
|
5894 |
return_SIZE(8, 8, 8); // Interface Builder |
|
5895 |
} else { |
|
5896 |
return_SIZE(20, 7, 7); // Interface Builder |
|
5897 |
} |
|
5898 |
} |
|
5899 |
||
5900 |
if ((control1 | control2) & ButtonMask) { |
|
5901 |
if (control1 == QSizePolicy::LineEdit) |
|
5902 |
return_SIZE(8, 8, 8); // Interface Builder |
|
5903 |
else if (control2 == QSizePolicy::LineEdit) { |
|
5904 |
if (orientation == Qt::Vertical) |
|
5905 |
return_SIZE(20, 7, 7); // Interface Builder |
|
5906 |
else |
|
5907 |
return_SIZE(20, 8, 8); |
|
5908 |
} |
|
5909 |
return_SIZE(14, 8, 8); // Interface Builder |
|
5910 |
} |
|
5911 |
||
5912 |
switch (CT2(control1, control2)) { |
|
5913 |
case CT1(QSizePolicy::Label): // guess |
|
5914 |
case CT2(QSizePolicy::Label, QSizePolicy::DefaultType): // guess |
|
5915 |
case CT2(QSizePolicy::Label, QSizePolicy::CheckBox): // AHIG |
|
5916 |
case CT2(QSizePolicy::Label, QSizePolicy::ComboBox): // AHIG |
|
5917 |
case CT2(QSizePolicy::Label, QSizePolicy::LineEdit): // guess |
|
5918 |
case CT2(QSizePolicy::Label, QSizePolicy::RadioButton): // AHIG |
|
5919 |
case CT2(QSizePolicy::Label, QSizePolicy::Slider): // guess |
|
5920 |
case CT2(QSizePolicy::Label, QSizePolicy::SpinBox): // guess |
|
5921 |
case CT2(QSizePolicy::Label, QSizePolicy::ToolButton): // guess |
|
5922 |
return_SIZE(8, 6, 5); |
|
5923 |
case CT1(QSizePolicy::ToolButton): |
|
5924 |
return 8; // AHIG |
|
5925 |
case CT1(QSizePolicy::CheckBox): |
|
5926 |
case CT2(QSizePolicy::CheckBox, QSizePolicy::RadioButton): |
|
5927 |
case CT2(QSizePolicy::RadioButton, QSizePolicy::CheckBox): |
|
5928 |
if (orientation == Qt::Vertical) |
|
5929 |
return_SIZE(8, 8, 7); // AHIG and Builder |
|
5930 |
break; |
|
5931 |
case CT1(QSizePolicy::RadioButton): |
|
5932 |
if (orientation == Qt::Vertical) |
|
5933 |
return 5; // (Builder, guess, AHIG) |
|
5934 |
} |
|
5935 |
||
5936 |
if (orientation == Qt::Horizontal |
|
5937 |
&& (control2 & (QSizePolicy::CheckBox | QSizePolicy::RadioButton))) |
|
5938 |
return_SIZE(12, 10, 8); // guess |
|
5939 |
||
5940 |
if ((control1 | control2) & (QSizePolicy::Frame |
|
5941 |
| QSizePolicy::GroupBox |
|
5942 |
| QSizePolicy::TabWidget)) { |
|
5943 |
/* |
|
5944 |
These values were chosen so that nested container widgets |
|
5945 |
look good side by side. Builder uses 8, which looks way |
|
5946 |
too small, and AHIG doesn't say anything. |
|
5947 |
*/ |
|
5948 |
return_SIZE(16, 10, 10); // guess |
|
5949 |
} |
|
5950 |
||
5951 |
if ((control1 | control2) & (QSizePolicy::Line | QSizePolicy::Slider)) |
|
5952 |
return_SIZE(12, 10, 8); // AHIG |
|
5953 |
||
5954 |
if ((control1 | control2) & QSizePolicy::LineEdit) |
|
5955 |
return_SIZE(10, 8, 8); // AHIG |
|
5956 |
||
5957 |
/* |
|
5958 |
AHIG and Builder differ by up to 4 pixels for stacked editable |
|
5959 |
comboboxes. We use some values that work fairly well in all |
|
5960 |
cases. |
|
5961 |
*/ |
|
5962 |
if ((control1 | control2) & QSizePolicy::ComboBox) |
|
5963 |
return_SIZE(10, 8, 7); // guess |
|
5964 |
||
5965 |
/* |
|
5966 |
Builder defaults to 8, 6, 5 in lots of cases, but most of the time the |
|
5967 |
result looks too cramped. |
|
5968 |
*/ |
|
5969 |
return_SIZE(10, 8, 6); // guess |
|
5970 |
} |
|
5971 |
||
5972 |
QT_END_NAMESPACE |