本文整理汇总了C++中KoPathPoint类的典型用法代码示例。如果您正苦于以下问题:C++ KoPathPoint类的具体用法?C++ KoPathPoint怎么用?C++ KoPathPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KoPathPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QLineF
void KarbonCalligraphicShape::addCap(int index1, int index2, int pointIndex,
bool inverted)
{
QPointF p1 = m_points[index1]->point();
QPointF p2 = m_points[index2]->point();
// TODO: review why spikes can appear with a lower limit
QPointF delta = p2 - p1;
if (delta.manhattanLength() < 1.0)
return;
QPointF direction = QLineF(QPointF(0, 0), delta).unitVector().p2();
qreal width = m_points[index2]->width();
QPointF p = p2 + direction * m_caps * width;
KoPathPoint * newPoint = new KoPathPoint(this, p);
qreal angle = m_points[index2]->angle();
if (inverted)
angle += M_PI;
qreal dx = std::cos(angle) * width;
qreal dy = std::sin(angle) * width;
newPoint->setControlPoint1(QPointF(p.x() - dx / 2, p.y() - dy / 2));
newPoint->setControlPoint2(QPointF(p.x() + dx / 2, p.y() + dy / 2));
insertPoint(newPoint, KoPathPointIndex(0, pointIndex));
}
示例2: KoPathPointIndex
QList<KoSubpath *> KarbonSimplifyPath::split( const KoPathShape &path )
{
QList<KoSubpath *> res;
KoSubpath *subpath = new KoSubpath;
res.append( subpath );
for ( int i = 0; i < path.pointCount(); ++i )
{
KoPathPoint *p = path.pointByIndex( KoPathPointIndex(0, i) );
// if the path separates two subpaths
// (if it isn't smooth nor the first or last point)
if ( i != 0 && i != path.pointCount()-1 )
{
KoPathPoint *prev = path.pointByIndex( KoPathPointIndex(0, i-1) );
KoPathPoint *next = path.pointByIndex( KoPathPointIndex(0, i+1) );
if ( ! p->isSmooth(prev, next) )
{
// create a new subpath
subpath->append( new KoPathPoint(*p) );
subpath = new KoSubpath;
res.append( subpath );
}
}
subpath->append( new KoPathPoint(*p) );
}
return res;
}
示例3: KUndo2Command
KoPathSegmentBreakCommand::KoPathSegmentBreakCommand(const KoPathPointData & pointData, KUndo2Command *parent)
: KUndo2Command(parent)
, m_pointData(pointData)
, m_startIndex(-1, -1)
, m_broken(false)
{
if (m_pointData.pathShape->isClosedSubpath(m_pointData.pointIndex.first)) {
m_startIndex = m_pointData.pointIndex;
KoPathPoint * before = m_pointData.pathShape->pointByIndex(m_startIndex);
if (before->properties() & KoPathPoint::CloseSubpath) {
m_startIndex.second = 0;
} else {
++m_startIndex.second;
}
}
setText(QObject::tr("Break subpath"));
}
示例4: KUndo2Command
KoPathControlPointMoveCommand::KoPathControlPointMoveCommand(
const KoPathPointData &pointData,
const QPointF &offset,
KoPathPoint::PointType pointType,
KUndo2Command *parent)
: KUndo2Command(parent)
, m_pointData(pointData)
, m_pointType(pointType)
{
Q_ASSERT(offset.x() < 1e14 && offset.y() < 1e14);
KoPathShape * pathShape = m_pointData.pathShape;
KoPathPoint * point = pathShape->pointByIndex(m_pointData.pointIndex);
if (point) {
m_offset = point->parent()->documentToShape(offset) - point->parent()->documentToShape(QPointF(0, 0));
}
setText(i18nc("(qtundo-format)", "Move control point"));
}
示例5: KoPathPoint
void RoundCornersCommand::copyPath(KoPathShape * dst, KoPathShape * src)
{
dst->clear();
int subpathCount = src->subpathCount();
for (int subpathIndex = 0; subpathIndex < subpathCount; ++subpathIndex) {
int pointCount = src->subpathPointCount(subpathIndex);
if (! pointCount)
continue;
KoSubpath * subpath = new KoSubpath;
for (int pointIndex = 0; pointIndex < pointCount; ++pointIndex) {
KoPathPoint * p = src->pointByIndex(KoPathPointIndex(subpathIndex, pointIndex));
KoPathPoint * c = new KoPathPoint(*p);
c->setParent(dst);
subpath->append(c);
}
dst->addSubpath(subpath, subpathIndex);
}
dst->setTransformation(src->transformation());
}
示例6: QLineF
void KarbonCalligraphicShape::addCap(int index1, int index2, int pointIndex,
bool inverted)
{
QPointF p1 = m_points[index1]->point();
QPointF p2 = m_points[index2]->point();
qreal width = m_points[index2]->width();
QPointF direction = QLineF(QPointF(0, 0), p2 - p1).unitVector().p2();
QPointF p = p2 + direction * m_caps * width;
KoPathPoint * newPoint = new KoPathPoint(this, p);
qreal angle = m_points[index2]->angle();
if (inverted)
angle += M_PI;
qreal dx = std::cos(angle) * width;
qreal dy = std::sin(angle) * width;
newPoint->setControlPoint1(QPointF(p.x() - dx / 2, p.y() - dy / 2));
newPoint->setControlPoint2(QPointF(p.x() + dx / 2, p.y() + dy / 2));
insertPoint(newPoint, KoPathPointIndex(0, pointIndex));
}
示例7: Q_D
void KoCreatePathTool::mouseReleaseEvent(KoPointerEvent *event)
{
Q_D(KoCreatePathTool);
if (! d->shape || (event->buttons() & Qt::RightButton))
return;
d->listeningToModifiers = true; // After the first press-and-release
d->repaintActivePoint();
d->pointIsDragged = false;
KoPathPoint *lastActivePoint = d->activePoint;
if (!d->finishAfterThisPoint) {
d->activePoint = d->shape->lineTo(event->point);
canvas()->snapGuide()->setIgnoredPathPoints((QList<KoPathPoint*>()<<d->activePoint));
}
// apply symmetric point property if applicable
if (lastActivePoint->activeControlPoint1() && lastActivePoint->activeControlPoint2()) {
QPointF diff1 = lastActivePoint->point() - lastActivePoint->controlPoint1();
QPointF diff2 = lastActivePoint->controlPoint2() - lastActivePoint->point();
if (qFuzzyCompare(diff1.x(), diff2.x()) && qFuzzyCompare(diff1.y(), diff2.y()))
lastActivePoint->setProperty(KoPathPoint::IsSymmetric);
}
if (d->finishAfterThisPoint) {
d->firstPoint->setControlPoint1(d->activePoint->controlPoint1());
delete d->shape->removePoint(d->shape->pathPointIndex(d->activePoint));
d->activePoint = d->firstPoint;
d->shape->closeMerge();
// we are closing the path, so reset the existing start path point
d->existingStartPoint = 0;
// finish path
endPath();
}
if (d->angleSnapStrategy && lastActivePoint->activeControlPoint2()) {
d->angleSnapStrategy->deactivate();
}
}
示例8: KoPathPointIndex
void KarbonWhirlPinchCommand::redo()
{
d->pathShape->update();
uint subpathCount = d->pathData.count();
for( uint subpathIndex = 0; subpathIndex < subpathCount; ++subpathIndex )
{
uint pointCount = d->pathData[subpathIndex].count();
for( uint pointIndex = 0; pointIndex < pointCount; ++pointIndex )
{
KoPathPoint * p = d->pathShape->pointByIndex( KoPathPointIndex( subpathIndex, pointIndex ) );
p->setPoint( d->whirlPinch( p->point() ) );
if( p->activeControlPoint1() )
p->setControlPoint1( d->whirlPinch( p->controlPoint1() ) );
if( p->activeControlPoint2() )
p->setControlPoint2( d->whirlPinch( p->controlPoint2() ) );
}
}
d->pathShape->normalize();
d->pathShape->update();
QUndoCommand::redo();
}
示例9: removeDuplicates
void KarbonSimplifyPath::removeDuplicates(KoPathShape *path)
{
// NOTE: works because path has only has one subshape, if this ever moves in
// KoPathPoint it should be changed
for (int i = 1; i < path->pointCount(); ++i) {
KoPathPoint *p = path->pointByIndex(KoPathPointIndex(0, i));
KoPathPoint *prev = path->pointByIndex(KoPathPointIndex(0, i - 1));
QPointF diff = p->point() - prev->point();
// if diff = 0 remove point
if (qFuzzyCompare(diff.x() + 1, 1) && qFuzzyCompare(diff.y() + 1, 1)) {
if (prev->activeControlPoint1())
p->setControlPoint1(prev->controlPoint1());
else
p->removeControlPoint1();
delete path->removePoint(KoPathPointIndex(0, i - 1));
--i;
}
}
}
示例10: appendPointData
bool KoPathPointTypeCommand::appendPointData(KoPathPointData data)
{
KoPathPoint *point = data.pathShape->pointByIndex(data.pointIndex);
if (! point)
return false;
PointData pointData(data);
pointData.m_oldControlPoint1 = data.pathShape->shapeToDocument(point->controlPoint1());
pointData.m_oldControlPoint2 = data.pathShape->shapeToDocument(point->controlPoint2());
pointData.m_oldProperties = point->properties();
pointData.m_hadControlPoint1 = point->activeControlPoint1();
pointData.m_hadControlPoint2 = point->activeControlPoint2();
m_additionalPointData.append(pointData);
return true;
}
示例11: it
void KoPathPointTypeCommand::undoChanges(const QList<PointData> &data)
{
QList<PointData>::const_iterator it(data.begin());
for (; it != data.end(); ++it) {
KoPathShape *pathShape = it->m_pointData.pathShape;
KoPathPoint *point = pathShape->pointByIndex(it->m_pointData.pointIndex);
point->setProperties(it->m_oldProperties);
if (it->m_hadControlPoint1)
point->setControlPoint1(pathShape->documentToShape(it->m_oldControlPoint1));
else
point->removeControlPoint1();
if (it->m_hadControlPoint2)
point->setControlPoint2(pathShape->documentToShape(it->m_oldControlPoint2));
else
point->removeControlPoint2();
}
}
示例12: KoPathBaseCommand
KoPathPointTypeCommand::KoPathPointTypeCommand(
const QList<KoPathPointData> & pointDataList,
PointType pointType,
KUndo2Command *parent)
: KoPathBaseCommand(parent)
, m_pointType(pointType)
{
QList<KoPathPointData>::const_iterator it(pointDataList.begin());
for (; it != pointDataList.end(); ++it) {
KoPathPoint *point = it->pathShape->pointByIndex(it->pointIndex);
if (point) {
PointData pointData(*it);
pointData.m_oldControlPoint1 = it->pathShape->shapeToDocument(point->controlPoint1());
pointData.m_oldControlPoint2 = it->pathShape->shapeToDocument(point->controlPoint2());
pointData.m_oldProperties = point->properties();
pointData.m_hadControlPoint1 = point->activeControlPoint1();
pointData.m_hadControlPoint2 = point->activeControlPoint2();
m_oldPointData.append(pointData);
m_shapes.insert(it->pathShape);
}
}
setText(QObject::tr("Set point type"));
}
示例13: appendPointToPath
void KarbonCalligraphicShape::
appendPointToPath(const KarbonCalligraphicPoint &p)
{
qreal dx = std::cos(p.angle()) * p.width();
qreal dy = std::sin(p.angle()) * p.width();
// find the outline points
QPointF p1 = p.point() - QPointF(dx / 2, dy / 2);
QPointF p2 = p.point() + QPointF(dx / 2, dy / 2);
if (pointCount() == 0) {
moveTo(p1);
lineTo(p2);
normalize();
return;
}
// pointCount > 0
bool flip = (pointCount() >= 2) ? flipDetected(p1, p2) : false;
// if there was a flip add additional points
if (flip) {
appendPointsToPathAux(p2, p1);
if (pointCount() > 4)
smoothLastPoints();
}
appendPointsToPathAux(p1, p2);
if (pointCount() > 4) {
smoothLastPoints();
if (flip) {
int index = pointCount() / 2;
// find the last two points
KoPathPoint *last1 = pointByIndex(KoPathPointIndex(0, index - 1));
KoPathPoint *last2 = pointByIndex(KoPathPointIndex(0, index));
last1->removeControlPoint1();
last1->removeControlPoint2();
last2->removeControlPoint1();
last2->removeControlPoint2();
m_lastWasFlip = true;
}
if (m_lastWasFlip) {
int index = pointCount() / 2;
// find the previous two points
KoPathPoint *prev1 = pointByIndex(KoPathPointIndex(0, index - 2));
KoPathPoint *prev2 = pointByIndex(KoPathPointIndex(0, index + 1));
prev1->removeControlPoint1();
prev1->removeControlPoint2();
prev2->removeControlPoint1();
prev2->removeControlPoint2();
if (! flip)
m_lastWasFlip = false;
}
}
normalize();
// add initial cap if it's the fourth added point
// this code is here because this function is called from different places
// pointCount() == 8 may causes crashes because it doesn't take possible
// flips into account
if (m_points.count() >= 4 && &p == m_points[3]) {
kDebug(38000) << "Adding caps!!!!!!!!!!!!!!!!" << m_points.count();
addCap(3, 0, 0, true);
// duplicate the last point to make the points remain "balanced"
// needed to keep all indexes code (else I would need to change
// everything in the code...)
KoPathPoint *last = pointByIndex(KoPathPointIndex(0, pointCount() - 1));
KoPathPoint *newPoint = new KoPathPoint(this, last->point());
insertPoint(newPoint, KoPathPointIndex(0, pointCount()));
close();
}
}
示例14: KoPathPointIndex
//.........这里部分代码省略.........
* | # /.1
* O--O------O--O O------O...
* 0 0
*
* 3) End
* ---
*
* path: new path:
*
* 2 4
* O--O------O--O 5 .O------O. 3
* | | / \
* 3 O O 1 6 O O 2
* | | 7 .\ /
* O--O------O--O ...O------O. 1
* 0 0
*/
// TODO: not sure if we should only touch flat segment joins as the original algorithm
m_path->clear();
int subpathCount = m_copy->subpathCount();
for( int subpathIndex = 0; subpathIndex < subpathCount; ++subpathIndex )
{
int pointCount = m_copy->pointCountSubpath( subpathIndex );
if( ! pointCount )
continue;
// check if we have sufficient number of points
if( pointCount < 3 )
{
// copy the only segment
KoPathSegment s = m_copy->segmentByIndex( KoPathPointIndex( subpathIndex, 0 ) );
m_path->moveTo( m_copy->pointByIndex( KoPathPointIndex( subpathIndex, 0 ) )->point() );
addSegment( m_path, s );
continue;
}
KoPathSegment prevSeg = m_copy->segmentByIndex( KoPathPointIndex( subpathIndex, pointCount-1 ) );
KoPathSegment nextSeg = m_copy->segmentByIndex( KoPathPointIndex( subpathIndex, 0 ) );
KoPathSegment lastSeg;
KoPathPoint * currPoint = nextSeg.first();
KoPathPoint * firstPoint = 0;
KoPathPoint * lastPoint = 0;
// check if first path point is a smooth join with the closing segment
bool firstPointIsCorner = m_copy->isClosedSubpath( subpathIndex )
&& ! currPoint->isSmooth( prevSeg.first(), nextSeg.second() );
// Begin: take care of the first path point
if( firstPointIsCorner )
{
// split the previous segment at length - radius
qreal prevLength = prevSeg.length();
qreal prevSplit = prevLength > m_radius ? prevSeg.paramAtLength( prevLength-m_radius ) : 0.5;
QPair<KoPathSegment,KoPathSegment> prevParts = prevSeg.splitAt( prevSplit );
// split the next segment at radius
qreal nextLength = nextSeg.length();
qreal nextSplit = nextLength > m_radius ? nextSeg.paramAtLength( m_radius ) : 0.5;
QPair<KoPathSegment,KoPathSegment> nextParts = nextSeg.splitAt( nextSplit );
// calculate smooth tangents
示例15: if
void KoPathControlPointMoveCommand::redo()
{
KUndo2Command::redo();
KoPathShape * pathShape = m_pointData.pathShape;
KoPathPoint * point = pathShape->pointByIndex(m_pointData.pointIndex);
if (point) {
pathShape->update();
if (m_pointType == KoPathPoint::ControlPoint1) {
point->setControlPoint1(point->controlPoint1() + m_offset);
if (point->properties() & KoPathPoint::IsSymmetric) {
// set the other control point so that it lies on the line between the moved
// control point and the point, with the same distance to the point as the moved point
point->setControlPoint2(2.0 * point->point() - point->controlPoint1());
} else if (point->properties() & KoPathPoint::IsSmooth) {
// move the other control point so that it lies on the line through point and control point
// keeping its distance to the point
QPointF direction = point->point() - point->controlPoint1();
direction /= sqrt(direction.x() * direction.x() + direction.y() * direction.y());
QPointF distance = point->point() - point->controlPoint2();
qreal length = sqrt(distance.x() * distance.x() + distance.y() * distance.y());
point->setControlPoint2(point->point() + length * direction);
}
} else if (m_pointType == KoPathPoint::ControlPoint2) {
point->setControlPoint2(point->controlPoint2() + m_offset);
if (point->properties() & KoPathPoint::IsSymmetric) {
// set the other control point so that it lies on the line between the moved
// control point and the point, with the same distance to the point as the moved point
point->setControlPoint1(2.0 * point->point() - point->controlPoint2());
} else if (point->properties() & KoPathPoint::IsSmooth) {
// move the other control point so that it lies on the line through point and control point
// keeping its distance to the point
QPointF direction = point->point() - point->controlPoint2();
direction /= sqrt(direction.x() * direction.x() + direction.y() * direction.y());
QPointF distance = point->point() - point->controlPoint1();
qreal length = sqrt(distance.x() * distance.x() + distance.y() * distance.y());
point->setControlPoint1(point->point() + length * direction);
}
}
pathShape->normalize();
pathShape->update();
}
}