summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-16 07:39:26 (UTC)
committer alwin <alwin>2004-04-16 07:39:26 (UTC)
commit9692c199f1f8b4c334687081e0d75bfbf9375ad8 (patch) (unidiff)
tree3ab64a3de58d5f266229d99d0eeae20a1d49f254
parent7c29eeaecc8301fb500851382b3d94092ae72719 (diff)
downloadopie-9692c199f1f8b4c334687081e0d75bfbf9375ad8.zip
opie-9692c199f1f8b4c334687081e0d75bfbf9375ad8.tar.gz
opie-9692c199f1f8b4c334687081e0d75bfbf9375ad8.tar.bz2
- displaying a busy makes no sense here. It results in double paintings
- method to set autoscale/autorotate at once
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiemm/oimagescrollview.cpp31
-rw-r--r--libopie2/opiemm/oimagescrollview.h13
2 files changed, 19 insertions, 25 deletions
diff --git a/libopie2/opiemm/oimagescrollview.cpp b/libopie2/opiemm/oimagescrollview.cpp
index 30a8fba..61b2062 100644
--- a/libopie2/opiemm/oimagescrollview.cpp
+++ b/libopie2/opiemm/oimagescrollview.cpp
@@ -1,34 +1,33 @@
1#include "oimagescrollview.h" 1#include "oimagescrollview.h"
2 2
3#include <opie2/oimagezoomer.h> 3#include <opie2/oimagezoomer.h>
4#include <opie2/odebug.h> 4#include <opie2/odebug.h>
5#include <opie2/oapplication.h> 5#include <opie2/oapplication.h>
6#include <opie2/owait.h> 6#include <opie2/owait.h>
7 7
8#include <qimage.h> 8#include <qimage.h>
9#include <qlayout.h> 9#include <qlayout.h>
10#include <qpe/qcopenvelope_qws.h>
11 10
12/* for usage with the bitset */ 11/* for usage with the bitset */
13#define AUTO_SCALE 0 12#define AUTO_SCALE 0
14#define AUTO_ROTATE 1 13#define AUTO_ROTATE 1
15#define SHOW_ZOOMER 2 14#define SHOW_ZOOMER 2
16#define FIRST_RESIZE_DONE 3 15#define FIRST_RESIZE_DONE 3
17#define IMAGE_IS_JPEG 4 16#define IMAGE_IS_JPEG 4
18#define IMAGE_SCALED_LOADED 5 17#define IMAGE_SCALED_LOADED 5
19 18
20#define SCROLLVIEW_BITSET_SIZE 6 19#define SCROLLVIEW_BITSET_SIZE 6
21 20
22namespace Opie { 21namespace Opie {
23namespace MM { 22namespace MM {
24OImageScrollView::OImageScrollView( QWidget* parent, const char* name, WFlags f ) 23OImageScrollView::OImageScrollView( QWidget* parent, const char* name, WFlags f )
25 :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(), 24 :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),
26 m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") 25 m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("")
27{ 26{
28 _zoomer = 0; 27 _zoomer = 0;
29 m_states[AUTO_SCALE]=true; 28 m_states[AUTO_SCALE]=true;
30 m_states[AUTO_ROTATE]=true; 29 m_states[AUTO_ROTATE]=true;
31 m_states[FIRST_RESIZE_DONE]=false; 30 m_states[FIRST_RESIZE_DONE]=false;
32 m_states[IMAGE_IS_JPEG]=false; 31 m_states[IMAGE_IS_JPEG]=false;
33 m_states[IMAGE_SCALED_LOADED]=false; 32 m_states[IMAGE_SCALED_LOADED]=false;
34 m_states[SHOW_ZOOMER]=true; 33 m_states[SHOW_ZOOMER]=true;
@@ -89,81 +88,67 @@ void OImageScrollView::loadJpeg(bool interncall)
89 if (AutoScale()) { 88 if (AutoScale()) {
90 if (!interncall) { 89 if (!interncall) {
91 int wid, hei; 90 int wid, hei;
92 wid = QApplication::desktop()->width(); 91 wid = QApplication::desktop()->width();
93 hei = QApplication::desktop()->height(); 92 hei = QApplication::desktop()->height();
94 if (hei>wid) { 93 if (hei>wid) {
95 wid = hei; 94 wid = hei;
96 } else { 95 } else {
97 hei = wid; 96 hei = wid;
98 } 97 }
99 param = QString( "Fast Shrink( 3 ) Scale( %1, %2, ScaleMin)" ).arg( wid ).arg( hei ); 98 param = QString( "Fast Shrink( 3 ) Scale( %1, %2, ScaleMin)" ).arg( wid ).arg( hei );
100 odebug << "Load jpeg scaled \"" << param << "\"" << oendl; 99 odebug << "Load jpeg scaled \"" << param << "\"" << oendl;
101 iio.setParameters(param.latin1()); 100 iio.setParameters(param.latin1());
102 setImageScaledLoaded(true); 101 setImageScaledLoaded(true);
103 real_load = true; 102 real_load = true;
104 } 103 }
105 } else { 104 } else {
106 if (ImageScaledLoaded()||!interncall) { 105 if (ImageScaledLoaded()||!interncall) {
107 odebug << "Load jpeg unscaled" << oendl; 106 odebug << "Load jpeg unscaled" << oendl;
108 real_load = true; 107 real_load = true;
109 } 108 }
110 setImageScaledLoaded(false); 109 setImageScaledLoaded(false);
111 } 110 }
112 if (real_load) { 111 if (real_load) {
113 {
114 QCopEnvelope( "QPE/System", "busy()" );
115 }
116 _original_data = iio.read() ? iio.image() : QImage(); 112 _original_data = iio.read() ? iio.image() : QImage();
117 {
118 QCopEnvelope env( "QPE/System", "notBusy(QString)" );
119 env << "Image loaded";
120 }
121 } 113 }
122} 114}
123 115
124void OImageScrollView::setImage( const QString& path ) { 116void OImageScrollView::setImage( const QString& path ) {
125 odebug << "load new image " << oendl; 117 odebug << "load new image " << oendl;
126 if (m_lastName == path) return; 118 if (m_lastName == path) return;
127 m_lastName = path; 119 m_lastName = path;
128 _original_data = QImage(); 120 _original_data = QImage();
129 QString itype = QImage::imageFormat(m_lastName); 121 QString itype = QImage::imageFormat(m_lastName);
130 odebug << "Image type = " << itype << oendl; 122 odebug << "Image type = " << itype << oendl;
131 if (itype == "JPEG") { 123 if (itype == "JPEG") {
132 setImageIsJpeg(true); 124 setImageIsJpeg(true);
133 loadJpeg(); 125 loadJpeg();
134 } else { 126 } else {
135 {
136 QCopEnvelope( "QPE/System", "busy()" );
137 }
138 setImageIsJpeg(false); 127 setImageIsJpeg(false);
139 _original_data.load(path); 128 _original_data.load(path);
140 _original_data.convertDepth(QPixmap::defaultDepth()); 129 _original_data.convertDepth(QPixmap::defaultDepth());
141 _original_data.setAlphaBuffer(false); 130 _original_data.setAlphaBuffer(false);
142 {
143 QCopEnvelope env( "QPE/System", "notBusy(QString)" );
144 env << "Image loaded";
145 }
146 } 131 }
147 _image_data = QImage(); 132 _image_data = QImage();
148 if (FirstResizeDone()) { 133 if (FirstResizeDone()) {
149 generateImage(); 134 generateImage();
150 if (isVisible()) viewport()->repaint(true); 135 if (isVisible()) viewport()->repaint(true);
151 } 136 }
152} 137}
153 138
154/* should be called every time the QImage changed it content */ 139/* should be called every time the QImage changed it content */
155void OImageScrollView::init() 140void OImageScrollView::init()
156{ 141{
157 odebug << "init " << oendl; 142 odebug << "init " << oendl;
158 143
159 /* 144 /*
160 * create the zoomer 145 * create the zoomer
161 * and connect ther various signals 146 * and connect ther various signals
162 */ 147 */
163 _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); 148 _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" );
164 connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), 149 connect(_zoomer, SIGNAL( zoomAreaRel(int,int)),
165 this, SLOT(scrollBy(int,int)) ); 150 this, SLOT(scrollBy(int,int)) );
166 connect(_zoomer, SIGNAL( zoomArea(int,int)), 151 connect(_zoomer, SIGNAL( zoomArea(int,int)),
167 this, SLOT(center(int,int)) ); 152 this, SLOT(center(int,int)) );
168 connect(this,SIGNAL(contentsMoving(int,int)), 153 connect(this,SIGNAL(contentsMoving(int,int)),
169 _zoomer, (SLOT(setVisiblePoint(int,int))) ); 154 _zoomer, (SLOT(setVisiblePoint(int,int))) );
@@ -179,54 +164,57 @@ void OImageScrollView::init()
179 if (FirstResizeDone()) { 164 if (FirstResizeDone()) {
180 m_last_rot = Rotate0; 165 m_last_rot = Rotate0;
181 generateImage(); 166 generateImage();
182 } else if (_original_data.size().isValid()) { 167 } else if (_original_data.size().isValid()) {
183 if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide(); 168 if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide();
184 resizeContents(_original_data.width(),_original_data.height()); 169 resizeContents(_original_data.width(),_original_data.height());
185 } 170 }
186} 171}
187 172
188void OImageScrollView::setAutoRotate(bool how) 173void OImageScrollView::setAutoRotate(bool how)
189{ 174{
190 /* to avoid double repaints */ 175 /* to avoid double repaints */
191 if (AutoRotate() != how) { 176 if (AutoRotate() != how) {
192 m_states.setBit(AUTO_ROTATE,how); 177 m_states.setBit(AUTO_ROTATE,how);
193 _image_data = QImage(); 178 _image_data = QImage();
194 generateImage(); 179 generateImage();
195 } 180 }
196} 181}
197 182
198bool OImageScrollView::AutoRotate()const 183bool OImageScrollView::AutoRotate()const
199{ 184{
200 return m_states.testBit(AUTO_ROTATE); 185 return m_states.testBit(AUTO_ROTATE);
201} 186}
202 187
188void OImageScrollView::setAutoScaleRotate(bool scale, bool rotate)
189{
190 m_states.setBit(AUTO_ROTATE,rotate);
191 setAutoScale(scale);
192}
193
203void OImageScrollView::setAutoScale(bool how) 194void OImageScrollView::setAutoScale(bool how)
204{ 195{
205 m_states.setBit(AUTO_SCALE,how); 196 m_states.setBit(AUTO_SCALE,how);
206 if (!how) {
207 setAutoRotate(false);
208 }
209 _image_data = QImage(); 197 _image_data = QImage();
210 if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) { 198 if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) {
211 loadJpeg(true); 199 loadJpeg(true);
212 } 200 }
213 generateImage(); 201 generateImage();
214} 202}
215 203
216bool OImageScrollView::AutoScale()const 204bool OImageScrollView::AutoScale()const
217{ 205{
218 return m_states.testBit(AUTO_SCALE); 206 return m_states.testBit(AUTO_SCALE);
219} 207}
220 208
221OImageScrollView::~OImageScrollView() 209OImageScrollView::~OImageScrollView()
222{ 210{
223} 211}
224 212
225void OImageScrollView::rescaleImage(int w, int h) 213void OImageScrollView::rescaleImage(int w, int h)
226{ 214{
227 if (_image_data.width()==w && _image_data.height()==h) { 215 if (_image_data.width()==w && _image_data.height()==h) {
228 return; 216 return;
229 } 217 }
230 double hs = (double)h / (double)_image_data.height() ; 218 double hs = (double)h / (double)_image_data.height() ;
231 double ws = (double)w / (double)_image_data.width() ; 219 double ws = (double)w / (double)_image_data.width() ;
232 double scaleFactor = (hs > ws) ? ws : hs; 220 double scaleFactor = (hs > ws) ? ws : hs;
@@ -337,102 +325,95 @@ void OImageScrollView::rotate_into_data(Rotation r)
337 { 325 {
338 destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); 326 destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1);
339 destData[y] = srcData[x]; 327 destData[y] = srcData[x];
340 } 328 }
341 } 329 }
342 break; 330 break;
343 default: 331 default:
344 dest = _original_data; 332 dest = _original_data;
345 break; 333 break;
346 } 334 }
347 335
348 } 336 }
349 _image_data = dest; 337 _image_data = dest;
350} 338}
351 339
352void OImageScrollView::generateImage() 340void OImageScrollView::generateImage()
353{ 341{
354 Rotation r = Rotate0; 342 Rotation r = Rotate0;
355 _pdata = QPixmap(); 343 _pdata = QPixmap();
356 if (_original_data.isNull()) { 344 if (_original_data.isNull()) {
357 emit imageSizeChanged( _image_data.size() ); 345 emit imageSizeChanged( _image_data.size() );
358 if (_zoomer) _zoomer->setImage( _image_data ); 346 if (_zoomer) _zoomer->setImage( _image_data );
359 return; 347 return;
360 } 348 }
361 {
362 QCopEnvelope( "QPE/System", "busy()" );
363 }
364 if (width()>height()&&_original_data.width()<_original_data.height() || 349 if (width()>height()&&_original_data.width()<_original_data.height() ||
365 width()<height()&&_original_data.width()>_original_data.height()) { 350 width()<height()&&_original_data.width()>_original_data.height()) {
366 if (AutoRotate()) r = Rotate90; 351 if (AutoRotate()) r = Rotate90;
367 } 352 }
368 353
369 354
370 odebug << " r = " << r << oendl; 355 odebug << " r = " << r << oendl;
371 if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) { 356 if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) {
372 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()) {
373 odebug << "Rescaling data" << oendl; 358 odebug << "Rescaling data" << oendl;
374 if (r==Rotate0) { 359 if (r==Rotate0) {
375 _image_data = _original_data; 360 _image_data = _original_data;
376 } else { 361 } else {
377 rotate_into_data(r); 362 rotate_into_data(r);
378 } 363 }
379 } 364 }
380 rescaleImage(width(),height()); 365 rescaleImage(width(),height());
381 resizeContents(_image_data.width(),_image_data.height()); 366 resizeContents(_image_data.width(),_image_data.height());
382 } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) { 367 } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) {
383 if (r==Rotate0) { 368 if (r==Rotate0) {
384 _image_data = _original_data; 369 _image_data = _original_data;
385 } else { 370 } else {
386 rotate_into_data(r); 371 rotate_into_data(r);
387 } 372 }
388 m_last_rot = r; 373 m_last_rot = r;
389 resizeContents(_image_data.width(),_image_data.height()); 374 resizeContents(_image_data.width(),_image_data.height());
390 } 375 }
391 _pdata.convertFromImage(_image_data); 376 _pdata.convertFromImage(_image_data);
392 377
393 /* 378 /*
394 * update the zoomer 379 * update the zoomer
395 */ 380 */
396 check_zoomer(); 381 check_zoomer();
397 emit imageSizeChanged( _image_data.size() ); 382 emit imageSizeChanged( _image_data.size() );
398 rescaleImage( 128, 128 ); 383 rescaleImage( 128, 128 );
399 /* 384 /*
400 * move scrollbar 385 * move scrollbar
401 */ 386 */
402 if (_zoomer) { 387 if (_zoomer) {
403 _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, 388 _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2,
404 _image_data.width()/2, _image_data.height()/2 ); 389 _image_data.width()/2, _image_data.height()/2 );
405 _zoomer->setImage( _image_data ); 390 _zoomer->setImage( _image_data );
406 } 391 }
407 /* 392 /*
408 * invalidate 393 * invalidate
409 */ 394 */
410 _image_data=QImage(); 395 _image_data=QImage();
411 {
412 QCopEnvelope env( "QPE/System", "notBusy(QString)" );
413 env << "Image generated";
414 }
415} 396}
416 397
417void OImageScrollView::resizeEvent(QResizeEvent * e) 398void OImageScrollView::resizeEvent(QResizeEvent * e)
418{ 399{
419 odebug << "OImageScrollView resizeEvent" << oendl; 400 odebug << "OImageScrollView resizeEvent" << oendl;
420 QScrollView::resizeEvent(e); 401 QScrollView::resizeEvent(e);
421 generateImage(); 402 generateImage();
422 setFirstResizeDone(true); 403 setFirstResizeDone(true);
423 emit viewportSizeChanged( viewport()->size() ); 404 emit viewportSizeChanged( viewport()->size() );
424 405
425} 406}
426 407
427void OImageScrollView::keyPressEvent(QKeyEvent * e) 408void OImageScrollView::keyPressEvent(QKeyEvent * e)
428{ 409{
429 if (!e) return; 410 if (!e) return;
430 int dx = horizontalScrollBar()->lineStep(); 411 int dx = horizontalScrollBar()->lineStep();
431 int dy = verticalScrollBar()->lineStep(); 412 int dy = verticalScrollBar()->lineStep();
432 if (e->key()==Qt::Key_Right) { 413 if (e->key()==Qt::Key_Right) {
433 scrollBy(dx,0); 414 scrollBy(dx,0);
434 e->accept(); 415 e->accept();
435 } else if (e->key()==Qt::Key_Left) { 416 } else if (e->key()==Qt::Key_Left) {
436 scrollBy(0-dx,0); 417 scrollBy(0-dx,0);
437 e->accept(); 418 e->accept();
438 } else if (e->key()==Qt::Key_Up) { 419 } else if (e->key()==Qt::Key_Up) {
diff --git a/libopie2/opiemm/oimagescrollview.h b/libopie2/opiemm/oimagescrollview.h
index 94fddb6..01a2d56 100644
--- a/libopie2/opiemm/oimagescrollview.h
+++ b/libopie2/opiemm/oimagescrollview.h
@@ -67,48 +67,61 @@ public:
67 /** 67 /**
68 * sets the WDestructiveClose flag to the view 68 * sets the WDestructiveClose flag to the view
69 */ 69 */
70 virtual void setDestructiveClose(); 70 virtual void setDestructiveClose();
71 71
72 /** 72 /**
73 * set if the image should be rotate to best fit 73 * set if the image should be rotate to best fit
74 * and repaint it if set to a new value. 74 * and repaint it if set to a new value.
75 * 75 *
76 * Be carefull - autorating real large images cost time! 76 * Be carefull - autorating real large images cost time!
77 * @param how if true then autorotate otherwise not 77 * @param how if true then autorotate otherwise not
78 */ 78 */
79 virtual void setAutoRotate(bool how); 79 virtual void setAutoRotate(bool how);
80 /** 80 /**
81 * set if the image should be scaled to the size of the viewport if larger(!) 81 * set if the image should be scaled to the size of the viewport if larger(!)
82 * 82 *
83 * if autoscaling is set when loading a jpeg image, it will use a feature of 83 * if autoscaling is set when loading a jpeg image, it will use a feature of
84 * jpeg lib to load the image scaled to display size. If switch of later the 84 * jpeg lib to load the image scaled to display size. If switch of later the
85 * image will reloaded. 85 * image will reloaded.
86 * 86 *
87 * @param how true - display image scaled down otherwise not 87 * @param how true - display image scaled down otherwise not
88 */ 88 */
89 virtual void setAutoScale(bool how); 89 virtual void setAutoScale(bool how);
90 /** 90 /**
91 * set if the image should be scaled to the size of the viewport if larger(!)
92 * and/or rotate to best fit. You avoid double repainting when you want to switch
93 * booth values.
94 *
95 * if autoscaling is set when loading a jpeg image, it will use a feature of
96 * jpeg lib to load the image scaled to display size. If switch of later the
97 * image will reloaded.
98 *
99 * @param scale true - display image scaled down otherwise not
100 * @param rotate true - the image will rotate for best fit
101 */
102 virtual void setAutoScaleRotate(bool scale, bool rotate);
103 /**
91 * set if there should be displayed a small zoomer widget at the right bottom of 104 * set if there should be displayed a small zoomer widget at the right bottom of
92 * the view when the image is larger than the viewport. 105 * the view when the image is larger than the viewport.
93 * 106 *
94 * @param how true - display zoomer 107 * @param how true - display zoomer
95 */ 108 */
96 virtual void setShowZoomer(bool how); 109 virtual void setShowZoomer(bool how);
97 110
98 /** 111 /**
99 * return the current value of the autorotate flag. 112 * return the current value of the autorotate flag.
100 */ 113 */
101 virtual bool AutoRotate()const; 114 virtual bool AutoRotate()const;
102 /** 115 /**
103 * return the current value of the autoscale flag. 116 * return the current value of the autoscale flag.
104 */ 117 */
105 virtual bool AutoScale()const; 118 virtual bool AutoScale()const;
106 /** 119 /**
107 * return the current value of the show zoomer flag. 120 * return the current value of the show zoomer flag.
108 */ 121 */
109 virtual bool ShowZoomer()const; 122 virtual bool ShowZoomer()const;
110 123
111public slots: 124public slots:
112 /** 125 /**
113 * Displays a new image, calculations will made immediately. 126 * Displays a new image, calculations will made immediately.
114 * 127 *