From dd51fa01de836b8ccb864048687c94fea2664917 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 18 Dec 2023 12:06:48 +0100 Subject: [PATCH] Added resizable Text area item based on AbstractEditor --- app/qml/inputs/MMAbstractEditor.qml | 4 ++- app/qml/inputs/MMPasswordEditor.qml | 2 +- app/qml/inputs/MMTextAreaEditor.qml | 47 +++++++++++++++++++++++++++++ gallery/qml.qrc | 1 + gallery/qml/pages/EditorsPage.qml | 10 +++++- 5 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 app/qml/inputs/MMTextAreaEditor.qml diff --git a/app/qml/inputs/MMAbstractEditor.qml b/app/qml/inputs/MMAbstractEditor.qml index 43de20e7d..d15f140c1 100644 --- a/app/qml/inputs/MMAbstractEditor.qml +++ b/app/qml/inputs/MMAbstractEditor.qml @@ -33,6 +33,8 @@ Item { property bool hasCheckbox: false property bool checkboxChecked: false + property real innerHeight: 50 * __dp + readonly property real spacing: 15 * __dp width: parent.width @@ -70,7 +72,7 @@ Item { } Item { - height: 50 * __dp + height: root.innerHeight anchors.left: parent.left anchors.right: parent.right diff --git a/app/qml/inputs/MMPasswordEditor.qml b/app/qml/inputs/MMPasswordEditor.qml index 5385c9da4..22d548145 100644 --- a/app/qml/inputs/MMPasswordEditor.qml +++ b/app/qml/inputs/MMPasswordEditor.qml @@ -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 diff --git a/app/qml/inputs/MMTextAreaEditor.qml b/app/qml/inputs/MMTextAreaEditor.qml new file mode 100644 index 000000000..d5dda0ebf --- /dev/null +++ b/app/qml/inputs/MMTextAreaEditor.qml @@ -0,0 +1,47 @@ +/*************************************************************************** + * * + * 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 ?? "" + property bool parentValueIsNull: parent.valueIsNull ?? false + property bool isReadOnly: parent.readOnly ?? false + + property alias placeholderText: textArea.placeholderText + property alias text: textArea.text + + signal editorValueChanged( var newValue, var isNull ) + + hasFocus: textArea.activeFocus + innerHeight: textArea.vertSpace + textArea.contentHeight + 2 * textArea.vertSpace + + content: TextArea { + id: textArea + + property real vertSpace: 11 * __dp + + y: textArea.vertSpace + height: contentHeight + textArea.vertSpace + width: parent.width + + hoverEnabled: true + placeholderTextColor: __style.nightAlphaColor + color: root.enabled ? __style.nightColor : __style.mediumGreenColor + font: __style.p5 + wrapMode: Text.WordWrap + } +} diff --git a/gallery/qml.qrc b/gallery/qml.qrc index 63e48064a..6bf9a906f 100644 --- a/gallery/qml.qrc +++ b/gallery/qml.qrc @@ -69,5 +69,6 @@ ../app/qml/components/MMBackButton.qml ../app/qml/components/MMIconCheckBoxHorizontal.qml ../app/qml/components/MMIconCheckBoxVertical.qml + ../app/qml/inputs/MMTextAreaEditor.qml diff --git a/gallery/qml/pages/EditorsPage.qml b/gallery/qml/pages/EditorsPage.qml index fcc8fcfef..36ff0829e 100644 --- a/gallery/qml/pages/EditorsPage.qml +++ b/gallery/qml/pages/EditorsPage.qml @@ -70,9 +70,17 @@ ScrollView { warningMsg: text.length > 0 ? "" : "Write something" } + MMTextAreaEditor { + title: "MMTextAreaEditor" + placeholderText: "Place for multi row text" + enabled: checkbox.checked + width: parent.width + warningMsg: text.length > 0 ? "" : "Write something" + } + 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