Browse Source

added simple drawer logic

pull/2/head
Skycoder42 7 years ago
parent
commit
aa81173335
  1. 4
      examples/mvvmquick/SampleQuick/SampleView.qml
  2. 98
      src/imports/mvvmquick/DialogPresenter.qml
  3. 39
      src/imports/mvvmquick/PresentingDrawer.qml
  4. 15
      src/imports/mvvmquick/PresentingStackView.qml
  5. 23
      src/imports/mvvmquick/QtMvvmApp.qml
  6. 9
      src/imports/mvvmquick/mvvmquick.pro
  7. 1
      src/imports/mvvmquick/plugins.qmltypes
  8. 1
      src/imports/mvvmquick/qmldir
  9. 10
      src/imports/mvvmquick/qqmlquickpresenter.cpp
  10. 3
      src/imports/mvvmquick/qqmlquickpresenter.h

4
examples/mvvmquick/SampleQuick/SampleView.qml

@ -11,9 +11,11 @@ Page {
property SampleViewModel viewModel: null
header: ActionBar {
showMenuButton: false
showMenuButton: true
title: qsTr("Sample")
onMenuButtonClicked: QuickPresenter.toggleDrawer()
moreMenu: Menu {
MenuItem {
text: qsTr("Another Input")

98
src/imports/mvvmquick/DialogPresenter.qml

@ -28,79 +28,71 @@ QtObject {
}
property var _popups: []
property Component _msgBoxComponent: Component {
MsgBox {
id: __msgBox
onClosed: {
var index = _popups.indexOf(__msgBox);
if(index > -1) {
__msgBox.destroy();
_dialogPresenter._popups.splice(index, 1);
}
property Component _msgBoxComponent: MsgBox {
id: __msgBox
onClosed: {
var index = _popups.indexOf(__msgBox);
if(index > -1) {
__msgBox.destroy();
_dialogPresenter._popups.splice(index, 1);
}
}
Component.onCompleted: {
_popups.push(__msgBox)
__msgBox.open()
}
Component.onCompleted: {
_popups.push(__msgBox)
__msgBox.open()
}
}
property Component _inputComponent: Component {
InputDialog {
id: __input
property Component _inputComponent: InputDialog {
id: __input
onClosed: {
var index = _popups.indexOf(__input);
if(index > -1) {
__input.destroy();
_dialogPresenter._popups.splice(index, 1);
}
onClosed: {
var index = _popups.indexOf(__input);
if(index > -1) {
__input.destroy();
_dialogPresenter._popups.splice(index, 1);
}
}
Component.onCompleted: {
_popups.push(__input)
__input.open()
}
Component.onCompleted: {
_popups.push(__input)
__input.open()
}
}
property Component _fileComponent: Component {
FileDialog {
id: __file
property Component _fileComponent: FileDialog {
id: __file
onClosed: {
var index = _popups.indexOf(__file);
if(index > -1) {
__file.destroy();
_dialogPresenter._popups.splice(index, 1);
}
onClosed: {
var index = _popups.indexOf(__file);
if(index > -1) {
__file.destroy();
_dialogPresenter._popups.splice(index, 1);
}
}
Component.onCompleted: {
_popups.push(__file)
__file.open()
}
Component.onCompleted: {
_popups.push(__file)
__file.open()
}
}
property Component _folderComponent: Component {
FolderDialog {
id: __folder
property Component _folderComponent: FolderDialog {
id: __folder
onClosed: {
var index = _popups.indexOf(__folder);
if(index > -1) {
__folder.destroy();
_dialogPresenter._popups.splice(index, 1);
}
onClosed: {
var index = _popups.indexOf(__folder);
if(index > -1) {
__folder.destroy();
_dialogPresenter._popups.splice(index, 1);
}
}
Component.onCompleted: {
_popups.push(__folder)
__folder.open()
}
Component.onCompleted: {
_popups.push(__folder)
__folder.open()
}
}

39
src/imports/mvvmquick/PresentingDrawer.qml

@ -0,0 +1,39 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
Drawer {
id: _presentingDrawer
width: Math.min(300, parent.width - 24);
height: parent.height - y
property Item _mainChild: null
function toggle() {
if(visible)
close();
else
open();
}
function presentDrawerContent(item) {
if(_mainChild)
_mainChild.destroy();
item.parent = _presentingDrawer; //TODO test
_mainChild = item;
return true;
}
function closeAction() {
if(_mainChild && typeof _mainChild.closeAction == "function") {
if(_mainChild.closeAction())
return true;
}
if(visible) {
close();
return true;
} else
return false;
}
}

15
src/imports/mvvmquick/PresentingStackView.qml

@ -8,10 +8,17 @@ StackView {
property int opDuration: 75
function presentItem(item) {
if(push(item))
return true;
else
return false;
if(item.presentAsRoot) { //TODO document
if(push(item))
return true;
else
return false;
} else {
if(replace(null, item))
return true;
else
return false;
}
}
function safePop(item, operation) {

23
src/imports/mvvmquick/QtMvvmApp.qml

@ -8,6 +8,8 @@ ApplicationWindow {
width: 360
height: 520
readonly property alias drawer: _drawerLoader.item
PresenterProgress {
id: _rootProgress
z: _rootStack.empty ? 10 : -10
@ -18,6 +20,15 @@ ApplicationWindow {
anchors.fill: parent
}
Loader {
id: _drawerLoader
active: false
asynchronous: false
sourceComponent: PresentingDrawer {
id: _rootDrawer
}
}
PopupPresenter {
id: _rootPopup
rootItem: _root.contentItem
@ -29,6 +40,9 @@ ApplicationWindow {
}
function presentDrawerContent(item) {
if(!_drawerLoader.item)
_drawerLoader.active = true;
_drawerLoader.item.presentDrawerContent(item);
return false
}
@ -44,11 +58,20 @@ ApplicationWindow {
return _rootDialogs.showDialog(config, result);
}
function toggleDrawer() {
if(_drawerLoader.item)
_drawerLoader.item.toggle();
else
console.warn("No drawer like view active. Cannot toggle drawer");
}
Component.onCompleted: QuickPresenter.qmlPresenter = _root
onClosing: {
var closed = false;
if(!closed && _drawerLoader.item)
closed = _drawerLoader.item.closeAction();
if(!closed)
closed = _rootDialogs.closeAction();
if(!closed)

9
src/imports/mvvmquick/mvvmquick.pro

@ -25,7 +25,11 @@ QML_FILES += \
TintIcon.qml \
MsgBoxBase.qml \
MsgBox.qml \
InputDialog.qml
InputDialog.qml \
PresentingDrawer.qml
RESOURCES += \
qtmvvmquick_plugin.qrc
OTHER_FILES += qmldir
@ -53,6 +57,3 @@ generate_qmltypes {
mfirst.depends += qmltypes
QMAKE_EXTRA_TARGETS += mfirst
}
RESOURCES += \
qtmvvmquick_plugin.qrc

1
src/imports/mvvmquick/plugins.qmltypes

@ -70,6 +70,7 @@ Module {
name: "inputViewFactoryChanged"
Parameter { name: "inputViewFactory"; type: "InputViewFactory"; isPointer: true }
}
Method { name: "toggleDrawer" }
Method {
name: "mimeTypeFilters"
type: "QStringList"

1
src/imports/mvvmquick/qmldir

@ -12,5 +12,6 @@ PresenterProgress 1.0 PresenterProgress.qml
PresentingStackView 1.0 PresentingStackView.qml
PopupPresenter 1.0 PopupPresenter.qml
DialogPresenter 1.0 DialogPresenter.qml
PresentingDrawer 1.0 PresentingDrawer.qml
QtMvvmApp 1.0 QtMvvmApp.qml

10
src/imports/mvvmquick/qqmlquickpresenter.cpp

@ -54,6 +54,16 @@ QStringList QQmlQuickPresenter::mimeTypeFilters(const QStringList &mimeTypes) co
return filters;
}
void QQmlQuickPresenter::toggleDrawer()
{
if(!_qmlPresenter) {
qmlWarning(this).space() << "No QML-Presenter registered! Unable to toggle drawer";
return;
}
QMetaObject::invokeMethod(_qmlPresenter, "toggleDrawer");
}
void QQmlQuickPresenter::present(ViewModel *viewModel, const QVariantHash &params, const QUrl &viewUrl, QPointer<ViewModel> parent)
{
auto component = _componentCache.object(viewUrl);

3
src/imports/mvvmquick/qqmlquickpresenter.h

@ -40,6 +40,9 @@ public:
Q_INVOKABLE QStringList mimeTypeFilters(const QStringList &mimeTypes) const;
public Q_SLOTS:
void toggleDrawer();
Q_SIGNALS:
void qmlPresenterChanged(QObject* qmlPresenter);
void viewLoadingChanged(bool viewLoading);

Loading…
Cancel
Save