-rw-r--r-- | libopie2/opiemm/oimagescrollview.cpp | 30 |
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 | |||
@@ -76,112 +76,106 @@ void OImageScrollView::setImage(const QImage&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 | ||
87 | void OImageScrollView::loadJpeg(bool interncall) | 87 | void 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 | ||
127 | void OImageScrollView::setImage( const QString& path ) { | 125 | void 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 */ |
152 | void OImageScrollView::init() | 148 | void 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 | ||
186 | void OImageScrollView::setAutoRotate(bool how) | 180 | void OImageScrollView::setAutoRotate(bool how) |
187 | { | 181 | { |
@@ -322,92 +316,100 @@ void OImageScrollView::rotate_into_data(Rotation r) | |||
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 | ||
354 | void OImageScrollView::apply_gamma(int aValue) | 349 | void 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 | } |
@@ -429,121 +431,118 @@ int OImageScrollView::setIntensity(int value,bool 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 | ||
446 | void OImageScrollView::generateImage() | 448 | void 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 | ||
515 | void OImageScrollView::resizeEvent(QResizeEvent * e) | 515 | void 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 | ||
526 | void OImageScrollView::keyPressEvent(QKeyEvent * e) | 525 | void 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 | ||
549 | void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | 548 | void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) |
@@ -566,65 +565,64 @@ void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clip | |||
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! */ |
582 | void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | 581 | void 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 | ||
596 | void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e) | 595 | void 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 | ||
608 | void OImageScrollView::setDestructiveClose() { | 606 | void 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 | ||
616 | bool OImageScrollView::image_fit_into(const QSize&s ) | 614 | bool 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 | ||
624 | void OImageScrollView::setShowZoomer(bool how) | 622 | void 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 | ||
630 | bool OImageScrollView::ShowZoomer()const | 628 | bool OImageScrollView::ShowZoomer()const |