mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-24 07:46:20 +00:00
Added GUI for widget adding.
This commit is contained in:
parent
038aa26e84
commit
1e84771ba0
12 changed files with 246 additions and 5 deletions
|
@ -60,6 +60,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR
|
|||
nelgui_widget.h
|
||||
new_property_widget.h
|
||||
new_widget_widget.h
|
||||
add_widget_widget.h
|
||||
editor_selection_watcher.h
|
||||
editor_message_processor.h
|
||||
)
|
||||
|
@ -76,6 +77,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_UIS
|
|||
project_window.ui
|
||||
new_property_widget.ui
|
||||
new_widget_widget.ui
|
||||
add_widget_widget.ui
|
||||
)
|
||||
|
||||
SET(QT_USE_QTGUI TRUE)
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
#include "add_widget_widget.h"
|
||||
#include "widget_info_tree.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <QMessageBox>
|
||||
|
||||
namespace GUIEditor
|
||||
{
|
||||
|
||||
AddWidgetWidget::AddWidgetWidget( QWidget *parent ) :
|
||||
QWidget( parent )
|
||||
{
|
||||
setupUi( this );
|
||||
setupConnections();
|
||||
}
|
||||
|
||||
AddWidgetWidget::~AddWidgetWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void AddWidgetWidget::setCurrentGroup( const QString &g )
|
||||
{
|
||||
groupEdit->setText( g );
|
||||
}
|
||||
|
||||
void AddWidgetWidget::setupWidgetInfo( const CWidgetInfoTree *tree )
|
||||
{
|
||||
std::vector< std::string > names;
|
||||
tree->getNames( names, false );
|
||||
|
||||
widgetCB->clear();
|
||||
|
||||
std::sort( names.begin(), names.end() );
|
||||
|
||||
std::vector< std::string >::const_iterator itr = names.begin();
|
||||
while( itr != names.end() )
|
||||
{
|
||||
widgetCB->addItem( QString( itr->c_str() ) );
|
||||
++itr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AddWidgetWidget::setupConnections()
|
||||
{
|
||||
connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( close() ) );
|
||||
connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) );
|
||||
}
|
||||
|
||||
void AddWidgetWidget::onAddClicked()
|
||||
{
|
||||
if( nameEdit->text().isEmpty() )
|
||||
{
|
||||
QMessageBox::warning( NULL,
|
||||
tr( "WARNING" ),
|
||||
tr( "You need to specify a name for your new widget!" ),
|
||||
QMessageBox::Ok );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef ADD_WIDGET_WIDGET_H
|
||||
#define ADD_WIDGET_WIDGET_H
|
||||
|
||||
#include "ui_add_widget_widget.h"
|
||||
|
||||
namespace GUIEditor
|
||||
{
|
||||
class CWidgetInfoTree;
|
||||
|
||||
class AddWidgetWidget : public QWidget, public Ui::AddWidgetWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AddWidgetWidget( QWidget *parent = NULL );
|
||||
~AddWidgetWidget();
|
||||
|
||||
void setCurrentGroup( const QString &g );
|
||||
void setupWidgetInfo( const CWidgetInfoTree *tree );
|
||||
|
||||
private:
|
||||
void setupConnections();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onAddClicked();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AddWidgetWidget</class>
|
||||
<widget class="QWidget" name="AddWidgetWidget">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>318</width>
|
||||
<height>132</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Add new widget</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Group</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="groupEdit">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Widget</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="widgetCB"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="nameEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="addButton">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="cancelButton">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -43,6 +43,7 @@
|
|||
#include "nelgui_widget.h"
|
||||
#include "editor_selection_watcher.h"
|
||||
#include "editor_message_processor.h"
|
||||
#include "add_widget_widget.h"
|
||||
|
||||
namespace GUIEditor
|
||||
{
|
||||
|
@ -61,6 +62,7 @@ namespace GUIEditor
|
|||
linkList = new LinkList;
|
||||
procList = new ProcList;
|
||||
projectWindow = new ProjectWindow;
|
||||
addWidgetWidget = new AddWidgetWidget;
|
||||
connect( projectWindow, SIGNAL( projectFilesChanged() ), this, SLOT( onProjectFilesChanged() ) );
|
||||
viewPort = new NelGUIWidget;
|
||||
setCentralWidget( viewPort );
|
||||
|
@ -76,6 +78,7 @@ namespace GUIEditor
|
|||
parser.setWidgetInfoTree( widgetInfoTree );
|
||||
parser.parseGUIWidgets();
|
||||
widgetProps->setupWidgetInfo( widgetInfoTree );
|
||||
addWidgetWidget->setupWidgetInfo( widgetInfoTree );
|
||||
|
||||
QDockWidget *dock = new QDockWidget( "Widget Hierarchy", this );
|
||||
dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
|
||||
|
@ -95,6 +98,7 @@ namespace GUIEditor
|
|||
viewPort->init();
|
||||
|
||||
connect( viewPort, SIGNAL( guiLoadComplete() ), this, SLOT( onGUILoaded() ) );
|
||||
connect( widgetProps, SIGNAL( treeChanged() ), this, SLOT( onTreeChanged() ) );
|
||||
}
|
||||
|
||||
GUIEditorWindow::~GUIEditorWindow()
|
||||
|
@ -119,6 +123,9 @@ namespace GUIEditor
|
|||
delete viewPort;
|
||||
viewPort = NULL;
|
||||
|
||||
delete addWidgetWidget;
|
||||
addWidgetWidget = NULL;
|
||||
|
||||
// no deletion needed for these, since dockwidget owns them
|
||||
hierarchyView = NULL;
|
||||
propBrowser = NULL;
|
||||
|
@ -309,6 +316,20 @@ namespace GUIEditor
|
|||
connect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), &browserCtrl, SLOT( onSelectionChanged( std::string& ) ) );
|
||||
}
|
||||
|
||||
void GUIEditorWindow::onAddWidgetClicked()
|
||||
{
|
||||
QString g;
|
||||
hierarchyView->getCurrentGroup( g );
|
||||
|
||||
addWidgetWidget->setCurrentGroup( g );
|
||||
addWidgetWidget->show();
|
||||
}
|
||||
|
||||
void GUIEditorWindow::onTreeChanged()
|
||||
{
|
||||
addWidgetWidget->setupWidgetInfo( widgetInfoTree );
|
||||
}
|
||||
|
||||
void GUIEditorWindow::createMenus()
|
||||
{
|
||||
Core::MenuManager *mm = Core::ICore::instance()->menuManager();
|
||||
|
@ -352,6 +373,10 @@ namespace GUIEditor
|
|||
a = new QAction( "Project Window", this );
|
||||
connect( a, SIGNAL( triggered( bool ) ), projectWindow, SLOT( show() ) );
|
||||
m->addAction( a );
|
||||
|
||||
a = new QAction( "Add Widget", this );
|
||||
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onAddWidgetClicked() ) );
|
||||
m->addAction( a );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace GUIEditor
|
|||
class NelGUIWidget;
|
||||
class CWidgetInfoTree;
|
||||
class CEditorMessageProcessor;
|
||||
class AddWidgetWidget;
|
||||
|
||||
class GUIEditorWindow: public QMainWindow
|
||||
{
|
||||
|
@ -60,6 +61,8 @@ public Q_SLOTS:
|
|||
private Q_SLOTS:
|
||||
void onProjectFilesChanged();
|
||||
void onGUILoaded();
|
||||
void onAddWidgetClicked();
|
||||
void onTreeChanged();
|
||||
|
||||
private:
|
||||
void createMenus();
|
||||
|
@ -80,6 +83,7 @@ private:
|
|||
NelGUIWidget *viewPort;
|
||||
CWidgetInfoTree *widgetInfoTree;
|
||||
CEditorMessageProcessor *messageProcessor;
|
||||
AddWidgetWidget *addWidgetWidget;
|
||||
|
||||
CPropBrowserCtrl browserCtrl;
|
||||
QString currentProject;
|
||||
|
|
|
@ -187,6 +187,38 @@ namespace GUIEditor
|
|||
widgetHierarchyMap.erase( itr );
|
||||
}
|
||||
|
||||
void WidgetHierarchy::getCurrentGroup( QString &g )
|
||||
{
|
||||
std::string s = CWidgetManager::getInstance()->getCurrentEditorSelection();
|
||||
if( s.empty() )
|
||||
{
|
||||
g = "";
|
||||
return;
|
||||
}
|
||||
|
||||
NLGUI::CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( s );
|
||||
if( e == NULL )
|
||||
{
|
||||
g = "";
|
||||
return;
|
||||
}
|
||||
|
||||
if( e->isGroup() )
|
||||
{
|
||||
g = e->getId().c_str();
|
||||
return;
|
||||
}
|
||||
|
||||
NLGUI::CInterfaceGroup *p = e->getParent();
|
||||
if( p == NULL )
|
||||
{
|
||||
g = "";
|
||||
return;
|
||||
}
|
||||
|
||||
g = p->getId().c_str();
|
||||
}
|
||||
|
||||
void WidgetHierarchy::onGUILoaded()
|
||||
{
|
||||
if( masterGroup.empty() )
|
||||
|
|
|
@ -44,6 +44,8 @@ namespace GUIEditor
|
|||
|
||||
void onWidgetDeleted( const std::string &id );
|
||||
|
||||
void getCurrentGroup( QString &g );
|
||||
|
||||
private:
|
||||
void buildHierarchy( QTreeWidgetItem *parent, NLGUI::CInterfaceGroup *group );
|
||||
|
||||
|
|
|
@ -93,11 +93,11 @@ namespace GUIEditor
|
|||
}
|
||||
|
||||
/// Get the node names and put them into the vector
|
||||
void getNames( std::vector< std::string > &v ) const
|
||||
void getNames( std::vector< std::string > &v, bool includeAbstract = true ) const
|
||||
{
|
||||
if( root == NULL )
|
||||
return;
|
||||
root->getNames( v );
|
||||
root->getNames( v, includeAbstract );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -215,11 +215,13 @@ namespace GUIEditor
|
|||
}
|
||||
|
||||
/// Get the node names and put them into the vector
|
||||
void getNames( std::vector< std::string > &v ) const
|
||||
void getNames( std::vector< std::string > &v, bool includeAbstract = true ) const
|
||||
{
|
||||
v.push_back( info.name );
|
||||
if( !info.isAbstract || ( info.isAbstract && includeAbstract ) )
|
||||
v.push_back( info.name );
|
||||
|
||||
for( std::vector< CWidgetInfoTreeNode* >::const_iterator itr = children.begin(); itr != children.end(); ++itr )
|
||||
( *itr )->getNames( v );
|
||||
( *itr )->getNames( v, includeAbstract );
|
||||
}
|
||||
|
||||
/// Accepts a visitor to itself and to the children nodes
|
||||
|
|
|
@ -84,6 +84,7 @@ namespace GUIEditor{
|
|||
return;
|
||||
|
||||
tree->removeNode( widgetName.toUtf8().constData() );
|
||||
Q_EMIT treeChanged();
|
||||
widgetPropTree->clear();
|
||||
buildWidgetList();
|
||||
}
|
||||
|
@ -156,6 +157,7 @@ namespace GUIEditor{
|
|||
void CWidgetProperties::onWidgetAdded()
|
||||
{
|
||||
buildWidgetList();
|
||||
Q_EMIT treeChanged();
|
||||
}
|
||||
|
||||
void CWidgetProperties::buildWidgetList()
|
||||
|
|
|
@ -74,6 +74,9 @@ namespace GUIEditor
|
|||
CWidgetInfoTree *tree;
|
||||
NewPropertyWidget *newPropertyWidget;
|
||||
NewWidgetWidget *newWidgetWidget;
|
||||
|
||||
Q_SIGNALS:
|
||||
void treeChanged();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue