![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2008 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 00008 00010 00011 #pragma once 00012 00013 #include <vrfGuiCoreQt/vrfGuiCoreQt.h> 00014 #include <vrfGuiCoreQt/simpleMenu.h> 00015 #include <vrvUtil/DtVirtualBaseClass.h> 00016 #include <vrvCore/DtMenuConfiguration.h> 00017 #include <vrvCoreQt/DtMenuItem.h> 00018 #include <vrvCoreQt/DtMenu.h> 00019 #include <vrvCoreQt/DtQtMenuAssembler.h> 00020 #include <vrvCoreQt/DtMenuManager.h> 00021 00022 #include <QtCore/QString> 00023 00024 00025 namespace makVrv 00026 { 00027 class DtDe; 00028 }; 00029 00030 namespace makVrf 00031 { 00032 class DT_DLL_VRFGUICOREQT DtSubMenuPath : public makVrv::DtMenuPath 00033 { 00034 public: 00035 struct SubMenuPathBuilder : public MenuPathBuilder 00036 { 00037 public: 00038 SubMenuPathBuilder(const std::string& path) 00039 : MenuPathBuilder(path) 00040 { 00041 } 00042 }; 00043 00044 DtSubMenuPath(const makVrv::DtMenuPath& p) : makVrv::DtMenuPath(p) {}; 00045 DtSubMenuPath(const std::string& p) : makVrv::DtMenuPath(SubMenuPathBuilder(p)) {}; 00046 00047 DtSubMenuPath& operator=(const DtSubMenuPath& rhs) 00048 { 00049 makVrv::DtMenuPath::operator=(rhs); 00050 return *this; 00051 } 00052 00053 DtSubMenuPath& operator=(const SubMenuPathBuilder& rhs) 00054 { 00055 makVrv::DtMenuPath::operator=(rhs); 00056 return *this; 00057 } 00058 00059 DtSubMenuPath& operator=(const std::string& rhs) 00060 { 00061 myPath = rhs; 00062 return *this; 00063 } 00064 00065 const std::string& path() const 00066 { 00067 return makVrv::DtMenuPath::path(); 00068 } 00069 00070 static SubMenuPathBuilder path(const makVrv::DtMenuPath& p) 00071 { 00072 return SubMenuPathBuilder(p.path()); 00073 } 00074 00075 static SubMenuPathBuilder path(const std::string& p) 00076 { 00077 return SubMenuPathBuilder(p); 00078 } 00079 00080 void strip(const std::string& str1, const std::string& str2) 00081 { 00082 QString str = myPath.c_str(); 00083 str.replace(str1.c_str(), str2.c_str()); 00084 myPath = str.toLatin1().constData(); 00085 } 00086 }; 00087 00091 class DT_DLL_VRFGUICOREQT DtSubMenuConfiguration : public makVrv::DtMenuConfiguration 00092 { 00093 public: 00094 DtSubMenuConfiguration() 00095 : makVrv::DtMenuConfiguration() 00096 , myDe(0) 00097 { 00098 } 00099 00100 DtSubMenuConfiguration(const makVrv::DtMenuConfiguration& c) 00101 : makVrv::DtMenuConfiguration(c) 00102 , myDe(0) 00103 { 00104 } 00105 00106 DtSubMenuConfiguration(makVrv::DtDe* de); 00107 00108 virtual ~DtSubMenuConfiguration(); 00109 00110 int size() const 00111 { 00112 return myMenuPaths.size(); 00113 } 00114 00115 void convert(const std::string& str1, const std::string& str2) 00116 { 00117 MenuPathSet::iterator curIter = myMenuPaths.begin(); 00118 for ( ; curIter != myMenuPaths.end(); curIter++) 00119 { 00120 if (curIter->isMenu() || curIter->isAbsolutePath()) 00121 { 00122 ((DtSubMenuPath&)*curIter).strip(str1, str2); 00123 } 00124 } 00125 00126 MenuPathOrderMap newMap; 00127 MenuPathOrderMap::const_iterator iter = myMenuOrder.begin(); 00128 for ( ; iter != myMenuOrder.end(); iter++) 00129 { 00130 if (iter->first.isMenu() || iter->first.isAbsolutePath()) 00131 { 00132 DtSubMenuPath path(iter->first); 00133 path.strip(str1, str2); 00134 00135 newMap[path] = iter->second; 00136 } 00137 else 00138 { 00139 newMap[iter->first] = iter->second; 00140 } 00141 } 00142 myMenuOrder = newMap; 00143 } 00144 00151 virtual void addMenuPath( const makVrv::DtMenuPath& path, int weight = -1); 00152 00156 virtual void removeMenuPath(const makVrv::DtMenuPath& path); 00157 00161 virtual void addMenuPathAfter(const makVrv::DtMenuPath& newPath, const makVrv::DtMenuPath& relativeTo); 00162 00166 virtual void addMenuPathBefore(const makVrv::DtMenuPath& newPath, const makVrv::DtMenuPath& relativeTo); 00167 00168 DtSubMenuConfiguration& operator=(const makVrv::DtMenuConfiguration& rhs) 00169 { 00170 makVrv::DtMenuConfiguration::operator=(rhs); 00171 00172 return *this; 00173 } 00174 00175 void makeChangesTo(makVrv::DtMenuConfiguration* c) 00176 { 00177 myMakeChangesTo.push_back(c); 00178 } 00179 00180 void clearMakeChangesTo() 00181 { 00182 myMakeChangesTo.clear(); 00183 } 00184 00185 const MenuPathSet& pathsRemoved() const 00186 { 00187 return myPathsRemoved; 00188 } 00189 00190 const MenuPathSet& menuPaths() const 00191 { 00192 return myMenuPaths; 00193 } 00194 00195 void setProtected(const std::string& p, bool b) 00196 { 00197 if (b) 00198 { 00199 myIsProtected[p] = b; 00200 } 00201 else 00202 { 00203 std::map<std::string, bool>::iterator iter = myIsProtected.find(p); 00204 if (iter != myIsProtected.end()) 00205 { 00206 myIsProtected.erase(iter); 00207 } 00208 } 00209 } 00210 00211 bool isProtected(const std::string& p) const 00212 { 00213 return (myIsProtected.find(p) != myIsProtected.end()); 00214 } 00215 00216 bool isGoingToBeRemoved(const makVrv::DtMenuPath& p) const 00217 { 00218 return (myPathsRemoved.find(p) != myPathsRemoved.end()); 00219 } 00220 00224 virtual void reworkRelativeOrder(); 00225 00226 protected: 00227 makVrv::DtDe* myDe; 00228 00229 std::vector<makVrv::DtMenuConfiguration*> myMakeChangesTo; 00230 MenuPathSet myPathsRemoved; 00231 std::map<std::string, bool> myIsProtected; 00232 }; 00233 00234 class DT_DLL_VRFGUICOREQT DtConfigurationMenuManager : public makVrv::DtMenuManager 00235 { 00236 public: 00237 DtConfigurationMenuManager() 00238 : makVrv::DtMenuManager() 00239 , myDeleteMenus(false) 00240 { 00241 } 00242 00243 void setDeleteMenus(bool b) 00244 { 00245 myDeleteMenus = b; 00246 } 00247 00248 bool deleteMenus() const 00249 { 00250 return myDeleteMenus; 00251 } 00252 00253 virtual ~DtConfigurationMenuManager() 00254 { 00255 if (myDeleteMenus) cleanup(); 00256 } 00257 00258 void cleanup(); 00259 00260 protected: 00261 bool myDeleteMenus; 00262 }; 00263 00267 class DT_DLL_VRFGUICOREQT DtConfigurableMenuAssembler : public makVrv::DtQtMenuAssembler 00268 { 00269 public: 00270 DtConfigurableMenuAssembler(makVrv::DtDe& de); 00271 00272 virtual ~DtConfigurableMenuAssembler() 00273 { 00274 if (!myDeleteReferences) 00275 { 00276 myMenuBuilders.clear(); 00277 myMenuItemBuilders.clear(); 00278 } 00279 else 00280 { 00281 cleanup(); 00282 } 00283 } 00284 00285 void setDeleteReferences(bool b) 00286 { 00287 myDeleteReferences = b; 00288 } 00289 00290 bool deleteReferences() const 00291 { 00292 return myDeleteReferences; 00293 } 00294 00295 void setLocalOnly(bool b) 00296 { 00297 myLocalOnly = b; 00298 } 00299 00300 bool localOnly() const 00301 { 00302 return myLocalOnly; 00303 } 00304 00305 void cleanup(); 00306 00308 DtConfigurationMenuManager& menuManager() 00309 { 00310 return myMenuManager; 00311 } 00312 00314 QMenu* findMenu(const makVrv::DtMenuPath& path) 00315 { 00316 return myMenuManager.findMenu(path); 00317 } 00318 00319 QAction* findMenuItem(const makVrv::DtMenuPath& path) 00320 { 00321 return myMenuManager.findMenuItem(path); 00322 } 00323 00325 virtual void registerMenu(makVrv::DtMenu*); 00326 00328 virtual void unregisterMenu(makVrv::DtMenu*, bool deleteBuilder = true); 00329 00331 virtual void registerMenu(makVrv::DtMenuItem*); 00332 00334 virtual void unregisterMenu(makVrv::DtMenuItem*, bool deleteBuilder = true); 00335 00336 void makeChangesTo(makVrv::DtQtMenuAssembler* c) 00337 { 00338 myMakeChangesTo.push_back(c); 00339 } 00340 00341 void clearMakeChangesTo() 00342 { 00343 myMakeChangesTo.clear(); 00344 } 00345 00346 virtual QMenuBar* menuBar() 00347 { 00348 if (myLocalOnly) return 0; 00349 else return makVrv::DtQtMenuAssembler::menuBar(); 00350 } 00351 00352 virtual QWidget* menuWindow() 00353 { 00354 if (myLocalOnly) return 0; 00355 else return makVrv::DtQtMenuAssembler::menuWindow(); 00356 } 00357 00358 protected: 00359 DtConfigurationMenuManager myMenuManager; 00360 std::vector<makVrv::DtQtMenuAssembler*> myMakeChangesTo; 00361 bool myDeleteReferences; 00362 bool myLocalOnly; 00363 }; 00364 00365 class DT_DLL_VRFGUICOREQT DtConfigurableMenu : 00366 public makVrv::DtMenu, public makVrv::DtVirtualBaseClass 00367 { 00368 public: 00369 00371 DtConfigurableMenu(makVrv::DtDe&, const std::string& className); 00372 00374 virtual ~DtConfigurableMenu(); 00375 00377 virtual DtSubMenuConfiguration& menuConfiguration() = 0; 00378 00380 virtual DtConfigurableMenuAssembler& menuAssembler() = 0; 00381 00385 virtual void registerMenu(makVrv::DtMenu* customMenu); 00386 00390 virtual void registerMenuItem(makVrv::DtMenuItem* customMenuItem); 00391 00392 virtual void createSimpleMenu(std::string menuText, makVrv::DtMenuPath menuIdPath, int weight = -1); 00393 virtual void createSimpleMenuAfter(std::string menuText, makVrv::DtMenuPath menuIdPath, makVrv::DtMenuPath afterIdPath); 00394 virtual void createSimpleMenuBefore(std::string menuText, makVrv::DtMenuPath menuIdPath, makVrv::DtMenuPath beforeIdPath); 00395 00396 virtual void createSimpleMenuItem(std::string itemText, makVrv::DtMenuPath itemIdPath, 00397 DtSimpleMenuItemAction* action, void* usr = NULL, int weight = -1); 00398 virtual void createSimpleMenuItemAfter(std::string itemText, makVrv::DtMenuPath itemIdPath, makVrv::DtMenuPath afterIdPath, 00399 DtSimpleMenuItemAction* action, void* usr = NULL); 00400 virtual void createSimpleMenuItemBefore(std::string itemText, makVrv::DtMenuPath itemIdPath, makVrv::DtMenuPath beforeIdPath, 00401 DtSimpleMenuItemAction* action, void* usr = NULL); 00402 00405 virtual void mergeMenu(makVrv::DtQtMenuAssembler& assembler, makVrv::DtMenuConfiguration& configuration); 00406 00409 virtual void mergeMenu(makVrv::DtQtMenuAssembler& assembler); 00410 00412 virtual void mergeMenu(makVrv::DtMenuConfiguration& configuration); 00413 00414 protected: 00415 virtual void initMenuItems(makVrv::DtDe& de); 00416 00417 makVrv::DtQtMenuAssembler& assembler() 00418 { 00419 return myAssembler; 00420 } 00421 00422 DtSubMenuConfiguration& configuration() 00423 { 00424 return myConfiguration; 00425 } 00426 00428 virtual void createMenuConfiguration(makVrv::DtDe&) = 0; 00429 00430 00431 DtConfigurableMenuAssembler myAssembler; 00432 DtSubMenuConfiguration myConfiguration; 00433 bool myInitialized; 00434 00435 public: 00436 boost::signal<void (QAction*)> signal_validateMenuItem; 00437 00438 }; 00439 }