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

16
src/imports/mvvmquick/DialogPresenter.qml

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