#include <QMouseEvent>
#include <Q3CanvasView>
#include <QPoint>
class MyCanvasView : public Q3CanvasView
{
Q_OBJECT
public:
MyCanvasView
( Q3Canvas
*c,
QWidget *parent
=0,
const char *name
=0, Qt
::WFlags f
=0 ) : Q3CanvasView
( c, parent, name, f
) {
dragging = 0;
wt=0;
}
protected:
{
wt=childAt(e->x(),e->y());
if(wt!=0 && e->button()==Qt::LeftButton)
{
wxoffset=(int)(e->x()- (wt->pos).x());//!not using currently
wyoffset=(int)(e->y()- (wt->pos).y());
}
}
{
if(wt!=0)
{
wt->move(e->x(),e->y());
}
}
{
if( wt!=0)
{
wt->move(e->x(),e->y());
wt=0;
}
}
{
Q3CanvasItemList il = canvas()->collisions( e->pos() );
for( Q3CanvasItemList::Iterator it=il.begin(); it!=il.end(); ++it )
{
if( (*it)->rtti() != Q3CanvasText::RTTI )
{
dragging = (*it);
xoffset = (int)(e->x() - dragging->x());
yoffset = (int)(e->y() - dragging->y());
return;
}
}
}
{
if( dragging )
{
dragging->setX( e->x() - xoffset );
dragging->setY( e->y() - yoffset );
dragging = 0;
canvas()->update();
}
}
{
if( dragging )
{
dragging->setX( e->x() - xoffset );
dragging->setY( e->y() - yoffset );
canvas()->update();
}
}
private:
Q3CanvasItem *dragging;
int xoffset, yoffset;
int wxoffset,wyoffset;
};
#include <QMouseEvent>
#include <Q3CanvasView>
#include <QPoint>
class MyCanvasView : public Q3CanvasView
{
Q_OBJECT
public:
MyCanvasView( Q3Canvas *c, QWidget *parent=0, const char *name=0, Qt::WFlags f=0 ) : Q3CanvasView( c, parent, name, f )
{
dragging = 0;
wt=0;
}
protected:
void mousePressEvent(QMouseEvent *e)
{
wt=childAt(e->x(),e->y());
if(wt!=0 && e->button()==Qt::LeftButton)
{
wxoffset=(int)(e->x()- (wt->pos).x());//!not using currently
wyoffset=(int)(e->y()- (wt->pos).y());
}
}
void mouseMoveEvent(QMouseEvent *e)
{
if(wt!=0)
{
wt->move(e->x(),e->y());
}
}
void mouseReleaseEvent(QMouseEvent *e)
{
if( wt!=0)
{
wt->move(e->x(),e->y());
wt=0;
}
}
void contentsMousePressEvent( QMouseEvent *e )
{
Q3CanvasItemList il = canvas()->collisions( e->pos() );
for( Q3CanvasItemList::Iterator it=il.begin(); it!=il.end(); ++it )
{
if( (*it)->rtti() != Q3CanvasText::RTTI )
{
dragging = (*it);
xoffset = (int)(e->x() - dragging->x());
yoffset = (int)(e->y() - dragging->y());
return;
}
}
}
void contentsMouseReleaseEvent( QMouseEvent *e )
{
if( dragging )
{
dragging->setX( e->x() - xoffset );
dragging->setY( e->y() - yoffset );
dragging = 0;
canvas()->update();
}
}
void contentsMouseMoveEvent( QMouseEvent *e )
{
if( dragging )
{
dragging->setX( e->x() - xoffset );
dragging->setY( e->y() - yoffset );
canvas()->update();
}
}
private:
QWidget *wt;
Q3CanvasItem *dragging;
int xoffset, yoffset;
int wxoffset,wyoffset;
};
To copy to clipboard, switch view to plain text mode
Bookmarks