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