7 #include "guiQt/editor/SSelectionMenuButton.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 11 #include <fwCom/Signals.hpp> 12 #include <fwCom/Slot.hpp> 13 #include <fwCom/Slot.hxx> 14 #include <fwCom/Slots.hpp> 15 #include <fwCom/Slots.hxx> 17 #include <fwCore/base.hpp> 19 #include <fwDataTools/fieldHelper/Image.hpp> 21 #include <fwGuiQt/container/QtContainer.hpp> 23 #include <fwRuntime/ConfigurationElement.hpp> 24 #include <fwRuntime/operations.hpp> 26 #include <fwServices/macros.hpp> 28 #include <fwTools/fwID.hpp> 30 #include <boost/filesystem.hpp> 31 #include <boost/filesystem/convenience.hpp> 35 #include <QPushButton> 37 #include <QVBoxLayout> 47 static const ::fwCom::Signals::SignalKeyType s_SELECTED_SIG =
"selected";
49 static const ::fwCom::Slots::SlotKeyType s_SET_ENABLED_SIG =
"setEnabled";
50 static const ::fwCom::Slots::SlotKeyType s_SENABLE_SIG =
"enable";
51 static const ::fwCom::Slots::SlotKeyType s_DISABLE_SIG =
"disable";
57 m_sigSelected = newSignal < SelectedSignalType >(s_SELECTED_SIG);
59 newSlot(s_SET_ENABLED_SIG, &SSelectionMenuButton::setEnabled,
this);
60 newSlot(s_SENABLE_SIG, &SSelectionMenuButton::enable,
this);
61 newSlot(s_DISABLE_SIG, &SSelectionMenuButton::disable,
this);
76 Configuration txtCfg =
m_configuration->findConfigurationElement(
"text");
79 m_text = txtCfg->getValue();
81 Configuration toolTipCfg =
m_configuration->findConfigurationElement(
"toolTip");
84 m_toolTip = toolTipCfg->getValue();
87 Configuration selectedCfg =
m_configuration->findConfigurationElement(
"selected");
90 m_selection = std::stoi(selectedCfg->getValue());
93 Configuration itemsCfg =
m_configuration->findConfigurationElement(
"items");
94 SLM_ASSERT(
"Missing 'items' config", itemsCfg);
96 std::vector < Configuration > itemCfgs = itemsCfg->find(
"item");
97 SLM_ASSERT(
"At least two items must be defined", itemCfgs.size() >= 2);
98 for (
auto itemCfg : itemCfgs)
100 SLM_ASSERT(
"Missing 'text' attribute", itemCfg->hasAttribute(
"text"));
101 SLM_ASSERT(
"Missing 'value' attribute", itemCfg->hasAttribute(
"value"));
102 std::string txt = itemCfg->getExistingAttributeValue(
"text");
103 std::string val = itemCfg->getExistingAttributeValue(
"value");
104 int value = std::stoi(val);
105 m_items.push_back(std::make_pair(value, txt));
115 ::fwGuiQt::container::QtContainer::sptr qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(
116 this->getContainer() );
118 m_dropDownButton =
new QPushButton( QString::fromStdString(m_text) );
119 m_dropDownButton->setToolTip( QString::fromStdString(m_toolTip));
122 m_pDropDownMenu =
new QMenu();
123 m_actionGroup =
new QActionGroup(m_pDropDownMenu);
125 for (
auto item : m_items)
127 QAction* action =
new QAction(QString::fromStdString(item.second), m_pDropDownMenu);
128 action->setCheckable(
true);
129 action->setData(QVariant(item.first));
130 m_actionGroup->addAction(action);
131 m_pDropDownMenu->addAction(action);
133 if (item.first == m_selection)
135 action->setChecked(
true);
138 QObject::connect(m_actionGroup, SIGNAL(triggered(QAction*)),
this, SLOT(
onSelection(QAction*)));
139 m_dropDownButton->setMenu(m_pDropDownMenu);
141 QVBoxLayout* vLayout =
new QVBoxLayout();
142 vLayout->addWidget( m_dropDownButton);
143 vLayout->setContentsMargins(0, 0, 0, 0);
145 qtContainer->setLayout( vLayout );
152 QObject::connect(m_actionGroup, SIGNAL(triggered(QAction*)),
this, SLOT(
onSelection(QAction*)));
153 for (QAction* action : m_actionGroup->actions())
155 m_actionGroup->removeAction(action);
184 if (action->isChecked())
186 int value = action->data().toInt();
187 m_sigSelected->asyncEmit(value);
194 void SSelectionMenuButton::setEnabled(
bool enabled)
196 m_dropDownButton->setEnabled(enabled);
201 void SSelectionMenuButton::enable()
203 this->setEnabled(
true);
208 void SSelectionMenuButton::disable()
210 this->setEnabled(
false);
Defines the service interface managing the editor service for object.
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
The namespace guiQt contains the basic services to build the application IHM with Qt...
FWGUI_API void initialize()
Initialize managers.