瀏覽代碼

Show artwork on every attached screen by default

Donald Carr 7 年之前
父節點
當前提交
f69d673c87
共有 3 個文件被更改,包括 46 次插入26 次删除
  1. 0 4
      qml/main.qml
  2. 1 1
      qml/views/reel/Reel.qml
  3. 45 21
      src/main.cpp

+ 0 - 4
qml/main.qml

@@ -9,10 +9,6 @@ Item {
         globalUtil.reset()
     }
 
-    PictureModel {
-        id: imageModel
-    }
-
     QtObject {
         id: globalVars
         property real goldenRatio

+ 1 - 1
qml/views/reel/Reel.qml

@@ -89,7 +89,7 @@ View {
                             image.destroy()
                             globalUtil.itemCount--
                         } else {
-                            nextColumn.addImage(image)
+                            !!nextColumn && nextColumn.addImage(image)
                         }
                     } else if ((!nextColumn || !nextColumn.receptive(image))
                                && prospectiveY >= restingY

+ 45 - 21
src/main.cpp

@@ -40,11 +40,11 @@
 #include <QFileSystemWatcher>
 #include <QtPlugin>
 
-class NativeUtil : public QObject {
+class NativeUtils : public QObject {
     Q_OBJECT
     Q_PROPERTY(bool rebootRequired MEMBER rebootRequired NOTIFY rebootRequiredChanged)
 public:
-    NativeUtil();
+    NativeUtils(QObject *p);
 
 signals:
     void rebootRequiredChanged();
@@ -56,17 +56,17 @@ private:
     bool rebootRequired;
 };
 
-NativeUtil::NativeUtil()
-    : QObject(),
+NativeUtils::NativeUtils(QObject *p)
+    : QObject(p),
       watchFile("/run/reboot-required"),
       rebootRequired(false)
 {
     runDirWatcher.addPath(QFileInfo(watchFile).absolutePath());
-    connect(&runDirWatcher, &QFileSystemWatcher::directoryChanged, this, &NativeUtil::monitorRunPath);
+    connect(&runDirWatcher, &QFileSystemWatcher::directoryChanged, this, &NativeUtils::monitorRunPath);
     monitorRunPath("");
 }
 
-void NativeUtil::monitorRunPath(const QString &path)
+void NativeUtils::monitorRunPath(const QString &path)
 {
     Q_UNUSED(path);
 
@@ -74,6 +74,39 @@ void NativeUtil::monitorRunPath(const QString &path)
     emit rebootRequiredChanged();
 }
 
+namespace ArtView {
+    static QQuickView* artView();
+    static QQmlEngine* sharedQmlEngine = nullptr;
+}
+
+QQuickView* ArtView::artView()
+{
+    static QString qmlPath;
+#ifdef COMPILED_RESOURCES
+    qmlPath = "qrc:/qml";
+#else
+    qmlPath = QCoreApplication::applicationDirPath() % "/qml";
+    if (!QDir(qmlPath).exists()) {
+        qmlPath = "/usr/share/" % qApp->applicationName() % "/qml";
+    }
+#endif
+
+    QQuickView *view;
+    if (sharedQmlEngine) {
+        view = new QQuickView(sharedQmlEngine, nullptr);
+    } else {
+        view = new QQuickView();
+        sharedQmlEngine = view->engine();
+        sharedQmlEngine->addImportPath(qmlPath);
+        sharedQmlEngine->rootContext()->setContextProperty("nativeUtils", new NativeUtils(sharedQmlEngine));
+        sharedQmlEngine->rootContext()->setContextProperty("imageModel", new PictureModel(sharedQmlEngine));
+
+    }
+    view->setResizeMode(QQuickView::SizeRootObjectToView);
+    view->setSource(QUrl(qmlPath + "/main.qml"));
+    return view;
+}
+
 int main(int argc, char *argv[])
 {
 #ifdef STATIC_BUILD
@@ -127,24 +160,15 @@ int main(int argc, char *argv[])
         });
     }
 
-    NativeUtil nativeUtils;
-    QQuickView view;
     qmlRegisterType<PictureModel>("PictureModel", 1, 0, "PictureModel");
 
-    QString qmlPath;
-#ifdef COMPILED_RESOURCES
-    qmlPath = "qrc:/qml";
-#else
-    qmlPath = QCoreApplication::applicationDirPath() % "/qml";
-    if (!QDir(qmlPath).exists()) {
-        qmlPath = "/usr/share/" % app.applicationName() % "/qml";
+    foreach(QScreen *screen, QGuiApplication::screens()) {
+            qDebug() << "Displaying artwork on" << screen;
+            QQuickView *view = ArtView::artView();
+            view->setScreen(screen);
+            view->setGeometry(screen->availableGeometry());
+            view->showFullScreen();
     }
-#endif
-
-    view.engine()->addImportPath(qmlPath);
-    view.rootContext()->setContextProperty("nativeUtils", &nativeUtils);
-    view.setSource(QUrl(qmlPath + "/main.qml"));
-    view.show();
 
     QGuiApplication::processEvents();
 #ifdef USING_SYSTEMD