Biomedical Image Analysis Library
The Biomedical Image Analysis Library is a poweful tool for developers, physicians, researchers, engineers, and so on.
graphicsview.cpp
Go to the documentation of this file.
1 #include "graphicsview.h"
2 
3 #include <QDebug>
4 #include <QDropEvent>
5 #include <QFileInfo>
6 #include <QMimeData>
7 
8 GraphicsView::GraphicsView( QWidget *parent ) : QGraphicsView( parent ) {
9 }
10 
11 void GraphicsView::dragEnterEvent( QDragEnterEvent *event ) {
12  event->acceptProposedAction( );
13 }
14 
15 void GraphicsView::dragMoveEvent( QDragMoveEvent *event ) {
16  event->acceptProposedAction( );
17 }
18 
19 void GraphicsView::dragLeaveEvent( QDragLeaveEvent *event ) {
20  event->accept( );
21 }
22 
23 void GraphicsView::dropEvent( QDropEvent *event ) {
24  const QMimeData *mimeData = event->mimeData( );
25 
26  qDebug( ) << "mime: " << mimeData->text( );
27  if( mimeData->hasText( ) ) {
28  QString file = mimeData->text( ).remove( "file://" ).remove( "\r\n" );
29  qDebug( ) << "text: " << file;
30  QFileInfo info( file );
31  qDebug( ) << "file: " << info.isFile( );
32  qDebug( ) << "folder: " << info.isDir( );
33  qDebug( ) << "suffix: " << info.completeSuffix( );
34  if( objectName( ) == "graphicsViewOutput" ) {
35  emit saveFile( event->mimeData( )->text( ) );
36  return;
37  }
38  if( info.isFile( ) ) {
39  emit dropImage( file );
40  }
41  else if( info.isDir( ) ) {
42  emit dropFolder( file );
43  }
44  }
45 }
46 
47 void GraphicsView::resizeEvent( QResizeEvent *event ) {
48  if( fit ) {
49  fitInView( scene( )->itemsBoundingRect( ), Qt::KeepAspectRatio );
50  }
51  QGraphicsView::resizeEvent( event );
52 }
53 
54 bool GraphicsView::getFit( ) const {
55  return( fit );
56 }
57 
58 void GraphicsView::setFit( bool value ) {
59  fit = value;
60 }
virtual void dragLeaveEvent(QDragLeaveEvent *event) override
void saveFile(const QString &item)
void dropImage(const QString &filePath)
void setFit(bool value)
GraphicsView(QWidget *parent=0)
Definition: graphicsview.cpp:8
virtual void dropEvent(QDropEvent *event) override
virtual void dragEnterEvent(QDragEnterEvent *event) override
virtual void resizeEvent(QResizeEvent *event) override
bool getFit() const
Definition: gzappend.c:170
virtual void dragMoveEvent(QDragMoveEvent *event) override
void dropFolder(const QString &folderPath)