From 9e494749606c108bbd21806dfbff5e09eeb81ac8 Mon Sep 17 00:00:00 2001 From: kelteseth Date: Wed, 5 Apr 2017 13:04:13 +0200 Subject: [PATCH] Cleanup and sidebar integration --- main.cpp | 12 ++--- qml/Components/Sidebar.qml | 94 ++++++++++++++++++++++++++------------ src/installedlistmodel.cpp | 26 ++++++++--- src/installedlistmodel.h | 2 +- 4 files changed, 91 insertions(+), 43 deletions(-) diff --git a/main.cpp b/main.cpp index 7f4dbaaa..c92874c9 100644 --- a/main.cpp +++ b/main.cpp @@ -2,18 +2,18 @@ #include #include #include +#include #include +#include #include #include #include +#include #include #include -#include -#include -#include -#include "screenplay.h" #include "installedlistmodel.h" +#include "screenplay.h" int main(int argc, char* argv[]) { @@ -25,18 +25,16 @@ int main(int argc, char* argv[]) QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); InstalledListModel ilm; - ilm.setData(QModelIndex(),QVariant("ascb"),0); QQmlApplicationEngine mainWindow; mainWindow.rootContext()->setContextProperty("installedListModel", &ilm); mainWindow.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); - //ScreenPlay sp(GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN)); int status = app.exec(); //Shutdown - return status; + return status; } diff --git a/qml/Components/Sidebar.qml b/qml/Components/Sidebar.qml index f0d3e2a2..11c89465 100644 --- a/qml/Components/Sidebar.qml +++ b/qml/Components/Sidebar.qml @@ -3,38 +3,45 @@ import QtGraphicalEffects 1.0 import QtQuick.Controls 2.2 Item { - id:sidebar + id: sidebar height: 768 - width:400 + width: 400 state: "inactive" focus: true - property string activeScreen: "" - - onActiveScreenChanged:{ - print(activeScreen) - + MouseArea { + id: mouseAreaHelper + anchors.fill: parent + enabled: true } + property string activeScreen: "" + + onActiveScreenChanged: { + text1.text = installedListModel.get(activeScreen).screenTitle + image.source = Qt.resolvedUrl( + "file:///" + installedListModel._screensPath + activeScreen + + "/" + installedListModel.get(activeScreen).screenPreview) + } Item { id: sidebarWrapper anchors { - top:sidebar.top - right:sidebar.right - bottom:sidebar.bottom - left:sidebar.left + top: sidebar.top + right: sidebar.right + bottom: sidebar.bottom + left: sidebar.left } Rectangle { - id:sidebarBackground - color: "grey" + id: sidebarBackground + color: "white" anchors { - top:parent.top - right:parent.right - bottom:parent.bottom - left:parent.left + top: parent.top + right: parent.right + bottom: parent.bottom + left: parent.left leftMargin: 5 } @@ -47,6 +54,13 @@ Item { anchors.rightMargin: 0 anchors.left: parent.left anchors.leftMargin: 0 + + Image { + id: image + fillMode: Image.PreserveAspectCrop + asynchronous: true + anchors.fill: parent + } } Button { @@ -74,37 +88,53 @@ Item { } } + Text { + id: text1 + text: "" + anchors.left: parent.left + anchors.leftMargin: 20 + anchors.top: parent.top + anchors.topMargin: 267 + font.pixelSize: 12 + } } Rectangle { - id:shadow + id: shadow anchors { - top:parent.top - right:sidebarBackground.left - bottom:parent.bottom - left:parent.left + top: parent.top + right: sidebarBackground.left + bottom: parent.bottom + left: parent.left } - LinearGradient { anchors.fill: parent start: Qt.point(0, 0) end: Qt.point(0, 5) gradient: Gradient { - GradientStop { position: 0.0; color: "#00000000" } - GradientStop { position: 1.0; color: "#22000000" } + GradientStop { + position: 0.0 + color: "#00000000" + } + GradientStop { + position: 1.0 + color: "#22000000" + } } } - } - } - states: [ State { name: "active" + PropertyChanges { + target: mouseAreaHelper + enabled: true + } + PropertyChanges { target: sidebarWrapper anchors.leftMargin: 0 @@ -113,6 +143,11 @@ Item { State { name: "inactive" + PropertyChanges { + target: mouseAreaHelper + enabled: false + } + PropertyChanges { target: sidebarWrapper anchors.leftMargin: sidebar.width @@ -125,6 +160,7 @@ Item { to: "active" NumberAnimation { + target: sidebarWrapper properties: "anchors.leftMargin" duration: 300 easing.type: Easing.InOutQuad @@ -134,11 +170,11 @@ Item { to: "inactive" NumberAnimation { + target: sidebarWrapper properties: "anchors.leftMargin" duration: 300 easing.type: Easing.InOutQuad } } ] - } diff --git a/src/installedlistmodel.cpp b/src/installedlistmodel.cpp index d178f7d8..d78eabca 100644 --- a/src/installedlistmodel.cpp +++ b/src/installedlistmodel.cpp @@ -12,7 +12,7 @@ InstalledListModel::InstalledListModel(QObject* parent) return; } } else { - _screensPath = writablePath + "/Installed/"; + _screensPath = writablePath + "/Installed/"; } loadScreens(); @@ -20,10 +20,6 @@ InstalledListModel::InstalledListModel(QObject* parent) int InstalledListModel::rowCount(const QModelIndex& parent) const { - // For list models only the root node (an invalid parent) should return the - // list's size. For all - // other (valid) parents, rowCount() should return 0 so that it does not - // become a tree model. return _screenPlayFiles.count(); } @@ -91,6 +87,24 @@ void InstalledListModel::loadScreens() if (!(parseError.error == QJsonParseError::NoError)) continue; - append(jsonProject.object(),item.baseName()); + append(jsonProject.object(), item.baseName()); } } + +QVariantMap InstalledListModel::get(QString folderId) +{ + + QVariantMap map; + if (_screenPlayFiles.count() == 0) + return map; + + for (int i = 0; i < _screenPlayFiles.count(); i++) { + + if (_screenPlayFiles[i]._folderId == folderId) { + map.insert("screenTitle", _screenPlayFiles[i]._title); + map.insert("screenPreview", _screenPlayFiles[i]._preview); + } + } + + return map; +} diff --git a/src/installedlistmodel.h b/src/installedlistmodel.h index 477510d0..e287595d 100644 --- a/src/installedlistmodel.h +++ b/src/installedlistmodel.h @@ -32,6 +32,7 @@ public: QHash roleNames() const; Q_INVOKABLE void loadScreens(); + Q_INVOKABLE QVariantMap get(QString folderId); Q_PROPERTY(QString _screensPath READ name CONSTANT) enum InstalledRole { @@ -49,7 +50,6 @@ public: private: QList _screenPlayFiles; QString _screensPath; - }; class ScreenPlayFile {