From 9117572f82620be4de801c82b600c2a4e09c5f75 Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Fri, 31 Oct 2025 09:52:22 +0100 Subject: [PATCH] feat: Add Text slider button --- UIControls/CMakeLists.txt | 1 + UIControls/qml/QoATextSlider.qml | 155 +++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 UIControls/qml/QoATextSlider.qml diff --git a/UIControls/CMakeLists.txt b/UIControls/CMakeLists.txt index d5d18f6..35ec23c 100644 --- a/UIControls/CMakeLists.txt +++ b/UIControls/CMakeLists.txt @@ -10,6 +10,7 @@ qt_add_qml_module(QodeAssistUIControls QML_FILES qml/Badge.qml qml/QoAButton.qml + qml/QoATextSlider.qml ) target_link_libraries(QodeAssistUIControls diff --git a/UIControls/qml/QoATextSlider.qml b/UIControls/qml/QoATextSlider.qml new file mode 100644 index 0000000..b51abf7 --- /dev/null +++ b/UIControls/qml/QoATextSlider.qml @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2025 Petr Mironychev + * + * This file is part of QodeAssist. + * + * QodeAssist is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QodeAssist is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QodeAssist. If not, see . + */ + +import QtQuick +import QtQuick.Controls.Basic + +Item { + id: root + + property alias leftText: leftLabel.text + property alias rightText: rightLabel.text + + property bool checked: false + property bool enabled: true + property bool hovered: mouseArea.containsMouse + property int padding: 8 + + signal toggled() + + readonly property real maxTextWidth: Math.max(leftLabel.implicitWidth, rightLabel.implicitWidth) + padding * 2 + readonly property real maxTextHeight: Math.max(leftLabel.implicitHeight, rightLabel.implicitHeight) + padding + + implicitWidth: maxTextWidth * 2 + implicitHeight: maxTextHeight + + Rectangle { + anchors.fill: parent + radius: height / 2 + color: root.enabled ? palette.button : palette.mid + border.color: root.enabled ? palette.mid : palette.midlight + border.width: 1 + + Behavior on color { + ColorAnimation { duration: 150 } + } + } + + Rectangle { + id: slider + + x: root.checked ? parent.width / 2 : 0 + width: parent.width / 2 + height: parent.height + opacity: 0.6 + radius: height / 2 + + color: root.enabled + ? (mouseArea.pressed ? palette.dark : palette.highlight) + : palette.midlight + + border.color: root.enabled ? palette.highlight : palette.mid + border.width: 1 + + Rectangle { + anchors.fill: parent + radius: parent.radius + gradient: Gradient { + GradientStop { position: 0.0; color: Qt.alpha(palette.highlight, 0.4) } + GradientStop { position: 1.0; color: Qt.alpha(palette.highlight, 0.2) } + } + opacity: root.hovered ? 0.3 : 0.01 + Behavior on opacity { + NumberAnimation { duration: 250 } + } + } + + Behavior on x { + NumberAnimation { + duration: 200 + easing.type: Easing.InOutQuad + } + } + + Behavior on color { + ColorAnimation { duration: 150 } + } + } + + Item { + id: leftContainer + + width: parent.width / 2 + height: parent.height + + Text { + id: leftLabel + + anchors.centerIn: parent + text: root.leftText + font.pixelSize: 14 + color: root.enabled + ? (!root.checked ? palette.highlightedText : palette.windowText) + : Qt.alpha(palette.windowText, 0.3) + + Behavior on color { + ColorAnimation { duration: 150 } + } + } + } + + Item { + id: rightContainer + + x: parent.width / 2 + width: parent.width / 2 + height: parent.height + + Text { + id: rightLabel + + anchors.centerIn: parent + text: root.rightText + font.pixelSize: 14 + color: root.enabled + ? (root.checked ? palette.highlightedText : palette.windowText) + : Qt.alpha(palette.windowText, 0.3) + + Behavior on color { + ColorAnimation { duration: 150 } + } + } + } + + MouseArea { + id: mouseArea + + anchors.fill: parent + hoverEnabled: true + cursorShape: root.enabled ? Qt.PointingHandCursor : Qt.ArrowCursor + enabled: root.enabled + + onClicked: { + if (root.enabled) { + root.checked = !root.checked + root.toggled() + } + } + } +}