Fix QGIVImage positioning/rotation
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ public:
|
||||
void setViewImageFeature(TechDraw::DrawViewImage *obj);
|
||||
|
||||
virtual void draw() override;
|
||||
virtual void rotateView(void) override;
|
||||
|
||||
protected:
|
||||
virtual void drawImage();
|
||||
|
||||
Reference in New Issue
Block a user