#include <Iguana/Studio/interface/IgQtObjectMenu.h>
Public Member Functions | |
QKeySequence | accel (int id) const |
void | changeItem (int id, const QIconSet &icon, const QPixmap &pixmap) |
void | changeItem (int id, const QIconSet &icon, const QString &text) |
void | changeItem (int id, const QPixmap &pixmap) |
void | changeItem (int id, const QString &text) |
bool | connectItem (int id, const QObject *receiver, const char *member) |
bool | disconnectItem (int id, const QObject *receiver, const char *member) |
bool | hasItem (int id) const |
QIconSet * | iconSet (int id) const |
IgQtObjectMenu (QPopupMenu *menu) | |
void | insertFromDefs (const QObject *receiver, const ItemDef *defs, unsigned n) |
int | insertItem (int id, const QIconSet &icon, const QPixmap &pixmap, const QObject *receiver, const char *member, const QKeySequence &accel=0) |
int | insertItem (int id, const QPixmap &pixmap, const QObject *receiver, const char *member, const QKeySequence &accel=0) |
int | insertItem (int id, const QIconSet &icon, const QString &text, const QObject *receiver, const char *member, const QKeySequence &accel=0) |
int | insertItem (int id, const QString &text, const QObject *receiver, const char *member, const QKeySequence &accel=0) |
int | insertItem (int id, const QIconSet &icon, const QPixmap &pixmap) |
int | insertItem (int id, const QPixmap &pixmap) |
int | insertItem (int id, const QIconSet &icon, const QString &text) |
int | insertItem (int id, const QString &text) |
int | insertSeparator (int id) |
IgQtObjectMenu * | insertSubMenu (int id, const QIconSet &icon, const QPixmap &pixmap) |
IgQtObjectMenu * | insertSubMenu (int id, const QPixmap &pixmap) |
IgQtObjectMenu * | insertSubMenu (int id, const QIconSet &icon, const QString &text) |
IgQtObjectMenu * | insertSubMenu (int id, const QString &text) |
bool | isItemActive (int id) const |
bool | isItemChecked (int id) const |
bool | isItemEnabled (int id) const |
int | itemParameter (int id) const |
QPixmap * | pixmap (int id) const |
void | removeFromDefs (const ItemDef *defs, unsigned n) |
void | removeItem (int id) |
void | setAccel (int id, const QKeySequence &key) |
void | setItemChecked (int id, bool check) |
void | setItemEnabled (int id, bool enable) |
bool | setItemParameter (int id, int param) |
void | setWhatsThis (int id, const QString &text) |
IgQtObjectMenu * | subMenu (int id) const |
QString | text (int id) const |
QString | whatsThis (int id) const |
Private Types | |
typedef std::vector < IgQtObjectMenu * > | SubMenus |
Private Member Functions | |
void | clearDummy (void) |
unsigned | itemPosition (int id) const |
void | setDummy (void) |
unsigned | subMenuPosition (int id, bool exact) const |
Private Attributes | |
int | m_dummy |
QPopupMenu * | m_menu |
SubMenus | m_submenus |
Classes | |
struct | ItemDef |
This is an interface highly similar to QPopupMenu, except it requires item ids to be provided and automatically sorts the underlying menu to the id order. It also provides the means to record which items are relevant, i.e. should actually appear on the menu.
There is only one menu for the IgQtObjectMenuService used for all pop-up contexts regardless of the type of object it is applied to. (If the menu is torn off, Qt will have two copies of it, but all the actions such enabling and disabling the items still works the same and most clients should not care.) Observers of IgQtObjectMenuMessage should add their items to this object upon receiving a creation message for an object that is relevant to them. Upon receiving an update menu message, they should update the items with setItemRelevant, setItemEnabled, setItemChecked, and so forth. Setting an item not relevant removes it from the menu and destroys the underlying object. Always use subMenu() and hasItem() to determine if the menu has the desired item or not.
The caller should register Qt slots with each item it creates, otherwise nothing will happen on item selection. Each item must have an explicitly defined id (hence an interface different from QPopupMenu). The menu items will be sorted according to the ids in order to avoid the visual appearance changing according to the observer invocation order.
This class is only a proxy through which items can be inserted into the menu; the rest of the menu logic is elsewhere (mainly in IgQtObjectMenuService).
Definition at line 57 of file IgQtObjectMenu.h.
typedef std::vector<IgQtObjectMenu *> IgQtObjectMenu::SubMenus [private] |
Definition at line 161 of file IgQtObjectMenu.h.
IgQtObjectMenu::IgQtObjectMenu | ( | QPopupMenu * | menu | ) |
QKeySequence IgQtObjectMenu::accel | ( | int | id | ) | const |
Referenced by IgTwigOps::menuUpdate(), VisEventContentTwigOps::menuUpdate(), and VisG4TwigOps::menuUpdate().
Definition at line 356 of file IgQtObjectMenu.cc.
References m_dummy, and m_menu.
Referenced by insertSeparator().
00357 { 00358 if (m_dummy != -1) 00359 { 00360 m_menu->removeItem (m_dummy); 00361 m_dummy = -1; 00362 } 00363 }
Definition at line 254 of file IgQtObjectMenu.cc.
References ASSERT, m_menu, and m_submenus.
00256 { 00257 ASSERT (m_menu); 00258 ASSERT (m_submenus.size () <= m_menu->count ()); 00259 ASSERT (m_menu->findItem (id)); 00260 return m_menu->connectItem (id, receiver, member); 00261 }
Definition at line 264 of file IgQtObjectMenu.cc.
References ASSERT, m_menu, and m_submenus.
00266 { 00267 ASSERT (m_menu); 00268 ASSERT (m_submenus.size () <= m_menu->count ()); 00269 ASSERT (m_menu->findItem (id)); 00270 return m_menu->disconnectItem (id, receiver, member); 00271 }
Definition at line 330 of file IgQtObjectMenu.cc.
References ASSERT, m_menu, and m_submenus.
Referenced by insertFromDefs(), and removeItem().
00331 { 00332 ASSERT (m_menu); 00333 ASSERT (m_submenus.size () <= m_menu->count ()); 00334 return m_menu->findItem (id) != 0; 00335 }
QIconSet* IgQtObjectMenu::iconSet | ( | int | id | ) | const |
Definition at line 383 of file IgQtObjectMenu.cc.
References ASSERT, hasItem(), i, IgQtObjectMenu::ItemDef::id, insertItem(), insertSeparator(), insertSubMenu(), IgQtObjectMenu::ItemDef::member, name, IgQtObjectMenu::ItemDef::name, IgQtObjectMenu::ItemDef::param, setItemParameter(), subMenu(), and VERIFY.
Referenced by VisEventContentTwigOps::menuAction(), VisG4TwigOps::menuAction(), IgTwigOps::menuAction(), Ig3DBaseBrowser::repMenu(), IgSpareWindow::repMenu(), IgLegoWindow::repMenu(), Ig3DWindow::repMenu(), IgRPhiWindow::repMenu(), and IgRZWindow::repMenu().
00386 { 00387 ASSERT (receiver); 00388 ASSERT (! n || defs); 00389 00390 for (unsigned i = 0; i < n; ++i) 00391 { 00392 if (defs [i].subid == -1 && ! defs [i].member && defs [i].name) 00393 { 00394 // Insert a sub-menu as such if it doesn't exist yet 00395 if (! subMenu (defs [i].id)) 00396 insertSubMenu (defs [i].id, defs [i].name); 00397 } 00398 else 00399 { 00400 // If the item has sub-menu owner, fetch it 00401 IgQtObjectMenu *menu = this; 00402 if (defs [i].subid != -1) 00403 VERIFY (menu = subMenu (defs [i].subid)); 00404 00405 // If the item doesn't exist yet, add it 00406 if (! menu->hasItem (defs [i].id)) 00407 if (defs [i].name) 00408 menu->setItemParameter (menu->insertItem (defs [i].id, 00409 defs [i].name, 00410 receiver, 00411 defs [i].member), 00412 defs [i].param); 00413 else 00414 menu->insertSeparator (defs [i].id); 00415 } 00416 } 00417 }
int IgQtObjectMenu::insertItem | ( | int | id, | |
const QIconSet & | icon, | |||
const QPixmap & | pixmap, | |||
const QObject * | receiver, | |||
const char * | member, | |||
const QKeySequence & | accel = 0 | |||
) |
int IgQtObjectMenu::insertItem | ( | int | id, | |
const QPixmap & | pixmap, | |||
const QObject * | receiver, | |||
const char * | member, | |||
const QKeySequence & | accel = 0 | |||
) |
int IgQtObjectMenu::insertItem | ( | int | id, | |
const QIconSet & | icon, | |||
const QString & | text, | |||
const QObject * | receiver, | |||
const char * | member, | |||
const QKeySequence & | accel = 0 | |||
) |
int IgQtObjectMenu::insertItem | ( | int | id, | |
const QString & | text, | |||
const QObject * | receiver, | |||
const char * | member, | |||
const QKeySequence & | accel = 0 | |||
) |
Referenced by insertFromDefs().
Definition at line 223 of file IgQtObjectMenu.cc.
References ASSERT, clearDummy(), itemPosition(), m_menu, and m_submenus.
Referenced by insertFromDefs().
00224 { 00225 ASSERT (m_menu); 00226 ASSERT (m_submenus.size () <= m_menu->count ()); 00227 ASSERT (! m_menu->findItem (id)); 00228 clearDummy (); 00229 unsigned pos = itemPosition (id); 00230 m_menu->insertSeparator (pos); 00231 m_menu->setId (pos, id); 00232 return id; 00233 }
IgQtObjectMenu* IgQtObjectMenu::insertSubMenu | ( | int | id, | |
const QIconSet & | icon, | |||
const QPixmap & | pixmap | |||
) |
IgQtObjectMenu* IgQtObjectMenu::insertSubMenu | ( | int | id, | |
const QPixmap & | pixmap | |||
) |
IgQtObjectMenu* IgQtObjectMenu::insertSubMenu | ( | int | id, | |
const QIconSet & | icon, | |||
const QString & | text | |||
) |
IgQtObjectMenu* IgQtObjectMenu::insertSubMenu | ( | int | id, | |
const QString & | text | |||
) |
Referenced by insertFromDefs().
Definition at line 284 of file IgQtObjectMenu.cc.
References ASSERT, m_menu, and m_submenus.
00285 { 00286 ASSERT (m_menu); 00287 ASSERT (m_submenus.size () <= m_menu->count ()); 00288 ASSERT (m_menu->findItem (id)); 00289 return m_menu->isItemActive (id); 00290 }
Definition at line 302 of file IgQtObjectMenu.cc.
References ASSERT, m_menu, and m_submenus.
00303 { 00304 ASSERT (m_menu); 00305 ASSERT (m_submenus.size () <= m_menu->count ()); 00306 ASSERT (m_menu->findItem (id)); 00307 return m_menu->isItemChecked (id); 00308 }
Definition at line 293 of file IgQtObjectMenu.cc.
References ASSERT, m_menu, and m_submenus.
00294 { 00295 ASSERT (m_menu); 00296 ASSERT (m_submenus.size () <= m_menu->count ()); 00297 ASSERT (m_menu->findItem (id)); 00298 return m_menu->isItemEnabled (id); 00299 }
unsigned IgQtObjectMenu::itemPosition | ( | int | id | ) | const [private] |
Definition at line 153 of file IgQtObjectMenu.cc.
References ASSERT, i, m_menu, and m_submenus.
Referenced by insertSeparator().
00154 { 00155 ASSERT (m_menu); 00156 ASSERT (m_submenus.size () <= m_menu->count ()); 00157 00158 for (unsigned i = 0; i < m_menu->count (); ++i) 00159 if (m_menu->idAt (i) >= id) 00160 return i; 00161 00162 return m_menu->count (); 00163 }
QPixmap* IgQtObjectMenu::pixmap | ( | int | id | ) | const |
Definition at line 420 of file IgQtObjectMenu.cc.
References ASSERT, i, m_menu, removeItem(), and subMenu().
Referenced by VisEventContentTwigOps::menuAction(), VisG4TwigOps::menuAction(), IgTwigOps::menuAction(), Ig3DBaseBrowser::repMenu(), IgSpareWindow::repMenu(), IgLegoWindow::repMenu(), Ig3DWindow::repMenu(), IgRPhiWindow::repMenu(), and IgRZWindow::repMenu().
00421 { 00422 ASSERT (! n || defs); 00423 00424 IgQtObjectMenu *menu; 00425 for (unsigned i = 0; i < n; ++i) 00426 { 00427 if (defs [i].subid == -1 && ! defs [i].member) 00428 { 00429 // If it is an empty sub-menu, remove it 00430 if ((menu = subMenu (defs [i].id)) && ! menu->m_menu->count ()) 00431 removeItem (defs [i].id); 00432 } 00433 else 00434 { 00435 // If the item has sub-menu owner, fetch it 00436 IgQtObjectMenu *menu = this; 00437 if (defs [i].subid != -1) 00438 menu = subMenu (defs [i].subid); 00439 00440 // Remove the item if the menu is still there 00441 if (menu) 00442 { 00443 menu->removeItem (defs [i].id); 00444 00445 // If a sub-menu became empty, remove it 00446 if (menu != this && ! menu->m_menu->count ()) 00447 removeItem (defs [i].subid); 00448 } 00449 } 00450 } 00451 }
Definition at line 338 of file IgQtObjectMenu.cc.
References ASSERT, hasItem(), m_menu, m_submenus, setDummy(), and subMenuPosition().
Referenced by removeFromDefs().
00339 { 00340 if (hasItem (id)) 00341 { 00342 ASSERT (m_menu->findItem (id)); 00343 if (m_menu->findItem (id)->popup ()) 00344 { 00345 unsigned pos = subMenuPosition (id, true); 00346 if (pos < m_submenus.size ()) 00347 m_submenus.erase (m_submenus.begin () + pos); 00348 } 00349 m_menu->removeItem (id); 00350 } 00351 setDummy (); 00352 }
Definition at line 366 of file IgQtObjectMenu.cc.
References ASSERT, m_dummy, and m_menu.
Referenced by IgQtObjectMenu(), and removeItem().
00367 { 00368 // If the menu has become empty and it is not the top level one, 00369 // add a simple note to help the user understand the situation. 00370 // FIXME: We check for one, not zero, because of the tear off 00371 // handle. Sort this out -- we shouldn't know if it has one or 00372 // not. 00373 if (m_menu->count () == 0 && ! dynamic_cast<QPopupMenu *> (m_menu->parent ())) 00374 { 00375 ASSERT (m_dummy == -1); 00376 m_dummy = m_menu->insertItem ("(Nothing applicable)"); 00377 m_menu->setItemEnabled (m_dummy, false); 00378 } 00379 }
Definition at line 320 of file IgQtObjectMenu.cc.
References ASSERT, m_menu, and m_submenus.
Referenced by VisG4TwigOps::menuUpdate().
00321 { 00322 ASSERT (m_menu); 00323 ASSERT (m_submenus.size () <= m_menu->count ()); 00324 ASSERT (m_menu->findItem (id)); 00325 m_menu->setItemChecked (id, check); 00326 }
Definition at line 311 of file IgQtObjectMenu.cc.
References ASSERT, m_menu, and m_submenus.
Referenced by VisG4TwigOps::menuUpdate().
00312 { 00313 ASSERT (m_menu); 00314 ASSERT (m_submenus.size () <= m_menu->count ()); 00315 ASSERT (m_menu->findItem (id)); 00316 m_menu->setItemEnabled (id, enable); 00317 }
Definition at line 274 of file IgQtObjectMenu.cc.
References ASSERT, m_menu, and m_submenus.
Referenced by insertFromDefs().
00275 { 00276 ASSERT (m_menu); 00277 ASSERT (m_submenus.size () <= m_menu->count ()); 00278 ASSERT (m_menu->findItem (id)); 00279 return m_menu->setItemParameter (id, param); 00280 }
IgQtObjectMenu * IgQtObjectMenu::subMenu | ( | int | id | ) | const |
Definition at line 197 of file IgQtObjectMenu.cc.
References m_submenus, and subMenuPosition().
Referenced by insertFromDefs(), VisG4TwigOps::menuUpdate(), and removeFromDefs().
00198 { 00199 unsigned pos = subMenuPosition (id, true); 00200 if (pos < m_submenus.size ()) 00201 return m_submenus [pos]; 00202 else 00203 return 0; 00204 }
Definition at line 166 of file IgQtObjectMenu.cc.
References ASSERT, i, j, m_menu, and m_submenus.
Referenced by removeItem(), and subMenu().
00167 { 00168 // If @a exact, must find an item here, not just insert position; 00169 // if not found, return m_submenu.size (). 00170 ASSERT (m_menu); 00171 ASSERT (m_submenus.size () <= m_menu->count ()); 00172 00173 for (unsigned i = 0, j = 0; i < m_menu->count (); ++i) 00174 { 00175 int itemId = m_menu->idAt (i); 00176 QMenuItem *item = m_menu->findItem (itemId); 00177 00178 ASSERT (item); 00179 ASSERT (j <= m_submenus.size ()); 00180 ASSERT (! item->popup () || j < m_submenus.size ()); 00181 ASSERT (! item->popup () || m_submenus [j]->m_menu == item->popup ()); 00182 00183 if (itemId == id || (itemId > id && ! exact)) 00184 return j; 00185 if (itemId > id && exact) 00186 break; 00187 00188 if (item->popup ()) 00189 ++j; 00190 } 00191 00192 return m_submenus.size (); 00193 }
QString IgQtObjectMenu::text | ( | int | id | ) | const |
QString IgQtObjectMenu::whatsThis | ( | int | id | ) | const |
int IgQtObjectMenu::m_dummy [private] |
QPopupMenu* IgQtObjectMenu::m_menu [private] |
Definition at line 163 of file IgQtObjectMenu.h.
Referenced by clearDummy(), connectItem(), disconnectItem(), hasItem(), IgQtObjectMenu(), insertSeparator(), isItemActive(), isItemChecked(), isItemEnabled(), itemPosition(), removeFromDefs(), removeItem(), setDummy(), setItemChecked(), setItemEnabled(), setItemParameter(), and subMenuPosition().
SubMenus IgQtObjectMenu::m_submenus [private] |
Definition at line 164 of file IgQtObjectMenu.h.
Referenced by connectItem(), disconnectItem(), hasItem(), insertSeparator(), isItemActive(), isItemChecked(), isItemEnabled(), itemPosition(), removeItem(), setItemChecked(), setItemEnabled(), setItemParameter(), subMenu(), and subMenuPosition().