Skip to content

Commit

Permalink
Merge pull request #43 from nemomobile-ux/add_main_menu
Browse files Browse the repository at this point in the history
[ApplicationWindow] Add mainMenu item
  • Loading branch information
neochapay committed Oct 11, 2023
2 parents 9cbfd68 + 4f85f8c commit e993b12
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 100 deletions.
43 changes: 14 additions & 29 deletions examples/touch/glacier-components.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Copyright (C) 2017-2021 Chupligin Sergey <neochapay@gmail.com>
** Copyright (C) 2017-2023 Chupligin Sergey <neochapay@gmail.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Quick Controls module of the Qt Toolkit.
Expand Down Expand Up @@ -49,20 +49,21 @@ import Nemo.Controls
import "content"

ApplicationWindow {

id: appWindow

// Implements back key navigation
Item{
id: keysHandler
focus: true
Keys.onReleased: {
if (event.key === Qt.Key_Back || event.key === Qt.Key_Escape) {
if (pageStack.depth > 1) {
pageStack.pop();
event.accepted = true;
} else { Qt.quit(); }
}
mainMenu: ListView {
id: mainList
model: pageModel
anchors.fill: parent
clip: true
delegate: ListViewItemWithActions {
iconVisible: false
label: title
onClicked: appWindow.push(Qt.resolvedUrl(page))
}

ScrollDecorator{
flickable: mainList
}
}

Expand Down Expand Up @@ -296,21 +297,5 @@ ApplicationWindow {

]
}

ListView {
id: mainList
model: pageModel
anchors.fill: parent
clip: true
delegate: ListViewItemWithActions {
iconVisible: false
label: title
onClicked: pageStack.push(Qt.resolvedUrl(page))
}

ScrollDecorator{
flickable: mainList
}
}
}
}
68 changes: 49 additions & 19 deletions src/controls/qml/ApplicationWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (C) 2013 Andrea Bernabei <and.bernabei@gmail.com>
* Copyright (C) 2013 Jolla Ltd.
* Copyright (C) 2017 Eetu Kahelin
* Copyright (C) 2021-2022 Chupligin Sergey (NeoChapay) <neochapay@gmail.com>
* Copyright (C) 2021-2023 Chupligin Sergey (NeoChapay) <neochapay@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand All @@ -29,7 +29,7 @@ import Nemo
import Nemo.Controls

NemoWindow {
id: root
id: applicationWindow

property alias header: toolBar
/*! \internal */
Expand All @@ -39,15 +39,19 @@ NemoWindow {
property alias initialPage: stackView.initialItem
property alias orientation: contentArea.uiOrientation

property bool isUiPortrait: root.width < root.height
property bool isUiPortrait: applicationWindow.width < applicationWindow.height

property alias mainMenu: mainMenuArea.sourceComponent
property int mainMenuWidth: Theme.itemWidthExtraLarge

color: Theme.backgroundColor


//Handles orientation of keyboard, MInputMethodQuick.appOrientation.
contentOrientation: orientation
onOrientationChanged: {
if (root.isOrientationAllowed(root.orientation)) {
contentArea.filteredOrientation = root.orientation
if (applicationWindow.isOrientationAllowed(applicationWindow.orientation)) {
contentArea.filteredOrientation = applicationWindow.orientation
}

contentOrientation = orientation
Expand All @@ -60,10 +64,13 @@ NemoWindow {
if(!params){
params = {}
}
console.log("##", url, params, pageStack)
var component = Qt.createComponent(url)
if (component.status === Component.Ready) {
pageStack.push(component.createObject(pageStack, params))
if(mainMenuArea.width != applicationWindow.width && mainMenuArea.width != 0) {
pageStack.replace(component.createObject(pageStack, params))
} else {
pageStack.push(component.createObject(pageStack, params))
}
} else {
console.warn("Error loading component", url, component.errorString())
pageStack.push(Qt.resolvedUrl("ErrorStackPage.qml"), {error: component.errorString()})
Expand Down Expand Up @@ -114,7 +121,7 @@ NemoWindow {

function isOrientationAllowed(orientationToBeChecked)
{
var allowedOrientations = root.allowedOrientations
var allowedOrientations = applicationWindow.allowedOrientations

//use Page's allowed orientations if available
if (stackView._isCurrentItemNemoPage() && stackView.currentItem.allowedOrientations) {
Expand Down Expand Up @@ -166,18 +173,41 @@ NemoWindow {

property bool orientationTransitionRunning: false

Loader{
id: mainMenuArea
height: parent.height
width: if(sourceComponent === null) {
return 0
} else if (applicationWindow.isUiPortrait) {
if(stackView.depth == 1) {
return parent.width
} else {
return 0
}

} else {
return applicationWindow.mainMenuWidth
}

anchors{
top: applicationWindow.isUiPortrait ? toolBar.bottom : parent.top
left: applicationWindow.isUiPortrait ? parent.left : toolBar.right
}
}


StackView {
id: stackView
anchors.top: root.isUiPortrait ? toolBar.bottom : parent.top
anchors.top: mainMenuArea.top
anchors.right: parent.right
anchors.left: root.isUiPortrait ? parent.left : toolBar.right
anchors.left: mainMenuArea.right
anchors.bottom: parent.bottom

property real panelSize: 0
property real previousImSize: 0
property real imSize: !Qt.application.active ? 0 : (isUiPortrait ? (root._transpose ? Qt.inputMethod.keyboardRectangle.width
property real imSize: !Qt.application.active ? 0 : (isUiPortrait ? (applicationWindow._transpose ? Qt.inputMethod.keyboardRectangle.width
: Qt.inputMethod.keyboardRectangle.height)
: (root._transpose ? Qt.inputMethod.keyboardRectangle.height
: (applicationWindow._transpose ? Qt.inputMethod.keyboardRectangle.height
: Qt.inputMethod.keyboardRectangle.width))


Expand Down Expand Up @@ -209,11 +239,11 @@ NemoWindow {
property bool stackInitialized: false
onStackInitializedChanged: if (stackInitialized) {
//set Screen.orientation as default, if allowed
if (root.isOrientationAllowed(root.orientation)) {
contentArea.filteredOrientation = root.orientation
if (applicationWindow.isOrientationAllowed(applicationWindow.orientation)) {
contentArea.filteredOrientation = applicationWindow.orientation
} else {
//let the window handle it, it will fall back to an allowed orientation
root.fallbackToAnAllowedOrientation()
applicationWindow.fallbackToAnAllowedOrientation()
}
}

Expand All @@ -227,7 +257,7 @@ NemoWindow {
//update orientation constraints when a Page is pushed/popped
onCurrentItemChanged: {
if (_isCurrentItemNemoPage()) {
root.fallbackToAnAllowedOrientation()
applicationWindow.fallbackToAnAllowedOrientation()
}
}

Expand All @@ -238,7 +268,7 @@ NemoWindow {
Connections {
id: pageConn
target: stackView._isCurrentItemNemoPage() ? stackView.currentItem : null
function onAllowedOrientationsChanged() { root.fallbackToAnAllowedOrientation() }
function onAllowedOrientationsChanged() { applicationWindow.fallbackToAnAllowedOrientation() }
}

SequentialAnimation {
Expand Down Expand Up @@ -267,8 +297,8 @@ NemoWindow {

Header {
id: toolBar
stackView: root.pageStack
appWindow: root
stackView: applicationWindow.pageStack
appWindow: applicationWindow
}

Item {
Expand Down
4 changes: 2 additions & 2 deletions src/controls/qml/ErrorStackPage.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************************
**
** Copyright (C) 2018 Chupligin Sergey <neochapay@gmail.com>
** Copyright (C) 2018-2023 Chupligin Sergey <neochapay@gmail.com>
** All rights reserved.
**
** You may use this file under the terms of BSD license as follows:
Expand Down Expand Up @@ -33,7 +33,7 @@ import QtQuick 2.6
import Nemo

Page {
id: root
id: errorStackPage

property alias error: errorLabel.text

Expand Down

0 comments on commit e993b12

Please sign in to comment.