Commit e99520b8 authored by Jan Möbius's avatar Jan Möbius

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
parent 1a60e697
......@@ -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(","));
}
// //-----------------------------------------------------------------------------
......
......@@ -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_;
......
......@@ -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());
......
......@@ -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 <http://www.gnu.org/licenses/>.
//
......@@ -43,8 +43,10 @@
// -------------------- mview
#include "Core.hh"
#include <QtUiTools/QUiLoader>
//== 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<Core*>(calleeData.toQObject());
widget->scriptLogFunction(result);
widget->scriptLogFunction(result);
return engine->undefinedValue();
}
......@@ -11,6 +11,7 @@ openmesh()
glut()
glew()
openmp()
qt()
DIRECTORIES = ../ ../Core ../Logging \
../Scripting ../Scripting/scriptPrototypes ../Scripting/scriptWrappers ../SimpleOpt \
......
......@@ -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<int> 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
......
......@@ -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 );
/** @} */
//===========================================================================
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment