I tried to debug further but some things i get are just strange. I can't figure out why this happens:
ORIG TOP LEFT 0 ORIG BOTTOM RIGHT QPointF(450,292)
ORIG TOP LEFT 0 ORIG BOTTOM RIGHT QPointF(450,292)
ORIG TOP LEFT 0 ORIG BOTTOM RIGHT QPointF(450,250)
ORIG TOP LEFT nan ORIG BOTTOM RIGHT QPointF(450,250)
ORIG TOP LEFT nan ORIG BOTTOM RIGHT QPointF(450,250)
ORIG TOP LEFT nan ORIG BOTTOM RIGHT QPointF(450,250)
ORIG TOP LEFT nan ORIG BOTTOM RIGHT QPointF(450,250)
ORIG TOP LEFT nan ORIG BOTTOM RIGHT QPointF(450,250)
Here is the code i get the debbug from:
#include "handleitem.h"
#include "resizablehandlerect.h"
#include <QGraphicsSceneMouseEvent>
#include <QDebug>
#include "resizablepixmapitem.h"
HandleItem::HandleItem(Position position) :
handlePosition(position)
{
setFlag(QGraphicsItem::ItemIsMovable);
}
void HandleItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
ResizableHandleRect *rectItem = dynamic_cast<ResizableHandleRect *>(parentItem());
if (!rectItem) {
return; // Wenn das Parent-Item kein ResizableHandleRect ist, beende die Funktion
}
QRectF boundingFrameRect = rectItem->selectorFrameBounds();
OriginTopLeft = mapToScene(boundingFrameRect.topLeft());
OriginBottomRight = mapToScene(boundingFrameRect.bottomRight());
QRectF SceneBoundingFrameRect(OriginTopLeft, OriginBottomRight);
qDebug() << "ORIG TOP LEFT" << OriginLeftCenter << "ORIG BOTTOM RIGHT" << OriginBottomRight;
OriginBottomCenter = SceneBoundingFrameRect.bottom();
OriginTopCenter = SceneBoundingFrameRect.top();
BottomCenterWasDragged = false;
TopCenterWasDragged = false;
}
void HandleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
ResizableHandleRect *rectItem = dynamic_cast<ResizableHandleRect *>(parentItem());
if (!rectItem) {
return; // Wenn das Parent-Item kein ResizableHandleRect ist, beende die Funktion
}
QRectF boundingFrameRect = rectItem->selectorFrameBounds();
QPointF topLeft = mapToScene(boundingFrameRect.topLeft());
QPointF bottomRight = mapToScene(boundingFrameRect.bottomRight());
QRectF SceneBoundingFrameRect(topLeft, bottomRight);
//qDebug() << "HandlePosition: " << handlePosition;
switch (handlePosition) {
case TopLeft:
break;
case TopCenter:
SceneBoundingFrameRect.setTop(event->scenePos().y());
if(SceneBoundingFrameRect.bottom() < SceneBoundingFrameRect.top() && BottomCenterWasDragged == false){
qDebug() << "-- (2)SWITCH Top to Bottom";
handlePosition = BottomCenter;
TopCenterWasDragged = true;
}
break;
case TopRight:
break;
case RightCenter:
break;
case BottomRight:
break;
case BottomCenter:
SceneBoundingFrameRect.setBottom(event->scenePos().y());
if(SceneBoundingFrameRect.bottom() < SceneBoundingFrameRect.top() && TopCenterWasDragged == false){
qDebug() << "(1)SWITCH Bottom to Top--";
handlePosition = TopCenter;
BottomCenterWasDragged = true;
}
break;
case BottomLeft:
break;
case LeftCenter:
break;
default:
break;
}
if(SceneBoundingFrameRect.topLeft() != OriginTopLeft && BottomCenterWasDragged == true){
SceneBoundingFrameRect.setTopLeft(OriginTopLeft);
BottomCenterWasDragged = false;
qDebug() << "(1*)Correct Top, Bottom was Dragged!" << SceneBoundingFrameRect.topLeft();
}
if(SceneBoundingFrameRect.bottomRight() != OriginBottomRight && TopCenterWasDragged == true){
SceneBoundingFrameRect.setBottomRight(OriginBottomRight);
TopCenterWasDragged = false;
qDebug() << "(2*)Correct Bottom, Top was Dragged!" << SceneBoundingFrameRect.bottomRight();
}
QPointF topLeft2 = mapFromScene(SceneBoundingFrameRect.topLeft());
QPointF bottomRight2 = mapFromScene(SceneBoundingFrameRect.bottomRight());
QRectF NEWBoundingFrameRect2(topLeft2, bottomRight2);
rectItem->setSelectorFrameBounds(NEWBoundingFrameRect2);