libs/flake
KoParameterShape.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "KoParameterShape.h"
00022 #include "KoPathShape_p.h"
00023
00024 #include <QPainter>
00025 #include <KDebug>
00026
00027 class KoParameterShapePrivate : public KoPathShapePrivate
00028 {
00029 public:
00030 KoParameterShapePrivate(KoParameterShape *shape)
00031 : KoPathShapePrivate(shape),
00032 modified(false)
00033 {
00034 }
00035 bool modified;
00036 };
00037
00038 KoParameterShape::KoParameterShape()
00039 : KoPathShape(*(new KoParameterShapePrivate(this)))
00040 {
00041 }
00042
00043 KoParameterShape::~KoParameterShape()
00044 {
00045 }
00046
00047 void KoParameterShape::moveHandle(int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers)
00048 {
00049 if (handleId >= m_handles.size()) {
00050 kWarning(30006) << "handleId out of bounds";
00051 return;
00052 }
00053 Q_D(KoParameterShape);
00054
00055 update();
00056
00057 moveHandleAction(handleId, documentToShape(point), modifiers);
00058
00059 updatePath(size());
00060 update();
00061 d->shapeChanged(ParameterChanged);
00062 }
00063
00064
00065 int KoParameterShape::handleIdAt(const QRectF & rect) const
00066 {
00067 int handle = -1;
00068
00069 for (int i = 0; i < m_handles.size(); ++i) {
00070 if (rect.contains(m_handles.at(i))) {
00071 handle = i;
00072 break;
00073 }
00074 }
00075 return handle;
00076 }
00077
00078 QPointF KoParameterShape::handlePosition(int handleId)
00079 {
00080 return m_handles.value(handleId);
00081 }
00082
00083 void KoParameterShape::paintHandles(QPainter & painter, const KoViewConverter & converter, int handleRadius)
00084 {
00085 applyConversion(painter, converter);
00086
00087 QMatrix worldMatrix = painter.worldMatrix();
00088 painter.setMatrix(QMatrix());
00089
00090 QMatrix matrix;
00091 matrix.rotate(45.0);
00092 QPolygonF poly(handleRect(QPointF(0, 0), handleRadius));
00093 poly = matrix.map(poly);
00094
00095 QList<QPointF>::const_iterator it(m_handles.constBegin());
00096 for (; it != m_handles.constEnd(); ++it) {
00097 QPointF moveVector = worldMatrix.map(*it);
00098 poly.translate(moveVector.x(), moveVector.y());
00099 painter.drawPolygon(poly);
00100 poly.translate(-moveVector.x(), -moveVector.y());
00101 }
00102 }
00103
00104 void KoParameterShape::paintHandle(QPainter & painter, const KoViewConverter & converter, int handleId, int handleRadius)
00105 {
00106 applyConversion(painter, converter);
00107
00108 QMatrix worldMatrix = painter.worldMatrix();
00109 painter.setMatrix(QMatrix());
00110
00111 QMatrix matrix;
00112 matrix.rotate(45.0);
00113 QPolygonF poly(handleRect(QPointF(0, 0), handleRadius));
00114 poly = matrix.map(poly);
00115 poly.translate(worldMatrix.map(m_handles[handleId]));
00116 painter.drawPolygon(poly);
00117 }
00118
00119 int KoParameterShape::getHandleCount()
00120 {
00121 return m_handles.count();
00122 }
00123
00124 void KoParameterShape::setSize(const QSizeF &newSize)
00125 {
00126 QMatrix matrix(resizeMatrix(newSize));
00127
00128 for (int i = 0; i < m_handles.size(); ++i) {
00129 m_handles[i] = matrix.map(m_handles[i]);
00130 }
00131
00132 KoPathShape::setSize(newSize);
00133 }
00134
00135 QPointF KoParameterShape::normalize()
00136 {
00137 QPointF offset(KoPathShape::normalize());
00138 QMatrix matrix;
00139 matrix.translate(-offset.x(), -offset.y());
00140
00141 for (int i = 0; i < m_handles.size(); ++i) {
00142 m_handles[i] = matrix.map(m_handles[i]);
00143 }
00144
00145 return offset;
00146 }
00147
00148 bool KoParameterShape::isParametricShape() const
00149 {
00150 Q_D(const KoParameterShape);
00151 return !d->modified;
00152 }
00153
00154 void KoParameterShape::setModified(bool modified)
00155 {
00156 Q_D(KoParameterShape);
00157 d->modified = modified;
00158 update();
00159 }
|