[plasma-workspace/sebas/faces-clock] applets/faces-clock/package/contents: [faces clock] bare-bones switching mechanism

Sebastian Kügler null at kde.org
Mon Mar 13 23:27:52 UTC 2017


Git commit 204cf3256b13d67d34b0db122239caf2b7b22108 by Sebastian Kügler.
Committed on 13/03/2017 at 23:27.
Pushed by sebas into branch 'sebas/faces-clock'.

[faces clock] bare-bones switching mechanism

During the Plasma sprint, we talked about that we're still not quite
happy about code duplication in the clocks available for Plasma, and the
complexity of the digital clocks code, which makes it very hard to get
the rendering juuuuuuuust perfect, because it still isn't in many cases.

So, new approach we came up with:
- Clock faces are different representations (done in QML) with a shared
underlying mechanism. This resembles a little bit what we did with
libplasmaclock during 4.x times, where we shared complex code for
timezone handling, etc. in a shared library. This approach is different
in that the clock actually gets its own (non-binary) plugins in the form
of easy to write clock faces that are geared and perfected towards a
specific scenario.

The idea is to use a Loader and load a clock face dynamically during
run-time, instead of loading the "fixed" DigitalClock.qml directly.

- Move DigitalClock.qml under faces/ directory
- Create a really simple alternative face
- Allow switching from the config ui

Rough, first prototype, in particular:

- rendering of the previews is somewhat very broken
- the exposed api is pretty much main.qml
- zero polish

Further steps:
- flesh out API to present to clock faces, perhaps as a base QtQuick
  class to implement the clock faces, expose API in a less ad-hoc way than
  right now
- design mechanisms to avoid the complexity requird by the vast matrix
  of rendering / constraint scenarios, perhaps splitting up the faces
  further into Horizontal.qml or Vertical.qml

All needs a lot more fleshing out, here are some ideas where to take
this branch:

- Use packages for the clock faces, allow installing third party
  clocks, hello store.kde.org
- Not just digital clock faces, but also analog; Kai has a prototype to
  change just the theme of the clock, take ideas from that
- Perhaps start easy with just a bunch of different pre-defined faces,
  and allow 3rd party faces later on, this way we can get it into the
  hands of users a bit earlier on and learn about mistakes through
  feedback early on
- Plasma is still all about clocks.

I'll hack a bit further on this, but since notmart asked during our
meeting this morning, I thought why not share at this early point,
perhaps others find it interesting as well.

Personal Note: I worked on the very first digital clock in Plasma, way
before 4.0. The plan was to simplify a very artistic experimental train
clock done by Ruphy into a basic digital clock, which we ended shipping
with 4.0. I wanted to use a 2 hour train ride (ironically) from Cologne
to Nijmegen to get that work done. That was in 2007. It'll be ten years
this year that I make the mistake of starting to hack on our clocks'
code.

CCMAIL:plasma-devel at kde.org
CCMAIL:ruphy at kde.org
CCMAIL:mklapetek at kde.org

M  +5    -0    applets/faces-clock/package/contents/config/config.qml
M  +4    -0    applets/faces-clock/package/contents/config/main.xml
M  +29   -0    applets/faces-clock/package/contents/ui/configAppearance.qml
A  +31   -0    applets/faces-clock/package/contents/ui/faces/BasicClock.qml     [License: GPL (v2+)]
R  +0    -0    applets/faces-clock/package/contents/ui/faces/DigitalClock.qml [from: applets/faces-clock/package/contents/ui/DigitalClock.qml - 100% similarity]
M  +6    -1    applets/faces-clock/package/contents/ui/main.qml

https://commits.kde.org/plasma-workspace/204cf3256b13d67d34b0db122239caf2b7b22108

diff --git a/applets/faces-clock/package/contents/config/config.qml b/applets/faces-clock/package/contents/config/config.qml
index ce03b16d..11fc7684 100644
--- a/applets/faces-clock/package/contents/config/config.qml
+++ b/applets/faces-clock/package/contents/config/config.qml
@@ -28,6 +28,11 @@ ConfigModel {
     id: configModel
 
     ConfigCategory {
+         name: i18n("Face")
+         icon: "preferences-desktop-color"
+         source: "configFace.qml"
+    }
+    ConfigCategory {
          name: i18n("Appearance")
          icon: "preferences-desktop-color"
          source: "configAppearance.qml"
diff --git a/applets/faces-clock/package/contents/config/main.xml b/applets/faces-clock/package/contents/config/main.xml
index 4d19fb5f..8fe1675f 100644
--- a/applets/faces-clock/package/contents/config/main.xml
+++ b/applets/faces-clock/package/contents/config/main.xml
@@ -6,6 +6,10 @@
   <kcfgfile name=""/>
 
   <group name="Appearance">
+    <entry name="clockFace" type="string">
+      <label>Face (theme) of the clock, should be a file under contents/ui/faces.</label>
+      <default>faces/BasicClock.qml</default>
+    </entry>
     <entry name="showLocalTimezone" type="Bool">
       <label>Whether the timezone should be displayed when the clock is showing the local timezone.</label>
       <default>false</default>
diff --git a/applets/faces-clock/package/contents/ui/configAppearance.qml b/applets/faces-clock/package/contents/ui/configAppearance.qml
index 24ed74f6..8631fe39 100644
--- a/applets/faces-clock/package/contents/ui/configAppearance.qml
+++ b/applets/faces-clock/package/contents/ui/configAppearance.qml
@@ -32,6 +32,8 @@ Item {
 
     signal configurationChanged
 
+    property string cfg_clockFace: ""
+
     property string cfg_fontFamily
     property alias cfg_boldText: boldCheckBox.checked
     property string cfg_timeFormat: ""
@@ -86,6 +88,33 @@ Item {
                 QtControls.Label {
                     QtLayouts.Layout.fillWidth: true
                     horizontalAlignment: Text.AlignRight
+                    text: i18n("Clock face:")
+                }
+
+                QtControls.ComboBox {
+                    id: clockFaceComboBox
+                    QtLayouts.Layout.fillWidth: true
+                    // ComboBox's sizing is just utterly broken
+                    QtLayouts.Layout.minimumWidth: units.gridUnit * 10
+                    model: ["faces/BasicClock.qml", "faces/DigitalClock.qml"]
+                    onCurrentIndexChanged: {
+                        var current = model[currentIndex]
+                        print("Current face:" + current);
+                        if (current) {
+                            cfg_clockFace = current
+                            appearancePage.configurationChanged()
+                        }
+                    }
+                }
+
+                // spacer, cannot do Qt.AlignTop on the font style label + rowSpan 3, otherwise looks odd
+                Item {
+                    QtLayouts.Layout.fillWidth: true
+                    QtLayouts.Layout.rowSpan: 2
+                }
+                QtControls.Label {
+                    QtLayouts.Layout.fillWidth: true
+                    horizontalAlignment: Text.AlignRight
                     text: i18n("Font style:")
                 }
 
diff --git a/applets/faces-clock/package/contents/ui/faces/BasicClock.qml b/applets/faces-clock/package/contents/ui/faces/BasicClock.qml
new file mode 100644
index 00000000..0e38449c
--- /dev/null
+++ b/applets/faces-clock/package/contents/ui/faces/BasicClock.qml
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017 Sebastian Kügler <sebas at kde.org>
+ *
+ * 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.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+import QtQuick 2.6
+// import QtQuick.Layouts 1.1
+// import org.kde.plasma.core 2.0 as PlasmaCore
+import org.kde.plasma.components 2.0 as Components
+import org.kde.plasma.private.digitalclock 1.0
+
+Item {
+    Components.Label {
+        id: main
+        text: "13:37"
+        font.pixelSize: parent.height * 0.8
+        anchors.centerIn: parent
+    }
+}
diff --git a/applets/faces-clock/package/contents/ui/DigitalClock.qml b/applets/faces-clock/package/contents/ui/faces/DigitalClock.qml
similarity index 100%
rename from applets/faces-clock/package/contents/ui/DigitalClock.qml
rename to applets/faces-clock/package/contents/ui/faces/DigitalClock.qml
diff --git a/applets/faces-clock/package/contents/ui/main.qml b/applets/faces-clock/package/contents/ui/main.qml
index 66e8420f..34c07771 100644
--- a/applets/faces-clock/package/contents/ui/main.qml
+++ b/applets/faces-clock/package/contents/ui/main.qml
@@ -50,7 +50,12 @@ Item {
     }
 
     Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
-    Plasmoid.compactRepresentation: DigitalClock { }
+    Plasmoid.compactRepresentation: Loader {
+        source: plasmoid.configuration.clockFace
+        //source: "faces/BasicClock.qml"
+
+        //DigitalClock { }
+    }
     Plasmoid.fullRepresentation: CalendarView { }
 
     Plasmoid.toolTipItem: Loader {


More information about the Plasma-devel mailing list