mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-27 19:30:54 +00:00
Allow multiselection.
This commit is contained in:
parent
20ccee370b
commit
0aead6db70
13 changed files with 132 additions and 61 deletions
|
@ -15,6 +15,7 @@
|
|||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace NLGUI
|
||||
{
|
||||
|
@ -24,7 +25,7 @@ namespace NLGUI
|
|||
public:
|
||||
|
||||
/// Notifies the watcher about the change
|
||||
virtual void selectionChanged( std::string &newSelection ) = 0;
|
||||
virtual void selectionChanged() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -503,8 +503,15 @@ namespace NLGUI
|
|||
|
||||
IParser* getParser() const{ return parser; }
|
||||
|
||||
std::string& getCurrentEditorSelection(){ return currentEditorSelection; }
|
||||
void setCurrentEditorSelection( const std::string &name );
|
||||
/// Retrieves the Id of the currently selected widgets
|
||||
void getEditorSelection( std::vector< std::string > &selection );
|
||||
|
||||
/// Adds the widget with the specified Id to the selected widgets
|
||||
void selectWidget( const std::string &name );
|
||||
|
||||
/// Clears the selection
|
||||
void clearEditorSelection();
|
||||
|
||||
void notifySelectionWatchers();
|
||||
void registerSelectionWatcher( IEditorSelectionWatcher *watcher );
|
||||
void unregisterSelectionWatcher( IEditorSelectionWatcher *watcher );
|
||||
|
@ -519,6 +526,7 @@ namespace NLGUI
|
|||
|
||||
void setGroupSelection( bool b ){ groupSelection = b; }
|
||||
bool unGroupSelection();
|
||||
void setMultiSelection( bool b ){ multiSelection = b; }
|
||||
|
||||
private:
|
||||
CWidgetManager();
|
||||
|
@ -611,9 +619,9 @@ namespace NLGUI
|
|||
std::vector< IEditorSelectionWatcher* > selectionWatchers;
|
||||
std::vector< IWidgetWatcher* > widgetWatchers;
|
||||
|
||||
|
||||
std::string currentEditorSelection;
|
||||
std::vector< std::string > editorSelection;
|
||||
bool groupSelection;
|
||||
bool multiSelection;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace NLGUI
|
|||
{
|
||||
if( editorMode )
|
||||
{
|
||||
CWidgetManager::getInstance()->setCurrentEditorSelection( getId() );
|
||||
CWidgetManager::getInstance()->selectWidget( getId() );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2077,9 +2077,9 @@ namespace NLGUI
|
|||
|
||||
if( CInterfaceElement::getEditorMode() )
|
||||
{
|
||||
if( !currentEditorSelection.empty() )
|
||||
for( int i = 0; i < editorSelection.size(); i++ )
|
||||
{
|
||||
CInterfaceElement *e = getElementFromId( currentEditorSelection );
|
||||
CInterfaceElement *e = getElementFromId( editorSelection[ i ] );
|
||||
if( e != NULL )
|
||||
e->drawHighlight();
|
||||
}
|
||||
|
@ -2478,7 +2478,7 @@ namespace NLGUI
|
|||
else
|
||||
{
|
||||
if( CInterfaceElement::getEditorMode() )
|
||||
setCurrentEditorSelection( "" );
|
||||
clearEditorSelection();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3349,25 +3349,53 @@ namespace NLGUI
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void CWidgetManager::setCurrentEditorSelection( const std::string &name )
|
||||
void CWidgetManager::getEditorSelection( std::vector< std::string > &selection )
|
||||
{
|
||||
selection.clear();
|
||||
for( int i = 0; i < editorSelection.size(); i++ )
|
||||
selection.push_back( editorSelection[ i ] );
|
||||
}
|
||||
|
||||
void CWidgetManager::selectWidget( const std::string &name )
|
||||
{
|
||||
std::vector< std::string >::iterator itr
|
||||
= std::find( editorSelection.begin(), editorSelection.end(), name );
|
||||
|
||||
CInterfaceElement *e = getElementFromId( name );
|
||||
if( e != NULL )
|
||||
|
||||
if( itr != editorSelection.end() )
|
||||
{
|
||||
if( !currentEditorSelection.empty() )
|
||||
// If multiselection is on unselect if already selected
|
||||
if( multiSelection )
|
||||
{
|
||||
CInterfaceElement *prev = getElementFromId( currentEditorSelection );
|
||||
if( prev != NULL )
|
||||
prev->setEditorSelected( false );
|
||||
editorSelection.erase( itr );
|
||||
if( e != NULL )
|
||||
e->setEditorSelected( false );
|
||||
}
|
||||
e->setEditorSelected( true );
|
||||
}
|
||||
else
|
||||
if( !name.empty() )
|
||||
return;
|
||||
|
||||
currentEditorSelection = name;
|
||||
{
|
||||
// Select if not yet selected
|
||||
if( e != NULL )
|
||||
{
|
||||
// If multiselection is off, we can only have 1 widget selected
|
||||
if( !multiSelection )
|
||||
{
|
||||
editorSelection.clear();
|
||||
}
|
||||
|
||||
e->setEditorSelected( true );
|
||||
editorSelection.push_back( name );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
notifySelectionWatchers();
|
||||
}
|
||||
|
||||
void CWidgetManager::clearEditorSelection()
|
||||
{
|
||||
editorSelection.clear();
|
||||
notifySelectionWatchers();
|
||||
}
|
||||
|
||||
|
@ -3376,7 +3404,7 @@ namespace NLGUI
|
|||
std::vector< IEditorSelectionWatcher* >::iterator itr = selectionWatchers.begin();
|
||||
while( itr != selectionWatchers.end() )
|
||||
{
|
||||
(*itr)->selectionChanged( currentEditorSelection );
|
||||
(*itr)->selectionChanged();
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
@ -3484,11 +3512,11 @@ namespace NLGUI
|
|||
|
||||
bool CWidgetManager::unGroupSelection()
|
||||
{
|
||||
if( currentEditorSelection.empty() )
|
||||
if( editorSelection.size() != 1 )
|
||||
return false;
|
||||
|
||||
// Does the element exist?
|
||||
CInterfaceElement *e = getElementFromId( currentEditorSelection );
|
||||
CInterfaceElement *e = getElementFromId( editorSelection[ 0 ] );
|
||||
if( e == NULL )
|
||||
return false;
|
||||
|
||||
|
@ -3509,7 +3537,7 @@ namespace NLGUI
|
|||
|
||||
p->delElement( g );
|
||||
|
||||
setCurrentEditorSelection( "" );
|
||||
clearEditorSelection();
|
||||
|
||||
p->updateCoords();
|
||||
|
||||
|
@ -3554,8 +3582,8 @@ namespace NLGUI
|
|||
|
||||
setScreenWH( 0, 0 );
|
||||
|
||||
currentEditorSelection = "";
|
||||
groupSelection = false;
|
||||
multiSelection = false;
|
||||
}
|
||||
|
||||
CWidgetManager::~CWidgetManager()
|
||||
|
@ -3569,6 +3597,8 @@ namespace NLGUI
|
|||
curContextHelp = NULL;
|
||||
|
||||
CStringShared::deleteStringMapper();
|
||||
|
||||
editorSelection.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,35 +25,40 @@ namespace GUIEditor
|
|||
{
|
||||
void CEditorMessageProcessor::onDelete()
|
||||
{
|
||||
std::string selection = CWidgetManager::getInstance()->getCurrentEditorSelection();
|
||||
std::vector< std::string > selection;
|
||||
|
||||
CWidgetManager::getInstance()->getEditorSelection( selection );
|
||||
if( selection.empty() )
|
||||
return;
|
||||
|
||||
QMessageBox::StandardButton r =
|
||||
QMessageBox::question( NULL,
|
||||
tr( "Deleting widget" ),
|
||||
tr( "Are you sure you want to delete %1?" ).arg( selection.c_str() ),
|
||||
tr( "Are you sure you want to delete these?" ),
|
||||
QMessageBox::Yes | QMessageBox::No );
|
||||
if( r != QMessageBox::Yes )
|
||||
return;
|
||||
|
||||
CInterfaceElement *e =
|
||||
CWidgetManager::getInstance()->getElementFromId( selection );
|
||||
if( e == NULL )
|
||||
return;
|
||||
|
||||
CInterfaceElement *p = e->getParent();
|
||||
if( p == NULL )
|
||||
return;
|
||||
|
||||
CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( p );
|
||||
if( g == NULL )
|
||||
return;
|
||||
|
||||
if( g->delElement( e ) )
|
||||
for( int i = 0; i < selection.size(); i++ )
|
||||
{
|
||||
CWidgetManager::getInstance()->setCurrentEditorSelection( "" );
|
||||
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( selection[ i ] );
|
||||
if( e == NULL )
|
||||
continue;
|
||||
|
||||
CInterfaceElement *p = e->getParent();
|
||||
if( p == NULL )
|
||||
continue;
|
||||
|
||||
CInterfaceGroup *g = dynamic_cast< CInterfaceGroup* >( p );
|
||||
if( g == NULL )
|
||||
continue;
|
||||
|
||||
g->delElement( e );
|
||||
|
||||
}
|
||||
|
||||
|
||||
CWidgetManager::getInstance()->clearEditorSelection();
|
||||
}
|
||||
|
||||
void CEditorMessageProcessor::onAdd( const QString &parentGroup, const QString &widgetType, const QString &name )
|
||||
|
@ -147,5 +152,10 @@ namespace GUIEditor
|
|||
tr( "Couldn't ungroup widgets." ) );
|
||||
}
|
||||
}
|
||||
|
||||
void CEditorMessageProcessor::onSetMultiSelection( bool b )
|
||||
{
|
||||
CWidgetManager::getInstance()->setMultiSelection( b );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace GUIEditor
|
|||
void onAdd( const QString &parentGroup, const QString &widgetType, const QString &name );
|
||||
void onSetGroupSelection( bool b );
|
||||
void onUngroup();
|
||||
void onSetMultiSelection( bool b );
|
||||
|
||||
private:
|
||||
CWidgetInfoTree *tree;
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
namespace GUIEditor
|
||||
{
|
||||
void CEditorSelectionWatcher::selectionChanged( std::string &newSelection )
|
||||
void CEditorSelectionWatcher::selectionChanged()
|
||||
{
|
||||
Q_EMIT sgnSelectionChanged( newSelection );
|
||||
Q_EMIT sgnSelectionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,10 +27,10 @@ namespace GUIEditor
|
|||
public:
|
||||
CEditorSelectionWatcher() : QObject( NULL ){}
|
||||
|
||||
void selectionChanged( std::string &newSelection );
|
||||
void selectionChanged();
|
||||
|
||||
Q_SIGNALS:
|
||||
void sgnSelectionChanged( std::string &id );
|
||||
void sgnSelectionChanged();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -283,8 +283,8 @@ namespace GUIEditor
|
|||
|
||||
|
||||
CEditorSelectionWatcher *w = GUICtrl->getWatcher();
|
||||
disconnect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), hierarchyView, SLOT( onSelectionChanged( std::string& ) ) );
|
||||
disconnect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), &browserCtrl, SLOT( onSelectionChanged( std::string& ) ) );
|
||||
disconnect( w, SIGNAL( sgnSelectionChanged() ), hierarchyView, SLOT( onSelectionChanged() ) );
|
||||
disconnect( w, SIGNAL( sgnSelectionChanged() ), &browserCtrl, SLOT( onSelectionChanged() ) );
|
||||
|
||||
projectFiles.clearAll();
|
||||
projectWindow->clear();
|
||||
|
@ -322,8 +322,8 @@ namespace GUIEditor
|
|||
linkList->onGUILoaded();
|
||||
|
||||
CEditorSelectionWatcher *w = GUICtrl->getWatcher();
|
||||
connect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), hierarchyView, SLOT( onSelectionChanged( std::string& ) ) );
|
||||
connect( w, SIGNAL( sgnSelectionChanged( std::string& ) ), &browserCtrl, SLOT( onSelectionChanged( std::string& ) ) );
|
||||
connect( w, SIGNAL( sgnSelectionChanged() ), hierarchyView, SLOT( onSelectionChanged() ) );
|
||||
connect( w, SIGNAL( sgnSelectionChanged() ), &browserCtrl, SLOT( onSelectionChanged() ) );
|
||||
}
|
||||
|
||||
void GUIEditorWindow::onAddWidgetClicked()
|
||||
|
@ -413,6 +413,12 @@ namespace GUIEditor
|
|||
connect( a, SIGNAL( triggered( bool ) ), messageProcessor, SLOT( onSetGroupSelection( bool ) ) );
|
||||
m->addAction( a );
|
||||
|
||||
a = new QAction( "Multiselect", this );
|
||||
a->setCheckable( true );
|
||||
a->setChecked( false );
|
||||
connect( a, SIGNAL( triggered( bool ) ), messageProcessor, SLOT( onSetMultiSelection( bool ) ) );
|
||||
m->addAction( a );
|
||||
|
||||
menu = m;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -436,7 +436,7 @@ namespace GUIEditor
|
|||
browser->clear();
|
||||
}
|
||||
|
||||
void CPropBrowserCtrl::onSelectionChanged( std::string &id )
|
||||
void CPropBrowserCtrl::onSelectionChanged()
|
||||
{
|
||||
if( browser == NULL )
|
||||
return;
|
||||
|
@ -444,14 +444,20 @@ namespace GUIEditor
|
|||
disablePropertyWatchers();
|
||||
browser->clear();
|
||||
|
||||
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( id );
|
||||
std::vector< std::string > selection;
|
||||
CWidgetManager::getInstance()->getEditorSelection( selection );
|
||||
|
||||
if( selection.size() != 1 )
|
||||
return;
|
||||
|
||||
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( selection[ 0 ] );
|
||||
if( e == NULL )
|
||||
{
|
||||
enablePropertyWatchers();
|
||||
return;
|
||||
}
|
||||
|
||||
currentElement = id;
|
||||
currentElement = selection[ 0 ];
|
||||
|
||||
std::string n = e->getClassName();
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace GUIEditor
|
|||
void clear();
|
||||
|
||||
public Q_SLOTS:
|
||||
void onSelectionChanged( std::string &id );
|
||||
void onSelectionChanged();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onPropertyChanged( QtProperty *prop, const QVariant &v );
|
||||
|
|
|
@ -304,14 +304,15 @@ namespace GUIEditor
|
|||
|
||||
void WidgetHierarchy::getCurrentGroup( QString &g )
|
||||
{
|
||||
std::string s = CWidgetManager::getInstance()->getCurrentEditorSelection();
|
||||
if( s.empty() )
|
||||
std::vector< std::string > selection;
|
||||
CWidgetManager::getInstance()->getEditorSelection( selection );
|
||||
if( selection.size() != 1 )
|
||||
{
|
||||
g = "";
|
||||
return;
|
||||
}
|
||||
|
||||
NLGUI::CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( s );
|
||||
NLGUI::CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( selection[ 0 ] );
|
||||
if( e == NULL )
|
||||
{
|
||||
g = "";
|
||||
|
@ -342,8 +343,16 @@ namespace GUIEditor
|
|||
currentSelection.clear();
|
||||
}
|
||||
|
||||
void WidgetHierarchy::onSelectionChanged( std::string &newSelection )
|
||||
void WidgetHierarchy::onSelectionChanged()
|
||||
{
|
||||
std::vector< std::string > selection;
|
||||
CWidgetManager::getInstance()->getEditorSelection( selection );
|
||||
|
||||
if( selection.size() != 1 )
|
||||
return;
|
||||
|
||||
std::string newSelection = selection[ 0 ];
|
||||
|
||||
if( newSelection == currentSelection )
|
||||
return;
|
||||
|
||||
|
@ -376,6 +385,6 @@ namespace GUIEditor
|
|||
|
||||
std::string n = item->text( 0 ).toUtf8().constData();
|
||||
currentSelection = makeFullName( item, n );
|
||||
CWidgetManager::getInstance()->setCurrentEditorSelection( currentSelection );
|
||||
CWidgetManager::getInstance()->selectWidget( currentSelection );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace GUIEditor
|
|||
|
||||
public Q_SLOTS:
|
||||
void onGUILoaded();
|
||||
void onSelectionChanged( std::string &newSelection );
|
||||
void onSelectionChanged();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onItemDblClicked( QTreeWidgetItem *item );
|
||||
|
|
Loading…
Reference in a new issue