mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-17 07:39:58 +00:00
initial plasma6 support
This commit is contained in:
@ -15,20 +15,20 @@
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
import QtQuick 2.4
|
||||
import QtQuick.Controls 1.3 as QtControls
|
||||
import QtQuick.Dialogs 1.2 as QtDialogs
|
||||
import QtQuick.Layouts 1.1
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Dialogs
|
||||
import QtQuick.Layouts
|
||||
import org.kde.plasma.core as PlasmaCore
|
||||
import org.kde.plasma.plasmoid 2.0
|
||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||
import org.kde.plasma.components 2.0 as PlasmaComponents
|
||||
|
||||
import org.kde.plasma.private.awesomewidget 1.0
|
||||
import "."
|
||||
|
||||
|
||||
Item {
|
||||
PlasmoidItem {
|
||||
id: main
|
||||
|
||||
// backend
|
||||
AWKeys {
|
||||
id: awKeys
|
||||
@ -43,7 +43,6 @@ Item {
|
||||
id: bugReport
|
||||
}
|
||||
|
||||
property bool debug: awActions.isDebugEnabled()
|
||||
property variant tooltipSettings: {
|
||||
"tooltipNumber": plasmoid.configuration.tooltipNumber,
|
||||
"useTooltipBackground": plasmoid.configuration.useTooltipBackground,
|
||||
@ -73,19 +72,12 @@ Item {
|
||||
signal needToolTipUpdate(string newText)
|
||||
signal sizeUpdate
|
||||
|
||||
|
||||
// init
|
||||
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
|
||||
Plasmoid.compactRepresentation: Plasmoid.fullRepresentation
|
||||
|
||||
Layout.fillWidth: plasmoid.formFactor != PlasmaCore.Planar
|
||||
Layout.fillHeight: plasmoid.formFactor != PlasmaCore.Planar
|
||||
Layout.fillWidth: PlasmoidItem.formFactor !== PlasmaCore.Planar
|
||||
Layout.fillHeight: PlasmoidItem.formFactor !== PlasmaCore.Planar
|
||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
|
||||
|
||||
Plasmoid.icon: "utilities-system-monitor"
|
||||
Plasmoid.backgroundHints: plasmoid.configuration.background ? "DefaultBackground" : "NoBackground"
|
||||
Plasmoid.associatedApplication: "ksysguard"
|
||||
|
||||
|
||||
// ui
|
||||
Text {
|
||||
@ -100,7 +92,7 @@ Item {
|
||||
|
||||
color: plasmoid.configuration.fontColor
|
||||
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.weight: General.fontWeight[plasmoid.configuration.fontWeight]
|
||||
|
||||
@ -119,19 +111,19 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
QtDialogs.Dialog {
|
||||
Dialog {
|
||||
id: tagSelector
|
||||
title: i18n("Select tag")
|
||||
|
||||
QtControls.ComboBox {
|
||||
ComboBox {
|
||||
id: tagSelectorBox
|
||||
width: parent.width
|
||||
editable: true
|
||||
}
|
||||
|
||||
onAccepted: {
|
||||
var tag = tagSelectorBox.editText
|
||||
var message = i18n("Tag: %1", tag)
|
||||
const tag = tagSelectorBox.editText
|
||||
let message = i18n("Tag: %1", tag)
|
||||
message += "<br>"
|
||||
message += i18n("Value: %1", awKeys.valueByKey(tag))
|
||||
message += "<br>"
|
||||
@ -140,17 +132,37 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
Plasmoid.contextualActions: [
|
||||
PlasmaCore.Action {
|
||||
text: i18n("Request key")
|
||||
icon.name: "utilities-system-monitor"
|
||||
onTriggered: {
|
||||
tagSelectorBox.model = awKeys.dictKeys(true)
|
||||
tagSelector.open()
|
||||
}
|
||||
},
|
||||
PlasmaCore.Action {
|
||||
text: i18n("Show README")
|
||||
icon.name: "text-x-readme"
|
||||
onTriggered: awActions.showReadme()
|
||||
},
|
||||
PlasmaCore.Action {
|
||||
text: i18n("Check updates")
|
||||
icon.name: "system-software-update"
|
||||
onTriggered: awActions.checkUpdates(true)
|
||||
},
|
||||
PlasmaCore.Action {
|
||||
text: i18n("Report bug")
|
||||
icon.name: "tools-report-bug"
|
||||
onTriggered: {
|
||||
bugReport.reset()
|
||||
bugReport.open()
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
Component.onCompleted: {
|
||||
if (debug) console.debug()
|
||||
|
||||
// actions
|
||||
// it makes no sense to use this field with optimization enable
|
||||
if (!plasmoid.configuration.optimize)
|
||||
plasmoid.setAction("requestKey", i18n("Request key"), "utilities-system-monitor")
|
||||
plasmoid.setAction("showReadme", i18n("Show README"), "text-x-readme")
|
||||
plasmoid.setAction("checkUpdates", i18n("Check updates"), "system-software-update")
|
||||
plasmoid.setAction("reportBug", i18n("Report bug"), "tools-report-bug")
|
||||
// init submodule
|
||||
Plasmoid.userConfiguringChanged(false)
|
||||
// connect data
|
||||
@ -160,32 +172,26 @@ Item {
|
||||
if (plasmoid.configuration.checkUpdates) return awActions.checkUpdates(false)
|
||||
}
|
||||
|
||||
onNeedTextUpdate: {
|
||||
if (debug) console.debug()
|
||||
|
||||
onNeedTextUpdate: newText => {
|
||||
text.text = newText
|
||||
sizeUpdate()
|
||||
}
|
||||
|
||||
onNeedToolTipUpdate: {
|
||||
if (debug) console.debug()
|
||||
|
||||
onNeedToolTipUpdate: newText => {
|
||||
tooltip.text = newText
|
||||
}
|
||||
|
||||
onSizeUpdate: {
|
||||
if (debug) console.debug()
|
||||
// 16 is a magic number
|
||||
// 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.maximumHeight = -1
|
||||
} else {
|
||||
Layout.minimumHeight = plasmoid.configuration.height
|
||||
Layout.maximumHeight = plasmoid.configuration.height
|
||||
}
|
||||
if (plasmoid.configuration.width == 0) {
|
||||
if (plasmoid.configuration.width === 0) {
|
||||
Layout.minimumWidth = text.contentWidth - 16
|
||||
Layout.maximumWidth = -1
|
||||
} else {
|
||||
@ -196,7 +202,6 @@ Item {
|
||||
|
||||
Plasmoid.onUserConfiguringChanged: {
|
||||
if (plasmoid.userConfiguring) return
|
||||
if (debug) console.debug()
|
||||
|
||||
// init submodule
|
||||
awKeys.initDataAggregator(tooltipSettings)
|
||||
@ -211,7 +216,7 @@ Item {
|
||||
awKeys.setAggregatorProperty("tempUnits", plasmoid.configuration.tempUnits)
|
||||
awKeys.setAggregatorProperty("translate", plasmoid.configuration.translateStrings)
|
||||
// update telemetry ID
|
||||
if (plasmoid.configuration.telemetryId.length == 0)
|
||||
if (plasmoid.configuration.telemetryId.length === 0)
|
||||
plasmoid.configuration.telemetryId = generateUuid()
|
||||
// save telemetry
|
||||
awTelemetryHandler.init(plasmoid.configuration.telemetryCount,
|
||||
@ -221,37 +226,10 @@ Item {
|
||||
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
|
||||
function generateUuid() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
||||
let r = Math.random() * 16 | 0, v = c === "x" ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user