diff --git a/modules/gui/src/file_type_dialog.cc b/modules/gui/src/file_type_dialog.cc index eeaafc823d13e9899d7cf640e5e787f60cc25506..3f137f82dec3df7e8acd3af0f0eb58050988e51b 100644 --- a/modules/gui/src/file_type_dialog.cc +++ b/modules/gui/src/file_type_dialog.cc @@ -24,8 +24,6 @@ #include <QTableWidgetItem> #include <QHeaderView> -#include <iostream> - #include <ost/io/io_manager.hh> #include <ost/io/io_exception.hh> @@ -77,6 +75,7 @@ FileTypeDialog::FileTypeDialog(const QString& file_name, QWidget* parent): this->AddRow(list_->rowCount(),map_handler[i]->GetFormatName().c_str(),map_handler[i]->GetFormatDescription().c_str(),handler); } #endif + io::SurfaceIOFList surf_handler = io::IOManager::Instance().GetAvailableSurfaceHandler(); for(unsigned int i = 0 ; i < surf_handler.size() ; i++){ QVariant handler = QVariant(); diff --git a/modules/gui/src/scene_selection.cc b/modules/gui/src/scene_selection.cc index 6866e8c8331d67133e3d77735d32d24055db0816..5f792bf56f73773028d1c59389c2d7f4f9504b42 100644 --- a/modules/gui/src/scene_selection.cc +++ b/modules/gui/src/scene_selection.cc @@ -46,9 +46,7 @@ SceneSelection* SceneSelection::scene_selection_ = NULL; SceneSelection::SceneSelection():nodes_(),views_() { - SceneWin* scene_win = GostyApp::Instance()->GetSceneWin(); - QObject::connect(scene_win, SIGNAL(ActiveNodesChanged(gfx::NodePtrList,gfx::EntityP,mol::QueryViewWrapperList)), - this, SLOT(SetActiveNodes(gfx::NodePtrList,gfx::EntityP,mol::QueryViewWrapperList))); + } void SceneSelection::SetActiveNodes(gfx::NodePtrList nodes, gfx::EntityP entity, mol::QueryViewWrapperList views){ diff --git a/modules/gui/src/scene_win/context_menu.cc b/modules/gui/src/scene_win/context_menu.cc index f9a66ce92fc86eef41474617efa26ba6870325de..54d244d26ebe059e9b56703fa0209419525cefa2 100644 --- a/modules/gui/src/scene_win/context_menu.cc +++ b/modules/gui/src/scene_win/context_menu.cc @@ -45,21 +45,84 @@ namespace ost { namespace gui { ContextMenu::ContextMenu(QTreeView* view, SceneWinModel* model): QObject(model),view_(view),model_(model) { + QAction* action = new QAction("Center on Object",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(CenterOnObjects())); + this->AddAction(action, GFX_OBJECT); + + action = new QAction("Copy",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(CopyViews())); + this->AddAction(action, ENTITY); + action = new QAction("Create Custom View",this); + connect(action, SIGNAL(triggered()), this, SLOT(AddViewFromEntity())); + this->AddAction(action, ENTITY); + action = new QAction("Select..", this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Select())); + this->AddAction(action, ENTITY); + action = new QAction("Deselect",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Deselect())); + this->AddAction(action, ENTITY); + + action = new QAction("Delete",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Delete())); + this->AddAction(action, GFX_OBJECT|NOT_SCENE); + + action = new QAction("Show",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Show())); + this->AddAction(action, NOT_VISIBLE); + action = new QAction("Hide",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Hide())); + this->AddAction(action, NOT_HIDDEN); + + action = new QAction("Show",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(MakeVisible())); + this->AddAction(action, ENTITY_VIEW); + action = new QAction("Hide",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(MakeHidden())); + this->AddAction(action, ENTITY_VIEW); + action = new QAction("Show Exclusive",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(ShowExclusive())); + this->AddAction(action, ENTITY_VIEW); + action = new QAction("Hide Exclusive",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(HideExclusive())); + this->AddAction(action, ENTITY_VIEW); + action = new QAction("Select All",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(SelectAllViews())); + this->AddAction(action, ENTITY_VIEW); + action = new QAction("Deselect All",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(DeselectAllViews())); + this->AddAction(action, ENTITY_VIEW); + action = new QAction("Select..",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(SelectViews())); + this->AddAction(action, ENTITY_VIEW); + action = new QAction("Create Custom View",this); + connect(action, SIGNAL(triggered()), this, SLOT(AddView())); + this->AddAction(action, ENTITY_VIEW); + + action = new QAction("Delete",this); + connect(action, SIGNAL(triggered()), this, SLOT(DeleteView())); + this->AddAction(action, ENTITY_VIEW | CUSTOM_VIEW); + + action = new QAction("Rename",this); + connect(action, SIGNAL(triggered()), this, SLOT(Rename())); + this->AddAction(action, GFX_OBJECT | SINGLE); + + action = new QAction("Rename",this); + connect(action, SIGNAL(triggered()), this, SLOT(Rename())); + this->AddAction(action, ENTITY_VIEW | SINGLE); + +#if OST_IMG_ENABLED + action = new QAction("View Density Slices",this); + connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(ViewDensitySlices())); + this->AddAction(action, MAP); +#endif // OST_IMG_ENABLED } void ContextMenu::ShowMenu(const QPoint& pos) { QModelIndexList indexes = view_->selectionModel()->selection().indexes(); - - bool all_visible = true; - bool all_not_scene = true; - bool all_hidden = true; - bool all_entities = true; - bool all_gfx_objects = true; - bool all_entity_views = true; - bool all_custom_views = true; - bool all_maps = true; + ContextActionTypes flags; + flags = ~flags; if(indexes.size()>0){ for(int i = 0; i < indexes.size(); i++){ @@ -67,116 +130,49 @@ void ContextMenu::ShowMenu(const QPoint& pos) GfxSceneNode* gfx_scene_node = qobject_cast<GfxSceneNode*>(model_->GetItem(indexes[i])); if(gfx_scene_node){ gfx::GfxNodeP gfx_node = gfx_scene_node->GetGfxNode(); - if(gfx_node->IsVisible()){all_hidden=false;} - else{all_visible=false;} - if(gfx_node->GetType()==0){all_not_scene = false;} - if(!dynamic_cast<gfx::GfxObj*> (gfx_node.get())){all_gfx_objects = false;} - if(!dynamic_cast<gfx::Entity*> (gfx_node.get())){all_entities = false;} + if(gfx_node->IsVisible()){ + flags &= ~NOT_HIDDEN; + } + else{ + flags &= ~NOT_VISIBLE; + } + if(gfx_node->GetType()==0){flags &= ~NOT_SCENE;} + if(!dynamic_cast<gfx::GfxObj*> (gfx_node.get())){flags &= ~GFX_OBJECT;} + if(!dynamic_cast<gfx::Entity*> (gfx_node.get())){flags &= ~ENTITY;} #if OST_IMG_ENABLED - if(!dynamic_cast<gfx::MapIso*> (gfx_node.get())){all_maps = false;} -#else - all_maps = false; + if(!dynamic_cast<gfx::MapIso*> (gfx_node.get())){flags &= ~MAP;} #endif // OST_IMG_ENABLED } else{ - all_gfx_objects = false; - all_entities = false; - all_maps = false; - all_visible = true; - all_hidden = true; + flags &= ~(GFX_OBJECT | ENTITY +#if OST_IMG_ENABLED + | MAP +#endif + ); + flags &= ~(NOT_VISIBLE | NOT_HIDDEN); } EntityPartNode* entity_part_node = qobject_cast<EntityPartNode*>(model_->GetItem(indexes[i])); if(!entity_part_node){ - all_entity_views = false; - all_custom_views = false; + flags &= ~(ENTITY_VIEW | CUSTOM_VIEW); } else{ CustomPartNode* custom_part_node = qobject_cast<CustomPartNode*>(entity_part_node); if(!custom_part_node){ - all_custom_views = false; + flags &= ~CUSTOM_VIEW; } } } } QMenu* menu = new QMenu(); - - QAction* action; - if(all_gfx_objects){ - action = menu->addAction("Center on Object"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(CenterOnObjects())); - - if(all_entities){ - action = menu->addAction("Copy"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(CopyViews())); - action = menu->addAction("Create Custom View"); - connect(action, SIGNAL(triggered()), this, SLOT(AddViewFromEntity())); - action = menu->addAction("Select.."); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Select())); - action = menu->addAction("Deselect"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Deselect())); - } - - if(all_not_scene){ - action = menu->addAction("Delete"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Delete())); - } - } - - if(!all_visible){ - action = menu->addAction("Show"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Show())); - } - if(!all_hidden){ - action = menu->addAction("Hide"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Hide())); - } - - if(all_entity_views){ - action = menu->addAction("Show"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(MakeVisible())); - - action = menu->addAction("Hide"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(MakeHidden())); - - action = menu->addAction("Show Exclusive"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(ShowExclusive())); - - action = menu->addAction("Hide Exclusive"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(HideExclusive())); - - action = menu->addAction("Select All"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(SelectAllViews())); - - action = menu->addAction("Deselect All"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(DeselectAllViews())); - - action = menu->addAction("Select.."); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(SelectViews())); - - action = menu->addAction("Create Custom View"); - connect(action, SIGNAL(triggered()), this, SLOT(AddView())); - - } - -#if OST_IMG_ENABLED - if(all_maps){ - action = menu->addAction("View Density Slices"); - connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(ViewDensitySlices())); - } -#endif // OST_IMG_ENABLED - - - if(all_entity_views){ - if(all_custom_views){ - action = menu->addAction("Delete"); - connect(action, SIGNAL(triggered()), this, SLOT(DeleteView())); - } - } - - if((all_gfx_objects || all_custom_views) && indexes.size()==2){ - action = menu->addAction("Rename"); - connect(action, SIGNAL(triggered()), this, SLOT(Rename())); + QMapIterator<QAction*, ContextActionTypes> i(actions_); + flags ^= NOT_VISIBLE; + flags ^= NOT_HIDDEN; + while (i.hasNext()) { + i.next(); + if (i.value() == (i.value() & flags)){ + menu->addAction(i.key()); + } } if(menu->actions().size()>0){ @@ -185,6 +181,10 @@ void ContextMenu::ShowMenu(const QPoint& pos) } } +void ContextMenu::AddAction(QAction* action,ContextActionTypes type){ + actions_[action] = type; +} + void ContextMenu::AddViewFromEntity() { QueryDialog d; if (d.exec() == QDialog::Accepted) { diff --git a/modules/gui/src/scene_win/context_menu.hh b/modules/gui/src/scene_win/context_menu.hh index 953cdf5a73b15a65d6051531ce6382369f1168ec..55c73e438537bd84a031525da2a20b4799436190 100644 --- a/modules/gui/src/scene_win/context_menu.hh +++ b/modules/gui/src/scene_win/context_menu.hh @@ -23,6 +23,7 @@ Author: Stefan Scheuber */ +#include <QFlags> #include <QMap> #include <QAbstractItemModel> #include <QTreeView> @@ -32,6 +33,23 @@ namespace ost { namespace gui { +enum ContextActionType +{ + GFX_OBJECT=0x1, + ENTITY=0x2, + ENTITY_VIEW=0x4, + CUSTOM_VIEW=0x8, + NOT_VISIBLE=0x10, + NOT_HIDDEN=0x20, + NOT_SCENE=0x40, + SINGLE=0x80 +#if OST_IMG_ENABLED + ,MAP=0x100 +#endif +}; +Q_DECLARE_FLAGS(ContextActionTypes, ContextActionType) + + class DLLEXPORT_OST_GUI ContextMenu : public QObject { Q_OBJECT public: @@ -41,18 +59,23 @@ public: void ShowMenu(const QPoint& pos); void Rename(QModelIndex index); + void AddAction(QAction* action,ContextActionTypes type); + private slots: void AddViewFromEntity(); void AddView(); void Rename(); void DeleteView(); - private: + QMap<QAction*, ContextActionTypes> actions_; + QTreeView* view_; SceneWinModel* model_; }; }} +Q_DECLARE_OPERATORS_FOR_FLAGS(ost::gui::ContextActionTypes) + #endif diff --git a/modules/gui/src/scene_win/scene_win.cc b/modules/gui/src/scene_win/scene_win.cc index c97253b340cc87e8bf6ca67d2128e05184013946..fb9045babfade67498a804cf8d8e58dcd2f895c5 100644 --- a/modules/gui/src/scene_win/scene_win.cc +++ b/modules/gui/src/scene_win/scene_win.cc @@ -71,6 +71,9 @@ SceneWin::SceneWin(QWidget* parent) : connect(view_, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(DoubleClicked(const QModelIndex &))); connect(model_, SIGNAL(rowsInserted(const QModelIndex&, int, int)), this, SLOT(RowsInserted(const QModelIndex&, int, int))); + + QObject::connect(this, SIGNAL(ActiveNodesChanged(gfx::NodePtrList,gfx::EntityP,mol::QueryViewWrapperList)), + SceneSelection::Instance(), SLOT(SetActiveNodes(gfx::NodePtrList,gfx::EntityP,mol::QueryViewWrapperList))); } void SceneWin::ContextMenuRequested(const QPoint& pos) {