mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-10 21:40:15 +00:00
Added custom spin box class
This commit is contained in:
parent
985af15a12
commit
bc6197c552
51
apps/opencs/view/settings/spinbox.cpp
Normal file
51
apps/opencs/view/settings/spinbox.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include "spinbox.hpp"
|
||||||
|
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
CSVSettings::SpinBox::SpinBox(QWidget *parent)
|
||||||
|
: mValueList(QStringList()), QSpinBox(parent)
|
||||||
|
{
|
||||||
|
setRange (0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CSVSettings::SpinBox::textFromValue(int val) const
|
||||||
|
{
|
||||||
|
if (mValueList.isEmpty())
|
||||||
|
return QVariant (val).toString();
|
||||||
|
|
||||||
|
QString value = "";
|
||||||
|
|
||||||
|
if (val < mValueList.size())
|
||||||
|
value = mValueList.at (val);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSVSettings::SpinBox::valueFromText(const QString &text) const
|
||||||
|
{
|
||||||
|
if (mValueList.isEmpty())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (mValueList.contains (text))
|
||||||
|
return mValueList.indexOf(text);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVSettings::SpinBox::setValue (const QString &value)
|
||||||
|
{
|
||||||
|
if (!mValueList.isEmpty())
|
||||||
|
{
|
||||||
|
lineEdit()->setText (value);
|
||||||
|
QSpinBox::setValue(valueFromText(value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
QSpinBox::setValue (value.toInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVSettings::SpinBox::setValueList (const QStringList &list)
|
||||||
|
{
|
||||||
|
mValueList = list;
|
||||||
|
setMaximum (list.size() - 1);
|
||||||
|
}
|
31
apps/opencs/view/settings/spinbox.hpp
Normal file
31
apps/opencs/view/settings/spinbox.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef CSVSETTINGS_SPINBOX_HPP
|
||||||
|
#define CSVSETTINGS_SPINBOX_HPP
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QSpinBox>
|
||||||
|
|
||||||
|
namespace CSVSettings
|
||||||
|
{
|
||||||
|
class SpinBox : public QSpinBox
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QStringList mValueList;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit SpinBox(QWidget *parent = 0);
|
||||||
|
|
||||||
|
void setObjectName (const QString &name);
|
||||||
|
|
||||||
|
void setValue (const QString &value);
|
||||||
|
void setValueList (const QStringList &list);
|
||||||
|
const QStringList &valueList() const { return mValueList; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
QString textFromValue (int val) const;
|
||||||
|
int valueFromText (const QString &text) const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // CSVSETTINGS_SPINBOX_HPP
|
Loading…
x
Reference in New Issue
Block a user