summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles/qmacstyle_mac.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/styles/qmacstyle_mac.mm')
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm109
1 files changed, 48 insertions, 61 deletions
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm
index 132cc8d59e..4adda2f151 100644
--- a/src/widgets/styles/qmacstyle_mac.mm
+++ b/src/widgets/styles/qmacstyle_mac.mm
@@ -3,7 +3,7 @@
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
-** This file is part of the QtGui module of the Qt Toolkit.
+** This file is part of the QtWidgets module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
@@ -41,14 +41,13 @@
/*
Note: The qdoc comments for QMacStyle are contained in
- .../doc/src/qstyles.qdoc.
+ .../doc/src/qstyles.qdoc.
*/
#include <Cocoa/Cocoa.h>
#include "qmacstyle_mac_p.h"
#include "qmacstyle_mac_p_p.h"
-#include "qmacstylepixmaps_mac_p.h"
#define QMAC_QAQUASTYLE_SIZE_CONSTRAIN
//#define DEBUG_SIZE_CONSTRAINT
@@ -458,6 +457,9 @@ static QString qt_mac_removeMnemonics(const QString &original)
return returnText;
}
+static CGContextRef qt_mac_cg_context(const QPaintDevice *pdev);
+
+namespace {
class QMacCGContext
{
CGContextRef context;
@@ -465,7 +467,6 @@ public:
QMacCGContext(QPainter *p);
inline QMacCGContext() { context = 0; }
inline QMacCGContext(const QPaintDevice *pdev) {
- extern CGContextRef qt_mac_cg_context(const QPaintDevice *);
context = qt_mac_cg_context(pdev);
}
inline QMacCGContext(CGContextRef cg, bool takeOwnership=false) {
@@ -495,6 +496,7 @@ public:
return *this;
}
};
+} // anonymous namespace
static QColor qcolorFromCGColor(CGColorRef cgcolor)
{
@@ -578,19 +580,17 @@ QRegion qt_mac_fromHIShapeRef(HIShapeRef shape)
}
CGColorSpaceRef m_genericColorSpace = 0;
-QHash<CGDirectDisplayID, CGColorSpaceRef> m_displayColorSpaceHash;
+static QHash<CGDirectDisplayID, CGColorSpaceRef> m_displayColorSpaceHash;
bool m_postRoutineRegistered = false;
-CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget);
-CGColorSpaceRef qt_mac_genericColorSpace()
+static CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget);
+static CGColorSpaceRef qt_mac_genericColorSpace()
{
#if 0
if (!m_genericColorSpace) {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
m_genericColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
} else
-#endif
{
m_genericColorSpace = CGColorSpaceCreateDeviceRGB();
}
@@ -606,11 +606,26 @@ CGColorSpaceRef qt_mac_genericColorSpace()
#endif
}
+static void qt_mac_cleanUpMacColorSpaces()
+{
+ if (m_genericColorSpace) {
+ CFRelease(m_genericColorSpace);
+ m_genericColorSpace = 0;
+ }
+ QHash<CGDirectDisplayID, CGColorSpaceRef>::const_iterator it = m_displayColorSpaceHash.constBegin();
+ while (it != m_displayColorSpaceHash.constEnd()) {
+ if (it.value())
+ CFRelease(it.value());
+ ++it;
+ }
+ m_displayColorSpaceHash.clear();
+}
+
/*
Ideally, we should pass the widget in here, and use CGGetDisplaysWithRect() etc.
to support multiple displays correctly.
*/
-CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget)
+static CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget)
{
CGColorSpaceRef colorSpace;
@@ -639,27 +654,11 @@ CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget)
m_displayColorSpaceHash.insert(displayID, colorSpace);
if (!m_postRoutineRegistered) {
m_postRoutineRegistered = true;
- void qt_mac_cleanUpMacColorSpaces();
qAddPostRoutine(qt_mac_cleanUpMacColorSpaces);
}
return colorSpace;
}
-void qt_mac_cleanUpMacColorSpaces()
-{
- if (m_genericColorSpace) {
- CFRelease(m_genericColorSpace);
- m_genericColorSpace = 0;
- }
- QHash<CGDirectDisplayID, CGColorSpaceRef>::const_iterator it = m_displayColorSpaceHash.constBegin();
- while (it != m_displayColorSpaceHash.constEnd()) {
- if (it.value())
- CFRelease(it.value());
- ++it;
- }
- m_displayColorSpaceHash.clear();
-}
-
bool qt_macWindowIsTextured(const QWidget *window)
{
NSWindow *nswindow = static_cast<NSWindow*>(
@@ -2371,6 +2370,9 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW
case PM_MenuHMargin:
ret = 0;
break;
+ case PM_ToolBarExtensionExtent:
+ ret = 21;
+ break;
case PM_ToolBarFrameWidth:
ret = 1;
if (widget) {
@@ -2954,16 +2956,16 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
p->save();
QPainterPath path;
int x = opt->rect.x() + 6;
- int y = opt->rect.y() + 5;
+ int y = opt->rect.y() + 7;
static const int RectHeight = 2;
if (opt->state & State_Horizontal) {
- while (y < opt->rect.height() - RectHeight - 6) {
+ while (y < opt->rect.height() - RectHeight - 5) {
path.moveTo(x, y);
path.addRect(x, y, RectHeight, RectHeight);
y += 6;
}
} else {
- while (x < opt->rect.width() - RectHeight - 6) {
+ while (x < opt->rect.width() - RectHeight - 5) {
path.moveTo(x, y);
path.addRect(x, y, RectHeight, RectHeight);
x += 6;
@@ -2975,12 +2977,6 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
QColor light = opt->palette.light().color();
light.setAlphaF(0.6);
p->fillPath(path, light);
- p->save();
- p->translate(1, 1);
- p->fillPath(path, dark);
- p->restore();
- p->translate(3, 3);
- p->fillPath(path, light);
p->translate(1, 1);
p->fillPath(path, dark);
p->restore();
@@ -3196,18 +3192,6 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
drawTabCloseButton(p, hover, active, selected);
} break;
case PE_PanelStatusBar: {
- if (QSysInfo::MacintoshVersion <= QSysInfo::MV_10_4) {
- QCommonStyle::drawPrimitive(pe, opt, p, w);
- break;
- }
- // Use the Leopard style only if the status bar is the status bar for a
- // QMainWindow with a unifed toolbar.
- if (w == 0 || w->parent() == 0 || qobject_cast<QMainWindow *>(w->parent()) == 0 ||
- qobject_cast<QMainWindow *>(w->parent())->unifiedTitleAndToolBarOnMac() == false ) {
- QCommonStyle::drawPrimitive(pe, opt, p, w);
- break;
- }
-
// Fill the status bar with the titlebar gradient.
QLinearGradient linearGrad(0, opt->rect.top(), 0, opt->rect.bottom());
if (opt->state & QStyle::State_Active) {
@@ -3413,7 +3397,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
} else {
pr.setHeight(pixmap.size().height() + 6);
cr.adjust(0, pr.bottom(), 0, -3);
- }
+ }
alignment |= Qt::AlignCenter;
} else {
pr.setWidth(pixmap.width() + 8);
@@ -4905,14 +4889,12 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
} else {
if (!(slider->subControls & SC_SliderHandle))
tdi.attributes &= ~kThemeTrackShowThumb;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
if (!(slider->subControls & SC_SliderGroove))
tdi.attributes |= kThemeTrackHideTrack;
-#endif
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
- if (cc == CC_ScrollBar && proxy()->styleHint(SH_ScrollBar_Transient, 0, widget)) {
+ if (cc == CC_ScrollBar && proxy()->styleHint(SH_ScrollBar_Transient, opt, widget)) {
bool wasActive = false;
CGFloat opacity = 1.0;
CGFloat expandScale = 1.0;
@@ -5303,7 +5285,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
else
x += br.width() / 2 - p->fontMetrics().width(titlebar->text) / 2;
if (iw)
- p->drawPixmap(x - iw, y,
+ p->drawPixmap(x - iw, y,
titlebar->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), QIcon::Normal));
drawItemText(p, br, Qt::AlignCenter, opt->palette, tds == kThemeStateActive,
titlebar->text, QPalette::Text);
@@ -5981,10 +5963,11 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
switch (ct) {
case QStyle::CT_SpinBox:
- // hack to work around horrible sizeHint() code in QAbstractSpinBox
+ // hack to work around horrible sizeHint() code in QAbstractSpinBox
+ sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
sz.setHeight(sz.height() - 3);
break;
- case QStyle::CT_TabWidget:
+ case QStyle::CT_TabWidget:
// the size between the pane and the "contentsRect" (+4,+4)
// (the "contentsRect" is on the inside of the pane)
sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
@@ -6012,12 +5995,12 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
------------------------------ <- top of stack widget
- To summarize:
- * 2 is the distance between the pane and the contentsRect
+ To summarize:
+ * 2 is the distance between the pane and the contentsRect
* The 14 and the 1's are the distance from the contentsRect to the stack widget.
(same value as used in SE_TabWidgetTabContents)
* overlap is how much the pane should overlap the tab bar
- */
+ */
// then add the size between the stackwidget and the "contentsRect"
if (const QStyleOptionTabWidgetFrame *twf
@@ -6368,7 +6351,7 @@ QIcon QMacStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *o
return QCommonStyle::standardIcon(standardIcon, opt, widget);
case SP_ToolBarHorizontalExtensionButton:
case SP_ToolBarVerticalExtensionButton: {
- QPixmap pixmap(qt_mac_toolbar_ext);
+ QPixmap pixmap(QLatin1String(":/qt-project.org/styles/macstyle/images/toolbar-ext.png"));
if (standardIcon == SP_ToolBarVerticalExtensionButton) {
QPixmap pix2(pixmap.height(), pixmap.width());
pix2.fill(Qt::transparent);
@@ -6484,7 +6467,7 @@ int QMacStyle::layoutSpacing(QSizePolicy::ControlType control1,
return_SIZE(10, 8, 6); // guess
}
-void qt_mac_clip_cg(CGContextRef hd, const QRegion &rgn, CGAffineTransform *orig_xform)
+static void qt_mac_clip_cg(CGContextRef hd, const QRegion &rgn, CGAffineTransform *orig_xform)
{
CGAffineTransform old_xform = CGAffineTransformIdentity;
if (orig_xform) { //setup xforms
@@ -6525,6 +6508,9 @@ void qt_mac_scale_region(QRegion *region, qreal scaleFactor)
region->setRects(&scaledRects[0], scaledRects.count());
}
+static CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *paintDevice);
+
+namespace {
QMacCGContext::QMacCGContext(QPainter *p)
{
QPaintEngine *pe = p->paintEngine();
@@ -6537,7 +6523,6 @@ QMacCGContext::QMacCGContext(QPainter *p)
devType == QInternal::Pixmap ||
devType == QInternal::Image)) {
- extern CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *paintDevice);
CGColorSpaceRef colorspace = qt_mac_colorSpaceForDeviceType(pe->paintDevice());
uint flags = kCGImageAlphaPremultipliedFirst;
flags |= kCGBitmapByteOrder32Host;
@@ -6579,7 +6564,9 @@ QMacCGContext::QMacCGContext(QPainter *p)
}
}
-CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *paintDevice)
+} // anonymous namespace
+
+static CGColorSpaceRef qt_mac_colorSpaceForDeviceType(const QPaintDevice *paintDevice)
{
bool isWidget = (paintDevice->devType() == QInternal::Widget);
return qt_mac_displayColorSpace(isWidget ? static_cast<const QWidget *>(paintDevice) : 0);