QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
DialogPresenter.qml
1 import QtQuick 2.10
2 import QtQuick.Controls 2.3
3 import de.skycoder42.QtMvvm.Core 1.1
4 import de.skycoder42.QtMvvm.Quick 1.1
5 
40 QtObject {
41  id: _dialogPresenter
42 
57  property Item rootItem: null
58 
73  readonly property bool empty: _popups.length == 0
74 
85  function showDialog(config, result) {
86  if(config.type === "msgbox")
87  return createMsgBox(config, result)
88  else if(config.type === "input")
89  return createInput(config, result)
90  else if(config.type === "file")
91  return createFile(config, result)
92  else if(config.type === "color")
93  return createColor(config, result)
94  else if(config.type === "progress")
95  return createProgress(config, result)
96  else
97  return false;
98  }
99 
109  function closeAction() {
110  if(_popups.length > 0) {
111  if(typeof _popups[_popups.length - 1].closeAction == "function") {
112  if(_popups[_popups.length - 1].closeAction())
113  return true;
114  }
115  _popups[_popups.length - 1].reject();
116  return true;
117  } else
118  return false;
119  }
120 
122  property var _popups: []
124  property Component _msgBoxComponent: MsgBox {
125  id: __msgBox
126 
127  onClosed: {
128  var index = _popups.indexOf(__msgBox);
129  if(index > -1) {
130  __msgBox.destroy();
131  _dialogPresenter._popups.splice(index, 1);
132  }
133  }
134 
135  Component.onCompleted: {
136  _popups.push(__msgBox)
137  __msgBox.open()
138  }
139  }
140 
142  property Component _inputComponent: InputDialog {
143  id: __input
144 
145  onClosed: {
146  var index = _popups.indexOf(__input);
147  if(index > -1) {
148  __input.destroy();
149  _dialogPresenter._popups.splice(index, 1);
150  }
151  }
152 
153  Component.onCompleted: {
154  _popups.push(__input)
155  __input.open()
156  }
157  }
158 
160  property Component _fileComponent: FileDialog {
161  id: __file
162 
163  onClosed: {
164  var index = _popups.indexOf(__file);
165  if(index > -1) {
166  __file.destroy();
167  _dialogPresenter._popups.splice(index, 1);
168  }
169  }
170 
171  Component.onCompleted: {
172  _popups.push(__file)
173  __file.open()
174  }
175  }
176 
178  property Component _folderComponent: FolderDialog {
179  id: __folder
180 
181  onClosed: {
182  var index = _popups.indexOf(__folder);
183  if(index > -1) {
184  __folder.destroy();
185  _dialogPresenter._popups.splice(index, 1);
186  }
187  }
188 
189  Component.onCompleted: {
190  _popups.push(__folder)
191  __folder.open()
192  }
193  }
194 
196  property Component _progressComponent: ProgressDialog {
197  id: __progress
198 
199  onClosed: {
200  var index = _popups.indexOf(__progress);
201  if(index > -1) {
202  __progress.destroy();
203  _dialogPresenter._popups.splice(index, 1);
204  }
205  }
206 
207  Component.onCompleted: {
208  _popups.push(__progress)
209  __progress.open()
210  }
211  }
212 
225  function createMsgBox(config, result) {
226  var props = config.viewProperties;
227  props["msgConfig"] = config;
228  props["msgResult"] = result;
229  var incubator = _msgBoxComponent.incubateObject(rootItem, props, Qt.Synchronous);
230  return incubator.status !== Component.Error;
231  }
232 
245  function createInput(config, result) {
246  var props = config.viewProperties;
247  props["msgConfig"] = config;
248  props["msgResult"] = result;
249  var incubator = _inputComponent.incubateObject(rootItem, props, Qt.Synchronous);
250  return incubator.status !== Component.Error;
251  }
252 
265  function createFile(config, result) {
266  var props = config.viewProperties;
267  props["msgConfig"] = config;
268  props["msgResult"] = result;
269  var incubator = null;
270  if(config.subType === "folder")
271  incubator = _folderComponent.incubateObject(rootItem, props, Qt.Synchronous);
272  else
273  incubator = _fileComponent.incubateObject(rootItem, props, Qt.Synchronous);
274  return incubator.status !== Component.Error;
275  }
276 
289  function createColor(config, result) {
290  config.viewProperties["alpha"] = (config.subType === "argb");
291  config.type = "input";
292  config.subType = "QColor";
293  return createInput(config, result);
294  }
295 
308  function createProgress(config, result) {
309  var props = config.viewProperties;
310  props["msgConfig"] = config;
311  props["msgResult"] = result;
312  var incubator = _progressComponent.incubateObject(rootItem, props, Qt.Synchronous);
313  return incubator.status !== Component.Error;
314  }
315 }
The QML import for the QtMvvmCore QML module.
Definition: qqmlcoreapp.h:9
The QML import for the QtMvvmQuick QML module.
Definition: ActionButton.qml:4
void open()
Opens the file chooser by sending the show intent.
A folder dialog implementation based on the labs folder dialog.
A file dialog implementation based on the labs file dialog.
Definition: FileDialog.qml:19