diff options
Diffstat (limited to 'src/widgets/styles')
-rw-r--r-- | src/widgets/styles/images/cleartext-16.png | bin | 0 -> 760 bytes | |||
-rw-r--r-- | src/widgets/styles/qandroidstyle.cpp | 353 | ||||
-rw-r--r-- | src/widgets/styles/qandroidstyle_p.h | 22 | ||||
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 35 | ||||
-rw-r--r-- | src/widgets/styles/qcommonstyle_p.h | 12 | ||||
-rw-r--r-- | src/widgets/styles/qgtkstyle_p.cpp | 3 | ||||
-rw-r--r-- | src/widgets/styles/qstyle.cpp | 17 | ||||
-rw-r--r-- | src/widgets/styles/qstyle.h | 5 | ||||
-rw-r--r-- | src/widgets/styles/qstyle.qrc | 1 | ||||
-rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 32 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsxpstyle.cpp | 6 |
11 files changed, 380 insertions, 106 deletions
diff --git a/src/widgets/styles/images/cleartext-16.png b/src/widgets/styles/images/cleartext-16.png Binary files differnew file mode 100644 index 0000000000..74133bafff --- /dev/null +++ b/src/widgets/styles/images/cleartext-16.png diff --git a/src/widgets/styles/qandroidstyle.cpp b/src/widgets/styles/qandroidstyle.cpp index d82a06987a..afd6c3024c 100644 --- a/src/widgets/styles/qandroidstyle.cpp +++ b/src/widgets/styles/qandroidstyle.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -54,9 +54,12 @@ #include <QPainter> #include <QJsonDocument> #include <QJsonObject> - #include <QDebug> +#include <QGuiApplication> +#include <qpa/qplatformnativeinterface.h> +#include <qpa/qplatformtheme.h> + QT_BEGIN_NAMESPACE namespace { @@ -71,16 +74,69 @@ namespace { const quint32 TRANSPARENT_COLOR = 0; } +static int fontType(const QString &androidControl) +{ + if (androidControl == QLatin1String("textViewStyle")) + return QPlatformTheme::SystemFont; + else if (androidControl == QLatin1String("buttonStyle")) + return QPlatformTheme::PushButtonFont; + else if (androidControl == QLatin1String("checkboxStyle")) + return QPlatformTheme::CheckBoxFont; + else if (androidControl == QLatin1String("radioButtonStyle")) + return QPlatformTheme::RadioButtonFont; + else if (androidControl == QLatin1String("simple_list_item_single_choice")) + return QPlatformTheme::ItemViewFont; + else if (androidControl == QLatin1String("simple_spinner_dropdown_item")) + return QPlatformTheme::ComboMenuItemFont; + else if (androidControl == QLatin1String("spinnerStyle")) + return QPlatformTheme::ComboLineEditFont; + else if (androidControl == QLatin1String("simple_list_item")) + return QPlatformTheme::ListViewFont; + return -1; +} + +static int paletteType(const QString &androidControl) +{ + if (androidControl == QLatin1String("textViewStyle")) + return QPlatformTheme::SystemPalette; + else if (androidControl == QLatin1String("buttonStyle")) + return QPlatformTheme::ButtonPalette; + else if (androidControl == QLatin1String("checkboxStyle")) + return QPlatformTheme::CheckBoxPalette; + else if (androidControl == QLatin1String("radioButtonStyle")) + return QPlatformTheme::RadioButtonPalette; + else if (androidControl == QLatin1String("simple_list_item_single_choice")) + return QPlatformTheme::ItemViewPalette; + else if (androidControl == QLatin1String("editTextStyle")) + return QPlatformTheme::TextLineEditPalette; + else if (androidControl == QLatin1String("spinnerStyle")) + return QPlatformTheme::ComboBoxPalette; + return -1; +} QAndroidStyle::QAndroidStyle() - : QCommonStyle() + : QFusionStyle() { + QPixmapCache::clear(); QString stylePath(QLatin1String(qgetenv("MINISTRO_ANDROID_STYLE_PATH"))); + const QLatin1Char slashChar('/'); + if (!stylePath.isEmpty() && !stylePath.endsWith(slashChar)) + stylePath += slashChar; + + QString androidTheme = QLatin1String(qgetenv("QT_ANDROID_THEME")); + if (!androidTheme.isEmpty() && !androidTheme.endsWith(slashChar)) + androidTheme += slashChar; if (stylePath.isEmpty()) - stylePath = QLatin1String("/data/data/org.kde.necessitas.ministro/files/qt/style/"); + { + stylePath = QLatin1String("/data/data/org.kde.necessitas.ministro/files/dl/style/") + + QLatin1String(qgetenv("QT_ANDROID_THEME_DISPLAY_DPI")) + slashChar; + } Q_ASSERT(!stylePath.isEmpty()); + if (!androidTheme.isEmpty() && QFileInfo(stylePath + androidTheme + QLatin1String("style.json")).exists()) + stylePath += androidTheme; + QFile f(stylePath + QLatin1String("style.json")); if (!f.open(QIODevice::ReadOnly)) return; @@ -97,6 +153,12 @@ QAndroidStyle::QAndroidStyle() return; } + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + + QHash<int, QPalette> * palettes = reinterpret_cast<QHash<int, QPalette> *>(nativeInterface->nativeResourceForIntegration("AndroidStylePalettes")); + QHash<int, QFont> * fonts = reinterpret_cast<QHash<int, QFont> *>(nativeInterface->nativeResourceForIntegration("AndroidStyleFonts")); + palettes->clear(); + fonts->clear(); QJsonObject object = document.object(); for (QJsonObject::const_iterator objectIterator = object.constBegin(); objectIterator != object.constEnd(); @@ -110,10 +172,13 @@ QAndroidStyle::QAndroidStyle() QJsonObject item = value.toObject(); QJsonObject::const_iterator attributeIterator = item.find(QLatin1String("qtClass")); + QString qtClassName; if (attributeIterator != item.constEnd()) { // The item has palette and font information for a specific Qt Class (e.g. QWidget, QPushButton, etc.) - const QString qtClassName = attributeIterator.value().toString(); - + qtClassName = attributeIterator.value().toString(); + } + const int ft = fontType(key); + if (ft > -1 || !qtClassName.isEmpty()) { // Extract font information QFont font; @@ -147,11 +212,25 @@ QAndroidStyle::QAndroidStyle() } font.setStyleHint(styleHint, QFont::PreferMatch); } - QApplication::setFont(font, qtClassName.toUtf8()); + if (!qtClassName.isEmpty()) + QApplication::setFont(font, qtClassName.toUtf8()); + if (ft>-1) + fonts->insert(ft, font); // Extract font information + } + const int pt = paletteType(key); + if (pt > -1 || !qtClassName.isEmpty()) { // Extract palette information QPalette palette; + attributeIterator = item.find(QLatin1String("defaultTextColorPrimary")); + if (attributeIterator != item.constEnd()) + palette.setColor(QPalette::WindowText, QRgb(int(attributeIterator.value().toDouble()))); + + attributeIterator = item.find(QLatin1String("defaultBackgroundColor")); + if (attributeIterator != item.constEnd()) + palette.setColor(QPalette::Background, QRgb(int(attributeIterator.value().toDouble()))); + attributeIterator = item.find(QLatin1String("TextAppearance_textColor")); if (attributeIterator != item.constEnd()) setPaletteColor(attributeIterator.value().toObject().toVariantMap(), palette, QPalette::WindowText); @@ -163,10 +242,12 @@ QAndroidStyle::QAndroidStyle() 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; + + if (pt > -1) + palettes->insert(pt, palette); // Extract palette information } QAndroidStyle::ItemType itemType = qtControl(key); @@ -201,10 +282,6 @@ QAndroidStyle::QAndroidStyle() 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() @@ -318,8 +395,6 @@ QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::ComplexControl control) return QC_Combobox; case CC_Slider: return QC_Slider; - case CC_GroupBox: - return QC_View; default: return QC_UnknownType; } @@ -340,6 +415,8 @@ QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::ContentsType contentsTy return QC_ProgressBar; case CT_Slider: return QC_Slider; + case CT_ScrollBar: + return QC_Slider; case CT_TabWidget: return QC_Tab; case CT_TabBarTab: @@ -383,6 +460,9 @@ QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::ControlElement controlE case CE_ComboBoxLabel: return QC_Combobox; + case CE_ShapedFrame: + return QC_View; + default: return QC_UnknownType; } @@ -438,7 +518,7 @@ void QAndroidStyle::drawPrimitive(PrimitiveElement pe, if (it != m_androidControlsHash.end()) it.value()->drawControl(opt, p, w); else - QCommonStyle::drawPrimitive(pe, opt, p, w); + QFusionStyle::drawPrimitive(pe, opt, p, w); } @@ -452,16 +532,17 @@ void QAndroidStyle::drawControl(QStyle::ControlElement element, ? m_androidControlsHash.find(itemType) : m_androidControlsHash.end(); if (it != m_androidControlsHash.end()) { - it.value()->drawControl(opt, p, w); + AndroidControl *androidControl = it.value(); + androidControl->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); + QMargins padding = androidControl->padding(); + QStyleOptionButton copy(*buttonOption); copy.rect.adjust(padding.left(), padding.top(), -padding.right(), -padding.bottom()); - QCommonStyle::drawControl(CE_PushButtonLabel, ©, p, w); + QFusionStyle::drawControl(CE_PushButtonLabel, ©, p, w); } break; case QC_Checkbox: @@ -472,26 +553,24 @@ void QAndroidStyle::drawControl(QStyle::ControlElement element, QStyleOptionButton subopt(*btn); subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents : SE_CheckBoxContents, btn, w); - QCommonStyle::drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, p, w); + QFusionStyle::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(); + QMargins padding = androidControl->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); + QFusionStyle::drawControl(CE_ComboBoxLabel, comboboxOption, p, w); } break; default: break; } + } else { + QFusionStyle::drawControl(element, opt, p, w); } - else - QCommonStyle::drawControl(element, opt, p, w); } QRect QAndroidStyle::subElementRect(SubElement subElement, @@ -504,7 +583,7 @@ QRect QAndroidStyle::subElementRect(SubElement subElement, : m_androidControlsHash.end(); if (it != m_androidControlsHash.end()) return it.value()->subElementRect(subElement, option, widget); - return QCommonStyle::subElementRect(subElement, option, widget); + return QFusionStyle::subElementRect(subElement, option, widget); } void QAndroidStyle::drawComplexControl(ComplexControl cc, @@ -519,7 +598,7 @@ void QAndroidStyle::drawComplexControl(ComplexControl cc, if (it != m_androidControlsHash.end()) it.value()->drawControl(opt, p, widget); else - QCommonStyle::drawComplexControl(cc, opt, p, widget); + QFusionStyle::drawComplexControl(cc, opt, p, widget); } QStyle::SubControl QAndroidStyle::hitTestComplexControl(ComplexControl cc, @@ -549,7 +628,7 @@ QStyle::SubControl QAndroidStyle::hitTestComplexControl(ComplexControl cc, break; } } - return QCommonStyle::hitTestComplexControl(cc, opt, pt, widget); + return QFusionStyle::hitTestComplexControl(cc, opt, pt, widget); } QRect QAndroidStyle::subControlRect(ComplexControl cc, @@ -563,7 +642,8 @@ QRect QAndroidStyle::subControlRect(ComplexControl cc, : m_androidControlsHash.end(); if (it != m_androidControlsHash.end()) return it.value()->subControlRect(opt, sc, widget); - return QCommonStyle::subControlRect(cc, opt, sc, widget); + + return QFusionStyle::subControlRect(cc, opt, sc, widget); } int QAndroidStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, @@ -575,9 +655,10 @@ int QAndroidStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, case PM_FocusFrameHMargin: case PM_ComboBoxFrameWidth: case PM_SpinBoxFrameWidth: + case PM_ScrollBarExtent: return 0; default: - return QCommonStyle::pixelMetric(metric, option, widget); + return QFusionStyle::pixelMetric(metric, option, widget); } } @@ -587,7 +668,7 @@ QSize QAndroidStyle::sizeFromContents(ContentsType ct, const QSize &contentsSize, const QWidget *w) const { - QSize sz=QCommonStyle::sizeFromContents(ct, opt, contentsSize, w); + QSize sz = QFusionStyle::sizeFromContents(ct, opt, contentsSize, w); const ItemType itemType = qtControl(ct); AndroidControlsHash::const_iterator it = itemType != QC_UnknownType ? m_androidControlsHash.find(itemType) @@ -601,14 +682,28 @@ QPixmap QAndroidStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const { - return QCommonStyle::standardPixmap(standardPixmap, opt, widget); + return QFusionStyle::standardPixmap(standardPixmap, opt, widget); } QPixmap QAndroidStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const { - return QCommonStyle::generatedIconPixmap(iconMode, pixmap, opt); + return QFusionStyle::generatedIconPixmap(iconMode, pixmap, opt); +} + +int QAndroidStyle::styleHint(QStyle::StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const +{ + switch (hint) { + case SH_Slider_AbsoluteSetButtons: + return 1; + + case SH_RequestSoftwareInputPanel: + return RSIP_OnMouseClick; + + default: + return QFusionStyle::styleHint(hint,option, widget, returnData); + } } QPalette QAndroidStyle::standardPalette() const @@ -616,6 +711,16 @@ QPalette QAndroidStyle::standardPalette() const return m_standardPalette; } +void QAndroidStyle::polish(QWidget *widget) +{ + widget->setAttribute(Qt::WA_StyledBackground, true); +} + +void QAndroidStyle::unpolish(QWidget *widget) +{ + widget->setAttribute(Qt::WA_StyledBackground, false); +} + QAndroidStyle::AndroidDrawable::AndroidDrawable(const QVariantMap &drawable, QAndroidStyle::ItemType itemType) { @@ -678,6 +783,13 @@ QMargins QAndroidStyle::AndroidDrawable::extractMargins(const QVariantMap &value return m; } +void QAndroidStyle::AndroidDrawable::setPaddingLeftToSizeWidth() +{ + QSize sz = size(); + if (m_padding.isNull() && !sz.isNull()) + m_padding.setLeft(sz.width()); +} + QAndroidStyle::AndroidImageDrawable::AndroidImageDrawable(const QVariantMap &drawable, QAndroidStyle::ItemType itemType) @@ -867,6 +979,8 @@ void QAndroidStyle::Android9PatchDrawable::draw(QPainter * painter, const QStyle i <= numXDivs && src.left() < bitmapWidth; i++, xIsStretchable = !xIsStretchable) { color = m_chunkData.colors[colorIndex++]; + if (color != TRANSPARENT_COLOR) + color = NO_COLOR; if (i == numXDivs) { src.setRight(bitmapWidth); dst.setRight(bounds.right()); @@ -904,7 +1018,7 @@ void QAndroidStyle::Android9PatchDrawable::draw(QPainter * painter, const QStyle if (color == TRANSPARENT_COLOR) goto nextDiv; if (color != NO_COLOR) - painter->fillRect(dst, (QRgb)color); + painter->fillRect(dst, QRgb(color)); else painter->drawPixmap(dst, pixmap, src); nextDiv: @@ -930,7 +1044,7 @@ QAndroidStyle::AndroidGradientDrawable::AndroidGradientDrawable(const QVariantMa 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()); + 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 @@ -1106,33 +1220,33 @@ const QAndroidStyle::AndroidDrawable* QAndroidStyle::AndroidStateDrawable::bestA foreach (const StateType & state, m_states) { if (int(opt->state) == state.first) return state.second; - uint cost = 0; + uint cost = 1; int difference = int(opt->state^state.first); if (difference & QStyle::State_Active) - cost += 1000; + cost <<= 1; if (difference & QStyle::State_Enabled) - cost += 1000; + cost <<= 1; - if ((m_itemType == QC_Button || m_itemType == QC_EditText) && (difference & QStyle::State_Raised)) - cost += 1000; + if (difference & QStyle::State_Raised) + cost <<= 1; - if ((m_itemType == QC_Button || m_itemType == QC_EditText) && (difference & QStyle::State_Sunken)) - cost += 1000; + if (difference & QStyle::State_Sunken) + cost <<= 1; if (difference & QStyle::State_Off) - cost += 1000; + cost <<= 1; if (difference & QStyle::State_On) - cost += 1000; + cost <<= 1; if (difference & QStyle::State_HasFocus) - cost += 1000; + cost <<= 1; if (difference & QStyle::State_Selected) - cost += 1000; + cost <<= 1; if (cost < bestCost) { bestCost = cost; @@ -1144,21 +1258,30 @@ const QAndroidStyle::AndroidDrawable* QAndroidStyle::AndroidStateDrawable::bestA int QAndroidStyle::AndroidStateDrawable::extractState(const QVariantMap &value) { - int state = QStyle::State_None; + int state = QStyle::State_Enabled | QStyle::State_Active;; foreach (const QString key, value.keys()) { bool val = value.value(key).toString() == QLatin1String("true"); - if (key == QLatin1String("enabled") && val) { - state |= QStyle::State_Enabled; + if (key == QLatin1String("enabled")) { + if (val) + state |= QStyle::State_Enabled; + else + state &= ~QStyle::State_Enabled; continue; } - if (key == QLatin1String("window_focused") && val) { - state |= QStyle::State_Active; + if (key == QLatin1String("window_focused")) { + if (val) + state |= QStyle::State_Active; + else + state &= ~QStyle::State_Active; continue; } - if (key == QLatin1String("focused") && val) { - state |= QStyle::State_HasFocus; + if (key == QLatin1String("focused")) { + if (val) + state |= QStyle::State_HasFocus; + else + state &= ~QStyle::State_HasFocus; continue; } @@ -1168,33 +1291,48 @@ int QAndroidStyle::AndroidStateDrawable::extractState(const QVariantMap &value) } if (key == QLatin1String("pressed")) { - state |= val ? QStyle::State_Raised : QStyle::State_Sunken; - state |= QStyle::State_Enabled | QStyle::State_HasFocus; + state |= val ? QStyle::State_Sunken : QStyle::State_Raised; continue; } - if (key == QLatin1String("selected") && val) { - state |= QStyle::State_Selected; - state |= QStyle::State_Enabled | QStyle::State_HasFocus; + if (key == QLatin1String("selected")) { + if (val) + state |= QStyle::State_Selected; + else + state &= ~QStyle::State_Selected; continue; } - if (key == QLatin1String("active") && val) { - state |= QStyle::State_Active; + if (key == QLatin1String("active")) { + if (val) + state |= QStyle::State_Active; + else + state &= ~QStyle::State_Active; continue; } - // Keep misspelling for compatibility - if (key == QLatin1String("backgroud") && val) + if (key == QLatin1String("multiline")) + return 0; + + if (key == QLatin1String("background") && val) return -1; } return state; } +void QAndroidStyle::AndroidStateDrawable::setPaddingLeftToSizeWidth() +{ + foreach (const StateType type, m_states) + const_cast<AndroidDrawable *>(type.second)->setPaddingLeftToSizeWidth(); +} + QAndroidStyle::AndroidLayerDrawable::AndroidLayerDrawable(const QVariantMap &drawable, QAndroidStyle::ItemType itemType) : AndroidDrawable(drawable, itemType) { + m_id = 0; + m_factor = 1; + m_orientation = Qt::Horizontal; QVariantList layers = drawable.value(QLatin1String("layers")).toList(); foreach (QVariant layer, layers) { QVariantMap layerMap = layer.toMap(); @@ -1219,10 +1357,29 @@ QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidLayerDrawable::type() c return QAndroidStyle::Layer; } +void QAndroidStyle::AndroidLayerDrawable::setFactor(int id, double factor, Qt::Orientation orientation) +{ + m_id = id; + m_factor = factor; + m_orientation = orientation; +} + void QAndroidStyle::AndroidLayerDrawable::draw(QPainter *painter, const QStyleOption *opt) const { foreach (const LayerType &layer, m_layers) - layer.second->draw(painter, opt); + { + if (layer.first == m_id) + { + 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); + layer.second->draw(painter, ©); + } else { + layer.second->draw(painter, opt); + } + } } QAndroidStyle::AndroidDrawable *QAndroidStyle::AndroidLayerDrawable::layer(int id) const @@ -1274,17 +1431,47 @@ QAndroidStyle::AndroidControl::~AndroidControl() void QAndroidStyle::AndroidControl::drawControl(const QStyleOption *opt, QPainter *p, const QWidget * /* w */) { - if (m_background) + if (m_background) { m_background->draw(p, opt); + } else { + if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) { + if ((frame->state & State_Sunken) || (frame->state & State_Raised)) { + qDrawShadePanel(p, frame->rect, frame->palette, frame->state & State_Sunken, + frame->lineWidth); + } else { + qDrawPlainRect(p, frame->rect, frame->palette.foreground().color(), frame->lineWidth); + } + } else { + if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) { + QColor bg = fropt->backgroundColor; + QPen oldPen = p->pen(); + if (bg.isValid()) { + int h, s, v; + bg.getHsv(&h, &s, &v); + if (v >= 128) + p->setPen(Qt::black); + else + p->setPen(Qt::white); + } else { + p->setPen(opt->palette.foreground().color()); + } + QRect focusRect = opt->rect.adjusted(1, 1, -1, -1); + p->drawRect(focusRect.adjusted(0, 0, -1, -1)); //draw pen inclusive + p->setPen(oldPen); + } else { + p->fillRect(opt->rect, opt->palette.brush(QPalette::Background)); + } + } + } } QRect QAndroidStyle::AndroidControl::subElementRect(QStyle::SubElement /* subElement */, const QStyleOption *option, const QWidget * /* widget */) const { - if (const AndroidDrawable *drawable=m_background) { + if (const AndroidDrawable *drawable = backgroundDrawable()) { if (drawable->type() == State) - drawable = static_cast<const AndroidStateDrawable *>(m_background)->bestAndroidStateMatch(option); + drawable = static_cast<const AndroidStateDrawable *>(backgroundDrawable())->bestAndroidStateMatch(option); const QMargins &padding = drawable->padding(); @@ -1315,10 +1502,10 @@ QSize QAndroidStyle::AndroidControl::sizeFromContents(const QStyleOption *opt, const QWidget * /* w */) const { QSize sz; - if (const AndroidDrawable *drawable=m_background) { + if (const AndroidDrawable *drawable = backgroundDrawable()) { if (drawable->type() == State) - drawable = static_cast<const AndroidStateDrawable*>(m_background)->bestAndroidStateMatch(opt); + drawable = static_cast<const AndroidStateDrawable*>(backgroundDrawable())->bestAndroidStateMatch(opt); const QMargins &padding = drawable->padding(); sz.setWidth(padding.left() + padding.right()); sz.setHeight(padding.top() + padding.bottom()); @@ -1346,6 +1533,11 @@ QMargins QAndroidStyle::AndroidControl::padding() return QMargins(); } +const QAndroidStyle::AndroidDrawable *QAndroidStyle::AndroidControl::backgroundDrawable() const +{ + return m_background; +} + QAndroidStyle::AndroidCompoundButtonControl::AndroidCompoundButtonControl(const QVariantMap &control, ItemType itemType) : AndroidControl(control, itemType) @@ -1355,6 +1547,7 @@ QAndroidStyle::AndroidCompoundButtonControl::AndroidCompoundButtonControl(const m_button = AndroidDrawable::fromMap(it.value().toMap(), itemType); else m_button = 0; + const_cast<AndroidDrawable *>(m_button)->setPaddingLeftToSizeWidth(); } QAndroidStyle::AndroidCompoundButtonControl::~AndroidCompoundButtonControl() @@ -1371,6 +1564,11 @@ void QAndroidStyle::AndroidCompoundButtonControl::drawControl(const QStyleOption m_button->draw(p, opt); } +const QAndroidStyle::AndroidDrawable *QAndroidStyle::AndroidCompoundButtonControl::backgroundDrawable() const +{ + return m_background ? m_background : m_button; +} + QAndroidStyle::AndroidProgressBarControl::AndroidProgressBarControl(const QVariantMap &control, ItemType itemType) : AndroidControl(control, itemType) @@ -1429,8 +1627,11 @@ void QAndroidStyle::AndroidProgressBarControl::drawControl(const QStyleOption *o 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)), + static_cast<QAndroidStyle::AndroidClipDrawable *>(clipDrawable)->setFactor(double(progressBarV2.progress)/double(progressBarV2.maximum-progressBarV2.minimum), progressBarV2.orientation); + else + static_cast<QAndroidStyle::AndroidLayerDrawable *>(m_progressDrawable)->setFactor(m_progressId,double(progressBarV2.progress)/double(progressBarV2.maximum-progressBarV2.minimum), + progressBarV2.orientation); } m_progressDrawable->draw(p, option); } @@ -1523,11 +1724,13 @@ void QAndroidStyle::AndroidSeekBarControl::drawControl(const QStyleOption *optio if (const QStyleOptionSlider *styleOption = qstyleoption_cast<const QStyleOptionSlider *>(option)) { - double factor = double(styleOption->sliderPosition/(styleOption->maximum-styleOption->minimum)); + double factor = double(styleOption->sliderPosition)/double(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); + else + static_cast<QAndroidStyle::AndroidLayerDrawable *>(m_progressDrawable)->setFactor(m_progressId, factor, styleOption->orientation); } const AndroidDrawable *drawable=m_seekBarThumb; if (drawable->type() == State) @@ -1535,12 +1738,12 @@ void QAndroidStyle::AndroidSeekBarControl::drawControl(const QStyleOption *optio 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); + 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); + int pos = copy.rect.width()*factor - drawable->size().width()/2; copy.rect.translate(pos, 0); copy.rect.setSize(drawable->size()); m_seekBarThumb->draw(p, ©); diff --git a/src/widgets/styles/qandroidstyle_p.h b/src/widgets/styles/qandroidstyle_p.h index 2d9abd65c5..d64e37b9db 100644 --- a/src/widgets/styles/qandroidstyle_p.h +++ b/src/widgets/styles/qandroidstyle_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> +** Copyright (C) 2013 BogDan Vatra <bogdan@kde.org> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -55,15 +55,15 @@ #include <QtCore/QList> #include <QtCore/QMargins> -#include <QtWidgets/QCommonStyle> #include <QtCore/QHash> #include <QtCore/QVariantMap> +#include "qfusionstyle_p.h" QT_BEGIN_NAMESPACE #if !defined(QT_NO_STYLE_ANDROID) -class Q_WIDGETS_EXPORT QAndroidStyle : public QCommonStyle +class Q_WIDGETS_EXPORT QAndroidStyle : public QFusionStyle { Q_OBJECT @@ -86,7 +86,7 @@ public: QC_TabButton, QC_RatingIndicator, QC_SearchBox, - QC_CustomCOntrol=0xf00, + QC_CustomControl=0xf00, QC_ControlMask=0xfff }; @@ -131,6 +131,7 @@ public: virtual QSize size() const; static AndroidDrawable *fromMap(const QVariantMap &drawable, ItemType itemType); static QMargins extractMargins(const QVariantMap &value); + virtual void setPaddingLeftToSizeWidth(); protected: ItemType m_itemType; QMargins m_padding; @@ -226,6 +227,7 @@ public: virtual void draw(QPainter *painter, const QStyleOption *opt) const; inline const AndroidDrawable *bestAndroidStateMatch(const QStyleOption *opt) const; static int extractState(const QVariantMap &value); + virtual void setPaddingLeftToSizeWidth(); private: typedef QPair<int, const AndroidDrawable *> StateType; @@ -238,12 +240,16 @@ public: AndroidLayerDrawable(const QVariantMap &drawable, QAndroidStyle::ItemType itemType); ~AndroidLayerDrawable(); virtual AndroidDrawableType type() const; + virtual void setFactor(int id, double factor, Qt::Orientation orientation); 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; + int m_id; + double m_factor; + Qt::Orientation m_orientation; }; class AndroidControl @@ -263,6 +269,7 @@ public: const QWidget *w) const; virtual QMargins padding(); protected: + virtual const AndroidDrawable * backgroundDrawable() const; const AndroidDrawable *m_background; QSize m_minSize; QSize m_maxSize; @@ -276,6 +283,7 @@ public: virtual void drawControl(const QStyleOption *opt, QPainter *p, const QWidget *w); protected: + virtual const AndroidDrawable * backgroundDrawable() const; const AndroidDrawable *m_button; }; @@ -356,7 +364,13 @@ public: virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const; + int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, + QStyleHintReturn *returnData = 0) const; + virtual QPalette standardPalette() const; + void polish(QWidget *widget); + void unpolish(QWidget *widget); + private: Q_DISABLE_COPY(QAndroidStyle) static ItemType qtControl(QStyle::ComplexControl control); diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index aaad4c3331..7f0813c303 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -65,6 +65,7 @@ #include <qtoolbar.h> #include <qtoolbutton.h> #include <qrubberband.h> +#include "qtreeview.h" #include <private/qcommonstylepixmaps_p.h> #include <private/qmath_p.h> #include <qdebug.h> @@ -5099,11 +5100,7 @@ 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; @@ -5111,6 +5108,27 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget case SH_Menu_SupportsSections: ret = false; break; +#ifndef QT_NO_TOOLTIP + case SH_ToolTip_WakeUpDelay: + ret = 700; + break; + case SH_ToolTip_FallAsleepDelay: + ret = 2000; + break; +#endif + case SH_Widget_Animate: +#ifndef QT_NO_TREEVIEW + if (qobject_cast<const QTreeView*>(widget)) { + ret = false; + } else +#endif + { + ret = true; + } + break; + case SH_Splitter_OpaqueResize: + ret = true; + break; default: ret = 0; break; @@ -5291,6 +5309,13 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti } } break; + case SP_LineEditClearButton: { + QString themeName = rtl ? QStringLiteral("edit-clear-locationbar-ltr") : QStringLiteral("edit-clear-locationbar-rtl"); + if (!QIcon::hasThemeIcon(themeName)) + themeName = QStringLiteral("edit-clear"); + pixmap = QIcon::fromTheme(themeName).pixmap(16); + } + break; default: break; } @@ -5419,6 +5444,8 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-volume-16.png")); case SP_MediaVolumeMuted: return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-volume-muted-16.png")); + case SP_LineEditClearButton: + return QPixmap(QStringLiteral(":/qt-project.org/styles/commonstyle/images/cleartext-16.png")); #endif // QT_NO_IMAGEFORMAT_PNG default: break; diff --git a/src/widgets/styles/qcommonstyle_p.h b/src/widgets/styles/qcommonstyle_p.h index 979c2a5548..8f8a97a2dc 100644 --- a/src/widgets/styles/qcommonstyle_p.h +++ b/src/widgets/styles/qcommonstyle_p.h @@ -92,19 +92,19 @@ public: mutable QRect decorationRect, displayRect, checkRect; mutable QStyleOptionViewItem *cachedOption; bool isViewItemCached(const QStyleOptionViewItem &option) const { - return cachedOption && (option.rect == cachedOption->rect - && option.direction == cachedOption->direction + return cachedOption && (option.widget == cachedOption->widget + && option.index == cachedOption->index && option.state == cachedOption->state + && option.rect == cachedOption->rect + && option.text == cachedOption->text + && option.direction == cachedOption->direction && option.displayAlignment == cachedOption->displayAlignment && option.decorationAlignment == cachedOption->decorationAlignment && option.decorationPosition == cachedOption->decorationPosition && option.decorationSize == cachedOption->decorationSize - && option.font == cachedOption->font && option.features == cachedOption->features - && option.widget == cachedOption->widget - && option.index == cachedOption->index && option.icon.isNull() == cachedOption->icon.isNull() - && option.text == cachedOption->text + && option.font == cachedOption->font && option.viewItemPosition == cachedOption->viewItemPosition); } #endif diff --git a/src/widgets/styles/qgtkstyle_p.cpp b/src/widgets/styles/qgtkstyle_p.cpp index 769d822108..c53a21e59a 100644 --- a/src/widgets/styles/qgtkstyle_p.cpp +++ b/src/widgets/styles/qgtkstyle_p.cpp @@ -756,8 +756,9 @@ void QGtkStylePrivate::removeWidgetFromMap(const QHashableLatin1Literal &path) WidgetMap *map = gtkWidgetMap(); WidgetMap::iterator it = map->find(path); if (it != map->end()) { - free(const_cast<char *>(it.key().data())); + char* keyData = const_cast<char *>(it.key().data()); map->erase(it); + free(keyData); } } diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index dccc9ff3ce..77f869f036 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -53,6 +53,7 @@ #endif #include <limits.h> +#include <algorithm> QT_BEGIN_NAMESPACE @@ -1894,6 +1895,19 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \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. + \value SH_ToolTip_WakeUpDelay Determines the delay before a tooltip is shown, in milliseconds. + + \value SH_ToolTip_FallAsleepDelay Determines the delay (in milliseconds) before a new wake time is needed when + a tooltip is shown (notice: shown, not hidden). When a new wake isn't needed, a user-requested tooltip + will be shown nearly instantly. + + \value SH_Widget_Animate Determines if the widget should show animations or not, for example + a transition between checked and unchecked statuses in a checkbox. + This enum value has been introduced in Qt 5.2. + + \value SH_Splitter_OpaqueResize Determines if resizing is opaque + This enum value has been introduced in Qt 5.2 + \sa styleHint() */ @@ -1986,6 +2000,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value SP_MediaSeekBackward Icon indicating that media should seek backward. \value SP_MediaVolume Icon indicating a volume control. \value SP_MediaVolumeMuted Icon indicating a muted volume control. + \value SP_LineEditClearButton Icon for a standard clear button in a QLineEdit. This enum value was added in Qt 5.2. \value SP_CustomBase Base value for custom standard pixmaps; custom values must be greater than this value. @@ -2323,7 +2338,7 @@ QDebug operator<<(QDebug debug, QStyle::State state) if (state & QStyle::State_Top) states << QLatin1String("Top"); if (state & QStyle::State_UpArrow) states << QLatin1String("UpArrow"); - qSort(states); + std::sort(states.begin(), states.end()); debug << states.join(QLatin1String(" | ")); debug << ')'; #else diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index beafad326e..bbb216bf92 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -698,6 +698,10 @@ public: SH_RequestSoftwareInputPanel, SH_ScrollBar_Transient, SH_Menu_SupportsSections, + SH_ToolTip_WakeUpDelay, + SH_ToolTip_FallAsleepDelay, + SH_Widget_Animate, + SH_Splitter_OpaqueResize, // Add new style hint values here SH_CustomBase = 0xf0000000 @@ -777,6 +781,7 @@ public: SP_MediaSeekBackward, SP_MediaVolume, SP_MediaVolumeMuted, + SP_LineEditClearButton, // do not add any values below/greater than this SP_CustomBase = 0xf0000000 }; diff --git a/src/widgets/styles/qstyle.qrc b/src/widgets/styles/qstyle.qrc index 28ad484032..c063ec5036 100644 --- a/src/widgets/styles/qstyle.qrc +++ b/src/widgets/styles/qstyle.qrc @@ -1,5 +1,6 @@ <RCC> <qresource prefix="/qt-project.org/styles/commonstyle"> + <file>images/cleartext-16.png</file> <file>images/filelink-16.png</file> <file>images/filelink-32.png</file> <file>images/filelink-128.png</file> diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index be89abf2b2..85520d3c40 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -1096,7 +1096,7 @@ void QRenderRule::fixupBorder(int nativeWidth) bd->borders[i] = nativeWidth; // intentional fall through default: - if (!bd->colors[i].style() != Qt::NoBrush) // auto-acquire 'color' + if (bd->colors[i].style() == Qt::NoBrush) // auto-acquire 'color' bd->colors[i] = color; break; } @@ -4810,10 +4810,22 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op switch (ct) { case CT_SpinBox: // ### hopelessly broken QAbstractSpinBox (part 1) - if (rule.hasBox() || !rule.hasNativeBorder()) - return csz; - return rule.baseStyleCanDraw() ? baseStyle()->sizeFromContents(ct, opt, sz, w) - : QWindowsStyle::sizeFromContents(ct, opt, sz, w); + if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { + // Add some space for the up/down buttons + QRenderRule subRule = renderRule(w, opt, PseudoElement_SpinBoxUpButton); + if (subRule.hasDrawable()) { + QRect r = positionRect(w, rule, subRule, PseudoElement_SpinBoxUpButton, + opt->rect, opt->direction); + sz += QSize(r.width(), 0); + } else { + QSize defaultUpSize = defaultSize(w, subRule.size(), spinbox->rect, PseudoElement_SpinBoxUpButton); + sz += QSize(defaultUpSize.width(), 0); + } + if (rule.hasBox() || !rule.hasNativeBorder()) + sz = rule.boxSize(sz); + return sz; + } + break; case CT_ToolButton: if (rule.hasBox() || !rule.hasNativeBorder() || !rule.baseStyleCanDraw()) sz += QSize(3, 3); // ### broken QToolButton @@ -4858,14 +4870,8 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op case CT_GroupBox: case CT_LineEdit: #ifndef QT_NO_SPINBOX - // ### hopelessly broken QAbstractSpinBox (part 2) - if (QAbstractSpinBox *spinBox = qobject_cast<QAbstractSpinBox *>(w ? w->parentWidget() : 0)) { - QRenderRule rule = renderRule(spinBox, opt); - if (rule.hasBox() || !rule.hasNativeBorder()) - return csz; - return rule.baseStyleCanDraw() ? baseStyle()->sizeFromContents(ct, opt, sz, w) - : QWindowsStyle::sizeFromContents(ct, opt, sz, w); - } + if (qobject_cast<QAbstractSpinBox *>(w ? w->parentWidget() : 0)) + return csz; // we only care about the size hint of the line edit #endif if (rule.hasBox() || !rule.hasNativeBorder()) { return rule.boxSize(sz); diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index 3b3c27f6cb..506a148d2f 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -72,6 +72,8 @@ #include <qvarlengtharray.h> #include <qdebug.h> +#include <algorithm> + QT_BEGIN_NAMESPACE // Runtime resolved theme engine function calls @@ -277,7 +279,7 @@ void QWindowsXPStylePrivate::init(bool force) ref.ref(); useXP(true); - qFill(m_themes, m_themes + NThemes, HTHEME(0)); + std::fill(m_themes, m_themes + NThemes, HTHEME(0)); } /* \internal @@ -4306,7 +4308,7 @@ void QWindowsXPStylePrivate::showProperties(XPThemeData &themeData) } } } - qSort(all_props); + std::sort(all_props.begin(), all_props.end()); {// List all properties printf("part properties count = %d:\n", all_props.count()); |