7 #include "guiQt/editor/SSlider.hpp" 9 #include <fwCom/Signal.hxx> 10 #include <fwCom/Slots.hxx> 12 #include <fwCore/base.hpp> 14 #include <fwGuiQt/container/QtContainer.hpp> 16 #include <fwServices/macros.hpp> 18 #include <QHBoxLayout> 19 #include <QIntValidator> 32 const ::fwCom::Signals::SignalKeyType SSlider::s_VALUE_CHANGED_SIG =
"valueChanged";
34 const ::fwCom::Slots::SlotKeyType SSlider::s_SET_VALUE_SLIDER_SLOT =
"setValue";
35 const ::fwCom::Slots::SlotKeyType SSlider::s_SET_MIN_VALUE_SLIDER_SLOT =
"setMinValue";
36 const ::fwCom::Slots::SlotKeyType SSlider::s_SET_MAX_VALUE_SLIDER_SLOT =
"setMaxValue";
46 m_isUpdatedOnRelease(false),
47 m_hasResetButton(false),
49 m_sliderPressed(false)
71 ::fwRuntime::ConfigurationElement::sptr config =
m_configuration->findConfigurationElement(
"value");
74 m_value = std::stoi(config->getValue());
80 ::fwRuntime::ConfigurationElement::sptr config =
m_configuration->findConfigurationElement(
"defaultValue");
83 m_defaultValue = std::stoi(config->getValue());
89 ::fwRuntime::ConfigurationElement::sptr config =
m_configuration->findConfigurationElement(
"resetButton");
92 m_hasResetButton = (config->getValue() ==
"true");
98 ::fwRuntime::ConfigurationElement::sptr config =
m_configuration->findConfigurationElement(
"updateOnRelease");
101 m_isUpdatedOnRelease = (config->getValue() ==
"true");
107 ::fwRuntime::ConfigurationElement::sptr config =
m_configuration->findConfigurationElement(
"editBox");
110 m_hasEditBox = (config->getValue() ==
"true");
116 ::fwRuntime::ConfigurationElement::sptr config =
m_configuration->findConfigurationElement(
"text");
119 m_text = QString(config->getValue().c_str());
125 ::fwRuntime::ConfigurationElement::sptr config =
m_configuration->findConfigurationElement(
"range");
128 ::fwRuntime::ConfigurationElement::sptr minCfg = config->findConfigurationElement(
"min");
129 ::fwRuntime::ConfigurationElement::sptr maxCfg = config->findConfigurationElement(
"max");
130 SLM_ASSERT(
"Missing min and max configuration", minCfg && maxCfg);
132 m_minValue = std::stoi(minCfg->getValue());
133 m_maxValue = std::stoi(maxCfg->getValue());
142 ::fwGuiQt::container::QtContainer::sptr qtContainer =
143 ::fwGuiQt::container::QtContainer::dynamicCast(this->getContainer());
145 QPointer<QHBoxLayout> layout =
new QHBoxLayout();
146 m_valueSlider =
new QSlider(Qt::Horizontal);
147 m_valueSlider->setRange(m_minValue, m_maxValue);
148 m_valueSlider->setValue(m_value);
150 QMetaObject::Connection isConnected;
152 SLM_ASSERT(
"sliderPressed Signal failed to connect to sliderPressed Slot.", isConnected);
154 isConnected = QObject::connect(m_valueSlider, SIGNAL(valueChanged(
int)),
this, SLOT(
setValue(
int)));
155 SLM_ASSERT(
"valueChanged Signal failed to connect to setValue Slot.", isConnected);
157 isConnected = QObject::connect(m_valueSlider, SIGNAL(sliderReleased()),
this, SLOT(
changeValue()));
158 SLM_ASSERT(
"sliderReleased Signal failed to connect to changeValue Slot.", isConnected);
160 m_textLabel =
new QLabel();
161 m_textLabel->setText(m_text);
165 m_valueLabel =
new QLabel();
166 m_valueLabel->setText(QString::number(m_value));
169 m_minValueLabel =
new QLabel();
170 m_minValueLabel->setText(QString::number(m_minValue));
172 m_maxValueLabel =
new QLabel();
173 m_maxValueLabel->setText(QString::number(m_maxValue));
175 layout->addWidget( m_textLabel );
179 layout->addWidget( m_valueLabel );
181 layout->addWidget( m_minValueLabel );
182 layout->addWidget( m_valueSlider );
183 layout->addWidget( m_maxValueLabel );
187 m_valueEdit =
new QLineEdit(
"");
188 m_valueEdit->setMaximumWidth( 70 );
189 m_valueEdit->setInputMask(
"#0000");
191 isConnected = QObject::connect( m_valueEdit, SIGNAL(returnPressed()),
this, SLOT(
editValue()) );
192 SLM_ASSERT(
"editingFinished Signal failed to connect to onTextChanged Slot.", isConnected);
194 layout->addWidget( m_valueEdit );
197 if( m_hasResetButton )
199 m_resetButton =
new QPushButton(
"R");
201 isConnected = QObject::connect(m_resetButton, SIGNAL(clicked()),
this, SLOT(
resetValue()));
202 SLM_ASSERT(
"clicked Signal failed to connect to resetValue Slot.", isConnected);
204 layout->addWidget( m_resetButton );
208 qtContainer->setLayout(layout);
219 QObject::disconnect(m_valueSlider, SIGNAL(valueChanged(
int)),
this, SLOT(
setValue(
int)));
239 m_sliderPressed =
true;
251 SLM_ASSERT(
"m_valueSlider must not be null",
nullptr != m_valueSlider );
254 int value = m_valueSlider->sliderPosition();
255 m_valueSlider->setSliderPosition(value);
260 SLM_ASSERT(
"m_valueLabel must not be null",
nullptr != m_valueLabel);
262 m_valueLabel->setText(QString::number(value));
266 SLM_ASSERT(
"m_valueEdit must not be null",
nullptr != m_valueEdit);
268 m_valueEdit->setText(QString::number(value));
274 m_sliderPressed =
false;
281 SLM_ASSERT(
"m_valueEdit must not be null",
false );
283 QString strValue = m_valueEdit->text();
292 SLM_ASSERT(
"m_valueSlider must not be null",
nullptr != m_valueSlider);
297 SLM_ASSERT(
"m_valueLabel must not be null",
nullptr != m_valueLabel);
299 m_valueLabel->setText(QString::number(value));
303 SLM_ASSERT(
"m_valueEdit must not be null",
nullptr != m_valueEdit);
305 m_valueEdit->setText(QString::number(value));
308 if( !m_sliderPressed || !m_isUpdatedOnRelease || _bForced )
311 m_valueSlider->setValue(value);
322 SLM_ASSERT(
"m_valueSlider must not be null",
nullptr != m_valueSlider);
323 SLM_ASSERT(
"m_valueSlider must not be null",
nullptr != m_valueSlider);
326 m_valueSlider->setMinimum( value );
327 m_minValueLabel->setText( QString::number(value));
334 SLM_ASSERT(
"m_valueSlider must not be null",
nullptr != m_valueSlider);
335 SLM_ASSERT(
"m_maxValueLabel must not be null",
nullptr != m_maxValueLabel);
338 m_valueSlider->setMaximum( value );
339 m_maxValueLabel->setText( QString::number(value));
virtual void configuring() override
Configure the service.
void setMaxValue(int value)
SLOT : Called to set the max range.
void setValue(int value, bool _bForced=false)
SLOT : Called to set the value.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
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 GUIQT_API ~SSlider() noexcept
Destructor. Do nothing.
This editor allows to draw a slider with an integer data.
void sliderPressed()
Internal slot. Called when the cursor starts to move.
virtual void starting() override
Installs the layout.
void resetValue()
Internal slot. Reset the value - and the slider position - to default.
virtual void swapping() override
Does nothing.
ValueChangedSignalType::sptr m_sigValueChanged
Signal when the position os the slider changed.
GUIQT_API SSlider() noexcept
Constructor. Do nothing.
void editValue()
Internal slot. Called when Return is pressed on the edit box.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual void stopping() override
Destroys the layout.
::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.
void changeValue()
Internal slot. Called when the cursor is moved.
void setMinValue(int value)
SLOT : Called to set the min range.
virtual void updating() override
Does nothing.
The namespace guiQt contains the basic services to build the application IHM with Qt...
FWGUI_API void initialize()
Initialize managers.