connected basic navigation model; completed controller

This commit is contained in:
Anika Raemer 2018-10-19 19:45:37 +02:00
parent 8a81c48606
commit 717e131b75
10 changed files with 60 additions and 39 deletions

View file

@ -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")
}
}

View file

@ -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")
}
}
}

View file

@ -1,5 +1,8 @@
#include "NavigationController.h"
#include <QDir>
#include <QDebug>
#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)

View file

@ -22,6 +22,7 @@ private:
NavigationItemModel* mRootItem;
NavigationListModel* mNavList;
QString mRootPath = ".";
QQmlContext* mContext;
};

View file

@ -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

View file

@ -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
}
}
}

View file

@ -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";

View file

@ -1,5 +1,7 @@
#include "NavigationListModel.h"
#include "NavigationItemModel.h"
NavigationListModel::NavigationListModel(QObject* parent) : QObject(parent)
{
@ -10,8 +12,11 @@ QList<QObject *> NavigationListModel::getModelItems()
return mItems;
}
void NavigationListModel::setModelItems(QList<QObject *> list)
void NavigationListModel::setModelItems(QList<NavigationItemModel *> list)
{
mItems = list;
mItems.clear();
for(const auto& item : list){
mItems.append(item);
}
emit modelItemsChanged();
}

View file

@ -3,6 +3,8 @@
#include <QObject>
class NavigationItemModel;
class NavigationListModel : public QObject
{
Q_OBJECT
@ -15,7 +17,7 @@ public:
NavigationListModel(QObject* parent = Q_NULLPTR);
QList<QObject*> getModelItems();
void setModelItems(QList<QObject*> list);
void setModelItems(QList<NavigationItemModel*> list);
private:
QList<QObject*> mItems;

View file

@ -2,8 +2,7 @@
<qresource prefix="/">
<file>main.qml</file>
<file>MainForm.ui.qml</file>
<file>CircularListDelegate.qml</file>
<file>NavigationListDelegate.qml</file>
<file>MyScrollView.qml</file>
<file>RectangularListDelegate.qml</file>
</qresource>
</RCC>