7 #include "guiQt/editor/SSignalButton.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 <fwGuiQt/container/QtContainer.hpp> 21 #include <fwRuntime/ConfigurationElement.hpp> 22 #include <fwRuntime/operations.hpp> 24 #include <fwServices/macros.hpp> 26 #include <fwTools/fwID.hpp> 28 #include <QVBoxLayout> 37 static const ::fwCom::Signals::SignalKeyType s_CLICKED_SIG =
"clicked";
38 static const ::fwCom::Signals::SignalKeyType s_TOGGLED_SIG =
"toggled";
40 static const ::fwCom::Slots::SlotKeyType s_SET_CHECKED_SLOT =
"setChecked";
48 m_checkAtStart(false),
52 m_sigClicked = newSignal< ClickedSignalType >(s_CLICKED_SIG);
53 m_sigToggled = newSignal< ToggledSignalType >(s_TOGGLED_SIG);
55 newSlot(s_SET_CHECKED_SLOT, &SSignalButton::setChecked,
this);
70 ::fwGuiQt::container::QtContainer::sptr qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(
71 this->getContainer() );
73 QVBoxLayout* layout =
new QVBoxLayout();
74 m_button =
new QPushButton(QString::fromStdString(m_text));
75 layout->addWidget(m_button);
76 qtContainer->setLayout(layout);
80 m_button->setIcon(QIcon(QString::fromStdString(m_icon.string())));
82 if (m_iconWidth > 0 && m_iconHeight > 0)
84 m_button->setIconSize(QSize(m_iconWidth, m_iconHeight));
89 m_button->setCheckable(
true);
93 m_button->setChecked(
true);
96 m_button->setText(QString::fromStdString(m_text2));
100 m_button->setIcon(QIcon(QString::fromStdString(m_icon2.string())));
105 QObject::connect(m_button.data(), &QPushButton::clicked,
this, &SSignalButton::onClicked );
106 QObject::connect(m_button.data(), &QPushButton::toggled,
this, &SSignalButton::onToggled );
122 ::fwRuntime::ConfigurationElement::sptr config =
m_configuration->findConfigurationElement(
"config");
123 SLM_ASSERT(
"'config' tag is missing", config);
125 ::fwRuntime::ConfigurationElement::sptr checkableCfg = config->findConfigurationElement(
"checkable");
128 SLM_ASSERT(
"'checkable' value must be 'true' or 'false'",
129 checkableCfg->getValue() ==
"true" || checkableCfg->getValue() ==
"false");
130 m_checkable = (checkableCfg->getValue() ==
"true");
133 ::fwRuntime::ConfigurationElement::sptr txtCfg = config->findConfigurationElement(
"text");
136 m_text = txtCfg->getValue();
138 ::fwRuntime::ConfigurationElement::sptr iconCfg = config->findConfigurationElement(
"icon");
141 m_icon = ::fwRuntime::getBundleResourceFilePath(iconCfg->getValue());
144 ::fwRuntime::ConfigurationElement::sptr txt2Cfg = config->findConfigurationElement(
"text2");
147 SLM_ASSERT(
"Button must be 'checkable' in order to defined 'text2'", m_checkable);
148 SLM_ASSERT(
"'text' tag must be defined in order to specify 'text2'", !m_text.empty());
149 m_text2 = txt2Cfg->getValue();
152 ::fwRuntime::ConfigurationElement::sptr icon2Cfg = config->findConfigurationElement(
"icon2");
155 SLM_ASSERT(
"Button must be 'checkable' in order to defined 'icon2'", m_checkable);
156 SLM_ASSERT(
"'icon' tag must be defined in order to specify 'icon2'", iconCfg);
157 m_icon2 = ::fwRuntime::getBundleResourceFilePath(icon2Cfg->getValue());
160 ::fwRuntime::ConfigurationElement::sptr checkedCfg = config->findConfigurationElement(
"checked");
163 SLM_ASSERT(
"Button must be 'checkable' in order to defined 'checked'", m_checkable);
164 SLM_ASSERT(
"'checked' value must be 'true' or 'false'",
165 checkedCfg->getValue() ==
"true" || checkedCfg->getValue() ==
"false");
166 m_checkAtStart = (checkedCfg->getValue() ==
"true");
169 ::fwRuntime::ConfigurationElement::sptr widthCfg = config->findConfigurationElement(
"iconWidth");
172 m_iconWidth = std::stoi(widthCfg->getValue());
175 ::fwRuntime::ConfigurationElement::sptr heightCfg = config->findConfigurationElement(
"iconHeight");
178 m_iconHeight = std::stoi(heightCfg->getValue());
184 void SSignalButton::onClicked()
186 m_sigClicked->asyncEmit();
191 void SSignalButton::onToggled(
bool toogled)
193 this->setChecked(toogled);
194 m_sigToggled->asyncEmit(toogled);
199 void SSignalButton::setChecked(
bool checked)
203 if (!m_text2.empty())
205 m_button->setText(QString::fromStdString(m_text2));
207 if (!m_icon2.empty())
209 m_button->setIcon(QIcon(QString::fromStdString(m_icon2.string())));
216 m_button->setText(QString::fromStdString(m_text));
220 m_button->setIcon(QIcon(QString::fromStdString(m_icon.string())));
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.