Added texture property editor, editor factory, manager. Textures can now be selected using these in the property tree browser.

This commit is contained in:
dfighter1985 2014-07-08 18:59:30 +02:00
parent 3b0b82423f
commit 559968ba41
6 changed files with 503 additions and 1 deletions

View file

@ -33,6 +33,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR
action_list.h
texture_chooser.h
action_property_manager.h
texture_property_manager.h
)
SET(OVQT_PLUGIN_GUI_EDITOR_UIS

View file

@ -27,6 +27,7 @@
#include <QList>
#include "action_property_manager.h"
#include "texture_property_manager.h"
namespace
{
@ -371,10 +372,12 @@ namespace GUIEditor
propertyMgr = new QtVariantPropertyManager;
enumMgr = new QtEnumPropertyManager;
actionMgr = new ActionPropertyManager;
textureMgr = new TexturePropertyManager;
variantFactory = new QtVariantEditorFactory;
enumFactory = new QtEnumEditorFactory;
actionFactory = new ActionEditorFactory;
textureFactory = new TextureEditorFactory;
ttPairs[ "tooltip_posref" ] = "tooltip_parent_posref";
ttPairs[ "tooltip_parent_posref" ] = "tooltip_posref";
@ -385,6 +388,8 @@ namespace GUIEditor
CPropBrowserCtrl::~CPropBrowserCtrl()
{
delete textureMgr;
textureMgr = NULL;
delete actionMgr;
actionMgr = NULL;
delete enumMgr;
@ -392,6 +397,8 @@ namespace GUIEditor
delete propertyMgr;
propertyMgr = NULL;
delete textureFactory;
textureFactory = NULL;
delete actionFactory;
actionFactory = NULL;
delete variantFactory;
@ -456,6 +463,7 @@ namespace GUIEditor
browser->setFactoryForManager( propertyMgr, variantFactory );
browser->setFactoryForManager( enumMgr, enumFactory );
browser->setFactoryForManager( actionMgr, actionFactory );
browser->setFactoryForManager( textureMgr, textureFactory );
enablePropertyWatchers();
}
@ -637,6 +645,17 @@ namespace GUIEditor
e->setProperty( propName.toUtf8().constData(), v.toUtf8().constData() );
}
void CPropBrowserCtrl::onTexturePropertyChanged( QtProperty *p, const QString &v )
{
QString propName = p->propertyName();
CInterfaceElement *e = CWidgetManager::getInstance()->getElementFromId( currentElement );
if( e == NULL )
return;
e->setProperty( propName.toUtf8().constData(), v.toUtf8().constData() );
}
void CPropBrowserCtrl::enablePropertyWatchers()
{
connect( propertyMgr, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ),
@ -646,6 +665,8 @@ namespace GUIEditor
connect( actionMgr, SIGNAL( valueChanged( QtProperty*, const QString& ) ),
this, SLOT( onActionPropertyChanged( QtProperty*, const QString& ) ) );
connect( textureMgr, SIGNAL( valueChanged( QtProperty*, const QString& ) ),
this, SLOT( onTexturePropertyChanged( QtProperty*, const QString& ) ) );
}
void CPropBrowserCtrl::disablePropertyWatchers()
@ -657,6 +678,8 @@ namespace GUIEditor
disconnect( actionMgr, SIGNAL( valueChanged( QtProperty*, const QString& ) ),
this, SLOT( onActionPropertyChanged( QtProperty*, const QString& ) ) );
disconnect( textureMgr, SIGNAL( valueChanged( QtProperty*, const QString& ) ),
this, SLOT( onTexturePropertyChanged( QtProperty*, const QString& ) ) );
}
void CPropBrowserCtrl::setupProperties( const std::string &type, const CInterfaceElement *element )
@ -683,6 +706,21 @@ namespace GUIEditor
QtVariantProperty *p = NULL;
QVariant v;
if( prop.propType == "texture" )
{
std::string j = element->getProperty( prop.propName );
if( j.empty() )
return;
QtProperty *pp = textureMgr->addProperty( prop.propName.c_str() );
if( pp == NULL )
return;
textureMgr->setValue( pp, j.c_str() );
browser->addProperty( pp );
}
else
if( prop.propType == "action" )
{
std::string j = element->getProperty( prop.propName );

View file

@ -33,6 +33,8 @@ class QVariant;
class ActionPropertyManager;
class ActionEditorFactory;
class TexturePropertyManager;
class TextureEditorFactory;
namespace NLGUI
{
@ -63,6 +65,7 @@ namespace GUIEditor
void onPropertyChanged( QtProperty *prop, const QVariant &v );
void onEnumPropertyChanged( QtProperty *prop, int value );
void onActionPropertyChanged( QtProperty *p, const QString &v );
void onTexturePropertyChanged( QtProperty *p, const QString &v );
private:
void enablePropertyWatchers();
@ -75,10 +78,12 @@ namespace GUIEditor
QtVariantPropertyManager *propertyMgr;
QtEnumPropertyManager *enumMgr;
ActionPropertyManager *actionMgr;
TexturePropertyManager *textureMgr;
QtVariantEditorFactory *variantFactory;
QtEnumEditorFactory *enumFactory;
ActionEditorFactory *actionFactory;
TextureEditorFactory *textureFactory;
std::string currentElement;
std::map< std::string, SWidgetInfo > widgetInfo;

View file

@ -0,0 +1,333 @@
// Ryzom Core Studio GUI Editor plugin <http://dev.ryzom.com/projects/ryzom/>
// 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 <http://www.gnu.org/licenses/>.
#include "texture_property_manager.h"
#include "texture_chooser.h"
#include <QMap>
#include <QList>
#include <QLineEdit>
#include <QToolButton>
#include <QHBoxLayout>
////////////////////////////////////////////////////////////////// Manager ///////////////////////////////////////////////////////////////////////////
struct TexturePropertyManagerPrivate
{
QMap< const QtProperty*, QString > values;
};
TexturePropertyManager::TexturePropertyManager( QObject *parent ) :
QtAbstractPropertyManager( parent )
{
d_ptr = new TexturePropertyManagerPrivate();
}
TexturePropertyManager::~TexturePropertyManager()
{
delete d_ptr;
d_ptr = NULL;
}
QString TexturePropertyManager::value( const QtProperty *p ) const
{
return valueText( p );
}
void TexturePropertyManager::setValue( QtProperty *p, const QString &value )
{
if( !d_ptr->values.contains( p ) )
return;
if( d_ptr->values[ p ] == value )
return;
d_ptr->values[ p ] = value;
Q_EMIT propertyChanged( p );
Q_EMIT valueChanged( p, value );
}
bool TexturePropertyManager::hasValue( const QtProperty *p ) const
{
return d_ptr->values.contains( p );
}
QString TexturePropertyManager::valueText( const QtProperty *p ) const
{
if( !d_ptr->values.contains( p ) )
return "";
return d_ptr->values[ p ];
}
void TexturePropertyManager::initializeProperty( QtProperty *p )
{
if( d_ptr->values.contains( p ) )
return;
d_ptr->values[ p ] = "";
}
void TexturePropertyManager::uninitializeProperty( QtProperty *p )
{
d_ptr->values.remove( p );
}
//////////////////////////////////////////////////////////////////// Factory ///////////////////////////////////////////////////////////////////////
struct TextureEditorFactoryPrivate
{
QMap< QtProperty*, QList< TexturePropertyEditor* > > createdEditors;
QMap< TexturePropertyEditor*, QtProperty* > editorToProperty;
~TextureEditorFactoryPrivate()
{
createdEditors.clear();
QMap< TexturePropertyEditor*, QtProperty* >::iterator itr = editorToProperty.begin();
while( itr != editorToProperty.end() )
{
delete itr.key();
++itr;
}
editorToProperty.clear();
}
void addEditor( QtProperty *p, TexturePropertyEditor *editor )
{
QMap< QtProperty*, QList< TexturePropertyEditor* > >::iterator itr = createdEditors.find( p );
if( itr != createdEditors.end() )
{
itr->push_back( editor );
}
else
{
QList< TexturePropertyEditor* > l;
l.push_back( editor );
createdEditors.insert( p, l );
}
editorToProperty.insert( editor, p );
}
void removeEditor( QObject *o )
{
// Remove from editorToProperty first
QMap< TexturePropertyEditor*, QtProperty* >::iterator itr1 = editorToProperty.begin();
while( itr1 != editorToProperty.end() )
{
if( itr1.key() == o )
break;
++itr1;
}
if( itr1 != editorToProperty.end() )
editorToProperty.erase( itr1 );
// Then from createdEditors
QMap< QtProperty*, QList< TexturePropertyEditor* > >::iterator itr2 = createdEditors.begin();
while( itr2 != createdEditors.end() )
{
QList< TexturePropertyEditor* > &l = *itr2;
QList< TexturePropertyEditor* >::iterator itr = l.begin();
while( itr != l.end() )
{
if( *itr == o )
{
QList< TexturePropertyEditor* >::iterator d = itr;
++itr;
l.erase( d );
continue;
}
++itr;
}
++itr2;
}
}
};
TextureEditorFactory::TextureEditorFactory( QObject *parent ) :
QtAbstractEditorFactory( parent )
{
d_ptr = new TextureEditorFactoryPrivate();
}
TextureEditorFactory::~TextureEditorFactory()
{
delete d_ptr;
d_ptr = NULL;
}
void TextureEditorFactory::connectPropertyManager( TexturePropertyManager *manager )
{
connect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ), this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) );
}
void TextureEditorFactory::disconnectPropertyManager( TexturePropertyManager *manager )
{
disconnect( manager, SIGNAL( valueChanged( QtProperty*, const QString& ) ), this, SLOT( onPropertyChanged( QtProperty*, const QString& ) ) );
}
QWidget* TextureEditorFactory::createEditor( TexturePropertyManager *manager, QtProperty *p, QWidget *parent )
{
TexturePropertyEditor *editor = new TexturePropertyEditor( parent );
editor->setValue( manager->value( p ) );
connect( editor, SIGNAL( valueChanged( const QString& ) ), this, SLOT( onSetValue( const QString& ) ) );
connect( editor, SIGNAL( destroyed( QObject* ) ), this, SLOT( onEditorDestroyed( QObject* ) ) );
d_ptr->addEditor( p, editor );
return editor;
}
void TextureEditorFactory::onPropertyChanged( QtProperty *p, const QString &value )
{
QMap< QtProperty*, QList< TexturePropertyEditor* > >::iterator itr = d_ptr->createdEditors.find( p );
if( itr == d_ptr->createdEditors.end() )
return;
QList< TexturePropertyEditor* > &l = *itr;
QList< TexturePropertyEditor* >::iterator i = l.begin();
while( i != l.end() )
{
TexturePropertyEditor *editor = *i;
editor->blockSignals( true );
editor->setValue( value );
editor->blockSignals( false );
++i;
}
}
void TextureEditorFactory::onSetValue( const QString &value )
{
QObject *s = sender();
TexturePropertyEditor *editor = qobject_cast< TexturePropertyEditor* >( s );
if( editor == NULL )
return;
QMap< TexturePropertyEditor*, QtProperty* >::iterator itr = d_ptr->editorToProperty.find( editor );
if( itr == d_ptr->editorToProperty.end() )
return;
QtProperty *p = *itr;
TexturePropertyManager *manager = qobject_cast< TexturePropertyManager* >( p->propertyManager() );
if( manager == NULL )
return;
blockSignals( true );
manager->setValue( p, value );
blockSignals( false );
}
void TextureEditorFactory::onEditorDestroyed( QObject *editor )
{
d_ptr->removeEditor( editor );
}
//////////////////////////////////////////////////////////////////////// Editor //////////////////////////////////////////////////////////////////
TexturePropertyEditor::TexturePropertyEditor( QWidget *parent ) :
QWidget( parent )
{
setupUi();
setupConnections();
}
TexturePropertyEditor::~TexturePropertyEditor()
{
}
void TexturePropertyEditor::setValue( const QString &value )
{
if( lineEdit->text() == value )
return;
disableConnections();
lineEdit->setText( value );
setupConnections();
}
void TexturePropertyEditor::showEvent( QShowEvent *e )
{
QWidget::showEvent( e );
}
void TexturePropertyEditor::onToolButtonClicked()
{
TextureChooser d;
d.load();
int result = d.exec();
if( QDialog::Accepted != result )
return;
lineEdit->setText( d.getSelection() );
}
void TexturePropertyEditor::onTextChanged( const QString &text )
{
Q_EMIT valueChanged( text );
}
void TexturePropertyEditor::setupConnections()
{
connect( toolButton, SIGNAL( clicked( bool ) ), this, SLOT( onToolButtonClicked() ) );
connect( lineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
}
void TexturePropertyEditor::disableConnections()
{
disconnect( toolButton, SIGNAL( clicked( bool ) ), this, SLOT( onToolButtonClicked() ) );
disconnect( lineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
}
void TexturePropertyEditor::setupUi()
{
lineEdit = new QLineEdit();
toolButton = new QToolButton();
toolButton->setText( "..." );
QHBoxLayout *lt = new QHBoxLayout( this );
lt->setContentsMargins( 0, 0, 0, 0 );
lt->setSpacing( 0 );
lt->addWidget( lineEdit );
lt->addWidget( toolButton );
setFocusProxy( lineEdit );
setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed );
}

View file

@ -0,0 +1,125 @@
// Ryzom Core Studio GUI Editor plugin <http://dev.ryzom.com/projects/ryzom/>
// 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 <http://www.gnu.org/licenses/>.
#ifndef TEXTURE_PROPERTY_MANAGER
#define TEXTURE_PROPERTY_MANAGER
#define QT_QTPROPERTYBROWSER_IMPORT
#include "3rdparty/qtpropertybrowser/qtpropertybrowser.h"
#include <QString>
/////////////////////////////////////////////////////// Manager ///////////////////////////////////////////////////////////////////////////
struct TexturePropertyManagerPrivate;
class TexturePropertyManager : public QtAbstractPropertyManager
{
Q_OBJECT
public:
TexturePropertyManager( QObject *parent = NULL );
~TexturePropertyManager();
QString value( const QtProperty *p ) const;
public Q_SLOTS:
void setValue( QtProperty *p, const QString &value );
Q_SIGNALS:
void valueChanged( QtProperty *p, const QString &value );
protected:
bool hasValue( const QtProperty *p ) const;
QString valueText( const QtProperty *p ) const;
void initializeProperty( QtProperty *p );
void uninitializeProperty( QtProperty *p );
private:
TexturePropertyManagerPrivate *d_ptr;
Q_DISABLE_COPY( TexturePropertyManager );
};
////////////////////////////////////////////////////////////////// Factory /////////////////////////////////////////////////////////////////////////
struct TextureEditorFactoryPrivate;
class TextureEditorFactory : public QtAbstractEditorFactory< TexturePropertyManager >
{
Q_OBJECT
public:
TextureEditorFactory( QObject *parent = NULL );
~TextureEditorFactory();
protected:
void connectPropertyManager( TexturePropertyManager *manager );
void disconnectPropertyManager( TexturePropertyManager *manager );
QWidget* createEditor( TexturePropertyManager *manager, QtProperty *p, QWidget *parent );
private Q_SLOTS:
void onPropertyChanged( QtProperty *p, const QString &value );
void onSetValue( const QString &value );
void onEditorDestroyed( QObject *editor );
private:
TextureEditorFactoryPrivate *d_ptr;
Q_DISABLE_COPY( TextureEditorFactory );
};
///////////////////////////////////////////////////////////////// Editor ///////////////////////////////////////////////////////////////////////////
class QLineEdit;
class QToolButton;
class TexturePropertyEditor : public QWidget
{
Q_OBJECT
public:
TexturePropertyEditor( QWidget *parent = NULL );
~TexturePropertyEditor();
public Q_SLOTS:
void setValue( const QString &value );
protected:
void showEvent( QShowEvent *e );
private Q_SLOTS:
void onToolButtonClicked();
void onTextChanged( const QString &text );
Q_SIGNALS:
void valueChanged( const QString &value );
private:
void setupUi();
void setupConnections();
void disableConnections();
QLineEdit *lineEdit;
QToolButton *toolButton;
};
#endif

View file

@ -35,7 +35,7 @@
</property>
<property>
<name>texture</name>
<type>string</type>
<type>texture</type>
<default></default>
</property>
<property>