7 #include "fwGuiQt/layoutManager/ToolBarLayoutManager.hpp" 9 #include "fwGuiQt/ActionCallback.hpp" 10 #include "fwGuiQt/container/QtContainer.hpp" 11 #include "fwGuiQt/container/QtMenuContainer.hpp" 12 #include "fwGuiQt/container/QtMenuItemContainer.hpp" 13 #include "fwGuiQt/container/QtToolBarContainer.hpp" 15 #include <fwGui/registry/macros.hpp> 17 #include <boost/assign/list_of.hpp> 18 #include <boost/lambda/lambda.hpp> 21 #include <QActionGroup> 24 #include <QToolButton> 29 ::fwGui::layoutManager::IToolBarLayoutManager::REGISTRY_KEY );
33 namespace layoutManager
44 ToolBarLayoutManager::~ToolBarLayoutManager()
54 m_parent = ::fwGuiQt::container::QtToolBarContainer::dynamicCast(parent);
55 SLM_ASSERT(
"dynamicCast fwToolBar to QtToolBarContainer failed", m_parent);
57 QToolBar* toolBar = m_parent->getQtToolBar();
59 QActionGroup* actionGroup = 0;
60 unsigned int menuItemIndex = 0;
63 if (actionInfo.m_isSeparator)
65 if (actionInfo.m_size > 0)
67 QWidget* widget =
new QWidget(toolBar);
68 widget->setMinimumWidth(actionInfo.m_size);
69 toolBar->addWidget(widget);
73 toolBar->addSeparator();
77 else if (actionInfo.m_isSpacer)
79 QWidget* spacer =
new QWidget(toolBar);
80 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
81 toolBar->addWidget(spacer);
84 else if (actionInfo.m_isMenu)
86 ::fwGuiQt::container::QtMenuContainer::sptr menu = ::fwGuiQt::container::QtMenuContainer::New();
87 QMenu* qtMenu =
new QMenu(toolBar);
88 menu->setQtMenu(qtMenu);
90 QToolButton* toolButton =
new QToolButton(toolBar);
91 if (toolBar->orientation() == Qt::Horizontal)
93 toolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
97 toolButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
99 toolButton->setMenu(qtMenu);
100 toolButton->setPopupMode(QToolButton::InstantPopup);
101 toolButton->setText(QString::fromStdString(actionInfo.m_name));
102 if (!actionInfo.m_icon.empty())
104 QIcon icon(QString::fromStdString(actionInfo.m_icon.string()));
105 toolButton->setIcon(icon);
106 toolButton->setToolTip(QString::fromStdString(actionInfo.m_name));
107 toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
109 toolBar->addWidget(toolButton);
112 else if (actionInfo.m_isEditor)
114 ::fwGuiQt::container::QtContainer::sptr container = ::fwGuiQt::container::QtContainer::New();
115 QWidget* widget =
new QWidget(toolBar);
116 container->setQtContainer(widget);
118 if (toolBar->orientation() == Qt::Horizontal)
120 widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
124 widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
126 widget->adjustSize();
127 toolBar->addWidget(widget);
133 ::fwGuiQt::container::QtMenuItemContainer::sptr menuItem = ::fwGuiQt::container::QtMenuItemContainer::New();
135 if (!actionInfo.m_icon.empty())
137 QIcon icon(QString::fromStdString(actionInfo.m_icon.string()));
138 if (!actionInfo.m_icon2.empty())
140 icon.addFile(QString::fromStdString(actionInfo.m_icon2.string()), QSize(), QIcon::Normal,
142 icon.addFile(QString::fromStdString(actionInfo.m_icon2.string()), QSize(), QIcon::Active,
145 action = toolBar->addAction( icon, QString::fromStdString(actionInfo.m_name) );
149 action = toolBar->addAction( QString::fromStdString(actionInfo.m_name) );
152 action->setCheckable(actionInfo.m_isCheckable || actionInfo.m_isRadio);
154 if (actionInfo.m_isRadio)
158 actionGroup =
new QActionGroup(toolBar);
160 actionGroup->addAction(action);
164 if( !actionInfo.m_shortcut.empty() )
166 action->setShortcut(QKeySequence(QString::fromStdString(actionInfo.m_shortcut)));
169 menuItem->setQtMenuItem(action);
173 ::fwGui::IMenuItemCallback::sptr callback =
m_callbacks.at(menuItemIndex);
175 ::fwGuiQt::ActionCallback::sptr qtCallback = ::fwGuiQt::ActionCallback::dynamicCast(callback);
176 SLM_ASSERT(
"dynamicCast IMenuItemCallback to ActionCallback failed", qtCallback);
178 QObject::connect( action, SIGNAL(triggered(
bool)), qtCallback.get(), SLOT(executeQt(
bool)));
179 QObject::connect( action, SIGNAL(toggled(
bool)), qtCallback.get(), SLOT(checkQt(
bool)));
198 ::fwGuiQt::container::QtMenuItemContainer::sptr menuItemContainer =
199 ::fwGuiQt::container::QtMenuItemContainer::dynamicCast(fwMenuItem);
200 QAction* action = menuItemContainer->getQtMenuItem();
201 action->setVisible(isVisible);
208 ::fwGuiQt::container::QtMenuItemContainer::sptr menuItemContainer =
209 ::fwGuiQt::container::QtMenuItemContainer::dynamicCast(fwMenuItem);
210 QAction* action = menuItemContainer->getQtMenuItem();
211 action->setEnabled(isEnabled);
218 ::fwGuiQt::container::QtMenuItemContainer::sptr menuItemContainer =
219 ::fwGuiQt::container::QtMenuItemContainer::dynamicCast(fwMenuItem);
220 QAction* action = menuItemContainer->getQtMenuItem();
221 action->setChecked(isChecked);
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
The namespace fwGui contains the base interface for IHM services.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...