refactored item type; moved navigation to qml component

This commit is contained in:
Anika Raemer 2018-10-20 17:34:08 +02:00
parent a32fd01e81
commit bf145a9be9
7 changed files with 54 additions and 55 deletions

45
LenaPi/Navigation.qml Normal file
View file

@ -0,0 +1,45 @@
import QtQuick 2.0
Item {
RoundButton{
id: back
anchors.top: parent.top
anchors.left: parent.left
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]
}
}
}
}

View file

@ -20,7 +20,7 @@ void NavigationController::init(const QString &rootPath)
if(!rootDir.exists()) return;
mRootPath = rootPath;
add(mRootPath, mRootItem, true);
add(mRootPath, mRootItem);
mNavList->setModelItems(mRootItem->getChildren());
}
@ -36,7 +36,7 @@ void NavigationController::setContextProperties()
mContext->setContextProperty("navigationList", mNavList);
}
void NavigationController::add(const QString &path, NavigationItemModel *parentItem, bool isCircleDelegate)
void NavigationController::add(const QString &path, NavigationItemModel *parentItem)
{
auto dir = QDir(path);
if(!dir.exists()) return;
@ -50,10 +50,9 @@ void NavigationController::add(const QString &path, NavigationItemModel *parentI
item->deleteLater();
continue;
}
item->setCircleDelegate(isCircleDelegate);
connect(item, &NavigationItemModel::clicked, this, &NavigationController::onNavigationRequest);
parentItem->appendChild(item);
add(item->getPath(), item, false);
add(item->getPath(), item);
}
}

View file

@ -19,7 +19,7 @@ public:
private:
void setContextProperties();
void add(const QString & path, NavigationItemModel* parentItem, bool isCircleDelegate);
void add(const QString & path, NavigationItemModel* parentItem);
NavigationItemModel* mRootItem;
NavigationListModel* mNavList;

View file

@ -16,46 +16,9 @@ Window {
source: "qrc:/background"
}
RoundButton{
id: back
anchors.top: parent.top
anchors.left: parent.left
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]
}
}
Loader{
anchors.fill: parent
source: "Navigation.qml"
}
}

View file

@ -45,15 +45,7 @@ bool NavigationItemModel::setPath(const QString &path)
bool NavigationItemModel::isCircleDelegate() const
{
return mIsCircleDelegate;
}
void NavigationItemModel::setCircleDelegate(bool value)
{
if(value != mIsCircleDelegate){
mIsCircleDelegate = value;
emit isCircleDelegateChanged();
}
return hasChildren();
}
bool NavigationItemModel::isRoot() const

View file

@ -42,7 +42,6 @@ public:
private:
QString mPath = QString("");
QString mImageSource;
bool mIsCircleDelegate = false;
QList<NavigationItemModel*> mChildren = QList<NavigationItemModel*>();
NavigationItemModel* mParentItem;

View file

@ -5,5 +5,6 @@
<file>NavigationListDelegate.qml</file>
<file>MyScrollView.qml</file>
<file>RoundButton.qml</file>
<file>Navigation.qml</file>
</qresource>
</RCC>