summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/gui
Unidiff
Diffstat (limited to 'noncore/graphics/opie-eye/gui') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp38
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h7
2 files changed, 43 insertions, 2 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
index ad19219..5b12258 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
@@ -51,24 +51,39 @@ void ImageScrollView::setImage( const QString& path ) {
51 _original_data.convertDepth(QPixmap::defaultDepth()); 51 _original_data.convertDepth(QPixmap::defaultDepth());
52 _original_data.setAlphaBuffer(false); 52 _original_data.setAlphaBuffer(false);
53 _image_data = QImage(); 53 _image_data = QImage();
54 if (first_resize_done) { 54 if (first_resize_done) {
55 generateImage(); 55 generateImage();
56 } 56 }
57} 57}
58 58
59/* should be called every time the QImage changed it content */ 59/* should be called every time the QImage changed it content */
60void ImageScrollView::init() 60void ImageScrollView::init()
61{ 61{
62 odebug << "init " << oendl; 62 odebug << "init " << oendl;
63
64 /*
65 * create the zoomer
66 * and connect ther various signals
67 */
68 _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" );
69 connect(_zoomer, SIGNAL( zoomAreaRel(int,int)),
70 this, SLOT(scrollBy(int,int)) );
71 connect(this,SIGNAL(contentsMoving(int,int)),
72 _zoomer, (SLOT(setVisiblePoint(int,int))) );
73 connect(this,SIGNAL(imageSizeChanged(const QSize&)),
74 _zoomer, SLOT(setImageSize(const QSize&)) );
75 connect(this,SIGNAL(viewportSizeChanged(const QSize&)),
76 _zoomer, SLOT(setViewPortSize(const QSize&)) );
77
63 viewport()->setBackgroundColor(white); 78 viewport()->setBackgroundColor(white);
64 setFocusPolicy(QWidget::StrongFocus); 79 setFocusPolicy(QWidget::StrongFocus);
65 if (first_resize_done) { 80 if (first_resize_done) {
66 last_rot = Rotate0; 81 last_rot = Rotate0;
67 generateImage(); 82 generateImage();
68 odebug << "reinit display " << oendl; 83 odebug << "reinit display " << oendl;
69 } else if (_original_data.size().isValid()) { 84 } else if (_original_data.size().isValid()) {
70 resizeContents(_original_data.width(),_original_data.height()); 85 resizeContents(_original_data.width(),_original_data.height());
71 } 86 }
72} 87}
73 88
74void ImageScrollView::setAutoRotate(bool how) 89void ImageScrollView::setAutoRotate(bool how)
@@ -242,33 +257,50 @@ void ImageScrollView::generateImage()
242 rescaleImage(width(),height()); 257 rescaleImage(width(),height());
243 resizeContents(_image_data.width(),_image_data.height()); 258 resizeContents(_image_data.width(),_image_data.height());
244 } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { 259 } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) {
245 if (r==Rotate0) { 260 if (r==Rotate0) {
246 _image_data = _original_data; 261 _image_data = _original_data;
247 } else { 262 } else {
248 rotate_into_data(r); 263 rotate_into_data(r);
249 } 264 }
250 last_rot = r; 265 last_rot = r;
251 resizeContents(_image_data.width(),_image_data.height()); 266 resizeContents(_image_data.width(),_image_data.height());
252 } 267 }
253 _pdata.convertFromImage(_image_data); 268 _pdata.convertFromImage(_image_data);
269
270 /*
271 * update the zoomer
272 */
273 emit imageSizeChanged( _image_data.size() );
274 rescaleImage( 128, 128 );
275 _zoomer->setImage( _image_data );
276
277 /*
278 * invalidate
279 */
254 _image_data=QImage(); 280 _image_data=QImage();
255} 281}
256 282
257void ImageScrollView::resizeEvent(QResizeEvent * e) 283void ImageScrollView::resizeEvent(QResizeEvent * e)
258{ 284{
259 odebug << "ImageScrollView resizeEvent" << oendl; 285 odebug << "ImageScrollView resizeEvent" << oendl;
260 QScrollView::resizeEvent(e); 286 QScrollView::resizeEvent(e);
261 generateImage(); 287 generateImage();
262 first_resize_done = true; 288 first_resize_done = true;
289 emit viewportSizeChanged( viewport()->size() );
290
291 /*
292 * move scrollbar
293 */
294 _zoomer->setGeometry( viewport()->width()-100, viewport()->height()-50, 100, 50 );
263} 295}
264 296
265void ImageScrollView::keyPressEvent(QKeyEvent * e) 297void ImageScrollView::keyPressEvent(QKeyEvent * e)
266{ 298{
267 if (!e) return; 299 if (!e) return;
268 int dx = horizontalScrollBar()->lineStep(); 300 int dx = horizontalScrollBar()->lineStep();
269 int dy = verticalScrollBar()->lineStep(); 301 int dy = verticalScrollBar()->lineStep();
270 if (e->key()==Qt::Key_Right) { 302 if (e->key()==Qt::Key_Right) {
271 scrollBy(dx,0); 303 scrollBy(dx,0);
272 e->accept(); 304 e->accept();
273 } else if (e->key()==Qt::Key_Left) { 305 } else if (e->key()==Qt::Key_Left) {
274 scrollBy(0-dx,0); 306 scrollBy(0-dx,0);
@@ -311,24 +343,25 @@ void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw
311 } else if (y+h>_pdata.height()){ 343 } else if (y+h>_pdata.height()){
312 y = _pdata.height()-h; 344 y = _pdata.height()-h;
313 } 345 }
314 if (erase||_original_data.hasAlphaBuffer()) { 346 if (erase||_original_data.hasAlphaBuffer()) {
315 p->fillRect(clipx,clipy,clipw,cliph,white); 347 p->fillRect(clipx,clipy,clipw,cliph,white);
316 } 348 }
317 p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); 349 p->drawPixmap(clipx,clipy,_pdata,x,y,w,h);
318} 350}
319 351
320/* using the real geometry points and not the translated points is wanted! */ 352/* using the real geometry points and not the translated points is wanted! */
321void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) 353void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
322{ 354{
355 odebug << "Move X and Y " << e->x() << " " << e->y() << oendl;
323 int mx, my; 356 int mx, my;
324 mx = e->x(); 357 mx = e->x();
325 my = e->y(); 358 my = e->y();
326 if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { 359 if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) {
327 int diffx = _mouseStartPosX-mx; 360 int diffx = _mouseStartPosX-mx;
328 int diffy = _mouseStartPosY-my; 361 int diffy = _mouseStartPosY-my;
329#if 0 362#if 0
330 QScrollBar*xbar = horizontalScrollBar(); 363 QScrollBar*xbar = horizontalScrollBar();
331 QScrollBar*ybar = verticalScrollBar(); 364 QScrollBar*ybar = verticalScrollBar();
332 if (xbar->value()+diffx>xbar->maxValue()) { 365 if (xbar->value()+diffx>xbar->maxValue()) {
333 diffx = xbar->maxValue()-xbar->value(); 366 diffx = xbar->maxValue()-xbar->value();
334 } else if (xbar->value()+diffx<0) { 367 } else if (xbar->value()+diffx<0) {
@@ -337,30 +370,31 @@ void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
337 if (ybar->value()+diffy>ybar->maxValue()) { 370 if (ybar->value()+diffy>ybar->maxValue()) {
338 diffy = ybar->maxValue()-ybar->value(); 371 diffy = ybar->maxValue()-ybar->value();
339 } else if (ybar->value()+diffy<0) { 372 } else if (ybar->value()+diffy<0) {
340 diffy=0-ybar->value(); 373 diffy=0-ybar->value();
341 } 374 }
342#endif 375#endif
343 scrollBy(diffx,diffy); 376 scrollBy(diffx,diffy);
344 } 377 }
345 _mouseStartPosX=mx; 378 _mouseStartPosX=mx;
346 _mouseStartPosY=my; 379 _mouseStartPosY=my;
347} 380}
348 381
349void ImageScrollView::contentsMousePressEvent ( QMouseEvent * ) 382void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e)
350{ 383{
384 odebug << " X and Y " << e->x() << " " << e->y() << oendl;
351 /* this marks the beginning of a possible mouse move. Due internal reasons of QT 385 /* this marks the beginning of a possible mouse move. Due internal reasons of QT
352 the geometry values here may real differ from that set in MoveEvent (I don't know 386 the geometry values here may real differ from that set in MoveEvent (I don't know
353 why). For getting them in real context, we use the first move-event to set the start 387 why). For getting them in real context, we use the first move-event to set the start
354 position ;) 388 position ;)
355 */ 389 */
356 _mouseStartPosX = -1; 390 _mouseStartPosX = -1;
357 _mouseStartPosY = -1; 391 _mouseStartPosY = -1;
358} 392}
359 393
360void ImageScrollView::setDestructiveClose() { 394void ImageScrollView::setDestructiveClose() {
361 WFlags fl = getWFlags(); 395 WFlags fl = getWFlags();
362 /* clear it just in case */ 396 /* clear it just in case */
363 fl &= ~WDestructiveClose; 397 fl &= ~WDestructiveClose;
364 fl |= WDestructiveClose; 398 fl |= WDestructiveClose;
365 setWFlags( fl ); 399 setWFlags( fl );
366} 400}
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h
index eb91dbd..1b25103 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.h
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.h
@@ -1,21 +1,25 @@
1#ifndef _IMAGE_SCROLL_VIEW_H 1#ifndef _IMAGE_SCROLL_VIEW_H
2#define _IMAGE_SCROLL_VIEW_H 2#define _IMAGE_SCROLL_VIEW_H
3 3
4#include <lib/oimagezoomer.h>
5
4#include <qscrollview.h> 6#include <qscrollview.h>
5#include <qimage.h> 7#include <qimage.h>
6#include <qpixmap.h> 8#include <qpixmap.h>
7#include <qstring.h> 9#include <qstring.h>
8#include <qdialog.h> 10#include <qdialog.h>
9 11
12
13
10class QPainter; 14class QPainter;
11 15
12class ImageScrollView:public QScrollView 16class ImageScrollView:public QScrollView
13{ 17{
14 Q_OBJECT 18 Q_OBJECT
15public: 19public:
16 ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); 20 ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 );
17 ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); 21 ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
18 ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); 22 ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
19 virtual ~ImageScrollView(); 23 virtual ~ImageScrollView();
20 24
21 virtual void setImage(const QImage&); 25 virtual void setImage(const QImage&);
@@ -25,29 +29,32 @@ public:
25 virtual void setAutoRotate(bool); 29 virtual void setAutoRotate(bool);
26 virtual void setAutoScale(bool); 30 virtual void setAutoScale(bool);
27 31
28 enum Rotation { 32 enum Rotation {
29 Rotate0, 33 Rotate0,
30 Rotate90, 34 Rotate90,
31 Rotate180, 35 Rotate180,
32 Rotate270 36 Rotate270
33 }; 37 };
34 38
35signals: 39signals:
36 void sig_return(); 40 void sig_return();
41 void imageSizeChanged( const QSize& );
42 void viewportSizeChanged( const QSize& );
37 43
38protected: 44protected:
39 virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); 45 virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
40 void init(); 46 void init();
41 47
48 Opie::MM::OImageZoomer *_zoomer;
42 QImage _image_data; 49 QImage _image_data;
43 QImage _original_data; 50 QImage _original_data;
44 QPixmap _pdata; 51 QPixmap _pdata;
45 52
46 int _mouseStartPosX,_mouseStartPosY; 53 int _mouseStartPosX,_mouseStartPosY;
47 54
48 bool scale_to_fit; 55 bool scale_to_fit;
49 bool rotate_to_fit; 56 bool rotate_to_fit;
50 bool first_resize_done; 57 bool first_resize_done;
51 Rotation last_rot; 58 Rotation last_rot;
52 QString m_lastName; 59 QString m_lastName;
53 virtual void rescaleImage(int w, int h); 60 virtual void rescaleImage(int w, int h);