diff --git a/.gitignore b/.gitignore
index 5c77fa9..91ccddb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
build-LenaPi-Desktop-Debug
+*.autosave
diff --git a/LenaPi/LenaPi.pro b/LenaPi/LenaPi.pro
index 500cd12..ab0a5a5 100644
--- a/LenaPi/LenaPi.pro
+++ b/LenaPi/LenaPi.pro
@@ -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 =
diff --git a/LenaPi/NavigationListDelegate.qml b/LenaPi/NavigationListDelegate.qml
index 753d9f8..0dddbd6 100644
--- a/LenaPi/NavigationListDelegate.qml
+++ b/LenaPi/NavigationListDelegate.qml
@@ -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")
}
}
}
diff --git a/LenaPi/RoundButton.qml b/LenaPi/RoundButton.qml
new file mode 100644
index 0000000..2323615
--- /dev/null
+++ b/LenaPi/RoundButton.qml
@@ -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();
+ }
+ }
+}
diff --git a/LenaPi/controllers/NavigationController.cpp b/LenaPi/controllers/NavigationController.cpp
index c528e98..556f163 100644
--- a/LenaPi/controllers/NavigationController.cpp
+++ b/LenaPi/controllers/NavigationController.cpp
@@ -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()
diff --git a/LenaPi/lenapi.qrc b/LenaPi/lenapi.qrc
new file mode 100644
index 0000000..174a464
--- /dev/null
+++ b/LenaPi/lenapi.qrc
@@ -0,0 +1,7 @@
+
+
+ resources/back.png
+ resources/defaultImage.png
+ resources/sky.jpg
+
+
diff --git a/LenaPi/main.qml b/LenaPi/main.qml
index c229698..47011d1 100644
--- a/LenaPi/main.qml
+++ b/LenaPi/main.qml
@@ -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
-// }
-// }
-// }
}
diff --git a/LenaPi/models/NavigationItemModel.cpp b/LenaPi/models/NavigationItemModel.cpp
index e57fb5f..1263d19 100644
--- a/LenaPi/models/NavigationItemModel.cpp
+++ b/LenaPi/models/NavigationItemModel.cpp
@@ -3,9 +3,10 @@
#include
#include
-NavigationItemModel::NavigationItemModel(QObject *parent) : QObject(parent)
+NavigationItemModel::NavigationItemModel(QObject *parent) : QObject(parent),
+ mImageSource("qrc:/default_image"),
+ mParentItem(qobject_cast(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::getChildren()
return mChildren;
}
+QList NavigationItemModel::getSiblings()
+{
+ if(isRoot()){
+ return QList();
+ } else{
+ return mParentItem->getChildren();
+ }
+
+}
+
void NavigationItemModel::appendChild(NavigationItemModel *item)
{
item->setParent(this);
diff --git a/LenaPi/models/NavigationItemModel.h b/LenaPi/models/NavigationItemModel.h
index f789f43..ce74cda 100644
--- a/LenaPi/models/NavigationItemModel.h
+++ b/LenaPi/models/NavigationItemModel.h
@@ -32,6 +32,8 @@ public:
bool hasChildren() const;
QList getChildren();
+ QList getSiblings();
+
void appendChild(NavigationItemModel* item);
void clearChildren();
@@ -43,7 +45,7 @@ private:
bool mIsCircleDelegate = false;
QList mChildren = QList();
- NavigationItemModel* mParentItem = nullptr;
+ NavigationItemModel* mParentItem;
};
#endif // NAVIGATIONITEMMODEL_H
diff --git a/LenaPi/models/NavigationListModel.cpp b/LenaPi/models/NavigationListModel.cpp
index 78645ca..4369b46 100644
--- a/LenaPi/models/NavigationListModel.cpp
+++ b/LenaPi/models/NavigationListModel.cpp
@@ -18,5 +18,27 @@ void NavigationListModel::setModelItems(QList 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(mItems.at(0));
+ if(!item || item->getParentItem()->isRoot()) return;
+
+ setModelItems(item->getParentItem()->getSiblings());
+}
diff --git a/LenaPi/models/NavigationListModel.h b/LenaPi/models/NavigationListModel.h
index 632aabc..6f4e65e 100644
--- a/LenaPi/models/NavigationListModel.h
+++ b/LenaPi/models/NavigationListModel.h
@@ -9,6 +9,7 @@ class NavigationListModel : public QObject
{
Q_OBJECT
Q_PROPERTY(QList pModelItems READ getModelItems NOTIFY modelItemsChanged)
+ Q_PROPERTY(bool pIsBackVisible READ isBackVisible NOTIFY modelItemsChanged)
signals:
void modelItemsChanged();
@@ -19,8 +20,13 @@ public:
QList getModelItems();
void setModelItems(QList list);
+ bool isBackVisible();
+
+ Q_INVOKABLE void navigateBack();
+
private:
QList mItems;
+ bool mIsBackVisible = false;
};
#endif // NAVIGATIONLISTMODEL_H
diff --git a/LenaPi/qml.qrc b/LenaPi/qml.qrc
index 71cf2ab..c5bae7c 100644
--- a/LenaPi/qml.qrc
+++ b/LenaPi/qml.qrc
@@ -4,5 +4,6 @@
MainForm.ui.qml
NavigationListDelegate.qml
MyScrollView.qml
+ RoundButton.qml
diff --git a/LenaPi/resources/back.png b/LenaPi/resources/back.png
new file mode 100644
index 0000000..e9cd55e
Binary files /dev/null and b/LenaPi/resources/back.png differ
diff --git a/LenaPi/resources/defaultImage.png b/LenaPi/resources/defaultImage.png
new file mode 100644
index 0000000..8024a0e
Binary files /dev/null and b/LenaPi/resources/defaultImage.png differ
diff --git a/LenaPi/resources/sky.jpg b/LenaPi/resources/sky.jpg
new file mode 100644
index 0000000..7002f7b
Binary files /dev/null and b/LenaPi/resources/sky.jpg differ