From e99520b846d0f13451f17d8c95beb0d038eb7ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Fri, 5 Dec 2008 13:14:30 +0000 Subject: [PATCH] Changed functions to show/hide toolbox,logger from scripting Added functionality to use a ui file and generate a widget from it in scripting environment git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@3885 383ad7c9-94d9-4d36-a494-682f7c89f535 --- Core/Core.cc | 16 ++++++++----- Core/Core.hh | 17 +++++++++++--- Core/optionHandling.cc | 2 +- Core/scripting.cc | 40 ++++++++++++++++++++++++-------- CoreApp/CoreApp.pro | 1 + widgets/coreWidget/CoreWidget.cc | 19 +++++++++++---- widgets/coreWidget/CoreWidget.hh | 5 +++- 7 files changed, 75 insertions(+), 25 deletions(-) diff --git a/Core/Core.cc b/Core/Core.cc index 28a370a4..362d595d 100644 --- a/Core/Core.cc +++ b/Core/Core.cc @@ -667,16 +667,16 @@ void Core::fullscreen( bool _state ) { //----------------------------------------------------------------------------- -void Core::logger() { +void Core::showLogger(bool _state) { if ( OpenFlipper::Options::gui() ) - coreWidget_->toggleLogger(); + coreWidget_->showLogger( _state ); } //----------------------------------------------------------------------------- -void Core::toolbox() { +void Core::showToolbox( bool _state ) { if ( OpenFlipper::Options::gui() ) - coreWidget_->toggleToolbox(); + coreWidget_->showToolbox(_state); } @@ -965,8 +965,8 @@ void Core::setDescriptions(){ emit setSlotDescription("fullscreen(bool)", "Enable or disable fullscreen mode", QStringList("enabled") , QStringList("Enable or disable fullscreen mode")); - emit setSlotDescription("logger()", "Toggle logging window visibility", QStringList(), QStringList()); - emit setSlotDescription("toolbox()", "Toggle toolbox visibility", QStringList(), QStringList()); + emit setSlotDescription("showLogger(bool)", "Show or hide logger window", QStringList("Show or hide logger window"), QStringList()); + emit setSlotDescription("showToolbox(bool)", "Show or hide toolbox", QStringList("Show or hide the toolbox"), QStringList()); emit setSlotDescription("setDrawMode(QString)", "Set the drawMode", QStringList("DrawMode"), QStringList("the drawMode ( ; separated list )")); emit setSlotDescription("restrictFrameRate(bool)", "Restrict FrameRate to MaxFrameRate", @@ -1002,6 +1002,10 @@ void Core::setDescriptions(){ emit setSlotDescription("loadObject()", "Show the dialog to load an object. (only works if GUI is available)",QStringList(), QStringList()); emit setSlotDescription("loadSettings()", "Show the dialog to load settings. (only works if GUI is available)",QStringList(), QStringList()); emit setSlotDescription("loadSettings(QString)", "load settings from file.",QStringList(), QStringList()); + emit setSlotDescription("createWidget(QString,QString);", "Create a widget from an ui file", + QString("Object name,ui file").split(","), + QString("Name of the new widget in script,ui file to load").split(",")); + } // //----------------------------------------------------------------------------- diff --git a/Core/Core.hh b/Core/Core.hh index 292b4ce1..47f927fa 100644 --- a/Core/Core.hh +++ b/Core/Core.hh @@ -283,10 +283,10 @@ public slots: void fullscreen( bool _state ); /// Hide or show logging window - void logger(); + void showLogger(bool _state); - /// Hide or show toolbox window - void toolbox(); + /// Show or hide toolbox + void showToolbox( bool _state ); /// Set the drawMode ( ; separated list ) void setDrawMode(QString _mode); @@ -584,6 +584,17 @@ private: void setSlotDescription(QString _slotName, QString _slotDescription, QStringList _parameters, QStringList _descriptions); + + public slots: + /** \brief Create an script object from a ui file + * + * This function will load an ui file, set up a qwidget from that and makes it available + * under _objectName for scripting. + * @param _objectName The name in scripting environment used for the new object + * @param _uiFilename ui file to load + */ + void createWidget(QString _objectName, QString _uiFilename); + private : /// Core scripting engine QScriptEngine scriptEngine_; diff --git a/Core/optionHandling.cc b/Core/optionHandling.cc index cbc86964..419dce69 100644 --- a/Core/optionHandling.cc +++ b/Core/optionHandling.cc @@ -69,7 +69,7 @@ void Core::applyOptions(){ coreWidget_->setWindowState( (coreWidget_->windowState() | Qt::WindowFullScreen) ^ Qt::WindowFullScreen); // Logger - coreWidget_->hideLogger( OpenFlipper::Options::hideLogger() ); + coreWidget_->showLogger( !OpenFlipper::Options::hideLogger() ); //animation coreWidget_->examiner_widget_->animation(OpenFlipper::Options::animation()); diff --git a/Core/scripting.cc b/Core/scripting.cc index 567de428..681ff123 100644 --- a/Core/scripting.cc +++ b/Core/scripting.cc @@ -12,12 +12,12 @@ // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // OpenFlipper is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public License // along with OpenFlipper. If not, see . // @@ -43,8 +43,10 @@ // -------------------- mview #include "Core.hh" +#include -//== IMPLEMENTATION ========================================================== + +//== IMPLEMENTATION ========================================================== @@ -57,7 +59,7 @@ void Core::slotExecuteScript( QString _script ) { } void Core::slotGetScriptingEngine( QScriptEngine*& _engine ) { - _engine = &scriptEngine_; + _engine = &scriptEngine_; } void Core::slotGetAllAvailableFunctions( QStringList& _functions ) { @@ -65,11 +67,29 @@ void Core::slotGetAllAvailableFunctions( QStringList& _functions ) { } void Core::scriptLogFunction( QString _output) { - emit scriptLog(_output); + emit scriptLog(_output); +} + +void Core::createWidget(QString _objectName, QString _uiFilename) { + QUiLoader loader; + + QFile uiFile(_uiFilename); + uiFile.open(QIODevice::ReadOnly); + QWidget *ui = loader.load(&uiFile); + uiFile.close(); + + QScriptValue scriptUi = scriptEngine_.newQObject(ui, QScriptEngine::ScriptOwnership); + scriptEngine_.globalObject().setProperty(_objectName, scriptUi); + + + ui->show(); + +// core.createWidget("calc1","/data/home1/moebius/Calculator.ui"); + } //============================================================================= -//== Script Special Functions ================================================= +//== Script Special Functions ================================================= //============================================================================= QScriptValue myPrintFunction(QScriptContext *context, QScriptEngine *engine) @@ -80,13 +100,13 @@ QScriptValue myPrintFunction(QScriptContext *context, QScriptEngine *engine) result.append(" "); result.append(context->argument(i).toString()); } - + // Get the textedit for Output ( Set in Core.cc ) QScriptValue calleeData = context->callee().property("textedit"); Core *widget = qobject_cast(calleeData.toQObject()); - - widget->scriptLogFunction(result); - + + widget->scriptLogFunction(result); + return engine->undefinedValue(); } diff --git a/CoreApp/CoreApp.pro b/CoreApp/CoreApp.pro index bcb0e45b..ffbe9be7 100644 --- a/CoreApp/CoreApp.pro +++ b/CoreApp/CoreApp.pro @@ -11,6 +11,7 @@ openmesh() glut() glew() openmp() +qt() DIRECTORIES = ../ ../Core ../Logging \ ../Scripting ../Scripting/scriptPrototypes ../Scripting/scriptWrappers ../SimpleOpt \ diff --git a/widgets/coreWidget/CoreWidget.cc b/widgets/coreWidget/CoreWidget.cc index f29e0ad9..909d37ac 100644 --- a/widgets/coreWidget/CoreWidget.cc +++ b/widgets/coreWidget/CoreWidget.cc @@ -320,15 +320,15 @@ CoreWidget::toggleLogger() { OpenFlipper::Options::hideLogger( !OpenFlipper::Options::hideLogger() ); // Hide/Show Logger - hideLogger( OpenFlipper::Options::hideLogger() ); + showLogger( !OpenFlipper::Options::hideLogger() ); } /** Hide or show logger */ void -CoreWidget::hideLogger(bool _hide) { +CoreWidget::showLogger(bool _state) { //Hide Logger - if ( _hide ) { + if ( !_state ) { QList wsizes( splitter_->sizes() ); // Remember old size @@ -361,7 +361,18 @@ void CoreWidget::toggleToolbox() { //toggle - OpenFlipper::Options::hideToolbox(!OpenFlipper::Options::hideToolbox()); + showToolbox( OpenFlipper::Options::hideToolbox() ); +} + +//----------------------------------------------------------------------------- + +/** Hide or show toolbox + */ +void +CoreWidget::showToolbox( bool _state ) { + + //toggle + OpenFlipper::Options::hideToolbox( !_state ); if ( OpenFlipper::Options::hideToolbox() ){ //hide all toolWidgets diff --git a/widgets/coreWidget/CoreWidget.hh b/widgets/coreWidget/CoreWidget.hh index 6eaf2870..b4f6ece6 100644 --- a/widgets/coreWidget/CoreWidget.hh +++ b/widgets/coreWidget/CoreWidget.hh @@ -212,11 +212,14 @@ public: void toggleLogger(); /// Change visibility of the logger - void hideLogger(bool _hide); + void showLogger(bool _state); /// Hide or show toolbox area void toggleToolbox(); + /// Show or hide toolbox + void showToolbox( bool _state ); + /** @} */ //=========================================================================== -- GitLab