mirror of
https://github.com/overte-org/overte.git
synced 2025-04-27 01:16:29 +02:00
291 lines
8.9 KiB
QML
291 lines
8.9 KiB
QML
//
|
|
// CustomQueryDialog.qml
|
|
//
|
|
// Created by Zander Otavka on 7/14/16
|
|
// Copyright 2016 High Fidelity, Inc.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// 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.Dialogs 1.2 as OriginalDialogs;
|
|
|
|
import "../controls-uit";
|
|
import "../styles-uit";
|
|
import "../windows";
|
|
|
|
ModalWindow {
|
|
id: root;
|
|
HifiConstants { id: hifi; }
|
|
implicitWidth: 640;
|
|
implicitHeight: 320;
|
|
visible: true;
|
|
|
|
signal selected(var result);
|
|
signal canceled();
|
|
|
|
property int icon: hifi.icons.none;
|
|
property string iconText: "";
|
|
property int iconSize: 35;
|
|
onIconChanged: updateIcon();
|
|
|
|
property var textInput;
|
|
property var comboBox;
|
|
property var checkBox;
|
|
|
|
property var warning: "";
|
|
property var result;
|
|
|
|
property var implicitCheckState: null;
|
|
|
|
property int titleWidth: 0;
|
|
onTitleWidthChanged: d.resize();
|
|
|
|
function updateIcon() {
|
|
if (!root) {
|
|
return;
|
|
}
|
|
iconText = hifi.glyphForIcon(root.icon);
|
|
}
|
|
|
|
function updateCheckbox() {
|
|
if (checkBox.disableForItems) {
|
|
var currentTextInDisableList = false;
|
|
for (var i in checkBox.disableForItems) {
|
|
if (comboBoxField.currentText === checkBox.disableForItems[i]) {
|
|
currentTextInDisableList = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (currentTextInDisableList) {
|
|
checkBoxField.enabled = false;
|
|
if (checkBox.checkStateOnDisable !== null && checkBox.checkStateOnDisable !== undefined) {
|
|
root.implicitCheckState = checkBoxField.checked;
|
|
checkBoxField.checked = checkBox.checkStateOnDisable;
|
|
}
|
|
root.warning = checkBox.warningOnDisable;
|
|
} else {
|
|
checkBoxField.enabled = true;
|
|
if (root.implicitCheckState !== null) {
|
|
checkBoxField.checked = root.implicitCheckState;
|
|
root.implicitCheckState = null;
|
|
}
|
|
root.warning = "";
|
|
}
|
|
}
|
|
}
|
|
|
|
Item {
|
|
clip: true;
|
|
width: pane.width;
|
|
height: pane.height;
|
|
anchors.margins: 0;
|
|
|
|
QtObject {
|
|
id: d;
|
|
readonly property int minWidth: 480;
|
|
readonly property int maxWdith: 1280;
|
|
readonly property int minHeight: 120;
|
|
readonly property int maxHeight: 720;
|
|
|
|
function resize() {
|
|
var targetWidth = Math.max(titleWidth, pane.width);
|
|
var targetHeight = (textInput ? textField.controlHeight : 0) + extraInputs.height +
|
|
(5 * hifi.dimensions.contentSpacing.y) + buttons.height;
|
|
root.width = (targetWidth < d.minWidth) ? d.minWidth : ((targetWidth > d.maxWdith) ? d.maxWidth : targetWidth);
|
|
root.height = (targetHeight < d.minHeight) ? d.minHeight: ((targetHeight > d.maxHeight) ?
|
|
d.maxHeight : targetHeight);
|
|
if (comboBoxField.visible) {
|
|
comboBoxField.width = extraInputs.width / 2;
|
|
}
|
|
}
|
|
}
|
|
|
|
Item {
|
|
anchors {
|
|
top: parent.top;
|
|
bottom: extraInputs.top;
|
|
left: parent.left;
|
|
right: parent.right;
|
|
margins: 0;
|
|
bottomMargin: hifi.dimensions.contentSpacing.y;
|
|
}
|
|
|
|
// FIXME make a text field type that can be bound to a history for autocompletion
|
|
TextField {
|
|
id: textField;
|
|
label: root.textInput.label;
|
|
focus: root.textInput ? true : false;
|
|
visible: root.textInput ? true : false;
|
|
anchors {
|
|
left: parent.left;
|
|
right: parent.right;
|
|
bottom: parent.bottom;
|
|
}
|
|
}
|
|
}
|
|
|
|
Row {
|
|
id: extraInputs;
|
|
spacing: hifi.dimensions.contentSpacing.x;
|
|
anchors {
|
|
left: parent.left;
|
|
right: parent.right;
|
|
bottom: buttons.top;
|
|
bottomMargin: hifi.dimensions.contentSpacing.y;
|
|
}
|
|
height: comboBoxField.controlHeight;
|
|
onHeightChanged: d.resize();
|
|
onWidthChanged: d.resize();
|
|
|
|
CheckBox {
|
|
id: checkBoxField;
|
|
text: root.checkBox.label;
|
|
focus: root.checkBox ? true : false;
|
|
visible: root.checkBox ? true : false;
|
|
anchors {
|
|
left: parent.left;
|
|
bottom: parent.bottom;
|
|
leftMargin: 6; // Magic number to align with warning icon
|
|
}
|
|
}
|
|
|
|
ComboBox {
|
|
id: comboBoxField;
|
|
label: root.comboBox.label;
|
|
focus: root.comboBox ? true : false;
|
|
visible: root.comboBox ? true : false;
|
|
anchors {
|
|
right: parent.right;
|
|
bottom: parent.bottom;
|
|
}
|
|
model: root.comboBox ? root.comboBox.items : [];
|
|
onCurrentTextChanged: updateCheckbox();
|
|
}
|
|
}
|
|
|
|
Row {
|
|
id: buttons;
|
|
focus: true;
|
|
spacing: hifi.dimensions.contentSpacing.x;
|
|
layoutDirection: Qt.RightToLeft;
|
|
onHeightChanged: d.resize();
|
|
onWidthChanged: {
|
|
d.resize();
|
|
resizeWarningText();
|
|
}
|
|
|
|
anchors {
|
|
bottom: parent.bottom;
|
|
left: parent.left;
|
|
right: parent.right;
|
|
bottomMargin: hifi.dimensions.contentSpacing.y;
|
|
}
|
|
|
|
function resizeWarningText() {
|
|
var rowWidth = buttons.width;
|
|
var buttonsWidth = acceptButton.width + cancelButton.width + hifi.dimensions.contentSpacing.x * 2;
|
|
var warningIconWidth = warningIcon.width + hifi.dimensions.contentSpacing.x;
|
|
warningText.width = rowWidth - buttonsWidth - warningIconWidth;
|
|
}
|
|
|
|
Button {
|
|
id: cancelButton;
|
|
action: cancelAction;
|
|
// anchors {
|
|
// bottom: parent.bottom;
|
|
// right: parent.right;
|
|
// leftMargin: hifi.dimensions.contentSpacing.x;
|
|
// }
|
|
}
|
|
|
|
Button {
|
|
id: acceptButton;
|
|
action: acceptAction;
|
|
// anchors {
|
|
// bottom: parent.bottom;
|
|
// right: cancelButton.left;
|
|
// leftMargin: hifi.dimensions.contentSpacing.x;
|
|
// }
|
|
}
|
|
|
|
Text {
|
|
id: warningText;
|
|
visible: Boolean(root.warning);
|
|
text: root.warning;
|
|
wrapMode: Text.WordWrap;
|
|
font.italic: true;
|
|
maximumLineCount: 2;
|
|
}
|
|
|
|
HiFiGlyphs {
|
|
id: warningIcon;
|
|
visible: Boolean(root.warning);
|
|
text: hifi.glyphs.alert;
|
|
size: hifi.dimensions.controlLineHeight;
|
|
}
|
|
}
|
|
|
|
Action {
|
|
id: cancelAction;
|
|
text: qsTr("Cancel");
|
|
shortcut: Qt.Key_Escape;
|
|
onTriggered: {
|
|
root.result = null;
|
|
root.canceled();
|
|
root.destroy();
|
|
}
|
|
}
|
|
|
|
Action {
|
|
id: acceptAction;
|
|
text: qsTr("Add");
|
|
shortcut: Qt.Key_Return;
|
|
onTriggered: {
|
|
var result = {};
|
|
if (textInput) {
|
|
result.textInput = textField.text;
|
|
}
|
|
if (comboBox) {
|
|
result.comboBox = comboBoxField.currentText;
|
|
result.comboBoxIndex = comboBoxField.currentIndex;
|
|
}
|
|
if (checkBox) {
|
|
result.checkBox = checkBoxField.enabled ? checkBoxField.checked : null;
|
|
}
|
|
root.result = result;
|
|
root.selected(root.result);
|
|
root.destroy();
|
|
}
|
|
}
|
|
}
|
|
|
|
Keys.onPressed: {
|
|
if (!visible) {
|
|
return;
|
|
}
|
|
|
|
switch (event.key) {
|
|
case Qt.Key_Escape:
|
|
case Qt.Key_Back:
|
|
cancelAction.trigger();
|
|
event.accepted = true;
|
|
break;
|
|
|
|
case Qt.Key_Return:
|
|
case Qt.Key_Enter:
|
|
acceptAction.trigger();
|
|
event.accepted = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
updateIcon();
|
|
d.resize();
|
|
textField.forceActiveFocus();
|
|
}
|
|
}
|