2020-12-22 00:01:36 +00:00
|
|
|
|
/**
|
2022-03-05 16:49:35 +00:00
|
|
|
|
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
2024-01-10 23:11:09 +00:00
|
|
|
|
* Copyright (C) 2021-2024 Ad5001
|
2020-12-22 00:01:36 +00:00
|
|
|
|
*
|
|
|
|
|
* 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 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-05-21 22:15:09 +00:00
|
|
|
|
import QtQuick.Controls
|
|
|
|
|
import QtQuick
|
2022-10-18 21:24:58 +00:00
|
|
|
|
import eu.ad5001.LogarithmPlotter.Popup 1.0 as Popup
|
2020-12-22 00:01:36 +00:00
|
|
|
|
|
2022-01-29 17:17:19 +00:00
|
|
|
|
/*!
|
|
|
|
|
\qmltype TextSetting
|
|
|
|
|
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
|
|
|
|
|
\brief Setting to edit strings and numbers.
|
|
|
|
|
|
|
|
|
|
\sa EditorDialog, Settings, Icon
|
|
|
|
|
*/
|
2020-12-22 00:01:36 +00:00
|
|
|
|
Item {
|
|
|
|
|
id: control
|
|
|
|
|
height: 30
|
|
|
|
|
|
2022-01-29 17:17:19 +00:00
|
|
|
|
/*!
|
|
|
|
|
\qmlsignal TextSetting::changed(string newValue)
|
|
|
|
|
|
|
|
|
|
Emitted when the value of the text has been changed.
|
|
|
|
|
The corresponding handler is \c onChanged.
|
|
|
|
|
*/
|
2020-12-22 00:01:36 +00:00
|
|
|
|
signal changed(string newValue)
|
|
|
|
|
|
2022-01-29 17:17:19 +00:00
|
|
|
|
/*!
|
|
|
|
|
\qmlproperty bool TextSetting::isInt
|
|
|
|
|
If true, the input is being parsed an int before being emitting the \a changed signal.
|
|
|
|
|
*/
|
2020-12-22 00:01:36 +00:00
|
|
|
|
property bool isInt: false
|
2022-01-29 17:17:19 +00:00
|
|
|
|
/*!
|
|
|
|
|
\qmlproperty bool TextSetting::isDouble
|
|
|
|
|
If true, the input is being parsed an double before being emitting the \a changed signal.
|
|
|
|
|
*/
|
2020-12-22 00:01:36 +00:00
|
|
|
|
property bool isDouble: false
|
2023-10-09 15:55:06 +00:00
|
|
|
|
/*!
|
|
|
|
|
\qmlproperty bool TextSetting::category
|
|
|
|
|
Type of special character to insert from the popup.
|
|
|
|
|
\sa InsertCharacter::category
|
|
|
|
|
*/
|
|
|
|
|
property alias category: insertPopup.category
|
2022-01-29 17:17:19 +00:00
|
|
|
|
/*!
|
|
|
|
|
\qmlproperty double TextSetting::min
|
|
|
|
|
Minimum value for numbers that can be entered into the input.
|
|
|
|
|
*/
|
2020-12-24 00:31:57 +00:00
|
|
|
|
property double min: -1
|
2022-01-29 17:17:19 +00:00
|
|
|
|
/*!
|
|
|
|
|
\qmlproperty string TextSetting::defValue
|
|
|
|
|
Default value of the input.
|
|
|
|
|
*/
|
2020-12-22 00:01:36 +00:00
|
|
|
|
property string defValue
|
2022-01-29 17:17:19 +00:00
|
|
|
|
/*!
|
|
|
|
|
\qmlproperty string TextSetting::value
|
|
|
|
|
Value of the input.
|
|
|
|
|
*/
|
2021-08-21 17:46:20 +00:00
|
|
|
|
property alias value: input.text
|
2022-02-01 08:59:31 +00:00
|
|
|
|
/*!
|
|
|
|
|
\qmlproperty string TextSetting::placeholderText
|
|
|
|
|
Value of the input.
|
|
|
|
|
*/
|
|
|
|
|
property alias placeholderText: input.placeholderText
|
2022-01-29 17:17:19 +00:00
|
|
|
|
/*!
|
|
|
|
|
\qmlproperty string TextSetting::label
|
|
|
|
|
Label of the setting.
|
|
|
|
|
*/
|
|
|
|
|
property string label
|
|
|
|
|
/*!
|
|
|
|
|
\qmlproperty string TextSetting::icon
|
|
|
|
|
Icon path of the setting.
|
|
|
|
|
*/
|
2021-03-31 13:58:21 +00:00
|
|
|
|
property string icon: ""
|
|
|
|
|
|
|
|
|
|
Icon {
|
|
|
|
|
id: iconLabel
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: icon == "" ? 0 : 3
|
2022-03-05 23:55:32 +00:00
|
|
|
|
source: control.visible && icon != "" ? "../icons/" + control.icon : ""
|
2021-03-31 13:58:21 +00:00
|
|
|
|
width: height
|
|
|
|
|
height: icon == "" || !visible ? 0 : 24
|
|
|
|
|
color: sysPalette.windowText
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-14 18:03:58 +00:00
|
|
|
|
Label {
|
2020-12-23 23:06:52 +00:00
|
|
|
|
id: labelItem
|
2021-03-31 13:58:21 +00:00
|
|
|
|
anchors.left: iconLabel.right
|
|
|
|
|
anchors.leftMargin: icon == "" ? 0 : 5
|
2020-12-23 23:06:52 +00:00
|
|
|
|
anchors.top: parent.top
|
2024-04-03 19:39:06 +00:00
|
|
|
|
height: parent.height
|
|
|
|
|
width: Math.max(85, implicitWidth)
|
2020-12-23 23:06:52 +00:00
|
|
|
|
verticalAlignment: TextInput.AlignVCenter
|
2021-03-14 18:03:58 +00:00
|
|
|
|
//color: sysPalette.windowText
|
2022-02-01 08:59:31 +00:00
|
|
|
|
text: visible ? qsTranslate("control", "%1: ").arg(control.label) : ""
|
|
|
|
|
visible: control.label != ""
|
2020-12-23 23:06:52 +00:00
|
|
|
|
}
|
2020-12-22 00:01:36 +00:00
|
|
|
|
|
2020-12-23 23:06:52 +00:00
|
|
|
|
TextField {
|
|
|
|
|
id: input
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.left: labelItem.right
|
|
|
|
|
anchors.leftMargin: 5
|
2022-02-01 08:59:31 +00:00
|
|
|
|
width: control.width - (labelItem.visible ? labelItem.width + 5 : 0) - iconLabel.width - 5
|
2021-03-31 13:58:21 +00:00
|
|
|
|
height: parent.height
|
2020-12-23 23:06:52 +00:00
|
|
|
|
verticalAlignment: TextInput.AlignVCenter
|
2022-02-01 08:59:31 +00:00
|
|
|
|
horizontalAlignment: control.label == "" ? TextInput.AlignLeft : TextInput.AlignHCenter
|
2020-12-23 23:06:52 +00:00
|
|
|
|
color: sysPalette.windowText
|
2023-05-21 20:32:49 +00:00
|
|
|
|
validator: RegularExpressionValidator {
|
|
|
|
|
regularExpression: control.isInt ? /-?[0-9]+/ : control.isDouble ? /-?[0-9]+(\.[0-9]+)?/ : /.+/
|
2022-02-08 13:33:08 +00:00
|
|
|
|
}
|
2020-12-23 23:06:52 +00:00
|
|
|
|
focus: true
|
|
|
|
|
text: control.defValue
|
|
|
|
|
selectByMouse: true
|
2023-05-24 01:17:21 +00:00
|
|
|
|
onEditingFinished: function() {
|
2022-10-18 21:24:58 +00:00
|
|
|
|
if(insertButton.focus || insertPopup.focus) return
|
2020-12-23 23:06:52 +00:00
|
|
|
|
var value = text
|
2024-04-03 19:39:06 +00:00
|
|
|
|
if(control.isInt)
|
|
|
|
|
value = isNaN(parseInt(value)) ? control.min : Math.max(control.min,parseInt(value))
|
|
|
|
|
if(control.isDouble)
|
|
|
|
|
value = isNaN(parseFloat(value)) ? control.min : Math.max(control.min,parseFloat(value))
|
2021-04-06 17:06:09 +00:00
|
|
|
|
if(value != "" && value.toString() != defValue) {
|
|
|
|
|
control.changed(value)
|
|
|
|
|
defValue = value.toString()
|
|
|
|
|
}
|
2020-12-22 00:01:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-14 12:28:30 +00:00
|
|
|
|
|
|
|
|
|
Button {
|
2022-10-18 21:24:58 +00:00
|
|
|
|
id: insertButton
|
2021-04-14 12:28:30 +00:00
|
|
|
|
text: "α"
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.rightMargin: 5
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
width: 20
|
|
|
|
|
height: width
|
|
|
|
|
visible: !isInt && !isDouble
|
2022-10-18 21:24:58 +00:00
|
|
|
|
onClicked: {
|
|
|
|
|
insertPopup.open()
|
|
|
|
|
insertPopup.focus = true
|
|
|
|
|
}
|
2021-04-14 12:28:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 21:24:58 +00:00
|
|
|
|
Popup.InsertCharacter {
|
2021-04-14 12:28:30 +00:00
|
|
|
|
id: insertPopup
|
2022-10-18 21:24:58 +00:00
|
|
|
|
|
2021-07-23 17:37:03 +00:00
|
|
|
|
x: Math.round((parent.width - width) / 2)
|
|
|
|
|
y: Math.round((parent.height - height) / 2)
|
2021-04-14 12:28:30 +00:00
|
|
|
|
|
2022-10-18 21:24:58 +00:00
|
|
|
|
onSelected: function(c) {
|
|
|
|
|
input.insert(input.cursorPosition, c)
|
|
|
|
|
insertPopup.close()
|
2022-10-19 15:37:38 +00:00
|
|
|
|
focus = false
|
2022-10-18 21:24:58 +00:00
|
|
|
|
input.focus = true
|
2021-04-14 12:28:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-22 00:01:36 +00:00
|
|
|
|
}
|