Verified Commit 42da2e74 authored by Flavien BRIDAULT-LOUCHEZ's avatar Flavien BRIDAULT-LOUCHEZ
Browse files

refactor(ui): remove obsolete SSlider, superseded by SParameters

parent cd069b69
......@@ -26,7 +26,6 @@ Here is the list of uncategorized services:
- **SSelectionMenuButton**: shows a menu button. The user can select one item in the menu.
- **SShowAbout**: shows the about frame.
- **SShowHelp**: shows the help content.
- **SSlider**: draws a slider with an integer data.
- **SStatus**: shows a colored square (red, orange, green) representing a status.
- **SStyleSelector**: selects a CSS style.
- **STextStatus**: displays and update values (int, double or string) in a `QLabel`.
......
/************************************************************************
*
* Copyright (C) 2015-2021 IRCAD France
* Copyright (C) 2015-2020 IHU Strasbourg
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
#include "SSlider.hpp"
#include <core/base.hpp>
#include <core/com/Signal.hxx>
#include <core/com/Slots.hxx>
#include <service/macros.hpp>
#include <ui/qt/container/QtContainer.hpp>
#include <QHBoxLayout>
#include <QIntValidator>
#include <QString>
#include <QTime>
#include <chrono>
namespace sight::module::ui::qt
{
const core::com::Signals::SignalKeyType SSlider::s_VALUE_CHANGED_SIG = "valueChanged";
const core::com::Slots::SlotKeyType SSlider::s_SET_VALUE_SLIDER_SLOT = "setValue";
const core::com::Slots::SlotKeyType SSlider::s_SET_MIN_VALUE_SLIDER_SLOT = "setMinValue";
const core::com::Slots::SlotKeyType SSlider::s_SET_MAX_VALUE_SLIDER_SLOT = "setMaxValue";
//------------------------------------------------------------------------------
SSlider::SSlider() noexcept :
m_value(0),
m_minValue(0),
m_maxValue(100),
m_defaultValue(0),
m_text(""),
m_isUpdatedOnRelease(false),
m_hasResetButton(false),
m_hasEditBox(false),
m_sliderPressed(false)
{
newSlot(s_SET_VALUE_SLIDER_SLOT, &SSlider::setValue, this);
newSlot(s_SET_MIN_VALUE_SLIDER_SLOT, &SSlider::setMinValue, this);
newSlot(s_SET_MAX_VALUE_SLIDER_SLOT, &SSlider::setMaxValue, this);
m_sigValueChanged = newSignal<ValueChangedSignalType>(s_VALUE_CHANGED_SIG);
}
//------------------------------------------------------------------------------
SSlider::~SSlider() noexcept
{
}
//------------------------------------------------------------------------------
void SSlider::configuring()
{
this->initialize();
// VALUE
{
core::runtime::ConfigurationElement::sptr config = m_configuration->findConfigurationElement("value");
if(config)
{
m_value = std::stoi(config->getValue());
}
}
// DEFAULT VALUE
{
core::runtime::ConfigurationElement::sptr config = m_configuration->findConfigurationElement("defaultValue");
if(config)
{
m_defaultValue = std::stoi(config->getValue());
}
}
// RESET BUTTON
{
core::runtime::ConfigurationElement::sptr config = m_configuration->findConfigurationElement("resetButton");
if(config)
{
m_hasResetButton = (config->getValue() == "true");
}
}
// UPDATE ON RELEASE
{
core::runtime::ConfigurationElement::sptr config = m_configuration->findConfigurationElement("updateOnRelease");
if(config)
{
m_isUpdatedOnRelease = (config->getValue() == "true");
}
}
// EDIT BOX
{
core::runtime::ConfigurationElement::sptr config = m_configuration->findConfigurationElement("editBox");
if(config)
{
m_hasEditBox = (config->getValue() == "true");
}
}
// TEXT
{
core::runtime::ConfigurationElement::sptr config = m_configuration->findConfigurationElement("text");
if(config)
{
m_text = QString(config->getValue().c_str());
}
}
// RANGE
{
core::runtime::ConfigurationElement::sptr config = m_configuration->findConfigurationElement("range");
if(config)
{
core::runtime::ConfigurationElement::sptr minCfg = config->findConfigurationElement("min");
core::runtime::ConfigurationElement::sptr maxCfg = config->findConfigurationElement("max");
SIGHT_ASSERT("Missing min and max configuration", minCfg && maxCfg);
m_minValue = std::stoi(minCfg->getValue());
m_maxValue = std::stoi(maxCfg->getValue());
}
}
}
//------------------------------------------------------------------------------
void SSlider::starting()
{
this->create();
auto qtContainer = ::sight::ui::qt::container::QtContainer::dynamicCast(this->getContainer());
QPointer<QHBoxLayout> layout = new QHBoxLayout();
m_valueSlider = new QSlider(Qt::Horizontal);
m_valueSlider->setRange(m_minValue, m_maxValue);
m_valueSlider->setValue(m_value);
QMetaObject::Connection isConnected;
isConnected = QObject::connect(m_valueSlider, SIGNAL(sliderPressed()), this, SLOT(sliderPressed()));
SIGHT_ASSERT("sliderPressed Signal failed to connect to sliderPressed Slot.", isConnected);
isConnected = QObject::connect(m_valueSlider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
SIGHT_ASSERT("valueChanged Signal failed to connect to setValue Slot.", isConnected);
isConnected = QObject::connect(m_valueSlider, SIGNAL(sliderReleased()), this, SLOT(changeValue()));
SIGHT_ASSERT("sliderReleased Signal failed to connect to changeValue Slot.", isConnected);
m_textLabel = new QLabel();
m_textLabel->setText(m_text);
if(!m_hasEditBox)
{
m_valueLabel = new QLabel();
m_valueLabel->setText(QString::number(m_value));
}
m_minValueLabel = new QLabel();
m_minValueLabel->setText(QString::number(m_minValue));
m_maxValueLabel = new QLabel();
m_maxValueLabel->setText(QString::number(m_maxValue));
layout->addWidget(m_textLabel);
if(!m_hasEditBox)
{
layout->addWidget(m_valueLabel);
}
layout->addWidget(m_minValueLabel);
layout->addWidget(m_valueSlider);
layout->addWidget(m_maxValueLabel);
if(m_hasEditBox)
{
m_valueEdit = new QLineEdit("");
m_valueEdit->setMaximumWidth(70);
m_valueEdit->setInputMask("#0000");
isConnected = QObject::connect(m_valueEdit, SIGNAL(returnPressed()), this, SLOT(editValue()));
SIGHT_ASSERT("editingFinished Signal failed to connect to onTextChanged Slot.", isConnected);
layout->addWidget(m_valueEdit);
}
if(m_hasResetButton)
{
m_resetButton = new QPushButton("R"); // "R" is codename for Reset !
isConnected = QObject::connect(m_resetButton, SIGNAL(clicked()), this, SLOT(resetValue()));
SIGHT_ASSERT("clicked Signal failed to connect to resetValue Slot.", isConnected);
layout->addWidget(m_resetButton);
}
qtContainer->setLayout(layout);
this->resetValue();
}
//------------------------------------------------------------------------------
void SSlider::stopping()
{
QObject::disconnect(m_valueSlider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
this->destroy();
}
//------------------------------------------------------------------------------
void SSlider::updating()
{
}
//------------------------------------------------------------------------------
void SSlider::sliderPressed()
{
m_sliderPressed = true;
}
//------------------------------------------------------------------------------
void SSlider::resetValue()
{
setValue(m_defaultValue, true);
}
//------------------------------------------------------------------------------
void SSlider::changeValue()
{
SIGHT_ASSERT("m_valueSlider must not be null", nullptr != m_valueSlider);
SIGHT_ASSERT("m_sigValueChanged must not be null", nullptr != m_sigValueChanged);
int value = m_valueSlider->sliderPosition();
m_valueSlider->setSliderPosition(value);
// we use either an edit box or a label to display the current value
if(!m_hasEditBox)
{
SIGHT_ASSERT("m_valueLabel must not be null", nullptr != m_valueLabel);
m_valueLabel->setText(QString::number(value));
}
else
{
SIGHT_ASSERT("m_valueEdit must not be null", nullptr != m_valueEdit);
m_valueEdit->setText(QString::number(value));
}
// Notify the new position
m_sigValueChanged->asyncEmit(value);
m_sliderPressed = false;
}
//------------------------------------------------------------------------------
void SSlider::editValue()
{
SIGHT_ASSERT("m_valueEdit must not be null", false); // && nullptr != m_valueEdit);
QString strValue = m_valueEdit->text();
setValue(strValue.toInt(), true);
}
//------------------------------------------------------------------------------
void SSlider::setValue(int value, bool _bForced)
{
SIGHT_ASSERT("m_valueSlider must not be null", nullptr != m_valueSlider);
// we use either an edit box or a label to display the current value
if(!m_hasEditBox)
{
SIGHT_ASSERT("m_valueLabel must not be null", nullptr != m_valueLabel);
m_valueLabel->setText(QString::number(value));
}
else
{
SIGHT_ASSERT("m_valueEdit must not be null", nullptr != m_valueEdit);
m_valueEdit->setText(QString::number(value));
}
if(!m_sliderPressed || !m_isUpdatedOnRelease || _bForced)
{
m_value = value;
m_valueSlider->setValue(value);
// Notify the new position
m_sigValueChanged->asyncEmit(value);
}
}
//------------------------------------------------------------------------------
void SSlider::setMinValue(int value)
{
SIGHT_ASSERT("m_valueSlider must not be null", nullptr != m_valueSlider);
SIGHT_ASSERT("m_valueSlider must not be null", nullptr != m_valueSlider);
m_minValue = value;
m_valueSlider->setMinimum(value);
m_minValueLabel->setText(QString::number(value));
}
//------------------------------------------------------------------------------
void SSlider::setMaxValue(int value)
{
SIGHT_ASSERT("m_valueSlider must not be null", nullptr != m_valueSlider);
SIGHT_ASSERT("m_maxValueLabel must not be null", nullptr != m_maxValueLabel);
m_maxValue = value;
m_valueSlider->setMaximum(value);
m_maxValueLabel->setText(QString::number(value));
}
//------------------------------------------------------------------------------
} //namespace sight::module::ui::qt
/************************************************************************
*
* Copyright (C) 2015-2021 IRCAD France
* Copyright (C) 2015-2019 IHU Strasbourg
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
#pragma once
#include "modules/ui/qt/config.hpp"
#include <core/com/Slot.hpp>
#include <core/com/Slots.hpp>
#include <core/tools/Failed.hpp>
#include <ui/base/IEditor.hpp>
#include <QLabel>
#include <QLineEdit>
#include <QObject>
#include <QPointer>
#include <QPushButton>
#include <QSlider>
namespace sight::module::ui::qt
{
/**
* @brief This editor allows to draw a slider with an integer data.
*
* Default slider params : value 0, range 0-100, no text, no reset button and edit box.
* @note value, defaultValue, min and max must be integers.
*
* @section XML XML Configuration
* @code{.xml}
<service uid="..." type="sight::module::ui::qt::SSlider" autoConnect="false"/>
<editBox>false</editBox>
<resetButton>false</resetButton>
<defaultValue>200</defaultValue>
<updateOnRelease>false</updateOnRelease>
<value>200</value>
<text>opacity value</text>
<range>
<min>1</min>
<max>600</max>
</range>
</service>
@endcode
*
* @section Signals Signals
* - \b valueChanged(int): This editor emits the signal "valueChanged" with the changed slider value.
*
* @section Slots Slots
* - \b setValue(int, bool): This slot allows to update the slider value.
* - \b setMinValue(int): This slot allows to set minimum value.
* - \b setMaxValue(int): This slot allows to set maximum value.
*/
class MODULE_UI_QT_CLASS_API SSlider : public QObject,
public sight::ui::base::IEditor
{
Q_OBJECT
public:
SIGHT_DECLARE_SERVICE(SSlider, sight::ui::base::IEditor);
/// Constructor. Do nothing.
MODULE_UI_QT_API SSlider() noexcept;
/// Destructor. Do nothing.
MODULE_UI_QT_API virtual ~SSlider() noexcept;
/**@name Signals API
* @{
*/
MODULE_UI_QT_API static const core::com::Signals::SignalKeyType s_VALUE_CHANGED_SIG;
typedef core::com::Signal<void (int)> ValueChangedSignalType;
/** @} */
/**
* @name Slots API
* @{
*/
MODULE_UI_QT_API static const core::com::Slots::SlotKeyType s_SET_VALUE_SLIDER_SLOT;
MODULE_UI_QT_API static const core::com::Slots::SlotKeyType s_SET_MIN_VALUE_SLIDER_SLOT;
MODULE_UI_QT_API static const core::com::Slots::SlotKeyType s_SET_MAX_VALUE_SLIDER_SLOT;
///@}
protected:
typedef core::runtime::ConfigurationElement::sptr Configuration;
/// Installs the layout
void starting() override;
/// Destroys the layout
void stopping() override;
/// Does nothing
void updating() override;
/// Configure the service
void configuring() override;
/// Signal when the position os the slider changed
ValueChangedSignalType::sptr m_sigValueChanged;
protected Q_SLOTS:
/// SLOT : Called to set the value.
void setValue(int value, bool _bForced = false);
/// SLOT : Called to set the min range
void setMinValue(int value);
/// SLOT : Called to set the max range
void setMaxValue(int value);
/// Internal slot. Called when the cursor starts to move.
void sliderPressed();
/// Internal slot. Reset the value - and the slider position - to default
void resetValue();
/// Internal slot. Called when the cursor is moved.
void changeValue();
/// Internal slot. Called when Return is pressed on the edit box
void editValue();
private:
QPointer<QSlider> m_valueSlider; ///< User draggable slider.
QPointer<QLabel> m_valueLabel; ///< The current value. Visible only when there is no edit box.
QPointer<QLabel> m_minValueLabel; ///< Minimum value of the slider displayed on the left side.
QPointer<QLabel> m_maxValueLabel; ///< Maximum value of the slider displayed on the right side.
QPointer<QLabel> m_textLabel; ///< Text displayed on the left.
QPointer<QPushButton> m_resetButton; ///< Button to reset the slider to default value.
QPointer<QLineEdit> m_valueEdit; ///< Edit box, allowing the user to change the slider value
// precisely.
int m_value; ///< Current value.
int m_minValue; ///< Minimum value.
int m_maxValue; ///< Maximum value.
int m_defaultValue; ///< Default value, used when button reset is pressed.
QString m_text; ///< Description, displayed via m_textLabel.
bool m_isUpdatedOnRelease; ///< If true, the value actually updated only on slider release.
bool m_hasResetButton; ///< If true, the reset button is available.
bool m_hasEditBox; ///< If true, the edit box is available, and the value label is off.
bool m_sliderPressed; ///< Set to true when the slider is pressed.
};
} // sight::module::ui::qt
......@@ -53,12 +53,6 @@
<desc>This action show the help contents.</desc>
</extension>
<extension implements="::sight::service::extension::Factory">
<type>sight::ui::base::IEditor</type>
<service>sight::module::ui::qt::SSlider</service>
<desc>This editor allows to draw a slider with an integer data.</desc>
</extension>
<extension implements="::sight::service::extension::Factory">
<type>sight::ui::base::IEditor</type>
<service>sight::module::ui::qt::SStatus</service>
......@@ -70,18 +64,19 @@
<service>sight::module::ui::qt::SStyleSelector</service>
<desc>Selector of theme/style.</desc>
</extension>
<extension implements="::sight::service::extension::Factory">
<type>sight::ui::base::IEditor</type>
<service>sight::module::ui::qt::STextStatus</service>
<desc>This service is used to displays and update values (int, double or string) in a QLabel.</desc>
</extension>
<extension implements="::sight::service::extension::Factory">
<type>sight::ui::base::view::IActivityView</type>
<service>sight::module::ui::qt::activity::SDynamicView</service>
<desc>This editor manages tabs containing activities.</desc>
</extension>
<extension implements="::sight::service::extension::Factory">
<type>sight::ui::base::IAction</type>
<service>sight::module::ui::qt::activity::SLauncher</service>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment