ソースを参照

Allow specification of view type in settings

Change-Id: Id6e70f844018b13fc2c2a207187110c90ccd52db
Donald Carr 9 年 前
コミット
a819d80d6a

+ 7 - 16
qml/basic/Basic.qml

@@ -2,7 +2,7 @@ import QtQuick 2.5
 import Box2D 2.0
 import Qt.labs.settings 1.0
 
-import "../effects"
+import ".."
 
 Item {
     id: root
@@ -11,21 +11,12 @@ Item {
     signal next
 
     property var pictureDelegate: Component {
-        Image {
-            property var effect
-
-            fillMode: Image.PreserveAspectFit
-            source: imageModel.randomPicture()
-            width: parent.width
-            mirror: generalSettings.randomlyMirrorArt && (Math.random() < 0.5)
-            smooth: generalSettings.smoothArt
-
-            sourceSize.height: height
-            sourceSize.width: width
-        }
+        ArtImage {}
     }
 
-    property var effectDelegate: Qt.createComponent("../VisualEffect.qml")
+    property var effectDelegate: Component {
+        VisualEffect {}
+    }
 
     anchors.fill: parent
 
@@ -71,7 +62,7 @@ Item {
                     image.y = root.height - compoundArtworkHeight
 
                     pictureArray.push(image)
-                    itemCount++
+                    globalVars.itemCount++
                 }
 
                 function removeImage(image) {
@@ -79,7 +70,7 @@ Item {
                         image.effect.destroy()
                     }
                     image.destroy()
-                    itemCount--
+                    globalVars.itemCount--
                 }
 
                 function shift() {

+ 14 - 0
qml/common/ArtImage.qml

@@ -0,0 +1,14 @@
+import QtQuick 2.5
+
+Image {
+    property var effect
+
+    fillMode: Image.PreserveAspectFit
+    source: imageModel.randomPicture()
+    width: parent.width
+    mirror: generalSettings.randomlyMirrorArt && (Math.random() < 0.5)
+    smooth: generalSettings.smoothArt
+
+    sourceSize.height: height
+    sourceSize.width: width
+}

+ 1 - 1
qml/VisualEffect.qml → qml/common/VisualEffect.qml

@@ -1,5 +1,5 @@
 import QtQuick 2.5
-import "effects"
+import ".."
 
 Item {
     id: root

+ 0 - 1
qml/effects/qmldir

@@ -1 +0,0 @@
-singleton Effects 1.0 Effects.qml

+ 20 - 11
qml/main.qml

@@ -2,23 +2,24 @@ import QtQuick 2.5
 import QtQuick.Window 2.2
 import Qt.labs.settings 1.0
 
-import "basic"
-
 Window {
     id: appWindow
 
     width: 1024
     height: 768
 
-    property int itemCount
 
-    function reset() {
-        itemCount = 0
+    QtObject {
+        id: d
+        function reset() {
+            globalVars.itemCount = 0
+        }
     }
 
     QtObject {
         id: globalVars
         property int adjustedInterval: 1000*(generalSettings.interval > 60 ? 60*(generalSettings.interval-60) : generalSettings.interval)*(Math.random()+1)
+        property int itemCount
     }
 
     Settings {
@@ -27,20 +28,28 @@ Window {
         property int interval: 5
         property bool viewItemCount: false
         property string effect: ""
+        property string view: "Basic"
         property bool smoothArt: false
         property bool randomlyMirrorArt: true
-        onColumnCountChanged: reset()
+
+        onViewChanged: {
+            loader.source = generalSettings.view.toLowerCase() + "/" + generalSettings.view + ".qml"
+            d.reset()
+        }
+
+        onColumnCountChanged: d.reset()
     }
 
     Rectangle {
         focus: true
         color: "black"
         anchors.fill: parent
-        Keys.forwardTo: [punk, toplevelhandler]
+        Keys.forwardTo: [loader.item, toplevelhandler]
 
-        Basic {
-            // TODO: generalize all this
-            id: punk
+        Loader {
+            id: loader
+            anchors.fill: parent
+            source: "basic/Basic.qml"
         }
     }
 
@@ -85,7 +94,7 @@ Window {
         Text {
             id: itemCountLabel
             font.pixelSize: 100
-            text: itemCount
+            text: globalVars.itemCount
             color: "white"
         }
     }

+ 0 - 5
qml/physics/HorizontalArtDelegate.qml

@@ -1,5 +0,0 @@
-import QtQuick 2.5
-
-ArtDelegate {
-    width: parent.width
-}

+ 3 - 4
qml/physics/ImageBoxBody.qml

@@ -1,7 +1,9 @@
 import QtQuick 2.0
 import Box2D 2.0
 
-Image {
+import ".."
+
+ArtImage {
     id: image
 
     property alias body: boxBody
@@ -34,9 +36,6 @@ Image {
     signal beginContact(Fixture other)
     signal endContact(Fixture other)
 
-    sourceSize.height: height
-    sourceSize.width: width
-
     Body {
         id: boxBody
 

+ 10 - 5
qml/physics/Physics.qml

@@ -2,7 +2,7 @@ import QtQuick 2.5
 import Box2D 2.0
 import Qt.labs.settings 1.0
 
-import "../effects"
+import ".."
 
 Item {
     id: root
@@ -11,8 +11,13 @@ Item {
     signal toggleChaos
     signal next
 
-    property var pictureDelegate: Qt.createComponent("HorizontalArtDelegate.qml")
-    property var effectDelegate: Qt.createComponent("../VisualEffect.qml")
+    property var pictureDelegate: Component {
+        ArtDelegate {}
+    }
+
+    property var effectDelegate: Component {
+        VisualEffect {}
+    }
 
     anchors.fill: parent
 
@@ -86,7 +91,7 @@ Item {
                 image.y = floor.y - stackHeight
 
                 pictureArray.push(image)
-                itemCount++
+                globalVars.itemCount++
             }
 
             function removeImage(image) {
@@ -95,7 +100,7 @@ Item {
                 }
                 stackHeight -= (image.height + d.itemTravel)
                 image.destroy()
-                itemCount--
+                globalVars.itemCount--
             }
 
             function shiftImageToLimbo() {

+ 3 - 3
qml/qml.qrc

@@ -1,11 +1,11 @@
 <RCC>
     <qresource prefix="/">
         <file>main.qml</file>
-        <file>VisualEffect.qml</file>
+        <file>qmldir</file>
+        <file>common/VisualEffect.qml</file>
         <file>physics/ArtDelegate.qml</file>
         <file>physics/ImageBoxBody.qml</file>
         <file>physics/RectangleBoxBody.qml</file>
-        <file>physics/HorizontalArtDelegate.qml</file>
         <file>physics/Physics.qml</file>
         <file>basic/Basic.qml</file>
         <file>effects/Effect.qml</file>
@@ -13,6 +13,6 @@
         <file>effects/Emboss.qml</file>
         <file>effects/GaussianBlur.qml</file>
         <file>effects/Effects.qml</file>
-        <file>effects/qmldir</file>
+        <file>common/ArtImage.qml</file>
     </qresource>
 </RCC>

+ 3 - 0
qml/qmldir

@@ -0,0 +1,3 @@
+singleton Effects 1.0 effects/Effects.qml
+ArtImage 1.0 common/ArtImage.qml
+VisualEffect 1.0 common/VisualEffect.qml