Эх сурвалжийг харах

Get appearance to the point I consider it usable

Change-Id: I07b02eb089a6f26d5ac44539c494524359a000ae
Donald Carr 9 жил өмнө
parent
commit
c3e5b65b25
8 өөрчлөгдсөн 211 нэмэгдсэн , 22 устгасан
  1. 15 0
      ArtDelegate.qml
  2. 52 0
      ImageBoxBody.qml
  3. 46 0
      RectangleBoxBody.qml
  4. 2 1
      main.cpp
  5. 86 21
      main.qml
  6. 6 0
      picturemodel.cpp
  7. 1 0
      picturemodel.h
  8. 3 0
      qml.qrc

+ 15 - 0
ArtDelegate.qml

@@ -0,0 +1,15 @@
+import QtQuick 2.5
+
+Rectangle {
+    color: "black"
+
+    Image {
+        id: artwork
+        property int padding: 0
+        width: parent.width - padding
+        height: parent.height - padding
+        fillMode: Image.PreserveAspectFit
+        anchors.centerIn: parent
+        source: "file://" + modelData
+    }
+}

+ 52 - 0
ImageBoxBody.qml

@@ -0,0 +1,52 @@
+import QtQuick 2.0
+import Box2D 2.0
+
+Image {
+    id: image
+
+    property alias body: boxBody
+    property alias fixture: box
+
+    // Body properties
+    property alias world: boxBody.world
+    property alias linearDamping: boxBody.linearDamping
+    property alias angularDamping: boxBody.angularDamping
+    property alias bodyType: boxBody.bodyType
+    property alias bullet: boxBody.bullet
+    property alias sleepingAllowed: boxBody.sleepingAllowed
+    property alias fixedRotation: boxBody.fixedRotation
+    property alias active: boxBody.active
+    property alias awake: boxBody.awake
+    property alias linearVelocity: boxBody.linearVelocity
+    property alias angularVelocity: boxBody.angularVelocity
+    property alias fixtures: boxBody.fixtures
+    property alias gravityScale: boxBody.gravityScale
+
+    // Box properties
+    property alias density: box.density
+    property alias friction: box.friction
+    property alias restitution: box.restitution
+    property alias sensor: box.sensor
+    property alias categories: box.categories
+    property alias collidesWith: box.collidesWith
+    property alias groupIndex: box.groupIndex
+
+    signal beginContact(Fixture other)
+    signal endContact(Fixture other)
+
+    Body {
+        id: boxBody
+
+        target: image
+
+        Box {
+            id: box
+
+            width: image.width
+            height: image.height
+
+            onBeginContact: image.beginContact(other)
+            onEndContact: image.endContact(other)
+        }
+    }
+}

+ 46 - 0
RectangleBoxBody.qml

@@ -0,0 +1,46 @@
+import QtQuick 2.0
+import Box2D 2.0
+
+Rectangle {
+    id: rectangle
+
+    property alias body: boxBody
+    property alias fixture: box
+
+    // Body properties
+    property alias world: boxBody.world
+    property alias linearDamping: boxBody.linearDamping
+    property alias angularDamping: boxBody.angularDamping
+    property alias bodyType: boxBody.bodyType
+    property alias bullet: boxBody.bullet
+    property alias sleepingAllowed: boxBody.sleepingAllowed
+    property alias fixedRotation: boxBody.fixedRotation
+    property alias active: boxBody.active
+    property alias awake: boxBody.awake
+    property alias linearVelocity: boxBody.linearVelocity
+    property alias angularVelocity: boxBody.angularVelocity
+    property alias fixtures: boxBody.fixtures
+    property alias gravityScale: boxBody.gravityScale
+
+    // Box properties
+    property alias density: box.density
+    property alias friction: box.friction
+    property alias restitution: box.restitution
+    property alias sensor: box.sensor
+    property alias categories: box.categories
+    property alias collidesWith: box.collidesWith
+    property alias groupIndex: box.groupIndex
+
+    Body {
+        id: boxBody
+
+        target: rectangle
+
+        Box {
+            id: box
+
+            width: rectangle.width
+            height: rectangle.height
+        }
+    }
+}

+ 2 - 1
main.cpp

@@ -9,12 +9,13 @@ class PictureThreadWrapper : public QObject {
 public:
     PictureThreadWrapper(QObject *parent = 0) : QObject (parent) {
         PictureModel::instance()->addSupportedExtension("jpg");
-        PictureModel::instance()->setModelRoot("/blackhole/media/art");
+        PictureModel::instance()->setModelRoot("/blackhole/media/art/Banksy");
     }
 };
 
 int main(int argc, char *argv[])
 {
+    qsrand(time(NULL));
     QGuiApplication app(argc, argv);
 
     QQmlApplicationEngine engine;

+ 86 - 21
main.qml

@@ -1,34 +1,99 @@
 import QtQuick 2.5
 import QtQuick.Window 2.2
+import Box2D 2.0
 
 Window {
     id: root
-    visible: true
+    visibility: Window.FullScreen
+
     width: 1024
     height: 768
 
-    ListView {
-        id: view
-        clip: true
-        snapMode: ListView.SnapToItem
-        orientation: ListView.Horizontal
-        anchors.fill: parent
-        delegate: Rectangle {
-            color: "black"
-            width: view.width
-            height: view.height
-            Image {
-                id: artwork
-                property int padding: 0
-                width: parent.width - padding
-                height: parent.height - padding
-                fillMode: Image.PreserveAspectFit
-                anchors.centerIn: parent
-                source: "file://" + modelData
+    property int columnCount: 4
+    property int interval: 5
+
+    Component {
+        id: pictureComponent
+        ImageBoxBody {
+            id: picture
+            function detonate() { destroyAnimation.start() }
+            fillMode: Image.PreserveAspectFit
+            height: implicitHeight/implicitWidth*width
+            width: parent.width
+            density: 0
+            fixedRotation: true
+            world: parent.physicsWorld
+            bodyType: Body.Dynamic
+            source: "file://" + imageModel.randomPicture()
+            restitution: 0.0
+            SequentialAnimation {
+                id: destroyAnimation
+                ScriptAction { script: { picture.destroy(); } }
+            }
+        }
+    }
+
+    Component {
+        id: columnComponent
+
+        Item {
+            id: column
+            x: width * index
+            width: parent.width/columnCount
+
+            anchors { top: parent.top; bottom: parent.bottom }
+
+            property var pictureArray: []
+            property var physicsWorld: World {
+                timeStep: 0.1
+            }
+
+            RectangleBoxBody {
+                world: physicsWorld
+                height: 1
+                anchors {
+                    left: parent.left
+                    right: parent.right
+                    top: parent.bottom
+                }
+                friction: 1
+                density: 1
+            }
+
+            Timer {
+                id: feedTimer
+                running: true
+                repeat: true
+                interval: 1000*(root.interval > 60 ? 60*(root.interval-60) : root.interval)
+                onTriggered: {
+                    pictureArray.push(pictureComponent.createObject(column, { y: -500 }))
+                    if (pictureArray.length > root.columnCount) {
+                        pictureArray.shift().detonate()
+                    }
+                }
+            }
+
+            Timer {
+                id: initialPopulation
+
+                property int runCount: 0
+                interval: 500
+                running: runCount < root.columnCount
+                repeat: true
+                onTriggered: {
+                    runCount = runCount + 1;
+                    feedTimer.triggered()
+                }
             }
         }
-        onWidthChanged: {
-            view.model = imageModel
+    }
+
+    Rectangle {
+        color: "black"
+        anchors.fill: parent
+        Repeater {
+            model: columnCount
+            delegate: columnComponent
         }
     }
 }

+ 6 - 0
picturemodel.cpp

@@ -43,6 +43,7 @@ bool PictureModel::setModelRoot(const QString &root)
 //    QDir::setCurrent(currentDir.path());
 
     nftw(root.toLatin1().data(), handleDirNode, 1000, FTW_PHYS);
+    qDebug() << "Finished flattening";
     return true;
 }
 
@@ -51,6 +52,11 @@ int PictureModel::rowCount(const QModelIndex &parent) const
     return paths.length();
 }
 
+QString PictureModel::randomPicture() const
+{
+    return paths.at(qrand()%paths.size());
+}
+
 QVariant PictureModel::data(const QModelIndex &index, int role) const
 {
     if (index.row() < 0 || index.row() >= paths.length())

+ 1 - 0
picturemodel.h

@@ -25,6 +25,7 @@ public:
     bool setModelRoot(const QString &root);
     int rowCount(const QModelIndex & parent = QModelIndex()) const;
 
+    Q_INVOKABLE QString randomPicture() const;
     QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
 
     bool addPath(const QString &path);

+ 3 - 0
qml.qrc

@@ -1,5 +1,8 @@
 <RCC>
     <qresource prefix="/">
         <file>main.qml</file>
+        <file>ArtDelegate.qml</file>
+        <file>ImageBoxBody.qml</file>
+        <file>RectangleBoxBody.qml</file>
     </qresource>
 </RCC>