Merge pull request #16 from Diyou/main

Added compatibility for plasma 6
This commit is contained in:
qewer 2024-04-17 00:48:22 +03:00 committed by GitHub
commit d38b8dab62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 46 additions and 56 deletions

View file

@ -6,13 +6,15 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.12 as QtControls import QtQuick.Controls 2.12 as QtControls
import QtQuick.Layouts 1.12 as QtLayouts import QtQuick.Layouts 1.12 as QtLayouts
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs
import org.kde.kirigami 2.3 as Kirigami import org.kde.kirigami 2.3 as Kirigami
import org.kde.kcmutils as KCM
import "../lib" import "../lib"
Item { KCM.SimpleKCM {
id: appearancePage id: appearancePage
width: childrenRect.width width: childrenRect.width
height: childrenRect.height height: childrenRect.height
@ -58,31 +60,6 @@ Item {
property int cfg_dateShadowXOffset property int cfg_dateShadowXOffset
property int cfg_dateShadowYOffset property int cfg_dateShadowYOffset
function fixFontFamilyChange(id, comboBox) {
// HACK by the time we populate our model and/or the ComboBox is finished the value is still undefined
if (id) {
for (var i = 0, j = fontsModel.count; i < j; ++i) {
if (fontsModel.get(i).value === id) {
comboBox.currentIndex = i
break
}
}
}
}
onCfg_clockFontFamilyChanged: {
fixFontFamilyChange(cfg_clockFontFamily, clockFontFamilyComboBox)
}
onCfg_dayFontFamilyChanged: {
fixFontFamilyChange(cfg_dayFontFamily, dayFontFamilyComboBox)
}
onCfg_dateFontFamilyChanged: {
fixFontFamilyChange(cfg_dateFontFamily, dateFontFamilyComboBox)
}
ListModel { ListModel {
id: fontsModel id: fontsModel
Component.onCompleted: { Component.onCompleted: {
@ -155,7 +132,7 @@ Item {
cfg_clockFontColor = colorValue cfg_clockFontColor = colorValue
} }
fontValue: cgf_clockFontFamily fontValue: cfg_clockFontFamily
onFontValueChanged: { onFontValueChanged: {
cfg_clockFontFamily = fontValue cfg_clockFontFamily = fontValue
} }
@ -232,7 +209,7 @@ Item {
cfg_dayFontColor = colorValue cfg_dayFontColor = colorValue
} }
fontValue: cgf_dayFontFamily fontValue: cfg_dayFontFamily
onFontValueChanged: { onFontValueChanged: {
cfg_dayFontFamily = fontValue cfg_dayFontFamily = fontValue
} }
@ -331,7 +308,7 @@ Item {
cfg_dateFontColor = colorValue cfg_dateFontColor = colorValue
} }
fontValue: cgf_dateFontFamily fontValue: cfg_dateFontFamily
onFontValueChanged: { onFontValueChanged: {
cfg_dateFontFamily = fontValue cfg_dateFontFamily = fontValue
} }

View file

@ -6,7 +6,7 @@ import QtQuick.Layouts 1.12 as QtLayouts
SPDX-License-Identifier: GPL-3.0-or-later SPDX-License-Identifier: GPL-3.0-or-later
*/ */
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs
QtControls.Button { QtControls.Button {
id: clockFontColorButton id: clockFontColorButton
@ -33,10 +33,12 @@ QtControls.Button {
ColorDialog { ColorDialog {
id: dialog id: dialog
title: "Select Background Color" title: "Select Background Color"
color: value selectedColor: value
showAlphaChannel: true options: {
ShowAlphaChannel: true
}
onAccepted: { onAccepted: {
value = dialog.color value = selectedColor
} }
} }
} }

View file

@ -6,7 +6,9 @@
import QtQuick 2.4 import QtQuick 2.4
import QtQuick.Controls 2.12 as QtControls import QtQuick.Controls 2.12 as QtControls
import QtQuick.Layouts 1.12 as QtLayouts import QtQuick.Layouts 1.12 as QtLayouts
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs
import org.kde.kirigami 2.3 as Kirigami
import "." import "."
@ -39,10 +41,19 @@ QtLayouts.RowLayout {
QtControls.ComboBox { QtControls.ComboBox {
id: fontFamilyComboBox id: fontFamilyComboBox
QtLayouts.Layout.fillWidth: true QtLayouts.Layout.fillWidth: true
QtLayouts.Layout.minimumWidth: units.gridUnit * 10 QtLayouts.Layout.minimumWidth: Kirigami.Units.gridUnit * 10
model: fontModel model: fontModel
textRole: "text" textRole: "text"
currentIndex: fontValue currentIndex: getIdFromModel()
function getIdFromModel(){
for(var i = 0; i < model.count; i++){
if(model.get(i).value === fontValue){
return i;
}
}
return 0;
}
onCurrentIndexChanged: { onCurrentIndexChanged: {
var current = model.get(currentIndex) var current = model.get(currentIndex)
@ -59,7 +70,7 @@ QtLayouts.RowLayout {
checkable: true checkable: true
checked: boldValue checked: boldValue
onStateChanged: { onToggled: {
boldValue = checked boldValue = checked
} }
} }
@ -70,8 +81,8 @@ QtLayouts.RowLayout {
checkable: true checkable: true
checked: italicValue checked: italicValue
onStateChanged: { onToggled: {
italicvalue = checked italicValue = checked
} }
} }

View file

@ -6,7 +6,7 @@
import QtQuick 2.4 import QtQuick 2.4
import QtQuick.Controls 2.12 as QtControls import QtQuick.Controls 2.12 as QtControls
import QtQuick.Layouts 1.12 as QtLayouts import QtQuick.Layouts 1.12 as QtLayouts
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs
import "." import "."

View file

@ -5,27 +5,28 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.12 import Qt5Compat.GraphicalEffects
import org.kde.plasma.plasma5support as Plasma5Support
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.components 3.0 as PlasmaComponents import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.extras 2.0 as PlasmaExtras
Item { PlasmoidItem {
id: root id: root
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation preferredRepresentation: fullRepresentation
Plasmoid.backgroundHints: PlasmaCore.Types.ConfigurableBackground Plasmoid.backgroundHints: PlasmaCore.Types.ConfigurableBackground
readonly property date currentDateTime: dataSource.data.Local ? dataSource.data.Local.DateTime : new Date() readonly property date currentDateTime: dataSource.data.Local ? dataSource.data.Local.DateTime : new Date()
PlasmaCore.DataSource { Plasma5Support.DataSource {
id: dataSource id: dataSource
engine: "time" engine: "time"
connectedSources: ["Local"] connectedSources: ["Local"]
interval: plasmoid.configuration.clockShowSeconds ? 1000 : 60000 interval: plasmoid.configuration.clockShowSeconds ? 1000 : 60000
intervalAlignment: plasmoid.configuration.clockShowSeconds ? PlasmaCore.Types.NoAlignment : PlasmaCore.Types.AlignToMinute intervalAlignment: plasmoid.configuration.clockShowSeconds ? Plasma5Support.Types.NoAlignment : Plasma5Support.Types.AlignToMinute
} }
FontLoader { FontLoader {
@ -43,7 +44,7 @@ Item {
source: "../fonts/Smooch-Regular.ttf" source: "../fonts/Smooch-Regular.ttf"
} }
Plasmoid.fullRepresentation: ColumnLayout { fullRepresentation: ColumnLayout {
anchors.fill: parent anchors.fill: parent
spacing: -20 spacing: -20
@ -65,15 +66,15 @@ Item {
} }
Item { Item {
width: Math.max(textMetricsClockLabel.width, textMetricsDayLabel.width) implicitWidth: Math.max(textMetricsClockLabel.width, textMetricsDayLabel.width)
height: Math.max(textMetricsClockLabel.height, textMetricsDayLabel.height) implicitHeight: Math.max(textMetricsClockLabel.height, textMetricsDayLabel.height)
Layout.alignment: Qt.AlignCenter Layout.alignment: Qt.AlignHCenter
Text { Text {
id: clockLabel id: clockLabel
anchors.centerIn: parent anchors.centerIn: parent
property var textFormat: { property var getTextFormat: {
var AMPM = plasmoid.configuration.clockUse24hFormat ? "" : " AP" var AMPM = plasmoid.configuration.clockUse24hFormat ? "" : " AP"
if (plasmoid.configuration.clockShowSeconds) if (plasmoid.configuration.clockShowSeconds)
return Qt.formatTime(currentDateTime, "hh.mm.ss" + AMPM).split(".").join(plasmoid.configuration.clockSeparator) return Qt.formatTime(currentDateTime, "hh.mm.ss" + AMPM).split(".").join(plasmoid.configuration.clockSeparator)
@ -81,7 +82,7 @@ Item {
return Qt.formatTime(currentDateTime, "hh.mm" + AMPM).split(".").join(plasmoid.configuration.clockSeparator) return Qt.formatTime(currentDateTime, "hh.mm" + AMPM).split(".").join(plasmoid.configuration.clockSeparator)
} }
text: textFormat text: getTextFormat
color: plasmoid.configuration.clockFontColor color: plasmoid.configuration.clockFontColor
font.family: if (plasmoid.configuration.clockFontFamily === "ccdefault") fontOutfitBold.name font.family: if (plasmoid.configuration.clockFontFamily === "ccdefault") fontOutfitBold.name
@ -110,7 +111,7 @@ Item {
color: plasmoid.configuration.dayFontColor color: plasmoid.configuration.dayFontColor
font.family: if (plasmoid.configuration.dayFontFamily === "ccdefault") fontSmooch.name font.family: if (plasmoid.configuration.dayFontFamily === "ccdefault") fontSmooch.name
else plasmoid.configuration.dayFontFamily else plasmoid.configuration.dayFontFamily
font.bold: plasmoid.configuration.daykBoldText font.bold: plasmoid.configuration.dayBoldText
font.italic: plasmoid.configuration.dayItalicText font.italic: plasmoid.configuration.dayItalicText
font.pixelSize: plasmoid.configuration.dayFontSize font.pixelSize: plasmoid.configuration.dayFontSize
@ -128,7 +129,7 @@ Item {
Text { Text {
id: dateLabel id: dateLabel
visible: plasmoid.configuration.showDateDisplay visible: plasmoid.configuration.showDateDisplay
Layout.alignment: Qt.AlignCenter Layout.alignment: Qt.AlignHCenter
text: Qt.formatDate(currentDateTime, plasmoid.configuration.dateCustomDateFormat) text: Qt.formatDate(currentDateTime, plasmoid.configuration.dateCustomDateFormat)

View file

@ -18,6 +18,5 @@
"Version": "0.3", "Version": "0.3",
"Website": "https://github.com/qewer33/ClearClock" "Website": "https://github.com/qewer33/ClearClock"
}, },
"X-Plasma-API": "declarativeappletscript", "X-Plasma-API-Minimum-Version": "6.0"
"X-Plasma-MainScript": "ui/main.qml"
} }