Commit 8b1f709a authored by Jan Möbius's avatar Jan Möbius

Basic context menu implementation

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5640 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ca58471f
...@@ -72,7 +72,7 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil ...@@ -72,7 +72,7 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil
} }
void TextureControlPlugin::fileOpened( int _id ) { void TextureControlPlugin::fileOpened( int _id ) {
// TODO:: Store origninal texture coors in a new property! // TODO:: Store original texture coords in a new property!
std::cerr << "File opened : " << _id << std::endl; std::cerr << "File opened : " << _id << std::endl;
...@@ -490,6 +490,15 @@ void TextureControlPlugin::pluginsInitialized() { ...@@ -490,6 +490,15 @@ void TextureControlPlugin::pluginsInitialized() {
textureMenu_->addSeparator(); textureMenu_->addSeparator();
textureMenu_->addActions(actionGroup_->actions()); textureMenu_->addActions(actionGroup_->actions());
// ================================================================================
// Create basic per object context menu
// ================================================================================
contextMenu_ = new QMenu(0);
contextMenu_->setTitle("Textures");
emit addContextMenuItem(contextMenu_->menuAction() ,DATA_TRIANGLE_MESH , CONTEXTOBJECTMENU );
emit addContextMenuItem(contextMenu_->menuAction() ,DATA_POLY_MESH , CONTEXTOBJECTMENU );
} }
void TextureControlPlugin::updateDialog() { void TextureControlPlugin::updateDialog() {
...@@ -698,5 +707,51 @@ void TextureControlPlugin::slotSwitchTexture( QString _textureName ) { ...@@ -698,5 +707,51 @@ void TextureControlPlugin::slotSwitchTexture( QString _textureName ) {
} }
void TextureControlPlugin::slotUpdateContextMenu( int _objectId ) {
std::cerr << "TextureControlPlugin::slotUpdateContextMenu " << _objectId << std::endl;
// ================================================================================
// Get picking object object
// ================================================================================
if ( _objectId == -1 )
return;
BaseObjectData* obj;
if (! PluginFunctions::getObject( _objectId , obj ) ) {
emit log(LOGERR,"slotUpdateContextMenu: Unable to get Object for id " + QString::number(_objectId) );
return;
}
// ================================================================================
// Get objects texture data and verify that texture exists
// ================================================================================
TextureData* texData = dynamic_cast< TextureData* > ( obj->objectData(TEXTUREDATA) );
if (texData == 0){
std::cerr << "TextureControlPlugin::slotUpdateContextMenu: Texture data not found!" << std::endl;
return;
}
// ================================================================================
// Prepare Texture menu
// ================================================================================
contextMenu_->clear();
QActionGroup* actionGroup = new QActionGroup(0);
actionGroup->setExclusive( true );
connect( actionGroup, SIGNAL( triggered( QAction * ) ),
this, SLOT( slotTextureContextMenu( QAction * ) ) );
for ( uint i = 0 ; i < texData->textures().size() ; ++i ) {
QAction* action = actionGroup->addAction( texData->textures()[i].name );
action->setCheckable(true);
if ( texData->textures()[i].enabled )
action->setChecked(true);
}
contextMenu_->addActions(actionGroup->actions());
}
Q_EXPORT_PLUGIN2( texturecontrolplugin , TextureControlPlugin ); Q_EXPORT_PLUGIN2( texturecontrolplugin , TextureControlPlugin );
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <OpenFlipper/BasePlugin/LoggingInterface.hh> #include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh> #include <OpenFlipper/BasePlugin/MenuInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh> #include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh> #include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh> #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
...@@ -75,7 +76,7 @@ struct Texture { ...@@ -75,7 +76,7 @@ struct Texture {
uint type; uint type;
};*/ };*/
class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface,ContextMenuInterface
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(BaseInterface) Q_INTERFACES(BaseInterface)
...@@ -83,27 +84,35 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me ...@@ -83,27 +84,35 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
Q_INTERFACES(MenuInterface) Q_INTERFACES(MenuInterface)
Q_INTERFACES(LoggingInterface) Q_INTERFACES(LoggingInterface)
Q_INTERFACES(LoadSaveInterface) Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(ContextMenuInterface)
public: public:
enum TextureType { VERTEXBASED = 1 << 0, HALFEDGEBASED = 1 << 1}; enum TextureType { VERTEXBASED = 1 << 0, HALFEDGEBASED = 1 << 1};
signals: signals:
// BaseInterface // BaseInterface
void updateView(); void updateView();
// TextureInterface // TextureInterface
void updateTexture( QString , int); void updateTexture( QString , int);
// LoggingInterface // LoggingInterface
void log(Logtype _type, QString _message); void log(Logtype _type, QString _message);
void log(QString _message); void log(QString _message);
// MenuInterface // MenuInterface
void addMenubarAction(QAction* _action, MenuActionType _type ); void addMenubarAction(QAction* _action, MenuActionType _type );
// ContextMenuInterface
void addContextMenuItem(QAction* _action ,DataType _objectType , ContextMenuType _type );
private slots: private slots:
// BaseInterface // BaseInterface
void pluginsInitialized(); void pluginsInitialized();
void slotObjectUpdated(int _identifier); void slotObjectUpdated(int _identifier);
// TextureInterface // TextureInterface
void slotUpdateAllTextures( ); void slotUpdateAllTextures( );
void slotTextureAdded( QString _textureName , QString _filename , uint _dimension ); void slotTextureAdded( QString _textureName , QString _filename , uint _dimension );
...@@ -114,6 +123,9 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me ...@@ -114,6 +123,9 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
// LoadSaveInterface // LoadSaveInterface
void fileOpened( int _id ); void fileOpened( int _id );
// ContextMenuInterface
void slotUpdateContextMenu( int _objectId );
private slots: private slots:
/// Called when an action in the TextureMenu is triggered /// Called when an action in the TextureMenu is triggered
void slotTextureMenu(QAction* _action); void slotTextureMenu(QAction* _action);
...@@ -151,6 +163,8 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me ...@@ -151,6 +163,8 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me
texturePropertiesWidget* settingsDialog_; texturePropertiesWidget* settingsDialog_;
QMenu* contextMenu_;
/// Set the active texture values to the values in the dialog box. /// Set the active texture values to the values in the dialog box.
void applyDialogSettings(); void applyDialogSettings();
......
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