Warning, file /office/calligra/libs/flake/KoParameterShape.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002    Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
0003    Copyright (C) 2007, 2009 Thomas Zander <zander@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "KoParameterShape.h"
0022 #include "KoParameterShape_p.h"
0023 
0024 #include <QPainter>
0025 #include <FlakeDebug.h>
0026 
0027 KoParameterShape::KoParameterShape()
0028     : KoPathShape(*(new KoParameterShapePrivate(this)))
0029 {
0030 }
0031 
0032 KoParameterShape::KoParameterShape(KoParameterShapePrivate &dd)
0033     : KoPathShape(dd)
0034 {
0035 }
0036 
0037 KoParameterShape::~KoParameterShape()
0038 {
0039 }
0040 
0041 void KoParameterShape::moveHandle(int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers)
0042 {
0043     Q_D(KoParameterShape);
0044     if (handleId >= d->handles.size()) {
0045         warnFlake << "handleId out of bounds";
0046         return;
0047     }
0048 
0049     update();
0050     // function to do special stuff
0051     moveHandleAction(handleId, documentToShape(point), modifiers);
0052 
0053     updatePath(size());
0054     update();
0055     d->shapeChanged(ParameterChanged);
0056 }
0057 
0058 
0059 int KoParameterShape::handleIdAt(const QRectF & rect) const
0060 {
0061     Q_D(const KoParameterShape);
0062     int handle = -1;
0063 
0064     for (int i = 0; i < d->handles.size(); ++i) {
0065         if (rect.contains(d->handles.at(i))) {
0066             handle = i;
0067             break;
0068         }
0069     }
0070     return handle;
0071 }
0072 
0073 QPointF KoParameterShape::handlePosition(int handleId) const
0074 {
0075     Q_D(const KoParameterShape);
0076     return d->handles.value(handleId);
0077 }
0078 
0079 void KoParameterShape::paintHandles(QPainter & painter, const KoViewConverter & converter, int handleRadius)
0080 {
0081     Q_D(KoParameterShape);
0082     applyConversion(painter, converter);
0083 
0084     QTransform worldMatrix = painter.worldTransform();
0085     painter.setTransform(QTransform());
0086 
0087     QTransform matrix;
0088     matrix.rotate(45.0);
0089     QPolygonF poly(d->handleRect(QPointF(0, 0), handleRadius));
0090     poly = matrix.map(poly);
0091 
0092     // There exists a problem on msvc with for(each) and QVector<QPointF>
0093     for (int i = 0; i < d->handles.count(); ++i) {
0094         const QPointF moveVector = worldMatrix.map(d->handles[i]);
0095         poly.translate(moveVector.x(), moveVector.y());
0096         painter.drawPolygon(poly);
0097         poly.translate(-moveVector.x(), -moveVector.y());
0098     }
0099 }
0100 
0101 void KoParameterShape::paintHandle(QPainter & painter, const KoViewConverter & converter, int handleId, int handleRadius)
0102 {
0103     Q_D(KoParameterShape);
0104     applyConversion(painter, converter);
0105 
0106     QTransform worldMatrix = painter.worldTransform();
0107     painter.setTransform(QTransform());
0108 
0109     QTransform matrix;
0110     matrix.rotate(45.0);
0111     QPolygonF poly(d->handleRect(QPointF(0, 0), handleRadius));
0112     poly = matrix.map(poly);
0113     poly.translate(worldMatrix.map(d->handles[handleId]));
0114     painter.drawPolygon(poly);
0115 }
0116 
0117 void KoParameterShape::setSize(const QSizeF &newSize)
0118 {
0119     Q_D(KoParameterShape);
0120     QTransform matrix(resizeMatrix(newSize));
0121 
0122     for (int i = 0; i < d->handles.size(); ++i) {
0123         d->handles[i] = matrix.map(d->handles[i]);
0124     }
0125 
0126     KoPathShape::setSize(newSize);
0127 }
0128 
0129 QPointF KoParameterShape::normalize()
0130 {
0131     Q_D(KoParameterShape);
0132     QPointF offset(KoPathShape::normalize());
0133     QTransform matrix;
0134     matrix.translate(-offset.x(), -offset.y());
0135 
0136     for (int i = 0; i < d->handles.size(); ++i) {
0137         d->handles[i] = matrix.map(d->handles[i]);
0138     }
0139 
0140     return offset;
0141 }
0142 
0143 bool KoParameterShape::isParametricShape() const
0144 {
0145     Q_D(const KoParameterShape);
0146     return d->parametric;
0147 }
0148 
0149 void KoParameterShape::setParametricShape(bool parametric)
0150 {
0151     Q_D(KoParameterShape);
0152     d->parametric = parametric;
0153     update();
0154 }
0155 
0156 QVector<QPointF> KoParameterShape::handles() const
0157 {
0158     Q_D(const KoParameterShape);
0159     return d->handles;
0160 }
0161 
0162 void KoParameterShape::setHandles(const QVector<QPointF> &handles)
0163 {
0164     Q_D(KoParameterShape);
0165     d->handles = handles;
0166 }
0167 
0168 int KoParameterShape::handleCount() const
0169 {
0170     Q_D(const KoParameterShape);
0171     return d->handles.count();
0172 }