added backnavigation and qrc
This commit is contained in:
parent
0b9e8fa067
commit
a32fd01e81
15 changed files with 138 additions and 55 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
build-LenaPi-Desktop-Debug
|
build-LenaPi-Desktop-Debug
|
||||||
|
*.autosave
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ SOURCES += main.cpp \
|
||||||
models/NavigationItemModel.cpp \
|
models/NavigationItemModel.cpp \
|
||||||
controllers/NavigationController.cpp
|
controllers/NavigationController.cpp
|
||||||
|
|
||||||
RESOURCES += qml.qrc
|
RESOURCES += qml.qrc \
|
||||||
|
lenapi.qrc
|
||||||
|
|
||||||
# Additional import path used to resolve QML modules in Qt Creator's code model
|
# Additional import path used to resolve QML modules in Qt Creator's code model
|
||||||
QML_IMPORT_PATH =
|
QML_IMPORT_PATH =
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,14 @@ Rectangle{
|
||||||
property var model
|
property var model
|
||||||
property alias imageSource: contentImage.source
|
property alias imageSource: contentImage.source
|
||||||
|
|
||||||
width: 100
|
width: height
|
||||||
height: width
|
height: 150
|
||||||
radius: model.pIsCircleDelegate ? width/2 : 0
|
radius: model.pIsCircleDelegate ? height/2 : 0
|
||||||
color: "blue"
|
color: "blue"
|
||||||
|
|
||||||
Image{
|
Image{
|
||||||
id: contentImage
|
id: contentImage
|
||||||
source: model ? model.pImageSource : "file:///home/ar/source/LenaPi/pics/benjamin.jpeg"
|
source: model ? model.pImageSource : "qrc:/default_image"
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
width: parent.width-10
|
width: parent.width-10
|
||||||
height: width
|
height: width
|
||||||
|
|
@ -29,7 +29,6 @@ Rectangle{
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked:{
|
onClicked:{
|
||||||
model.onClicked();
|
model.onClicked();
|
||||||
console.log("circle clicked")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
LenaPi/RoundButton.qml
Normal file
32
LenaPi/RoundButton.qml
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
import QtQuick 2.0
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: container
|
||||||
|
property alias imageSource: image.source
|
||||||
|
signal clicked();
|
||||||
|
|
||||||
|
border.width: 2
|
||||||
|
border.color: "grey"
|
||||||
|
|
||||||
|
color: "white"
|
||||||
|
|
||||||
|
width: 50
|
||||||
|
height: width
|
||||||
|
radius: width/2
|
||||||
|
|
||||||
|
Image{
|
||||||
|
id: image
|
||||||
|
anchors.centerIn: parent
|
||||||
|
width: 30
|
||||||
|
height: width
|
||||||
|
source: "qrc:/icon_back"
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea{
|
||||||
|
id: controlObject
|
||||||
|
anchors.fill: parent
|
||||||
|
onClicked:{
|
||||||
|
container.clicked();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -42,7 +42,6 @@ void NavigationController::add(const QString &path, NavigationItemModel *parentI
|
||||||
if(!dir.exists()) return;
|
if(!dir.exists()) return;
|
||||||
|
|
||||||
auto subDirsNames = dir.entryList(QDir::AllDirs);
|
auto subDirsNames = dir.entryList(QDir::AllDirs);
|
||||||
qDebug() << path << subDirsNames;
|
|
||||||
|
|
||||||
for(const auto& name : subDirsNames){
|
for(const auto& name : subDirsNames){
|
||||||
if(name == "." || name == "..") continue;
|
if(name == "." || name == "..") continue;
|
||||||
|
|
@ -51,19 +50,11 @@ void NavigationController::add(const QString &path, NavigationItemModel *parentI
|
||||||
item->deleteLater();
|
item->deleteLater();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
qDebug() << "appending item " << item->getPath();
|
|
||||||
item->setCircleDelegate(isCircleDelegate);
|
item->setCircleDelegate(isCircleDelegate);
|
||||||
connect(item, &NavigationItemModel::clicked, this, &NavigationController::onNavigationRequest);
|
connect(item, &NavigationItemModel::clicked, this, &NavigationController::onNavigationRequest);
|
||||||
parentItem->appendChild(item);
|
parentItem->appendChild(item);
|
||||||
add(item->getPath(), item, false);
|
add(item->getPath(), item, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// just for testing!
|
|
||||||
auto list = parentItem->getChildren();
|
|
||||||
for (const auto& elem: list){
|
|
||||||
qDebug() << elem->getImageSource() << elem->isCircleDelegate();
|
|
||||||
}
|
|
||||||
// end testing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavigationController::onNavigationRequest()
|
void NavigationController::onNavigationRequest()
|
||||||
|
|
|
||||||
7
LenaPi/lenapi.qrc
Normal file
7
LenaPi/lenapi.qrc
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file alias="icon_back">resources/back.png</file>
|
||||||
|
<file alias="default_image">resources/defaultImage.png</file>
|
||||||
|
<file alias="background">resources/sky.jpg</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
|
|
@ -8,44 +8,54 @@ Window {
|
||||||
height: 480
|
height: 480
|
||||||
title: "LenaPi 1.0"
|
title: "LenaPi 1.0"
|
||||||
|
|
||||||
MyScrollView{
|
Image{
|
||||||
id: circleList
|
id: background
|
||||||
anchors.left: parent.left
|
|
||||||
anchors.right: parent.right
|
anchors.fill: parent
|
||||||
|
z: -1
|
||||||
|
source: "qrc:/background"
|
||||||
|
}
|
||||||
|
|
||||||
|
RoundButton{
|
||||||
|
id: back
|
||||||
|
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
anchors.left: parent.left
|
||||||
anchors.margins: 20
|
anchors.margins: 20
|
||||||
|
|
||||||
flickableItem.interactive: true
|
visible: navigationList.pIsBackVisible
|
||||||
contentItem:
|
|
||||||
ListView{
|
onClicked: navigationList.navigateBack();
|
||||||
model: navigationList.pModelItems
|
}
|
||||||
anchors.fill: parent
|
|
||||||
spacing: 10
|
Rectangle{
|
||||||
orientation: ListView.Horizontal
|
anchors.left: parent.left
|
||||||
delegate:
|
anchors.right: parent.right
|
||||||
NavigationListDelegate{
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
id: delegate
|
|
||||||
model: navigationList.pModelItems[index]
|
height: 210
|
||||||
}
|
|
||||||
}
|
color: "#99ffffff"
|
||||||
}
|
|
||||||
// MyScrollView{
|
ListView{
|
||||||
// anchors.left: parent.left
|
id: circleList
|
||||||
// anchors.right: parent.right
|
anchors.left: parent.left
|
||||||
// anchors.top: circleList.bottom
|
anchors.right: parent.right
|
||||||
// anchors.margins: 20
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.margins: 20
|
||||||
|
|
||||||
|
height: parent.height - 40
|
||||||
|
|
||||||
|
model: navigationList.pModelItems
|
||||||
|
spacing: 20
|
||||||
|
orientation: ListView.Horizontal
|
||||||
|
delegate:
|
||||||
|
NavigationListDelegate{
|
||||||
|
id: delegate
|
||||||
|
height: parent.height
|
||||||
|
model: navigationList.pModelItems[index]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// flickableItem.interactive: true
|
|
||||||
// contentItem:
|
|
||||||
// ListView{
|
|
||||||
// model: 20
|
|
||||||
// anchors.fill: parent
|
|
||||||
// spacing: 10
|
|
||||||
// orientation: ListView.Horizontal
|
|
||||||
// delegate:
|
|
||||||
// NavigationListDelegate{
|
|
||||||
// id: test
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
||||||
NavigationItemModel::NavigationItemModel(QObject *parent) : QObject(parent)
|
NavigationItemModel::NavigationItemModel(QObject *parent) : QObject(parent),
|
||||||
|
mImageSource("qrc:/default_image"),
|
||||||
|
mParentItem(qobject_cast<NavigationItemModel*>(parent))
|
||||||
{
|
{
|
||||||
///@todo init imageSource with defaul image from qrc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString NavigationItemModel::getImageSource() const
|
QString NavigationItemModel::getImageSource() const
|
||||||
|
|
@ -57,7 +58,7 @@ void NavigationItemModel::setCircleDelegate(bool value)
|
||||||
|
|
||||||
bool NavigationItemModel::isRoot() const
|
bool NavigationItemModel::isRoot() const
|
||||||
{
|
{
|
||||||
return mParentItem;
|
return !mParentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
NavigationItemModel *NavigationItemModel::getParentItem()
|
NavigationItemModel *NavigationItemModel::getParentItem()
|
||||||
|
|
@ -75,6 +76,16 @@ QList<NavigationItemModel *> NavigationItemModel::getChildren()
|
||||||
return mChildren;
|
return mChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<NavigationItemModel *> NavigationItemModel::getSiblings()
|
||||||
|
{
|
||||||
|
if(isRoot()){
|
||||||
|
return QList<NavigationItemModel*>();
|
||||||
|
} else{
|
||||||
|
return mParentItem->getChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void NavigationItemModel::appendChild(NavigationItemModel *item)
|
void NavigationItemModel::appendChild(NavigationItemModel *item)
|
||||||
{
|
{
|
||||||
item->setParent(this);
|
item->setParent(this);
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ public:
|
||||||
bool hasChildren() const;
|
bool hasChildren() const;
|
||||||
QList<NavigationItemModel *> getChildren();
|
QList<NavigationItemModel *> getChildren();
|
||||||
|
|
||||||
|
QList<NavigationItemModel *> getSiblings();
|
||||||
|
|
||||||
void appendChild(NavigationItemModel* item);
|
void appendChild(NavigationItemModel* item);
|
||||||
void clearChildren();
|
void clearChildren();
|
||||||
|
|
||||||
|
|
@ -43,7 +45,7 @@ private:
|
||||||
bool mIsCircleDelegate = false;
|
bool mIsCircleDelegate = false;
|
||||||
|
|
||||||
QList<NavigationItemModel*> mChildren = QList<NavigationItemModel*>();
|
QList<NavigationItemModel*> mChildren = QList<NavigationItemModel*>();
|
||||||
NavigationItemModel* mParentItem = nullptr;
|
NavigationItemModel* mParentItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAVIGATIONITEMMODEL_H
|
#endif // NAVIGATIONITEMMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -18,5 +18,27 @@ void NavigationListModel::setModelItems(QList<NavigationItemModel *> list)
|
||||||
for(const auto& item : list){
|
for(const auto& item : list){
|
||||||
mItems.append(item);
|
mItems.append(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mItems.isEmpty()){
|
||||||
|
mIsBackVisible = false;
|
||||||
|
} else{
|
||||||
|
mIsBackVisible = !list.at(0)->getParentItem()->isRoot();
|
||||||
|
}
|
||||||
|
|
||||||
emit modelItemsChanged();
|
emit modelItemsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NavigationListModel::isBackVisible()
|
||||||
|
{
|
||||||
|
return mIsBackVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NavigationListModel::navigateBack()
|
||||||
|
{
|
||||||
|
if(!mIsBackVisible || mItems.isEmpty()) return;
|
||||||
|
|
||||||
|
auto item = qobject_cast<NavigationItemModel*>(mItems.at(0));
|
||||||
|
if(!item || item->getParentItem()->isRoot()) return;
|
||||||
|
|
||||||
|
setModelItems(item->getParentItem()->getSiblings());
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ class NavigationListModel : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QList<QObject*> pModelItems READ getModelItems NOTIFY modelItemsChanged)
|
Q_PROPERTY(QList<QObject*> pModelItems READ getModelItems NOTIFY modelItemsChanged)
|
||||||
|
Q_PROPERTY(bool pIsBackVisible READ isBackVisible NOTIFY modelItemsChanged)
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void modelItemsChanged();
|
void modelItemsChanged();
|
||||||
|
|
@ -19,8 +20,13 @@ public:
|
||||||
QList<QObject*> getModelItems();
|
QList<QObject*> getModelItems();
|
||||||
void setModelItems(QList<NavigationItemModel*> list);
|
void setModelItems(QList<NavigationItemModel*> list);
|
||||||
|
|
||||||
|
bool isBackVisible();
|
||||||
|
|
||||||
|
Q_INVOKABLE void navigateBack();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QObject*> mItems;
|
QList<QObject*> mItems;
|
||||||
|
bool mIsBackVisible = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAVIGATIONLISTMODEL_H
|
#endif // NAVIGATIONLISTMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,6 @@
|
||||||
<file>MainForm.ui.qml</file>
|
<file>MainForm.ui.qml</file>
|
||||||
<file>NavigationListDelegate.qml</file>
|
<file>NavigationListDelegate.qml</file>
|
||||||
<file>MyScrollView.qml</file>
|
<file>MyScrollView.qml</file>
|
||||||
|
<file>RoundButton.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
||||||
BIN
LenaPi/resources/back.png
Normal file
BIN
LenaPi/resources/back.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
LenaPi/resources/defaultImage.png
Normal file
BIN
LenaPi/resources/defaultImage.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
BIN
LenaPi/resources/sky.jpg
Normal file
BIN
LenaPi/resources/sky.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
Loading…
Add table
Add a link
Reference in a new issue