summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiemm/oimagescrollview.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/libopie2/opiemm/oimagescrollview.cpp b/libopie2/opiemm/oimagescrollview.cpp
index 61b2062..a8165a4 100644
--- a/libopie2/opiemm/oimagescrollview.cpp
+++ b/libopie2/opiemm/oimagescrollview.cpp
@@ -136,49 +136,49 @@ void OImageScrollView::setImage( const QString& path ) {
136 } 136 }
137} 137}
138 138
139/* should be called every time the QImage changed it content */ 139/* should be called every time the QImage changed it content */
140void OImageScrollView::init() 140void OImageScrollView::init()
141{ 141{
142 odebug << "init " << oendl; 142 odebug << "init " << oendl;
143 143
144 /* 144 /*
145 * create the zoomer 145 * create the zoomer
146 * and connect ther various signals 146 * and connect ther various signals
147 */ 147 */
148 _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); 148 _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" );
149 connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), 149 connect(_zoomer, SIGNAL( zoomAreaRel(int,int)),
150 this, SLOT(scrollBy(int,int)) ); 150 this, SLOT(scrollBy(int,int)) );
151 connect(_zoomer, SIGNAL( zoomArea(int,int)), 151 connect(_zoomer, SIGNAL( zoomArea(int,int)),
152 this, SLOT(center(int,int)) ); 152 this, SLOT(center(int,int)) );
153 connect(this,SIGNAL(contentsMoving(int,int)), 153 connect(this,SIGNAL(contentsMoving(int,int)),
154 _zoomer, (SLOT(setVisiblePoint(int,int))) ); 154 _zoomer, (SLOT(setVisiblePoint(int,int))) );
155 connect(this,SIGNAL(imageSizeChanged(const QSize&)), 155 connect(this,SIGNAL(imageSizeChanged(const QSize&)),
156 _zoomer, SLOT(setImageSize(const QSize&)) ); 156 _zoomer, SLOT(setImageSize(const QSize&)) );
157 connect(this,SIGNAL(viewportSizeChanged(const QSize&)), 157 connect(this,SIGNAL(viewportSizeChanged(const QSize&)),
158 _zoomer, SLOT(setViewPortSize(const QSize&)) ); 158 _zoomer, SLOT(setViewPortSize(const QSize&)) );
159 159
160 viewport()->setBackgroundColor(white); 160 setBackgroundColor(white);
161 setFocusPolicy(QWidget::StrongFocus); 161 setFocusPolicy(QWidget::StrongFocus);
162 setImageScaledLoaded(false); 162 setImageScaledLoaded(false);
163 setImageIsJpeg(false); 163 setImageIsJpeg(false);
164 if (FirstResizeDone()) { 164 if (FirstResizeDone()) {
165 m_last_rot = Rotate0; 165 m_last_rot = Rotate0;
166 generateImage(); 166 generateImage();
167 } else if (_original_data.size().isValid()) { 167 } else if (_original_data.size().isValid()) {
168 if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide(); 168 if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide();
169 resizeContents(_original_data.width(),_original_data.height()); 169 resizeContents(_original_data.width(),_original_data.height());
170 } 170 }
171} 171}
172 172
173void OImageScrollView::setAutoRotate(bool how) 173void OImageScrollView::setAutoRotate(bool how)
174{ 174{
175 /* to avoid double repaints */ 175 /* to avoid double repaints */
176 if (AutoRotate() != how) { 176 if (AutoRotate() != how) {
177 m_states.setBit(AUTO_ROTATE,how); 177 m_states.setBit(AUTO_ROTATE,how);
178 _image_data = QImage(); 178 _image_data = QImage();
179 generateImage(); 179 generateImage();
180 } 180 }
181} 181}
182 182
183bool OImageScrollView::AutoRotate()const 183bool OImageScrollView::AutoRotate()const
184{ 184{
@@ -330,153 +330,157 @@ void OImageScrollView::rotate_into_data(Rotation r)
330 break; 330 break;
331 default: 331 default:
332 dest = _original_data; 332 dest = _original_data;
333 break; 333 break;
334 } 334 }
335 335
336 } 336 }
337 _image_data = dest; 337 _image_data = dest;
338} 338}
339 339
340void OImageScrollView::generateImage() 340void OImageScrollView::generateImage()
341{ 341{
342 Rotation r = Rotate0; 342 Rotation r = Rotate0;
343 _pdata = QPixmap(); 343 _pdata = QPixmap();
344 if (_original_data.isNull()) { 344 if (_original_data.isNull()) {
345 emit imageSizeChanged( _image_data.size() ); 345 emit imageSizeChanged( _image_data.size() );
346 if (_zoomer) _zoomer->setImage( _image_data ); 346 if (_zoomer) _zoomer->setImage( _image_data );
347 return; 347 return;
348 } 348 }
349 if (width()>height()&&_original_data.width()<_original_data.height() || 349 if (width()>height()&&_original_data.width()<_original_data.height() ||
350 width()<height()&&_original_data.width()>_original_data.height()) { 350 width()<height()&&_original_data.width()>_original_data.height()) {
351 if (AutoRotate()) r = Rotate90; 351 if (AutoRotate()) r = Rotate90;
352 } 352 }
353 353
354 354 int twidth,theight;
355 odebug << " r = " << r << oendl; 355 odebug << " r = " << r << oendl;
356 if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) { 356 if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) {
357 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { 357 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) {
358 odebug << "Rescaling data" << oendl; 358 odebug << "Rescaling data" << oendl;
359 if (r==Rotate0) { 359 if (r==Rotate0) {
360 _image_data = _original_data; 360 _image_data = _original_data;
361 } else { 361 } else {
362 rotate_into_data(r); 362 rotate_into_data(r);
363 } 363 }
364 } 364 }
365 rescaleImage(width(),height()); 365 rescaleImage(width(),height());
366 resizeContents(_image_data.width(),_image_data.height());
367 } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) { 366 } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) {
368 if (r==Rotate0) { 367 if (r==Rotate0) {
369 _image_data = _original_data; 368 _image_data = _original_data;
370 } else { 369 } else {
371 rotate_into_data(r); 370 rotate_into_data(r);
372 } 371 }
373 m_last_rot = r; 372 m_last_rot = r;
374 resizeContents(_image_data.width(),_image_data.height());
375 } 373 }
376 _pdata.convertFromImage(_image_data); 374 _pdata.convertFromImage(_image_data);
375 twidth = _image_data.width();
376 theight = _image_data.height();
377 377
378 /* 378 /*
379 * update the zoomer 379 * update the zoomer
380 */ 380 */
381 check_zoomer(); 381 check_zoomer();
382 emit imageSizeChanged( _image_data.size() ); 382 emit imageSizeChanged( _image_data.size() );
383 rescaleImage( 128, 128 ); 383 rescaleImage( 128, 128 );
384 resizeContents(twidth,theight);
384 /* 385 /*
385 * move scrollbar 386 * move scrollbar
386 */ 387 */
387 if (_zoomer) { 388 if (_zoomer) {
388 _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, 389 _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2,
389 _image_data.width()/2, _image_data.height()/2 ); 390 _image_data.width()/2, _image_data.height()/2 );
390 _zoomer->setImage( _image_data ); 391 _zoomer->setImage( _image_data );
391 } 392 }
392 /* 393 /*
393 * invalidate 394 * invalidate
394 */ 395 */
395 _image_data=QImage(); 396 _image_data=QImage();
397 if (isVisible()) {
398 updateContents(contentsX(),contentsY(),width(),height());
399 }
396} 400}
397 401
398void OImageScrollView::resizeEvent(QResizeEvent * e) 402void OImageScrollView::resizeEvent(QResizeEvent * e)
399{ 403{
400 odebug << "OImageScrollView resizeEvent" << oendl; 404 odebug << "OImageScrollView resizeEvent" << oendl;
401 QScrollView::resizeEvent(e); 405 QScrollView::resizeEvent(e);
402 generateImage(); 406 generateImage();
403 setFirstResizeDone(true); 407 setFirstResizeDone(true);
404 emit viewportSizeChanged( viewport()->size() ); 408 emit viewportSizeChanged( viewport()->size() );
405 409
406} 410}
407 411
408void OImageScrollView::keyPressEvent(QKeyEvent * e) 412void OImageScrollView::keyPressEvent(QKeyEvent * e)
409{ 413{
410 if (!e) return; 414 if (!e) return;
411 int dx = horizontalScrollBar()->lineStep(); 415 int dx = horizontalScrollBar()->lineStep();
412 int dy = verticalScrollBar()->lineStep(); 416 int dy = verticalScrollBar()->lineStep();
413 if (e->key()==Qt::Key_Right) { 417 if (e->key()==Qt::Key_Right) {
414 scrollBy(dx,0); 418 scrollBy(dx,0);
415 e->accept(); 419 e->accept();
416 } else if (e->key()==Qt::Key_Left) { 420 } else if (e->key()==Qt::Key_Left) {
417 scrollBy(0-dx,0); 421 scrollBy(0-dx,0);
418 e->accept(); 422 e->accept();
419 } else if (e->key()==Qt::Key_Up) { 423 } else if (e->key()==Qt::Key_Up) {
420 scrollBy(0,0-dy); 424 scrollBy(0,0-dy);
421 e->accept(); 425 e->accept();
422 } else if (e->key()==Qt::Key_Down) { 426 } else if (e->key()==Qt::Key_Down) {
423 scrollBy(0,dy); 427 scrollBy(0,dy);
424 e->accept(); 428 e->accept();
425 } else { 429 } else {
426 e->ignore(); 430 e->ignore();
427 } 431 }
428 QScrollView::keyPressEvent(e); 432 QScrollView::keyPressEvent(e);
429} 433}
430 434
431void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) 435void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph)
432{ 436{
433 int w = clipw; 437 int w = clipw;
434 int h = cliph; 438 int h = cliph;
435 int x = clipx; 439 int x = clipx;
436 int y = clipy; 440 int y = clipy;
437 bool erase = false; 441 bool erase = false;
438 442
439 if (!_pdata.size().isValid()) { 443 if (!_pdata.size().isValid()) {
440 p->fillRect(clipx,clipy,clipw,cliph,white); 444 p->fillRect(clipx,clipy,clipw,cliph, backgroundColor());
441 return; 445 return;
442 } 446 }
443 if (w>_pdata.width()) { 447 if (w>_pdata.width()) {
444 w=_pdata.width(); 448 w=_pdata.width();
445 x = 0; 449 x = 0;
446 erase = true; 450 erase = true;
447 } else if (x+w>_pdata.width()){ 451 } else if (x+w>_pdata.width()){
448 x = _pdata.width()-w; 452 x = _pdata.width()-w;
449 } 453 }
450 if (h>_pdata.height()) { 454 if (h>_pdata.height()) {
451 h=_pdata.height(); 455 h=_pdata.height();
452 y = 0; 456 y = 0;
453 erase = true; 457 erase = true;
454 } else if (y+h>_pdata.height()){ 458 } else if (y+h>_pdata.height()){
455 y = _pdata.height()-h; 459 y = _pdata.height()-h;
456 } 460 }
457 if (erase||_original_data.hasAlphaBuffer()) { 461 if (erase||_original_data.hasAlphaBuffer()) {
458 p->fillRect(clipx,clipy,clipw,cliph,white); 462 p->fillRect(clipx,clipy,clipw,cliph, backgroundColor());
459 } 463 }
460 p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); 464 p->drawPixmap(clipx,clipy,_pdata,x,y,w,h);
461} 465}
462 466
463/* using the real geometry points and not the translated points is wanted! */ 467/* using the real geometry points and not the translated points is wanted! */
464void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) 468void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
465{ 469{
466 int mx, my; 470 int mx, my;
467 mx = e->x(); 471 mx = e->x();
468 my = e->y(); 472 my = e->y();
469 if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { 473 if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) {
470 int diffx = _mouseStartPosX-mx; 474 int diffx = _mouseStartPosX-mx;
471 int diffy = _mouseStartPosY-my; 475 int diffy = _mouseStartPosY-my;
472 scrollBy(diffx,diffy); 476 scrollBy(diffx,diffy);
473 } 477 }
474 _mouseStartPosX=mx; 478 _mouseStartPosX=mx;
475 _mouseStartPosY=my; 479 _mouseStartPosY=my;
476} 480}
477 481
478void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e) 482void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e)
479{ 483{
480 odebug << " X and Y " << e->x() << " " << e->y() << oendl; 484 odebug << " X and Y " << e->x() << " " << e->y() << oendl;
481 /* this marks the beginning of a possible mouse move. Due internal reasons of QT 485 /* this marks the beginning of a possible mouse move. Due internal reasons of QT
482 the geometry values here may real differ from that set in MoveEvent (I don't know 486 the geometry values here may real differ from that set in MoveEvent (I don't know