summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/styles')
-rw-r--r--src/widgets/styles/qandroidstyle.cpp2
-rw-r--r--src/widgets/styles/qfusionstyle.cpp7
-rw-r--r--src/widgets/styles/qgtkstyle.cpp5
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm171
-rw-r--r--src/widgets/styles/qmacstyle_mac_p_p.h16
-rw-r--r--src/widgets/styles/qstyle.cpp5
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp6
-rw-r--r--src/widgets/styles/qwindowscestyle.cpp4
-rw-r--r--src/widgets/styles/qwindowsstyle.cpp4
-rw-r--r--src/widgets/styles/qwindowsvistastyle.cpp4
-rw-r--r--src/widgets/styles/qwindowsxpstyle.cpp4
11 files changed, 167 insertions, 61 deletions
diff --git a/src/widgets/styles/qandroidstyle.cpp b/src/widgets/styles/qandroidstyle.cpp
index eb688e3c46..38c7497ffa 100644
--- a/src/widgets/styles/qandroidstyle.cpp
+++ b/src/widgets/styles/qandroidstyle.cpp
@@ -624,8 +624,6 @@ QRect QAndroidStyle::subElementRect(SubElement subElement,
const QStyleOption *option,
const QWidget *widget) const
{
- if (subElement == SE_LineEditContents) // fix spinbox display problem
- return QFusionStyle::subElementRect(subElement, option, widget);
const ItemType itemType = qtControl(subElement);
AndroidControlsHash::const_iterator it = itemType != QC_UnknownType
? m_androidControlsHash.find(itemType)
diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp
index 7814f80001..142bd5882e 100644
--- a/src/widgets/styles/qfusionstyle.cpp
+++ b/src/widgets/styles/qfusionstyle.cpp
@@ -3084,8 +3084,7 @@ int QFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, co
val = 2;
break;
case PM_MaximumDragDistance:
- val = -1;
- break;
+ return -1; // Do not dpi-scale because the value is magic
case PM_TabCloseIndicatorWidth:
case PM_TabCloseIndicatorHeight:
val = 20;
@@ -3100,8 +3099,7 @@ int QFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, co
val = 2;
break;
case PM_SubMenuOverlap:
- val = -1;
- break;
+ return -1; // Do not dpi-scale because the value is magic
case PM_DockWidgetHandleExtent:
case PM_SplitterWidth:
val = 4;
@@ -3122,7 +3120,6 @@ int QFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, co
break;
case PM_DefaultFrameWidth:
return 1; // Do not dpi-scale because the drawn frame is always exactly 1 pixel thick
- break;
default:
return QCommonStyle::pixelMetric(metric, option, widget);
}
diff --git a/src/widgets/styles/qgtkstyle.cpp b/src/widgets/styles/qgtkstyle.cpp
index fe35c7c695..6f2a2046b7 100644
--- a/src/widgets/styles/qgtkstyle.cpp
+++ b/src/widgets/styles/qgtkstyle.cpp
@@ -289,6 +289,7 @@ static QColor mergedColors(const QColor &colorA, const QColor &colorB, int facto
static GdkColor fromQColor(const QColor &color)
{
GdkColor retval;
+ retval.pixel = 0;
retval.red = color.red() * 255;
retval.green = color.green() * 255;
retval.blue = color.blue() * 255;
@@ -3235,8 +3236,8 @@ void QGtkStyle::drawControl(ControlElement element,
else
pixmap = menuItem->icon.pixmap(iconSize, mode);
- int pixw = pixmap.width();
- int pixh = pixmap.height();
+ const int pixw = pixmap.width() / pixmap.devicePixelRatio();
+ const int pixh = pixmap.height() / pixmap.devicePixelRatio();
QRect pmr(0, 0, pixw, pixh);
pmr.moveCenter(vCheckRect.center() - QPoint(0, 1));
painter->setPen(menuItem->palette.text().color());
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm
index 7f6495e29d..a4838d5777 100644
--- a/src/widgets/styles/qmacstyle_mac.mm
+++ b/src/widgets/styles/qmacstyle_mac.mm
@@ -93,6 +93,7 @@
#include <qmath.h>
#include <QtWidgets/qgraphicsproxywidget.h>
#include <QtWidgets/qgraphicsview.h>
+#include <QtCore/qvariant.h>
#include <private/qstylehelper_p.h>
#include <private/qstyleanimation_p.h>
#include <qpa/qplatformfontdatabase.h>
@@ -1728,7 +1729,7 @@ QMacStylePrivate::QMacStylePrivate()
QMacStylePrivate::~QMacStylePrivate()
{
- Q_FOREACH (NSView *b, buttons)
+ Q_FOREACH (NSView *b, cocoaControls)
[b release];
}
@@ -1749,41 +1750,92 @@ ThemeDrawState QMacStylePrivate::getDrawState(QStyle::State flags)
return tds;
}
-NSView *QMacStylePrivate::buttonOfKind(ThemeButtonKind kind) const
+static QCocoaWidget cocoaWidgetFromHIThemeButtonKind(ThemeButtonKind kind)
{
- NSView *bv = buttons[kind];
+ QCocoaWidget w;
+
+ switch (kind) {
+ case kThemePopupButton:
+ case kThemePopupButtonSmall:
+ case kThemePopupButtonMini:
+ w.first = QCocoaPopupButton;
+ break;
+ case kThemeComboBox:
+ w.first = QCocoaComboBox;
+ break;
+ case kThemeArrowButton:
+ w.first = QCocoaArrowButton;
+ break;
+ case kThemeCheckBox:
+ case kThemeCheckBoxSmall:
+ case kThemeCheckBoxMini:
+ w.first = QCocoaCheckBox;
+ break;
+ case kThemeRadioButton:
+ case kThemeRadioButtonSmall:
+ case kThemeRadioButtonMini:
+ w.first = QCocoaRadioButton;
+ break;
+ case kThemePushButton:
+ case kThemePushButtonSmall:
+ case kThemePushButtonMini:
+ w.first = QCocoaPushButton;
+ break;
+ default:
+ break;
+ }
+
+ switch (kind) {
+ case kThemePushButtonSmall:
+ case kThemePopupButtonSmall:
+ case kThemeCheckBoxSmall:
+ case kThemeRadioButtonSmall:
+ w.second = QAquaSizeSmall;
+ break;
+ case kThemePushButtonMini:
+ case kThemePopupButtonMini:
+ case kThemeCheckBoxMini:
+ case kThemeRadioButtonMini:
+ w.second = QAquaSizeMini;
+ break;
+ default:
+ w.second = QAquaSizeLarge;
+ break;
+ }
+
+ return w;
+}
+
+NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget, QPoint *offset) const
+{
+ NSView *bv = cocoaControls[widget];
if (!bv) {
- if (kind == kThemePopupButton)
+
+ if (widget.first == QCocoaPopupButton)
bv = [[NSPopUpButton alloc] init];
- else if (kind == kThemeComboBox)
+ else if (widget.first == QCocoaComboBox)
bv = [[NSComboBox alloc] init];
else
bv = [[NSButton alloc] init];
- switch (kind) {
- case kThemeArrowButton: {
+ switch (widget.first) {
+ case QCocoaArrowButton: {
NSButton *bc = (NSButton *)bv;
bc.buttonType = NSOnOffButton;
bc.bezelStyle = NSDisclosureBezelStyle;
break;
}
- case kThemeCheckBox:
- case kThemeCheckBoxSmall:
- case kThemeCheckBoxMini: {
+ case QCocoaCheckBox: {
NSButton *bc = (NSButton *)bv;
bc.buttonType = NSSwitchButton;
break;
}
- case kThemeRadioButton:
- case kThemeRadioButtonSmall:
- case kThemeRadioButtonMini: {
+ case QCocoaRadioButton: {
NSButton *bc = (NSButton *)bv;
bc.buttonType = NSRadioButton;
break;
}
- case kThemePushButton:
- case kThemePushButtonSmall:
- case kThemePushButtonMini: {
+ case QCocoaPushButton: {
NSButton *bc = (NSButton *)bv;
bc.buttonType = NSMomentaryPushButton;
bc.bezelStyle = NSRoundedBezelStyle;
@@ -1793,23 +1845,44 @@ NSView *QMacStylePrivate::buttonOfKind(ThemeButtonKind kind) const
break;
}
-// if (kind == kThemePushButtonSmall
-// || kind == kThemePopupButtonSmall
-// || kind == kThemeCheckBoxSmall
-// || kind == kThemeRadioButtonSmall)
-// bc.controlSize = NSSmallControlSize;
-// else if (kind == kThemePushButtonMini
-// || kind == kThemePopupButtonMini
-// || kind == kThemeCheckBoxMini
-// || kind == kThemeRadioButtonMini)
-// bc.controlSize = NSMiniControlSize;
-
if ([bv isKindOfClass:[NSButton class]]) {
NSButton *bc = (NSButton *)bv;
bc.title = nil;
}
- const_cast<QMacStylePrivate *>(this)->buttons.insert(kind, bv);
+ if ([bv isKindOfClass:[NSControl class]]) {
+ NSCell *bcell = [(NSControl *)bv cell];
+ switch (widget.second) {
+ case QAquaSizeSmall:
+ bcell.controlSize = NSSmallControlSize;
+ break;
+ case QAquaSizeMini:
+ bcell.controlSize = NSMiniControlSize;
+ break;
+ default:
+ break;
+ }
+ }
+
+ const_cast<QMacStylePrivate *>(this)->cocoaControls.insert(widget, bv);
+ }
+
+ if (offset) {
+ if (widget == QCocoaWidget(QCocoaRadioButton, QAquaSizeLarge))
+ offset->setY(2);
+ else if (widget == QCocoaWidget(QCocoaRadioButton, QAquaSizeSmall))
+ *offset = QPoint(-1, 2);
+ else if (widget == QCocoaWidget(QCocoaRadioButton, QAquaSizeMini))
+ offset->setY(2);
+ else if (widget == QCocoaWidget(QCocoaPopupButton, QAquaSizeSmall)
+ || widget == QCocoaWidget(QCocoaCheckBox, QAquaSizeLarge))
+ offset->setY(1);
+ else if (widget == QCocoaWidget(QCocoaCheckBox, QAquaSizeSmall))
+ offset->setX(-1);
+ else if (widget == QCocoaWidget(QCocoaCheckBox, QAquaSizeMini))
+ *offset = QPoint(7, 5);
+ else if (widget == QCocoaWidget(QCocoaPopupButton, QAquaSizeMini))
+ *offset = QPoint(2, -1);
}
return bv;
@@ -1827,8 +1900,8 @@ void QMacStylePrivate::drawNSViewInRect(NSView *view, const QRect &qtRect, QPain
CGRect rect = CGRectMake(qtRect.x() + 1, qtRect.y(), qtRect.width(), qtRect.height());
[backingStoreNSView addSubview:view];
- view.frame = rect;
- [view drawRect:rect];
+ view.frame = NSRectFromCGRect(rect);
+ [view drawRect:NSRectFromCGRect(rect)];
[view removeFromSuperviewWithoutNeedingDisplay];
[NSGraphicsContext restoreGraphicsState];
@@ -1928,14 +2001,20 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
}
pm = QPixmap::fromImage(image);
} else if ((usingYosemiteOrLater && combo && !editableCombo) || button) {
- NSButton *bc = (NSButton *)buttonOfKind(bdi->kind);
+ QPoint offset;
+ NSButton *bc = (NSButton *)cocoaControl(cocoaWidgetFromHIThemeButtonKind(bdi->kind), &offset);
[bc highlight:pressed];
bc.enabled = bdi->state != kThemeStateUnavailable && bdi->state != kThemeStateUnavailableInactive;
+ bc.allowsMixedState = YES;
bc.state = bdi->value == kThemeButtonOn ? NSOnState :
bdi->value == kThemeButtonMixed ? NSMixedState : NSOffState;
- p->translate(0, 1);
- drawNSViewInRect(bc, opt->rect, p);
- p->translate(0, -1);
+ // The view frame may differ from what we pass to HITheme
+ QRect rect = opt->rect;
+ if (bdi->kind == kThemePopupButtonMini)
+ rect.adjust(0, 0, -5, 0);
+ p->translate(offset);
+ drawNSViewInRect(bc, rect, p);
+ p->translate(-offset);
return;
} else if (usingYosemiteOrLater && editableCombo) {
QImage image = activePixmap.toImage();
@@ -3834,9 +3913,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
NSBezierPath *pushButtonFocusRingPath;
if (bdi.kind == kThemeBevelButton)
- pushButtonFocusRingPath = [NSBezierPath bezierPathWithRect:focusRect];
+ pushButtonFocusRingPath = [NSBezierPath bezierPathWithRect:NSRectFromCGRect(focusRect)];
else
- pushButtonFocusRingPath = [NSBezierPath bezierPathWithRoundedRect:focusRect xRadius:4 yRadius:4];
+ pushButtonFocusRingPath = [NSBezierPath bezierPathWithRoundedRect:NSRectFromCGRect(focusRect) xRadius:4 yRadius:4];
qt_drawFocusRingOnPath(cg, pushButtonFocusRingPath);
}
@@ -5761,7 +5840,25 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
drawToolbarButtonArrow(tb->rect, tds, cg);
}
if (tb->state & State_On) {
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
+ if (QSysInfo::MacintoshVersion > QSysInfo::MV_MAVERICKS) {
+ QWindow *window = 0;
+ if (widget && widget->window())
+ window = widget->window()->windowHandle();
+ else if (opt->styleObject)
+ window = opt->styleObject->property("_q_styleObjectWindow").value<QWindow *>();
+
+ NSView *view = window ? (NSView *)window->winId() : nil;
+ bool isKey = false;
+ if (view)
+ isKey = [view.window isKeyWindow];
+
+ QBrush brush(isKey ? QColor(0, 0, 0, 28)
+ : QColor(0, 0, 0, 21));
+ QPainterPath path;
+ path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4);
+ p->setRenderHint(QPainter::Antialiasing);
+ p->fillPath(path, brush);
+ } else if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
static QPixmap pm(QLatin1String(":/qt-project.org/mac/style/images/leopard-unified-toolbar-on.png"));
p->setRenderHint(QPainter::SmoothPixmapTransform);
QStyleHelper::drawBorderPixmap(pm, p, tb->rect, 2, 2, 2, 2);
diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h
index f5b67cd549..b6267c43e6 100644
--- a/src/widgets/styles/qmacstyle_mac_p_p.h
+++ b/src/widgets/styles/qmacstyle_mac_p_p.h
@@ -85,6 +85,7 @@
#include <qlibrary.h>
#include <qdatetimeedit.h>
#include <qmath.h>
+#include <qpair.h>
#include <qset.h>
#include <QtWidgets/qgraphicsproxywidget.h>
#include <QtWidgets/qgraphicsview.h>
@@ -120,6 +121,17 @@ QT_BEGIN_NAMESPACE
enum QAquaWidgetSize { QAquaSizeLarge = 0, QAquaSizeSmall = 1, QAquaSizeMini = 2,
QAquaSizeUnknown = -1 };
+enum QCocoaWidgetKind {
+ QCocoaArrowButton, // Disclosure triangle, like in QTreeView
+ QCocoaCheckBox,
+ QCocoaComboBox, // Editable QComboBox
+ QCocoaPopupButton, // Non-editable QComboBox
+ QCocoaPushButton,
+ QCocoaRadioButton
+};
+
+typedef QPair<QCocoaWidgetKind, QAquaWidgetSize> QCocoaWidget;
+
#define SIZE(large, small, mini) \
(controlSize == QAquaSizeLarge ? (large) : controlSize == QAquaSizeSmall ? (small) : (mini))
@@ -187,7 +199,7 @@ public:
void setAutoDefaultButton(QObject *button) const;
- NSView *buttonOfKind(ThemeButtonKind kind) const;
+ NSView *cocoaControl(QCocoaWidget widget, QPoint *offset) const;
void drawNSViewInRect(NSView *view, const QRect &rect, QPainter *p) const;
void resolveCurrentNSView(QWindow *window);
@@ -211,7 +223,7 @@ public:
#endif
void *indicatorBranchButtonCell;
NSView *backingStoreNSView;
- QHash<ThemeButtonKind , NSView *> buttons;
+ QHash<QCocoaWidget, NSView *> cocoaControls;
};
QT_END_NAMESPACE
diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp
index 09cb6fd06b..3affd84124 100644
--- a/src/widgets/styles/qstyle.cpp
+++ b/src/widgets/styles/qstyle.cpp
@@ -302,8 +302,9 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C
applications, which may not be yours and hence not available for
you to recompile. The Qt Plugin system makes it possible to create
styles as plugins. Styles created as plugins are loaded as shared
- objects at runtime by Qt itself. Please refer to the \l{plugins-howto.html}{Qt Plugin} documentation for more
- information on how to go about creating a style plugin.
+ objects at runtime by Qt itself. Please refer to the \l{How to Create Qt Plugins}{Qt Plugin}
+ documentation for more information on how to go about creating a style
+ plugin.
Compile your plugin and put it into Qt's \c plugins/styles
directory. We now have a pluggable style that Qt can load
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 18cd793051..a6c7f5dde2 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -2485,7 +2485,7 @@ void QStyleSheetStyle::setProperties(QWidget *w)
QSet<const QString> propertySet;
for (int i = decls.count() - 1; i >= 0; --i) {
const QString property = decls.at(i).d->property;
- if (!property.startsWith(QStringLiteral("qproperty-"), Qt::CaseInsensitive))
+ if (!property.startsWith(QLatin1String("qproperty-"), Qt::CaseInsensitive))
continue;
if (!propertySet.contains(property)) {
propertySet.insert(property);
@@ -3573,8 +3573,8 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
pixmap = mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
else
pixmap = mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
- int pixw = pixmap.width();
- int pixh = pixmap.height();
+ const int pixw = pixmap.width() / pixmap.devicePixelRatio();
+ const int pixh = pixmap.height() / pixmap.devicePixelRatio();
QRenderRule iconRule = renderRule(w, opt, PseudoElement_MenuIcon);
if (!iconRule.hasGeometry()) {
iconRule.geo = new QStyleSheetGeometryData(pixw, pixh, pixw, pixh, -1, -1);
diff --git a/src/widgets/styles/qwindowscestyle.cpp b/src/widgets/styles/qwindowscestyle.cpp
index ea5c0435d8..d3a8877d00 100644
--- a/src/widgets/styles/qwindowscestyle.cpp
+++ b/src/widgets/styles/qwindowscestyle.cpp
@@ -671,8 +671,8 @@ void QWindowsCEStyle::drawControl(ControlElement element, const QStyleOption *op
pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
else
pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
- int pixw = pixmap.width();
- int pixh = pixmap.height();
+ const int pixw = pixmap.width() / pixmap.devicePixelRatio();
+ const int pixh = pixmap.height() / pixmap.devicePixelRatio();
if (act && !dis && !checked)
qDrawPlainRect(painter, vCheckRect, menuitem->palette.button().color(), 1,
&menuitem->palette.brush(QPalette::Button));
diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp
index f4306e7bd3..3619c3ff29 100644
--- a/src/widgets/styles/qwindowsstyle.cpp
+++ b/src/widgets/styles/qwindowsstyle.cpp
@@ -1156,8 +1156,8 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode, QIcon::On);
else
pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode);
- int pixw = pixmap.width();
- int pixh = pixmap.height();
+ const int pixw = pixmap.width() / pixmap.devicePixelRatio();
+ const int pixh = pixmap.height() / pixmap.devicePixelRatio();
if (act && !dis && !checked)
qDrawShadePanel(p, vCheckRect, menuitem->palette, false, 1,
&menuitem->palette.brush(QPalette::Button));
diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp
index 35a5a08a2c..a6eb2c0bc6 100644
--- a/src/widgets/styles/qwindowsvistastyle.cpp
+++ b/src/widgets/styles/qwindowsvistastyle.cpp
@@ -1275,8 +1275,8 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode, QIcon::On);
else
pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode);
- int pixw = pixmap.width();
- int pixh = pixmap.height();
+ const int pixw = pixmap.width() / pixmap.devicePixelRatio();
+ const int pixh = pixmap.height() / pixmap.devicePixelRatio();
QRect pmr(0, 0, pixw, pixh);
pmr.moveCenter(vCheckRect.center());
painter->setPen(menuitem->palette.text().color());
diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp
index 5cd378acba..624023f627 100644
--- a/src/widgets/styles/qwindowsxpstyle.cpp
+++ b/src/widgets/styles/qwindowsxpstyle.cpp
@@ -2246,8 +2246,8 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op
QPixmap pixmap = checked ?
menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode, QIcon::On) :
menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode);
- int pixw = pixmap.width();
- int pixh = pixmap.height();
+ const int pixw = pixmap.width() / pixmap.devicePixelRatio();
+ const int pixh = pixmap.height() / pixmap.devicePixelRatio();
QRect iconRect(0, 0, pixw, pixh);
iconRect.moveCenter(QRect(xpos, y, checkcol, h).center());
QRect vIconRect = visualRect(option->direction, option->rect, iconRect);