summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiemm/oimagescrollview.cpp30
1 files changed, 14 insertions, 16 deletions
diff --git a/libopie2/opiemm/oimagescrollview.cpp b/libopie2/opiemm/oimagescrollview.cpp
index 58a9748..10da823 100644
--- a/libopie2/opiemm/oimagescrollview.cpp
+++ b/libopie2/opiemm/oimagescrollview.cpp
@@ -44,176 +44,170 @@ OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const ch
44 m_states[AUTO_SCALE]=always_scale; 44 m_states[AUTO_SCALE]=always_scale;
45 m_states[AUTO_ROTATE]=rfit; 45 m_states[AUTO_ROTATE]=rfit;
46 m_states[FIRST_RESIZE_DONE]=false; 46 m_states[FIRST_RESIZE_DONE]=false;
47 m_states[IMAGE_IS_JPEG]=false; 47 m_states[IMAGE_IS_JPEG]=false;
48 m_states[IMAGE_SCALED_LOADED]=false; 48 m_states[IMAGE_SCALED_LOADED]=false;
49 m_states[SHOW_ZOOMER]=true; 49 m_states[SHOW_ZOOMER]=true;
50 _original_data.convertDepth(QPixmap::defaultDepth()); 50 _original_data.convertDepth(QPixmap::defaultDepth());
51 _original_data.setAlphaBuffer(false); 51 _original_data.setAlphaBuffer(false);
52 _newImage = true; 52 _newImage = true;
53 init(); 53 init();
54} 54}
55 55
56OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) 56OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit)
57 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") 57 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("")
58{ 58{
59 _zoomer = 0; 59 _zoomer = 0;
60 m_states.resize(SCROLLVIEW_BITSET_SIZE); 60 m_states.resize(SCROLLVIEW_BITSET_SIZE);
61 m_states[AUTO_SCALE]=always_scale; 61 m_states[AUTO_SCALE]=always_scale;
62 m_states[AUTO_ROTATE]=rfit; 62 m_states[AUTO_ROTATE]=rfit;
63 m_states[FIRST_RESIZE_DONE]=false; 63 m_states[FIRST_RESIZE_DONE]=false;
64 m_states[IMAGE_IS_JPEG]=false; 64 m_states[IMAGE_IS_JPEG]=false;
65 m_states[IMAGE_SCALED_LOADED]=false; 65 m_states[IMAGE_SCALED_LOADED]=false;
66 m_states[SHOW_ZOOMER]=true; 66 m_states[SHOW_ZOOMER]=true;
67 _newImage = true; 67 _newImage = true;
68 init(); 68 init();
69 setImage(img); 69 setImage(img);
70} 70}
71 71
72void OImageScrollView::setImage(const QImage&img) 72void OImageScrollView::setImage(const QImage&img)
73{ 73{
74 _image_data = QImage(); 74 _image_data = QImage();
75 _original_data=img; 75 _original_data=img;
76 _original_data.convertDepth(QPixmap::defaultDepth()); 76 _original_data.convertDepth(QPixmap::defaultDepth());
77 _original_data.setAlphaBuffer(false); 77 _original_data.setAlphaBuffer(false);
78 m_lastName = ""; 78 m_lastName = "";
79 setImageIsJpeg(false); 79 setImageIsJpeg(false);
80 setImageScaledLoaded(false); 80 setImageScaledLoaded(false);
81 _newImage = true; 81 _newImage = true;
82 if (FirstResizeDone()) { 82 if (FirstResizeDone()) {
83 generateImage(); 83 generateImage();
84 } 84 }
85} 85}
86 86
87void OImageScrollView::loadJpeg(bool interncall) 87void OImageScrollView::loadJpeg(bool interncall)
88{ 88{
89 if (m_lastName.isEmpty()) return; 89 if (m_lastName.isEmpty()) return;
90 QImageIO iio( m_lastName, 0l ); 90 QImageIO iio( m_lastName, 0l );
91 QString param; 91 QString param;
92 bool real_load = false; 92 bool real_load = false;
93 _newImage = true; 93 _newImage = true;
94 if (AutoScale()) { 94 if (AutoScale()) {
95 if (!interncall) { 95 if (!interncall) {
96 ExifData xf; 96 ExifData xf;
97 bool scanned = xf.scan(m_lastName); 97 bool scanned = xf.scan(m_lastName);
98 int wid, hei; 98 int wid, hei;
99 wid = QApplication::desktop()->width(); 99 wid = QApplication::desktop()->width();
100 hei = QApplication::desktop()->height(); 100 hei = QApplication::desktop()->height();
101 if (hei>wid) { 101 if (hei>wid) {
102 wid = hei; 102 wid = hei;
103 } else { 103 } else {
104 hei = wid; 104 hei = wid;
105 } 105 }
106 if ( (scanned && (wid<xf.getWidth()||hei<xf.getHeight()))||!scanned ) { 106 if ( (scanned && (wid<xf.getWidth()||hei<xf.getHeight()))||!scanned ) {
107 param = QString( "Fast Shrink( 3 ) Scale( %1, %2, ScaleMin)" ).arg( wid ).arg( hei ); 107 param = QString( "Fast Shrink( 3 ) Scale( %1, %2, ScaleMin)" ).arg( wid ).arg( hei );
108 odebug << "Load jpeg scaled \"" << param << "\"" << oendl;
109 iio.setParameters(param.latin1()); 108 iio.setParameters(param.latin1());
110 setImageScaledLoaded(true); 109 setImageScaledLoaded(true);
111 } 110 }
112 111
113 real_load = true; 112 real_load = true;
114 } 113 }
115 } else { 114 } else {
116 if (ImageScaledLoaded()||!interncall) { 115 if (ImageScaledLoaded()||!interncall) {
117 odebug << "Load jpeg unscaled" << oendl;
118 real_load = true; 116 real_load = true;
119 } 117 }
120 setImageScaledLoaded(false); 118 setImageScaledLoaded(false);
121 } 119 }
122 if (real_load) { 120 if (real_load) {
123 _original_data = iio.read() ? iio.image() : QImage(); 121 _original_data = iio.read() ? iio.image() : QImage();
124 } 122 }
125} 123}
126 124
127void OImageScrollView::setImage( const QString& path ) { 125void OImageScrollView::setImage( const QString& path ) {
128 odebug << "load new image " << oendl;
129 if (m_lastName == path) return; 126 if (m_lastName == path) return;
130 m_lastName = path; 127 m_lastName = path;
131 _newImage = true; 128 _newImage = true;
132 _original_data = QImage(); 129 _original_data = QImage();
133 QString itype = QImage::imageFormat(m_lastName); 130 QString itype = QImage::imageFormat(m_lastName);
134 odebug << "Image type = " << itype << oendl;
135 if (itype == "JPEG") { 131 if (itype == "JPEG") {
136 setImageIsJpeg(true); 132 setImageIsJpeg(true);
137 loadJpeg(); 133 loadJpeg();
138 } else { 134 } else {
139 setImageIsJpeg(false); 135 setImageIsJpeg(false);
140 _original_data.load(path); 136 _original_data.load(path);
141 _original_data.convertDepth(QPixmap::defaultDepth()); 137 _original_data.convertDepth(QPixmap::defaultDepth());
142 _original_data.setAlphaBuffer(false); 138 _original_data.setAlphaBuffer(false);
143 } 139 }
144 _image_data = QImage(); 140 _image_data = QImage();
145 if (FirstResizeDone()) { 141 if (FirstResizeDone()) {
146 generateImage(); 142 generateImage();
147 if (isVisible()) viewport()->repaint(true); 143 if (isVisible()) viewport()->repaint(true);
148 } 144 }
149} 145}
150 146
151/* should be called every time the QImage changed it content */ 147/* should be called every time the QImage changed it content */
152void OImageScrollView::init() 148void OImageScrollView::init()
153{ 149{
154 odebug << "init " << oendl;
155
156 /* 150 /*
157 * create the zoomer 151 * create the zoomer
158 * and connect ther various signals 152 * and connect ther various signals
159 */ 153 */
160 _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); 154 _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" );
161 connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), 155 connect(_zoomer, SIGNAL( zoomAreaRel(int,int)),
162 this, SLOT(scrollBy(int,int)) ); 156 this, SLOT(scrollBy(int,int)) );
163 connect(_zoomer, SIGNAL( zoomArea(int,int)), 157 connect(_zoomer, SIGNAL( zoomArea(int,int)),
164 this, SLOT(center(int,int)) ); 158 this, SLOT(center(int,int)) );
165 connect(this,SIGNAL(contentsMoving(int,int)), 159 connect(this,SIGNAL(contentsMoving(int,int)),
166 _zoomer, (SLOT(setVisiblePoint(int,int))) ); 160 _zoomer, (SLOT(setVisiblePoint(int,int))) );
167 connect(this,SIGNAL(imageSizeChanged(const QSize&)), 161 connect(this,SIGNAL(imageSizeChanged(const QSize&)),
168 _zoomer, SLOT(setImageSize(const QSize&)) ); 162 _zoomer, SLOT(setImageSize(const QSize&)) );
169 connect(this,SIGNAL(viewportSizeChanged(const QSize&)), 163 connect(this,SIGNAL(viewportSizeChanged(const QSize&)),
170 _zoomer, SLOT(setViewPortSize(const QSize&)) ); 164 _zoomer, SLOT(setViewPortSize(const QSize&)) );
171 165
172 setBackgroundColor(white); 166 setBackgroundColor(white);
173 setFocusPolicy(QWidget::StrongFocus); 167 setFocusPolicy(QWidget::StrongFocus);
174 setImageScaledLoaded(false); 168 setImageScaledLoaded(false);
175 setImageIsJpeg(false); 169 setImageIsJpeg(false);
176 if (FirstResizeDone()) { 170 if (FirstResizeDone()) {
177 m_last_rot = Rotate0; 171 m_last_rot = Rotate0;
178 generateImage(); 172 generateImage();
179 } else if (_original_data.size().isValid()) { 173 } else if (_original_data.size().isValid()) {
180 if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide(); 174 if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide();
181 resizeContents(_original_data.width(),_original_data.height()); 175 resizeContents(_original_data.width(),_original_data.height());
182 } 176 }
183 _intensity = 0; 177 _intensity = 0;
184} 178}
185 179
186void OImageScrollView::setAutoRotate(bool how) 180void OImageScrollView::setAutoRotate(bool how)
187{ 181{
188 /* to avoid double repaints */ 182 /* to avoid double repaints */
189 if (AutoRotate() != how) { 183 if (AutoRotate() != how) {
190 m_states.setBit(AUTO_ROTATE,how); 184 m_states.setBit(AUTO_ROTATE,how);
191 _image_data = QImage(); 185 _image_data = QImage();
192 generateImage(); 186 generateImage();
193 } 187 }
194} 188}
195 189
196bool OImageScrollView::AutoRotate()const 190bool OImageScrollView::AutoRotate()const
197{ 191{
198 return m_states.testBit(AUTO_ROTATE); 192 return m_states.testBit(AUTO_ROTATE);
199} 193}
200 194
201void OImageScrollView::setAutoScaleRotate(bool scale, bool rotate) 195void OImageScrollView::setAutoScaleRotate(bool scale, bool rotate)
202{ 196{
203 m_states.setBit(AUTO_ROTATE,rotate); 197 m_states.setBit(AUTO_ROTATE,rotate);
204 setAutoScale(scale); 198 setAutoScale(scale);
205} 199}
206 200
207void OImageScrollView::setAutoScale(bool how) 201void OImageScrollView::setAutoScale(bool how)
208{ 202{
209 m_states.setBit(AUTO_SCALE,how); 203 m_states.setBit(AUTO_SCALE,how);
210 _image_data = QImage(); 204 _image_data = QImage();
211 if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) { 205 if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) {
212 loadJpeg(true); 206 loadJpeg(true);
213 } 207 }
214 generateImage(); 208 generateImage();
215} 209}
216 210
217bool OImageScrollView::AutoScale()const 211bool OImageScrollView::AutoScale()const
218{ 212{
219 return m_states.testBit(AUTO_SCALE); 213 return m_states.testBit(AUTO_SCALE);
@@ -290,373 +284,377 @@ void OImageScrollView::rotate_into_data(Rotation r)
290 { 284 {
291 unsigned char *srcData, *destData; 285 unsigned char *srcData, *destData;
292 unsigned int *srcTable, *destTable; 286 unsigned int *srcTable, *destTable;
293 switch ( r ) 287 switch ( r )
294 { 288 {
295 case Rotate90: 289 case Rotate90:
296 dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); 290 dest.create(_original_data.height(), _original_data.width(), _original_data.depth());
297 dest.setNumColors(_original_data.numColors()); 291 dest.setNumColors(_original_data.numColors());
298 srcTable = (unsigned int *)_original_data.colorTable(); 292 srcTable = (unsigned int *)_original_data.colorTable();
299 destTable = (unsigned int *)dest.colorTable(); 293 destTable = (unsigned int *)dest.colorTable();
300 for ( x=0; x < _original_data.numColors(); ++x ) 294 for ( x=0; x < _original_data.numColors(); ++x )
301 destTable[x] = srcTable[x]; 295 destTable[x] = srcTable[x];
302 for ( y=0; y < _original_data.height(); ++y ) 296 for ( y=0; y < _original_data.height(); ++y )
303 { 297 {
304 srcData = (unsigned char *)_original_data.scanLine(y); 298 srcData = (unsigned char *)_original_data.scanLine(y);
305 for ( x=0; x < _original_data.width(); ++x ) 299 for ( x=0; x < _original_data.width(); ++x )
306 { 300 {
307 destData = (unsigned char *)dest.scanLine(x); 301 destData = (unsigned char *)dest.scanLine(x);
308 destData[_original_data.height()-y-1] = srcData[x]; 302 destData[_original_data.height()-y-1] = srcData[x];
309 } 303 }
310 } 304 }
311 break; 305 break;
312 case Rotate180: 306 case Rotate180:
313 dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); 307 dest.create(_original_data.width(), _original_data.height(), _original_data.depth());
314 dest.setNumColors(_original_data.numColors()); 308 dest.setNumColors(_original_data.numColors());
315 srcTable = (unsigned int *)_original_data.colorTable(); 309 srcTable = (unsigned int *)_original_data.colorTable();
316 destTable = (unsigned int *)dest.colorTable(); 310 destTable = (unsigned int *)dest.colorTable();
317 for ( x=0; x < _original_data.numColors(); ++x ) 311 for ( x=0; x < _original_data.numColors(); ++x )
318 destTable[x] = srcTable[x]; 312 destTable[x] = srcTable[x];
319 for ( y=0; y < _original_data.height(); ++y ) 313 for ( y=0; y < _original_data.height(); ++y )
320 { 314 {
321 srcData = (unsigned char *)_original_data.scanLine(y); 315 srcData = (unsigned char *)_original_data.scanLine(y);
322 destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); 316 destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1);
323 for ( x=0; x < _original_data.width(); ++x ) 317 for ( x=0; x < _original_data.width(); ++x )
324 destData[_original_data.width()-x-1] = srcData[x]; 318 destData[_original_data.width()-x-1] = srcData[x];
325 } 319 }
326 break; 320 break;
327 case Rotate270: 321 case Rotate270:
328 dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); 322 dest.create(_original_data.height(), _original_data.width(), _original_data.depth());
329 dest.setNumColors(_original_data.numColors()); 323 dest.setNumColors(_original_data.numColors());
330 srcTable = (unsigned int *)_original_data.colorTable(); 324 srcTable = (unsigned int *)_original_data.colorTable();
331 destTable = (unsigned int *)dest.colorTable(); 325 destTable = (unsigned int *)dest.colorTable();
332 for ( x=0; x < _original_data.numColors(); ++x ) 326 for ( x=0; x < _original_data.numColors(); ++x )
333 destTable[x] = srcTable[x]; 327 destTable[x] = srcTable[x];
334 for ( y=0; y < _original_data.height(); ++y ) 328 for ( y=0; y < _original_data.height(); ++y )
335 { 329 {
336 srcData = (unsigned char *)_original_data.scanLine(y); 330 srcData = (unsigned char *)_original_data.scanLine(y);
337 for ( x=0; x < _original_data.width(); ++x ) 331 for ( x=0; x < _original_data.width(); ++x )
338 { 332 {
339 destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); 333 destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1);
340 destData[y] = srcData[x]; 334 destData[y] = srcData[x];
341 } 335 }
342 } 336 }
343 break; 337 break;
344 default: 338 default:
345 dest = _original_data; 339 dest = _original_data;
346 break; 340 break;
347 } 341 }
348 342
349 } 343 }
350 _newImage = true; 344 _newImage = true;
351 _image_data = dest; 345 _image_data = dest;
352} 346}
353 347
348// yes - sorry - it is NOT gamma it is just BRIGHTNESS. Alwin
354void OImageScrollView::apply_gamma(int aValue) 349void OImageScrollView::apply_gamma(int aValue)
355{ 350{
356 if (!_image_data.size().isValid()) return; 351 if (!_image_data.size().isValid()) return;
357 float percent = ((float)aValue/100); 352 float percent = ((float)aValue/100.0);
358 odebug << "Apply gamma " << percent << oendl; 353
359 int pixels = _image_data.depth()>8?_image_data.width()*_image_data.height() : _image_data.numColors();
360 int segColors = _image_data.depth() > 8 ? 256 : _image_data.numColors(); 354 int segColors = _image_data.depth() > 8 ? 256 : _image_data.numColors();
355 /* must be - otherwise it displays some ... strange colors */
356 if (segColors<256) segColors=256;
357
361 unsigned char *segTbl = new unsigned char[segColors]; 358 unsigned char *segTbl = new unsigned char[segColors];
359 int pixels = _image_data.depth()>8?_image_data.width()*_image_data.height() : _image_data.numColors();
360
361
362 bool brighten = (percent >= 0); 362 bool brighten = (percent >= 0);
363 if ( percent < 0 ) 363 if ( percent < 0 ) {
364 percent = -percent; 364 percent = -percent;
365 }
365 366
366 unsigned int *data = _image_data.depth() > 8 ? (unsigned int *)_image_data.bits() : 367 unsigned int *data = _image_data.depth() > 8 ? (unsigned int *)_image_data.bits() :
367 (unsigned int *)_image_data.colorTable(); 368 (unsigned int *)_image_data.colorTable();
368 369
370 int tmp = 0;
369 371
370 if (brighten) { 372 if (brighten) {
371 for ( int i=0; i < segColors; ++i ) 373 for ( int i=0; i < segColors; ++i )
372 { 374 {
373 int tmp = (int)(i*percent); 375 tmp = (int)(i*percent);
374 if ( tmp > 255 ) 376 if ( tmp > 255 )
375 tmp = 255; 377 tmp = 255;
376 segTbl[i] = tmp; 378 segTbl[i] = tmp;
377 } 379 }
378 } else { 380 } else {
379 for ( int i=0; i < segColors; ++i ) 381 for ( int i=0; i < segColors; ++i )
380 { 382 {
381 int tmp = (int)(i*percent); 383 tmp = (int)(i*percent);
382 if ( tmp < 0 ) 384 if ( tmp < 0 )
383 tmp = 0; 385 tmp = 0;
384 segTbl[i] = tmp; 386 segTbl[i] = tmp;
385 } 387 }
386 } 388 }
387 if (brighten) { 389 if (brighten) {
388 for ( int i=0; i < pixels; ++i ) 390 for ( int i=0; i < pixels; ++i )
389 { 391 {
390 int r = qRed(data[i]); 392 int r = qRed(data[i]);
391 int g = qGreen(data[i]); 393 int g = qGreen(data[i]);
392 int b = qBlue(data[i]); 394 int b = qBlue(data[i]);
393 int a = qAlpha(data[i]); 395 int a = qAlpha(data[i]);
394 r = r + segTbl[r] > 255 ? 255 : r + segTbl[r]; 396 r = r + segTbl[r] > 255 ? 255 : r + segTbl[r];
395 g = g + segTbl[g] > 255 ? 255 : g + segTbl[g]; 397 g = g + segTbl[g] > 255 ? 255 : g + segTbl[g];
396 b = b + segTbl[b] > 255 ? 255 : b + segTbl[b]; 398 b = b + segTbl[b] > 255 ? 255 : b + segTbl[b];
397 data[i] = qRgba(r, g, b,a); 399 data[i] = qRgba(r, g, b,a);
398 } 400 }
399 } else { 401 } else {
400 for ( int i=0; i < pixels; ++i ) 402 for ( int i=0; i < pixels; ++i )
401 { 403 {
402 int r = qRed(data[i]); 404 int r = qRed(data[i]);
403 int g = qGreen(data[i]); 405 int g = qGreen(data[i]);
404 int b = qBlue(data[i]); 406 int b = qBlue(data[i]);
405 int a = qAlpha(data[i]); 407 int a = qAlpha(data[i]);
406 r = r - segTbl[r] < 0 ? 0 : r - segTbl[r]; 408 r = r - segTbl[r] < 0 ? 0 : r - segTbl[r];
407 g = g - segTbl[g] < 0 ? 0 : g - segTbl[g]; 409 g = g - segTbl[g] < 0 ? 0 : g - segTbl[g];
408 b = b - segTbl[b] < 0 ? 0 : b - segTbl[b]; 410 b = b - segTbl[b] < 0 ? 0 : b - segTbl[b];
409 data[i] = qRgba(r, g, b, a); 411 data[i] = qRgba(r, g, b, a);
410 } 412 }
411 } 413 }
412 delete [] segTbl; 414 delete [] segTbl;
413} 415}
414 416
415const int OImageScrollView::Intensity()const 417const int OImageScrollView::Intensity()const
416{ 418{
417 return _intensity; 419 return _intensity;
418} 420}
419 421
420int OImageScrollView::setIntensity(int value,bool reload) 422int OImageScrollView::setIntensity(int value,bool reload)
421{ 423{
422 int oldi = _intensity; 424 int oldi = _intensity;
423 _intensity = value; 425 _intensity = value;
424 if (!_pdata.size().isValid()) { 426 if (!_pdata.size().isValid()) {
425 return _intensity; 427 return _intensity;
426 } 428 }
427 429
428 if (!reload) { 430 if (!reload) {
429 _image_data = _pdata.convertToImage(); 431 _image_data = _pdata.convertToImage();
430 apply_gamma(_intensity-oldi); 432 apply_gamma(_intensity-oldi);
431 _pdata.convertFromImage(_image_data); 433 _pdata.convertFromImage(_image_data);
432 /* 434 /*
433 * invalidate 435 * invalidate
434 */ 436 */
435 _image_data=QImage(); 437 _image_data=QImage();
436 if (isVisible()) { 438 if (isVisible()) {
437 updateContents(contentsX(),contentsY(),width(),height()); 439 updateContents(contentsX(),contentsY(),width(),height());
438 } 440 }
439 } else { 441 } else {
440 _newImage = true; 442 _newImage = true;
441 generateImage(); 443 generateImage();
442 } 444 }
443 return _intensity; 445 return _intensity;
444} 446}
445 447
446void OImageScrollView::generateImage() 448void OImageScrollView::generateImage()
447{ 449{
448 Rotation r = Rotate0; 450 Rotation r = Rotate0;
449 _pdata = QPixmap(); 451 _pdata = QPixmap();
450 if (_original_data.isNull()) { 452 if (_original_data.isNull()) {
451 emit imageSizeChanged( _image_data.size() ); 453 emit imageSizeChanged( _image_data.size() );
452 if (_zoomer) _zoomer->setImage( _image_data ); 454 if (_zoomer) _zoomer->setImage( _image_data );
453 return; 455 return;
454 } 456 }
455 if (width()>height()&&_original_data.width()<_original_data.height() || 457 if (width()>height()&&_original_data.width()<_original_data.height() ||
456 width()<height()&&_original_data.width()>_original_data.height()) { 458 width()<height()&&_original_data.width()>_original_data.height()) {
457 if (AutoRotate()) r = Rotate90; 459 if (AutoRotate()) r = Rotate90;
458 } 460 }
459 461
460 int twidth,theight; 462 int twidth,theight;
461 odebug << " r = " << r << oendl;
462 if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) { 463 if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) {
463 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { 464 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) {
464 odebug << "Rescaling data" << oendl;
465 if (r==Rotate0) { 465 if (r==Rotate0) {
466 _image_data = _original_data; 466 _image_data = _original_data;
467 } else { 467 } else {
468 rotate_into_data(r); 468 rotate_into_data(r);
469 } 469 }
470 _newImage = true; 470 _newImage = true;
471 } 471 }
472 rescaleImage(width(),height()); 472 rescaleImage(width(),height());
473 } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) { 473 } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) {
474 if (r==Rotate0) { 474 if (r==Rotate0) {
475 _image_data = _original_data; 475 _image_data = _original_data;
476 } else { 476 } else {
477 rotate_into_data(r); 477 rotate_into_data(r);
478 } 478 }
479 m_last_rot = r; 479 m_last_rot = r;
480 } 480 }
481 481
482 if (_newImage) { 482 if (_newImage) {
483 apply_gamma(_intensity); 483 apply_gamma(_intensity);
484 _newImage = false; 484 _newImage = false;
485 } 485 }
486 486
487 _pdata.convertFromImage(_image_data); 487 _pdata.convertFromImage(_image_data);
488 twidth = _image_data.width(); 488 twidth = _image_data.width();
489 theight = _image_data.height(); 489 theight = _image_data.height();
490 490
491 /* 491 /*
492 * update the zoomer 492 * update the zoomer
493 */ 493 */
494 check_zoomer(); 494 check_zoomer();
495 emit imageSizeChanged( _image_data.size() ); 495 emit imageSizeChanged( _image_data.size() );
496 rescaleImage( 128, 128 ); 496 rescaleImage( 128, 128 );
497 resizeContents(twidth,theight); 497 resizeContents(twidth,theight);
498 /* 498 /*
499 * move scrollbar 499 * move scrollbar
500 */ 500 */
501 if (_zoomer) { 501 if (_zoomer) {
502 _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, 502 _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2,
503 _image_data.width()/2, _image_data.height()/2 ); 503 _image_data.width()/2, _image_data.height()/2 );
504 _zoomer->setImage( _image_data ); 504 _zoomer->setImage( _image_data );
505 } 505 }
506 /* 506 /*
507 * invalidate 507 * invalidate
508 */ 508 */
509 _image_data=QImage(); 509 _image_data=QImage();
510 if (isVisible()) { 510 if (isVisible()) {
511 updateContents(contentsX(),contentsY(),width(),height()); 511 updateContents(contentsX(),contentsY(),width(),height());
512 } 512 }
513} 513}
514 514
515void OImageScrollView::resizeEvent(QResizeEvent * e) 515void OImageScrollView::resizeEvent(QResizeEvent * e)
516{ 516{
517 odebug << "OImageScrollView resizeEvent (" << e->size() << " - " << e->oldSize() << oendl;
518 QScrollView::resizeEvent(e); 517 QScrollView::resizeEvent(e);
519 if (e->oldSize()==e->size()||!isUpdatesEnabled ()) return; 518 if (e->oldSize()==e->size()||!isUpdatesEnabled ()) return;
520 generateImage(); 519 generateImage();
521 setFirstResizeDone(true); 520 setFirstResizeDone(true);
522 emit viewportSizeChanged( viewport()->size() ); 521 emit viewportSizeChanged( viewport()->size() );
523 522
524} 523}
525 524
526void OImageScrollView::keyPressEvent(QKeyEvent * e) 525void OImageScrollView::keyPressEvent(QKeyEvent * e)
527{ 526{
528 if (!e) return; 527 if (!e) return;
529 int dx = horizontalScrollBar()->lineStep(); 528 int dx = horizontalScrollBar()->lineStep();
530 int dy = verticalScrollBar()->lineStep(); 529 int dy = verticalScrollBar()->lineStep();
531 if (e->key()==Qt::Key_Right) { 530 if (e->key()==Qt::Key_Right) {
532 scrollBy(dx,0); 531 scrollBy(dx,0);
533 e->accept(); 532 e->accept();
534 } else if (e->key()==Qt::Key_Left) { 533 } else if (e->key()==Qt::Key_Left) {
535 scrollBy(0-dx,0); 534 scrollBy(0-dx,0);
536 e->accept(); 535 e->accept();
537 } else if (e->key()==Qt::Key_Up) { 536 } else if (e->key()==Qt::Key_Up) {
538 scrollBy(0,0-dy); 537 scrollBy(0,0-dy);
539 e->accept(); 538 e->accept();
540 } else if (e->key()==Qt::Key_Down) { 539 } else if (e->key()==Qt::Key_Down) {
541 scrollBy(0,dy); 540 scrollBy(0,dy);
542 e->accept(); 541 e->accept();
543 } else { 542 } else {
544 e->ignore(); 543 e->ignore();
545 } 544 }
546 QScrollView::keyPressEvent(e); 545 QScrollView::keyPressEvent(e);
547} 546}
548 547
549void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) 548void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph)
550{ 549{
551 if (!_pdata.size().isValid()) { 550 if (!_pdata.size().isValid()) {
552 p->fillRect(clipx,clipy,clipw,cliph, backgroundColor()); 551 p->fillRect(clipx,clipy,clipw,cliph, backgroundColor());
553 return; 552 return;
554 } 553 }
555 554
556 int w = clipw; 555 int w = clipw;
557 int h = cliph; 556 int h = cliph;
558 int x = clipx; 557 int x = clipx;
559 int y = clipy; 558 int y = clipy;
560 bool erase = false; 559 bool erase = false;
561 560
562 if (w>_pdata.width()) { 561 if (w>_pdata.width()) {
563 w = _pdata.width()-x; 562 w = _pdata.width()-x;
564 erase=true; 563 erase=true;
565 } 564 }
566 if (h>_pdata.height()) { 565 if (h>_pdata.height()) {
567 h = _pdata.height()-y; 566 h = _pdata.height()-y;
568 erase=true; 567 erase=true;
569 } 568 }
570 if (!erase && (clipy+cliph>_pdata.height()||clipx+clipw>_pdata.width())) { 569 if (!erase && (clipy+cliph>_pdata.height()||clipx+clipw>_pdata.width())) {
571 erase = true; 570 erase = true;
572 } 571 }
573 if (erase||_original_data.hasAlphaBuffer()) { 572 if (erase||_original_data.hasAlphaBuffer()) {
574 p->fillRect(clipx,clipy,clipw,cliph, backgroundColor()); 573 p->fillRect(clipx,clipy,clipw,cliph, backgroundColor());
575 } 574 }
576 if (w>0 && h>0&&x<_pdata.width()&&y<_pdata.height()) { 575 if (w>0 && h>0&&x<_pdata.width()&&y<_pdata.height()) {
577 p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); 576 p->drawPixmap(clipx,clipy,_pdata,x,y,w,h);
578 } 577 }
579} 578}
580 579
581/* using the real geometry points and not the translated points is wanted! */ 580/* using the real geometry points and not the translated points is wanted! */
582void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) 581void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
583{ 582{
584 int mx, my; 583 int mx, my;
585 mx = e->x(); 584 mx = e->x();
586 my = e->y(); 585 my = e->y();
587 if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { 586 if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) {
588 int diffx = _mouseStartPosX-mx; 587 int diffx = _mouseStartPosX-mx;
589 int diffy = _mouseStartPosY-my; 588 int diffy = _mouseStartPosY-my;
590 scrollBy(diffx,diffy); 589 scrollBy(diffx,diffy);
591 } 590 }
592 _mouseStartPosX=mx; 591 _mouseStartPosX=mx;
593 _mouseStartPosY=my; 592 _mouseStartPosY=my;
594} 593}
595 594
596void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e) 595void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e)
597{ 596{
598 odebug << " X and Y " << e->x() << " " << e->y() << oendl;
599 /* this marks the beginning of a possible mouse move. Due internal reasons of QT 597 /* this marks the beginning of a possible mouse move. Due internal reasons of QT
600 the geometry values here may real differ from that set in MoveEvent (I don't know 598 the geometry values here may real differ from that set in MoveEvent (I don't know
601 why). For getting them in real context, we use the first move-event to set the start 599 why). For getting them in real context, we use the first move-event to set the start
602 position ;) 600 position ;)
603 */ 601 */
604 _mouseStartPosX = -1; 602 _mouseStartPosX = -1;
605 _mouseStartPosY = -1; 603 _mouseStartPosY = -1;
606} 604}
607 605
608void OImageScrollView::setDestructiveClose() { 606void OImageScrollView::setDestructiveClose() {
609 WFlags fl = getWFlags(); 607 WFlags fl = getWFlags();
610 /* clear it just in case */ 608 /* clear it just in case */
611 fl &= ~WDestructiveClose; 609 fl &= ~WDestructiveClose;
612 fl |= WDestructiveClose; 610 fl |= WDestructiveClose;
613 setWFlags( fl ); 611 setWFlags( fl );
614} 612}
615 613
616bool OImageScrollView::image_fit_into(const QSize&s ) 614bool OImageScrollView::image_fit_into(const QSize&s )
617{ 615{
618 if (s.width()>width()||s.height()>height()) { 616 if (s.width()>width()||s.height()>height()) {
619 return false; 617 return false;
620 } 618 }
621 return true; 619 return true;
622} 620}
623 621
624void OImageScrollView::setShowZoomer(bool how) 622void OImageScrollView::setShowZoomer(bool how)
625{ 623{
626 m_states.setBit(SHOW_ZOOMER,how); 624 m_states.setBit(SHOW_ZOOMER,how);
627 check_zoomer(); 625 check_zoomer();
628} 626}
629 627
630bool OImageScrollView::ShowZoomer()const 628bool OImageScrollView::ShowZoomer()const
631{ 629{
632 return m_states.testBit(SHOW_ZOOMER); 630 return m_states.testBit(SHOW_ZOOMER);
633} 631}
634 632
635void OImageScrollView::check_zoomer() 633void OImageScrollView::check_zoomer()
636{ 634{
637 if (!_zoomer) return; 635 if (!_zoomer) return;
638 if ( (!ShowZoomer()||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) { 636 if ( (!ShowZoomer()||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) {
639 _zoomer->hide(); 637 _zoomer->hide();
640 } else if ( ShowZoomer() && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){ 638 } else if ( ShowZoomer() && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){
641 _zoomer->show(); 639 _zoomer->show();
642 } 640 }
643} 641}
644 642
645bool OImageScrollView::FirstResizeDone()const 643bool OImageScrollView::FirstResizeDone()const
646{ 644{
647 return m_states.testBit(FIRST_RESIZE_DONE); 645 return m_states.testBit(FIRST_RESIZE_DONE);
648} 646}
649 647
650void OImageScrollView::setFirstResizeDone(bool how) 648void OImageScrollView::setFirstResizeDone(bool how)
651{ 649{
652 m_states.setBit(FIRST_RESIZE_DONE,how); 650 m_states.setBit(FIRST_RESIZE_DONE,how);
653} 651}
654 652
655bool OImageScrollView::ImageIsJpeg()const 653bool OImageScrollView::ImageIsJpeg()const
656{ 654{
657 return m_states.testBit(IMAGE_IS_JPEG); 655 return m_states.testBit(IMAGE_IS_JPEG);
658} 656}
659 657
660void OImageScrollView::setImageIsJpeg(bool how) 658void OImageScrollView::setImageIsJpeg(bool how)
661{ 659{
662 m_states.setBit(IMAGE_IS_JPEG,how); 660 m_states.setBit(IMAGE_IS_JPEG,how);