Commit d3f53cca authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner: Adding custom color dialog

parent 40ce2289
......@@ -43,6 +43,11 @@
#include <QToolButton>
#include <QGradient>
#include <QPainter>
#include <QDoubleSpinBox>
#include <QGridLayout>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QGraphicsEffect>
static inline int clamp(int x, int lower, int upper)
{
......@@ -151,7 +156,7 @@ void HueControl::setCurrent(int y)
m_color.setHsv((y * 359)/120, m_color.hsvSaturation(), m_color.value());
m_color.setAlpha(oldAlpha);
update(); // redraw pointer
emit hueChanged();
emit hueChanged(m_color.hsvHue());
}
void HueControl::setHue(int newHue)
......@@ -160,7 +165,7 @@ void HueControl::setHue(int newHue)
return;
m_color.setHsv(newHue, m_color.hsvSaturation(), m_color.value());
update();
emit hueChanged();
emit hueChanged(m_color.hsvHue());
}
void HueControl::paintEvent(QPaintEvent *event)
......@@ -754,4 +759,105 @@ void GradientLine::setCurrentIndex(int i)
update();
}
BauhausColorDialog::BauhausColorDialog(QWidget *parent) : QFrame(parent )
{
setFrameStyle(QFrame::NoFrame);
setFrameShape(QFrame::StyledPanel);
setFrameShadow(QFrame::Sunken);
QGraphicsDropShadowEffect *dropShadowEffect = new QGraphicsDropShadowEffect;
dropShadowEffect->setBlurRadius(6);
dropShadowEffect->setOffset(2, 2);
setGraphicsEffect(dropShadowEffect);
setAutoFillBackground(true);
m_hueControl = new HueControl(this);
m_colorBox = new ColorBox(this);
m_rSpinBox = new QDoubleSpinBox(this);
m_gSpinBox = new QDoubleSpinBox(this);
m_bSpinBox = new QDoubleSpinBox(this);
m_alphaSpinBox = new QDoubleSpinBox(this);
QGridLayout *gridLayout = new QGridLayout(this);
setLayout(gridLayout);
gridLayout->addWidget(m_colorBox, 0, 0, 4, 1);
gridLayout->addWidget(m_hueControl, 0, 1, 4, 1);
gridLayout->addWidget(new QLabel("R", this), 0, 2, 1, 1);
gridLayout->addWidget(new QLabel("G", this), 1, 2, 1, 1);
gridLayout->addWidget(new QLabel("B", this), 2, 2, 1, 1);
gridLayout->addWidget(new QLabel("A", this), 3, 2, 1, 1);
gridLayout->addWidget(m_rSpinBox, 0, 3, 1, 1);
gridLayout->addWidget(m_gSpinBox, 1, 3, 1, 1);
gridLayout->addWidget(m_bSpinBox, 2, 3, 1, 1);
gridLayout->addWidget(m_alphaSpinBox, 3, 3, 1, 1);
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
QPushButton *applyButton = buttonBox->addButton(QDialogButtonBox::Apply);
gridLayout->addWidget(buttonBox, 4, 0, 2, 1);
resize(sizeHint());
connect(m_colorBox, SIGNAL(colorChanged()), this, SLOT(onColorBoxChanged()));
connect(m_alphaSpinBox, SIGNAL(valueChanged(double)), this, SLOT(spinBoxChanged()));
connect(m_rSpinBox, SIGNAL(valueChanged(double)), this, SLOT(spinBoxChanged()));
connect(m_gSpinBox, SIGNAL(valueChanged(double)), this, SLOT(spinBoxChanged()));
connect(m_bSpinBox, SIGNAL(valueChanged(double)), this, SLOT(spinBoxChanged()));
connect(m_hueControl, SIGNAL(hueChanged(int)), this, SLOT(onHueChanged(int)));
connect(applyButton, SIGNAL(pressed()), this, SLOT(onAccept()));
connect(cancelButton, SIGNAL(pressed()), this, SIGNAL(rejected()));
m_alphaSpinBox->setMaximum(1);
m_rSpinBox->setMaximum(1);
m_gSpinBox->setMaximum(1);
m_bSpinBox->setMaximum(1);
m_alphaSpinBox->setSingleStep(0.1);
m_rSpinBox->setSingleStep(0.1);
m_gSpinBox->setSingleStep(0.1);
m_bSpinBox->setSingleStep(0.1);
m_blockUpdate = false;
}
void BauhausColorDialog::spinBoxChanged()
{
if (m_blockUpdate)
return;
QColor newColor;
newColor.setAlphaF(m_alphaSpinBox->value());
newColor.setRedF(m_rSpinBox->value());
newColor.setGreenF(m_gSpinBox->value());
newColor.setBlueF(m_bSpinBox->value());
setColor(newColor);
}
void BauhausColorDialog::onColorBoxChanged()
{
if (m_blockUpdate)
return;
setColor(m_colorBox->color());
}
void BauhausColorDialog::setupWidgets()
{
m_blockUpdate = true;
m_hueControl->setHue(m_color.hsvHue());
m_alphaSpinBox->setValue(m_color.alphaF());
m_rSpinBox->setValue(m_color.redF());
m_gSpinBox->setValue(m_color.greenF());
m_bSpinBox->setValue(m_color.blueF());
m_colorBox->setColor(m_color);
m_blockUpdate = false;
}
}
......@@ -39,10 +39,12 @@
#include <qdeclarative.h>
#include <propertyeditorvalue.h>
#include <qmlitemnode.h>
#include <QDialog>
QT_BEGIN_NAMESPACE
class QtColorButton;
class QToolButton;
class QDoubleSpinBox;
QT_END_NAMESPACE
namespace QmlDesigner {
......@@ -144,7 +146,7 @@ public:
int hue() const { return m_color.hsvHue(); }
signals:
void hueChanged();
void hueChanged(int hue);
protected:
void paintEvent(QPaintEvent *);
......@@ -215,6 +217,68 @@ private:
bool m_dragOff;
};
class BauhausColorDialog : public QFrame {
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
public:
BauhausColorDialog(QWidget *parent = 0);
QColor color() const { return m_color; }
void setColor(const QColor &color)
{
if (color == m_color)
return;
m_color = color;
setupWidgets();
emit colorChanged();
}
public slots:
void changeColor(const QColor &color) { setColor(color); }
void spinBoxChanged();
void onColorBoxChanged();
void onHueChanged(int newHue)
{
if (m_blockUpdate)
return;
if (m_color.hsvHue() == newHue)
return;
m_color.setHsv(newHue, m_color.hsvSaturation(), m_color.value());
setupWidgets();
emit colorChanged();
}
void onAccept()
{
emit accepted(m_color);
}
signals:
void colorChanged();
void accepted(const QColor &color);
void rejected();
protected:
void setupWidgets();
private:
ColorBox *m_colorBox;
HueControl *m_hueControl;
QDoubleSpinBox *m_rSpinBox;
QDoubleSpinBox *m_gSpinBox;
QDoubleSpinBox *m_bSpinBox;
QDoubleSpinBox *m_alphaSpinBox;
QColor m_color;
bool m_blockUpdate;
};
class ColorWidget {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment