|
@@ -922,6 +922,43 @@ QScriptValue QWidget_activateWindow(QScriptContext *context,
|
922
|
922
|
return QScriptValue();
|
923
|
923
|
}
|
924
|
924
|
|
|
925
|
+@* Scripting QMessageBox.
|
|
926
|
+
|
|
927
|
+\noindent Some features require that \pn{} pauses an operation until further
|
|
928
|
+information can be obtained. An example of this is discretionary validation
|
|
929
|
+where input is checked and if it seems unlikely but not impossible to be
|
|
930
|
+correct a dialog should come up asking if that input is correct. If it is not,
|
|
931
|
+the operation should be cancelled and the person using \pn{} should be allowed
|
|
932
|
+to correct the information and try again.
|
|
933
|
+
|
|
934
|
+For this use case, it is not necessary to fully expose the |QMessageBox| class.
|
|
935
|
+Instead, it is enough to provide a function that will raise an appropriate
|
|
936
|
+message and return the selected action.
|
|
937
|
+
|
|
938
|
+@<Function prototypes for scripting@>=
|
|
939
|
+QScriptValue displayWarning(QScriptContext *context, QScriptEngine *engine);
|
|
940
|
+
|
|
941
|
+@ This function is exposed to the host environment.
|
|
942
|
+
|
|
943
|
+@<Set up the scripting engine@>=
|
|
944
|
+constructor = engine->newFunction(displayWarning);
|
|
945
|
+engine->globalObject().setProperty("displayWarning", constructor);
|
|
946
|
+
|
|
947
|
+@ The function takes some arguments.
|
|
948
|
+
|
|
949
|
+@<Functions for scripting@>=
|
|
950
|
+QScriptValue displayWarning(QScriptContext *context, QScriptEngine *)
|
|
951
|
+{
|
|
952
|
+ QMessageBox::StandardButton selection = QMessageBox::warning(NULL,
|
|
953
|
+ argument<QString>(0, context),
|
|
954
|
+ argument<QString>(1, context),
|
|
955
|
+ QMessageBox::Ok | QMessageBox::Cancel);
|
|
956
|
+ if(selection == QMessageBox::Ok) {
|
|
957
|
+ return QScriptValue(true);
|
|
958
|
+ }
|
|
959
|
+ return QScriptValue(false);
|
|
960
|
+}
|
|
961
|
+
|
925
|
962
|
@* Scripting QMainWindow.
|
926
|
963
|
|
927
|
964
|
\noindent Rather than directly exposing |QMainWindow| to the scripting engine,
|