2012-01-05 18:39:17 +00:00
|
|
|
#include "inputcolor.h"
|
|
|
|
|
|
|
|
#include <QLabel>
|
2012-01-05 19:41:10 +00:00
|
|
|
#include <QPushButton>
|
2012-01-07 16:53:23 +00:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QColorDialog>
|
|
|
|
|
|
|
|
class ColorPreview:public QWidget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ColorPreview(QWidget* parent):
|
|
|
|
QWidget(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent* event)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
painter.fillRect(this->rect(), col);
|
|
|
|
}
|
|
|
|
QColor col;
|
|
|
|
};
|
2012-01-05 18:39:17 +00:00
|
|
|
|
2012-01-05 19:41:10 +00:00
|
|
|
InputColor::InputColor(QWidget* form, QString label, Color* value):
|
2012-01-05 18:39:17 +00:00
|
|
|
BaseInput(form, label),
|
2012-01-05 19:41:10 +00:00
|
|
|
_value(value)
|
2012-01-05 18:39:17 +00:00
|
|
|
{
|
2012-01-07 16:53:23 +00:00
|
|
|
_preview = new ColorPreview(form);
|
|
|
|
_preview->setMinimumSize(50, 20);
|
2012-02-28 13:45:11 +00:00
|
|
|
_control = new QPushButton(tr("Edit"), form);
|
2012-01-07 16:53:23 +00:00
|
|
|
_control->setMaximumWidth(150);
|
|
|
|
|
|
|
|
connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(chooseColor()));
|
2012-01-05 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 10:31:01 +00:00
|
|
|
void InputColor::updatePreview()
|
|
|
|
{
|
|
|
|
_preview->update();
|
|
|
|
BaseInput::updatePreview();
|
|
|
|
}
|
|
|
|
|
2012-01-05 18:39:17 +00:00
|
|
|
void InputColor::applyValue()
|
|
|
|
{
|
2012-01-07 16:53:23 +00:00
|
|
|
_value->r = ((ColorPreview*)_preview)->col.redF();
|
|
|
|
_value->g = ((ColorPreview*)_preview)->col.greenF();
|
|
|
|
_value->b = ((ColorPreview*)_preview)->col.blueF();
|
|
|
|
_value->a = 1.0;
|
2012-01-05 19:41:10 +00:00
|
|
|
BaseInput::applyValue();
|
2012-01-05 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputColor::revert()
|
|
|
|
{
|
2012-01-07 16:53:23 +00:00
|
|
|
((ColorPreview*)_preview)->col = QColor::fromRgbF(_value->r, _value->g, _value->b);
|
2012-01-08 10:31:01 +00:00
|
|
|
BaseInput::revert();
|
2012-01-07 16:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputColor::chooseColor()
|
|
|
|
{
|
|
|
|
QColor col = QColorDialog::getColor(((ColorPreview*)_preview)->col, _control);
|
|
|
|
if (col.isValid())
|
|
|
|
{
|
|
|
|
((ColorPreview*)_preview)->col = col;
|
|
|
|
applyValue();
|
|
|
|
}
|
2012-01-05 18:39:17 +00:00
|
|
|
}
|