Fix QGIVImage positioning/rotation

This commit is contained in:
WandererFan
2017-10-23 20:02:45 -04:00
parent 3b8c240f89
commit d832eb55c9
4 changed files with 26 additions and 30 deletions

View File

@@ -35,7 +35,6 @@
#include <Base/Console.h>
#include <Base/Parameter.h>
#include <qmath.h>
#include "QGCustomClip.h"
using namespace TechDrawGui;
@@ -53,12 +52,7 @@ QGCustomClip::QGCustomClip()
void QGCustomClip::centerAt(QPointF centerPos)
{
QRectF box = boundingRect();
double width = box.width();
double height = box.height();
double newX = centerPos.x() - width/2.;
double newY = centerPos.y() - height/2.;
setPos(newX,newY);
centerAt(centerPos.x(),centerPos.y());
}
void QGCustomClip::centerAt(double cX, double cY)
@@ -83,7 +77,6 @@ void QGCustomClip::setRect(double x, double y, double w, double h)
setRect(r);
}
QRectF QGCustomClip::rect()
{
return m_rect;
@@ -93,6 +86,8 @@ void QGCustomClip::paint ( QPainter * painter, const QStyleOptionGraphicsItem *
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
// painter->drawRect(boundingRect()); //good for debugging
QGraphicsItemGroup::paint (painter, &myOption, widget);
}

View File

@@ -31,6 +31,7 @@
#include <QRectF>
#include <QPixmap>
#include "QGCustomImage.h"
using namespace TechDrawGui;
@@ -55,20 +56,12 @@ void QGCustomImage::centerAt(QPointF centerPos)
void QGCustomImage::centerAt(double cX, double cY)
{
// QGraphicsItemGroup* g = group();
// if (g == nullptr) {
// return;
// }
QPointF parentPt(cX,cY);
QPointF myPt = mapFromParent(parentPt);
QRectF br = boundingRect();
double width = br.width();
double height = br.height();
double newX = width/2.0;
double newY = height/2.0;
QPointF off(myPt.x() - newX,myPt.y() - newY);
setOffset(off);
double width = br.width() * scale();
double height = br.height() * scale();
double newX = cX - width/2.;
double newY = cY - height/2.;
setPos(newX, newY);
}
bool QGCustomImage::load(QString fileSpec)
@@ -76,9 +69,6 @@ bool QGCustomImage::load(QString fileSpec)
bool success = true;
QPixmap px(fileSpec);
m_px = px;
// if (m_px.isNull()) {
// Base::Console().Message("TRACE - QGCustomImage::load - pixmap no good\n");
// }
prepareGeometryChange();
setPixmap(m_px);
return(success);
@@ -88,5 +78,8 @@ void QGCustomImage::paint ( QPainter * painter, const QStyleOptionGraphicsItem *
QStyleOptionGraphicsItem myOption(*option);
myOption.state &= ~QStyle::State_Selected;
//painter->drawRect(boundingRect()); //good for debugging
QGraphicsPixmapItem::paint (painter, &myOption, widget);
}

View File

@@ -61,13 +61,13 @@ QGIViewImage::QGIViewImage()
m_cliparea = new QGCustomClip();
addToGroup(m_cliparea);
m_cliparea->setPos(0.,0.);
m_cliparea->setRect(0.,0.,5.,5.);
m_cliparea->centerAt(0.,0.);
m_imageItem = new QGCustomImage();
m_imageItem->setTransformationMode(Qt::SmoothTransformation);
m_cliparea->addToGroup(m_imageItem);
m_imageItem->setPos(0.,0.);
m_imageItem->centerAt(0.,0.);
}
QGIViewImage::~QGIViewImage()
@@ -117,11 +117,10 @@ void QGIViewImage::draw()
auto viewImage( dynamic_cast<TechDraw::DrawViewImage*>(getViewObject()) );
if (!viewImage)
return;
QRectF newRect(0.0,0.0,Rez::guiX(viewImage->Width.getValue()),Rez::guiX(viewImage->Height.getValue()));
double pad = Rez::guiX(1.0);
m_cliparea->setRect(newRect.adjusted(-pad,-pad,pad,pad));
QRectF newRect(0.0,0.0,viewImage->Width.getValue(),viewImage->Height.getValue());
m_cliparea->setRect(newRect);
drawImage();
m_cliparea->centerAt(0.0,0.0);
if (borderVisible) {
drawBorder();
}
@@ -146,4 +145,12 @@ void QGIViewImage::drawImage()
}
}
void QGIViewImage::rotateView(void)
{
QRectF r = m_cliparea->boundingRect();
m_cliparea->setTransformOriginPoint(r.center());
double rot = getViewObject()->Rotation.getValue();
m_cliparea->setRotation(-rot);
}

View File

@@ -51,6 +51,7 @@ public:
void setViewImageFeature(TechDraw::DrawViewImage *obj);
virtual void draw() override;
virtual void rotateView(void) override;
protected:
virtual void drawImage();