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
|
||||
*.autosave
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ SOURCES += main.cpp \
|
|||
models/NavigationItemModel.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
|
||||
QML_IMPORT_PATH =
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ Rectangle{
|
|||
property var model
|
||||
property alias imageSource: contentImage.source
|
||||
|
||||
width: 100
|
||||
height: width
|
||||
radius: model.pIsCircleDelegate ? width/2 : 0
|
||||
width: height
|
||||
height: 150
|
||||
radius: model.pIsCircleDelegate ? height/2 : 0
|
||||
color: "blue"
|
||||
|
||||
Image{
|
||||
id: contentImage
|
||||
source: model ? model.pImageSource : "file:///home/ar/source/LenaPi/pics/benjamin.jpeg"
|
||||
source: model ? model.pImageSource : "qrc:/default_image"
|
||||
anchors.centerIn: parent
|
||||
width: parent.width-10
|
||||
height: width
|
||||
|
|
@ -29,7 +29,6 @@ Rectangle{
|
|||
anchors.fill: parent
|
||||
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;
|
||||
|
||||
auto subDirsNames = dir.entryList(QDir::AllDirs);
|
||||
qDebug() << path << subDirsNames;
|
||||
|
||||
for(const auto& name : subDirsNames){
|
||||
if(name == "." || name == "..") continue;
|
||||
|
|
@ -51,19 +50,11 @@ void NavigationController::add(const QString &path, NavigationItemModel *parentI
|
|||
item->deleteLater();
|
||||
continue;
|
||||
}
|
||||
qDebug() << "appending item " << item->getPath();
|
||||
item->setCircleDelegate(isCircleDelegate);
|
||||
connect(item, &NavigationItemModel::clicked, this, &NavigationController::onNavigationRequest);
|
||||
parentItem->appendChild(item);
|
||||
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()
|
||||
|
|
|
|||
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
|
||||
title: "LenaPi 1.0"
|
||||
|
||||
MyScrollView{
|
||||
id: circleList
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
Image{
|
||||
id: background
|
||||
|
||||
anchors.fill: parent
|
||||
z: -1
|
||||
source: "qrc:/background"
|
||||
}
|
||||
|
||||
RoundButton{
|
||||
id: back
|
||||
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.margins: 20
|
||||
|
||||
flickableItem.interactive: true
|
||||
contentItem:
|
||||
ListView{
|
||||
model: navigationList.pModelItems
|
||||
anchors.fill: parent
|
||||
spacing: 10
|
||||
orientation: ListView.Horizontal
|
||||
delegate:
|
||||
NavigationListDelegate{
|
||||
id: delegate
|
||||
model: navigationList.pModelItems[index]
|
||||
}
|
||||
}
|
||||
}
|
||||
// MyScrollView{
|
||||
// anchors.left: parent.left
|
||||
// anchors.right: parent.right
|
||||
// anchors.top: circleList.bottom
|
||||
// anchors.margins: 20
|
||||
visible: navigationList.pIsBackVisible
|
||||
|
||||
onClicked: navigationList.navigateBack();
|
||||
}
|
||||
|
||||
Rectangle{
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
height: 210
|
||||
|
||||
color: "#99ffffff"
|
||||
|
||||
ListView{
|
||||
id: circleList
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
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 <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
|
||||
|
|
@ -57,7 +58,7 @@ void NavigationItemModel::setCircleDelegate(bool value)
|
|||
|
||||
bool NavigationItemModel::isRoot() const
|
||||
{
|
||||
return mParentItem;
|
||||
return !mParentItem;
|
||||
}
|
||||
|
||||
NavigationItemModel *NavigationItemModel::getParentItem()
|
||||
|
|
@ -75,6 +76,16 @@ QList<NavigationItemModel *> NavigationItemModel::getChildren()
|
|||
return mChildren;
|
||||
}
|
||||
|
||||
QList<NavigationItemModel *> NavigationItemModel::getSiblings()
|
||||
{
|
||||
if(isRoot()){
|
||||
return QList<NavigationItemModel*>();
|
||||
} else{
|
||||
return mParentItem->getChildren();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void NavigationItemModel::appendChild(NavigationItemModel *item)
|
||||
{
|
||||
item->setParent(this);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ public:
|
|||
bool hasChildren() const;
|
||||
QList<NavigationItemModel *> getChildren();
|
||||
|
||||
QList<NavigationItemModel *> getSiblings();
|
||||
|
||||
void appendChild(NavigationItemModel* item);
|
||||
void clearChildren();
|
||||
|
||||
|
|
@ -43,7 +45,7 @@ private:
|
|||
bool mIsCircleDelegate = false;
|
||||
|
||||
QList<NavigationItemModel*> mChildren = QList<NavigationItemModel*>();
|
||||
NavigationItemModel* mParentItem = nullptr;
|
||||
NavigationItemModel* mParentItem;
|
||||
};
|
||||
|
||||
#endif // NAVIGATIONITEMMODEL_H
|
||||
|
|
|
|||
|
|
@ -18,5 +18,27 @@ void NavigationListModel::setModelItems(QList<NavigationItemModel *> list)
|
|||
for(const auto& item : list){
|
||||
mItems.append(item);
|
||||
}
|
||||
|
||||
if(mItems.isEmpty()){
|
||||
mIsBackVisible = false;
|
||||
} else{
|
||||
mIsBackVisible = !list.at(0)->getParentItem()->isRoot();
|
||||
}
|
||||
|
||||
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_PROPERTY(QList<QObject*> pModelItems READ getModelItems NOTIFY modelItemsChanged)
|
||||
Q_PROPERTY(bool pIsBackVisible READ isBackVisible NOTIFY modelItemsChanged)
|
||||
|
||||
signals:
|
||||
void modelItemsChanged();
|
||||
|
|
@ -19,8 +20,13 @@ public:
|
|||
QList<QObject*> getModelItems();
|
||||
void setModelItems(QList<NavigationItemModel*> list);
|
||||
|
||||
bool isBackVisible();
|
||||
|
||||
Q_INVOKABLE void navigateBack();
|
||||
|
||||
private:
|
||||
QList<QObject*> mItems;
|
||||
bool mIsBackVisible = false;
|
||||
};
|
||||
|
||||
#endif // NAVIGATIONLISTMODEL_H
|
||||
|
|
|
|||
|
|
@ -4,5 +4,6 @@
|
|||
<file>MainForm.ui.qml</file>
|
||||
<file>NavigationListDelegate.qml</file>
|
||||
<file>MyScrollView.qml</file>
|
||||
<file>RoundButton.qml</file>
|
||||
</qresource>
|
||||
</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