From c14d91cfafb416817d2d896045943357710b9ef2 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 25 Jul 2012 09:09:12 +0200 Subject: [PATCH] ADDED: #1471 My work on the link editor so far. Not yet fully implemented. --HG-- branch : gsoc2012-gui-editor --- code/nel/include/nel/gui/interface_parser.h | 11 +++ code/nel/include/nel/gui/link_data.h | 40 +++++++++ code/nel/include/nel/gui/parser.h | 4 + code/nel/src/gui/interface_parser.cpp | 22 +++++ .../src/plugins/gui_editor/CMakeLists.txt | 2 + .../plugins/gui_editor/gui_editor_window.cpp | 15 ++-- .../plugins/gui_editor/gui_editor_window.h | 4 +- .../src/plugins/gui_editor/link_editor.cpp | 49 +++++++++++ .../src/plugins/gui_editor/link_editor.h | 6 ++ .../src/plugins/gui_editor/link_editor.ui | 80 +++++++++--------- .../src/plugins/gui_editor/link_list.cpp | 79 +++++++++++++++++ .../src/plugins/gui_editor/link_list.h | 46 ++++++++++ .../src/plugins/gui_editor/link_list.ui | 84 +++++++++++++++++++ .../src/plugins/gui_editor/nelgui_widget.cpp | 2 + 14 files changed, 391 insertions(+), 53 deletions(-) create mode 100644 code/nel/include/nel/gui/link_data.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.ui diff --git a/code/nel/include/nel/gui/interface_parser.h b/code/nel/include/nel/gui/interface_parser.h index f2c16ebe4..2893adfbf 100644 --- a/code/nel/include/nel/gui/interface_parser.h +++ b/code/nel/include/nel/gui/interface_parser.h @@ -27,6 +27,7 @@ #include "nel/gui/lua_helper.h" #include "nel/gui/proc.h" #include "nel/gui/widget_manager.h" +#include "nel/gui/link_data.h" namespace NLGUI { @@ -324,6 +325,11 @@ namespace NLGUI bool luaInitialized; ISetupOptionCallbackClass *setupCallback; + uint32 linkId; + std::map< uint32, SLinkData > links; + + bool editorMode; + public: void initLUA(); void uninitLUA(); @@ -340,6 +346,11 @@ namespace NLGUI bool hasProc( const std::string &name ) const; bool addProc( const std::string &name ); bool removeProc( const std::string &name ); + + const std::map< uint32, SLinkData >& getLinkMap() const{ return links; } + void addLinkData( const SLinkData &linkData ); + + void setEditorMode( bool b ){ editorMode = b; } }; } diff --git a/code/nel/include/nel/gui/link_data.h b/code/nel/include/nel/gui/link_data.h new file mode 100644 index 000000000..66aac9ced --- /dev/null +++ b/code/nel/include/nel/gui/link_data.h @@ -0,0 +1,40 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +#ifndef LINKDATA_H +#define LINKDATA_H + +#include + +namespace NLGUI +{ + + struct SLinkData + { + public: + std::string parent; + std::string expr; + std::string target; + std::string action; + std::string params; + std::string cond; + }; + + +} + + +#endif diff --git a/code/nel/include/nel/gui/parser.h b/code/nel/include/nel/gui/parser.h index 06fdc4c62..aba7d1f82 100644 --- a/code/nel/include/nel/gui/parser.h +++ b/code/nel/include/nel/gui/parser.h @@ -22,6 +22,7 @@ #include #include "nel/misc/types_nl.h" #include "nel/gui/proc.h" +#include "nel/gui/link_data.h" namespace NLGUI { @@ -71,6 +72,9 @@ namespace NLGUI virtual bool hasProc( const std::string &name ) const = 0; virtual bool addProc( const std::string &name ) = 0; virtual bool removeProc( const std::string &name ) = 0; + virtual void setEditorMode( bool b ) = 0; + virtual const std::map< uint32, SLinkData >& getLinkMap() const = 0; + virtual void addLinkData( const SLinkData &linkData ) = 0; }; } diff --git a/code/nel/src/gui/interface_parser.cpp b/code/nel/src/gui/interface_parser.cpp index 520aec87a..bd9217eb3 100644 --- a/code/nel/src/gui/interface_parser.cpp +++ b/code/nel/src/gui/interface_parser.cpp @@ -200,6 +200,8 @@ namespace NLGUI { luaInitialized = false; cacheUIParsing = false; + linkId = 0; + editorMode = false; setupCallback = NULL; } @@ -991,6 +993,7 @@ namespace NLGUI std::vector targets; ptr = (char*) xmlGetProp (cur, (xmlChar*)"target"); + std::string target = ptr; if (ptr) { CInterfaceLink::splitLinkTargets(std::string((const char*)ptr), parentGroup, targets); @@ -1009,6 +1012,20 @@ namespace NLGUI // create the link CInterfaceLink *il = new CInterfaceLink; il->init(targets, expr, action, params, cond, parentGroup); // init will add 'il' in the list of link present in 'elm' + + if( editorMode ) + { + SLinkData linkData; + linkData.parent = parentGroup->getId(); + linkData.expr = expr; + linkData.target = target; + linkData.action = action; + linkData.cond = cond; + linkData.params = params; + + addLinkData( linkData ); + } + return true; } @@ -2814,5 +2831,10 @@ namespace NLGUI _ProcedureMap.erase( itr ); return true; } + + void CInterfaceParser::addLinkData( const SLinkData &linkData ) + { + links[ ++linkId ] = linkData; + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt index 8b31cce7c..86873ac4d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/CMakeLists.txt @@ -15,6 +15,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR gui_editor_context.h widget_properties.h widget_hierarchy.h + link_list.h link_editor.h proc_list.h proc_editor.h @@ -29,6 +30,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_UIS gui_editor_window.ui widget_properties.ui widget_hierarchy.ui + link_list.ui link_editor.ui proc_list.ui proc_editor.ui diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp index 27c10107f..a4a5b69c2 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.cpp @@ -33,7 +33,7 @@ #include "widget_properties.h" #include "widget_properties_parser.h" #include "widget_hierarchy.h" -#include "link_editor.h" +#include "link_list.h" #include "proc_list.h" #include "project_file_parser.h" #include "project_window.h" @@ -51,7 +51,7 @@ namespace GUIEditor m_ui.setupUi(this); m_undoStack = new QUndoStack(this); widgetProps = new CWidgetProperties; - linkEditor = new LinkEditor; + linkList = new LinkList; procList = new ProcList; projectWindow = new ProjectWindow; connect( projectWindow, SIGNAL( projectFilesChanged() ), this, SLOT( onProjectFilesChanged() ) ); @@ -85,6 +85,7 @@ namespace GUIEditor connect( viewPort, SIGNAL( guiLoadComplete() ), hierarchyView, SLOT( onGUILoaded() ) ); connect( viewPort, SIGNAL( guiLoadComplete() ), procList, SLOT( onGUILoaded() ) ); + connect( viewPort, SIGNAL( guiLoadComplete() ), linkList, SLOT( onGUILoaded() ) ); } GUIEditorWindow::~GUIEditorWindow() @@ -94,8 +95,8 @@ namespace GUIEditor delete widgetProps; widgetProps = NULL; - delete linkEditor; - linkEditor = NULL; + delete linkList; + linkList = NULL; delete procList; procList = NULL; @@ -194,7 +195,7 @@ namespace GUIEditor m->addAction( a ); a = new QAction( "Link Editor", this ); - connect( a, SIGNAL( triggered( bool ) ), linkEditor, SLOT( show() ) ); + connect( a, SIGNAL( triggered( bool ) ), linkList, SLOT( show() ) ); m->addAction( a ); a = new QAction( "Procedure Editor", this ); @@ -204,10 +205,6 @@ namespace GUIEditor a = new QAction( "Project Window", this ); connect( a, SIGNAL( triggered( bool ) ), projectWindow, SLOT( show() ) ); m->addAction( a ); - - a = new QAction( "Clear Viewport", this ); - connect( a, SIGNAL( triggered( bool ) ), viewPort, SLOT( clear() ) ); - m->addAction( a ); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h index d7fe15245..1e3527d19 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/gui_editor_window.h @@ -31,7 +31,7 @@ namespace GUIEditor class CWidgetProperties; class WidgetHierarchy; - class LinkEditor; + class LinkList; class ProcList; class ProjectWindow; class NelGUIWidget; @@ -67,7 +67,7 @@ private: CWidgetProperties *widgetProps; WidgetHierarchy *hierarchyView; QtTreePropertyBrowser *propBrowser; - LinkEditor *linkEditor; + LinkList *linkList; ProcList *procList; ProjectWindow *projectWindow; NelGUIWidget *viewPort; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.cpp index 7a028f649..a0dd8e78e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.cpp @@ -16,6 +16,8 @@ #include "link_editor.h" +#include "nel/gui/interface_group.h" +#include "nel/gui/widget_manager.h" namespace GUIEditor { @@ -23,6 +25,7 @@ namespace GUIEditor QWidget( parent ) { setupUi( this ); + setup(); connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) ); connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) ); } @@ -30,4 +33,50 @@ namespace GUIEditor LinkEditor::~LinkEditor() { } + + void LinkEditor::setup() + { + expressionEdit->clear(); + groupCB->setCheckable( true ); + groupCB->setChecked( false ); + groupCB->setDisabled( true ); + ahCB->setCheckable( true ); + ahCB->setChecked( false ); + ahCB->setDisabled( true ); + ahEdit->clear(); + ahParamEdit->clear(); + ahParamEdit->setDisabled( true ); + } + + void LinkEditor::setLinkId( uint32 linkId ) + { + setup(); + currentLinkId = linkId; + + const std::map< uint32, SLinkData > &linkMap = + CWidgetManager::getInstance()->getParser()->getLinkMap(); + + std::map< uint32, SLinkData >::const_iterator itr = + linkMap.find( currentLinkId ); + + if( itr == linkMap.end() ) + return; + SLinkData data = itr->second; + + expressionEdit->setPlainText( data.expr.c_str() ); + if( !data.target.empty() ) + { + groupCB->setEnabled( true ); + groupCB->setChecked( true ); + ahEdit->setText( data.target.c_str() ); + } + else + { + ahCB->setEnabled( true ); + ahCB->setChecked( true ); + ahEdit->setText( data.action.c_str() ); + ahParamEdit->setEnabled( true ); + ahParamEdit->setText( data.params.c_str() ); + } + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.h index 93b7fb348..ca6286022 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.h @@ -19,6 +19,7 @@ #define LINK_EDITOR_H #include "ui_link_editor.h" +#include "nel/misc/types_nl.h" namespace GUIEditor { @@ -28,6 +29,11 @@ namespace GUIEditor public: LinkEditor( QWidget *parent = NULL ); ~LinkEditor(); + void setup(); + void setLinkId( uint32 linkId ); + + private: + uint32 currentLinkId; }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.ui index e72fe972c..328a85709 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_editor.ui @@ -10,92 +10,88 @@ 0 0 545 - 340 + 348 Link Editor - - + + Expression - + expression - + - When the condition is met + When the expression is evaluated - + - Activate group + Pass result to targeted group(s) - + Run Action Handler - + - Group or action handler + Targeted group(s) or action handler - + Action Handler parameters - - - - - - Qt::Horizontal - - - - 348 - 20 - - - - - - - - OK - - - - - - - Cancel - - - - + + + + Qt::Horizontal + + + + 362 + 20 + + + + + + + + OK + + + + + + + Cancel + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.cpp new file mode 100644 index 000000000..94e808196 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.cpp @@ -0,0 +1,79 @@ +// Object Viewer Qt GUI Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#include "link_list.h" +#include "link_editor.h" +#include "nel/gui/interface_group.h" +#include "nel/gui/widget_manager.h" +#include "nel/gui/link_data.h" +#include +#include + + +namespace GUIEditor +{ + LinkList::LinkList( QWidget *parent ) : + QWidget( parent ) + { + setupUi( this ); + linkEditor = new LinkEditor(); + + connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) ); + connect( editButton, SIGNAL( clicked( bool ) ), this, SLOT( onEditButtonClicked() ) ); + } + + LinkList::~LinkList() + { + delete linkEditor; + } + + void LinkList::onGUILoaded() + { + const std::map< uint32, SLinkData > &linkMap = + CWidgetManager::getInstance()->getParser()->getLinkMap(); + + std::map< uint32, SLinkData >::const_iterator itr; + for( itr = linkMap.begin(); itr != linkMap.end(); ++itr ) + { + QTreeWidgetItem *item = new QTreeWidgetItem( linkTree ); + item->setText( 0, itr->second.parent.c_str() ); + item->setText( 1, itr->second.target.c_str() ); + item->setText( 2, itr->second.action.c_str() ); + item->setData( 3, Qt::UserRole, itr->first ); + linkTree->addTopLevelItem( item ); + } + linkTree->sortByColumn( 0 ); + } + + void LinkList::onEditButtonClicked() + { + + QTreeWidgetItem *item = + linkTree->currentItem(); + if( item == NULL ) + return; + + bool ok; + uint32 id = item->data( 3, Qt::UserRole ).toUInt( &ok ); + if( !ok ) + return; + + linkEditor->setLinkId( id ); + linkEditor->show(); + } +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.h new file mode 100644 index 000000000..ef4111712 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.h @@ -0,0 +1,46 @@ +// Object Viewer Qt GUI Editor plugin +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef LINK_LIST_H +#define LINK_LIST_H + +#include "ui_link_list.h" + +namespace GUIEditor +{ + class LinkEditor; + + class LinkList : public QWidget, public Ui::LinkList + { + Q_OBJECT + public: + LinkList( QWidget *parent = NULL ); + ~LinkList(); + + public Q_SLOTS: + void onGUILoaded(); + + private Q_SLOTS: + void onEditButtonClicked(); + + private: + LinkEditor *linkEditor; + }; +} + +#endif + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.ui new file mode 100644 index 000000000..3e27d63aa --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/link_list.ui @@ -0,0 +1,84 @@ + + + LinkList + + + Qt::ApplicationModal + + + + 0 + 0 + 539 + 353 + + + + LinkList + + + + + + + parent + + + + + target(s) + + + + + action handler + + + + + + + + OK + + + + + + + Qt::Horizontal + + + + 273 + 20 + + + + + + + + Add + + + + + + + Remove + + + + + + + Edit + + + + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp index 6d834bab6..dd491ba57 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/nelgui_widget.cpp @@ -68,6 +68,8 @@ namespace GUIEditor NLGUI::CViewRenderer::setTextContext( getTextContext() ); NLGUI::CViewRenderer::hwCursors = &hwCursors; NLGUI::CViewRenderer::getInstance()->init(); + + CWidgetManager::getInstance()->getParser()->setEditorMode( true ); } bool NelGUIWidget::parse( SProjectFiles &files )