forked from qt-creator/qt-creator
QmlDesigner.propertyEditor: cleanup of Color Widgets
This commit is contained in:
@@ -28,12 +28,6 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "colorwidget.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QToolButton>
|
||||
#include <QGradient>
|
||||
#include <QPainter>
|
||||
#include <QtDebug>
|
||||
#include <modelnode.h>
|
||||
#include <abstractview.h>
|
||||
#include <nodeproperty.h>
|
||||
@@ -44,17 +38,72 @@
|
||||
#include <QGradient>
|
||||
#include <metainfo.h>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QToolButton>
|
||||
#include <QGradient>
|
||||
#include <QPainter>
|
||||
|
||||
static inline int clamp(int x, int lower, int upper)
|
||||
{
|
||||
if (x < lower)
|
||||
x = lower;
|
||||
if (x > upper)
|
||||
x = upper;
|
||||
return x;
|
||||
}
|
||||
|
||||
inline QString properName(const QColor &color)
|
||||
{
|
||||
QString s;
|
||||
if (color.alpha() == 255)
|
||||
s.sprintf("#%02x%02x%02x", color.red(), color.green(), color.blue());
|
||||
else
|
||||
s.sprintf("#%02x%02x%02x%02x", color.alpha(), color.red(), color.green(), color.blue());
|
||||
return s;
|
||||
}
|
||||
|
||||
inline QColor properColor(const QString &str)
|
||||
{
|
||||
int lalpha = 255;
|
||||
QString lcolorStr = str;
|
||||
if (lcolorStr.at(0) == '#' && lcolorStr.length() == 9) {
|
||||
QString alphaStr = lcolorStr;
|
||||
alphaStr.truncate(3);
|
||||
lcolorStr.remove(0, 3);
|
||||
lcolorStr = "#" + lcolorStr;
|
||||
alphaStr.remove(0,1);
|
||||
bool v;
|
||||
lalpha = alphaStr.toInt(&v, 16);
|
||||
if (!v)
|
||||
lalpha = 255;
|
||||
}
|
||||
QColor lcolor(lcolorStr);
|
||||
lcolor.setAlpha(lalpha);
|
||||
return lcolor;
|
||||
}
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
void ColorWidget::registerDeclarativeTypes() {
|
||||
void ColorWidget::registerDeclarativeTypes() {
|
||||
qmlRegisterType<QmlDesigner::ColorButton>("Bauhaus",1,0,"ColorButton");
|
||||
qmlRegisterType<QmlDesigner::HueControl>("Bauhaus",1,0,"HueControl");
|
||||
qmlRegisterType<QmlDesigner::ColorBox>("Bauhaus",1,0,"ColorBox");
|
||||
qmlRegisterType<QmlDesigner::GradientLine>("Bauhaus",1,0,"GradientLine");
|
||||
}
|
||||
}
|
||||
|
||||
void ColorButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
void ColorButton::setColor(const QString &colorStr)
|
||||
{
|
||||
if (m_colorString == colorStr)
|
||||
return;
|
||||
|
||||
m_colorString = colorStr;
|
||||
update();
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
void ColorButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QToolButton::paintEvent(event);
|
||||
if (!isEnabled())
|
||||
return;
|
||||
@@ -94,22 +143,30 @@ namespace QmlDesigner {
|
||||
p.setPen("#707070");
|
||||
p.setBrush(Qt::white);
|
||||
p.drawPolygon(points);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HueControl::setCurrent(int y)
|
||||
{
|
||||
if (y<0) y=0;
|
||||
if (y>120) y=120;
|
||||
void HueControl::setCurrent(int y)
|
||||
{
|
||||
y = clamp(y, 0, 120);
|
||||
int oldAlpha = m_color.alpha();
|
||||
m_color.setHsv((y * 359)/120, m_color.hsvSaturation(), m_color.value());
|
||||
m_color.setAlpha(oldAlpha);
|
||||
update(); // redraw pointer
|
||||
emit hueChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void HueControl::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
void HueControl::setHue(int newHue)
|
||||
{
|
||||
if (m_color.hsvHue() == newHue)
|
||||
return;
|
||||
m_color.setHsv(newHue, m_color.hsvSaturation(), m_color.value());
|
||||
update();
|
||||
emit hueChanged();
|
||||
}
|
||||
|
||||
void HueControl::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
|
||||
QPainter p(this);
|
||||
@@ -146,23 +203,127 @@ namespace QmlDesigner {
|
||||
p.setPen(Qt::black);
|
||||
p.setBrush(QColor("#707070"));
|
||||
p.drawPolygon(points);
|
||||
}
|
||||
}
|
||||
|
||||
void ColorBox::setCurrent(int x, int y)
|
||||
{
|
||||
void HueControl::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
// The current cell marker is set to the cell the mouse is pressed in
|
||||
QPoint pos = e->pos();
|
||||
m_mousePressed = true;
|
||||
setCurrent(pos.y() - 5);
|
||||
}
|
||||
|
||||
void HueControl::mouseReleaseEvent(QMouseEvent * /* event */)
|
||||
{
|
||||
m_mousePressed = false;
|
||||
}
|
||||
|
||||
void HueControl::mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
if (!m_mousePressed)
|
||||
return;
|
||||
QPoint pos = e->pos();
|
||||
setCurrent(pos.y() - 5);
|
||||
}
|
||||
|
||||
void ColorBox::setHue(int newHue)
|
||||
{
|
||||
if (m_color.hsvHue() == newHue)
|
||||
return;
|
||||
|
||||
int oldAlpha = m_color.alpha();
|
||||
m_color.setHsv(newHue,m_color.hsvSaturation(),m_color.value());
|
||||
m_color.setAlpha(oldAlpha);
|
||||
update();
|
||||
emit hueChanged();
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
int ColorBox::hue() const
|
||||
{
|
||||
int retval = m_color.hsvHue();
|
||||
if (retval<0) retval=0;
|
||||
if (retval>359) retval=359;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void ColorBox::setAlpha(int newAlpha)
|
||||
{
|
||||
if (m_color.alpha() == newAlpha)
|
||||
return;
|
||||
|
||||
m_color.setAlpha(newAlpha);
|
||||
update();
|
||||
emit alphaChanged();
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
QString ColorBox::strColor() const
|
||||
{
|
||||
return properName(m_color);
|
||||
}
|
||||
|
||||
void ColorBox::setStrColor(const QString &colorStr)
|
||||
{
|
||||
if (properName(m_color) == colorStr)
|
||||
return;
|
||||
|
||||
setColor(properColor(colorStr));
|
||||
}
|
||||
|
||||
void ColorBox::setColor(const QColor &color)
|
||||
{
|
||||
if (m_color == color)
|
||||
return;
|
||||
|
||||
int oldsaturation = m_color.hsvSaturation();
|
||||
int oldvalue = m_color.value();
|
||||
int oldhue = m_color.hsvHue();
|
||||
int oldAlpha = m_color.alpha();
|
||||
m_color=color;
|
||||
update();
|
||||
if (oldhue != m_color.hsvHue()) emit hueChanged();
|
||||
if (oldsaturation != saturation()) emit saturationChanged();
|
||||
if (oldvalue != value()) emit valueChanged();
|
||||
if (oldAlpha != alpha()) emit alphaChanged();
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
void ColorBox::setSaturation(int newsaturation)
|
||||
{
|
||||
if (m_color.hsvSaturation()==newsaturation) return;
|
||||
int oldAlpha = m_color.alpha();
|
||||
m_color.setHsv(m_color.hsvHue(),newsaturation,m_color.value());
|
||||
m_color.setAlpha(oldAlpha);
|
||||
update();
|
||||
emit saturationChanged();
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
void ColorBox::setCurrent(int x, int y)
|
||||
{
|
||||
QColor newColor;
|
||||
if (x<0) x=0;
|
||||
if (x>120) x=120;
|
||||
if (y<0) y=0;
|
||||
if (y>120) y=120;
|
||||
x = clamp(x, 0, 120);
|
||||
y = clamp(y, 0, 120);
|
||||
int oldAlpha = m_color.alpha();
|
||||
newColor.setHsv(hue(), (x*255) / 120, 255 - (y*255) / 120);
|
||||
newColor.setAlpha(oldAlpha);
|
||||
setColor(newColor);
|
||||
}
|
||||
}
|
||||
|
||||
void ColorBox::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
void ColorBox::setValue(int newvalue)
|
||||
{
|
||||
if (m_color.value()==newvalue) return;
|
||||
int oldAlpha = m_color.alpha();
|
||||
m_color.setHsv(m_color.hsvHue(),m_color.hsvSaturation(),newvalue);
|
||||
m_color.setAlpha(oldAlpha);
|
||||
update();
|
||||
emit valueChanged();
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
void ColorBox::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
|
||||
QPainter p(this);
|
||||
@@ -173,10 +334,7 @@ namespace QmlDesigner {
|
||||
if ((hue() != m_lastHue) || (m_cache.isNull())) {
|
||||
m_lastHue = hue();
|
||||
|
||||
int fixedHue = m_lastHue;
|
||||
|
||||
if (fixedHue<0) fixedHue=0;
|
||||
if (fixedHue>359) fixedHue=359;
|
||||
int fixedHue = clamp(m_lastHue, 0, 359);
|
||||
|
||||
m_cache = QPixmap(120, 120);
|
||||
|
||||
@@ -197,20 +355,36 @@ namespace QmlDesigner {
|
||||
|
||||
p.drawPixmap(5, 5, m_cache);
|
||||
|
||||
int x = m_color.hsvSaturationF() * 120 + 5;
|
||||
int y = 120 - m_color.valueF() * 120 + 5;
|
||||
|
||||
if (x<5) x=5;
|
||||
if (x>125) x=125;
|
||||
if (y<5) y=5;
|
||||
if (y>125) y=125;
|
||||
int x = clamp(m_color.hsvSaturationF() * 120, 0, 120) + 5;
|
||||
int y = clamp(120 - m_color.valueF() * 120, 0, 120) + 5;
|
||||
|
||||
p.setPen(Qt::white);
|
||||
p.drawEllipse(x - 2, y - 2, 4, 4);
|
||||
|
||||
p.setPen(Qt::black);
|
||||
p.drawRect(QRect(0, 0, width() - 1, height() -1).adjusted(4, 4, -4, -4));
|
||||
}
|
||||
}
|
||||
|
||||
void ColorBox::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
// The current cell marker is set to the cell the mouse is pressed in
|
||||
QPoint pos = e->pos();
|
||||
m_mousePressed = true;
|
||||
setCurrent(pos.x() - 5, pos.y() - 5);
|
||||
}
|
||||
|
||||
void ColorBox::mouseReleaseEvent(QMouseEvent * /* event */)
|
||||
{
|
||||
m_mousePressed = false;
|
||||
}
|
||||
|
||||
void ColorBox::mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
if (!m_mousePressed)
|
||||
return;
|
||||
QPoint pos = e->pos();
|
||||
setCurrent(pos.x() - 5, pos.y() - 5);
|
||||
}
|
||||
|
||||
void GradientLine::setItemNode(const QVariant &itemNode)
|
||||
{
|
||||
@@ -229,6 +403,40 @@ static inline QColor invertColor(const QColor color)
|
||||
return c;
|
||||
}
|
||||
|
||||
GradientLine::GradientLine(QWidget *parent) : QWidget(parent), m_activeColor(Qt::black), m_gradientName("gradient"), m_dragActive(false), m_yOffset(0), m_create(false), m_active(false)
|
||||
{
|
||||
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
setFixedHeight(50);
|
||||
setMinimumWidth(160);
|
||||
resize(160, 50);
|
||||
m_colorList << m_activeColor << QColor(Qt::white);
|
||||
m_stops << 0 << 1;
|
||||
updateGradient();
|
||||
setCurrentIndex(0);
|
||||
}
|
||||
|
||||
void GradientLine::setGradientName(const QString &newName)
|
||||
{
|
||||
if (newName == m_gradientName)
|
||||
return;
|
||||
m_gradientName = newName;
|
||||
setup();
|
||||
emit gradientNameChanged();
|
||||
}
|
||||
|
||||
void GradientLine::setActiveColor(const QColor &newColor)
|
||||
{
|
||||
if (newColor.name() == m_activeColor.name() && newColor.alpha() == m_activeColor.alpha())
|
||||
return;
|
||||
|
||||
m_activeColor = newColor;
|
||||
m_colorList.removeAt(currentColorIndex());
|
||||
m_colorList.insert(currentColorIndex(), m_activeColor);
|
||||
updateGradient();
|
||||
update();
|
||||
}
|
||||
|
||||
void GradientLine::setupGradient()
|
||||
{
|
||||
ModelNode modelNode = m_itemNode.modelNode();
|
||||
@@ -255,6 +463,27 @@ void GradientLine::setupGradient()
|
||||
updateGradient();
|
||||
}
|
||||
|
||||
void GradientLine::deleteGradient()
|
||||
{
|
||||
if (!m_itemNode.isValid())
|
||||
return;
|
||||
|
||||
if (!m_itemNode.modelNode().metaInfo().hasProperty(m_gradientName))
|
||||
return;
|
||||
|
||||
ModelNode modelNode = m_itemNode.modelNode();
|
||||
|
||||
if (m_itemNode.isInBaseState()) {
|
||||
if (modelNode.hasProperty(m_gradientName)) {
|
||||
RewriterTransaction transaction;
|
||||
m_itemNode.modelNode().removeProperty(m_gradientName); //### there is atm a bug in the node instances which lead to a crash if using destroy()
|
||||
/*ModelNode gradientNode = modelNode.nodeProperty(m_gradientName).modelNode();
|
||||
if (QmlObjectNode(gradientNode).isValid())
|
||||
QmlObjectNode(gradientNode).destroy();*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GradientLine::event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::ShortcutOverride)
|
||||
@@ -350,7 +579,6 @@ void GradientLine::mousePressEvent(QMouseEvent *event)
|
||||
}
|
||||
setFocus(Qt::MouseFocusReason);
|
||||
event->accept();
|
||||
//QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void GradientLine::mouseReleaseEvent(QMouseEvent *event)
|
||||
@@ -376,7 +604,6 @@ void GradientLine::mouseReleaseEvent(QMouseEvent *event)
|
||||
update();
|
||||
updateGradient();
|
||||
event->accept();
|
||||
//QWidget::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void GradientLine::mouseMoveEvent(QMouseEvent *event)
|
||||
@@ -445,8 +672,9 @@ void GradientLine::updateGradient()
|
||||
ModelNode modelNode = m_itemNode.modelNode();
|
||||
|
||||
if (m_itemNode.isInBaseState()) {
|
||||
if (modelNode.hasProperty(m_gradientName))
|
||||
if (modelNode.hasProperty(m_gradientName)) {
|
||||
modelNode.removeProperty(m_gradientName);
|
||||
}
|
||||
|
||||
ModelNode gradientNode = modelNode.view()->createModelNode("Qt/Gradient", 4, 6);
|
||||
|
||||
@@ -473,4 +701,14 @@ void GradientLine::updateGradient()
|
||||
}
|
||||
}
|
||||
|
||||
void GradientLine::setCurrentIndex(int i)
|
||||
{
|
||||
if (i == m_colorIndex)
|
||||
return;
|
||||
m_colorIndex = i;
|
||||
setActiveColor(m_colorList.at(i));
|
||||
emit activeColorChanged();
|
||||
update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,28 +54,11 @@ Q_OBJECT
|
||||
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(bool noColor READ noColor WRITE setNoColor)
|
||||
|
||||
|
||||
public:
|
||||
ColorButton(QWidget *parent = 0) : QToolButton (parent), m_colorString("#ffffff"), m_noColor(false) {}
|
||||
|
||||
ColorButton(QWidget *parent = 0) : QToolButton (parent), m_colorString("#ffffff"), m_noColor(false)
|
||||
{
|
||||
}
|
||||
|
||||
void setColor(const QString &colorStr)
|
||||
{
|
||||
if (m_colorString == colorStr)
|
||||
return;
|
||||
|
||||
m_colorString = colorStr;
|
||||
update();
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
QString color() const
|
||||
{
|
||||
return m_colorString;
|
||||
}
|
||||
|
||||
void setColor(const QString &colorStr);
|
||||
QString color() const { return m_colorString; }
|
||||
bool noColor() const { return m_noColor; }
|
||||
void setNoColor(bool f) { m_noColor = f; update(); }
|
||||
|
||||
@@ -89,36 +72,6 @@ private:
|
||||
bool m_noColor;
|
||||
};
|
||||
|
||||
inline QString properName(const QColor &color)
|
||||
{
|
||||
QString s;
|
||||
if (color.alpha() == 255)
|
||||
s.sprintf("#%02x%02x%02x", color.red(), color.green(), color.blue());
|
||||
else
|
||||
s.sprintf("#%02x%02x%02x%02x", color.alpha(), color.red(), color.green(), color.blue());
|
||||
return s;
|
||||
}
|
||||
|
||||
inline QColor properColor(const QString &str)
|
||||
{
|
||||
int lalpha = 255;
|
||||
QString lcolorStr = str;
|
||||
if (lcolorStr.at(0) == '#' && lcolorStr.length() == 9) {
|
||||
QString alphaStr = lcolorStr;
|
||||
alphaStr.truncate(3);
|
||||
lcolorStr.remove(0, 3);
|
||||
lcolorStr = "#" + lcolorStr;
|
||||
alphaStr.remove(0,1);
|
||||
bool v;
|
||||
lalpha = alphaStr.toInt(&v, 16);
|
||||
if (!v)
|
||||
lalpha = 255;
|
||||
}
|
||||
QColor lcolor(lcolorStr);
|
||||
lcolor.setAlpha(lalpha);
|
||||
return lcolor;
|
||||
}
|
||||
|
||||
class ColorBox : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -131,117 +84,24 @@ Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
|
||||
Q_PROPERTY(int alpha READ alpha WRITE setAlpha NOTIFY alphaChanged)
|
||||
|
||||
public:
|
||||
|
||||
ColorBox(QWidget *parent = 0) : QWidget(parent), m_color(Qt::white), m_saturatedColor(Qt::white), m_lastHue(0)
|
||||
{
|
||||
ColorBox(QWidget *parent = 0) : QWidget(parent), m_color(Qt::white), m_saturatedColor(Qt::white), m_lastHue(0)
|
||||
{
|
||||
setFixedWidth(130);
|
||||
setFixedHeight(130);
|
||||
}
|
||||
}
|
||||
|
||||
void setHue(int newHue)
|
||||
{
|
||||
if (m_color.hsvHue() == newHue)
|
||||
return;
|
||||
|
||||
int oldAlpha = m_color.alpha();
|
||||
m_color.setHsv(newHue,m_color.hsvSaturation(),m_color.value());
|
||||
m_color.setAlpha(oldAlpha);
|
||||
update();
|
||||
emit hueChanged();
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
int hue() const
|
||||
{
|
||||
int retval = m_color.hsvHue();
|
||||
if (retval<0) retval=0;
|
||||
if (retval>359) retval=359;
|
||||
return retval;
|
||||
}
|
||||
|
||||
void setAlpha(int newAlpha)
|
||||
{
|
||||
if (m_color.alpha() == newAlpha)
|
||||
return;
|
||||
|
||||
m_color.setAlpha(newAlpha);
|
||||
update();
|
||||
emit alphaChanged();
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
int alpha() const
|
||||
{
|
||||
return m_color.alpha();
|
||||
}
|
||||
|
||||
void setStrColor(const QString &colorStr)
|
||||
{
|
||||
if (properName(m_color) == colorStr)
|
||||
return;
|
||||
|
||||
setColor(properColor(colorStr));
|
||||
}
|
||||
|
||||
void setColor(const QColor &color)
|
||||
{
|
||||
if (m_color == color)
|
||||
return;
|
||||
|
||||
int oldsaturation = m_color.hsvSaturation();
|
||||
int oldvalue = m_color.value();
|
||||
int oldhue = m_color.hsvHue();
|
||||
int oldAlpha = m_color.alpha();
|
||||
m_color=color;
|
||||
update();
|
||||
if (oldhue != m_color.hsvHue()) emit hueChanged();
|
||||
if (oldsaturation != saturation()) emit saturationChanged();
|
||||
if (oldvalue != value()) emit valueChanged();
|
||||
if (oldAlpha != alpha()) emit alphaChanged();
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
QString strColor() const
|
||||
{
|
||||
return properName(m_color);
|
||||
}
|
||||
|
||||
QColor color() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
int saturation() const
|
||||
{
|
||||
return m_color.hsvSaturation();
|
||||
}
|
||||
|
||||
void setSaturation(int newsaturation)
|
||||
{
|
||||
if (m_color.hsvSaturation()==newsaturation) return;
|
||||
int oldAlpha = m_color.alpha();
|
||||
m_color.setHsv(m_color.hsvHue(),newsaturation,m_color.value());
|
||||
m_color.setAlpha(oldAlpha);
|
||||
update();
|
||||
emit saturationChanged();
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
int value() const
|
||||
{
|
||||
return m_color.value();
|
||||
}
|
||||
|
||||
void setValue(int newvalue)
|
||||
{
|
||||
if (m_color.value()==newvalue) return;
|
||||
int oldAlpha = m_color.alpha();
|
||||
m_color.setHsv(m_color.hsvHue(),m_color.hsvSaturation(),newvalue);
|
||||
m_color.setAlpha(oldAlpha);
|
||||
update();
|
||||
emit valueChanged();
|
||||
emit colorChanged();
|
||||
}
|
||||
void setHue(int newHue);
|
||||
int hue() const;
|
||||
void setAlpha(int newAlpha);
|
||||
int alpha() const { return m_color.alpha(); }
|
||||
void setStrColor(const QString &colorStr);
|
||||
void setColor(const QColor &color);
|
||||
QString strColor() const;
|
||||
QColor color() const { return m_color; }
|
||||
int saturation() const { return m_color.hsvSaturation(); }
|
||||
void setSaturation(int newsaturation);
|
||||
int value() const { return m_color.value(); }
|
||||
void setValue(int newvalue);
|
||||
|
||||
signals:
|
||||
void colorChanged();
|
||||
@@ -253,29 +113,10 @@ signals:
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
void mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
// The current cell marker is set to the cell the mouse is pressed in
|
||||
QPoint pos = e->pos();
|
||||
m_mousePressed = true;
|
||||
setCurrent(pos.x() - 5, pos.y() - 5);
|
||||
}
|
||||
|
||||
void mouseReleaseEvent(QMouseEvent * /* event */)
|
||||
{
|
||||
m_mousePressed = false;
|
||||
}
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
if (!m_mousePressed)
|
||||
return;
|
||||
QPoint pos = e->pos();
|
||||
setCurrent(pos.x() - 5, pos.y() - 5);
|
||||
}
|
||||
|
||||
void setCurrent(int x, int y);
|
||||
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
void mouseReleaseEvent(QMouseEvent *);
|
||||
void mouseMoveEvent(QMouseEvent *);
|
||||
void setCurrent(int x, int y);
|
||||
|
||||
private:
|
||||
QColor m_color;
|
||||
@@ -293,55 +134,24 @@ Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged)
|
||||
|
||||
public:
|
||||
|
||||
HueControl(QWidget *parent = 0) : QWidget(parent), m_color(Qt::white), m_mousePressed(false)
|
||||
{
|
||||
HueControl(QWidget *parent = 0) : QWidget(parent), m_color(Qt::white), m_mousePressed(false)
|
||||
{
|
||||
setFixedWidth(40);
|
||||
setFixedHeight(130);
|
||||
}
|
||||
}
|
||||
|
||||
void setHue(int newHue)
|
||||
{
|
||||
if (m_color.hsvHue() == newHue)
|
||||
return;
|
||||
m_color.setHsv(newHue, m_color.hsvSaturation(), m_color.value());
|
||||
update();
|
||||
emit hueChanged();
|
||||
}
|
||||
|
||||
int hue() const
|
||||
{
|
||||
return m_color.hsvHue();
|
||||
}
|
||||
void setHue(int newHue);
|
||||
int hue() const { return m_color.hsvHue(); }
|
||||
|
||||
signals:
|
||||
void hueChanged();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
void mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
// The current cell marker is set to the cell the mouse is pressed in
|
||||
QPoint pos = e->pos();
|
||||
m_mousePressed = true;
|
||||
setCurrent(pos.y() - 5);
|
||||
}
|
||||
|
||||
void mouseReleaseEvent(QMouseEvent * /* event */)
|
||||
{
|
||||
m_mousePressed = false;
|
||||
}
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
if (!m_mousePressed)
|
||||
return;
|
||||
QPoint pos = e->pos();
|
||||
setCurrent(pos.y() - 5);
|
||||
}
|
||||
|
||||
void setCurrent(int y);
|
||||
|
||||
void paintEvent(QPaintEvent *);
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
void mouseReleaseEvent(QMouseEvent *);
|
||||
void mouseMoveEvent(QMouseEvent *);
|
||||
void setCurrent(int y);
|
||||
|
||||
private:
|
||||
QColor m_color;
|
||||
@@ -358,50 +168,20 @@ class GradientLine : public QWidget {
|
||||
Q_PROPERTY(bool active READ active WRITE setActive)
|
||||
|
||||
public:
|
||||
GradientLine(QWidget *parent = 0) : QWidget(parent), m_activeColor(Qt::black), m_gradientName("gradient"), m_dragActive(false), m_yOffset(0), m_create(false), m_active(false)
|
||||
{
|
||||
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
setFixedHeight(50);
|
||||
setMinimumWidth(160);
|
||||
resize(160, 50);
|
||||
m_colorList << m_activeColor << QColor(Qt::white);
|
||||
m_stops << 0 << 1;
|
||||
updateGradient();
|
||||
setCurrentIndex(0);
|
||||
}
|
||||
|
||||
GradientLine(QWidget *parent = 0);
|
||||
|
||||
QVariant itemNode() const { return QVariant::fromValue(m_itemNode.modelNode()); }
|
||||
void setItemNode(const QVariant &itemNode);
|
||||
QString gradientName() const { return m_gradientName; }
|
||||
void setGradientName(const QString &newName)
|
||||
{
|
||||
if (newName == m_gradientName)
|
||||
return;
|
||||
m_gradientName = newName;
|
||||
setup();
|
||||
emit gradientNameChanged();
|
||||
}
|
||||
|
||||
void setGradientName(const QString &newName);
|
||||
QColor activeColor() const { return m_activeColor; }
|
||||
void setActiveColor(const QColor &newColor)
|
||||
{
|
||||
if (newColor.name() == m_activeColor.name() && newColor.alpha() == m_activeColor.alpha())
|
||||
return;
|
||||
|
||||
m_activeColor = newColor;
|
||||
m_colorList.removeAt(currentColorIndex());
|
||||
m_colorList.insert(currentColorIndex(), m_activeColor);
|
||||
updateGradient();
|
||||
update();
|
||||
}
|
||||
|
||||
void setActiveColor(const QColor &newColor);
|
||||
bool active() const { return m_active; }
|
||||
void setActive(bool a) { m_active = a; }
|
||||
|
||||
public slots:
|
||||
void setupGradient();
|
||||
void deleteGradient();
|
||||
|
||||
signals:
|
||||
void activeColorChanged();
|
||||
@@ -419,15 +199,7 @@ private:
|
||||
void setup();
|
||||
void updateGradient();
|
||||
int currentColorIndex() const { return m_colorIndex; }
|
||||
void setCurrentIndex(int i)
|
||||
{
|
||||
if (i == m_colorIndex)
|
||||
return;
|
||||
m_colorIndex = i;
|
||||
setActiveColor(m_colorList.at(i));
|
||||
emit activeColorChanged();
|
||||
update();
|
||||
}
|
||||
void setCurrentIndex(int i);
|
||||
|
||||
QColor m_activeColor;
|
||||
QmlItemNode m_itemNode;
|
||||
|
||||
Reference in New Issue
Block a user