-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ScalableImage initializes image to given QRect
- Loading branch information
Showing
11 changed files
with
225 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/**************************************************************************** | ||
Copyright (c) 2013, Hans Robeers | ||
All rights reserved. | ||
BSD 2-Clause License | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
****************************************************************************/ | ||
|
||
#include "scalableimage.h" | ||
#include "pathsettings.h" | ||
#include <QPainter> | ||
#include "qmath.h" | ||
|
||
using namespace patheditor; | ||
|
||
ScalableImage::ScalableImage(const QPixmap &pixmap, const QRect &initialRect, QGraphicsItem *parent) : | ||
QGraphicsObject(parent) | ||
{ | ||
_pixmap = pixmap; | ||
_rect = initialRect; | ||
|
||
qreal imageAR = (qreal)pixmap.height() / (qreal)pixmap.width(); | ||
qreal rectAR = (qreal)_rect.height() / (qreal)_rect.width(); | ||
if (imageAR > rectAR) | ||
_rect.setWidth(_rect.height() / imageAR); | ||
else | ||
_rect.setHeight(_rect.width() * imageAR); | ||
|
||
|
||
_scalePoint.reset(new ScalePoint(_rect.topRight().x(), _rect.topRight().y())); | ||
|
||
PathSettings settings = PathSettings::Default(); | ||
_scalePoint->createPointHandle(settings, this); | ||
} | ||
|
||
void ScalableImage::paint(QPainter *painter, const QStyleOptionGraphicsItem */*unused*/, QWidget */*unused*/) | ||
{ | ||
painter->drawPixmap(_rect, _pixmap); | ||
} | ||
|
||
QRectF ScalableImage::boundingRect() const | ||
{ | ||
return QRectF(_rect); | ||
} | ||
|
||
ScalableImage::~ScalableImage() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/**************************************************************************** | ||
Copyright (c) 2013, Hans Robeers | ||
All rights reserved. | ||
BSD 2-Clause License | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
****************************************************************************/ | ||
|
||
#ifndef SCALABLEIMAGE_H | ||
#define SCALABLEIMAGE_H | ||
|
||
#include <QGraphicsObject> | ||
#include "scalepoint.h" | ||
|
||
namespace patheditor | ||
{ | ||
class ScalableImage : public QGraphicsObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit ScalableImage(const QPixmap &pixmap, const QRect &initialRect, QGraphicsItem *parent = 0); | ||
|
||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | ||
virtual QRectF boundingRect() const; | ||
|
||
virtual ~ScalableImage(); | ||
|
||
signals: | ||
|
||
public slots: | ||
|
||
private: | ||
QPixmap _pixmap; | ||
QRect _rect; | ||
QScopedPointer<ScalePoint> _scalePoint; | ||
}; | ||
} | ||
|
||
#endif // SCALABLEIMAGE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/**************************************************************************** | ||
Copyright (c) 2013, Hans Robeers | ||
All rights reserved. | ||
BSD 2-Clause License | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
****************************************************************************/ | ||
|
||
#include "scalepoint.h" | ||
#include "pathsettings.h" | ||
|
||
using namespace patheditor; | ||
|
||
ScalePoint::ScalePoint(qreal xpos, qreal ypos) : | ||
PathPoint(xpos, ypos) | ||
{ | ||
} | ||
|
||
void ScalePoint::createPointHandle(PathSettings &settings, QGraphicsItem *parent) | ||
{ | ||
PointHandle *newPointHandle = new PointHandle(this, settings.handleSize(), settings.scalePointBrush(), parent); | ||
newPointHandle->setZValue(1); | ||
replaceCurrentPointHandle(newPointHandle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/**************************************************************************** | ||
Copyright (c) 2013, Hans Robeers | ||
All rights reserved. | ||
BSD 2-Clause License | ||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
****************************************************************************/ | ||
|
||
#ifndef SCALEPOINT_H | ||
#define SCALEPOINT_H | ||
|
||
#include "pathpoint.h" | ||
|
||
namespace patheditor | ||
{ | ||
class ScalePoint : public PathPoint | ||
{ | ||
public: | ||
explicit ScalePoint(qreal xpos, qreal ypos); | ||
|
||
virtual void createPointHandle(PathSettings &settings, QGraphicsItem *parent); | ||
|
||
virtual ~ScalePoint() {} | ||
}; | ||
} | ||
|
||
#endif // SCALEPOINT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters