From df5a2cb5fb22bc1ac80cfce61f245de95c629e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Fri, 8 Mar 2013 15:07:13 +0000 Subject: [PATCH] Additional scipting function to jump out of loop git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16489 383ad7c9-94d9-4d36-a494-682f7c89f535 --- VsiMetadata/dialogs.xml | 22 ++++++++++++++++++++++ vsiPlugin.cc | 22 ++++++++++++++++++++++ vsiPlugin.hh | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/VsiMetadata/dialogs.xml b/VsiMetadata/dialogs.xml index 9e91c63..86c64fa 100644 --- a/VsiMetadata/dialogs.xml +++ b/VsiMetadata/dialogs.xml @@ -119,5 +119,27 @@ + + Widgets and UI + Continue box + Deliver true until the user clicks on the stop button + true + + Displayed message + Displayed message. + Stop? + + + + continue + Delivers true until stop button is pressed. + + + + var dialog_stop_box_message = [input="message"]; + + [output="continue"] = visualscripting.continueBox(dialog_stop_box_message); + + diff --git a/vsiPlugin.cc b/vsiPlugin.cc index dc2cae6..caf8112 100644 --- a/vsiPlugin.cc +++ b/vsiPlugin.cc @@ -257,4 +257,26 @@ bool VsiPlugin::questionBox (QString _message) return false; } +/// Non blocking box which can be used inside scripting loops to stop on clicks +bool VsiPlugin::continueBox (QString _message) +{ + static QContinueBox* msgBox = NULL; + + if ( !msgBox ) { + msgBox = new QContinueBox(_message); + msgBox->show(); + } else { + + if ( msgBox->continueBox() ) { + return true; + } else { + delete msgBox; + msgBox = NULL; + return false; + } + } + + return true; +} + //------------------------------------------------------------------------------ diff --git a/vsiPlugin.hh b/vsiPlugin.hh index 92247cb..6d1f79a 100644 --- a/vsiPlugin.hh +++ b/vsiPlugin.hh @@ -109,6 +109,9 @@ class VsiPlugin : public QObject, BaseInterface, MenuInterface, ScriptInterface, /// Scripting function, that displays a Yes/No message box bool questionBox (QString _message); + /// Shows a non blocking stop box for use inside loops + bool continueBox(QString _message); + QString version () { return QString("1.0"); }; private slots: @@ -133,8 +136,41 @@ class VsiPlugin : public QObject, BaseInterface, MenuInterface, ScriptInterface, VSI::BaseWidget *baseWidget_; }; +//============================================================================= + +class QContinueBox : public QWidget { + Q_OBJECT + +public: + QContinueBox(QString _message,QWidget* _parent = 0) : + QWidget(_parent), + continue_(true) + { + QPushButton* stopButton = new QPushButton("Stop",this); + QHBoxLayout* layout = new QHBoxLayout(this); + + this->setWindowTitle(_message); + + layout->addWidget(stopButton); + this->setLayout(layout); + + connect(stopButton,SIGNAL(clicked()), this, SLOT(clicked())); + } + +public slots: + void clicked( ) { + continue_ = false; + } + +public: + bool continueBox() { return continue_; }; + +private: + bool continue_; +}; + //============================================================================= //============================================================================= -#endif \ No newline at end of file +#endif -- GitLab