diff options
Diffstat (limited to 'src/widgets/styles')
65 files changed, 2374 insertions, 478 deletions
diff --git a/src/widgets/styles/images/toolbar-ext.png b/src/widgets/styles/images/toolbar-ext.png Binary files differnew file mode 100644 index 0000000000..37bd403ff8 --- /dev/null +++ b/src/widgets/styles/images/toolbar-ext.png diff --git a/src/widgets/styles/images/toolbar-ext@2x.png b/src/widgets/styles/images/toolbar-ext@2x.png Binary files differnew file mode 100644 index 0000000000..6fc729efb0 --- /dev/null +++ b/src/widgets/styles/images/toolbar-ext@2x.png diff --git a/src/widgets/styles/qandroidstyle.cpp b/src/widgets/styles/qandroidstyle.cpp new file mode 100644 index 0000000000..d82a06987a --- /dev/null +++ b/src/widgets/styles/qandroidstyle.cpp @@ -0,0 +1,1601 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWidgets module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidstyle_p.h" + +#if !defined(QT_NO_STYLE_ANDROID) || defined(QT_PLUGIN) + +#include <QFile> +#include <QFont> +#include <QApplication> +#include <QTime> +#include <qdrawutil.h> +#include <QPixmapCache> +#include <QFileInfo> +#include <QStyleOption> +#include <QPainter> +#include <QJsonDocument> +#include <QJsonObject> + +#include <QDebug> + +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; +} + + +QAndroidStyle::QAndroidStyle() + : QCommonStyle() +{ + QString stylePath(QLatin1String(qgetenv("MINISTRO_ANDROID_STYLE_PATH"))); + + if (stylePath.isEmpty()) + stylePath = QLatin1String("/data/data/org.kde.necessitas.ministro/files/qt/style/"); + Q_ASSERT(!stylePath.isEmpty()); + + 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; + } + + if (!document.isObject()) { + qCritical() << "Style.json does not contain a valid style."; + return; + } + + QJsonObject object = document.object(); + for (QJsonObject::const_iterator objectIterator = object.constBegin(); + objectIterator != object.constEnd(); + ++objectIterator) { + QString key = objectIterator.key(); + QJsonValue value = objectIterator.value(); + if (!value.isObject()) { + qWarning("Style.json structure is unrecognized."); + continue; + } + + QJsonObject item = value.toObject(); + QJsonObject::const_iterator attributeIterator = item.find(QLatin1String("qtClass")); + if (attributeIterator != item.constEnd()) { + // The item has palette and font information for a specific Qt Class (e.g. QWidget, QPushButton, etc.) + const QString qtClassName = attributeIterator.value().toString(); + + // 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); + } + QApplication::setFont(font, qtClassName.toUtf8()); + // Extract font information + + // Extract palette information + QPalette palette; + 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()))); + palette.setColor(QPalette::Window, Qt::black); + QApplication::setPalette(palette, qtClassName.toUtf8()); + if (QLatin1String("QWidget") == qtClassName) + m_standardPalette = palette; + // Extract palette information + } + QAndroidStyle::ItemType itemType = qtControl(key); + if (QC_UnknownType == itemType) + continue; + + switch (itemType) { + case QC_Checkbox: + case QC_RadioButton: + m_androidControlsHash[int(itemType)] = new AndroidCompoundButtonControl(item.toVariantMap(), + itemType); + break; + + case QC_ProgressBar: + m_androidControlsHash[int(itemType)] = new AndroidProgressBarControl(item.toVariantMap(), + itemType); + break; + + case QC_Slider: + m_androidControlsHash[int(itemType)] = new AndroidSeekBarControl(item.toVariantMap(), + itemType); + break; + + case QC_Combobox: + m_androidControlsHash[int(itemType)] = new AndroidSpinnerControl(item.toVariantMap(), + itemType); + break; + + default: + m_androidControlsHash[int(itemType)] = new AndroidControl(item.toVariantMap(), + itemType); + break; + } + } + QApplication::setPalette(QApplication::palette("simple_list_item"), "QListView"); + QApplication::setFont(QApplication::font("simple_list_item"), "QListView"); + QApplication::setPalette(QApplication::palette("simple_list_item"), "QAbstractItemView"); + QApplication::setFont(QApplication::font("simple_list_item"), "QAbstractItemView"); +} + +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")) + return QC_Button; + if (android == QLatin1String("editTextStyle")) + return QC_EditText; + if (android == QLatin1String("radioButtonStyle")) + return QC_RadioButton; + if (android == QLatin1String("checkboxStyle")) + return QC_Checkbox; + if (android == QLatin1String("textViewStyle")) + return QC_View; + if (android == QLatin1String("buttonStyleToggle")) + return QC_Switch; + if (android == QLatin1String("spinnerStyle")) + return QC_Combobox; + if (android == QLatin1String("progressBarStyleHorizontal")) + return QC_ProgressBar; + if (android == QLatin1String("seekBarStyle")) + return QC_Slider; + + return QC_UnknownType; +} + +QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::ComplexControl control) +{ + switch (control) { + case CC_ComboBox: + return QC_Combobox; + case CC_Slider: + return QC_Slider; + case CC_GroupBox: + return QC_View; + default: + return QC_UnknownType; + } +} + +QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::ContentsType contentsType) +{ + switch (contentsType) { + case CT_PushButton: + return QC_Button; + case CT_CheckBox: + return QC_Checkbox; + case CT_RadioButton: + return QC_RadioButton; + case CT_ComboBox: + return QC_Combobox; + case CT_ProgressBar: + return QC_ProgressBar; + case CT_Slider: + return QC_Slider; + case CT_TabWidget: + return QC_Tab; + case CT_TabBarTab: + return QC_TabButton; + case CT_LineEdit: + return QC_EditText; + case CT_GroupBox: + return QC_GroupBox; + default: + return QC_UnknownType; + } +} + +QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::ControlElement controlElement) +{ + switch (controlElement) { + case CE_PushButton: + case CE_PushButtonBevel: + case CE_PushButtonLabel: + return QC_Button; + + case CE_CheckBox: + case CE_CheckBoxLabel: + return QC_Checkbox; + + case CE_RadioButton: + case CE_RadioButtonLabel: + return QC_RadioButton; + + case CE_TabBarTab: + case CE_TabBarTabShape: + case CE_TabBarTabLabel: + return QC_Tab; + + case CE_ProgressBar: + case CE_ProgressBarGroove: + case CE_ProgressBarContents: + case CE_ProgressBarLabel: + return QC_ProgressBar; + + case CE_ComboBoxLabel: + return QC_Combobox; + + default: + return QC_UnknownType; + } +} + +QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::PrimitiveElement primitiveElement) +{ + switch (primitiveElement) { + case QStyle::PE_PanelLineEdit: + case QStyle::PE_FrameLineEdit: + return QC_EditText; + + case QStyle::PE_FrameWindow: + case QStyle::PE_Widget: + case QStyle::PE_Frame: + case QStyle::PE_FrameFocusRect: + return QC_View; + default: + return QC_UnknownType; + } +} + +QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::SubElement subElement) +{ + switch (subElement) { + case QStyle::SE_LineEditContents: + return QC_EditText; + + case QStyle::SE_PushButtonContents: + case QStyle::SE_PushButtonFocusRect: + return QC_Button; + + case SE_RadioButtonContents: + return QC_RadioButton; + + case SE_CheckBoxContents: + return QC_Checkbox; + + default: + return QC_UnknownType; + } +} + +void QAndroidStyle::drawPrimitive(PrimitiveElement pe, + const QStyleOption *opt, + QPainter *p, + const QWidget *w) const +{ + const ItemType itemType = qtControl(pe); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) + it.value()->drawControl(opt, p, w); + else + QCommonStyle::drawPrimitive(pe, opt, p, w); +} + + +void QAndroidStyle::drawControl(QStyle::ControlElement element, + const QStyleOption *opt, + QPainter *p, + const QWidget *w) const +{ + const ItemType itemType = qtControl(element); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) { + it.value()->drawControl(opt, p, w); + + switch (itemType) { + case QC_Button: + if (const QStyleOptionButton *buttonOption = + qstyleoption_cast<const QStyleOptionButton *>(opt)) { + QMargins padding = it.value()->padding(); + QStyleOptionButton copy (*buttonOption); + copy.rect.adjust(padding.left(), padding.top(), -padding.right(), -padding.bottom()); + QCommonStyle::drawControl(CE_PushButtonLabel, ©, p, w); + } + break; + case QC_Checkbox: + case QC_RadioButton: + if (const QStyleOptionButton *btn = + qstyleoption_cast<const QStyleOptionButton *>(opt)) { + const bool isRadio = (element == CE_RadioButton); + QStyleOptionButton subopt(*btn); + subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents + : SE_CheckBoxContents, btn, w); + QCommonStyle::drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, p, w); + } + break; + case QC_Combobox: + if (const QStyleOptionComboBox *comboboxOption = + qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { + QMargins padding = it.value()->padding(); + QStyleOptionComboBox copy (*comboboxOption); + copy.rect.adjust(padding.left(), padding.top(), -padding.right(), -padding.bottom()); + p->setFont(QApplication::font("simple_spinner_item")); + p->setPen(QApplication::palette("QPushButton").color(QPalette::Active, QPalette::Text)); + QCommonStyle::drawControl(CE_ComboBoxLabel, comboboxOption, p, w); + } + break; + default: + break; + } + } + else + QCommonStyle::drawControl(element, opt, p, w); +} + +QRect QAndroidStyle::subElementRect(SubElement subElement, + const QStyleOption *option, + const QWidget *widget) const +{ + const ItemType itemType = qtControl(subElement); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) + return it.value()->subElementRect(subElement, option, widget); + return QCommonStyle::subElementRect(subElement, option, widget); +} + +void QAndroidStyle::drawComplexControl(ComplexControl cc, + const QStyleOptionComplex *opt, + QPainter *p, + const QWidget *widget) const +{ + const ItemType itemType = qtControl(cc); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) + it.value()->drawControl(opt, p, widget); + else + QCommonStyle::drawComplexControl(cc, opt, p, widget); +} + +QStyle::SubControl QAndroidStyle::hitTestComplexControl(ComplexControl cc, + const QStyleOptionComplex *opt, + const QPoint &pt, + const QWidget *widget) const +{ + const ItemType itemType = qtControl(cc); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) { + switch (cc) { + case CC_Slider: + if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { + QRect r = it.value()->subControlRect(slider, SC_SliderHandle, widget); + if (r.isValid() && r.contains(pt)) { + return SC_SliderHandle; + } else { + r = it.value()->subControlRect(slider, SC_SliderGroove, widget); + if (r.isValid() && r.contains(pt)) + return SC_SliderGroove; + } + } + break; + default: + break; + } + } + return QCommonStyle::hitTestComplexControl(cc, opt, pt, widget); +} + +QRect QAndroidStyle::subControlRect(ComplexControl cc, + const QStyleOptionComplex *opt, + SubControl sc, + const QWidget *widget) const +{ + const ItemType itemType = qtControl(cc); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) + return it.value()->subControlRect(opt, sc, widget); + return QCommonStyle::subControlRect(cc, opt, sc, widget); +} + +int QAndroidStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, + const QWidget *widget) const +{ + switch (metric) { + case PM_ButtonMargin: + case PM_FocusFrameVMargin: + case PM_FocusFrameHMargin: + case PM_ComboBoxFrameWidth: + case PM_SpinBoxFrameWidth: + return 0; + default: + return QCommonStyle::pixelMetric(metric, option, widget); + } + +} + +QSize QAndroidStyle::sizeFromContents(ContentsType ct, + const QStyleOption *opt, + const QSize &contentsSize, + const QWidget *w) const +{ + QSize sz=QCommonStyle::sizeFromContents(ct, opt, contentsSize, w); + const ItemType itemType = qtControl(ct); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) + return it.value()->sizeFromContents(opt, sz, w); + return sz; +} + +QPixmap QAndroidStyle::standardPixmap(StandardPixmap standardPixmap, + const QStyleOption *opt, + const QWidget *widget) const +{ + return QCommonStyle::standardPixmap(standardPixmap, opt, widget); +} + +QPixmap QAndroidStyle::generatedIconPixmap(QIcon::Mode iconMode, + const QPixmap &pixmap, + const QStyleOption *opt) const +{ + return QCommonStyle::generatedIconPixmap(iconMode, pixmap, opt); +} + +QPalette QAndroidStyle::standardPalette() const +{ + return m_standardPalette; +} + +QAndroidStyle::AndroidDrawable::AndroidDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) +{ + initPadding(drawable); + m_itemType = itemType; +} + +QAndroidStyle::AndroidDrawable::~AndroidDrawable() +{ +} + +void QAndroidStyle::AndroidDrawable::initPadding(const QVariantMap &drawable) +{ + QVariantMap::const_iterator it = drawable.find(QLatin1String("padding")); + if (it != drawable.end()) + m_padding = extractMargins(it.value().toMap()); +} + +const QMargins &QAndroidStyle::AndroidDrawable::padding() const +{ + return m_padding; +} + +QSize QAndroidStyle::AndroidDrawable::size() const +{ + if (type() == Image || type() == NinePatch) + return static_cast<const QAndroidStyle::AndroidImageDrawable *>(this)->size(); + + return QSize(); +} + +QAndroidStyle::AndroidDrawable * QAndroidStyle::AndroidDrawable::fromMap(const QVariantMap &drawable, + ItemType itemType) +{ + const QString type = drawable.value(QLatin1String("type")).toString(); + if (type == QLatin1String("image")) + return new QAndroidStyle::AndroidImageDrawable(drawable, itemType); + if (type == QLatin1String("9patch")) + return new QAndroidStyle::Android9PatchDrawable(drawable, itemType); + if (type == QLatin1String("stateslist")) + return new QAndroidStyle::AndroidStateDrawable(drawable, itemType); + if (type == QLatin1String("layer")) + return new QAndroidStyle::AndroidLayerDrawable(drawable, itemType); + if (type == QLatin1String("gradient")) + return new QAndroidStyle::AndroidGradientDrawable(drawable, itemType); + if (type == QLatin1String("clipDrawable")) + return new QAndroidStyle::AndroidClipDrawable(drawable, itemType); + if (type == QLatin1String("color")) + return new QAndroidStyle::AndroidColorDrawable(drawable, itemType); + return 0; +} + +QMargins QAndroidStyle::AndroidDrawable::extractMargins(const QVariantMap &value) +{ + QMargins m; + m.setLeft(value.value(QLatin1String("left")).toInt()); + m.setRight(value.value(QLatin1String("right")).toInt()); + m.setTop(value.value(QLatin1String("top")).toInt()); + m.setBottom(value.value(QLatin1String("bottom")).toInt()); + return m; +} + + +QAndroidStyle::AndroidImageDrawable::AndroidImageDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidDrawable(drawable, itemType) +{ + m_filePath = drawable.value(QLatin1String("path")).toString(); + m_size.setHeight(drawable.value(QLatin1String("height")).toInt()); + m_size.setWidth(drawable.value(QLatin1String("width")).toInt()); +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidImageDrawable::type() const +{ + return QAndroidStyle::Image; +} + +void QAndroidStyle::AndroidImageDrawable::draw(QPainter *painter, const QStyleOption *opt) 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); + } + + painter->drawPixmap(opt->rect.x(), (opt->rect.height() - pm.height()) / 2, pm); +} + +QSize QAndroidStyle::AndroidImageDrawable::size() const +{ + return m_size; +} + +QAndroidStyle::AndroidColorDrawable::AndroidColorDrawable(const QVariantMap &drawable, + ItemType itemType) + : AndroidDrawable(drawable, itemType) +{ + m_color.setRgba(QRgb(drawable.value(QLatin1String("color")).toInt())); +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidColorDrawable::type() const +{ + return QAndroidStyle::Color; +} + +void QAndroidStyle::AndroidColorDrawable::draw(QPainter *painter, const QStyleOption *opt) const +{ + painter->fillRect(opt->rect, m_color); +} + +QAndroidStyle::Android9PatchDrawable::Android9PatchDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidImageDrawable(drawable.value(QLatin1String("drawable")).toMap(), itemType) +{ + initPadding(drawable); + QVariantMap chunk = drawable.value(QLatin1String("chunkInfo")).toMap(); + extractIntArray(chunk.value(QLatin1String("xdivs")).toList(), m_chunkData.xDivs); + extractIntArray(chunk.value(QLatin1String("ydivs")).toList(), m_chunkData.yDivs); + extractIntArray(chunk.value(QLatin1String("colors")).toList(), m_chunkData.colors); +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::Android9PatchDrawable::type() const +{ + return QAndroidStyle::NinePatch; +} + +int QAndroidStyle::Android9PatchDrawable::calculateStretch(int boundsLimit, + int startingPoint, + int srcSpace, + int numStrechyPixelsRemaining, + int numFixedPixelsRemaining) +{ + int spaceRemaining = boundsLimit - startingPoint; + int stretchySpaceRemaining = spaceRemaining - numFixedPixelsRemaining; + return (float(srcSpace) * stretchySpaceRemaining / numStrechyPixelsRemaining + .5); +} + +void QAndroidStyle::Android9PatchDrawable::extractIntArray(const QVariantList &values, + QVector<int> & array) +{ + foreach (QVariant value, values) + array << value.toInt(); +} + + +void QAndroidStyle::Android9PatchDrawable::draw(QPainter * painter, const QStyleOption *opt) const +{ + if (m_hashKey.isEmpty()) + m_hashKey = QFileInfo(m_filePath).fileName(); + + QPixmap pixmap; + if (!QPixmapCache::find(m_hashKey, &pixmap)) { + pixmap.load(m_filePath); + QPixmapCache::insert(m_hashKey, pixmap); + } + + const QRect &bounds=opt->rect; + + // shamelessly stolen from Android's sources (NinepatchImpl.cpp) and adapted for Qt + const int pixmapWidth = pixmap.width(); + const int pixmapHeight = pixmap.height(); + + if (bounds.isNull() || !pixmapWidth || !pixmapHeight) + return; + + QPainter::RenderHints savedHints = painter->renderHints(); + + // The patchs doesn't need smooth transform ! + painter->setRenderHints(QPainter::SmoothPixmapTransform, false); + + QRectF dst; + QRectF src; + + const qint32 x0 = m_chunkData.xDivs[0]; + const qint32 y0 = m_chunkData.yDivs[0]; + const quint8 numXDivs = m_chunkData.xDivs.size(); + const quint8 numYDivs = m_chunkData.yDivs.size(); + int i; + int j; + int colorIndex = 0; + quint32 color; + bool xIsStretchable; + const bool initialXIsStretchable = (x0 == 0); + bool yIsStretchable = (y0 == 0); + const int bitmapWidth = pixmap.width(); + const int bitmapHeight = pixmap.height(); + + int *dstRights = static_cast<int *>(alloca((numXDivs + 1) * sizeof(int))); + bool dstRightsHaveBeenCached = false; + + int numStretchyXPixelsRemaining = 0; + for (i = 0; i < numXDivs; i += 2) + numStretchyXPixelsRemaining += m_chunkData.xDivs[i + 1] - m_chunkData.xDivs[i]; + + int numFixedXPixelsRemaining = bitmapWidth - numStretchyXPixelsRemaining; + int numStretchyYPixelsRemaining = 0; + for (i = 0; i < numYDivs; i += 2) + numStretchyYPixelsRemaining += m_chunkData.yDivs[i + 1] - m_chunkData.yDivs[i]; + + int numFixedYPixelsRemaining = bitmapHeight - numStretchyYPixelsRemaining; + src.setTop(0); + dst.setTop(bounds.top()); + // The first row always starts with the top being at y=0 and the bottom + // being either yDivs[1] (if yDivs[0]=0) of yDivs[0]. In the former case + // the first row is stretchable along the Y axis, otherwise it is fixed. + // The last row always ends with the bottom being bitmap.height and the top + // being either yDivs[numYDivs-2] (if yDivs[numYDivs-1]=bitmap.height) or + // yDivs[numYDivs-1]. In the former case the last row is stretchable along + // the Y axis, otherwise it is fixed. + // + // The first and last columns are similarly treated with respect to the X + // axis. + // + // The above is to help explain some of the special casing that goes on the + // code below. + + // The initial yDiv and whether the first row is considered stretchable or + // not depends on whether yDiv[0] was zero or not. + for (j = yIsStretchable ? 1 : 0; + j <= numYDivs && src.top() < bitmapHeight; + j++, yIsStretchable = !yIsStretchable) { + src.setLeft(0); + dst.setLeft(bounds.left()); + if (j == numYDivs) { + src.setBottom(bitmapHeight); + dst.setBottom(bounds.bottom()); + } else { + src.setBottom(m_chunkData.yDivs[j]); + const int srcYSize = src.bottom() - src.top(); + if (yIsStretchable) { + dst.setBottom(dst.top() + calculateStretch(bounds.bottom(), dst.top(), + srcYSize, + numStretchyYPixelsRemaining, + numFixedYPixelsRemaining)); + numStretchyYPixelsRemaining -= srcYSize; + } else { + dst.setBottom(dst.top() + srcYSize); + numFixedYPixelsRemaining -= srcYSize; + } + } + + xIsStretchable = initialXIsStretchable; + // The initial xDiv and whether the first column is considered + // stretchable or not depends on whether xDiv[0] was zero or not. + for (i = xIsStretchable ? 1 : 0; + i <= numXDivs && src.left() < bitmapWidth; + i++, xIsStretchable = !xIsStretchable) { + color = m_chunkData.colors[colorIndex++]; + if (i == numXDivs) { + src.setRight(bitmapWidth); + dst.setRight(bounds.right()); + } else { + src.setRight(m_chunkData.xDivs[i]); + if (dstRightsHaveBeenCached) { + dst.setRight(dstRights[i]); + } else { + const int srcXSize = src.right() - src.left(); + if (xIsStretchable) { + dst.setRight(dst.left() + calculateStretch(bounds.right(), dst.left(), + srcXSize, + numStretchyXPixelsRemaining, + numFixedXPixelsRemaining)); + numStretchyXPixelsRemaining -= srcXSize; + } else { + dst.setRight(dst.left() + srcXSize); + numFixedXPixelsRemaining -= srcXSize; + } + dstRights[i] = dst.right(); + } + } + // If this horizontal patch is too small to be displayed, leave + // the destination left edge where it is and go on to the next patch + // in the source. + if (src.left() >= src.right()) { + src.setLeft(src.right()); + continue; + } + // Make sure that we actually have room to draw any bits + if (dst.right() <= dst.left() || dst.bottom() <= dst.top()) { + goto nextDiv; + } + // If this patch is transparent, skip and don't draw. + if (color == TRANSPARENT_COLOR) + goto nextDiv; + if (color != NO_COLOR) + painter->fillRect(dst, (QRgb)color); + else + painter->drawPixmap(dst, pixmap, src); +nextDiv: + src.setLeft(src.right()); + dst.setLeft(dst.right()); + } + src.setTop(src.bottom()); + dst.setTop(dst.bottom()); + dstRightsHaveBeenCached = true; + } + painter->setRenderHints(savedHints); +} + +QAndroidStyle::AndroidGradientDrawable::AndroidGradientDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidDrawable(drawable, itemType), m_orientation(TOP_BOTTOM) +{ + m_radius = drawable.value(QLatin1String("radius")).toInt(); + if (m_radius < 0) + m_radius = 0; + + QVariantList colors = drawable.value(QLatin1String("colors")).toList(); + QVariantList positions = drawable.value(QLatin1String("positions")).toList(); + int min=colors.size() < positions.size() ? colors.size() : positions.size(); + for (int i = 0; i < min; i++) + m_gradient.setColorAt(positions.at(i).toDouble(), (QRgb)colors.at(i).toInt()); + + QByteArray orientation=drawable.value(QLatin1String("orientation")).toByteArray(); + if (orientation == "TOP_BOTTOM") // draw the gradient from the top to the bottom + m_orientation = TOP_BOTTOM; + else if (orientation == "TR_BL") // draw the gradient from the top-right to the bottom-left + m_orientation = TR_BL; + else if (orientation == "RIGHT_LEFT") // draw the gradient from the right to the left + m_orientation = RIGHT_LEFT; + else if (orientation == "BR_TL") // draw the gradient from the bottom-right to the top-left + m_orientation = BR_TL; + else if (orientation == "BOTTOM_TOP") // draw the gradient from the bottom to the top + m_orientation = BOTTOM_TOP; + else if (orientation == "BL_TR") // draw the gradient from the bottom-left to the top-right + m_orientation = BL_TR; + else if (orientation == "LEFT_RIGHT") // draw the gradient from the left to the right + m_orientation = LEFT_RIGHT; + else if (orientation == "TL_BR") // draw the gradient from the top-left to the bottom-right + m_orientation = TL_BR; + else + qWarning("AndroidGradientDrawable: unknown orientation"); +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidGradientDrawable::type() const +{ + return QAndroidStyle::Gradient; +} + +void QAndroidStyle::AndroidGradientDrawable::draw(QPainter *painter, const QStyleOption *opt) const +{ + const int width = opt->rect.width(); + const int height = opt->rect.height(); + switch (m_orientation) { + case TOP_BOTTOM: + // draw the gradient from the top to the bottom + m_gradient.setStart(width/2,0); + m_gradient.setFinalStop(width/2,height); + break; + case TR_BL: + // draw the gradient from the top-right to the bottom-left + m_gradient.setStart(width,0); + m_gradient.setFinalStop(0,height); + break; + case RIGHT_LEFT: + // draw the gradient from the right to the left + m_gradient.setStart(width,height/2); + m_gradient.setFinalStop(0,height/2); + break; + case BR_TL: + // draw the gradient from the bottom-right to the top-left + m_gradient.setStart(width,height); + m_gradient.setFinalStop(0,0); + break; + case BOTTOM_TOP: + // draw the gradient from the bottom to the top + m_gradient.setStart(width/2,height); + m_gradient.setFinalStop(width/2,0); + break; + case BL_TR: + // draw the gradient from the bottom-left to the top-right + m_gradient.setStart(0,height); + m_gradient.setFinalStop(width,0); + break; + case LEFT_RIGHT: + // draw the gradient from the left to the right + m_gradient.setStart(0,height/2); + m_gradient.setFinalStop(width,height/2); + break; + case TL_BR: + // draw the gradient from the top-left to the bottom-right + m_gradient.setStart(0,0); + m_gradient.setFinalStop(width,height); + break; + } + + const QBrush &oldBrush = painter->brush(); + const QPen oldPen = painter->pen(); + painter->setPen(Qt::NoPen); + painter->setBrush(m_gradient); + painter->drawRoundedRect(opt->rect, m_radius, m_radius); + painter->setBrush(oldBrush); + painter->setPen(oldPen); +} + +QSize QAndroidStyle::AndroidGradientDrawable::size() const +{ + return QSize(m_radius*2, m_radius*2); +} + +QAndroidStyle::AndroidClipDrawable::AndroidClipDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidDrawable(drawable, itemType) +{ + m_drawable = fromMap(drawable.value(QLatin1String("drawable")).toMap(), itemType); + m_factor = 0; + m_orientation = Qt::Horizontal; +} + +QAndroidStyle::AndroidClipDrawable::~AndroidClipDrawable() +{ + delete m_drawable; +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidClipDrawable::type() const +{ + return QAndroidStyle::Clip; +} + +void QAndroidStyle::AndroidClipDrawable::setFactor(double factor, Qt::Orientation orientation) +{ + m_factor = factor; + m_orientation = orientation; +} + +void QAndroidStyle::AndroidClipDrawable::draw(QPainter *painter, const QStyleOption *opt) const +{ + QStyleOption copy(*opt); + if (m_orientation == Qt::Horizontal) + copy.rect.setWidth(copy.rect.width()*m_factor); + else + copy.rect.setHeight(copy.rect.height()*m_factor); + + m_drawable->draw(painter, ©); +} + +QAndroidStyle::AndroidStateDrawable::AndroidStateDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidDrawable(drawable, itemType) +{ + QVariantList states = drawable.value(QLatin1String("stateslist")).toList(); + foreach (QVariant stateVariant, states) { + QVariantMap state = stateVariant.toMap(); + const int s = extractState(state.value(QLatin1String("states")).toMap()); + if (-1 == s) + continue; + const AndroidDrawable *ad = fromMap(state.value(QLatin1String("drawable")).toMap(), itemType); + if (!ad) + continue; + StateType item; + item.first = s; + item.second = ad; + m_states<<item; + } +} + +QAndroidStyle::AndroidStateDrawable::~AndroidStateDrawable() +{ + foreach (const StateType type, m_states) + delete type.second; +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidStateDrawable::type() const +{ + return QAndroidStyle::State; +} + +void QAndroidStyle::AndroidStateDrawable::draw(QPainter *painter, const QStyleOption *opt) const +{ + const AndroidDrawable *drawable=bestAndroidStateMatch(opt); + if (drawable) + drawable->draw(painter, opt); +} + +const QAndroidStyle::AndroidDrawable* QAndroidStyle::AndroidStateDrawable::bestAndroidStateMatch(const QStyleOption *opt) const +{ + const AndroidDrawable *bestMatch = 0; + if (!opt) { + if (m_states.size()) + return m_states[0].second; + return bestMatch; + } + + uint bestCost=0xffff; + foreach (const StateType & state, m_states) { + if (int(opt->state) == state.first) + return state.second; + uint cost = 0; + + int difference = int(opt->state^state.first); + + if (difference & QStyle::State_Active) + cost += 1000; + + if (difference & QStyle::State_Enabled) + cost += 1000; + + if ((m_itemType == QC_Button || m_itemType == QC_EditText) && (difference & QStyle::State_Raised)) + cost += 1000; + + if ((m_itemType == QC_Button || m_itemType == QC_EditText) && (difference & QStyle::State_Sunken)) + cost += 1000; + + if (difference & QStyle::State_Off) + cost += 1000; + + if (difference & QStyle::State_On) + cost += 1000; + + if (difference & QStyle::State_HasFocus) + cost += 1000; + + if (difference & QStyle::State_Selected) + cost += 1000; + + if (cost < bestCost) { + bestCost = cost; + bestMatch = state.second; + } + } + return bestMatch; +} + +int QAndroidStyle::AndroidStateDrawable::extractState(const QVariantMap &value) +{ + int state = QStyle::State_None; + foreach (const QString key, value.keys()) { + bool val = value.value(key).toString() == QLatin1String("true"); + if (key == QLatin1String("enabled") && val) { + state |= QStyle::State_Enabled; + continue; + } + + if (key == QLatin1String("window_focused") && val) { + state |= QStyle::State_Active; + continue; + } + + if (key == QLatin1String("focused") && val) { + state |= QStyle::State_HasFocus; + continue; + } + + if (key == QLatin1String("checked")) { + state |= val ? QStyle::State_On : QStyle::State_Off; + continue; + } + + if (key == QLatin1String("pressed")) { + state |= val ? QStyle::State_Raised : QStyle::State_Sunken; + state |= QStyle::State_Enabled | QStyle::State_HasFocus; + continue; + } + + if (key == QLatin1String("selected") && val) { + state |= QStyle::State_Selected; + state |= QStyle::State_Enabled | QStyle::State_HasFocus; + continue; + } + + if (key == QLatin1String("active") && val) { + state |= QStyle::State_Active; + continue; + } + + // Keep misspelling for compatibility + if (key == QLatin1String("backgroud") && val) + return -1; + } + return state; +} + +QAndroidStyle::AndroidLayerDrawable::AndroidLayerDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidDrawable(drawable, itemType) +{ + QVariantList layers = drawable.value(QLatin1String("layers")).toList(); + foreach (QVariant layer, layers) { + QVariantMap layerMap = layer.toMap(); + AndroidDrawable *ad = fromMap(layerMap, itemType); + if (ad) { + LayerType l; + l.second = ad; + l.first = layerMap.value(QLatin1String("id")).toInt(); + m_layers << l; + } + } +} + +QAndroidStyle::AndroidLayerDrawable::~AndroidLayerDrawable() +{ + foreach (const LayerType &layer, m_layers) + delete layer.second; +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidLayerDrawable::type() const +{ + return QAndroidStyle::Layer; +} + +void QAndroidStyle::AndroidLayerDrawable::draw(QPainter *painter, const QStyleOption *opt) const +{ + foreach (const LayerType &layer, m_layers) + layer.second->draw(painter, opt); +} + +QAndroidStyle::AndroidDrawable *QAndroidStyle::AndroidLayerDrawable::layer(int id) const +{ + foreach (const LayerType &layer, m_layers) + if (layer.first == id) + return layer.second; + return 0; +} + +QSize QAndroidStyle::AndroidLayerDrawable::size() const +{ + QSize sz; + foreach (const LayerType &layer, m_layers) + sz = sz.expandedTo(layer.second->size()); + return sz; +} + +QAndroidStyle::AndroidControl::AndroidControl(const QVariantMap &control, + QAndroidStyle::ItemType itemType) +{ + QVariantMap::const_iterator it = control.find(QLatin1String("View_background")); + if (it != control.end()) + m_background = AndroidDrawable::fromMap(it.value().toMap(), itemType); + else + m_background = 0; + + it = control.find(QLatin1String("View_minWidth")); + if (it!=control.end()) + m_minSize.setWidth(it.value().toInt()); + + it = control.find(QLatin1String("View_minHeight")); + if (it != control.end()) + m_minSize.setHeight(it.value().toInt()); + + it = control.find(QLatin1String("View_maxWidth")); + if (it != control.end()) + m_maxSize.setWidth(it.value().toInt()); + + it = control.find(QLatin1String("View_maxHeight")); + if (it != control.end()) + m_maxSize.setHeight(it.value().toInt()); +} + +QAndroidStyle::AndroidControl::~AndroidControl() +{ + delete m_background; +} + +void QAndroidStyle::AndroidControl::drawControl(const QStyleOption *opt, QPainter *p, const QWidget * /* w */) +{ + if (m_background) + m_background->draw(p, opt); +} + +QRect QAndroidStyle::AndroidControl::subElementRect(QStyle::SubElement /* subElement */, + const QStyleOption *option, + const QWidget * /* widget */) const +{ + if (const AndroidDrawable *drawable=m_background) { + if (drawable->type() == State) + drawable = static_cast<const AndroidStateDrawable *>(m_background)->bestAndroidStateMatch(option); + + const QMargins &padding = drawable->padding(); + + QRect r = option->rect.adjusted(padding.left(), padding.top(), + -padding.right(), -padding.bottom()); + + if (r.width() < m_minSize.width()) + r.setWidth(m_minSize.width()); + + if (r.height() < m_minSize.height()) + r.setHeight(m_minSize.height()); + + return visualRect(option->direction, option->rect, r); + } + return option->rect; + +} + +QRect QAndroidStyle::AndroidControl::subControlRect(const QStyleOptionComplex *option, + QStyle::SubControl /*sc*/, + const QWidget *widget) const +{ + return subElementRect(QStyle::SE_CustomBase, option, widget); +} + +QSize QAndroidStyle::AndroidControl::sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, + const QWidget * /* w */) const +{ + QSize sz; + if (const AndroidDrawable *drawable=m_background) { + + if (drawable->type() == State) + drawable = static_cast<const AndroidStateDrawable*>(m_background)->bestAndroidStateMatch(opt); + const QMargins &padding = drawable->padding(); + sz.setWidth(padding.left() + padding.right()); + sz.setHeight(padding.top() + padding.bottom()); + if (sz.isEmpty()) + sz = drawable->size(); + } + sz += contentsSize; + if (contentsSize.height() < opt->fontMetrics.height()) + sz.setHeight(sz.height() + (opt->fontMetrics.height() - contentsSize.height())); + if (sz.height() < m_minSize.height()) + sz.setHeight(m_minSize.height()); + if (sz.width() < m_minSize.width()) + sz.setWidth(m_minSize.width()); + return sz; +} + +QMargins QAndroidStyle::AndroidControl::padding() +{ + if (const AndroidDrawable *drawable = m_background) + { + if (drawable->type() == State) + drawable=static_cast<const AndroidStateDrawable *>(m_background)->bestAndroidStateMatch(0); + return drawable->padding(); + } + return QMargins(); +} + +QAndroidStyle::AndroidCompoundButtonControl::AndroidCompoundButtonControl(const QVariantMap &control, + ItemType itemType) + : AndroidControl(control, itemType) +{ + QVariantMap::const_iterator it = control.find(QLatin1String("CompoundButton_button")); + if (it != control.end()) + m_button = AndroidDrawable::fromMap(it.value().toMap(), itemType); + else + m_button = 0; +} + +QAndroidStyle::AndroidCompoundButtonControl::~AndroidCompoundButtonControl() +{ + delete m_button; +} + +void QAndroidStyle::AndroidCompoundButtonControl::drawControl(const QStyleOption *opt, + QPainter *p, + const QWidget *w) +{ + AndroidControl::drawControl(opt, p, w); + if (m_button) + m_button->draw(p, opt); +} + +QAndroidStyle::AndroidProgressBarControl::AndroidProgressBarControl(const QVariantMap &control, + ItemType itemType) + : AndroidControl(control, itemType) +{ + QVariantMap::const_iterator it = control.find(QLatin1String("ProgressBar_indeterminateDrawable")); + if (it != control.end()) + m_indeterminateDrawable = AndroidDrawable::fromMap(it.value().toMap(), itemType); + else + m_indeterminateDrawable = 0; + + it = control.find(QLatin1String("ProgressBar_progressDrawable")); + if (it != control.end()) + m_progressDrawable = AndroidDrawable::fromMap(it.value().toMap(), itemType); + else + m_progressDrawable = 0; + + it = control.find(QLatin1String("ProgressBar_progress_id")); + if (it != control.end()) + m_progressId = it.value().toInt(); + + it = control.find(QLatin1String("ProgressBar_secondaryProgress_id")); + if (it != control.end()) + m_secondaryProgress_id = it.value().toInt(); + + it = control.find(QLatin1String("ProgressBar_minWidth")); + if (it != control.end()) + m_minSize.setWidth(it.value().toInt()); + + it = control.find(QLatin1String("ProgressBar_minHeight")); + if (it != control.end()) + m_minSize.setHeight(it.value().toInt()); + + it = control.find(QLatin1String("ProgressBar_maxWidth")); + if (it != control.end()) + m_maxSize.setWidth(it.value().toInt()); + + it = control.find(QLatin1String("ProgressBar_maxHeight")); + if (it != control.end()) + m_maxSize.setHeight(it.value().toInt()); +} + +QAndroidStyle::AndroidProgressBarControl::~AndroidProgressBarControl() +{ + delete m_progressDrawable; + delete m_indeterminateDrawable; +} + +void QAndroidStyle::AndroidProgressBarControl::drawControl(const QStyleOption *option, QPainter *p, const QWidget * /* w */) +{ + if (!m_progressDrawable) + return; + + if (const QStyleOptionProgressBar *progressBarOption = + qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { + QStyleOptionProgressBarV2 progressBarV2(*progressBarOption); + if (m_progressDrawable->type() == QAndroidStyle::Layer) { + QAndroidStyle::AndroidDrawable *clipDrawable = static_cast<QAndroidStyle::AndroidLayerDrawable *>(m_progressDrawable)->layer(m_progressId); + if (clipDrawable->type() == QAndroidStyle::Clip) + static_cast<QAndroidStyle::AndroidClipDrawable *>(clipDrawable)->setFactor(double(progressBarV2.progress/(progressBarV2.maximum-progressBarV2.minimum)), + progressBarV2.orientation); + } + m_progressDrawable->draw(p, option); + } +} + +QRect QAndroidStyle::AndroidProgressBarControl::subElementRect(QStyle::SubElement subElement, + const QStyleOption *option, + const QWidget *widget) const +{ + if (const QStyleOptionProgressBar *progressBarOption = + qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { + QStyleOptionProgressBarV2 progressBarV2(*progressBarOption); + const bool horizontal = progressBarV2.orientation == Qt::Vertical; + if (!m_background) + return option->rect; + + QMargins padding = m_background->padding(); + QRect p(padding.left(), padding.top(), padding.right()-padding.left(), padding.bottom()-padding.top()); + padding = m_indeterminateDrawable->padding(); + 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) { + if (r.height()<m_minSize.height()) + r.setHeight(m_minSize.height()); + + if (r.height()>m_maxSize.height()) + r.setHeight(m_maxSize.height()); + } else { + if (r.width()<m_minSize.width()) + r.setWidth(m_minSize.width()); + + if (r.width()>m_maxSize.width()) + r.setWidth(m_maxSize.width()); + } + return visualRect(option->direction, option->rect, r); + } + return AndroidControl::subElementRect(subElement, option, widget); +} + +QSize QAndroidStyle::AndroidProgressBarControl::sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, + const QWidget * /* w */) const +{ + QSize sz(contentsSize); + if (sz.height() < m_minSize.height()) + sz.setHeight(m_minSize.height()); + if (sz.width() < m_minSize.width()) + sz.setWidth(m_minSize.width()); + + if (const QStyleOptionProgressBar *progressBarOption = + qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { + QStyleOptionProgressBarV2 progressBarV2(*progressBarOption); + if (progressBarV2.orientation == Qt::Vertical) { + if (sz.height() > m_maxSize.height()) + sz.setHeight(m_maxSize.height()); + } else { + if (sz.width() > m_maxSize.width()) + sz.setWidth(m_maxSize.width()); + } + } + return contentsSize; +} + +QAndroidStyle::AndroidSeekBarControl::AndroidSeekBarControl(const QVariantMap &control, + ItemType itemType) + : AndroidProgressBarControl(control, itemType) +{ + QVariantMap::const_iterator it = control.find(QLatin1String("SeekBar_thumb")); + if (it != control.end()) + m_seekBarThumb = AndroidDrawable::fromMap(it.value().toMap(), itemType); + else + m_seekBarThumb = 0; +} + +QAndroidStyle::AndroidSeekBarControl::~AndroidSeekBarControl() +{ + delete m_seekBarThumb; +} + +void QAndroidStyle::AndroidSeekBarControl::drawControl(const QStyleOption *option, + QPainter *p, + const QWidget * /* w */) +{ + if (!m_seekBarThumb || !m_progressDrawable) + return; + + if (const QStyleOptionSlider *styleOption = + qstyleoption_cast<const QStyleOptionSlider *>(option)) { + double factor = double(styleOption->sliderPosition/(styleOption->maximum-styleOption->minimum)); + if (m_progressDrawable->type()==QAndroidStyle::Layer) { + QAndroidStyle::AndroidDrawable *clipDrawable = static_cast<QAndroidStyle::AndroidLayerDrawable *>(m_progressDrawable)->layer(m_progressId); + if (clipDrawable->type() == QAndroidStyle::Clip) + static_cast<QAndroidStyle::AndroidClipDrawable *>(clipDrawable)->setFactor(factor, styleOption->orientation); + } + const AndroidDrawable *drawable=m_seekBarThumb; + 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.setWidth(copy.rect.width()-drawable->size().width()); + copy.rect.translate(drawable->size().width()/2,0); + m_progressDrawable->draw(p, ©); + if (styleOption->orientation == Qt::Vertical) + qCritical() << "Vertical slider are not supported"; + int pos = (double(copy.rect.width()*factor - drawable->size().width()) / 2); + copy.rect.translate(pos, 0); + copy.rect.setSize(drawable->size()); + m_seekBarThumb->draw(p, ©); + } +} + +QSize QAndroidStyle::AndroidSeekBarControl::sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, + const QWidget *w) const +{ + QSize sz = AndroidProgressBarControl::sizeFromContents(opt, contentsSize, w); + if (!m_seekBarThumb) + return sz; + const AndroidDrawable *drawable=m_seekBarThumb; + if (drawable->type() == State) + drawable = static_cast<const QAndroidStyle::AndroidStateDrawable *>(m_seekBarThumb)->bestAndroidStateMatch(opt); + return sz.expandedTo(drawable->size()); +} + +QRect QAndroidStyle::AndroidSeekBarControl::subControlRect(const QStyleOptionComplex *option, + SubControl sc, + const QWidget * /* widget */) const +{ + const QStyleOptionSlider *styleOption = + qstyleoption_cast<const QStyleOptionSlider *>(option); + + if (m_seekBarThumb && sc == SC_SliderHandle && styleOption) { + const AndroidDrawable *drawable = m_seekBarThumb; + if (drawable->type() == State) + drawable = static_cast<const QAndroidStyle::AndroidStateDrawable *>(m_seekBarThumb)->bestAndroidStateMatch(option); + + QRect r(option->rect); + double factor = double(styleOption->sliderPosition/(styleOption->maximum-styleOption->minimum)); + int pos=(double(option->rect.width()*factor - drawable->size().width()) / 2); + r.setX(r.x()+pos); + r.setSize(drawable->size()); + return r; + } + return option->rect; +} + +QAndroidStyle::AndroidSpinnerControl::AndroidSpinnerControl(const QVariantMap &control, + QAndroidStyle::ItemType itemType) + : AndroidControl(control, itemType) +{} + +QRect QAndroidStyle::AndroidSpinnerControl::subControlRect(const QStyleOptionComplex *option, + SubControl sc, + const QWidget *widget) const +{ + if (sc == QStyle::SC_ComboBoxListBoxPopup) + return option->rect; + return AndroidControl::subControlRect(option, sc, widget); +} + +QT_END_NAMESPACE + +#endif // !defined(QT_NO_STYLE_ANDROID) || defined(QT_PLUGIN) diff --git a/src/widgets/styles/qandroidstyle_p.h b/src/widgets/styles/qandroidstyle_p.h new file mode 100644 index 0000000000..2d9abd65c5 --- /dev/null +++ b/src/widgets/styles/qandroidstyle_p.h @@ -0,0 +1,382 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWidgets module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDSTYLE_P_H +#define QANDROIDSTYLE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of qstylefactory.cpp. This header may change from version to version +// without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/QList> +#include <QtCore/QMargins> +#include <QtWidgets/QCommonStyle> +#include <QtCore/QHash> +#include <QtCore/QVariantMap> + +QT_BEGIN_NAMESPACE + +#if !defined(QT_NO_STYLE_ANDROID) + +class Q_WIDGETS_EXPORT QAndroidStyle : public QCommonStyle +{ + Q_OBJECT + +public: + enum ItemType + { + QC_UnknownType = -1, + QC_View, + QC_GroupBox, + QC_Button, + QC_Checkbox, + QC_RadioButton, + QC_Slider, + QC_Switch, + QC_EditText, + QC_Combobox, + QC_BusyIndicator, + QC_ProgressBar, + QC_Tab, + QC_TabButton, + QC_RatingIndicator, + QC_SearchBox, + QC_CustomCOntrol=0xf00, + QC_ControlMask=0xfff + }; + + struct Android9PatchChunk + { + QVector<int> xDivs; + QVector<int> yDivs; + QVector<int> colors; + }; + + struct AndroidItemStateInfo + { + AndroidItemStateInfo():state(0){} + int state; + QByteArray filePath; + QByteArray hashKey; + Android9PatchChunk chunkData; + QSize size; + QMargins padding; + }; + + enum AndroidDrawableType + { + Color, + Image, + Clip, + NinePatch, + Gradient, + State, + Layer + }; + + class AndroidDrawable + { + public: + AndroidDrawable(const QVariantMap &drawable, ItemType itemType); + virtual ~AndroidDrawable(); + virtual void initPadding(const QVariantMap &drawable); + virtual AndroidDrawableType type() const = 0; + virtual void draw(QPainter *painter,const QStyleOption *opt) const = 0; + const QMargins &padding() const; + virtual QSize size() const; + static AndroidDrawable *fromMap(const QVariantMap &drawable, ItemType itemType); + static QMargins extractMargins(const QVariantMap &value); + protected: + ItemType m_itemType; + QMargins m_padding; + }; + + class AndroidColorDrawable: public AndroidDrawable + { + public: + AndroidColorDrawable(const QVariantMap &drawable, ItemType itemType); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter,const QStyleOption *opt) const; + + protected: + QColor m_color; + }; + + class AndroidImageDrawable: public AndroidDrawable + { + public: + AndroidImageDrawable(const QVariantMap &drawable, ItemType itemType); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter,const QStyleOption *opt) const; + virtual QSize size() const; + + protected: + QString m_filePath; + mutable QString m_hashKey; + QSize m_size; + }; + + class Android9PatchDrawable: public AndroidImageDrawable + { + public: + Android9PatchDrawable(const QVariantMap &drawable, ItemType itemType); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter, const QStyleOption *opt) const; + private: + static int calculateStretch(int boundsLimit, int startingPoint, + int srcSpace, int numStrechyPixelsRemaining, + int numFixedPixelsRemaining); + void extractIntArray(const QVariantList &values, QVector<int> &array); + private: + Android9PatchChunk m_chunkData; + }; + + class AndroidGradientDrawable: public AndroidDrawable + { + public: + enum GradientOrientation + { + TOP_BOTTOM, + TR_BL, + RIGHT_LEFT, + BR_TL, + BOTTOM_TOP, + BL_TR, + LEFT_RIGHT, + TL_BR + }; + + public: + AndroidGradientDrawable(const QVariantMap &drawable, ItemType itemType); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter, const QStyleOption *opt) const; + QSize size() const; + private: + mutable QLinearGradient m_gradient; + GradientOrientation m_orientation; + int m_radius; + }; + + class AndroidClipDrawable: public AndroidDrawable + { + public: + AndroidClipDrawable(const QVariantMap &drawable, ItemType itemType); + ~AndroidClipDrawable(); + virtual AndroidDrawableType type() const; + virtual void setFactor(double factor, Qt::Orientation orientation); + virtual void draw(QPainter *painter, const QStyleOption *opt) const; + + private: + double m_factor; + Qt::Orientation m_orientation; + const AndroidDrawable *m_drawable; + }; + + class AndroidStateDrawable: public AndroidDrawable + { + public: + AndroidStateDrawable(const QVariantMap &drawable, ItemType itemType); + ~AndroidStateDrawable(); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter, const QStyleOption *opt) const; + inline const AndroidDrawable *bestAndroidStateMatch(const QStyleOption *opt) const; + static int extractState(const QVariantMap &value); + + private: + typedef QPair<int, const AndroidDrawable *> StateType; + QList<StateType> m_states; + }; + + class AndroidLayerDrawable: public AndroidDrawable + { + public: + AndroidLayerDrawable(const QVariantMap &drawable, QAndroidStyle::ItemType itemType); + ~AndroidLayerDrawable(); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter, const QStyleOption *opt) const; + AndroidDrawable *layer(int id) const; + QSize size() const; + private: + typedef QPair<int, AndroidDrawable *> LayerType; + QList<LayerType> m_layers; + }; + + class AndroidControl + { + public: + AndroidControl(const QVariantMap &control, ItemType itemType); + virtual ~AndroidControl(); + virtual void drawControl(const QStyleOption *opt, QPainter *p, const QWidget *w); + virtual QRect subElementRect(SubElement subElement, + const QStyleOption *option, + const QWidget *widget = 0) const; + virtual QRect subControlRect(const QStyleOptionComplex *option, + SubControl sc, + const QWidget *widget = 0) const; + virtual QSize sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, + const QWidget *w) const; + virtual QMargins padding(); + protected: + const AndroidDrawable *m_background; + QSize m_minSize; + QSize m_maxSize; + }; + + class AndroidCompoundButtonControl : public AndroidControl + { + public: + AndroidCompoundButtonControl(const QVariantMap &control, ItemType itemType); + virtual ~AndroidCompoundButtonControl(); + virtual void drawControl(const QStyleOption *opt, QPainter *p, const QWidget *w); + + protected: + const AndroidDrawable *m_button; + }; + + class AndroidProgressBarControl : public AndroidControl + { + public: + AndroidProgressBarControl(const QVariantMap &control, ItemType itemType); + virtual ~AndroidProgressBarControl(); + virtual void drawControl(const QStyleOption *option, QPainter *p, const QWidget *w); + virtual QRect subElementRect(SubElement subElement, + const QStyleOption *option, + const QWidget *widget = 0) const; + + QSize sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, + const QWidget *w) const; + protected: + AndroidDrawable *m_progressDrawable; + AndroidDrawable *m_indeterminateDrawable; + int m_secondaryProgress_id; + int m_progressId; + }; + + class AndroidSeekBarControl : public AndroidProgressBarControl + { + public: + AndroidSeekBarControl(const QVariantMap &control, ItemType itemType); + virtual ~AndroidSeekBarControl(); + virtual void drawControl(const QStyleOption *option, QPainter *p, const QWidget *w); + QSize sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, const QWidget *w) const; + QRect subControlRect(const QStyleOptionComplex *option, SubControl sc, + const QWidget *widget = 0) const; + private: + AndroidDrawable *m_seekBarThumb; + }; + + class AndroidSpinnerControl : public AndroidControl + { + public: + AndroidSpinnerControl(const QVariantMap &control, ItemType itemType); + virtual ~AndroidSpinnerControl(){} + virtual QRect subControlRect(const QStyleOptionComplex *option, + SubControl sc, + const QWidget *widget = 0) const; + }; + + typedef QList<AndroidItemStateInfo *> AndroidItemStateInfoList; + +public: + QAndroidStyle(); + ~QAndroidStyle(); + + virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, + const QWidget *w = 0) const; + + virtual void drawControl(QStyle::ControlElement element, const QStyleOption *opt, QPainter *p, + const QWidget *w = 0) const; + + virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, + const QWidget *widget = 0) const; + virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, + const QWidget *widget = 0) const; + virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, + const QPoint &pt, const QWidget *widget = 0) const; + virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, + SubControl sc, const QWidget *widget = 0) const; + + virtual int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, + const QWidget *widget = 0) const; + + virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, + const QSize &contentsSize, const QWidget *w = 0) const; + + virtual QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt = 0, + const QWidget *widget = 0) const; + + virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, + const QStyleOption *opt) const; + + virtual QPalette standardPalette() const; +private: + Q_DISABLE_COPY(QAndroidStyle) + static ItemType qtControl(QStyle::ComplexControl control); + static ItemType qtControl(QStyle::ContentsType contentsType); + static ItemType qtControl(QStyle::ControlElement controlElement); + static ItemType qtControl(QStyle::PrimitiveElement primitiveElement); + 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; + QPalette m_standardPalette; +}; + +#endif // QT_NO_STYLE_ANDROID + +QT_END_NAMESPACE + +#endif // QANDROIDSTYLE_P_H diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index d1d80f5af0..f7ae667a82 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -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 @@ -1115,6 +1115,8 @@ void QCommonStylePrivate::tabLayout(const QStyleOptionTabV3 *opt, const QWidget QSize tabIconSize = opt->icon.actualSize(iconSize, (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())); *iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2, tabIconSize.width(), tabIconSize .height()); @@ -1236,8 +1238,11 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, state = QIcon::On; QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state); - int labelWidth = pixmap.width(); - int labelHeight = pixmap.height(); + + int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio(); + int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio(); + int labelWidth = pixmapWidth; + int labelHeight = pixmapHeight; int iconSpacing = 4;//### 4 is currently hardcoded in QPushButton::sizeHint() int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width(); if (!button->text.isEmpty()) @@ -1245,7 +1250,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2, textRect.y() + (textRect.height() - labelHeight) / 2, - pixmap.width(), pixmap.height()); + pixmapWidth, pixmapHeight); iconRect = visualRect(button->direction, textRect, iconRect); @@ -1517,9 +1522,9 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, if (!header->icon.isNull()) { QPixmap pixmap = header->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), (header->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); - int pixw = pixmap.width(); + int pixw = pixmap.width() / pixmap.devicePixelRatio(); - QRect aligned = alignedRect(header->direction, QFlag(header->iconAlignment), pixmap.size(), rect); + QRect aligned = alignedRect(header->direction, QFlag(header->iconAlignment), pixmap.size() / pixmap.devicePixelRatio(), rect); QRect inter = aligned.intersected(rect); p->drawPixmap(inter.x(), inter.y(), pixmap, inter.x() - aligned.x(), inter.y() - aligned.y(), inter.width(), inter.height()); @@ -1574,7 +1579,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, mode = QIcon::Normal; pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize), mode, state); - pmSize = pm.size(); + pmSize = pm.size() / pm.devicePixelRatio(); } if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) { @@ -1800,8 +1805,8 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, tr = cr; tr.adjust(4, 0, -8, 0); } else { - int iw = pm.width() + 4; - ih = pm.height(); + int iw = pm.width() / pm.devicePixelRatio() + 4; + ih = pm.height()/ pm.devicePixelRatio(); ir = QRect(cr.left() + 4, cr.top(), iw + 2, ih); tr = QRect(ir.right(), cr.top(), cr.width() - ir.right() - 4, cr.height()); } @@ -2138,9 +2143,9 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, p->save(); p->setClipRect(opt->rect); - QRect checkRect = subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget); - QRect iconRect = subElementRect(SE_ItemViewItemDecoration, vopt, widget); - QRect textRect = subElementRect(SE_ItemViewItemText, vopt, widget); + QRect checkRect = proxy()->subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget); + QRect iconRect = proxy()->subElementRect(SE_ItemViewItemDecoration, vopt, widget); + QRect textRect = proxy()->subElementRect(SE_ItemViewItemText, vopt, widget); // draw the background proxy()->drawPrimitive(PE_PanelItemViewItem, opt, p, widget); @@ -2265,11 +2270,11 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, case QFrame::VLine: { QPoint p1, p2; if (frameShape == QFrame::HLine) { - p1 = QPoint(opt->rect.x(), opt->rect.height() / 2); + p1 = QPoint(opt->rect.x(), opt->rect.y() + opt->rect.height() / 2); p2 = QPoint(opt->rect.x() + opt->rect.width(), p1.y()); } else { - p1 = QPoint(opt->rect.x()+opt->rect.width() / 2, 0); - p2 = QPoint(p1.x(), opt->rect.height()); + p1 = QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y()); + p2 = QPoint(p1.x(), p1.y() + opt->rect.height()); } if (frameShadow == QFrame::Plain) { QPen oldPen = p->pen(); @@ -3003,7 +3008,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, case SE_ToolBarHandle: if (const QStyleOptionToolBar *tbopt = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) { if (tbopt->features & QStyleOptionToolBar::Movable) { - ///we need to access the widget here because the style option doesn't + ///we need to access the widget here because the style option doesn't //have all the information we need (ie. the layout's margin) const QToolBar *tb = qobject_cast<const QToolBar*>(widget); const int margin = tb && tb->layout() ? tb->layout()->margin() : 2; @@ -4808,6 +4813,16 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, } break; #endif // QT_NO_ITEMVIEWS +#ifndef QT_NO_SPINBOX + case CT_SpinBox: + if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { + // Add button + frame widths + int buttonWidth = 20; + int fw = vopt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, vopt, widget) : 0; + sz += QSize(buttonWidth + 2*fw, 2*fw); + } + break; +#endif case CT_ScrollBar: case CT_MenuBar: case CT_Menu: @@ -5090,11 +5105,18 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget ret = theme->themeHint(QPlatformTheme::ToolButtonStyle).toInt(); break; case SH_RequestSoftwareInputPanel: +#ifdef Q_OS_ANDROID + ret = RSIP_OnMouseClick; +#else ret = RSIP_OnMouseClickAndAlreadyFocused; +#endif break; case SH_ScrollBar_Transient: ret = false; break; + case SH_Menu_SupportsSections: + ret = false; + break; default: ret = 0; break; diff --git a/src/widgets/styles/qcommonstyle.h b/src/widgets/styles/qcommonstyle.h index 1d203ded34..942721a6a3 100644 --- a/src/widgets/styles/qcommonstyle.h +++ b/src/widgets/styles/qcommonstyle.h @@ -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 @@ -44,8 +44,6 @@ #include <QtWidgets/qstyle.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE class QCommonStylePrivate; @@ -53,7 +51,7 @@ class QCommonStylePrivate; class Q_WIDGETS_EXPORT QCommonStyle: public QStyle { Q_OBJECT - + public: QCommonStyle(); ~QCommonStyle(); @@ -105,6 +103,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QCOMMONSTYLE_H diff --git a/src/widgets/styles/qcommonstyle_p.h b/src/widgets/styles/qcommonstyle_p.h index dbb4d3cd37..979c2a5548 100644 --- a/src/widgets/styles/qcommonstyle_p.h +++ b/src/widgets/styles/qcommonstyle_p.h @@ -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 diff --git a/src/widgets/styles/qcommonstylepixmaps_p.h b/src/widgets/styles/qcommonstylepixmaps_p.h index 0699ff8914..d47b16d1a4 100644 --- a/src/widgets/styles/qcommonstylepixmaps_p.h +++ b/src/widgets/styles/qcommonstylepixmaps_p.h @@ -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 @@ -39,6 +39,8 @@ ** ****************************************************************************/ +#include <QtCore/qglobal.h> + #ifndef QT_NO_IMAGEFORMAT_XPM // diff --git a/src/widgets/styles/qdrawutil.cpp b/src/widgets/styles/qdrawutil.cpp index 0f73a16bcb..3df3bfa50d 100644 --- a/src/widgets/styles/qdrawutil.cpp +++ b/src/widgets/styles/qdrawutil.cpp @@ -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 @@ -748,10 +748,10 @@ void qDrawPlainRect(QPainter *p, const QRect &r, const QColor &c, \since 4.6 \inmodule QtWidgets - + \brief The QTileRules class provides the rules used to draw a pixmap or image split into nine segments. - + Spliiting is similar to \l{http://www.w3.org/TR/css3-background/}{CSS3 border-images}. \sa Qt::TileRule, QMargins diff --git a/src/widgets/styles/qdrawutil.h b/src/widgets/styles/qdrawutil.h index f0cc98f54a..6e9dc26591 100644 --- a/src/widgets/styles/qdrawutil.h +++ b/src/widgets/styles/qdrawutil.h @@ -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 @@ -46,8 +46,6 @@ #include <QtCore/qstring.h> // char*->QString conversion #include <QtCore/qmargins.h> #include <QtGui/qpixmap.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -169,6 +167,4 @@ inline void qDrawBorderPixmap(QPainter *painter, QT_END_NAMESPACE -QT_END_HEADER - #endif // QDRAWUTIL_H diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 11558de16a..bfc22807a0 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -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 @@ -1086,7 +1086,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio case CE_ToolBar: if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) { // Reserve the beveled appearance only for mainwindow toolbars - if (!(widget && qobject_cast<const QMainWindow*> (widget->parentWidget()))) + if (widget && !(qobject_cast<const QMainWindow*> (widget->parentWidget()))) break; // Draws the light line above and the dark line below menu bars and @@ -1768,12 +1768,10 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio painter->save(); { painter->fillRect(rect, option->palette.window()); - if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) { - QColor shadow = mergedColors(option->palette.background().color().darker(120), - outline.lighter(140), 60); - painter->setPen(QPen(shadow)); - painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight()); - } + QColor shadow = mergedColors(option->palette.background().color().darker(120), + outline.lighter(140), 60); + painter->setPen(QPen(shadow)); + painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight()); } painter->restore(); break; @@ -2800,53 +2798,6 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption painter->restore(); } - // draw handle - if ((option->subControls & SC_SliderHandle) ) { - QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size()); - if (!QPixmapCache::find(handlePixmapName, cache)) { - cache = styleCachePixmap(handle.size()); - cache.fill(Qt::transparent); - QRect pixmapRect(0, 0, handle.width(), handle.height()); - QPainter handlePainter(&cache); - QRect gradRect = pixmapRect.adjusted(2, 2, -2, -2); - - // gradient fill - QRect r = pixmapRect.adjusted(1, 1, -2, -2); - QLinearGradient gradient = qt_fusion_gradient(gradRect, d->buttonColor(option->palette),horizontal ? TopDown : FromLeft); - - handlePainter.setRenderHint(QPainter::Antialiasing, true); - handlePainter.translate(0.5, 0.5); - - handlePainter.setPen(Qt::NoPen); - handlePainter.setBrush(QColor(0, 0, 0, 40)); - handlePainter.drawRect(r.adjusted(-1, 2, 1, -2)); - - handlePainter.setPen(QPen(d->outline(option->palette))); - if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange) - handlePainter.setPen(QPen(d->highlightedOutline(option->palette))); - - handlePainter.setBrush(gradient); - handlePainter.drawRoundedRect(r, 2, 2); - handlePainter.setBrush(Qt::NoBrush); - handlePainter.setPen(d->innerContrastLine()); - handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2); - - QColor cornerAlpha = outline.darker(120); - cornerAlpha.setAlpha(80); - - //handle shadow - handlePainter.setPen(shadowAlpha); - handlePainter.drawLine(QPoint(r.left() + 2, r.bottom() + 1), QPoint(r.right() - 2, r.bottom() + 1)); - handlePainter.drawLine(QPoint(r.right() + 1, r.bottom() - 3), QPoint(r.right() + 1, r.top() + 4)); - handlePainter.drawLine(QPoint(r.right() - 1, r.bottom()), QPoint(r.right() + 1, r.bottom() - 2)); - - handlePainter.end(); - QPixmapCache::insert(handlePixmapName, cache); - } - - painter->drawPixmap(handle.topLeft(), cache); - - } if (option->subControls & SC_SliderTickmarks) { painter->setPen(outline); int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget); @@ -2902,6 +2853,53 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption v = nextInterval; } } + // draw handle + if ((option->subControls & SC_SliderHandle) ) { + QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size()); + if (!QPixmapCache::find(handlePixmapName, cache)) { + cache = styleCachePixmap(handle.size()); + cache.fill(Qt::transparent); + QRect pixmapRect(0, 0, handle.width(), handle.height()); + QPainter handlePainter(&cache); + QRect gradRect = pixmapRect.adjusted(2, 2, -2, -2); + + // gradient fill + QRect r = pixmapRect.adjusted(1, 1, -2, -2); + QLinearGradient gradient = qt_fusion_gradient(gradRect, d->buttonColor(option->palette),horizontal ? TopDown : FromLeft); + + handlePainter.setRenderHint(QPainter::Antialiasing, true); + handlePainter.translate(0.5, 0.5); + + handlePainter.setPen(Qt::NoPen); + handlePainter.setBrush(QColor(0, 0, 0, 40)); + handlePainter.drawRect(r.adjusted(-1, 2, 1, -2)); + + handlePainter.setPen(QPen(d->outline(option->palette))); + if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange) + handlePainter.setPen(QPen(d->highlightedOutline(option->palette))); + + handlePainter.setBrush(gradient); + handlePainter.drawRoundedRect(r, 2, 2); + handlePainter.setBrush(Qt::NoBrush); + handlePainter.setPen(d->innerContrastLine()); + handlePainter.drawRoundedRect(r.adjusted(1, 1, -1, -1), 2, 2); + + QColor cornerAlpha = outline.darker(120); + cornerAlpha.setAlpha(80); + + //handle shadow + handlePainter.setPen(shadowAlpha); + handlePainter.drawLine(QPoint(r.left() + 2, r.bottom() + 1), QPoint(r.right() - 2, r.bottom() + 1)); + handlePainter.drawLine(QPoint(r.right() + 1, r.bottom() - 3), QPoint(r.right() + 1, r.top() + 4)); + handlePainter.drawLine(QPoint(r.right() - 1, r.bottom()), QPoint(r.right() + 1, r.bottom() - 2)); + + handlePainter.end(); + QPixmapCache::insert(handlePixmapName, cache); + } + + painter->drawPixmap(handle.topLeft(), cache); + + } painter->setBrush(oldBrush); painter->setPen(oldPen); } @@ -2922,6 +2920,8 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption int QFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const { switch (metric) { + case PM_SliderTickmarkOffset: + return 4; case PM_HeaderMargin: return 2; case PM_ToolTipLabelFrameWidth: @@ -3475,6 +3475,7 @@ int QFusionStyle::styleHint(StyleHint hint, const QStyleOption *option, const QW case SH_ItemView_ChangeHighlightOnFocus: case SH_MenuBar_MouseTracking: case SH_Menu_MouseTracking: + case SH_Menu_SupportsSections: return 1; case SH_ToolBox_SelectedPageTitleBold: diff --git a/src/widgets/styles/qfusionstyle_p.h b/src/widgets/styles/qfusionstyle_p.h index e024677a9b..9e5a55918d 100644 --- a/src/widgets/styles/qfusionstyle_p.h +++ b/src/widgets/styles/qfusionstyle_p.h @@ -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 @@ -44,8 +44,6 @@ #include <QtWidgets/qcommonstyle.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -106,6 +104,4 @@ protected: QT_END_NAMESPACE -QT_END_HEADER - #endif //QFUSIONSTYLE_P_H diff --git a/src/widgets/styles/qfusionstyle_p_p.h b/src/widgets/styles/qfusionstyle_p_p.h index d3f2ff5f40..acdf409dbf 100644 --- a/src/widgets/styles/qfusionstyle_p_p.h +++ b/src/widgets/styles/qfusionstyle_p_p.h @@ -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 @@ -88,9 +88,9 @@ public: // On mac we want a standard blue color used when the system palette is used bool isMacSystemPalette(const QPalette &pal) const { Q_UNUSED(pal); -#ifdef Q_OS_MAC +#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette(); - if (themePalette->color(QPalette::Normal, QPalette::Highlight) == + if (themePalette && themePalette->color(QPalette::Normal, QPalette::Highlight) == pal.color(QPalette::Normal, QPalette::Highlight) && themePalette->color(QPalette::Normal, QPalette::HighlightedText) == pal.color(QPalette::Normal, QPalette::HighlightedText)) diff --git a/src/widgets/styles/qgtk2painter.cpp b/src/widgets/styles/qgtk2painter.cpp index 4d00a7385e..7b9bd975d8 100644 --- a/src/widgets/styles/qgtk2painter.cpp +++ b/src/widgets/styles/qgtk2painter.cpp @@ -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 diff --git a/src/widgets/styles/qgtk2painter_p.h b/src/widgets/styles/qgtk2painter_p.h index 286430cd33..f1444a87de 100644 --- a/src/widgets/styles/qgtk2painter_p.h +++ b/src/widgets/styles/qgtk2painter_p.h @@ -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 diff --git a/src/widgets/styles/qgtkglobal_p.h b/src/widgets/styles/qgtkglobal_p.h index 24da8c8e64..06ed7cfce4 100644 --- a/src/widgets/styles/qgtkglobal_p.h +++ b/src/widgets/styles/qgtkglobal_p.h @@ -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 diff --git a/src/widgets/styles/qgtkpainter.cpp b/src/widgets/styles/qgtkpainter.cpp index dac98a199c..a733049f65 100644 --- a/src/widgets/styles/qgtkpainter.cpp +++ b/src/widgets/styles/qgtkpainter.cpp @@ -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 diff --git a/src/widgets/styles/qgtkpainter_p.h b/src/widgets/styles/qgtkpainter_p.h index 58833b7c95..12d4dc9bc4 100644 --- a/src/widgets/styles/qgtkpainter_p.h +++ b/src/widgets/styles/qgtkpainter_p.h @@ -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 diff --git a/src/widgets/styles/qgtkstyle.cpp b/src/widgets/styles/qgtkstyle.cpp index 159f8dce83..15fa00d8a6 100644 --- a/src/widgets/styles/qgtkstyle.cpp +++ b/src/widgets/styles/qgtkstyle.cpp @@ -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 @@ -2121,7 +2121,7 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom label.state = bflags; GtkWidget *gtkButton = d->gtkWidget("GtkToolButton.GtkButton"); QPalette pal = toolbutton->palette; - if (option->state & State_Enabled && + if (option->state & State_Enabled && option->state & State_MouseOver && !(widget && widget->testAttribute(Qt::WA_SetPalette))) { GdkColor gdkText = d->gtk_widget_get_style(gtkButton)->fg[GTK_STATE_PRELIGHT]; QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8); @@ -2971,7 +2971,7 @@ void QGtkStyle::drawControl(ControlElement element, if (option->state & State_Sunken) shadow = GTK_SHADOW_IN; - + gtkPainter->paintBox(gtkTreeHeader, "button", option->rect.adjusted(-1, 0, 0, 0), state, shadow, d->gtk_widget_get_style(gtkTreeHeader)); } @@ -3171,7 +3171,8 @@ void QGtkStyle::drawControl(ControlElement element, #ifndef QT_NO_COMBOBOX - if (qobject_cast<const QComboBox*>(widget)) + if (qobject_cast<const QComboBox*>(widget) || + (option->styleObject && option->styleObject->property("_q_isComboBoxPopupItem").toBool())) ignoreCheckMark = true; // Ignore the checkmarks provided by the QComboMenuDelegate #endif @@ -3912,7 +3913,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option, break; case CT_SpinBox: // QSpinBox does some nasty things that depends on CT_LineEdit - newSize = size + QSize(0, -d->gtk_widget_get_style(d->gtkWidget("GtkSpinButton"))->ythickness * 2); + newSize = newSize + QSize(0, -d->gtk_widget_get_style(d->gtkWidget("GtkSpinButton"))->ythickness * 2); break; case CT_RadioButton: case CT_CheckBox: diff --git a/src/widgets/styles/qgtkstyle_p.cpp b/src/widgets/styles/qgtkstyle_p.cpp index 810a8995f8..f29f250de0 100644 --- a/src/widgets/styles/qgtkstyle_p.cpp +++ b/src/widgets/styles/qgtkstyle_p.cpp @@ -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 diff --git a/src/widgets/styles/qgtkstyle_p.h b/src/widgets/styles/qgtkstyle_p.h index f2710af4c6..525d7f840a 100644 --- a/src/widgets/styles/qgtkstyle_p.h +++ b/src/widgets/styles/qgtkstyle_p.h @@ -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 @@ -47,8 +47,6 @@ #include <QtGui/QFont> #include <QtWidgets/QFileDialog> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -119,6 +117,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif //QGTKSTYLE_P_H diff --git a/src/widgets/styles/qgtkstyle_p_p.h b/src/widgets/styles/qgtkstyle_p_p.h index fc77aea48b..6f3759bd9e 100644 --- a/src/widgets/styles/qgtkstyle_p_p.h +++ b/src/widgets/styles/qgtkstyle_p_p.h @@ -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 diff --git a/src/widgets/styles/qmacstyle.qdoc b/src/widgets/styles/qmacstyle.qdoc index 9f5299032f..9ee464667a 100644 --- a/src/widgets/styles/qmacstyle.qdoc +++ b/src/widgets/styles/qmacstyle.qdoc @@ -104,43 +104,43 @@ */ /*! \fn void QMacStyle::polish(QPalette &pal) - \reimp + \reimp */ /*! \fn void QMacStyle::polish(QApplication *) - \reimp + \reimp */ /*! \fn void QMacStyle::unpolish(QApplication *) - \reimp + \reimp */ /*! \fn void QMacStyle::polish(QWidget* w) - \reimp + \reimp */ /*! \fn void QMacStyle::unpolish(QWidget* w) - \reimp + \reimp */ /*! \fn int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QWidget *widget) const - \reimp + \reimp */ /*! \fn QPalette QMacStyle::standardPalette() const - \reimp + \reimp */ /*! \fn int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *hret) const - \reimp + \reimp */ /*! \fn QPixmap QMacStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const - \reimp + \reimp */ /*! \fn QPixmap QMacStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const - \reimp + \reimp */ /*! @@ -199,41 +199,41 @@ /*! \fn void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const - \reimp + \reimp */ /*! \fn void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p, const QWidget *w) const - \reimp + \reimp */ /*! \fn QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *widget) const - \reimp + \reimp */ /*! \fn void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const - \reimp + \reimp */ /*! \fn QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget) const - \reimp + \reimp */ /*! \fn QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const - \reimp + \reimp */ /*! \fn QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &csz, const QWidget *widget) const - \reimp + \reimp */ /*! \fn void QMacStyle::drawItemText(QPainter *p, const QRect &r, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole) const - \reimp + \reimp */ /*! \fn bool QMacStyle::event(QEvent *e) - \reimp + \reimp */ /*! \fn QIcon QMacStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *opt, const QWidget *widget) const diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index dab8e3fe74..04fea3ec47 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 @@ -589,11 +588,9 @@ 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(); } @@ -1208,7 +1205,6 @@ void QMacStylePrivate::initHIThemePushButton(const QStyleOptionButton *btn, const ThemeDrawState tds, HIThemeButtonDrawInfo *bdi) const { - bool drawColorless = btn->palette.currentColorGroup() == QPalette::Active; ThemeDrawState tdsModified = tds; if (btn->state & QStyle::State_On) tdsModified = kThemeStatePressed; @@ -1216,7 +1212,7 @@ void QMacStylePrivate::initHIThemePushButton(const QStyleOptionButton *btn, bdi->state = tdsModified; bdi->value = kThemeButtonOff; - if (drawColorless && tdsModified == kThemeStateInactive) + if (tds == kThemeStateInactive) bdi->state = kThemeStateActive; if (btn->state & QStyle::State_HasFocus) bdi->adornment = kThemeAdornmentFocus; @@ -1287,10 +1283,9 @@ void QMacStylePrivate::initComboboxBdi(const QStyleOptionComboBox *combo, HIThem bdi->value = kThemeButtonOff; if (combo->state & QStyle::State_HasFocus) bdi->adornment = kThemeAdornmentFocus; - bool drawColorless = combo->palette.currentColorGroup() == QPalette::Active && tds == kThemeStateInactive; if (combo->activeSubControls & QStyle::SC_ComboBoxArrow) bdi->state = kThemeStatePressed; - else if (drawColorless) + else if (tds == kThemeStateInactive) bdi->state = kThemeStateActive; else bdi->state = tds; @@ -1611,8 +1606,6 @@ void QMacStylePrivate::getSliderInfo(QStyle::ComplexControl cc, const QStyleOpti tdi->enableState = (slider->state & QStyle::State_Enabled) ? kThemeTrackActive : kThemeTrackDisabled; - if (!(slider->state & QStyle::State_Active)) - tdi->enableState = kThemeTrackInactive; if (!isScrollbar) { if (slider->state & QStyle::QStyle::State_HasFocus) tdi->attributes |= kThemeTrackHasFocus; @@ -2377,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) { @@ -2960,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; @@ -2981,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(); @@ -3033,12 +3023,11 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai case PE_IndicatorViewItemCheck: case PE_IndicatorRadioButton: case PE_IndicatorCheckBox: { - bool drawColorless = (!(opt->state & State_Active)) - && opt->palette.currentColorGroup() == QPalette::Active; + bool drawColorless = tds == kThemeStateInactive; HIThemeButtonDrawInfo bdi; bdi.version = qt_mac_hitheme_version; bdi.state = tds; - if (drawColorless && tds == kThemeStateInactive) + if (drawColorless) bdi.state = kThemeStateActive; bdi.adornment = kThemeDrawIndicatorOnly; if (opt->state & State_HasFocus) @@ -3203,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) { @@ -3359,9 +3336,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter QPixmap pixmap = header->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), mode); QRect pixr = header->rect; - pixr.setY(header->rect.center().y() - (pixmap.height() - 1) / 2); + pixr.setY(header->rect.center().y() - (pixmap.height() / pixmap.devicePixelRatio() - 1) / 2); proxy()->drawItemPixmap(p, pixr, Qt::AlignVCenter, pixmap); - textr.translate(pixmap.width() + 2, 0); + textr.translate(pixmap.width() / pixmap.devicePixelRatio() + 2, 0); } p->setFont(qt_app_fonts_hash()->value("QSmallFont", QFont())); @@ -3415,15 +3392,15 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) { QMainWindow *mw = qobject_cast<QMainWindow *>(w->window()); if (mw && mw->unifiedTitleAndToolBarOnMac()) { - pr.setHeight(pixmap.size().height()); + pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio()); cr.adjust(0, pr.bottom() + 1, 0, 1); } else { - pr.setHeight(pixmap.size().height() + 6); + pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio() + 6); cr.adjust(0, pr.bottom(), 0, -3); - } + } alignment |= Qt::AlignCenter; } else { - pr.setWidth(pixmap.width() + 8); + pr.setWidth(pixmap.width() / pixmap.devicePixelRatio() + 8); cr.adjust(pr.right(), 0, 0, 0); alignment |= Qt::AlignLeft | Qt::AlignVCenter; } @@ -3572,13 +3549,10 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter int arrowYOffset = bdi.kind == kThemePushButton ? 4 : 2; HIRect arrowRect = CGRectMake(ir.right() - mbi - QMacStylePrivate::PushButtonRightOffset, ir.height() / 2 - arrowYOffset, mbi, ir.height() / 2); - bool drawColorless = btn->palette.currentColorGroup() == QPalette::Active; - if (drawColorless && tds == kThemeStateInactive) - tds = kThemeStateActive; HIThemePopupArrowDrawInfo pdi; pdi.version = qt_mac_hitheme_version; - pdi.state = tds; + pdi.state = tds == kThemeStateInactive ? kThemeStateActive : tds; pdi.orientation = kThemeArrowDown; if (arrowRect.size.width < 8.) pdi.size = kThemeArrow5pt; @@ -3664,10 +3638,12 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter if (btn->state & State_On) state = QIcon::On; QPixmap pixmap = btn->icon.pixmap(btn->iconSize, mode, state); - contentW += pixmap.width() + QMacStylePrivate::PushButtonContentPadding; + int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio(); + int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio(); + contentW += pixmapWidth + QMacStylePrivate::PushButtonContentPadding; int iconLeftOffset = freeContentRect.x() + (freeContentRect.width() - contentW) / 2; - int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmap.height()) / 2; - QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmap.width(), pixmap.height()); + int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmapHeight) / 2; + QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmapWidth, pixmapHeight); QRect visualIconDestRect = visualRect(btn->direction, freeContentRect, iconDestRect); proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap); int newOffset = iconDestRect.x() + iconDestRect.width() @@ -4009,7 +3985,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter HIRect cr; bool needAlpha = mi->palette.color(QPalette::Button) == Qt::transparent; if (needAlpha) { - needAlpha = true; CGContextSaveGState(cg); CGContextSetAlpha(cg, 0.0); } @@ -4026,7 +4001,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter if (!enabled) p->setPen(mi->palette.text().color()); else if (active) - p->setPen(QColor(Qt::white)); // QPalette's API is incomplete for this case + p->setPen(mi->palette.highlightedText().color()); else p->setPen(mi->palette.buttonText().color()); @@ -4097,8 +4072,8 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter iconSize = comboBox->iconSize(); } QPixmap pixmap = mi->icon.pixmap(iconSize, mode); - int pixw = pixmap.width(); - int pixh = pixmap.height(); + int pixw = pixmap.width() / pixmap.devicePixelRatio(); + int pixh = pixmap.height() / pixmap.devicePixelRatio(); QRect cr(xpos, contentRect.y(), checkcol, contentRect.height()); QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(cr.center()); @@ -4915,14 +4890,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; @@ -5019,6 +4992,8 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex bgColor.blue() < 128; if (isDarkBg) [scroller setKnobStyle:NSScrollerKnobStyleLight]; + else + [scroller setKnobStyle:NSScrollerKnobStyleDefault]; [scroller setControlSize:(tdi.kind == kThemeSmallScrollBar ? NSMiniControlSize : NSRegularControlSize)]; @@ -5136,7 +5111,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex HIThemeFrameDrawInfo fdi; fdi.version = qt_mac_hitheme_version; - fdi.state = tds; + fdi.state = tds == kThemeStateInactive ? kThemeStateActive : tds; fdi.kind = kHIThemeFrameTextFieldSquare; fdi.isFocused = false; HIRect hirect = qt_hirectForQRect(lineeditRect); @@ -5167,11 +5142,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex else if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) tds = kThemeStatePressedUp; - bdi.state = tds; - if (!(sb->state & State_Active) - && sb->palette.currentColorGroup() == QPalette::Active - && tds == kThemeStateInactive) + if (tds == kThemeStateInactive) bdi.state = kThemeStateActive; + else + bdi.state = tds; bdi.value = kThemeButtonOff; bdi.adornment = kThemeAdornmentNone; @@ -5188,7 +5162,10 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex int(outRect.size.height - newRect.size.height)); newRect = qt_hirectForQRect(updown, off_rct); - HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0); + if (tds == kThemeStateInactive) + d->drawColorlessButton(newRect, &bdi, p, sb); + else + HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0); } } break; @@ -5196,8 +5173,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex if (const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)){ HIThemeButtonDrawInfo bdi; d->initComboboxBdi(combo, &bdi, widget, d->getDrawState(opt->state)); - bool drawColorless = combo->palette.currentColorGroup() == QPalette::Active && tds == kThemeStateInactive; - if (!drawColorless) + if (!tds == kThemeStateInactive) QMacStylePrivate::drawCombobox(qt_hirectForQRect(combo->rect), bdi, p); else d->drawColorlessButton(qt_hirectForQRect(combo->rect), &bdi, p, opt); @@ -5310,7 +5286,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); @@ -5988,10 +5964,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); @@ -6019,12 +5996,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 @@ -6375,9 +6352,10 @@ 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.setDevicePixelRatio(pixmap.devicePixelRatio()); pix2.fill(Qt::transparent); QPainter p(&pix2); p.translate(pix2.width(), 0); @@ -6527,7 +6505,7 @@ void qt_mac_scale_region(QRegion *region, qreal scaleFactor) scaledRects.reserve(region->rects().count()); foreach (const QRect &rect, region->rects()) { - scaledRects.append(QRect(rect.topLeft(), rect.size() * scaleFactor)); + scaledRects.append(QRect(rect.topLeft() * scaleFactor, rect.size() * scaleFactor)); } region->setRects(&scaledRects[0], scaledRects.count()); } @@ -6556,15 +6534,16 @@ QMacCGContext::QMacCGContext(QPainter *p) context = CGBitmapContextCreate((void *) image->bits(), image->width(), image->height(), 8, image->bytesPerLine(), colorspace, flags); + // Invert y axis. CGContextTranslateCTM(context, 0, image->height()); CGContextScaleCTM(context, 1, -1); + const qreal devicePixelRatio = image->devicePixelRatio(); + if (devType == QInternal::Widget) { // Set the clip rect which is an intersection of the system clip // and the painter clip. To make matters more interesting these // are in device pixels and device-independent pixels, respectively. - const qreal devicePixelRatio = image->devicePixelRatio(); - QRegion clip = p->paintEngine()->systemClip(); // get system clip in device pixels QTransform native = p->deviceTransform(); // get device transform. dx/dy is in device pixels @@ -6582,6 +6561,9 @@ QMacCGContext::QMacCGContext(QPainter *p) // Scale the context so that painting happens in device-independet pixels. CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio); CGContextTranslateCTM(context, native.dx() / devicePixelRatio, native.dy() / devicePixelRatio); + } else { + // Scale to paint in device-independent pixels. + CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio); } } else { qDebug() << "QMacCGContext:: Unsupported painter devtype type" << devType; diff --git a/src/widgets/styles/qmacstyle_mac_p.h b/src/widgets/styles/qmacstyle_mac_p.h index d06a5a951f..305bcf871c 100644 --- a/src/widgets/styles/qmacstyle_mac_p.h +++ b/src/widgets/styles/qmacstyle_mac_p.h @@ -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 @@ -44,8 +44,6 @@ #include <QtWidgets/qcommonstyle.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -130,6 +128,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QMACSTYLE_MAC_P_H diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h index 6c0493fe04..c424ff0c3c 100644 --- a/src/widgets/styles/qmacstyle_mac_p_p.h +++ b/src/widgets/styles/qmacstyle_mac_p_p.h @@ -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 diff --git a/src/widgets/styles/qmacstylepixmaps_mac_p.h b/src/widgets/styles/qmacstylepixmaps_mac_p.h deleted file mode 100644 index f76383a2d4..0000000000 --- a/src/widgets/styles/qmacstylepixmaps_mac_p.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** 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. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMACSTYLEPIXMAPS_MAC_P_H -#define QMACSTYLEPIXMAPS_MAC_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -static const char * const qt_mac_toolbar_ext[]={ - "14 9 4 1", - "# c #858585", - "b c #d9d9d9", - ". c #dbdbdb", - "a c None", - ".###..###.aaaa", - "a.###..###.aaa", - "aab###bb###baa", - "aaab###bb###ba", - "aaaa.###..###.", - "aaa.###..###.a", - "aab###bb###baa", - "ab###bb###baaa", - ".###..###.aaaa"}; - -#endif // QMACSTYLEPIXMAPS_MAC_P_H diff --git a/src/widgets/styles/qproxystyle.cpp b/src/widgets/styles/qproxystyle.cpp index 66ace0f60b..b63e820bb9 100644 --- a/src/widgets/styles/qproxystyle.cpp +++ b/src/widgets/styles/qproxystyle.cpp @@ -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 @@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE \since 4.6 \inmodule QtWidgets - + A QProxyStyle wraps a QStyle (usually the default system style) for the purpose of dynamically overriding painting or other specific style behavior. @@ -108,10 +108,9 @@ void QProxyStylePrivate::ensureBaseStyle() const } /*! - Constructs a QProxyStyle object for overriding behavior in \a style - or in the current application \l{QStyle}{style} if \a style is 0 - (default). Normally \a style is 0, because you want to override - behavior in the system style. + Constructs a QProxyStyle object for overriding behavior in the + specified base \a style, or in the current \l{QApplication::style} + {application style} if base \a style is not specified. Ownership of \a style is transferred to QProxyStyle. */ @@ -127,6 +126,26 @@ QProxyStyle::QProxyStyle(QStyle *style) : } /*! + Constructs a QProxyStyle object for overriding behavior in + the base style specified by style \a key, or in the current + \l{QApplication::style}{application style} if the specified + style \a key is unrecognized. + + \sa QStyleFactory::create() +*/ +QProxyStyle::QProxyStyle(const QString &key) : + QCommonStyle(*new QProxyStylePrivate()) +{ + Q_D(QProxyStyle); + QStyle *style = QStyleFactory::create(key); + if (style) { + d->baseStyle = style; + style->setProxy(this); + style->setParent(this); // Take ownership + } +} + +/*! Destroys the QProxyStyle object. */ QProxyStyle::~QProxyStyle() diff --git a/src/widgets/styles/qproxystyle.h b/src/widgets/styles/qproxystyle.h index 52b02c8e5b..5864c195c6 100644 --- a/src/widgets/styles/qproxystyle.h +++ b/src/widgets/styles/qproxystyle.h @@ -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 @@ -44,8 +44,6 @@ #include <QtWidgets/QCommonStyle> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -57,7 +55,8 @@ class Q_WIDGETS_EXPORT QProxyStyle : public QCommonStyle Q_OBJECT public: - QProxyStyle(QStyle *baseStyle = 0); + QProxyStyle(QStyle *style = 0); + QProxyStyle(const QString &key); ~QProxyStyle(); QStyle *baseStyle() const; @@ -107,6 +106,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPROXYSTYLE_H diff --git a/src/widgets/styles/qproxystyle_p.h b/src/widgets/styles/qproxystyle_p.h index 3d428a0c84..92f6f73ccc 100644 --- a/src/widgets/styles/qproxystyle_p.h +++ b/src/widgets/styles/qproxystyle_p.h @@ -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 diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 9c4901795d..603d0e50a5 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -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 @@ -137,7 +137,7 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C state. \endtable - + For more information about widget styling and appearance, see the \l{Styles and Style Aware Widgets}. */ @@ -1891,6 +1891,9 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value SH_ScrollBar_Transient Determines if the style supports transient scroll bars. Transient scroll bars appear when the content is scrolled and disappear when they are no longer needed. + \value SH_Menu_SupportsSections Determines if the style displays sections in menus or treat them as + plain separators. Sections are separators with a text and icon hint. + \sa styleHint() */ diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index b69f5da6c5..beafad326e 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -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 @@ -50,8 +50,6 @@ #include <QtGui/qpalette.h> #include <QtWidgets/qsizepolicy.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -699,6 +697,7 @@ public: SH_ToolButtonStyle, SH_RequestSoftwareInputPanel, SH_ScrollBar_Transient, + SH_Menu_SupportsSections, // Add new style hint values here SH_CustomBase = 0xf0000000 @@ -831,6 +830,4 @@ Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, QStyle::State state); QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTYLE_H diff --git a/src/widgets/styles/qstyle.qrc b/src/widgets/styles/qstyle.qrc index d835728928..28ad484032 100644 --- a/src/widgets/styles/qstyle.qrc +++ b/src/widgets/styles/qstyle.qrc @@ -133,5 +133,7 @@ <file>images/closedock-down-16.png</file> <file>images/dockdock-16.png</file> <file>images/dockdock-down-16.png</file> + <file>images/toolbar-ext.png</file> + <file>images/toolbar-ext@2x.png</file> </qresource> </RCC> diff --git a/src/widgets/styles/qstyle_p.h b/src/widgets/styles/qstyle_p.h index 6cc28b7506..70221f6d8f 100644 --- a/src/widgets/styles/qstyle_p.h +++ b/src/widgets/styles/qstyle_p.h @@ -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 diff --git a/src/widgets/styles/qstyleanimation.cpp b/src/widgets/styles/qstyleanimation.cpp index 61048df96a..4fb67d90c0 100644 --- a/src/widgets/styles/qstyleanimation.cpp +++ b/src/widgets/styles/qstyleanimation.cpp @@ -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 @@ -46,13 +46,9 @@ QT_BEGIN_NAMESPACE -QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(), +QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(target), _delay(0), _duration(-1), _startTime(QTime::currentTime()) { - if (target) { - moveToThread(target->thread()); - setParent(target); - } } QStyleAnimation::~QStyleAnimation() diff --git a/src/widgets/styles/qstyleanimation_p.h b/src/widgets/styles/qstyleanimation_p.h index f9f0eced9d..77962bedac 100644 --- a/src/widgets/styles/qstyleanimation_p.h +++ b/src/widgets/styles/qstyleanimation_p.h @@ -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 diff --git a/src/widgets/styles/qstylefactory.cpp b/src/widgets/styles/qstylefactory.cpp index 471d3b748d..2b81acf246 100644 --- a/src/widgets/styles/qstylefactory.cpp +++ b/src/widgets/styles/qstylefactory.cpp @@ -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 @@ -48,6 +48,9 @@ #include "qwindowsstyle_p.h" #ifndef QT_NO_STYLE_FUSION #include "qfusionstyle_p.h" +#ifndef QT_NO_STYLE_ANDROID +#include "qandroidstyle_p.h" +#endif #endif #ifndef QT_NO_STYLE_GTK #include "qgtkstyle_p.h" @@ -143,6 +146,11 @@ QStyle *QStyleFactory::create(const QString& key) ret = new QFusionStyle; else #endif +#ifndef QT_NO_STYLE_ANDROID + if (style == QLatin1String("android")) + ret = new QAndroidStyle; + else +#endif #ifndef QT_NO_STYLE_GTK if (style == QLatin1String("gtk") || style == QLatin1String("gtk+")) ret = new QGtkStyle; @@ -206,6 +214,10 @@ QStringList QStyleFactory::keys() (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))) list << QLatin1String("WindowsVista"); #endif +#ifndef QT_NO_STYLE_ANDROID + if (!list.contains(QLatin1String("Android"))) + list << QLatin1String("Android"); +#endif #ifndef QT_NO_STYLE_GTK if (!list.contains(QLatin1String("GTK+"))) list << QLatin1String("GTK+"); diff --git a/src/widgets/styles/qstylefactory.h b/src/widgets/styles/qstylefactory.h index 500e86a9d4..539f47464b 100644 --- a/src/widgets/styles/qstylefactory.h +++ b/src/widgets/styles/qstylefactory.h @@ -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 @@ -44,8 +44,6 @@ #include <QtCore/qstringlist.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -60,6 +58,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTYLEFACTORY_H diff --git a/src/widgets/styles/qstylehelper.cpp b/src/widgets/styles/qstylehelper.cpp index 75c74e4a88..fc73488154 100644 --- a/src/widgets/styles/qstylehelper.cpp +++ b/src/widgets/styles/qstylehelper.cpp @@ -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 @@ -92,7 +92,6 @@ bool isInstanceOf(QObject *obj, QAccessible::Role role) bool match = false; QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(obj); match = iface && iface->role() == role; - delete iface; return match; } diff --git a/src/widgets/styles/qstylehelper_p.h b/src/widgets/styles/qstylehelper_p.h index 01772e765c..6355cbc985 100644 --- a/src/widgets/styles/qstylehelper_p.h +++ b/src/widgets/styles/qstylehelper_p.h @@ -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 diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp index 01e51d594d..4f4cd71070 100644 --- a/src/widgets/styles/qstyleoption.cpp +++ b/src/widgets/styles/qstyleoption.cpp @@ -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 @@ -206,7 +206,7 @@ void QStyleOption::init(const QWidget *widget) if (!(state & QStyle::State_Active) && !qt_mac_can_clickThrough(widget)) state &= ~QStyle::State_Enabled; #endif -#ifdef Q_OS_MAC +#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) switch (QMacStyle::widgetSizePolicy(widget)) { case QMacStyle::SizeSmall: state |= QStyle::State_Small; @@ -374,7 +374,7 @@ QStyleOption &QStyleOption::operator=(const QStyleOption &other) parameters for drawing a focus rectangle with QStyle. \inmodule QtWidgets - + For performance reasons, the access to the member variables is direct (i.e., using the \c . or \c -> operator). This low-level feel makes the structures straightforward to use and emphasizes that @@ -458,7 +458,7 @@ QStyleOptionFocusRect::QStyleOptionFocusRect(int version) parameters for drawing a frame. \inmodule QtWidgets - + QStyleOptionFrame is used for drawing several built-in Qt widgets, including QFrame, QGroupBox, QLineEdit, and QMenu. @@ -738,7 +738,7 @@ QStyleOptionGroupBox::QStyleOptionGroupBox(int version) parameters for drawing a header. \inmodule QtWidgets - + QStyleOptionHeader contains all the information that QStyle functions need to draw the item views' header pane, header sort arrow, and header label. @@ -925,7 +925,7 @@ QStyleOptionHeader::QStyleOptionHeader(int version) parameters for drawing buttons. \inmodule QtWidgets - + QStyleOptionButton contains all the information that QStyle functions need to draw graphical elements like QPushButton, QCheckBox, and QRadioButton. @@ -1237,7 +1237,7 @@ QStyleOptionToolBar::QStyleOptionToolBar(int version) parameters for drawing a tab bar. \inmodule QtWidgets - + The QStyleOptionTab class is used for drawing several built-in Qt widgets including \l QTabBar and the panel for \l QTabWidget. @@ -1662,7 +1662,7 @@ QStyleOptionProgressBar::QStyleOptionProgressBar(int version) parameter necessary for drawing a menu item. \inmodule QtWidgets - + QStyleOptionMenuItem contains all the information that QStyle functions need to draw the menu items from \l QMenu. It is also used for drawing other menu-related widgets. @@ -1862,7 +1862,7 @@ QStyleOptionMenuItem::QStyleOptionMenuItem(int version) common to all complex controls. \inmodule QtWidgets - + This class is not used on its own. Instead it is used to derive other complex control options, for example QStyleOptionSlider and QStyleOptionSpinBox. @@ -1953,7 +1953,7 @@ QStyleOptionComplex::QStyleOptionComplex(int version, int type) parameters needed for drawing a slider. \inmodule QtWidgets - + QStyleOptionSlider contains all the information that QStyle functions need to draw QSlider and QScrollBar. @@ -2152,7 +2152,7 @@ QStyleOptionSlider::QStyleOptionSlider(int version) parameters necessary for drawing a spin box. \inmodule QtWidgets - + QStyleOptionSpinBox contains all the information that QStyle functions need to draw QSpinBox and QDateTimeEdit. @@ -2257,7 +2257,7 @@ QStyleOptionSpinBox::QStyleOptionSpinBox(int version) parameters for drawing a dock widget. \inmodule QtWidgets - + QStyleOptionDockWidget contains all the information that QStyle functions need to draw graphical elements like QDockWidget. diff --git a/src/widgets/styles/qstyleoption.h b/src/widgets/styles/qstyleoption.h index 4109c8e702..4f817a3353 100644 --- a/src/widgets/styles/qstyleoption.h +++ b/src/widgets/styles/qstyleoption.h @@ -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 @@ -56,8 +56,6 @@ # include <QtCore/qabstractitemmodel.h> #endif -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -751,6 +749,4 @@ Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, const QStyleOption &option); QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTYLEOPTION_H diff --git a/src/widgets/styles/qstylepainter.cpp b/src/widgets/styles/qstylepainter.cpp index 1faf4a743b..5c2c44b45b 100644 --- a/src/widgets/styles/qstylepainter.cpp +++ b/src/widgets/styles/qstylepainter.cpp @@ -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 diff --git a/src/widgets/styles/qstylepainter.h b/src/widgets/styles/qstylepainter.h index dee01c09a3..2031921d12 100644 --- a/src/widgets/styles/qstylepainter.h +++ b/src/widgets/styles/qstylepainter.h @@ -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 @@ -46,8 +46,6 @@ #include <QtWidgets/qstyle.h> #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -106,6 +104,4 @@ void QStylePainter::drawItemPixmap(const QRect &r, int flags, const QPixmap &pix QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTYLEPAINTER_H diff --git a/src/widgets/styles/qstyleplugin.cpp b/src/widgets/styles/qstyleplugin.cpp index e8f9878603..77f5bd30f4 100644 --- a/src/widgets/styles/qstyleplugin.cpp +++ b/src/widgets/styles/qstyleplugin.cpp @@ -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 diff --git a/src/widgets/styles/qstyleplugin.h b/src/widgets/styles/qstyleplugin.h index d34f0c0a15..041bdbfa68 100644 --- a/src/widgets/styles/qstyleplugin.h +++ b/src/widgets/styles/qstyleplugin.h @@ -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 @@ -45,8 +45,6 @@ #include <QtCore/qplugin.h> #include <QtCore/qfactoryinterface.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -66,6 +64,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTYLEPLUGIN_H diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 7087e2a5ca..be89abf2b2 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -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 diff --git a/src/widgets/styles/qstylesheetstyle_default.cpp b/src/widgets/styles/qstylesheetstyle_default.cpp index 2c9a72b4b4..bca4c8928a 100644 --- a/src/widgets/styles/qstylesheetstyle_default.cpp +++ b/src/widgets/styles/qstylesheetstyle_default.cpp @@ -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 diff --git a/src/widgets/styles/qstylesheetstyle_p.h b/src/widgets/styles/qstylesheetstyle_p.h index a199721200..9ca3c9ed24 100644 --- a/src/widgets/styles/qstylesheetstyle_p.h +++ b/src/widgets/styles/qstylesheetstyle_p.h @@ -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 diff --git a/src/widgets/styles/qwindowscestyle.cpp b/src/widgets/styles/qwindowscestyle.cpp index f297e64631..564e84b35b 100644 --- a/src/widgets/styles/qwindowscestyle.cpp +++ b/src/widgets/styles/qwindowscestyle.cpp @@ -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 diff --git a/src/widgets/styles/qwindowscestyle_p.h b/src/widgets/styles/qwindowscestyle_p.h index 5d38abe41b..73fb2b7ab7 100644 --- a/src/widgets/styles/qwindowscestyle_p.h +++ b/src/widgets/styles/qwindowscestyle_p.h @@ -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 @@ -44,8 +44,6 @@ #include <private/qwindowsstyle_p.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -98,6 +96,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWINDOWSCESTYLE_P_H diff --git a/src/widgets/styles/qwindowscestyle_p_p.h b/src/widgets/styles/qwindowscestyle_p_p.h index 7fbf6d8160..f17aae7cbb 100644 --- a/src/widgets/styles/qwindowscestyle_p_p.h +++ b/src/widgets/styles/qwindowscestyle_p_p.h @@ -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 diff --git a/src/widgets/styles/qwindowsmobilestyle.cpp b/src/widgets/styles/qwindowsmobilestyle.cpp index 2b30bf5a2d..36c5d7e1bb 100644 --- a/src/widgets/styles/qwindowsmobilestyle.cpp +++ b/src/widgets/styles/qwindowsmobilestyle.cpp @@ -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 @@ -90,7 +90,7 @@ static const int windowsMobileExclusiveIndicatorSize = 14; static const int windowsMobileSliderThickness = 6; static const int windowsMobileIconSize = 16; static const int PE_IndicatorArrowUpBig = 0xf000101; -static const int PE_IndicatorArrowDownBig = 0xf000102; +static const int PE_IndicatorArrowDownBig = 0xf000102; static const int PE_IndicatorArrowLeftBig = 0xf000103; static const int PE_IndicatorArrowRightBig = 0xf000104; @@ -241,7 +241,7 @@ static const char *const radiochecked_xpm[] = { static const char * const radiochecked_low_xpm[] = { "9 9 2 1", " c None", - ". c #000000", + ". c #000000", " ... ", " ....... ", " ....... ", @@ -3904,39 +3904,39 @@ QColor fromHsl(QColor c) qreal ca[3] = {0, 0, 0}; if (s == 0 || h == 1) { - // achromatic case + // achromatic case ca[0] = ca[1] = ca[2] = l; - } else { - // chromatic case - qreal temp2; - if (l < qreal(0.5)) - temp2 = l * (qreal(1.0) + s); - else - temp2 = l + s - (l * s); - - const qreal temp1 = (qreal(2.0) * l) - temp2; - qreal temp3[3] = { h + (qreal(1.0) / qreal(3.0)), - h, - h - (qreal(1.0) / qreal(3.0)) }; - - for (int i = 0; i != 3; ++i) { - if (temp3[i] < qreal(0.0)) - temp3[i] += qreal(1.0); - else if (temp3[i] > qreal(1.0)) + } else { + // chromatic case + qreal temp2; + if (l < qreal(0.5)) + temp2 = l * (qreal(1.0) + s); + else + temp2 = l + s - (l * s); + + const qreal temp1 = (qreal(2.0) * l) - temp2; + qreal temp3[3] = { h + (qreal(1.0) / qreal(3.0)), + h, + h - (qreal(1.0) / qreal(3.0)) }; + + for (int i = 0; i != 3; ++i) { + if (temp3[i] < qreal(0.0)) + temp3[i] += qreal(1.0); + else if (temp3[i] > qreal(1.0)) temp3[i] -= qreal(1.0); const qreal sixtemp3 = temp3[i] * qreal(6.0); - if (sixtemp3 < qreal(1.0)) - ca[i] = ((temp1 + (temp2 - temp1) * sixtemp3)); - else if ((temp3[i] * qreal(2.0)) < qreal(1.0)) - ca[i] = (temp2); - else if ((temp3[i] * qreal(3.0)) < qreal(2.0)) + if (sixtemp3 < qreal(1.0)) + ca[i] = ((temp1 + (temp2 - temp1) * sixtemp3)); + else if ((temp3[i] * qreal(2.0)) < qreal(1.0)) + ca[i] = (temp2); + else if ((temp3[i] * qreal(3.0)) < qreal(2.0)) ca[i] = temp1 + (temp2 -temp1) * (qreal(2.0) /qreal(3.0) - temp3[i]) * qreal(6.0); else ca[i] = temp1; } } - + return QColor::fromRgbF(ca[0], ca[1], ca[2]); } @@ -3945,7 +3945,7 @@ QColor fromHsl(QColor c) QColor toHsl(QColor c) { - QColor color; + QColor color; qreal h; qreal s; qreal l; @@ -3953,36 +3953,36 @@ QColor toHsl(QColor c) const qreal r = c.redF(); const qreal g = c.greenF(); const qreal b = c.blueF(); - const qreal max = Q_MAX_3(r, g, b); - const qreal min = Q_MIN_3(r, g, b); - const qreal delta = max - min; - const qreal delta2 = max + min; - const qreal lightness = qreal(0.5) * delta2; + const qreal max = Q_MAX_3(r, g, b); + const qreal min = Q_MIN_3(r, g, b); + const qreal delta = max - min; + const qreal delta2 = max + min; + const qreal lightness = qreal(0.5) * delta2; l = (lightness); - if (qFuzzyIsNull(delta)) { - // achromatic case, hue is undefined + if (qFuzzyIsNull(delta)) { + // achromatic case, hue is undefined h = 0; - s = 0; + s = 0; } else { - // chromatic case - qreal hue = 0; - if (lightness < qreal(0.5)) - s = ((delta / delta2)); - else - s = ((delta / (qreal(2.0) - delta2))); - if (qFuzzyCompare(r, max)) { - hue = ((g - b) /delta); - } else if (qFuzzyCompare(g, max)) { - hue = (2.0 + (b - r) / delta); - } else if (qFuzzyCompare(b, max)) { - hue = (4.0 + (r - g) / delta); - } else { - Q_ASSERT_X(false, "QColor::toHsv", "internal error"); + // chromatic case + qreal hue = 0; + if (lightness < qreal(0.5)) + s = ((delta / delta2)); + else + s = ((delta / (qreal(2.0) - delta2))); + if (qFuzzyCompare(r, max)) { + hue = ((g - b) /delta); + } else if (qFuzzyCompare(g, max)) { + hue = (2.0 + (b - r) / delta); + } else if (qFuzzyCompare(b, max)) { + hue = (4.0 + (r - g) / delta); + } else { + Q_ASSERT_X(false, "QColor::toHsv", "internal error"); } - hue *= 60.0; - if (hue < 0.0) - hue += 360.0; - h = (hue * 100); + hue *= 60.0; + if (hue < 0.0) + hue += 360.0; + h = (hue * 100); } h = h / 36000; @@ -4083,7 +4083,7 @@ void QWindowsMobileStylePrivate::tintListViewHighlight(QColor color) imageListViewHighlightMiddle = QImage(listviewhighmiddle_xpm); tintImage(&imageListViewHighlightMiddle, color, qreal(0.0)); - + int height = imageListViewHighlightMiddle.height(); if (!doubleControls) { height = height / 2; @@ -4218,7 +4218,7 @@ void QWindowsMobileStylePrivate::drawPanelItemViewSelected(QPainter *painter, co QRect r; if (rect.isValid()) r = rect; - else + else r = option->rect; tintImagesHigh(option->palette.highlight().color()); @@ -4892,7 +4892,7 @@ void QWindowsMobileStyle::drawPrimitive(PrimitiveElement element, const QStyleOp } else { QRect r = QRect(option->rect.x(), option->rect.y(), windowsMobileitemViewCheckBoxSize, windowsMobileitemViewCheckBoxSize); qDrawPlainRect(painter, r, option->palette.shadow().color(), 1); - } + } if (option->state & State_Enabled) d->imageChecked.setColor(1, option->palette.shadow().color().rgba()); else @@ -5129,7 +5129,7 @@ void QWindowsMobileStyle::drawPrimitive(PrimitiveElement element, const QStyleOp image.setColor(1, color.rgba()); painter->drawImage(option->rect.x() + xoffset, option->rect.y() + yoffset, image); } - else { + else { QPoint points[7]; switch (element) { case PE_IndicatorArrowUp: @@ -5194,7 +5194,7 @@ void QWindowsMobileStyle::drawPrimitive(PrimitiveElement element, const QStyleOp painter->drawLine(points[2], points[3]); painter->drawLine(points[4], points[5]); painter->drawPoint(points[6]); - } + } } painter->restore(); break; } @@ -5432,7 +5432,7 @@ void QWindowsMobileStyle::drawControl(ControlElement element, const QStyleOption QWindowsMobileStylePrivate *d = const_cast<QWindowsMobileStylePrivate*>(d_func()); - + painter->setClipping(false); switch (element) { case CE_MenuBarEmptyArea: @@ -5527,7 +5527,7 @@ void QWindowsMobileStyle::drawControl(ControlElement element, const QStyleOption break; case CE_TabBarTabShape: if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) { - + if (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::RoundedWest) { d->drawTabBarTab(painter, tab); @@ -5564,7 +5564,7 @@ void QWindowsMobileStyle::drawControl(ControlElement element, const QStyleOption proxy()->drawControl(CE_HeaderSection, header, painter, widget); QStyleOptionHeader subopt = *header; subopt.rect = proxy()->subElementRect(SE_HeaderLabel, header, widget); - if (header->state & State_Sunken) + if (header->state & State_Sunken) subopt.palette.setColor(QPalette::ButtonText, header->palette.brightText().color()); subopt.state |= QStyle::State_On; if (subopt.rect.isValid()) @@ -7079,7 +7079,7 @@ int QWindowsMobileStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, co } break; case PM_ScrollBarExtent: { - + if (d->smartphone) ret = 9; else diff --git a/src/widgets/styles/qwindowsmobilestyle_p.h b/src/widgets/styles/qwindowsmobilestyle_p.h index 21df982344..4262bf5c73 100644 --- a/src/widgets/styles/qwindowsmobilestyle_p.h +++ b/src/widgets/styles/qwindowsmobilestyle_p.h @@ -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 @@ -44,8 +44,6 @@ #include <private/qwindowsstyle_p.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -111,6 +109,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif //QWINDOWSMOBILESTYLE_P_H diff --git a/src/widgets/styles/qwindowsmobilestyle_p_p.h b/src/widgets/styles/qwindowsmobilestyle_p_p.h index d73c6eebaa..45e02fb379 100644 --- a/src/widgets/styles/qwindowsmobilestyle_p_p.h +++ b/src/widgets/styles/qwindowsmobilestyle_p_p.h @@ -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 diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 2b48096a7b..86fccabcbc 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -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 @@ -2358,7 +2358,6 @@ QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2); break; #endif - // Otherwise, fall through case CT_ToolButton: if (qstyleoption_cast<const QStyleOptionToolButton *>(opt)) return sz += QSize(7, 6); diff --git a/src/widgets/styles/qwindowsstyle_p.h b/src/widgets/styles/qwindowsstyle_p.h index 65573acf67..1107e70061 100644 --- a/src/widgets/styles/qwindowsstyle_p.h +++ b/src/widgets/styles/qwindowsstyle_p.h @@ -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 @@ -44,8 +44,6 @@ #include <QtWidgets/qcommonstyle.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -103,6 +101,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWINDOWSSTYLE_P_H diff --git a/src/widgets/styles/qwindowsstyle_p_p.h b/src/widgets/styles/qwindowsstyle_p_p.h index ca77964fb8..872b6f0e9e 100644 --- a/src/widgets/styles/qwindowsstyle_p_p.h +++ b/src/widgets/styles/qwindowsstyle_p_p.h @@ -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 diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 48d2027834..f65e52305c 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -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 @@ -273,15 +273,15 @@ void QWindowsVistaAnimation::paint(QPainter *painter, const QStyleOption *option /*! \internal - + Animations are used for some state transitions on specific widgets. - + Only one running animation can exist for a widget at any specific time. Animations can be added through QWindowsVistaStylePrivate::startAnimation(Animation *) and any existing animation on a widget can be retrieved with QWindowsVistaStylePrivate::widgetAnimation(Widget *). - + Once an animation has been started, QWindowsVistaStylePrivate::timerEvent(QTimerEvent *) will continuously call update() on the widget until it is stopped, @@ -377,8 +377,9 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt // The end state of the transition is simply the result we would have painted // if the style was not animated. + styleOption->styleObject = 0; styleOption->state = option->state; - drawPrimitive(element, styleOption, &endPainter, widget); + proxy()->drawPrimitive(element, styleOption, &endPainter, widget); t->setEndImage(endImage); @@ -520,7 +521,12 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt } break; case PE_Frame: { - if (QStyleHelper::isInstanceOf(option->styleObject, QAccessible::EditableText)) { +#ifndef QT_NO_ACCESSIBILITY + if (QStyleHelper::isInstanceOf(option->styleObject, QAccessible::EditableText) + || QStyleHelper::isInstanceOf(option->styleObject, QAccessible::StaticText)) { +#else + if (false) { +#endif painter->save(); int stateId = ETS_NORMAL; if (!(state & State_Enabled)) @@ -532,16 +538,13 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt XPThemeData theme(widget, painter, QWindowsXPStylePrivate::EditTheme, EP_EDITBORDER_HVSCROLL, stateId, option->rect); - uint resolve_mask = option->palette.resolve(); - if (resolve_mask & (1 << QPalette::Base)) { - // Since EP_EDITBORDER_HVSCROLL does not us borderfill, theme.noContent cannot be used for clipping - int borderSize = 1; - pGetThemeInt(theme.handle(), theme.partId, theme.stateId, TMT_BORDERSIZE, &borderSize); - QRegion clipRegion = option->rect; - QRegion content = option->rect.adjusted(borderSize, borderSize, -borderSize, -borderSize); - clipRegion ^= content; - painter->setClipRegion(clipRegion); - } + // Since EP_EDITBORDER_HVSCROLL does not us borderfill, theme.noContent cannot be used for clipping + int borderSize = 1; + pGetThemeInt(theme.handle(), theme.partId, theme.stateId, TMT_BORDERSIZE, &borderSize); + QRegion clipRegion = option->rect; + QRegion content = option->rect.adjusted(borderSize, borderSize, -borderSize, -borderSize); + clipRegion ^= content; + painter->setClipRegion(clipRegion); d->drawBackground(theme); painter->restore(); } else { @@ -794,17 +797,17 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt || vopt->viewItemPosition == QStyleOptionViewItem::Invalid) painter->drawPixmap(pixmapRect.topLeft(), pixmap); else if (reverse ? rightSection : leftSection){ - painter->drawPixmap(QRect(pixmapRect.topLeft(), - QSize(frame, pixmapRect.height())), pixmap, + painter->drawPixmap(QRect(pixmapRect.topLeft(), + QSize(frame, pixmapRect.height())), pixmap, QRect(QPoint(0, 0), QSize(frame, pixmapRect.height()))); - painter->drawPixmap(pixmapRect.adjusted(frame, 0, 0, 0), + painter->drawPixmap(pixmapRect.adjusted(frame, 0, 0, 0), pixmap, srcRect.adjusted(frame, 0, -frame, 0)); } else if (reverse ? leftSection : rightSection) { - painter->drawPixmap(QRect(pixmapRect.topRight() - QPoint(frame - 1, 0), - QSize(frame, pixmapRect.height())), pixmap, - QRect(QPoint(pixmapRect.width() - frame, 0), + painter->drawPixmap(QRect(pixmapRect.topRight() - QPoint(frame - 1, 0), + QSize(frame, pixmapRect.height())), pixmap, + QRect(QPoint(pixmapRect.width() - frame, 0), QSize(frame, pixmapRect.height()))); - painter->drawPixmap(pixmapRect.adjusted(0, 0, -frame, 0), + painter->drawPixmap(pixmapRect.adjusted(0, 0, -frame, 0), pixmap, srcRect.adjusted(frame, 0, -frame, 0)); } else if (vopt->viewItemPosition == QStyleOptionViewItem::Middle) painter->drawPixmap(pixmapRect, pixmap, @@ -1106,7 +1109,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption } else { animRect = QRect(rect.left() - glowSize + animOffset, rect.top(), glowSize, rect.height()); - animRect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight, + animRect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight, option->rect, animRect); pixmapSize.setWidth(animRect.width()); } @@ -1152,7 +1155,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(double(1.0), double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth); int width = isIndeterminate ? maxWidth : qMax(int(vc6_workaround), minWidth); theme.rect.setWidth(width); - theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight, + theme.rect = QStyle::visualRect(reverse ? Qt::RightToLeft : Qt::LeftToRight, option->rect, theme.rect); } d->drawBackground(theme); @@ -1518,7 +1521,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QStyleOptionViewItem adjustedOption = *vopt; adjustedOption.palette = palette; // We hide the focusrect in singleselection as it is not required - if ((view->selectionMode() == QAbstractItemView::SingleSelection) + if ((view->selectionMode() == QAbstractItemView::SingleSelection) && !(vopt->state & State_KeyboardFocusChange)) adjustedOption.state &= ~State_HasFocus; QWindowsXPStyle::drawControl(element, &adjustedOption, painter, widget); @@ -1581,7 +1584,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) || (state & State_On) != (oldState & State_On) || (state & State_MouseOver) != (oldState & State_MouseOver) || - oldActiveControls != option->activeSubControls); + oldActiveControls != int(option->activeSubControls)); if (qstyleoption_cast<const QStyleOptionSlider *>(option)) { QRect oldSliderPos = styleObject->property("_q_stylesliderpos").toRect(); @@ -1940,7 +1943,7 @@ QSize QWindowsVistaStyle::sizeFromContents(ContentsType type, const QStyleOption minimumHeight = qMax<qint32>(size.cy + margins.cyBottomHeight+ margins.cyTopHeight, sz.height()); sz.rwidth() += size.cx + margins.cxLeftWidth + margins.cxRightWidth; } - + if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { if (menuitem->menuItemType != QStyleOptionMenuItem::Separator) sz.setHeight(minimumHeight); diff --git a/src/widgets/styles/qwindowsvistastyle_p.h b/src/widgets/styles/qwindowsvistastyle_p.h index 2a06c78806..f7914f1645 100644 --- a/src/widgets/styles/qwindowsvistastyle_p.h +++ b/src/widgets/styles/qwindowsvistastyle_p.h @@ -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 @@ -44,8 +44,6 @@ #include <private/qwindowsxpstyle_p.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -99,6 +97,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWINDOWSVISTASTYLE_P_H diff --git a/src/widgets/styles/qwindowsvistastyle_p_p.h b/src/widgets/styles/qwindowsvistastyle_p_p.h index 17d510abf2..f2f208fbb5 100644 --- a/src/widgets/styles/qwindowsvistastyle_p_p.h +++ b/src/widgets/styles/qwindowsvistastyle_p_p.h @@ -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 diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index 8bd5699e4a..64569cfd9b 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -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 diff --git a/src/widgets/styles/qwindowsxpstyle_p.h b/src/widgets/styles/qwindowsxpstyle_p.h index 626bcc4ad7..d61132295c 100644 --- a/src/widgets/styles/qwindowsxpstyle_p.h +++ b/src/widgets/styles/qwindowsxpstyle_p.h @@ -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 @@ -44,8 +44,6 @@ #include <private/qwindowsstyle_p.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -99,6 +97,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWINDOWSXPSTYLE_P_H diff --git a/src/widgets/styles/qwindowsxpstyle_p_p.h b/src/widgets/styles/qwindowsxpstyle_p_p.h index 234b8e8a59..783adc3085 100644 --- a/src/widgets/styles/qwindowsxpstyle_p_p.h +++ b/src/widgets/styles/qwindowsxpstyle_p_p.h @@ -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 diff --git a/src/widgets/styles/styles.pri b/src/widgets/styles/styles.pri index b15eb1fa48..b39b17fd86 100644 --- a/src/widgets/styles/styles.pri +++ b/src/widgets/styles/styles.pri @@ -40,7 +40,7 @@ contains( styles, all ) { styles = fusion mac windows windowsxp windowsvista } -!macx-*|ios:styles -= mac +!macx:styles -= mac contains(QT_CONFIG, gtkstyle) { QMAKE_CXXFLAGS += $$QT_CFLAGS_QGTKSTYLE @@ -52,7 +52,6 @@ contains(QT_CONFIG, gtkstyle) { contains( styles, mac ) { HEADERS += \ styles/qmacstyle_mac_p.h \ - styles/qmacstylepixmaps_mac_p.h \ styles/qmacstyle_mac_p_p.h OBJECTIVE_SOURCES += styles/qmacstyle_mac.mm @@ -136,3 +135,10 @@ contains( styles, windowsmobile ) { } else { DEFINES += QT_NO_STYLE_WINDOWSMOBILE } + +contains( styles, android ) { + HEADERS += styles/qandroidstyle_p.h + SOURCES += styles/qandroidstyle.cpp +} else { + DEFINES += QT_NO_STYLE_ANDROID +} |