-
Wuttke, Joachim authoredWuttke, Joachim authored
DoubleSpinBox.cpp 1.96 KiB
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Numeric/DoubleSpinBox.cpp
//! @brief Implements class DoubleSpinBox.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2021
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/View/Numeric/DoubleSpinBox.h"
#include "GUI/View/Numeric/NumberUtil.h"
#include <QWheelEvent>
DoubleSpinBox::DoubleSpinBox(const DoubleProperty& d, bool easyScrollable, QWidget* parent)
: QDoubleSpinBox(parent)
, m_valueProperty(d)
, m_easyScrollable(easyScrollable)
{
setFocusPolicy(Qt::StrongFocus);
GUI::View::NumberUtil::configSpinBox(this, d.decimals(), d.limits());
setToolTip(d.tooltip());
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
QSignalBlocker b(this);
QDoubleSpinBox::setValue(m_valueProperty.value());
QObject::connect(this, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&DoubleSpinBox::onDisplayValueChanged);
setSingleStep(m_valueProperty.step());
}
// This method is only used in undo/redo functionality in SampleEditorController
QString DoubleSpinBox::uid() const
{
return m_valueProperty.uid();
}
void DoubleSpinBox::setBaseValue(double value)
{
QDoubleSpinBox::setValue(value);
}
void DoubleSpinBox::wheelEvent(QWheelEvent* event)
{
if (hasFocus() || m_easyScrollable)
QDoubleSpinBox::wheelEvent(event);
else
event->ignore();
}
void DoubleSpinBox::onDisplayValueChanged(double value)
{
emit baseValueChanged(value);
}
void DoubleSpinBox::updateValue()
{
QSignalBlocker _(this);
setBaseValue(m_valueProperty.value());
}