diff --git a/src/Tools/plugins/widget/customwidgets.cpp b/src/Tools/plugins/widget/customwidgets.cpp
index 4e98707e44..d96b9fb9cb 100644
--- a/src/Tools/plugins/widget/customwidgets.cpp
+++ b/src/Tools/plugins/widget/customwidgets.cpp
@@ -518,6 +518,110 @@ void InputField::setHistorySize(int i)
// --------------------------------------------------------------------
+QuantitySpinBox::QuantitySpinBox (QWidget * parent)
+ : QAbstractSpinBox(parent),
+ Value(0),
+ Maximum(INT_MAX),
+ Minimum(-INT_MAX),
+ StepSize(1.0)
+{
+}
+
+QuantitySpinBox::~QuantitySpinBox()
+{
+}
+
+/// sets the field with a quantity
+void QuantitySpinBox::setValue(double quant)
+{
+ Value = quant;
+ lineEdit()->setText(QString("%1 %2").arg(Value).arg(UnitStr));
+}
+
+/// sets the field with a quantity
+double QuantitySpinBox::value() const
+{
+ return Value;
+}
+
+/// get the value of the singleStep property
+double QuantitySpinBox::singleStep(void)const
+{
+ return StepSize;
+}
+
+/// set the value of the singleStep property
+void QuantitySpinBox::setSingleStep(double s)
+{
+ StepSize = s;
+}
+
+/// get the value of the maximum property
+double QuantitySpinBox::maximum(void)const
+{
+ return Maximum;
+}
+
+/// set the value of the maximum property
+void QuantitySpinBox::setMaximum(double m)
+{
+ Maximum = m;
+}
+
+/// get the value of the minimum property
+double QuantitySpinBox::minimum(void)const
+{
+ return Minimum;
+}
+
+/// set the value of the minimum property
+void QuantitySpinBox::setMinimum(double m)
+{
+ Minimum = m;
+}
+
+QAbstractSpinBox::StepEnabled QuantitySpinBox::stepEnabled() const
+{
+ if (isReadOnly())
+ return StepNone;
+ if (wrapping())
+ return StepEnabled(StepUpEnabled | StepDownEnabled);
+ StepEnabled ret = StepNone;
+ if (Value < Maximum) {
+ ret |= StepUpEnabled;
+ }
+ if (Value > Minimum) {
+ ret |= StepDownEnabled;
+ }
+ return ret;
+}
+
+void QuantitySpinBox::stepBy(int steps)
+{
+ double step = StepSize * steps;
+ double val = Value + step;
+ if (val > Maximum)
+ val = Maximum;
+ else if (val < Minimum)
+ val = Minimum;
+
+ lineEdit()->setText(QString::fromUtf8("%L1 %2").arg(val).arg(UnitStr));
+ update();
+}
+
+void QuantitySpinBox::setUnitText(QString str)
+{
+ UnitStr = str;
+ lineEdit()->setText(QString("%1 %2").arg(Value).arg(UnitStr));
+}
+
+QString QuantitySpinBox::unitText(void)
+{
+ return UnitStr;
+}
+
+// --------------------------------------------------------------------
+
CommandIconView::CommandIconView ( QWidget * parent )
: QListWidget(parent)
{
diff --git a/src/Tools/plugins/widget/customwidgets.h b/src/Tools/plugins/widget/customwidgets.h
index c13e1f8ffb..cdb697aab2 100644
--- a/src/Tools/plugins/widget/customwidgets.h
+++ b/src/Tools/plugins/widget/customwidgets.h
@@ -257,6 +257,50 @@ private:
// ------------------------------------------------------------------------------
+class QuantitySpinBox : public QAbstractSpinBox
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QString unit READ unitText WRITE setUnitText)
+ Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
+ Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
+ Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
+ Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true)
+
+public:
+ QuantitySpinBox (QWidget * parent = 0);
+ virtual ~QuantitySpinBox();
+
+ void setValue(double);
+ double value(void) const;
+ double singleStep(void) const;
+ void setSingleStep(double);
+ double maximum(void) const;
+ void setMaximum(double);
+ double minimum(void) const;
+ void setMinimum(double);
+ void setUnitText(QString);
+ QString unitText(void);
+ void stepBy(int steps);
+
+protected:
+ StepEnabled stepEnabled() const;
+
+Q_SIGNALS:
+ void valueChanged(const Base::Quantity&);
+ void valueChanged(double);
+ void parseError(const QString& errorText);
+
+private:
+ QString UnitStr;
+ double Value;
+ double Maximum;
+ double Minimum;
+ double StepSize;
+};
+
+// ------------------------------------------------------------------------------
+
class CommandIconView : public QListWidget
{
Q_OBJECT
diff --git a/src/Tools/plugins/widget/plugin.cpp b/src/Tools/plugins/widget/plugin.cpp
index 3c4c64db3c..86445f1d11 100644
--- a/src/Tools/plugins/widget/plugin.cpp
+++ b/src/Tools/plugins/widget/plugin.cpp
@@ -514,7 +514,7 @@ public:
}
QString whatsThis() const
{
- return QLatin1String("A widget to work qith quantities.");
+ return QLatin1String("A widget to work with quantities.");
}
bool isContainer() const
{
@@ -533,6 +533,86 @@ public:
}
};
+/* XPM */
+static const char *quantityspinbox_pixmap[]={
+"22 22 6 1",
+"a c #000000",
+"# c #000080",
+"b c #008080",
+"c c #808080",
+"d c #c0c0c0",
+". c #ffffff",
+"...#aaaaaaaaaaaaaa#...",
+".baccccccccccccccccab.",
+".acccddddddddddddddca.",
+"#ccd................d#",
+"acc.............dcd.da",
+"acd.............dbd..a",
+"acd............dcbbd.a",
+"acd.d..dd..d...dbbbc.a",
+"acddb.dbbdcbb.dbbb#bda",
+"acd.b.d.cc..b.bb###bda",
+"acd.b...bd.cb.dddccdda",
+"acd.b...b..db...dddd.a",
+"acd.b..cd...bdddccbbda",
+"acd.b.dbbccdb.ccbbbbda",
+"acddd.ddd.dd..dbbb#cda",
+"acd............bb##cda",
+"acd............db#cd.a",
+"acd.............bbcdda",
+"#cd.............ddd.d#",
+".ac................da.",
+".badd............dda#.",
+"...#aaaaaaaaaaaaaa#..."};
+
+class QuantitySpinBoxPlugin : public QDesignerCustomWidgetInterface
+{
+ Q_INTERFACES(QDesignerCustomWidgetInterface)
+public:
+ QuantitySpinBoxPlugin()
+ {
+ }
+ QWidget *createWidget(QWidget *parent)
+ {
+ return new Gui::QuantitySpinBox(parent);
+ }
+ QString group() const
+ {
+ return QLatin1String("Input Widgets");
+ }
+ QIcon icon() const
+ {
+ return QIcon( QPixmap( quantityspinbox_pixmap ) );
+ }
+ QString includeFile() const
+ {
+ return QLatin1String("Gui/QuantitySpinBox.h");
+ }
+ QString toolTip() const
+ {
+ return QLatin1String("Quantity spin box");
+ }
+ QString whatsThis() const
+ {
+ return QLatin1String("A widget to work with quantities.");
+ }
+ bool isContainer() const
+ {
+ return false;
+ }
+ QString domXml() const
+ {
+ return "\n"
+ " \n"
+ " \n"
+ "";
+ }
+ QString name() const
+ {
+ return QLatin1String("Gui::QuantitySpinBox");
+ }
+};
+
/* XPM */
static const char *iconview_pixmap[]={
"22 22 10 1",
@@ -1333,6 +1413,7 @@ QList CustomWidgetPlugin::customWidgets () con
cw.append(new AccelLineEditPlugin);
cw.append(new ActionSelectorPlugin);
cw.append(new InputFieldPlugin);
+ cw.append(new QuantitySpinBoxPlugin);
cw.append(new CommandIconViewPlugin);
cw.append(new UIntSpinBoxPlugin);
cw.append(new ColorButtonPlugin);