40 QMenuProxy(Type type, QWidget* parent =
nullptr)
41 : menu(nullptr), menuBar(nullptr)
45 case MenuBar: menuBar =
new QMenuBar(parent);
46 case Menu: menu =
new QMenu(parent);
50 bool isMenuBar()
const
52 return menuBar !=
nullptr;
55 void setTitle(
const QString& title)
58 menu->setTitle(title);
61 void setIcon(
const QIcon& icon)
67 QList<QAction*> actions()
const
69 return menu ? menu->actions() : menuBar->actions();
72 void removeAction(QAction* action)
74 menu ? menu->removeAction(action) : menuBar->removeAction(action);
77 bool isEnabled()
const
79 return menu ? menu->isEnabled() : menuBar->isEnabled();
82 void setEnabled(
bool enabled)
84 menu ? menu->setEnabled(enabled) : menuBar->setEnabled(enabled);
87 QAction* getParentItem()
const
89 return menu ? menu->menuAction() :
nullptr;
97 struct NullOverrides:
public IContributionManagerOverrides
101 int GetEnabled(
const IContributionItem* )
const override
106 int GetVisible(
const IContributionItem* )
const override
112 void MenuManager::HandleAboutToShow()
119 this->
Update(
false,
false);
122 void MenuManager::HandleAboutToHide()
128 : id(id), menu(nullptr), menuItem(nullptr)
129 , menuText(text), parent(nullptr)
130 , removeAllWhenShown(false), visible(true)
136 : id(id), menu(nullptr), menuItem(nullptr)
137 , menuText(text), image(image)
138 , parent(nullptr), removeAllWhenShown(false), visible(true)
157 menu =
new QMenuProxy(QMenuProxy::Menu, parent);
158 this->InitializeMenu();
167 menu =
new QMenuProxy(QMenuProxy::MenuBar, parent);
170 return menu->menuBar;
181 this->disconnect(listener);
194 this->FillMenu(parent, before);
199 this->FillMenu(parent, before);
202 void MenuManager::FillMenu(QWidget* parent, QAction* before)
209 parent->insertAction(before,
menuItem);
217 menu =
new QMenuProxy(QMenuProxy::Menu, parent);
220 if (!menu->isMenuBar())
223 this->InitializeMenu();
243 int separator = path.indexOf(
'/');
246 id = path.left(separator);
247 rest = path.mid(separator + 1);
257 return manager->FindUsingPath(rest);
358 bool visibleChildren =
false;
361 if (item->IsVisible() && !item->IsSeparator())
363 visibleChildren =
true;
368 return visibleChildren;
420 this->UpdateMenuItem();
425 QList<IContributionItem::Pointer> items =
GetItems();
427 for (
int i = 0; i < items.size(); i++)
429 items[i]->Update(property);
432 if (menu !=
nullptr && menu->getParentItem() !=
nullptr)
439 menu->getParentItem()->setText(text);
444 menu->getParentItem()->setIcon(
image);
451 this->
Update(force,
false);
456 this->
Update(force,
true);
459 void MenuManager::InitializeMenu()
464 if (!menu->isMenuBar())
466 this->connect(menu->menu, SIGNAL(aboutToShow()), SLOT(HandleAboutToShow()));
467 this->connect(menu->menu, SIGNAL(aboutToHide()), SLOT(HandleAboutToHide()));
474 void MenuManager::UpdateMenuItem()
479 if (menu->isEnabled() != enabled)
488 if (menu->isMenuBar())
490 ci->Fill(menu->menuBar, before);
494 ci->Fill(menu->menu, before);
505 QList<IContributionItem::Pointer> items = this->
GetItems();
506 QList<IContributionItem::Pointer> clean;
510 if (!ci->IsVisible())
514 if (ci->IsSeparator())
524 if (clean.size() > 0)
526 clean.push_back(separator);
535 QList<QAction*> mi = menu->actions();
537 for (
int i = 0; i < mi.size(); i++)
543 menu->removeAction(mi[i]);
547 if(ci->IsDynamic() && ci->IsDirty())
549 menu->removeAction(mi[i]);
556 mi = menu->actions();
560 for (QList<IContributionItem::Pointer>::Iterator e = clean.begin();
561 e != clean.end(); ++e)
567 if (srcIx < mi.size())
569 dest = mi[srcIx]->data().value<
Object::Pointer>().Cast<IContributionItem>();
576 if (dest && src == dest)
581 else if (dest && dest->IsSeparator() && src->IsSeparator())
583 mi[srcIx]->setData(QVariant::fromValue<Object::Pointer>(src));
589 int start = menu->actions().size();
591 this->
DoItemFill(src, destIx >= start ?
nullptr : menu->actions().at(destIx));
592 int newItems = menu->actions().size() - start;
594 for (
int i = 0; i < newItems; ++i)
596 menu->actions().at(destIx++)->setData(QVariant::fromValue<Object::Pointer>(src));
611 item = subItem->GetInnerItem();
615 mm->UpdateAll(force);
622 for (; srcIx < mi.size(); srcIx++)
624 menu->removeAction(mi[srcIx]);
642 mm->UpdateAll(force);
648 this->UpdateMenuItem();
651 void MenuManager::DumpActionInfo(QMenuProxy* menu)
653 if (menu->isMenuBar())
656 DumpActionInfo(menu->menuBar, 1);
661 DumpActionInfo(menu->menu, 1);
665 void MenuManager::DumpActionInfo(QWidget* widget,
int level)
667 QString indent =
" |";
668 for (
int i = 0; i < level; ++i) indent +=
"--";
669 foreach(QAction* action, widget->actions())
671 qDebug() << qPrintable(indent) << action->text() <<
"[" << action <<
"]";
674 DumpActionInfo(action->menu(), level+1);
void RemoveAll() override
void SetDirty(bool dirty)
QList< SmartPointer< IContributionItem > > GetItems() const override
virtual void MarkDirty()=0
static const QString IMAGE
berry::SmartPointer< Self > Pointer
void MarkDirty() override
SmartPointer< IContributionItem > Find(const QString &id) const override
static const QString TEXT
bool IsDirty() const override
The custom viewer plugin implements simple viewer functionality presented in a customized look and feel It was developed to demonstrate extensibility and customizability of the blueberry application framework As an example for the GUI customization capabilities provided by the BlueBerry application the custom viewer plugin was developed It features simple viewer functionality presented in a customized look and feel The custom viewer consists of two i e a viewer perspective and a DICOM perspective As part of the viewer an instance of QmitkDataManagerView allows for data selection Visualization of the selected data is then performed by a simple render window view According data can either be directly loaded from file or be imported as DICOM data DICOM import functionality is accessible from the DICOM perspective incorporating the QmitkDicomExternalDataWidget The customization of Qt Stylesheets is used to give the application a non native look and feel This is further emphasized by a Tab Widget like unification of the perspectives with the according perspective bar In addition to an absence of menu
void SetOverrides(const SmartPointer< IContributionManagerOverrides > &newOverrides)
SmartPointer< Other > Cast() const