qml improvements

This commit is contained in:
Evgenii Alekseev 2024-03-26 15:41:34 +02:00
parent 0b2b58bd33
commit 4fcea42e8e
8 changed files with 62 additions and 156 deletions

View File

@ -16,27 +16,15 @@
***************************************************************************/ ***************************************************************************/
import QtQuick 2.15 import QtQuick 2.15
import org.kde.kcmutils as KCM
import org.kde.plasma.private.awesomewidget 1.0 import org.kde.plasma.private.awesomewidget 1.0
Item { KCM.SimpleKCM {
id: aboutPage id: aboutPage
// backend
AWActions {
id: awActions
}
width: childrenRect.width
height: childrenRect.height
property bool debug: awActions.isDebugEnabled()
AboutTab { AboutTab {
textProvider: awActions textProvider: awActions
} }
Component.onCompleted: {
if (debug) console.debug()
}
} }

View File

@ -17,24 +17,19 @@
import QtQuick 2.15 import QtQuick 2.15
import QtQuick.Controls import QtQuick.Controls
import org.kde.kcmutils as KCM
import org.kde.plasma.private.awesomewidget 1.0 import org.kde.plasma.private.awesomewidget 1.0
Item { KCM.SimpleKCM {
id: advancedPage id: advancedPage
// backend // backend
AWActions { AWActions {
id: awActions id: awActions
} }
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: awActions.isDebugEnabled()
property alias cfg_background: background.checked property alias cfg_background: background.checked
property alias cfg_translateStrings: translate.checked property alias cfg_translateStrings: translate.checked
property alias cfg_wrapNewLines: wrapNewLines.checked property alias cfg_wrapNewLines: wrapNewLines.checked
@ -55,7 +50,6 @@ Item {
property alias cfg_telemetryRemote: telemetryRemote.checked property alias cfg_telemetryRemote: telemetryRemote.checked
property alias cfg_telemetryId: telemetryId.value property alias cfg_telemetryId: telemetryId.value
Column { Column {
id: pageColumn id: pageColumn
anchors.fill: parent anchors.fill: parent
@ -194,14 +188,18 @@ Item {
GroupBox { GroupBox {
width: parent.width width: parent.width
height: implicitHeight
title: i18n("Actions") title: i18n("Actions")
Column { Column {
height: implicitHeight
width: parent.width width: parent.width
ButtonSelector { ButtonSelector {
value: i18n("Drop key cache") value: i18n("Drop key cache")
onButtonActivated: awActions.dropCache() onButtonActivated: awActions.dropCache()
} }
ButtonSelector { ButtonSelector {
ExportDialog { ExportDialog {
id: saveConfigAs id: saveConfigAs
@ -210,11 +208,12 @@ Item {
value: i18n("Export configuration") value: i18n("Export configuration")
onButtonActivated: saveConfigAs.open() onButtonActivated: saveConfigAs.open()
} }
ButtonSelector { ButtonSelector {
ImportDialog { ImportDialog {
id: loadConfigFrom id: loadConfigFrom
onConfigurationReceived: { onConfigurationReceived: {
for (var key in configuration) for (const key in configuration)
plasmoid.configuration[key] = configuration[key] plasmoid.configuration[key] = configuration[key]
} }
} }
@ -225,15 +224,19 @@ Item {
} }
GroupBox { GroupBox {
height: implicitHeight
width: parent.width width: parent.width
title: i18n("Telemetry") title: i18n("Telemetry")
Column { Column {
height: implicitHeight
width: parent.width width: parent.width
CheckBoxSelector { CheckBoxSelector {
id: telemetryRemote id: telemetryRemote
text: i18n("Enable remote telemetry") text: i18n("Enable remote telemetry")
} }
IntegerSelector { IntegerSelector {
id: telemetryCount id: telemetryCount
maximumValue: 10000 maximumValue: 10000
@ -242,6 +245,7 @@ Item {
text: i18n("History count") text: i18n("History count")
value: plasmoid.configuration.telemetryCount value: plasmoid.configuration.telemetryCount
} }
LineSelector { LineSelector {
id: telemetryId id: telemetryId
text: i18n("Telemetry ID") text: i18n("Telemetry ID")
@ -250,9 +254,4 @@ Item {
} }
} }
} }
Component.onCompleted: {
if (debug) console.debug()
}
} }

View File

@ -16,30 +16,21 @@
***************************************************************************/ ***************************************************************************/
import QtQuick 2.15 import QtQuick 2.15
import org.kde.kcmutils as KCM
import org.kde.plasma.private.awesomewidget 1.0 import org.kde.plasma.private.awesomewidget 1.0
import "." import "."
Item { KCM.SimpleKCM {
id: appearancePage id: appearancePage
// backend
AWActions {
id: awActions
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: awActions.isDebugEnabled()
property variant weight: { property variant weight: {
25: 0, 25: 0,
50: 1, 50: 1,
63: 3, 63: 3,
75: 4, 75: 4,
87: 5 87: 5,
} }
property alias cfg_fontFamily: font.value property alias cfg_fontFamily: font.value
@ -106,9 +97,4 @@ Item {
value: plasmoid.configuration.textStyleColor value: plasmoid.configuration.textStyleColor
} }
} }
Component.onCompleted: {
if (debug) console.debug()
}
} }

View File

@ -17,36 +17,28 @@
import QtQuick 2.15 import QtQuick 2.15
import QtQuick.Controls import QtQuick.Controls
import org.kde.kcmutils as KCM
import org.kde.plasma.private.awesomewidget 1.0 import org.kde.plasma.private.awesomewidget 1.0
Item { KCM.SimpleKCM {
id: dataenginePage id: dataenginePage
// backend // backend
AWKeys { AWKeys {
id: awKeys id: awKeys
} }
AWActions {
id: awActions
}
AWConfigHelper { AWConfigHelper {
id: awConfig id: awConfig
} }
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: awActions.isDebugEnabled()
property variant cfg_dataengine: awConfig.readDataEngineConfiguration() property variant cfg_dataengine: awConfig.readDataEngineConfiguration()
Column { Column {
id: pageColumn id: pageColumn
anchors.fill: parent anchors.fill: parent
const
GroupBox { GroupBox {
height: implicitHeight height: implicitHeight
width: parent.width width: parent.width
@ -62,6 +54,7 @@ Item {
height: implicitHeight height: implicitHeight
width: parent.width width: parent.width
title: i18n("Player") title: i18n("Player")
Column { Column {
height: implicitHeight height: implicitHeight
width: parent.width width: parent.width
@ -160,9 +153,11 @@ Item {
height: implicitHeight height: implicitHeight
width: parent.width width: parent.width
title: i18n("Extensions") title: i18n("Extensions")
Column { Column {
height: implicitHeight height: implicitHeight
width: parent.width width: parent.width
ButtonSelector { ButtonSelector {
value: i18n("Custom scripts") value: i18n("Custom scripts")
onButtonActivated: awKeys.editItem("extscript") onButtonActivated: awKeys.editItem("extscript")
@ -193,8 +188,6 @@ Item {
Component.onCompleted: { Component.onCompleted: {
if (debug) console.debug()
// init submodule // init submodule
awKeys.updateCache() awKeys.updateCache()
@ -204,8 +197,6 @@ Item {
} }
Component.onDestruction: { Component.onDestruction: {
if (debug) console.debug()
cfg_dataengine["MPRIS"] = mpris.editText cfg_dataengine["MPRIS"] = mpris.editText
awConfig.writeDataEngineConfiguration(cfg_dataengine) awConfig.writeDataEngineConfiguration(cfg_dataengine)
} }

View File

@ -28,6 +28,7 @@ import "."
PlasmoidItem { PlasmoidItem {
id: main id: main
// backend // backend
AWKeys { AWKeys {
id: awKeys id: awKeys
@ -42,7 +43,6 @@ PlasmoidItem {
id: bugReport id: bugReport
} }
property bool debug: awActions.isDebugEnabled()
property variant tooltipSettings: { property variant tooltipSettings: {
"tooltipNumber": plasmoid.configuration.tooltipNumber, "tooltipNumber": plasmoid.configuration.tooltipNumber,
"useTooltipBackground": plasmoid.configuration.useTooltipBackground, "useTooltipBackground": plasmoid.configuration.useTooltipBackground,
@ -72,15 +72,13 @@ PlasmoidItem {
signal needToolTipUpdate(string newText) signal needToolTipUpdate(string newText)
signal sizeUpdate signal sizeUpdate
Layout.fillWidth: PlasmoidItem.formFactor !== PlasmaCore.Planar
Layout.fillWidth: PlasmoidItem.formFactor != PlasmaCore.Planar Layout.fillHeight: PlasmoidItem.formFactor !== PlasmaCore.Planar
Layout.fillHeight: PlasmoidItem.formFactor != PlasmaCore.Planar
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
Plasmoid.icon: "utilities-system-monitor" Plasmoid.icon: "utilities-system-monitor"
Plasmoid.backgroundHints: plasmoid.configuration.background ? "DefaultBackground" : "NoBackground" Plasmoid.backgroundHints: plasmoid.configuration.background ? "DefaultBackground" : "NoBackground"
// ui // ui
Text { Text {
id: text id: text
@ -94,7 +92,7 @@ PlasmoidItem {
color: plasmoid.configuration.fontColor color: plasmoid.configuration.fontColor
font.family: plasmoid.configuration.fontFamily font.family: plasmoid.configuration.fontFamily
font.italic: plasmoid.configuration.fontStyle == "italic" ? true : false font.italic: plasmoid.configuration.fontStyle === "italic" ? true : false
font.pointSize: plasmoid.configuration.fontSize font.pointSize: plasmoid.configuration.fontSize
font.weight: General.fontWeight[plasmoid.configuration.fontWeight] font.weight: General.fontWeight[plasmoid.configuration.fontWeight]
@ -124,8 +122,8 @@ PlasmoidItem {
} }
onAccepted: { onAccepted: {
var tag = tagSelectorBox.editText const tag = tagSelectorBox.editText
var message = i18n("Tag: %1", tag) let message = i18n("Tag: %1", tag)
message += "<br>" message += "<br>"
message += i18n("Value: %1", awKeys.valueByKey(tag)) message += i18n("Value: %1", awKeys.valueByKey(tag))
message += "<br>" message += "<br>"
@ -138,25 +136,33 @@ PlasmoidItem {
PlasmaCore.Action { PlasmaCore.Action {
text: i18n("Request key") text: i18n("Request key")
icon.name: "utilities-system-monitor" icon.name: "utilities-system-monitor"
onTriggered: {
tagSelectorBox.model = awKeys.dictKeys(true)
tagSelector.open()
}
}, },
PlasmaCore.Action { PlasmaCore.Action {
text: i18n("Show README") text: i18n("Show README")
icon.name: "text-x-readme" icon.name: "text-x-readme"
onTriggered: awActions.showReadme()
}, },
PlasmaCore.Action { PlasmaCore.Action {
text: i18n("Check updates") text: i18n("Check updates")
icon.name: "system-software-update" icon.name: "system-software-update"
onTriggered: awActions.checkUpdates(true)
}, },
PlasmaCore.Action { PlasmaCore.Action {
text: i18n("Report bug") text: i18n("Report bug")
icon.name: "tools-report-bug" icon.name: "tools-report-bug"
onTriggered: {
bugReport.reset()
bugReport.open()
}
} }
] ]
Component.onCompleted: { Component.onCompleted: {
if (debug) console.debug()
// init submodule // init submodule
Plasmoid.userConfiguringChanged(false) Plasmoid.userConfiguringChanged(false)
// connect data // connect data
@ -167,31 +173,25 @@ PlasmoidItem {
} }
onNeedTextUpdate: newText => { onNeedTextUpdate: newText => {
if (debug) console.debug()
text.text = newText text.text = newText
sizeUpdate() sizeUpdate()
} }
onNeedToolTipUpdate: newText => { onNeedToolTipUpdate: newText => {
if (debug) console.debug()
tooltip.text = newText tooltip.text = newText
} }
onSizeUpdate: { onSizeUpdate: {
if (debug) console.debug()
// 16 is a magic number // 16 is a magic number
// in other case plasmoid will increase own size on each update // in other case plasmoid will increase own size on each update
if (plasmoid.configuration.height === 0) {
if (plasmoid.configuration.height == 0) {
Layout.minimumHeight = text.contentHeight - 16 Layout.minimumHeight = text.contentHeight - 16
Layout.maximumHeight = -1 Layout.maximumHeight = -1
} else { } else {
Layout.minimumHeight = plasmoid.configuration.height Layout.minimumHeight = plasmoid.configuration.height
Layout.maximumHeight = plasmoid.configuration.height Layout.maximumHeight = plasmoid.configuration.height
} }
if (plasmoid.configuration.width == 0) { if (plasmoid.configuration.width === 0) {
Layout.minimumWidth = text.contentWidth - 16 Layout.minimumWidth = text.contentWidth - 16
Layout.maximumWidth = -1 Layout.maximumWidth = -1
} else { } else {
@ -202,7 +202,6 @@ PlasmoidItem {
Plasmoid.onUserConfiguringChanged: { Plasmoid.onUserConfiguringChanged: {
if (plasmoid.userConfiguring) return if (plasmoid.userConfiguring) return
if (debug) console.debug()
// init submodule // init submodule
awKeys.initDataAggregator(tooltipSettings) awKeys.initDataAggregator(tooltipSettings)
@ -217,7 +216,7 @@ PlasmoidItem {
awKeys.setAggregatorProperty("tempUnits", plasmoid.configuration.tempUnits) awKeys.setAggregatorProperty("tempUnits", plasmoid.configuration.tempUnits)
awKeys.setAggregatorProperty("translate", plasmoid.configuration.translateStrings) awKeys.setAggregatorProperty("translate", plasmoid.configuration.translateStrings)
// update telemetry ID // update telemetry ID
if (plasmoid.configuration.telemetryId.length == 0) if (plasmoid.configuration.telemetryId.length === 0)
plasmoid.configuration.telemetryId = generateUuid() plasmoid.configuration.telemetryId = generateUuid()
// save telemetry // save telemetry
awTelemetryHandler.init(plasmoid.configuration.telemetryCount, awTelemetryHandler.init(plasmoid.configuration.telemetryCount,
@ -227,37 +226,10 @@ PlasmoidItem {
awTelemetryHandler.uploadTelemetry("awwidgetconfig", plasmoid.configuration.text) awTelemetryHandler.uploadTelemetry("awwidgetconfig", plasmoid.configuration.text)
} }
function action_checkUpdates() {
if (debug) console.debug()
return awActions.checkUpdates(true)
}
function action_showReadme() {
if (debug) console.debug()
return awActions.showReadme()
}
function action_reportBug() {
if (debug) console.debug()
bugReport.reset()
bugReport.open()
}
function action_requestKey() {
if (debug) console.debug()
tagSelectorBox.model = awKeys.dictKeys(true)
return tagSelector.open()
}
// code from http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript // code from http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
function generateUuid() { function generateUuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); let r = Math.random() * 16 | 0, v = c === "x" ? r : (r & 0x3 | 0x8);
return v.toString(16); return v.toString(16);
}); });
} }

View File

@ -17,23 +17,13 @@
import QtQuick 2.15 import QtQuick 2.15
import QtQuick.Controls import QtQuick.Controls
import org.kde.kcmutils as KCM
import org.kde.plasma.private.awesomewidget 1.0 import org.kde.plasma.private.awesomewidget 1.0
Item { KCM.SimpleKCM {
id: tooltipPage id: tooltipPage
// backend
AWActions {
id: awActions
}
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: awActions.isDebugEnabled()
property alias cfg_tooltipNumber: tooltipNumber.value property alias cfg_tooltipNumber: tooltipNumber.value
property alias cfg_useTooltipBackground: useTooltipBackground.checked property alias cfg_useTooltipBackground: useTooltipBackground.checked
@ -53,7 +43,6 @@ Item {
property alias cfg_batTooltipColor: batTooltipColor.value property alias cfg_batTooltipColor: batTooltipColor.value
property alias cfg_batInTooltipColor: batInTooltipColor.value property alias cfg_batInTooltipColor: batInTooltipColor.value
Column { Column {
id: pageColumn id: pageColumn
anchors.fill: parent anchors.fill: parent
@ -178,11 +167,13 @@ Item {
Column { Column {
width: parent.width width: parent.width
enabled: networkTooltipLabel.checked enabled: networkTooltipLabel.checked
ColorSelector { ColorSelector {
id: downkbTooltipColor id: downkbTooltipColor
text: i18n("Download speed color") text: i18n("Download speed color")
value: plasmoid.configuration.downkbTooltipColor value: plasmoid.configuration.downkbTooltipColor
} }
ColorSelector { ColorSelector {
id: upkbTooltipColor id: upkbTooltipColor
text: i18n("Upload speed color") text: i18n("Upload speed color")
@ -204,11 +195,13 @@ Item {
Column { Column {
width: parent.width width: parent.width
enabled: batteryTooltipLabel.checked enabled: batteryTooltipLabel.checked
ColorSelector { ColorSelector {
id: batTooltipColor id: batTooltipColor
text: i18n("Battery active color") text: i18n("Battery active color")
value: plasmoid.configuration.batTooltipColor value: plasmoid.configuration.batTooltipColor
} }
ColorSelector { ColorSelector {
id: batInTooltipColor id: batInTooltipColor
text: i18n("Battery inactive color") text: i18n("Battery inactive color")
@ -217,9 +210,4 @@ Item {
} }
} }
} }
Component.onCompleted: {
if (debug) console.debug()
}
} }

View File

@ -16,13 +16,16 @@
***************************************************************************/ ***************************************************************************/
import QtQuick 2.15 import QtQuick 2.15
import QtQuick.Controls
import org.kde.kcmutils as KCM
import org.kde.plasma.private.awesomewidget 1.0 import org.kde.plasma.private.awesomewidget 1.0
import "." import "."
Item { KCM.SimpleKCM {
id: widgetPage id: widgetPage
// backend // backend
AWKeys { AWKeys {
id: awKeys id: awKeys
@ -31,19 +34,11 @@ Item {
id: awActions id: awActions
} }
width: childrenRect.width
height: childrenRect.height
implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight
property bool debug: awActions.isDebugEnabled()
property alias cfg_text: textPattern.text property alias cfg_text: textPattern.text
property bool lock: true property bool lock: true
signal needTextUpdate(string newText) signal needTextUpdate(string newText)
Column { Column {
id: pageColumn id: pageColumn
anchors.fill: parent anchors.fill: parent
@ -74,10 +69,7 @@ Item {
} }
} }
Component.onCompleted: { Component.onCompleted: {
if (debug) console.debug()
awKeys.needTextToBeUpdated.connect(needTextUpdate) awKeys.needTextToBeUpdated.connect(needTextUpdate)
// init submodule // init submodule
awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.interval, awKeys.initKeys(plasmoid.configuration.text, plasmoid.configuration.interval,
@ -92,7 +84,6 @@ Item {
onNeedTextUpdate: newText => { onNeedTextUpdate: newText => {
if (lock) return if (lock) return
if (debug) console.debug()
extensions.showMessage(newText) extensions.showMessage(newText)
lock = true lock = true

View File

@ -19,7 +19,7 @@ import QtQuick 2.15
import QtQuick.Controls import QtQuick.Controls
Item { ScrollView {
width: parent.width width: parent.width
height: parent.height * 4 / 5 height: parent.height * 4 / 5
@ -28,7 +28,6 @@ Item {
TextArea { TextArea {
id: textArea id: textArea
anchors.fill: parent
textFormat: TextEdit.PlainText textFormat: TextEdit.PlainText
Column { Column {
@ -50,9 +49,9 @@ Item {
} }
onTextChanged: { onTextChanged: {
var currentTag = getLastTag() let currentTag = getLastTag()
// exit if there are spaces or empty // exit if there are spaces or empty
if ((currentTag.indexOf(" ") != -1) || (currentTag.length == 0)) { if ((currentTag.indexOf(" ") !== -1) || (currentTag.length === 0)) {
tooltip.visible = false tooltip.visible = false
return return
} }
@ -63,7 +62,7 @@ Item {
// show tooltip if found more than 1 or current text does not match // show tooltip if found more than 1 or current text does not match
// tag found // tag found
tooltip.visible = ((tags.count > 1) tooltip.visible = ((tags.count > 1)
|| ((tags.count == 1) && (tags.model[0] != tooltip.substring))) || ((tags.count === 1) && (tags.model[0] !== tooltip.substring)))
} }
} }
@ -81,7 +80,7 @@ Item {
var substring = textArea.getText(0, textArea.cursorPosition) var substring = textArea.getText(0, textArea.cursorPosition)
// find last position of index in the given substring // find last position of index in the given substring
var signIndex = substring.lastIndexOf('$') + 1 var signIndex = substring.lastIndexOf('$') + 1
if ((signIndex == 0) || (signIndex == textArea.cursorPosition)) if ((signIndex === 0) || (signIndex === textArea.cursorPosition))
return "" return ""
// get current tag text // get current tag text
return substring.substr(signIndex) return substring.substr(signIndex)
@ -90,14 +89,6 @@ Item {
function insert(text) { function insert(text) {
textArea.insert(textArea.cursorPosition, text) textArea.insert(textArea.cursorPosition, text)
} }
function removeSelection() {
textArea.remove(textArea.selectionStart, textArea.selectionEnd)
}
function selectedText() {
return textArea.selectedText
}
} }