00001 00002 #ifndef MAINDISPLAY_QT_C 00003 #define MAINDISPLAY_QT_C 00004 00005 00006 #include <QtGui/qboxlayout.h> 00007 00008 #include "NeovisionII/NeoAnnotate/MainDisplay.qt.H" 00009 00010 MainDisplay::MainDisplay(QWidget *parent) : 00011 QGraphicsView(parent) 00012 { 00013 //Create a new graphics scene which will handle all of our objects 00014 itsScene = new QGraphicsScene; 00015 setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); 00016 00017 //Create a new display widget to show our movie images 00018 itsImageDisplay = new ImageGraphicsItem; 00019 itsScene->addItem(itsImageDisplay); 00020 00021 //Set itsScene as the main scene for this viewer 00022 setScene(itsScene); 00023 00024 //Preload the cursors for our various mouse actions 00025 QPixmap editCursorBmp("src/NeovisionII/NeoAnnotate/icons/cursor-arrow.png"); 00026 itsEditCursor = QCursor(editCursorBmp, 7, 1); 00027 00028 QPixmap addCursorBmp("src/NeovisionII/NeoAnnotate/icons/cursor-add.png"); 00029 itsAddCursor = QCursor(addCursorBmp, 7, 1); 00030 00031 QPixmap remCursorBmp("src/NeovisionII/NeoAnnotate/icons/cursor-rem.png"); 00032 itsRemCursor = QCursor(remCursorBmp, 7, 1); 00033 00034 QPixmap rotCursorBmp("src/NeovisionII/NeoAnnotate/icons/rotate-icon.jpg"); 00035 itsRotCursor = QCursor(rotCursorBmp, 7, 1); 00036 00037 setCursor(itsEditCursor); 00038 } 00039 00040 void MainDisplay::setImage(QImage img) 00041 { 00042 itsImageDisplay->setImage(img); 00043 itsImageDisplay->update(); 00044 setSceneRect(itsImageDisplay->getRect()); 00045 } 00046 00047 void MainDisplay::zoomIn() 00048 { 00049 scale(1.3, 1.3); 00050 } 00051 00052 void MainDisplay::zoomOut() 00053 { 00054 scale(1.0/1.3, 1.0/1.3); 00055 } 00056 00057 void MainDisplay::mousePressEvent(QMouseEvent * event) 00058 { 00059 //Convert the raw mouse click onto the possibly zoomed 00060 //and panned scene coordinates 00061 QMouseEvent * originalEvent = new QMouseEvent(*event); 00062 QPointF sceneClick = QGraphicsView::mapToScene(event->pos()); 00063 00064 switch(itsActionMode) 00065 { 00066 case Edit: 00067 QGraphicsView::mousePressEvent(originalEvent); 00068 break; 00069 case Add: 00070 emit(addVertex(sceneClick)); 00071 break; 00072 case Remove: 00073 emit(removeVertex(sceneClick)); 00074 break; 00075 case Rotate: 00076 break; 00077 } 00078 00079 } 00080 00081 void MainDisplay::addObject(AnnotationObject * object) 00082 { 00083 itsScene->addItem(object); 00084 } 00085 00086 void MainDisplay::setActionMode_Cursor() 00087 { 00088 setCursor(itsEditCursor); 00089 itsActionMode = Edit; 00090 } 00091 00092 void MainDisplay::setActionMode_AddVertex() 00093 { 00094 setCursor(itsAddCursor); 00095 itsActionMode = Add; 00096 } 00097 00098 void MainDisplay::setActionMode_RemVertex() 00099 { 00100 setCursor(itsRemCursor); 00101 itsActionMode = Remove; 00102 } 00103 00104 void MainDisplay::setActionMode_Rotate() 00105 { 00106 setCursor(itsRotCursor); 00107 itsActionMode = Rotate; 00108 } 00109 #endif //MAINDISPLAY_QT_C 00110