connected basic navigation model; completed controller
This commit is contained in:
parent
8a81c48606
commit
717e131b75
10 changed files with 60 additions and 39 deletions
|
|
@ -2,27 +2,34 @@ import QtQuick 2.0
|
||||||
import QtGraphicalEffects 1.0
|
import QtGraphicalEffects 1.0
|
||||||
|
|
||||||
Rectangle{
|
Rectangle{
|
||||||
id: circle
|
id: container
|
||||||
|
|
||||||
|
property var model
|
||||||
|
property bool isCircle : true
|
||||||
|
property alias imageSource: contentImage.source
|
||||||
|
|
||||||
width: 100
|
width: 100
|
||||||
height: width
|
height: width
|
||||||
radius: width/2
|
radius: isCircle ? width/2 : 0
|
||||||
color: "blue"
|
color: "blue"
|
||||||
|
|
||||||
Image{
|
Image{
|
||||||
id: contentImage
|
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
|
anchors.centerIn: parent
|
||||||
width: parent.width-10
|
width: parent.width-10
|
||||||
height: width
|
height: width
|
||||||
fillMode: Image.PreserveAspectCrop
|
fillMode: Image.PreserveAspectCrop
|
||||||
layer.enabled: true
|
layer.enabled: true
|
||||||
layer.effect: OpacityMask{
|
layer.effect: OpacityMask{
|
||||||
maskSource: circle
|
maskSource: container
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MouseArea{
|
MouseArea{
|
||||||
id: controlObject
|
id: controlObject
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked:{
|
onClicked:{
|
||||||
|
model.onClicked();
|
||||||
console.log("circle clicked")
|
console.log("circle clicked")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
#include "NavigationController.h"
|
#include "NavigationController.h"
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "../models/NavigationItemModel.h"
|
#include "../models/NavigationItemModel.h"
|
||||||
#include "../models/NavigationListModel.h"
|
#include "../models/NavigationListModel.h"
|
||||||
|
|
||||||
|
|
@ -13,7 +16,31 @@ NavigationController::NavigationController(QObject *parent) : QObject(parent),
|
||||||
|
|
||||||
void NavigationController::init(const QString &rootPath)
|
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)
|
void NavigationController::setContext(QQmlContext *context)
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ private:
|
||||||
|
|
||||||
NavigationItemModel* mRootItem;
|
NavigationItemModel* mRootItem;
|
||||||
NavigationListModel* mNavList;
|
NavigationListModel* mNavList;
|
||||||
|
QString mRootPath = ".";
|
||||||
|
|
||||||
QQmlContext* mContext;
|
QQmlContext* mContext;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
NavigationController navController;
|
NavigationController navController;
|
||||||
navController.setContext(engine.rootContext());
|
navController.setContext(engine.rootContext());
|
||||||
|
navController.init("/home/ar/source/testLenaPi/");
|
||||||
|
|
||||||
///@todo call init with test path containing several folders each containing image.jpg
|
///@todo call init with test path containing several folders each containing image.jpg
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,14 @@ Window {
|
||||||
flickableItem.interactive: true
|
flickableItem.interactive: true
|
||||||
contentItem:
|
contentItem:
|
||||||
ListView{
|
ListView{
|
||||||
model: 20
|
model: navigationList.pModelItems
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
spacing: 10
|
spacing: 10
|
||||||
orientation: ListView.Horizontal
|
orientation: ListView.Horizontal
|
||||||
delegate:
|
delegate:
|
||||||
CircularListDelegate{
|
NavigationListDelegate{
|
||||||
id: test
|
id: delegate
|
||||||
|
model: navigationList.pModelItems[index]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -42,8 +43,9 @@ Window {
|
||||||
spacing: 10
|
spacing: 10
|
||||||
orientation: ListView.Horizontal
|
orientation: ListView.Horizontal
|
||||||
delegate:
|
delegate:
|
||||||
RectangularListDelegate{
|
NavigationListDelegate{
|
||||||
id: test
|
id: test
|
||||||
|
isCircle: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ bool NavigationItemModel::setPath(const QString &path)
|
||||||
mPath = path;
|
mPath = path;
|
||||||
|
|
||||||
/// @todo move default image to qrc
|
/// @todo move default image to qrc
|
||||||
auto source = dir.filePath("file.jpg");
|
auto source = dir.filePath("image.jpg");
|
||||||
if(QFile(source).exists())
|
if(QFile(source).exists())
|
||||||
mImageSource = source;
|
mImageSource = "file:///" + source;
|
||||||
else
|
else
|
||||||
mImageSource = "file:///home/ar/source/LenaPi/pics/benjamin.jpeg";
|
mImageSource = "file:///home/ar/source/LenaPi/pics/benjamin.jpeg";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include "NavigationListModel.h"
|
#include "NavigationListModel.h"
|
||||||
|
|
||||||
|
#include "NavigationItemModel.h"
|
||||||
|
|
||||||
NavigationListModel::NavigationListModel(QObject* parent) : QObject(parent)
|
NavigationListModel::NavigationListModel(QObject* parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -10,8 +12,11 @@ QList<QObject *> NavigationListModel::getModelItems()
|
||||||
return mItems;
|
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();
|
emit modelItemsChanged();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
class NavigationItemModel;
|
||||||
|
|
||||||
class NavigationListModel : public QObject
|
class NavigationListModel : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -15,7 +17,7 @@ public:
|
||||||
NavigationListModel(QObject* parent = Q_NULLPTR);
|
NavigationListModel(QObject* parent = Q_NULLPTR);
|
||||||
|
|
||||||
QList<QObject*> getModelItems();
|
QList<QObject*> getModelItems();
|
||||||
void setModelItems(QList<QObject*> list);
|
void setModelItems(QList<NavigationItemModel*> list);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QObject*> mItems;
|
QList<QObject*> mItems;
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file>main.qml</file>
|
<file>main.qml</file>
|
||||||
<file>MainForm.ui.qml</file>
|
<file>MainForm.ui.qml</file>
|
||||||
<file>CircularListDelegate.qml</file>
|
<file>NavigationListDelegate.qml</file>
|
||||||
<file>MyScrollView.qml</file>
|
<file>MyScrollView.qml</file>
|
||||||
<file>RectangularListDelegate.qml</file>
|
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue