refactored item type; moved navigation to qml component
This commit is contained in:
parent
a32fd01e81
commit
bf145a9be9
7 changed files with 54 additions and 55 deletions
45
LenaPi/Navigation.qml
Normal file
45
LenaPi/Navigation.qml
Normal 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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -20,7 +20,7 @@ void NavigationController::init(const QString &rootPath)
|
||||||
if(!rootDir.exists()) return;
|
if(!rootDir.exists()) return;
|
||||||
mRootPath = rootPath;
|
mRootPath = rootPath;
|
||||||
|
|
||||||
add(mRootPath, mRootItem, true);
|
add(mRootPath, mRootItem);
|
||||||
|
|
||||||
mNavList->setModelItems(mRootItem->getChildren());
|
mNavList->setModelItems(mRootItem->getChildren());
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +36,7 @@ void NavigationController::setContextProperties()
|
||||||
mContext->setContextProperty("navigationList", mNavList);
|
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);
|
auto dir = QDir(path);
|
||||||
if(!dir.exists()) return;
|
if(!dir.exists()) return;
|
||||||
|
|
@ -50,10 +50,9 @@ void NavigationController::add(const QString &path, NavigationItemModel *parentI
|
||||||
item->deleteLater();
|
item->deleteLater();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setContextProperties();
|
void setContextProperties();
|
||||||
void add(const QString & path, NavigationItemModel* parentItem, bool isCircleDelegate);
|
void add(const QString & path, NavigationItemModel* parentItem);
|
||||||
|
|
||||||
NavigationItemModel* mRootItem;
|
NavigationItemModel* mRootItem;
|
||||||
NavigationListModel* mNavList;
|
NavigationListModel* mNavList;
|
||||||
|
|
|
||||||
|
|
@ -16,46 +16,9 @@ Window {
|
||||||
source: "qrc:/background"
|
source: "qrc:/background"
|
||||||
}
|
}
|
||||||
|
|
||||||
RoundButton{
|
Loader{
|
||||||
id: back
|
anchors.fill: parent
|
||||||
|
source: "Navigation.qml"
|
||||||
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]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,15 +45,7 @@ bool NavigationItemModel::setPath(const QString &path)
|
||||||
|
|
||||||
bool NavigationItemModel::isCircleDelegate() const
|
bool NavigationItemModel::isCircleDelegate() const
|
||||||
{
|
{
|
||||||
return mIsCircleDelegate;
|
return hasChildren();
|
||||||
}
|
|
||||||
|
|
||||||
void NavigationItemModel::setCircleDelegate(bool value)
|
|
||||||
{
|
|
||||||
if(value != mIsCircleDelegate){
|
|
||||||
mIsCircleDelegate = value;
|
|
||||||
emit isCircleDelegateChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NavigationItemModel::isRoot() const
|
bool NavigationItemModel::isRoot() const
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@ public:
|
||||||
private:
|
private:
|
||||||
QString mPath = QString("");
|
QString mPath = QString("");
|
||||||
QString mImageSource;
|
QString mImageSource;
|
||||||
bool mIsCircleDelegate = false;
|
|
||||||
|
|
||||||
QList<NavigationItemModel*> mChildren = QList<NavigationItemModel*>();
|
QList<NavigationItemModel*> mChildren = QList<NavigationItemModel*>();
|
||||||
NavigationItemModel* mParentItem;
|
NavigationItemModel* mParentItem;
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,6 @@
|
||||||
<file>NavigationListDelegate.qml</file>
|
<file>NavigationListDelegate.qml</file>
|
||||||
<file>MyScrollView.qml</file>
|
<file>MyScrollView.qml</file>
|
||||||
<file>RoundButton.qml</file>
|
<file>RoundButton.qml</file>
|
||||||
|
<file>Navigation.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue