Skip to content

Commit

Permalink
Scaling using the ScaleHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
hrobeers committed Nov 4, 2013
1 parent 6452223 commit cd40a0c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
28 changes: 26 additions & 2 deletions src/patheditor/scalableimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
****************************************************************************/

#include "scalableimage.h"
#include "pathsettings.h"
#include <QPainter>
#include <QGraphicsScene>
#include "qmath.h"
#include "pathsettings.h"
#include "linerestrictor.h"

using namespace patheditor;

Expand All @@ -45,6 +47,14 @@ ScalableImage::ScalableImage(const QPixmap &pixmap, const QRect &initialRect, QG

PathSettings settings = PathSettings::Default();
_scalePoint->createPointHandle(settings, this);

connect(_scalePoint.data(), SIGNAL(pointDrag(PathPoint*)), this, SLOT(onScaleMove(PathPoint*)));
connect(_scalePoint.data(), SIGNAL(pointRelease(PathPoint*)), this, SLOT(onScaleMove(PathPoint*)));

QPointF botLeft(_rect.bottomLeft());
QPointF topRight(_rect.topRight());
QSharedPointer<LineRestrictor> restrictor(new LineRestrictor(botLeft, topRight));
_scalePoint->setRestrictor(restrictor);
}

void ScalableImage::paint(QPainter *painter, const QStyleOptionGraphicsItem */*unused*/, QWidget */*unused*/)
Expand All @@ -54,9 +64,23 @@ void ScalableImage::paint(QPainter *painter, const QStyleOptionGraphicsItem */*u

QRectF ScalableImage::boundingRect() const
{
return QRectF(_rect);
return QRectF(_rect) | _scalePoint.data()->handle()->boundingRect();
}

ScalableImage::~ScalableImage()
{
}

void ScalableImage::onScaleMove(PathPoint *point)
{
QRect oldRect = _rect;

QPointF relativePnt = *point - _rect.bottomLeft();

_rect.setHeight(-relativePnt.y());
_rect.setWidth(relativePnt.x());

_rect.moveBottomLeft(oldRect.bottomLeft());

this->scene()->update();
}
3 changes: 3 additions & 0 deletions src/patheditor/scalableimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace patheditor
QPixmap _pixmap;
QRect _rect;
QScopedPointer<ScalePoint> _scalePoint;

private slots:
void onScaleMove(PathPoint *point);
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/version_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef VERSION_AUTOGEN_H
#define VERSION_AUTOGEN_H

#define BUILD_NUMBER 229
#define COMMIT_HASH "86e1d99c2a11ea74a05499951e9512cceb302dac"
#define BUILD_NUMBER 230
#define COMMIT_HASH "645222332ebd341a19835353dffa7324d691f6cd"

#endif // VERSION_AUTOGEN_H

0 comments on commit cd40a0c

Please sign in to comment.