diff --git a/examples/quick/controls/gallery/main.qml b/examples/quick/controls/gallery/main.qml index 86dddbe2f9014069679fae61f7c55dff90283bf2..8ea3cf9e89c2e49346656e41ef8ac5f4081b34bf 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 21231e57c734884adb1ab7465b57d97cd0da5ccc..1f00dccbb17767f1008236dbe11de6b124932715 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 6cd3661b0e9993789407b354c70ad146e8374376..3c1eab1a6a256f4704cc5e1e623286d47fcd49b7 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 e106a9206b689133b69333fdad9fc5ab2aeaac9b..aa63b408370582bfb6931d918da38b429bfe840b 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 622fdd2da490f05b2fc97b782b796f96d08310f0..ed03b336e2771c60d0c39d6842e4b2209bae1a97 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 3ef4b6e97d26bf48b8caa010ce1122852e5cc9c3..a967f73f07f64eb5e42207136dbaace568168325 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 81d6b5633c25198816c26c2d46e9dff12b794757..2c47ff0e72a529f6aaef5a25d00c803817b630c0 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 3ae42c03e95e9db8b338bc922d2c79cda6cc5880..3f0670bfb3cce2f15a796fbbf68591df96b22b39 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 b5b260e627d7fe8b2dee62ec3d41f2fd46ea7bbd..3dd22a53384cfc33086c90bf32802fe0e4385584 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 } }