summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@digia.com>2013-05-29 13:32:25 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-30 09:21:20 +0200
commitcf3d91d6db86fb74d5968405371c4e83b1410d86 (patch)
tree798c3ae3fdf3651da45ed151d52d44e909829c9a
parentc536d0cf324bd7cb2299ecd3e5212b9826b2bf42 (diff)
downloadqtquickcontrols-cf3d91d6db86fb74d5968405371c4e83b1410d86.tar.gz
Make styleHints a variant map
The styleHints are not really flexible enough as a stringlist as we want to be able to pass actual properties. Since we already have a properties member of the style we should move all of our internal properties to that. Change-Id: Id7a66ade243461f54c41b9ec89144668aaf19483 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
-rw-r--r--src/private/Control.qml2
-rw-r--r--src/private/qquickstyleitem.cpp95
-rw-r--r--src/private/qquickstyleitem_p.h9
-rw-r--r--src/styles/Desktop/CheckBoxStyle.qml12
-rw-r--r--src/styles/Desktop/SpinBoxStyle.qml3
-rw-r--r--src/styles/Desktop/TabViewStyle.qml7
-rw-r--r--src/styles/Desktop/TableViewStyle.qml3
-rw-r--r--src/styles/Desktop/TextFieldStyle.qml6
-rw-r--r--src/styles/Desktop/ToolButtonStyle.qml5
9 files changed, 71 insertions, 71 deletions
diff --git a/src/private/Control.qml b/src/private/Control.qml
index 109e37ed..05916c0a 100644
--- a/src/private/Control.qml
+++ b/src/private/Control.qml
@@ -64,7 +64,7 @@ FocusScope {
property Item __panel: panelLoader.item
/*! \internal */
- property var styleHints: []
+ property var styleHints
implicitWidth: __panel ? __panel.implicitWidth: 0
implicitHeight: __panel ? __panel.implicitHeight: 0
diff --git a/src/private/qquickstyleitem.cpp b/src/private/qquickstyleitem.cpp
index 422d9a8e..71d98bb6 100644
--- a/src/private/qquickstyleitem.cpp
+++ b/src/private/qquickstyleitem.cpp
@@ -177,8 +177,9 @@ void QQuickStyleItem::initStyleOption()
if (m_styleoption)
m_styleoption->state = 0;
- QPlatformTheme::Font platformFont = (m_hints.indexOf("mini") != -1) ? QPlatformTheme::MiniFont :
- (m_hints.indexOf("small") != -1) ? QPlatformTheme::SmallFont :
+ QString sizeHint = m_hints.value("size").toString();
+ QPlatformTheme::Font platformFont = (sizeHint == "mini") ? QPlatformTheme::MiniFont :
+ (sizeHint == "small") ? QPlatformTheme::SmallFont :
QPlatformTheme::SystemFont;
switch (m_itemType) {
@@ -266,11 +267,12 @@ void QQuickStyleItem::initStyleOption()
QStyleOptionHeader::SortDown
: activeControl() == "up" ?
QStyleOptionHeader::SortUp : QStyleOptionHeader::None;
- if (hints().contains("beginning"))
+ QString headerpos = m_properties.value("headerpos").toString();
+ if (headerpos == "beginning")
opt->position = QStyleOptionHeader::Beginning;
- else if (hints().contains("end"))
+ else if (headerpos == "end")
opt->position = QStyleOptionHeader::End;
- else if (hints().contains("only"))
+ else if (headerpos == "only")
opt->position = QStyleOptionHeader::OnlyOneSection;
else
opt->position = QStyleOptionHeader::Middle;
@@ -318,32 +320,30 @@ void QQuickStyleItem::initStyleOption()
QStyleOptionTab *opt = qstyleoption_cast<QStyleOptionTab*>(m_styleoption);
opt->text = text();
- if (m_properties["hasFrame"].toBool())
+ if (m_properties.value("hasFrame").toBool())
opt->features |= QStyleOptionTab::HasFrame;
- if (hints().length() > 2) {
- QString orientation = hints()[0];
- QString position = hints()[1];
- QString selectedPosition = hints()[2];
+ QString orientation = m_properties.value("orientation").toString();
+ QString position = m_properties.value("tabpos").toString();
+ QString selectedPosition = m_properties.value("selectedpos").toString();
+
+ opt->shape = (orientation == "Bottom") ? QTabBar::RoundedSouth : QTabBar::RoundedNorth;
+ if (position == QLatin1String("beginning"))
+ opt->position = QStyleOptionTab::Beginning;
+ else if (position == QLatin1String("end"))
+ opt->position = QStyleOptionTab::End;
+ else if (position == QLatin1String("only"))
+ opt->position = QStyleOptionTab::OnlyOneTab;
+ else
+ opt->position = QStyleOptionTab::Middle;
- opt->shape = (orientation == "Bottom") ? QTabBar::RoundedSouth : QTabBar::RoundedNorth;
+ if (selectedPosition == QLatin1String("next"))
+ opt->selectedPosition = QStyleOptionTab::NextIsSelected;
+ else if (selectedPosition == QLatin1String("previous"))
+ opt->selectedPosition = QStyleOptionTab::PreviousIsSelected;
+ else
+ opt->selectedPosition = QStyleOptionTab::NotAdjacent;
- if (position == QLatin1String("beginning"))
- opt->position = QStyleOptionTab::Beginning;
- else if (position == QLatin1String("end"))
- opt->position = QStyleOptionTab::End;
- else if (position == QLatin1String("only"))
- opt->position = QStyleOptionTab::OnlyOneTab;
- else
- opt->position = QStyleOptionTab::Middle;
-
- if (selectedPosition == QLatin1String("next"))
- opt->selectedPosition = QStyleOptionTab::NextIsSelected;
- else if (selectedPosition == QLatin1String("previous"))
- opt->selectedPosition = QStyleOptionTab::PreviousIsSelected;
- else
- opt->selectedPosition = QStyleOptionTab::NotAdjacent;
- }
} break;
@@ -459,7 +459,7 @@ void QQuickStyleItem::initStyleOption()
QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption);
if (!on())
opt->state |= QStyle::State_Off;
- if (m_hints.contains("partiallyChecked"))
+ if (m_properties.value("partiallyChecked").toBool())
opt->state |= QStyle::State_NoChange;
opt->text = text();
}
@@ -643,9 +643,9 @@ void QQuickStyleItem::initStyleOption()
if (m_horizontal)
m_styleoption->state |= QStyle::State_Horizontal;
- if (m_hints.indexOf("mini") != -1) {
+ if (sizeHint == "mini") {
m_styleoption->state |= QStyle::State_Mini;
- } else if (m_hints.indexOf("small") != -1) {
+ } else if (sizeHint == "small") {
m_styleoption->state |= QStyle::State_Small;
}
@@ -801,10 +801,14 @@ QSize QQuickStyleItem::sizeFromContents(int width, int height)
case Edit:
#ifdef Q_OS_MAC
if (style() =="mac") {
- if (m_hints.indexOf("small") != -1 || m_hints.indexOf("mini") != -1)
+ QString sizeHint = m_hints.value("size").toString();
+ if ((sizeHint == "small") || (sizeHint == "mini"))
size = QSize(width, 19);
else
size = QSize(width, 22);
+ if (style() == "mac" && hints().value("rounded").toBool())
+ size += QSize(4, 4);
+
} else
#endif
{
@@ -965,7 +969,7 @@ QVariant QQuickStyleItem::styleHint(const QString &metric)
// Add SH_Menu_SpaceActivatesItem, SH_Menu_SubMenuPopupDelay
}
-void QQuickStyleItem::setHints(const QStringList &str)
+void QQuickStyleItem::setHints(const QVariantMap &str)
{
if (m_hints != str) {
m_hints = str;
@@ -983,6 +987,11 @@ void QQuickStyleItem::setHints(const QStringList &str)
}
}
+void QQuickStyleItem::resetHints()
+{
+ m_hints.clear();
+}
+
void QQuickStyleItem::setElementType(const QString &str)
{
@@ -1211,7 +1220,7 @@ void QQuickStyleItem::paint(QPainter *painter)
case ToolButton:
#ifdef Q_OS_MAC
- if (style() == "mac" && hints().indexOf("segmented") != -1) {
+ if (style() == "mac" && hints().value("segmented").toBool()) {
const QPaintDevice *target = painter->device();
HIThemeSegmentDrawInfo sgi;
sgi.version = 0;
@@ -1227,9 +1236,10 @@ void QQuickStyleItem::paint(QPainter *painter)
}
SInt32 button_height;
GetThemeMetric(kThemeMetricButtonRoundedHeight, &button_height);
- sgi.position = hints().contains("leftmost") ? kHIThemeSegmentPositionFirst:
- hints().contains("rightmost") ? kHIThemeSegmentPositionLast :
- hints().contains("h_middle") ? kHIThemeSegmentPositionMiddle :
+ QString buttonPos = m_properties.value("position").toString();
+ sgi.position = buttonPos == "leftmost" ? kHIThemeSegmentPositionFirst :
+ buttonPos == "rightmost" ? kHIThemeSegmentPositionLast :
+ buttonPos == "h_middle" ? kHIThemeSegmentPositionMiddle :
kHIThemeSegmentPositionOnly;
QRect centered = m_styleoption->rect;
centered.setHeight(button_height);
@@ -1257,12 +1267,7 @@ void QQuickStyleItem::paint(QPainter *painter)
qApp->style()->drawControl(QStyle::CE_ShapedFrame, m_styleoption, painter);
break;
case FocusFrame:
-#ifdef Q_OS_MAC
- if (style() == "mac" && hints().indexOf("rounded") != -1)
- break; // embedded in the line itself
- else
-#endif
- qApp->style()->drawControl(QStyle::CE_FocusFrame, m_styleoption, painter);
+ qApp->style()->drawControl(QStyle::CE_FocusFrame, m_styleoption, painter);
break;
case FocusRect:
qApp->style()->drawPrimitive(QStyle::PE_FrameFocusRect, m_styleoption, painter);
@@ -1288,7 +1293,7 @@ void QQuickStyleItem::paint(QPainter *painter)
break;
case Edit: {
#ifdef Q_OS_MAC
- if (style() == "mac" && hints().indexOf("rounded") != -1) {
+ if (style() == "mac" && hints().value("rounded").toBool()) {
const QPaintDevice *target = painter->device();
HIThemeFrameDrawInfo fdi;
fdi.version = 0;
@@ -1299,9 +1304,7 @@ void QQuickStyleItem::paint(QPainter *painter)
if ((m_styleoption->state & QStyle::State_ReadOnly) || !(m_styleoption->state & QStyle::State_Enabled))
fdi.state = kThemeStateInactive;
fdi.isFocused = hasFocus();
- HIRect hirect = qt_hirectForQRect(m_styleoption->rect,
- QRect(frame_size, frame_size,
- frame_size * 2, frame_size * 2));
+ HIRect hirect = qt_hirectForQRect(m_styleoption->rect.adjusted(2, 2, -2, 2), QRect(0, 0, 0, 0));
HIThemeDrawFrame(&hirect, &fdi, qt_mac_cg_context(target), kHIThemeOrientationNormal);
} else
#endif
diff --git a/src/private/qquickstyleitem_p.h b/src/private/qquickstyleitem_p.h
index 6deaeb16..eee9e6e5 100644
--- a/src/private/qquickstyleitem_p.h
+++ b/src/private/qquickstyleitem_p.h
@@ -67,7 +67,7 @@ class QQuickStyleItem: public QQuickItem
Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY( QString activeControl READ activeControl WRITE setActiveControl NOTIFY activeControlChanged)
Q_PROPERTY( QString style READ style NOTIFY styleChanged)
- Q_PROPERTY( QStringList hints READ hints WRITE setHints NOTIFY hintChanged)
+ Q_PROPERTY( QVariantMap hints READ hints WRITE setHints NOTIFY hintChanged RESET resetHints)
Q_PROPERTY( QVariantMap properties READ properties WRITE setProperties NOTIFY propertiesChanged)
Q_PROPERTY( QFont font READ font NOTIFY fontChanged)
@@ -140,7 +140,7 @@ public:
QString elementType() const { return m_type; }
QString text() const { return m_text; }
QString activeControl() const { return m_activeControl; }
- QStringList hints() const { return m_hints; }
+ QVariantMap hints() const { return m_hints; }
QVariantMap properties() const { return m_properties; }
QFont font() const { return m_font;}
QString style() const;
@@ -161,8 +161,9 @@ public:
void setElementType(const QString &str);
void setText(const QString &str) { if (m_text != str) {m_text = str; emit textChanged();}}
void setActiveControl(const QString &str) { if (m_activeControl != str) {m_activeControl = str; emit activeControlChanged();}}
- void setHints(const QStringList &str);
+ void setHints(const QVariantMap &str);
void setProperties(const QVariantMap &props) { if (m_properties != props) { m_properties = props; emit propertiesChanged(); } }
+ void resetHints();
int contentWidth() const { return m_contentWidth; }
void setContentWidth(int arg);
@@ -228,7 +229,7 @@ protected:
QString m_type;
QString m_text;
QString m_activeControl;
- QStringList m_hints;
+ QVariantMap m_hints;
QVariantMap m_properties;
QFont m_font;
diff --git a/src/styles/Desktop/CheckBoxStyle.qml b/src/styles/Desktop/CheckBoxStyle.qml
index 65c517ba..d85a2cb3 100644
--- a/src/styles/Desktop/CheckBoxStyle.qml
+++ b/src/styles/Desktop/CheckBoxStyle.qml
@@ -55,16 +55,8 @@ Style {
hover: control.__containsMouse
enabled: control.enabled
hasFocus: control.activeFocus && styleitem.style == "mac"
- hints: {
- if (control.checkedState === Qt.PartiallyChecked)
- control.styleHints.push("partiallyChecked");
- else {
- var index = control.styleHints.indexOf("partiallyChecked");
- if (index !== -1)
- control.styleHints.splice(index, 1);
- }
- control.styleHints;
- }
+ hints: control.styleHints
+ properties: {"partiallyChecked": (control.checkedState === Qt.PartiallyChecked) }
contentHeight: textitem.implicitHeight
contentWidth: textitem.implicitWidth + indicatorWidth
property int indicatorWidth: pixelMetric("indicatorwidth") + (macStyle ? 2 : 4)
diff --git a/src/styles/Desktop/SpinBoxStyle.qml b/src/styles/Desktop/SpinBoxStyle.qml
index 2f05838e..d43a2630 100644
--- a/src/styles/Desktop/SpinBoxStyle.qml
+++ b/src/styles/Desktop/SpinBoxStyle.qml
@@ -50,11 +50,12 @@ Style {
}
padding {
- top: control.__panel ? control.__panel.topPadding + (control.__panel.style === "mac" ? 1 : 0) : 0
+ top: control.__panel ? control.__panel.topPadding + (styleitem.style === "mac" ? 2 : 0) : 0
left: control.__panel ? control.__panel.leftPadding : 0
right: control.__panel ? control.__panel.rightPadding : 0
bottom: control.__panel ? control.__panel.bottomPadding : 0
}
+ StyleItem {id: styleitem ; visible: false}
property Component panel: Item {
id: style
diff --git a/src/styles/Desktop/TabViewStyle.qml b/src/styles/Desktop/TabViewStyle.qml
index b28300e2..51b70ea4 100644
--- a/src/styles/Desktop/TabViewStyle.qml
+++ b/src/styles/Desktop/TabViewStyle.qml
@@ -51,7 +51,7 @@ Style {
property StyleItem __barstyle: StyleItem {
elementType: "tab"
- hints: [control.tabPosition === Qt.TopEdge ? "Top" : "Bottom"]
+ properties: { "tabposition" : (control.tabPosition === Qt.TopEdge ? "Top" : "Bottom") }
visible: false
}
@@ -65,6 +65,7 @@ Style {
minimum: tabbarItem && tabsVisible && tabbarItem.tab(currentIndex) ? tabbarItem.tab(currentIndex).width : 0
maximum: tabbarItem && tabsVisible ? tabbarItem.width : width
properties: { "selectedTabRect" : tabbarItem.__selectedTabRect, "orientation" : control.tabPosition }
+ hints: control.styleHints
Component.onCompleted: {
stack.frameWidth = styleitem.pixelMetric("defaultframewidth");
stack.style = style;
@@ -94,8 +95,8 @@ Style {
anchors.rightMargin: -paintMargins
anchors.bottomMargin: -1
anchors.leftMargin: -paintMargins + (style === "mac" && selected ? -1 : 0)
- properties: { "hasFrame" : true }
- hints: [orientation, tabpos, selectedpos]
+ properties: { "hasFrame" : true, "orientation": orientation, "tabpos": tabpos, "selectedpos": selectedpos }
+ hints: control.styleHints
selected: styleData.selected
text: elidedText(styleData.title, tabbarItem.elide, item.width - item.tabHSpace)
diff --git a/src/styles/Desktop/TableViewStyle.qml b/src/styles/Desktop/TableViewStyle.qml
index 97dfcd5c..171678a3 100644
--- a/src/styles/Desktop/TableViewStyle.qml
+++ b/src/styles/Desktop/TableViewStyle.qml
@@ -73,7 +73,8 @@ ScrollViewStyle {
sunken: styleData.pressed
text: styleData.value
hover: styleData.containsMouse
- hints: headerPosition
+ hints: control.styleHints
+ properties: {"headerpos": headerPosition}
property string itemSort: (control.sortIndicatorVisible && styleData.column === control.sortIndicatorColumn) ? (control.sortIndicatorOrder == Qt.AscendingOrder ? "up" : "down") : "";
property string headerPosition: control.columnCount === 1 ? "only" :
styleData.column === control.columnCount-1 ? "end" :
diff --git a/src/styles/Desktop/TextFieldStyle.qml b/src/styles/Desktop/TextFieldStyle.qml
index 9a093d2a..ee6779eb 100644
--- a/src/styles/Desktop/TextFieldStyle.qml
+++ b/src/styles/Desktop/TextFieldStyle.qml
@@ -64,9 +64,9 @@ Style {
property color selectedTextColor: syspal.highlightedText
- property bool rounded: hints.indexOf("rounded") > -1
+ property bool rounded: !!hints["rounded"]
property int topMargin: style === "mac" ? 3 : 2
- property int leftMargin: rounded ? 8 : 4
+ property int leftMargin: rounded ? 12 : 4
property int rightMargin: leftMargin
property int bottomMargin: 2
@@ -76,7 +76,7 @@ Style {
FocusFrame {
anchors.fill: parent
- visible: textfield.activeFocus && textfieldstyle.styleHint("focuswidget")
+ visible: textfield.activeFocus && textfieldstyle.styleHint("focuswidget") && !rounded
}
}
}
diff --git a/src/styles/Desktop/ToolButtonStyle.qml b/src/styles/Desktop/ToolButtonStyle.qml
index b54eeee2..ebeec761 100644
--- a/src/styles/Desktop/ToolButtonStyle.qml
+++ b/src/styles/Desktop/ToolButtonStyle.qml
@@ -51,11 +51,12 @@ Style {
raised: !(control.checkable && control.checked) && control.__containsMouse
hover: control.__containsMouse
hasFocus: control.activeFocus
- hints: control.styleHints.concat([control.__position])
+ hints: control.styleHints
text: control.text
properties: {
- "icon": control.__action.__icon
+ "icon": control.__action.__icon,
+ "position": control.__position
}
}
}