Skip to content

Commit

Permalink
Added Switch item based on AbstractEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
iiLubos committed Dec 18, 2023
1 parent 4eb9499 commit 4349dec
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
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
}
}
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"

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

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
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

1 comment on commit 4349dec

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

iOS - version 23.12.498511 just submitted!

Please sign in to comment.