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 input editors: #2923

Closed
wants to merge 2 commits into from
Closed

Added input editors: #2923

wants to merge 2 commits into from

Conversation

iiLubos
Copy link
Contributor

@iiLubos iiLubos commented Nov 27, 2023

image

  • MMInputEditor (optional left icon)

  • MMPasswordEditor (with eye button)

  • MMSliderEditor See how to use it in EditorsPage.qml

      MMSliderEditor {
        title: "MMSliderEditor"
        from: -100
        to: 100
        parentValue: -100
        suffix: " s"
        width: parent.width
        onEditorValueChanged: function(newValue) { errorMsg = newValue > 0 ? "" : "Set positive value!" }
        hasCheckbox: true
        checkboxChecked: true
      }
    
      MMInputEditor {
        title: "MMInputEditor"
        parentValue: "Text"
        width: parent.width
        hasCheckbox: true
        checkboxChecked: false
      }
    
      MMInputEditor {
        title: "MMInputEditor"
        placeholderText: "Placeholder"
        width: parent.width
        warningMsg: text.length > 0 ? "" : "Write something"
      }
    
      MMPasswordEditor {
        title: "MMPasswordEditor"
        parentValue: "Password"
        regexp: '(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.{6,})'
        errorMsg: isPasswordCorrect(text) ? "" : "Password must contain at least 6 characters\nMinimum 1 number, uppercase and lowercase letter and special character"
        width: parent.width
      }
    

- MMInputEditor (optional left icon)
- MMPasswordEditor (with eye button)
- MMSliderEditor
See how to use it in EditorsPage.qml
@iiLubos iiLubos self-assigned this Nov 27, 2023
@iiLubos iiLubos marked this pull request as ready for review November 29, 2023 08:07
border.color: root.hasFocus ? ( errorMsg.length > 0 ? StyleV2.negativeColor : warningMsg.length > 0 ? StyleV2.warningColor : StyleV2.forestColor ) : StyleV2.transparentColor
border.width: 2 * __dp
color: root.bgColor
radius: 12 * __dp
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would expect this radius value to be in __style as it is likely reused in many other places


width: parent.width
height: parent.height
border.color: root.hasFocus ? ( errorMsg.length > 0 ? StyleV2.negativeColor : warningMsg.length > 0 ? StyleV2.warningColor : StyleV2.forestColor ) : StyleV2.transparentColor
Copy link
Collaborator

Choose a reason for hiding this comment

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

In case of more complicated conditions like here, we should write them with proper if/else statements. These are much easier to read, understand and update if needed. See for example: https://doc.qt.io/qt-6/qml-codingconventions.html#javascript-code

Suggested change
border.color: root.hasFocus ? ( errorMsg.length > 0 ? StyleV2.negativeColor : warningMsg.length > 0 ? StyleV2.warningColor : StyleV2.forestColor ) : StyleV2.transparentColor
border.color: {
if (root.hasFocus) {
if (errorMsg.length > 0) {
return __style.negativeColor
}
else if (warningMsg.length > 0) {
return __style.warningColor
}
}
else {
return __style.transparentColor
}
}

Comment on lines +102 to +106
Rectangle {
color: StyleV2.transparentColor
anchors.centerIn: parent
width: leftActionContainer.actionAllowed ? parent.width + root.spacing/2 : 0
height: parent.height
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the point of this rectangle?

id: contentContainer

height: parent.height
width: parent.width - (leftActionContainer.actionAllowed ? leftActionContainer.width : 0) - (rightActionContainer.actionAllowed ? rightActionContainer.width : 0) //- 2 * root.spacing - ( leftActionContainer.actionAllowed ? root.spacing : 0 )
Copy link
Collaborator

Choose a reason for hiding this comment

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

Commented out code

Suggested change
width: parent.width - (leftActionContainer.actionAllowed ? leftActionContainer.width : 0) - (rightActionContainer.actionAllowed ? rightActionContainer.width : 0) //- 2 * root.spacing - ( leftActionContainer.actionAllowed ? root.spacing : 0 )
width: parent.width - (leftActionContainer.actionAllowed ? leftActionContainer.width : 0) - (rightActionContainer.actionAllowed ? rightActionContainer.width : 0)

Item {
id: leftActionContainer

property bool actionAllowed: leftActionContainer.children.length > 1 && (leftActionContainer.children[1]?.visible ?? false)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What type of input changes the visibility state?

Suggested change
property bool actionAllowed: leftActionContainer.children.length > 1 && (leftActionContainer.children[1]?.visible ?? false)
property bool actionAllowed: leftActionContainer.children.length > 1 )

import Qt5Compat.GraphicalEffects
import ".."

//import lc 1.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Commented out code

Comment on lines +28 to +30
/*required*/ property var parentValue: parent.value ?? ""
/*required*/ property bool parentValueIsNull: parent.valueIsNull ?? false
/*required*/ property bool isReadOnly: parent.readOnly ?? false
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is Qt6, we can finally start using the required properties! :)) 🍾

Suggested change
/*required*/ property var parentValue: parent.value ?? ""
/*required*/ property bool parentValueIsNull: parent.valueIsNull ?? false
/*required*/ property bool isReadOnly: parent.readOnly ?? false
required property var parentValue: parent.value ?? ""
required property bool parentValueIsNull: parent.valueIsNull ?? false
required property bool isReadOnly: parent.readOnly ?? false

Copy link
Collaborator

Choose a reason for hiding this comment

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

This applies to other files too

Comment on lines +1 to +14
/***************************************************************************
range.qml
--------------------------------------
Date : 2019
Copyright : (C) 2019 by Viktor Sklencar
Email : [email protected]
***************************************************************************
* *
* 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. *
* *
***************************************************************************/
Copy link
Collaborator

Choose a reason for hiding this comment

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

New file, new header :)

Suggested change
/***************************************************************************
range.qml
--------------------------------------
Date : 2019
Copyright : (C) 2019 by Viktor Sklencar
Email : viktor.sklencar@lutraconsulting.co.uk
***************************************************************************
* *
* 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. *
* *
***************************************************************************/
/ ***************************************************************************
* *
* 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. *
* *
***************************************************************************/

Copy link
Collaborator

Choose a reason for hiding this comment

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

The same applies to all files

import Qt5Compat.GraphicalEffects
import ".."

//import lc 1.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

commented out code

Copy link
Collaborator

Choose a reason for hiding this comment

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

The same applies to all files, please remove code that is commented out

/*required*/ property bool parentValueIsNull: parent.valueIsNull ?? false
/*required*/ property bool isReadOnly: parent.readOnly ?? false

required property string regexp
Copy link
Collaborator

Choose a reason for hiding this comment

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

Validation of password goes through c++, not here. This field will instead receive an error is password is not strong enough

@iiLubos
Copy link
Contributor Author

iiLubos commented Dec 5, 2023

Done in #2944

@iiLubos iiLubos closed this Dec 5, 2023
@PeterPetrik PeterPetrik deleted the master_designEditors branch March 20, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants