From 8b1f709aac1a4d5f914d274d3c7faffba5a3b27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Wed, 15 Apr 2009 11:00:26 +0000 Subject: [PATCH] Basic context menu implementation git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5640 383ad7c9-94d9-4d36-a494-682f7c89f535 --- TextureControl.cc | 57 ++++++++++++++++++++++++++++++++++++++++++++++- TextureControl.hh | 18 +++++++++++++-- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/TextureControl.cc b/TextureControl.cc index 48a76d6..7e964cd 100644 --- a/TextureControl.cc +++ b/TextureControl.cc @@ -72,7 +72,7 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil } 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; @@ -490,6 +490,15 @@ void TextureControlPlugin::pluginsInitialized() { textureMenu_->addSeparator(); 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() { @@ -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 ); diff --git a/TextureControl.hh b/TextureControl.hh index b94055a..eb15d33 100644 --- a/TextureControl.hh +++ b/TextureControl.hh @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -75,7 +76,7 @@ struct Texture { uint type; };*/ -class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface +class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, MenuInterface, LoggingInterface, LoadSaveInterface,ContextMenuInterface { Q_OBJECT Q_INTERFACES(BaseInterface) @@ -83,27 +84,35 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me Q_INTERFACES(MenuInterface) Q_INTERFACES(LoggingInterface) Q_INTERFACES(LoadSaveInterface) + Q_INTERFACES(ContextMenuInterface) public: enum TextureType { VERTEXBASED = 1 << 0, HALFEDGEBASED = 1 << 1}; signals: + // BaseInterface void updateView(); + // TextureInterface void updateTexture( QString , int); + // LoggingInterface void log(Logtype _type, QString _message); void log(QString _message); + // MenuInterface void addMenubarAction(QAction* _action, MenuActionType _type ); - + // ContextMenuInterface + void addContextMenuItem(QAction* _action ,DataType _objectType , ContextMenuType _type ); private slots: + // BaseInterface void pluginsInitialized(); void slotObjectUpdated(int _identifier); + // TextureInterface void slotUpdateAllTextures( ); void slotTextureAdded( QString _textureName , QString _filename , uint _dimension ); @@ -114,6 +123,9 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me // LoadSaveInterface void fileOpened( int _id ); + // ContextMenuInterface + void slotUpdateContextMenu( int _objectId ); + private slots: /// Called when an action in the TextureMenu is triggered void slotTextureMenu(QAction* _action); @@ -151,6 +163,8 @@ class TextureControlPlugin : public QObject, BaseInterface, TextureInterface, Me texturePropertiesWidget* settingsDialog_; + QMenu* contextMenu_; + /// Set the active texture values to the values in the dialog box. void applyDialogSettings(); -- GitLab