Adding the prop library

This commit is contained in:
Sam Gateau 2019-03-03 23:35:40 -08:00
parent 0594879816
commit fe23ef1485
11 changed files with 437 additions and 0 deletions

View file

@ -0,0 +1,44 @@
//
// Prop/Global.qml
//
// Created by Sam Gateau on 3/2/2019
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.7
import stylesUit 1.0
import controlsUit 1.0 as HifiControls
Item {
HifiConstants { id: hifi }
id: root
property real lineHeight: 32
property real slimHeight: 24
property var color: hifi.colors.baseGray
property var colorBackHighlight: hifi.colors.baseGrayHighlight
property var colorBorderLight: hifi.colors.lightGray
property var colorBorderHighight: hifi.colors.blueHighlight
property real fontSize: 12
property var fontFamily: "Raleway"
property var fontWeight: Font.DemiBold
property var fontColor: hifi.colors.faintGray
property var splitterRightWidthScale: 0.44
property real splitterWidth: 4
property var labelTextAlign: Text.AlignRight
property var labelTextElide: Text.ElideMiddle
property var valueAreaWidthScale: 0.3 * (1.0 - splitterRightWidthScale)
property var valueTextAlign: Text.AlignHCenter
property real valueBorderWidth: 1
property real valueBorderRadius: 2
}

View file

@ -0,0 +1,110 @@
//
// PropEnum.qml
//
// Created by Sam Gateau on 3/2/2019
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.7
import QtQuick.Controls 2.2
PropItem {
Global { id: global }
id: root
property alias valueVar : valueCombo.currentIndex
property alias enums : valueCombo.model
ComboBox {
id: valueCombo
flat: true
anchors.left: root.splitter.right
anchors.right: parent.right
anchors.verticalCenter: root.verticalCenter
height: global.slimHeight
currentIndex: root.valueVarGetter()
onCurrentIndexChanged: { root.valueVarSetter(currentIndex); }
delegate: ItemDelegate {
width: valueCombo.width
height: valueCombo.height
contentItem: PropText {
text: modelData
horizontalAlignment: global.valueTextAlign
}
background: Rectangle {
color:highlighted?global.colorBackHighlight:global.color;
}
highlighted: valueCombo.highlightedIndex === index
}
indicator: Canvas {
id: canvas
x: valueCombo.width - width - valueCombo.rightPadding
y: valueCombo.topPadding + (valueCombo.availableHeight - height) / 2
width: 12
height: 8
contextType: "2d"
Connections {
target: valueCombo
onPressedChanged: canvas.requestPaint()
}
onPaint: {
context.reset();
context.moveTo(0, 0);
context.lineTo(width, 0);
context.lineTo(width / 2, height);
context.closePath();
context.fillStyle = (valueCombo.pressed) ? global.colorBorderHighight : global.colorBorderLight;
context.fill();
}
}
contentItem: PropText {
leftPadding: 0
rightPadding: valueCombo.indicator.width + valueCombo.spacing
text: valueCombo.displayText
horizontalAlignment: global.valueTextAlign
}
background: Rectangle {
implicitWidth: 120
implicitHeight: 40
color: global.color
border.color: valueCombo.popup.visible ? global.colorBorderHighight : global.colorBorderLight
border.width: global.valueBorderWidth
radius: global.valueBorderRadius
}
popup: Popup {
y: valueCombo.height - 1
width: valueCombo.width
implicitHeight: contentItem.implicitHeight + 2
padding: 1
contentItem: ListView {
clip: true
implicitHeight: contentHeight
model: valueCombo.popup.visible ? valueCombo.delegateModel : null
currentIndex: valueCombo.highlightedIndex
ScrollIndicator.vertical: ScrollIndicator { }
}
background: Rectangle {
color: global.color
border.color: global.colorBorderHighight
radius: global.valueBorderRadius
}
}
}
}

View file

@ -0,0 +1,62 @@
//
// PropItem.qml
//
// Created by Sam Gateau on 3/2/2019
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.7
Item {
Global { id: global }
id: root
// Prop item is designed to author an object[property]:
property var object: NULL
property string property: ""
// value is accessed through the "valueVarSetter" and "valueVarGetter"
// By default, these just go get or set the value from the object[property]
//
function defaultGet() { return root.object[root.property]; }
function defaultSet(value) { root.object[root.property] = value; }
property var valueVarSetter: defaultSet
property var valueVarGetter: defaultGet
// PropItem is stretching horizontally accross its parent
// Fixed height
anchors.left: parent.left
anchors.right: parent.right
height: global.lineHeight
// LabelControl And SplitterControl are on the left side of the PropItem
property bool showLabel: true
property alias labelControl: labelControl
property alias label: labelControl.text
property var labelAreaWidth: root.width * global.splitterRightWidthScale - global.splitterWidth
PropText {
id: labelControl
text: root.label
enabled: root.showLabel
anchors.left: root.left
anchors.verticalCenter: root.verticalCenter
width: labelAreaWidth
}
property alias splitter: splitterControl
PropSplitter {
id: splitterControl
anchors.left: labelControl.right
size: global.splitterWidth
}
}

View file

@ -0,0 +1,25 @@
//
// PropLabel.qml
//
// Created by Sam Gateau on 3/2/2019
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.7
import QtQuick.Controls 2.2
Label {
Global { id: global }
color: global.fontColor
font.pixelSize: global.fontSize
font.family: global.fontFamily
font.weight: global.fontWeight
verticalAlignment: Text.AlignVCenter
horizontalAlignment: global.labelTextAlign
elide: global.labelTextElide
}

View file

@ -0,0 +1,71 @@
//
// PropItem.qml
//
// Created by Sam Gateau on 3/2/2019
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.7
import controlsUit 1.0 as HifiControls
PropItem {
Global { id: global }
id: root
// Scalar Prop
property bool integral: false
property var numDigits: 2
property alias valueVar : sliderControl.value
property alias min: sliderControl.minimumValue
property alias max: sliderControl.maximumValue
property bool showValue: true
signal valueChanged(real value)
Component.onCompleted: {
valueVar = root.valueVarGetter();
}
PropLabel {
id: valueLabel
enabled: root.showValue
anchors.left: root.splitter.right
anchors.verticalCenter: root.verticalCenter
width: root.width * global.valueAreaWidthScale
horizontalAlignment: global.valueTextAlign
height: global.slimHeight
text: sliderControl.value.toFixed(root.integral ? 0 : root.numDigits)
background: Rectangle {
color: global.color
border.color: global.colorBorderLight
border.width: global.valueBorderWidth
radius: global.valueBorderRadius
}
}
HifiControls.Slider {
id: sliderControl
stepSize: root.integral ? 1.0 : 0.0
anchors.left: valueLabel.right
anchors.right: root.right
anchors.rightMargin: 0
anchors.verticalCenter: root.verticalCenter
onValueChanged: { root.valueVarSetter(value) }
}
}

View file

@ -0,0 +1,21 @@
//
// PropSplitter.qml
//
// Created by Sam Gateau on 3/2/2019
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.7
Item {
id: root
property real size
width: size // Must be non-zero
height: size
anchors.verticalCenter: parent.verticalCenter
}

View file

@ -0,0 +1,24 @@
//
// Prop/Text.qml
//
// Created by Sam Gateau on 3/2/2019
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.7
Text {
Global { id: global }
color: global.fontColor
font.pixelSize: global.fontSize
font.family: global.fontFamily
font.weight: global.fontWeight
verticalAlignment: Text.AlignVCenter
horizontalAlignment: global.labelTextAlign
elide: global.labelTextElide
}

View file

@ -0,0 +1,8 @@
PropGlobal 1.0 PropGlobal.qml
PropText 1.0 PropText.qml
PropLabel 1.0 PropLabel.qml
PropSplitter 1.0 PropSplitter.qml
PropItem 1.0 PropItem.qml
PropScalar 1.0 PropScalar.qml
PropEnum 1.0 PropEnum.qml
PropColor 1.0 PropColor.qml

View file

@ -0,0 +1,59 @@
//
// luci.qml
//
// Created by Sam Gateau on 3/2/2019
// Copyright 2019 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.7
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.3
import controlsUit 1.0 as HifiControls
import "../lib/prop" as Prop
Rectangle {
Prop.Global { id: prop;}
id: render;
anchors.fill: parent
color: prop.color;
property var mainViewTask: Render.getConfig("RenderMainView")
Column {
anchors.left: parent.left
anchors.right: parent.right
Repeater {
model: [ "Tone mapping exposure:ToneMapping:exposure:5.0:-5.0",
"Tone:ToneMapping:exposure:5.0:-5.0"
]
Prop.PropScalar {
label: qsTr(modelData.split(":")[0])
integral: false
object: render.mainViewTask.getConfig(modelData.split(":")[1])
property: modelData.split(":")[2]
max: modelData.split(":")[3]
min: modelData.split(":")[4]
anchors.left: parent.left
anchors.right: parent.right
}
}
Prop.PropEnum {
label: "Tone Curve"
object: render.mainViewTask.getConfig("ToneMapping")
property: "curve"
enums: [
"RGB",
"SRGB",
"Reinhard",
"Filmic",
]
anchors.left: parent.left
anchors.right: parent.right
}
}
}

View file

@ -0,0 +1,13 @@
function openEngineTaskView() {
// Set up the qml ui
var qml = Script.resolvePath('luci.qml');
var window = new OverlayWindow({
title: 'luci qml',
source: qml,
width: 300,
height: 400
});
window.setPosition(200, 50);
//window.closed.connect(function() { Script.stop(); });
}
openEngineTaskView();