00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <math.h>
00026 #include <iostream>
00027
00028 #include <QMouseEvent>
00029 #include <QPainter>
00030 #include <QScrollArea>
00031 #include <QScrollBar>
00032 #include <QGLWidget>
00033 #include <QToolButton>
00034 #include <QStatusBar>
00035 #include <QHBoxLayout>
00036 #include <QGridLayout>
00037
00038 #include <qwt_scale_widget.h>
00039 #include <qwt_scale_engine.h>
00040 #include <qwt_scale_div.h>
00041 #include <math.h>
00042
00043 #include <QVImage>
00044 #include "qvcanvas.h"
00045
00046 #ifndef DOXYGEN_IGNORE_THIS
00047 void QVPainter::drawQVImage(QVGenericImage *image,bool adaptSize,float low,float high)
00048 {
00049 imageArea->drawQVImage(image,adaptSize,low,high);
00050 }
00051
00052
00053 void QVPainter::drawTextUnscaled(const QPointF & position, const QString & text)
00054 {
00055 save();
00056 resetMatrix();
00057 translate(-imageArea->topLeft);
00058 drawText(imageArea->zoom*position,text);
00059 restore();
00060 }
00061
00062 void QVPainter::drawTextUnscaled(const QPoint & position, const QString & text)
00063 {
00064 save();
00065 resetMatrix();
00066 translate(-imageArea->topLeft);
00067 drawText(imageArea->zoom*position,text);
00068 restore();
00069 }
00070
00071 void QVPainter::drawTextUnscaled(const QRectF & rectangle, int flags,
00072 const QString & text, QRectF * boundingRect)
00073 {
00074 save();
00075 resetMatrix();
00076 translate(-imageArea->topLeft);
00077 drawText(QRectF(imageArea->zoom*rectangle.topLeft(),
00078 imageArea->zoom*rectangle.size()),flags,text,boundingRect);
00079 if(boundingRect != 0)
00080 *boundingRect = QRectF(imageArea->zoom*boundingRect->topLeft(),
00081 imageArea->zoom*boundingRect->size());
00082 restore();
00083 }
00084
00085 void QVPainter::drawTextUnscaled(const QRect & rectangle, int flags,
00086 const QString & text, QRect * boundingRect)
00087 {
00088 save();
00089 resetMatrix();
00090 translate(-imageArea->topLeft);
00091 drawText(QRect(imageArea->zoom*rectangle.topLeft(),
00092 imageArea->zoom*rectangle.size()),flags,text,boundingRect);
00093 if(boundingRect != 0)
00094 *boundingRect = QRect(imageArea->zoom*boundingRect->topLeft(),
00095 imageArea->zoom*boundingRect->size());
00096 restore();
00097 }
00098
00099 void QVPainter::drawTextUnscaled(int x, int y, const QString & text)
00100 {
00101 save();
00102 resetMatrix();
00103 translate(-imageArea->topLeft);
00104 drawText(imageArea->zoom*x,imageArea->zoom*y,text);
00105 restore();
00106 }
00107
00108 void QVPainter::drawTextUnscaled(int x, int y, int width, int height, int flags,
00109 const QString & text, QRect * boundingRect)
00110 {
00111 save();
00112 resetMatrix();
00113 translate(-imageArea->topLeft);
00114 drawText(imageArea->zoom*x,imageArea->zoom*y,imageArea->zoom*width,
00115 imageArea->zoom*height,flags,text,boundingRect);
00116 if(boundingRect != 0)
00117 *boundingRect = QRect(imageArea->zoom*boundingRect->topLeft(),
00118 imageArea->zoom*boundingRect->size());
00119 restore();
00120 }
00121
00122 void QVPainter::drawTextUnscaled(const QRectF & rectangle, const QString & text,
00123 const QTextOption & option)
00124 {
00125 save();
00126 resetMatrix();
00127 translate(-imageArea->topLeft);
00128 drawText(QRectF(imageArea->zoom*rectangle.topLeft(),
00129 imageArea->zoom*rectangle.size()),text,option);
00130 restore();
00131 }
00132
00133
00134 void QVImageArea::initObject(int w, int h)
00135 {
00136 zoom = 1;
00137 origwidth = w;
00138 origheight = h;
00139 topLeft = QPoint(0,0);
00140 selRect = QRect();
00141 zoomRect = QRect();
00142 setAttribute(Qt::WA_NoSystemBackground);
00143 setMouseTracking(TRUE);
00144 setMinimumSize(qMin(w,max_zoom),qMin(h,max_zoom));
00145 setMaximumSize(w,h);
00146 resize(w,h);
00147 mouseMode = NONE;
00148 polyMode = LINE;
00149 dragging = FALSE;
00150 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width(),height(),zoom);
00151 }
00152
00153 QVImageArea::QVImageArea(int w, int h,QWidget *parent)
00154 : QGLWidget(QGLFormat(QGL::DoubleBuffer|QGL::NoDepthBuffer|
00155 QGL::DirectRendering|QGL::HasOverlay), parent), max_zoom(128)
00156 {
00157 initObject(w,h);
00158 }
00159
00160 QVImageArea::QVImageArea(int w, int h,QWidget *parent,QGLWidget *other)
00161 : QGLWidget(parent,other), max_zoom(128)
00162 {
00163 initObject(w,h);
00164 }
00165
00166 QList<QVImageArea::QVImageArea *> image_areas;
00167
00168 void QVImageArea::centerZoom(int zoom)
00169 {
00170 if((zoom != this->zoom) and (zoom >= 1) and (zoom <= max_zoom)) {
00171 int old_zoom = this->zoom;
00172 this->zoom = zoom;
00173 setMaximumSize(zoom*origwidth,zoom*origheight);
00174 QPoint newTopLeft = zoom*(topLeft+QPoint(width(),height())/2)/old_zoom
00175 - QPoint(width(),height())/2;
00176 if(newTopLeft.x() < 0)
00177 newTopLeft.setX(0);
00178 if(newTopLeft.y() < 0)
00179 newTopLeft.setY(0);
00180 if(newTopLeft.x()+width() > origwidth*zoom)
00181 newTopLeft.setX(origwidth*zoom-width());
00182 if(newTopLeft.y()+height() > origheight*zoom)
00183 newTopLeft.setY(origheight*zoom-height());
00184 topLeft = newTopLeft;
00185 makeCurrent();
00186 update();
00187 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width(),height(),zoom);
00188 }
00189 }
00190
00191 void QVImageArea::resizeGL(int width, int height)
00192 {
00193 QPoint newTopLeft = topLeft,newBottomRight = topLeft+QPoint(width,height);
00194 if(newBottomRight.x() > origwidth*zoom)
00195 newTopLeft.setX(origwidth*zoom-width);
00196 if(newBottomRight.y() > origheight*zoom)
00197 newTopLeft.setY(origheight*zoom-height);
00198 topLeft = newTopLeft;
00199 makeCurrent();
00200 update();
00201 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width,height,zoom);
00202 }
00203
00204
00205 void QVImageArea::wheelEvent(QWheelEvent *event)
00206 {
00207 if (event->delta() > 0) {
00208 centerZoom(2*zoom);
00209 } else {
00210 centerZoom(zoom/2);
00211 }
00212 }
00213
00214
00215
00216 QRectF QVImageArea::intuitiveRect(QRect rect)
00217 {
00218 return QRectF(rect.x(),rect.y()+1.0/zoom,
00219 rect.width()-1.0/zoom,rect.height()-1.0/zoom);
00220 }
00221
00222
00223 QRect QVImageArea::innerRect()
00224 {
00225 QPoint q1(static_cast<int>(ceilf(static_cast<float>(topLeft.x())/zoom)),
00226 static_cast<int>(ceilf(static_cast<float>(topLeft.y())/zoom))),
00227 q2(static_cast<int>(floor(static_cast<float>((topLeft.x()+width()))/zoom)-1),
00228 (static_cast<int>(floor(static_cast<float>(topLeft.y()+height()))/zoom))-1);
00229 return QRect(q1,q2);
00230 }
00231
00232 QRect QVImageArea::outerRect()
00233 {
00234 QPoint q1(static_cast<int>(ceilf(static_cast<float>(topLeft.x())/zoom)-1),
00235 static_cast<int>(ceilf(static_cast<float>(topLeft.y())/zoom))-1),
00236 q2(static_cast<int>(floor(static_cast<float>((topLeft.x()+width()))/zoom)),
00237 (static_cast<int>(floor(static_cast<float>(topLeft.y()+height()))/zoom)));
00238
00239 return QRect(q1,q2) & QRect(0,0,origwidth,origheight);
00240 }
00241
00242 void QVImageArea::paintEvent(QPaintEvent *event)
00243 {
00244 Q_UNUSED(event);
00245
00246 painter = new QVPainter(this);
00247
00248 painter->begin(this);
00249
00250
00251 painter->setViewport(0,0,width(),height());
00252 painter->resetMatrix();
00253 painter->translate(-topLeft);
00254 painter->scale(zoom,zoom);
00255
00256
00257 QVCanvas *image_viewer = qobject_cast<QVCanvas *>(parent());
00258 if(image_viewer == 0) {
00259 qFatal("Error interno de QVision: El padre de una QVImageArea deberÃa ser un QVCanvas");
00260 } else {
00261 glClearColor(0,0,1,0);
00262 glClear(GL_COLOR_BUFFER_BIT);
00263 image_viewer->viewer();
00264 }
00265
00266
00267 if(selRect != QRect()) {
00268 painter->setPen(QColor(Qt::red));
00269
00270
00271 painter->drawRect(intuitiveRect(selRect));
00272 }
00273 if(zoomRect != QRect()) {
00274 painter->setPen(QColor(Qt::blue));
00275
00276
00277 painter->drawRect(intuitiveRect(zoomRect));
00278 }
00279
00280
00281 if(zoom >= 32) {
00282 painter->setPen(QColor(Qt::green));
00283 QRect outer = outerRect();
00284 for(int j=outer.y();j<outer.y()+outer.height();j++) {
00285 for(int i=outer.x();i<outer.x()+outer.width();i++) {
00286 if(not imageList.isEmpty()) {
00287 QString value_string;
00288 int k;
00289 for(k=0;k<imageList.size();k++) {
00290 QRect img_rect = QRect(imageList[k]->getAnchor()+imageList[k]->getROI().topLeft(),
00291 QSize(imageList[k]->getROI().width(),imageList[k]->getROI().height()));
00292 if(i>=img_rect.left() and i<=img_rect.right() and j>=img_rect.top() and j<=img_rect.bottom()) {
00293
00295 if(imageList[k]->isCompatibleWith("QVImage<uChar,1>")) {
00296 if(zoom >= 64) {
00297 value_string = QString("%1").arg((*(QVImage<uChar,1>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y()));
00298 }
00299 }
00300 else if(imageList[k]->isCompatibleWith("QVImage<uShort,1>")) {
00301 if(zoom >= 64) {
00302 value_string = QString("%1").arg((*(QVImage<uShort,1>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y()));
00303 }
00304 }
00305 else if(imageList[k]->isCompatibleWith("QVImage<sShort,1>")) {
00306 if(zoom >= 64) {
00307 value_string = QString("%1").arg((*(QVImage<sShort,1>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y()));
00308 }
00309 }
00310 else if(imageList[k]->isCompatibleWith("QVImage<sInt,1>")) {
00311 if(zoom >= 64) {
00312 value_string = QString("%1").arg((*(QVImage<sInt,1>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y()));
00313 }
00314 }
00315 else if(imageList[k]->isCompatibleWith("QVImage<sFloat,1>")) {
00316 if(zoom >= 64) {
00317 value_string = QString("%1").arg((*(QVImage<sFloat,1>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y()));
00318 }
00319 }
00320 else if(imageList[k]->isCompatibleWith("QVImage<uChar,3>")) {
00321 int red,green,blue;
00322 if(zoom >= 64) {
00323 red = (*(QVImage<uChar,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),0);
00324 green = (*(QVImage<uChar,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),1);
00325 blue = (*(QVImage<uChar,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),2);
00326 value_string = QString("R:%1\nG:%2\nB:%3").arg(red).arg(green).arg(blue);
00327 }
00328 }
00329 else if(imageList[k]->isCompatibleWith("QVImage<uShort,3>")) {
00330 int red,green,blue;
00331 if(zoom >= 64) {
00332 red = (*(QVImage<uShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),0);
00333 green = (*(QVImage<uShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),1);
00334 blue = (*(QVImage<uShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),2);
00335 value_string = QString("R:%1\nG:%2\nB:%3").arg(red).arg(green).arg(blue);
00336 }
00337 }
00338 else if(imageList[k]->isCompatibleWith("QVImage<sShort,3>")) {
00339 int red,green,blue;
00340 if(zoom >= 64) {
00341 red = (*(QVImage<sShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),0);
00342 green = (*(QVImage<sShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),1);
00343 blue = (*(QVImage<sShort,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),2);
00344 value_string = QString("R:%1\nG:%2\nB:%3").arg(red).arg(green).arg(blue);
00345 }
00346 }
00347 else if(imageList[k]->isCompatibleWith("QVImage<sInt,3>")) {
00348 int red,green,blue;
00349 if(zoom >= 64) {
00350 red = (*(QVImage<sInt,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),0);
00351 green = (*(QVImage<sInt,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),1);
00352 blue = (*(QVImage<sInt,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),2);
00353 value_string = QString("R:%1\nG:%2\nB:%3").arg(red).arg(green).arg(blue);
00354 }
00355 }
00356 else if(imageList[k]->isCompatibleWith("QVImage<sFloat,3>")) {
00357 float red,green,blue;
00358 if(zoom >= 64) {
00359 red = (*(QVImage<sFloat,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),0);
00360 green = (*(QVImage<sFloat,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),1);
00361 blue = (*(QVImage<sFloat,3>*)imageList[k])(i-img_rect.topLeft().x()+imageList[k]->getROI().topLeft().x(),j-img_rect.topLeft().y()+imageList[k]->getROI().topLeft().y(),2);
00362 value_string = QString("R:%1\nG:%2\nB:%3").arg(red).arg(green).arg(blue);
00363 }
00364 }
00365 else {
00366
00367 qFatal("Type of QVGenericImage still not supported in paintEvent");
00368 }
00369 break;
00370 }
00371 }
00372 if(k==imageList.size()) {
00373 value_string = QString("X");
00374 }
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 painter->drawTextUnscaled(
00397 QRect(QPoint(i,j),QSize(1,1)),
00398 Qt::AlignCenter|Qt::TextDontClip,value_string);
00399 }
00400 }
00401 }
00402 }
00403
00404
00405 painter->end();
00406 delete painter;
00407
00408
00409 while (!imageList.isEmpty())
00410 delete imageList.takeFirst();
00411 }
00412
00413 void QVImageArea::resizeImageArea(int w,int h)
00414 {
00415 if(w != origwidth or h != origheight) {
00416 zoom = 1;
00417 origwidth = w;
00418 origheight = h;
00419 topLeft = QPoint(0,0);
00420 selRect = QRect();
00421 zoomRect = QRect();
00422 setMinimumSize(qMin(w,max_zoom),qMin(h,max_zoom));
00423 setMaximumSize(w,h);
00424 resize(w,h);
00425 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width(),height(),zoom);
00426 }
00427 }
00428
00429 void QVImageArea::drawQVImage(QVGenericImage *image,bool adaptSize,float low, float high)
00430 {
00431
00432 QVGenericImage *imagecopy=NULL;
00433 if(image->isCompatibleWith("QVImage<uChar,1>")) {
00434 imagecopy = new QVImage<uChar,1>;
00435 *(dynamic_cast<QVImage<uChar,1>*>(imagecopy)) = *(dynamic_cast<QVImage<uChar,1>*>(image));
00436 }
00437 else if(image->isCompatibleWith("QVImage<uShort,1>")) {
00438 imagecopy = new QVImage<uShort,1>;
00439 *(dynamic_cast<QVImage<uShort,1>*>(imagecopy)) = *(dynamic_cast<QVImage<uShort,1>*>(image));
00440 }
00441 else if(image->isCompatibleWith("QVImage<sShort,1>")) {
00442 imagecopy = new QVImage<sShort,1>;
00443 *(dynamic_cast<QVImage<sShort,1>*>(imagecopy)) = *(dynamic_cast<QVImage<sShort,1>*>(image));
00444 }
00445 else if(image->isCompatibleWith("QVImage<sInt,1>")) {
00446 imagecopy = new QVImage<sInt,1>;
00447 *(dynamic_cast<QVImage<sInt,1>*>(imagecopy)) = *(dynamic_cast<QVImage<sInt,1>*>(image));
00448 }
00449 else if(image->isCompatibleWith("QVImage<sFloat,1>")) {
00450 imagecopy = new QVImage<sFloat,1>;
00451 *(dynamic_cast<QVImage<sFloat,1>*>(imagecopy)) = *(dynamic_cast<QVImage<sFloat,1>*>(image));
00452 }
00453 else if(image->isCompatibleWith("QVImage<uChar,3>")) {
00454 imagecopy = new QVImage<uChar,3>;
00455 *(dynamic_cast<QVImage<uChar,3>*>(imagecopy)) = *(dynamic_cast<QVImage<uChar,3>*>(image));
00456 }
00457 else if(image->isCompatibleWith("QVImage<uShort,3>")) {
00458 imagecopy = new QVImage<uShort,3>;
00459 *(dynamic_cast<QVImage<uShort,3>*>(imagecopy)) = *(dynamic_cast<QVImage<uShort,3>*>(image));
00460 }
00461 else if(image->isCompatibleWith("QVImage<sShort,3>")) {
00462 imagecopy = new QVImage<sShort,3>;
00463 *(dynamic_cast<QVImage<sShort,3>*>(imagecopy)) = *(dynamic_cast<QVImage<sShort,3>*>(image));
00464 }
00465 else if(image->isCompatibleWith("QVImage<sInt,3>")) {
00466 imagecopy = new QVImage<sInt,3>;
00467 *(dynamic_cast<QVImage<sInt,3>*>(imagecopy)) = *(dynamic_cast<QVImage<sInt,3>*>(image));
00468 }
00469 else if(image->isCompatibleWith("QVImage<sFloat,3>")) {
00470 imagecopy = new QVImage<sFloat,3>;
00471 *(dynamic_cast<QVImage<sFloat,3>*>(imagecopy)) = *(dynamic_cast<QVImage<sFloat,3>*>(image));
00472 }
00473 else {
00474
00475 qFatal("Type of QVGenericImage still not supported in drawQVImage");
00476 }
00477
00478
00479 imageList.push_front(imagecopy);
00480
00481
00483 if(adaptSize) {
00484 this->resizeImageArea(image->getAnchor().x()+image->getROI().x()+image->getROI().width(),image->getAnchor().y()+image->getROI().y()+image->getROI().height());
00485 }
00486
00487
00488
00489 glPushAttrib(GL_ALL_ATTRIB_BITS);
00490 glPushClientAttrib(GL_ALL_ATTRIB_BITS);
00491 glMatrixMode(GL_PROJECTION);
00492 glPushMatrix();
00493 glMatrixMode(GL_MODELVIEW);
00494 glPushMatrix();
00495
00496
00497
00498 glViewport(0,0,width(),height());
00499 glMatrixMode(GL_PROJECTION);
00500 glLoadIdentity();
00501 glOrtho(topLeft.x(),topLeft.x()+width(),
00502 topLeft.y()+height(),topLeft.y(),-1,1);
00503 glMatrixMode(GL_MODELVIEW);
00504 glLoadIdentity();
00505
00506
00507 QRect final_rect,outer_rect = outerRect(),
00508 img_rect = QRect(imagecopy->getAnchor()+imagecopy->getROI().topLeft(),
00509 QSize(imagecopy->getROI().width(),imagecopy->getROI().height()));
00510 final_rect = outer_rect & img_rect;
00511
00512
00513
00514
00515 QPoint where,dirty;
00516 if(outer_rect.topLeft().x() >= img_rect.topLeft().x()) {
00517 where.setX(outer_rect.topLeft().x());
00518 dirty.setX(1);
00519 } else {
00520 where.setX(img_rect.topLeft().x());
00521 dirty.setX(0);
00522 }
00523 if(outer_rect.topLeft().y() >= img_rect.topLeft().y()) {
00524 where.setY(outer_rect.topLeft().y());
00525 dirty.setY(1);
00526 } else {
00527 where.setY(img_rect.topLeft().y());
00528 dirty.setY(0);
00529 }
00530
00531 glRasterPos2f(zoom*(where.x()+dirty.x()+0.0001),zoom*(where.y()+dirty.y()+0.0001));
00532 glBitmap(0, 0, 0, 0, -zoom*dirty.x(), +zoom*dirty.y(), NULL);
00533
00534
00535 QRect what;
00536 int img_step = imagecopy->getStep();
00537 glPixelZoom(zoom,-zoom);
00538 if(outer_rect.topLeft().x() >= img_rect.topLeft().x()) {
00539 what.setX(outer_rect.topLeft().x() - img_rect.topLeft().x() + imagecopy->getROI().topLeft().x());
00540 } else {
00541 what.setX(imagecopy->getROI().topLeft().x());
00542 }
00543 what.setWidth(final_rect.width());
00544 if(outer_rect.topLeft().y() >= img_rect.topLeft().y()) {
00545 what.setY(outer_rect.topLeft().y() - img_rect.topLeft().y() + imagecopy->getROI().topLeft().y());
00546 } else {
00547 what.setY(imagecopy->getROI().topLeft().y());
00548 }
00549 what.setHeight(final_rect.height());
00550
00551 if(image->isCompatibleWith("QVImage<uChar,1>")) {
00552 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step);
00553 glDrawPixels(what.width(),what.height(),
00554 GL_LUMINANCE,GL_UNSIGNED_BYTE,
00555 static_cast<QVImage<uchar,1> *>(imagecopy)->getReadData() +
00556 what.y()*img_step+what.x());
00557 }
00558 else if(image->isCompatibleWith("QVImage<uShort,1>")) {
00559 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/sizeof(uShort));
00560 glDrawPixels(what.width(),what.height(),
00561 GL_LUMINANCE,GL_UNSIGNED_SHORT,
00562 static_cast<QVImage<uShort,1> *>(imagecopy)->getReadData() +
00563 what.y()*img_step/sizeof(uShort)+what.x());
00564 }
00565 else if(image->isCompatibleWith("QVImage<sShort,1>")) {
00566 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/sizeof(sShort));
00567
00568 float scale=1.0/(high-low),bias=-low*scale;
00569 glPixelTransferf(GL_RED_BIAS,bias);
00570 glPixelTransferf(GL_GREEN_BIAS,bias);
00571 glPixelTransferf(GL_BLUE_BIAS,bias);
00572 glPixelTransferf(GL_RED_SCALE,scale);
00573 glPixelTransferf(GL_GREEN_SCALE,scale);
00574 glPixelTransferf(GL_BLUE_SCALE,scale);
00575
00576 glDrawPixels(what.width(),what.height(),
00577 GL_LUMINANCE,GL_SHORT,
00578 static_cast<QVImage<sShort,1> *>(imagecopy)->getReadData() +
00579 what.y()*img_step/sizeof(sShort)+what.x());
00580 }
00581 else if(image->isCompatibleWith("QVImage<sInt,1>")) {
00582 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/sizeof(sInt));
00583
00584 float scale=1.0/(high-low),bias=-low*scale;
00585 glPixelTransferf(GL_RED_BIAS,bias);
00586 glPixelTransferf(GL_GREEN_BIAS,bias);
00587 glPixelTransferf(GL_BLUE_BIAS,bias);
00588 glPixelTransferf(GL_RED_SCALE,scale);
00589 glPixelTransferf(GL_GREEN_SCALE,scale);
00590 glPixelTransferf(GL_BLUE_SCALE,scale);
00591
00592 glDrawPixels(what.width(),what.height(),
00593 GL_LUMINANCE,GL_INT,
00594 static_cast<QVImage<sInt,1> *>(imagecopy)->getReadData() +
00595 what.y()*img_step/sizeof(sInt)+what.x());
00596 }
00597 else if(image->isCompatibleWith("QVImage<sFloat,1>")) {
00598 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/sizeof(sFloat));
00599
00600 float scale=1.0/(high-low),bias=-low*scale;
00601
00602 glPixelTransferf(GL_RED_BIAS,bias);
00603 glPixelTransferf(GL_GREEN_BIAS,bias);
00604 glPixelTransferf(GL_BLUE_BIAS,bias);
00605 glPixelTransferf(GL_RED_SCALE,scale);
00606 glPixelTransferf(GL_GREEN_SCALE,scale);
00607 glPixelTransferf(GL_BLUE_SCALE,scale);
00608
00609
00610
00611
00612
00613
00614 glDrawPixels(what.width(),what.height(),
00615 GL_LUMINANCE,GL_FLOAT,
00616 static_cast<QVImage<sFloat,1> *>(imagecopy)->getReadData() +
00617 what.y()*img_step/sizeof(sFloat)+what.x());
00618 }
00619 else if(image->isCompatibleWith("QVImage<uChar,3>")) {
00620 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/3);
00621 glDrawPixels(what.width(),what.height(),
00622 GL_RGB,GL_UNSIGNED_BYTE,
00623 static_cast<QVImage<uchar,3> *>(imagecopy)->getReadData() +
00624 what.y()*img_step+3*what.x());
00625 }
00626 else if(image->isCompatibleWith("QVImage<uShort,3>")) {
00627 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/(sizeof(uShort)*3));
00628 glDrawPixels(what.width(),what.height(),
00629 GL_RGB,GL_UNSIGNED_SHORT,
00630 static_cast<QVImage<uShort,3> *>(imagecopy)->getReadData() +
00631 what.y()*img_step/sizeof(uShort)+3*what.x());
00632 }
00633 else if(image->isCompatibleWith("QVImage<sShort,3>")) {
00634 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/(sizeof(sShort)*3));
00635
00636 float scale=1.0/(high-low),bias=-low*scale;
00637 glPixelTransferf(GL_RED_BIAS,bias);
00638 glPixelTransferf(GL_GREEN_BIAS,bias);
00639 glPixelTransferf(GL_BLUE_BIAS,bias);
00640 glPixelTransferf(GL_RED_SCALE,scale);
00641 glPixelTransferf(GL_GREEN_SCALE,scale);
00642 glPixelTransferf(GL_BLUE_SCALE,scale);
00643
00644 glDrawPixels(what.width(),what.height(),
00645 GL_RGB,GL_SHORT,
00646 static_cast<QVImage<sShort,3> *>(imagecopy)->getReadData() +
00647 what.y()*img_step/sizeof(sShort)+3*what.x());
00648 }
00649 else if(image->isCompatibleWith("QVImage<sInt,3>")) {
00650 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/(sizeof(sInt)*3));
00651
00652 float scale=1.0/(high-low),bias=-low*scale;
00653 glPixelTransferf(GL_RED_BIAS,bias);
00654 glPixelTransferf(GL_GREEN_BIAS,bias);
00655 glPixelTransferf(GL_BLUE_BIAS,bias);
00656 glPixelTransferf(GL_RED_SCALE,scale);
00657 glPixelTransferf(GL_GREEN_SCALE,scale);
00658 glPixelTransferf(GL_BLUE_SCALE,scale);
00659
00660 glDrawPixels(what.width(),what.height(),
00661 GL_RGB,GL_INT,
00662 static_cast<QVImage<sInt,3> *>(imagecopy)->getReadData() +
00663 what.y()*img_step/sizeof(sInt)+3*what.x());
00664 }
00665 else if(image->isCompatibleWith("QVImage<sFloat,3>")) {
00666 glPixelStorei(GL_UNPACK_ROW_LENGTH,img_step/(sizeof(sFloat)*3));
00667
00668 float scale=1.0/(high-low),bias=-low*scale;
00669 glPixelTransferf(GL_RED_BIAS,bias);
00670 glPixelTransferf(GL_GREEN_BIAS,bias);
00671 glPixelTransferf(GL_BLUE_BIAS,bias);
00672 glPixelTransferf(GL_RED_SCALE,scale);
00673 glPixelTransferf(GL_GREEN_SCALE,scale);
00674 glPixelTransferf(GL_BLUE_SCALE,scale);
00675
00676 glDrawPixels(what.width(),what.height(),
00677 GL_RGB,GL_FLOAT,
00678 static_cast<QVImage<sFloat,3> *>(imagecopy)->getReadData() +
00679 what.y()*img_step/sizeof(sFloat)+3*what.x());
00680 }
00681 else {
00682
00683 qFatal("Type of QVGenericImage still not supported in drawQVImage");
00684 }
00685
00686
00687
00688 glPopClientAttrib();
00689 glPopAttrib();
00690 glMatrixMode(GL_MODELVIEW);
00691 glPopMatrix();
00692 glMatrixMode(GL_PROJECTION);
00693 glPopMatrix();
00694 }
00695
00696 void QVImageArea::mousePressEvent(QMouseEvent *event)
00697 {
00698 firstPos = event->pos();
00699 dragging = TRUE;
00700 if(mouseMode == DRAG) {
00701
00702 }
00703
00704 if ( (mouseMode == SEL) && (event->button() == Qt::RightButton) )
00705 emit rectSelected(QRect());
00706
00707
00708 if (mouseMode == POLY) {
00709 if (event->button() == Qt::RightButton) {
00710 (polyMode == CIRCLE) ? emit circleSelected(QPoint(), 0.0) : emit polySelected(QPoint(), true, polyMode);
00711 }
00712 else if (polyMode != CIRCLE) {
00713 QPoint pos = event->pos();
00714 QPoint point(qRound(static_cast<float>(pos.x()+topLeft.x())/zoom), qRound(static_cast<float>(pos.y()+topLeft.y())/zoom));
00715 emit polySelected(point, false, polyMode);
00716 }
00717 }
00718 }
00719
00720 void QVImageArea::mouseMoveEvent(QMouseEvent *event)
00721 {
00722 if(dragging) {
00723 lastPos = event->pos();
00724 switch(mouseMode) {
00725 case DRAG: {
00726 QPoint minDesp = -topLeft,
00727 maxDesp = QPoint(origwidth*zoom,origheight*zoom) -
00728 (topLeft + QPoint(width(),height()));
00729 QPoint desp = firstPos-lastPos,
00730 boundDesp = QPoint(qBound(minDesp.x(),desp.x(),maxDesp.x()),
00731 qBound(minDesp.y(),desp.y(),maxDesp.y()));
00732 if(boundDesp != QPoint(0,0)) {
00733 topLeft = topLeft+boundDesp;
00734 makeCurrent();
00735 update();
00736 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width(),height(),zoom);
00737 }
00738 firstPos = lastPos;
00739 emit mouseLeavesImageArea(FALSE);
00740 emit newMousePosition(static_cast<float>(event->x()+topLeft.x())/zoom,static_cast<float>(event->y()+topLeft.y())/zoom);
00741 break;
00742 }
00743 case ZOOM: {
00744 QPoint p1(qRound(static_cast<float>(firstPos.x()+topLeft.x())/zoom),
00745 qRound(static_cast<float>(firstPos.y()+topLeft.y())/zoom)),
00746 p2(qRound(static_cast<float>(lastPos.x()+topLeft.x())/zoom)-1,
00747 qRound(static_cast<float>(lastPos.y()+topLeft.y())/zoom)-1);
00748
00749
00750
00751
00752 zoomRect = QRect(p1,p2) & innerRect();
00753 emit mouseLeavesImageArea(FALSE);
00754 emit newMousePosition(lastPos.x()>firstPos.x()?zoomRect.right():zoomRect.left(), lastPos.y()>firstPos.y()?zoomRect.bottom():zoomRect.top());
00755 makeCurrent();
00756 update();
00757 break;
00758 }
00759 case SEL: {
00760 QPoint p1(qRound(static_cast<float>(firstPos.x()+topLeft.x())/zoom),
00761 qRound(static_cast<float>(firstPos.y()+topLeft.y())/zoom)),
00762 p2(qRound(static_cast<float>(lastPos.x()+topLeft.x())/zoom)-1,
00763 qRound(static_cast<float>(lastPos.y()+topLeft.y())/zoom)-1);
00764
00765 selRect = QRect(p1,p2) & innerRect();
00766 emit rectSelected(selRect);
00767 emit mouseLeavesImageArea(FALSE);
00768 emit newMousePosition(lastPos.x()>firstPos.x()?selRect.right():selRect.left(), lastPos.y()>firstPos.y()?selRect.bottom():selRect.top());
00769 makeCurrent();
00770 update();
00771 break;
00772 }
00773 case POLY: {
00774 if (polyMode == CIRCLE) {
00775 QPoint p1(qRound(static_cast<float>(firstPos.x()+topLeft.x())/zoom),
00776 qRound(static_cast<float>(firstPos.y()+topLeft.y())/zoom)),
00777 p2(qRound(static_cast<float>(lastPos.x()+topLeft.x())/zoom)-1,
00778 qRound(static_cast<float>(lastPos.y()+topLeft.y())/zoom)-1);
00779
00780 float cat1 = p1.x() - p2.x(), cat2 = p1.y() - p2.y();
00781 float radio = sqrt(cat1*cat1 + cat2*cat2);
00782 emit circleSelected(p1, radio);
00783 }
00784 break;
00785 }
00786 case NONE: {
00787 break;
00788 }
00789 }
00790 } else {
00791 emit mouseLeavesImageArea(FALSE);
00792 emit newMousePosition(static_cast<float>(event->x()+topLeft.x())/zoom,static_cast<float>(event->y()+topLeft.y())/zoom);
00793 }
00794 }
00795
00796
00797 void QVImageArea::mouseReleaseEvent(QMouseEvent *event)
00798 {
00799
00800 if(mouseMode == DRAG) {
00801
00802 }
00803 dragging = FALSE;
00804 lastPos = event->pos();
00805 switch(mouseMode) {
00806 case DRAG: {
00807 break;
00808 }
00809 case ZOOM: {
00810 int newzoom = zoom;
00811
00812 if (zoomRect.width() < 1 or zoomRect.height() < 1)
00813 newzoom = max_zoom + 1;
00814 else {
00815 do {
00816 if (newzoom < 2) newzoom++;
00817 else newzoom = 2*newzoom;
00818 }
00819 while(newzoom*zoomRect.width() < minimumWidth() or newzoom*zoomRect.height() < minimumHeight());
00820 }
00821
00822 if(newzoom <= max_zoom) {
00823 zoom = newzoom;
00824 topLeft = zoom*zoomRect.topLeft();
00825 setMaximumSize(zoom*origwidth,zoom*origheight);
00826 resize(zoom*zoomRect.width(),zoom*zoomRect.height());
00827 zoomRect = QRect();
00828 makeCurrent();
00829 update();
00830 emit newGeometry(origwidth,origheight,topLeft.x(),topLeft.y(),width(),height(),zoom);
00831 } else {
00832 zoomRect = QRect();
00833 makeCurrent();
00834 update();
00835 }
00836 break;
00837 }
00838 case SEL: {
00839 if(event->button() == Qt::RightButton) {
00840 selRect = QRect();
00841 makeCurrent();
00842 update();
00843 }
00844 break;
00845 }
00846 case POLY: {
00847 break;
00848 }
00849 case NONE: {
00850 break;
00851 }
00852 }
00853 }
00854
00855 void QVImageArea::leaveEvent(QEvent *event)
00856 {
00857 Q_UNUSED(event);
00858 emit mouseLeavesImageArea(TRUE);
00859 }
00860
00861
00862
00863
00864 void QVCanvas::resizeEvent(QResizeEvent *event)
00865 {
00866 QFontMetrics fm(font());
00867
00868 int w = event->size().width() - scaleWidgetsFixedWidth - 1;
00869 int h = event->size().height() - scaleWidgetsFixedWidth - statusBarWidgetFixedHeight - 1;
00870 imageArea->setGeometry(scaleWidgetsFixedWidth,scaleWidgetsFixedWidth,w,h);
00871 }
00872
00873 QString QVCanvas::statusMessage()
00874 {
00875 if(mouseIsOut) {
00876 return QString("z=%1").arg(imageArea->zoom);
00877 } else {
00878 return QString("(%1,%2) z=%3").arg(mousePosX).arg(mousePosY).arg(imageArea->zoom);
00879 }
00880 }
00881
00882 QVCanvas::QVCanvas(QWidget *parent) : QWidget(parent)
00883 {
00884 mouseIsOut = TRUE;
00885 int w = 1, h = 1;
00886
00887 QFontMetrics fm(font());
00888 scaleWidgetsFixedWidth = 5*fm.height()/3;
00889
00890
00891 scaleWidgetX = new QwtScaleWidget(QwtScaleDraw::TopScale,this);
00892
00893 scaleWidgetX->setLabelAlignment(Qt::AlignHCenter|Qt::AlignTop);
00894 scaleWidgetX->setMargin(1);
00895
00896
00897
00898 scaleWidgetX->setBorderDist(scaleWidgetsFixedWidth,scaleWidgetsFixedWidth);
00899
00900 scaleWidgetY = new QwtScaleWidget(QwtScaleDraw::LeftScale,this);
00901 scaleWidgetY->setLabelRotation(-90.0);
00902 scaleWidgetY->setLabelAlignment(Qt::AlignVCenter|Qt::AlignTop);
00903 scaleWidgetY->setMargin(1);
00904
00905
00906
00907 scaleWidgetY->setBorderDist(scaleWidgetsFixedWidth,scaleWidgetsFixedWidth);
00908
00909
00910 scaleEngineX = new QwtLinearScaleEngine;
00911 scaleEngineY = new QwtLinearScaleEngine;
00912
00913
00914 if(image_areas.isEmpty()) {
00915
00916 imageArea = new QVImageArea(w,h,this);
00917 }
00918 else {
00919
00920 imageArea = new QVImageArea(w,h,this,image_areas.first());
00921 }
00922
00923 image_areas.append(imageArea);
00924
00925 statusBar = new QStatusBar(this);
00926 statusBar->addPermanentWidget(buttonZoomIn = new QToolButton(statusBar));
00927 statusBar->addPermanentWidget(buttonZoomOut = new QToolButton(statusBar));
00928 statusBar->addPermanentWidget(buttonZoomOriginal = new QToolButton(statusBar));
00929 statusBar->addPermanentWidget(buttonZoomRect = new QToolButton(statusBar));
00930 statusBar->addPermanentWidget(buttonSelPoli = new QToolButton(statusBar));
00931 statusBar->addPermanentWidget(buttonSelRect = new QToolButton(statusBar));
00932 statusBar->addPermanentWidget(buttonDrag = new QToolButton(statusBar));
00933 buttonZoomIn->setCheckable(FALSE);
00934 buttonZoomIn->setIcon(QIcon(":/images/zoom-in.png"));
00935 buttonZoomOut->setCheckable(FALSE);
00936 buttonZoomOut->setIcon(QIcon(":/images/zoom-out.png"));
00937 buttonZoomOriginal->setCheckable(FALSE);
00938 buttonZoomOriginal->setIcon(QIcon(":/images/zoom-original.png"));
00939 buttonZoomRect->setCheckable(TRUE);
00940 buttonZoomRect->setIcon(QIcon(":/images/zoom-best-fit.png"));
00941 buttonSelPoli->setCheckable(TRUE);
00942 buttonSelPoli->setIcon(QIcon(":/images/poly.png"));
00943 menuSelPoli = new QMenu();
00944 menuSelPoli->addAction(QIcon(":/images/poly.png"), "polyline", this, SLOT(selPoliChangedToLine()));
00945 menuSelPoli->addAction(QIcon(":/images/list.png"), "points", this, SLOT(selPoliChangedToList()));
00946 menuSelPoli->addAction(QIcon(":/images/circle.png"), "circle", this, SLOT(selPoliChangedToCircle()));
00947 buttonSelPoli->setMenu(menuSelPoli);
00948 polyMode = LINE;
00949 buttonSelRect->setCheckable(TRUE);
00950 buttonSelRect->setIcon(QIcon(":/images/select.png"));
00951 buttonDrag->setCheckable(TRUE);
00952 buttonDrag->setIcon(QIcon(":/images/hand.png"));
00953
00954 statusBar->showMessage(statusMessage());
00955 statusBarWidgetFixedHeight = statusBar->height();
00956
00957 setMinimumSize(scaleWidgetsFixedWidth + imageArea->minimumWidth() + 1,
00958 scaleWidgetsFixedWidth + imageArea->minimumHeight() + 1 +
00959 statusBarWidgetFixedHeight);
00960 setMaximumSize(scaleWidgetsFixedWidth + w + 1,
00961 scaleWidgetsFixedWidth + h + 1 +
00962 statusBarWidgetFixedHeight);
00963 resize(scaleWidgetsFixedWidth + w + 1,
00964 scaleWidgetsFixedWidth + h + 1 +
00965 statusBarWidgetFixedHeight);
00966 connect(imageArea,SIGNAL(newGeometry(int,int,int,int,int,int,int)),
00967 this,SLOT(setGeometry(int,int,int,int,int,int,int)));
00968 connect(imageArea,SIGNAL(newMousePosition(float,float)),
00969 this,SLOT(newMousePositionSlot(float,float)));
00970 connect(imageArea,SIGNAL(mouseLeavesImageArea(bool)),
00971 this,SLOT(mouseLeavesImageAreaSlot(bool)));
00972 connect(imageArea, SIGNAL(rectSelected(QRect)),
00973 this, SLOT(rectSelectedSlot(QRect)));
00974 connect(imageArea, SIGNAL(polySelected(QPoint,bool,TPolyMode)),
00975 this, SLOT(polySelectedSlot(QPoint,bool,TPolyMode)));
00976 connect(imageArea, SIGNAL(circleSelected(QPoint,float)),
00977 this, SLOT(circleSelectedSlot(QPoint,float)));
00978 connect(buttonZoomRect,SIGNAL(clicked(bool)),this,SLOT(zoomRectClicked(bool)));
00979 connect(buttonSelPoli,SIGNAL(clicked(bool)),this,SLOT(selPoliClicked(bool)));
00980 connect(buttonSelRect,SIGNAL(clicked(bool)),this,SLOT(selRectClicked(bool)));
00981 connect(buttonDrag,SIGNAL(clicked(bool)),this,SLOT(dragClicked(bool)));
00982 connect(buttonZoomIn,SIGNAL(clicked()),this,SLOT(zoomInClicked()));
00983 connect(buttonZoomOut,SIGNAL(clicked()),this,SLOT(zoomOutClicked()));
00984 connect(buttonZoomOriginal,SIGNAL(clicked()),this,SLOT(zoomOriginalClicked()));
00985
00986 }
00987
00988 void QVCanvas::zoomInClicked() {
00989 imageArea->centerZoom(2*imageArea->zoom);
00990 }
00991
00992 void QVCanvas::zoomOutClicked() {
00993 imageArea->centerZoom(imageArea->zoom/2);
00994 }
00995
00996 void QVCanvas::zoomOriginalClicked() {
00997
00998 int w = imageArea->origwidth, h = imageArea->origheight;
00999 imageArea->origwidth = imageArea->origheight = 0;
01000 QRect saveSelRect = imageArea->selRect;
01001 imageArea->resizeImageArea(w,h);
01002 imageArea->selRect = saveSelRect;
01003 }
01004
01005
01006 void QVCanvas::zoomRectClicked(bool checked) {
01007 if(checked)
01008 imageArea->setCursor(Qt::CrossCursor);
01009 else
01010 imageArea->setCursor(Qt::ArrowCursor);
01011 imageArea->mouseMode = (checked ? QVImageArea::ZOOM : QVImageArea::NONE);
01012 buttonSelPoli->setChecked(false);
01013 buttonSelRect->setChecked(false);
01014 buttonDrag->setChecked(false);
01015 }
01016
01017 void QVCanvas::selPoliClicked(bool checked) {
01018 if(checked)
01019 imageArea->setCursor(Qt::CrossCursor);
01020 else
01021 imageArea->setCursor(Qt::ArrowCursor);
01022
01023 if (!checked) {
01024 switch (imageArea->polyMode) {
01025 case LINE:
01026 case LIST: {
01027 imageArea->polyMode = polyMode;
01028 emit imageArea->polySelected(QPoint(), true, polyMode);
01029 break;
01030 }
01031 case CIRCLE: {
01032 imageArea->polyMode = polyMode;
01033 emit imageArea->circleSelected(QPoint(), 0.0);
01034 break;
01035 }
01036 }
01037 imageArea->mouseMode = QVImageArea::NONE;
01038 }
01039 else {
01040 imageArea->mouseMode = QVImageArea::POLY;
01041 imageArea->polyMode = polyMode;
01042 }
01043 buttonZoomRect->setChecked(false);
01044 buttonSelRect->setChecked(false);
01045 buttonDrag->setChecked(false);
01046 }
01047
01048 void QVCanvas::selPoliChangedToLine() {
01049 polyMode = LINE;
01050 if (imageArea->mouseMode == QVImageArea::POLY)
01051 switch (imageArea->polyMode) {
01052 case LIST: {
01053 imageArea->polyMode = polyMode;
01054 emit imageArea->polySelected(QPoint(), true, polyMode);
01055 break;
01056 }
01057 case CIRCLE: {
01058 imageArea->polyMode = polyMode;
01059 emit imageArea->circleSelected(QPoint(), 0.0);
01060 break;
01061 }
01062 case LINE: {
01063 break;
01064 }
01065 }
01066 buttonSelPoli->setIcon(QIcon(":/images/poly.png"));
01067 }
01068
01069 void QVCanvas::selPoliChangedToList() {
01070 polyMode = LIST;
01071 if (imageArea->mouseMode == QVImageArea::POLY)
01072 switch (imageArea->polyMode) {
01073 case LINE: {
01074 imageArea->polyMode = polyMode;
01075 emit imageArea->polySelected(QPoint(), true, polyMode);
01076 break;
01077 }
01078 case CIRCLE: {
01079 imageArea->polyMode = polyMode;
01080 emit imageArea->circleSelected(QPoint(), 0.0);
01081 break;
01082 }
01083 case LIST: {
01084 break;
01085 }
01086 }
01087 buttonSelPoli->setIcon(QIcon(":/images/list.png"));
01088 }
01089
01090 void QVCanvas::selPoliChangedToCircle() {
01091 polyMode = CIRCLE;
01092 if (imageArea->mouseMode == QVImageArea::POLY)
01093 switch (imageArea->polyMode) {
01094 case LIST:
01095 case LINE: {
01096 imageArea->polyMode = polyMode;
01097 emit imageArea->polySelected(QPoint(), true, polyMode);
01098 break;
01099 }
01100 case CIRCLE: {
01101 break;
01102 }
01103 }
01104 buttonSelPoli->setIcon(QIcon(":/images/circle.png"));
01105 }
01106
01107 void QVCanvas::selRectClicked(bool checked) {
01108 if(checked)
01109 imageArea->setCursor(Qt::CrossCursor);
01110 else
01111 imageArea->setCursor(Qt::ArrowCursor);
01112 imageArea->mouseMode = (checked ? QVImageArea::SEL : QVImageArea::NONE);
01113 buttonZoomRect->setChecked(false);
01114 buttonSelPoli->setChecked(false);
01115 buttonDrag->setChecked(false);
01116 if (!checked) {
01117 imageArea->selRect = QRect();
01118 emit imageArea->rectSelected(imageArea->selRect);
01119 }
01120 }
01121
01122 void QVCanvas::dragClicked(bool checked) {
01123 if(checked)
01124 ;
01125 else
01126 imageArea->setCursor(Qt::ArrowCursor);
01127
01128 imageArea->mouseMode = (checked ? QVImageArea::DRAG : QVImageArea::NONE);
01129 buttonSelPoli->setChecked(false);
01130 buttonSelRect->setChecked(false);
01131 buttonZoomRect->setChecked(false);
01132 }
01133
01134
01135 void QVCanvas::newMousePositionSlot(float x,float y) {
01136 mousePosX = x;
01137 mousePosY = y;
01138 statusBar->showMessage(statusMessage());
01139 }
01140
01141 void QVCanvas::mouseLeavesImageAreaSlot(bool leaves) {
01142
01143
01144
01145
01146 mouseIsOut = leaves;
01147 statusBar->showMessage(statusMessage());
01148 }
01149
01150
01151 QVCanvas::~QVCanvas()
01152 {
01153 delete scaleEngineX;
01154 delete scaleEngineY;
01155
01156
01157 image_areas.removeAll(imageArea);
01158
01159 delete imageArea;
01160 }
01161
01162 void QVCanvas::refreshImageArea()
01163 {
01164 imageArea->makeCurrent();
01165 imageArea->update();
01166 }
01167
01168
01169 void QVCanvas::setGeometry(int origwidth,int origheight,int topleftx,int toplefty,int width,int height, int zoom)
01170 {
01171 Q_UNUSED(origwidth);
01172 Q_UNUSED(origheight);
01173
01174 QFontMetrics fm(font());
01175
01176
01177
01178 QwtScaleDiv scaleDivX = scaleEngineX->divideScale(
01179 ((double)topleftx)/zoom,((double)(topleftx+width))/zoom,
01180 qMin(width/zoom+1,static_cast<int>(width/(fm.width("999")))),
01181 10,0);
01182 scaleWidgetX->setScaleDiv(scaleEngineX->transformation(),scaleDivX);
01183
01184 QwtScaleDiv scaleDivY = scaleEngineY->divideScale(
01185 ((double)toplefty+height)/zoom,((double)(toplefty))/zoom,
01186 qMin(height/zoom+1,static_cast<int>(height/(fm.width("999")))),
01187 10,0);
01188 scaleWidgetY->setScaleDiv(scaleEngineY->transformation(),scaleDivY);
01189
01190
01191 setMinimumSize(scaleWidgetsFixedWidth + imageArea->minimumWidth() + 1,
01192 scaleWidgetsFixedWidth + imageArea->minimumHeight() + 1 +
01193 statusBarWidgetFixedHeight);
01194
01195
01196
01197 setMaximumSize(scaleWidgetsFixedWidth+zoom*imageArea->origwidth + 1,
01198 scaleWidgetsFixedWidth+zoom*imageArea->origheight + 1 +
01199 statusBarWidgetFixedHeight);
01200
01201 resize(scaleWidgetsFixedWidth+width+1,
01202 scaleWidgetsFixedWidth+height+1+statusBarWidgetFixedHeight);
01203
01204
01205
01206
01207 scaleWidgetX->setGeometry(0,0,
01208 2*scaleWidgetsFixedWidth+width+1,scaleWidgetsFixedWidth);
01209 scaleWidgetY->setGeometry(0,0,
01210 scaleWidgetsFixedWidth,2*scaleWidgetsFixedWidth+height+1);
01211
01212 statusBar->setGeometry(
01213 0,scaleWidgetsFixedWidth+height+1,
01214 scaleWidgetsFixedWidth+width+1,statusBarWidgetFixedHeight);
01215
01216 statusBar->showMessage(statusMessage());
01217 }
01218 #endif
01219