Qt 4.8
Functions
qt_mac.cpp File Reference
#include <private/qt_mac_p.h>
#include <private/qpixmap_mac_p.h>
#include <private/qnativeimage_p.h>
#include <qdebug.h>

Go to the source code of this file.

Functions

static QColor leopardBrush (ThemeBrush brush)
 
QColor qcolorForTheme (ThemeBrush brush)
 
QColor qcolorForThemeTextColor (ThemeTextColor themeColor)
 
static QColor qcolorFromCGColor (CGColorRef cgcolor)
 
QFont qfontForThemeFont (ThemeFontID themeID)
 

Function Documentation

◆ leopardBrush()

static QColor leopardBrush ( ThemeBrush  brush)
inlinestatic

Definition at line 102 of file qt_mac.cpp.

Referenced by qcolorForTheme().

103 {
104  QCFType<CGColorRef> cgClr = 0;
105  HIThemeBrushCreateCGColor(brush, &cgClr);
106  return qcolorFromCGColor(cgClr);
107 }
static QColor qcolorFromCGColor(CGColorRef cgcolor)
Definition: qt_mac.cpp:83

◆ qcolorForTheme()

QColor qcolorForTheme ( ThemeBrush  brush)

Definition at line 110 of file qt_mac.cpp.

Referenced by QApplicationPrivate::initializeWidgetPaletteHash(), and QMacStyle::polish().

111 {
112 #ifndef QT_MAC_USE_COCOA
113 # if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
115  return leopardBrush(brush);
116  } else
117 # endif
118  {
119  RGBColor rgbcolor;
120  GetThemeBrushAsColor(brush, 32, true, &rgbcolor);
121  return QColor(rgbcolor.red / 256, rgbcolor.green / 256, rgbcolor.blue / 256);
122  }
123 #else
124  return leopardBrush(brush);
125 #endif
126 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
static QColor leopardBrush(ThemeBrush brush)
Definition: qt_mac.cpp:102
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
Definition: qglobal.h:1646

◆ qcolorForThemeTextColor()

QColor qcolorForThemeTextColor ( ThemeTextColor  themeColor)

Definition at line 128 of file qt_mac.cpp.

Referenced by QApplicationPrivate::initializeWidgetPaletteHash().

129 {
130 #ifdef Q_OS_MAC32
131  RGBColor c;
132  GetThemeTextColor(themeColor, 32, true, &c);
133  QColor color = QColor(c.red / 256, c.green / 256, c.blue / 256);
134  return color;
135 #else
136  // There is no equivalent to GetThemeTextColor in 64-bit and it was rather bad that
137  // I didn't file a request to implement this for Snow Leopard. So, in the meantime
138  // I've encoded the values from the GetThemeTextColor. This is not exactly ideal
139  // as if someone really wants to mess with themeing, these colors will be wrong.
140  // It also means that we need to make sure the values for differences between
141  // OS releases (and it will be likely that we are a step behind.)
142  switch (themeColor) {
143  case kThemeTextColorAlertActive:
144  case kThemeTextColorTabFrontActive:
145  case kThemeTextColorBevelButtonActive:
146  case kThemeTextColorListView:
147  case kThemeTextColorPlacardActive:
148  case kThemeTextColorPopupButtonActive:
149  case kThemeTextColorPopupLabelActive:
150  case kThemeTextColorPushButtonActive:
151  return Qt::black;
152  case kThemeTextColorAlertInactive:
153  case kThemeTextColorDialogInactive:
154  case kThemeTextColorPlacardInactive:
155  return QColor(69, 69, 69, 255);
156  case kThemeTextColorPopupButtonInactive:
157  case kThemeTextColorPopupLabelInactive:
158  case kThemeTextColorPushButtonInactive:
159  case kThemeTextColorTabFrontInactive:
160  case kThemeTextColorBevelButtonInactive:
161  return QColor(127, 127, 127, 255);
162  default: {
163  QNativeImage nativeImage(16,16, QNativeImage::systemFormat());
164  CGRect cgrect = CGRectMake(0, 0, 16, 16);
165  HIThemeSetTextFill(themeColor, 0, nativeImage.cg, kHIThemeOrientationNormal);
166  CGContextFillRect(nativeImage.cg, cgrect);
167  QColor color = nativeImage.image.pixel(0,0);
168  return QColor(nativeImage.image.pixel(0 , 0));
169  }
170  }
171 #endif
172 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
unsigned char c[8]
Definition: qnumeric_p.h:62
static QImage::Format systemFormat()
struct CGRect CGRect

◆ qcolorFromCGColor()

static QColor qcolorFromCGColor ( CGColorRef  cgcolor)
static

Definition at line 83 of file qt_mac.cpp.

Referenced by leopardBrush().

84 {
85  QColor pc;
86  CGColorSpaceModel model = CGColorSpaceGetModel(CGColorGetColorSpace(cgcolor));
87  const CGFloat *components = CGColorGetComponents(cgcolor);
88  if (model == kCGColorSpaceModelRGB) {
89  pc.setRgbF(components[0], components[1], components[2], components[3]);
90  } else if (model == kCGColorSpaceModelCMYK) {
91  pc.setCmykF(components[0], components[1], components[2], components[3]);
92  } else if (model == kCGColorSpaceModelMonochrome) {
93  pc.setRgbF(components[0], components[0], components[0], components[1]);
94  } else {
95  // Colorspace we can't deal with.
96  qWarning("Qt: qcolorFromCGColor: cannot convert from colorspace model: %d", model);
97  Q_ASSERT(false);
98  }
99  return pc;
100 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
void setRgbF(qreal r, qreal g, qreal b, qreal a=1.0)
Sets the color channels of this color to r (red), g (green), b (blue) and a (alpha, transparency).
Definition: qcolor.cpp:954
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a=1.0)
Sets the color to CMYK values, c (cyan), m (magenta), y (yellow), k (black), and a (alpha-channel...
Definition: qcolor.cpp:2276
Q_CORE_EXPORT void qWarning(const char *,...)
float CGFloat

◆ qfontForThemeFont()

QFont qfontForThemeFont ( ThemeFontID  themeID)

Definition at line 56 of file qt_mac.cpp.

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  return QFont(qt_mac_from_pascal_string(f_name), f_size,
65  (f_style & ::bold) ? QFont::Bold : QFont::Normal,
66  (bool)(f_style & ::italic));
67 #else
68  QCFType<CTFontRef> ctfont = CopyCTThemeFont(themeID);
69  QString familyName = QCFString(CTFontCopyFamilyName(ctfont));
70  QCFType<CFDictionaryRef> dict = CTFontCopyTraits(ctfont);
71  CFNumberRef num = static_cast<CFNumberRef>(CFDictionaryGetValue(dict, kCTFontWeightTrait));
72  float fW;
73  CFNumberGetValue(num, kCFNumberFloat32Type, &fW);
74  QFont::Weight wght = fW > 0. ? QFont::Bold : QFont::Normal;
75  num = static_cast<CFNumberRef>(CFDictionaryGetValue(dict, kCTFontSlantTrait));
76  CFNumberGetValue(num, kCFNumberFloatType, &fW);
77  bool italic = (fW != 0.0);
78  return QFont(familyName, CTFontGetSize(ctfont), wght, italic);
79 #endif
80 }
Weight
Qt uses a weighting scale from 0 to 99 similar to, but not the same as, the scales used in Windows or...
Definition: qfont.h:103
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QString qt_mac_from_pascal_string(const Str255 pstr)
Definition: qcore_mac.cpp:120