Biomedical Image Analysis Library
The Biomedical Image Analysis Library is a poweful tool for developers, physicians, researchers, engineers, and so on.
graphicsitem.cpp
Go to the documentation of this file.
1 #include <QtWidgets>
2 
3 #include "graphicsitem.h"
4 
5 /* GraphicsItem::GraphicsItem(QPixmap pix, QString file) : QGraphicsItem(), pix(pix), file(file) { */
6 GraphicsItem::GraphicsItem( QString name, QPixmap pix, QFileInfo file ) : QGraphicsObject( ), pix( pix ), file( file ) {
7  setCursor( Qt::OpenHandCursor );
8  setObjectName( name );
9 }
10 
11 QRectF GraphicsItem::boundingRect( ) const {
12  return( pix.rect( ) );
13 }
14 
15 void GraphicsItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget ) {
16  Q_UNUSED( option )
17  Q_UNUSED( widget )
18  painter->drawPixmap( pix.rect( ), pix );
19 }
20 
21 void GraphicsItem::mousePressEvent( QGraphicsSceneMouseEvent *event ) {
22  Q_UNUSED( event )
23  emit Image( pix2, file );
24  /* setCursor(Qt::OpenHandCursor); */
25 }
26 
27 void GraphicsItem::mouseMoveEvent( QGraphicsSceneMouseEvent *event ) {
28  /*
29  * qDebug() << "move";
30  * setCursor(Qt::ClosedHandCursor);
31  * qDebug() << "press";
32  */
33  if( QLineF( event->screenPos( ), event->buttonDownScreenPos( Qt::LeftButton ) ).length( ) <
34  QApplication::startDragDistance( ) ) {
35  return;
36  }
37  /* QByteArray itemData; */
38  qDebug( ) << objectName( );
39  QDrag *drag = new QDrag( event->widget( ) );
40  QMimeData *mime = new QMimeData;
41  /* mime->setData("application/x-imagedata", itemData); */
42  mime->setText( objectName( ) );
43  /* mime->setImageData(pix); */
44  drag->setMimeData( mime );
45  drag->setPixmap( pix.scaledToWidth( 100 ) );
46  /* drag->setHotSpot(event->scenePos()); */
47  drag->exec( Qt::CopyAction, Qt::CopyAction );
48 }
49 
50 void GraphicsItem::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) {
51  Q_UNUSED( event )
52  /* qDebug() << "release"; */
53  setCursor( Qt::OpenHandCursor );
54 }
55 
56 QPixmap GraphicsItem::getPix2( ) const {
57  return( pix2 );
58 }
59 
60 void GraphicsItem::setPix2( const QPixmap &value ) {
61  pix2 = value;
62 }
63 
64 QFileInfo GraphicsItem::fileInfo( ) const {
65  return( file );
66 }
67 
68 QPixmap GraphicsItem::pixmap( ) const {
69  return( pix );
70 }
GraphicsItem(QString name, QPixmap pix, QFileInfo file)
Definition: graphicsitem.cpp:6
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
QPixmap getPix2() const
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
void setPix2(const QPixmap &value)
virtual QRectF boundingRect() const Q_DECL_OVERRIDE
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE
QPixmap pixmap() const
Definition: gzappend.c:170
void Image(const QPixmap &, const QFileInfo &)
QFileInfo fileInfo() const