summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2014-11-24 13:37:06 +0100
committerFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2014-11-24 13:39:13 +0100
commit34aba4724f196e34ed02cf50073f41968f119bb6 (patch)
tree0ebdfcabda989ab76ee6de53c6461553c7a767a5 /src/widgets/styles
parentb86b2a742afae118bf974c82ba966ddb0cae4afb (diff)
parentb1cf07f495e10c93e53651ac03e46ebdaea0a97e (diff)
Merge remote-tracking branch 'origin/5.4' into dev
Conflicts: src/corelib/io/qiodevice.cpp src/plugins/bearer/linux_common/qofonoservice_linux.cpp src/plugins/bearer/linux_common/qofonoservice_linux_p.h src/plugins/platforms/android/qandroidplatformtheme.cpp src/tools/bootstrap/bootstrap.pro src/widgets/styles/qmacstyle_mac.mm Change-Id: Ia02aab6c4598ce74e9c30bb4666d5e2ef000f99b
Diffstat (limited to 'src/widgets/styles')
-rw-r--r--src/widgets/styles/qandroidstyle.cpp379
-rw-r--r--src/widgets/styles/qandroidstyle_p.h11
-rw-r--r--src/widgets/styles/qcommonstyle.cpp2
-rw-r--r--src/widgets/styles/qfusionstyle.cpp4
-rw-r--r--src/widgets/styles/qgtkstyle_p.cpp4
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm265
-rw-r--r--src/widgets/styles/qmacstyle_mac_p_p.h6
-rw-r--r--src/widgets/styles/qstyle.cpp3
-rw-r--r--src/widgets/styles/qstyle.h2
-rw-r--r--src/widgets/styles/qwindowsstyle.cpp14
-rw-r--r--src/widgets/styles/qwindowsvistastyle.cpp6
-rw-r--r--src/widgets/styles/qwindowsxpstyle.cpp5
12 files changed, 194 insertions, 507 deletions
diff --git a/src/widgets/styles/qandroidstyle.cpp b/src/widgets/styles/qandroidstyle.cpp
index 38c7497ffa..5b4b346da9 100644
--- a/src/widgets/styles/qandroidstyle.cpp
+++ b/src/widgets/styles/qandroidstyle.cpp
@@ -38,7 +38,6 @@
#include <QFile>
#include <QFont>
#include <QApplication>
-#include <QTime>
#include <qdrawutil.h>
#include <QPixmapCache>
#include <QFileInfo>
@@ -55,105 +54,33 @@
QT_BEGIN_NAMESPACE
namespace {
- const int textStyle_bold = 1;
- const int textStyle_italic = 2;
-
- const int typeface_sans = 1;
- const int typeface_serif = 2;
- const int typeface_monospace = 3;
-
const quint32 NO_COLOR = 1;
const quint32 TRANSPARENT_COLOR = 0;
}
-static int fontType(const QString &androidControl)
-{
- if (androidControl == QLatin1String("textViewStyle"))
- return QPlatformTheme::SystemFont;
- else if (androidControl == QLatin1String("buttonStyle"))
- return QPlatformTheme::PushButtonFont;
- else if (androidControl == QLatin1String("checkboxStyle"))
- return QPlatformTheme::CheckBoxFont;
- else if (androidControl == QLatin1String("radioButtonStyle"))
- return QPlatformTheme::RadioButtonFont;
- else if (androidControl == QLatin1String("simple_list_item_single_choice"))
- return QPlatformTheme::ItemViewFont;
- else if (androidControl == QLatin1String("simple_spinner_dropdown_item"))
- return QPlatformTheme::ComboMenuItemFont;
- else if (androidControl == QLatin1String("spinnerStyle"))
- return QPlatformTheme::ComboLineEditFont;
- else if (androidControl == QLatin1String("simple_list_item"))
- return QPlatformTheme::ListViewFont;
- return -1;
-}
-
-static int paletteType(const QString &androidControl)
-{
- if (androidControl == QLatin1String("textViewStyle"))
- return QPlatformTheme::SystemPalette;
- else if (androidControl == QLatin1String("buttonStyle"))
- return QPlatformTheme::ButtonPalette;
- else if (androidControl == QLatin1String("checkboxStyle"))
- return QPlatformTheme::CheckBoxPalette;
- else if (androidControl == QLatin1String("radioButtonStyle"))
- return QPlatformTheme::RadioButtonPalette;
- else if (androidControl == QLatin1String("simple_list_item_single_choice"))
- return QPlatformTheme::ItemViewPalette;
- else if (androidControl == QLatin1String("editTextStyle"))
- return QPlatformTheme::TextLineEditPalette;
- else if (androidControl == QLatin1String("spinnerStyle"))
- return QPlatformTheme::ComboBoxPalette;
- return -1;
-}
-
QAndroidStyle::QAndroidStyle()
: QFusionStyle()
{
QPixmapCache::clear();
checkBoxControl = NULL;
- QString stylePath(QLatin1String(qgetenv("MINISTRO_ANDROID_STYLE_PATH")));
- const QLatin1Char slashChar('/');
- if (!stylePath.isEmpty() && !stylePath.endsWith(slashChar))
- stylePath += slashChar;
-
- QString androidTheme = QLatin1String(qgetenv("QT_ANDROID_THEME"));
- if (!androidTheme.isEmpty() && !androidTheme.endsWith(slashChar))
- androidTheme += slashChar;
-
- if (stylePath.isEmpty()) {
- stylePath = QLatin1String("/data/data/org.kde.necessitas.ministro/files/dl/style/")
- + QLatin1String(qgetenv("QT_ANDROID_THEME_DISPLAY_DPI")) + slashChar;
- }
- Q_ASSERT(!stylePath.isEmpty());
-
- if (!androidTheme.isEmpty() && QFileInfo(stylePath + androidTheme + QLatin1String("style.json")).exists())
- stylePath += androidTheme;
-
- QFile f(stylePath + QLatin1String("style.json"));
- if (!f.open(QIODevice::ReadOnly))
- return;
-
- QJsonParseError error;
- QJsonDocument document = QJsonDocument::fromJson(f.readAll(), &error);
- if (document.isNull()) {
- qCritical() << error.errorString();
- return;
+ QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
+ QPalette *standardPalette = reinterpret_cast<QPalette *>(nativeInterface->nativeResourceForIntegration("AndroidStandardPalette"));
+ if (standardPalette)
+ m_standardPalette = *standardPalette;
+
+ QHash<QByteArray, QFont> *qwidgetsFonts = reinterpret_cast<QHash<QByteArray, QFont> *>(nativeInterface->nativeResourceForIntegration("AndroidQWidgetFonts"));
+ if (qwidgetsFonts) {
+ for (auto it = qwidgetsFonts->constBegin(); it != qwidgetsFonts->constEnd(); ++it)
+ QApplication::setFont(it.value(), it.key());
+ qwidgetsFonts->clear(); // free the memory
}
- if (!document.isObject()) {
- qCritical() << "Style.json does not contain a valid style.";
+ QJsonObject *object = reinterpret_cast<QJsonObject *>(nativeInterface->nativeResourceForIntegration("AndroidStyleData"));
+ if (!object)
return;
- }
- QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
-
- QHash<int, QPalette> *palettes = reinterpret_cast<QHash<int, QPalette> *>(nativeInterface->nativeResourceForIntegration("AndroidStylePalettes"));
- QHash<int, QFont> *fonts = reinterpret_cast<QHash<int, QFont> *>(nativeInterface->nativeResourceForIntegration("AndroidStyleFonts"));
- palettes->clear();
- fonts->clear();
- QJsonObject object = document.object();
- for (QJsonObject::const_iterator objectIterator = object.constBegin();
- objectIterator != object.constEnd();
+ for (QJsonObject::const_iterator objectIterator = object->constBegin();
+ objectIterator != object->constEnd();
++objectIterator) {
QString key = objectIterator.key();
QJsonValue value = objectIterator.value();
@@ -163,85 +90,6 @@ QAndroidStyle::QAndroidStyle()
}
QJsonObject item = value.toObject();
- QJsonObject::const_iterator attributeIterator = item.find(QLatin1String("qtClass"));
- QString qtClassName;
- if (attributeIterator != item.constEnd()) {
- // The item has palette and font information for a specific Qt Class (e.g. QWidget, QPushButton, etc.)
- qtClassName = attributeIterator.value().toString();
- }
- const int ft = fontType(key);
- if (ft > -1 || !qtClassName.isEmpty()) {
- // Extract font information
- QFont font;
-
- // Font size (in pixels)
- attributeIterator = item.find(QLatin1String("TextAppearance_textSize"));
- if (attributeIterator != item.constEnd())
- font.setPixelSize(int(attributeIterator.value().toDouble()));
-
- // Font style
- attributeIterator = item.find(QLatin1String("TextAppearance_textStyle"));
- if (attributeIterator != item.constEnd()) {
- const int style = int(attributeIterator.value().toDouble());
- font.setBold(style & textStyle_bold);
- font.setItalic(style & textStyle_italic);
- }
-
- // Font typeface
- attributeIterator = item.find(QLatin1String("TextAppearance_typeface"));
- if (attributeIterator != item.constEnd()) {
- QFont::StyleHint styleHint = QFont::AnyStyle;
- switch (int(attributeIterator.value().toDouble())) {
- case typeface_sans:
- styleHint = QFont::SansSerif;
- break;
- case typeface_serif:
- styleHint = QFont::Serif;
- break;
- case typeface_monospace:
- styleHint = QFont::Monospace;
- break;
- }
- font.setStyleHint(styleHint, QFont::PreferMatch);
- }
- if (!qtClassName.isEmpty())
- QApplication::setFont(font, qtClassName.toUtf8());
- if (ft > -1)
- fonts->insert(ft, font);
- // Extract font information
- }
-
- const int pt = paletteType(key);
- if (pt > -1 || !qtClassName.isEmpty()) {
- // Extract palette information
- QPalette palette;
- attributeIterator = item.find(QLatin1String("defaultTextColorPrimary"));
- if (attributeIterator != item.constEnd())
- palette.setColor(QPalette::WindowText, QRgb(int(attributeIterator.value().toDouble())));
-
- attributeIterator = item.find(QLatin1String("defaultBackgroundColor"));
- if (attributeIterator != item.constEnd())
- palette.setColor(QPalette::Background, QRgb(int(attributeIterator.value().toDouble())));
-
- attributeIterator = item.find(QLatin1String("TextAppearance_textColor"));
- if (attributeIterator != item.constEnd())
- setPaletteColor(attributeIterator.value().toObject().toVariantMap(), palette, QPalette::WindowText);
-
- attributeIterator = item.find(QLatin1String("TextAppearance_textColorLink"));
- if (attributeIterator != item.constEnd())
- setPaletteColor(attributeIterator.value().toObject().toVariantMap(), palette, QPalette::Link);
-
- attributeIterator = item.find(QLatin1String("TextAppearance_textColorHighlight"));
- if (attributeIterator != item.constEnd())
- palette.setColor(QPalette::Highlight, QRgb(int(attributeIterator.value().toDouble())));
-
- if (QLatin1String("QWidget") == qtClassName)
- m_standardPalette = palette;
-
- if (pt > -1)
- palettes->insert(pt, palette);
- // Extract palette information
- }
QAndroidStyle::ItemType itemType = qtControl(key);
if (QC_UnknownType == itemType)
continue;
@@ -277,6 +125,7 @@ QAndroidStyle::QAndroidStyle()
break;
}
}
+ *object = QJsonObject(); // free memory
}
QAndroidStyle::~QAndroidStyle()
@@ -284,81 +133,6 @@ QAndroidStyle::~QAndroidStyle()
qDeleteAll(m_androidControlsHash);
}
-
-void QAndroidStyle::setPaletteColor(const QVariantMap &object,
- QPalette &palette,
- QPalette::ColorRole role)
-{
- // QPalette::Active -> ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
- palette.setColor(QPalette::Active,
- role,
- QRgb(object.value(QLatin1String("ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET")).toInt()));
-
- // QPalette::Inactive -> ENABLED_STATE_SET
- palette.setColor(QPalette::Inactive,
- role,
- QRgb(object.value(QLatin1String("ENABLED_STATE_SET")).toInt()));
-
- // QPalette::Disabled -> EMPTY_STATE_SET
- palette.setColor(QPalette::Disabled,
- role,
- QRgb(object.value(QLatin1String("EMPTY_STATE_SET")).toInt()));
-
- palette.setColor(QPalette::Current, role, palette.color(QPalette::Active, role));
-
- if (role == QPalette::WindowText) {
- // QPalette::BrightText -> PRESSED
- // QPalette::Active -> PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
- palette.setColor(QPalette::Active,
- QPalette::BrightText,
- QRgb(object.value(QLatin1String("PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET")).toInt()));
-
- // QPalette::Inactive -> PRESSED_ENABLED_STATE_SET
- palette.setColor(QPalette::Inactive,
- QPalette::BrightText,
- QRgb(object.value(QLatin1String("PRESSED_ENABLED_STATE_SET")).toInt()));
-
- // QPalette::Disabled -> PRESSED_STATE_SET
- palette.setColor(QPalette::Disabled,
- QPalette::BrightText,
- QRgb(object.value(QLatin1String("PRESSED_STATE_SET")).toInt()));
-
- palette.setColor(QPalette::Current, QPalette::BrightText, palette.color(QPalette::Active, QPalette::BrightText));
-
- // QPalette::HighlightedText -> SELECTED
- // QPalette::Active -> ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET
- palette.setColor(QPalette::Active,
- QPalette::HighlightedText,
- QRgb(object.value(QLatin1String("ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET")).toInt()));
-
- // QPalette::Inactive -> ENABLED_SELECTED_STATE_SET
- palette.setColor(QPalette::Inactive,
- QPalette::HighlightedText,
- QRgb(object.value(QLatin1String("ENABLED_SELECTED_STATE_SET")).toInt()));
-
- // QPalette::Disabled -> SELECTED_STATE_SET
- palette.setColor(QPalette::Disabled,
- QPalette::HighlightedText,
- QRgb(object.value(QLatin1String("SELECTED_STATE_SET")).toInt()));
-
- palette.setColor(QPalette::Current,
- QPalette::HighlightedText,
- palette.color(QPalette::Active, QPalette::HighlightedText));
-
- // Same colors for Text
- palette.setColor(QPalette::Active, QPalette::Text, palette.color(QPalette::Active, role));
- palette.setColor(QPalette::Inactive, QPalette::Text, palette.color(QPalette::Inactive, role));
- palette.setColor(QPalette::Disabled, QPalette::Text, palette.color(QPalette::Disabled, role));
- palette.setColor(QPalette::Current, QPalette::Text, palette.color(QPalette::Current, role));
-
- // And for ButtonText
- palette.setColor(QPalette::Active, QPalette::ButtonText, palette.color(QPalette::Active, role));
- palette.setColor(QPalette::Inactive, QPalette::ButtonText, palette.color(QPalette::Inactive, role));
- palette.setColor(QPalette::Disabled, QPalette::ButtonText, palette.color(QPalette::Disabled, role));
- palette.setColor(QPalette::Current, QPalette::ButtonText, palette.color(QPalette::Current, role));
- }
-}
-
QAndroidStyle::ItemType QAndroidStyle::qtControl(const QString &android)
{
if (android == QLatin1String("buttonStyle"))
@@ -470,6 +244,10 @@ QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::PrimitiveElement primit
case QStyle::PE_FrameLineEdit:
return QC_EditText;
+ case QStyle::PE_IndicatorViewItemCheck:
+ case QStyle::PE_IndicatorCheckBox:
+ return QC_Checkbox;
+
case QStyle::PE_FrameWindow:
case QStyle::PE_Widget:
case QStyle::PE_Frame:
@@ -583,37 +361,8 @@ void QAndroidStyle::drawControl(QStyle::ControlElement element,
}
break;
default:
- break;
- }
- } else if (element == CE_ItemViewItem) {
- const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt);
- if (vopt && vopt->features & QStyleOptionViewItem::HasCheckIndicator) {
- p->save();
- p->setClipRect(opt->rect);
-
- QRect checkRect = proxy()->subElementRect(SE_ItemViewItemCheckIndicator, vopt, w);
-
- // draw the background
- proxy()->drawPrimitive(PE_PanelItemViewItem, opt, p, w);
-
- // draw the check mark
- QStyleOptionViewItem option(*vopt);
- option.rect = checkRect;
- option.state = option.state & ~QStyle::State_HasFocus;
-
- switch (vopt->checkState) {
- case Qt::Unchecked:
- option.state |= QStyle::State_Off;
- break;
- default:
- option.state |= QStyle::State_On;
- break;
- }
- QPixmap pixmap = checkBoxControl->imgCheckBox(&option);
- p->drawPixmap(checkRect, pixmap);
- p->restore();
- } else {
QFusionStyle::drawControl(element, opt, p, w);
+ break;
}
} else {
QFusionStyle::drawControl(element, opt, p, w);
@@ -758,7 +507,7 @@ QRect QAndroidStyle::subControlRect(ComplexControl cc,
case CC_GroupBox: {
if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
QSize textSize = opt->fontMetrics.boundingRect(groupBox->text).size() + QSize(2, 2);
- QSize checkBoxSize = checkBoxControl->sizeCheckBox(opt);
+ QSize checkBoxSize = checkBoxControl->size(opt);
int indicatorWidth = checkBoxSize.width();
int indicatorHeight = checkBoxSize.height();
QRect checkBoxRect;
@@ -815,9 +564,9 @@ int QAndroidStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
case PM_ScrollBarExtent:
return 0;
case PM_IndicatorWidth:
- return checkBoxControl->sizeCheckBox(option).width();
+ return checkBoxControl->size(option).width();
case PM_IndicatorHeight:
- return checkBoxControl->sizeCheckBox(option).height();
+ return checkBoxControl->size(option).height();
default:
return QFusionStyle::pixelMetric(metric, option, widget);
}
@@ -834,7 +583,7 @@ QSize QAndroidStyle::sizeFromContents(ContentsType ct,
if (const QStyleOptionHeader *hdr = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
bool nullIcon = hdr->icon.isNull();
int margin = pixelMetric(QStyle::PM_HeaderMargin, hdr, w);
- int iconSize = nullIcon ? 0 : checkBoxControl->sizeCheckBox(opt).width();
+ int iconSize = nullIcon ? 0 : checkBoxControl->size(opt).width();
QSize txt;
/*
* These next 4 lines are a bad hack to fix a bug in case a QStyleSheet is applied at QApplication level.
@@ -868,7 +617,7 @@ QSize QAndroidStyle::sizeFromContents(ContentsType ct,
if (ct == CT_GroupBox) {
if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
QSize textSize = opt->fontMetrics.boundingRect(groupBox->text).size() + QSize(2, 2);
- QSize checkBoxSize = checkBoxControl->sizeCheckBox(opt);
+ QSize checkBoxSize = checkBoxControl->size(opt);
int indicatorWidth = checkBoxSize.width();
int indicatorHeight = checkBoxSize.height();
QRect checkBoxRect;
@@ -964,13 +713,6 @@ QSize QAndroidStyle::AndroidDrawable::size() const
return QSize();
}
-QPixmap QAndroidStyle::AndroidDrawable::img() const
-{
- if (type() == Image || type() == NinePatch)
- return static_cast<const QAndroidStyle::AndroidImageDrawable *>(this)->img();
-
- return QPixmap();
-}
QAndroidStyle::AndroidDrawable * QAndroidStyle::AndroidDrawable::fromMap(const QVariantMap &drawable,
ItemType itemType)
@@ -1036,19 +778,7 @@ void QAndroidStyle::AndroidImageDrawable::draw(QPainter *painter, const QStyleOp
QPixmapCache::insert(m_hashKey, pm);
}
- painter->drawPixmap(opt->rect.x(), (opt->rect.height() - pm.height()) / 2, pm);
-}
-QPixmap QAndroidStyle::AndroidImageDrawable::img() const
-{
- if (m_hashKey.isEmpty())
- m_hashKey = QFileInfo(m_filePath).fileName();
-
- QPixmap pm;
- if (!QPixmapCache::find(m_hashKey, &pm)) {
- pm.load(m_filePath);
- QPixmapCache::insert(m_hashKey, pm);
- }
- return pm;
+ painter->drawPixmap(opt->rect.x(), opt->rect.y() + (opt->rect.height() - pm.height()) / 2, pm);
}
QSize QAndroidStyle::AndroidImageDrawable::size() const
@@ -1446,14 +1176,6 @@ QSize QAndroidStyle::AndroidStateDrawable::sizeImage(const QStyleOption *opt) co
s = drawable->size();
return s;
}
-QPixmap QAndroidStyle::AndroidStateDrawable::img(const QStyleOption *opt) const
-{
- QPixmap pm;
- const AndroidDrawable *drawable = bestAndroidStateMatch(opt);
- if (drawable)
- pm = drawable->img();
- return pm;
-}
const QAndroidStyle::AndroidDrawable * QAndroidStyle::AndroidStateDrawable::bestAndroidStateMatch(const QStyleOption *opt) const
{
@@ -1733,7 +1455,6 @@ QRect QAndroidStyle::AndroidControl::subElementRect(QStyle::SubElement /* subEle
return visualRect(option->direction, option->rect, r);
}
return option->rect;
-
}
QRect QAndroidStyle::AndroidControl::subControlRect(const QStyleOptionComplex *option,
@@ -1778,6 +1499,16 @@ QMargins QAndroidStyle::AndroidControl::padding()
return QMargins();
}
+QSize QAndroidStyle::AndroidControl::size(const QStyleOption *option)
+{
+ if (const AndroidDrawable *drawable = backgroundDrawable()) {
+ if (drawable->type() == State)
+ drawable = static_cast<const AndroidStateDrawable *>(backgroundDrawable())->bestAndroidStateMatch(option);
+ return drawable->size();
+ }
+ return QSize();
+}
+
const QAndroidStyle::AndroidDrawable *QAndroidStyle::AndroidControl::backgroundDrawable() const
{
return m_background;
@@ -1788,11 +1519,12 @@ QAndroidStyle::AndroidCompoundButtonControl::AndroidCompoundButtonControl(const
: AndroidControl(control, itemType)
{
QVariantMap::const_iterator it = control.find(QLatin1String("CompoundButton_button"));
- if (it != control.end())
+ if (it != control.end()) {
m_button = AndroidDrawable::fromMap(it.value().toMap(), itemType);
- else
+ const_cast<AndroidDrawable *>(m_button)->setPaddingLeftToSizeWidth();
+ } else {
m_button = 0;
- const_cast<AndroidDrawable *>(m_button)->setPaddingLeftToSizeWidth();
+ }
}
QAndroidStyle::AndroidCompoundButtonControl::~AndroidCompoundButtonControl()
@@ -1808,16 +1540,24 @@ void QAndroidStyle::AndroidCompoundButtonControl::drawControl(const QStyleOption
if (m_button)
m_button->draw(p, opt);
}
-QSize QAndroidStyle::AndroidCompoundButtonControl::sizeCheckBox(const QStyleOption *opt) const
+
+QMargins QAndroidStyle::AndroidCompoundButtonControl::padding()
{
- const AndroidDrawable *drawable = m_button;
- return static_cast<const QAndroidStyle::AndroidStateDrawable *>(drawable)->sizeImage(opt);
+ if (m_button)
+ return m_button->padding();
+ return AndroidControl::padding();
}
-QPixmap QAndroidStyle::AndroidCompoundButtonControl::imgCheckBox(const QStyleOption *opt) const
+
+QSize QAndroidStyle::AndroidCompoundButtonControl::size(const QStyleOption *option)
{
- const AndroidDrawable *drawable = m_button;
- return static_cast<const QAndroidStyle::AndroidStateDrawable *>(drawable)->img(opt);
+ if (m_button) {
+ if (m_button->type() == State)
+ return static_cast<const AndroidStateDrawable *>(m_button)->bestAndroidStateMatch(option)->size();
+ return m_button->size();
+ }
+ return AndroidControl::size(option);
}
+
const QAndroidStyle::AndroidDrawable * QAndroidStyle::AndroidCompoundButtonControl::backgroundDrawable() const
{
return m_background ? m_background : m_button;
@@ -1908,7 +1648,6 @@ QRect QAndroidStyle::AndroidProgressBarControl::subElementRect(QStyle::SubElemen
p |= QRect(padding.left(), padding.top(), padding.right() - padding.left(), padding.bottom() - padding.top());
padding = m_progressDrawable->padding();
p |= QRect(padding.left(), padding.top(), padding.right() - padding.left(), padding.bottom() - padding.top());
-
QRect r = option->rect.adjusted(p.left(), p.top(), -p.right(), -p.bottom());
if (horizontal) {
@@ -1991,15 +1730,15 @@ void QAndroidStyle::AndroidSeekBarControl::drawControl(const QStyleOption *optio
if (drawable->type() == State)
drawable = static_cast<const QAndroidStyle::AndroidStateDrawable *>(m_seekBarThumb)->bestAndroidStateMatch(option);
QStyleOption copy(*option);
- copy.rect.setY((copy.rect.height() - m_minSize.height()) / 2);
- copy.rect.setHeight(m_minSize.height());
+ copy.rect.setHeight(m_progressDrawable->size().height());
copy.rect.setWidth(copy.rect.width() - drawable->size().width());
- copy.rect.translate(drawable->size().width() / 2, 0);
+ const int yTranslate = abs(drawable->size().height() - copy.rect.height()) / 2;
+ copy.rect.translate(drawable->size().width() / 2, yTranslate);
m_progressDrawable->draw(p, &copy);
if (styleOption->orientation == Qt::Vertical)
qCritical() << "Vertical slider are not supported";
- int pos = copy.rect.width()*factor - drawable->size().width() / 2;
- copy.rect.translate(pos, 0);
+ int pos = copy.rect.width() * factor - drawable->size().width() / 2;
+ copy.rect.translate(pos, -yTranslate);
copy.rect.setSize(drawable->size());
m_seekBarThumb->draw(p, &copy);
}
diff --git a/src/widgets/styles/qandroidstyle_p.h b/src/widgets/styles/qandroidstyle_p.h
index 65fa4cd096..d8e7768380 100644
--- a/src/widgets/styles/qandroidstyle_p.h
+++ b/src/widgets/styles/qandroidstyle_p.h
@@ -124,7 +124,6 @@ public:
static AndroidDrawable *fromMap(const QVariantMap &drawable, ItemType itemType);
static QMargins extractMargins(const QVariantMap &value);
virtual void setPaddingLeftToSizeWidth();
- QPixmap img() const;
protected:
ItemType m_itemType;
QMargins m_padding;
@@ -149,7 +148,6 @@ public:
virtual void draw(QPainter *painter,const QStyleOption *opt) const;
virtual QSize size() const;
- QPixmap img() const;
protected:
QString m_filePath;
mutable QString m_hashKey;
@@ -223,7 +221,6 @@ public:
static int extractState(const QVariantMap &value);
virtual void setPaddingLeftToSizeWidth();
QSize sizeImage(const QStyleOption *opt) const;
- QPixmap img(const QStyleOption *opt) const;
private:
typedef QPair<int, const AndroidDrawable *> StateType;
QList<StateType> m_states;
@@ -263,6 +260,7 @@ public:
const QSize &contentsSize,
const QWidget *w) const;
virtual QMargins padding();
+ virtual QSize size(const QStyleOption *option);
protected:
virtual const AndroidDrawable * backgroundDrawable() const;
const AndroidDrawable *m_background;
@@ -276,8 +274,8 @@ public:
AndroidCompoundButtonControl(const QVariantMap &control, ItemType itemType);
virtual ~AndroidCompoundButtonControl();
virtual void drawControl(const QStyleOption *opt, QPainter *p, const QWidget *w);
- QSize sizeCheckBox(const QStyleOption *opt) const;
- QPixmap imgCheckBox(const QStyleOption *opt) const;
+ virtual QMargins padding();
+ virtual QSize size(const QStyleOption *option);
protected:
virtual const AndroidDrawable * backgroundDrawable() const;
const AndroidDrawable *m_button;
@@ -376,9 +374,6 @@ private:
static ItemType qtControl(QStyle::SubElement subElement);
static ItemType qtControl(const QString &android);
- static void setPaletteColor(const QVariantMap &object,
- QPalette &palette,
- QPalette::ColorRole role);
private:
typedef QHash<int, AndroidControl *> AndroidControlsHash;
AndroidControlsHash m_androidControlsHash;
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index 815b10c921..7e9a631c5e 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -1114,7 +1114,7 @@ void QCommonStylePrivate::tabLayout(const QStyleOptionTabV3 *opt, const QWidget
(opt->state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled,
(opt->state & QStyle::State_Selected) ? QIcon::On : QIcon::Off );
// High-dpi icons do not need adjustmet; make sure tabIconSize is not larger than iconSize
- tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.width()));
+ tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height()));
*iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2,
tabIconSize.width(), tabIconSize .height());
diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp
index ef3795c9a1..817f16b297 100644
--- a/src/widgets/styles/qfusionstyle.cpp
+++ b/src/widgets/styles/qfusionstyle.cpp
@@ -553,7 +553,9 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem,
arrow = colorizedImage(QLatin1String(":/qt-project.org/styles/commonstyle/images/fusion_arrow.png"), arrowColor);
} else if (header->sortIndicator & QStyleOptionHeader::SortDown) {
arrow = colorizedImage(QLatin1String(":/qt-project.org/styles/commonstyle/images/fusion_arrow.png"), arrowColor, 180);
- } if (!arrow.isNull()) {
+ }
+
+ if (!arrow.isNull()) {
r.setSize(QSize(arrow.width()/2, arrow.height()/2));
r.moveCenter(header->rect.center());
painter->drawPixmap(r.translated(offset), arrow);
diff --git a/src/widgets/styles/qgtkstyle_p.cpp b/src/widgets/styles/qgtkstyle_p.cpp
index 06ee74bdfe..61d1cd796e 100644
--- a/src/widgets/styles/qgtkstyle_p.cpp
+++ b/src/widgets/styles/qgtkstyle_p.cpp
@@ -701,10 +701,12 @@ GtkWidget* QGtkStylePrivate::getTextColorWidget() const
void QGtkStylePrivate::setupGtkWidget(GtkWidget* widget)
{
if (Q_GTK_IS_WIDGET(widget)) {
- static GtkWidget* protoLayout = 0;
+ GtkWidget *protoLayout = gtkWidgetMap()->value("GtkContainer");
if (!protoLayout) {
protoLayout = QGtkStylePrivate::gtk_fixed_new();
QGtkStylePrivate::gtk_container_add((GtkContainer*)(gtkWidgetMap()->value("GtkWindow")), protoLayout);
+ QHashableLatin1Literal widgetPath = QHashableLatin1Literal::fromData(strdup("GtkContainer"));
+ gtkWidgetMap()->insert(widgetPath, protoLayout);
}
Q_ASSERT(protoLayout);
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm
index fb0bafa66d..328378cb8e 100644
--- a/src/widgets/styles/qmacstyle_mac.mm
+++ b/src/widgets/styles/qmacstyle_mac.mm
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@@ -296,14 +296,12 @@ void drawTabShape(QPainter *p, const QStyleOptionTabV3 *tabOpt, bool isUnified)
p->fillRect(rect, QColor(Qt::transparent));
p->restore();
} else if (active) {
- int d = (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) ? 16 : 0;
- p->fillRect(rect, QColor(151 + d, 151 + d, 151 + d));
+ p->fillRect(rect, QColor(167, 167, 167));
} else {
- int d = (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) ? 9 : 0;
QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
- gradient.setColorAt(0, QColor(207 + d, 207 + d, 207 + d));
- gradient.setColorAt(0.5, QColor(206 + d, 206 + d, 206 + d));
- gradient.setColorAt(1, QColor(201 + d, 201 + d, 201 + d));
+ gradient.setColorAt(0, QColor(216, 216, 216));
+ gradient.setColorAt(0.5, QColor(215, 215, 215));
+ gradient.setColorAt(1, QColor(210, 210, 210));
p->fillRect(rect, gradient);
}
@@ -881,13 +879,6 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg
gbi.size = sz == QAquaSizeSmall ? kHIThemeGrowBoxSizeSmall : kHIThemeGrowBoxSizeNormal;
if (HIThemeGetGrowBoxBounds(&p, &gbi, &r) == noErr) {
int width = 0;
- // Snow Leopard and older get a size grip, as well as QMdiSubWindows.
- if (QSysInfo::MacintoshVersion <= QSysInfo::MV_10_6
-#ifndef QT_NO_MDIAREA
- || (widg && widg->parentWidget() && qobject_cast<QMdiSubWindow *>(widg->parentWidget()))
-#endif
- )
- width = r.size.width;
ret = QSize(width, r.size.height);
}
}
@@ -1830,7 +1821,7 @@ static QCocoaWidget cocoaWidgetFromHIThemeButtonKind(ThemeButtonKind kind)
return w;
}
-NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget, QPoint *offset) const
+NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget) const
{
NSView *bv = cocoaControls[widget];
if (!bv) {
@@ -1903,37 +1894,39 @@ NSView *QMacStylePrivate::cocoaControl(QCocoaWidget widget, QPoint *offset) cons
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);
- else if (widget == QCocoaWidget(QCocoaPullDownButton, QAquaSizeLarge))
- *offset = QPoint(3, -1);
- else if (widget == QCocoaWidget(QCocoaPullDownButton, QAquaSizeSmall))
- *offset = QPoint(2, 1);
- else if (widget == QCocoaWidget(QCocoaPullDownButton, QAquaSizeMini))
- *offset = QPoint(5, 0);
- }
-
return bv;
}
-void QMacStylePrivate::drawNSViewInRect(NSView *view, const QRect &qtRect, QPainter *p, QCocoaDrawRectBlock drawRectBlock) const
+void QMacStylePrivate::drawNSViewInRect(QCocoaWidget widget, NSView *view, const QRect &qtRect, QPainter *p, bool isQWidget, QCocoaDrawRectBlock drawRectBlock) const
{
+ QPoint 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);
+ else if (widget == QCocoaWidget(QCocoaPullDownButton, QAquaSizeLarge))
+ offset = isQWidget ? QPoint(3, -1) : QPoint(-1, -3);
+ else if (widget == QCocoaWidget(QCocoaPullDownButton, QAquaSizeSmall))
+ offset = QPoint(2, 1);
+ else if (widget == QCocoaWidget(QCocoaPullDownButton, QAquaSizeMini))
+ offset = QPoint(5, 0);
+ else if (widget == QCocoaWidget(QCocoaComboBox, QAquaSizeLarge))
+ offset = QPoint(3, 0);
+
QMacCGContext ctx(p);
CGContextSaveGState(ctx);
+ CGContextTranslateCTM(ctx, offset.x(), offset.y());
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext
@@ -2046,8 +2039,8 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
}
pm = QPixmap::fromImage(image);
} else if ((usingYosemiteOrLater && combo && !editableCombo) || button) {
- QPoint offset;
- NSButton *bc = (NSButton *)cocoaControl(cocoaWidgetFromHIThemeButtonKind(bdi->kind), &offset);
+ QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi->kind);
+ NSButton *bc = (NSButton *)cocoaControl(cw);
[bc highlight:pressed];
bc.enabled = bdi->state != kThemeStateUnavailable && bdi->state != kThemeStateUnavailableInactive;
bc.allowsMixedState = YES;
@@ -2057,9 +2050,7 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
QRect rect = opt->rect;
if (bdi->kind == kThemePopupButtonMini)
rect.adjust(0, 0, -5, 0);
- p->translate(offset);
- drawNSViewInRect(bc, rect, p);
- p->translate(-offset);
+ drawNSViewInRect(cw, bc, rect, p);
return;
} else if (usingYosemiteOrLater && editableCombo) {
QImage image = activePixmap.toImage();
@@ -2131,34 +2122,26 @@ QMacStyle::QMacStyle()
: QCommonStyle(*new QMacStylePrivate)
{
Q_D(QMacStyle);
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
- d->receiver = [[NotificationReceiver alloc] initWithPrivate:d];
- NotificationReceiver *receiver = static_cast<NotificationReceiver *>(d->receiver);
+ d->receiver = [[NotificationReceiver alloc] initWithPrivate:d];
+ NotificationReceiver *receiver = static_cast<NotificationReceiver *>(d->receiver);
- [[NSNotificationCenter defaultCenter] addObserver:receiver
- selector:@selector(scrollBarStyleDidChange:)
- name:NSPreferredScrollerStyleDidChangeNotification
- object:nil];
+ [[NSNotificationCenter defaultCenter] addObserver:receiver
+ selector:@selector(scrollBarStyleDidChange:)
+ name:NSPreferredScrollerStyleDidChangeNotification
+ object:nil];
- d->nsscroller = [[NSScroller alloc] init];
- }
-#endif
+ d->nsscroller = [[NSScroller alloc] init];
d->indicatorBranchButtonCell = nil;
}
QMacStyle::~QMacStyle()
{
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
Q_D(QMacStyle);
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
- [reinterpret_cast<NSScroller*>(d->nsscroller) release];
+ [reinterpret_cast<NSScroller*>(d->nsscroller) release];
- NotificationReceiver *receiver = static_cast<NotificationReceiver *>(d->receiver);
- [[NSNotificationCenter defaultCenter] removeObserver:receiver];
- [receiver release];
- }
-#endif
+ NotificationReceiver *receiver = static_cast<NotificationReceiver *>(d->receiver);
+ [[NSNotificationCenter defaultCenter] removeObserver:receiver];
+ [receiver release];
delete qt_mac_backgroundPattern;
qt_mac_backgroundPattern = 0;
@@ -2256,7 +2239,7 @@ void QMacStyle::polish(QWidget* w)
}
if (qobject_cast<QMenu*>(w) || qobject_cast<QComboBoxPrivateContainer *>(w)) {
- w->setWindowOpacity(QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 ? 0.985 : 0.94);
+ w->setWindowOpacity(0.985);
if (!w->testAttribute(Qt::WA_SetPalette)) {
QPixmap px(64, 64);
px.fill(Qt::white);
@@ -2541,9 +2524,7 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW
}
break;
case PM_ScrollBarExtent: {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7 &&
- [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay) {
+ if ([NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay) {
switch (d->aquaSizeConstrain(opt, widget)) {
case QAquaSizeUnknown:
case QAquaSizeLarge:
@@ -2556,7 +2537,6 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW
}
break;
}
-#endif
switch (d->aquaSizeConstrain(opt, widget)) {
case QAquaSizeUnknown:
case QAquaSizeLarge:
@@ -2747,13 +2727,8 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW
ret = 1;
break;
case PM_ScrollView_ScrollBarOverlap:
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
- ret = (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7 &&
- [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay) ?
+ ret = [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay ?
pixelMetric(PM_ScrollBarExtent, opt, widget) : 0;
-#else
- ret = 0;
-#endif
break;
default:
ret = QCommonStyle::pixelMetric(metric, opt, widget);
@@ -3083,11 +3058,7 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w
|| (opt && QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ScrollBar))
#endif
) {
- ret = QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
- if (ret)
- ret = [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay;
-#endif
+ ret = [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay;
}
break;
default:
@@ -3795,9 +3766,8 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
alignment |= Qt::TextHideMnemonic;
if (down)
cr.translate(shiftX, shiftY);
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5
- && (tbstyle == Qt::ToolButtonTextOnly
- || (tbstyle != Qt::ToolButtonTextOnly && !down))) {
+ if (tbstyle == Qt::ToolButtonTextOnly
+ || (tbstyle != Qt::ToolButtonTextOnly && !down)) {
QPen pen = p->pen();
QColor light = down ? Qt::black : Qt::white;
light.setAlphaF(0.375f);
@@ -3812,12 +3782,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
}
proxy()->drawItemText(p, cr, alignment, pal,
tb->state & State_Enabled, tb->text, role);
- if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5 &&
- (tb->state & State_Sunken)) {
- // Draw a "drop shadow" in earlier versions.
- proxy()->drawItemText(p, cr.adjusted(0, 1, 0, 1), alignment,
- tb->palette, tb->state & State_Enabled, tb->text);
- }
}
} else {
QCommonStyle::drawControl(ce, &myTb, p, w);
@@ -3938,17 +3902,15 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
}
if (hasMenu && yosemiteOrLater && bdi.kind != kThemeBevelButton) {
- QCocoaWidget w = cocoaWidgetFromHIThemeButtonKind(bdi.kind);
- QPoint offset;
- NSPopUpButton *pdb = (NSPopUpButton *)d->cocoaControl(QCocoaWidget(QCocoaPullDownButton, w.second), &offset);
+ QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi.kind);
+ cw.first = QCocoaPullDownButton;
+ NSPopUpButton *pdb = (NSPopUpButton *)d->cocoaControl(cw);
[pdb highlight:(bdi.state == kThemeStatePressed)];
pdb.enabled = bdi.state != kThemeStateUnavailable && bdi.state != kThemeStateUnavailableInactive;
QRect rect = opt->rect;
- rect.adjust(0, 0, w.second == QAquaSizeSmall ? -4 : w.second == QAquaSizeMini ? -9 : -6, 0);
- p->translate(offset);
- d->drawNSViewInRect(pdb, rect, p);
- p->translate(-offset);
- } else if (hasMenu && bdi.state == kThemeStatePressed && QSysInfo::macVersion() > QSysInfo::MV_10_6)
+ rect.adjust(0, 0, cw.second == QAquaSizeSmall ? -4 : cw.second == QAquaSizeMini ? -9 : -6, 0);
+ d->drawNSViewInRect(cw, pdb, rect, p, w != 0);
+ } else if (hasMenu && bdi.state == kThemeStatePressed)
d->drawColorlessButton(newRect, &bdi, p, opt);
else
HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0);
@@ -3987,16 +3949,10 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
if (hasMenu && (!yosemiteOrLater || bdi.kind == kThemeBevelButton)) {
int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w);
QRect ir = btn->rect;
- int arrowXOffset = 0;
- if (QSysInfo::macVersion() > QSysInfo::MV_10_6)
- arrowXOffset = bdi.kind == kThemePushButton ? 6 :
+ int arrowXOffset = bdi.kind == kThemePushButton ? 6 :
bdi.kind == kThemePushButtonSmall ? 7 : 8;
- int arrowYOffset;
- if (QSysInfo::macVersion() > QSysInfo::MV_10_6)
- arrowYOffset = bdi.kind == kThemePushButton ? 3 :
+ int arrowYOffset = bdi.kind == kThemePushButton ? 3 :
bdi.kind == kThemePushButtonSmall ? 1 : 2;
- else
- arrowYOffset = bdi.kind == kThemePushButton ? 4 : 2;
if (!w) {
// adjustment for Qt Quick Controls
arrowYOffset -= ir.top();
@@ -4012,17 +3968,10 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
pdi.version = qt_mac_hitheme_version;
pdi.state = tds == kThemeStateInactive ? kThemeStateActive : tds;
pdi.orientation = kThemeArrowDown;
- if (QSysInfo::macVersion() > QSysInfo::MV_10_6) {
- if (bdi.kind == kThemePushButtonMini)
- pdi.size = kThemeArrow5pt;
- else if (bdi.kind == kThemePushButton || bdi.kind == kThemePushButtonSmall)
- pdi.size = kThemeArrow7pt;
- } else {
- if (arrowRect.size.width < 8.)
- pdi.size = kThemeArrow5pt;
- else
- pdi.size = kThemeArrow9pt;
- }
+ if (bdi.kind == kThemePushButtonMini)
+ pdi.size = kThemeArrow5pt;
+ else if (bdi.kind == kThemePushButton || bdi.kind == kThemePushButtonSmall)
+ pdi.size = kThemeArrow7pt;
HIThemeDrawPopupArrow(&arrowRect, &pdi, cg, kHIThemeOrientationNormal);
}
}
@@ -4101,10 +4050,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
QRect textRect = itemTextRect(
btn.fontMetrics, freeContentRect, Qt::AlignCenter, btn.state & State_Enabled, btn.text);
if (hasMenu) {
- if (QSysInfo::macVersion() > QSysInfo::MV_10_6)
- textRect.moveTo(w ? 15 : 11, textRect.top()); // Supports Qt Quick Controls
- else
- textRect.adjust(-1, 0, -1, 0);
+ textRect.moveTo(w ? 15 : 11, textRect.top()); // Supports Qt Quick Controls
}
// Draw the icon:
if (hasIcon) {
@@ -4145,9 +4091,10 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
QStyleOptionComboBox comboCopy = *cb;
comboCopy.direction = Qt::LeftToRight;
- if ((opt->state & QStyle::State_Small) && QSysInfo::macVersion() > QSysInfo::MV_10_6)
- comboCopy.rect.translate(0, w ? (QSysInfo::macVersion() > QSysInfo::MV_10_8 ? 0 : -1) : -2); // Supports Qt Quick Controls
- else if (QSysInfo::macVersion() > QSysInfo::MV_10_8)
+ if (opt->state & QStyle::State_Small)
+ comboCopy.rect.translate(0, w ? (QSysInfo::macVersion() > QSysInfo::MV_10_8 ? 0 : -1) :
+ (QSysInfo::macVersion() > QSysInfo::MV_10_9 ? 0 : -2)); // Supports Qt Quick Controls
+ else if (QSysInfo::macVersion() == QSysInfo::MV_10_9)
comboCopy.rect.translate(0, 1);
QCommonStyle::drawControl(CE_ComboBoxLabel, &comboCopy, p, w);
}
@@ -4284,10 +4231,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
ThemeTabDirection ttd = getTabDirection(myTab.shape);
bool verticalTabs = ttd == kThemeTabWest || ttd == kThemeTabEast;
bool selected = (myTab.state & QStyle::State_Selected);
- bool usingLionOrLater = QSysInfo::MacintoshVersion > QSysInfo::MV_10_6;
bool usingYosemiteOrLater = QSysInfo::MacintoshVersion > QSysInfo::MV_10_9;
- if (usingLionOrLater && selected && !myTab.documentMode
+ if (selected && !myTab.documentMode
&& (!usingYosemiteOrLater || myTab.state & State_Active))
myTab.palette.setColor(QPalette::WindowText, Qt::white);
@@ -4296,7 +4242,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
// outside world, unless they read the source, in which case, it's
// their own fault).
bool nonDefaultFont = p->font() != qt_app_fonts_hash()->value("QComboMenuItem");
- bool isSelectedAndNeedsShadow = selected && usingLionOrLater && !usingYosemiteOrLater;
+ bool isSelectedAndNeedsShadow = selected && !usingYosemiteOrLater;
if (isSelectedAndNeedsShadow || verticalTabs || nonDefaultFont || !tab->icon.isNull()
|| !myTab.leftButtonSize.isEmpty() || !myTab.rightButtonSize.isEmpty()) {
int heightOffset = 0;
@@ -4768,14 +4714,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
case CE_ProgressBarGroove:
break;
case CE_SizeGrip: {
- // We do not draw size grips on versions > 10.6 unless it's a QMdiSubWindow
- if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_6
-#ifndef QT_NO_MDIAREA
- && !(w && w->parentWidget() && qobject_cast<QMdiSubWindow *>(w->parentWidget()))
-#endif
- )
- break;
-
if (w && w->testAttribute(Qt::WA_MacOpaqueSizeGrip)) {
HIThemeGrowBoxDrawInfo gdi;
gdi.version = qt_mac_hitheme_version;
@@ -5444,7 +5382,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
const bool usingYosemiteOrLater = QSysInfo::MacintoshVersion > QSysInfo::MV_10_9;
const bool isHorizontal = slider->orientation == Qt::Horizontal;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
if (cc == CC_ScrollBar && proxy()->styleHint(SH_ScrollBar_Transient, opt, widget)) {
bool wasActive = false;
CGFloat opacity = 0.0;
@@ -5607,9 +5544,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
[NSGraphicsContext restoreGraphicsState];
CGContextRestoreGState(cg);
- } else
-#endif
- {
+ } else {
d->stopAnimation(opt->styleObject);
if (usingYosemiteOrLater && cc == CC_Slider) {
@@ -5641,12 +5576,13 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
// Yosemite demands its blue progress track when no tickmarks are present
if (!(slider->subControls & SC_SliderTickmarks)) {
QCocoaWidgetKind sliderKind = slider->orientation == Qt::Horizontal ? QCocoaHorizontalSlider : QCocoaVerticalSlider;
- NSSlider *sl = (NSSlider *)d->cocoaControl(QCocoaWidget(sliderKind, QAquaSizeLarge), 0);
+ QCocoaWidget cw = QCocoaWidget(sliderKind, QAquaSizeLarge);
+ NSSlider *sl = (NSSlider *)d->cocoaControl(cw);
sl.minValue = slider->minimum;
sl.maxValue = slider->maximum;
sl.intValue = slider->sliderValue;
sl.enabled = slider->state & QStyle::State_Enabled;
- d->drawNSViewInRect(sl, opt->rect, p, ^(NSRect rect, CGContextRef ctx) {
+ d->drawNSViewInRect(cw, sl, opt->rect, p, widget != 0, ^(NSRect rect, CGContextRef ctx) {
if (slider->upsideDown) {
if (isHorizontal) {
CGContextTranslateCTM(ctx, rect.size.width, 0);
@@ -5819,12 +5755,21 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
break;
case CC_ComboBox:
if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)){
+ const bool usingYosemiteOrLater = QSysInfo::MacintoshVersion > QSysInfo::MV_10_9;
HIThemeButtonDrawInfo bdi;
- d->initComboboxBdi(combo, &bdi, widget, d->getDrawState(opt->state));
+ d->initComboboxBdi(combo, &bdi, widget, tds);
+ HIRect rect = qt_hirectForQRect(combo->rect);
+ if (combo->editable && usingYosemiteOrLater)
+ rect.origin.y += tds == kThemeStateInactive ? 1 : 2;
if (tds != kThemeStateInactive)
- QMacStylePrivate::drawCombobox(qt_hirectForQRect(combo->rect), bdi, p);
- else
- d->drawColorlessButton(qt_hirectForQRect(combo->rect), &bdi, p, opt);
+ QMacStylePrivate::drawCombobox(rect, bdi, p);
+ else if (!widget && combo->editable && usingYosemiteOrLater) {
+ QCocoaWidget cw = cocoaWidgetFromHIThemeButtonKind(bdi.kind);
+ NSView *cb = d->cocoaControl(cw);
+ QRect r = combo->rect.adjusted(3, 0, 0, 0);
+ d->drawNSViewInRect(cw, cb, r, p, widget != 0);
+ } else
+ d->drawColorlessButton(rect, &bdi, p, opt);
}
break;
case CC_TitleBar:
@@ -5880,11 +5825,6 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
uint sc = SC_TitleBarMinButton;
ThemeTitleBarWidget tbw = kThemeWidgetCollapseBox;
bool active = titlebar->state & State_Active;
- if (QSysInfo::macVersion() < QSysInfo::MV_10_6) {
- int border = 2;
- titleBarRect.origin.x += border;
- titleBarRect.origin.y -= border;
- }
while (sc <= SC_TitleBarCloseButton) {
if (sc & titlebar->subControls) {
@@ -6023,23 +5963,12 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
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) {
+ } else {
static QPixmap pm(QLatin1String(":/qt-project.org/mac/style/images/leopard-unified-toolbar-on.png"));
p->save();
p->setRenderHint(QPainter::SmoothPixmapTransform);
QStyleHelper::drawBorderPixmap(pm, p, tb->rect, 2, 2, 2, 2);
p->restore();
- } else {
- QPen oldPen = p->pen();
- p->setPen(QColor(0, 0, 0, 0x3a));
- p->fillRect(tb->rect.adjusted(1, 1, -1, -1), QColor(0, 0, 0, 0x12));
- p->drawLine(tb->rect.left() + 1, tb->rect.top(),
- tb->rect.right() - 1, tb->rect.top());
- p->drawLine(tb->rect.left() + 1, tb->rect.bottom(),
- tb->rect.right() - 1, tb->rect.bottom());
- p->drawLine(tb->rect.topLeft(), tb->rect.bottomLeft());
- p->drawLine(tb->rect.topRight(), tb->rect.bottomRight());
- p->setPen(oldPen);
}
}
proxy()->drawControl(CE_ToolButtonLabel, opt, p, widget);
@@ -6192,10 +6121,7 @@ QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc,
HIRect macSBRect = qt_hirectForQRect(sb->rect);
ControlPartCode part;
bool reverseHorizontal = (sb->direction == Qt::RightToLeft
- && sb->orientation == Qt::Horizontal
- && (!sb->upsideDown ||
- (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4
- && sb->upsideDown)));
+ && sb->orientation == Qt::Horizontal);
if (HIThemeHitTestScrollBarArrows(&macSBRect, &sbi, sb->orientation == Qt::Horizontal,
&pos, 0, &part)) {
if (part == kControlUpButtonPart)
@@ -6381,6 +6307,8 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op
switch (sc) {
case SC_ComboBoxEditField:{
ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi);
+ if (QSysInfo::MacintoshVersion > QSysInfo::MV_10_9)
+ ret.setHeight(ret.height() - 1);
break; }
case SC_ComboBoxArrow:{
ret = QMacStylePrivate::comboboxEditBounds(combo->rect, bdi);
@@ -6822,10 +6750,13 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
sz.rwidth() += 10;
sz.rheight() += 10;
return sz;
- case CT_ComboBox:
+ case CT_ComboBox: {
sz.rwidth() += 50;
- sz.rheight() += 2;
+ const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt);
+ if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_10 || (cb && !cb->editable))
+ sz.rheight() += 2;
break;
+ }
case CT_Menu: {
QStyleHintReturnMask menuMask;
QStyleOption myOption = *opt;
diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h
index 080f944ef8..89a95713b7 100644
--- a/src/widgets/styles/qmacstyle_mac_p_p.h
+++ b/src/widgets/styles/qmacstyle_mac_p_p.h
@@ -204,9 +204,9 @@ public:
void setAutoDefaultButton(QObject *button) const;
- NSView *cocoaControl(QCocoaWidget widget, QPoint *offset) const;
+ NSView *cocoaControl(QCocoaWidget widget) const;
- void drawNSViewInRect(NSView *view, const QRect &rect, QPainter *p, QCocoaDrawRectBlock drawRectBlock = nil) const;
+ void drawNSViewInRect(QCocoaWidget widget, NSView *view, const QRect &rect, QPainter *p, bool isQWidget = true, QCocoaDrawRectBlock drawRectBlock = nil) const;
void resolveCurrentNSView(QWindow *window);
public:
@@ -222,10 +222,8 @@ public:
mutable QPointer<QFocusFrame> focusWidget;
CFAbsoluteTime defaultButtonStart;
bool mouseDown;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
void* receiver;
void *nsscroller;
-#endif
void *indicatorBranchButtonCell;
NSView *backingStoreNSView;
QHash<QCocoaWidget, NSView *> cocoaControls;
diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp
index 7c4d239894..109a0ea451 100644
--- a/src/widgets/styles/qstyle.cpp
+++ b/src/widgets/styles/qstyle.cpp
@@ -1772,8 +1772,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value SH_ComboBox_Popup Allows popups as a combobox drop-down
menu.
- \omitvalue SH_ComboBox_UseNativePopup Whether we should use a native popup.
- Only supported for non-editable combo boxes on Mac OS X so far.
+ \omitvalue SH_ComboBox_UseNativePopup
\value SH_Workspace_FillSpaceOnMaximize The workspace should
maximize the client area.
diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h
index 12ada3f6e4..fa15a0d4c4 100644
--- a/src/widgets/styles/qstyle.h
+++ b/src/widgets/styles/qstyle.h
@@ -698,6 +698,8 @@ public:
SH_ToolTip_FallAsleepDelay,
SH_Widget_Animate,
SH_Splitter_OpaqueResize,
+ // Whether we should use a native popup.
+ // Only supported for non-editable combo boxes on Mac OS X so far.
SH_ComboBox_UseNativePopup,
SH_LineEdit_PasswordMaskDelay,
SH_TabBar_ChangeCurrentDelay,
diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp
index 3619c3ff29..9deeb725f9 100644
--- a/src/widgets/styles/qwindowsstyle.cpp
+++ b/src/widgets/styles/qwindowsstyle.cpp
@@ -1832,6 +1832,20 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
}
return;
#endif // QT_NO_DOCKWIDGET
+#ifndef QT_NO_COMBOBOX
+ case CE_ComboBoxLabel:
+ if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
+ if (cb->state & State_HasFocus) {
+ p->setPen(cb->palette.highlightedText().color());
+ p->setBackground(cb->palette.highlight());
+ } else {
+ p->setPen(cb->palette.text().color());
+ p->setBackground(cb->palette.background());
+ }
+ }
+ QCommonStyle::drawControl(ce, opt, p, widget);
+ break;
+#endif // QT_NO_COMBOBOX
default:
QCommonStyle::drawControl(ce, opt, p, widget);
}
diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp
index 007952192a..463b120e04 100644
--- a/src/widgets/styles/qwindowsvistastyle.cpp
+++ b/src/widgets/styles/qwindowsvistastyle.cpp
@@ -1473,7 +1473,11 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
break;
}
#endif // QT_NO_ITEMVIEWS
-
+#ifndef QT_NO_COMBOBOX
+ case CE_ComboBoxLabel:
+ QCommonStyle::drawControl(element, option, painter, widget);
+ break;
+#endif // QT_NO_COMBOBOX
default:
QWindowsXPStyle::drawControl(element, option, painter, widget);
break;
diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp
index c18bbb3431..c1f7b599b3 100644
--- a/src/widgets/styles/qwindowsxpstyle.cpp
+++ b/src/widgets/styles/qwindowsxpstyle.cpp
@@ -963,7 +963,8 @@ void QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa
QImage img;
if (!haveCachedPixmap) { // If the pixmap is not cached, generate it! -------------------------
- buffer(w, h); // Ensure a buffer of at least (w, h) in size
+ if (!buffer(w, h)) // Ensure a buffer of at least (w, h) in size
+ return;
HDC dc = bufferHDC();
// Clear the buffer
@@ -2539,7 +2540,7 @@ QRect QWindowsXPStylePrivate::scrollBarGripperBounds(QStyle::State flags, const
const int hSpace = theme->rect.width() - size.width();
const int vSpace = theme->rect.height() - size.height();
- const bool sufficientSpace = horizontal && hSpace > (contentsMargin.left() + contentsMargin.right())
+ const bool sufficientSpace = (horizontal && hSpace > (contentsMargin.left() + contentsMargin.right()))
|| vSpace > contentsMargin.top() + contentsMargin.bottom();
return sufficientSpace ? QRect(theme->rect.topLeft() + QPoint(hSpace, vSpace) / 2, size) : QRect();
}