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 string buttonGlyph: "";
//TODO: add real Action item. Backport from Qt 5.10
property Shortcut action: null
property Action action: null
width: 120
height: hifi.dimensions.controlLineHeight
@ -35,10 +34,16 @@ Original.Button {
}
}
onActionChanged: {
if (action !== null && action.text !== "") {
control.text = action.text
}
}
onClicked: {
tabletInterface.playSound(TabletEnums.ButtonClick);
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
//
import QtQuick 2.5
import QtQuick.Controls 1.4 as Original
import QtQuick.Controls.Styles 1.4
import QtQuick 2.7
import QtQuick.Controls 2.2 as Original
import TabletScriptingInterface 1.0
import "../styles-uit"
Original.Button {
id: control
property int color: 0
property int colorScheme: hifi.colorSchemes.light
property string glyph: ""
@ -25,17 +24,25 @@ Original.Button {
width: 120
height: 28
property Action action: null
onHoveredChanged: {
if (hovered) {
tabletInterface.playSound(TabletEnums.ButtonHover);
}
}
onActionChanged: {
if (action !== null && action.text !== "") {
control.text = action.text
}
}
onClicked: {
tabletInterface.playSound(TabletEnums.ButtonClick);
if (action !== null) {
action.triggered()
}
}
style: ButtonStyle {
background: Rectangle {
radius: hifi.buttons.radius
@ -72,18 +79,13 @@ Original.Button {
}
}
label: HiFiGlyphs {
contentItem: HiFiGlyphs {
color: enabled ? hifi.buttons.textColor[control.color]
: hifi.buttons.disabledTextColor[control.colorScheme]
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
anchors {
// Tweak horizontal alignment so that it looks right.
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 "../styles"
import "../controls-uit"
Original.Button {
id: control
HifiConstants { id: hifi }
property Action action: null
onActionChanged: {
if (action !== null && action.text !== "") {
control.text = action.text
}
}
padding {
top: 8
left: 12

View file

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

View file

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

View file

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