7 #include "uiImageQt/ImageTransparency.hpp" 9 #include <fwCom/Signal.hpp> 10 #include <fwCom/Signal.hxx> 11 #include <fwCom/Signals.hpp> 13 #include <fwCore/base.hpp> 15 #include <fwData/Boolean.hpp> 16 #include <fwData/Image.hpp> 18 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp> 20 #include <fwGuiQt/container/QtContainer.hpp> 22 #include <fwMath/IntrasecTypes.hpp> 24 #include <fwServices/IService.hpp> 25 #include <fwServices/macros.hpp> 27 #include <QHBoxLayout> 36 static const ::fwServices::IService::KeyType s_IMAGE_INOUT =
"image";
38 ImageTransparency::ImageTransparency() noexcept
44 ImageTransparency::~ImageTransparency() noexcept
55 ::fwGuiQt::container::QtContainer::sptr qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(
56 this->getContainer() );
58 QHBoxLayout* hLayout =
new QHBoxLayout();
60 QLabel* staticText =
new QLabel( QObject::tr(
"Transparency: "));
61 hLayout->addWidget( staticText, 0, Qt::AlignVCenter );
63 m_valueSlider =
new QSlider( Qt::Horizontal );
64 hLayout->addWidget( m_valueSlider, 1, Qt::AlignVCenter );
65 m_valueSlider->setRange(0, 100);
66 m_valueSlider->setMinimumWidth(100);
68 m_valueCheckBox =
new QCheckBox( QObject::tr(
"visible"));
69 m_action =
new QAction(m_valueCheckBox);
70 m_action->setCheckable(
true);
71 if (!m_shortcut.empty())
73 m_action->setShortcut(QKeySequence(QString::fromStdString(m_shortcut)));
75 m_valueCheckBox->addAction(m_action);
76 hLayout->addWidget( m_valueCheckBox, 0, Qt::AlignVCenter );
78 qtContainer->setLayout( hLayout );
80 QObject::connect(m_valueSlider, SIGNAL(valueChanged(
int)),
this, SLOT(
onModifyTransparency(
int)));
81 QObject::connect(m_valueCheckBox, SIGNAL(stateChanged(
int)),
this, SLOT(
onModifyVisibility(
int)));
82 QObject::connect(m_action, SIGNAL(triggered(
bool)),
this, SLOT(
onModifyVisibility(
bool)));
92 QObject::disconnect(m_valueSlider, SIGNAL(valueChanged(
int)),
this, SLOT(
onModifyTransparency(
int)));
93 QObject::disconnect(m_valueCheckBox, SIGNAL(stateChanged(
int)),
this, SLOT(
onModifyVisibility(
int)));
94 QObject::disconnect(m_action, SIGNAL(triggered(
bool)),
this, SLOT(
onModifyVisibility(
bool)));
107 std::vector < ConfigurationType > vectCfg =
m_configuration->find(
"shortcut");
110 ConfigurationType config = vectCfg.at(0);
111 SLM_ASSERT(
"Missing attribute value", config->hasAttribute(
"value"));
112 m_shortcut = config->getAttributeValue(
"value");
120 ::fwData::Image::sptr img = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
124 img = this->getObject< ::fwData::Image >();
128 m_valueSlider->setEnabled(imageIsValid);
129 m_valueCheckBox->setEnabled(imageIsValid);
132 QObject::disconnect(m_valueSlider, SIGNAL(valueChanged(
int)),
this, SLOT(
onModifyTransparency(
int)));
133 QObject::disconnect(m_valueCheckBox, SIGNAL(stateChanged(
int)),
this, SLOT(
onModifyVisibility(
int)));
134 QObject::disconnect(m_action, SIGNAL(triggered(
bool)),
this, SLOT(
onModifyVisibility(
bool)));
136 if(img->getField(
"TRANSPARENCY" ) )
138 ::fwData::Integer::sptr transparency = img->getField<
::fwData::Integer >(
"TRANSPARENCY" );
139 m_valueSlider->setValue( *transparency );
143 img->setField(
"TRANSPARENCY", ::fwData::Integer::New(0) );
144 m_valueSlider->setValue( 0 );
146 if(img->getField(
"VISIBILITY" ) )
148 ::fwData::Boolean::sptr visible = img->getField<
::fwData::Boolean >(
"VISIBILITY" );
149 m_valueCheckBox->setChecked( *visible );
150 m_action->setChecked(*visible);
154 img->setField(
"VISIBILITY", ::fwData::Boolean::New(
true) );
155 m_valueCheckBox->setChecked(
true );
156 m_action->setChecked(
true);
158 QObject::connect(m_valueSlider, SIGNAL(valueChanged(
int)),
this, SLOT(
onModifyTransparency(
int)));
159 QObject::connect(m_valueCheckBox, SIGNAL(stateChanged(
int)),
this, SLOT(
onModifyVisibility(
int)));
160 QObject::connect(m_action, SIGNAL(triggered(
bool)),
this, SLOT(
onModifyVisibility(
bool)));
175 _sstream <<
"Image Features Editor";
183 ::fwData::Image::sptr img = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
187 img = this->getObject< ::fwData::Image >();
189 img->setField(
"TRANSPARENCY", ::fwData::Integer::New(value) );
204 m_valueCheckBox->setCheckState(value ? Qt::Checked : Qt::Unchecked);
205 this->notifyVisibility(value);
213 m_action->setChecked(value == Qt::Checked);
215 this->notifyVisibility(value == Qt::Checked);
220 void ImageTransparency::notifyVisibility(
bool isVisible)
222 ::fwData::Image::sptr img = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
226 img = this->getObject< ::fwData::Image >();
228 img->setField(
"VISIBILITY", ::fwData::Boolean::New(isVisible) );
233 sig->asyncEmit(isVisible);
257 if (this->getInOut< ::fwData::Image >(s_IMAGE_INOUT))
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_TRANSPARENCY_MODIFIED_SIG
Type of signal when image's buffer is added.
This class is a helper to define the connections of a service and its data.
virtual void info(std::ostream &_sstream) override
Write information in a stream.
ImageTransparency service allows to change image transparency.
Class allowing to block a Connection.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
This class contains an integer value. Integer object is essentially used as a field in other objects...
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.
virtual void swapping() override
Swap the service from associated object to another object.
The namespace uiImageQt contains several editors on image written with Qt. This namespace is included...
virtual void stopping() override
Stops editor.
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
virtual UIIMAGEQT_API KeyConnectionsType getObjSrvConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
virtual KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_VISIBILITY_MODIFIED_SIG
Type of signal when image's buffer is added.
#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...
::fwCom::helper::SigSlotConnection::KeyConnectionsType KeyConnectionsType
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
FWGUI_API void create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
virtual void configuring() override
Configure the service before starting. Apply the configuration to service.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_BUFFER_MODIFIED_SIG
Type of signal when image's buffer is added.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
void onModifyVisibility(bool value)
This method is called when the visibility value change using action shortcut.
void onModifyTransparency(int value)
This method is called when the transparency value change moving slider.
This class defines an image.
virtual void starting() override
Starts editor.
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
virtual void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
FWGUI_API void initialize()
Initialize managers.
This class contains a boolean value.