Custom ComboBox element.

This commit is contained in:
armored-dragon 2024-11-18 08:35:48 -06:00
parent c460a582e4
commit 97e6271391
No known key found for this signature in database
GPG key ID: C7207ACC3382AD8B
2 changed files with 141 additions and 78 deletions

View file

@ -0,0 +1,121 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.3
Item {
id: root;
property string settingText: "";
property int optionIndex: 0;
property var options: [];
signal valueChanged(int index);
height: 50;
width: parent.width;
RowLayout {
width: parent.width - 10;
height: parent.height;
anchors.horizontalCenter: parent.horizontalCenter;
Layout.alignment: Qt.AlignTop;
Text {
id: settingTextElem
height: parent.height;
text: settingText;
color: "white";
font.pointSize: 14;
}
ComboBox {
id: control
Layout.alignment: Qt.AlignRight;
implicitWidth: 225;
implicitHeight: parent.height - 15;
model: options;
currentIndex: optionIndex;
onCurrentIndexChanged: {
valueChanged(currentIndex);
}
delegate: ItemDelegate {
width: control.width
contentItem: Text {
text: options[index]
color: "white"
font: control.font
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
background: Rectangle {
color: highlighted ? "gray" : "transparent";
radius: 10
}
highlighted: control.highlightedIndex === index
}
contentItem: Text {
text: control.displayText
color: "white";
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 14;
elide: Text.ElideRight
width: parent.width;
}
background: Rectangle {
border.color: "white";
border.width: 1;
color: "transparent";
radius: 10;
width: parent.width;
}
popup: Popup {
width: control.width
padding: 1
contentItem: ListView {
clip: true
implicitHeight: contentHeight
model: control.popup.visible ? control.delegateModel : null
currentIndex: control.highlightedIndex
ScrollIndicator.vertical: ScrollIndicator { }
}
background: Rectangle {
color: Qt.rgba(0,0,0,0.9)
radius: 10
}
}
indicator: Canvas {
id: canvas
x: control.width - width - control.rightPadding
y: control.topPadding + (control.availableHeight - height) / 2
width: 12
height: 8
contextType: "2d"
Connections {
target: control
function onPressedChanged() { canvas.requestPaint(); }
}
onPaint: {
context.reset();
context.moveTo(0, 0);
context.lineTo(width, 0);
context.lineTo(width / 2, height);
context.closePath();
context.fillStyle = "white";
context.fill();
}
}
}
}
}

View file

@ -56,33 +56,13 @@ Rectangle {
spacing: 10
// Graphics Presets
RowLayout {
width: parent.width
SettingComboBox {
settingText: "Graphics preset";
optionIndex: Performance.getPerformancePreset() - 1;
options: ["Low Power", "Low", "Medium", "High", "Custom"];
Text {
text: "Graphics Preset"
color: "white"
height: parent.height
width: parent.width - 150
font.pointSize: 14
Layout.fillWidth: true
}
ComboBox {
currentIndex: Performance.getPerformancePreset() - 1 // One off error FTW!
Layout.fillWidth: true
model: ListModel {
id: cbItems
ListElement { text: "Low Power" }
ListElement { text: "Low" }
ListElement { text: "Medium" }
ListElement { text: "High" }
ListElement { text: "Custom" }
}
onCurrentIndexChanged: {
Performance.setPerformancePreset(currentIndex + 1)
}
onValueChanged: {
Performance.setPerformancePreset(index + 1)
}
}
@ -162,36 +142,17 @@ Rectangle {
}
// FPS
RowLayout {
width: parent.width
SettingComboBox {
settingText: "Refresh rate";
optionIndex: Performance.getPerformancePreset() - 1;
options: ["Economical", "Interactive", "Real-Time", "Custom"];
Text {
text: "Refresh Rate"
color: "white"
height: parent.height
width: parent.width - 150
font.pointSize: 14
Layout.fillWidth: true
Component.onCompleted: {
optionIndex = Performance.getRefreshRateProfile()
}
ComboBox {
id: refresh_rate_cb
currentIndex: 3
Layout.fillWidth: true
model: ListModel {
ListElement { text: "Economical" }
ListElement { text: "Interactive" }
ListElement { text: "Real-Time" }
ListElement { text: "Custom" }
}
Component.onCompleted: {
refresh_rate_cb.currentIndex = Performance.getRefreshRateProfile()
}
onCurrentIndexChanged: {
Performance.setRefreshRateProfile(currentIndex)
}
onValueChanged: {
Performance.setRefreshRateProfile(index)
}
}
@ -416,30 +377,13 @@ Rectangle {
}
// Anti Aliasing
RowLayout {
width: parent.width
SettingComboBox {
settingText: "Anti-aliasing";
optionIndex: Render.antialiasingMode;
options: ["None", "TAA", "FXAA"];
Text {
text: "Anti-Aliasing"
color: "white"
height: parent.height
width: parent.width - 150
font.pointSize: 14
Layout.fillWidth: true
}
ComboBox {
currentIndex: Render.antialiasingMode
Layout.fillWidth: true
model: ListModel {
ListElement { text: "None" }
ListElement { text: "TAA" }
ListElement { text: "FXAA" }
}
onCurrentIndexChanged: {
Render.antialiasingMode = currentIndex;
}
onValueChanged: {
Render.antialiasingMode = index;
}
}
}
@ -451,8 +395,6 @@ Rectangle {
visible: current_page == "Audio"
}
// Templates
// Messages from script