1
1
import QtQuick 2.10
2
2
import QtQuick.Controls 2.3
3
- import de.skycoder42.QtMvvm.Core 1.0
4
- import de.skycoder42.QtMvvm.Quick 1.0
3
+ import de.skycoder42.QtMvvm.Core 1.1
4
+ import de.skycoder42.QtMvvm.Quick 1.1
5
5
6
6
/*! @brief A presentation helper that can present generic mvvm dialogs
7
7
*
@@ -56,6 +56,22 @@ QtObject {
56
56
*/
57
57
property Item rootItem: null
58
58
59
+ /* ! @brief Checks if the presenter has no open dialogs
60
+ *
61
+ * @default{`false`}
62
+ *
63
+ * As soon as there is at least a single open dialog, this property gets false. Only when
64
+ * no dialogs are show is it true. This property is always updated from within the
65
+ * closeAction() method, so you can be shure that it is true after the last dialog was
66
+ * closed that way.
67
+ *
68
+ * @accessors{
69
+ * @memberAc{empty}
70
+ * @notifyAc{emptyChanged()}
71
+ * }
72
+ */
73
+ readonly property bool empty: _popups .length == 0
74
+
59
75
/* ! @brief The primary presenting method to present a dialog
60
76
*
61
77
* @param type:MessageConfig config The message configuration to create a dialog of
@@ -67,12 +83,16 @@ QtObject {
67
83
* @sa QtMvvm::MessageConfig, QtMvvm::MessageResult, QtMvvmApp::showDialog
68
84
*/
69
85
function showDialog (config , result ) {
70
- if (config .type == " msgbox" )
86
+ if (config .type === " msgbox" )
71
87
return createMsgBox (config, result)
72
- else if (config .type == " input" )
88
+ else if (config .type === " input" )
73
89
return createInput (config, result)
74
- else if (config .type == " file" )
90
+ else if (config .type === " file" )
75
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)
76
96
else
77
97
return false ;
78
98
}
@@ -88,6 +108,10 @@ QtObject {
88
108
*/
89
109
function closeAction () {
90
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
+ }
91
115
_popups[_popups .length - 1 ].reject ();
92
116
return true ;
93
117
} else
@@ -168,6 +192,24 @@ QtObject {
168
192
}
169
193
}
170
194
195
+ // ! Internal property
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
+
171
213
/* ! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeMessageBox
172
214
*
173
215
* @param type:MessageConfig config The message configuration to create a dialog of
@@ -225,10 +267,49 @@ QtObject {
225
267
props[" msgConfig" ] = config;
226
268
props[" msgResult" ] = result;
227
269
var incubator = null ;
228
- if (config .subType == " folder" )
270
+ if (config .subType === " folder" )
229
271
incubator = _folderComponent .incubateObject (rootItem, props, Qt .Synchronous );
230
272
else
231
273
incubator = _fileComponent .incubateObject (rootItem, props, Qt .Synchronous );
232
274
return incubator .status !== Component .Error ;
233
275
}
276
+
277
+ /* ! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeColorDialog
278
+ *
279
+ * @param type:MessageConfig config The message configuration to create a dialog of
280
+ * @param type:MessageResult result The result to report the dialog result to
281
+ * @return type:bool `true` if successfully presented, `false` if not
282
+ *
283
+ * Used by the showDialog() method to show a dialog of the color dialog type. You can use
284
+ * it yourself if you want to extend the presenter and still keep the default dialogs it
285
+ * supports.
286
+ *
287
+ * @sa DialogPresenter::showDialog
288
+ */
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
+
296
+ /* ! @brief Method present a dialog of the QtMvvm::MessageConfig::TypeProgressDialog
297
+ *
298
+ * @param type:MessageConfig config The message configuration to create a dialog of
299
+ * @param type:MessageResult result The result to report the dialog result to
300
+ * @return type:bool `true` if successfully presented, `false` if not
301
+ *
302
+ * Used by the showDialog() method to show a dialog of the progress dialog type. You can
303
+ * use it yourself if you want to extend the presenter and still keep the default dialogs
304
+ * it supports.
305
+ *
306
+ * @sa DialogPresenter::showDialog
307
+ */
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
+ }
234
315
}
0 commit comments