diff options
Diffstat (limited to 'src')
269 files changed, 6509 insertions, 1704 deletions
diff --git a/src/imports/calendar/qtlabscalendarplugin.cpp b/src/imports/calendar/qtlabscalendarplugin.cpp index 6d2d5b97..178118fb 100644 --- a/src/imports/calendar/qtlabscalendarplugin.cpp +++ b/src/imports/calendar/qtlabscalendarplugin.cpp @@ -58,7 +58,7 @@ class QtLabsCalendarPlugin: public QQmlExtensionPlugin public: QtLabsCalendarPlugin(QObject *parent = nullptr); - void registerTypes(const char *uri); + void registerTypes(const char *uri) override; }; QtLabsCalendarPlugin::QtLabsCalendarPlugin(QObject *parent) : QQmlExtensionPlugin(parent) diff --git a/src/imports/controls/AbstractButton.qml b/src/imports/controls/AbstractButton.qml index 96987cf2..e5214d37 100644 --- a/src/imports/controls/AbstractButton.qml +++ b/src/imports/controls/AbstractButton.qml @@ -35,7 +35,7 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T +import QtQuick.Templates 2.3 as T T.AbstractButton { id: control diff --git a/src/imports/controls/ApplicationWindow.qml b/src/imports/controls/ApplicationWindow.qml index af3986ac..6698fcb3 100644 --- a/src/imports/controls/ApplicationWindow.qml +++ b/src/imports/controls/ApplicationWindow.qml @@ -36,9 +36,9 @@ import QtQuick 2.9 import QtQuick.Window 2.3 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.ApplicationWindow { id: window diff --git a/src/imports/controls/BusyIndicator.qml b/src/imports/controls/BusyIndicator.qml index 234c2e01..e3757703 100644 --- a/src/imports/controls/BusyIndicator.qml +++ b/src/imports/controls/BusyIndicator.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.BusyIndicator { id: control @@ -51,6 +51,8 @@ T.BusyIndicator { implicitWidth: 48 implicitHeight: 48 + pen: Default.textColor + fill: Default.textColor opacity: control.running ? 1 : 0 visible: control.running || animator.running Behavior on opacity { OpacityAnimator { id: animator; duration: 250 } } diff --git a/src/imports/controls/Button.qml b/src/imports/controls/Button.qml index 6c150d5d..b1670c9a 100644 --- a/src/imports/controls/Button.qml +++ b/src/imports/controls/Button.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.Button { id: control @@ -51,17 +51,25 @@ T.Button { padding: 6 leftPadding: padding + 2 rightPadding: padding + 2 + spacing: 6 - contentItem: Text { + icon.width: 24 + icon.height: 24 + icon.color: Color.transparent(checked || highlighted ? Default.textLightColor : + visualFocus ? Default.focusColor : down ? Default.textDarkColor : Default.textColor, + enabled || highlighted || checked ? 1 : 0.3) + + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font - opacity: enabled || control.highlighted || control.checked ? 1 : 0.3 - color: control.checked || control.highlighted ? - Default.textLightColor : - (control.visualFocus ? Default.focusColor : (control.down ? Default.textDarkColor : Default.textColor)) - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight + color: Color.transparent(control.checked || control.highlighted ? Default.textLightColor : + control.visualFocus ? Default.focusColor : control.down ? Default.textDarkColor : Default.textColor, + enabled || control.highlighted || control.checked ? 1 : 0.3) } background: Rectangle { diff --git a/src/imports/controls/CheckBox.qml b/src/imports/controls/CheckBox.qml index 7945ca72..808f82ba 100644 --- a/src/imports/controls/CheckBox.qml +++ b/src/imports/controls/CheckBox.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 T.CheckBox { id: control diff --git a/src/imports/controls/CheckDelegate.qml b/src/imports/controls/CheckDelegate.qml index 05a0baf6..6ae09ace 100644 --- a/src/imports/controls/CheckDelegate.qml +++ b/src/imports/controls/CheckDelegate.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 T.CheckDelegate { id: control @@ -52,17 +52,23 @@ T.CheckDelegate { padding: 12 spacing: 12 - contentItem: Text { + icon.width: 24 + icon.height: 24 + icon.color: enabled ? Default.textDarkColor : Default.textDisabledColor + + contentItem: IconLabel { leftPadding: control.mirrored ? control.indicator.width + control.spacing : 0 rightPadding: !control.mirrored ? control.indicator.width + control.spacing : 0 + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + + icon: control.icon text: control.text font: control.font color: control.enabled ? Default.textDarkColor : Default.textDisabledColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } indicator: CheckIndicator { diff --git a/src/imports/controls/CheckIndicator.qml b/src/imports/controls/CheckIndicator.qml index 0be3e6cd..2bc87fe6 100644 --- a/src/imports/controls/CheckIndicator.qml +++ b/src/imports/controls/CheckIndicator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 Rectangle { id: indicator @@ -55,12 +55,11 @@ Rectangle { : (control.down ? Default.indicatorFramePressedColor : Default.indicatorFrameColor)) : "transparent" opacity: enabled ? 1 : 0.3 - Image { + ColorImage { x: (parent.width - width) / 2 y: (parent.height - height) / 2 - source: "image://default/check/" + (control.visualFocus ? Default.focusColor : Default.textColor) - sourceSize.width: width - sourceSize.height: height + color: control.visualFocus ? Default.focusColor : Default.textColor + source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/check.png" visible: control.checkState === Qt.Checked } diff --git a/src/imports/controls/ComboBox.qml b/src/imports/controls/ComboBox.qml index db3ca955..162a799a 100644 --- a/src/imports/controls/ComboBox.qml +++ b/src/imports/controls/ComboBox.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.ComboBox { id: control @@ -60,12 +60,11 @@ T.ComboBox { hoverEnabled: control.hoverEnabled } - indicator: Image { + indicator: ColorImage { x: control.mirrored ? control.padding : control.width - width - control.padding y: control.topPadding + (control.availableHeight - height) / 2 - source: "image://default/double-arrow/" + (!control.editable && control.visualFocus ? Default.focusColor : Default.textColor) - sourceSize.width: width - sourceSize.height: height + color: !control.editable && control.visualFocus ? Default.focusColor : Default.textColor + source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/double-arrow.png" opacity: enabled ? 1 : 0.3 } @@ -99,7 +98,7 @@ T.ComboBox { } background: Rectangle { - implicitWidth: 120 + implicitWidth: 140 implicitHeight: 40 color: !control.editable && control.visualFocus ? (control.pressed ? Default.focusPressedColor : Default.focusLightColor) : diff --git a/src/imports/controls/Container.qml b/src/imports/controls/Container.qml index 5844e0a2..a1f15d19 100644 --- a/src/imports/controls/Container.qml +++ b/src/imports/controls/Container.qml @@ -35,7 +35,7 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T +import QtQuick.Templates 2.3 as T T.Container { id: control diff --git a/src/imports/controls/Control.qml b/src/imports/controls/Control.qml index 85f40ae5..b747840b 100644 --- a/src/imports/controls/Control.qml +++ b/src/imports/controls/Control.qml @@ -35,7 +35,7 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T +import QtQuick.Templates 2.3 as T T.Control { id: control diff --git a/src/imports/controls/DelayButton.qml b/src/imports/controls/DelayButton.qml index 4a569fcf..0c66a5a2 100644 --- a/src/imports/controls/DelayButton.qml +++ b/src/imports/controls/DelayButton.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.DelayButton { id: control diff --git a/src/imports/controls/Dial.qml b/src/imports/controls/Dial.qml index affcfa62..f33ebf72 100644 --- a/src/imports/controls/Dial.qml +++ b/src/imports/controls/Dial.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.Dial { id: control @@ -45,7 +45,7 @@ T.Dial { implicitWidth: 184 implicitHeight: 184 - background: DialRing { + background: DialImpl { width: control.availableWidth height: control.availableHeight color: control.visualFocus ? Default.focusColor : Default.frameDarkColor @@ -53,15 +53,14 @@ T.Dial { opacity: control.enabled ? 1 : 0.3 } - handle: Image { + handle: ColorImage { id: handleItem x: background.x + background.width / 2 - handle.width / 2 y: background.y + background.height / 2 - handle.height / 2 width: 14 height: 10 - source: "image://default/dial-indicator/" + (control.visualFocus ? Default.focusColor : Default.textColor) - sourceSize.width: width - sourceSize.height: height + color: control.visualFocus ? Default.focusColor : Default.textColor + source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/dial-indicator.png" antialiasing: true opacity: control.enabled ? 1 : 0.3 transform: [ diff --git a/src/imports/controls/Dialog.qml b/src/imports/controls/Dialog.qml index 84c33b63..f2ebae34 100644 --- a/src/imports/controls/Dialog.qml +++ b/src/imports/controls/Dialog.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 T.Dialog { id: control diff --git a/src/imports/controls/DialogButtonBox.qml b/src/imports/controls/DialogButtonBox.qml index ba9fa52f..51c17d05 100644 --- a/src/imports/controls/DialogButtonBox.qml +++ b/src/imports/controls/DialogButtonBox.qml @@ -35,7 +35,7 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T +import QtQuick.Templates 2.3 as T T.DialogButtonBox { id: control diff --git a/src/imports/controls/Drawer.qml b/src/imports/controls/Drawer.qml index b3240ca3..8368838a 100644 --- a/src/imports/controls/Drawer.qml +++ b/src/imports/controls/Drawer.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.Drawer { id: control diff --git a/src/imports/controls/Frame.qml b/src/imports/controls/Frame.qml index 5add003f..c4b871d5 100644 --- a/src/imports/controls/Frame.qml +++ b/src/imports/controls/Frame.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.Frame { id: control diff --git a/src/imports/controls/GroupBox.qml b/src/imports/controls/GroupBox.qml index ee81250b..c991b251 100644 --- a/src/imports/controls/GroupBox.qml +++ b/src/imports/controls/GroupBox.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.GroupBox { id: control diff --git a/src/imports/controls/ItemDelegate.qml b/src/imports/controls/ItemDelegate.qml index 6ee03ca2..26309a9a 100644 --- a/src/imports/controls/ItemDelegate.qml +++ b/src/imports/controls/ItemDelegate.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.ItemDelegate { id: control @@ -50,19 +50,22 @@ T.ItemDelegate { baselineOffset: contentItem.y + contentItem.baselineOffset padding: 12 - spacing: 12 + spacing: 8 - contentItem: Text { - leftPadding: control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 - rightPadding: !control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 + icon.width: 24 + icon.height: 24 + icon.color: enabled ? Default.textDarkColor : Default.textDisabledColor + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + + icon: control.icon text: control.text font: control.font color: control.enabled ? Default.textDarkColor : Default.textDisabledColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } background: Rectangle { diff --git a/src/imports/controls/Label.qml b/src/imports/controls/Label.qml index d2052774..db6b25bf 100644 --- a/src/imports/controls/Label.qml +++ b/src/imports/controls/Label.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.Label { id: control diff --git a/src/imports/controls/Menu.qml b/src/imports/controls/Menu.qml index dc428629..9e4ce902 100644 --- a/src/imports/controls/Menu.qml +++ b/src/imports/controls/Menu.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.Menu { id: control diff --git a/src/imports/controls/MenuItem.qml b/src/imports/controls/MenuItem.qml index d2420d86..c60bc708 100644 --- a/src/imports/controls/MenuItem.qml +++ b/src/imports/controls/MenuItem.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.MenuItem { id: control @@ -50,18 +50,25 @@ T.MenuItem { baselineOffset: contentItem.y + contentItem.baselineOffset padding: 6 + spacing: 6 - contentItem: Text { + icon.width: 24 + icon.height: 24 + icon.color: enabled ? Default.textDarkColor : Default.textDisabledColor + + contentItem: IconLabel { leftPadding: control.checkable && !control.mirrored ? control.indicator.width + control.spacing : 0 rightPadding: control.checkable && control.mirrored ? control.indicator.width + control.spacing : 0 + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: Qt.AlignLeft + + icon: control.icon text: control.text font: control.font color: control.enabled ? Default.textDarkColor : Default.textDisabledColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } indicator: Image { diff --git a/src/imports/controls/MenuSeparator.qml b/src/imports/controls/MenuSeparator.qml index f0c588b2..f3916673 100644 --- a/src/imports/controls/MenuSeparator.qml +++ b/src/imports/controls/MenuSeparator.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.MenuSeparator { id: control diff --git a/src/imports/controls/Page.qml b/src/imports/controls/Page.qml index 64c16bf4..4e8ce753 100644 --- a/src/imports/controls/Page.qml +++ b/src/imports/controls/Page.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.Page { id: control diff --git a/src/imports/controls/PageIndicator.qml b/src/imports/controls/PageIndicator.qml index 3ff7d0c1..a702794f 100644 --- a/src/imports/controls/PageIndicator.qml +++ b/src/imports/controls/PageIndicator.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.PageIndicator { id: control diff --git a/src/imports/controls/Pane.qml b/src/imports/controls/Pane.qml index 7ed7f0d8..eaad8e99 100644 --- a/src/imports/controls/Pane.qml +++ b/src/imports/controls/Pane.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.Pane { id: control diff --git a/src/imports/controls/Popup.qml b/src/imports/controls/Popup.qml index 4a7a1dfd..7a94aaab 100644 --- a/src/imports/controls/Popup.qml +++ b/src/imports/controls/Popup.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.Popup { id: control diff --git a/src/imports/controls/ProgressBar.qml b/src/imports/controls/ProgressBar.qml index eae6c019..78778c72 100644 --- a/src/imports/controls/ProgressBar.qml +++ b/src/imports/controls/ProgressBar.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 T.ProgressBar { id: control @@ -53,6 +53,7 @@ T.ProgressBar { scale: control.mirrored ? -1 : 1 progress: control.position indeterminate: control.visible && control.indeterminate + color: Default.textColor } background: Rectangle { diff --git a/src/imports/controls/RadioButton.qml b/src/imports/controls/RadioButton.qml index 878a0fe3..a0829ab6 100644 --- a/src/imports/controls/RadioButton.qml +++ b/src/imports/controls/RadioButton.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.RadioButton { id: control diff --git a/src/imports/controls/RadioDelegate.qml b/src/imports/controls/RadioDelegate.qml index 03cd83bd..b3aeb2b3 100644 --- a/src/imports/controls/RadioDelegate.qml +++ b/src/imports/controls/RadioDelegate.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.RadioDelegate { id: control @@ -52,17 +52,23 @@ T.RadioDelegate { padding: 12 spacing: 12 - contentItem: Text { + icon.width: 24 + icon.height: 24 + icon.color: enabled ? Default.textDarkColor : Default.textDisabledColor + + contentItem: IconLabel { leftPadding: control.mirrored ? control.indicator.width + control.spacing : 0 rightPadding: !control.mirrored ? control.indicator.width + control.spacing : 0 + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + + icon: control.icon text: control.text font: control.font color: control.enabled ? Default.textDarkColor : Default.textDisabledColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } indicator: RadioIndicator { diff --git a/src/imports/controls/RadioIndicator.qml b/src/imports/controls/RadioIndicator.qml index d9889fba..96ff4bb6 100644 --- a/src/imports/controls/RadioIndicator.qml +++ b/src/imports/controls/RadioIndicator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 Rectangle { implicitWidth: 28 diff --git a/src/imports/controls/RangeSlider.qml b/src/imports/controls/RangeSlider.qml index b38cb0f6..3a3c2202 100644 --- a/src/imports/controls/RangeSlider.qml +++ b/src/imports/controls/RangeSlider.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.RangeSlider { id: control @@ -52,8 +52,8 @@ T.RangeSlider { padding: 6 first.handle: Rectangle { - x: control.leftPadding + (horizontal ? control.first.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : control.first.visualPosition * (control.availableHeight - height)) + x: control.leftPadding + (control.horizontal ? control.first.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.first.visualPosition * (control.availableHeight - height)) implicitWidth: 28 implicitHeight: 28 radius: width / 2 @@ -64,13 +64,11 @@ T.RangeSlider { color: control.enabled ? (first.pressed ? (activeFocus ? Default.focusPressedColor : Default.indicatorPressedColor) : (activeFocus ? Default.focusLightColor : Default.backgroundColor)) : Default.indicatorDisabledColor - - readonly property bool horizontal: control.orientation === Qt.Horizontal } second.handle: Rectangle { - x: control.leftPadding + (horizontal ? control.second.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : control.second.visualPosition * (control.availableHeight - height)) + x: control.leftPadding + (control.horizontal ? control.second.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.second.visualPosition * (control.availableHeight - height)) implicitWidth: 28 implicitHeight: 28 radius: width / 2 @@ -81,28 +79,24 @@ T.RangeSlider { color: control.enabled ? (second.pressed ? (activeFocus ? Default.focusPressedColor : Default.indicatorPressedColor) : (activeFocus ? Default.focusLightColor : Default.backgroundColor)) : Default.indicatorDisabledColor - - readonly property bool horizontal: control.orientation === Qt.Horizontal } background: Rectangle { - x: control.leftPadding + (horizontal ? 0 : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : 0) - implicitWidth: horizontal ? 200 : 6 - implicitHeight: horizontal ? 6 : 200 - width: horizontal ? control.availableWidth : implicitWidth - height: horizontal ? implicitHeight : control.availableHeight + x: control.leftPadding + (control.horizontal ? 0 : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : 0) + implicitWidth: control.horizontal ? 200 : 6 + implicitHeight: control.horizontal ? 6 : 200 + width: control.horizontal ? control.availableWidth : implicitWidth + height: control.horizontal ? implicitHeight : control.availableHeight radius: 3 color: Default.buttonColor - scale: horizontal && control.mirrored ? -1 : 1 - - readonly property bool horizontal: control.orientation === Qt.Horizontal + scale: control.horizontal && control.mirrored ? -1 : 1 Rectangle { - x: parent.horizontal ? control.first.position * parent.width + 3 : 0 - y: parent.horizontal ? 0 : control.second.visualPosition * parent.height + 3 - width: parent.horizontal ? control.second.position * parent.width - control.first.position * parent.width - 6 : 6 - height: parent.horizontal ? 6 : control.second.position * parent.height - control.first.position * parent.height - 6 + x: control.horizontal ? control.first.position * parent.width + 3 : 0 + y: control.horizontal ? 0 : control.second.visualPosition * parent.height + 3 + width: control.horizontal ? control.second.position * parent.width - control.first.position * parent.width - 6 : 6 + height: control.horizontal ? 6 : control.second.position * parent.height - control.first.position * parent.height - 6 color: Default.textColor } diff --git a/src/imports/controls/RoundButton.qml b/src/imports/controls/RoundButton.qml index 6b4000b1..62c5556e 100644 --- a/src/imports/controls/RoundButton.qml +++ b/src/imports/controls/RoundButton.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.RoundButton { id: control @@ -49,15 +49,27 @@ T.RoundButton { baselineOffset: contentItem.y + contentItem.baselineOffset padding: 6 + spacing: 6 - contentItem: Text { + icon.width: 24 + icon.height: 24 + icon.color: Color.transparent(checked || highlighted ? Default.textLightColor + : visualFocus ? Default.focusColor + : down ? Default.textDarkColor : Default.textColor, + enabled || highlighted || checked ? 1 : 0.3) + + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font - opacity: enabled || control.highlighted || control.checked ? 1 : 0.3 - color: control.checked || control.highlighted ? Default.textLightColor : (control.visualFocus ? Default.focusColor : (control.down ? Default.textDarkColor : Default.textColor)) - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight + color: Color.transparent(control.checked || control.highlighted ? Default.textLightColor + : control.visualFocus ? Default.focusColor + : control.down ? Default.textDarkColor : Default.textColor, + enabled || control.highlighted || control.checked ? 1 : 0.3) } background: Rectangle { diff --git a/src/imports/controls/ScrollBar.qml b/src/imports/controls/ScrollBar.qml index 79e3e1ee..54e9b6fa 100644 --- a/src/imports/controls/ScrollBar.qml +++ b/src/imports/controls/ScrollBar.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.ScrollBar { id: control diff --git a/src/imports/controls/ScrollIndicator.qml b/src/imports/controls/ScrollIndicator.qml index 12ec2d40..c233c16f 100644 --- a/src/imports/controls/ScrollIndicator.qml +++ b/src/imports/controls/ScrollIndicator.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.ScrollIndicator { id: control diff --git a/src/imports/controls/ScrollView.qml b/src/imports/controls/ScrollView.qml index e10c5328..6167801e 100644 --- a/src/imports/controls/ScrollView.qml +++ b/src/imports/controls/ScrollView.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.ScrollView { id: control diff --git a/src/imports/controls/Slider.qml b/src/imports/controls/Slider.qml index 37145cad..399b25c7 100644 --- a/src/imports/controls/Slider.qml +++ b/src/imports/controls/Slider.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.Slider { id: control @@ -50,8 +50,8 @@ T.Slider { padding: 6 handle: Rectangle { - x: control.leftPadding + (horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : control.visualPosition * (control.availableHeight - height)) + x: control.leftPadding + (control.horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.visualPosition * (control.availableHeight - height)) implicitWidth: 28 implicitHeight: 28 radius: width / 2 @@ -62,21 +62,26 @@ T.Slider { border.color: control.enabled ? (control.visualFocus ? Default.focusColor : (control.pressed ? Default.indicatorFramePressedColor : Default.indicatorFrameColor)) : Default.indicatorFrameDisabledColor - - readonly property bool horizontal: control.orientation === Qt.Horizontal } background: Rectangle { - x: control.leftPadding + (horizontal ? 0 : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : 0) - implicitWidth: horizontal ? 200 : 6 - implicitHeight: horizontal ? 6 : 200 - width: horizontal ? control.availableWidth : implicitWidth - height: horizontal ? implicitHeight : control.availableHeight + x: control.leftPadding + (control.horizontal ? 0 : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : 0) + implicitWidth: control.horizontal ? 200 : 6 + implicitHeight: control.horizontal ? 6 : 200 + width: control.horizontal ? control.availableWidth : implicitWidth + height: control.horizontal ? implicitHeight : control.availableHeight radius: 3 color: Default.buttonColor - scale: horizontal && control.mirrored ? -1 : 1 + scale: control.horizontal && control.mirrored ? -1 : 1 + + Rectangle { + y: control.horizontal ? 0 : control.visualPosition * parent.height + width: control.horizontal ? control.position * parent.width : 6 + height: control.horizontal ? 6 : control.position * parent.height - readonly property bool horizontal: control.orientation === Qt.Horizontal + radius: 3 + color: Default.textColor + } } } diff --git a/src/imports/controls/SpinBox.qml b/src/imports/controls/SpinBox.qml index 9aca4d7c..ef00924c 100644 --- a/src/imports/controls/SpinBox.qml +++ b/src/imports/controls/SpinBox.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.SpinBox { id: control diff --git a/src/imports/controls/StackView.qml b/src/imports/controls/StackView.qml index 6d52aaed..71cf1f42 100644 --- a/src/imports/controls/StackView.qml +++ b/src/imports/controls/StackView.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Templates 2.3 as T T.StackView { id: control diff --git a/src/imports/controls/SwipeDelegate.qml b/src/imports/controls/SwipeDelegate.qml index d9f72da9..01f21130 100644 --- a/src/imports/controls/SwipeDelegate.qml +++ b/src/imports/controls/SwipeDelegate.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.SwipeDelegate { id: control @@ -52,22 +52,27 @@ T.SwipeDelegate { padding: 12 spacing: 12 + icon.width: 24 + icon.height: 24 + icon.color: control.enabled ? Default.textDarkColor : Default.textDisabledColor + swipe.transition: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } - contentItem: Text { - leftPadding: control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 - rightPadding: !control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + icon: control.icon text: control.text font: control.font color: control.enabled ? Default.textDarkColor : Default.textDisabledColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } background: Rectangle { + implicitWidth: 100 + implicitHeight: 40 color: control.visualFocus ? (control.down ? Default.focusPressedColor : Default.delegateFocusColor) : (control.down ? Default.delegatePressedColor : Default.backgroundColor) diff --git a/src/imports/controls/SwipeView.qml b/src/imports/controls/SwipeView.qml index 4ccef22b..e395b8a2 100644 --- a/src/imports/controls/SwipeView.qml +++ b/src/imports/controls/SwipeView.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Templates 2.3 as T T.SwipeView { id: control diff --git a/src/imports/controls/Switch.qml b/src/imports/controls/Switch.qml index 55b08039..3afa7d21 100644 --- a/src/imports/controls/Switch.qml +++ b/src/imports/controls/Switch.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 T.Switch { id: control diff --git a/src/imports/controls/SwitchDelegate.qml b/src/imports/controls/SwitchDelegate.qml index 6536ac53..d54c00fa 100644 --- a/src/imports/controls/SwitchDelegate.qml +++ b/src/imports/controls/SwitchDelegate.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 T.SwitchDelegate { id: control @@ -52,23 +52,29 @@ T.SwitchDelegate { padding: 12 spacing: 12 + icon.width: 24 + icon.height: 24 + icon.color: enabled ? Default.textDarkColor : Default.textDisabledColor + indicator: SwitchIndicator { x: text ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 control: control } - contentItem: Text { - leftPadding: control.indicator && !control.mirrored ? 0 : control.indicator.width + control.spacing - rightPadding: control.indicator && control.mirrored ? 0 : control.indicator.width + control.spacing + contentItem: IconLabel { + leftPadding: control.mirrored ? control.indicator.width + control.spacing : 0 + rightPadding: !control.mirrored ? control.indicator.width + control.spacing : 0 + + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + icon: control.icon text: control.text font: control.font color: control.enabled ? Default.textDarkColor : Default.textDisabledColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } background: Rectangle { diff --git a/src/imports/controls/SwitchIndicator.qml b/src/imports/controls/SwitchIndicator.qml index 347b2293..795e68ef 100644 --- a/src/imports/controls/SwitchIndicator.qml +++ b/src/imports/controls/SwitchIndicator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 Item { implicitWidth: 56 diff --git a/src/imports/controls/TabBar.qml b/src/imports/controls/TabBar.qml index 6e6b7d74..8b899d66 100644 --- a/src/imports/controls/TabBar.qml +++ b/src/imports/controls/TabBar.qml @@ -35,7 +35,7 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T +import QtQuick.Templates 2.3 as T T.TabBar { id: control @@ -46,7 +46,6 @@ T.TabBar { contentHeight + topPadding + bottomPadding) spacing: 1 - contentHeight: 40 contentItem: ListView { model: control.contentModel diff --git a/src/imports/controls/TabButton.qml b/src/imports/controls/TabButton.qml index acdda056..2350d0d0 100644 --- a/src/imports/controls/TabButton.qml +++ b/src/imports/controls/TabButton.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.TabButton { id: control @@ -49,15 +49,22 @@ T.TabButton { baselineOffset: contentItem.y + contentItem.baselineOffset padding: 6 + spacing: 6 - contentItem: Text { + icon.width: 24 + icon.height: 24 + icon.color: Color.transparent(!checked ? Default.textLightColor : down ? Default.textDarkColor : Default.textColor, enabled ? 1 : 0.3) + + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font - elide: Text.ElideRight - opacity: enabled ? 1 : 0.3 - color: !control.checked ? Default.textLightColor : control.down ? Default.textDarkColor : Default.textColor - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter + color: Color.transparent(!control.checked ? Default.textLightColor : control.down ? Default.textDarkColor : Default.textColor, + enabled ? 1 : 0.3) } background: Rectangle { diff --git a/src/imports/controls/TextArea.qml b/src/imports/controls/TextArea.qml index cbba5912..4f30457f 100644 --- a/src/imports/controls/TextArea.qml +++ b/src/imports/controls/TextArea.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.TextArea { id: control diff --git a/src/imports/controls/TextField.qml b/src/imports/controls/TextField.qml index 980ff172..4e4bd681 100644 --- a/src/imports/controls/TextField.qml +++ b/src/imports/controls/TextField.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.TextField { id: control diff --git a/src/imports/controls/ToolBar.qml b/src/imports/controls/ToolBar.qml index e3d4fec3..2e5bd912 100644 --- a/src/imports/controls/ToolBar.qml +++ b/src/imports/controls/ToolBar.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.ToolBar { id: control diff --git a/src/imports/controls/ToolButton.qml b/src/imports/controls/ToolButton.qml index 6199607a..345fdb9a 100644 --- a/src/imports/controls/ToolButton.qml +++ b/src/imports/controls/ToolButton.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.ToolButton { id: control @@ -49,14 +49,21 @@ T.ToolButton { baselineOffset: contentItem.y + contentItem.baselineOffset padding: 6 + spacing: 6 - contentItem: Text { + icon.width: 24 + icon.height: 24 + icon.color: enabled ? (visualFocus ? Default.focusColor : Default.textDarkColor) : Default.textDisabledLightColor + + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font color: control.enabled ? (control.visualFocus ? Default.focusColor : Default.textDarkColor) : Default.textDisabledLightColor - elide: Text.ElideRight - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter } background: Rectangle { diff --git a/src/imports/controls/ToolSeparator.qml b/src/imports/controls/ToolSeparator.qml index 3c588558..b1d5dd7b 100644 --- a/src/imports/controls/ToolSeparator.qml +++ b/src/imports/controls/ToolSeparator.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.ToolSeparator { id: control diff --git a/src/imports/controls/ToolTip.qml b/src/imports/controls/ToolTip.qml index 587fc042..5e3614b2 100644 --- a/src/imports/controls/ToolTip.qml +++ b/src/imports/controls/ToolTip.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.ToolTip { id: control diff --git a/src/imports/controls/Tumbler.qml b/src/imports/controls/Tumbler.qml index 3659e770..be69c9e0 100644 --- a/src/imports/controls/Tumbler.qml +++ b/src/imports/controls/Tumbler.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T T.Tumbler { id: control diff --git a/src/imports/controls/controls.pri b/src/imports/controls/controls.pri index 1dfe1911..7d23e7ae 100644 --- a/src/imports/controls/controls.pri +++ b/src/imports/controls/controls.pri @@ -1,12 +1,12 @@ HEADERS += \ - $$PWD/qquickdialring_p.h \ $$PWD/qquickdefaultbusyindicator_p.h \ + $$PWD/qquickdefaultdial_p.h \ $$PWD/qquickdefaultprogressbar_p.h \ $$PWD/qquickdefaultstyle_p.h SOURCES += \ - $$PWD/qquickdialring.cpp \ $$PWD/qquickdefaultbusyindicator.cpp \ + $$PWD/qquickdefaultdial.cpp \ $$PWD/qquickdefaultprogressbar.cpp \ $$PWD/qquickdefaultstyle.cpp diff --git a/src/imports/controls/controls.pro b/src/imports/controls/controls.pro index 8024bbf8..b75e4f56 100644 --- a/src/imports/controls/controls.pro +++ b/src/imports/controls/controls.pro @@ -1,6 +1,6 @@ TARGET = qtquickcontrols2plugin TARGETPATH = QtQuick/Controls.2 -IMPORT_VERSION = 2.2 +IMPORT_VERSION = 2.3 QT += qml quick QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private diff --git a/src/imports/controls/dependencies.json b/src/imports/controls/dependencies.json index 4c9cfcd3..8cec519e 100644 --- a/src/imports/controls/dependencies.json +++ b/src/imports/controls/dependencies.json @@ -12,6 +12,6 @@ { "name": "QtQuick.Templates", "type": "module", - "version": "2.2" + "version": "2.3" } ] diff --git a/src/imports/controls/doc/images/qtquickcontrols2-button-icononly.png b/src/imports/controls/doc/images/qtquickcontrols2-button-icononly.png Binary files differnew file mode 100644 index 00000000..91a21d17 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-button-icononly.png diff --git a/src/imports/controls/doc/images/qtquickcontrols2-button-textbesideicon.png b/src/imports/controls/doc/images/qtquickcontrols2-button-textbesideicon.png Binary files differnew file mode 100644 index 00000000..1d46133f --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-button-textbesideicon.png diff --git a/src/imports/controls/doc/images/qtquickcontrols2-button-textonly.png b/src/imports/controls/doc/images/qtquickcontrols2-button-textonly.png Binary files differnew file mode 100644 index 00000000..4449e748 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-button-textonly.png diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-action.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-action.qml new file mode 100644 index 00000000..e4ef4f5b --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-action.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Controls 2.3 + +Item { + //! [action] + Action { + id: copyAction + text: qsTr("&Copy") + icon.name: "edit-copy" + shortcut: StandardKey.Copy + onTriggered: window.activeFocusItem.copy() + } + //! [action] + + //! [toolbutton] + ToolButton { + id: toolButton + action: copyAction + } + //! [toolbutton] + + //! [menuitem] + MenuItem { + id: menuItem + action: copyAction + text: qsTr("&Copy selected Text") + } + //! [menuitem] +} diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-button-icononly.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-button-icononly.qml new file mode 100644 index 00000000..0a58d4ad --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-button-icononly.qml @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Controls 2.3 + +Button { + icon.source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/check.png" + display: Button.IconOnly +} diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-button-textbesideicon.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-button-textbesideicon.qml new file mode 100644 index 00000000..308837f7 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-button-textbesideicon.qml @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Controls 2.3 + +Button { + text: "Button" + icon.source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/images/check.png" + display: Button.TextBesideIcon +} diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-button-textonly.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-button-textonly.qml new file mode 100644 index 00000000..89d335e4 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-button-textonly.qml @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Controls 2.3 + +Button { + text: "Button" + display: Button.TextOnly +} diff --git a/src/imports/controls/doc/src/includes/qquickicon.qdocinc b/src/imports/controls/doc/src/includes/qquickicon.qdocinc new file mode 100644 index 00000000..a6ab90bb --- /dev/null +++ b/src/imports/controls/doc/src/includes/qquickicon.qdocinc @@ -0,0 +1,42 @@ +//! [grouped-properties] +\table +\header + \li Name + \li Description +\row + \li name + \li This property holds the name of the icon to use. + + The icon will be loaded from the platform theme. If the icon is found + in the theme, it will always be used; even if \l icon.source is also set. + If the icon is not found, \l icon.source will be used instead. + + For more information on theme icons, see \l {QIcon::fromTheme()}. +\row + \li source + \li This property holds the name of the icon to use. + + The icon will be loaded as a regular image. + + If \l icon.name is set and refers to a valid theme icon, it will always + be used instead of this property. +\row + \li width + \li This property holds the width of the icon. + + The icon's width will never exceed this value, though it will + shrink when necessary. +\row + \li height + \li This property holds the height of the icon. + + The icon's height will never exceed this value, though it will + shrink when necessary. +\row + \li color + \li This property holds the color of the icon. + + The icon is tinted with the specified color, unless the color is + set to \c "transparent". +\endtable +//! [grouped-properties] diff --git a/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc index e6e2977f..419fd991 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-differences.qdoc @@ -203,15 +203,9 @@ \li Remarks \row \li \l [QML QtQuickControls] {Action} - \li \mdash + \li \l [QML QtQuickControls2] {Action} \li \l [QML QtQuick] {Shortcut} \br\sup {(Qt Quick)} - \li \list - \li \b {Qt Quick Controls 1}: \c Action is an abstract user interface - action that is bound to buttons and menu items, and can provide - shortcuts. - \li \b {Qt Quick}: \c Shortcut provides the shortcut functionality that - was previously only provided by \c Action. - \endlist + \li \row \li \l [QML QtQuickControls] {ApplicationWindow} \li \l [QML QtQuickControls2] {ApplicationWindow} @@ -250,9 +244,10 @@ \row \li \l [QML QtQuickControls] {ExclusiveGroup} \li \mdash - \li \l [QML QtQuickControls2] {ButtonGroup} \br\sup {(Qt Quick Controls 2)} + \li \l [QML QtQuickControls2] {ActionGroup},\br + \l [QML QtQuickControls2] {ButtonGroup} \br\sup {(Qt Quick Controls 2)} \li \list - \li \b {Qt Quick Controls 2}: \c ButtonGroup offers similar functionality. + \li \b {Qt Quick Controls 2}: \c ActionGroup and \c ButtonGroup offer similar functionality. \endlist \row \li \l [QML QtQuickControls] {GroupBox} @@ -521,6 +516,13 @@ \li \row \li \mdash + \li \l [QML QtQuickControls2] {ActionGroup} + \li \l [QML QtQuickControls] {ExclusiveGroup} \br\sup {(Qt Quick Controls 1)} + \li \list + \li \b {Qt Quick Controls 1}: \c ExclusiveGroup offers similar functionality. + \endlist + \row + \li \mdash \li \l [QML QtQuickControls2] {ButtonGroup} \li \l [QML QtQuickControls] {ExclusiveGroup} \br\sup {(Qt Quick Controls 1)} \li \list diff --git a/src/imports/controls/doc/src/qtquickcontrols2-index.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-index.qdoc index 868e77e0..703c5d33 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-index.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-index.qdoc @@ -71,7 +71,7 @@ application using the following import statement in your \c {.qml} file: \code - import QtQuick.Controls 2.2 + import QtQuick.Controls 2.3 \endcode The \l{Qt Quick Controls 2 C++ Classes}{C++ classes} can be included into @@ -122,6 +122,11 @@ \li 2.2 \li 1.0 \row + \li 5.10 + \li 2.10 + \li 2.3 + \li 1.0 + \row \li ... \li ... \li ... diff --git a/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc index 065f3fe9..f661a28d 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-material.qdoc @@ -32,7 +32,7 @@ The Material Style is based on the Google Material Design Guidelines. \l{detailed-desc-material}{More...} - \styleimport {QtQuick.Controls.Material 2.2} {Qt 5.7} + \styleimport {QtQuick.Controls.Material 2.3} {Qt 5.7} \section1 Attached Properties diff --git a/src/imports/controls/doc/src/qtquickcontrols2-qmltypes.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-qmltypes.qdoc index 3b69da04..4bdccecc 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-qmltypes.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-qmltypes.qdoc @@ -26,7 +26,7 @@ ****************************************************************************/ /*! - \qmlmodule QtQuick.Controls 2.2 + \qmlmodule QtQuick.Controls 2.3 \title Qt Quick Controls 2 QML Types \ingroup qmlmodules \brief Provides QML types for user interfaces (Qt Quick Controls 2). @@ -39,7 +39,7 @@ using the following import statement in your .qml file: \badcode - import QtQuick.Controls 2.2 + import QtQuick.Controls 2.3 \endcode \section1 QML Types diff --git a/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc index 8f3d2330..b4fe4dfa 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-universal.qdoc @@ -32,7 +32,7 @@ The Universal Style is based on the Microsoft Universal Design Guidelines. \l {detailed-desc-universal}{More...} - \styleimport {QtQuick.Controls.Universal 2.2} {Qt 5.7} + \styleimport {QtQuick.Controls.Universal 2.3} {Qt 5.7} \section1 Attached Properties diff --git a/src/imports/controls/material/ApplicationWindow.qml b/src/imports/controls/material/ApplicationWindow.qml index 0d56ed2c..45f1b59a 100644 --- a/src/imports/controls/material/ApplicationWindow.qml +++ b/src/imports/controls/material/ApplicationWindow.qml @@ -36,8 +36,8 @@ import QtQuick 2.9 import QtQuick.Window 2.3 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 T.ApplicationWindow { id: window diff --git a/src/imports/controls/material/BoxShadow.qml b/src/imports/controls/material/BoxShadow.qml index aa9fd0fa..b2ceeaeb 100644 --- a/src/imports/controls/material/BoxShadow.qml +++ b/src/imports/controls/material/BoxShadow.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 /* A implementation of CSS's box-shadow, used by ElevationEffect for a Material Design diff --git a/src/imports/controls/material/BusyIndicator.qml b/src/imports/controls/material/BusyIndicator.qml index f1cf8eb5..6ffd65cc 100644 --- a/src/imports/controls/material/BusyIndicator.qml +++ b/src/imports/controls/material/BusyIndicator.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.BusyIndicator { id: control diff --git a/src/imports/controls/material/Button.qml b/src/imports/controls/material/Button.qml index e5821375..7d5ff57d 100644 --- a/src/imports/controls/material/Button.qml +++ b/src/imports/controls/material/Button.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.Button { id: control @@ -52,20 +54,29 @@ T.Button { padding: 12 leftPadding: padding - 4 rightPadding: padding - 4 + spacing: 6 + + icon.width: 24 + icon.height: 24 + icon.color: !enabled ? Material.hintTextColor : + flat && highlighted ? Material.accentColor : + highlighted ? Material.primaryHighlightedTextColor : Material.foreground Material.elevation: flat ? control.down || control.hovered ? 2 : 0 : control.down ? 8 : 2 Material.background: flat ? "transparent" : undefined - contentItem: Text { + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font color: !control.enabled ? control.Material.hintTextColor : control.flat && control.highlighted ? control.Material.accentColor : control.highlighted ? control.Material.primaryHighlightedTextColor : control.Material.foreground - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight } // TODO: Add a proper ripple/ink effect for mouse/touch input and focus state diff --git a/src/imports/controls/material/CheckBox.qml b/src/imports/controls/material/CheckBox.qml index e1c559da..543122b8 100644 --- a/src/imports/controls/material/CheckBox.qml +++ b/src/imports/controls/material/CheckBox.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.CheckBox { id: control diff --git a/src/imports/controls/material/CheckDelegate.qml b/src/imports/controls/material/CheckDelegate.qml index 545ca64a..5e6aabef 100644 --- a/src/imports/controls/material/CheckDelegate.qml +++ b/src/imports/controls/material/CheckDelegate.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.CheckDelegate { id: control @@ -54,23 +56,29 @@ T.CheckDelegate { bottomPadding: 14 spacing: 16 + icon.width: 24 + icon.height: 24 + icon.color: enabled ? Material.foreground : Material.hintTextColor + indicator: CheckIndicator { x: text ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 control: control } - contentItem: Text { + contentItem: IconLabel { leftPadding: !control.mirrored ? 0 : control.indicator.width + control.spacing rightPadding: control.mirrored ? 0 : control.indicator.width + control.spacing + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + + icon: control.icon text: control.text font: control.font color: control.enabled ? control.Material.foreground : control.Material.hintTextColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } background: Rectangle { diff --git a/src/imports/controls/material/CheckIndicator.qml b/src/imports/controls/material/CheckIndicator.qml index 8fe860f0..b8d4a972 100644 --- a/src/imports/controls/material/CheckIndicator.qml +++ b/src/imports/controls/material/CheckIndicator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 Rectangle { id: indicatorItem diff --git a/src/imports/controls/material/ComboBox.qml b/src/imports/controls/material/ComboBox.qml index d3e6d588..c2bdff65 100644 --- a/src/imports/controls/material/ComboBox.qml +++ b/src/imports/controls/material/ComboBox.qml @@ -35,10 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.ComboBox { id: control @@ -66,12 +67,11 @@ T.ComboBox { hoverEnabled: control.hoverEnabled } - indicator: Image { + indicator: ColorImage { x: control.mirrored ? control.padding : control.width - width - control.padding y: control.topPadding + (control.availableHeight - height) / 2 - source: "image://material/drop-indicator/" + (control.enabled ? control.Material.foreground : control.Material.hintTextColor) - sourceSize.width: width - sourceSize.height: height + color: control.enabled ? control.Material.foreground : control.Material.hintTextColor + source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Material/images/drop-indicator.png" } contentItem: T.TextField { diff --git a/src/imports/controls/material/CursorDelegate.qml b/src/imports/controls/material/CursorDelegate.qml index 2af44017..032f01c7 100644 --- a/src/imports/controls/material/CursorDelegate.qml +++ b/src/imports/controls/material/CursorDelegate.qml @@ -35,7 +35,7 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls.Material 2.2 +import QtQuick.Controls.Material 2.3 Rectangle { id: cursor diff --git a/src/imports/controls/material/DelayButton.qml b/src/imports/controls/material/DelayButton.qml index 16f240a2..df4dc3fe 100644 --- a/src/imports/controls/material/DelayButton.qml +++ b/src/imports/controls/material/DelayButton.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.DelayButton { id: control diff --git a/src/imports/controls/material/Dial.qml b/src/imports/controls/material/Dial.qml index e0632e62..4c4fb239 100644 --- a/src/imports/controls/material/Dial.qml +++ b/src/imports/controls/material/Dial.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.Dial { id: control diff --git a/src/imports/controls/material/Dialog.qml b/src/imports/controls/material/Dialog.qml index a97cb2fd..68f856c6 100644 --- a/src/imports/controls/material/Dialog.qml +++ b/src/imports/controls/material/Dialog.qml @@ -35,10 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.Dialog { id: control diff --git a/src/imports/controls/material/DialogButtonBox.qml b/src/imports/controls/material/DialogButtonBox.qml index c4b3e0ad..0b1321a2 100644 --- a/src/imports/controls/material/DialogButtonBox.qml +++ b/src/imports/controls/material/DialogButtonBox.qml @@ -35,10 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.DialogButtonBox { id: control diff --git a/src/imports/controls/material/Drawer.qml b/src/imports/controls/material/Drawer.qml index dc06c895..78b6f2b8 100644 --- a/src/imports/controls/material/Drawer.qml +++ b/src/imports/controls/material/Drawer.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.Drawer { id: control diff --git a/src/imports/controls/material/ElevationEffect.qml b/src/imports/controls/material/ElevationEffect.qml index 0d0c1992..1d60a102 100644 --- a/src/imports/controls/material/ElevationEffect.qml +++ b/src/imports/controls/material/ElevationEffect.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 /* An effect for standard Material Design elevation shadows. Useful for using as \c layer.effect. diff --git a/src/imports/controls/material/Frame.qml b/src/imports/controls/material/Frame.qml index 760fc6d2..56cbdcaa 100644 --- a/src/imports/controls/material/Frame.qml +++ b/src/imports/controls/material/Frame.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.Frame { id: control diff --git a/src/imports/controls/material/GroupBox.qml b/src/imports/controls/material/GroupBox.qml index e7055404..67bf2090 100644 --- a/src/imports/controls/material/GroupBox.qml +++ b/src/imports/controls/material/GroupBox.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.GroupBox { id: control diff --git a/src/imports/controls/material/ItemDelegate.qml b/src/imports/controls/material/ItemDelegate.qml index 59d51c36..09471fae 100644 --- a/src/imports/controls/material/ItemDelegate.qml +++ b/src/imports/controls/material/ItemDelegate.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.ItemDelegate { id: control @@ -52,17 +54,20 @@ T.ItemDelegate { padding: 16 spacing: 16 - contentItem: Text { - leftPadding: control.checkable && !control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 - rightPadding: control.checkable && control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 + icon.width: 24 + icon.height: 24 + icon.color: enabled ? Material.foreground : Material.hintTextColor + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + + icon: control.icon text: control.text font: control.font color: control.enabled ? control.Material.foreground : control.Material.hintTextColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } background: Rectangle { diff --git a/src/imports/controls/material/Label.qml b/src/imports/controls/material/Label.qml index 4433e248..ddbe80c4 100644 --- a/src/imports/controls/material/Label.qml +++ b/src/imports/controls/material/Label.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 T.Label { id: control diff --git a/src/imports/controls/material/Menu.qml b/src/imports/controls/material/Menu.qml index 3e76c81d..9767eed0 100644 --- a/src/imports/controls/material/Menu.qml +++ b/src/imports/controls/material/Menu.qml @@ -35,10 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Controls 2.3 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.Menu { id: control diff --git a/src/imports/controls/material/MenuItem.qml b/src/imports/controls/material/MenuItem.qml index 5a136231..b91718b6 100644 --- a/src/imports/controls/material/MenuItem.qml +++ b/src/imports/controls/material/MenuItem.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.MenuItem { id: control @@ -54,6 +56,10 @@ T.MenuItem { bottomPadding: 12 spacing: 16 + icon.width: 24 + icon.height: 24 + icon.color: enabled ? Material.foreground : Material.hintTextColor + indicator: CheckIndicator { x: text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 @@ -61,17 +67,19 @@ T.MenuItem { control: control } - contentItem: Text { + contentItem: IconLabel { leftPadding: control.checkable && !control.mirrored ? control.indicator.width + control.spacing : 0 rightPadding: control.checkable && control.mirrored ? control.indicator.width + control.spacing : 0 + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: Qt.AlignLeft + + icon: control.icon text: control.text font: control.font color: control.enabled ? control.Material.foreground : control.Material.hintTextColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } background: Rectangle { diff --git a/src/imports/controls/material/MenuSeparator.qml b/src/imports/controls/material/MenuSeparator.qml index fd0febbe..b00ae79b 100644 --- a/src/imports/controls/material/MenuSeparator.qml +++ b/src/imports/controls/material/MenuSeparator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 T.MenuSeparator { id: control diff --git a/src/imports/controls/material/Page.qml b/src/imports/controls/material/Page.qml index 825b9f90..cb2ae6f9 100644 --- a/src/imports/controls/material/Page.qml +++ b/src/imports/controls/material/Page.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 T.Page { id: control diff --git a/src/imports/controls/material/PageIndicator.qml b/src/imports/controls/material/PageIndicator.qml index 15acae5e..55a60e51 100644 --- a/src/imports/controls/material/PageIndicator.qml +++ b/src/imports/controls/material/PageIndicator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 T.PageIndicator { id: control diff --git a/src/imports/controls/material/Pane.qml b/src/imports/controls/material/Pane.qml index 925778fa..6109f65d 100644 --- a/src/imports/controls/material/Pane.qml +++ b/src/imports/controls/material/Pane.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.Pane { id: control diff --git a/src/imports/controls/material/Popup.qml b/src/imports/controls/material/Popup.qml index cfcf00cb..49b39a6c 100644 --- a/src/imports/controls/material/Popup.qml +++ b/src/imports/controls/material/Popup.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.Popup { id: control diff --git a/src/imports/controls/material/ProgressBar.qml b/src/imports/controls/material/ProgressBar.qml index 1bc03016..daa2c74b 100644 --- a/src/imports/controls/material/ProgressBar.qml +++ b/src/imports/controls/material/ProgressBar.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.ProgressBar { id: control diff --git a/src/imports/controls/material/RadioButton.qml b/src/imports/controls/material/RadioButton.qml index d178654f..81cd302b 100644 --- a/src/imports/controls/material/RadioButton.qml +++ b/src/imports/controls/material/RadioButton.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.RadioButton { id: control diff --git a/src/imports/controls/material/RadioDelegate.qml b/src/imports/controls/material/RadioDelegate.qml index fb4f33dc..7b163ea8 100644 --- a/src/imports/controls/material/RadioDelegate.qml +++ b/src/imports/controls/material/RadioDelegate.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.RadioDelegate { id: control @@ -54,23 +56,29 @@ T.RadioDelegate { bottomPadding: 8 spacing: 16 + icon.width: 24 + icon.height: 24 + icon.color: enabled ? Material.foreground : Material.hintTextColor + indicator: RadioIndicator { x: text ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 control: control } - contentItem: Text { + contentItem: IconLabel { leftPadding: !control.mirrored ? 0 : control.indicator.width + control.spacing rightPadding: control.mirrored ? 0 : control.indicator.width + control.spacing + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + + icon: control.icon text: control.text font: control.font color: control.enabled ? control.Material.foreground : control.Material.hintTextColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } background: Rectangle { diff --git a/src/imports/controls/material/RadioIndicator.qml b/src/imports/controls/material/RadioIndicator.qml index 82b01ad3..2da77446 100644 --- a/src/imports/controls/material/RadioIndicator.qml +++ b/src/imports/controls/material/RadioIndicator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 Rectangle { implicitWidth: 20 diff --git a/src/imports/controls/material/RangeSlider.qml b/src/imports/controls/material/RangeSlider.qml index 0b38ad6d..6e631843 100644 --- a/src/imports/controls/material/RangeSlider.qml +++ b/src/imports/controls/material/RangeSlider.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.RangeSlider { id: control @@ -52,8 +52,8 @@ T.RangeSlider { padding: 6 first.handle: SliderHandle { - x: control.leftPadding + (horizontal ? control.first.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : control.first.visualPosition * (control.availableHeight - height)) + x: control.leftPadding + (control.horizontal ? control.first.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.first.visualPosition * (control.availableHeight - height)) value: first.value handleHasFocus: activeFocus handlePressed: first.pressed @@ -61,8 +61,8 @@ T.RangeSlider { } second.handle: SliderHandle { - x: control.leftPadding + (horizontal ? control.second.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : control.second.visualPosition * (control.availableHeight - height)) + x: control.leftPadding + (control.horizontal ? control.second.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.second.visualPosition * (control.availableHeight - height)) value: second.value handleHasFocus: activeFocus handlePressed: second.pressed @@ -70,22 +70,20 @@ T.RangeSlider { } background: Rectangle { - x: control.leftPadding + (horizontal ? 0 : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : 0) - implicitWidth: horizontal ? 200 : 48 - implicitHeight: horizontal ? 48 : 200 - width: horizontal ? control.availableWidth : 1 - height: horizontal ? 1 : control.availableHeight + x: control.leftPadding + (control.horizontal ? 0 : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : 0) + implicitWidth: control.horizontal ? 200 : 48 + implicitHeight: control.horizontal ? 48 : 200 + width: control.horizontal ? control.availableWidth : 1 + height: control.horizontal ? 1 : control.availableHeight color: control.Material.foreground - scale: horizontal && control.mirrored ? -1 : 1 - - readonly property bool horizontal: control.orientation === Qt.Horizontal + scale:control.horizontal && control.mirrored ? -1 : 1 Rectangle { - x: parent.horizontal ? control.first.position * parent.width : -1 - y: parent.horizontal ? -1 : control.second.visualPosition * parent.height + 3 - width: parent.horizontal ? control.second.position * parent.width - control.first.position * parent.width - 3 : 3 - height: parent.horizontal ? 3 : control.second.position * parent.height - control.first.position * parent.height - 3 + x: control.horizontal ? control.first.position * parent.width : -1 + y: control.horizontal ? -1 : control.second.visualPosition * parent.height + 3 + width: control.horizontal ? control.second.position * parent.width - control.first.position * parent.width - 3 : 3 + height: control.horizontal ? 3 : control.second.position * parent.height - control.first.position * parent.height - 3 color: control.Material.accentColor } diff --git a/src/imports/controls/material/RoundButton.qml b/src/imports/controls/material/RoundButton.qml index 9660a1e4..f36ef614 100644 --- a/src/imports/controls/material/RoundButton.qml +++ b/src/imports/controls/material/RoundButton.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.RoundButton { id: control @@ -50,20 +52,29 @@ T.RoundButton { // external vertical padding is 6 (to increase touch area) padding: 12 + spacing: 6 + + icon.width: 24 + icon.height: 24 + icon.color: !enabled ? Material.hintTextColor : + flat && highlighted ? Material.accentColor : + highlighted ? Material.primaryHighlightedTextColor : Material.foreground Material.elevation: flat ? control.down || control.hovered ? 2 : 0 : control.down ? 12 : 6 Material.background: flat ? "transparent" : undefined - contentItem: Text { + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font color: !control.enabled ? control.Material.hintTextColor : control.flat && control.highlighted ? control.Material.accentColor : control.highlighted ? control.Material.primaryHighlightedTextColor : control.Material.foreground - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - elide: Text.ElideRight } // TODO: Add a proper ripple/ink effect for mouse/touch input and focus state diff --git a/src/imports/controls/material/ScrollBar.qml b/src/imports/controls/material/ScrollBar.qml index 156c5781..1b014b87 100644 --- a/src/imports/controls/material/ScrollBar.qml +++ b/src/imports/controls/material/ScrollBar.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 T.ScrollBar { id: control diff --git a/src/imports/controls/material/ScrollIndicator.qml b/src/imports/controls/material/ScrollIndicator.qml index effb18ad..38bb5a65 100644 --- a/src/imports/controls/material/ScrollIndicator.qml +++ b/src/imports/controls/material/ScrollIndicator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 T.ScrollIndicator { id: control diff --git a/src/imports/controls/material/Slider.qml b/src/imports/controls/material/Slider.qml index cb60dba6..f7bdfeb1 100644 --- a/src/imports/controls/material/Slider.qml +++ b/src/imports/controls/material/Slider.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.Slider { id: control @@ -50,8 +50,8 @@ T.Slider { padding: 6 handle: SliderHandle { - x: control.leftPadding + (horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : control.visualPosition * (control.availableHeight - height)) + x: control.leftPadding + (control.horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.visualPosition * (control.availableHeight - height)) value: control.value handleHasFocus: control.visualFocus handlePressed: control.pressed @@ -59,22 +59,20 @@ T.Slider { } background: Rectangle { - x: control.leftPadding + (horizontal ? 0 : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : 0) - implicitWidth: horizontal ? 200 : 48 - implicitHeight: horizontal ? 48 : 200 - width: horizontal ? control.availableWidth : 1 - height: horizontal ? 1 : control.availableHeight + x: control.leftPadding + (control.horizontal ? 0 : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : 0) + implicitWidth: control.horizontal ? 200 : 48 + implicitHeight: control.horizontal ? 48 : 200 + width: control.horizontal ? control.availableWidth : 1 + height: control.horizontal ? 1 : control.availableHeight color: control.Material.foreground - scale: horizontal && control.mirrored ? -1 : 1 - - readonly property bool horizontal: control.orientation === Qt.Horizontal + scale: control.horizontal && control.mirrored ? -1 : 1 Rectangle { - x: parent.horizontal ? 0 : (parent.width - width) / 2 - y: parent.horizontal ? (parent.height - height) / 2 : control.visualPosition * parent.height - width: parent.horizontal ? control.position * parent.width : 3 - height: parent.horizontal ? 3 : control.position * parent.height + x: control.horizontal ? 0 : (parent.width - width) / 2 + y: control.horizontal ? (parent.height - height) / 2 : control.visualPosition * parent.height + width: control.horizontal ? control.position * parent.width : 3 + height: control.horizontal ? 3 : control.position * parent.height color: control.Material.accentColor } diff --git a/src/imports/controls/material/SliderHandle.qml b/src/imports/controls/material/SliderHandle.qml index dd4de4a2..7ab4b1a2 100644 --- a/src/imports/controls/material/SliderHandle.qml +++ b/src/imports/controls/material/SliderHandle.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 Item { id: root @@ -48,7 +48,6 @@ Item { property bool handlePressed: false property bool handleHovered: false readonly property int initialSize: 13 - readonly property bool horizontal: control.orientation === Qt.Horizontal readonly property var control: parent Rectangle { diff --git a/src/imports/controls/material/SpinBox.qml b/src/imports/controls/material/SpinBox.qml index f0dfba08..816dcb14 100644 --- a/src/imports/controls/material/SpinBox.qml +++ b/src/imports/controls/material/SpinBox.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.SpinBox { id: control diff --git a/src/imports/controls/material/StackView.qml b/src/imports/controls/material/StackView.qml index 03cd384d..6cc5634a 100644 --- a/src/imports/controls/material/StackView.qml +++ b/src/imports/controls/material/StackView.qml @@ -35,7 +35,7 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T +import QtQuick.Templates 2.3 as T T.StackView { id: control diff --git a/src/imports/controls/material/SwipeDelegate.qml b/src/imports/controls/material/SwipeDelegate.qml index d9014fcd..08f07e1f 100644 --- a/src/imports/controls/material/SwipeDelegate.qml +++ b/src/imports/controls/material/SwipeDelegate.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.SwipeDelegate { id: control @@ -54,19 +56,22 @@ T.SwipeDelegate { bottomPadding: 8 spacing: 16 + icon.width: 24 + icon.height: 24 + icon.color: enabled ? Material.foreground : Material.hintTextColor + swipe.transition: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } - contentItem: Text { - leftPadding: !control.mirrored ? (control.indicator ? control.indicator.width + control.spacing : 0) : 0 - rightPadding: control.mirrored ? (control.indicator ? control.indicator.width + control.spacing : 0) : 0 + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + icon: control.icon text: control.text font: control.font color: control.enabled ? control.Material.foreground : control.Material.hintTextColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } background: Rectangle { diff --git a/src/imports/controls/material/SwipeView.qml b/src/imports/controls/material/SwipeView.qml index 293cce46..26a1de0b 100644 --- a/src/imports/controls/material/SwipeView.qml +++ b/src/imports/controls/material/SwipeView.qml @@ -35,7 +35,7 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T +import QtQuick.Templates 2.3 as T T.SwipeView { id: control diff --git a/src/imports/controls/material/Switch.qml b/src/imports/controls/material/Switch.qml index c4f279ee..7207c940 100644 --- a/src/imports/controls/material/Switch.qml +++ b/src/imports/controls/material/Switch.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 -import QtQuick.Templates 2.2 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 +import QtQuick.Templates 2.3 as T T.Switch { id: control diff --git a/src/imports/controls/material/SwitchDelegate.qml b/src/imports/controls/material/SwitchDelegate.qml index 717ee250..f96a67ac 100644 --- a/src/imports/controls/material/SwitchDelegate.qml +++ b/src/imports/controls/material/SwitchDelegate.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.SwitchDelegate { id: control @@ -54,23 +56,29 @@ T.SwitchDelegate { bottomPadding: 8 spacing: 16 + icon.width: 24 + icon.height: 24 + icon.color: enabled ? Material.foreground : Material.hintTextColor + indicator: SwitchIndicator { x: text ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 control: control } - contentItem: Text { + contentItem: IconLabel { leftPadding: !control.mirrored ? 0 : control.indicator.width + control.spacing rightPadding: control.mirrored ? 0 : control.indicator.width + control.spacing + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + + icon: control.icon text: control.text font: control.font color: control.enabled ? control.Material.foreground : control.Material.hintTextColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } background: Rectangle { diff --git a/src/imports/controls/material/SwitchIndicator.qml b/src/imports/controls/material/SwitchIndicator.qml index 0ac7aee3..5a1cf868 100644 --- a/src/imports/controls/material/SwitchIndicator.qml +++ b/src/imports/controls/material/SwitchIndicator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 Item { id: indicator diff --git a/src/imports/controls/material/TabBar.qml b/src/imports/controls/material/TabBar.qml index db076447..dcdda818 100644 --- a/src/imports/controls/material/TabBar.qml +++ b/src/imports/controls/material/TabBar.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.TabBar { id: control @@ -48,7 +48,6 @@ T.TabBar { contentHeight + topPadding + bottomPadding) spacing: 1 - contentHeight: 48 contentItem: ListView { model: control.contentModel diff --git a/src/imports/controls/material/TabButton.qml b/src/imports/controls/material/TabButton.qml index d83fc441..96546d3f 100644 --- a/src/imports/controls/material/TabButton.qml +++ b/src/imports/controls/material/TabButton.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.TabButton { id: control @@ -49,14 +51,21 @@ T.TabButton { baselineOffset: contentItem.y + contentItem.baselineOffset padding: 12 + spacing: 6 - contentItem: Text { + icon.width: 24 + icon.height: 24 + icon.color: !enabled ? Material.hintTextColor : down || checked ? Material.accentColor : Material.foreground + + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font - elide: Text.ElideRight color: !control.enabled ? control.Material.hintTextColor : control.down || control.checked ? control.Material.accentColor : control.Material.foreground - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter } background: Ripple { diff --git a/src/imports/controls/material/TextArea.qml b/src/imports/controls/material/TextArea.qml index 34c633b6..989341e9 100644 --- a/src/imports/controls/material/TextArea.qml +++ b/src/imports/controls/material/TextArea.qml @@ -35,11 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.TextArea { id: control diff --git a/src/imports/controls/material/TextField.qml b/src/imports/controls/material/TextField.qml index f5c77f86..9f18afef 100644 --- a/src/imports/controls/material/TextField.qml +++ b/src/imports/controls/material/TextField.qml @@ -35,11 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.TextField { id: control diff --git a/src/imports/controls/material/ToolBar.qml b/src/imports/controls/material/ToolBar.qml index 228a2692..c8c1b6b6 100644 --- a/src/imports/controls/material/ToolBar.qml +++ b/src/imports/controls/material/ToolBar.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.ToolBar { id: control diff --git a/src/imports/controls/material/ToolButton.qml b/src/imports/controls/material/ToolButton.qml index eaff0b1c..158aea1b 100644 --- a/src/imports/controls/material/ToolButton.qml +++ b/src/imports/controls/material/ToolButton.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 -import QtQuick.Controls.Material.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Material.impl 2.3 T.ToolButton { id: control @@ -49,15 +51,22 @@ T.ToolButton { baselineOffset: contentItem.y + contentItem.baselineOffset padding: 6 + spacing: 6 - contentItem: Text { + icon.width: 24 + icon.height: 24 + icon.color: !enabled ? Material.hintTextColor : checked || highlighted ? Material.accent : Material.foreground + + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font color: !control.enabled ? control.Material.hintTextColor : control.checked || control.highlighted ? control.Material.accent : control.Material.foreground - elide: Text.ElideRight - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter } background: Ripple { diff --git a/src/imports/controls/material/ToolSeparator.qml b/src/imports/controls/material/ToolSeparator.qml index 808ddf4f..f8a5d9bb 100644 --- a/src/imports/controls/material/ToolSeparator.qml +++ b/src/imports/controls/material/ToolSeparator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 T.ToolSeparator { id: control diff --git a/src/imports/controls/material/ToolTip.qml b/src/imports/controls/material/ToolTip.qml index a1c2b0ef..13a35701 100644 --- a/src/imports/controls/material/ToolTip.qml +++ b/src/imports/controls/material/ToolTip.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 T.ToolTip { id: control diff --git a/src/imports/controls/material/Tumbler.qml b/src/imports/controls/material/Tumbler.qml index 9b1309ab..a0334488 100644 --- a/src/imports/controls/material/Tumbler.qml +++ b/src/imports/controls/material/Tumbler.qml @@ -35,10 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Material 2.2 +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Material 2.3 T.Tumbler { id: control diff --git a/src/imports/controls/material/material.pro b/src/imports/controls/material/material.pro index 72e937f3..08d5e3ab 100644 --- a/src/imports/controls/material/material.pro +++ b/src/imports/controls/material/material.pro @@ -1,6 +1,6 @@ TARGET = qtquickcontrols2materialstyleplugin TARGETPATH = QtQuick/Controls.2/Material -IMPORT_VERSION = 2.2 +IMPORT_VERSION = 2.3 QT += qml quick QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private diff --git a/src/imports/controls/material/qmldir b/src/imports/controls/material/qmldir index 839ca3af..a5bae170 100644 --- a/src/imports/controls/material/qmldir +++ b/src/imports/controls/material/qmldir @@ -1,4 +1,4 @@ module QtQuick.Controls.Material plugin qtquickcontrols2materialstyleplugin classname QtQuickControls2MaterialStylePlugin -depends QtQuick.Controls 2.2 +depends QtQuick.Controls 2.3 diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp index eeadb5f3..08d88ec7 100644 --- a/src/imports/controls/material/qquickmaterialstyle.cpp +++ b/src/imports/controls/material/qquickmaterialstyle.cpp @@ -39,7 +39,7 @@ #include <QtCore/qdebug.h> #include <QtCore/qsettings.h> #include <QtQml/qqmlinfo.h> -#include <QtQuickControls2/private/qquickstyleattached_p.h> +#include <QtQuickControls2/private/qquickstyle_p.h> QT_BEGIN_NAMESPACE @@ -419,16 +419,14 @@ static const QRgb rippleColorDark = 0x20FFFFFF; static const QRgb spinBoxDisabledIconColorLight = 0xFFCCCCCC; static const QRgb spinBoxDisabledIconColorDark = 0xFF666666; -extern bool qt_is_dark_system_theme(); - static QQuickMaterialStyle::Theme effectiveTheme(QQuickMaterialStyle::Theme theme) { if (theme == QQuickMaterialStyle::System) - theme = qt_is_dark_system_theme() ? QQuickMaterialStyle::Dark : QQuickMaterialStyle::Light; + theme = QQuickStylePrivate::isDarkSystemTheme() ? QQuickMaterialStyle::Dark : QQuickMaterialStyle::Light; return theme; } -QQuickMaterialStyle::QQuickMaterialStyle(QObject *parent) : QQuickStyleAttached(parent), +QQuickMaterialStyle::QQuickMaterialStyle(QObject *parent) : QQuickAttachedObject(parent), m_explicitTheme(false), m_explicitPrimary(false), m_explicitAccent(false), @@ -463,7 +461,7 @@ QQuickMaterialStyle::Theme QQuickMaterialStyle::theme() const void QQuickMaterialStyle::setTheme(Theme theme) { if (theme == System) - theme = qt_is_dark_system_theme() ? Dark : Light; + theme = QQuickStylePrivate::isDarkSystemTheme() ? Dark : Light; m_explicitTheme = true; if (m_theme == theme) @@ -500,8 +498,8 @@ void QQuickMaterialStyle::inheritTheme(Theme theme) void QQuickMaterialStyle::propagateTheme() { - const auto styles = childStyles(); - for (QQuickStyleAttached *child : styles) { + const auto styles = attachedChildren(); + for (QQuickAttachedObject *child : styles) { QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child); if (material) material->inheritTheme(m_theme); @@ -514,7 +512,7 @@ void QQuickMaterialStyle::resetTheme() return; m_explicitTheme = false; - QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(parentStyle()); + QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent()); inheritTheme(material ? material->theme() : globalTheme); } @@ -555,8 +553,8 @@ void QQuickMaterialStyle::inheritPrimary(uint primary, bool custom) void QQuickMaterialStyle::propagatePrimary() { - const auto styles = childStyles(); - for (QQuickStyleAttached *child : styles) { + const auto styles = attachedChildren(); + for (QQuickAttachedObject *child : styles) { QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child); if (material) material->inheritPrimary(m_primary, m_customPrimary); @@ -570,7 +568,7 @@ void QQuickMaterialStyle::resetPrimary() m_customPrimary = false; m_explicitPrimary = false; - QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(parentStyle()); + QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent()); if (material) inheritPrimary(material->m_primary, material->m_customPrimary); else @@ -614,8 +612,8 @@ void QQuickMaterialStyle::inheritAccent(uint accent, bool custom) void QQuickMaterialStyle::propagateAccent() { - const auto styles = childStyles(); - for (QQuickStyleAttached *child : styles) { + const auto styles = attachedChildren(); + for (QQuickAttachedObject *child : styles) { QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child); if (material) material->inheritAccent(m_accent, m_customAccent); @@ -629,7 +627,7 @@ void QQuickMaterialStyle::resetAccent() m_customAccent = false; m_explicitAccent = false; - QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(parentStyle()); + QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent()); if (material) inheritAccent(material->m_accent, material->m_customAccent); else @@ -679,8 +677,8 @@ void QQuickMaterialStyle::inheritForeground(uint foreground, bool custom, bool h void QQuickMaterialStyle::propagateForeground() { - const auto styles = childStyles(); - for (QQuickStyleAttached *child : styles) { + const auto styles = attachedChildren(); + for (QQuickAttachedObject *child : styles) { QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child); if (material) material->inheritForeground(m_foreground, m_customForeground, m_hasForeground); @@ -695,7 +693,7 @@ void QQuickMaterialStyle::resetForeground() m_hasForeground = false; m_customForeground = false; m_explicitForeground = false; - QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(parentStyle()); + QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent()); inheritForeground(material ? material->m_foreground : globalForeground, true, material ? material->m_hasForeground : false); } @@ -738,8 +736,8 @@ void QQuickMaterialStyle::inheritBackground(uint background, bool custom, bool h void QQuickMaterialStyle::propagateBackground() { - const auto styles = childStyles(); - for (QQuickStyleAttached *child : styles) { + const auto styles = attachedChildren(); + for (QQuickAttachedObject *child : styles) { QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(child); if (material) material->inheritBackground(m_background, m_customBackground, m_hasBackground); @@ -754,7 +752,7 @@ void QQuickMaterialStyle::resetBackground() m_hasBackground = false; m_customBackground = false; m_explicitBackground = false; - QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(parentStyle()); + QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(attachedParent()); inheritBackground(material ? material->m_background : globalBackground, true, material ? material->m_hasBackground : false); } @@ -1137,7 +1135,7 @@ QColor QQuickMaterialStyle::shade(const QColor &color, Shade shade) const } } -void QQuickMaterialStyle::parentStyleChange(QQuickStyleAttached *newParent, QQuickStyleAttached *oldParent) +void QQuickMaterialStyle::attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) { Q_UNUSED(oldParent); QQuickMaterialStyle *material = qobject_cast<QQuickMaterialStyle *>(newParent); @@ -1171,7 +1169,7 @@ void QQuickMaterialStyle::init() { static bool globalsInitialized = false; if (!globalsInitialized) { - QSharedPointer<QSettings> settings = QQuickStyleAttached::settings(QStringLiteral("Material")); + QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(QStringLiteral("Material")); bool ok = false; QByteArray themeValue = resolveSetting("QT_QUICK_CONTROLS_MATERIAL_THEME", settings, QStringLiteral("Theme")); @@ -1248,7 +1246,7 @@ void QQuickMaterialStyle::init() globalsInitialized = true; } - QQuickStyleAttached::init(); // TODO: lazy init? + QQuickAttachedObject::init(); // TODO: lazy init? } bool QQuickMaterialStyle::variantToRgba(const QVariant &var, const char *name, QRgb *rgba, bool *custom) const diff --git a/src/imports/controls/material/qquickmaterialstyle_p.h b/src/imports/controls/material/qquickmaterialstyle_p.h index bb494697..2374eefb 100644 --- a/src/imports/controls/material/qquickmaterialstyle_p.h +++ b/src/imports/controls/material/qquickmaterialstyle_p.h @@ -49,11 +49,11 @@ // #include <QtGui/qcolor.h> -#include <QtQuickControls2/private/qquickstyleattached_p.h> +#include <QtQuickControls2/private/qquickattachedobject_p.h> QT_BEGIN_NAMESPACE -class QQuickMaterialStyle : public QQuickStyleAttached +class QQuickMaterialStyle : public QQuickAttachedObject { Q_OBJECT Q_PROPERTY(Theme theme READ theme WRITE setTheme RESET resetTheme NOTIFY themeChanged FINAL) @@ -236,7 +236,7 @@ Q_SIGNALS: void paletteChanged(); protected: - void parentStyleChange(QQuickStyleAttached *newParent, QQuickStyleAttached *oldParent) override; + void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) override; private: void init(); diff --git a/src/imports/controls/material/qquickmaterialtheme.cpp b/src/imports/controls/material/qquickmaterialtheme.cpp index 3ea41779..f75fa8a5 100644 --- a/src/imports/controls/material/qquickmaterialtheme.cpp +++ b/src/imports/controls/material/qquickmaterialtheme.cpp @@ -110,14 +110,7 @@ QVariant QQuickMaterialTheme::themeHint(ThemeHint hint) const { switch (hint) { case QPlatformTheme::DialogButtonBoxLayout: - // https://material.io/guidelines/components/dialogs.html#dialogs-specs - // As per spec, affirmative actions are placed to the right, dismissive - // actions are placed directly to the left of affirmative actions. - // In the Android sources, there are additional type of actions - - // neutral, which are placed to the left. - // Rules for macOS seems to be the most suitable here and are also used - // in the Android QPA plugin. - return QVariant(QPlatformDialogHelper::MacLayout); + return QVariant(QPlatformDialogHelper::AndroidLayout); default: return QQuickProxyTheme::themeHint(hint); } diff --git a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp index 3f3a66b0..7eae0826 100644 --- a/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp +++ b/src/imports/controls/material/qtquickcontrols2materialstyleplugin.cpp @@ -44,7 +44,6 @@ #include <QtQuickControls2/private/qquickstyleselector_p.h> #include <QtQuickControls2/private/qquickpaddedrectangle_p.h> -#include <QtQuickControls2/private/qquickcolorimageprovider_p.h> static inline void initResources() { @@ -86,12 +85,9 @@ void QtQuickControls2MaterialStylePlugin::initializeEngine(QQmlEngine *engine, c { QQuickStylePlugin::initializeEngine(engine, uri); - engine->addImageProvider(name(), new QQuickColorImageProvider(QStringLiteral(":/qt-project.org/imports/QtQuick/Controls.2/Material/images"))); - QByteArray import = QByteArray(uri) + ".impl"; qmlRegisterModule(import, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2... - qmlRegisterType<QQuickPaddedRectangle>(import, 2, 0, "PaddedRectangle"); qmlRegisterType<QQuickMaterialBusyIndicator>(import, 2, 0, "BusyIndicatorImpl"); qmlRegisterType<QQuickMaterialProgressBar>(import, 2, 0, "ProgressBarImpl"); qmlRegisterType<QQuickMaterialRipple>(import, 2, 0, "Ripple"); diff --git a/src/imports/controls/plugins.qmltypes b/src/imports/controls/plugins.qmltypes index 1e1b9d0f..e10c187a 100644 --- a/src/imports/controls/plugins.qmltypes +++ b/src/imports/controls/plugins.qmltypes @@ -4,20 +4,53 @@ import QtQuick.tooling 1.2 // It is used for QML tooling purposes only. // // This file was auto-generated by: -// 'qmlplugindump -nonrelocatable QtQuick.Controls 2.2 -merge ../templates/plugins.qmltypes -dependencies dependencies.json' +// 'qmlplugindump -nonrelocatable QtQuick.Controls 2.3 -merge ../templates/plugins.qmltypes -dependencies dependencies.json' Module { dependencies: [ "QtQuick 2.9", - "QtQuick.Templates 2.2", + "QtQuick.Templates 2.3", "QtQuick.Window 2.2" ] Component { + name: "QQuickColor" + prototype: "QObject" + exports: ["QtQuick.Controls.impl/Color 2.3"] + isCreatable: false + isSingleton: true + exportMetaObjectRevisions: [0] + Method { + name: "transparent" + type: "QColor" + Parameter { name: "color"; type: "QColor" } + Parameter { name: "opacity"; type: "double" } + } + } + Component { + name: "QQuickColorImage" + defaultProperty: "data" + prototype: "QQuickImage" + exports: ["QtQuick.Controls.impl/ColorImage 2.3"] + exportMetaObjectRevisions: [0] + Property { name: "color"; type: "QColor" } + } + Component { name: "QQuickDefaultBusyIndicator" defaultProperty: "data" prototype: "QQuickItem" exports: ["QtQuick.Controls.impl/BusyIndicatorImpl 2.0"] exportMetaObjectRevisions: [0] + Property { name: "pen"; type: "QColor" } + Property { name: "fill"; type: "QColor" } + } + Component { + name: "QQuickDefaultDial" + defaultProperty: "data" + prototype: "QQuickPaintedItem" + exports: ["QtQuick.Controls.impl/DialImpl 2.0"] + exportMetaObjectRevisions: [0] + Property { name: "progress"; type: "double" } + Property { name: "color"; type: "QColor" } } Component { name: "QQuickDefaultProgressBar" @@ -27,6 +60,7 @@ Module { exportMetaObjectRevisions: [0] Property { name: "indeterminate"; type: "bool" } Property { name: "progress"; type: "double" } + Property { name: "color"; type: "QColor" } } Component { name: "QQuickDefaultStyle" @@ -76,13 +110,41 @@ Module { Property { name: "disabledLightColor"; type: "QColor"; isReadonly: true } } Component { - name: "QQuickDialRing" + name: "QQuickIconImage" defaultProperty: "data" - prototype: "QQuickPaintedItem" - exports: ["QtQuick.Controls.impl/DialRing 2.0"] + prototype: "QQuickImage" + exports: ["QtQuick.Controls.impl/IconImage 2.3"] exportMetaObjectRevisions: [0] - Property { name: "progress"; type: "double" } + Property { name: "name"; type: "string" } + Property { name: "color"; type: "QColor" } + } + Component { + name: "QQuickIconLabel" + defaultProperty: "data" + prototype: "QQuickItem" + exports: ["QtQuick.Controls.impl/IconLabel 2.3"] + exportMetaObjectRevisions: [0] + Enum { + name: "Display" + values: { + "IconOnly": 0, + "TextOnly": 1, + "TextBesideIcon": 2, + "TextUnderIcon": 3 + } + } + Property { name: "icon"; type: "QQuickIcon"; isPointer: true } + Property { name: "text"; type: "string" } + Property { name: "font"; type: "QFont" } Property { name: "color"; type: "QColor" } + Property { name: "display"; type: "Display" } + Property { name: "spacing"; type: "double" } + Property { name: "mirrored"; type: "bool" } + Property { name: "alignment"; type: "Qt::Alignment" } + Property { name: "topPadding"; type: "double" } + Property { name: "leftPadding"; type: "double" } + Property { name: "rightPadding"; type: "double" } + Property { name: "bottomPadding"; type: "double" } } Component { name: "QQuickPlaceholderText" @@ -537,6 +599,9 @@ Module { Property { name: "checkable"; type: "bool" } Property { name: "autoExclusive"; type: "bool" } Property { name: "indicator"; type: "QQuickItem"; isPointer: true } + Property { name: "icon"; revision: 3; type: "QQuickIcon"; isReadonly: true; isPointer: true } + Property { name: "display"; revision: 3; type: "Display" } + Property { name: "action"; revision: 3; type: "QQuickAction"; isPointer: true } Signal { name: "pressed" } Signal { name: "released" } Signal { name: "canceled" } @@ -544,7 +609,89 @@ Module { Signal { name: "toggled"; revision: 2 } Signal { name: "pressAndHold" } Signal { name: "doubleClicked" } + Signal { name: "displayChanged"; revision: 3 } + Signal { name: "actionChanged"; revision: 3 } + Method { name: "toggle" } + } + Component { + name: "QQuickAction" + prototype: "QObject" + exports: ["QtQuick.Templates/Action 2.3"] + exportMetaObjectRevisions: [0] + Property { name: "text"; type: "string" } + Property { name: "icon"; type: "QQuickIcon"; isReadonly: true; isPointer: true } + Property { name: "enabled"; type: "bool" } + Property { name: "checked"; type: "bool" } + Property { name: "checkable"; type: "bool" } + Property { name: "shortcut"; type: "QVariant" } + Signal { + name: "textChanged" + Parameter { name: "text"; type: "string" } + } + Signal { + name: "enabledChanged" + Parameter { name: "enabled"; type: "bool" } + } + Signal { + name: "checkedChanged" + Parameter { name: "checked"; type: "bool" } + } + Signal { + name: "checkableChanged" + Parameter { name: "checkable"; type: "bool" } + } + Signal { + name: "shortcutChanged" + Parameter { name: "shortcut"; type: "QKeySequence" } + } + Signal { + name: "toggled" + Parameter { name: "source"; type: "QObject"; isPointer: true } + } + Signal { name: "toggled" } + Signal { + name: "triggered" + Parameter { name: "source"; type: "QObject"; isPointer: true } + } + Signal { name: "triggered" } + Method { + name: "toggle" + Parameter { name: "source"; type: "QObject"; isPointer: true } + } Method { name: "toggle" } + Method { + name: "trigger" + Parameter { name: "source"; type: "QObject"; isPointer: true } + } + Method { name: "trigger" } + } + Component { + name: "QQuickActionGroup" + prototype: "QObject" + exports: ["QtQuick.Templates/ActionGroup 2.3"] + exportMetaObjectRevisions: [0] + attachedType: "QQuickActionGroupAttached" + Property { name: "checkedAction"; type: "QQuickAction"; isPointer: true } + Property { name: "actions"; type: "QQuickAction"; isList: true; isReadonly: true } + Property { name: "exclusive"; type: "bool" } + Property { name: "enabled"; type: "bool" } + Signal { + name: "triggered" + Parameter { name: "action"; type: "QQuickAction"; isPointer: true } + } + Method { + name: "addAction" + Parameter { name: "action"; type: "QQuickAction"; isPointer: true } + } + Method { + name: "removeAction" + Parameter { name: "action"; type: "QQuickAction"; isPointer: true } + } + } + Component { + name: "QQuickActionGroupAttached" + prototype: "QObject" + Property { name: "group"; type: "QQuickActionGroup"; isPointer: true } } Component { name: "QQuickApplicationWindow" @@ -902,6 +1049,35 @@ Module { Property { name: "label"; type: "QQuickItem"; isPointer: true } } Component { + name: "QQuickIcon" + prototype: "QObject" + Property { name: "name"; type: "string" } + Property { name: "source"; type: "string" } + Property { name: "width"; type: "int" } + Property { name: "height"; type: "int" } + Property { name: "color"; type: "QColor" } + Signal { + name: "nameChanged" + Parameter { name: "name"; type: "string" } + } + Signal { + name: "sourceChanged" + Parameter { name: "source"; type: "string" } + } + Signal { + name: "widthChanged" + Parameter { name: "width"; type: "int" } + } + Signal { + name: "heightChanged" + Parameter { name: "height"; type: "int" } + } + Signal { + name: "colorChanged" + Parameter { name: "color"; type: "QColor" } + } + } + Component { name: "QQuickItemDelegate" defaultProperty: "data" prototype: "QQuickAbstractButton" @@ -1140,9 +1316,10 @@ Module { exports: [ "QtQuick.Templates/RangeSlider 2.0", "QtQuick.Templates/RangeSlider 2.1", - "QtQuick.Templates/RangeSlider 2.2" + "QtQuick.Templates/RangeSlider 2.2", + "QtQuick.Templates/RangeSlider 2.3" ] - exportMetaObjectRevisions: [0, 1, 2] + exportMetaObjectRevisions: [0, 1, 2, 3] Enum { name: "SnapMode" values: { @@ -1158,6 +1335,8 @@ Module { Property { name: "stepSize"; type: "double" } Property { name: "snapMode"; type: "SnapMode" } Property { name: "orientation"; type: "Qt::Orientation" } + Property { name: "horizontal"; revision: 3; type: "bool"; isReadonly: true } + Property { name: "vertical"; revision: 3; type: "bool"; isReadonly: true } Property { name: "live"; revision: 2; type: "bool" } Signal { name: "liveChanged"; revision: 2 } Method { @@ -1193,9 +1372,10 @@ Module { prototype: "QQuickControl" exports: [ "QtQuick.Templates/ScrollBar 2.0", - "QtQuick.Templates/ScrollBar 2.2" + "QtQuick.Templates/ScrollBar 2.2", + "QtQuick.Templates/ScrollBar 2.3" ] - exportMetaObjectRevisions: [0, 2] + exportMetaObjectRevisions: [0, 2, 3] attachedType: "QQuickScrollBarAttached" Enum { name: "SnapMode" @@ -1222,6 +1402,8 @@ Module { Property { name: "snapMode"; revision: 2; type: "SnapMode" } Property { name: "interactive"; revision: 2; type: "bool" } Property { name: "policy"; revision: 2; type: "Policy" } + Property { name: "horizontal"; revision: 3; type: "bool"; isReadonly: true } + Property { name: "vertical"; revision: 3; type: "bool"; isReadonly: true } Signal { name: "snapModeChanged"; revision: 2 } Signal { name: "interactiveChanged"; revision: 2 } Signal { name: "policyChanged"; revision: 2 } @@ -1246,13 +1428,18 @@ Module { name: "QQuickScrollIndicator" defaultProperty: "data" prototype: "QQuickControl" - exports: ["QtQuick.Templates/ScrollIndicator 2.0"] - exportMetaObjectRevisions: [0] + exports: [ + "QtQuick.Templates/ScrollIndicator 2.0", + "QtQuick.Templates/ScrollIndicator 2.3" + ] + exportMetaObjectRevisions: [0, 3] attachedType: "QQuickScrollIndicatorAttached" Property { name: "size"; type: "double" } Property { name: "position"; type: "double" } Property { name: "active"; type: "bool" } Property { name: "orientation"; type: "Qt::Orientation" } + Property { name: "horizontal"; revision: 3; type: "bool"; isReadonly: true } + Property { name: "vertical"; revision: 3; type: "bool"; isReadonly: true } Method { name: "setSize" Parameter { name: "size"; type: "double" } @@ -1286,9 +1473,10 @@ Module { exports: [ "QtQuick.Templates/Slider 2.0", "QtQuick.Templates/Slider 2.1", - "QtQuick.Templates/Slider 2.2" + "QtQuick.Templates/Slider 2.2", + "QtQuick.Templates/Slider 2.3" ] - exportMetaObjectRevisions: [0, 1, 2] + exportMetaObjectRevisions: [0, 1, 2, 3] Enum { name: "SnapMode" values: { @@ -1306,6 +1494,8 @@ Module { Property { name: "snapMode"; type: "SnapMode" } Property { name: "live"; revision: 2; type: "bool" } Property { name: "pressed"; type: "bool" } + Property { name: "horizontal"; revision: 3; type: "bool"; isReadonly: true } + Property { name: "vertical"; revision: 3; type: "bool"; isReadonly: true } Property { name: "orientation"; type: "Qt::Orientation" } Property { name: "handle"; type: "QQuickItem"; isPointer: true } Signal { name: "liveChanged"; revision: 2 } @@ -1512,6 +1702,8 @@ Module { attachedType: "QQuickSwipeViewAttached" Property { name: "interactive"; revision: 1; type: "bool" } Property { name: "orientation"; revision: 2; type: "Qt::Orientation" } + Property { name: "horizontal"; revision: 3; type: "bool"; isReadonly: true } + Property { name: "vertical"; revision: 3; type: "bool"; isReadonly: true } Signal { name: "interactiveChanged"; revision: 1 } Signal { name: "orientationChanged"; revision: 2 } } diff --git a/src/imports/controls/qmldir b/src/imports/controls/qmldir index 32f0d20d..9930b8d8 100644 --- a/src/imports/controls/qmldir +++ b/src/imports/controls/qmldir @@ -1,5 +1,5 @@ module QtQuick.Controls plugin qtquickcontrols2plugin classname QtQuickControls2Plugin -depends QtQuick.Templates 2.2 +depends QtQuick.Templates 2.3 designersupported diff --git a/src/imports/controls/qquickdefaultbusyindicator.cpp b/src/imports/controls/qquickdefaultbusyindicator.cpp index 315b2b8b..138e94e8 100644 --- a/src/imports/controls/qquickdefaultbusyindicator.cpp +++ b/src/imports/controls/qquickdefaultbusyindicator.cpp @@ -45,7 +45,6 @@ QT_BEGIN_NAMESPACE static const int CircleCount = 10; static const int TotalDuration = 100 * CircleCount * 2; static const QRgb TransparentColor = 0x00000000; -static const QRgb FillColor = 0xFF353637; static QPointF moveCircle(const QPointF &pos, qreal rotation, qreal distance) { @@ -59,6 +58,10 @@ public: void updateCurrentTime(int time) override; void sync(QQuickItem *item) override; + +private: + QColor m_pen; + QColor m_fill; }; QQuickDefaultBusyIndicatorNode::QQuickDefaultBusyIndicatorNode(QQuickDefaultBusyIndicator *item) @@ -92,8 +95,9 @@ void QQuickDefaultBusyIndicatorNode::updateCurrentTime(int time) Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); const bool fill = (firstPhaseProgress > qreal(i) / CircleCount) || (secondPhaseProgress > 0 && secondPhaseProgress < qreal(i) / CircleCount); - rectNode->setColor(QColor::fromRgba(fill ? FillColor : TransparentColor)); - rectNode->setPenWidth(fill ? 0 : 1); + rectNode->setColor(fill ? m_fill : QColor::fromRgba(TransparentColor)); + rectNode->setPenColor(m_pen); + rectNode->setPenWidth(1); rectNode->update(); transformNode = static_cast<QSGTransformNode*>(transformNode->nextSibling()); @@ -109,6 +113,9 @@ void QQuickDefaultBusyIndicatorNode::sync(QQuickItem *item) const qreal dy = (h - sz) / 2; const int circleRadius = sz / 12; + m_pen = static_cast<QQuickDefaultBusyIndicator *>(item)->pen(); + m_fill = static_cast<QQuickDefaultBusyIndicator *>(item)->fill(); + QSGTransformNode *transformNode = static_cast<QSGTransformNode *>(firstChild()); for (int i = 0; i < CircleCount; ++i) { Q_ASSERT(transformNode->type() == QSGNode::TransformNodeType); @@ -136,6 +143,34 @@ QQuickDefaultBusyIndicator::QQuickDefaultBusyIndicator(QQuickItem *parent) : setFlag(ItemHasContents); } +QColor QQuickDefaultBusyIndicator::pen() const +{ + return m_pen; +} + +void QQuickDefaultBusyIndicator::setPen(const QColor &pen) +{ + if (pen == m_pen) + return; + + m_pen = pen; + update(); +} + +QColor QQuickDefaultBusyIndicator::fill() const +{ + return m_fill; +} + +void QQuickDefaultBusyIndicator::setFill(const QColor &fill) +{ + if (fill == m_fill) + return; + + m_fill = fill; + update(); +} + int QQuickDefaultBusyIndicator::elapsed() const { return m_elapsed; diff --git a/src/imports/controls/qquickdefaultbusyindicator_p.h b/src/imports/controls/qquickdefaultbusyindicator_p.h index 7daeabd1..e214020c 100644 --- a/src/imports/controls/qquickdefaultbusyindicator_p.h +++ b/src/imports/controls/qquickdefaultbusyindicator_p.h @@ -55,10 +55,18 @@ QT_BEGIN_NAMESPACE class QQuickDefaultBusyIndicator : public QQuickItem { Q_OBJECT + Q_PROPERTY(QColor pen READ pen WRITE setPen FINAL) + Q_PROPERTY(QColor fill READ fill WRITE setFill FINAL) public: explicit QQuickDefaultBusyIndicator(QQuickItem *parent = nullptr); + QColor pen() const; + void setPen(const QColor &pen); + + QColor fill() const; + void setFill(const QColor &fill); + int elapsed() const; protected: @@ -67,6 +75,8 @@ protected: private: int m_elapsed; + QColor m_pen; + QColor m_fill; }; QT_END_NAMESPACE diff --git a/src/imports/controls/qquickdialring.cpp b/src/imports/controls/qquickdefaultdial.cpp index 2c6e7921..845e634d 100644 --- a/src/imports/controls/qquickdialring.cpp +++ b/src/imports/controls/qquickdefaultdial.cpp @@ -34,7 +34,7 @@ ** ****************************************************************************/ -#include "qquickdialring_p.h" +#include "qquickdefaultdial_p.h" #include <QtCore/qmath.h> #include <QtGui/qpainter.h> @@ -42,44 +42,42 @@ QT_BEGIN_NAMESPACE -QQuickDialRing::QQuickDialRing(QQuickItem *parent) : +QQuickDefaultDial::QQuickDefaultDial(QQuickItem *parent) : QQuickPaintedItem(parent), m_progress(0), m_color(Qt::black) { } -qreal QQuickDialRing::progress() const +qreal QQuickDefaultDial::progress() const { return m_progress; } -void QQuickDialRing::setProgress(qreal progress) +void QQuickDefaultDial::setProgress(qreal progress) { if (progress == m_progress) return; m_progress = progress; update(); - emit progressChanged(); } -QColor QQuickDialRing::color() const +QColor QQuickDefaultDial::color() const { return m_color; } -void QQuickDialRing::setColor(const QColor &color) +void QQuickDefaultDial::setColor(const QColor &color) { if (color == m_color) return; m_color = color; update(); - emit colorChanged(); } -void QQuickDialRing::paint(QPainter *painter) +void QQuickDefaultDial::paint(QPainter *painter) { if (width() <= 0 || height() <= 0) return; diff --git a/src/imports/controls/qquickdialring_p.h b/src/imports/controls/qquickdefaultdial_p.h index 5b2f49ba..10490610 100644 --- a/src/imports/controls/qquickdialring_p.h +++ b/src/imports/controls/qquickdefaultdial_p.h @@ -34,8 +34,8 @@ ** ****************************************************************************/ -#ifndef QQUICKDIALRING_P_H -#define QQUICKDIALRING_P_H +#ifndef QQUICKDEFAULTDIAL_P_H +#define QQUICKDEFAULTDIAL_P_H // // W A R N I N G @@ -53,14 +53,14 @@ QT_BEGIN_NAMESPACE -class QQuickDialRing : public QQuickPaintedItem +class QQuickDefaultDial : public QQuickPaintedItem { Q_OBJECT - Q_PROPERTY(qreal progress READ progress WRITE setProgress NOTIFY progressChanged) - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(qreal progress READ progress WRITE setProgress FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) public: - QQuickDialRing(QQuickItem *parent = nullptr); + explicit QQuickDefaultDial(QQuickItem *parent = nullptr); qreal progress() const; void setProgress(qreal progress); @@ -70,10 +70,6 @@ public: void paint(QPainter *painter) override; -Q_SIGNALS: - void progressChanged(); - void colorChanged(); - private: qreal m_progress; QColor m_color; @@ -81,4 +77,4 @@ private: QT_END_NAMESPACE -#endif // QQUICKDIALRING_P_H +#endif // QQUICKDEFAULTDIAL_P_H diff --git a/src/imports/controls/qquickdefaultprogressbar.cpp b/src/imports/controls/qquickdefaultprogressbar.cpp index a34b6a28..f5bd1db8 100644 --- a/src/imports/controls/qquickdefaultprogressbar.cpp +++ b/src/imports/controls/qquickdefaultprogressbar.cpp @@ -51,7 +51,6 @@ static const int BlockSpan = Blocks * (BlockWidth + BlockRestingSpacing) - Block static const int TotalDuration = 4000; static const int SecondPhaseStart = TotalDuration * 0.4; static const int ThirdPhaseStart = TotalDuration * 0.6; -static const QRgb FillColor = 0x353637; static inline qreal blockStartX(int blockIndex) { @@ -178,7 +177,7 @@ void QQuickDefaultProgressBarNode::sync(QQuickItem *item) QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode*>(transformNode->firstChild()); if (!rectNode) { rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setColor(FillColor); + rectNode->setColor(bar->color()); transformNode->appendChildNode(rectNode); } @@ -200,7 +199,7 @@ void QQuickDefaultProgressBarNode::sync(QQuickItem *item) QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(firstChild()); if (!rectNode) { rectNode = d->sceneGraphContext()->createInternalRectangleNode(); - rectNode->setColor(FillColor); + rectNode->setColor(bar->color()); appendChildNode(rectNode); } @@ -229,7 +228,6 @@ void QQuickDefaultProgressBar::setProgress(qreal progress) m_progress = progress; update(); - emit progressChanged(); } bool QQuickDefaultProgressBar::isIndeterminate() const @@ -245,7 +243,20 @@ void QQuickDefaultProgressBar::setIndeterminate(bool indeterminate) m_indeterminate = indeterminate; setClip(m_indeterminate); update(); - emit indeterminateChanged(); +} + +QColor QQuickDefaultProgressBar::color() const +{ + return m_color; +} + +void QQuickDefaultProgressBar::setColor(const QColor &color) +{ + if (color == m_color) + return; + + m_color = color; + update(); } void QQuickDefaultProgressBar::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) diff --git a/src/imports/controls/qquickdefaultprogressbar_p.h b/src/imports/controls/qquickdefaultprogressbar_p.h index 4fb9ae0b..dbdf5ad4 100644 --- a/src/imports/controls/qquickdefaultprogressbar_p.h +++ b/src/imports/controls/qquickdefaultprogressbar_p.h @@ -55,8 +55,9 @@ QT_BEGIN_NAMESPACE class QQuickDefaultProgressBar : public QQuickItem { Q_OBJECT - Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate NOTIFY indeterminateChanged FINAL) - Q_PROPERTY(qreal progress READ progress WRITE setProgress NOTIFY progressChanged FINAL) + Q_PROPERTY(bool indeterminate READ isIndeterminate WRITE setIndeterminate FINAL) + Q_PROPERTY(qreal progress READ progress WRITE setProgress FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) public: explicit QQuickDefaultProgressBar(QQuickItem *parent = nullptr); @@ -67,9 +68,8 @@ public: qreal progress() const; void setProgress(qreal progress); -Q_SIGNALS: - void progressChanged(); - void indeterminateChanged(); + QColor color() const; + void setColor(const QColor &color); protected: void itemChange(ItemChange change, const ItemChangeData &data) override; @@ -78,6 +78,7 @@ protected: private: qreal m_progress; bool m_indeterminate; + QColor m_color; }; QT_END_NAMESPACE diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index 848f55b5..3f84202e 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -36,20 +36,27 @@ #include <QtCore/private/qfileselector_p.h> #include <QtQuickControls2/qquickstyle.h> +#include <QtQuickControls2/private/qquickcolor_p.h> +#include <QtQuickControls2/private/qquickcolorimage_p.h> +#include <QtQuickControls2/private/qquickiconimage_p.h> +#include <QtQuickControls2/private/qquickpaddedrectangle_p.h> #include <QtQuickControls2/private/qquickplaceholdertext_p.h> +#include <QtQuickControls2/private/qquickiconlabel_p.h> #include <QtQuickControls2/private/qquickstyle_p.h> #include <QtQuickControls2/private/qquickstyleplugin_p.h> #include <QtQuickControls2/private/qquickstyleselector_p.h> -#include <QtQuickControls2/private/qquickcolorimageprovider_p.h> #if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview) #include <QtQuickControls2/private/qquicktumblerview_p.h> #endif +#include <QtQuickTemplates2/private/qquickaction_p.h> +#include <QtQuickTemplates2/private/qquickactiongroup_p.h> #include <QtQuickTemplates2/private/qquickbuttongroup_p.h> +#include <QtQuickTemplates2/private/qquickicon_p.h> #include "qquickdefaultbusyindicator_p.h" +#include "qquickdefaultdial_p.h" #include "qquickdefaultprogressbar_p.h" #include "qquickdefaultstyle_p.h" -#include "qquickdialring_p.h" static inline void initResources() { @@ -68,8 +75,8 @@ class QtQuickControls2Plugin: public QQuickStylePlugin public: QtQuickControls2Plugin(QObject *parent = nullptr); - void registerTypes(const char *uri); - void initializeEngine(QQmlEngine *engine, const char *uri); + void registerTypes(const char *uri) override; + void initializeEngine(QQmlEngine *engine, const char *uri) override; }; QtQuickControls2Plugin::QtQuickControls2Plugin(QObject *parent) : QQuickStylePlugin(parent) @@ -148,6 +155,12 @@ void QtQuickControls2Plugin::registerTypes(const char *uri) // QtQuick.Controls 2.2 (new types in Qt 5.9) qmlRegisterType(selector.select(QStringLiteral("DelayButton.qml")), uri, 2, 2, "DelayButton"); qmlRegisterType(selector.select(QStringLiteral("ScrollView.qml")), uri, 2, 2, "ScrollView"); + + // QtQuick.Controls 2.3 (new types in Qt 5.10) + qmlRegisterType<QQuickAction>(uri, 2, 3, "Action"); + qmlRegisterType<QQuickActionGroup>(uri, 2, 3, "ActionGroup"); + qmlRegisterType<QQuickButtonGroup, 3>(uri, 2, 3, "ButtonGroup"); + qRegisterMetaType<QQuickIcon>(); } static QObject *styleSingleton(QQmlEngine *engine, QJSEngine *scriptEngine) @@ -157,18 +170,23 @@ static QObject *styleSingleton(QQmlEngine *engine, QJSEngine *scriptEngine) return new QQuickDefaultStyle; } -void QtQuickControls2Plugin::initializeEngine(QQmlEngine *engine, const char *uri) +static QObject *colorSingleton(QQmlEngine *engine, QJSEngine *scriptEngine) { - Q_UNUSED(uri); + Q_UNUSED(engine); + Q_UNUSED(scriptEngine); + return new QQuickColor; +} - engine->addImageProvider(QStringLiteral("default"), new QQuickColorImageProvider(QStringLiteral(":/qt-project.org/imports/QtQuick/Controls.2/images"))); +void QtQuickControls2Plugin::initializeEngine(QQmlEngine *engine, const char *uri) +{ + Q_UNUSED(engine); const QByteArray import = QByteArray(uri) + ".impl"; qmlRegisterModule(import, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2... qmlRegisterType<QQuickDefaultBusyIndicator>(import, 2, 0, "BusyIndicatorImpl"); + qmlRegisterType<QQuickDefaultDial>(import, 2, 0, "DialImpl"); qmlRegisterType<QQuickDefaultProgressBar>(import, 2, 0, "ProgressBarImpl"); - qmlRegisterType<QQuickDialRing>(import, 2, 0, "DialRing"); qmlRegisterType<QQuickPlaceholderText>(import, 2, 2, "PlaceholderText"); #if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview) qmlRegisterType<QQuickTumblerView>(import, 2, 1, "TumblerView"); @@ -177,6 +195,12 @@ void QtQuickControls2Plugin::initializeEngine(QQmlEngine *engine, const char *ur qmlRegisterType(typeUrl(QStringLiteral("CheckIndicator.qml")), import, 2, 0, "CheckIndicator"); qmlRegisterType(typeUrl(QStringLiteral("RadioIndicator.qml")), import, 2, 0, "RadioIndicator"); qmlRegisterType(typeUrl(QStringLiteral("SwitchIndicator.qml")), import, 2, 0, "SwitchIndicator"); + + qmlRegisterType<QQuickColorImage>(import, 2, 3, "ColorImage"); + qmlRegisterType<QQuickIconImage>(import, 2, 3, "IconImage"); + qmlRegisterSingletonType<QQuickColor>(import, 2, 3, "Color", colorSingleton); + qmlRegisterType<QQuickIconLabel>(import, 2, 3, "IconLabel"); + qmlRegisterType<QQuickPaddedRectangle>(import, 2, 3, "PaddedRectangle"); } QT_END_NAMESPACE diff --git a/src/imports/controls/universal/ApplicationWindow.qml b/src/imports/controls/universal/ApplicationWindow.qml index 3f3926de..c9bd4cec 100644 --- a/src/imports/controls/universal/ApplicationWindow.qml +++ b/src/imports/controls/universal/ApplicationWindow.qml @@ -36,9 +36,9 @@ import QtQuick 2.9 import QtQuick.Window 2.3 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 -import QtQuick.Controls.Universal.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 +import QtQuick.Controls.Universal.impl 2.3 T.ApplicationWindow { id: window diff --git a/src/imports/controls/universal/BusyIndicator.qml b/src/imports/controls/universal/BusyIndicator.qml index 8f0574fe..ae7977d1 100644 --- a/src/imports/controls/universal/BusyIndicator.qml +++ b/src/imports/controls/universal/BusyIndicator.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 -import QtQuick.Controls.Universal.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 +import QtQuick.Controls.Universal.impl 2.3 T.BusyIndicator { id: control diff --git a/src/imports/controls/universal/Button.qml b/src/imports/controls/universal/Button.qml index 0bf3621b..27d8aa78 100644 --- a/src/imports/controls/universal/Button.qml +++ b/src/imports/controls/universal/Button.qml @@ -35,8 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 T.Button { id: control @@ -50,18 +52,23 @@ T.Button { padding: 8 topPadding: padding - 4 bottomPadding: padding - 4 + spacing: 8 + + icon.width: 20 + icon.height: 20 + icon.color: Color.transparent(Universal.foreground, enabled ? 1.0 : 0.2) property bool useSystemFocusVisuals: true - contentItem: Text { + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font - elide: Text.ElideRight - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - - opacity: enabled ? 1.0 : 0.2 - color: control.Universal.foreground + color: Color.transparent(control.Universal.foreground, enabled ? 1.0 : 0.2) } background: Rectangle { diff --git a/src/imports/controls/universal/CheckBox.qml b/src/imports/controls/universal/CheckBox.qml index 8f4b248d..5557ab59 100644 --- a/src/imports/controls/universal/CheckBox.qml +++ b/src/imports/controls/universal/CheckBox.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 -import QtQuick.Controls.Universal.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 +import QtQuick.Controls.Universal.impl 2.3 T.CheckBox { id: control diff --git a/src/imports/controls/universal/CheckDelegate.qml b/src/imports/controls/universal/CheckDelegate.qml index d3d8690e..72edd60f 100644 --- a/src/imports/controls/universal/CheckDelegate.qml +++ b/src/imports/controls/universal/CheckDelegate.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 -import QtQuick.Controls.Universal.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 +import QtQuick.Controls.Universal.impl 2.3 T.CheckDelegate { id: control @@ -55,25 +57,29 @@ T.CheckDelegate { topPadding: padding - 1 bottomPadding: padding + 1 + icon.width: 20 + icon.height: 20 + icon.color: Color.transparent(Universal.foreground, enabled ? 1.0 : 0.2) + indicator: CheckIndicator { x: text ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 control: control } - contentItem: Text { + contentItem: IconLabel { leftPadding: !control.mirrored ? 0 : control.indicator.width + control.spacing rightPadding: control.mirrored ? 0 : control.indicator.width + control.spacing + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + + icon: control.icon text: control.text font: control.font - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter - - opacity: enabled ? 1.0 : 0.2 - color: control.Universal.foreground + color: Color.transparent(control.Universal.foreground, enabled ? 1.0 : 0.2) } background: Rectangle { diff --git a/src/imports/controls/universal/CheckIndicator.qml b/src/imports/controls/universal/CheckIndicator.qml index eac150e2..e9288bf9 100644 --- a/src/imports/controls/universal/CheckIndicator.qml +++ b/src/imports/controls/universal/CheckIndicator.qml @@ -35,8 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 Rectangle { implicitWidth: 20 @@ -53,14 +55,13 @@ Rectangle { property Item control readonly property bool partiallyChecked: control.checkState === Qt.PartiallyChecked - Image { + ColorImage { x: (parent.width - width) / 2 y: (parent.height - height) / 2 visible: control.checkState === Qt.Checked - source: "image://universal/checkmark/" + (!control.enabled ? control.Universal.baseLowColor : control.Universal.chromeWhiteColor) - sourceSize.width: width - sourceSize.height: height + color: !control.enabled ? control.Universal.baseLowColor : control.Universal.chromeWhiteColor + source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/checkmark.png" } Rectangle { diff --git a/src/imports/controls/universal/ComboBox.qml b/src/imports/controls/universal/ComboBox.qml index 5a6ced60..5ec5bbee 100644 --- a/src/imports/controls/universal/ComboBox.qml +++ b/src/imports/controls/universal/ComboBox.qml @@ -35,9 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.ComboBox { id: control @@ -61,12 +62,11 @@ T.ComboBox { hoverEnabled: control.hoverEnabled } - indicator: Image { + indicator: ColorImage { x: control.mirrored ? control.padding : control.width - width - control.padding y: control.topPadding + (control.availableHeight - height) / 2 - source: "image://universal/downarrow/" + (!control.enabled ? control.Universal.baseLowColor : control.Universal.baseMediumHighColor) - sourceSize.width: width - sourceSize.height: height + color: !control.enabled ? control.Universal.baseLowColor : control.Universal.baseMediumHighColor + source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/downarrow.png" Rectangle { z: -1 diff --git a/src/imports/controls/universal/DelayButton.qml b/src/imports/controls/universal/DelayButton.qml index 9d43be44..5582348d 100644 --- a/src/imports/controls/universal/DelayButton.qml +++ b/src/imports/controls/universal/DelayButton.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.DelayButton { id: control diff --git a/src/imports/controls/universal/Dial.qml b/src/imports/controls/universal/Dial.qml index 2ffb4167..fb48a57a 100644 --- a/src/imports/controls/universal/Dial.qml +++ b/src/imports/controls/universal/Dial.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.Dial { id: control diff --git a/src/imports/controls/universal/Dialog.qml b/src/imports/controls/universal/Dialog.qml index 07ae56a6..4f8a6180 100644 --- a/src/imports/controls/universal/Dialog.qml +++ b/src/imports/controls/universal/Dialog.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.Universal 2.3 T.Dialog { id: control diff --git a/src/imports/controls/universal/DialogButtonBox.qml b/src/imports/controls/universal/DialogButtonBox.qml index 4ce41ad6..2049cca0 100644 --- a/src/imports/controls/universal/DialogButtonBox.qml +++ b/src/imports/controls/universal/DialogButtonBox.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.Universal 2.3 T.DialogButtonBox { id: control diff --git a/src/imports/controls/universal/Drawer.qml b/src/imports/controls/universal/Drawer.qml index 3543887e..5ef0b325 100644 --- a/src/imports/controls/universal/Drawer.qml +++ b/src/imports/controls/universal/Drawer.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.Drawer { id: control diff --git a/src/imports/controls/universal/Frame.qml b/src/imports/controls/universal/Frame.qml index 7d7d55a7..45d18a52 100644 --- a/src/imports/controls/universal/Frame.qml +++ b/src/imports/controls/universal/Frame.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.Frame { id: control diff --git a/src/imports/controls/universal/GroupBox.qml b/src/imports/controls/universal/GroupBox.qml index 420cf22d..14a92c47 100644 --- a/src/imports/controls/universal/GroupBox.qml +++ b/src/imports/controls/universal/GroupBox.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.GroupBox { id: control diff --git a/src/imports/controls/universal/ItemDelegate.qml b/src/imports/controls/universal/ItemDelegate.qml index 69b2cd9d..5c4c3ba9 100644 --- a/src/imports/controls/universal/ItemDelegate.qml +++ b/src/imports/controls/universal/ItemDelegate.qml @@ -35,8 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 T.ItemDelegate { id: control @@ -54,19 +56,20 @@ T.ItemDelegate { topPadding: padding - 1 bottomPadding: padding + 1 - contentItem: Text { - leftPadding: !control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 - rightPadding: control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 + icon.width: 20 + icon.height: 20 + icon.color: Color.transparent(Universal.foreground, enabled ? 1.0 : 0.2) + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + + icon: control.icon text: control.text font: control.font - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter - - opacity: enabled ? 1.0 : 0.2 - color: control.Universal.foreground + color: Color.transparent(control.Universal.foreground, enabled ? 1.0 : 0.2) } background: Rectangle { diff --git a/src/imports/controls/universal/Label.qml b/src/imports/controls/universal/Label.qml index 3cfa9317..99159b79 100644 --- a/src/imports/controls/universal/Label.qml +++ b/src/imports/controls/universal/Label.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.Label { id: control diff --git a/src/imports/controls/universal/Menu.qml b/src/imports/controls/universal/Menu.qml index 0ca475f5..60dc8904 100644 --- a/src/imports/controls/universal/Menu.qml +++ b/src/imports/controls/universal/Menu.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls 2.2 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Controls 2.3 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.Menu { id: control diff --git a/src/imports/controls/universal/MenuItem.qml b/src/imports/controls/universal/MenuItem.qml index 35e2f2ba..ac3c4e98 100644 --- a/src/imports/controls/universal/MenuItem.qml +++ b/src/imports/controls/universal/MenuItem.qml @@ -35,8 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 T.MenuItem { id: control @@ -53,27 +55,32 @@ T.MenuItem { bottomPadding: padding + 1 spacing: 12 - contentItem: Text { - leftPadding: !control.mirrored ? control.indicator.width + control.spacing : 0 - rightPadding: control.mirrored ? control.indicator.width + control.spacing : 0 + icon.width: 20 + icon.height: 20 + icon.color: !enabled ? Universal.baseLowColor : Universal.baseHighColor + contentItem: IconLabel { + leftPadding: control.checkable && !control.mirrored ? control.indicator.width + control.spacing : 0 + rightPadding: control.checkable && control.mirrored ? control.indicator.width + control.spacing : 0 + + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: Qt.AlignLeft + + icon: control.icon text: control.text font: control.font color: !control.enabled ? control.Universal.baseLowColor : control.Universal.baseHighColor - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter } - indicator: Image { + indicator: ColorImage { x: control.text ? (control.mirrored ? control.width - width - control.rightPadding : control.leftPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 visible: control.checked - source: !control.checkable ? "" : "image://universal/checkmark/" + (!control.enabled ? control.Universal.baseLowColor : control.down ? control.Universal.baseHighColor : control.Universal.baseMediumHighColor) - sourceSize.width: width - sourceSize.height: height + color: !control.enabled ? control.Universal.baseLowColor : control.down ? control.Universal.baseHighColor : control.Universal.baseMediumHighColor + source: !control.checkable ? "" : "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/checkmark.png" } background: Rectangle { diff --git a/src/imports/controls/universal/MenuSeparator.qml b/src/imports/controls/universal/MenuSeparator.qml index 18d12528..e73444c8 100644 --- a/src/imports/controls/universal/MenuSeparator.qml +++ b/src/imports/controls/universal/MenuSeparator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.MenuSeparator { id: control diff --git a/src/imports/controls/universal/Page.qml b/src/imports/controls/universal/Page.qml index 1f006f16..cf5b0e22 100644 --- a/src/imports/controls/universal/Page.qml +++ b/src/imports/controls/universal/Page.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.Page { id: control diff --git a/src/imports/controls/universal/PageIndicator.qml b/src/imports/controls/universal/PageIndicator.qml index f6a6baa6..2d65c23e 100644 --- a/src/imports/controls/universal/PageIndicator.qml +++ b/src/imports/controls/universal/PageIndicator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.PageIndicator { id: control diff --git a/src/imports/controls/universal/Pane.qml b/src/imports/controls/universal/Pane.qml index 67a66c93..f952b2a9 100644 --- a/src/imports/controls/universal/Pane.qml +++ b/src/imports/controls/universal/Pane.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.Pane { id: control diff --git a/src/imports/controls/universal/Popup.qml b/src/imports/controls/universal/Popup.qml index 0e42219c..f844d8e1 100644 --- a/src/imports/controls/universal/Popup.qml +++ b/src/imports/controls/universal/Popup.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.Popup { id: control diff --git a/src/imports/controls/universal/ProgressBar.qml b/src/imports/controls/universal/ProgressBar.qml index 58545d61..e3689fc6 100644 --- a/src/imports/controls/universal/ProgressBar.qml +++ b/src/imports/controls/universal/ProgressBar.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 -import QtQuick.Controls.Universal.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 +import QtQuick.Controls.Universal.impl 2.3 T.ProgressBar { id: control diff --git a/src/imports/controls/universal/RadioButton.qml b/src/imports/controls/universal/RadioButton.qml index 5d778660..db0209fb 100644 --- a/src/imports/controls/universal/RadioButton.qml +++ b/src/imports/controls/universal/RadioButton.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 -import QtQuick.Controls.Universal.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 +import QtQuick.Controls.Universal.impl 2.3 T.RadioButton { id: control diff --git a/src/imports/controls/universal/RadioDelegate.qml b/src/imports/controls/universal/RadioDelegate.qml index e8b0216c..924080f6 100644 --- a/src/imports/controls/universal/RadioDelegate.qml +++ b/src/imports/controls/universal/RadioDelegate.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 -import QtQuick.Controls.Universal.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 +import QtQuick.Controls.Universal.impl 2.3 T.RadioDelegate { id: control @@ -55,25 +57,29 @@ T.RadioDelegate { topPadding: padding - 1 bottomPadding: padding + 1 + icon.width: 20 + icon.height: 20 + icon.color: Color.transparent(Universal.foreground, enabled ? 1.0 : 0.2) + indicator: RadioIndicator { x: text ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 control: control } - contentItem: Text { + contentItem: IconLabel { leftPadding: !control.mirrored ? 0 : control.indicator.width + control.spacing rightPadding: control.mirrored ? 0 : control.indicator.width + control.spacing + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + + icon: control.icon text: control.text font: control.font - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter - - opacity: enabled ? 1.0 : 0.2 - color: control.Universal.foreground + color: Color.transparent(control.Universal.foreground, enabled ? 1.0 : 0.2) } background: Rectangle { diff --git a/src/imports/controls/universal/RadioIndicator.qml b/src/imports/controls/universal/RadioIndicator.qml index 220983da..676dcd07 100644 --- a/src/imports/controls/universal/RadioIndicator.qml +++ b/src/imports/controls/universal/RadioIndicator.qml @@ -35,7 +35,7 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Controls.Universal 2.2 +import QtQuick.Controls.Universal 2.3 Rectangle { implicitWidth: 20 diff --git a/src/imports/controls/universal/RangeSlider.qml b/src/imports/controls/universal/RangeSlider.qml index d2cf7a65..6aab392f 100644 --- a/src/imports/controls/universal/RangeSlider.qml +++ b/src/imports/controls/universal/RangeSlider.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.RangeSlider { id: control @@ -51,13 +51,11 @@ T.RangeSlider { padding: 6 first.handle: Rectangle { - implicitWidth: horizontal ? 8 : 24 - implicitHeight: horizontal ? 24 : 8 + implicitWidth: control.horizontal ? 8 : 24 + implicitHeight: control.horizontal ? 24 : 8 - readonly property bool horizontal: control.orientation === Qt.Horizontal - - x: control.leftPadding + (horizontal ? control.first.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : control.first.visualPosition * (control.availableHeight - height)) + x: control.leftPadding + (control.horizontal ? control.first.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.first.visualPosition * (control.availableHeight - height)) radius: 4 color: control.first.pressed ? control.Universal.chromeHighColor : @@ -66,13 +64,11 @@ T.RangeSlider { } second.handle: Rectangle { - implicitWidth: horizontal ? 8 : 24 - implicitHeight: horizontal ? 24 : 8 - - readonly property bool horizontal: control.orientation === Qt.Horizontal + implicitWidth: control.horizontal ? 8 : 24 + implicitHeight: control.horizontal ? 24 : 8 - x: control.leftPadding + (horizontal ? control.second.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : control.second.visualPosition * (control.availableHeight - height)) + x: control.leftPadding + (control.horizontal ? control.second.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.second.visualPosition * (control.availableHeight - height)) radius: 4 color: control.second.pressed ? control.Universal.chromeHighColor : @@ -81,33 +77,31 @@ T.RangeSlider { } background: Item { - implicitWidth: horizontal ? 200 : 18 - implicitHeight: horizontal ? 18 : 200 - - readonly property bool horizontal: control.orientation === Qt.Horizontal + implicitWidth: control.horizontal ? 200 : 18 + implicitHeight: control.horizontal ? 18 : 200 - x: control.leftPadding + (horizontal ? 0 : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : 0) - width: horizontal ? control.availableWidth : implicitWidth - height: horizontal ? implicitHeight : control.availableHeight + x: control.leftPadding + (control.horizontal ? 0 : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : 0) + width: control.horizontal ? control.availableWidth : implicitWidth + height: control.horizontal ? implicitHeight : control.availableHeight - scale: horizontal && control.mirrored ? -1 : 1 + scale: control.horizontal && control.mirrored ? -1 : 1 Rectangle { - x: parent.horizontal ? 0 : (parent.width - width) / 2 - y: parent.horizontal ? (parent.height - height) / 2 : 0 - width: parent.horizontal ? parent.width : 2 // SliderBackgroundThemeHeight - height: !parent.horizontal ? parent.height : 2 // SliderBackgroundThemeHeight + x: control.horizontal ? 0 : (parent.width - width) / 2 + y: control.horizontal ? (parent.height - height) / 2 : 0 + width: control.horizontal ? parent.width : 2 // SliderBackgroundThemeHeight + height: control.vertical ? parent.height : 2 // SliderBackgroundThemeHeight color: control.hovered && !control.pressed ? control.Universal.baseMediumColor : control.enabled ? control.Universal.baseMediumLowColor : control.Universal.chromeDisabledHighColor } Rectangle { - x: parent.horizontal ? control.first.position * parent.width : (parent.width - width) / 2 - y: parent.horizontal ? (parent.height - height) / 2 : control.second.visualPosition * parent.height - width: parent.horizontal ? control.second.position * parent.width - control.first.position * parent.width : 2 // SliderBackgroundThemeHeight - height: !parent.horizontal ? control.second.position * parent.height - control.first.position * parent.height : 2 // SliderBackgroundThemeHeight + x: control.horizontal ? control.first.position * parent.width : (parent.width - width) / 2 + y: control.horizontal ? (parent.height - height) / 2 : control.second.visualPosition * parent.height + width: control.horizontal ? control.second.position * parent.width - control.first.position * parent.width : 2 // SliderBackgroundThemeHeight + height: control.vertical ? control.second.position * parent.height - control.first.position * parent.height : 2 // SliderBackgroundThemeHeight color: control.enabled ? control.Universal.accent : control.Universal.chromeDisabledHighColor } diff --git a/src/imports/controls/universal/RoundButton.qml b/src/imports/controls/universal/RoundButton.qml index d70c4cda..ac5f2545 100644 --- a/src/imports/controls/universal/RoundButton.qml +++ b/src/imports/controls/universal/RoundButton.qml @@ -35,8 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 T.RoundButton { id: control @@ -48,18 +50,23 @@ T.RoundButton { baselineOffset: contentItem.y + contentItem.baselineOffset padding: 8 + spacing: 8 + + icon.width: 20 + icon.height: 20 + icon.color: Color.transparent(Universal.foreground, enabled ? 1.0 : 0.2) property bool useSystemFocusVisuals: true - contentItem: Text { + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font - elide: Text.ElideRight - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - - opacity: enabled ? 1.0 : 0.2 - color: control.Universal.foreground + color: Color.transparent(control.Universal.foreground, enabled ? 1.0 : 0.2) } background: Rectangle { diff --git a/src/imports/controls/universal/ScrollBar.qml b/src/imports/controls/universal/ScrollBar.qml index 981e382a..c6ca874e 100644 --- a/src/imports/controls/universal/ScrollBar.qml +++ b/src/imports/controls/universal/ScrollBar.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.ScrollBar { id: control diff --git a/src/imports/controls/universal/ScrollIndicator.qml b/src/imports/controls/universal/ScrollIndicator.qml index 2f30ebe5..6c15050b 100644 --- a/src/imports/controls/universal/ScrollIndicator.qml +++ b/src/imports/controls/universal/ScrollIndicator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.ScrollIndicator { id: control diff --git a/src/imports/controls/universal/Slider.qml b/src/imports/controls/universal/Slider.qml index e02065e5..bc483c3a 100644 --- a/src/imports/controls/universal/Slider.qml +++ b/src/imports/controls/universal/Slider.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.Slider { id: control @@ -51,13 +51,11 @@ T.Slider { property bool useSystemFocusVisuals: true handle: Rectangle { - implicitWidth: horizontal ? 8 : 24 - implicitHeight: horizontal ? 24 : 8 + implicitWidth: control.horizontal ? 8 : 24 + implicitHeight: control.horizontal ? 24 : 8 - readonly property bool horizontal: control.orientation === Qt.Horizontal - - x: control.leftPadding + (horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : control.visualPosition * (control.availableHeight - height)) + x: control.leftPadding + (control.horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.visualPosition * (control.availableHeight - height)) radius: 4 color: control.pressed ? control.Universal.chromeHighColor : @@ -66,33 +64,31 @@ T.Slider { } background: Item { - implicitWidth: horizontal ? 200 : 18 - implicitHeight: horizontal ? 18 : 200 - - readonly property bool horizontal: control.orientation === Qt.Horizontal + implicitWidth: control.horizontal ? 200 : 18 + implicitHeight: control.horizontal ? 18 : 200 - x: control.leftPadding + (horizontal ? 0 : (control.availableWidth - width) / 2) - y: control.topPadding + (horizontal ? (control.availableHeight - height) / 2 : 0) - width: horizontal ? control.availableWidth : implicitWidth - height: horizontal ? implicitHeight : control.availableHeight + x: control.leftPadding + (control.horizontal ? 0 : (control.availableWidth - width) / 2) + y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : 0) + width: control.horizontal ? control.availableWidth : implicitWidth + height: control.horizontal ? implicitHeight : control.availableHeight - scale: horizontal && control.mirrored ? -1 : 1 + scale: control.horizontal && control.mirrored ? -1 : 1 Rectangle { - x: parent.horizontal ? 0 : (parent.width - width) / 2 - y: parent.horizontal ? (parent.height - height) / 2 : 0 - width: parent.horizontal ? parent.width : 2 // SliderTrackThemeHeight - height: !parent.horizontal ? parent.height : 2 // SliderTrackThemeHeight + x: control.horizontal ? 0 : (parent.width - width) / 2 + y: control.horizontal ? (parent.height - height) / 2 : 0 + width: control.horizontal ? parent.width : 2 // SliderTrackThemeHeight + height: !control.horizontal ? parent.height : 2 // SliderTrackThemeHeight color: control.hovered && !control.pressed ? control.Universal.baseMediumColor : control.enabled ? control.Universal.baseMediumLowColor : control.Universal.chromeDisabledHighColor } Rectangle { - x: parent.horizontal ? 0 : (parent.width - width) / 2 - y: parent.horizontal ? (parent.height - height) / 2 : control.visualPosition * parent.height - width: parent.horizontal ? control.position * parent.width : 2 // SliderTrackThemeHeight - height: !parent.horizontal ? control.position * parent.height : 2 // SliderTrackThemeHeight + x: control.horizontal ? 0 : (parent.width - width) / 2 + y: control.horizontal ? (parent.height - height) / 2 : control.visualPosition * parent.height + width: control.horizontal ? control.position * parent.width : 2 // SliderTrackThemeHeight + height: !control.horizontal ? control.position * parent.height : 2 // SliderTrackThemeHeight color: control.enabled ? control.Universal.accent : control.Universal.chromeDisabledHighColor } diff --git a/src/imports/controls/universal/SpinBox.qml b/src/imports/controls/universal/SpinBox.qml index 0cbfdd16..499afc82 100644 --- a/src/imports/controls/universal/SpinBox.qml +++ b/src/imports/controls/universal/SpinBox.qml @@ -35,8 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 T.SpinBox { id: control @@ -99,14 +101,12 @@ T.SpinBox { opacity: control.activeFocus && !control.up.pressed ? 0.4 : 1.0 } - Image { + ColorImage { x: (parent.width - width) / 2 y: (parent.height - height) / 2 - source: "image://universal/" + (control.mirrored ? "left" : "right") + "arrow/" - + (!enabled ? control.Universal.chromeDisabledLowColor : - control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.baseHighColor) - sourceSize.width: width - sourceSize.height: height + color: !enabled ? control.Universal.chromeDisabledLowColor : + control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.baseHighColor + source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/" + (control.mirrored ? "left" : "right") + "arrow.png" } } @@ -127,14 +127,12 @@ T.SpinBox { opacity: control.activeFocus && !control.down.pressed ? 0.4 : 1.0 } - Image { + ColorImage { x: (parent.width - width) / 2 y: (parent.height - height) / 2 - source: "image://universal/" + (control.mirrored ? "right" : "left") + "arrow/" - + (!enabled ? control.Universal.chromeDisabledLowColor : - control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.baseHighColor) - sourceSize.width: width - sourceSize.height: height + color: !enabled ? control.Universal.chromeDisabledLowColor : + control.activeFocus ? control.Universal.chromeBlackHighColor : control.Universal.baseHighColor + source: "qrc:/qt-project.org/imports/QtQuick/Controls.2/Universal/images/" + (control.mirrored ? "right" : "left") + "arrow.png" } } diff --git a/src/imports/controls/universal/StackView.qml b/src/imports/controls/universal/StackView.qml index 071e1737..3e951c67 100644 --- a/src/imports/controls/universal/StackView.qml +++ b/src/imports/controls/universal/StackView.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.StackView { id: control diff --git a/src/imports/controls/universal/SwipeDelegate.qml b/src/imports/controls/universal/SwipeDelegate.qml index cec5c132..246d4a15 100644 --- a/src/imports/controls/universal/SwipeDelegate.qml +++ b/src/imports/controls/universal/SwipeDelegate.qml @@ -35,8 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 T.SwipeDelegate { id: control @@ -54,21 +56,22 @@ T.SwipeDelegate { topPadding: padding - 1 bottomPadding: padding + 1 + icon.width: 20 + icon.height: 20 + icon.color: Color.transparent(Universal.foreground, enabled ? 1.0 : 0.2) + swipe.transition: Transition { SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } } - contentItem: Text { - leftPadding: !control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 - rightPadding: control.mirrored ? (control.indicator ? control.indicator.width : 0) + control.spacing : 0 + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + icon: control.icon text: control.text font: control.font - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter - - opacity: enabled ? 1.0 : 0.2 - color: control.Universal.foreground + color: Color.transparent(control.Universal.foreground, enabled ? 1.0 : 0.2) } background: Rectangle { diff --git a/src/imports/controls/universal/Switch.qml b/src/imports/controls/universal/Switch.qml index ad07d0df..2b05d45f 100644 --- a/src/imports/controls/universal/Switch.qml +++ b/src/imports/controls/universal/Switch.qml @@ -35,9 +35,9 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 -import QtQuick.Controls.Universal.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 +import QtQuick.Controls.Universal.impl 2.3 T.Switch { id: control diff --git a/src/imports/controls/universal/SwitchDelegate.qml b/src/imports/controls/universal/SwitchDelegate.qml index a4ba85db..ec4f37b4 100644 --- a/src/imports/controls/universal/SwitchDelegate.qml +++ b/src/imports/controls/universal/SwitchDelegate.qml @@ -35,9 +35,11 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 -import QtQuick.Controls.Universal.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 +import QtQuick.Controls.Universal.impl 2.3 T.SwitchDelegate { id: control @@ -55,25 +57,29 @@ T.SwitchDelegate { topPadding: padding - 1 bottomPadding: padding + 1 + icon.width: 20 + icon.height: 20 + icon.color: Color.transparent(Universal.foreground, enabled ? 1.0 : 0.2) + indicator: SwitchIndicator { x: text ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding) : control.leftPadding + (control.availableWidth - width) / 2 y: control.topPadding + (control.availableHeight - height) / 2 control: control } - contentItem: Text { + contentItem: IconLabel { leftPadding: !control.mirrored ? 0 : control.indicator.width + control.spacing rightPadding: control.mirrored ? 0 : control.indicator.width + control.spacing + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + + icon: control.icon text: control.text font: control.font - elide: Text.ElideRight - visible: control.text - horizontalAlignment: Text.AlignLeft - verticalAlignment: Text.AlignVCenter - - opacity: enabled ? 1.0 : 0.2 - color: control.Universal.foreground + color: Color.transparent(control.Universal.foreground, enabled ? 1.0 : 0.2) } background: Rectangle { diff --git a/src/imports/controls/universal/SwitchIndicator.qml b/src/imports/controls/universal/SwitchIndicator.qml index 1eb2f9b5..6e66f16d 100644 --- a/src/imports/controls/universal/SwitchIndicator.qml +++ b/src/imports/controls/universal/SwitchIndicator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 Item { implicitWidth: 44 diff --git a/src/imports/controls/universal/TabBar.qml b/src/imports/controls/universal/TabBar.qml index c0de7fb2..9c6fa217 100644 --- a/src/imports/controls/universal/TabBar.qml +++ b/src/imports/controls/universal/TabBar.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.TabBar { id: control @@ -46,8 +46,6 @@ T.TabBar { implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding) - contentHeight: 48 - contentItem: PathView { model: control.contentModel currentIndex: control.currentIndex diff --git a/src/imports/controls/universal/TabButton.qml b/src/imports/controls/universal/TabButton.qml index ef982c60..054f65f5 100644 --- a/src/imports/controls/universal/TabButton.qml +++ b/src/imports/controls/universal/TabButton.qml @@ -35,8 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 T.TabButton { id: control @@ -48,15 +50,22 @@ T.TabButton { baselineOffset: contentItem.y + contentItem.baselineOffset padding: 12 // PivotItemMargin + spacing: 8 - contentItem: Text { + icon.width: 20 + icon.height: 20 + icon.color: Color.transparent(control.hovered ? control.Universal.baseMediumHighColor : control.Universal.foreground, + control.checked || control.down || control.hovered ? 1.0 : 0.2) + + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font - elide: Text.ElideRight - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - - opacity: control.checked || control.down || control.hovered ? 1.0 : 0.2 - color: control.hovered ? control.Universal.baseMediumHighColor : control.Universal.foreground + color: Color.transparent(control.hovered ? control.Universal.baseMediumHighColor : control.Universal.foreground, + control.checked || control.down || control.hovered ? 1.0 : 0.2) } } diff --git a/src/imports/controls/universal/TextArea.qml b/src/imports/controls/universal/TextArea.qml index a173e676..f356dd3a 100644 --- a/src/imports/controls/universal/TextArea.qml +++ b/src/imports/controls/universal/TextArea.qml @@ -35,10 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 T.TextArea { id: control diff --git a/src/imports/controls/universal/TextField.qml b/src/imports/controls/universal/TextField.qml index 476630fd..01ce2601 100644 --- a/src/imports/controls/universal/TextField.qml +++ b/src/imports/controls/universal/TextField.qml @@ -35,10 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 T.TextField { id: control diff --git a/src/imports/controls/universal/ToolBar.qml b/src/imports/controls/universal/ToolBar.qml index f6bec475..d41ca17f 100644 --- a/src/imports/controls/universal/ToolBar.qml +++ b/src/imports/controls/universal/ToolBar.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.ToolBar { id: control diff --git a/src/imports/controls/universal/ToolButton.qml b/src/imports/controls/universal/ToolButton.qml index 9b07490f..cd0b2ca9 100644 --- a/src/imports/controls/universal/ToolButton.qml +++ b/src/imports/controls/universal/ToolButton.qml @@ -35,8 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 +import QtQuick.Controls.Universal 2.3 T.ToolButton { id: control @@ -48,18 +50,23 @@ T.ToolButton { baselineOffset: contentItem.y + contentItem.baselineOffset padding: 6 + spacing: 8 + + icon.width: 20 + icon.height: 20 + icon.color: Color.transparent(Universal.foreground, enabled ? 1.0 : 0.2) property bool useSystemFocusVisuals: true - contentItem: Text { + contentItem: IconLabel { + spacing: control.spacing + mirrored: control.mirrored + display: control.display + + icon: control.icon text: control.text font: control.font - elide: Text.ElideRight - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - - opacity: enabled ? 1.0 : 0.2 - color: control.Universal.foreground + color: Color.transparent(control.Universal.foreground, enabled ? 1.0 : 0.2) } background: Rectangle { diff --git a/src/imports/controls/universal/ToolSeparator.qml b/src/imports/controls/universal/ToolSeparator.qml index 8d36d95b..965b9690 100644 --- a/src/imports/controls/universal/ToolSeparator.qml +++ b/src/imports/controls/universal/ToolSeparator.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.ToolSeparator { id: control diff --git a/src/imports/controls/universal/ToolTip.qml b/src/imports/controls/universal/ToolTip.qml index 6f8f27f4..cb131919 100644 --- a/src/imports/controls/universal/ToolTip.qml +++ b/src/imports/controls/universal/ToolTip.qml @@ -35,8 +35,8 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 T.ToolTip { id: control diff --git a/src/imports/controls/universal/Tumbler.qml b/src/imports/controls/universal/Tumbler.qml index 45bcb6c8..bf31e68a 100644 --- a/src/imports/controls/universal/Tumbler.qml +++ b/src/imports/controls/universal/Tumbler.qml @@ -35,10 +35,10 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T -import QtQuick.Controls.Universal 2.2 -import QtQuick.Controls 2.2 -import QtQuick.Controls.impl 2.2 +import QtQuick.Templates 2.3 as T +import QtQuick.Controls.Universal 2.3 +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 T.Tumbler { id: control diff --git a/src/imports/controls/universal/qmldir b/src/imports/controls/universal/qmldir index da4a89d6..271eafa9 100644 --- a/src/imports/controls/universal/qmldir +++ b/src/imports/controls/universal/qmldir @@ -1,4 +1,4 @@ module QtQuick.Controls.Universal plugin qtquickcontrols2universalstyleplugin classname QtQuickControls2UniversalStylePlugin -depends QtQuick.Controls 2.2 +depends QtQuick.Controls 2.3 diff --git a/src/imports/controls/universal/qquickuniversalstyle.cpp b/src/imports/controls/universal/qquickuniversalstyle.cpp index c581a784..157d5ddb 100644 --- a/src/imports/controls/universal/qquickuniversalstyle.cpp +++ b/src/imports/controls/universal/qquickuniversalstyle.cpp @@ -39,7 +39,7 @@ #include <QtCore/qdebug.h> #include <QtCore/qsettings.h> #include <QtQml/qqmlinfo.h> -#include <QtQuickControls2/private/qquickstyleattached_p.h> +#include <QtQuickControls2/private/qquickstyle_p.h> QT_BEGIN_NAMESPACE @@ -132,12 +132,10 @@ static QRgb qquickuniversal_accent_color(QQuickUniversalStyle::Color accent) return colors[accent]; } -extern bool qt_is_dark_system_theme(); - static QQuickUniversalStyle::Theme qquickuniversal_effective_theme(QQuickUniversalStyle::Theme theme) { if (theme == QQuickUniversalStyle::System) - theme = qt_is_dark_system_theme() ? QQuickUniversalStyle::Dark : QQuickUniversalStyle::Light; + theme = QQuickStylePrivate::isDarkSystemTheme() ? QQuickUniversalStyle::Dark : QQuickUniversalStyle::Light; return theme; } @@ -153,7 +151,7 @@ static QRgb GlobalBackground = qquickuniversal_light_color(QQuickUniversalStyle: static bool HasGlobalForeground = false; static bool HasGlobalBackground = false; -QQuickUniversalStyle::QQuickUniversalStyle(QObject *parent) : QQuickStyleAttached(parent), +QQuickUniversalStyle::QQuickUniversalStyle(QObject *parent) : QQuickAttachedObject(parent), m_explicitTheme(false), m_explicitAccent(false), m_explicitForeground(false), m_explicitBackground(false), m_hasForeground(HasGlobalForeground), m_hasBackground(HasGlobalBackground), m_theme(GlobalTheme), m_accent(GlobalAccent), m_foreground(GlobalForeground), m_background(GlobalBackground) @@ -201,8 +199,8 @@ void QQuickUniversalStyle::inheritTheme(Theme theme) void QQuickUniversalStyle::propagateTheme() { - const auto styles = childStyles(); - for (QQuickStyleAttached *child : styles) { + const auto styles = attachedChildren(); + for (QQuickAttachedObject *child : styles) { QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(child); if (universal) universal->inheritTheme(m_theme); @@ -215,7 +213,7 @@ void QQuickUniversalStyle::resetTheme() return; m_explicitTheme = false; - QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(parentStyle()); + QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(attachedParent()); inheritTheme(universal ? universal->theme() : GlobalTheme); } @@ -251,8 +249,8 @@ void QQuickUniversalStyle::inheritAccent(QRgb accent) void QQuickUniversalStyle::propagateAccent() { - const auto styles = childStyles(); - for (QQuickStyleAttached *child : styles) { + const auto styles = attachedChildren(); + for (QQuickAttachedObject *child : styles) { QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(child); if (universal) universal->inheritAccent(m_accent); @@ -265,7 +263,7 @@ void QQuickUniversalStyle::resetAccent() return; m_explicitAccent = false; - QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(parentStyle()); + QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(attachedParent()); inheritAccent(universal ? universal->m_accent : GlobalAccent); } @@ -305,8 +303,8 @@ void QQuickUniversalStyle::inheritForeground(QRgb foreground, bool has) void QQuickUniversalStyle::propagateForeground() { - const auto styles = childStyles(); - for (QQuickStyleAttached *child : styles) { + const auto styles = attachedChildren(); + for (QQuickAttachedObject *child : styles) { QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(child); if (universal) universal->inheritForeground(m_foreground, m_hasForeground); @@ -320,7 +318,7 @@ void QQuickUniversalStyle::resetForeground() m_hasForeground = false; m_explicitForeground = false; - QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(parentStyle()); + QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(attachedParent()); inheritForeground(universal ? universal->m_foreground : GlobalForeground, universal ? universal->m_hasForeground : false); } @@ -360,8 +358,8 @@ void QQuickUniversalStyle::inheritBackground(QRgb background, bool has) void QQuickUniversalStyle::propagateBackground() { - const auto styles = childStyles(); - for (QQuickStyleAttached *child : styles) { + const auto styles = attachedChildren(); + for (QQuickAttachedObject *child : styles) { QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(child); if (universal) universal->inheritBackground(m_background, m_hasBackground); @@ -375,7 +373,7 @@ void QQuickUniversalStyle::resetBackground() m_hasBackground = false; m_explicitBackground = false; - QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(parentStyle()); + QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(attachedParent()); inheritBackground(universal ? universal->m_background : GlobalBackground, universal ? universal->m_hasBackground : false); } @@ -509,7 +507,7 @@ QColor QQuickUniversalStyle::systemColor(SystemColor role) const return QColor::fromRgba(m_theme == QQuickUniversalStyle::Dark ? qquickuniversal_dark_color(role) : qquickuniversal_light_color(role)); } -void QQuickUniversalStyle::parentStyleChange(QQuickStyleAttached *newParent, QQuickStyleAttached *oldParent) +void QQuickUniversalStyle::attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) { Q_UNUSED(oldParent); QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(newParent); @@ -542,7 +540,7 @@ void QQuickUniversalStyle::init() { static bool globalsInitialized = false; if (!globalsInitialized) { - QSharedPointer<QSettings> settings = QQuickStyleAttached::settings(QStringLiteral("Universal")); + QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(QStringLiteral("Universal")); bool ok = false; QByteArray themeValue = resolveSetting("QT_QUICK_CONTROLS_UNIVERSAL_THEME", settings, QStringLiteral("Theme")); @@ -597,7 +595,7 @@ void QQuickUniversalStyle::init() globalsInitialized = true; } - QQuickStyleAttached::init(); // TODO: lazy init? + QQuickAttachedObject::init(); // TODO: lazy init? } bool QQuickUniversalStyle::variantToRgba(const QVariant &var, const char *name, QRgb *rgba) const diff --git a/src/imports/controls/universal/qquickuniversalstyle_p.h b/src/imports/controls/universal/qquickuniversalstyle_p.h index 508e8297..196048ef 100644 --- a/src/imports/controls/universal/qquickuniversalstyle_p.h +++ b/src/imports/controls/universal/qquickuniversalstyle_p.h @@ -49,13 +49,13 @@ // #include <QtGui/qcolor.h> -#include <QtQuickControls2/private/qquickstyleattached_p.h> +#include <QtQuickControls2/private/qquickattachedobject_p.h> QT_BEGIN_NAMESPACE class QQuickUniversalStylePrivate; -class QQuickUniversalStyle : public QQuickStyleAttached +class QQuickUniversalStyle : public QQuickAttachedObject { Q_OBJECT Q_PROPERTY(Theme theme READ theme WRITE setTheme RESET resetTheme NOTIFY themeChanged FINAL) @@ -208,7 +208,7 @@ Q_SIGNALS: void paletteChanged(); protected: - void parentStyleChange(QQuickStyleAttached *newParent, QQuickStyleAttached *oldParent) override; + void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) override; private: void init(); diff --git a/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp b/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp index 017a1aad..55255181 100644 --- a/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp +++ b/src/imports/controls/universal/qtquickcontrols2universalstyleplugin.cpp @@ -42,8 +42,6 @@ #include "qquickuniversalstyle_p.h" #include "qquickuniversaltheme_p.h" -#include <QtQuickControls2/private/qquickcolorimageprovider_p.h> - static inline void initResources() { Q_INIT_RESOURCE(qtquickcontrols2universalstyleplugin); @@ -84,8 +82,6 @@ void QtQuickControls2UniversalStylePlugin::initializeEngine(QQmlEngine *engine, { QQuickStylePlugin::initializeEngine(engine, uri); - engine->addImageProvider(name(), new QQuickColorImageProvider(QStringLiteral(":/qt-project.org/imports/QtQuick/Controls.2/Universal/images"))); - QByteArray import = QByteArray(uri) + ".impl"; qmlRegisterModule(import, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2... diff --git a/src/imports/controls/universal/universal.pro b/src/imports/controls/universal/universal.pro index f2515205..d9bae111 100644 --- a/src/imports/controls/universal/universal.pro +++ b/src/imports/controls/universal/universal.pro @@ -1,6 +1,6 @@ TARGET = qtquickcontrols2universalstyleplugin TARGETPATH = QtQuick/Controls.2/Universal -IMPORT_VERSION = 2.2 +IMPORT_VERSION = 2.3 QT += qml quick QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2-private diff --git a/src/imports/platform/widgets/qwidgetplatformmenu.cpp b/src/imports/platform/widgets/qwidgetplatformmenu.cpp index 1aacb0ff..e5fe734f 100644 --- a/src/imports/platform/widgets/qwidgetplatformmenu.cpp +++ b/src/imports/platform/widgets/qwidgetplatformmenu.cpp @@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE QWidgetPlatformMenu::QWidgetPlatformMenu(QObject *parent) - : m_tag(reinterpret_cast<quintptr>(this)), m_menu(new QMenu) + : m_menu(new QMenu) { setParent(parent); @@ -95,16 +95,6 @@ void QWidgetPlatformMenu::syncSeparatorsCollapsible(bool enable) m_menu->setSeparatorsCollapsible(enable); } -quintptr QWidgetPlatformMenu::tag() const -{ - return m_tag; -} - -void QWidgetPlatformMenu::setTag(quintptr tag) -{ - m_tag = tag; -} - void QWidgetPlatformMenu::setText(const QString &text) { m_menu->setTitle(text); diff --git a/src/imports/platform/widgets/qwidgetplatformmenu_p.h b/src/imports/platform/widgets/qwidgetplatformmenu_p.h index 1df9ef78..4d58f528 100644 --- a/src/imports/platform/widgets/qwidgetplatformmenu_p.h +++ b/src/imports/platform/widgets/qwidgetplatformmenu_p.h @@ -70,9 +70,6 @@ public: void syncMenuItem(QPlatformMenuItem *item) override; void syncSeparatorsCollapsible(bool enable) override; - quintptr tag()const override; - void setTag(quintptr tag) override; - void setText(const QString &text) override; void setIcon(const QIcon &icon) override; void setEnabled(bool enabled) override; @@ -92,7 +89,6 @@ public: QPlatformMenu *createSubMenu() const override; private: - quintptr m_tag; QScopedPointer<QMenu> m_menu; QVector<QWidgetPlatformMenuItem *> m_items; }; diff --git a/src/imports/platform/widgets/qwidgetplatformmenuitem.cpp b/src/imports/platform/widgets/qwidgetplatformmenuitem.cpp index 8519c899..9de899f2 100644 --- a/src/imports/platform/widgets/qwidgetplatformmenuitem.cpp +++ b/src/imports/platform/widgets/qwidgetplatformmenuitem.cpp @@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE QWidgetPlatformMenuItem::QWidgetPlatformMenuItem(QObject *parent) - : m_tag(reinterpret_cast<quintptr>(this)), m_action(new QAction) + : m_action(new QAction) { setParent(parent); connect(m_action.data(), &QAction::hovered, this, &QPlatformMenuItem::hovered); @@ -59,16 +59,6 @@ QAction *QWidgetPlatformMenuItem::action() const return m_action.data(); } -quintptr QWidgetPlatformMenuItem::tag() const -{ - return m_tag; -} - -void QWidgetPlatformMenuItem::setTag(quintptr tag) -{ - m_tag = tag; -} - void QWidgetPlatformMenuItem::setText(const QString &text) { m_action->setText(text); diff --git a/src/imports/platform/widgets/qwidgetplatformmenuitem_p.h b/src/imports/platform/widgets/qwidgetplatformmenuitem_p.h index 752f8a03..43b3fc17 100644 --- a/src/imports/platform/widgets/qwidgetplatformmenuitem_p.h +++ b/src/imports/platform/widgets/qwidgetplatformmenuitem_p.h @@ -64,9 +64,6 @@ public: QAction *action() const; - quintptr tag()const override; - void setTag(quintptr tag) override; - void setText(const QString &text) override; void setIcon(const QIcon &icon) override; void setMenu(QPlatformMenu *menu) override; @@ -83,7 +80,6 @@ public: void setIconSize(int size) override; private: - quintptr m_tag; QScopedPointer<QAction> m_action; }; diff --git a/src/imports/templates/doc/src/qtquicktemplates2-qmltypes.qdoc b/src/imports/templates/doc/src/qtquicktemplates2-qmltypes.qdoc index 19725fa4..52796425 100644 --- a/src/imports/templates/doc/src/qtquicktemplates2-qmltypes.qdoc +++ b/src/imports/templates/doc/src/qtquicktemplates2-qmltypes.qdoc @@ -26,7 +26,7 @@ ****************************************************************************/ /*! - \qmlmodule QtQuick.Templates 2.2 + \qmlmodule QtQuick.Templates 2.3 \title Qt Quick Templates 2 QML Types \ingroup qmlmodules \brief Provides QML types for templates (Qt Quick Templates). @@ -38,7 +38,7 @@ \c .qml file: \badcode - import QtQuick.Templates 2.2 as T + import QtQuick.Templates 2.3 as T \endcode For the sake of clarity, there is a one-to-one mapping between the types diff --git a/src/imports/templates/plugins.qmltypes b/src/imports/templates/plugins.qmltypes index 712cf3b6..13d9e205 100644 --- a/src/imports/templates/plugins.qmltypes +++ b/src/imports/templates/plugins.qmltypes @@ -4,7 +4,7 @@ import QtQuick.tooling 1.2 // It is used for QML tooling purposes only. // // This file was auto-generated by: -// 'qmlplugindump -nonrelocatable -dependencies dependencies.json QtQuick.Templates 2.2' +// 'qmlplugindump -nonrelocatable -dependencies dependencies.json QtQuick.Templates 2.3' Module { dependencies: ["QtQuick 2.9", "QtQuick.Window 2.2"] @@ -24,6 +24,9 @@ Module { Property { name: "checkable"; type: "bool" } Property { name: "autoExclusive"; type: "bool" } Property { name: "indicator"; type: "QQuickItem"; isPointer: true } + Property { name: "icon"; revision: 3; type: "QQuickIcon"; isReadonly: true; isPointer: true } + Property { name: "display"; revision: 3; type: "Display" } + Property { name: "action"; revision: 3; type: "QQuickAction"; isPointer: true } Signal { name: "pressed" } Signal { name: "released" } Signal { name: "canceled" } @@ -31,9 +34,91 @@ Module { Signal { name: "toggled"; revision: 2 } Signal { name: "pressAndHold" } Signal { name: "doubleClicked" } + Signal { name: "displayChanged"; revision: 3 } + Signal { name: "actionChanged"; revision: 3 } Method { name: "toggle" } } Component { + name: "QQuickAction" + prototype: "QObject" + exports: ["QtQuick.Templates/Action 2.3"] + exportMetaObjectRevisions: [0] + Property { name: "text"; type: "string" } + Property { name: "icon"; type: "QQuickIcon"; isReadonly: true; isPointer: true } + Property { name: "enabled"; type: "bool" } + Property { name: "checked"; type: "bool" } + Property { name: "checkable"; type: "bool" } + Property { name: "shortcut"; type: "QVariant" } + Signal { + name: "textChanged" + Parameter { name: "text"; type: "string" } + } + Signal { + name: "enabledChanged" + Parameter { name: "enabled"; type: "bool" } + } + Signal { + name: "checkedChanged" + Parameter { name: "checked"; type: "bool" } + } + Signal { + name: "checkableChanged" + Parameter { name: "checkable"; type: "bool" } + } + Signal { + name: "shortcutChanged" + Parameter { name: "shortcut"; type: "QKeySequence" } + } + Signal { + name: "toggled" + Parameter { name: "source"; type: "QObject"; isPointer: true } + } + Signal { name: "toggled" } + Signal { + name: "triggered" + Parameter { name: "source"; type: "QObject"; isPointer: true } + } + Signal { name: "triggered" } + Method { + name: "toggle" + Parameter { name: "source"; type: "QObject"; isPointer: true } + } + Method { name: "toggle" } + Method { + name: "trigger" + Parameter { name: "source"; type: "QObject"; isPointer: true } + } + Method { name: "trigger" } + } + Component { + name: "QQuickActionGroup" + prototype: "QObject" + exports: ["QtQuick.Templates/ActionGroup 2.3"] + exportMetaObjectRevisions: [0] + attachedType: "QQuickActionGroupAttached" + Property { name: "checkedAction"; type: "QQuickAction"; isPointer: true } + Property { name: "actions"; type: "QQuickAction"; isList: true; isReadonly: true } + Property { name: "exclusive"; type: "bool" } + Property { name: "enabled"; type: "bool" } + Signal { + name: "triggered" + Parameter { name: "action"; type: "QQuickAction"; isPointer: true } + } + Method { + name: "addAction" + Parameter { name: "action"; type: "QQuickAction"; isPointer: true } + } + Method { + name: "removeAction" + Parameter { name: "action"; type: "QQuickAction"; isPointer: true } + } + } + Component { + name: "QQuickActionGroupAttached" + prototype: "QObject" + Property { name: "group"; type: "QQuickActionGroup"; isPointer: true } + } + Component { name: "QQuickApplicationWindow" defaultProperty: "contentData" prototype: "QQuickWindowQmlImpl" @@ -389,6 +474,35 @@ Module { Property { name: "label"; type: "QQuickItem"; isPointer: true } } Component { + name: "QQuickIcon" + prototype: "QObject" + Property { name: "name"; type: "string" } + Property { name: "source"; type: "string" } + Property { name: "width"; type: "int" } + Property { name: "height"; type: "int" } + Property { name: "color"; type: "QColor" } + Signal { + name: "nameChanged" + Parameter { name: "name"; type: "string" } + } + Signal { + name: "sourceChanged" + Parameter { name: "source"; type: "string" } + } + Signal { + name: "widthChanged" + Parameter { name: "width"; type: "int" } + } + Signal { + name: "heightChanged" + Parameter { name: "height"; type: "int" } + } + Signal { + name: "colorChanged" + Parameter { name: "color"; type: "QColor" } + } + } + Component { name: "QQuickItemDelegate" defaultProperty: "data" prototype: "QQuickAbstractButton" @@ -627,9 +741,10 @@ Module { exports: [ "QtQuick.Templates/RangeSlider 2.0", "QtQuick.Templates/RangeSlider 2.1", - "QtQuick.Templates/RangeSlider 2.2" + "QtQuick.Templates/RangeSlider 2.2", + "QtQuick.Templates/RangeSlider 2.3" ] - exportMetaObjectRevisions: [0, 1, 2] + exportMetaObjectRevisions: [0, 1, 2, 3] Enum { name: "SnapMode" values: { @@ -645,6 +760,8 @@ Module { Property { name: "stepSize"; type: "double" } Property { name: "snapMode"; type: "SnapMode" } Property { name: "orientation"; type: "Qt::Orientation" } + Property { name: "horizontal"; revision: 3; type: "bool"; isReadonly: true } + Property { name: "vertical"; revision: 3; type: "bool"; isReadonly: true } Property { name: "live"; revision: 2; type: "bool" } Signal { name: "liveChanged"; revision: 2 } Method { @@ -680,9 +797,10 @@ Module { prototype: "QQuickControl" exports: [ "QtQuick.Templates/ScrollBar 2.0", - "QtQuick.Templates/ScrollBar 2.2" + "QtQuick.Templates/ScrollBar 2.2", + "QtQuick.Templates/ScrollBar 2.3" ] - exportMetaObjectRevisions: [0, 2] + exportMetaObjectRevisions: [0, 2, 3] attachedType: "QQuickScrollBarAttached" Enum { name: "SnapMode" @@ -709,6 +827,8 @@ Module { Property { name: "snapMode"; revision: 2; type: "SnapMode" } Property { name: "interactive"; revision: 2; type: "bool" } Property { name: "policy"; revision: 2; type: "Policy" } + Property { name: "horizontal"; revision: 3; type: "bool"; isReadonly: true } + Property { name: "vertical"; revision: 3; type: "bool"; isReadonly: true } Signal { name: "snapModeChanged"; revision: 2 } Signal { name: "interactiveChanged"; revision: 2 } Signal { name: "policyChanged"; revision: 2 } @@ -733,13 +853,18 @@ Module { name: "QQuickScrollIndicator" defaultProperty: "data" prototype: "QQuickControl" - exports: ["QtQuick.Templates/ScrollIndicator 2.0"] - exportMetaObjectRevisions: [0] + exports: [ + "QtQuick.Templates/ScrollIndicator 2.0", + "QtQuick.Templates/ScrollIndicator 2.3" + ] + exportMetaObjectRevisions: [0, 3] attachedType: "QQuickScrollIndicatorAttached" Property { name: "size"; type: "double" } Property { name: "position"; type: "double" } Property { name: "active"; type: "bool" } Property { name: "orientation"; type: "Qt::Orientation" } + Property { name: "horizontal"; revision: 3; type: "bool"; isReadonly: true } + Property { name: "vertical"; revision: 3; type: "bool"; isReadonly: true } Method { name: "setSize" Parameter { name: "size"; type: "double" } @@ -773,9 +898,10 @@ Module { exports: [ "QtQuick.Templates/Slider 2.0", "QtQuick.Templates/Slider 2.1", - "QtQuick.Templates/Slider 2.2" + "QtQuick.Templates/Slider 2.2", + "QtQuick.Templates/Slider 2.3" ] - exportMetaObjectRevisions: [0, 1, 2] + exportMetaObjectRevisions: [0, 1, 2, 3] Enum { name: "SnapMode" values: { @@ -793,6 +919,8 @@ Module { Property { name: "snapMode"; type: "SnapMode" } Property { name: "live"; revision: 2; type: "bool" } Property { name: "pressed"; type: "bool" } + Property { name: "horizontal"; revision: 3; type: "bool"; isReadonly: true } + Property { name: "vertical"; revision: 3; type: "bool"; isReadonly: true } Property { name: "orientation"; type: "Qt::Orientation" } Property { name: "handle"; type: "QQuickItem"; isPointer: true } Signal { name: "liveChanged"; revision: 2 } @@ -999,6 +1127,8 @@ Module { attachedType: "QQuickSwipeViewAttached" Property { name: "interactive"; revision: 1; type: "bool" } Property { name: "orientation"; revision: 2; type: "Qt::Orientation" } + Property { name: "horizontal"; revision: 3; type: "bool"; isReadonly: true } + Property { name: "vertical"; revision: 3; type: "bool"; isReadonly: true } Signal { name: "interactiveChanged"; revision: 1 } Signal { name: "orientationChanged"; revision: 2 } } diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp index 263d7fde..9f74a012 100644 --- a/src/imports/templates/qtquicktemplates2plugin.cpp +++ b/src/imports/templates/qtquicktemplates2plugin.cpp @@ -37,6 +37,8 @@ #include <QtQml/qqmlextensionplugin.h> #include <QtQuickTemplates2/private/qquickabstractbutton_p.h> +#include <QtQuickTemplates2/private/qquickaction_p.h> +#include <QtQuickTemplates2/private/qquickactiongroup_p.h> #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> #include <QtQuickTemplates2/private/qquickbusyindicator_p.h> #include <QtQuickTemplates2/private/qquickbutton_p.h> @@ -53,6 +55,7 @@ #include <QtQuickTemplates2/private/qquickdrawer_p.h> #include <QtQuickTemplates2/private/qquickframe_p.h> #include <QtQuickTemplates2/private/qquickgroupbox_p.h> +#include <QtQuickTemplates2/private/qquickicon_p.h> #include <QtQuickTemplates2/private/qquickitemdelegate_p.h> #include <QtQuickTemplates2/private/qquicklabel_p.h> #include <QtQuickTemplates2/private/qquickmenu_p.h> @@ -117,7 +120,7 @@ public: QtQuickTemplates2Plugin(QObject *parent = nullptr); ~QtQuickTemplates2Plugin(); - void registerTypes(const char *uri); + void registerTypes(const char *uri) override; private: #if QT_CONFIG(shortcut) @@ -186,21 +189,21 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri) qmlRegisterType<QQuickSpinButton>(); qmlRegisterType<QQuickStackView>(uri, 2, 0, "StackView"); qmlRegisterType<QQuickStackViewAttached>(); - qmlRegisterType<QQuickSwipeDelegate>(uri, 2, 0, "SwipeDelegate"); qmlRegisterType<QQuickSwipe>(); - qmlRegisterType<QQuickSwipeViewAttached>(); + qmlRegisterType<QQuickSwipeDelegate>(uri, 2, 0, "SwipeDelegate"); qmlRegisterType<QQuickSwipeView>(uri, 2, 0, "SwipeView"); + qmlRegisterType<QQuickSwipeViewAttached>(); qmlRegisterType<QQuickSwitch>(uri, 2, 0, "Switch"); qmlRegisterType<QQuickSwitchDelegate>(uri, 2, 0, "SwitchDelegate"); qmlRegisterType<QQuickTabBar>(uri, 2, 0, "TabBar"); qmlRegisterType<QQuickTabButton>(uri, 2, 0, "TabButton"); - qmlRegisterType<QQuickTextAreaAttached>(); qmlRegisterType<QQuickTextArea>(uri, 2, 0, "TextArea"); + qmlRegisterType<QQuickTextAreaAttached>(); qmlRegisterType<QQuickTextField>(uri, 2, 0, "TextField"); qmlRegisterType<QQuickToolBar>(uri, 2, 0, "ToolBar"); qmlRegisterType<QQuickToolButton>(uri, 2, 0, "ToolButton"); - qmlRegisterType<QQuickToolTipAttached>(); qmlRegisterType<QQuickToolTip>(uri, 2, 0, "ToolTip"); + qmlRegisterType<QQuickToolTipAttached>(); #if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview) qmlRegisterType<QQuickTumblerAttached>(); qmlRegisterType<QQuickTumbler>(uri, 2, 0, "Tumbler"); @@ -209,10 +212,10 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri) // NOTE: register the latest revisions of all template/control base classes to // make revisioned properties available to their subclasses (synced with Qt 5.7) qmlRegisterRevision<QQuickItem, 7>(uri, 2, 0); - qmlRegisterRevision<QQuickWindow, 2>(uri, 2, 0); qmlRegisterRevision<QQuickText, 6>(uri, 2, 0); qmlRegisterRevision<QQuickTextInput, 7>(uri, 2, 0); qmlRegisterRevision<QQuickTextEdit, 7>(uri, 2, 0); + qmlRegisterRevision<QQuickWindow, 2>(uri, 2, 0); qmlRegisterRevision<QWindow, 3>(uri, 2, 0); // QtQuick.Templates 2.1 (new types and revisions in Qt 5.8) @@ -262,6 +265,20 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri) qmlRegisterRevision<QQuickText, 9>(uri, 2, 2); qmlRegisterRevision<QQuickTextInput, 9>(uri, 2, 2); qmlRegisterRevision<QQuickWindowQmlImpl, 2>(uri, 2, 2); + + // QtQuick.Templates 2.3 (new types and revisions in Qt 5.10) + qmlRegisterType<QQuickAbstractButton, 3>(uri, 2, 3, "AbstractButton"); + qmlRegisterType<QQuickAction>(uri, 2, 3, "Action"); + qmlRegisterType<QQuickActionGroup>(uri, 2, 3, "ActionGroup"); + qmlRegisterType<QQuickButtonGroup, 3>(uri, 2, 3, "ButtonGroup"); + qmlRegisterType<QQuickDialog, 2>(uri, 2, 3, "Dialog"); + qmlRegisterType<QQuickDialogButtonBox>(uri, 2, 3, "DialogButtonBox"); + qRegisterMetaType<QQuickIcon>(); + qmlRegisterType<QQuickRangeSlider, 3>(uri, 2, 3, "RangeSlider"); + qmlRegisterType<QQuickScrollBar, 3>(uri, 2, 3, "ScrollBar"); + qmlRegisterType<QQuickScrollIndicator, 3>(uri, 2, 3, "ScrollIndicator"); + qmlRegisterType<QQuickSlider, 3>(uri, 2, 3, "Slider"); + qmlRegisterType<QQuickSpinBox, 3>(uri, 2, 3, "SpinBox"); } QT_END_NAMESPACE diff --git a/src/imports/templates/templates.pro b/src/imports/templates/templates.pro index 28207807..9a95812b 100644 --- a/src/imports/templates/templates.pro +++ b/src/imports/templates/templates.pro @@ -1,6 +1,6 @@ TARGET = qtquicktemplates2plugin TARGETPATH = QtQuick/Templates.2 -IMPORT_VERSION = 2.2 +IMPORT_VERSION = 2.3 QT += qml quick QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2-private diff --git a/src/quickcontrols2/qquickattachedobject.cpp b/src/quickcontrols2/qquickattachedobject.cpp new file mode 100644 index 00000000..bada982e --- /dev/null +++ b/src/quickcontrols2/qquickattachedobject.cpp @@ -0,0 +1,249 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickattachedobject_p.h" + +#include <QtQuick/qquickwindow.h> +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuickTemplates2/private/qquickpopup_p.h> + +QT_BEGIN_NAMESPACE + +static QQuickAttachedObject *attachedObject(const QMetaObject *type, QObject *object, bool create = false) +{ + if (!object) + return nullptr; + int idx = -1; + return qobject_cast<QQuickAttachedObject *>(qmlAttachedPropertiesObject(&idx, object, type, create)); +} + +static QQuickAttachedObject *findAttachedParent(const QMetaObject *type, QObject *object) +{ + QQuickItem *item = qobject_cast<QQuickItem *>(object); + if (item) { + // lookup parent items and popups + QQuickItem *parent = item->parentItem(); + while (parent) { + QQuickAttachedObject *attached = attachedObject(type, parent); + if (attached) + return attached; + + QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent->parent()); + if (popup) + return attachedObject(type, popup); + + parent = parent->parentItem(); + } + + // fallback to item's window + QQuickAttachedObject *attached = attachedObject(type, item->window()); + if (attached) + return attached; + } else { + // lookup popup's window + QQuickPopup *popup = qobject_cast<QQuickPopup *>(object); + if (popup) + return attachedObject(type, popup->popupItem()->window()); + } + + // lookup parent window + QQuickWindow *window = qobject_cast<QQuickWindow *>(object); + if (window) { + QQuickWindow *parentWindow = qobject_cast<QQuickWindow *>(window->parent()); + if (parentWindow) { + QQuickAttachedObject *attached = attachedObject(type, window); + if (attached) + return attached; + } + } + + // fallback to engine (global) + if (object) { + QQmlEngine *engine = qmlEngine(object); + if (engine) { + QByteArray name = QByteArray("_q_") + type->className(); + QQuickAttachedObject *attached = engine->property(name).value<QQuickAttachedObject *>(); + if (!attached) { + attached = attachedObject(type, engine, true); + engine->setProperty(name, QVariant::fromValue(attached)); + } + return attached; + } + } + + return nullptr; +} + +static QList<QQuickAttachedObject *> findAttachedChildren(const QMetaObject *type, QObject *object) +{ + QList<QQuickAttachedObject *> children; + + QQuickItem *item = qobject_cast<QQuickItem *>(object); + if (!item) { + QQuickWindow *window = qobject_cast<QQuickWindow *>(object); + if (window) { + item = window->contentItem(); + + const auto windowChildren = window->children(); + for (QObject *child : windowChildren) { + QQuickWindow *childWindow = qobject_cast<QQuickWindow *>(child); + if (childWindow) { + QQuickAttachedObject *attached = attachedObject(type, childWindow); + if (attached) + children += attached; + } + } + } + } + + if (item) { + const auto childItems = item->childItems(); + for (QQuickItem *child : childItems) { + QQuickAttachedObject *attached = attachedObject(type, child); + if (attached) + children += attached; + else + children += findAttachedChildren(type, child); + } + } + + return children; +} + +static QQuickItem *findAttachedItem(QObject *parent) +{ + QQuickItem *item = qobject_cast<QQuickItem *>(parent); + if (!item) { + QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent); + if (popup) + item = popup->popupItem(); + } + return item; +} + +QQuickAttachedObject::QQuickAttachedObject(QObject *parent) : QObject(parent) +{ + attachTo(parent); +} + +QQuickAttachedObject::QQuickAttachedObject(QObjectPrivate &dd, QObject *parent) + : QObject(dd, parent) +{ + attachTo(parent); +} + +QQuickAttachedObject::~QQuickAttachedObject() +{ + detachFrom(parent()); + setAttachedParent(nullptr); +} + +QList<QQuickAttachedObject *> QQuickAttachedObject::attachedChildren() const +{ + return m_attachedChildren; +} + +QQuickAttachedObject *QQuickAttachedObject::attachedParent() const +{ + return m_attachedParent; +} + +void QQuickAttachedObject::setAttachedParent(QQuickAttachedObject *parent) +{ + if (m_attachedParent != parent) { + QQuickAttachedObject *oldParent = m_attachedParent; + if (m_attachedParent) + m_attachedParent->m_attachedChildren.removeOne(this); + m_attachedParent = parent; + if (parent) + parent->m_attachedChildren.append(this); + attachedParentChange(parent, oldParent); + } +} + +void QQuickAttachedObject::init() +{ + QQuickAttachedObject *attachedParent = findAttachedParent(metaObject(), parent()); + if (attachedParent) + setAttachedParent(attachedParent); + + const QList<QQuickAttachedObject *> attachedChildren = findAttachedChildren(metaObject(), parent()); + for (QQuickAttachedObject *child : attachedChildren) + child->setAttachedParent(this); +} + +void QQuickAttachedObject::attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) +{ + Q_UNUSED(newParent); + Q_UNUSED(oldParent); +} + +void QQuickAttachedObject::itemWindowChanged(QQuickWindow *window) +{ + QQuickAttachedObject *attachedParent = nullptr; + QQuickItem *item = qobject_cast<QQuickItem *>(sender()); + if (item) + attachedParent = findAttachedParent(metaObject(), item); + if (!attachedParent) + attachedParent = attachedObject(metaObject(), window); + setAttachedParent(attachedParent); +} + +void QQuickAttachedObject::itemParentChanged(QQuickItem *item, QQuickItem *parent) +{ + Q_UNUSED(parent); + setAttachedParent(findAttachedParent(metaObject(), item)); +} + +void QQuickAttachedObject::attachTo(QObject *object) +{ + QQuickItem *item = findAttachedItem(object); + if (item) { + connect(item, &QQuickItem::windowChanged, this, &QQuickAttachedObject::itemWindowChanged); + QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent); + } +} + +void QQuickAttachedObject::detachFrom(QObject *object) +{ + QQuickItem *item = findAttachedItem(object); + if (item) { + disconnect(item, &QQuickItem::windowChanged, this, &QQuickAttachedObject::itemWindowChanged); + QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent); + } +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyleattached_p.h b/src/quickcontrols2/qquickattachedobject_p.h index ed5a5417..5d4194ef 100644 --- a/src/quickcontrols2/qquickstyleattached_p.h +++ b/src/quickcontrols2/qquickattachedobject_p.h @@ -34,8 +34,8 @@ ** ****************************************************************************/ -#ifndef QQUICKSTYLEATTACHED_P_H -#define QQUICKSTYLEATTACHED_P_H +#ifndef QQUICKATTACHEDOBJECT_P_H +#define QQUICKATTACHEDOBJECT_P_H // // W A R N I N G @@ -52,43 +52,44 @@ #include <QtCore/qlist.h> #include <QtCore/qobject.h> #include <QtCore/qpointer.h> -#include <QtCore/qsharedpointer.h> #include <QtQuick/private/qquickitemchangelistener_p.h> #include <QtQuickControls2/private/qtquickcontrols2global_p.h> QT_BEGIN_NAMESPACE -class QSettings; class QQuickWindow; -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStyleAttached : public QObject, public QQuickItemChangeListener +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickAttachedObject : public QObject, public QQuickItemChangeListener { Q_OBJECT public: - explicit QQuickStyleAttached(QObject *parent = nullptr); - ~QQuickStyleAttached(); + explicit QQuickAttachedObject(QObject *parent = nullptr); + ~QQuickAttachedObject(); - static QSharedPointer<QSettings> settings(const QString &group = QString()); + QList<QQuickAttachedObject *> attachedChildren() const; -protected: - void init(); + QQuickAttachedObject *attachedParent() const; + void setAttachedParent(QQuickAttachedObject *parent); - QList<QQuickStyleAttached *> childStyles() const; +protected: + QQuickAttachedObject(QObjectPrivate &dd, QObject *parent = nullptr); - QQuickStyleAttached *parentStyle() const; - void setParentStyle(QQuickStyleAttached *style); + void init(); - virtual void parentStyleChange(QQuickStyleAttached *newParent, QQuickStyleAttached *oldParent); + virtual void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent); void itemWindowChanged(QQuickWindow *window); void itemParentChanged(QQuickItem *item, QQuickItem *parent) override; private: - QList<QQuickStyleAttached *> m_childStyles; - QPointer<QQuickStyleAttached> m_parentStyle; + void attachTo(QObject *object); + void detachFrom(QObject *object); + + QList<QQuickAttachedObject *> m_attachedChildren; + QPointer<QQuickAttachedObject> m_attachedParent; }; QT_END_NAMESPACE -#endif // QQUICKSTYLEATTACHED_P_H +#endif // QQUICKATTACHEDOBJECT_P_H diff --git a/src/quickcontrols2/qquickcolor.cpp b/src/quickcontrols2/qquickcolor.cpp new file mode 100644 index 00000000..bede2a88 --- /dev/null +++ b/src/quickcontrols2/qquickcolor.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickcolor_p.h" + +QT_BEGIN_NAMESPACE + +QQuickColor::QQuickColor(QObject *parent) : + QObject(parent) +{ +} + +QColor QQuickColor::transparent(const QColor &color, qreal opacity) const +{ + return QColor(color.red(), color.green(), color.blue(), qBound(0.0, opacity, 1.0) * 255); +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickcolorimageprovider_p.h b/src/quickcontrols2/qquickcolor_p.h index 4b7a34b9..85578359 100644 --- a/src/quickcontrols2/qquickcolorimageprovider_p.h +++ b/src/quickcontrols2/qquickcolor_p.h @@ -34,8 +34,8 @@ ** ****************************************************************************/ -#ifndef QQUICKCOLORIMAGEPROVIDER_P_H -#define QQUICKCOLORIMAGEPROVIDER_P_H +#ifndef QQUICKCOLOR_P_H +#define QQUICKCOLOR_P_H // // W A R N I N G @@ -48,22 +48,22 @@ // We mean it. // -#include <QtQuick/qquickimageprovider.h> +#include <QtCore/qobject.h> +#include <QtGui/qcolor.h> #include <QtQuickControls2/private/qtquickcontrols2global_p.h> QT_BEGIN_NAMESPACE -class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColorImageProvider : public QQuickImageProvider +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColor : public QObject { -public: - QQuickColorImageProvider(const QString &path); + Q_OBJECT - QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override; +public: + explicit QQuickColor(QObject *parent = nullptr); -private: - QString m_path; + Q_INVOKABLE QColor transparent(const QColor &color, qreal opacity) const; }; QT_END_NAMESPACE -#endif // QQUICKOCOLORIMAGEPROVIDER_P_H +#endif // QQUICKCOLOR_P_H diff --git a/src/quickcontrols2/qquickcolorimageprovider.cpp b/src/quickcontrols2/qquickcolorimage.cpp index a6e941b3..430ba6ea 100644 --- a/src/quickcontrols2/qquickcolorimageprovider.cpp +++ b/src/quickcontrols2/qquickcolorimage.cpp @@ -34,47 +34,46 @@ ** ****************************************************************************/ -#include "qquickcolorimageprovider_p.h" +#include "qquickcolorimage_p.h" -#include <QtCore/qdebug.h> -#include <QtGui/qpainter.h> -#include <QtGui/qguiapplication.h> -#include <QtGui/qscreen.h> -#include <QtGui/qicon.h> +#include <QtQuick/private/qquickimagebase_p_p.h> QT_BEGIN_NAMESPACE -QQuickColorImageProvider::QQuickColorImageProvider(const QString &path) - : QQuickImageProvider(Image), m_path(path) +QQuickColorImage::QQuickColorImage(QQuickItem *parent) + : QQuickImage(parent), m_color(Qt::transparent) { } -QImage QQuickColorImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) +QColor QQuickColorImage::color() const { - Q_UNUSED(requestedSize); - - int sep = id.indexOf(QLatin1Char('/')); - const QStringRef name = id.leftRef(sep); - qreal dpr = qApp->primaryScreen()->devicePixelRatio(); - QString file = qt_findAtNxFile(m_path + QLatin1Char('/') + name + QLatin1String(".png"), dpr); + return m_color; +} - QImage image(file); - if (image.isNull()) { - qWarning() << "QQuickColorImageProvider: unknown id:" << id; - return QImage(); - } +void QQuickColorImage::setColor(const QColor &color) +{ + if (m_color == color) + return; - if (size) - *size = image.size(); + m_color = color; + if (isComponentComplete()) + load(); + emit colorChanged(); +} - const QString color = id.mid(sep + 1); - if (!color.isEmpty()) { - QPainter painter(&image); - painter.setCompositionMode(QPainter::CompositionMode_SourceIn); - painter.fillRect(image.rect(), QColor(color)); +void QQuickColorImage::pixmapChange() +{ + QQuickImage::pixmapChange(); + if (m_color.alpha() > 0) { + QQuickImageBasePrivate *d = static_cast<QQuickImageBasePrivate *>(QQuickItemPrivate::get(this)); + QImage image = d->pix.image(); + if (!image.isNull()) { + QPainter painter(&image); + painter.setCompositionMode(QPainter::CompositionMode_SourceIn); + painter.fillRect(image.rect(), m_color); + d->pix.setImage(image); + } } - - return image; } QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickcolorimage_p.h b/src/quickcontrols2/qquickcolorimage_p.h new file mode 100644 index 00000000..8b0f769d --- /dev/null +++ b/src/quickcontrols2/qquickcolorimage_p.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKCOLORIMAGE_P_H +#define QQUICKCOLORIMAGE_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. +// + +#include <QtGui/qcolor.h> +#include <QtQuick/private/qquickimage_p.h> +#include <QtQuickControls2/private/qtquickcontrols2global_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColorImage : public QQuickImage +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) + +public: + explicit QQuickColorImage(QQuickItem *parent = nullptr); + + QColor color() const; + void setColor(const QColor &color); + +Q_SIGNALS: + void colorChanged(); + +protected: + void pixmapChange() override; + +private: + QColor m_color; +}; + +QT_END_NAMESPACE + +#endif // QQUICKCOLORIMAGE_P_H diff --git a/src/quickcontrols2/qquickiconimage.cpp b/src/quickcontrols2/qquickiconimage.cpp new file mode 100644 index 00000000..c628c7ae --- /dev/null +++ b/src/quickcontrols2/qquickiconimage.cpp @@ -0,0 +1,221 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickiconimage_p.h" +#include "qquickiconimage_p_p.h" + +#include <QtCore/qmath.h> +#include <QtQuick/private/qquickimagebase_p_p.h> + +QT_BEGIN_NAMESPACE + +QQuickIconImagePrivate::QQuickIconImagePrivate() + : color(Qt::transparent), + updatingIcon(false), + isThemeIcon(false), + updatingFillMode(false) +{ +} + +bool QQuickIconImagePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio) +{ + if (isThemeIcon) { + devicePixelRatio = calculateDevicePixelRatio(); + return true; + } + + return QQuickImagePrivate::updateDevicePixelRatio(targetDevicePixelRatio); +} + +void QQuickIconImagePrivate::updateIcon() +{ + Q_Q(QQuickIconImage); + // Both geometryChanged() and QQuickImageBase::sourceSizeChanged() + // (which we connect to updateIcon() in the constructor) can be called as a result + // of updateIcon() changing the various sizes, so we must check that we're not recursing. + if (updatingIcon) + return; + + updatingIcon = true; + + QSize size = sourcesize; + // If no size is specified for theme icons, it will use the smallest available size. + if (size.width() <= 0) + size.setWidth(q->width()); + if (size.height() <= 0) + size.setHeight(q->height()); + + const qreal dpr = calculateDevicePixelRatio(); + const QIconLoaderEngineEntry *entry = QIconLoaderEngine::entryForSize(icon, size * dpr, qCeil(dpr)); + + if (entry) { + QQmlContext *context = qmlContext(q); + const QUrl entryUrl = QUrl::fromLocalFile(entry->filename); + url = context ? context->resolvedUrl(entryUrl) : entryUrl; + isThemeIcon = true; + } else { + url = source; + isThemeIcon = false; + } + q->load(); + + updatingIcon = false; +} + +void QQuickIconImagePrivate::updateFillMode() +{ + Q_Q(QQuickIconImage); + // If we start with a sourceSize of 28x28 and then set sourceSize.width to 24, the fillMode + // will change to PreserveAspectFit (because pixmapSize.width() > width()), which causes the + // pixmap to be reloaded at its original size of 28x28, which causes the fillMode to change + // to Pad (because pixmapSize.width() <= width()), and so on. + if (updatingFillMode) + return; + + updatingFillMode = true; + + const QSize pixmapSize = QSize(pix.width(), pix.height()) / calculateDevicePixelRatio(); + if (pixmapSize.width() > q->width() || pixmapSize.height() > q->height()) + q->setFillMode(QQuickImage::PreserveAspectFit); + else + q->setFillMode(QQuickImage::Pad); + + updatingFillMode = false; +} + +qreal QQuickIconImagePrivate::calculateDevicePixelRatio() const +{ + Q_Q(const QQuickIconImage); + return q->window() ? q->window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio(); +} + +QQuickIconImage::QQuickIconImage(QQuickItem *parent) + : QQuickImage(*(new QQuickIconImagePrivate), parent) +{ + Q_D(QQuickIconImage); + setFillMode(Pad); + QObjectPrivate::connect(this, &QQuickImageBase::sourceSizeChanged, d, &QQuickIconImagePrivate::updateIcon); +} + +QString QQuickIconImage::name() const +{ + Q_D(const QQuickIconImage); + return d->icon.iconName; +} + +void QQuickIconImage::setName(const QString &name) +{ + Q_D(QQuickIconImage); + if (d->icon.iconName == name) + return; + + d->icon = QIconLoader::instance()->loadIcon(name); + if (isComponentComplete()) + d->updateIcon(); + emit nameChanged(); +} + +QColor QQuickIconImage::color() const +{ + Q_D(const QQuickIconImage); + return d->color; +} + +void QQuickIconImage::setColor(const QColor &color) +{ + Q_D(QQuickIconImage); + if (d->color == color) + return; + + d->color = color; + if (isComponentComplete()) + d->updateIcon(); + emit colorChanged(); +} + +void QQuickIconImage::setSource(const QUrl &source) +{ + Q_D(QQuickIconImage); + if (d->source == source) + return; + + d->source = source; + if (isComponentComplete()) + d->updateIcon(); + emit sourceChanged(source); +} + +void QQuickIconImage::componentComplete() +{ + Q_D(QQuickIconImage); + QQuickImage::componentComplete(); + d->updateIcon(); +} + +void QQuickIconImage::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickIconImage); + QQuickImage::geometryChanged(newGeometry, oldGeometry); + if (isComponentComplete() && newGeometry.size() != oldGeometry.size()) + d->updateIcon(); +} + +void QQuickIconImage::itemChange(ItemChange change, const ItemChangeData &value) +{ + Q_D(QQuickIconImage); + if (change == ItemDevicePixelRatioHasChanged) + d->updateIcon(); + QQuickImage::itemChange(change, value); +} + +void QQuickIconImage::pixmapChange() +{ + Q_D(QQuickIconImage); + QQuickImage::pixmapChange(); + d->updateFillMode(); + + if (d->color.alpha() > 0) { + QImage image = d->pix.image(); + if (!image.isNull()) { + QPainter painter(&image); + painter.setCompositionMode(QPainter::CompositionMode_SourceIn); + painter.fillRect(image.rect(), d->color); + d->pix.setImage(image); + } + } +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickiconimage_p.h b/src/quickcontrols2/qquickiconimage_p.h new file mode 100644 index 00000000..b1af767e --- /dev/null +++ b/src/quickcontrols2/qquickiconimage_p.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKICONIMAGE_P_H +#define QQUICKICONIMAGE_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. +// + +#include <QtQuick/private/qquickimage_p.h> +#include <QtQuickControls2/private/qtquickcontrols2global_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickIconImagePrivate; + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconImage : public QQuickImage +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) + +public: + explicit QQuickIconImage(QQuickItem *parent = nullptr); + + QString name() const; + void setName(const QString &name); + + QColor color() const; + void setColor(const QColor &color); + + void setSource(const QUrl &url) override; + +Q_SIGNALS: + void nameChanged(); + void colorChanged(); + +protected: + void componentComplete() override; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; + void itemChange(ItemChange change, const ItemChangeData &value) override; + void pixmapChange() override; + +private: + Q_DISABLE_COPY(QQuickIconImage) + Q_DECLARE_PRIVATE(QQuickIconImage) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickIconImage) + +#endif // QQUICKICONIMAGE_P_H diff --git a/src/quickcontrols2/qquickiconimage_p_p.h b/src/quickcontrols2/qquickiconimage_p_p.h new file mode 100644 index 00000000..8e8012bf --- /dev/null +++ b/src/quickcontrols2/qquickiconimage_p_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKICONIMAGE_P_P_H +#define QQUICKICONIMAGE_P_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. +// + +#include <QtQuick/private/qquickimage_p_p.h> +#include <QtQuickControls2/private/qtquickcontrols2global_p.h> +#include <QtGui/private/qiconloader_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconImagePrivate : public QQuickImagePrivate +{ + Q_DECLARE_PUBLIC(QQuickIconImage) + +public: + QQuickIconImagePrivate(); + + void updateIcon(); + void updateFillMode(); + qreal calculateDevicePixelRatio() const; + bool updateDevicePixelRatio(qreal targetDevicePixelRatio) override; + + QUrl source; + QColor color; + QThemeIconInfo icon; + bool updatingIcon; + bool isThemeIcon; + bool updatingFillMode; +}; + +QT_END_NAMESPACE + +#endif // QQUICKICONIMAGE_P_P_H diff --git a/src/quickcontrols2/qquickiconlabel.cpp b/src/quickcontrols2/qquickiconlabel.cpp new file mode 100644 index 00000000..06d74d43 --- /dev/null +++ b/src/quickcontrols2/qquickiconlabel.cpp @@ -0,0 +1,634 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickiconlabel_p.h" +#include "qquickiconlabel_p_p.h" +#include "qquickiconimage_p.h" + +#include <QtGui/private/qguiapplication_p.h> +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/private/qquicktext_p.h> + +QT_BEGIN_NAMESPACE + +static void beginClass(QQuickItem *item) +{ + if (QQmlParserStatus *parserStatus = qobject_cast<QQmlParserStatus *>(item)) + parserStatus->classBegin(); +} + +static void completeComponent(QQuickItem *item) +{ + if (QQmlParserStatus *parserStatus = qobject_cast<QQmlParserStatus *>(item)) + parserStatus->componentComplete(); +} + +QQuickIconLabelPrivate::QQuickIconLabelPrivate() + : mirrored(false), + display(QQuickIconLabel::TextBesideIcon), + alignment(Qt::AlignCenter), + spacing(0), + topPadding(0), + leftPadding(0), + rightPadding(0), + bottomPadding(0), + image(nullptr), + label(nullptr) +{ +} + +bool QQuickIconLabelPrivate::hasIcon() const +{ + return display != QQuickIconLabel::TextOnly && !icon.isEmpty(); +} + +bool QQuickIconLabelPrivate::hasText() const +{ + return display != QQuickIconLabel::IconOnly && !text.isEmpty(); +} + +bool QQuickIconLabelPrivate::createImage() +{ + Q_Q(QQuickIconLabel); + if (image) + return false; + + image = new QQuickIconImage(q); + watchChanges(image); + beginClass(image); + image->setObjectName(QStringLiteral("image")); + image->setName(icon.name()); + image->setSource(icon.source()); + image->setSourceSize(QSize(icon.width(), icon.height())); + image->setColor(icon.color()); + QQmlEngine::setContextForObject(image, qmlContext(q)); + if (componentComplete) + completeComponent(image); + return true; +} + +bool QQuickIconLabelPrivate::destroyImage() +{ + if (!image) + return false; + + unwatchChanges(image); + delete image; + image = nullptr; + return true; +} + +bool QQuickIconLabelPrivate::updateImage() +{ + if (!hasIcon()) + return destroyImage(); + return createImage(); +} + +void QQuickIconLabelPrivate::syncImage() +{ + if (!image || icon.isEmpty()) + return; + + image->setName(icon.name()); + image->setSource(icon.source()); + image->setSourceSize(QSize(icon.width(), icon.height())); + image->setColor(icon.color()); +} + +void QQuickIconLabelPrivate::updateOrSyncImage() +{ + if (updateImage()) { + if (componentComplete) { + updateImplicitSize(); + layout(); + } + } else { + syncImage(); + } +} + +bool QQuickIconLabelPrivate::createLabel() +{ + Q_Q(QQuickIconLabel); + if (label) + return false; + + label = new QQuickText(q); + watchChanges(label); + beginClass(label); + label->setObjectName(QStringLiteral("label")); + label->setFont(font); + label->setColor(color); + label->setElideMode(QQuickText::ElideRight); + label->setText(text); + if (componentComplete) + completeComponent(label); + return true; +} + +bool QQuickIconLabelPrivate::destroyLabel() +{ + if (!label) + return false; + + unwatchChanges(label); + delete label; + label = nullptr; + return true; +} + +bool QQuickIconLabelPrivate::updateLabel() +{ + if (!hasText()) + return destroyLabel(); + return createLabel(); +} + +void QQuickIconLabelPrivate::syncLabel() +{ + if (!label) + return; + + label->setText(text); +} + +void QQuickIconLabelPrivate::updateOrSyncLabel() +{ + if (updateLabel()) { + if (componentComplete) { + updateImplicitSize(); + layout(); + } + } else { + syncLabel(); + } +} + +void QQuickIconLabelPrivate::updateImplicitSize() +{ + Q_Q(QQuickIconLabel); + const bool showIcon = image && hasIcon(); + const bool showText = label && hasText(); + const qreal horizontalPadding = leftPadding + rightPadding; + const qreal verticalPadding = topPadding + bottomPadding; + const qreal iconImplicitWidth = showIcon ? image->implicitWidth() : 0; + const qreal iconImplicitHeight = showIcon ? image->implicitHeight() : 0; + const qreal textImplicitWidth = showText ? label->implicitWidth() : 0; + const qreal textImplicitHeight = showText ? label->implicitHeight() : 0; + const qreal effectiveSpacing = showText && showIcon && image->implicitWidth() > 0 ? spacing : 0; + const qreal implicitWidth = display == QQuickIconLabel::TextBesideIcon ? iconImplicitWidth + textImplicitWidth + effectiveSpacing + : qMax(iconImplicitWidth, textImplicitWidth); + const qreal implicitHeight = display == QQuickIconLabel::TextUnderIcon ? iconImplicitHeight + textImplicitHeight + effectiveSpacing + : qMax(iconImplicitHeight, textImplicitHeight); + q->setImplicitSize(implicitWidth + horizontalPadding, implicitHeight + verticalPadding); +} + +// adapted from QStyle::alignedRect() +static QRectF alignedRect(bool mirrored, Qt::Alignment alignment, const QSizeF &size, const QRectF &rectangle) +{ + alignment = QGuiApplicationPrivate::visualAlignment(mirrored ? Qt::RightToLeft : Qt::LeftToRight, alignment); + qreal x = rectangle.x(); + qreal y = rectangle.y(); + const qreal w = size.width(); + const qreal h = size.height(); + if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter) + y += rectangle.height() / 2 - h / 2; + else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom) + y += rectangle.height() - h; + if ((alignment & Qt::AlignRight) == Qt::AlignRight) + x += rectangle.width() - w; + else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter) + x += rectangle.width() / 2 - w / 2; + return QRectF(x, y, w, h); +} + +void QQuickIconLabelPrivate::layout() +{ + if (!componentComplete) + return; + + const qreal availableWidth = width - leftPadding - rightPadding; + const qreal availableHeight = height - topPadding - bottomPadding; + + switch (display) { + case QQuickIconLabel::IconOnly: + if (image) { + const QRectF iconRect = alignedRect(mirrored, alignment, + QSizeF(qMin(image->implicitWidth(), availableWidth), + qMin(image->implicitHeight(), availableHeight)), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + image->setSize(iconRect.size()); + image->setPosition(iconRect.topLeft()); + } + break; + case QQuickIconLabel::TextOnly: + if (label) { + const QRectF textRect = alignedRect(mirrored, alignment, + QSizeF(qMin(label->implicitWidth(), availableWidth), + qMin(label->implicitHeight(), availableHeight)), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + label->setSize(textRect.size()); + label->setPosition(textRect.topLeft()); + } + break; + + case QQuickIconLabel::TextUnderIcon: { + // Work out the sizes first, as the positions depend on them. + QSizeF iconSize; + QSizeF textSize; + if (image) { + iconSize.setWidth(qMin(image->implicitWidth(), availableWidth)); + iconSize.setHeight(qMin(image->implicitHeight(), availableHeight)); + } + qreal effectiveSpacing = 0; + if (label) { + if (!iconSize.isEmpty()) + effectiveSpacing = spacing; + textSize.setWidth(qMin(label->implicitWidth(), availableWidth)); + textSize.setHeight(qMin(label->implicitHeight(), availableHeight - iconSize.height() - effectiveSpacing)); + } + + QRectF combinedRect = alignedRect(mirrored, alignment, + QSizeF(qMax(iconSize.width(), textSize.width()), + iconSize.height() + effectiveSpacing + textSize.height()), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + if (image) { + QRectF iconRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignTop, iconSize, combinedRect); + image->setSize(iconRect.size()); + image->setPosition(iconRect.topLeft()); + } + if (label) { + QRectF textRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignBottom, textSize, combinedRect); + label->setSize(textRect.size()); + label->setPosition(textRect.topLeft()); + } + break; + } + + case QQuickIconLabel::TextBesideIcon: + default: + // Work out the sizes first, as the positions depend on them. + QSizeF iconSize(0, 0); + QSizeF textSize(0, 0); + if (image) { + iconSize.setWidth(qMin(image->implicitWidth(), availableWidth)); + iconSize.setHeight(qMin(image->implicitHeight(), availableHeight)); + } + qreal effectiveSpacing = 0; + if (label) { + if (!iconSize.isEmpty()) + effectiveSpacing = spacing; + textSize.setWidth(qMin(label->implicitWidth(), availableWidth - iconSize.width() - effectiveSpacing)); + textSize.setHeight(qMin(label->implicitHeight(), availableHeight)); + } + + const QRectF combinedRect = alignedRect(mirrored, alignment, + QSizeF(iconSize.width() + effectiveSpacing + textSize.width(), + qMax(iconSize.height(), textSize.height())), + QRectF(leftPadding, topPadding, availableWidth, availableHeight)); + if (image) { + const QRectF iconRect = alignedRect(mirrored, Qt::AlignLeft | Qt::AlignVCenter, iconSize, combinedRect); + image->setSize(iconRect.size()); + image->setPosition(iconRect.topLeft()); + } + if (label) { + const QRectF textRect = alignedRect(mirrored, Qt::AlignRight | Qt::AlignVCenter, textSize, combinedRect); + label->setSize(textRect.size()); + label->setPosition(textRect.topLeft()); + } + break; + } +} + +static const QQuickItemPrivate::ChangeTypes itemChangeTypes = + QQuickItemPrivate::ImplicitWidth + | QQuickItemPrivate::ImplicitHeight + | QQuickItemPrivate::Destroyed; + +void QQuickIconLabelPrivate::watchChanges(QQuickItem *item) +{ + QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); + itemPrivate->addItemChangeListener(this, itemChangeTypes); +} + +void QQuickIconLabelPrivate::unwatchChanges(QQuickItem* item) +{ + QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); + itemPrivate->removeItemChangeListener(this, itemChangeTypes); +} + +void QQuickIconLabelPrivate::itemImplicitWidthChanged(QQuickItem *) +{ + updateImplicitSize(); + layout(); +} + +void QQuickIconLabelPrivate::itemImplicitHeightChanged(QQuickItem *) +{ + updateImplicitSize(); + layout(); +} + +void QQuickIconLabelPrivate::itemDestroyed(QQuickItem *item) +{ + unwatchChanges(item); + if (item == image) + image = nullptr; + else if (item == label) + label = nullptr; +} + +QQuickIconLabel::QQuickIconLabel(QQuickItem *parent) + : QQuickItem(*(new QQuickIconLabelPrivate), parent) +{ +} + +QQuickIconLabel::~QQuickIconLabel() +{ + Q_D(QQuickIconLabel); + if (d->image) + d->unwatchChanges(d->image); + if (d->label) + d->unwatchChanges(d->label); +} + +QQuickIcon QQuickIconLabel::icon() const +{ + Q_D(const QQuickIconLabel); + return d->icon; +} + +void QQuickIconLabel::setIcon(const QQuickIcon &icon) +{ + Q_D(QQuickIconLabel); + if (d->icon == icon) + return; + + d->icon = icon; + d->updateOrSyncImage(); +} + +QString QQuickIconLabel::text() const +{ + Q_D(const QQuickIconLabel); + return d->text; +} + +void QQuickIconLabel::setText(const QString text) +{ + Q_D(QQuickIconLabel); + if (d->text == text) + return; + + d->text = text; + d->updateOrSyncLabel(); +} + +QFont QQuickIconLabel::font() const +{ + Q_D(const QQuickIconLabel); + return d->font; +} + +void QQuickIconLabel::setFont(const QFont &font) +{ + Q_D(QQuickIconLabel); + if (d->font == font) + return; + + d->font = font; + if (d->label) + d->label->setFont(font); +} + +QColor QQuickIconLabel::color() const +{ + Q_D(const QQuickIconLabel); + return d->color; +} + +void QQuickIconLabel::setColor(const QColor &color) +{ + Q_D(QQuickIconLabel); + if (d->color == color) + return; + + d->color = color; + if (d->label) + d->label->setColor(color); +} + +QQuickIconLabel::Display QQuickIconLabel::display() const +{ + Q_D(const QQuickIconLabel); + return d->display; +} + +void QQuickIconLabel::setDisplay(Display display) +{ + Q_D(QQuickIconLabel); + if (d->display == display) + return; + + d->display = display; + d->updateImage(); + d->updateLabel(); + d->updateImplicitSize(); + d->layout(); +} + +qreal QQuickIconLabel::spacing() const +{ + Q_D(const QQuickIconLabel); + return d->spacing; +} + +void QQuickIconLabel::setSpacing(qreal spacing) +{ + Q_D(QQuickIconLabel); + if (qFuzzyCompare(d->spacing, spacing)) + return; + + d->spacing = spacing; + if (d->image && d->label) { + d->updateImplicitSize(); + d->layout(); + } +} + +bool QQuickIconLabel::isMirrored() const +{ + Q_D(const QQuickIconLabel); + return d->mirrored; +} + +void QQuickIconLabel::setMirrored(bool mirrored) +{ + Q_D(QQuickIconLabel); + if (d->mirrored == mirrored) + return; + + d->mirrored = mirrored; + d->layout(); +} + +Qt::Alignment QQuickIconLabel::alignment() const +{ + Q_D(const QQuickIconLabel); + return d->alignment; +} + +void QQuickIconLabel::setAlignment(Qt::Alignment alignment) +{ + Q_D(QQuickIconLabel); + const int valign = alignment & Qt::AlignVertical_Mask; + const int halign = alignment & Qt::AlignHorizontal_Mask; + const uint align = (valign ? valign : Qt::AlignVCenter) | (halign ? halign : Qt::AlignHCenter); + if (d->alignment == align) + return; + + d->alignment = static_cast<Qt::Alignment>(align); + d->layout(); +} + +qreal QQuickIconLabel::topPadding() const +{ + Q_D(const QQuickIconLabel); + return d->topPadding; +} + +void QQuickIconLabel::setTopPadding(qreal padding) +{ + Q_D(QQuickIconLabel); + if (qFuzzyCompare(d->topPadding, padding)) + return; + + d->topPadding = padding; + d->updateImplicitSize(); + d->layout(); +} + +void QQuickIconLabel::resetTopPadding() +{ + setTopPadding(0); +} + +qreal QQuickIconLabel::leftPadding() const +{ + Q_D(const QQuickIconLabel); + return d->leftPadding; +} + +void QQuickIconLabel::setLeftPadding(qreal padding) +{ + Q_D(QQuickIconLabel); + if (qFuzzyCompare(d->leftPadding, padding)) + return; + + d->leftPadding = padding; + d->updateImplicitSize(); + d->layout(); +} + +void QQuickIconLabel::resetLeftPadding() +{ + setLeftPadding(0); +} + +qreal QQuickIconLabel::rightPadding() const +{ + Q_D(const QQuickIconLabel); + return d->rightPadding; +} + +void QQuickIconLabel::setRightPadding(qreal padding) +{ + Q_D(QQuickIconLabel); + if (qFuzzyCompare(d->rightPadding, padding)) + return; + + d->rightPadding = padding; + d->updateImplicitSize(); + d->layout(); +} + +void QQuickIconLabel::resetRightPadding() +{ + setRightPadding(0); +} + +qreal QQuickIconLabel::bottomPadding() const +{ + Q_D(const QQuickIconLabel); + return d->bottomPadding; +} + +void QQuickIconLabel::setBottomPadding(qreal padding) +{ + Q_D(QQuickIconLabel); + if (qFuzzyCompare(d->bottomPadding, padding)) + return; + + d->bottomPadding = padding; + d->updateImplicitSize(); + d->layout(); +} + +void QQuickIconLabel::resetBottomPadding() +{ + setBottomPadding(0); +} + +void QQuickIconLabel::componentComplete() +{ + Q_D(QQuickIconLabel); + if (d->image) + completeComponent(d->image); + if (d->label) + completeComponent(d->label); + QQuickItem::componentComplete(); + d->layout(); +} + +void QQuickIconLabel::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickIconLabel); + QQuickItem::geometryChanged(newGeometry, oldGeometry); + d->layout(); +} + +QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickiconlabel_p.h b/src/quickcontrols2/qquickiconlabel_p.h new file mode 100644 index 00000000..df79dbf2 --- /dev/null +++ b/src/quickcontrols2/qquickiconlabel_p.h @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKICONLABEL_P_H +#define QQUICKICONLABEL_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. +// + +#include <QtQuick/qquickitem.h> +#include <QtQuickControls2/private/qtquickcontrols2global_p.h> +#include <QtQuickTemplates2/private/qquickicon_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickIconLabelPrivate; + +class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconLabel : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon FINAL) + Q_PROPERTY(QString text READ text WRITE setText FINAL) + Q_PROPERTY(QFont font READ font WRITE setFont FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor FINAL) + Q_PROPERTY(Display display READ display WRITE setDisplay FINAL) + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing FINAL) + Q_PROPERTY(bool mirrored READ isMirrored WRITE setMirrored FINAL) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment FINAL) + Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding FINAL) + Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding FINAL) + Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding FINAL) + Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding FINAL) + +public: + enum Display { + IconOnly, + TextOnly, + TextBesideIcon, + TextUnderIcon + }; + Q_ENUM(Display) + + explicit QQuickIconLabel(QQuickItem *parent = nullptr); + ~QQuickIconLabel(); + + QQuickIcon icon() const; + void setIcon(const QQuickIcon &icon); + + QString text() const; + void setText(const QString text); + + QFont font() const; + void setFont(const QFont &font); + + QColor color() const; + void setColor(const QColor &color); + + Display display() const; + void setDisplay(Display display); + + qreal spacing() const; + void setSpacing(qreal spacing); + + bool isMirrored() const; + void setMirrored(bool mirrored); + + Qt::Alignment alignment() const; + void setAlignment(Qt::Alignment alignment); + + qreal topPadding() const; + void setTopPadding(qreal padding); + void resetTopPadding(); + + qreal leftPadding() const; + void setLeftPadding(qreal padding); + void resetLeftPadding(); + + qreal rightPadding() const; + void setRightPadding(qreal padding); + void resetRightPadding(); + + qreal bottomPadding() const; + void setBottomPadding(qreal padding); + void resetBottomPadding(); + +protected: + void componentComplete() override; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; + +private: + Q_DISABLE_COPY(QQuickIconLabel) + Q_DECLARE_PRIVATE(QQuickIconLabel) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickIconLabel) + +#endif // QQUICKICONLABEL_P_H diff --git a/src/quickcontrols2/qquickiconlabel_p_p.h b/src/quickcontrols2/qquickiconlabel_p_p.h new file mode 100644 index 00000000..5762187c --- /dev/null +++ b/src/quickcontrols2/qquickiconlabel_p_p.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKICONLABEL_P_P_H +#define QQUICKICONLABEL_P_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. +// + +#include <QtQuick/private/qquickitem_p.h> +#include <QtQuickControls2/private/qtquickcontrols2global_p.h> +#include <QtQuickControls2/private/qquickiconlabel_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickText; +class QQuickIconImage; + +class QQuickIconLabelPrivate : public QQuickItemPrivate, public QQuickItemChangeListener +{ + Q_DECLARE_PUBLIC(QQuickIconLabel) + +public: + explicit QQuickIconLabelPrivate(); + + bool hasIcon() const; + bool hasText() const; + + bool createImage(); + bool destroyImage(); + bool updateImage(); + void syncImage(); + void updateOrSyncImage(); + + bool createLabel(); + bool destroyLabel(); + bool updateLabel(); + void syncLabel(); + void updateOrSyncLabel(); + + void updateImplicitSize(); + void layout(); + + void watchChanges(QQuickItem *item); + void unwatchChanges(QQuickItem *item); + void setPositioningDirty(); + + bool isLeftToRight() const; + + void itemImplicitWidthChanged(QQuickItem *) override; + void itemImplicitHeightChanged(QQuickItem *) override; + void itemDestroyed(QQuickItem *item) override; + + bool mirrored; + QQuickIconLabel::Display display; + Qt::Alignment alignment; + qreal spacing; + qreal topPadding; + qreal leftPadding; + qreal rightPadding; + qreal bottomPadding; + QFont font; + QColor color; + QString text; + QQuickIcon icon; + QQuickIconImage *image; + QQuickText *label; +}; + +QT_END_NAMESPACE + +#endif // QQUICKICONLABEL_P_P_H diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index 184cbfc7..f154f0ce 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -36,13 +36,17 @@ #include "qquickstyle.h" #include "qquickstyle_p.h" -#include "qquickstyleattached_p.h" #include <QtCore/qdir.h> +#include <QtCore/qfile.h> #include <QtCore/qdebug.h> #include <QtCore/qsettings.h> +#include <QtCore/qfileselector.h> #include <QtCore/qlibraryinfo.h> +#include <QtGui/qcolor.h> +#include <QtGui/qpalette.h> #include <QtGui/private/qguiapplication_p.h> +#include <QtGui/qpa/qplatformtheme.h> #include <QtQml/private/qqmlmetatype_p.h> #include <QtQml/qqmlengine.h> #include <QtQml/qqmlfile.h> @@ -176,7 +180,7 @@ struct QQuickStyleSpec setFallbackStyle(QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_FALLBACK_STYLE")), "QT_QUICK_CONTROLS_FALLBACK_STYLE"); #if QT_CONFIG(settings) if (style.isEmpty() || fallbackStyle.isEmpty()) { - QSharedPointer<QSettings> settings = QQuickStyleAttached::settings(QStringLiteral("Controls")); + QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(QStringLiteral("Controls")); if (settings) { if (style.isEmpty()) style = settings->value(QStringLiteral("Style")).toString(); @@ -313,6 +317,38 @@ QString QQuickStylePrivate::configFilePath() return styleSpec()->resolveConfigFilePath(); } +QSharedPointer<QSettings> QQuickStylePrivate::settings(const QString &group) +{ +#ifndef QT_NO_SETTINGS + const QString filePath = QQuickStylePrivate::configFilePath(); + if (QFile::exists(filePath)) { + QFileSelector selector; + QSettings *settings = new QSettings(selector.select(filePath), QSettings::IniFormat); + if (!group.isEmpty()) + settings->beginGroup(group); + return QSharedPointer<QSettings>(settings); + } +#endif // QT_NO_SETTINGS + return QSharedPointer<QSettings>(); +} + +static bool qt_is_dark_system_theme() +{ + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { + if (const QPalette *systemPalette = theme->palette(QPlatformTheme::SystemPalette)) { + const QColor textColor = systemPalette->color(QPalette::WindowText); + return textColor.red() > 128 && textColor.blue() > 128 && textColor.green() > 128; + } + } + return false; +} + +bool QQuickStylePrivate::isDarkSystemTheme() +{ + static bool dark = qt_is_dark_system_theme(); + return dark; +} + /*! Returns the name of the application style. diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h index 316783c4..b92df3c2 100644 --- a/src/quickcontrols2/qquickstyle_p.h +++ b/src/quickcontrols2/qquickstyle_p.h @@ -49,10 +49,13 @@ // #include <QtCore/qurl.h> +#include <QtCore/qsharedpointer.h> #include <QtQuickControls2/private/qtquickcontrols2global_p.h> QT_BEGIN_NAMESPACE +class QSettings; + class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePrivate { public: @@ -62,6 +65,8 @@ public: static void init(const QUrl &baseUrl); static void reset(); static QString configFilePath(); + static QSharedPointer<QSettings> settings(const QString &group = QString()); + static bool isDarkSystemTheme(); }; QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyleattached.cpp b/src/quickcontrols2/qquickstyleattached.cpp deleted file mode 100644 index b9a66169..00000000 --- a/src/quickcontrols2/qquickstyleattached.cpp +++ /dev/null @@ -1,269 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/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 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPLv3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or later 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 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickstyleattached_p.h" -#include "qquickstyle_p.h" - -#include <QtCore/qfile.h> -#include <QtCore/qsettings.h> -#include <QtCore/qfileselector.h> -#include <QtGui/qcolor.h> -#include <QtGui/qpalette.h> -#include <QtGui/private/qguiapplication_p.h> -#include <QtGui/qpa/qplatformtheme.h> -#include <QtQuick/qquickwindow.h> -#include <QtQuick/private/qquickitem_p.h> -#include <QtQuickTemplates2/private/qquickpopup_p.h> - -QT_BEGIN_NAMESPACE - -static bool isDarkSystemTheme() -{ - if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { - if (const QPalette *systemPalette = theme->palette(QPlatformTheme::SystemPalette)) { - const QColor textColor = systemPalette->color(QPalette::WindowText); - return textColor.red() > 128 && textColor.blue() > 128 && textColor.green() > 128; - } - } - return false; -} - -Q_QUICKCONTROLS2_PRIVATE_EXPORT bool qt_is_dark_system_theme() -{ - static bool dark = isDarkSystemTheme(); - return dark; -} - -static QQuickStyleAttached *attachedStyle(const QMetaObject *type, QObject *object, bool create = false) -{ - if (!object) - return nullptr; - int idx = -1; - return qobject_cast<QQuickStyleAttached *>(qmlAttachedPropertiesObject(&idx, object, type, create)); -} - -static QQuickStyleAttached *findParentStyle(const QMetaObject *type, QObject *object) -{ - QQuickItem *item = qobject_cast<QQuickItem *>(object); - if (item) { - // lookup parent items and popups - QQuickItem *parent = item->parentItem(); - while (parent) { - QQuickStyleAttached *style = attachedStyle(type, parent); - if (style) - return style; - - QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent->parent()); - if (popup) - return attachedStyle(type, popup); - - parent = parent->parentItem(); - } - - // fallback to item's window - QQuickStyleAttached *style = attachedStyle(type, item->window()); - if (style) - return style; - } else { - // lookup popup's window - QQuickPopup *popup = qobject_cast<QQuickPopup *>(object); - if (popup) - return attachedStyle(type, popup->popupItem()->window()); - } - - // lookup parent window - QQuickWindow *window = qobject_cast<QQuickWindow *>(object); - if (window) { - QQuickWindow *parentWindow = qobject_cast<QQuickWindow *>(window->parent()); - if (parentWindow) { - QQuickStyleAttached *style = attachedStyle(type, window); - if (style) - return style; - } - } - - // fallback to engine (global) - if (object) { - QQmlEngine *engine = qmlEngine(object); - if (engine) { - QByteArray name = QByteArray("_q_") + type->className(); - QQuickStyleAttached *style = engine->property(name).value<QQuickStyleAttached*>(); - if (!style) { - style = attachedStyle(type, engine, true); - engine->setProperty(name, QVariant::fromValue(style)); - } - return style; - } - } - - return nullptr; -} - -static QList<QQuickStyleAttached *> findChildStyles(const QMetaObject *type, QObject *object) -{ - QList<QQuickStyleAttached *> children; - - QQuickItem *item = qobject_cast<QQuickItem *>(object); - if (!item) { - QQuickWindow *window = qobject_cast<QQuickWindow *>(object); - if (window) { - item = window->contentItem(); - - const auto windowChildren = window->children(); - for (QObject *child : windowChildren) { - QQuickWindow *childWindow = qobject_cast<QQuickWindow *>(child); - if (childWindow) { - QQuickStyleAttached *style = attachedStyle(type, childWindow); - if (style) - children += style; - } - } - } - } - - if (item) { - const auto childItems = item->childItems(); - for (QQuickItem *child : childItems) { - QQuickStyleAttached *style = attachedStyle(type, child); - if (style) - children += style; - else - children += findChildStyles(type, child); - } - } - - return children; -} - -QQuickStyleAttached::QQuickStyleAttached(QObject *parent) : QObject(parent) -{ - QQuickItem *item = qobject_cast<QQuickItem *>(parent); - if (!item) { - QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent); - if (popup) - item = popup->popupItem(); - } - - if (item) { - connect(item, &QQuickItem::windowChanged, this, &QQuickStyleAttached::itemWindowChanged); - QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent); - } -} - -QQuickStyleAttached::~QQuickStyleAttached() -{ - QQuickItem *item = qobject_cast<QQuickItem *>(parent()); - if (item) { - disconnect(item, &QQuickItem::windowChanged, this, &QQuickStyleAttached::itemWindowChanged); - QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent); - } - - setParentStyle(nullptr); -} - -QSharedPointer<QSettings> QQuickStyleAttached::settings(const QString &group) -{ -#ifndef QT_NO_SETTINGS - const QString filePath = QQuickStylePrivate::configFilePath(); - if (QFile::exists(filePath)) { - QFileSelector selector; - QSettings *settings = new QSettings(selector.select(filePath), QSettings::IniFormat); - if (!group.isEmpty()) - settings->beginGroup(group); - return QSharedPointer<QSettings>(settings); - } -#endif // QT_NO_SETTINGS - return QSharedPointer<QSettings>(); -} - -QList<QQuickStyleAttached *> QQuickStyleAttached::childStyles() const -{ - return m_childStyles; -} - -QQuickStyleAttached *QQuickStyleAttached::parentStyle() const -{ - return m_parentStyle; -} - -void QQuickStyleAttached::setParentStyle(QQuickStyleAttached *style) -{ - if (m_parentStyle != style) { - QQuickStyleAttached *oldParent = m_parentStyle; - if (m_parentStyle) - m_parentStyle->m_childStyles.removeOne(this); - m_parentStyle = style; - if (style) - style->m_childStyles.append(this); - parentStyleChange(style, oldParent); - } -} - -void QQuickStyleAttached::init() -{ - QQuickStyleAttached *parentStyle = findParentStyle(metaObject(), parent()); - if (parentStyle) - setParentStyle(parentStyle); - - const QList<QQuickStyleAttached *> children = findChildStyles(metaObject(), parent()); - for (QQuickStyleAttached *child : children) - child->setParentStyle(this); -} - -void QQuickStyleAttached::parentStyleChange(QQuickStyleAttached *newParent, QQuickStyleAttached *oldParent) -{ - Q_UNUSED(newParent); - Q_UNUSED(oldParent); -} - -void QQuickStyleAttached::itemWindowChanged(QQuickWindow *window) -{ - QQuickStyleAttached *parentStyle = nullptr; - QQuickItem *item = qobject_cast<QQuickItem *>(sender()); - if (item) - parentStyle = findParentStyle(metaObject(), item); - if (!parentStyle) - parentStyle = attachedStyle(metaObject(), window); - setParentStyle(parentStyle); -} - -void QQuickStyleAttached::itemParentChanged(QQuickItem *item, QQuickItem *parent) -{ - Q_UNUSED(parent); - setParentStyle(findParentStyle(metaObject(), item)); -} - -QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyleselector.cpp b/src/quickcontrols2/qquickstyleselector.cpp index 6d04c190..0e403dc1 100644 --- a/src/quickcontrols2/qquickstyleselector.cpp +++ b/src/quickcontrols2/qquickstyleselector.cpp @@ -65,13 +65,21 @@ static QString ensureSlash(const QString &path) return path + QLatin1Char('/'); } +static QStringList prefixedPlatformSelectors(const QChar &prefix) +{ + QStringList selectors = QFileSelectorPrivate::platformSelectors(); + for (int i = 0; i < selectors.count(); ++i) + selectors[i].prepend(prefix); + return selectors; +} + static QStringList allSelectors(const QString &style = QString()) { - static const QStringList platformSelectors = QFileSelectorPrivate::platformSelectors(); + static const QStringList platformSelectors = prefixedPlatformSelectors(QLatin1Char('+')); QStringList selectors = platformSelectors; const QString locale = QLocale().name(); if (!locale.isEmpty()) - selectors += locale; + selectors += QLatin1Char('+') + locale; if (!style.isEmpty()) selectors.prepend(style); return selectors; diff --git a/src/quickcontrols2/quickcontrols2.pri b/src/quickcontrols2/quickcontrols2.pri index a618989e..7124027b 100644 --- a/src/quickcontrols2/quickcontrols2.pri +++ b/src/quickcontrols2/quickcontrols2.pri @@ -1,11 +1,16 @@ HEADERS += \ $$PWD/qquickanimatednode_p.h \ - $$PWD/qquickcolorimageprovider_p.h \ + $$PWD/qquickattachedobject_p.h \ + $$PWD/qquickcolor_p.h \ + $$PWD/qquickcolorimage_p.h \ + $$PWD/qquickiconimage_p.h \ + $$PWD/qquickiconimage_p_p.h \ + $$PWD/qquickiconlabel_p.h \ + $$PWD/qquickiconlabel_p_p.h \ $$PWD/qquickplaceholdertext_p.h \ $$PWD/qquickproxytheme_p.h \ $$PWD/qquickstyle.h \ $$PWD/qquickstyle_p.h \ - $$PWD/qquickstyleattached_p.h \ $$PWD/qquickstyleplugin_p.h \ $$PWD/qquickstyleselector_p.h \ $$PWD/qquickstyleselector_p_p.h \ @@ -13,11 +18,14 @@ HEADERS += \ SOURCES += \ $$PWD/qquickanimatednode.cpp \ - $$PWD/qquickcolorimageprovider.cpp \ + $$PWD/qquickattachedobject.cpp \ + $$PWD/qquickcolor.cpp \ + $$PWD/qquickcolorimage.cpp \ + $$PWD/qquickiconimage.cpp \ + $$PWD/qquickiconlabel.cpp \ $$PWD/qquickplaceholdertext.cpp \ $$PWD/qquickproxytheme.cpp \ $$PWD/qquickstyle.cpp \ - $$PWD/qquickstyleattached.cpp \ $$PWD/qquickstyleplugin.cpp \ $$PWD/qquickstyleselector.cpp \ $$PWD/qquickpaddedrectangle.cpp diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp index 0207d2f9..350a196e 100644 --- a/src/quicktemplates2/qquickabstractbutton.cpp +++ b/src/quicktemplates2/qquickabstractbutton.cpp @@ -37,6 +37,8 @@ #include "qquickabstractbutton_p.h" #include "qquickabstractbutton_p_p.h" #include "qquickbuttongroup_p.h" +#include "qquickaction_p.h" +#include "qquickaction_p_p.h" #include <QtGui/qstylehints.h> #include <QtGui/qguiapplication.h> @@ -63,6 +65,56 @@ static const int AUTO_REPEAT_INTERVAL = 100; radio buttons and check boxes. As an abstract control, it has no delegate implementations, leaving them to the types that derive from it. + \section2 Button Icons + + AbstractButton provides the following properties through which icons can + be set: + + \list + \li \l icon.name + \li \l icon.source + \li \l icon.width + \li \l icon.height + \li \l icon.color + \endlist + + For applications that target platforms that support both + \l {QIcon::fromTheme()}{theme icons} and regular icons, + both \l icon.name and \l icon.source can be set to ensure that an icon will + always be found. If the icon is found in the theme, it will always be used; + even if \l icon.source is also set. If the icon is not found, + \l icon.source will be used instead. + + \code + Button { + icon.name: "edit-cut" + icon.source: "qrc:/icons/edit-cut.png" + } + \endcode + + Each \l {Styling Qt Quick Controls 2}{style} sets a default icon size and + color according to their guidelines, but it is possible to override these + by setting the \l icon.width, \l icon.height, and \l icon.color properties. + + The image that is loaded by an icon whose \c width and \c height are not set + depends on the type of icon in use. For theme icons, the closest available + size will be chosen. For regular icons, the behavior is the same as the + \l {Image::}{sourceSize} property of \l Image. + + The icon color is specified by default so that it matches the text color in + different states. In order to use an icon with the original colors, set the + color to \c "transparent". + + \code + Button { + icon.color: "transparent" + icon.source: "qrc:/icons/logo.png" + } + \endcode + + The \l display property can be used to control how the icon and text are + displayed within the button. + \sa ButtonGroup, {Button Controls} */ @@ -126,7 +178,9 @@ QQuickAbstractButtonPrivate::QQuickAbstractButtonPrivate() repeatTimer(0), pressButtons(Qt::NoButton), indicator(nullptr), - group(nullptr) + group(nullptr), + display(QQuickAbstractButton::TextBesideIcon), + action(nullptr) { } @@ -173,7 +227,7 @@ void QQuickAbstractButtonPrivate::handleRelease(const QPointF &point) if (wasPressed) { emit q->released(); if (!wasHeld) - emit q->clicked(); + trigger(); } else { emit q->canceled(); } @@ -249,6 +303,22 @@ void QQuickAbstractButtonPrivate::stopPressRepeat() } } +void QQuickAbstractButtonPrivate::click() +{ + Q_Q(QQuickAbstractButton); + if (effectiveEnable) + emit q->clicked(); +} + +void QQuickAbstractButtonPrivate::trigger() +{ + Q_Q(QQuickAbstractButton); + if (action && action->isEnabled()) + action->trigger(q); // -> click() + else if (effectiveEnable) + emit q->clicked(); +} + void QQuickAbstractButtonPrivate::toggle(bool value) { Q_Q(QQuickAbstractButton); @@ -453,6 +523,8 @@ void QQuickAbstractButton::setChecked(bool checked) setCheckable(true); d->checked = checked; + if (d->action) + d->action->setChecked(checked); setAccessibleProperty("checked", checked); buttonChange(ButtonCheckedChange); emit checkedChanged(); @@ -486,6 +558,8 @@ void QQuickAbstractButton::setCheckable(bool checkable) return; d->checkable = checkable; + if (d->action) + d->action->setCheckable(checkable); setAccessibleProperty("checkable", checkable); buttonChange(ButtonCheckableChange); emit checkableChanged(); @@ -566,6 +640,142 @@ void QQuickAbstractButton::setIndicator(QQuickItem *indicator) } /*! + \qmlpropertygroup QtQuick.Controls::AbstractButton::icon + \qmlproperty string QtQuick.Controls::AbstractButton::icon.name + \qmlproperty url QtQuick.Controls::AbstractButton::icon.source + \qmlproperty int QtQuick.Controls::AbstractButton::icon.width + \qmlproperty int QtQuick.Controls::AbstractButton::icon.height + \qmlproperty color QtQuick.Controls::AbstractButton::icon.color + + This property group was added in QtQuick.Controls 2.3. + + \include qquickicon.qdocinc grouped-properties + + \sa {Button Icons} +*/ + +QQuickIcon QQuickAbstractButton::icon() const +{ + Q_D(const QQuickAbstractButton); + return d->icon; +} + +void QQuickAbstractButton::setIcon(const QQuickIcon &icon) +{ + Q_D(QQuickAbstractButton); + if (d->icon == icon) + return; + + d->icon = icon; + emit iconChanged(); +} + +/*! + \since QtQuick.Controls 2.3 + \qmlproperty enumeration QtQuick.Controls::AbstractButton::display + + This property determines how the \l icon and \l text are displayed within + the button. + + \table + \header \li Display \li Result + \row \li \c AbstractButton.IconOnly \li \image qtquickcontrols2-button-icononly.png + \row \li \c AbstractButton.TextOnly \li \image qtquickcontrols2-button-textonly.png + \row \li \c AbstractButton.TextBesideIcon \li \image qtquickcontrols2-button-textbesideicon.png + \endtable + + \sa {Control::}{spacing}, {Control::}{padding} +*/ +QQuickAbstractButton::Display QQuickAbstractButton::display() const +{ + Q_D(const QQuickAbstractButton); + return d->display; +} + +void QQuickAbstractButton::setDisplay(Display display) +{ + Q_D(QQuickAbstractButton); + if (display == d->display) + return; + + d->display = display; + emit displayChanged(); +} + +/*! + \since QtQuick.Controls 2.3 + \qmlproperty Action QtQuick.Controls::AbstractButton::action + + This property holds the button action. + + \sa Action +*/ +QQuickAction *QQuickAbstractButton::action() const +{ + Q_D(const QQuickAbstractButton); + return d->action; +} + +void QQuickAbstractButton::setAction(QQuickAction *action) +{ + Q_D(QQuickAbstractButton); + if (d->action == action) + return; + + if (QQuickAction *oldAction = d->action.data()) { + QQuickActionPrivate::get(oldAction)->unregisterItem(this); + QObjectPrivate::disconnect(oldAction, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click); + + disconnect(oldAction, &QQuickAction::textChanged, this, &QQuickAbstractButton::setText); + disconnect(oldAction, &QQuickAction::iconChanged, this, &QQuickAbstractButton::setIcon); + disconnect(oldAction, &QQuickAction::checkedChanged, this, &QQuickAbstractButton::setChecked); + disconnect(oldAction, &QQuickAction::checkableChanged, this, &QQuickAbstractButton::setCheckable); + disconnect(oldAction, &QQuickAction::enabledChanged, this, &QQuickItem::setEnabled); + } + + if (action) { + QQuickActionPrivate::get(action)->registerItem(this); + QObjectPrivate::connect(action, &QQuickAction::triggered, d, &QQuickAbstractButtonPrivate::click); + + connect(action, &QQuickAction::textChanged, this, &QQuickAbstractButton::setText); + connect(action, &QQuickAction::iconChanged, this, &QQuickAbstractButton::setIcon); + connect(action, &QQuickAction::checkedChanged, this, &QQuickAbstractButton::setChecked); + connect(action, &QQuickAction::checkableChanged, this, &QQuickAbstractButton::setCheckable); + connect(action, &QQuickAction::enabledChanged, this, &QQuickItem::setEnabled); + + QQuickIcon actionIcon = action->icon(); + + QString name = actionIcon.name(); + if (!name.isEmpty()) + d->icon.setName(name); + + QUrl source = actionIcon.source(); + if (!source.isEmpty()) + d->icon.setSource(source); + + int width = actionIcon.width(); + if (width > 0) + d->icon.setWidth(width); + + int height = actionIcon.height(); + if (height) + d->icon.setHeight(height); + + QColor color = actionIcon.color(); + if (color != Qt::transparent) + d->icon.setColor(color); + + setText(action->text()); + setChecked(action->isChecked()); + setCheckable(action->isCheckable()); + setEnabled(action->isEnabled()); + } + + d->action = action; + emit actionChanged(); +} + +/*! \qmlmethod void QtQuick.Controls::AbstractButton::toggle() Toggles the checked state of the button. @@ -609,7 +819,7 @@ void QQuickAbstractButton::keyReleaseEvent(QKeyEvent *event) nextCheckState(); emit released(); - emit clicked(); + d->trigger(); if (d->autoRepeat) d->stopPressRepeat(); @@ -642,7 +852,7 @@ void QQuickAbstractButton::timerEvent(QTimerEvent *event) d->startPressRepeat(); } else if (event->timerId() == d->repeatTimer) { emit released(); - emit clicked(); + d->trigger(); emit pressed(); } } diff --git a/src/quicktemplates2/qquickabstractbutton_p.h b/src/quicktemplates2/qquickabstractbutton_p.h index 72038ee4..9c372414 100644 --- a/src/quicktemplates2/qquickabstractbutton_p.h +++ b/src/quicktemplates2/qquickabstractbutton_p.h @@ -49,9 +49,11 @@ // #include <QtQuickTemplates2/private/qquickcontrol_p.h> +#include <QtQuickTemplates2/private/qquickicon_p.h> QT_BEGIN_NAMESPACE +class QQuickAction; class QQuickAbstractButtonPrivate; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAbstractButton : public QQuickControl @@ -64,6 +66,9 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAbstractButton : public QQuickContr Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged FINAL) Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive NOTIFY autoExclusiveChanged FINAL) Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) + Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL REVISION 3) + Q_PROPERTY(Display display READ display WRITE setDisplay NOTIFY displayChanged REVISION 3) + Q_PROPERTY(QQuickAction *action READ action WRITE setAction NOTIFY actionChanged FINAL REVISION 3) public: explicit QQuickAbstractButton(QQuickItem *parent = nullptr); @@ -94,6 +99,23 @@ public: QQuickItem *indicator() const; void setIndicator(QQuickItem *indicator); + QQuickIcon icon() const; + void setIcon(const QQuickIcon &icon); + + enum Display { + IconOnly, + TextOnly, + TextBesideIcon, + TextUnderIcon + }; + Q_ENUM(Display) + + Display display() const; + void setDisplay(Display display); + + QQuickAction *action() const; + void setAction(QQuickAction *action); + public Q_SLOTS: void toggle(); @@ -112,6 +134,9 @@ Q_SIGNALS: void checkableChanged(); void autoExclusiveChanged(); void indicatorChanged(); + Q_REVISION(3) void iconChanged(); + Q_REVISION(3) void displayChanged(); + Q_REVISION(3) void actionChanged(); protected: QQuickAbstractButton(QQuickAbstractButtonPrivate &dd, QQuickItem *parent); diff --git a/src/quicktemplates2/qquickabstractbutton_p_p.h b/src/quicktemplates2/qquickabstractbutton_p_p.h index 39af6896..f1fef5e5 100644 --- a/src/quicktemplates2/qquickabstractbutton_p_p.h +++ b/src/quicktemplates2/qquickabstractbutton_p_p.h @@ -53,6 +53,7 @@ QT_BEGIN_NAMESPACE +class QQuickAction; class QQuickButtonGroup; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAbstractButtonPrivate : public QQuickControlPrivate @@ -83,6 +84,8 @@ public: QQuickAbstractButton *findCheckedButton() const; QList<QQuickAbstractButton *> findExclusiveButtons() const; + void click(); + void trigger(); void toggle(bool value); QString text; @@ -98,10 +101,13 @@ public: int holdTimer; int delayTimer; int repeatTimer; + QQuickIcon icon; QPointF pressPoint; Qt::MouseButtons pressButtons; QQuickItem *indicator; QQuickButtonGroup *group; + QQuickAbstractButton::Display display; + QPointer<QQuickAction> action; }; QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquickaction.cpp b/src/quicktemplates2/qquickaction.cpp new file mode 100644 index 00000000..fb6d7c3e --- /dev/null +++ b/src/quicktemplates2/qquickaction.cpp @@ -0,0 +1,553 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickaction_p.h" +#include "qquickaction_p_p.h" +#include "qquickactiongroup_p.h" +#include "qquickshortcutcontext_p_p.h" + +#include <QtGui/qevent.h> +#include <QtGui/private/qshortcutmap_p.h> +#include <QtGui/private/qguiapplication_p.h> +#include <QtQuick/private/qquickitem_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Action + \inherits QtObject + \instantiates QQuickAction + \inqmlmodule QtQuick.Controls + \since 5.10 + \ingroup utilities + \brief Abstract user interface action. + + Action represents an abstract user interface action that can have shortcuts + and can be assigned to menu items and toolbar buttons. + + Actions may contain \l text, an \l icon, and a \l shortcut. Actions are normally + \l triggered by the user via menu items, toolbar buttons, or keyboard shortcuts. + A \l checkable Action toggles its \l checked state when triggered. + + \snippet qtquickcontrols2-action.qml action + + Action is commonly used to implement application commands that can be invoked + via menu items, toolbar buttons, and keyboard shortcuts. Since the user expects + the commands to be performed in the same way, regardless of the user interface + used, it is useful to represent the commands as shareable actions. + + Action can be also used to separate the logic and the visual presentation. For + example, when declaring buttons and menu items in \c .ui.qml files, actions can + be declared elsewhere and assigned from the outside. + + \snippet qtquickcontrols2-action.qml toolbutton + + When an action is paired with buttons and menu items, the \c enabled, \c checkable, + and \c checked states are synced automatically. For example, in a word processor, + if the user clicks a "Bold" toolbar button, the "Bold" menu item will automatically + be checked. Buttons and menu items get their \c text and \c icon from the action by + default. An action-specific \c text or \c icon can be overridden for a specific + control by specifying \c text or \c icon directly on the control. + + \snippet qtquickcontrols2-action.qml menuitem + + Since Action presents a user interface action, it is intended to be assigned to + a \l MenuItem, \l ToolButton, or any other control that inherits \l AbstractButton. + For keyboard shortcuts, the simpler \l Shortcut type is more appropriate. + + \sa MenuItem, ToolButton, Shortcut +*/ + +/*! + \qmlsignal QtQuick.Controls::Action::toggled(QtObject source) + + This signal is emitted when the action is toggled. The \a source argument + identifies the object that toggled the action. + + For example, if the action is assigned to a menu item and a toolbar button, the + action is toggled when the control is toggled, the shortcut is activated, or + when \l toggle() is called directly. +*/ + +/*! + \qmlsignal QtQuick.Controls::Action::triggered(QtObject source) + + This signal is emitted when the action is triggered. The \a source argument + identifies the object that triggered the action. + + For example, if the action is assigned to a menu item and a toolbar button, the + action is triggered when the control is clicked, the shortcut is activated, or + when \l trigger() is called directly. +*/ + +static QKeySequence variantToKeySequence(const QVariant &var) +{ + if (var.type() == QVariant::Int) + return QKeySequence(static_cast<QKeySequence::StandardKey>(var.toInt())); + return QKeySequence::fromString(var.toString()); +} + +QQuickActionPrivate::ShortcutEntry::ShortcutEntry(QObject *target) + : m_shortcutId(0), + m_target(target) +{ +} + +QQuickActionPrivate::ShortcutEntry::~ShortcutEntry() +{ + ungrab(); +} + +QObject *QQuickActionPrivate::ShortcutEntry::target() const +{ + return m_target; +} + +int QQuickActionPrivate::ShortcutEntry::shortcutId() const +{ + return m_shortcutId; +} + +void QQuickActionPrivate::ShortcutEntry::grab(const QKeySequence &shortcut, bool enabled) +{ + if (shortcut.isEmpty()) + return; + + Qt::ShortcutContext context = Qt::WindowShortcut; // TODO + m_shortcutId = QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(m_target, shortcut, context, QQuickShortcutContext::matcher); + + if (!enabled) + QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(false, m_shortcutId, m_target); +} + +void QQuickActionPrivate::ShortcutEntry::ungrab() +{ + if (!m_shortcutId) + return; + + QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(m_shortcutId, m_target); + m_shortcutId = 0; +} + +void QQuickActionPrivate::ShortcutEntry::setEnabled(bool enabled) +{ + if (!m_shortcutId) + return; + + QGuiApplicationPrivate::instance()->shortcutMap.setShortcutEnabled(enabled, m_shortcutId, m_target); +} + +QQuickActionPrivate::QQuickActionPrivate() + : explicitEnabled(false), + enabled(true), + checked(false), + checkable(false), + defaultShortcutEntry(nullptr), + group(nullptr) +{ +} + +QVariant QQuickActionPrivate::shortcut() const +{ + return vshortcut; +} + +void QQuickActionPrivate::setShortcut(const QVariant &var) +{ + Q_Q(QQuickAction); + if (vshortcut == var) + return; + + defaultShortcutEntry->ungrab(); + for (QQuickActionPrivate::ShortcutEntry *entry : qAsConst(shortcutEntries)) + entry->ungrab(); + + vshortcut = var.toString(); + keySequence = variantToKeySequence(var); + + defaultShortcutEntry->grab(keySequence, enabled); + for (QQuickActionPrivate::ShortcutEntry *entry : qAsConst(shortcutEntries)) + entry->grab(keySequence, enabled); + + emit q->shortcutChanged(keySequence); +} + +void QQuickActionPrivate::setEnabled(bool enable) +{ + Q_Q(QQuickAction); + if (enabled == enable) + return; + + enabled = enable; + + defaultShortcutEntry->setEnabled(enable); + for (QQuickActionPrivate::ShortcutEntry *entry : qAsConst(shortcutEntries)) + entry->setEnabled(enable); + + emit q->enabledChanged(enable); +} + +bool QQuickActionPrivate::watchItem(QQuickItem *item) +{ + Q_Q(QQuickAction); + if (!item) + return false; + + item->installEventFilter(q); + QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Visibility | QQuickItemPrivate::Destroyed); + return true; +} + +bool QQuickActionPrivate::unwatchItem(QQuickItem *item) +{ + Q_Q(QQuickAction); + if (!item) + return false; + + item->removeEventFilter(q); + QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Visibility | QQuickItemPrivate::Destroyed); + return true; +} + +void QQuickActionPrivate::registerItem(QQuickItem *item) +{ + if (!watchItem(item)) + return; + + QQuickActionPrivate::ShortcutEntry *entry = new QQuickActionPrivate::ShortcutEntry(item); + if (item->isVisible()) + entry->grab(keySequence, enabled); + shortcutEntries += entry; + + updateDefaultShortcutEntry(); +} + +void QQuickActionPrivate::unregisterItem(QQuickItem *item) +{ + QQuickActionPrivate::ShortcutEntry *entry = findShortcutEntry(item); + if (!entry || !unwatchItem(item)) + return; + + shortcutEntries.removeOne(entry); + delete entry; + + updateDefaultShortcutEntry(); +} + +void QQuickActionPrivate::itemVisibilityChanged(QQuickItem *item) +{ + QQuickActionPrivate::ShortcutEntry *entry = findShortcutEntry(item); + if (!entry) + return; + + if (item->isVisible()) + entry->grab(keySequence, enabled); + else + entry->ungrab(); + + updateDefaultShortcutEntry(); +} + +void QQuickActionPrivate::itemDestroyed(QQuickItem *item) +{ + unregisterItem(item); +} + +bool QQuickActionPrivate::handleShortcutEvent(QObject *object, QShortcutEvent *event) +{ + Q_Q(QQuickAction); + if (event->key() != keySequence) + return false; + + QQuickActionPrivate::ShortcutEntry *entry = findShortcutEntry(object); + if (!entry || event->shortcutId() != entry->shortcutId()) + return false; + + q->trigger(entry->target()); + return true; +} + +QQuickActionPrivate::ShortcutEntry *QQuickActionPrivate::findShortcutEntry(QObject *target) const +{ + Q_Q(const QQuickAction); + if (target == q) + return defaultShortcutEntry; + for (QQuickActionPrivate::ShortcutEntry *entry : shortcutEntries) { + if (entry->target() == target) + return entry; + } + return nullptr; +} + +void QQuickActionPrivate::updateDefaultShortcutEntry() +{ + bool hasActiveShortcutEntries = false; + for (QQuickActionPrivate::ShortcutEntry *entry : qAsConst(shortcutEntries)) { + if (entry->shortcutId()) { + hasActiveShortcutEntries = true; + break; + } + } + + if (hasActiveShortcutEntries) + defaultShortcutEntry->ungrab(); + else if (!defaultShortcutEntry->shortcutId()) + defaultShortcutEntry->grab(keySequence, enabled); +} + +QQuickAction::QQuickAction(QObject *parent) + : QObject(*(new QQuickActionPrivate), parent) +{ + Q_D(QQuickAction); + d->defaultShortcutEntry = new QQuickActionPrivate::ShortcutEntry(this); +} + +QQuickAction::~QQuickAction() +{ + Q_D(QQuickAction); + if (d->group) + d->group->removeAction(this); + + for (QQuickActionPrivate::ShortcutEntry *entry : qAsConst(d->shortcutEntries)) + d->unwatchItem(qobject_cast<QQuickItem *>(entry->target())); + + qDeleteAll(d->shortcutEntries); + delete d->defaultShortcutEntry; +} + +/*! + \qmlproperty string QtQuick.Controls::Action::text + + This property holds a textual description of the action. +*/ +QString QQuickAction::text() const +{ + Q_D(const QQuickAction); + return d->text; +} + +void QQuickAction::setText(const QString &text) +{ + Q_D(QQuickAction); + if (d->text == text) + return; + + d->text = text; + emit textChanged(text); +} + +/*! + \qmlpropertygroup QtQuick.Controls::Action::icon + \qmlproperty string QtQuick.Controls::Action::icon.name + \qmlproperty url QtQuick.Controls::Action::icon.source + \qmlproperty int QtQuick.Controls::Action::icon.width + \qmlproperty int QtQuick.Controls::Action::icon.height + \qmlproperty color QtQuick.Controls::Action::icon.color + + \include qquickicon.qdocinc grouped-properties +*/ +QQuickIcon QQuickAction::icon() const +{ + Q_D(const QQuickAction); + return d->icon; +} + +void QQuickAction::setIcon(const QQuickIcon &icon) +{ + Q_D(QQuickAction); + if (d->icon == icon) + return; + + d->icon = icon; + emit iconChanged(icon); +} + +/*! + \qmlproperty bool QtQuick.Controls::Action::enabled + + This property holds whether the action is enabled. The default value is \c true. +*/ +bool QQuickAction::isEnabled() const +{ + Q_D(const QQuickAction); + return d->enabled && (!d->group || d->group->isEnabled()); +} + +void QQuickAction::setEnabled(bool enabled) +{ + Q_D(QQuickAction); + d->explicitEnabled = true; + d->setEnabled(enabled); +} + +void QQuickAction::resetEnabled() +{ + Q_D(QQuickAction); + if (!d->explicitEnabled) + return; + + d->explicitEnabled = false; + d->setEnabled(true); +} + +/*! + \qmlproperty bool QtQuick.Controls::Action::checked + + This property holds whether the action is checked. + + \sa checkable +*/ +bool QQuickAction::isChecked() const +{ + Q_D(const QQuickAction); + return d->checked; +} + +void QQuickAction::setChecked(bool checked) +{ + Q_D(QQuickAction); + if (d->checked == checked) + return; + + d->checked = checked; + emit checkedChanged(checked); +} + +/*! + \qmlproperty bool QtQuick.Controls::Action::checkable + + This property holds whether the action is checkable. The default value is \c false. + + A checkable action toggles between checked (on) and unchecked (off) when triggered. + + \sa checked +*/ +bool QQuickAction::isCheckable() const +{ + Q_D(const QQuickAction); + return d->checkable; +} + +void QQuickAction::setCheckable(bool checkable) +{ + Q_D(QQuickAction); + if (d->checkable == checkable) + return; + + d->checkable = checkable; + emit checkableChanged(checkable); +} + +/*! + \qmlproperty keysequence QtQuick.Controls::Action::shortcut + + This property holds the action's shortcut. The key sequence can be set + to one of the \l{QKeySequence::StandardKey}{standard keyboard shortcuts}, + or it can be described with a string containing a sequence of up to four + key presses that are needed to trigger the shortcut. + + \code + Action { + sequence: "Ctrl+E,Ctrl+W" + onTriggered: edit.wrapMode = TextEdit.Wrap + } + \endcode +*/ +QKeySequence QQuickAction::shortcut() const +{ + Q_D(const QQuickAction); + return d->keySequence; +} + +void QQuickAction::setShortcut(const QKeySequence &shortcut) +{ + Q_D(QQuickAction); + d->setShortcut(shortcut.toString()); +} + +/*! + \qmlmethod void QtQuick.Controls::Action::toggle(QtObject source = null) + + Toggles the action and emits \l toggled() if enabled, with an optional \a source object defined. +*/ +void QQuickAction::toggle(QObject *source) +{ + Q_D(QQuickAction); + if (!d->enabled) + return; + + if (d->checkable) + setChecked(!d->checked); + + emit toggled(source); +} + +/*! + \qmlmethod void QtQuick.Controls::Action::trigger(QtObject source = null) + + Triggers the action and emits \l triggered() if enabled, with an optional \a source object defined. +*/ +void QQuickAction::trigger(QObject *source) +{ + Q_D(QQuickAction); + if (!d->enabled) + return; + + if (d->checkable) + toggle(source); + + emit triggered(source); +} + +bool QQuickAction::event(QEvent *event) +{ + Q_D(QQuickAction); + if (event->type() != QEvent::Shortcut) + return QObject::event(event); + return d->handleShortcutEvent(this, static_cast<QShortcutEvent *>(event)); +} + +bool QQuickAction::eventFilter(QObject *object, QEvent *event) +{ + Q_D(QQuickAction); + if (event->type() != QEvent::Shortcut) + return false; + return d->handleShortcutEvent(object, static_cast<QShortcutEvent *>(event)); +} + +QT_END_NAMESPACE + +#include "moc_qquickaction_p.cpp" diff --git a/src/quicktemplates2/qquickaction_p.h b/src/quicktemplates2/qquickaction_p.h new file mode 100644 index 00000000..ce989bed --- /dev/null +++ b/src/quicktemplates2/qquickaction_p.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKACTION_P_H +#define QQUICKACTION_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. +// + +#include <QtQuickTemplates2/private/qtquicktemplates2global_p.h> +#include <QtQuickTemplates2/private/qquickicon_p.h> +#include <QtCore/qobject.h> +#include <QtQml/qqml.h> + +QT_BEGIN_NAMESPACE + +class QQuickIcon; +class QQuickActionPrivate; + +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAction : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged FINAL) + Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon NOTIFY iconChanged FINAL) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged RESET resetEnabled FINAL) + Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY checkedChanged FINAL) + Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged FINAL) + Q_PRIVATE_PROPERTY(QQuickAction::d_func(), QVariant shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged FINAL) + +public: + explicit QQuickAction(QObject *parent = nullptr); + ~QQuickAction(); + + QString text() const; + void setText(const QString &text); + + QQuickIcon icon() const; + void setIcon(const QQuickIcon &icon); + + bool isEnabled() const; + void setEnabled(bool enabled); + void resetEnabled(); + + bool isChecked() const; + void setChecked(bool checked); + + bool isCheckable() const; + void setCheckable(bool checkable); + + QKeySequence shortcut() const; + void setShortcut(const QKeySequence &shortcut); + +public Q_SLOTS: + void toggle(QObject *source = nullptr); + void trigger(QObject *source = nullptr); + +Q_SIGNALS: + void textChanged(const QString &text); + void iconChanged(const QQuickIcon &icon); + void enabledChanged(bool enabled); + void checkedChanged(bool checked); + void checkableChanged(bool checkable); + void shortcutChanged(const QKeySequence &shortcut); + + void toggled(QObject *source = nullptr); + void triggered(QObject *source = nullptr); + +protected: + bool event(QEvent *event) override; + bool eventFilter(QObject *object, QEvent *event) override; + +private: + Q_DISABLE_COPY(QQuickAction) + Q_DECLARE_PRIVATE(QQuickAction) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickAction) + +#endif // QQUICKACTION_P_H diff --git a/src/quicktemplates2/qquickaction_p_p.h b/src/quicktemplates2/qquickaction_p_p.h new file mode 100644 index 00000000..08c442ed --- /dev/null +++ b/src/quicktemplates2/qquickaction_p_p.h @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKACTION_P_P_H +#define QQUICKACTION_P_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. +// + +#include <QtCore/private/qobject_p.h> +#include <QtCore/qvariant.h> +#include <QtCore/qstring.h> +#include <QtGui/qkeysequence.h> +#include <QtQuick/private/qquickitemchangelistener_p.h> + +QT_BEGIN_NAMESPACE + +class QShortcutEvent; +class QQuickActionGroup; + +class QQuickActionPrivate : public QObjectPrivate, public QQuickItemChangeListener +{ + Q_DECLARE_PUBLIC(QQuickAction) + +public: + QQuickActionPrivate(); + + static QQuickActionPrivate *get(QQuickAction *action) + { + return action->d_func(); + } + + QVariant shortcut() const; + void setShortcut(const QVariant &shortcut); + + void setEnabled(bool enable); + + bool watchItem(QQuickItem *item); + bool unwatchItem(QQuickItem *item); + + void registerItem(QQuickItem *item); + void unregisterItem(QQuickItem *item); + + void itemVisibilityChanged(QQuickItem *item) override; + void itemDestroyed(QQuickItem *item) override; + + bool handleShortcutEvent(QObject *object, QShortcutEvent *event); + + class ShortcutEntry + { + public: + explicit ShortcutEntry(QObject *target); + ~ShortcutEntry(); + + QObject *target() const; + int shortcutId() const; + + void grab(const QKeySequence &vshortcut, bool enabled); + void ungrab(); + + void setEnabled(bool enabled); + + private: + int m_shortcutId; + QObject *m_target; + }; + + ShortcutEntry *findShortcutEntry(QObject *target) const; + void updateDefaultShortcutEntry(); + + bool explicitEnabled; + bool enabled; + bool checked; + bool checkable; + QString text; + QQuickIcon icon; + QVariant vshortcut; + QKeySequence keySequence; + ShortcutEntry *defaultShortcutEntry; + QVector<ShortcutEntry *> shortcutEntries; + QQuickActionGroup *group; +}; + +QT_END_NAMESPACE + +#endif // QQUICKACTION_P_P_H diff --git a/src/quicktemplates2/qquickactiongroup.cpp b/src/quicktemplates2/qquickactiongroup.cpp new file mode 100644 index 00000000..7a5e17ee --- /dev/null +++ b/src/quicktemplates2/qquickactiongroup.cpp @@ -0,0 +1,474 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickactiongroup_p.h" + +#include <QtCore/private/qobject_p.h> +#include <QtCore/qmetaobject.h> +#include <QtCore/qvariant.h> +#include <QtQml/qqmlinfo.h> + +#include "qquickaction_p.h" +#include "qquickaction_p_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmltype ActionGroup + \inherits QtObject + \instantiates QQuickActionGroup + \inqmlmodule QtQuick.Controls + \since 5.10 + \ingroup utilities + \brief Groups actions together. + + ActionGroup is a non-visual group of actions. A mutually \l exclusive + action group is used with actions where only one of the options can be + selected at a time. + + The most straight-forward way to use ActionGroup is to declare actions + as children of the group. + + \code + ActionGroup { + id: alignmentGroup + + Action { + checked: true + text: qsTr("Left") + } + + Action { + text: qsTr("Center") + } + + Action { + text: qsTr("Right") + } + } + \endcode + + Alternatively, the \l group attached property allows declaring the actions + elsewhere and assigning them to a specific group. + + \code + ActionGroup { id: alignmentGroup } + + Action { + checked: true + text: qsTr("Left") + ActionGroup.group: alignmentGroup + } + + Action { + text: qsTr("Center") + ActionGroup.group: alignmentGroup + } + + Action { + text: qsTr("Right") + ActionGroup.group: alignmentGroup + } + \endcode + + More advanced use cases can be handled using the \c addAction() and + \c removeAction() methods. + + \sa Action, ButtonGroup +*/ + +/*! + \qmlsignal QtQuick.Controls::ActionGroup::triggered(Action action) + + This signal is emitted when an \a action in the group has been triggered. + + This signal is convenient for implementing a common signal handler for + all actions in the same group. + + \code + ActionGroup { + onTriggered: console.log("triggered:", action.text) + + Action { text: "First" } + Action { text: "Second" } + Action { text: "Third" } + } + \endcode + + \sa Action::triggered() +*/ + +class QQuickActionGroupPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QQuickActionGroup) + +public: + QQuickActionGroupPrivate() + : enabled(true), + exclusive(true), + checkedAction(nullptr) + { + } + + void clear(); + void actionTriggered(); + void _q_updateCurrent(); + + static bool changeEnabled(QQuickAction *action, bool enabled); + + static void actions_append(QQmlListProperty<QQuickAction> *prop, QQuickAction *obj); + static int actions_count(QQmlListProperty<QQuickAction> *prop); + static QQuickAction *actions_at(QQmlListProperty<QQuickAction> *prop, int index); + static void actions_clear(QQmlListProperty<QQuickAction> *prop); + + bool enabled; + bool exclusive; + QQuickAction *checkedAction; + QVector<QQuickAction*> actions; +}; + +void QQuickActionGroupPrivate::clear() +{ + for (QQuickAction *action : qAsConst(actions)) { + QQuickActionPrivate::get(action)->group = nullptr; + QObjectPrivate::disconnect(action, &QQuickAction::triggered, this, &QQuickActionGroupPrivate::actionTriggered); + QObjectPrivate::disconnect(action, &QQuickAction::checkedChanged, this, &QQuickActionGroupPrivate::_q_updateCurrent); + } + actions.clear(); +} + +void QQuickActionGroupPrivate::actionTriggered() +{ + Q_Q(QQuickActionGroup); + QQuickAction *action = qobject_cast<QQuickAction*>(q->sender()); + if (action) + emit q->triggered(action); +} + +void QQuickActionGroupPrivate::_q_updateCurrent() +{ + Q_Q(QQuickActionGroup); + if (!exclusive) + return; + QQuickAction *action = qobject_cast<QQuickAction*>(q->sender()); + if (action && action->isChecked()) + q->setCheckedAction(action); + else if (!actions.contains(checkedAction)) + q->setCheckedAction(nullptr); +} + +bool QQuickActionGroupPrivate::changeEnabled(QQuickAction *action, bool enabled) +{ + return action->isEnabled() != enabled && (!enabled || !QQuickActionPrivate::get(action)->explicitEnabled); +} + +void QQuickActionGroupPrivate::actions_append(QQmlListProperty<QQuickAction> *prop, QQuickAction *obj) +{ + QQuickActionGroup *q = static_cast<QQuickActionGroup *>(prop->object); + q->addAction(obj); +} + +int QQuickActionGroupPrivate::actions_count(QQmlListProperty<QQuickAction> *prop) +{ + QQuickActionGroupPrivate *p = static_cast<QQuickActionGroupPrivate *>(prop->data); + return p->actions.count(); +} + +QQuickAction *QQuickActionGroupPrivate::actions_at(QQmlListProperty<QQuickAction> *prop, int index) +{ + QQuickActionGroupPrivate *p = static_cast<QQuickActionGroupPrivate *>(prop->data); + return p->actions.value(index); +} + +void QQuickActionGroupPrivate::actions_clear(QQmlListProperty<QQuickAction> *prop) +{ + QQuickActionGroupPrivate *p = static_cast<QQuickActionGroupPrivate *>(prop->data); + if (!p->actions.isEmpty()) { + p->clear(); + QQuickActionGroup *q = static_cast<QQuickActionGroup *>(prop->object); + // QTBUG-52358: don't clear the checked action immediately + QMetaObject::invokeMethod(q, "_q_updateCurrent", Qt::QueuedConnection); + emit q->actionsChanged(); + } +} + +QQuickActionGroup::QQuickActionGroup(QObject *parent) + : QObject(*(new QQuickActionGroupPrivate), parent) +{ +} + +QQuickActionGroup::~QQuickActionGroup() +{ + Q_D(QQuickActionGroup); + d->clear(); +} + +QQuickActionGroupAttached *QQuickActionGroup::qmlAttachedProperties(QObject *object) +{ + return new QQuickActionGroupAttached(object); +} + +/*! + \qmlproperty Action QtQuick.Controls::ActionGroup::checkedAction + + This property holds the currently selected action in an exclusive group, + or \c null if there is none or the group is non-exclusive. + + By default, it is the first checked action added to an exclusive action group. + + \sa exclusive +*/ +QQuickAction *QQuickActionGroup::checkedAction() const +{ + Q_D(const QQuickActionGroup); + return d->checkedAction; +} + +void QQuickActionGroup::setCheckedAction(QQuickAction *checkedAction) +{ + Q_D(QQuickActionGroup); + if (d->checkedAction == checkedAction) + return; + + if (d->checkedAction) + d->checkedAction->setChecked(false); + d->checkedAction = checkedAction; + if (checkedAction) + checkedAction->setChecked(true); + emit checkedActionChanged(); +} + +/*! + \qmlproperty list<Action> QtQuick.Controls::ActionGroup::actions + \default + + This property holds the list of actions in the group. + + \sa group +*/ +QQmlListProperty<QQuickAction> QQuickActionGroup::actions() +{ + Q_D(QQuickActionGroup); + return QQmlListProperty<QQuickAction>(this, d, + QQuickActionGroupPrivate::actions_append, + QQuickActionGroupPrivate::actions_count, + QQuickActionGroupPrivate::actions_at, + QQuickActionGroupPrivate::actions_clear); +} + +/*! + \qmlproperty bool QtQuick.Controls::ActionGroup::exclusive + + This property holds whether the action group is exclusive. The default value is \c true. + + If this property is \c true, then only one action in the group can be checked at any given time. + The user can trigger any action to check it, and that action will replace the existing one as + the checked action in the group. + + In an exclusive group, the user cannot uncheck the currently checked action by triggering it; + instead, another action in the group must be triggered to set the new checked action for that + group. + + In a non-exclusive group, checking and unchecking actions does not affect the other actions in + the group. Furthermore, the value of the \l checkedAction property is \c null. +*/ +bool QQuickActionGroup::isExclusive() const +{ + Q_D(const QQuickActionGroup); + return d->exclusive; +} + +void QQuickActionGroup::setExclusive(bool exclusive) +{ + Q_D(QQuickActionGroup); + if (d->exclusive == exclusive) + return; + + d->exclusive = exclusive; + emit exclusiveChanged(); +} + +/*! + \qmlproperty bool QtQuick.Controls::ActionGroup::enabled + + This property holds whether the action group is enabled. The default value is \c true. + + If this property is \c false, then all actions in the group are disabled. If this property + is \c true, all actions in the group are enabled, unless explicitly disabled. +*/ +bool QQuickActionGroup::isEnabled() const +{ + Q_D(const QQuickActionGroup); + return d->enabled; +} + +void QQuickActionGroup::setEnabled(bool enabled) +{ + Q_D(QQuickActionGroup); + if (d->enabled == enabled) + return; + + for (QQuickAction *action : qAsConst(d->actions)) { + if (d->changeEnabled(action, enabled)) + emit action->enabledChanged(enabled); + } + + d->enabled = enabled; + emit enabledChanged(); +} + +/*! + \qmlmethod void QtQuick.Controls::ActionGroup::addAction(Action action) + + Adds an \a action to the action group. + + \note Manually adding objects to a action group is typically unnecessary. + The \l actions property and the \l group attached property provide a + convenient and declarative syntax. + + \sa actions, group +*/ +void QQuickActionGroup::addAction(QQuickAction *action) +{ + Q_D(QQuickActionGroup); + if (!action || d->actions.contains(action)) + return; + + const bool enabledChange = d->changeEnabled(action, d->enabled); + + QQuickActionPrivate::get(action)->group = this; + QObjectPrivate::connect(action, &QQuickAction::triggered, d, &QQuickActionGroupPrivate::actionTriggered); + QObjectPrivate::connect(action, &QQuickAction::checkedChanged, d, &QQuickActionGroupPrivate::_q_updateCurrent); + + if (d->exclusive && action->isChecked()) + setCheckedAction(action); + if (enabledChange) + emit action->enabledChanged(action->isEnabled()); + + d->actions.append(action); + emit actionsChanged(); +} + +/*! + \qmlmethod void QtQuick.Controls::ActionGroup::removeAction(Action action) + + Removes an \a action from the action group. + + \note Manually removing objects from a action group is typically unnecessary. + The \l actions property and the \l group attached property provide a + convenient and declarative syntax. + + \sa actions, group +*/ +void QQuickActionGroup::removeAction(QQuickAction *action) +{ + Q_D(QQuickActionGroup); + if (!action || !d->actions.contains(action)) + return; + + const bool enabledChange = d->changeEnabled(action, d->enabled); + + QQuickActionPrivate::get(action)->group = nullptr; + QObjectPrivate::disconnect(action, &QQuickAction::triggered, d, &QQuickActionGroupPrivate::actionTriggered); + QObjectPrivate::disconnect(action, &QQuickAction::checkedChanged, d, &QQuickActionGroupPrivate::_q_updateCurrent); + + if (d->checkedAction == action) + setCheckedAction(nullptr); + if (enabledChange) + emit action->enabledChanged(action->isEnabled()); + + d->actions.removeOne(action); + emit actionsChanged(); +} + +class QQuickActionGroupAttachedPrivate : public QObjectPrivate +{ +public: + QQuickActionGroupAttachedPrivate() : group(nullptr) { } + + QQuickActionGroup *group; +}; + +QQuickActionGroupAttached::QQuickActionGroupAttached(QObject *parent) + : QObject(*(new QQuickActionGroupAttachedPrivate), parent) +{ +} + +/*! + \qmlattachedproperty ActionGroup QtQuick.Controls::ActionGroup::group + + This property attaches an action to an action group. + + \code + ActionGroup { id: group } + + Action { + checked: true + text: qsTr("Option A") + ActionGroup.group: group + } + + Action { + text: qsTr("Option B") + ActionGroup.group: group + } + \endcode + + \sa actions +*/ +QQuickActionGroup *QQuickActionGroupAttached::group() const +{ + Q_D(const QQuickActionGroupAttached); + return d->group; +} + +void QQuickActionGroupAttached::setGroup(QQuickActionGroup *group) +{ + Q_D(QQuickActionGroupAttached); + if (d->group == group) + return; + + if (d->group) + d->group->removeAction(qobject_cast<QQuickAction*>(parent())); + d->group = group; + if (group) + group->addAction(qobject_cast<QQuickAction*>(parent())); + emit groupChanged(); +} + +QT_END_NAMESPACE + +#include "moc_qquickactiongroup_p.cpp" diff --git a/src/quicktemplates2/qquickactiongroup_p.h b/src/quicktemplates2/qquickactiongroup_p.h new file mode 100644 index 00000000..42280831 --- /dev/null +++ b/src/quicktemplates2/qquickactiongroup_p.h @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKACTIONGROUP_P_H +#define QQUICKACTIONGROUP_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. +// + +#include <QtCore/qobject.h> +#include <QtQuickTemplates2/private/qtquicktemplates2global_p.h> +#include <QtQml/qqml.h> + +QT_BEGIN_NAMESPACE + +class QQuickAction; +class QQuickActionGroupPrivate; +class QQuickActionGroupAttached; +class QQuickActionGroupAttachedPrivate; + +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickActionGroup : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickAction *checkedAction READ checkedAction WRITE setCheckedAction NOTIFY checkedActionChanged FINAL) + Q_PROPERTY(QQmlListProperty<QQuickAction> actions READ actions NOTIFY actionsChanged FINAL) + Q_PROPERTY(bool exclusive READ isExclusive WRITE setExclusive NOTIFY exclusiveChanged FINAL) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged FINAL) + +public: + explicit QQuickActionGroup(QObject *parent = nullptr); + ~QQuickActionGroup(); + + static QQuickActionGroupAttached *qmlAttachedProperties(QObject *object); + + QQuickAction *checkedAction() const; + void setCheckedAction(QQuickAction *checkedAction); + + QQmlListProperty<QQuickAction> actions(); + + bool isExclusive() const; + void setExclusive(bool exclusive); + + bool isEnabled() const; + void setEnabled(bool enabled); + +public Q_SLOTS: + void addAction(QQuickAction *action); + void removeAction(QQuickAction *action); + +Q_SIGNALS: + void checkedActionChanged(); + void actionsChanged(); + void exclusiveChanged(); + void enabledChanged(); + void triggered(QQuickAction *action); + +private: + Q_DISABLE_COPY(QQuickActionGroup) + Q_DECLARE_PRIVATE(QQuickActionGroup) + + Q_PRIVATE_SLOT(d_func(), void _q_updateCurrent()) +}; + +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickActionGroupAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickActionGroup *group READ group WRITE setGroup NOTIFY groupChanged FINAL) + +public: + explicit QQuickActionGroupAttached(QObject *parent = nullptr); + + QQuickActionGroup *group() const; + void setGroup(QQuickActionGroup *group); + +Q_SIGNALS: + void groupChanged(); + +private: + Q_DISABLE_COPY(QQuickActionGroupAttached) + Q_DECLARE_PRIVATE(QQuickActionGroupAttached) +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickActionGroup) +QML_DECLARE_TYPEINFO(QQuickActionGroup, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKACTIONGROUP_P_H diff --git a/src/quicktemplates2/qquickapplicationwindow.cpp b/src/quicktemplates2/qquickapplicationwindow.cpp index 0cd78502..4a445d9b 100644 --- a/src/quicktemplates2/qquickapplicationwindow.cpp +++ b/src/quicktemplates2/qquickapplicationwindow.cpp @@ -251,6 +251,29 @@ void QQuickApplicationWindowPrivate::itemImplicitHeightChanged(QQuickItem *item) relayout(); } +void QQuickApplicationWindowPrivate::updateFont(const QFont &f) +{ + Q_Q(QQuickApplicationWindow); + const bool changed = font != f; + font = f; + + QQuickControlPrivate::updateFontRecur(q->QQuickWindow::contentItem(), f); + + // TODO: internal QQuickPopupManager that provides reliable access to all QQuickPopup instances + const QList<QQuickPopup *> popups = q->findChildren<QQuickPopup *>(); + for (QQuickPopup *popup : popups) + QQuickControlPrivate::get(static_cast<QQuickControl *>(popup->popupItem()))->inheritFont(f); + + if (changed) + emit q->fontChanged(); +} + +void QQuickApplicationWindowPrivate::resolveFont() +{ + QFont resolvedFont = font.resolve(QQuickControlPrivate::themeFont(QPlatformTheme::SystemFont)); + setFont_helper(resolvedFont); +} + void QQuickApplicationWindowPrivate::_q_updateActiveFocus() { Q_Q(QQuickApplicationWindow); @@ -614,28 +637,6 @@ void QQuickApplicationWindow::resetFont() setFont(QFont()); } -void QQuickApplicationWindowPrivate::resolveFont() -{ - QFont resolvedFont = font.resolve(QQuickControlPrivate::themeFont(QPlatformTheme::SystemFont)); - setFont_helper(resolvedFont); -} - -void QQuickApplicationWindowPrivate::updateFont(const QFont &f) -{ - Q_Q(QQuickApplicationWindow); - const bool changed = font != f; - font = f; - - QQuickControlPrivate::updateFontRecur(q->QQuickWindow::contentItem(), f); - - // TODO: internal QQuickPopupManager that provides reliable access to all QQuickPopup instances - const QList<QQuickPopup *> popups = q->findChildren<QQuickPopup *>(); - for (QQuickPopup *popup : popups) - QQuickControlPrivate::get(static_cast<QQuickControl *>(popup->popupItem()))->inheritFont(f); - - if (changed) - emit q->fontChanged(); -} /*! \qmlproperty Locale QtQuick.Controls::ApplicationWindow::locale diff --git a/src/quicktemplates2/qquickbutton.cpp b/src/quicktemplates2/qquickbutton.cpp index 1a614754..d324feb2 100644 --- a/src/quicktemplates2/qquickbutton.cpp +++ b/src/quicktemplates2/qquickbutton.cpp @@ -77,6 +77,9 @@ QT_BEGIN_NAMESPACE } \endcode + In addition to displaying \l {AbstractButton::}{text}, buttons can also + display an \l [QML]{Button Icons}{icon}. + \sa {Customizing Button}, {Button Controls} */ diff --git a/src/quicktemplates2/qquickbuttongroup.cpp b/src/quicktemplates2/qquickbuttongroup.cpp index a9c0d435..705224d6 100644 --- a/src/quicktemplates2/qquickbuttongroup.cpp +++ b/src/quicktemplates2/qquickbuttongroup.cpp @@ -154,7 +154,11 @@ class QQuickButtonGroupPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QQuickButtonGroup) public: - QQuickButtonGroupPrivate() : checkedButton(nullptr) { } + QQuickButtonGroupPrivate() + : exclusive(true), + checkedButton(nullptr) + { + } void clear(); void buttonClicked(); @@ -165,6 +169,7 @@ public: static QQuickAbstractButton *buttons_at(QQmlListProperty<QQuickAbstractButton> *prop, int index); static void buttons_clear(QQmlListProperty<QQuickAbstractButton> *prop); + bool exclusive; QQuickAbstractButton *checkedButton; QVector<QQuickAbstractButton*> buttons; }; @@ -190,6 +195,8 @@ void QQuickButtonGroupPrivate::buttonClicked() void QQuickButtonGroupPrivate::_q_updateCurrent() { Q_Q(QQuickButtonGroup); + if (!exclusive) + return; QQuickAbstractButton *button = qobject_cast<QQuickAbstractButton*>(q->sender()); if (button && button->isChecked()) q->setCheckedButton(button); @@ -246,9 +253,12 @@ QQuickButtonGroupAttached *QQuickButtonGroup::qmlAttachedProperties(QObject *obj /*! \qmlproperty AbstractButton QtQuick.Controls::ButtonGroup::checkedButton - This property holds the currently selected button, or \c null if there is none. + This property holds the currently selected button in an exclusive group, + or \c null if there is none or the group is non-exclusive. + + By default, it is the first checked button added to an exclusive button group. - By default, it is the first checked button added to the button group. + \sa exclusive */ QQuickAbstractButton *QQuickButtonGroup::checkedButton() const { @@ -308,6 +318,38 @@ QQmlListProperty<QQuickAbstractButton> QQuickButtonGroup::buttons() } /*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::ButtonGroup::exclusive + + This property holds whether the button group is exclusive. The default value is \c true. + + If this property is \c true, then only one button in the group can be checked at any given time. + The user can click on any button to check it, and that button will replace the existing one as + the checked button in the group. + + In an exclusive group, the user cannot uncheck the currently checked button by clicking on it; + instead, another button in the group must be clicked to set the new checked button for that group. + + In a non-exclusive group, checking and unchecking buttons does not affect the other buttons in + the group. Furthermore, the value of the \l checkedButton property is \c null. +*/ +bool QQuickButtonGroup::isExclusive() const +{ + Q_D(const QQuickButtonGroup); + return d->exclusive; +} + +void QQuickButtonGroup::setExclusive(bool exclusive) +{ + Q_D(QQuickButtonGroup); + if (d->exclusive == exclusive) + return; + + d->exclusive = exclusive; + emit exclusiveChanged(); +} + +/*! \qmlmethod void QtQuick.Controls::ButtonGroup::addButton(AbstractButton button) Adds a \a button to the button group. @@ -328,7 +370,7 @@ void QQuickButtonGroup::addButton(QQuickAbstractButton *button) QObjectPrivate::connect(button, &QQuickAbstractButton::clicked, d, &QQuickButtonGroupPrivate::buttonClicked); QObjectPrivate::connect(button, &QQuickAbstractButton::checkedChanged, d, &QQuickButtonGroupPrivate::_q_updateCurrent); - if (button->isChecked()) + if (d->exclusive && button->isChecked()) setCheckedButton(button); d->buttons.append(button); diff --git a/src/quicktemplates2/qquickbuttongroup_p.h b/src/quicktemplates2/qquickbuttongroup_p.h index 21deb035..5fe1858d 100644 --- a/src/quicktemplates2/qquickbuttongroup_p.h +++ b/src/quicktemplates2/qquickbuttongroup_p.h @@ -64,6 +64,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickButtonGroup : public QObject Q_OBJECT Q_PROPERTY(QQuickAbstractButton *checkedButton READ checkedButton WRITE setCheckedButton NOTIFY checkedButtonChanged) Q_PROPERTY(QQmlListProperty<QQuickAbstractButton> buttons READ buttons NOTIFY buttonsChanged FINAL) + Q_PROPERTY(bool exclusive READ isExclusive WRITE setExclusive NOTIFY exclusiveChanged FINAL REVISION 3) public: explicit QQuickButtonGroup(QObject *parent = nullptr); @@ -76,6 +77,9 @@ public: QQmlListProperty<QQuickAbstractButton> buttons(); + bool isExclusive() const; + void setExclusive(bool exclusive); + public Q_SLOTS: void addButton(QQuickAbstractButton *button); void removeButton(QQuickAbstractButton *button); @@ -83,6 +87,7 @@ public Q_SLOTS: Q_SIGNALS: void checkedButtonChanged(); void buttonsChanged(); + Q_REVISION(3) void exclusiveChanged(); Q_REVISION(1) void clicked(QQuickAbstractButton *button); private: diff --git a/src/quicktemplates2/qquickcontainer.cpp b/src/quicktemplates2/qquickcontainer.cpp index 2bc37e9c..54e03c81 100644 --- a/src/quicktemplates2/qquickcontainer.cpp +++ b/src/quicktemplates2/qquickcontainer.cpp @@ -253,13 +253,17 @@ void QQuickContainerPrivate::insertItem(int index, QQuickItem *item) q->itemAdded(index, item); - if (contentModel->count() == 1 && currentIndex == -1) + int count = contentModel->count(); + for (int i = index + 1; i < count; ++i) + q->itemMoved(i, itemAt(i)); + + if (count == 1 && currentIndex == -1) q->setCurrentIndex(index); updatingCurrent = false; } -void QQuickContainerPrivate::moveItem(int from, int to) +void QQuickContainerPrivate::moveItem(int from, int to, QQuickItem *item) { Q_Q(QQuickContainer); int oldCurrent = currentIndex; @@ -267,6 +271,16 @@ void QQuickContainerPrivate::moveItem(int from, int to) updatingCurrent = true; + q->itemMoved(to, item); + + if (from < to) { + for (int i = from; i < to; ++i) + q->itemMoved(i, itemAt(i)); + } else { + for (int i = from; i > to; --i) + q->itemMoved(i, itemAt(i)); + } + if (from == oldCurrent) q->setCurrentIndex(to); else if (from < oldCurrent && to >= oldCurrent) @@ -300,6 +314,10 @@ void QQuickContainerPrivate::removeItem(int index, QQuickItem *item) q->itemRemoved(index, item); + int count = contentModel->count(); + for (int i = index; i < count; ++i) + q->itemMoved(i, itemAt(i)); + if (currentChanged) emit q->currentIndexChanged(); @@ -476,7 +494,7 @@ void QQuickContainer::insertItem(int index, QQuickItem *item) if (oldIndex < index) --index; if (oldIndex != index) - d->moveItem(oldIndex, index); + d->moveItem(oldIndex, index, item); } else { d->insertItem(index, item); } @@ -497,7 +515,7 @@ void QQuickContainer::moveItem(int from, int to) to = count - 1; if (from != to) - d->moveItem(from, to); + d->moveItem(from, to, d->itemAt(from)); } /*! @@ -735,6 +753,12 @@ void QQuickContainer::itemAdded(int index, QQuickItem *item) Q_UNUSED(item); } +void QQuickContainer::itemMoved(int index, QQuickItem *item) +{ + Q_UNUSED(index); + Q_UNUSED(item); +} + void QQuickContainer::itemRemoved(int index, QQuickItem *item) { Q_UNUSED(index); diff --git a/src/quicktemplates2/qquickcontainer_p.h b/src/quicktemplates2/qquickcontainer_p.h index 6db45589..55aa15b9 100644 --- a/src/quicktemplates2/qquickcontainer_p.h +++ b/src/quicktemplates2/qquickcontainer_p.h @@ -103,6 +103,7 @@ protected: virtual bool isContent(QQuickItem *item) const; virtual void itemAdded(int index, QQuickItem *item); + virtual void itemMoved(int index, QQuickItem *item); virtual void itemRemoved(int index, QQuickItem *item); private: diff --git a/src/quicktemplates2/qquickcontainer_p_p.h b/src/quicktemplates2/qquickcontainer_p_p.h index 38c6b3e4..cbc04f9a 100644 --- a/src/quicktemplates2/qquickcontainer_p_p.h +++ b/src/quicktemplates2/qquickcontainer_p_p.h @@ -66,7 +66,7 @@ public: QQuickItem *itemAt(int index) const; void insertItem(int index, QQuickItem *item); - void moveItem(int from, int to); + void moveItem(int from, int to, QQuickItem *item); void removeItem(int index, QQuickItem *item); void _q_currentIndexChanged(); diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index a2b16a10..d285fdd2 100644 --- a/src/quicktemplates2/qquickcontrol.cpp +++ b/src/quicktemplates2/qquickcontrol.cpp @@ -314,29 +314,6 @@ QAccessible::Role QQuickControlPrivate::accessibleRole() const Q_Q(const QQuickControl); return q->accessibleRole(); } - -QAccessible::Role QQuickControl::accessibleRole() const -{ - return QAccessible::NoRole; -} - -void QQuickControl::accessibilityActiveChanged(bool active) -{ - Q_D(QQuickControl); - if (d->accessibleAttached || !active) - return; - - d->accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, true)); - - // QQuickControl relies on the existence of a QQuickAccessibleAttached object. - // However, qmlAttachedPropertiesObject(create=true) creates an instance only - // for items that have been created by a QML engine. Therefore we create the - // object by hand for items created in C++ (QQuickPopupItem, for instance). - if (!d->accessibleAttached) - d->accessibleAttached = new QQuickAccessibleAttached(this); - - d->accessibleAttached->setRole(accessibleRole()); -} #endif /*! @@ -395,11 +372,11 @@ void QQuickControlPrivate::resolveFont() inheritFont(parentFont(q)); } -void QQuickControlPrivate::inheritFont(const QFont &f) +void QQuickControlPrivate::inheritFont(const QFont &font) { Q_Q(QQuickControl); - QFont parentFont = extra.isAllocated() ? extra->font.resolve(f) : f; - parentFont.resolve(extra.isAllocated() ? extra->font.resolve() | f.resolve() : f.resolve()); + QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font; + parentFont.resolve(extra.isAllocated() ? extra->requestedFont.resolve() | font.resolve() : font.resolve()); const QFont defaultFont = q->defaultFont(); const QFont resolvedFont = parentFont.resolve(defaultFont); @@ -412,35 +389,87 @@ void QQuickControlPrivate::inheritFont(const QFont &f) Assign \a font to this control, and propagate it to all children. */ -void QQuickControlPrivate::updateFont(const QFont &f) +void QQuickControlPrivate::updateFont(const QFont &font) { Q_Q(QQuickControl); - QFont old = resolvedFont; - resolvedFont = f; + QFont oldFont = resolvedFont; + resolvedFont = font; - if (old != f) - q->fontChange(f, old); + if (oldFont != font) + q->fontChange(font, oldFont); - QQuickControlPrivate::updateFontRecur(q, f); + QQuickControlPrivate::updateFontRecur(q, font); - if (old != f) + if (oldFont != font) emit q->fontChanged(); } -void QQuickControlPrivate::updateFontRecur(QQuickItem *item, const QFont &f) +void QQuickControlPrivate::updateFontRecur(QQuickItem *item, const QFont &font) { const auto childItems = item->childItems(); for (QQuickItem *child : childItems) { if (QQuickControl *control = qobject_cast<QQuickControl *>(child)) - QQuickControlPrivate::get(control)->inheritFont(f); + QQuickControlPrivate::get(control)->inheritFont(font); else if (QQuickLabel *label = qobject_cast<QQuickLabel *>(child)) - QQuickLabelPrivate::get(label)->inheritFont(f); + QQuickLabelPrivate::get(label)->inheritFont(font); else if (QQuickTextArea *textArea = qobject_cast<QQuickTextArea *>(child)) - QQuickTextAreaPrivate::get(textArea)->inheritFont(f); + QQuickTextAreaPrivate::get(textArea)->inheritFont(font); else if (QQuickTextField *textField = qobject_cast<QQuickTextField *>(child)) - QQuickTextFieldPrivate::get(textField)->inheritFont(f); + QQuickTextFieldPrivate::get(textField)->inheritFont(font); else - QQuickControlPrivate::updateFontRecur(child, f); + QQuickControlPrivate::updateFontRecur(child, font); + } +} + +QLocale QQuickControlPrivate::calcLocale(const QQuickItem *item) +{ + const QQuickItem *p = item; + while (p) { + if (const QQuickControl *control = qobject_cast<const QQuickControl *>(p)) + return control->locale(); + + QVariant v = p->property("locale"); + if (v.isValid() && v.userType() == QMetaType::QLocale) + return v.toLocale(); + + p = p->parentItem(); + } + + if (item) { + if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window())) + return window->locale(); + } + + return QLocale(); +} + +void QQuickControlPrivate::updateLocale(const QLocale &l, bool e) +{ + Q_Q(QQuickControl); + if (!e && hasLocale) + return; + + QLocale old = q->locale(); + hasLocale = e; + if (old != l) { + bool wasMirrored = q->isMirrored(); + q->localeChange(l, old); + locale = l; + QQuickControlPrivate::updateLocaleRecur(q, l); + emit q->localeChanged(); + if (wasMirrored != q->isMirrored()) + q->mirrorChange(); + } +} + +void QQuickControlPrivate::updateLocaleRecur(QQuickItem *item, const QLocale &l) +{ + const auto childItems = item->childItems(); + for (QQuickItem *child : childItems) { + if (QQuickControl *control = qobject_cast<QQuickControl *>(child)) + QQuickControlPrivate::get(control)->updateLocale(l, false); + else + updateLocaleRecur(child, l); } } @@ -502,48 +531,26 @@ bool QQuickControlPrivate::calcHoverEnabled(const QQuickItem *item) } #endif -QString QQuickControl::accessibleName() const -{ -#if QT_CONFIG(accessibility) - Q_D(const QQuickControl); - if (d->accessibleAttached) - return d->accessibleAttached->name(); -#endif - return QString(); -} - -void QQuickControl::setAccessibleName(const QString &name) +/* + Cancels incubation recursively to avoid "Object destroyed during incubation" (QTBUG-50992) +*/ +static void cancelIncubation(QObject *object, QQmlContext *context) { -#if QT_CONFIG(accessibility) - Q_D(QQuickControl); - if (d->accessibleAttached) - d->accessibleAttached->setName(name); -#else - Q_UNUSED(name) -#endif + const auto children = object->children(); + for (QObject *child : children) + cancelIncubation(child, context); + QQmlIncubatorPrivate::cancel(object, context); } -QVariant QQuickControl::accessibleProperty(const char *propertyName) +void QQuickControlPrivate::destroyDelegate(QObject *delegate, QObject *parent) { -#if QT_CONFIG(accessibility) - Q_D(QQuickControl); - if (d->accessibleAttached) - return QQuickAccessibleAttached::property(this, propertyName); -#endif - Q_UNUSED(propertyName) - return QVariant(); -} + if (!delegate) + return; -bool QQuickControl::setAccessibleProperty(const char *propertyName, const QVariant &value) -{ -#if QT_CONFIG(accessibility) - Q_D(QQuickControl); - if (d->accessibleAttached) - return QQuickAccessibleAttached::setProperty(this, propertyName, value); -#endif - Q_UNUSED(propertyName) - Q_UNUSED(value) - return false; + QQmlContext *context = parent ? qmlContext(parent) : nullptr; + if (context) + cancelIncubation(delegate, context); + delete delegate; } QQuickControl::QQuickControl(QQuickItem *parent) @@ -632,10 +639,10 @@ QFont QQuickControl::font() const void QQuickControl::setFont(const QFont &font) { Q_D(QQuickControl); - if (d->extra.value().font.resolve() == font.resolve() && d->extra.value().font == font) + if (d->extra.value().requestedFont.resolve() == font.resolve() && d->extra.value().requestedFont == font) return; - d->extra.value().font = font; + d->extra.value().requestedFont = font; d->resolveFont(); } @@ -908,80 +915,6 @@ void QQuickControl::resetLocale() d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem), false); // explicit=false } -QLocale QQuickControlPrivate::calcLocale(const QQuickItem *item) -{ - const QQuickItem *p = item; - while (p) { - if (const QQuickControl *control = qobject_cast<const QQuickControl *>(p)) - return control->locale(); - - QVariant v = p->property("locale"); - if (v.isValid() && v.userType() == QMetaType::QLocale) - return v.toLocale(); - - p = p->parentItem(); - } - - if (item) { - if (QQuickApplicationWindow *window = qobject_cast<QQuickApplicationWindow *>(item->window())) - return window->locale(); - } - - return QLocale(); -} - -/* - Cancels incubation recursively to avoid "Object destroyed during incubation" (QTBUG-50992) -*/ -static void cancelIncubation(QObject *object, QQmlContext *context) -{ - const auto children = object->children(); - for (QObject *child : children) - cancelIncubation(child, context); - QQmlIncubatorPrivate::cancel(object, context); -} - -void QQuickControlPrivate::destroyDelegate(QObject *delegate, QObject *parent) -{ - if (!delegate) - return; - - QQmlContext *context = parent ? qmlContext(parent) : nullptr; - if (context) - cancelIncubation(delegate, context); - delete delegate; -} - -void QQuickControlPrivate::updateLocale(const QLocale &l, bool e) -{ - Q_Q(QQuickControl); - if (!e && hasLocale) - return; - - QLocale old = q->locale(); - hasLocale = e; - if (old != l) { - bool wasMirrored = q->isMirrored(); - q->localeChange(l, old); - locale = l; - QQuickControlPrivate::updateLocaleRecur(q, l); - emit q->localeChanged(); - if (wasMirrored != q->isMirrored()) - q->mirrorChange(); - } -} - -void QQuickControlPrivate::updateLocaleRecur(QQuickItem *item, const QLocale &l) -{ - const auto childItems = item->childItems(); - for (QQuickItem *child : childItems) { - if (QQuickControl *control = qobject_cast<QQuickControl *>(child)) - QQuickControlPrivate::get(control)->updateLocale(l, false); - else - updateLocaleRecur(child, l); - } -} - /*! \qmlproperty bool QtQuick.Controls::Control::mirrored \readonly @@ -1487,4 +1420,73 @@ void QQuickControl::localeChange(const QLocale &newLocale, const QLocale &oldLoc Q_UNUSED(oldLocale); } +#if QT_CONFIG(accessibility) +QAccessible::Role QQuickControl::accessibleRole() const +{ + return QAccessible::NoRole; +} + +void QQuickControl::accessibilityActiveChanged(bool active) +{ + Q_D(QQuickControl); + if (d->accessibleAttached || !active) + return; + + d->accessibleAttached = qobject_cast<QQuickAccessibleAttached *>(qmlAttachedPropertiesObject<QQuickAccessibleAttached>(this, true)); + + // QQuickControl relies on the existence of a QQuickAccessibleAttached object. + // However, qmlAttachedPropertiesObject(create=true) creates an instance only + // for items that have been created by a QML engine. Therefore we create the + // object by hand for items created in C++ (QQuickPopupItem, for instance). + if (!d->accessibleAttached) + d->accessibleAttached = new QQuickAccessibleAttached(this); + + d->accessibleAttached->setRole(accessibleRole()); +} +#endif + +QString QQuickControl::accessibleName() const +{ +#if QT_CONFIG(accessibility) + Q_D(const QQuickControl); + if (d->accessibleAttached) + return d->accessibleAttached->name(); +#endif + return QString(); +} + +void QQuickControl::setAccessibleName(const QString &name) +{ +#if QT_CONFIG(accessibility) + Q_D(QQuickControl); + if (d->accessibleAttached) + d->accessibleAttached->setName(name); +#else + Q_UNUSED(name) +#endif +} + +QVariant QQuickControl::accessibleProperty(const char *propertyName) +{ +#if QT_CONFIG(accessibility) + Q_D(QQuickControl); + if (d->accessibleAttached) + return QQuickAccessibleAttached::property(this, propertyName); +#endif + Q_UNUSED(propertyName) + return QVariant(); +} + +bool QQuickControl::setAccessibleProperty(const char *propertyName, const QVariant &value) +{ +#if QT_CONFIG(accessibility) + Q_D(QQuickControl); + if (d->accessibleAttached) + return QQuickAccessibleAttached::setProperty(this, propertyName, value); +#endif + Q_UNUSED(propertyName) + Q_UNUSED(value) + return false; +} + QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquickcontrol_p.h b/src/quicktemplates2/qquickcontrol_p.h index 6ad89376..feb6646e 100644 --- a/src/quicktemplates2/qquickcontrol_p.h +++ b/src/quicktemplates2/qquickcontrol_p.h @@ -204,8 +204,8 @@ protected: virtual void localeChange(const QLocale &newLocale, const QLocale &oldLocale); #if QT_CONFIG(accessibility) - virtual void accessibilityActiveChanged(bool active); virtual QAccessible::Role accessibleRole() const; + virtual void accessibilityActiveChanged(bool active); #endif // helper functions which avoid to check QT_CONFIG(accessibility) diff --git a/src/quicktemplates2/qquickcontrol_p_p.h b/src/quicktemplates2/qquickcontrol_p_p.h index 42924875..7ff9dff3 100644 --- a/src/quicktemplates2/qquickcontrol_p_p.h +++ b/src/quicktemplates2/qquickcontrol_p_p.h @@ -48,7 +48,7 @@ // We mean it. // -#include "qquickcontrol_p.h" +#include <QtQuickTemplates2/private/qquickcontrol_p.h> #include <QtQuick/private/qquickitem_p.h> #include <QtQml/private/qlazilyallocated_p.h> @@ -102,15 +102,15 @@ public: QAccessible::Role accessibleRole() const override; #endif - void updateFont(const QFont &f); - static void updateFontRecur(QQuickItem *item, const QFont &f); - inline void setFont_helper(const QFont &f) { - if (resolvedFont.resolve() == f.resolve() && resolvedFont == f) + virtual void resolveFont(); + void inheritFont(const QFont &font); + void updateFont(const QFont &font); + static void updateFontRecur(QQuickItem *item, const QFont &font); + inline void setFont_helper(const QFont &font) { + if (resolvedFont.resolve() == font.resolve() && resolvedFont == font) return; - updateFont(f); + updateFont(font); } - virtual void resolveFont(); - void inheritFont(const QFont &f); static QFont parentFont(const QQuickItem *item); static QFont themeFont(QPlatformTheme::Font type); @@ -128,11 +128,10 @@ public: struct ExtraData { ExtraData(); - QFont font; + QFont requestedFont; }; QLazilyAllocated<ExtraData> extra; - QFont resolvedFont; bool hasTopPadding; bool hasLeftPadding; bool hasRightPadding; @@ -151,6 +150,7 @@ public: qreal bottomPadding; qreal spacing; QLocale locale; + QFont resolvedFont; Qt::FocusPolicy focusPolicy; Qt::FocusReason focusReason; QQuickItem *background; diff --git a/src/quicktemplates2/qquickdialog.cpp b/src/quicktemplates2/qquickdialog.cpp index 3ac99caa..4fe53c99 100644 --- a/src/quicktemplates2/qquickdialog.cpp +++ b/src/quicktemplates2/qquickdialog.cpp @@ -37,6 +37,7 @@ #include "qquickdialog_p.h" #include "qquickdialog_p_p.h" #include "qquickdialogbuttonbox_p.h" +#include "qquickabstractbutton_p.h" #include "qquickpopupitem_p_p.h" QT_BEGIN_NAMESPACE @@ -115,6 +116,69 @@ QT_BEGIN_NAMESPACE \sa accepted() */ +/*! + \since QtQuick.Controls 2.3 + \qmlsignal QtQuick.Controls::Dialog::applied() + + This signal is emitted when the \c Dialog.Apply standard button is clicked. + + \sa discarded(), reset() +*/ + +/*! + \since QtQuick.Controls 2.3 + \qmlsignal QtQuick.Controls::Dialog::reset() + + This signal is emitted when the \c Dialog.Reset standard button is clicked. + + \sa discarded(), applied() +*/ + +/*! + \since QtQuick.Controls 2.3 + \qmlsignal QtQuick.Controls::Dialog::discarded() + + This signal is emitted when the \c Dialog.Discard standard button is clicked. + + \sa reset(), applied() +*/ + +/*! + \since QtQuick.Controls 2.3 + \qmlsignal QtQuick.Controls::Dialog::helpRequested() + + This signal is emitted when the \c Dialog.Help standard button is clicked. + + \sa accepted(), rejected() +*/ + +QPlatformDialogHelper::ButtonRole QQuickDialogPrivate::buttonRole(QQuickAbstractButton *button) +{ + const QQuickDialogButtonBoxAttached *attached = qobject_cast<QQuickDialogButtonBoxAttached *>(qmlAttachedPropertiesObject<QQuickDialogButtonBox>(button, false)); + return attached ? attached->buttonRole() : QPlatformDialogHelper::InvalidRole; +} + +void QQuickDialogPrivate::handleClick(QQuickAbstractButton *button) +{ + Q_Q(QQuickDialog); + switch (buttonRole(button)) { + case QPlatformDialogHelper::ApplyRole: + emit q->applied(); + break; + case QPlatformDialogHelper::ResetRole: + emit q->reset(); + break; + case QPlatformDialogHelper::DestructiveRole: + emit q->discarded(); + break; + case QPlatformDialogHelper::HelpRole: + emit q->helpRequested(); + break; + default: + break; + } +} + QQuickDialog::QQuickDialog(QObject *parent) : QQuickPopup(*(new QQuickDialogPrivate), parent) { @@ -188,12 +252,14 @@ void QQuickDialog::setHeader(QQuickItem *header) if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(oldHeader)) { disconnect(buttonBox, &QQuickDialogButtonBox::accepted, this, &QQuickDialog::accept); disconnect(buttonBox, &QQuickDialogButtonBox::rejected, this, &QQuickDialog::reject); + QObjectPrivate::disconnect(buttonBox, &QQuickDialogButtonBox::clicked, d, &QQuickDialogPrivate::handleClick); if (d->buttonBox == buttonBox) d->buttonBox = nullptr; } if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(header)) { connect(buttonBox, &QQuickDialogButtonBox::accepted, this, &QQuickDialog::accept); connect(buttonBox, &QQuickDialogButtonBox::rejected, this, &QQuickDialog::reject); + QObjectPrivate::connect(buttonBox, &QQuickDialogButtonBox::clicked, d, &QQuickDialogPrivate::handleClick); d->buttonBox = buttonBox; buttonBox->setStandardButtons(d->standardButtons); } @@ -235,12 +301,14 @@ void QQuickDialog::setFooter(QQuickItem *footer) if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(oldFooter)) { disconnect(buttonBox, &QQuickDialogButtonBox::accepted, this, &QQuickDialog::accept); disconnect(buttonBox, &QQuickDialogButtonBox::rejected, this, &QQuickDialog::reject); + QObjectPrivate::disconnect(buttonBox, &QQuickDialogButtonBox::clicked, d, &QQuickDialogPrivate::handleClick); if (d->buttonBox == buttonBox) d->buttonBox = nullptr; } if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(footer)) { connect(buttonBox, &QQuickDialogButtonBox::accepted, this, &QQuickDialog::accept); connect(buttonBox, &QQuickDialogButtonBox::rejected, this, &QQuickDialog::reject); + QObjectPrivate::connect(buttonBox, &QQuickDialogButtonBox::clicked, d, &QQuickDialogPrivate::handleClick); d->buttonBox = buttonBox; buttonBox->setStandardButtons(d->standardButtons); } @@ -301,16 +369,59 @@ void QQuickDialog::setStandardButtons(QPlatformDialogHelper::StandardButtons but } /*! + \since QtQuick.Controls 2.3 + \qmlmethod AbstractButton QtQuick.Controls::Dialog::standardButton(StandardButton button) + + Returns the specified standard \a button, or \c null if it does not exist. + + \sa standardButtons +*/ +QQuickAbstractButton *QQuickDialog::standardButton(QPlatformDialogHelper::StandardButton button) const +{ + Q_D(const QQuickDialog); + if (!d->buttonBox) + return nullptr; + return d->buttonBox->standardButton(button); +} + +/*! + \since QtQuick.Controls 2.3 + \qmlproperty int QtQuick.Controls::Dialog::result + + This property holds the result code. + + Standard result codes: + \value Dialog.Accepted The dialog was accepted. + \value Dialog.Rejected The dialog was rejected. + + \sa accept(), reject(), done() +*/ +int QQuickDialog::result() const +{ + Q_D(const QQuickDialog); + return d->result; +} + +void QQuickDialog::setResult(int result) +{ + Q_D(QQuickDialog); + if (d->result == result) + return; + + d->result = result; + emit resultChanged(); +} + +/*! \qmlmethod void QtQuick.Controls::Dialog::accept() Closes the dialog and emits the \l accepted() signal. - \sa reject() + \sa reject(), done() */ void QQuickDialog::accept() { - close(); - emit accepted(); + done(Accepted); } /*! @@ -318,12 +429,32 @@ void QQuickDialog::accept() Closes the dialog and emits the \l rejected() signal. - \sa accept() + \sa accept(), done() */ void QQuickDialog::reject() { + done(Rejected); +} + +/*! + \since QtQuick.Controls 2.3 + \qmlmethod void Qt.labs.platform::Dialog::done(int result) + + Closes the dialog, sets the \a result, and emits \l accepted() or + \l rejected() depending on whether the result is \c Dialog.Accepted + or \c Dialog.Rejected, respectively. + + \sa accept(), reject(), result +*/ +void QQuickDialog::done(int result) +{ close(); - emit rejected(); + setResult(result); + + if (result == Accepted) + emit accepted(); + else if (result == Rejected) + emit rejected(); } void QQuickDialog::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) diff --git a/src/quicktemplates2/qquickdialog_p.h b/src/quicktemplates2/qquickdialog_p.h index 97c90a59..8032cf83 100644 --- a/src/quicktemplates2/qquickdialog_p.h +++ b/src/quicktemplates2/qquickdialog_p.h @@ -54,6 +54,7 @@ QT_BEGIN_NAMESPACE class QQuickDialogPrivate; +class QQuickAbstractButton; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDialog : public QQuickPopup { @@ -62,6 +63,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickDialog : public QQuickPopup Q_PROPERTY(QQuickItem *header READ header WRITE setHeader NOTIFY headerChanged FINAL) Q_PROPERTY(QQuickItem *footer READ footer WRITE setFooter NOTIFY footerChanged FINAL) Q_PROPERTY(QPlatformDialogHelper::StandardButtons standardButtons READ standardButtons WRITE setStandardButtons NOTIFY standardButtonsChanged FINAL) + Q_PROPERTY(int result READ result WRITE setResult NOTIFY resultChanged FINAL REVISION 3) Q_FLAGS(QPlatformDialogHelper::StandardButtons) public: @@ -78,19 +80,32 @@ public: QPlatformDialogHelper::StandardButtons standardButtons() const; void setStandardButtons(QPlatformDialogHelper::StandardButtons buttons); + Q_REVISION(3) Q_INVOKABLE QQuickAbstractButton *standardButton(QPlatformDialogHelper::StandardButton button) const; + + enum StandardCode { Rejected, Accepted }; + Q_ENUM(StandardCode) + + int result() const; + void setResult(int result); public Q_SLOTS: - void accept(); - void reject(); + virtual void accept(); + virtual void reject(); + virtual void done(int result); Q_SIGNALS: void accepted(); void rejected(); + Q_REVISION(3) void applied(); + Q_REVISION(3) void reset(); + Q_REVISION(3) void discarded(); + Q_REVISION(3) void helpRequested(); void titleChanged(); void headerChanged(); void footerChanged(); void standardButtonsChanged(); + Q_REVISION(3) void resultChanged(); protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; diff --git a/src/quicktemplates2/qquickdialog_p_p.h b/src/quicktemplates2/qquickdialog_p_p.h index 13885ca9..e26182ac 100644 --- a/src/quicktemplates2/qquickdialog_p_p.h +++ b/src/quicktemplates2/qquickdialog_p_p.h @@ -48,11 +48,14 @@ // We mean it. // +#include <QtQuickTemplates2/private/qquickdialog_p.h> #include <QtQuickTemplates2/private/qquickpopup_p_p.h> #include <QtQuickTemplates2/private/qquickpagelayout_p_p.h> +#include <QtGui/qpa/qplatformdialoghelper.h> QT_BEGIN_NAMESPACE +class QQuickAbstractButton; class QQuickDialogButtonBox; class QQuickDialogPrivate : public QQuickPopupPrivate @@ -60,13 +63,18 @@ class QQuickDialogPrivate : public QQuickPopupPrivate Q_DECLARE_PUBLIC(QQuickDialog) public: - QQuickDialogPrivate() : buttonBox(nullptr) { } + QQuickDialogPrivate() : result(0), buttonBox(nullptr) { } static QQuickDialogPrivate *get(QQuickDialog *dialog) { return dialog->d_func(); } + static QPlatformDialogHelper::ButtonRole buttonRole(QQuickAbstractButton *button); + + void handleClick(QQuickAbstractButton *button); + + int result; QString title; QQuickDialogButtonBox *buttonBox; QScopedPointer<QQuickPageLayout> layout; diff --git a/src/quicktemplates2/qquickdialogbuttonbox.cpp b/src/quicktemplates2/qquickdialogbuttonbox.cpp index 3c422268..7b4dbb56 100644 --- a/src/quicktemplates2/qquickdialogbuttonbox.cpp +++ b/src/quicktemplates2/qquickdialogbuttonbox.cpp @@ -38,6 +38,7 @@ #include "qquickdialogbuttonbox_p_p.h" #include "qquickabstractbutton_p.h" #include "qquickbutton_p.h" +#include "qquickdialog_p_p.h" #include <QtCore/qpointer.h> #include <QtGui/private/qguiapplication_p.h> @@ -122,6 +123,36 @@ QT_BEGIN_NAMESPACE */ /*! + \since QtQuick.Controls 2.3 + \qmlsignal QtQuick.Controls::DialogButtonBox::applied() + + This signal is emitted when a button defined with the \c ApplyRole is + clicked. + + \sa discarded(), reset() +*/ + +/*! + \since QtQuick.Controls 2.3 + \qmlsignal QtQuick.Controls::DialogButtonBox::reset() + + This signal is emitted when a button defined with the \c ResetRole is + clicked. + + \sa discarded(), applied() +*/ + +/*! + \since QtQuick.Controls 2.3 + \qmlsignal QtQuick.Controls::DialogButtonBox::discarded() + + This signal is emitted when a button defined with the \c DiscardRole is + clicked. + + \sa reset(), applied() +*/ + +/*! \qmlsignal QtQuick.Controls::DialogButtonBox::helpRequested() This signal is emitted when a button defined with the \c HelpRole is clicked. @@ -137,12 +168,6 @@ QT_BEGIN_NAMESPACE \sa accepted(), rejected(), helpRequested() */ -static QPlatformDialogHelper::ButtonRole buttonRole(QQuickAbstractButton *button) -{ - const QQuickDialogButtonBoxAttached *attached = qobject_cast<QQuickDialogButtonBoxAttached *>(qmlAttachedPropertiesObject<QQuickDialogButtonBox>(button, false)); - return attached ? attached->buttonRole() : QPlatformDialogHelper::InvalidRole; -} - QQuickDialogButtonBoxPrivate::QQuickDialogButtonBoxPrivate() : alignment(0), position(QQuickDialogButtonBox::Footer), @@ -238,8 +263,8 @@ void QQuickDialogButtonBoxPrivate::updateLayout() struct ButtonLayout { bool operator()(QQuickAbstractButton *first, QQuickAbstractButton *second) { - const QPlatformDialogHelper::ButtonRole firstRole = buttonRole(first); - const QPlatformDialogHelper::ButtonRole secondRole = buttonRole(second); + const QPlatformDialogHelper::ButtonRole firstRole = QQuickDialogPrivate::buttonRole(first); + const QPlatformDialogHelper::ButtonRole secondRole = QQuickDialogPrivate::buttonRole(second); if (firstRole != secondRole && firstRole != QPlatformDialogHelper::InvalidRole && secondRole != QPlatformDialogHelper::InvalidRole) { const int *l = m_layout; @@ -283,7 +308,7 @@ void QQuickDialogButtonBoxPrivate::handleClick() // or change its role. Now changing the role is not possible yet, but arguably // both clicked and accepted/rejected/etc. should be emitted "atomically" // depending on whatever role the button had at the time of the click. - const QPlatformDialogHelper::ButtonRole role = buttonRole(button); + const QPlatformDialogHelper::ButtonRole role = QQuickDialogPrivate::buttonRole(button); QPointer<QQuickDialogButtonBox> guard(q); emit q->clicked(button); @@ -300,6 +325,15 @@ void QQuickDialogButtonBoxPrivate::handleClick() case QPlatformDialogHelper::NoRole: emit q->rejected(); break; + case QPlatformDialogHelper::ApplyRole: + emit q->applied(); + break; + case QPlatformDialogHelper::ResetRole: + emit q->reset(); + break; + case QPlatformDialogHelper::DestructiveRole: + emit q->discarded(); + break; case QPlatformDialogHelper::HelpRole: emit q->helpRequested(); break; diff --git a/src/quicktemplates2/qquickdialogbuttonbox_p.h b/src/quicktemplates2/qquickdialogbuttonbox_p.h index 9bd92c79..5d6e568e 100644 --- a/src/quicktemplates2/qquickdialogbuttonbox_p.h +++ b/src/quicktemplates2/qquickdialogbuttonbox_p.h @@ -98,6 +98,9 @@ Q_SIGNALS: void accepted(); void rejected(); void helpRequested(); + Q_REVISION(3) void applied(); + Q_REVISION(3) void reset(); + Q_REVISION(3) void discarded(); void clicked(QQuickAbstractButton *button); void positionChanged(); diff --git a/src/quicktemplates2/qquickdrawer_p_p.h b/src/quicktemplates2/qquickdrawer_p_p.h index bc4f91eb..110aa350 100644 --- a/src/quicktemplates2/qquickdrawer_p_p.h +++ b/src/quicktemplates2/qquickdrawer_p_p.h @@ -48,9 +48,9 @@ // We mean it. // -#include "qquickdrawer_p.h" -#include "qquickpopup_p_p.h" -#include "qquickvelocitycalculator_p_p.h" +#include <QtQuickTemplates2/private/qquickdrawer_p.h> +#include <QtQuickTemplates2/private/qquickpopup_p_p.h> +#include <QtQuickTemplates2/private/qquickvelocitycalculator_p_p.h> QT_BEGIN_NAMESPACE diff --git a/src/quicktemplates2/qquickicon.cpp b/src/quicktemplates2/qquickicon.cpp new file mode 100644 index 00000000..0b0127d3 --- /dev/null +++ b/src/quicktemplates2/qquickicon.cpp @@ -0,0 +1,152 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickicon_p.h" + +QT_BEGIN_NAMESPACE + +class QQuickIconPrivate : public QSharedData +{ +public: + QQuickIconPrivate() + : width(0), + height(0), + color(Qt::transparent) + { + } + + QString name; + QUrl source; + int width; + int height; + QColor color; +}; + +QQuickIcon::QQuickIcon() + : d(new QQuickIconPrivate) +{ +} + +QQuickIcon::QQuickIcon(const QQuickIcon &other) + : d(other.d) +{ +} + +QQuickIcon::~QQuickIcon() +{ +} + +QQuickIcon &QQuickIcon::operator=(const QQuickIcon &other) +{ + d = other.d; + return *this; +} + +bool QQuickIcon::operator==(const QQuickIcon &other) const +{ + return d == other.d || (d->name == other.d->name + && d->source == other.d->source + && d->width == other.d->width + && d->height == other.d->height + && d->color == other.d->color); +} + +bool QQuickIcon::operator!=(const QQuickIcon &other) const +{ + return !(*this == other); +} + +bool QQuickIcon::isEmpty() const +{ + return d->name.isEmpty() && d->source.isEmpty(); +} + +QString QQuickIcon::name() const +{ + return d->name; +} + +void QQuickIcon::setName(const QString &name) +{ + d->name = name; +} + +QUrl QQuickIcon::source() const +{ + return d->source; +} + +void QQuickIcon::setSource(const QUrl &source) +{ + d->source = source; +} + +int QQuickIcon::width() const +{ + return d->width; +} + +void QQuickIcon::setWidth(int width) +{ + d->width = width; +} + +int QQuickIcon::height() const +{ + return d->height; +} + +void QQuickIcon::setHeight(int height) +{ + d->height = height; +} + +QColor QQuickIcon::color() const +{ + return d->color; +} + +void QQuickIcon::setColor(const QColor &color) +{ + d->color = color; +} + +void QQuickIcon::resetColor() +{ + d->color = Qt::transparent; +} + +QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquickicon_p.h b/src/quicktemplates2/qquickicon_p.h new file mode 100644 index 00000000..6e28f2a9 --- /dev/null +++ b/src/quicktemplates2/qquickicon_p.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKICON_P_H +#define QQUICKICON_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. +// + +#include <QtCore/qurl.h> +#include <QtCore/qstring.h> +#include <QtCore/qobjectdefs.h> +#include <QtCore/qshareddata.h> +#include <QtQuickTemplates2/private/qtquicktemplates2global_p.h> +#include <QtGui/qcolor.h> + +QT_BEGIN_NAMESPACE + +class QQuickIconPrivate; + +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickIcon +{ + Q_GADGET + Q_PROPERTY(QString name READ name WRITE setName FINAL) + Q_PROPERTY(QUrl source READ source WRITE setSource FINAL) + Q_PROPERTY(int width READ width WRITE setWidth FINAL) + Q_PROPERTY(int height READ height WRITE setHeight FINAL) + Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor FINAL) + +public: + QQuickIcon(); + QQuickIcon(const QQuickIcon &other); + ~QQuickIcon(); + + QQuickIcon& operator=(const QQuickIcon &other); + bool operator==(const QQuickIcon &other) const; + bool operator!=(const QQuickIcon &other) const; + + bool isEmpty() const; + + QString name() const; + void setName(const QString &name); + + QUrl source() const; + void setSource(const QUrl &source); + + int width() const; + void setWidth(int width); + + int height() const; + void setHeight(int height); + + QColor color() const; + void setColor(const QColor &color); + void resetColor(); + +private: + QSharedDataPointer<QQuickIconPrivate> d; +}; + +QT_END_NAMESPACE + +#endif // QQUICKICON_P_H diff --git a/src/quicktemplates2/qquickitemdelegate.cpp b/src/quicktemplates2/qquickitemdelegate.cpp index 1b93c145..fb540a49 100644 --- a/src/quicktemplates2/qquickitemdelegate.cpp +++ b/src/quicktemplates2/qquickitemdelegate.cpp @@ -57,7 +57,8 @@ QT_BEGIN_NAMESPACE ItemDelegate inherits its API from AbstractButton. For instance, you can set \l {AbstractButton::text}{text}, and react to \l {AbstractButton::clicked}{clicks} - using the AbstractButton API. + using the AbstractButton API. In addition to displaying text, item delegates + can also display an \l [QML]{Button Icons}{icon}. \snippet qtquickcontrols2-itemdelegate.qml 1 diff --git a/src/quicktemplates2/qquicklabel.cpp b/src/quicktemplates2/qquicklabel.cpp index 45c7e5a4..fdda4542 100644 --- a/src/quicktemplates2/qquicklabel.cpp +++ b/src/quicktemplates2/qquicklabel.cpp @@ -108,18 +108,31 @@ void QQuickLabelPrivate::resolveFont() inheritFont(QQuickControlPrivate::parentFont(q)); } -void QQuickLabelPrivate::inheritFont(const QFont &f) +void QQuickLabelPrivate::inheritFont(const QFont &font) { - Q_Q(QQuickLabel); - QFont parentFont = font.resolve(f); - parentFont.resolve(font.resolve() | f.resolve()); + QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font; + parentFont.resolve(extra.isAllocated() ? extra->requestedFont.resolve() | font.resolve() : font.resolve()); const QFont defaultFont = QQuickControlPrivate::themeFont(QPlatformTheme::LabelFont); const QFont resolvedFont = parentFont.resolve(defaultFont); - const bool changed = resolvedFont != sourceFont; - q->QQuickText::setFont(resolvedFont); - if (changed) + setFont_helper(resolvedFont); +} + +/*! + \internal + + Assign \a font to this control, and propagate it to all children. +*/ +void QQuickLabelPrivate::updateFont(const QFont &font) +{ + Q_Q(QQuickLabel); + QFont oldFont = sourceFont; + q->QQuickText::setFont(font); + + QQuickControlPrivate::updateFontRecur(q, font); + + if (oldFont != font) emit q->fontChanged(); } @@ -170,10 +183,10 @@ QFont QQuickLabel::font() const void QQuickLabel::setFont(const QFont &font) { Q_D(QQuickLabel); - if (d->font.resolve() == font.resolve() && d->font == font) + if (d->extra.value().requestedFont.resolve() == font.resolve() && d->extra.value().requestedFont == font) return; - d->font = font; + d->extra.value().requestedFont = font; d->resolveFont(); } diff --git a/src/quicktemplates2/qquicklabel_p_p.h b/src/quicktemplates2/qquicklabel_p_p.h index c24c855b..dadd63df 100644 --- a/src/quicktemplates2/qquicklabel_p_p.h +++ b/src/quicktemplates2/qquicklabel_p_p.h @@ -48,6 +48,7 @@ // We mean it. // +#include <QtQml/private/qlazilyallocated_p.h> #include <QtQuick/private/qquicktext_p_p.h> #if QT_CONFIG(accessibility) @@ -75,7 +76,13 @@ public: } void resolveFont(); - void inheritFont(const QFont &f); + void inheritFont(const QFont &font); + void updateFont(const QFont &font); + inline void setFont_helper(const QFont &font) { + if (sourceFont.resolve() == font.resolve() && sourceFont == font) + return; + updateFont(font); + } void textChanged(const QString &text); @@ -84,7 +91,11 @@ public: QAccessible::Role accessibleRole() const override; #endif - QFont font; + struct ExtraData { + QFont requestedFont; + }; + QLazilyAllocated<ExtraData> extra; + QQuickItem *background; QQuickAccessibleAttached *accessibleAttached; }; diff --git a/src/quicktemplates2/qquickmenuitem.cpp b/src/quicktemplates2/qquickmenuitem.cpp index e15640fb..0c6c80a3 100644 --- a/src/quicktemplates2/qquickmenuitem.cpp +++ b/src/quicktemplates2/qquickmenuitem.cpp @@ -55,6 +55,10 @@ QT_BEGIN_NAMESPACE providing a familiar way to respond to menu items being \l triggered, for example. + MenuItem inherits its API from AbstractButton. For instance, you can set + \l {AbstractButton::text}{text} and \l [QML]{Button Icons}{icon} using the + AbstractButton API + \code Button { id: fileButton @@ -110,11 +114,6 @@ QQuickMenuItem::QQuickMenuItem(QQuickItem *parent) connect(this, &QQuickAbstractButton::clicked, this, &QQuickMenuItem::triggered); } -QFont QQuickMenuItem::defaultFont() const -{ - return QQuickControlPrivate::themeFont(QPlatformTheme::MenuItemFont); -} - /*! \qmlproperty bool QtQuick.Controls::MenuItem::highlighted @@ -141,6 +140,11 @@ void QQuickMenuItem::setHighlighted(bool highlighted) emit highlightedChanged(); } +QFont QQuickMenuItem::defaultFont() const +{ + return QQuickControlPrivate::themeFont(QPlatformTheme::MenuItemFont); +} + #if QT_CONFIG(accessibility) QAccessible::Role QQuickMenuItem::accessibleRole() const { diff --git a/src/quicktemplates2/qquickoverlay_p_p.h b/src/quicktemplates2/qquickoverlay_p_p.h index fa53d52b..de8539c9 100644 --- a/src/quicktemplates2/qquickoverlay_p_p.h +++ b/src/quicktemplates2/qquickoverlay_p_p.h @@ -48,7 +48,7 @@ // We mean it. // -#include "qquickoverlay_p.h" +#include <QtQuickTemplates2/private/qquickoverlay_p.h> #include <QtQuick/private/qquickitem_p.h> #include <QtQuick/private/qquickitemchangelistener_p.h> diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index aee013e3..045b0fb8 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -657,6 +657,7 @@ QQuickPopup::~QQuickPopup() setParentItem(nullptr); d->popupItem->ungrabShortcut(); delete d->popupItem; + d->popupItem = nullptr; } /*! diff --git a/src/quicktemplates2/qquickpopup_p_p.h b/src/quicktemplates2/qquickpopup_p_p.h index 316ea5bd..fa79003e 100644 --- a/src/quicktemplates2/qquickpopup_p_p.h +++ b/src/quicktemplates2/qquickpopup_p_p.h @@ -48,8 +48,8 @@ // We mean it. // -#include "qquickpopup_p.h" -#include "qquickcontrol_p.h" +#include <QtQuickTemplates2/private/qquickpopup_p.h> +#include <QtQuickTemplates2/private/qquickcontrol_p.h> #include <QtCore/private/qobject_p.h> #include <QtQuick/qquickitem.h> diff --git a/src/quicktemplates2/qquickpopupitem_p_p.h b/src/quicktemplates2/qquickpopupitem_p_p.h index 16321feb..9b3c76df 100644 --- a/src/quicktemplates2/qquickpopupitem_p_p.h +++ b/src/quicktemplates2/qquickpopupitem_p_p.h @@ -48,7 +48,7 @@ // We mean it. // -#include "qquickcontrol_p.h" +#include <QtQuickTemplates2/private/qquickcontrol_p.h> QT_BEGIN_NAMESPACE diff --git a/src/quicktemplates2/qquickrangeslider.cpp b/src/quicktemplates2/qquickrangeslider.cpp index 5b03de88..f1e8a01e 100644 --- a/src/quicktemplates2/qquickrangeslider.cpp +++ b/src/quicktemplates2/qquickrangeslider.cpp @@ -779,6 +779,8 @@ void QQuickRangeSlider::setSnapMode(SnapMode mode) Possible values: \value Qt.Horizontal Horizontal (default) \value Qt.Vertical Vertical + + \sa horizontal, vertical */ Qt::Orientation QQuickRangeSlider::orientation() const { @@ -797,6 +799,36 @@ void QQuickRangeSlider::setOrientation(Qt::Orientation orientation) } /*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::RangeSlider::horizontal + \readonly + + This property holds whether the slider is horizontal. + + \sa orientation +*/ +bool QQuickRangeSlider::isHorizontal() const +{ + Q_D(const QQuickRangeSlider); + return d->orientation == Qt::Horizontal; +} + +/*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::RangeSlider::vertical + \readonly + + This property holds whether the slider is vertical. + + \sa orientation +*/ +bool QQuickRangeSlider::isVertical() const +{ + Q_D(const QQuickRangeSlider); + return d->orientation == Qt::Vertical; +} + +/*! \since QtQuick.Controls 2.2 \qmlproperty bool QtQuick.Controls::RangeSlider::live diff --git a/src/quicktemplates2/qquickrangeslider_p.h b/src/quicktemplates2/qquickrangeslider_p.h index c4bc52ff..b4553501 100644 --- a/src/quicktemplates2/qquickrangeslider_p.h +++ b/src/quicktemplates2/qquickrangeslider_p.h @@ -65,6 +65,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickRangeSlider : public QQuickControl Q_PROPERTY(qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged FINAL) Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) + Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) + Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL REVISION 2) public: @@ -95,6 +97,9 @@ public: Qt::Orientation orientation() const; void setOrientation(Qt::Orientation orientation); + bool isHorizontal() const; + bool isVertical() const; + bool live() const; void setLive(bool live); diff --git a/src/quicktemplates2/qquickscrollbar.cpp b/src/quicktemplates2/qquickscrollbar.cpp index c04a2d0d..128bca6f 100644 --- a/src/quicktemplates2/qquickscrollbar.cpp +++ b/src/quicktemplates2/qquickscrollbar.cpp @@ -438,6 +438,8 @@ void QQuickScrollBar::setPressed(bool pressed) This property is automatically set when the scroll bar is \l {Attaching ScrollBar to a Flickable}{attached to a flickable}. + + \sa horizontal, vertical */ Qt::Orientation QQuickScrollBar::orientation() const { @@ -559,6 +561,36 @@ void QQuickScrollBar::setPolicy(Policy policy) } /*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::ScrollBar::horizontal + \readonly + + This property holds whether the scroll bar is horizontal. + + \sa orientation +*/ +bool QQuickScrollBar::isHorizontal() const +{ + Q_D(const QQuickScrollBar); + return d->orientation == Qt::Horizontal; +} + +/*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::ScrollBar::vertical + \readonly + + This property holds whether the scroll bar is vertical. + + \sa orientation +*/ +bool QQuickScrollBar::isVertical() const +{ + Q_D(const QQuickScrollBar); + return d->orientation == Qt::Vertical; +} + +/*! \qmlmethod void QtQuick.Controls::ScrollBar::increase() Increases the position by \l stepSize or \c 0.1 if stepSize is \c 0.0. diff --git a/src/quicktemplates2/qquickscrollbar_p.h b/src/quicktemplates2/qquickscrollbar_p.h index 28c48428..9b417a2b 100644 --- a/src/quicktemplates2/qquickscrollbar_p.h +++ b/src/quicktemplates2/qquickscrollbar_p.h @@ -67,6 +67,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickScrollBar : public QQuickControl Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL REVISION 2) Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive RESET resetInteractive NOTIFY interactiveChanged FINAL REVISION 2) Q_PROPERTY(Policy policy READ policy WRITE setPolicy NOTIFY policyChanged FINAL REVISION 2) + Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) + Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) public: explicit QQuickScrollBar(QQuickItem *parent = nullptr); @@ -112,6 +114,9 @@ public: Policy policy() const; void setPolicy(Policy policy); + bool isHorizontal() const; + bool isVertical() const; + public Q_SLOTS: void increase(); void decrease(); diff --git a/src/quicktemplates2/qquickscrollindicator.cpp b/src/quicktemplates2/qquickscrollindicator.cpp index 347c2a68..5e39134c 100644 --- a/src/quicktemplates2/qquickscrollindicator.cpp +++ b/src/quicktemplates2/qquickscrollindicator.cpp @@ -276,6 +276,8 @@ void QQuickScrollIndicator::setActive(bool active) This property is automatically set when the scroll indicator is \l {Attaching ScrollIndicator to a Flickable}{attached to a flickable}. + + \sa horizontal, vertical */ Qt::Orientation QQuickScrollIndicator::orientation() const { @@ -295,6 +297,36 @@ void QQuickScrollIndicator::setOrientation(Qt::Orientation orientation) emit orientationChanged(); } +/*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::ScrollIndicator::horizontal + \readonly + + This property holds whether the scroll indicator is horizontal. + + \sa orientation +*/ +bool QQuickScrollIndicator::isHorizontal() const +{ + Q_D(const QQuickScrollIndicator); + return d->orientation == Qt::Horizontal; +} + +/*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::ScrollIndicator::vertical + \readonly + + This property holds whether the scroll indicator is vertical. + + \sa orientation +*/ +bool QQuickScrollIndicator::isVertical() const +{ + Q_D(const QQuickScrollIndicator); + return d->orientation == Qt::Vertical; +} + class QQuickScrollIndicatorAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener { public: diff --git a/src/quicktemplates2/qquickscrollindicator_p.h b/src/quicktemplates2/qquickscrollindicator_p.h index bc6c5418..6f08ef31 100644 --- a/src/quicktemplates2/qquickscrollindicator_p.h +++ b/src/quicktemplates2/qquickscrollindicator_p.h @@ -63,6 +63,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickScrollIndicator : public QQuickCont Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged FINAL) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) + Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) + Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) public: explicit QQuickScrollIndicator(QQuickItem *parent = nullptr); @@ -78,6 +80,9 @@ public: Qt::Orientation orientation() const; void setOrientation(Qt::Orientation orientation); + bool isHorizontal() const; + bool isVertical() const; + public Q_SLOTS: void setSize(qreal size); void setPosition(qreal position); diff --git a/src/quicktemplates2/qquickslider.cpp b/src/quicktemplates2/qquickslider.cpp index 15c7be97..2e337c3a 100644 --- a/src/quicktemplates2/qquickslider.cpp +++ b/src/quicktemplates2/qquickslider.cpp @@ -479,6 +479,36 @@ void QQuickSlider::setPressed(bool pressed) } /*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::Slider::horizontal + \readonly + + This property holds whether the slider is horizontal. + + \sa orientation +*/ +bool QQuickSlider::isHorizontal() const +{ + Q_D(const QQuickSlider); + return d->orientation == Qt::Horizontal; +} + +/*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::Slider::vertical + \readonly + + This property holds whether the slider is vertical. + + \sa orientation +*/ +bool QQuickSlider::isVertical() const +{ + Q_D(const QQuickSlider); + return d->orientation == Qt::Vertical; +} + +/*! \qmlproperty enumeration QtQuick.Controls::Slider::orientation This property holds the orientation. @@ -486,6 +516,8 @@ void QQuickSlider::setPressed(bool pressed) Possible values: \value Qt.Horizontal Horizontal (default) \value Qt.Vertical Vertical + + \sa horizontal, vertical */ Qt::Orientation QQuickSlider::orientation() const { diff --git a/src/quicktemplates2/qquickslider_p.h b/src/quicktemplates2/qquickslider_p.h index 6f0e6fc6..cb441ddd 100644 --- a/src/quicktemplates2/qquickslider_p.h +++ b/src/quicktemplates2/qquickslider_p.h @@ -66,6 +66,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSlider : public QQuickControl Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL) Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL REVISION 2) Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) + Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) + Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL) Q_PROPERTY(QQuickItem *handle READ handle WRITE setHandle NOTIFY handleChanged FINAL) @@ -103,6 +105,9 @@ public: bool isPressed() const; void setPressed(bool pressed); + bool isHorizontal() const; + bool isVertical() const; + Qt::Orientation orientation() const; void setOrientation(Qt::Orientation orientation); diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp index a41383aa..07bf4121 100644 --- a/src/quicktemplates2/qquickspinbox.cpp +++ b/src/quicktemplates2/qquickspinbox.cpp @@ -108,6 +108,7 @@ class QQuickSpinBoxPrivate : public QQuickControlPrivate public: QQuickSpinBoxPrivate() : editable(false), + wrap(false), from(0), to(99), value(0), @@ -121,9 +122,10 @@ public: { } - int boundValue(int value) const; + int boundValue(int value, bool wrap) const; void updateValue(); - bool setValue(int value); + bool setValue(int value, bool wrap); + bool stepBy(int steps); int effectiveStepSize() const; @@ -143,6 +145,7 @@ public: void handleUngrab() override; bool editable; + bool wrap; int from; int to; int value; @@ -157,9 +160,20 @@ public: Qt::InputMethodHints inputMethodHints; }; -int QQuickSpinBoxPrivate::boundValue(int value) const +int QQuickSpinBoxPrivate::boundValue(int value, bool wrap) const { - return from > to ? qBound(to, value, from) : qBound(from, value, to); + bool inverted = from > to; + if (!wrap) + return inverted ? qBound(to, value, from) : qBound(from, value, to); + + int f = inverted ? to : from; + int t = inverted ? from : to; + if (value < f) + value = t; + else if (value > t) + value = f; + + return value; } void QQuickSpinBoxPrivate::updateValue() @@ -174,7 +188,7 @@ void QQuickSpinBoxPrivate::updateValue() QJSValue loc(v4, QQmlLocale::wrap(v4, locale)); QJSValue val = q->valueFromText().call(QJSValueList() << text.toString() << loc); const int oldValue = value; - q->setValue(val.toInt()); + setValue(val.toInt(), /* allowWrap = */ false); if (oldValue != value) emit q->valueModified(); } @@ -182,11 +196,11 @@ void QQuickSpinBoxPrivate::updateValue() } } -bool QQuickSpinBoxPrivate::setValue(int newValue) +bool QQuickSpinBoxPrivate::setValue(int newValue, bool allowWrap) { Q_Q(QQuickSpinBox); if (q->isComponentComplete()) - newValue = boundValue(newValue); + newValue = boundValue(newValue, allowWrap); if (value == newValue) return false; @@ -200,6 +214,11 @@ bool QQuickSpinBoxPrivate::setValue(int newValue) return true; } +bool QQuickSpinBoxPrivate::stepBy(int steps) +{ + return setValue(value + steps, wrap); +} + int QQuickSpinBoxPrivate::effectiveStepSize() const { return from > to ? -1 * stepSize : stepSize; @@ -217,7 +236,7 @@ void QQuickSpinBoxPrivate::updateUpEnabled() if (!upIndicator) return; - upIndicator->setEnabled(from < to ? value < to : value > to); + upIndicator->setEnabled(wrap || (from < to ? value < to : value > to)); } bool QQuickSpinBoxPrivate::downEnabled() const @@ -232,7 +251,7 @@ void QQuickSpinBoxPrivate::updateDownEnabled() if (!downIndicator) return; - downIndicator->setEnabled(from < to ? value > from : value < from); + downIndicator->setEnabled(wrap || (from < to ? value > from : value < from)); } void QQuickSpinBoxPrivate::updateHover(const QPointF &pos) @@ -373,7 +392,7 @@ void QQuickSpinBox::setFrom(int from) d->from = from; emit fromChanged(); if (isComponentComplete()) { - if (!d->setValue(d->value)) { + if (!d->setValue(d->value, /* allowWrap = */ false)) { d->updateUpEnabled(); d->updateDownEnabled(); } @@ -402,7 +421,7 @@ void QQuickSpinBox::setTo(int to) d->to = to; emit toChanged(); if (isComponentComplete()) { - if (!d->setValue(d->value)) { + if (!d->setValue(d->value, /* allowWrap = */false)) { d->updateUpEnabled(); d->updateDownEnabled(); } @@ -423,7 +442,7 @@ int QQuickSpinBox::value() const void QQuickSpinBox::setValue(int value) { Q_D(QQuickSpinBox); - d->setValue(value); + d->setValue(value, /* allowWrap = */ false); } /*! @@ -694,6 +713,34 @@ bool QQuickSpinBox::isInputMethodComposing() const } /*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::SpinBox::wrap + + This property holds whether the spinbox wraps. The default value is \c false. + + If wrap is \c true, stepping past \l to changes the value to \l from and vice versa. +*/ +bool QQuickSpinBox::wrap() const +{ + Q_D(const QQuickSpinBox); + return d->wrap; +} + +void QQuickSpinBox::setWrap(bool wrap) +{ + Q_D(QQuickSpinBox); + if (d->wrap == wrap) + return; + + d->wrap = wrap; + if (d->value == d->from || d->value == d->to) { + d->updateUpEnabled(); + d->updateDownEnabled(); + } + emit wrapChanged(); +} + +/*! \qmlmethod void QtQuick.Controls::SpinBox::increase() Increases the value by \l stepSize, or \c 1 if stepSize is not defined. @@ -703,7 +750,7 @@ bool QQuickSpinBox::isInputMethodComposing() const void QQuickSpinBox::increase() { Q_D(QQuickSpinBox); - setValue(d->value + d->effectiveStepSize()); + d->stepBy(d->effectiveStepSize()); } /*! @@ -716,7 +763,7 @@ void QQuickSpinBox::increase() void QQuickSpinBox::decrease() { Q_D(QQuickSpinBox); - setValue(d->value - d->effectiveStepSize()); + d->stepBy(-d->effectiveStepSize()); } void QQuickSpinBox::focusInEvent(QFocusEvent *event) @@ -819,7 +866,7 @@ void QQuickSpinBox::wheelEvent(QWheelEvent *event) const int oldValue = d->value; const QPointF angle = event->angleDelta(); const qreal delta = (qFuzzyIsNull(angle.y()) ? angle.x() : angle.y()) / QWheelEvent::DefaultDeltasPerStep; - setValue(oldValue + qRound(d->effectiveStepSize() * delta)); + d->stepBy(qRound(d->effectiveStepSize() * delta)); if (d->value != oldValue) emit valueModified(); event->setAccepted(d->value != oldValue); diff --git a/src/quicktemplates2/qquickspinbox_p.h b/src/quicktemplates2/qquickspinbox_p.h index 73cb3389..27956d7c 100644 --- a/src/quicktemplates2/qquickspinbox_p.h +++ b/src/quicktemplates2/qquickspinbox_p.h @@ -73,6 +73,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSpinBox : public QQuickControl Q_PROPERTY(QQuickSpinButton *down READ down CONSTANT FINAL) Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints NOTIFY inputMethodHintsChanged FINAL REVISION 2) Q_PROPERTY(bool inputMethodComposing READ isInputMethodComposing NOTIFY inputMethodComposingChanged FINAL REVISION 2) + Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY wrapChanged FINAL REVISION 3) public: explicit QQuickSpinBox(QQuickItem *parent = nullptr); @@ -109,6 +110,9 @@ public: bool isInputMethodComposing() const; + bool wrap() const; + void setWrap(bool wrap); + public Q_SLOTS: void increase(); void decrease(); @@ -125,6 +129,7 @@ Q_SIGNALS: Q_REVISION(2) void valueModified(); Q_REVISION(2) void inputMethodHintsChanged(); Q_REVISION(2) void inputMethodComposingChanged(); + Q_REVISION(3) void wrapChanged(); protected: void focusInEvent(QFocusEvent *event) override; diff --git a/src/quicktemplates2/qquickswipeview.cpp b/src/quicktemplates2/qquickswipeview.cpp index cfea81bc..8770294b 100644 --- a/src/quicktemplates2/qquickswipeview.cpp +++ b/src/quicktemplates2/qquickswipeview.cpp @@ -121,6 +121,32 @@ public: Qt::Orientation orientation; }; +class QQuickSwipeViewAttachedPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QQuickSwipeViewAttached) + +public: + QQuickSwipeViewAttachedPrivate() + : swipeView(nullptr), + index(-1), + currentIndex(-1) + { + } + + static QQuickSwipeViewAttachedPrivate *get(QQuickSwipeViewAttached *attached) + { + return attached->d_func(); + } + + void update(QQuickSwipeView *newView, int newIndex); + void updateCurrentIndex(); + void setCurrentIndex(int i); + + QQuickSwipeView *swipeView; + int index; + int currentIndex; +}; + void QQuickSwipeViewPrivate::resizeItems() { Q_Q(QQuickSwipeView); @@ -190,6 +216,8 @@ void QQuickSwipeView::setInteractive(bool interactive) Possible values: \value Qt.Horizontal Horizontal (default) \value Qt.Vertical Vertical + + \sa horizontal, vertical */ Qt::Orientation QQuickSwipeView::orientation() const { @@ -209,6 +237,36 @@ void QQuickSwipeView::setOrientation(Qt::Orientation orientation) emit orientationChanged(); } +/*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::SwipeView::horizontal + \readonly + + This property holds whether the swipe view is horizontal. + + \sa orientation +*/ +bool QQuickSwipeView::isHorizontal() const +{ + Q_D(const QQuickSwipeView); + return d->orientation == Qt::Horizontal; +} + +/*! + \since QtQuick.Controls 2.3 + \qmlproperty bool QtQuick.Controls::SwipeView::vertical + \readonly + + This property holds whether the swipe view is vertical. + + \sa orientation +*/ +bool QQuickSwipeView::isVertical() const +{ + Q_D(const QQuickSwipeView); + return d->orientation == Qt::Vertical; +} + QQuickSwipeViewAttached *QQuickSwipeView::qmlAttachedProperties(QObject *object) { return new QQuickSwipeViewAttached(object); @@ -221,12 +279,29 @@ void QQuickSwipeView::geometryChanged(const QRectF &newGeometry, const QRectF &o d->resizeItems(); } -void QQuickSwipeView::itemAdded(int, QQuickItem *item) +void QQuickSwipeView::itemAdded(int index, QQuickItem *item) { Q_D(QQuickSwipeView); QQuickItemPrivate::get(item)->setCulled(true); // QTBUG-51078, QTBUG-51669 if (isComponentComplete()) item->setSize(QSizeF(d->contentItem->width(), d->contentItem->height())); + QQuickSwipeViewAttached *attached = qobject_cast<QQuickSwipeViewAttached *>(qmlAttachedPropertiesObject<QQuickSwipeView>(item)); + if (attached) + QQuickSwipeViewAttachedPrivate::get(attached)->update(this, index); +} + +void QQuickSwipeView::itemMoved(int index, QQuickItem *item) +{ + QQuickSwipeViewAttached *attached = qobject_cast<QQuickSwipeViewAttached *>(qmlAttachedPropertiesObject<QQuickSwipeView>(item)); + if (attached) + QQuickSwipeViewAttachedPrivate::get(attached)->update(this, index); +} + +void QQuickSwipeView::itemRemoved(int, QQuickItem *item) +{ + QQuickSwipeViewAttached *attached = qobject_cast<QQuickSwipeViewAttached *>(qmlAttachedPropertiesObject<QQuickSwipeView>(item)); + if (attached) + QQuickSwipeViewAttachedPrivate::get(attached)->update(nullptr, -1); } #if QT_CONFIG(accessibility) @@ -283,85 +358,11 @@ QAccessible::Role QQuickSwipeView::accessibleRole() const It is attached to each child item of the SwipeView. */ -class QQuickSwipeViewAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickSwipeViewAttached) -public: - QQuickSwipeViewAttachedPrivate() - : item(nullptr), - swipeView(nullptr), - index(-1), - currentIndex(-1) - { - } - - ~QQuickSwipeViewAttachedPrivate() { - } - - void updateView(QQuickItem *parent); - - void itemChildAdded(QQuickItem *, QQuickItem *) override; - void itemChildRemoved(QQuickItem *, QQuickItem *) override; - void itemParentChanged(QQuickItem *, QQuickItem *) override; - void itemDestroyed(QQuickItem *) override; - - void updateIndex(); - void updateCurrentIndex(); - - void setView(QQuickSwipeView *view); - void setIndex(int i); - void setCurrentIndex(int i); - - QQuickItem *item; - QQuickSwipeView *swipeView; - int index; - int currentIndex; -}; - -void QQuickSwipeViewAttachedPrivate::updateIndex() -{ - setIndex(swipeView ? QQuickSwipeViewPrivate::get(swipeView)->contentModel->indexOf(item, nullptr) : -1); -} - void QQuickSwipeViewAttachedPrivate::updateCurrentIndex() { setCurrentIndex(swipeView ? swipeView->currentIndex() : -1); } -void QQuickSwipeViewAttachedPrivate::setView(QQuickSwipeView *view) -{ - if (view == swipeView) - return; - - if (swipeView) { - QQuickItemPrivate *p = QQuickItemPrivate::get(swipeView); - p->removeItemChangeListener(this, QQuickItemPrivate::Children); - - disconnect(swipeView, &QQuickSwipeView::currentIndexChanged, - this, &QQuickSwipeViewAttachedPrivate::updateCurrentIndex); - disconnect(swipeView, &QQuickSwipeView::contentChildrenChanged, - this, &QQuickSwipeViewAttachedPrivate::updateIndex); - } - - swipeView = view; - - if (swipeView) { - QQuickItemPrivate *p = QQuickItemPrivate::get(swipeView); - p->addItemChangeListener(this, QQuickItemPrivate::Children); - - connect(swipeView, &QQuickSwipeView::currentIndexChanged, - this, &QQuickSwipeViewAttachedPrivate::updateCurrentIndex); - connect(swipeView, &QQuickSwipeView::contentChildrenChanged, - this, &QQuickSwipeViewAttachedPrivate::updateIndex); - } - - Q_Q(QQuickSwipeViewAttached); - emit q->viewChanged(); - - updateIndex(); - updateCurrentIndex(); -} - void QQuickSwipeViewAttachedPrivate::setCurrentIndex(int i) { if (i == currentIndex) @@ -381,79 +382,37 @@ void QQuickSwipeViewAttachedPrivate::setCurrentIndex(int i) emit q->isPreviousItemChanged(); } -void QQuickSwipeViewAttachedPrivate::setIndex(int i) +void QQuickSwipeViewAttachedPrivate::update(QQuickSwipeView *newView, int newIndex) { - if (i == index) - return; - - index = i; Q_Q(QQuickSwipeViewAttached); - emit q->indexChanged(); -} + int oldIndex = index; + QQuickSwipeView *oldView = swipeView; -void QQuickSwipeViewAttachedPrivate::updateView(QQuickItem *parent) -{ - // parent can be, e.g.: - // - The contentItem of a ListView (typically the case) - // - A non-visual or weird type like TestCase, when child items are created from components - // wherein the attached properties are used - // - null, when the item was removed with removeItem() - QQuickSwipeView *view = nullptr; - if (parent) { - view = qobject_cast<QQuickSwipeView*>(parent); - if (!view) { - if (parent->parentItem() && parent->parentItem()->property("contentItem").isValid()) { - // The parent is the contentItem of some kind of view. - view = qobject_cast<QQuickSwipeView*>(parent->parentItem()->parentItem()); - } + index = newIndex; + swipeView = newView; + + if (oldView != newView) { + if (oldView) { + disconnect(oldView, &QQuickSwipeView::currentIndexChanged, + this, &QQuickSwipeViewAttachedPrivate::updateCurrentIndex); } + if (newView) { + connect(newView, &QQuickSwipeView::currentIndexChanged, + this, &QQuickSwipeViewAttachedPrivate::updateCurrentIndex); + } + emit q->viewChanged(); } + if (oldIndex != newIndex) + emit q->indexChanged(); - setView(view); -} - -void QQuickSwipeViewAttachedPrivate::itemChildAdded(QQuickItem *, QQuickItem *) -{ - updateIndex(); -} - -void QQuickSwipeViewAttachedPrivate::itemChildRemoved(QQuickItem *, QQuickItem *) -{ - updateIndex(); -} - -void QQuickSwipeViewAttachedPrivate::itemParentChanged(QQuickItem *, QQuickItem *parent) -{ - updateView(parent); -} - -void QQuickSwipeViewAttachedPrivate::itemDestroyed(QQuickItem *item) -{ - QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent | QQuickItemPrivate::Destroyed); + updateCurrentIndex(); } QQuickSwipeViewAttached::QQuickSwipeViewAttached(QObject *parent) : QObject(*(new QQuickSwipeViewAttachedPrivate), parent) { - Q_D(QQuickSwipeViewAttached); - d->item = qobject_cast<QQuickItem *>(parent); - if (d->item) { - if (d->item->parentItem()) - d->updateView(d->item->parentItem()); - - QQuickItemPrivate *p = QQuickItemPrivate::get(d->item); - p->addItemChangeListener(d, QQuickItemPrivate::Parent | QQuickItemPrivate::Destroyed); - } else if (parent) { + if (!qobject_cast<QQuickItem *>(parent)) qmlWarning(parent) << "SwipeView: attached properties must be accessed from within a child item"; - } -} - -QQuickSwipeViewAttached::~QQuickSwipeViewAttached() -{ - Q_D(QQuickSwipeViewAttached); - QQuickItem *item = qobject_cast<QQuickItem *>(parent()); - if (item) - QQuickItemPrivate::get(item)->removeItemChangeListener(d, QQuickItemPrivate::Parent | QQuickItemPrivate::Destroyed); } QQuickSwipeView *QQuickSwipeViewAttached::view() const diff --git a/src/quicktemplates2/qquickswipeview_p.h b/src/quicktemplates2/qquickswipeview_p.h index e07ed7f0..543cb6aa 100644 --- a/src/quicktemplates2/qquickswipeview_p.h +++ b/src/quicktemplates2/qquickswipeview_p.h @@ -60,6 +60,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwipeView : public QQuickContainer Q_OBJECT Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged FINAL REVISION 1) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL REVISION 2) + Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) + Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) public: explicit QQuickSwipeView(QQuickItem *parent = nullptr); @@ -70,6 +72,9 @@ public: Qt::Orientation orientation() const; void setOrientation(Qt::Orientation orientation); + bool isHorizontal() const; + bool isVertical() const; + static QQuickSwipeViewAttached *qmlAttachedProperties(QObject *object); Q_SIGNALS: @@ -79,6 +84,8 @@ Q_SIGNALS: protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; void itemAdded(int index, QQuickItem *item) override; + void itemMoved(int index, QQuickItem *item) override; + void itemRemoved(int index, QQuickItem *item) override; #if QT_CONFIG(accessibility) QAccessible::Role accessibleRole() const override; @@ -102,7 +109,6 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSwipeViewAttached : public QObject public: explicit QQuickSwipeViewAttached(QObject *parent = nullptr); - ~QQuickSwipeViewAttached(); int index() const; bool isCurrentItem() const; diff --git a/src/quicktemplates2/qquicktabbar.cpp b/src/quicktemplates2/qquicktabbar.cpp index 7ce8a21e..2f025dcf 100644 --- a/src/quicktemplates2/qquicktabbar.cpp +++ b/src/quicktemplates2/qquicktabbar.cpp @@ -116,6 +116,28 @@ public: QQuickTabBar::Position position; }; +class QQuickTabBarAttachedPrivate : public QObjectPrivate +{ + Q_DECLARE_PUBLIC(QQuickTabBarAttached) + +public: + QQuickTabBarAttachedPrivate() + : index(-1), + tabBar(nullptr) + { + } + + static QQuickTabBarAttachedPrivate *get(QQuickTabBarAttached *attached) + { + return attached->d_func(); + } + + void update(QQuickTabBar *tabBar, int index); + + int index; + QQuickTabBar *tabBar; +}; + QQuickTabBarPrivate::QQuickTabBarPrivate() : updatingLayout(false), hasContentWidth(false), @@ -152,38 +174,47 @@ void QQuickTabBarPrivate::updateLayout() qreal maxHeight = 0; qreal totalWidth = 0; qreal reservedWidth = 0; + int resizableCount = 0; - QVector<QQuickItem *> resizableItems; - resizableItems.reserve(count); + QVector<QQuickItem *> allItems; + allItems.reserve(count); for (int i = 0; i < count; ++i) { QQuickItem *item = q->itemAt(i); if (item) { QQuickItemPrivate *p = QQuickItemPrivate::get(item); if (!p->widthValid) { - resizableItems += item; + ++resizableCount; totalWidth += item->implicitWidth(); } else { reservedWidth += item->width(); totalWidth += item->width(); } maxHeight = qMax(maxHeight, item->implicitHeight()); + allItems += item; } } const qreal totalSpacing = qMax(0, count - 1) * spacing; totalWidth += totalSpacing; - if (!resizableItems.isEmpty()) { - const qreal itemWidth = (contentItem->width() - reservedWidth - totalSpacing) / resizableItems.count(); + const qreal itemWidth = (contentItem->width() - reservedWidth - totalSpacing) / qMax(1, resizableCount); - updatingLayout = true; - for (QQuickItem *item : qAsConst(resizableItems)) { + updatingLayout = true; + for (QQuickItem *item : qAsConst(allItems)) { + QQuickItemPrivate *p = QQuickItemPrivate::get(item); + if (!p->widthValid) { item->setWidth(itemWidth); - QQuickItemPrivate::get(item)->widthValid = false; + p->widthValid = false; + } + if (!p->heightValid) { + item->setHeight(hasContentHeight ? contentHeight : maxHeight); + p->heightValid = false; + } else { + item->setY((maxHeight - item->height()) / 2); } - updatingLayout = false; } + updatingLayout = false; bool contentWidthChange = false; if (!hasContentWidth && !qFuzzyCompare(contentWidth, totalWidth)) { @@ -342,6 +373,11 @@ void QQuickTabBar::resetContentHeight() d->updateLayout(); } +QQuickTabBarAttached *QQuickTabBar::qmlAttachedProperties(QObject *object) +{ + return new QQuickTabBarAttached(object); +} + void QQuickTabBar::updatePolish() { Q_D(QQuickTabBar); @@ -376,16 +412,29 @@ void QQuickTabBar::itemAdded(int index, QQuickItem *item) QQuickItemPrivate::get(item)->setCulled(true); // QTBUG-55129 if (QQuickTabButton *button = qobject_cast<QQuickTabButton *>(item)) QObjectPrivate::connect(button, &QQuickTabButton::checkedChanged, d, &QQuickTabBarPrivate::updateCurrentIndex); + QQuickTabBarAttached *attached = qobject_cast<QQuickTabBarAttached *>(qmlAttachedPropertiesObject<QQuickTabBar>(item)); + if (attached) + QQuickTabBarAttachedPrivate::get(attached)->update(this, index); if (isComponentComplete()) polish(); } +void QQuickTabBar::itemMoved(int index, QQuickItem *item) +{ + QQuickTabBarAttached *attached = qobject_cast<QQuickTabBarAttached *>(qmlAttachedPropertiesObject<QQuickTabBar>(item)); + if (attached) + QQuickTabBarAttachedPrivate::get(attached)->update(this, index); +} + void QQuickTabBar::itemRemoved(int index, QQuickItem *item) { Q_D(QQuickTabBar); Q_UNUSED(index); if (QQuickTabButton *button = qobject_cast<QQuickTabButton *>(item)) QObjectPrivate::disconnect(button, &QQuickTabButton::checkedChanged, d, &QQuickTabBarPrivate::updateCurrentIndex); + QQuickTabBarAttached *attached = qobject_cast<QQuickTabBarAttached *>(qmlAttachedPropertiesObject<QQuickTabBar>(item)); + if (attached) + QQuickTabBarAttachedPrivate::get(attached)->update(nullptr, -1); if (isComponentComplete()) polish(); } @@ -397,4 +446,87 @@ QAccessible::Role QQuickTabBar::accessibleRole() const } #endif +/*! + \qmlattachedproperty int QtQuick.Controls::TabBar::index + \since QtQuick.Controls 2.3 + \readonly + + This attached property holds the index of each tab button in the TabBar. + + It is attached to each tab button of the TabBar. +*/ + +/*! + \qmlattachedproperty TabBar QtQuick.Controls::TabBar::tabBar + \since QtQuick.Controls 2.3 + \readonly + + This attached property holds the tab bar that manages this tab button. + + It is attached to each tab button of the TabBar. +*/ + +/*! + \qmlattachedproperty enumeration QtQuick.Controls::TabBar::position + \since QtQuick.Controls 2.3 + \readonly + + This attached property holds the position of the tab bar. + + It is attached to each tab button of the TabBar. + + Possible values: + \value TabBar.Header The tab bar is at the top, as a window or page header. + \value TabBar.Footer The tab bar is at the bottom, as a window or page footer. +*/ + +void QQuickTabBarAttachedPrivate::update(QQuickTabBar *newTabBar, int newIndex) +{ + Q_Q(QQuickTabBarAttached); + const int oldIndex = index; + const QQuickTabBar *oldTabBar = tabBar; + const QQuickTabBar::Position oldPos = q->position(); + + index = newIndex; + tabBar = newTabBar; + + if (oldTabBar != newTabBar) { + if (oldTabBar) + QObject::disconnect(oldTabBar, &QQuickTabBar::positionChanged, q, &QQuickTabBarAttached::positionChanged); + if (newTabBar) + QObject::connect(newTabBar, &QQuickTabBar::positionChanged, q, &QQuickTabBarAttached::positionChanged); + emit q->tabBarChanged(); + } + + if (oldIndex != newIndex) + emit q->indexChanged(); + if (oldPos != q->position()) + emit q->positionChanged(); +} + +QQuickTabBarAttached::QQuickTabBarAttached(QObject *parent) + : QObject(*(new QQuickTabBarAttachedPrivate), parent) +{ +} + +int QQuickTabBarAttached::index() const +{ + Q_D(const QQuickTabBarAttached); + return d->index; +} + +QQuickTabBar *QQuickTabBarAttached::tabBar() const +{ + Q_D(const QQuickTabBarAttached); + return d->tabBar; +} + +QQuickTabBar::Position QQuickTabBarAttached::position() const +{ + Q_D(const QQuickTabBarAttached); + if (!d->tabBar) + return QQuickTabBar::Header; + return d->tabBar->position(); +} + QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquicktabbar_p.h b/src/quicktemplates2/qquicktabbar_p.h index 0ffd53d5..e1016c06 100644 --- a/src/quicktemplates2/qquicktabbar_p.h +++ b/src/quicktemplates2/qquicktabbar_p.h @@ -53,6 +53,8 @@ QT_BEGIN_NAMESPACE class QQuickTabBarPrivate; +class QQuickTabBarAttached; +class QQuickTabBarAttachedPrivate; class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTabBar : public QQuickContainer { @@ -81,6 +83,8 @@ public: void setContentHeight(qreal height); void resetContentHeight(); + static QQuickTabBarAttached *qmlAttachedProperties(QObject *object); + Q_SIGNALS: void positionChanged(); Q_REVISION(2) void contentWidthChanged(); @@ -92,6 +96,7 @@ protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; bool isContent(QQuickItem *item) const override; void itemAdded(int index, QQuickItem *item) override; + void itemMoved(int index, QQuickItem *item) override; void itemRemoved(int index, QQuickItem *item) override; #if QT_CONFIG(accessibility) @@ -103,8 +108,33 @@ private: Q_DECLARE_PRIVATE(QQuickTabBar) }; +class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTabBarAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(int index READ index NOTIFY indexChanged FINAL) + Q_PROPERTY(QQuickTabBar *tabBar READ tabBar NOTIFY tabBarChanged FINAL) + Q_PROPERTY(QQuickTabBar::Position position READ position NOTIFY positionChanged FINAL) + +public: + explicit QQuickTabBarAttached(QObject *parent = nullptr); + + int index() const; + QQuickTabBar *tabBar() const; + QQuickTabBar::Position position() const; + +Q_SIGNALS: + void indexChanged(); + void tabBarChanged(); + void positionChanged(); + +private: + Q_DISABLE_COPY(QQuickTabBarAttached) + Q_DECLARE_PRIVATE(QQuickTabBarAttached) +}; + QT_END_NAMESPACE QML_DECLARE_TYPE(QQuickTabBar) +QML_DECLARE_TYPEINFO(QQuickTabBar, QML_HAS_ATTACHED_PROPERTIES) #endif // QQUICKTABBAR_P_H diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp index 21d74dd8..3359f6cb 100644 --- a/src/quicktemplates2/qquicktextarea.cpp +++ b/src/quicktemplates2/qquicktextarea.cpp @@ -189,18 +189,31 @@ void QQuickTextAreaPrivate::resolveFont() inheritFont(QQuickControlPrivate::parentFont(q)); } -void QQuickTextAreaPrivate::inheritFont(const QFont &f) +void QQuickTextAreaPrivate::inheritFont(const QFont &font) { - Q_Q(QQuickTextArea); - QFont parentFont = font.resolve(f); - parentFont.resolve(font.resolve() | f.resolve()); + QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font; + parentFont.resolve(extra.isAllocated() ? extra->requestedFont.resolve() | font.resolve() : font.resolve()); const QFont defaultFont = QQuickControlPrivate::themeFont(QPlatformTheme::EditorFont); const QFont resolvedFont = parentFont.resolve(defaultFont); - const bool changed = resolvedFont != sourceFont; - q->QQuickTextEdit::setFont(resolvedFont); - if (changed) + setFont_helper(resolvedFont); +} + +/*! + \internal + + Assign \a font to this control, and propagate it to all children. +*/ +void QQuickTextAreaPrivate::updateFont(const QFont &font) +{ + Q_Q(QQuickTextArea); + QFont oldFont = sourceFont; + q->QQuickTextEdit::setFont(font); + + QQuickControlPrivate::updateFontRecur(q, font); + + if (oldFont != font) emit q->fontChanged(); } @@ -419,10 +432,10 @@ QFont QQuickTextArea::font() const void QQuickTextArea::setFont(const QFont &font) { Q_D(QQuickTextArea); - if (d->font.resolve() == font.resolve() && d->font == font) + if (d->extra.value().requestedFont.resolve() == font.resolve() && d->extra.value().requestedFont == font) return; - d->font = font; + d->extra.value().requestedFont = font; d->resolveFont(); } diff --git a/src/quicktemplates2/qquicktextarea_p_p.h b/src/quicktemplates2/qquicktextarea_p_p.h index ef2c7237..22ad4b09 100644 --- a/src/quicktemplates2/qquicktextarea_p_p.h +++ b/src/quicktemplates2/qquicktextarea_p_p.h @@ -48,11 +48,12 @@ // We mean it. // +#include <QtQml/private/qlazilyallocated_p.h> #include <QtQuick/private/qquicktextedit_p_p.h> #include <QtQuick/private/qquickitemchangelistener_p.h> #include <QtQuickTemplates2/private/qquickpresshandler_p_p.h> -#include "qquicktextarea_p.h" +#include <QtQuickTemplates2/private/qquicktextarea_p.h> #if QT_CONFIG(accessibility) #include <QtGui/qaccessible.h> @@ -80,8 +81,15 @@ public: } void resizeBackground(); + void resolveFont(); - void inheritFont(const QFont &f); + void inheritFont(const QFont &font); + void updateFont(const QFont &font); + inline void setFont_helper(const QFont &font) { + if (sourceFont.resolve() == font.resolve() && sourceFont == font) + return; + updateFont(font); + } #if QT_CONFIG(quicktemplates2_hover) void updateHoverEnabled(bool h, bool e); @@ -112,7 +120,12 @@ public: bool hovered; bool explicitHoverEnabled; #endif - QFont font; + + struct ExtraData { + QFont requestedFont; + }; + QLazilyAllocated<ExtraData> extra; + QQuickItem *background; QString placeholder; Qt::FocusReason focusReason; diff --git a/src/quicktemplates2/qquicktextfield.cpp b/src/quicktemplates2/qquicktextfield.cpp index e6ca2496..241ff922 100644 --- a/src/quicktemplates2/qquicktextfield.cpp +++ b/src/quicktemplates2/qquicktextfield.cpp @@ -163,18 +163,31 @@ void QQuickTextFieldPrivate::resolveFont() inheritFont(QQuickControlPrivate::parentFont(q)); } -void QQuickTextFieldPrivate::inheritFont(const QFont &f) +void QQuickTextFieldPrivate::inheritFont(const QFont &font) { - Q_Q(QQuickTextField); - QFont parentFont = font.resolve(f); - parentFont.resolve(font.resolve() | f.resolve()); + QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font; + parentFont.resolve(extra.isAllocated() ? extra->requestedFont.resolve() | font.resolve() : font.resolve()); const QFont defaultFont = QQuickControlPrivate::themeFont(QPlatformTheme::EditorFont); const QFont resolvedFont = parentFont.resolve(defaultFont); - const bool changed = resolvedFont != sourceFont; - q->QQuickTextInput::setFont(resolvedFont); - if (changed) + setFont_helper(resolvedFont); +} + +/*! + \internal + + Assign \a font to this control, and propagate it to all children. +*/ +void QQuickTextFieldPrivate::updateFont(const QFont &font) +{ + Q_Q(QQuickTextField); + QFont oldFont = sourceFont; + q->QQuickTextInput::setFont(font); + + QQuickControlPrivate::updateFontRecur(q, font); + + if (oldFont != font) emit q->fontChanged(); } @@ -288,10 +301,10 @@ QFont QQuickTextField::font() const void QQuickTextField::setFont(const QFont &font) { Q_D(QQuickTextField); - if (d->font.resolve() == font.resolve() && d->font == font) + if (d->extra.value().requestedFont.resolve() == font.resolve() && d->extra.value().requestedFont == font) return; - d->font = font; + d->extra.value().requestedFont = font; d->resolveFont(); } diff --git a/src/quicktemplates2/qquicktextfield_p_p.h b/src/quicktemplates2/qquicktextfield_p_p.h index 31ccb361..6f36dda4 100644 --- a/src/quicktemplates2/qquicktextfield_p_p.h +++ b/src/quicktemplates2/qquicktextfield_p_p.h @@ -48,10 +48,11 @@ // We mean it. // +#include <QtQml/private/qlazilyallocated_p.h> #include <QtQuick/private/qquicktextinput_p_p.h> #include <QtQuickTemplates2/private/qquickpresshandler_p_p.h> -#include "qquicktextfield_p.h" +#include <QtQuickTemplates2/private/qquicktextfield_p.h> #if QT_CONFIG(accessibility) #include <QtGui/qaccessible.h> @@ -76,8 +77,15 @@ public: return static_cast<QQuickTextFieldPrivate *>(QObjectPrivate::get(item)); } void resizeBackground(); + void resolveFont(); - void inheritFont(const QFont &f); + void inheritFont(const QFont &font); + void updateFont(const QFont &font); + inline void setFont_helper(const QFont &font) { + if (sourceFont.resolve() == font.resolve() && sourceFont == font) + return; + updateFont(font); + } #if QT_CONFIG(quicktemplates2_hover) void updateHoverEnabled(bool h, bool e); @@ -101,7 +109,12 @@ public: bool hovered; bool explicitHoverEnabled; #endif - QFont font; + + struct ExtraData { + QFont requestedFont; + }; + QLazilyAllocated<ExtraData> extra; + QQuickItem *background; QString placeholder; Qt::FocusReason focusReason; diff --git a/src/quicktemplates2/qquicktoolbutton.cpp b/src/quicktemplates2/qquicktoolbutton.cpp index 5ef25e3e..3db22022 100644 --- a/src/quicktemplates2/qquicktoolbutton.cpp +++ b/src/quicktemplates2/qquicktoolbutton.cpp @@ -59,7 +59,8 @@ QT_BEGIN_NAMESPACE ToolButton inherits its API from AbstractButton. For instance, you can set \l {AbstractButton::text}{text}, and react to \l {AbstractButton::clicked}{clicks} - using the AbstractButton API. + using the AbstractButton API. In addition to displaying text, tool buttons + can also display an \l [QML]{Button Icons}{icon}. \sa ToolBar, {Customizing ToolButton}, {Button Controls} */ diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index bf83a725..47aacea1 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -353,7 +353,7 @@ QQuickToolTip *QQuickToolTipAttachedPrivate::instance(bool create) const if (!tip && create) { // TODO: a cleaner way to create the instance? QQml(Meta)Type? QQmlComponent component(engine); - component.setData("import QtQuick.Controls 2.2; ToolTip { }", QUrl()); + component.setData("import QtQuick.Controls 2.3; ToolTip { }", QUrl()); QObject *object = component.create(); if (object) diff --git a/src/quicktemplates2/qtquicktemplates2global_p.h b/src/quicktemplates2/qtquicktemplates2global_p.h index b7f54bb6..e5ee3f2e 100644 --- a/src/quicktemplates2/qtquicktemplates2global_p.h +++ b/src/quicktemplates2/qtquicktemplates2global_p.h @@ -49,6 +49,7 @@ // #include <QtCore/qglobal.h> +#include <QtQml/private/qqmlglobal_p.h> #include <QtQuickTemplates2/private/qtquicktemplates2-config_p.h> QT_BEGIN_NAMESPACE diff --git a/src/quicktemplates2/quicktemplates2.pri b/src/quicktemplates2/quicktemplates2.pri index a7570ec5..e1a1a917 100644 --- a/src/quicktemplates2/quicktemplates2.pri +++ b/src/quicktemplates2/quicktemplates2.pri @@ -3,6 +3,8 @@ INCLUDEPATH += $$PWD HEADERS += \ $$PWD/qquickabstractbutton_p.h \ $$PWD/qquickabstractbutton_p_p.h \ + $$PWD/qquickaction_p.h \ + $$PWD/qquickactiongroup_p.h \ $$PWD/qquickapplicationwindow_p.h \ $$PWD/qquickbusyindicator_p.h \ $$PWD/qquickbutton_p.h \ @@ -26,6 +28,7 @@ HEADERS += \ $$PWD/qquickframe_p.h \ $$PWD/qquickframe_p_p.h \ $$PWD/qquickgroupbox_p.h \ + $$PWD/qquickicon_p.h \ $$PWD/qquickitemdelegate_p.h \ $$PWD/qquickitemdelegate_p_p.h \ $$PWD/qquicklabel_p.h \ @@ -82,6 +85,8 @@ HEADERS += \ SOURCES += \ $$PWD/qquickabstractbutton.cpp \ + $$PWD/qquickaction.cpp \ + $$PWD/qquickactiongroup.cpp \ $$PWD/qquickapplicationwindow.cpp \ $$PWD/qquickbusyindicator.cpp \ $$PWD/qquickbutton.cpp \ @@ -98,6 +103,7 @@ SOURCES += \ $$PWD/qquickdrawer.cpp \ $$PWD/qquickframe.cpp \ $$PWD/qquickgroupbox.cpp \ + $$PWD/qquickicon.cpp \ $$PWD/qquickitemdelegate.cpp \ $$PWD/qquicklabel.cpp \ $$PWD/qquickmenu.cpp \ |