summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2013-06-03 14:05:26 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-06-03 22:25:54 +0200
commiteeb3c959334d1e6b4ea9f7538b603a711f8a8262 (patch)
treea8e8336d2cc1de41e64ddfdfa4092b5afe329000
parent4e5bf941f1b3089c22392bb5416d44cb8defe47d (diff)
downloadqtquickcontrols-eeb3c959334d1e6b4ea9f7538b603a711f8a8262.tar.gz
Buttons: Allow overriding of visual properties when 'action' is set
Those properties are, text, tooltip, iconName, and iconSource. Also, properly capitalized gallery's tooltips. Change-Id: I1995a85565edd7aaa420279821d7c1a31ef18253 Reviewed-by: J-P Nurmi <jpnurmi@digia.com> Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
-rw-r--r--examples/quick/controls/gallery/main.qml4
-rw-r--r--src/controls/Button.qml22
-rw-r--r--src/controls/ToolButton.qml12
-rw-r--r--src/controls/qquickaction_p.h9
-rw-r--r--src/controls/qquickmenuitem.cpp2
-rw-r--r--src/private/BasicButton.qml36
-rw-r--r--src/private/style.js15
-rw-r--r--src/styles/Desktop/ButtonStyle.qml2
-rw-r--r--src/styles/Desktop/ToolButtonStyle.qml2
9 files changed, 63 insertions, 41 deletions
diff --git a/examples/quick/controls/gallery/main.qml b/examples/quick/controls/gallery/main.qml
index 86dddbe2..8ea3cf9e 100644
--- a/examples/quick/controls/gallery/main.qml
+++ b/examples/quick/controls/gallery/main.qml
@@ -76,7 +76,7 @@ ApplicationWindow {
shortcut: "Ctrl+O"
iconSource: "images/document-open.png"
onTriggered: fileDialog.open()
- tooltip: "open an image"
+ tooltip: "Open an image"
}
Action {
@@ -168,7 +168,7 @@ ApplicationWindow {
ToolButton { action: openAction }
ToolButton {
iconSource: "images/document-save-as.png"
- tooltip: "(Pretend to) save as..."
+ tooltip: "(Pretend to) Save as..."
}
Item { Layout.fillWidth: true }
CheckBox {
diff --git a/src/controls/Button.qml b/src/controls/Button.qml
index 21231e57..1f00dccb 100644
--- a/src/controls/Button.qml
+++ b/src/controls/Button.qml
@@ -72,20 +72,6 @@ BasicButton {
*/
property bool isDefault: false
- /*! This property holds the text shown on the button. If the button has no
- text, the \l text property will be an empty string.
-
- The default value is the empty string.
- */
- property string text
-
- /*! This property holds the icon shown on the button. If the button has no
- icon, the iconSource property will be an empty string.
-
- The default value is the empty string.
- */
- property url iconSource
-
/*! Assign a \l Menu to this property to get a pull-down menu button.
The default value is \c null.
@@ -115,6 +101,14 @@ BasicButton {
value: button
}
+ Binding {
+ target: button
+ property: "tooltip"
+ // We don't want a tooltip if it's the same as the button text
+ when: !!text && !(action && (!!action.tooltip || action.tooltip === text))
+ value: ""
+ }
+
Connections {
target: __behavior
onEffectivePressedChanged: {
diff --git a/src/controls/ToolButton.qml b/src/controls/ToolButton.qml
index 6cd3661b..3c1eab1a 100644
--- a/src/controls/ToolButton.qml
+++ b/src/controls/ToolButton.qml
@@ -62,18 +62,6 @@ import QtQuick.Controls.Private 1.0
BasicButton {
id: button
- /*! The image label source as file name or resource. */
- property url iconSource
-
- /*! The image label source as theme name.
- When an icon from the platform icon theme is found, this takes
- precedence over iconSource.
- */
- property url iconName
-
- /*! The label text. */
- property string text
-
activeFocusOnTab: true
Accessible.name: text
diff --git a/src/controls/qquickaction_p.h b/src/controls/qquickaction_p.h
index e106a920..aa63b408 100644
--- a/src/controls/qquickaction_p.h
+++ b/src/controls/qquickaction_p.h
@@ -57,11 +57,11 @@ class QQuickAction : public QObject
{
Q_OBJECT
- Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
- Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource NOTIFY iconSourceChanged)
+ Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged RESET resetText)
+ Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource NOTIFY iconSourceChanged RESET resetIconSource)
Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged)
Q_PROPERTY(QVariant __icon READ iconVariant NOTIFY iconChanged)
- Q_PROPERTY(QString tooltip READ tooltip WRITE setTooltip NOTIFY tooltipChanged)
+ Q_PROPERTY(QString tooltip READ tooltip WRITE setTooltip NOTIFY tooltipChanged RESET resetTooltip)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged)
Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled)
@@ -76,6 +76,7 @@ public:
~QQuickAction();
QString text() const { return m_text; }
+ void resetText() { setText(QString()); }
void setText(const QString &text);
QString shortcut() const;
@@ -87,9 +88,11 @@ public:
void setIconName(const QString &iconName);
QUrl iconSource() const { return m_iconSource; }
+ void resetIconSource() { setIconSource(QString()); }
void setIconSource(const QUrl &iconSource);
QString tooltip() const { return m_tooltip; }
+ void resetTooltip() { setTooltip(QString()); }
void setTooltip(const QString &tooltip);
bool isEnabled() const { return m_enabled; }
diff --git a/src/controls/qquickmenuitem.cpp b/src/controls/qquickmenuitem.cpp
index 622fdd2d..ed03b336 100644
--- a/src/controls/qquickmenuitem.cpp
+++ b/src/controls/qquickmenuitem.cpp
@@ -503,7 +503,7 @@ void QQuickMenuItem::setBoundAction(QQuickAction *a)
QString QQuickMenuItem::text() const
{
QString ownText = QQuickMenuText::text();
- if (!ownText.isEmpty())
+ if (!ownText.isNull())
return ownText;
return m_boundAction ? m_boundAction->text() : QString();
}
diff --git a/src/private/BasicButton.qml b/src/private/BasicButton.qml
index 3ef4b6e9..a967f73f 100644
--- a/src/private/BasicButton.qml
+++ b/src/private/BasicButton.qml
@@ -42,6 +42,7 @@ import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Controls.Private 1.0
import QtQuick.Controls.Styles 1.0
+import "style.js" as StyleHelpers
/*!
\qmltype BasicButton
@@ -83,6 +84,9 @@ Control {
If a button has an action associated, the action defines the
button's properties like checked, text, tooltip etc.
+ When an action is set, it's still possible to override the \l text,
+ \l tooltip, \l iconSource, and \l iconName properties.
+
The default value is \c null. */
property Action action: null
@@ -91,8 +95,28 @@ Control {
The default value is \c false. */
property bool activeFocusOnPress: false
+ /*! This property holds the text shown on the button. If the button has no
+ text, the \l text property will be an empty string.
+
+ The default value is the empty string.
+ */
+ property string text: action ? action.text : ""
+
/*! This property holds the button tooltip. */
- property string tooltip
+ property string tooltip: action ? (action.tooltip || StyleHelpers.removeMnemonics(action.text)) : ""
+
+ /*! This property holds the icon shown on the button. If the button has no
+ icon, the iconSource property will be an empty string.
+
+ The default value is the empty string.
+ */
+ property url iconSource: action ? action.iconSource : ""
+
+ /*! The image label source as theme name.
+ When an icon from the platform icon theme is found, this takes
+ precedence over iconSource.
+ */
+ property string iconName: action ? action.iconName : ""
/*! \internal */
property color __textColor: syspal.text
@@ -101,7 +125,11 @@ Control {
/*! \internal */
property alias __containsMouse: behavior.containsMouse
/*! \internal */
+ readonly property bool __iconOverriden: button.action && (button.action.iconSource !== button.iconSource || button.action.iconName !== button.iconName)
+ /*! \internal */
property Action __action: action || ownAction
+ /*! \internal */
+ readonly property Action __iconAction: __iconOverriden ? ownAction : __action
/*! \internal */
onExclusiveGroupChanged: {
@@ -119,7 +147,8 @@ Control {
Action {
id: ownAction
- iconSource: !button.action ? button.iconSource : ""
+ iconSource: !button.action || __iconOverriden ? button.iconSource : ""
+ iconName: !button.action || __iconOverriden ? button.iconName : ""
}
Connections {
@@ -181,9 +210,6 @@ Control {
enabled: action.enabled
checkable: action.checkable
checked: action.checked
- text: action.text
- iconSource: action.iconSource
- tooltip: action.tooltip
}
}
]
diff --git a/src/private/style.js b/src/private/style.js
index 81d6b563..2c47ff0e 100644
--- a/src/private/style.js
+++ b/src/private/style.js
@@ -40,13 +40,24 @@
.pragma library
-function replaceAmpersands(match, p1, p2, p3) {
+function underlineAmpersands(match, p1, p2, p3) {
if (p2 === "&")
return p1.concat(p2, p3)
return p1.concat("<u>", p2, "</u>", p3)
}
+function removeAmpersands(match, p1, p2, p3) {
+ return p1.concat(p2, p3)
+}
+
+function replaceAmpersands(text, replaceFunction) {
+ return text.replace(/([^&]*)&(.)([^&]*)/g, replaceFunction)
+}
+
function stylizeMnemonics(text) {
+ return replaceAmpersands(text, underlineAmpersands)
+}
- return text.replace(/([^&]*)&(.)([^&]*)/g, replaceAmpersands)
+function removeMnemonics(text) {
+ return replaceAmpersands(text, removeAmpersands)
}
diff --git a/src/styles/Desktop/ButtonStyle.qml b/src/styles/Desktop/ButtonStyle.qml
index 3ae42c03..3f0670bf 100644
--- a/src/styles/Desktop/ButtonStyle.qml
+++ b/src/styles/Desktop/ButtonStyle.qml
@@ -54,7 +54,7 @@ Style {
activeControl: control.isDefault ? "default" : "f"
properties: {
- "icon": control.__action.__icon,
+ "icon": control.__iconAction.__icon,
"menu": control.menu
}
}
diff --git a/src/styles/Desktop/ToolButtonStyle.qml b/src/styles/Desktop/ToolButtonStyle.qml
index b5b260e6..3dd22a53 100644
--- a/src/styles/Desktop/ToolButtonStyle.qml
+++ b/src/styles/Desktop/ToolButtonStyle.qml
@@ -55,7 +55,7 @@ Style {
text: control.text
properties: {
- "icon": control.__action.__icon,
+ "icon": control.__iconAction.__icon,
"position": control.__position
}
}