summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiemm/oimagescrollview.cpp30
1 files changed, 11 insertions, 19 deletions
diff --git a/libopie2/opiemm/oimagescrollview.cpp b/libopie2/opiemm/oimagescrollview.cpp
index 68b06af..30a8fba 100644
--- a/libopie2/opiemm/oimagescrollview.cpp
+++ b/libopie2/opiemm/oimagescrollview.cpp
@@ -87,25 +87,25 @@ void OImageScrollView::loadJpeg(bool interncall)
87 QString param; 87 QString param;
88 bool real_load = false; 88 bool real_load = false;
89 if (AutoScale()) { 89 if (AutoScale()) {
90 if (!interncall) { 90 if (!interncall) {
91 int wid, hei; 91 int wid, hei;
92 wid = QApplication::desktop()->width(); 92 wid = QApplication::desktop()->width();
93 hei = QApplication::desktop()->height(); 93 hei = QApplication::desktop()->height();
94 if (hei>wid) { 94 if (hei>wid) {
95 wid = hei; 95 wid = hei;
96 } else { 96 } else {
97 hei = wid; 97 hei = wid;
98 } 98 }
99 param = QString( "Fast Shrink( 3 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei ); 99 param = QString( "Fast Shrink( 3 ) Scale( %1, %2, ScaleMin)" ).arg( wid ).arg( hei );
100 odebug << "Load jpeg scaled \"" << param << "\"" << oendl; 100 odebug << "Load jpeg scaled \"" << param << "\"" << oendl;
101 iio.setParameters(param.latin1()); 101 iio.setParameters(param.latin1());
102 setImageScaledLoaded(true); 102 setImageScaledLoaded(true);
103 real_load = true; 103 real_load = true;
104 } 104 }
105 } else { 105 } else {
106 if (ImageScaledLoaded()||!interncall) { 106 if (ImageScaledLoaded()||!interncall) {
107 odebug << "Load jpeg unscaled" << oendl; 107 odebug << "Load jpeg unscaled" << oendl;
108 real_load = true; 108 real_load = true;
109 } 109 }
110 setImageScaledLoaded(false); 110 setImageScaledLoaded(false);
111 } 111 }
@@ -116,45 +116,47 @@ void OImageScrollView::loadJpeg(bool interncall)
116 _original_data = iio.read() ? iio.image() : QImage(); 116 _original_data = iio.read() ? iio.image() : QImage();
117 { 117 {
118 QCopEnvelope env( "QPE/System", "notBusy(QString)" ); 118 QCopEnvelope env( "QPE/System", "notBusy(QString)" );
119 env << "Image loaded"; 119 env << "Image loaded";
120 } 120 }
121 } 121 }
122} 122}
123 123
124void OImageScrollView::setImage( const QString& path ) { 124void OImageScrollView::setImage( const QString& path ) {
125 odebug << "load new image " << oendl; 125 odebug << "load new image " << oendl;
126 if (m_lastName == path) return; 126 if (m_lastName == path) return;
127 m_lastName = path; 127 m_lastName = path;
128 _original_data = QImage();
128 QString itype = QImage::imageFormat(m_lastName); 129 QString itype = QImage::imageFormat(m_lastName);
129 odebug << "Image type = " << itype << oendl; 130 odebug << "Image type = " << itype << oendl;
130 if (itype == "JPEG") { 131 if (itype == "JPEG") {
131 setImageIsJpeg(true); 132 setImageIsJpeg(true);
132 loadJpeg(); 133 loadJpeg();
133 } else { 134 } else {
134 { 135 {
135 QCopEnvelope( "QPE/System", "busy()" ); 136 QCopEnvelope( "QPE/System", "busy()" );
136 } 137 }
137 setImageIsJpeg(false); 138 setImageIsJpeg(false);
138 _original_data.load(path); 139 _original_data.load(path);
139 _original_data.convertDepth(QPixmap::defaultDepth()); 140 _original_data.convertDepth(QPixmap::defaultDepth());
140 _original_data.setAlphaBuffer(false); 141 _original_data.setAlphaBuffer(false);
141 { 142 {
142 QCopEnvelope env( "QPE/System", "notBusy(QString)" ); 143 QCopEnvelope env( "QPE/System", "notBusy(QString)" );
143 env << "Image loaded"; 144 env << "Image loaded";
144 } 145 }
145 } 146 }
146 _image_data = QImage(); 147 _image_data = QImage();
147 if (FirstResizeDone()) { 148 if (FirstResizeDone()) {
148 generateImage(); 149 generateImage();
150 if (isVisible()) viewport()->repaint(true);
149 } 151 }
150} 152}
151 153
152/* should be called every time the QImage changed it content */ 154/* should be called every time the QImage changed it content */
153void OImageScrollView::init() 155void OImageScrollView::init()
154{ 156{
155 odebug << "init " << oendl; 157 odebug << "init " << oendl;
156 158
157 /* 159 /*
158 * create the zoomer 160 * create the zoomer
159 * and connect ther various signals 161 * and connect ther various signals
160 */ 162 */
@@ -341,57 +343,62 @@ void OImageScrollView::rotate_into_data(Rotation r)
341 default: 343 default:
342 dest = _original_data; 344 dest = _original_data;
343 break; 345 break;
344 } 346 }
345 347
346 } 348 }
347 _image_data = dest; 349 _image_data = dest;
348} 350}
349 351
350void OImageScrollView::generateImage() 352void OImageScrollView::generateImage()
351{ 353{
352 Rotation r = Rotate0; 354 Rotation r = Rotate0;
353 if (_original_data.isNull()) return; 355 _pdata = QPixmap();
356 if (_original_data.isNull()) {
357 emit imageSizeChanged( _image_data.size() );
358 if (_zoomer) _zoomer->setImage( _image_data );
359 return;
360 }
354 { 361 {
355 QCopEnvelope( "QPE/System", "busy()" ); 362 QCopEnvelope( "QPE/System", "busy()" );
356 } 363 }
357 if (width()>height()&&_original_data.width()<_original_data.height() || 364 if (width()>height()&&_original_data.width()<_original_data.height() ||
358 width()<height()&&_original_data.width()>_original_data.height()) { 365 width()<height()&&_original_data.width()>_original_data.height()) {
359 if (AutoRotate()) r = Rotate90; 366 if (AutoRotate()) r = Rotate90;
360 } 367 }
361 368
369
362 odebug << " r = " << r << oendl; 370 odebug << " r = " << r << oendl;
363 if (AutoScale()) { 371 if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) {
364 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { 372 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) {
365 odebug << "Rescaling data" << oendl; 373 odebug << "Rescaling data" << oendl;
366 if (r==Rotate0) { 374 if (r==Rotate0) {
367 _image_data = _original_data; 375 _image_data = _original_data;
368 } else { 376 } else {
369 rotate_into_data(r); 377 rotate_into_data(r);
370 } 378 }
371 } 379 }
372 rescaleImage(width(),height()); 380 rescaleImage(width(),height());
373 resizeContents(_image_data.width(),_image_data.height()); 381 resizeContents(_image_data.width(),_image_data.height());
374 } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) { 382 } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) {
375 if (r==Rotate0) { 383 if (r==Rotate0) {
376 _image_data = _original_data; 384 _image_data = _original_data;
377 } else { 385 } else {
378 rotate_into_data(r); 386 rotate_into_data(r);
379 } 387 }
380 m_last_rot = r; 388 m_last_rot = r;
381 resizeContents(_image_data.width(),_image_data.height()); 389 resizeContents(_image_data.width(),_image_data.height());
382 } 390 }
383 _pdata.convertFromImage(_image_data); 391 _pdata.convertFromImage(_image_data);
384 392
385
386 /* 393 /*
387 * update the zoomer 394 * update the zoomer
388 */ 395 */
389 check_zoomer(); 396 check_zoomer();
390 emit imageSizeChanged( _image_data.size() ); 397 emit imageSizeChanged( _image_data.size() );
391 rescaleImage( 128, 128 ); 398 rescaleImage( 128, 128 );
392 /* 399 /*
393 * move scrollbar 400 * move scrollbar
394 */ 401 */
395 if (_zoomer) { 402 if (_zoomer) {
396 _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, 403 _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2,
397 _image_data.width()/2, _image_data.height()/2 ); 404 _image_data.width()/2, _image_data.height()/2 );
@@ -466,45 +473,30 @@ void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clip
466 } else if (y+h>_pdata.height()){ 473 } else if (y+h>_pdata.height()){
467 y = _pdata.height()-h; 474 y = _pdata.height()-h;
468 } 475 }
469 if (erase||_original_data.hasAlphaBuffer()) { 476 if (erase||_original_data.hasAlphaBuffer()) {
470 p->fillRect(clipx,clipy,clipw,cliph,white); 477 p->fillRect(clipx,clipy,clipw,cliph,white);
471 } 478 }
472 p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); 479 p->drawPixmap(clipx,clipy,_pdata,x,y,w,h);
473} 480}
474 481
475/* using the real geometry points and not the translated points is wanted! */ 482/* using the real geometry points and not the translated points is wanted! */
476void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) 483void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
477{ 484{
478 odebug << "Move X and Y " << e->x() << " " << e->y() << oendl;
479 int mx, my; 485 int mx, my;
480 mx = e->x(); 486 mx = e->x();
481 my = e->y(); 487 my = e->y();
482 if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { 488 if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) {
483 int diffx = _mouseStartPosX-mx; 489 int diffx = _mouseStartPosX-mx;
484 int diffy = _mouseStartPosY-my; 490 int diffy = _mouseStartPosY-my;
485#if 0
486 QScrollBar*xbar = horizontalScrollBar();
487 QScrollBar*ybar = verticalScrollBar();
488 if (xbar->value()+diffx>xbar->maxValue()) {
489 diffx = xbar->maxValue()-xbar->value();
490 } else if (xbar->value()+diffx<0) {
491 diffx=0-xbar->value();
492 }
493 if (ybar->value()+diffy>ybar->maxValue()) {
494 diffy = ybar->maxValue()-ybar->value();
495 } else if (ybar->value()+diffy<0) {
496 diffy=0-ybar->value();
497 }
498#endif
499 scrollBy(diffx,diffy); 491 scrollBy(diffx,diffy);
500 } 492 }
501 _mouseStartPosX=mx; 493 _mouseStartPosX=mx;
502 _mouseStartPosY=my; 494 _mouseStartPosY=my;
503} 495}
504 496
505void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e) 497void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e)
506{ 498{
507 odebug << " X and Y " << e->x() << " " << e->y() << oendl; 499 odebug << " X and Y " << e->x() << " " << e->y() << oendl;
508 /* this marks the beginning of a possible mouse move. Due internal reasons of QT 500 /* this marks the beginning of a possible mouse move. Due internal reasons of QT
509 the geometry values here may real differ from that set in MoveEvent (I don't know 501 the geometry values here may real differ from that set in MoveEvent (I don't know
510 why). For getting them in real context, we use the first move-event to set the start 502 why). For getting them in real context, we use the first move-event to set the start