00001 #include "view.h" 00002 #include <qmessagebox.h> 00003 00004 View::Tool View::mTool = NO_TOOL; 00005 HistogramUser View::mGlbHistUser; 00006 00007 View::View( QWidget *parent ) : 00008 QWidget( parent, "", Qt::WRepaintNoErase | Qt::WResizeNoErase ) { 00009 init(); 00010 resize( 300, 300 ); 00011 } 00012 00013 View::View( QWidget *parent, Image *img, VectorLayerSet *vls ) : 00014 QWidget( parent, "", Qt::WRepaintNoErase | Qt::WResizeNoErase ) { 00015 init(); 00016 mImage = img; 00017 mLyrSet = vls; 00018 resize( 300, 300 ); 00019 } 00020 00021 View::~View( ) { 00022 delete mTimer; 00023 } 00024 00025 void View::init( ) { 00026 this->setMouseTracking( true ); 00027 00028 mImage = NULL; 00029 mCurImg = NULL; 00030 mCurScreen = NULL; 00031 mDspImg = true; 00032 mDspVec = true; 00033 mFullRedraw = true; 00034 mChildLinked = false; 00035 mParentLinked = false; 00036 mCTableNew = true; 00037 mPaning = false; 00038 00039 mLinkBox.moving = false; 00040 mLinkBox.dim.x = -1; 00041 mLinkBox.dim.y = -1; 00042 mLinkBox.dim.w = -1; 00043 mLinkBox.dim.h = -1; 00044 00045 mVirDims.x = 0; 00046 mVirDims.y = 0; 00047 mVirDims.w = 0; 00048 mVirDims.h = 0; 00049 00050 mSelBox.x = 0; 00051 mSelBox.y = 0; 00052 mSelBox.w = 0; 00053 mSelBox.h = 0; 00054 00055 mMouse.mLeftButDown = false; 00056 mMouse.mRightButDown = false; 00057 mMouse.mMidButDown = false; 00058 00059 mSclType = ImageFormat::SCALE_NN; 00060 00061 this->setBackgroundColor( QColor( 0,0,0 ) ); 00062 mTimer = new QTimer( this ); 00063 connect( mTimer, SIGNAL( timeout() ), this, SLOT( timerDone() ) ); 00064 } 00065 00066 void View::initView( ) { 00067 mImage = NULL; 00068 resetView(); 00069 00070 disconnect( this, SIGNAL( viewMouseMove( QMouseEvent *, View::MouseState & ) ) ); 00071 disconnect( this, SIGNAL( viewMousePress( QMouseEvent *, View::MouseState & ) ) ); 00072 disconnect( this, SIGNAL( viewMouseRelease( QMouseEvent *, View::MouseState & ) ) ); 00073 disconnect( this, SIGNAL( viewKeyPress( QKeyEvent * ) ) ); 00074 disconnect( this, SIGNAL( viewKeyRelease( QKeyEvent * ) ) ); 00075 // disconnect( this, SIGNAL( viewPaintEvent( QPainter &, Rect & ) ) ); 00076 00077 repaint( true ); 00078 } 00079 00080 void View::resetView( ) { 00081 if ( mCurImg ) 00082 delete mCurImg; 00083 mCurImg = NULL; 00084 00085 mFullRedraw = true; 00086 00087 mLinkBox.moving = false; 00088 mLinkBox.dim.x = -1; 00089 mLinkBox.dim.y = -1; 00090 mLinkBox.dim.w = -1; 00091 mLinkBox.dim.h = -1; 00092 00093 mVirDims.x = 0; 00094 mVirDims.y = 0; 00095 mVirDims.w = 0; 00096 mVirDims.h = 0; 00097 //repaint( false ); 00098 } 00099 00100 void View::setImage( Image *img ) { 00101 if ( img == NULL ) 00102 return; 00103 00104 mImage = img; 00105 calcDims(); 00106 } 00107 00108 void View::setLinkChild( View *parentlink ) { 00109 disconnect( this, SLOT( setLinkLimits( Rect ) ) ); 00110 disconnect( this, SLOT( setVirDims( Rect ) ) ); 00111 00112 connect( parentlink, 00113 SIGNAL( parentVirDimsChanged( Rect ) ), 00114 this, 00115 SLOT( setLinkLimits( Rect ) ) ); 00116 00117 connect( parentlink, 00118 SIGNAL( parentLinkBoxChanged( Rect ) ), 00119 this, 00120 SLOT( setVirDims( Rect ) ) ); 00121 00122 mLinkLimits = parentlink->getVirDims(); 00123 mParentLinked = true; 00124 mState.mParentName = parentlink->getViewState().mName; 00125 } 00126 00127 void View::setLinkParent( View *childlink ) { 00128 disconnect( this, SLOT( setLinkBoxDims( Rect ) ) ); 00129 00130 connect( childlink, 00131 SIGNAL( childVirDimsChanged( Rect ) ), 00132 this, 00133 SLOT( setLinkBoxDims( Rect ) ) ); 00134 00135 mLinkBox.dim = childlink->getVirDims(); 00136 mChildLinked = true; 00137 mState.mChildName = childlink->getViewState().mName; 00138 00139 } 00140 00141 void View::setLinkLimits( Rect d ) { 00142 mLinkLimits = d; 00143 } 00144 00145 void View::setVirDims( Rect d ) { 00146 if ( mChildLinked ) { 00147 mLinkBox.dim.x += (d.x - mVirDims.x); 00148 mLinkBox.dim.y += (d.y - mVirDims.y); 00149 emit parentLinkBoxChanged( mLinkBox.dim ); 00150 } 00151 mVirDims = d; 00152 mFullRedraw = true; 00153 repaint( false ); 00154 } 00155 00156 void View::setLinkBoxDims( Rect d ) { 00157 mLinkBox.dim = d; 00158 repaint( false ); 00159 } 00160 00161 void View::setZoomAttr( ZoomAttr attr ) { 00162 mState.mZoom = attr; 00163 00164 switch ( mState.mZoom.type ) { 00165 case ZoomAttr::SCALE: 00166 case ZoomAttr::FIXED: 00167 mVirDims.x = 0; 00168 mVirDims.y = 0; 00169 mDspDims.x = 0; 00170 mDspDims.y = 0; 00171 mDspDims.w = this->width(); 00172 mDspDims.h = this->height(); 00173 calcDims(); 00174 mFullRedraw = true; 00175 repaint( false ); 00176 break; 00177 00178 default: 00179 break; 00180 } 00181 } 00182 00183 ZoomAttr* View::getZoomAttr( ) const { 00184 return(ZoomAttr*)&mState.mZoom; 00185 } 00186 00187 void View::paintEvent( QPaintEvent * ) { 00188 if ( mImage == NULL || mImage->getImageState().mRed == -1 ) 00189 return; 00190 00191 QPixmap bufpm( width(), height() ); 00192 QPainter p( &bufpm ); 00193 00194 p.fillRect( 0, 0, width(), height(), QBrush( black ) ); 00195 00196 if ( mFullRedraw ) { 00197 00198 if ( mCurImg ) { 00199 delete mCurImg; 00200 } 00201 00202 calcDims(); 00203 00204 switch ( mState.mZoom.type ) { 00205 case ZoomAttr::SCALE: 00206 case ZoomAttr::FIXED: 00207 { 00208 Rect imgdim; 00209 int imgw = mImage->width(); 00210 int imgh = mImage->height(); 00211 00212 imgdim.x = ( mVirDims.x <= 0 ) ? 0 : mVirDims.x; 00213 imgdim.y = ( mVirDims.y <= 0 ) ? 0 : mVirDims.y; 00214 if ( imgdim.x + mVirDims.w > imgw ) 00215 imgdim.w = imgw - imgdim.x; 00216 else 00217 imgdim.w = mVirDims.w; 00218 if ( imgdim.y + mVirDims.h > imgh ) 00219 imgdim.h = imgh - imgdim.y; 00220 else 00221 imgdim.h = mVirDims.h; 00222 00223 if ( imgdim.w <= 0 || imgdim.h <= 0 ) 00224 mCurImg = new QImage; 00225 else { 00226 QApplication::setOverrideCursor( Qt::waitCursor, true ); 00227 mCurImg = mImage->getRect( (int)imgdim.x, 00228 (int)imgdim.y, 00229 (int)imgdim.w, 00230 (int)imgdim.h, 00231 (int)(imgdim.w * mState.mZoom.factor), 00232 (int)(imgdim.h * mState.mZoom.factor), 00233 mSclType ); 00234 QApplication::restoreOverrideCursor(); 00235 } 00236 00237 mDspDims.x = ( imgdim.x - mVirDims.x ) * mState.mZoom.factor; 00238 mDspDims.y = ( imgdim.y - mVirDims.y ) * mState.mZoom.factor; 00239 00240 } break; 00241 00242 case ZoomAttr::WHOLE: 00243 { 00244 QApplication::setOverrideCursor( Qt::waitCursor, true ); 00245 mCurImg = mImage->getRect( 0, 00246 0, 00247 mImage->width(), 00248 mImage->height(), 00249 (int)mDspDims.w, 00250 (int)mDspDims.h, 00251 mSclType ); 00252 QApplication::restoreOverrideCursor(); 00253 } break; 00254 00255 default: 00256 break; 00257 } 00258 00259 mCTableNew = true; 00260 mFullRedraw = false; 00261 00262 emit childVirDimsChanged( mVirDims ); 00263 emit parentVirDimsChanged( mVirDims ); 00264 mHistDlg->reloadHistSet(); 00265 } 00266 00267 if ( mCTableNew ) { 00268 QImage tmpimg = mCurImg->copy(); 00269 mGlbHistUser.scaleVal( tmpimg.bits(), 4 * tmpimg.width() * tmpimg.height() ); 00270 00271 if ( mCurScreen ) { 00272 delete mCurScreen; 00273 } 00274 mCurScreen = new QPixmap; 00275 00276 if (!mCurScreen || !(&tmpimg)) cout << QMessageBox::message("View::paintEvent", "mCurScreen or tmpimage is null") ; 00277 mCurScreen->convertFromImage( tmpimg ); 00278 mCTableNew = false; 00279 } 00280 00281 bitBlt( &bufpm, 00282 (int)mDspDims.x, 00283 (int)mDspDims.y, 00284 mCurScreen, 0, 0, 00285 mCurScreen->width(), mCurScreen->height() ); 00286 00287 Rect tmpVirDims = mVirDims; 00288 // if( mState.mZoom.type != WHOLE && (mDspDims.x !=0 || mDspDims.y != 0) ) 00289 if ( mPaning && !mLinkBox.moving ) { 00290 double vmsedifx = (mMouse.mCurPos.x - mMouse.mStartPos.x) / 00291 mState.mZoom.factor; 00292 double vmsedify = (mMouse.mCurPos.y - mMouse.mStartPos.y) / 00293 mState.mZoom.factor; 00294 00295 tmpVirDims.x -= vmsedifx; 00296 tmpVirDims.y -= vmsedify; 00297 } 00298 00299 p.save(); 00300 00301 for ( unsigned int ilyr=0; ilyr < mLyrSet->numLayers(); ilyr++ ) { 00302 mLyrSet->getLayer( ilyr )->draw( p, tmpVirDims, mState.mZoom.factor ); 00303 } 00304 00305 p.restore(); 00306 00307 if ( mChildLinked ) { 00308 Rect tmp = virDimToDsp( mLinkBox.dim ); 00309 p.setBrush( Qt::NoBrush ); 00310 p.setPen( red ); 00311 p.drawRect( (int)tmp.x, 00312 (int)tmp.y, 00313 (int)tmp.w, 00314 (int)tmp.h ); 00315 } 00316 00317 if ( mSelBox.w != 0 ) { 00318 Rect tmp = virDimToDsp( mSelBox ); 00319 p.setBrush( Qt::NoBrush ); 00320 p.setPen( QPen( QColor( 75,75,75 ), 1, Qt::SolidLine ) ); 00321 p.drawRect( (int)tmp.x, (int)tmp.y, (int)tmp.w, (int)tmp.h ); 00322 p.setPen( QPen( QColor( 200,200,200 ), 1, Qt::DashLine ) ); 00323 p.drawRect( (int)tmp.x, (int)tmp.y, (int)tmp.w, (int)tmp.h ); 00324 } 00325 00326 bitBlt( this, 0, 0, &bufpm, 0, 0, width(), height() ); 00327 00328 } 00329 00330 void View::fullRedraw( ) { 00331 mFullRedraw = true; 00332 repaint( false ); 00333 } 00334 00335 void View::calcDims( ) { 00336 00337 if ( mImage == NULL ) 00338 return; 00339 00340 int imgw = mImage->width(); 00341 int imgh = mImage->height(); 00342 int winw = this->width(); 00343 int winh = this->height(); 00344 00345 switch ( mState.mZoom.type ) { 00346 case ZoomAttr::SCALE: 00347 case ZoomAttr::FIXED: 00348 if ( mState.mZoom.factor == 0.0 ) break; 00349 mVirDims.w = winw / mState.mZoom.factor; 00350 mVirDims.h = winh / mState.mZoom.factor; 00351 break; 00352 00353 case ZoomAttr::FREE: 00354 break; 00355 00356 case ZoomAttr::WHOLE: 00357 { 00358 double scale1, scale2; 00359 scale1 = (double)winw / (double)imgw; 00360 scale2 = (double)winh / (double)imgh; 00361 00362 if ( scale1 < scale2 ) { 00363 mState.mZoom.factor = scale1; 00364 mDspDims.w = imgw * scale1; 00365 mDspDims.h = imgh * scale1; 00366 if ( (mDspDims.h/2) == 0 ) break; 00367 mDspDims.y = (winh/2) - (mDspDims.h/2); 00368 mDspDims.x = 0; 00369 00370 if ( scale1 == 0 ) break; 00371 mVirDims.w = winw / scale1; 00372 mVirDims.h = winh / scale1; 00373 mVirDims.x = 0; 00374 mVirDims.y = -( (mVirDims.h/2) - (imgh/2) ); 00375 } else { 00376 mState.mZoom.factor = scale2; 00377 mDspDims.w = imgw * scale2; 00378 mDspDims.h = imgh * scale2; 00379 mDspDims.y = 0; 00380 mDspDims.x = (winw/2)-(mDspDims.w/2); 00381 00382 if ( scale2 == 0 ) break; 00383 mVirDims.w = winw / scale2; 00384 mVirDims.h = winh / scale2; 00385 mVirDims.x = -( (mVirDims.w/2) - (imgw/2) ); 00386 mVirDims.y = 0; 00387 } 00388 } 00389 break; 00390 } 00391 } 00392 00393 void View::mouseMoveEvent( QMouseEvent *me ) { 00394 MousePos mvxy, ll; 00395 00396 mMouse.mCurPos.x = me->x(); 00397 mMouse.mCurPos.y = me->y(); 00398 00399 if ( !mImage ) 00400 return; 00401 00402 mvxy = mMouse.mCurPos; 00403 dspToVir( mvxy.x, mvxy.y ); 00404 ll = mvxy; 00405 00406 mImage->getLL( ll.x, ll.y ); 00407 00408 emit mousePosChanged( ll, mvxy ); 00409 00410 if ( mMouse.mLeftButDown && mLinkBox.moving ) { 00411 int mxdif = int( mvxy.x - mLinkBox.origpos.x); 00412 int mydif = int( mvxy.y - mLinkBox.origpos.y ); 00413 mLinkBox.dim.x = mLinkBox.origpos.x - mLinkBox.xoff + mxdif; 00414 mLinkBox.dim.y = mLinkBox.origpos.y - mLinkBox.yoff + mydif; 00415 if ( mLinkBox.dim.x < mVirDims.x ) 00416 mLinkBox.dim.x = mVirDims.x; 00417 if ( mLinkBox.dim.y < mVirDims.y ) 00418 mLinkBox.dim.y = mVirDims.y; 00419 if ( mLinkBox.dim.x + mLinkBox.dim.w > mVirDims.x + mVirDims.w ) 00420 mLinkBox.dim.x = mVirDims.x + mVirDims.w - mLinkBox.dim.w; 00421 if ( mLinkBox.dim.y + mLinkBox.dim.h > mVirDims.y + mVirDims.h ) 00422 mLinkBox.dim.y = mVirDims.y + mVirDims.h - mLinkBox.dim.h; 00423 00424 // mLinkBox.origpos = mLinkBox.dim; 00425 repaint( false ); 00426 00427 } 00428 00429 switch ( mTool ) { 00430 case PAN_HAND: 00431 switch ( mState.mZoom.type ) { 00432 case ZoomAttr::SCALE: 00433 case ZoomAttr::FIXED: 00434 if ( mMouse.mLeftButDown && !mLinkBox.moving ) { 00435 mDspDims.x += (mMouse.mCurPos.x - mMouse.mLastPos.x); 00436 mDspDims.y += (mMouse.mCurPos.y - mMouse.mLastPos.y); 00437 00438 repaint( false ); 00439 } 00440 break; 00441 00442 default: 00443 break; 00444 } 00445 break; 00446 00447 default: 00448 break; 00449 } 00450 00451 mMouse.mLastPos.x = mMouse.mCurPos.x; 00452 mMouse.mLastPos.y = mMouse.mCurPos.y; 00453 00454 if ( mState.mEditable && !mLinkBox.moving ) { 00455 MouseState ms = mMouse; 00456 dspToVir( ms.mCurPos.x, ms.mCurPos.y ); 00457 dspToVir( ms.mLastPos.x, ms.mLastPos.y ); 00458 dspToVir( ms.mStartPos.x, ms.mStartPos.y ); 00459 00460 emit viewMouseMove( me, ms ); 00461 } 00462 } 00463 00464 void View::mousePressEvent( QMouseEvent *me ) { 00465 mMouse.mStartPos.x = mMouse.mCurPos.x; 00466 mMouse.mStartPos.y = mMouse.mCurPos.y; 00467 mMouse.mLastPos.x = mMouse.mCurPos.x; 00468 mMouse.mLastPos.y = mMouse.mCurPos.y; 00469 00470 if ( me->button() == LeftButton ) 00471 mMouse.mLeftButDown = true; 00472 else if ( me->button() == RightButton ) 00473 mMouse.mRightButDown = true; 00474 00475 00476 switch ( mTool ) { 00477 case PAN_HAND: 00478 { 00479 MousePos mvxy; 00480 mvxy = mMouse.mCurPos; 00481 dspToVir( mvxy.x, mvxy.y ); 00482 if ( mvxy.x > mLinkBox.dim.x && 00483 mvxy.x < mLinkBox.dim.x + mLinkBox.dim.w && 00484 mvxy.y > mLinkBox.dim.y && 00485 mvxy.y < mLinkBox.dim.y + mLinkBox.dim.h ) { 00486 mLinkBox.moving = true; 00487 mLinkBox.origpos = mLinkBox.dim; 00488 mLinkBox.xoff = (int)(mvxy.x - mLinkBox.dim.x); 00489 mLinkBox.yoff = (int)(mvxy.y - mLinkBox.dim.y); 00490 } else { 00491 mPaning = true; 00492 } 00493 break; 00494 } 00495 case ZOOMOUT_INC: 00496 switch ( mState.mZoom.type ) { 00497 case ZoomAttr::FREE: 00498 case ZoomAttr::SCALE: 00499 { 00500 MousePos vmp = mMouse.mCurPos; 00501 dspToVir( vmp.x, vmp.y ); 00502 if ( mState.mZoom.factor > 2.0 ) 00503 mState.mZoom.factor -= 1.0; 00504 else if ( mState.mZoom.factor > 1.0 ) 00505 mState.mZoom.factor = 1.0; 00506 else 00507 mState.mZoom.factor -= 0.1; 00508 00509 if ( mState.mZoom.factor <= 0.1 ) 00510 mState.mZoom.factor = 0.2; 00511 calcDims(); 00512 mFullRedraw = true; 00513 centerOn( vmp.x, vmp.y ); 00514 loadCaption(); 00515 } 00516 break; 00517 00518 default: 00519 break; 00520 } 00521 break; 00522 00523 case ZOOMIN_INC: 00524 switch ( mState.mZoom.type ) { 00525 case ZoomAttr::FREE: 00526 case ZoomAttr::SCALE: 00527 { 00528 MousePos vmp = mMouse.mCurPos; 00529 dspToVir( vmp.x, vmp.y ); 00530 if ( mState.mZoom.factor < 1.0 ) 00531 mState.mZoom.factor += 0.1; 00532 else 00533 mState.mZoom.factor += 1.0; 00534 if ( mState.mZoom.factor > 20 ) 00535 mState.mZoom.factor = 20; 00536 calcDims(); 00537 mFullRedraw = true; 00538 centerOn( vmp.x, vmp.y ); 00539 loadCaption(); 00540 } 00541 break; 00542 00543 default: 00544 break; 00545 } 00546 break; 00547 00548 default: 00549 break; 00550 } 00551 00552 if ( mState.mEditable && !mLinkBox.moving ) { 00553 MouseState ms = mMouse; 00554 dspToVir( ms.mCurPos.x, ms.mCurPos.y ); 00555 dspToVir( ms.mLastPos.x, ms.mLastPos.y ); 00556 dspToVir( ms.mStartPos.x, ms.mStartPos.y ); 00557 emit viewMousePress( me, ms ); 00558 } 00559 } 00560 00561 void View::mouseReleaseEvent( QMouseEvent *me ) { 00562 00563 mMouse.mLeftButDown = false; 00564 mMouse.mRightButDown = false; 00565 mMouse.mMidButDown = false; 00566 00567 switch ( mTool ) { 00568 case PAN_HAND: 00569 mPaning = false; 00570 switch ( mState.mZoom.type ) { 00571 case ZoomAttr::SCALE: 00572 case ZoomAttr::FIXED: 00573 { 00574 if ( !mLinkBox.moving ) { 00575 //int mousedifx = int( (mMouse.mCurPos.x - mMouse.mStartPos.x) / mState.mZoom.factor ); 00576 //int mousedify = int( (mMouse.mCurPos.y - mMouse.mStartPos.y) / mState.mZoom.factor ); 00577 double vmsedifx = (mMouse.mCurPos.x - mMouse.mStartPos.x) / 00578 mState.mZoom.factor; 00579 double vmsedify = (mMouse.mCurPos.y - mMouse.mStartPos.y) / 00580 mState.mZoom.factor; 00581 mVirDims.x -= vmsedifx; 00582 mVirDims.y -= vmsedify; 00583 if ( mVirDims.x + mVirDims.w > mLinkLimits.x + mLinkLimits.w ) 00584 mVirDims.x = mLinkLimits.x + mLinkLimits.w - mVirDims.w; 00585 if ( mVirDims.x < mLinkLimits.x ) 00586 mVirDims.x = mLinkLimits.x; 00587 if ( mVirDims.y + mVirDims.h > mLinkLimits.y + mLinkLimits.h ) 00588 mVirDims.y = mLinkLimits.y + mLinkLimits.h - mVirDims.h; 00589 if ( mVirDims.y < mLinkLimits.y ) 00590 mVirDims.y = mLinkLimits.y; 00591 00592 if ( mChildLinked ) { 00593 mLinkBox.dim.x -= vmsedifx; 00594 mLinkBox.dim.y -= vmsedify; 00595 if ( mLinkBox.dim.x < mVirDims.x ) 00596 mLinkBox.dim.x = mVirDims.x; 00597 if ( mLinkBox.dim.y < mVirDims.y ) 00598 mLinkBox.dim.y = mVirDims.y; 00599 if ( mLinkBox.dim.x + mLinkBox.dim.w > mVirDims.x + mVirDims.w ) 00600 mLinkBox.dim.x = mVirDims.x + mVirDims.w - mLinkBox.dim.w; 00601 if ( mLinkBox.dim.y + mLinkBox.dim.h > mVirDims.y + mVirDims.h ) 00602 mLinkBox.dim.y = mVirDims.y + mVirDims.h - mLinkBox.dim.h; 00603 emit parentLinkBoxChanged( mLinkBox.dim ); 00604 } 00605 calcDims(); 00606 mFullRedraw = true; 00607 repaint( false ); 00608 } 00609 } 00610 break; 00611 00612 default: 00613 break; 00614 } 00615 00616 break; 00617 00618 default: 00619 break; 00620 } 00621 00622 if ( mLinkBox.moving ) { 00623 mLinkBox.moving = false; 00624 emit parentLinkBoxChanged( mLinkBox.dim ); 00625 } else if ( mState.mEditable ) { 00626 MouseState ms = mMouse; 00627 dspToVir( ms.mCurPos.x, ms.mCurPos.y ); 00628 dspToVir( ms.mLastPos.x, ms.mLastPos.y ); 00629 dspToVir( ms.mStartPos.x, ms.mStartPos.y ); 00630 emit viewMouseRelease( me, ms ); 00631 } 00632 } 00633 00634 void View::resizeEvent( QResizeEvent * ) { 00635 // CALC NEW DSP/VIR DIMS 00636 calcDims(); 00637 if ( mTimer->isActive() ) 00638 mTimer->stop(); 00639 mTimer->start( 300, true ); 00640 loadCaption(); 00641 repaint( false ); 00642 } 00643 00644 void View::keyPressEvent( QKeyEvent *ke ) { 00645 if ( ke->key() == Qt::Key_C && (ke->state() & ControlButton) ) { 00646 MousePos tmp = mMouse.mCurPos; 00647 dspToVir( tmp.x, tmp.y ); 00648 centerOn( tmp.x, tmp.y ); 00649 } 00650 if ( mState.mEditable ) 00651 emit viewKeyPress( ke ); 00652 } 00653 00654 void View::keyReleaseEvent( QKeyEvent *ke ) { 00655 if ( mState.mEditable ) 00656 emit viewKeyRelease( ke ); 00657 } 00658 00659 char* View::getHistName( ) const { 00660 return(char*)mState.mName.c_str(); 00661 } 00662 00663 HistogramSet View::getHistSet( ) const { 00664 HistogramSet histset; 00665 00666 unsigned char *rdata, *gdata, *bdata, *imgdata; 00667 int len; 00668 00669 if ( mCurImg == NULL ) 00670 return histset; 00671 00672 QImage &img = *mCurImg;//->copy(); 00673 imgdata = img.bits(); 00674 00675 len = img.width() * img.height(); 00676 00677 rdata = new unsigned char[len]; 00678 gdata = NULL; 00679 bdata = NULL; 00680 00681 ImageState st = mImage->getImageState(); 00682 if ( !(st.mRed == st.mGreen && st.mGreen == st.mBlue ) ) { 00683 gdata = new unsigned char[len]; 00684 bdata = new unsigned char[len]; 00685 00686 for ( int i=0; i < len; i++ ) { 00687 rdata[i] = imgdata[(i*4)+2]; 00688 gdata[i] = imgdata[(i*4)+1]; 00689 bdata[i] = imgdata[(i*4)+0]; 00690 } 00691 } else { 00692 for ( int i=0; i < len; i++ ) 00693 rdata[i] = imgdata[(i*4)+2]; 00694 gdata = NULL; 00695 bdata = NULL; 00696 } 00697 00698 histset.setData( rdata, len, gdata, len, bdata, len ); 00699 delete [] rdata; 00700 delete [] gdata; 00701 delete [] bdata; 00702 00703 return histset; 00704 } 00705 00706 void View::timerDone( ) { 00707 loadCaption(); 00708 mFullRedraw = true; 00709 repaint( false ); 00710 } 00711 00712 const Rect& View::getVirDims( ) const { 00713 return mVirDims; 00714 } 00715 00716 void View::dspToVir( double &x, double &y ) { 00717 double scale = mState.mZoom.factor; 00718 00719 x = x / scale + mVirDims.x; 00720 y = y / scale + mVirDims.y; 00721 } 00722 00723 void View::virToDsp( double &x, double &y ) { 00724 double scale = mState.mZoom.factor; 00725 00726 x = ( x - mVirDims.x ) * scale; 00727 y = ( y - mVirDims.y ) * scale; 00728 } 00729 00730 void View::dspToVir( int &x, int &y ) { 00731 double dx, dy; 00732 dx = x; 00733 dy = y; 00734 dspToVir( dx, dy ); 00735 x = (int)dx; 00736 y = (int)dy; 00737 } 00738 00739 void View::virToDsp( int &x, int &y ) { 00740 double dx, dy; 00741 dx = x; 00742 dy = y; 00743 virToDsp( dx, dy ); 00744 x = (int)dx; 00745 y = (int)dy; 00746 } 00747 00748 Rect View::virDimToDsp( const Rect &d ) { 00749 double x1, y1, x2, y2; 00750 Rect dim = d; 00751 00752 x1 = dim.x; 00753 y1 = dim.y; 00754 x2 = (dim.x + dim.w); 00755 y2 = (dim.y + dim.h); 00756 00757 virToDsp( x1, y1 ); 00758 virToDsp( x2, y2 ); 00759 00760 dim.x = x1; 00761 dim.y = y1; 00762 dim.w = x2 - dim.x; 00763 dim.h = y2 - dim.y; 00764 00765 return dim; 00766 } 00767 00768 void View::selBoxChanged( Rect &dim ) { 00769 mSelBox = dim; 00770 } 00771 00772 void View::ctableChanged( ) { 00773 mCTableNew = true; 00774 repaint( false ); 00775 } 00776 00777 00778 void View::centerOn( double x, double y ) { 00779 double xdif = x - (mVirDims.x + mVirDims.w / 2.0); 00780 double ydif = y - (mVirDims.y + mVirDims.h / 2.0); 00781 00782 mLinkBox.dim.x += xdif; 00783 mLinkBox.dim.y += ydif; 00784 mVirDims.x += xdif; 00785 mVirDims.y += ydif; 00786 00787 emit parentLinkBoxChanged( mLinkBox.dim ); 00788 emit childVirDimsChanged( mVirDims ); 00789 emit parentVirDimsChanged( mVirDims ); 00790 mFullRedraw = true; 00791 repaint( false ); 00792 } 00793 00794 00795 00796 00797
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |