Explorar o código

Introduce the Qt Project provided logo as default image

Guard % access on zero sized model

Change-Id: Iae861972cb757d5ead685efed54b18ffa618683e
Donald Carr %!s(int64=9) %!d(string=hai) anos
pai
achega
258b6b45a8
Modificáronse 7 ficheiros con 21 adicións e 4 borrados
  1. 1 1
      ArtDelegate.qml
  2. 1 1
      Gravity.qml
  3. 1 1
      main.cpp
  4. 13 0
      main.qml
  5. 4 1
      picturemodel.cpp
  6. 1 0
      qml.qrc
  7. BIN=BIN
      qt_logo_green_rgb.png

+ 1 - 1
ArtDelegate.qml

@@ -15,5 +15,5 @@ ImageBoxBody {
     world: parent.physicsWorld
     bodyType: Body.Dynamic
 
-    source: "file://" + imageModel.randomPicture()
+    source: imageModel.randomPicture()
 }

+ 1 - 1
Gravity.qml

@@ -42,7 +42,7 @@ Item {
                 if (columnHeight < (1.1+1/settings.columnCount)*root.height) {
                     var item = pictureDelegate.createObject(column)
                     columnHeight += item.height
-                    item.y = (floor.y - 1) - columnHeight
+                    item.y = floor.y - columnHeight
                     d.itemCount++
                     pictureArray.push(item)
                 }

+ 1 - 1
main.cpp

@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
     model->addSupportedExtension("png");
     model->moveToThread(&scanningThread);
     scanningThread.start();
-    //QTimer::singleShot(0, model, [model,artPath]() { model->setModelRoot(artPath); });
+
     QMetaObject::invokeMethod(model, "setModelRoot", Qt::QueuedConnection, Q_ARG(QString,artPath));
     settings.setValue("artPath", artPath);
 

+ 13 - 0
main.qml

@@ -37,5 +37,18 @@ Window {
         Keys.onRightPressed: settings.columnCount++
     }
 
+    Rectangle {
+        visible: imageModel.rowCount() == 0
+        color: "red"
+        width: childrenRect.width
+        height: childrenRect.height
+
+        anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter }
+        Text {
+            font.pointSize: 40
+            text: "No images found/provided"
+        }
+    }
+
     Component.onCompleted: showFullScreen()
 }

+ 4 - 1
picturemodel.cpp

@@ -66,7 +66,10 @@ int PictureModel::rowCount(const QModelIndex &parent) const
 
 QString PictureModel::randomPicture() const
 {
-    return qualifyNode(files.at(qrand()%files.size()));
+    if (files.size() <= 0)
+        return QString("qrc:///qt_logo_green_rgb.png");
+
+    return QString("file://").append(qualifyNode(files.at(qrand()%files.size())));
 }
 
 QVariant PictureModel::data(const QModelIndex &index, int role) const

+ 1 - 0
qml.qrc

@@ -8,5 +8,6 @@
         <file>HorizontalArtDelegate.qml</file>
         <file>Gravity.qml</file>
         <file>Ticker.qml</file>
+        <file>qt_logo_green_rgb.png</file>
     </qresource>
 </RCC>

BIN=BIN
qt_logo_green_rgb.png