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 property SampleViewModel viewModel: null
header: ActionBar { header: ActionBar {
showMenuButton: false showMenuButton: true
title: qsTr("Sample") title: qsTr("Sample")
onMenuButtonClicked: QuickPresenter.toggleDrawer()
moreMenu: Menu { moreMenu: Menu {
MenuItem { MenuItem {
text: qsTr("Another Input") text: qsTr("Another Input")

98
src/imports/mvvmquick/DialogPresenter.qml

@ -28,79 +28,71 @@ QtObject {
} }
property var _popups: [] property var _popups: []
property Component _msgBoxComponent: Component { property Component _msgBoxComponent: MsgBox {
MsgBox { id: __msgBox
id: __msgBox
onClosed: {
onClosed: { var index = _popups.indexOf(__msgBox);
var index = _popups.indexOf(__msgBox); if(index > -1) {
if(index > -1) { __msgBox.destroy();
__msgBox.destroy(); _dialogPresenter._popups.splice(index, 1);
_dialogPresenter._popups.splice(index, 1);
}
} }
}
Component.onCompleted: { Component.onCompleted: {
_popups.push(__msgBox) _popups.push(__msgBox)
__msgBox.open() __msgBox.open()
}
} }
} }
property Component _inputComponent: Component { property Component _inputComponent: InputDialog {
InputDialog { id: __input
id: __input
onClosed: { onClosed: {
var index = _popups.indexOf(__input); var index = _popups.indexOf(__input);
if(index > -1) { if(index > -1) {
__input.destroy(); __input.destroy();
_dialogPresenter._popups.splice(index, 1); _dialogPresenter._popups.splice(index, 1);
}
} }
}
Component.onCompleted: { Component.onCompleted: {
_popups.push(__input) _popups.push(__input)
__input.open() __input.open()
}
} }
} }
property Component _fileComponent: Component { property Component _fileComponent: FileDialog {
FileDialog { id: __file
id: __file
onClosed: { onClosed: {
var index = _popups.indexOf(__file); var index = _popups.indexOf(__file);
if(index > -1) { if(index > -1) {
__file.destroy(); __file.destroy();
_dialogPresenter._popups.splice(index, 1); _dialogPresenter._popups.splice(index, 1);
}
} }
}
Component.onCompleted: { Component.onCompleted: {
_popups.push(__file) _popups.push(__file)
__file.open() __file.open()
}
} }
} }
property Component _folderComponent: Component { property Component _folderComponent: FolderDialog {
FolderDialog { id: __folder
id: __folder
onClosed: { onClosed: {
var index = _popups.indexOf(__folder); var index = _popups.indexOf(__folder);
if(index > -1) { if(index > -1) {
__folder.destroy(); __folder.destroy();
_dialogPresenter._popups.splice(index, 1); _dialogPresenter._popups.splice(index, 1);
}
} }
}
Component.onCompleted: { Component.onCompleted: {
_popups.push(__folder) _popups.push(__folder)
__folder.open() __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 property int opDuration: 75
function presentItem(item) { function presentItem(item) {
if(push(item)) if(item.presentAsRoot) { //TODO document
return true; if(push(item))
else return true;
return false; else
return false;
} else {
if(replace(null, item))
return true;
else
return false;
}
} }
function safePop(item, operation) { function safePop(item, operation) {

23
src/imports/mvvmquick/QtMvvmApp.qml

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

9
src/imports/mvvmquick/mvvmquick.pro

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

1
src/imports/mvvmquick/plugins.qmltypes

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

1
src/imports/mvvmquick/qmldir

@ -12,5 +12,6 @@ PresenterProgress 1.0 PresenterProgress.qml
PresentingStackView 1.0 PresentingStackView.qml PresentingStackView 1.0 PresentingStackView.qml
PopupPresenter 1.0 PopupPresenter.qml PopupPresenter 1.0 PopupPresenter.qml
DialogPresenter 1.0 DialogPresenter.qml DialogPresenter 1.0 DialogPresenter.qml
PresentingDrawer 1.0 PresentingDrawer.qml
QtMvvmApp 1.0 QtMvvmApp.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; 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) void QQmlQuickPresenter::present(ViewModel *viewModel, const QVariantHash &params, const QUrl &viewUrl, QPointer<ViewModel> parent)
{ {
auto component = _componentCache.object(viewUrl); auto component = _componentCache.object(viewUrl);

3
src/imports/mvvmquick/qqmlquickpresenter.h

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

Loading…
Cancel
Save