diff --git a/LenaPi/CircularListDelegate.qml b/LenaPi/NavigationListDelegate.qml similarity index 60% rename from LenaPi/CircularListDelegate.qml rename to LenaPi/NavigationListDelegate.qml index 1ce8541..0b5dda4 100644 --- a/LenaPi/CircularListDelegate.qml +++ b/LenaPi/NavigationListDelegate.qml @@ -2,27 +2,34 @@ import QtQuick 2.0 import QtGraphicalEffects 1.0 Rectangle{ - id: circle + id: container + + property var model + property bool isCircle : true + property alias imageSource: contentImage.source + width: 100 height: width - radius: width/2 + radius: isCircle ? width/2 : 0 color: "blue" + Image{ id: contentImage - source: "file:///home/ar/source/LenaPi/pics/benjamin.jpeg" + source: model ? model.pImageSource : "file:///home/ar/source/LenaPi/pics/benjamin.jpeg" anchors.centerIn: parent width: parent.width-10 height: width fillMode: Image.PreserveAspectCrop layer.enabled: true layer.effect: OpacityMask{ - maskSource: circle + maskSource: container } } MouseArea{ id: controlObject anchors.fill: parent onClicked:{ + model.onClicked(); console.log("circle clicked") } } diff --git a/LenaPi/RectangularListDelegate.qml b/LenaPi/RectangularListDelegate.qml deleted file mode 100644 index 4f2fb2e..0000000 --- a/LenaPi/RectangularListDelegate.qml +++ /dev/null @@ -1,23 +0,0 @@ -import QtQuick 2.0 - -Rectangle{ - id: container - width: 100 - height: width - color: "blue" - Image{ - id: contentImage - source: "file:///home/ar/source/LenaPi/pics/benjamin.jpeg" - anchors.centerIn: parent - width: parent.width-10 - height: width - fillMode: Image.PreserveAspectCrop - } - MouseArea{ - id: controlObject - anchors.fill: parent - onClicked:{ - console.log("rectangle clicked") - } - } -} diff --git a/LenaPi/controllers/NavigationController.cpp b/LenaPi/controllers/NavigationController.cpp index ba020ef..bf000f0 100644 --- a/LenaPi/controllers/NavigationController.cpp +++ b/LenaPi/controllers/NavigationController.cpp @@ -1,5 +1,8 @@ #include "NavigationController.h" +#include +#include + #include "../models/NavigationItemModel.h" #include "../models/NavigationListModel.h" @@ -13,7 +16,31 @@ NavigationController::NavigationController(QObject *parent) : QObject(parent), void NavigationController::init(const QString &rootPath) { - ///@todo create item for each subfolder and append to root; + auto rootDir = QDir(rootPath); + if(!rootDir.exists()) return; + mRootPath = rootPath; + + ///@todo recursively do the following for all subdirs + auto subDirsNames = rootDir.entryList(QDir::AllDirs); + qDebug() << subDirsNames; + for(const auto& name : subDirsNames){ + if(name == "." || name == "..") continue; + auto item = new NavigationItemModel(mRootItem); + if(!item->setPath(mRootPath + name)) { + item->deleteLater(); + continue; + } + mRootItem->appendChild(item); + + } + // just for testing! + auto list = mRootItem->getChildren(); + for (const auto& elem: list){ + qDebug() << elem->getImageSource(); + } + // end testing + + mNavList->setModelItems(mRootItem->getChildren()); } void NavigationController::setContext(QQmlContext *context) diff --git a/LenaPi/controllers/NavigationController.h b/LenaPi/controllers/NavigationController.h index 7804171..7efa6c1 100644 --- a/LenaPi/controllers/NavigationController.h +++ b/LenaPi/controllers/NavigationController.h @@ -22,6 +22,7 @@ private: NavigationItemModel* mRootItem; NavigationListModel* mNavList; + QString mRootPath = "."; QQmlContext* mContext; }; diff --git a/LenaPi/main.cpp b/LenaPi/main.cpp index 51cc862..cab87cb 100644 --- a/LenaPi/main.cpp +++ b/LenaPi/main.cpp @@ -12,6 +12,7 @@ int main(int argc, char *argv[]) NavigationController navController; navController.setContext(engine.rootContext()); + navController.init("/home/ar/source/testLenaPi/"); ///@todo call init with test path containing several folders each containing image.jpg diff --git a/LenaPi/main.qml b/LenaPi/main.qml index d9d3e16..d69e653 100644 --- a/LenaPi/main.qml +++ b/LenaPi/main.qml @@ -18,13 +18,14 @@ Window { flickableItem.interactive: true contentItem: ListView{ - model: 20 + model: navigationList.pModelItems anchors.fill: parent spacing: 10 orientation: ListView.Horizontal delegate: - CircularListDelegate{ - id: test + NavigationListDelegate{ + id: delegate + model: navigationList.pModelItems[index] } } } @@ -42,8 +43,9 @@ Window { spacing: 10 orientation: ListView.Horizontal delegate: - RectangularListDelegate{ + NavigationListDelegate{ id: test + isCircle: false } } } diff --git a/LenaPi/models/NavigationItemModel.cpp b/LenaPi/models/NavigationItemModel.cpp index ab8f507..1e3a0a3 100644 --- a/LenaPi/models/NavigationItemModel.cpp +++ b/LenaPi/models/NavigationItemModel.cpp @@ -31,9 +31,9 @@ bool NavigationItemModel::setPath(const QString &path) mPath = path; /// @todo move default image to qrc - auto source = dir.filePath("file.jpg"); + auto source = dir.filePath("image.jpg"); if(QFile(source).exists()) - mImageSource = source; + mImageSource = "file:///" + source; else mImageSource = "file:///home/ar/source/LenaPi/pics/benjamin.jpeg"; diff --git a/LenaPi/models/NavigationListModel.cpp b/LenaPi/models/NavigationListModel.cpp index f25484a..78645ca 100644 --- a/LenaPi/models/NavigationListModel.cpp +++ b/LenaPi/models/NavigationListModel.cpp @@ -1,5 +1,7 @@ #include "NavigationListModel.h" +#include "NavigationItemModel.h" + NavigationListModel::NavigationListModel(QObject* parent) : QObject(parent) { @@ -10,8 +12,11 @@ QList NavigationListModel::getModelItems() return mItems; } -void NavigationListModel::setModelItems(QList list) +void NavigationListModel::setModelItems(QList list) { - mItems = list; + mItems.clear(); + for(const auto& item : list){ + mItems.append(item); + } emit modelItemsChanged(); } diff --git a/LenaPi/models/NavigationListModel.h b/LenaPi/models/NavigationListModel.h index 1458060..632aabc 100644 --- a/LenaPi/models/NavigationListModel.h +++ b/LenaPi/models/NavigationListModel.h @@ -3,6 +3,8 @@ #include +class NavigationItemModel; + class NavigationListModel : public QObject { Q_OBJECT @@ -15,7 +17,7 @@ public: NavigationListModel(QObject* parent = Q_NULLPTR); QList getModelItems(); - void setModelItems(QList list); + void setModelItems(QList list); private: QList mItems; diff --git a/LenaPi/qml.qrc b/LenaPi/qml.qrc index 9394177..71cf2ab 100644 --- a/LenaPi/qml.qrc +++ b/LenaPi/qml.qrc @@ -2,8 +2,7 @@ main.qml MainForm.ui.qml - CircularListDelegate.qml + NavigationListDelegate.qml MyScrollView.qml - RectangularListDelegate.qml