Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Switch item based on AbstractEditor #2963

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/qml/components/MMSwitch.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@ Switch {

property string textOn
property string textOff
property bool visibleText: true

contentItem: Text {
text: (control.textOn.length > 0 && control.textOff.length > 0) ? (control.checked ? control.textOn : control.textOff) : control.text
text: {
if(control.visibleText) {
if(control.textOn.length > 0 && control.textOff.length > 0) {
if(control.checked)
return control.textOn
return control.textOff
}
return control.text
}
}
iiLubos marked this conversation as resolved.
Show resolved Hide resolved
font: __style.p5
color: control.enabled ? __style.forestColor : __style.mediumGreenColor
verticalAlignment: Text.AlignVCenter
Expand Down
2 changes: 1 addition & 1 deletion app/qml/inputs/MMPasswordEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ MMAbstractEditor {
id: root

property alias placeholderText: textField.placeholderText
readonly property alias text: textField.text
property alias text: textField.text

hasFocus: textField.activeFocus

Expand Down
58 changes: 58 additions & 0 deletions app/qml/inputs/MMSwitchEditor.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
import "../components"
iiLubos marked this conversation as resolved.
Show resolved Hide resolved

MMAbstractEditor {
id: root

property var parentValue: parent.value ?? false
property bool parentValueIsNull: parent.valueIsNull ?? false
property bool isReadOnly: parent.readOnly ?? false

property string textOn: qsTr("True")
property string textOff: qsTr("False")
property alias checked: rightSwitch.checked
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
property string textOn: qsTr("True")
property string textOff: qsTr("False")
property alias checked: rightSwitch.checked
property alias text: textField.text
property alias checked: rightSwitch.checked


signal editorValueChanged( var newValue, var isNull )

hasFocus: rightSwitch.focus

content: Text {
id: textField

width: parent.width + rightSwitch.x
anchors.verticalCenter: parent.verticalCenter

text: root.checked ? root.textOn : root.textOff
color: root.enabled ? __style.nightColor : __style.mediumGreenColor
font: __style.p5
elide: Text.ElideRight
}

rightAction: MMSwitch {
id: rightSwitch

width: 50
height: parent.height
x: -30 * __dp

checked: root.checked
textOn: root.textOn
textOff: root.textOff
iiLubos marked this conversation as resolved.
Show resolved Hide resolved
visibleText: false

onCheckedChanged: focus = true
}
}
1 change: 1 addition & 0 deletions gallery/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@
<file>../app/qml/components/MMBackButton.qml</file>
<file>../app/qml/components/MMIconCheckBoxHorizontal.qml</file>
<file>../app/qml/components/MMIconCheckBoxVertical.qml</file>
<file>../app/qml/inputs/MMSwitchEditor.qml</file>
</qresource>
</RCC>
10 changes: 9 additions & 1 deletion gallery/qml/pages/EditorsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,20 @@ ScrollView {

MMPasswordEditor {
title: "MMPasswordEditor"
parentValue: "Password"
text: "Password"
//regexp: '(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.{6,})'
errorMsg: "Password must contain at least 6 characters\nMinimum 1 number, uppercase and lowercase letter and special character"
enabled: checkbox.checked
width: parent.width
}

MMSwitchEditor {
title: "MMSwitchEditor"
checked: true
warningMsg: checked ? "" : "Should be checked :)"
enabled: checkbox.checked
width: parent.width
}
}
}

Expand Down