forked from qt-creator/qt-creator
QmlDesigner.propertyEditor: code cleanup for property editing
Instead of duplicating the code from QmlEditorWigets we now subclass and expose the gradient editing to qml. The adaptor class is called GradientLineQmlAdaptor.
This commit is contained in:
@@ -27,7 +27,7 @@
|
|||||||
**
|
**
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "colorwidget.h"
|
#include "colorwidgets.h"
|
||||||
#include <qdeclarative.h>
|
#include <qdeclarative.h>
|
||||||
|
|
||||||
#include "colorbox.h"
|
#include "colorbox.h"
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
namespace QmlEditorWidgets {
|
namespace QmlEditorWidgets {
|
||||||
|
|
||||||
void ColorWidget::registerDeclarativeTypes() {
|
void ColorWidgets::registerDeclarativeTypes() {
|
||||||
qmlRegisterType<QmlEditorWidgets::ColorButton>("Bauhaus",1,0,"ColorButton");
|
qmlRegisterType<QmlEditorWidgets::ColorButton>("Bauhaus",1,0,"ColorButton");
|
||||||
qmlRegisterType<QmlEditorWidgets::HueControl>("Bauhaus",1,0,"HueControl");
|
qmlRegisterType<QmlEditorWidgets::HueControl>("Bauhaus",1,0,"HueControl");
|
||||||
qmlRegisterType<QmlEditorWidgets::ColorBox>("Bauhaus",1,0,"ColorBox");
|
qmlRegisterType<QmlEditorWidgets::ColorBox>("Bauhaus",1,0,"ColorBox");
|
||||||
@@ -44,7 +44,7 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace QmlEditorWidgets {
|
namespace QmlEditorWidgets {
|
||||||
|
|
||||||
class ColorWidget {
|
class QMLEDITORWIDGETS_EXPORT ColorWidgets {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void registerDeclarativeTypes();
|
static void registerDeclarativeTypes();
|
||||||
@@ -39,7 +39,6 @@
|
|||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include "colorwidget.h"
|
|
||||||
#include "contextpanetextwidget.h"
|
#include "contextpanetextwidget.h"
|
||||||
#include "easingcontextpane.h"
|
#include "easingcontextpane.h"
|
||||||
#include "contextpanewidgetimage.h"
|
#include "contextpanewidgetimage.h"
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ void GradientLine::setGradient(const QLinearGradient &gradient)
|
|||||||
{
|
{
|
||||||
m_gradient = gradient;
|
m_gradient = gradient;
|
||||||
m_useGradient = true;
|
m_useGradient = true;
|
||||||
setupGradient();
|
readGradient();
|
||||||
emit gradientChanged();
|
emit gradientChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ void GradientLine::setActiveColor(const QColor &newColor)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GradientLine::setupGradient()
|
void GradientLine::readGradient()
|
||||||
{
|
{
|
||||||
if (m_useGradient) {
|
if (m_useGradient) {
|
||||||
m_colorList.clear();
|
m_colorList.clear();
|
||||||
|
|||||||
@@ -56,9 +56,6 @@ public:
|
|||||||
QLinearGradient gradient() const { return m_gradient; }
|
QLinearGradient gradient() const { return m_gradient; }
|
||||||
void setGradient(const QLinearGradient &);
|
void setGradient(const QLinearGradient &);
|
||||||
|
|
||||||
public slots:
|
|
||||||
void setupGradient();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void activeColorChanged();
|
void activeColorChanged();
|
||||||
void itemNodeChanged();
|
void itemNodeChanged();
|
||||||
@@ -76,6 +73,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void setup();
|
void setup();
|
||||||
|
void readGradient();
|
||||||
void updateGradient();
|
void updateGradient();
|
||||||
int currentColorIndex() const { return m_colorIndex; }
|
int currentColorIndex() const { return m_colorIndex; }
|
||||||
void setCurrentIndex(int i);
|
void setCurrentIndex(int i);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ HEADERS += \
|
|||||||
contextpanewidgetimage.h \
|
contextpanewidgetimage.h \
|
||||||
contextpanewidget.h \
|
contextpanewidget.h \
|
||||||
contextpanetextwidget.h \
|
contextpanetextwidget.h \
|
||||||
colorwidget.h \
|
colorwidgets.h \
|
||||||
colorbutton.h \
|
colorbutton.h \
|
||||||
colorbox.h \
|
colorbox.h \
|
||||||
customcolordialog.h \
|
customcolordialog.h \
|
||||||
@@ -34,7 +34,7 @@ SOURCES += \
|
|||||||
contextpanewidgetimage.cpp \
|
contextpanewidgetimage.cpp \
|
||||||
contextpanewidget.cpp \
|
contextpanewidget.cpp \
|
||||||
contextpanetextwidget.cpp \
|
contextpanetextwidget.cpp \
|
||||||
colorwidget.cpp \
|
colorwidgets.cpp \
|
||||||
colorbox.cpp \
|
colorbox.cpp \
|
||||||
customcolordialog.cpp \
|
customcolordialog.cpp \
|
||||||
huecontrol.cpp \
|
huecontrol.cpp \
|
||||||
|
|||||||
@@ -1,989 +0,0 @@
|
|||||||
/**************************************************************************
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator
|
|
||||||
**
|
|
||||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
||||||
**
|
|
||||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
||||||
**
|
|
||||||
** Commercial Usage
|
|
||||||
**
|
|
||||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
||||||
** accordance with the Qt Commercial License Agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and Nokia.
|
|
||||||
**
|
|
||||||
** GNU Lesser General Public License Usage
|
|
||||||
**
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
||||||
** General Public License version 2.1 as published by the Free Software
|
|
||||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
||||||
** packaging of this file. Please review the following information to
|
|
||||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
||||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
||||||
**
|
|
||||||
** If you are unsure which license is appropriate for your use, please
|
|
||||||
** contact the sales department at http://qt.nokia.com/contact.
|
|
||||||
**
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#include "colorwidget.h"
|
|
||||||
#include <modelnode.h>
|
|
||||||
#include <abstractview.h>
|
|
||||||
#include <nodeproperty.h>
|
|
||||||
#include <nodelistproperty.h>
|
|
||||||
#include <variantproperty.h>
|
|
||||||
#include <qmlobjectnode.h>
|
|
||||||
#include <qmlitemnode.h>
|
|
||||||
#include <QGradient>
|
|
||||||
#include <metainfo.h>
|
|
||||||
#include <rewritingexception.h>
|
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QToolButton>
|
|
||||||
#include <QGradient>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QDoubleSpinBox>
|
|
||||||
#include <QGridLayout>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QDialogButtonBox>
|
|
||||||
#include <QGraphicsEffect>
|
|
||||||
#include <QMessageBox>
|
|
||||||
|
|
||||||
static inline int clamp(int x, int lower, int upper)
|
|
||||||
{
|
|
||||||
if (x < lower)
|
|
||||||
x = lower;
|
|
||||||
if (x > upper)
|
|
||||||
x = upper;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline QColor properColor(const QString &str)
|
|
||||||
{
|
|
||||||
if (str.isEmpty())
|
|
||||||
return QColor();
|
|
||||||
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);
|
|
||||||
if (lcolorStr.contains('#'))
|
|
||||||
lcolor.setAlpha(lalpha);
|
|
||||||
return lcolor;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool isColorString(const QString &colorString)
|
|
||||||
{
|
|
||||||
bool ok = true;
|
|
||||||
if (colorString.size() == 9 && colorString.at(0) == QLatin1Char('#')) {
|
|
||||||
// #rgba
|
|
||||||
for (int i = 1; i < 9; ++i) {
|
|
||||||
const QChar c = colorString.at(i);
|
|
||||||
if ((c >= QLatin1Char('0') && c <= QLatin1Char('9'))
|
|
||||||
|| (c >= QLatin1Char('a') && c <= QLatin1Char('f'))
|
|
||||||
|| (c >= QLatin1Char('A') && c <= QLatin1Char('F')))
|
|
||||||
continue;
|
|
||||||
ok = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ok = QColor::isValidColor(colorString);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline QPixmap tilePixMap(int size)
|
|
||||||
{
|
|
||||||
const int checkerbordSize= size;
|
|
||||||
QPixmap tilePixmap(checkerbordSize * 2, checkerbordSize * 2);
|
|
||||||
tilePixmap.fill(Qt::white);
|
|
||||||
QPainter tilePainter(&tilePixmap);
|
|
||||||
QColor color(220, 220, 220);
|
|
||||||
tilePainter.fillRect(0, 0, checkerbordSize, checkerbordSize, color);
|
|
||||||
tilePainter.fillRect(checkerbordSize, checkerbordSize, checkerbordSize, checkerbordSize, color);
|
|
||||||
return tilePixmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
|
||||||
|
|
||||||
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::setColor(const QString &colorStr)
|
|
||||||
{
|
|
||||||
if (m_colorString == colorStr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
setEnabled(isColorString(colorStr));
|
|
||||||
|
|
||||||
m_colorString = colorStr;
|
|
||||||
update();
|
|
||||||
emit colorChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
QColor ColorButton::convertedColor() const
|
|
||||||
{
|
|
||||||
return properColor(m_colorString);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColorButton::paintEvent(QPaintEvent *event)
|
|
||||||
{
|
|
||||||
QToolButton::paintEvent(event);
|
|
||||||
if (!isEnabled())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QColor color = properColor(m_colorString);
|
|
||||||
|
|
||||||
QPainter p(this);
|
|
||||||
|
|
||||||
|
|
||||||
QRect r(0, 0, width() - 2, height() - 2);
|
|
||||||
p.drawTiledPixmap(r.adjusted(1, 1, -1, -1), tilePixMap(9));
|
|
||||||
if (isEnabled())
|
|
||||||
p.setBrush(color);
|
|
||||||
else
|
|
||||||
p.setBrush(Qt::transparent);
|
|
||||||
|
|
||||||
if (color.value() > 80)
|
|
||||||
p.setPen(QColor(0x444444));
|
|
||||||
else
|
|
||||||
p.setPen(QColor(0x9e9e9e));
|
|
||||||
p.drawRect(r.translated(1, 1));
|
|
||||||
|
|
||||||
if (m_showArrow) {
|
|
||||||
p.setRenderHint(QPainter::Antialiasing, true);
|
|
||||||
QVector<QPointF> points;
|
|
||||||
if (isChecked()) {
|
|
||||||
points.append(QPointF(2, 3));
|
|
||||||
points.append(QPointF(8, 3));
|
|
||||||
points.append(QPointF(5, 9));
|
|
||||||
} else {
|
|
||||||
points.append(QPointF(8, 6));
|
|
||||||
points.append(QPointF(2, 9));
|
|
||||||
points.append(QPointF(2, 3));
|
|
||||||
}
|
|
||||||
p.translate(0.5, 0.5);
|
|
||||||
p.setBrush(QColor(0xaaaaaa));
|
|
||||||
p.setPen(QColor(0x444444));
|
|
||||||
p.drawPolygon(points);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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(m_color.hsvHue());
|
|
||||||
}
|
|
||||||
|
|
||||||
void HueControl::setHue(int newHue)
|
|
||||||
{
|
|
||||||
if (m_color.hsvHue() == newHue)
|
|
||||||
return;
|
|
||||||
m_color.setHsv(newHue, m_color.hsvSaturation(), m_color.value());
|
|
||||||
update();
|
|
||||||
emit hueChanged(m_color.hsvHue());
|
|
||||||
}
|
|
||||||
|
|
||||||
void HueControl::paintEvent(QPaintEvent *event)
|
|
||||||
{
|
|
||||||
QWidget::paintEvent(event);
|
|
||||||
|
|
||||||
QPainter p(this);
|
|
||||||
|
|
||||||
int localHeight = 120;
|
|
||||||
|
|
||||||
if (m_cache.isNull()) {
|
|
||||||
m_cache = QPixmap(10, localHeight);
|
|
||||||
|
|
||||||
QPainter cacheP(&m_cache);
|
|
||||||
|
|
||||||
for (int i = 0; i < localHeight; i++)
|
|
||||||
{
|
|
||||||
QColor c;
|
|
||||||
c.setHsv( (i*359) / 120.0, 255,255);
|
|
||||||
cacheP.fillRect(0, i, 10, i + 1, c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//p.setPen(QColor(0x404040));
|
|
||||||
//p.drawRect(QRect(1, 1, width() - 1, height() - 1).adjusted(10, 5, -20, -5));
|
|
||||||
|
|
||||||
p.drawPixmap(0, 5, m_cache);
|
|
||||||
|
|
||||||
QVector<QPointF> points;
|
|
||||||
|
|
||||||
int y = m_color.hueF() * 120 + 5;
|
|
||||||
|
|
||||||
points.append(QPointF(5, y));
|
|
||||||
points.append(QPointF(15, y + 5));
|
|
||||||
points.append(QPointF(15, y - 5));
|
|
||||||
|
|
||||||
|
|
||||||
p.setRenderHint(QPainter::Antialiasing, true);
|
|
||||||
p.translate(0.5, 1.5);
|
|
||||||
p.setPen(QColor(0, 0, 0, 120));
|
|
||||||
p.drawPolygon(points);
|
|
||||||
p.translate(0, -1);
|
|
||||||
p.setPen(0x222222);
|
|
||||||
p.setBrush(QColor(0x707070));
|
|
||||||
p.drawPolygon(points);
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
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::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);
|
|
||||||
|
|
||||||
if ((m_color.saturation()>1) && (m_color.value()>1))
|
|
||||||
m_saturatedColor.setHsv(m_color.hsvHue(),255,255);
|
|
||||||
|
|
||||||
if ((hue() != m_lastHue) || (m_cache.isNull())) {
|
|
||||||
m_lastHue = hue();
|
|
||||||
|
|
||||||
int fixedHue = clamp(m_lastHue, 0, 359);
|
|
||||||
|
|
||||||
m_cache = QPixmap(120, 120);
|
|
||||||
|
|
||||||
int height = 120;
|
|
||||||
int width = 120;
|
|
||||||
|
|
||||||
QPainter chacheP(&m_cache);
|
|
||||||
|
|
||||||
for (int y = 0; y < height; y++)
|
|
||||||
for (int x = 0; x < width; x++)
|
|
||||||
{
|
|
||||||
QColor c;
|
|
||||||
c.setHsv(fixedHue, (x*255) / width, 255 - (y*255) / height);
|
|
||||||
chacheP.setPen(c);
|
|
||||||
chacheP.drawPoint(x ,y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p.drawPixmap(5, 5, m_cache);
|
|
||||||
|
|
||||||
int x = clamp(m_color.hsvSaturationF() * 120, 0, 119) + 5;
|
|
||||||
int y = clamp(120 - m_color.valueF() * 120, 0, 119) + 5;
|
|
||||||
|
|
||||||
p.setPen(QColor(255, 255, 255, 50));
|
|
||||||
p.drawLine(5, y, x-1, y);
|
|
||||||
p.drawLine(x+1, y, width()-7, y);
|
|
||||||
p.drawLine(x, 5, x, y-1);
|
|
||||||
p.drawLine(x, y+1, x, height()-7);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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 */)
|
|
||||||
{
|
|
||||||
if (m_mousePressed)
|
|
||||||
emit colorChanged();
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!itemNode.value<ModelNode>().isValid())
|
|
||||||
return;
|
|
||||||
m_itemNode = itemNode.value<ModelNode>();
|
|
||||||
m_useGradient = false;
|
|
||||||
setupGradient();
|
|
||||||
emit itemNodeChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GradientLine::setGradient(const QLinearGradient &gradient)
|
|
||||||
{
|
|
||||||
m_gradient = gradient;
|
|
||||||
m_useGradient = false;
|
|
||||||
setupGradient();
|
|
||||||
emit gradientChanged();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline QColor invertColor(const QColor color)
|
|
||||||
{
|
|
||||||
QColor c = color.toHsv();
|
|
||||||
c.setHsv(c.hue(), c.saturation(), 255 - c.value());
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
GradientLine::GradientLine(QWidget *parent) :
|
|
||||||
QWidget(parent),
|
|
||||||
m_activeColor(Qt::black),
|
|
||||||
m_gradientName("gradient"),
|
|
||||||
m_colorIndex(0),
|
|
||||||
m_dragActive(false),
|
|
||||||
m_yOffset(0),
|
|
||||||
m_create(false),
|
|
||||||
m_active(false),
|
|
||||||
m_dragOff(false),
|
|
||||||
m_useGradient(true)
|
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
if (m_useGradient) {
|
|
||||||
m_colorList.clear();
|
|
||||||
m_stops.clear();
|
|
||||||
foreach (const QGradientStop &stop, m_gradient.stops()) {
|
|
||||||
m_stops << stop.first;
|
|
||||||
m_colorList << stop.second;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ModelNode modelNode = m_itemNode.modelNode();
|
|
||||||
if (!modelNode.isValid())
|
|
||||||
return;
|
|
||||||
m_colorList.clear();
|
|
||||||
m_stops.clear();
|
|
||||||
|
|
||||||
if (modelNode.hasProperty(m_gradientName)) { //gradient exists
|
|
||||||
|
|
||||||
ModelNode gradientNode = modelNode.nodeProperty(m_gradientName).modelNode();
|
|
||||||
QList<ModelNode> stopList = gradientNode.nodeListProperty("stops").toModelNodeList();
|
|
||||||
|
|
||||||
foreach (const ModelNode &stopNode, stopList) {
|
|
||||||
QmlObjectNode stopObjectNode = stopNode;
|
|
||||||
if (stopObjectNode.isValid()) {
|
|
||||||
m_stops << stopObjectNode.instanceValue("position").toReal();
|
|
||||||
m_colorList << stopObjectNode.instanceValue("color").value<QColor>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_colorList << m_activeColor << QColor(Qt::black);
|
|
||||||
m_stops << 0 << 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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().view()->beginRewriterTransaction();
|
|
||||||
ModelNode gradientNode = modelNode.nodeProperty(m_gradientName).modelNode();
|
|
||||||
if (QmlObjectNode(gradientNode).isValid())
|
|
||||||
QmlObjectNode(gradientNode).destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GradientLine::event(QEvent *event)
|
|
||||||
{
|
|
||||||
if (event->type() == QEvent::ShortcutOverride)
|
|
||||||
if (static_cast<QKeyEvent*>(event)->matches(QKeySequence::Delete)) {
|
|
||||||
event->accept();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QWidget::event(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GradientLine::keyPressEvent(QKeyEvent * event)
|
|
||||||
{
|
|
||||||
if (event->matches(QKeySequence::Delete)) {
|
|
||||||
if ((currentColorIndex()) != 0 && (currentColorIndex() < m_stops.size() - 1)) {
|
|
||||||
m_dragActive = false;
|
|
||||||
m_stops.removeAt(currentColorIndex());
|
|
||||||
m_colorList.removeAt(currentColorIndex());
|
|
||||||
updateGradient();
|
|
||||||
setCurrentIndex(0);
|
|
||||||
//delete item
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
QWidget::keyPressEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GradientLine::paintEvent(QPaintEvent *event)
|
|
||||||
{
|
|
||||||
QWidget::paintEvent(event);
|
|
||||||
|
|
||||||
QPainter p(this);
|
|
||||||
|
|
||||||
if (!isEnabled()) {
|
|
||||||
p.setBrush(Qt::NoBrush);
|
|
||||||
p.setPen(QColor(0x444444));
|
|
||||||
p.drawRect(9, 31, width() - 14, height() - 32);
|
|
||||||
|
|
||||||
p.drawTiledPixmap(10, 32, width() - 16, height() - 34, tilePixMap(8));
|
|
||||||
} else {
|
|
||||||
|
|
||||||
QLinearGradient linearGradient(QPointF(0, 0), QPointF(width(), 0));
|
|
||||||
|
|
||||||
for (int i =0; i < m_stops.size(); i++)
|
|
||||||
linearGradient.setColorAt(m_stops.at(i), m_colorList.at(i));
|
|
||||||
|
|
||||||
p.setBrush(Qt::NoBrush);
|
|
||||||
p.setPen(QColor(0x444444));
|
|
||||||
p.drawRect(9, 31, width() - 14, height() - 32);
|
|
||||||
|
|
||||||
|
|
||||||
p.drawTiledPixmap(9, 31, width() - 16, height() - 34, tilePixMap(8));
|
|
||||||
|
|
||||||
p.setBrush(linearGradient);
|
|
||||||
p.setPen(QColor(0x222222));
|
|
||||||
p.drawRect(8, 30, width() - 14, height() - 32);
|
|
||||||
p.setPen(QColor(255, 255, 255, 40));
|
|
||||||
p.drawRect(9, 31, width() - 16, height() - 34);
|
|
||||||
|
|
||||||
p.setPen(Qt::black);
|
|
||||||
|
|
||||||
for (int i =0; i < m_colorList.size(); i++) {
|
|
||||||
int localYOffset = 0;
|
|
||||||
QColor arrowColor(Qt::black);
|
|
||||||
if (i == currentColorIndex()) {
|
|
||||||
localYOffset = m_yOffset;
|
|
||||||
arrowColor = QColor(0x909090);
|
|
||||||
}
|
|
||||||
p.setPen(arrowColor);
|
|
||||||
if (i == 0 || i == (m_colorList.size() - 1))
|
|
||||||
localYOffset = 0;
|
|
||||||
|
|
||||||
int pos = qreal((width() - 16)) * m_stops.at(i) + 9;
|
|
||||||
p.setBrush(arrowColor);
|
|
||||||
QVector<QPointF> points;
|
|
||||||
points.append(QPointF(pos + 0.5, 28.5 + localYOffset)); //triangle
|
|
||||||
points.append(QPointF(pos - 3.5, 22.5 + localYOffset));
|
|
||||||
points.append(QPointF(pos + 4.5, 22.5 + localYOffset));
|
|
||||||
p.setRenderHint(QPainter::Antialiasing, true);
|
|
||||||
p.drawPolygon(points);
|
|
||||||
p.setRenderHint(QPainter::Antialiasing, false);
|
|
||||||
p.setBrush(Qt::NoBrush);
|
|
||||||
p.setPen(QColor(0x424242));
|
|
||||||
p.drawRect(pos - 4, 9 + localYOffset, 10, 11);
|
|
||||||
|
|
||||||
p.drawTiledPixmap(pos - 4, 9 + localYOffset, 9, 10, tilePixMap(5));
|
|
||||||
p.setPen(QColor(0x424242));
|
|
||||||
p.setBrush(m_colorList.at(i));
|
|
||||||
p.drawRect(pos - 5, 8 + localYOffset, 10, 11);
|
|
||||||
p.setBrush(Qt::NoBrush);
|
|
||||||
p.setPen(QColor(255, 255, 255, 30));
|
|
||||||
p.drawRect(pos - 4, 9 + localYOffset, 8, 9);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GradientLine::mousePressEvent(QMouseEvent *event)
|
|
||||||
{
|
|
||||||
if (event->button() == Qt::LeftButton) {
|
|
||||||
event->accept();
|
|
||||||
int xPos = event->pos().x();
|
|
||||||
int yPos = event->pos().y();
|
|
||||||
|
|
||||||
int draggedIndex = -1;
|
|
||||||
m_create = false;
|
|
||||||
m_dragActive = false;
|
|
||||||
if ((yPos > 10) && (yPos < 30))
|
|
||||||
for (int i =0; i < m_stops.size(); i++) {
|
|
||||||
int pos = qreal((width() - 16)) * m_stops.at(i) + 9;
|
|
||||||
if (((xPos + 5) > pos) && ((xPos - 5) < pos)) {
|
|
||||||
draggedIndex = i;
|
|
||||||
m_dragActive = true;
|
|
||||||
m_dragStart = event->pos();
|
|
||||||
setCurrentIndex(draggedIndex);
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (draggedIndex == -1)
|
|
||||||
m_create = true;
|
|
||||||
}
|
|
||||||
setFocus(Qt::MouseFocusReason);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GradientLine::mouseDoubleClickEvent(QMouseEvent *event)
|
|
||||||
{
|
|
||||||
event->accept();
|
|
||||||
m_dragActive = false;
|
|
||||||
m_create = false;
|
|
||||||
emit openColorDialog(event->pos());
|
|
||||||
}
|
|
||||||
|
|
||||||
void GradientLine::mouseReleaseEvent(QMouseEvent *event)
|
|
||||||
{
|
|
||||||
if (event->button() == Qt::LeftButton) {
|
|
||||||
event->accept();
|
|
||||||
if (m_dragActive == false && m_create) {
|
|
||||||
qreal stopPos = qreal(event->pos().x() - 9) / qreal((width() - 15));
|
|
||||||
int index = -1;
|
|
||||||
for (int i =0; i < m_stops.size() - 1; i++) {
|
|
||||||
if ((stopPos > m_stops.at(i)) && (index == -1))
|
|
||||||
index = i +1;
|
|
||||||
}
|
|
||||||
if (index != -1 && (m_useGradient || m_itemNode.isInBaseState())) { //creating of items only in base state
|
|
||||||
m_stops.insert(index, stopPos);
|
|
||||||
m_colorList.insert(index, QColor(Qt::white));
|
|
||||||
setCurrentIndex(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_dragActive = false;
|
|
||||||
m_yOffset = 0;
|
|
||||||
updateGradient();
|
|
||||||
update();
|
|
||||||
setFocus(Qt::MouseFocusReason);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GradientLine::mouseMoveEvent(QMouseEvent *event)
|
|
||||||
{
|
|
||||||
if (m_dragActive) {
|
|
||||||
event->accept();
|
|
||||||
int xPos = event->pos().x();
|
|
||||||
int pos = qreal((width() - 20)) * m_stops.at(currentColorIndex()) + 8;
|
|
||||||
int offset = m_dragOff ? 2 : 20;
|
|
||||||
if (xPos < pos + offset && xPos > pos - offset) {
|
|
||||||
m_dragOff = false;
|
|
||||||
int xDistance = event->pos().x() - m_dragStart.x();
|
|
||||||
qreal distance = qreal(xDistance) / qreal((width() - 20));
|
|
||||||
qreal newStop = m_stops.at(currentColorIndex()) + distance;
|
|
||||||
if ((newStop >=0) && (newStop <= 1))
|
|
||||||
m_stops[currentColorIndex()] = newStop;
|
|
||||||
m_yOffset += event->pos().y() - m_dragStart.y();
|
|
||||||
if (m_yOffset > 0 || !(m_itemNode.isInBaseState() || m_useGradient)) { //deleting only in base state
|
|
||||||
m_yOffset = 0;
|
|
||||||
} else if ((m_yOffset < - 12) && (currentColorIndex()) != 0 && (currentColorIndex() < m_stops.size() - 1)) {
|
|
||||||
m_yOffset = 0;
|
|
||||||
m_dragActive = false;
|
|
||||||
m_stops.removeAt(currentColorIndex());
|
|
||||||
m_colorList.removeAt(currentColorIndex());
|
|
||||||
updateGradient();
|
|
||||||
setCurrentIndex(0);
|
|
||||||
//delete item
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_dragOff = true;
|
|
||||||
}
|
|
||||||
m_dragStart = event->pos();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GradientLine::setup()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline QColor normalizeColor(const QColor &color)
|
|
||||||
{
|
|
||||||
QColor newColor = QColor(color.name());
|
|
||||||
newColor.setAlpha(color.alpha());
|
|
||||||
return newColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline qreal roundReal(qreal real)
|
|
||||||
{
|
|
||||||
int i = real * 100;
|
|
||||||
return qreal(i) / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GradientLine::updateGradient()
|
|
||||||
{
|
|
||||||
if (m_useGradient) {
|
|
||||||
QGradientStops stops;
|
|
||||||
for (int i = 0;i < m_stops.size(); i++) {
|
|
||||||
stops.append(QPair<qreal, QColor>(m_stops.at(i), m_colorList.at(i)));
|
|
||||||
}
|
|
||||||
m_gradient.setStops(stops);
|
|
||||||
emit gradientChanged();
|
|
||||||
} else {
|
|
||||||
if (!active())
|
|
||||||
return;
|
|
||||||
try {
|
|
||||||
RewriterTransaction transaction = m_itemNode.modelNode().view()->beginRewriterTransaction();
|
|
||||||
if (!m_itemNode.isValid())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!m_itemNode.modelNode().metaInfo().hasProperty(m_gradientName))
|
|
||||||
return;
|
|
||||||
|
|
||||||
ModelNode modelNode = m_itemNode.modelNode();
|
|
||||||
|
|
||||||
QString oldId;
|
|
||||||
if (m_itemNode.isInBaseState()) {
|
|
||||||
if (modelNode.hasProperty(m_gradientName)) {
|
|
||||||
oldId = modelNode.nodeProperty(m_gradientName).modelNode().id();
|
|
||||||
modelNode.removeProperty(m_gradientName);
|
|
||||||
}
|
|
||||||
|
|
||||||
ModelNode gradientNode = modelNode.view()->createModelNode("Qt/Gradient", 4, 7);
|
|
||||||
|
|
||||||
if (!oldId.isNull())
|
|
||||||
gradientNode.setId(oldId);
|
|
||||||
|
|
||||||
for (int i = 0;i < m_stops.size(); i++) {
|
|
||||||
ModelNode gradientStopNode = modelNode.view()->createModelNode("Qt/GradientStop", 4, 7);
|
|
||||||
gradientStopNode.variantProperty("position") = roundReal(m_stops.at(i));
|
|
||||||
gradientStopNode.variantProperty("color") = normalizeColor(m_colorList.at(i));
|
|
||||||
gradientNode.nodeListProperty("stops").reparentHere(gradientStopNode);
|
|
||||||
}
|
|
||||||
modelNode.nodeProperty(m_gradientName).reparentHere(gradientNode);
|
|
||||||
} else { //state
|
|
||||||
if (!modelNode.hasProperty(m_gradientName)) {
|
|
||||||
qWarning(" GradientLine::updateGradient: no gradient in state");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ModelNode gradientNode = modelNode.nodeProperty(m_gradientName).modelNode();
|
|
||||||
QList<ModelNode> stopList = gradientNode.nodeListProperty("stops").toModelNodeList();
|
|
||||||
for (int i = 0;i < m_stops.size(); i++) {
|
|
||||||
QmlObjectNode stopObjectNode = stopList.at(i);
|
|
||||||
stopObjectNode.setVariantProperty("position", roundReal(m_stops.at(i)));
|
|
||||||
stopObjectNode.setVariantProperty("color", normalizeColor(m_colorList.at(i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (RewritingException &e) {
|
|
||||||
QMessageBox::warning(0, "Error", e.description());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GradientLine::setCurrentIndex(int i)
|
|
||||||
{
|
|
||||||
if (i == m_colorIndex)
|
|
||||||
return;
|
|
||||||
m_colorIndex = i;
|
|
||||||
m_activeColor = m_colorList.at(i);
|
|
||||||
emit activeColorChanged();
|
|
||||||
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);
|
|
||||||
|
|
||||||
QWidget *colorFrameWidget = new QWidget(this);
|
|
||||||
QVBoxLayout* vBox = new QVBoxLayout(colorFrameWidget);
|
|
||||||
colorFrameWidget->setLayout(vBox);
|
|
||||||
vBox->setSpacing(0);
|
|
||||||
vBox->setMargin(0);
|
|
||||||
vBox->setContentsMargins(0,5,0,28);
|
|
||||||
|
|
||||||
m_beforeColorWidget = new QFrame(colorFrameWidget);
|
|
||||||
m_beforeColorWidget->setFixedSize(30, 18);
|
|
||||||
m_beforeColorWidget->setAutoFillBackground(true);
|
|
||||||
//m_beforeColorWidget->setFrameShape(QFrame::StyledPanel);
|
|
||||||
m_currentColorWidget = new QFrame(colorFrameWidget);
|
|
||||||
m_currentColorWidget->setFixedSize(30, 18);
|
|
||||||
m_currentColorWidget->setAutoFillBackground(true);
|
|
||||||
//m_currentColorWidget->setFrameShape(QFrame::StyledPanel);
|
|
||||||
|
|
||||||
vBox->addWidget(m_beforeColorWidget);
|
|
||||||
vBox->addWidget(m_currentColorWidget);
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
gridLayout->setSpacing(4);
|
|
||||||
gridLayout->setVerticalSpacing(4);
|
|
||||||
gridLayout->setMargin(4);
|
|
||||||
setLayout(gridLayout);
|
|
||||||
|
|
||||||
gridLayout->addWidget(m_colorBox, 0, 0, 4, 1);
|
|
||||||
gridLayout->addWidget(m_hueControl, 0, 1, 4, 1);
|
|
||||||
|
|
||||||
gridLayout->addWidget(colorFrameWidget, 0, 2, 2, 1);
|
|
||||||
|
|
||||||
|
|
||||||
gridLayout->addWidget(new QLabel("R", this), 0, 3, 1, 1);
|
|
||||||
gridLayout->addWidget(new QLabel("G", this), 1, 3, 1, 1);
|
|
||||||
gridLayout->addWidget(new QLabel("B", this), 2, 3, 1, 1);
|
|
||||||
gridLayout->addWidget(new QLabel("A", this), 3, 3, 1, 1);
|
|
||||||
|
|
||||||
gridLayout->addWidget(m_rSpinBox, 0, 4, 1, 1);
|
|
||||||
gridLayout->addWidget(m_gSpinBox, 1, 4, 1, 1);
|
|
||||||
gridLayout->addWidget(m_bSpinBox, 2, 4, 1, 1);
|
|
||||||
gridLayout->addWidget(m_alphaSpinBox, 3, 4, 1, 1);
|
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
|
|
||||||
|
|
||||||
QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
|
|
||||||
QPushButton *applyButton = buttonBox->addButton(QDialogButtonBox::Apply);
|
|
||||||
|
|
||||||
gridLayout->addWidget(buttonBox, 4, 0, 1, 2);
|
|
||||||
|
|
||||||
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::setupColor(const QColor &color)
|
|
||||||
{
|
|
||||||
QPalette pal = m_beforeColorWidget->palette();
|
|
||||||
pal.setColor(QPalette::Background, color);
|
|
||||||
m_beforeColorWidget->setPalette(pal);
|
|
||||||
setColor(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
QPalette pal = m_currentColorWidget->palette();
|
|
||||||
pal.setColor(QPalette::Background, m_color);
|
|
||||||
m_currentColorWidget->setPalette(pal);
|
|
||||||
m_blockUpdate = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,318 +0,0 @@
|
|||||||
/**************************************************************************
|
|
||||||
**
|
|
||||||
** This file is part of Qt Creator
|
|
||||||
**
|
|
||||||
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
||||||
**
|
|
||||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
||||||
**
|
|
||||||
** Commercial Usage
|
|
||||||
**
|
|
||||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
||||||
** accordance with the Qt Commercial License Agreement provided with the
|
|
||||||
** Software or, alternatively, in accordance with the terms contained in
|
|
||||||
** a written agreement between you and Nokia.
|
|
||||||
**
|
|
||||||
** GNU Lesser General Public License Usage
|
|
||||||
**
|
|
||||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
||||||
** General Public License version 2.1 as published by the Free Software
|
|
||||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
||||||
** packaging of this file. Please review the following information to
|
|
||||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
||||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
||||||
**
|
|
||||||
** If you are unsure which license is appropriate for your use, please
|
|
||||||
** contact the sales department at http://qt.nokia.com/contact.
|
|
||||||
**
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
#ifndef COLORWIDGET_H
|
|
||||||
#define COLORWIDGET_H
|
|
||||||
|
|
||||||
#include <QWeakPointer>
|
|
||||||
#include <QtGui/QWidget>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QToolButton>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <modelnode.h>
|
|
||||||
#include <qdeclarative.h>
|
|
||||||
#include <propertyeditorvalue.h>
|
|
||||||
#include <qmlitemnode.h>
|
|
||||||
#include <QDialog>
|
|
||||||
#include <QLinearGradient>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QtColorButton;
|
|
||||||
class QToolButton;
|
|
||||||
class QDoubleSpinBox;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
|
||||||
|
|
||||||
class ColorButton : public QToolButton {
|
|
||||||
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
|
|
||||||
Q_PROPERTY(bool noColor READ noColor WRITE setNoColor)
|
|
||||||
Q_PROPERTY(bool showArrow READ showArrow WRITE setShowArrow)
|
|
||||||
|
|
||||||
public:
|
|
||||||
ColorButton(QWidget *parent = 0) : QToolButton (parent), m_colorString("#ffffff"), m_noColor(false), m_showArrow(true) {}
|
|
||||||
|
|
||||||
void setColor(const QString &colorStr);
|
|
||||||
QString color() const { return m_colorString; }
|
|
||||||
QColor convertedColor() const;
|
|
||||||
bool noColor() const { return m_noColor; }
|
|
||||||
void setNoColor(bool f) { m_noColor = f; update(); }
|
|
||||||
bool showArrow() const { return m_showArrow; }
|
|
||||||
void setShowArrow(bool b) { m_showArrow = b; }
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void colorChanged();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void paintEvent(QPaintEvent *event);
|
|
||||||
private:
|
|
||||||
QString m_colorString;
|
|
||||||
bool m_noColor;
|
|
||||||
bool m_showArrow;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ColorBox : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
Q_PROPERTY(QString strColor READ strColor WRITE setStrColor NOTIFY colorChanged)
|
|
||||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
|
||||||
Q_PROPERTY(int hue READ hue WRITE setHue NOTIFY hueChanged)
|
|
||||||
Q_PROPERTY(int saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
setFixedWidth(130);
|
|
||||||
setFixedHeight(130);
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
void hueChanged();
|
|
||||||
void saturationChanged();
|
|
||||||
void valueChanged();
|
|
||||||
void alphaChanged();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void paintEvent(QPaintEvent *event);
|
|
||||||
|
|
||||||
void mousePressEvent(QMouseEvent *);
|
|
||||||
void mouseReleaseEvent(QMouseEvent *);
|
|
||||||
void mouseMoveEvent(QMouseEvent *);
|
|
||||||
void setCurrent(int x, int y);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QColor m_color;
|
|
||||||
QColor m_saturatedColor;
|
|
||||||
bool m_mousePressed;
|
|
||||||
int m_lastHue;
|
|
||||||
QPixmap m_cache;
|
|
||||||
};
|
|
||||||
|
|
||||||
class HueControl : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged)
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
HueControl(QWidget *parent = 0) : QWidget(parent), m_color(Qt::white), m_mousePressed(false)
|
|
||||||
{
|
|
||||||
setFixedWidth(28);
|
|
||||||
setFixedHeight(130);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setHue(int newHue);
|
|
||||||
int hue() const { return m_color.hsvHue(); }
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void hueChanged(int hue);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void paintEvent(QPaintEvent *);
|
|
||||||
void mousePressEvent(QMouseEvent *);
|
|
||||||
void mouseReleaseEvent(QMouseEvent *);
|
|
||||||
void mouseMoveEvent(QMouseEvent *);
|
|
||||||
void setCurrent(int y);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QColor m_color;
|
|
||||||
bool m_mousePressed;
|
|
||||||
QPixmap m_cache;
|
|
||||||
};
|
|
||||||
|
|
||||||
class GradientLine : public QWidget {
|
|
||||||
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PROPERTY(QColor activeColor READ activeColor WRITE setActiveColor NOTIFY activeColorChanged)
|
|
||||||
Q_PROPERTY(QVariant itemNode READ itemNode WRITE setItemNode NOTIFY itemNodeChanged)
|
|
||||||
Q_PROPERTY(QString gradientName READ gradientName WRITE setGradientName NOTIFY gradientNameChanged)
|
|
||||||
Q_PROPERTY(bool active READ active WRITE setActive)
|
|
||||||
Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient NOTIFY gradientChanged)
|
|
||||||
|
|
||||||
public:
|
|
||||||
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);
|
|
||||||
QColor activeColor() const { return m_activeColor; }
|
|
||||||
void setActiveColor(const QColor &newColor);
|
|
||||||
bool active() const { return m_active; }
|
|
||||||
void setActive(bool a) { m_active = a; }
|
|
||||||
QLinearGradient gradient() const { return m_gradient; }
|
|
||||||
void setGradient(const QLinearGradient &);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void setupGradient();
|
|
||||||
void deleteGradient();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void activeColorChanged();
|
|
||||||
void itemNodeChanged();
|
|
||||||
void gradientNameChanged();
|
|
||||||
void gradientChanged();
|
|
||||||
void openColorDialog(const QPoint &pos);
|
|
||||||
protected:
|
|
||||||
bool event(QEvent *event);
|
|
||||||
void keyPressEvent(QKeyEvent * event);
|
|
||||||
void paintEvent(QPaintEvent *event);
|
|
||||||
void mousePressEvent(QMouseEvent *event);
|
|
||||||
void mouseDoubleClickEvent(QMouseEvent *event);
|
|
||||||
void mouseReleaseEvent(QMouseEvent *);
|
|
||||||
void mouseMoveEvent(QMouseEvent *);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setup();
|
|
||||||
void updateGradient();
|
|
||||||
int currentColorIndex() const { return m_colorIndex; }
|
|
||||||
void setCurrentIndex(int i);
|
|
||||||
|
|
||||||
QColor m_activeColor;
|
|
||||||
QmlItemNode m_itemNode;
|
|
||||||
QString m_gradientName;
|
|
||||||
QList<QColor> m_colorList;
|
|
||||||
QList<qreal> m_stops;
|
|
||||||
int m_colorIndex;
|
|
||||||
bool m_dragActive;
|
|
||||||
QPoint m_dragStart;
|
|
||||||
QLinearGradient m_gradient;
|
|
||||||
int m_yOffset;
|
|
||||||
bool m_create;
|
|
||||||
bool m_active;
|
|
||||||
bool m_dragOff;
|
|
||||||
bool m_useGradient;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
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 setupColor(const QColor &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:
|
|
||||||
QFrame *m_beforeColorWidget;
|
|
||||||
QFrame *m_currentColorWidget;
|
|
||||||
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 {
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void registerDeclarativeTypes();
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} //QmlDesigner
|
|
||||||
|
|
||||||
QML_DECLARE_TYPE(QmlDesigner::ColorButton)
|
|
||||||
QML_DECLARE_TYPE(QmlDesigner::HueControl)
|
|
||||||
QML_DECLARE_TYPE(QmlDesigner::ColorBox)
|
|
||||||
|
|
||||||
#endif //COLORWIDGET_H
|
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
#include "gradientlineqmladaptor.h"
|
||||||
|
|
||||||
|
#include <qdeclarative.h>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
#include <nodeproperty.h>
|
||||||
|
#include <nodelistproperty.h>
|
||||||
|
#include <nodemetainfo.h>
|
||||||
|
#include <abstractview.h>
|
||||||
|
#include <rewritingexception.h>
|
||||||
|
#include <variantproperty.h>
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
GradientLineQmlAdaptor::GradientLineQmlAdaptor(QWidget *parent) :
|
||||||
|
QmlEditorWidgets::GradientLine(parent)
|
||||||
|
{
|
||||||
|
connect(this, SIGNAL(gradientChanged()), this, SLOT(writeGradient()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GradientLineQmlAdaptor::setItemNode(const QVariant &itemNode)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!itemNode.value<ModelNode>().isValid())
|
||||||
|
return;
|
||||||
|
m_itemNode = itemNode.value<ModelNode>();
|
||||||
|
setupGradient();
|
||||||
|
emit itemNodeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline QColor normalizeColor(const QColor &color)
|
||||||
|
{
|
||||||
|
QColor newColor = QColor(color.name());
|
||||||
|
newColor.setAlpha(color.alpha());
|
||||||
|
return newColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline qreal roundReal(qreal real)
|
||||||
|
{
|
||||||
|
int i = real * 100;
|
||||||
|
return qreal(i) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GradientLineQmlAdaptor::setupGradient()
|
||||||
|
{
|
||||||
|
ModelNode modelNode = m_itemNode.modelNode();
|
||||||
|
QLinearGradient newGradient;
|
||||||
|
QVector<QGradientStop> stops;
|
||||||
|
|
||||||
|
if (!modelNode.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (modelNode.hasProperty(gradientName())) { //gradient exists
|
||||||
|
|
||||||
|
ModelNode gradientNode = modelNode.nodeProperty(gradientName()).modelNode();
|
||||||
|
QList<ModelNode> stopList = gradientNode.nodeListProperty("stops").toModelNodeList();
|
||||||
|
|
||||||
|
foreach (const ModelNode &stopNode, stopList) {
|
||||||
|
QmlObjectNode stopObjectNode = stopNode;
|
||||||
|
if (stopObjectNode.isValid()) {
|
||||||
|
qreal position = stopObjectNode.instanceValue("position").toReal();
|
||||||
|
QColor color = stopObjectNode.instanceValue("color").value<QColor>();
|
||||||
|
stops.append( QPair<qreal, QColor>(position, color));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stops.append( QPair<qreal, QColor>(0, activeColor()));
|
||||||
|
stops.append( QPair<qreal, QColor>(1, QColor(Qt::black)));
|
||||||
|
}
|
||||||
|
|
||||||
|
newGradient.setStops(stops);
|
||||||
|
setGradient(newGradient);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GradientLineQmlAdaptor::writeGradient()
|
||||||
|
{
|
||||||
|
if (!active())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!m_itemNode.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!m_itemNode.modelNode().metaInfo().hasProperty(gradientName()))
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
RewriterTransaction transaction = m_itemNode.modelNode().view()->beginRewriterTransaction();
|
||||||
|
|
||||||
|
ModelNode modelNode = m_itemNode.modelNode();
|
||||||
|
|
||||||
|
QString oldId;
|
||||||
|
QVector<QGradientStop> stops = gradient().stops();
|
||||||
|
if (m_itemNode.isInBaseState()) {
|
||||||
|
if (modelNode.hasProperty(gradientName())) {
|
||||||
|
oldId = modelNode.nodeProperty(gradientName()).modelNode().id();
|
||||||
|
modelNode.removeProperty(gradientName());
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelNode gradientNode = modelNode.view()->createModelNode("Qt/Gradient", 4, 7);
|
||||||
|
|
||||||
|
if (!oldId.isNull())
|
||||||
|
gradientNode.setId(oldId);
|
||||||
|
|
||||||
|
for (int i = 0;i < stops.size(); i++) {
|
||||||
|
ModelNode gradientStopNode = modelNode.view()->createModelNode("Qt/GradientStop", 4, 7);
|
||||||
|
gradientStopNode.variantProperty("position") = roundReal(stops.at(i).first);
|
||||||
|
gradientStopNode.variantProperty("color") = normalizeColor(stops.at(i).second);
|
||||||
|
gradientNode.nodeListProperty("stops").reparentHere(gradientStopNode);
|
||||||
|
}
|
||||||
|
modelNode.nodeProperty(gradientName()).reparentHere(gradientNode);
|
||||||
|
} else { //state
|
||||||
|
if (!modelNode.hasProperty(gradientName())) {
|
||||||
|
qWarning(" GradientLine::updateGradient: no gradient in state");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ModelNode gradientNode = modelNode.nodeProperty(gradientName()).modelNode();
|
||||||
|
QList<ModelNode> stopList = gradientNode.nodeListProperty("stops").toModelNodeList();
|
||||||
|
for (int i = 0;i < stops.size(); i++) {
|
||||||
|
QmlObjectNode stopObjectNode = stopList.at(i);
|
||||||
|
stopObjectNode.setVariantProperty("position", roundReal(stops.at(i).first));
|
||||||
|
stopObjectNode.setVariantProperty("color", normalizeColor(stops.at(i).second));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (RewritingException &e) {
|
||||||
|
QMessageBox::warning(0, "Error", e.description());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GradientLineQmlAdaptor::deleteGradient()
|
||||||
|
{
|
||||||
|
if (!m_itemNode.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!m_itemNode.modelNode().metaInfo().hasProperty(gradientName()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ModelNode modelNode = m_itemNode.modelNode();
|
||||||
|
|
||||||
|
if (m_itemNode.isInBaseState()) {
|
||||||
|
if (modelNode.hasProperty(gradientName())) {
|
||||||
|
RewriterTransaction transaction = m_itemNode.modelNode().view()->beginRewriterTransaction();
|
||||||
|
ModelNode gradientNode = modelNode.nodeProperty(gradientName()).modelNode();
|
||||||
|
if (QmlObjectNode(gradientNode).isValid())
|
||||||
|
QmlObjectNode(gradientNode).destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GradientLineQmlAdaptor::registerDeclarativeType() {
|
||||||
|
qmlRegisterType<QmlDesigner::GradientLineQmlAdaptor>("Bauhaus",1,0,"GradientLine");
|
||||||
|
}
|
||||||
|
|
||||||
|
} //QmlDesigner
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#ifndef GRADIENTLINEQMLADAPTOR_H
|
||||||
|
#define GRADIENTLINEQMLADAPTOR_H
|
||||||
|
|
||||||
|
#include <qmleditorwidgets/gradientline.h>
|
||||||
|
#include <propertyeditorvalue.h>
|
||||||
|
#include <qmlitemnode.h>
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
class GradientLineQmlAdaptor : public QmlEditorWidgets::GradientLine
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QVariant itemNode READ itemNode WRITE setItemNode NOTIFY itemNodeChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GradientLineQmlAdaptor(QWidget *parent = 0);
|
||||||
|
|
||||||
|
static void registerDeclarativeType();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void itemNodeChanged();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setupGradient();
|
||||||
|
void writeGradient();
|
||||||
|
void deleteGradient();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVariant itemNode() const { return QVariant::fromValue(m_itemNode.modelNode()); }
|
||||||
|
void setItemNode(const QVariant &itemNode);
|
||||||
|
|
||||||
|
QmlItemNode m_itemNode;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} //QmlDesigner
|
||||||
|
|
||||||
|
#endif // GRADIENTLINEQMLADAPTOR_H
|
||||||
@@ -47,7 +47,8 @@
|
|||||||
#include "basicwidgets.h"
|
#include "basicwidgets.h"
|
||||||
#include "resetwidget.h"
|
#include "resetwidget.h"
|
||||||
#include "qlayoutobject.h"
|
#include "qlayoutobject.h"
|
||||||
#include "colorwidget.h"
|
#include <qmleditorwidgets/colorwidgets.h>
|
||||||
|
#include "gradientlineqmladaptor.h"
|
||||||
#include "behaviordialog.h"
|
#include "behaviordialog.h"
|
||||||
#include "qproxylayoutitem.h"
|
#include "qproxylayoutitem.h"
|
||||||
#include "fontwidget.h"
|
#include "fontwidget.h"
|
||||||
@@ -291,13 +292,14 @@ PropertyEditor::PropertyEditor(QWidget *parent) :
|
|||||||
BasicLayouts::registerDeclarativeTypes();
|
BasicLayouts::registerDeclarativeTypes();
|
||||||
ResetWidget::registerDeclarativeType();
|
ResetWidget::registerDeclarativeType();
|
||||||
QLayoutObject::registerDeclarativeType();
|
QLayoutObject::registerDeclarativeType();
|
||||||
ColorWidget::registerDeclarativeTypes();
|
QmlEditorWidgets::ColorWidgets::registerDeclarativeTypes();
|
||||||
BehaviorDialog::registerDeclarativeType();
|
BehaviorDialog::registerDeclarativeType();
|
||||||
QProxyLayoutItem::registerDeclarativeTypes();
|
QProxyLayoutItem::registerDeclarativeTypes();
|
||||||
PropertyEditorValue::registerDeclarativeTypes();
|
PropertyEditorValue::registerDeclarativeTypes();
|
||||||
FontWidget::registerDeclarativeTypes();
|
FontWidget::registerDeclarativeTypes();
|
||||||
SiblingComboBox::registerDeclarativeTypes();
|
SiblingComboBox::registerDeclarativeTypes();
|
||||||
OriginWidget::registerDeclarativeType();
|
OriginWidget::registerDeclarativeType();
|
||||||
|
GradientLineQmlAdaptor::registerDeclarativeType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ SOURCES += propertyeditor.cpp \
|
|||||||
qlayoutobject.cpp \
|
qlayoutobject.cpp \
|
||||||
basiclayouts.cpp \
|
basiclayouts.cpp \
|
||||||
basicwidgets.cpp \
|
basicwidgets.cpp \
|
||||||
colorwidget.cpp \
|
|
||||||
behaviordialog.cpp \
|
behaviordialog.cpp \
|
||||||
qproxylayoutitem.cpp \
|
qproxylayoutitem.cpp \
|
||||||
layoutwidget.cpp \
|
layoutwidget.cpp \
|
||||||
@@ -18,7 +17,8 @@ SOURCES += propertyeditor.cpp \
|
|||||||
siblingcombobox.cpp \
|
siblingcombobox.cpp \
|
||||||
propertyeditortransaction.cpp \
|
propertyeditortransaction.cpp \
|
||||||
propertyeditorcontextobject.cpp \
|
propertyeditorcontextobject.cpp \
|
||||||
declarativewidgetview.cpp
|
declarativewidgetview.cpp \
|
||||||
|
gradientlineqmladaptor.cpp
|
||||||
|
|
||||||
HEADERS += propertyeditor.h \
|
HEADERS += propertyeditor.h \
|
||||||
qmlanchorbindingproxy.h \
|
qmlanchorbindingproxy.h \
|
||||||
@@ -27,7 +27,6 @@ HEADERS += propertyeditor.h \
|
|||||||
qlayoutobject.h \
|
qlayoutobject.h \
|
||||||
basiclayouts.h \
|
basiclayouts.h \
|
||||||
basicwidgets.h \
|
basicwidgets.h \
|
||||||
colorwidget.h \
|
|
||||||
behaviordialog.h \
|
behaviordialog.h \
|
||||||
qproxylayoutitem.h \
|
qproxylayoutitem.h \
|
||||||
layoutwidget.h \
|
layoutwidget.h \
|
||||||
@@ -39,7 +38,8 @@ HEADERS += propertyeditor.h \
|
|||||||
propertyeditortransaction.h \
|
propertyeditortransaction.h \
|
||||||
designerpropertymap.h \
|
designerpropertymap.h \
|
||||||
propertyeditorcontextobject.h \
|
propertyeditorcontextobject.h \
|
||||||
declarativewidgetview.h
|
declarativewidgetview.h \
|
||||||
|
gradientlineqmladaptor.h
|
||||||
|
|
||||||
QT += declarative
|
QT += declarative
|
||||||
RESOURCES += propertyeditor.qrc
|
RESOURCES += propertyeditor.qrc
|
||||||
|
|||||||
Reference in New Issue
Block a user