165 lines
4.7 KiB
C++
165 lines
4.7 KiB
C++
/*
|
|
PIQt Utils - Qt utilites for PIP
|
|
|
|
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
|
|
|
This program 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.
|
|
|
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef pivariant_edit_widgets_H
|
|
#define pivariant_edit_widgets_H
|
|
|
|
#include "pivariant_edit.h"
|
|
#include <piqt.h>
|
|
#include <QCheckBox>
|
|
#include <QSpinBox>
|
|
#include <QDoubleSpinBox>
|
|
#include <clineedit.h>
|
|
#include <colorbutton.h>
|
|
#include <QTimeEdit>
|
|
#include <QDateEdit>
|
|
|
|
namespace PIVariantEditors {
|
|
|
|
|
|
class QAD_PIQT_UTILS_EXPORT Bool: public PIVariantEditorBase {
|
|
public:
|
|
Bool() {
|
|
widget = new QCheckBox();
|
|
layout()->addWidget(widget);
|
|
}
|
|
void setValue(const PIVariant & v) override {widget->setChecked(v.toBool());}
|
|
PIVariant value() const override {return widget->isChecked();}
|
|
private:
|
|
QCheckBox * widget;
|
|
};
|
|
|
|
|
|
class QAD_PIQT_UTILS_EXPORT Int: public PIVariantEditorBase {
|
|
public:
|
|
Int() {
|
|
widget = new QSpinBox();
|
|
widget->setRange(-std::numeric_limits<int>::max(), std::numeric_limits<int>::max());
|
|
layout()->addWidget(widget);
|
|
}
|
|
void setValue(const PIVariant & v) override {widget->setValue(v.toInt());}
|
|
PIVariant value() const override {return widget->value();}
|
|
PIVariantMap defaultAttributes() const override;
|
|
private:
|
|
void applyAttributes(const PIVariantMap & a) override;
|
|
QSpinBox * widget;
|
|
};
|
|
|
|
|
|
class QAD_PIQT_UTILS_EXPORT Double: public PIVariantEditorBase {
|
|
public:
|
|
Double() {
|
|
widget = new QDoubleSpinBox();
|
|
widget->setRange(-std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
|
|
layout()->addWidget(widget);
|
|
}
|
|
void setValue(const PIVariant & v) override {widget->setValue(v.toDouble());}
|
|
PIVariant value() const override {return widget->value();}
|
|
PIVariantMap defaultAttributes() const override;
|
|
private:
|
|
void applyAttributes(const PIVariantMap & a) override;
|
|
QDoubleSpinBox * widget;
|
|
|
|
};
|
|
|
|
|
|
class QAD_PIQT_UTILS_EXPORT String: public PIVariantEditorBase {
|
|
public:
|
|
String() {
|
|
widget = new CLineEdit();
|
|
layout()->addWidget(widget);
|
|
}
|
|
void setValue(const PIVariant & v) override {widget->setText(PI2QString(v.toString()));}
|
|
PIVariant value() const override {return Q2PIString(widget->text());}
|
|
PIVariantMap defaultAttributes() const override;
|
|
private:
|
|
void applyAttributes(const PIVariantMap & a) override;
|
|
CLineEdit * widget;
|
|
|
|
};
|
|
|
|
|
|
class QAD_PIQT_UTILS_EXPORT Color: public PIVariantEditorBase {
|
|
public:
|
|
Color() {
|
|
widget = new ColorButton();
|
|
layout()->addWidget(widget);
|
|
}
|
|
void setValue(const PIVariant & v) override {widget->setColor(PI2QColor(v.toColor()));}
|
|
PIVariant value() const override {return Q2PIColor(widget->color());}
|
|
PIVariantMap defaultAttributes() const override;
|
|
private:
|
|
void applyAttributes(const PIVariantMap & a) override;
|
|
ColorButton * widget;
|
|
};
|
|
|
|
|
|
class QAD_PIQT_UTILS_EXPORT Time: public PIVariantEditorBase {
|
|
public:
|
|
Time() {
|
|
widget = new QTimeEdit();
|
|
widget->setDisplayFormat("h:mm:ss");
|
|
layout()->addWidget(widget);
|
|
}
|
|
void setValue(const PIVariant & v) override {widget->setTime(PI2QTime(v.toTime()));}
|
|
PIVariant value() const override {return Q2PITime(widget->time());}
|
|
PIVariantMap defaultAttributes() const override {return {};}
|
|
private:
|
|
void applyAttributes(const PIVariantMap & a) override;
|
|
QTimeEdit * widget;
|
|
};
|
|
|
|
|
|
class QAD_PIQT_UTILS_EXPORT Date: public PIVariantEditorBase {
|
|
public:
|
|
Date() {
|
|
widget = new QDateEdit();
|
|
widget->setDisplayFormat("d.MM.yyyy");
|
|
layout()->addWidget(widget);
|
|
}
|
|
void setValue(const PIVariant & v) override {widget->setDate(PI2QDate(v.toDate()));}
|
|
PIVariant value() const override {return Q2PIDate(widget->date());}
|
|
PIVariantMap defaultAttributes() const override {return {};}
|
|
private:
|
|
void applyAttributes(const PIVariantMap & a) override;
|
|
QDateEdit * widget;
|
|
};
|
|
|
|
|
|
class QAD_PIQT_UTILS_EXPORT DateTime: public PIVariantEditorBase {
|
|
public:
|
|
DateTime() {
|
|
widget = new QDateTimeEdit();
|
|
widget->setDisplayFormat("d.MM.yyyy h:mm:ss");
|
|
layout()->addWidget(widget);
|
|
}
|
|
void setValue(const PIVariant & v) override {widget->setDateTime(PI2QDateTime(v.toDateTime()));}
|
|
PIVariant value() const override {return Q2PIDateTime(widget->dateTime());}
|
|
PIVariantMap defaultAttributes() const override {return {};}
|
|
private:
|
|
void applyAttributes(const PIVariantMap & a) override;
|
|
QDateTimeEdit * widget;
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
#endif
|