Selaa lähdekoodia

Move all widgets out into their own QML files

Donald Carr 8 vuotta sitten
vanhempi
commit
2914273cbc

+ 1 - 1
qml/common/ArtImage.qml

@@ -50,7 +50,7 @@ Item {
         modelIndex = Math.floor(Math.random()*imageModel.count)
         if (globalSettings.effect !== "" && Effects.validate(globalSettings.effect)) {
             var component = Qt.createComponent("VisualEffect.qml");
-            component.status !== Component.Ready && console.log('Component failed with:' + effectDelegate.errorString())
+            component.status !== Component.Ready && console.log('Component failed with:' + component.errorString())
             root.effect = component.createObject(root, { target: image, effect: globalSettings.effect })
         }
     }

+ 12 - 123
qml/main.qml

@@ -77,9 +77,6 @@ Window {
     QtObject {
         id: d
         property int primedColumns: 0
-        property string timeString
-        property string day
-        property string month
         property string currentViewFilename
         property string overrideViewFilename
         property bool displayUnlicensed: false
@@ -92,18 +89,6 @@ Window {
             return view.toLowerCase() + "/" + view + ".qml"
         }
 
-        function timeChanged() {
-            var date = new Date;
-            timeString = Qt.formatDateTime(date, "hh:mm")
-            day = Qt.formatDateTime(date, "dd")
-            month = Qt.formatDateTime(date, "MM")
-        }
-
-        property variant timeTimer: Timer {
-            interval: 1000; running: true; repeat: true;
-            onTriggered: d.timeChanged()
-        }
-
         onCurrentViewFilenameChanged: {
             globalUtil.reset()
         }
@@ -113,30 +98,22 @@ Window {
         id: globalSettings
         property int columnCount: 6
         property int interval: 5
-        property bool showViewItemCount: false
-        property bool showScreenResolution: false
+
         property string effect: ""
         property string view: "Reel"
         property string backdrop: ""
+
         property bool smoothArt: false
         property bool randomlyMirrorArt: true
         property bool fullscreen: true
-
-        property bool clockWidget: false
-        property real clockIntensity: 0.6
-
         property bool commonFeed: true
         property bool commonFeedRoundRobin: true
-
         property bool unlicensed: false
-
-        property real artOpacity: 1.0
         property bool fadeInImages: true
-
-        property bool animatedBackground: false
-
         property bool useGoldenRatio: false
-        //property real lessGoldenRatio: 1.25
+        property bool widgetTray: false
+
+        property real artOpacity: 1.0
         property real lessGoldenRatio: 1.35
 
         onColumnCountChanged: globalUtil.reset()
@@ -149,8 +126,8 @@ Window {
 
     Item {
         id: root
-        focus: true
 
+        focus: true
         anchors.fill: parent
         Keys.forwardTo: [artViewLoader.item, toplevelhandler]
 
@@ -160,63 +137,17 @@ Window {
             anchors.fill: parent
         }
 
-        Rectangle {
-            id: clock
-            width: childrenRect.width
-            opacity: 0.7
-            color: "black"
-            visible: height > 0
-            height: globalSettings.clockWidget ? appWindow.height/15 : 0
-            anchors { top: parent.top; horizontalCenter: parent.horizontalCenter }
-            Text {
-                //anchors.centerIn: parent
-                id: clockLabel
-                color: "white"
-                font.bold: true
-                font.pixelSize: parent.height
-                text: d.timeString
-            }
-            Item {
-                anchors { left: clockLabel.right; leftMargin: 20 }
-                height: clock.height
-                width: childrenRect.width
-                Item {
-                    width: childrenRect.width
-                    height: parent.height/2
-                    Text {
-                        anchors.centerIn: parent
-                        color: "white"
-                        font.bold: true
-                        verticalAlignment: Text.AlignVCenter
-                        horizontalAlignment: Text.AlignHCenter
-                        font.pixelSize: clock.height/3
-                        text: d.day
-                    }
-                }
-                Item {
-                    y: parent.height/2
-                    width: childrenRect.width
-                    height: parent.height/2
-                    Text {
-                        anchors.centerIn: parent
-                        color: "white"
-                        font.bold: true
-                        verticalAlignment: Text.AlignVCenter
-                        horizontalAlignment: Text.AlignHCenter
-                        font.pixelSize: clock.height/3
-                        text: d.month
-                    }
-                }
-
-            }
-        }
         Component.onCompleted: {
             if (globalSettings.backdrop != "") {
-                Qt.createQmlObject(globalSettings.backdrop + ' { anchors.fill: parent}', root)
+                Qt.createQmlObject(globalSettings.backdrop + ' { anchors.fill: parent }', root)
+            }
+
+            if (globalSettings.widgetTray) {
+                Qt.createQmlObject('WidgetTray { z: 2; anchors { top: parent.top; right: parent.right } }', root)
             }
 
             if (globalSettings.unlicensed) {
-                Qt.createQmlObject('Unlicensed { z: 2 }', root)
+                Qt.createQmlObject('Unlicensed { z: 3 }', root)
             }
         }
     }
@@ -247,48 +178,10 @@ Window {
         }
     }
 
-    Rectangle {
-        z: 1
-        opacity: 0.5
-        visible: globalSettings.showViewItemCount
-        color: "black"
-
-        anchors { right: parent.right; top: parent.top }
-        width: itemCountLabel.width
-        height: itemCountLabel.height
-
-        Text {
-            id: itemCountLabel
-            font.pixelSize: 100
-            text: globalUtil.itemCount
-            color: "white"
-        }
-    }
-
-    Rectangle {
-        z: 1
-        opacity: 0.5
-        visible: globalSettings.showScreenResolution
-        color: "black"
-
-        anchors { right: parent.right; top: parent.top }
-        width: resolutionLabel.width
-        height: resolutionLabel.height
-
-        Text {
-            id: resolutionLabel
-            font.pixelSize: 100
-            text: screenSize.width + "x" + screenSize.height
-            color: "white"
-        }
-    }
-
     Component.onCompleted: {
         showTimer.start()
     }
 
-
-
     Timer {
         id: showTimer
 
@@ -299,8 +192,4 @@ Window {
             showAtCorrectSize()
         }
     }
-
-    FPSMonitor {
-        anchors { top: parent.top; right: parent.right }
-    }
 }

+ 6 - 1
qml/qml.qrc

@@ -2,7 +2,12 @@
     <qresource prefix="/">
         <file>main.qml</file>
         <file>qmldir</file>
-        <file>widget/FPSMonitor.qml</file>
+        <file>widgets/Widget.qml</file>
+        <file>widgets/FPS.qml</file>
+        <file>widgets/Clock.qml</file>
+        <file>widgets/ItemCount.qml</file>
+        <file>widgets/Resolution.qml</file>
+        <file>widgets/WidgetTray.qml</file>
         <file>common/VisualEffect.qml</file>
         <file>physics/BoxBody.qml</file>
         <file>physics/ImageBoxBody.qml</file>

+ 5 - 1
qml/qmldir

@@ -6,6 +6,10 @@ ImageBoxBody 1.0 physics/ImageBoxBody.qml
 ArtBoxBody 1.0 physics/ArtBoxBody.qml
 RectangleBoxBody 1.0 physics/RectangleBoxBody.qml
 BoxBody 1.0 physics/BoxBody.qml
-FPSMonitor 1.0 widget/FPSMonitor.qml
+FPS 1.0 widgets/FPS.qml
+Clock 1.0 widgets/Clock.qml
+Resolution 1.0 widgets/Resolution.qml
+ItemCount 1.0 widgets/ItemCount.qml
+WidgetTray 1.0 widgets/WidgetTray.qml
 BackgroundSwirls 1.0 3rdparty/backdrops/qml-presentation-visuals/BackgroundSwirls.qml
 Unlicensed 1.0 unlicensed/Unlicensed.qml

+ 69 - 0
qml/widgets/Clock.qml

@@ -0,0 +1,69 @@
+import QtQuick 2.6
+
+Widget {
+    id: root
+
+    width: childrenRect.width
+    height: clockLabel.height
+
+    QtObject {
+        id: d
+        property string timeString
+        property int day
+        property int month
+
+        function timeChanged() {
+            var date = new Date;
+            timeString = Qt.formatDateTime(date, "hh:mm")
+            day = Qt.formatDateTime(date, "dd")
+            month = Qt.formatDateTime(date, "MM")
+        }
+    }
+
+    Timer {
+        interval: 10*1000; running: true; repeat: true;
+        onTriggered: d.timeChanged()
+    }
+
+    Text {
+        //anchors.centerIn: parent
+        id: clockLabel
+        color: "white"
+        font.bold: true
+        font.pixelSize: 100
+        text: d.timeString
+    }
+    Item {
+        anchors { left: clockLabel.right; leftMargin: 20 }
+        height: root.height
+        width: childrenRect.width
+        Item {
+            width: childrenRect.width
+            height: parent.height/2
+            Text {
+                anchors.centerIn: parent
+                color: "white"
+                font.bold: true
+                verticalAlignment: Text.AlignVCenter
+                horizontalAlignment: Text.AlignHCenter
+                font.pixelSize: root.height/3
+                text: d.day
+            }
+        }
+        Item {
+            y: parent.height/2
+            width: childrenRect.width
+            height: parent.height/2
+            Text {
+                anchors.centerIn: parent
+                color: "white"
+                font.bold: true
+                verticalAlignment: Text.AlignVCenter
+                horizontalAlignment: Text.AlignHCenter
+                font.pixelSize: root.height/3
+                text: d.month
+            }
+        }
+
+    }
+}

+ 2 - 4
qml/widget/FPSMonitor.qml → qml/widgets/FPS.qml

@@ -3,9 +3,7 @@ import QtQuick 2.0
 // pretty much entirely stolen from:
 // https://github.com/capisce/motionblur/blob/master/main.qml
 
-Rectangle {
-    color: "black"
-
+Widget {
     property real t
     property int frame: 0
 
@@ -15,7 +13,7 @@ Rectangle {
     Text {
         id: fpsText
 
-        font.pixelSize: 100
+        font.pixelSize: widgetProperties.fontPixelSize
         color: "white"
         text: "FPS:" + fpsTimer.fps
     }

+ 13 - 0
qml/widgets/ItemCount.qml

@@ -0,0 +1,13 @@
+import QtQuick 2.6
+
+Widget {
+    width: itemCountLabel.width
+    height: itemCountLabel.height
+
+    Text {
+        id: itemCountLabel
+        font.pixelSize: widgetProperties.fontPixelSize
+        text: "Items:" + globalUtil.itemCount
+        color: "white"
+    }
+}

+ 13 - 0
qml/widgets/Resolution.qml

@@ -0,0 +1,13 @@
+import QtQuick 2.6
+
+Widget {
+    width: resolutionLabel.width
+    height: resolutionLabel.height
+
+    Text {
+        id: resolutionLabel
+        font.pixelSize: 100
+        text: screenSize.width + "x" + screenSize.height
+        color: "white"
+    }
+}

+ 7 - 0
qml/widgets/Widget.qml

@@ -0,0 +1,7 @@
+import QtQuick 2.6
+
+Item {
+    property variant widgetProperties: QtObject {
+        property int fontPixelSize: 40
+    }
+}

+ 20 - 0
qml/widgets/WidgetTray.qml

@@ -0,0 +1,20 @@
+import QtQuick 2.6
+
+Item {
+    width: childrenRect.width
+    height: childrenRect.height
+
+    Rectangle {
+        anchors.fill: parent
+        opacity: 0.5
+        color: "black"
+    }
+
+    Row {
+        spacing: 10.0
+        ItemCount {
+        }
+        FPS {
+        }
+    }
+}