73 lines
1.5 KiB
C++
73 lines
1.5 KiB
C++
|
|
|
|
#pragma once
|
|
#include "lts_widgets_export.h"
|
|
|
|
#include <QObject>
|
|
#include <QSpinBox>
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
|
|
class LTSWIDGETS_EXPORT LtsSpinBox : public QSpinBox
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit LtsSpinBox(QWidget* parent = nullptr);
|
|
~LtsSpinBox() = default;
|
|
|
|
public slots:
|
|
|
|
void setValue(int val)
|
|
{
|
|
QString valStr = QString::number(val);
|
|
fixup(valStr);
|
|
QSpinBox::setValue(valStr.toInt());
|
|
}
|
|
|
|
bool setExclusionRanges(const QVector<QPair<int, int>>& exclusionRanges, bool preserveCurrentValues = false);
|
|
bool addExclusionRange(int min, int max);
|
|
void clearExclusionRanges();
|
|
|
|
protected:
|
|
QValidator::State validate(QString& input, int& pos) const override;
|
|
void fixup(QString& str) const override;
|
|
|
|
private:
|
|
struct
|
|
{
|
|
bool operator()(const QPair<int, int>& a, const QPair<int, int>& b) const
|
|
{
|
|
return a.first < b.first;
|
|
}
|
|
} customless;
|
|
|
|
QVector<QPair<int, int>> m_exclusions;
|
|
QVector<QPair<int, int>> m_validRanges;
|
|
};
|
|
|
|
class LTSWIDGETS_EXPORT LtsDoubleSpinBox : public QDoubleSpinBox
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit LtsDoubleSpinBox(QWidget* parent = nullptr);
|
|
~LtsDoubleSpinBox() = default;
|
|
|
|
public slots:
|
|
|
|
void setValue(double val)
|
|
{
|
|
QString valStr = QString::number(val);
|
|
fixup(valStr);
|
|
QDoubleSpinBox::setValue(valStr.toDouble());
|
|
}
|
|
|
|
protected:
|
|
QValidator::State validate(QString& input, int& pos) const override;
|
|
void fixup(QString& str) const override;
|
|
};
|
|
|
|
} // namespace LtsWidgets
|