author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 |
#include <private/qt_mac_p.h> |
|
43 |
#include <private/qpixmap_mac_p.h> |
|
44 |
#include <private/qnativeimage_p.h> |
|
45 |
#include <qdebug.h> |
|
46 |
||
47 |
QT_BEGIN_NAMESPACE |
|
48 |
#ifdef QT_MAC_USE_COCOA |
|
49 |
static CTFontRef CopyCTThemeFont(ThemeFontID themeID) |
|
50 |
{ |
|
51 |
CTFontUIFontType ctID = HIThemeGetUIFontType(themeID); |
|
52 |
return CTFontCreateUIFontForLanguage(ctID, 0, 0); |
|
53 |
} |
|
54 |
#endif |
|
55 |
||
56 |
QFont qfontForThemeFont(ThemeFontID themeID) |
|
57 |
{ |
|
58 |
#ifndef QT_MAC_USE_COCOA |
|
59 |
static const ScriptCode Script = smRoman; |
|
60 |
Str255 f_name; |
|
61 |
SInt16 f_size; |
|
62 |
Style f_style; |
|
63 |
GetThemeFont(themeID, Script, f_name, &f_size, &f_style); |
|
64 |
extern QString qt_mac_from_pascal_string(const Str255); //qglobal.cpp |
|
65 |
return QFont(qt_mac_from_pascal_string(f_name), f_size, |
|
66 |
(f_style & ::bold) ? QFont::Bold : QFont::Normal, |
|
67 |
(bool)(f_style & ::italic)); |
|
68 |
#else |
|
69 |
QCFType<CTFontRef> ctfont = CopyCTThemeFont(themeID); |
|
70 |
QString familyName = QCFString(CTFontCopyFamilyName(ctfont)); |
|
71 |
QCFType<CFDictionaryRef> dict = CTFontCopyTraits(ctfont); |
|
72 |
CFNumberRef num = static_cast<CFNumberRef>(CFDictionaryGetValue(dict, kCTFontWeightTrait)); |
|
73 |
float fW; |
|
74 |
CFNumberGetValue(num, kCFNumberFloat32Type, &fW); |
|
75 |
QFont::Weight wght = fW > 0. ? QFont::Bold : QFont::Normal; |
|
76 |
num = static_cast<CFNumberRef>(CFDictionaryGetValue(dict, kCTFontSlantTrait)); |
|
77 |
CFNumberGetValue(num, kCFNumberFloatType, &fW); |
|
78 |
bool italic = (fW != 0.0); |
|
79 |
return QFont(familyName, CTFontGetSize(ctfont), wght, italic); |
|
80 |
#endif |
|
81 |
} |
|
82 |
||
83 |
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) |
|
84 |
static QColor qcolorFromCGColor(CGColorRef cgcolor) |
|
85 |
{ |
|
86 |
QColor pc; |
|
87 |
CGColorSpaceModel model = CGColorSpaceGetModel(CGColorGetColorSpace(cgcolor)); |
|
88 |
const CGFloat *components = CGColorGetComponents(cgcolor); |
|
89 |
if (model == kCGColorSpaceModelRGB) { |
|
90 |
pc.setRgbF(components[0], components[1], components[2], components[3]); |
|
91 |
} else if (model == kCGColorSpaceModelCMYK) { |
|
92 |
pc.setCmykF(components[0], components[1], components[2], components[3]); |
|
93 |
} else if (model == kCGColorSpaceModelMonochrome) { |
|
94 |
pc.setRgbF(components[0], components[0], components[0], components[1]); |
|
95 |
} else { |
|
96 |
// Colorspace we can't deal with. |
|
97 |
qWarning("Qt: qcolorFromCGColor: cannot convert from colorspace model: %d", model); |
|
98 |
Q_ASSERT(false); |
|
99 |
} |
|
100 |
return pc; |
|
101 |
} |
|
102 |
||
103 |
static inline QColor leopardBrush(ThemeBrush brush) |
|
104 |
{ |
|
105 |
QCFType<CGColorRef> cgClr = 0; |
|
106 |
HIThemeBrushCreateCGColor(brush, &cgClr); |
|
107 |
return qcolorFromCGColor(cgClr); |
|
108 |
} |
|
109 |
#endif |
|
110 |
||
111 |
QColor qcolorForTheme(ThemeBrush brush) |
|
112 |
{ |
|
113 |
#ifndef QT_MAC_USE_COCOA |
|
114 |
# if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) |
|
115 |
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { |
|
116 |
return leopardBrush(brush); |
|
117 |
} else |
|
118 |
# endif |
|
119 |
{ |
|
120 |
RGBColor rgbcolor; |
|
121 |
GetThemeBrushAsColor(brush, 32, true, &rgbcolor); |
|
122 |
return QColor(rgbcolor.red / 256, rgbcolor.green / 256, rgbcolor.blue / 256); |
|
123 |
} |
|
124 |
#else |
|
125 |
return leopardBrush(brush); |
|
126 |
#endif |
|
127 |
} |
|
128 |
||
129 |
QColor qcolorForThemeTextColor(ThemeTextColor themeColor) |
|
130 |
{ |
|
131 |
#ifdef Q_OS_MAC32 |
|
132 |
RGBColor c; |
|
133 |
GetThemeTextColor(themeColor, 32, true, &c); |
|
134 |
QColor color = QColor(c.red / 256, c.green / 256, c.blue / 256); |
|
135 |
return color; |
|
136 |
#else |
|
137 |
// There is no equivalent to GetThemeTextColor in 64-bit and it was rather bad that |
|
138 |
// I didn't file a request to implement this for Snow Leopard. So, in the meantime |
|
139 |
// I've encoded the values from the GetThemeTextColor. This is not exactly ideal |
|
140 |
// as if someone really wants to mess with themeing, these colors will be wrong. |
|
141 |
// It also means that we need to make sure the values for differences between |
|
142 |
// OS releases (and it will be likely that we are a step behind.) |
|
143 |
switch (themeColor) { |
|
144 |
case kThemeTextColorAlertActive: |
|
145 |
case kThemeTextColorTabFrontActive: |
|
146 |
case kThemeTextColorBevelButtonActive: |
|
147 |
case kThemeTextColorListView: |
|
148 |
case kThemeTextColorPlacardActive: |
|
149 |
case kThemeTextColorPopupButtonActive: |
|
150 |
case kThemeTextColorPopupLabelActive: |
|
151 |
case kThemeTextColorPushButtonActive: |
|
152 |
return Qt::black; |
|
153 |
case kThemeTextColorAlertInactive: |
|
154 |
case kThemeTextColorDialogInactive: |
|
155 |
case kThemeTextColorPlacardInactive: |
|
156 |
return QColor(69, 69, 69, 255); |
|
157 |
case kThemeTextColorPopupButtonInactive: |
|
158 |
case kThemeTextColorPopupLabelInactive: |
|
159 |
case kThemeTextColorPushButtonInactive: |
|
160 |
case kThemeTextColorTabFrontInactive: |
|
161 |
case kThemeTextColorBevelButtonInactive: |
|
162 |
return QColor(127, 127, 127, 255); |
|
163 |
default: { |
|
164 |
QNativeImage nativeImage(16,16, QNativeImage::systemFormat()); |
|
165 |
CGRect cgrect = CGRectMake(0, 0, 16, 16); |
|
166 |
HIThemeSetTextFill(themeColor, 0, nativeImage.cg, kHIThemeOrientationNormal); |
|
167 |
CGContextFillRect(nativeImage.cg, cgrect); |
|
168 |
QColor color = nativeImage.image.pixel(0,0); |
|
169 |
return QColor(nativeImage.image.pixel(0 , 0)); |
|
170 |
} |
|
171 |
} |
|
172 |
#endif |
|
173 |
} |
|
174 |
QT_END_NAMESPACE |