#include "StdAfx.h"
#include "SelectionHandle.h"
#include "DrawingObject.h"
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QApplication>
CSelectionHandle
::CSelectionHandle(qreal x, qreal y,
int handleId, CDrawingObject
* pParent,
QGraphicsItem* pGraphicsParent
): m_pParent(pParent), m_pGraphicsParent(pGraphicsParent)
{
Q_ASSERT(pParent != NULL);
Q_ASSERT(pGraphicsParent != NULL);
m_Id = handleId;
m_bHandleMoving = false;
// Create the graphics object for the handle
setRect(x-2, y-2, 4, 4);
pParent->m_pScene->addItem(this);
setParentItem(pGraphicsParent);
}
CSelectionHandle::~CSelectionHandle(void)
{
}
{
m_bHandleMoving = true;
}
{
if (m_bHandleMoving)
{
QPointF eventPos, eventParentPos, eventScenePos;
eventPos = event->pos();
eventParentPos = mapToParent(eventPos);
eventScenePos = mapToScene(eventPos);
prepareGeometryChange();
setPos(eventParentPos);
m_pParent->MoveHandle(m_Id, eventParentPos);
}
else
{
}
}
{
m_bHandleMoving = false;
}
#include "StdAfx.h"
#include "SelectionHandle.h"
#include "DrawingObject.h"
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QApplication>
CSelectionHandle::CSelectionHandle(qreal x, qreal y, int handleId, CDrawingObject* pParent, QGraphicsItem* pGraphicsParent)
: m_pParent(pParent), m_pGraphicsParent(pGraphicsParent)
{
Q_ASSERT(pParent != NULL);
Q_ASSERT(pGraphicsParent != NULL);
m_Id = handleId;
m_bHandleMoving = false;
// Create the graphics object for the handle
setRect(x-2, y-2, 4, 4);
pParent->m_pScene->addItem(this);
setBrush(QBrush(QColor("black")));
setParentItem(pGraphicsParent);
}
CSelectionHandle::~CSelectionHandle(void)
{
}
void CSelectionHandle::mousePressEvent( QGraphicsSceneMouseEvent *event )
{
m_bHandleMoving = true;
}
void CSelectionHandle::mouseMoveEvent( QGraphicsSceneMouseEvent *event )
{
QGraphicsItem::mouseMoveEvent(event);
if (m_bHandleMoving)
{
QPointF itemPos = pos();
QPointF eventPos, eventParentPos, eventScenePos;
eventPos = event->pos();
eventParentPos = mapToParent(eventPos);
eventScenePos = mapToScene(eventPos);
prepareGeometryChange();
setPos(eventParentPos);
m_pParent->MoveHandle(m_Id, eventParentPos);
}
else
{
QApplication::beep();
}
}
void CSelectionHandle::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
{
m_bHandleMoving = false;
}
To copy to clipboard, switch view to plain text mode
Bookmarks