Implement QQC1-compatible Action component

This commit is contained in:
vladest 2017-11-16 19:04:35 +01:00
parent 0e53afc346
commit b4f6c25f4d
7 changed files with 91 additions and 69 deletions

View file

@ -0,0 +1,8 @@
import QtQuick 2.7
Shortcut {
id: root
property string text
property alias shortcut: root.sequence
signal triggered()
}

View file

@ -21,8 +21,7 @@ Original.Button {
property int colorScheme: hifi.colorSchemes.light property int colorScheme: hifi.colorSchemes.light
property string buttonGlyph: ""; property string buttonGlyph: "";
//TODO: add real Action item. Backport from Qt 5.10 property Action action: null
property Shortcut action: null
width: 120 width: 120
height: hifi.dimensions.controlLineHeight height: hifi.dimensions.controlLineHeight
@ -35,10 +34,16 @@ Original.Button {
} }
} }
onActionChanged: {
if (action !== null && action.text !== "") {
control.text = action.text
}
}
onClicked: { onClicked: {
tabletInterface.playSound(TabletEnums.ButtonClick); tabletInterface.playSound(TabletEnums.ButtonClick);
if (action !== null) { if (action !== null) {
action.activated() action.triggered()
} }
} }

View file

@ -8,15 +8,14 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
import QtQuick 2.7
import QtQuick 2.5 import QtQuick.Controls 2.2 as Original
import QtQuick.Controls 1.4 as Original
import QtQuick.Controls.Styles 1.4
import TabletScriptingInterface 1.0 import TabletScriptingInterface 1.0
import "../styles-uit" import "../styles-uit"
Original.Button { Original.Button {
id: control
property int color: 0 property int color: 0
property int colorScheme: hifi.colorSchemes.light property int colorScheme: hifi.colorSchemes.light
property string glyph: "" property string glyph: ""
@ -25,65 +24,68 @@ Original.Button {
width: 120 width: 120
height: 28 height: 28
property Action action: null
onHoveredChanged: { onHoveredChanged: {
if (hovered) { if (hovered) {
tabletInterface.playSound(TabletEnums.ButtonHover); tabletInterface.playSound(TabletEnums.ButtonHover);
} }
} }
onActionChanged: {
if (action !== null && action.text !== "") {
control.text = action.text
}
}
onClicked: { onClicked: {
tabletInterface.playSound(TabletEnums.ButtonClick); tabletInterface.playSound(TabletEnums.ButtonClick);
if (action !== null) {
action.triggered()
}
} }
style: ButtonStyle { background: Rectangle {
radius: hifi.buttons.radius
background: Rectangle { gradient: Gradient {
radius: hifi.buttons.radius GradientStop {
position: 0.2
gradient: Gradient { color: {
GradientStop { if (!control.enabled) {
position: 0.2 hifi.buttons.disabledColorStart[control.colorScheme]
color: { } else if (control.pressed) {
if (!control.enabled) { hifi.buttons.pressedColor[control.color]
hifi.buttons.disabledColorStart[control.colorScheme] } else if (control.hovered) {
} else if (control.pressed) { hifi.buttons.hoveredColor[control.color]
hifi.buttons.pressedColor[control.color] } else {
} else if (control.hovered) { hifi.buttons.colorStart[control.color]
hifi.buttons.hoveredColor[control.color]
} else {
hifi.buttons.colorStart[control.color]
}
} }
} }
GradientStop { }
position: 1.0 GradientStop {
color: { position: 1.0
if (!control.enabled) { color: {
hifi.buttons.disabledColorFinish[control.colorScheme] if (!control.enabled) {
} else if (control.pressed) { hifi.buttons.disabledColorFinish[control.colorScheme]
hifi.buttons.pressedColor[control.color] } else if (control.pressed) {
} else if (control.hovered) { hifi.buttons.pressedColor[control.color]
hifi.buttons.hoveredColor[control.color] } else if (control.hovered) {
} else { hifi.buttons.hoveredColor[control.color]
hifi.buttons.colorFinish[control.color] } else {
} hifi.buttons.colorFinish[control.color]
} }
} }
} }
} }
}
label: HiFiGlyphs { contentItem: HiFiGlyphs {
color: enabled ? hifi.buttons.textColor[control.color] color: enabled ? hifi.buttons.textColor[control.color]
: hifi.buttons.disabledTextColor[control.colorScheme] : hifi.buttons.disabledTextColor[control.colorScheme]
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
anchors { text: control.glyph
// Tweak horizontal alignment so that it looks right. size: control.size
left: parent.left
leftMargin: -0.5
}
text: control.glyph
size: control.size
}
} }
} }

View file

@ -3,9 +3,20 @@ import QtQuick.Controls 2.2 as Original
import "." import "."
import "../styles" import "../styles"
import "../controls-uit"
Original.Button { Original.Button {
id: control
HifiConstants { id: hifi } HifiConstants { id: hifi }
property Action action: null
onActionChanged: {
if (action !== null && action.text !== "") {
control.text = action.text
}
}
padding { padding {
top: 8 top: 8
left: 12 left: 12

View file

@ -8,12 +8,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
import QtQuick 2.5 import QtQuick 2.7
import QtQuick.Controls 1.4
import Qt.labs.folderlistmodel 2.1 import Qt.labs.folderlistmodel 2.1
import Qt.labs.settings 1.0 import Qt.labs.settings 1.0
import QtQuick.Controls.Styles 1.4
import QtQuick.Dialogs 1.2 as OriginalDialogs import QtQuick.Dialogs 1.2 as OriginalDialogs
import QtQuick.Controls 1.4 as QQC1
import ".." import ".."
import "../controls-uit" import "../controls-uit"
@ -543,7 +542,7 @@ ModalWindow {
} }
} }
TableViewColumn { QQC1.TableViewColumn {
id: fileNameColumn id: fileNameColumn
role: "fileName" role: "fileName"
title: "Name" title: "Name"
@ -551,7 +550,7 @@ ModalWindow {
movable: false movable: false
resizable: true resizable: true
} }
TableViewColumn { QQC1.TableViewColumn {
id: fileMofifiedColumn id: fileMofifiedColumn
role: "fileModified" role: "fileModified"
title: "Date" title: "Date"
@ -560,7 +559,7 @@ ModalWindow {
resizable: true resizable: true
visible: !selectDirectory visible: !selectDirectory
} }
TableViewColumn { QQC1.TableViewColumn {
role: "fileSize" role: "fileSize"
title: "Size" title: "Size"
width: fileTableView.width - fileNameColumn.width - fileMofifiedColumn.width width: fileTableView.width - fileNameColumn.width - fileMofifiedColumn.width

View file

@ -9,8 +9,6 @@
// //
import QtQuick 2.5 import QtQuick 2.5
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2 as OriginalDialogs
import "../controls-uit" import "../controls-uit"
import "../styles-uit" import "../styles-uit"
@ -147,28 +145,28 @@ ModalWindow {
} }
Button { Button {
action: cancelAction; action: cancelAction;
text: qsTr("Cancel");
} }
Button { Button {
action: acceptAction action: acceptAction
text: qsTr("OK");
} }
} }
Shortcut { Action {
id: cancelAction id: cancelAction
text: qsTr("Cancel");
sequence: Qt.Key_Escape sequence: Qt.Key_Escape
onActivated: { onTriggered: {
root.canceled(); root.canceled();
root.destroy(); root.destroy();
} }
} }
Shortcut { Action {
id: acceptAction id: acceptAction
text: qsTr("OK");
sequence: Qt.Key_Return sequence: Qt.Key_Return
onActivated: { onTriggered: {
root.result = items ? comboBox.currentText : textResult.text root.result = items ? comboBox.currentText : textResult.text
root.selected(root.result); root.selected(root.result);
root.destroy(); root.destroy();

View file

@ -8,12 +8,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
import QtQuick 2.5 import QtQuick 2.7
import QtQuick.Controls 1.4
import Qt.labs.folderlistmodel 2.1 import Qt.labs.folderlistmodel 2.1
import Qt.labs.settings 1.0 import Qt.labs.settings 1.0
import QtQuick.Controls.Styles 1.4
import QtQuick.Dialogs 1.2 as OriginalDialogs import QtQuick.Dialogs 1.2 as OriginalDialogs
import QtQuick.Controls 1.4 as QQC1
import ".." import ".."
import "../controls-uit" import "../controls-uit"
@ -541,7 +540,7 @@ TabletModalWindow {
} }
} }
TableViewColumn { QQC1.TableViewColumn {
id: fileNameColumn id: fileNameColumn
role: "fileName" role: "fileName"
title: "Name" title: "Name"
@ -549,7 +548,7 @@ TabletModalWindow {
movable: false movable: false
resizable: true resizable: true
} }
TableViewColumn { QQC1.TableViewColumn {
id: fileMofifiedColumn id: fileMofifiedColumn
role: "fileModified" role: "fileModified"
title: "Date" title: "Date"
@ -558,7 +557,7 @@ TabletModalWindow {
resizable: true resizable: true
visible: !selectDirectory visible: !selectDirectory
} }
TableViewColumn { QQC1.TableViewColumn {
role: "fileSize" role: "fileSize"
title: "Size" title: "Size"
width: fileTableView.width - fileNameColumn.width - fileMofifiedColumn.width width: fileTableView.width - fileNameColumn.width - fileMofifiedColumn.width