Browse Source

added simple drawer logic

pull/2/head
Skycoder42 7 years ago
parent
commit
aa81173335
  1. 4
      examples/mvvmquick/SampleQuick/SampleView.qml
  2. 16
      src/imports/mvvmquick/DialogPresenter.qml
  3. 39
      src/imports/mvvmquick/PresentingDrawer.qml
  4. 7
      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")

16
src/imports/mvvmquick/DialogPresenter.qml

@ -28,8 +28,7 @@ QtObject {
} }
property var _popups: [] property var _popups: []
property Component _msgBoxComponent: Component { property Component _msgBoxComponent: MsgBox {
MsgBox {
id: __msgBox id: __msgBox
onClosed: { onClosed: {
@ -45,10 +44,8 @@ QtObject {
__msgBox.open() __msgBox.open()
} }
} }
}
property Component _inputComponent: Component { property Component _inputComponent: InputDialog {
InputDialog {
id: __input id: __input
onClosed: { onClosed: {
@ -64,10 +61,8 @@ QtObject {
__input.open() __input.open()
} }
} }
}
property Component _fileComponent: Component { property Component _fileComponent: FileDialog {
FileDialog {
id: __file id: __file
onClosed: { onClosed: {
@ -83,10 +78,8 @@ QtObject {
__file.open() __file.open()
} }
} }
}
property Component _folderComponent: Component { property Component _folderComponent: FolderDialog {
FolderDialog {
id: __folder id: __folder
onClosed: { onClosed: {
@ -102,7 +95,6 @@ QtObject {
__folder.open() __folder.open()
} }
} }
}
function createMsgBox(config, result) { function createMsgBox(config, result) {
var props = config.viewProperties; var props = config.viewProperties;

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;
}
}

7
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(item.presentAsRoot) { //TODO document
if(push(item)) if(push(item))
return true; return true;
else else
return false; 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