23 #include <QColorDialog>
24 #include <QCoreApplication>
26 #include <QHBoxLayout>
30 #include <QSizePolicy>
31 #include <QSpacerItem>
32 #include <QToolButton>
34 #include "../vproperty.h"
37 : QWidget(parent), Color(), ToolButton(nullptr), TextLabel(nullptr), ColorLabel(nullptr), Spacer(nullptr)
39 setAutoFillBackground(
true);
43 ToolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
60 Spacer =
new QSpacerItem(1, 0, QSizePolicy::Expanding, QSizePolicy::Ignored);
63 QHBoxLayout *layout =
new QHBoxLayout(
this);
64 layout->setSpacing(3);
79 ColorLabel->setPixmap(GetColorPixmap(Color));
80 TextLabel->setText(GetColorString(Color));
86 QImage tmpImgage(
static_cast<int>(size),
static_cast<int>(size), QImage::Format_ARGB32_Premultiplied);
87 tmpImgage.fill(
static_cast<quint32
>(color.rgb()));
88 return QPixmap::fromImage(tmpImgage);
94 return QString(
"[%1, %2, %3] (%4)").arg(color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha());
99 const QColor newColor = QColorDialog::getColor(Color,
this, QString(), QColorDialog::ShowAlphaChannel);
100 if (newColor.isValid() && newColor != Color)
102 setLineColor(newColor);
103 emit dataChangedByUser(Color,
this);
105 QCoreApplication::postEvent (
this, event );
111 if (obj == ToolButton && ev->type() == QEvent::KeyPress)
118 return QWidget::eventFilter(obj, ev);
static QString GetColorString(const QColor &color)
A helper function to convert a color into a string.
VColorPropertyEditor(QWidget *parent)
Constructor taking a widget as parent.
static QPixmap GetColorPixmap(const QColor &color, quint32 size=16)
A little helper function generating an image to represent a color.
virtual bool eventFilter(QObject *obj, QEvent *ev) Q_DECL_OVERRIDE
Needed for proper event handling.
QColor getLineColor() const
Returns the color currently set.
virtual ~VColorPropertyEditor() Q_DECL_OVERRIDE
Destructor.
void onToolButtonClicked()
void setLineColor(const QColor &color_)
Sets the color of the widget.