-
Qt by Nokia authored
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
50123887
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qtgradientwidget.h"
#include <QtCore/QMap>
#include <QtGui/QImage>
#include <QtGui/QPainter>
#include <QtGui/QScrollBar>
#include <QtGui/QMouseEvent>
#define _USE_MATH_DEFINES
#include "math.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
QT_BEGIN_NAMESPACE
class QtGradientWidgetPrivate
{
QtGradientWidget *q_ptr;
Q_DECLARE_PUBLIC(QtGradientWidget)
public:
QPointF fromViewport(const QPointF &point) const;
QPointF toViewport(const QPointF &point) const;
// void setupDrag(QtGradientStop *stop, int x);
QPointF checkRange(const QPointF &point) const;
QRectF pointRect(const QPointF &point, double size) const;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
double correctAngle(double angle) const;
void setAngleConical(double angle);
void paintPoint(QPainter *painter, const QPointF &point, double size) const;
double m_handleSize;
bool m_backgroundCheckered;
QGradientStops m_gradientStops;
QGradient::Type m_gradientType;
QGradient::Spread m_gradientSpread;
QPointF m_startLinear;
QPointF m_endLinear;
QPointF m_centralRadial;
QPointF m_focalRadial;
qreal m_radiusRadial;
QPointF m_centralConical;
qreal m_angleConical;
enum Handle {
NoHandle,
StartLinearHandle,
EndLinearHandle,
CentralRadialHandle,
FocalRadialHandle,
RadiusRadialHandle,
CentralConicalHandle,
AngleConicalHandle
};
Handle m_dragHandle;
QPointF m_dragOffset;
//double m_radiusOffset;
double m_radiusFactor;
double m_dragRadius;
double m_angleOffset;
double m_dragAngle;
};
double QtGradientWidgetPrivate::correctAngle(double angle) const
{
double a = angle;
while (a >= 360)
a -= 360;
while (a < 0)
a += 360;
return a;
}
void QtGradientWidgetPrivate::setAngleConical(double angle)
{
double a = correctAngle(angle);
if (m_angleConical == a)
return;
m_angleConical = a;
emit q_ptr->angleConicalChanged(m_angleConical);
}
QRectF QtGradientWidgetPrivate::pointRect(const QPointF &point, double size) const
{
return QRectF(point.x() - size / 2, point.y() - size / 2, size, size);
}
QPointF QtGradientWidgetPrivate::checkRange(const QPointF &point) const
{
QPointF p = point;
if (p.x() > 1)
p.setX(1);
else if (p.x() < 0)
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
p.setX(0);
if (p.y() > 1)
p.setY(1);
else if (p.y() < 0)
p.setY(0);
return p;
}
QPointF QtGradientWidgetPrivate::fromViewport(const QPointF &point) const
{
QSize size = q_ptr->size();
return QPointF(point.x() / size.width(), point.y() / size.height());
}
QPointF QtGradientWidgetPrivate::toViewport(const QPointF &point) const
{
QSize size = q_ptr->size();
return QPointF(point.x() * size.width(), point.y() * size.height());
}
void QtGradientWidgetPrivate::paintPoint(QPainter *painter, const QPointF &point, double size) const
{
QPointF pf = toViewport(point);
QRectF rf = pointRect(pf, size);
QPen pen;
pen.setWidthF(1);
QColor alphaZero = Qt::white;
alphaZero.setAlpha(0);
painter->save();
painter->drawEllipse(rf);
/*
painter->save();
QLinearGradient lgV(0, rf.top(), 0, rf.bottom());
lgV.setColorAt(0, alphaZero);
lgV.setColorAt(0.25, Qt::white);
lgV.setColorAt(0.25, Qt::white);
lgV.setColorAt(1, alphaZero);
pen.setBrush(lgV);
painter->setPen(pen);
painter->drawLine(QPointF(pf.x(), rf.top()), QPointF(pf.x(), rf.bottom()));
QLinearGradient lgH(rf.left(), 0, rf.right(), 0);
lgH.setColorAt(0, alphaZero);
lgH.setColorAt(0.5, Qt::white);
lgH.setColorAt(1, alphaZero);
pen.setBrush(lgH);
painter->setPen(pen);
painter->drawLine(QPointF(rf.left(), pf.y()), QPointF(rf.right(), pf.y()));
painter->restore();
*/
painter->restore();
}
/*
void QtGradientWidgetPrivate::setupDrag(QtGradientStop *stop, int x)
{
m_model->setCurrentStop(stop);
int viewportX = qRound(toViewport(stop->position()));
m_dragOffset = x - viewportX;
QList<QtGradientStop *> stops = m_stops;
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
m_stops.clear();
QListIterator<QtGradientStop *> itStop(stops);
while (itStop.hasNext()) {
QtGradientStop *s = itStop.next();
if (m_model->isSelected(s) || s == stop) {
m_dragStops[s] = s->position() - stop->position();
m_stops.append(s);
} else {
m_dragOriginal[s->position()] = s->color();
}
}
itStop.toFront();
while (itStop.hasNext()) {
QtGradientStop *s = itStop.next();
if (!m_model->isSelected(s))
m_stops.append(s);
}
m_stops.removeAll(stop);
m_stops.prepend(stop);
}
*/
////////////////////////////
QtGradientWidget::QtGradientWidget(QWidget *parent)
: QWidget(parent), d_ptr(new QtGradientWidgetPrivate)
{
d_ptr->q_ptr = this;
d_ptr->m_backgroundCheckered = true;
d_ptr->m_handleSize = 20.0;
d_ptr->m_gradientType = QGradient::LinearGradient;
d_ptr->m_startLinear = QPointF(0, 0);
d_ptr->m_endLinear = QPointF(1, 1);
d_ptr->m_centralRadial = QPointF(0.5, 0.5);
d_ptr->m_focalRadial = QPointF(0.5, 0.5);
d_ptr->m_radiusRadial = 0.5;
d_ptr->m_centralConical = QPointF(0.5, 0.5);
d_ptr->m_angleConical = 0;
d_ptr->m_dragHandle = QtGradientWidgetPrivate::NoHandle;
setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
}
QtGradientWidget::~QtGradientWidget()
{
}
QSize QtGradientWidget::sizeHint() const
{
return QSize(176, 176);
}
QSize QtGradientWidget::minimumSizeHint() const
{
return QSize(128, 128);
}
int QtGradientWidget::heightForWidth(int w) const
{
return w;
}
void QtGradientWidget::setBackgroundCheckered(bool checkered)
{
if (d_ptr->m_backgroundCheckered == checkered)
return;
d_ptr->m_backgroundCheckered = checkered;
update();
}
bool QtGradientWidget::isBackgroundCheckered() const
281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
{
return d_ptr->m_backgroundCheckered;
}
void QtGradientWidget::mousePressEvent(QMouseEvent *e)
{
if (e->button() != Qt::LeftButton)
return;
QPoint p = e->pos();
if (d_ptr->m_gradientType == QGradient::LinearGradient) {
QPointF startPoint = d_ptr->toViewport(d_ptr->m_startLinear);
double x = p.x() - startPoint.x();
double y = p.y() - startPoint.y();
if ((d_ptr->m_handleSize * d_ptr->m_handleSize / 4) > (x * x + y * y)) {
d_ptr->m_dragHandle = QtGradientWidgetPrivate::StartLinearHandle;
d_ptr->m_dragOffset = QPointF(x, y);
update();
return;
}
QPointF endPoint = d_ptr->toViewport(d_ptr->m_endLinear);
x = p.x() - endPoint.x();
y = p.y() - endPoint.y();
if ((d_ptr->m_handleSize * d_ptr->m_handleSize / 4) > (x * x + y * y)) {
d_ptr->m_dragHandle = QtGradientWidgetPrivate::EndLinearHandle;
d_ptr->m_dragOffset = QPointF(x, y);
update();
return;
}
} else if (d_ptr->m_gradientType == QGradient::RadialGradient) {
QPointF focalPoint = d_ptr->toViewport(d_ptr->m_focalRadial);
double x = p.x() - focalPoint.x();
double y = p.y() - focalPoint.y();
if ((d_ptr->m_handleSize * d_ptr->m_handleSize / 9) > (x * x + y * y)) {
d_ptr->m_dragHandle = QtGradientWidgetPrivate::FocalRadialHandle;
d_ptr->m_dragOffset = QPointF(x, y);
update();
return;
}
QPointF centralPoint = d_ptr->toViewport(d_ptr->m_centralRadial);
x = p.x() - centralPoint.x();
y = p.y() - centralPoint.y();
if ((d_ptr->m_handleSize * d_ptr->m_handleSize / 4) > (x * x + y * y)) {
d_ptr->m_dragHandle = QtGradientWidgetPrivate::CentralRadialHandle;
d_ptr->m_dragOffset = QPointF(x, y);
update();
return;
}
QPointF central = d_ptr->toViewport(d_ptr->m_centralRadial);
QRectF r = d_ptr->pointRect(central, 2 * d_ptr->m_handleSize / 3);
QRectF r1(0, r.y(), size().width(), r.height());
QRectF r2(r.x(), 0, r.width(), r.y());
QRectF r3(r.x(), r.y() + r.height(), r.width(), size().height() - r.y() - r.height());
QPointF pF(p.x(), p.y());
if (r1.contains(pF) || r2.contains(pF) || r3.contains(pF)) {
x = pF.x() / size().width() - d_ptr->m_centralRadial.x();
y = pF.y() / size().height() - d_ptr->m_centralRadial.y();
double clickRadius = sqrt(x * x + y * y);
//d_ptr->m_radiusOffset = d_ptr->m_radiusRadial - clickRadius;
d_ptr->m_radiusFactor = d_ptr->m_radiusRadial / clickRadius;
if (d_ptr->m_radiusFactor == 0)
d_ptr->m_radiusFactor = 1;
d_ptr->m_dragRadius = d_ptr->m_radiusRadial;
351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
d_ptr->m_dragHandle = QtGradientWidgetPrivate::RadiusRadialHandle;
mouseMoveEvent(e);
update();
return;
}
} else if (d_ptr->m_gradientType == QGradient::ConicalGradient) {
QPointF centralPoint = d_ptr->toViewport(d_ptr->m_centralConical);
double x = p.x() - centralPoint.x();
double y = p.y() - centralPoint.y();
if ((d_ptr->m_handleSize * d_ptr->m_handleSize / 4) > (x * x + y * y)) {
d_ptr->m_dragHandle = QtGradientWidgetPrivate::CentralConicalHandle;
d_ptr->m_dragOffset = QPointF(x, y);
update();
return;
}
double radius = size().width();
if (size().height() < radius)
radius = size().height();
radius /= 2;
double corr = d_ptr->m_handleSize / 3;
radius -= corr;
QPointF vp = d_ptr->toViewport(d_ptr->m_centralConical);
x = p.x() - vp.x();
y = p.y() - vp.y();
if (((radius - corr) * (radius - corr) < (x * x + y * y)) &&
((radius + corr) * (radius + corr) > (x * x + y * y))) {
QPointF central = d_ptr->toViewport(d_ptr->m_centralConical);
QPointF current(e->pos().x(), e->pos().y());
x = current.x() - central.x();
y = current.y() - central.y();
x /= size().width() / 2;
y /= size().height() / 2;
double r = sqrt(x * x + y * y);
double arcSin = asin(y / r);
double arcCos = acos(x / r);
double angle = arcCos * 180 / M_PI;
if (arcSin > 0) {
angle = -angle;
}
d_ptr->m_angleOffset = d_ptr->m_angleConical - angle;
d_ptr->m_dragAngle = d_ptr->m_angleConical;
d_ptr->m_dragHandle = QtGradientWidgetPrivate::AngleConicalHandle;
update();
return;
}
}
}
void QtGradientWidget::mouseReleaseEvent(QMouseEvent *e)
{
Q_UNUSED(e)
d_ptr->m_dragHandle = QtGradientWidgetPrivate::NoHandle;
update();
}
void QtGradientWidget::mouseMoveEvent(QMouseEvent *e)
{
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::NoHandle)
return;
QPointF newPos = QPointF((double)e->pos().x() - d_ptr->m_dragOffset.x(),
(double)e->pos().y() - d_ptr->m_dragOffset.y());
QPointF newPoint = d_ptr->fromViewport(newPos);
if (newPoint.x() < 0)
newPoint.setX(0);
else if (newPoint.x() > 1)
421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
newPoint.setX(1);
if (newPoint.y() < 0)
newPoint.setY(0);
else if (newPoint.y() > 1)
newPoint.setY(1);
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::StartLinearHandle) {
d_ptr->m_startLinear = newPoint;
emit startLinearChanged(newPoint);
} else if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::EndLinearHandle) {
d_ptr->m_endLinear = newPoint;
emit endLinearChanged(newPoint);
} else if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::CentralRadialHandle) {
d_ptr->m_centralRadial = newPoint;
emit centralRadialChanged(newPoint);
} else if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::FocalRadialHandle) {
d_ptr->m_focalRadial = newPoint;
emit focalRadialChanged(newPoint);
} else if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::RadiusRadialHandle) {
QPointF centralPoint = d_ptr->toViewport(d_ptr->m_centralRadial);
QPointF pF(e->pos().x(), e->pos().y());
double x = pF.x() - centralPoint.x();
double y = pF.y() - centralPoint.y();
if ((d_ptr->m_handleSize * d_ptr->m_handleSize / 4) > (x * x + y * y)) {
if (d_ptr->m_radiusRadial != d_ptr->m_dragRadius) {
d_ptr->m_radiusRadial = d_ptr->m_dragRadius;
emit radiusRadialChanged(d_ptr->m_radiusRadial);
}
} else {
x = pF.x() / size().width() - d_ptr->m_centralRadial.x();
y = pF.y() / size().height() - d_ptr->m_centralRadial.y();
double moveRadius = sqrt(x * x + y * y);
//double newRadius = moveRadius + d_ptr->m_radiusOffset;
double newRadius = moveRadius * d_ptr->m_radiusFactor;
if (newRadius > 2)
newRadius = 2;
d_ptr->m_radiusRadial = newRadius;
emit radiusRadialChanged(d_ptr->m_radiusRadial);
}
} else if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::CentralConicalHandle) {
d_ptr->m_centralConical = newPoint;
emit centralConicalChanged(newPoint);
} else if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::AngleConicalHandle) {
QPointF centralPoint = d_ptr->toViewport(d_ptr->m_centralConical);
QPointF pF(e->pos().x(), e->pos().y());
double x = pF.x() - centralPoint.x();
double y = pF.y() - centralPoint.y();
if ((d_ptr->m_handleSize * d_ptr->m_handleSize / 4) > (x * x + y * y)) {
if (d_ptr->m_angleConical != d_ptr->m_dragAngle) {
d_ptr->m_angleConical = d_ptr->m_dragAngle;
emit angleConicalChanged(d_ptr->m_angleConical);
}
} else {
QPointF central = d_ptr->toViewport(d_ptr->m_centralConical);
QPointF current = pF;
x = current.x() - central.x();
y = current.y() - central.y();
x /= size().width() / 2;
y /= size().height() / 2;
double r = sqrt(x * x + y * y);
double arcSin = asin(y / r);
double arcCos = acos(x / r);
double angle = arcCos * 180 / M_PI;
if (arcSin > 0) {
angle = -angle;
}
491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
angle += d_ptr->m_angleOffset;
d_ptr->setAngleConical(angle);
}
}
update();
}
void QtGradientWidget::mouseDoubleClickEvent(QMouseEvent *e)
{
mousePressEvent(e);
}
void QtGradientWidget::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e)
QPainter p(this);
if (d_ptr->m_backgroundCheckered) {
int pixSize = 40;
QPixmap pm(2 * pixSize, 2 * pixSize);
QPainter pmp(&pm);
pmp.fillRect(0, 0, pixSize, pixSize, Qt::white);
pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::white);
pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black);
pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black);
p.setBrushOrigin((size().width() % pixSize + pixSize) / 2, (size().height() % pixSize + pixSize) / 2);
p.fillRect(rect(), pm);
p.setBrushOrigin(0, 0);
}
QGradient *gradient = 0;
switch (d_ptr->m_gradientType) {
case QGradient::LinearGradient:
gradient = new QLinearGradient(d_ptr->m_startLinear, d_ptr->m_endLinear);
break;
case QGradient::RadialGradient:
gradient = new QRadialGradient(d_ptr->m_centralRadial, d_ptr->m_radiusRadial, d_ptr->m_focalRadial);
break;
case QGradient::ConicalGradient:
gradient = new QConicalGradient(d_ptr->m_centralConical, d_ptr->m_angleConical);
break;
default:
break;
}
if (!gradient)
return;
gradient->setStops(d_ptr->m_gradientStops);
gradient->setSpread(d_ptr->m_gradientSpread);
p.save();
p.scale(size().width(), size().height());
p.fillRect(QRect(0, 0, 1, 1), *gradient);
p.restore();
p.setRenderHint(QPainter::Antialiasing);
QColor c = QColor::fromRgbF(0.5, 0.5, 0.5, 0.5);
QBrush br(c);
p.setBrush(br);
QPen pen(Qt::white);
pen.setWidthF(1);
p.setPen(pen);
QPen dragPen = pen;
dragPen.setWidthF(2);
561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
if (d_ptr->m_gradientType == QGradient::LinearGradient) {
p.save();
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::StartLinearHandle)
p.setPen(dragPen);
d_ptr->paintPoint(&p, d_ptr->m_startLinear, d_ptr->m_handleSize);
p.restore();
p.save();
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::EndLinearHandle)
p.setPen(dragPen);
d_ptr->paintPoint(&p, d_ptr->m_endLinear, d_ptr->m_handleSize);
p.restore();
} else if (d_ptr->m_gradientType == QGradient::RadialGradient) {
QPointF central = d_ptr->toViewport(d_ptr->m_centralRadial);
p.save();
QRectF r = d_ptr->pointRect(central, 2 * d_ptr->m_handleSize / 3);
QRectF r1(0, r.y(), size().width(), r.height());
QRectF r2(r.x(), 0, r.width(), r.y());
QRectF r3(r.x(), r.y() + r.height(), r.width(), size().height() - r.y() - r.height());
p.fillRect(r1, c);
p.fillRect(r2, c);
p.fillRect(r3, c);
p.setBrush(Qt::NoBrush);
p.save();
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::CentralRadialHandle)
p.setPen(dragPen);
d_ptr->paintPoint(&p, d_ptr->m_centralRadial, d_ptr->m_handleSize);
p.restore();
QRectF rect = QRectF(central.x() - d_ptr->m_radiusRadial * size().width(),
central.y() - d_ptr->m_radiusRadial * size().height(),
2 * d_ptr->m_radiusRadial * size().width(),
2 * d_ptr->m_radiusRadial * size().height());
p.setClipRect(r1);
p.setClipRect(r2, Qt::UniteClip);
p.setClipRect(r3, Qt::UniteClip);
p.drawEllipse(rect);
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::RadiusRadialHandle) {
p.save();
p.setPen(dragPen);
QRectF rect = QRectF(central.x() - d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().width(),
central.y() - d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().height(),
2 * d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().width(),
2 * d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().height());
p.drawEllipse(rect);
p.restore();
}
p.restore();
p.save();
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::FocalRadialHandle)
p.setPen(dragPen);
d_ptr->paintPoint(&p, d_ptr->m_focalRadial, 2 * d_ptr->m_handleSize / 3);
p.restore();
} else if (d_ptr->m_gradientType == QGradient::ConicalGradient) {
double radius = size().width();
if (size().height() < radius)
radius = size().height();
radius /= 2;
double corr = d_ptr->m_handleSize / 3;
radius -= corr;
QPointF central = d_ptr->toViewport(d_ptr->m_centralConical);
p.save();
p.setBrush(Qt::NoBrush);
QPen pen2(c);
pen2.setWidthF(2 * d_ptr->m_handleSize / 3);
p.setPen(pen2);
631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
p.drawEllipse(d_ptr->pointRect(central, 2 * radius));
p.restore();
p.save();
p.setBrush(Qt::NoBrush);
int pointCount = 2;
for (int i = 0; i < pointCount; i++) {
QPointF ang(cos(M_PI * (i * 180.0 / pointCount + d_ptr->m_angleConical) / 180) * size().width() / 2,
-sin(M_PI * (i * 180.0 / pointCount + d_ptr->m_angleConical) / 180) * size().height() / 2);
double mod = sqrt(ang.x() * ang.x() + ang.y() * ang.y());
p.drawLine(QPointF(central.x() + ang.x() * (radius - corr) / mod,
central.y() + ang.y() * (radius - corr) / mod),
QPointF(central.x() + ang.x() * (radius + corr) / mod,
central.y() + ang.y() * (radius + corr) / mod));
p.drawLine(QPointF(central.x() - ang.x() * (radius - corr) / mod,
central.y() - ang.y() * (radius - corr) / mod),
QPointF(central.x() - ang.x() * (radius + corr) / mod,
central.y() - ang.y() * (radius + corr) / mod));
}
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::AngleConicalHandle) {
p.save();
p.setPen(dragPen);
QPointF ang(cos(M_PI * (d_ptr->m_angleConical - d_ptr->m_angleOffset) / 180) * size().width() / 2,
-sin(M_PI * (d_ptr->m_angleConical - d_ptr->m_angleOffset) / 180) * size().height() / 2);
double mod = sqrt(ang.x() * ang.x() + ang.y() * ang.y());
p.drawLine(QPointF(central.x() + ang.x() * (radius - corr) / mod,
central.y() + ang.y() * (radius - corr) / mod),
QPointF(central.x() + ang.x() * (radius + corr) / mod,
central.y() + ang.y() * (radius + corr) / mod));
p.restore();
}
p.restore();
p.save();
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::CentralConicalHandle)
p.setPen(dragPen);
d_ptr->paintPoint(&p, d_ptr->m_centralConical, d_ptr->m_handleSize);
p.restore();
}
delete gradient;
}
void QtGradientWidget::setGradientStops(const QGradientStops &stops)
{
d_ptr->m_gradientStops = stops;
update();
}
QGradientStops QtGradientWidget::gradientStops() const
{
return d_ptr->m_gradientStops;
}
void QtGradientWidget::setGradientType(QGradient::Type type)
{
if (type == QGradient::NoGradient)
return;
if (d_ptr->m_gradientType == type)
return;
d_ptr->m_gradientType = type;
update();
}
QGradient::Type QtGradientWidget::gradientType() const
{
return d_ptr->m_gradientType;
701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
}
void QtGradientWidget::setGradientSpread(QGradient::Spread spread)
{
if (d_ptr->m_gradientSpread == spread)
return;
d_ptr->m_gradientSpread = spread;
update();
}
QGradient::Spread QtGradientWidget::gradientSpread() const
{
return d_ptr->m_gradientSpread;
}
void QtGradientWidget::setStartLinear(const QPointF &point)
{
if (d_ptr->m_startLinear == point)
return;
d_ptr->m_startLinear = d_ptr->checkRange(point);
update();
}
QPointF QtGradientWidget::startLinear() const
{
return d_ptr->m_startLinear;
}
void QtGradientWidget::setEndLinear(const QPointF &point)
{
if (d_ptr->m_endLinear == point)
return;
d_ptr->m_endLinear = d_ptr->checkRange(point);
update();
}
QPointF QtGradientWidget::endLinear() const
{
return d_ptr->m_endLinear;
}
void QtGradientWidget::setCentralRadial(const QPointF &point)
{
if (d_ptr->m_centralRadial == point)
return;
d_ptr->m_centralRadial = point;
update();
}
QPointF QtGradientWidget::centralRadial() const
{
return d_ptr->m_centralRadial;
}
void QtGradientWidget::setFocalRadial(const QPointF &point)
{
if (d_ptr->m_focalRadial == point)
return;
d_ptr->m_focalRadial = point;
update();
}
QPointF QtGradientWidget::focalRadial() const
{
return d_ptr->m_focalRadial;
771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
}
void QtGradientWidget::setRadiusRadial(qreal radius)
{
if (d_ptr->m_radiusRadial == radius)
return;
d_ptr->m_radiusRadial = radius;
update();
}
qreal QtGradientWidget::radiusRadial() const
{
return d_ptr->m_radiusRadial;
}
void QtGradientWidget::setCentralConical(const QPointF &point)
{
if (d_ptr->m_centralConical == point)
return;
d_ptr->m_centralConical = point;
update();
}
QPointF QtGradientWidget::centralConical() const
{
return d_ptr->m_centralConical;
}
void QtGradientWidget::setAngleConical(qreal angle)
{
if (d_ptr->m_angleConical == angle)
return;
d_ptr->m_angleConical = angle;
update();
}
qreal QtGradientWidget::angleConical() const
{
return d_ptr->m_angleConical;
}
QT_END_NAMESPACE