author | zecke <zecke> | 2004-04-07 23:33:48 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-04-07 23:33:48 (UTC) |
commit | 61cb9c9ad238e5aec6aaa1384549e0aab99d14bf (patch) (unidiff) | |
tree | b96da732386aa45060bd80890cd7466cbcf77afb | |
parent | 0a21abab4eed64d17c4b1475569194117dab709c (diff) | |
download | opie-61cb9c9ad238e5aec6aaa1384549e0aab99d14bf.zip opie-61cb9c9ad238e5aec6aaa1384549e0aab99d14bf.tar.gz opie-61cb9c9ad238e5aec6aaa1384549e0aab99d14bf.tar.bz2 |
First version of the zoomer placement still needs some work though
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 38 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 7 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.cpp | 14 |
3 files changed, 52 insertions, 7 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 | |||
@@ -31,64 +31,79 @@ ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const cha | |||
31 | setImage(img); | 31 | setImage(img); |
32 | } | 32 | } |
33 | 33 | ||
34 | void ImageScrollView::setImage(const QImage&img) | 34 | void ImageScrollView::setImage(const QImage&img) |
35 | { | 35 | { |
36 | _image_data = QImage(); | 36 | _image_data = QImage(); |
37 | _original_data=img; | 37 | _original_data=img; |
38 | _original_data.convertDepth(QPixmap::defaultDepth()); | 38 | _original_data.convertDepth(QPixmap::defaultDepth()); |
39 | _original_data.setAlphaBuffer(false); | 39 | _original_data.setAlphaBuffer(false); |
40 | m_lastName = ""; | 40 | m_lastName = ""; |
41 | if (first_resize_done) { | 41 | if (first_resize_done) { |
42 | generateImage(); | 42 | generateImage(); |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | void ImageScrollView::setImage( const QString& path ) { | 46 | void ImageScrollView::setImage( const QString& path ) { |
47 | odebug << "load new image " << oendl; | 47 | odebug << "load new image " << oendl; |
48 | if (m_lastName == path) return; | 48 | if (m_lastName == path) return; |
49 | m_lastName = path; | 49 | m_lastName = path; |
50 | _original_data.load(path); | 50 | _original_data.load(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 */ |
60 | void ImageScrollView::init() | 60 | void 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 | ||
74 | void ImageScrollView::setAutoRotate(bool how) | 89 | void ImageScrollView::setAutoRotate(bool how) |
75 | { | 90 | { |
76 | /* to avoid double repaints */ | 91 | /* to avoid double repaints */ |
77 | if (rotate_to_fit != how) { | 92 | if (rotate_to_fit != how) { |
78 | rotate_to_fit = how; | 93 | rotate_to_fit = how; |
79 | _image_data = QImage(); | 94 | _image_data = QImage(); |
80 | generateImage(); | 95 | generateImage(); |
81 | } | 96 | } |
82 | } | 97 | } |
83 | 98 | ||
84 | void ImageScrollView::setAutoScale(bool how) | 99 | void ImageScrollView::setAutoScale(bool how) |
85 | { | 100 | { |
86 | scale_to_fit = how; | 101 | scale_to_fit = how; |
87 | if (!how) { | 102 | if (!how) { |
88 | rotate_to_fit = false; | 103 | rotate_to_fit = false; |
89 | } | 104 | } |
90 | _image_data = QImage(); | 105 | _image_data = QImage(); |
91 | generateImage(); | 106 | generateImage(); |
92 | } | 107 | } |
93 | 108 | ||
94 | ImageScrollView::~ImageScrollView() | 109 | ImageScrollView::~ImageScrollView() |
@@ -222,145 +237,164 @@ void ImageScrollView::rotate_into_data(Rotation r) | |||
222 | _image_data = dest; | 237 | _image_data = dest; |
223 | } | 238 | } |
224 | 239 | ||
225 | void ImageScrollView::generateImage() | 240 | void ImageScrollView::generateImage() |
226 | { | 241 | { |
227 | Rotation r = Rotate0; | 242 | Rotation r = Rotate0; |
228 | if (width()>height()&&_original_data.width()<_original_data.height() || | 243 | if (width()>height()&&_original_data.width()<_original_data.height() || |
229 | width()<height()&&_original_data.width()>_original_data.height()) { | 244 | width()<height()&&_original_data.width()>_original_data.height()) { |
230 | if (rotate_to_fit) r = Rotate90; | 245 | if (rotate_to_fit) r = Rotate90; |
231 | } | 246 | } |
232 | odebug << " r = " << r << oendl; | 247 | odebug << " r = " << r << oendl; |
233 | if (scale_to_fit) { | 248 | if (scale_to_fit) { |
234 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { | 249 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { |
235 | odebug << "Rescaling data" << oendl; | 250 | odebug << "Rescaling data" << oendl; |
236 | if (r==Rotate0) { | 251 | if (r==Rotate0) { |
237 | _image_data = _original_data; | 252 | _image_data = _original_data; |
238 | } else { | 253 | } else { |
239 | rotate_into_data(r); | 254 | rotate_into_data(r); |
240 | } | 255 | } |
241 | } | 256 | } |
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 | ||
257 | void ImageScrollView::resizeEvent(QResizeEvent * e) | 283 | void 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 | ||
265 | void ImageScrollView::keyPressEvent(QKeyEvent * e) | 297 | void 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); |
275 | e->accept(); | 307 | e->accept(); |
276 | } else if (e->key()==Qt::Key_Up) { | 308 | } else if (e->key()==Qt::Key_Up) { |
277 | scrollBy(0,0-dy); | 309 | scrollBy(0,0-dy); |
278 | e->accept(); | 310 | e->accept(); |
279 | } else if (e->key()==Qt::Key_Down) { | 311 | } else if (e->key()==Qt::Key_Down) { |
280 | scrollBy(0,dy); | 312 | scrollBy(0,dy); |
281 | e->accept(); | 313 | e->accept(); |
282 | } else { | 314 | } else { |
283 | e->ignore(); | 315 | e->ignore(); |
284 | } | 316 | } |
285 | QScrollView::keyPressEvent(e); | 317 | QScrollView::keyPressEvent(e); |
286 | } | 318 | } |
287 | 319 | ||
288 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | 320 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) |
289 | { | 321 | { |
290 | int w = clipw; | 322 | int w = clipw; |
291 | int h = cliph; | 323 | int h = cliph; |
292 | int x = clipx; | 324 | int x = clipx; |
293 | int y = clipy; | 325 | int y = clipy; |
294 | bool erase = false; | 326 | bool erase = false; |
295 | 327 | ||
296 | if (!_pdata.size().isValid()) { | 328 | if (!_pdata.size().isValid()) { |
297 | p->fillRect(clipx,clipy,clipw,cliph,white); | 329 | p->fillRect(clipx,clipy,clipw,cliph,white); |
298 | return; | 330 | return; |
299 | } | 331 | } |
300 | if (w>_pdata.width()) { | 332 | if (w>_pdata.width()) { |
301 | w=_pdata.width(); | 333 | w=_pdata.width(); |
302 | x = 0; | 334 | x = 0; |
303 | erase = true; | 335 | erase = true; |
304 | } else if (x+w>_pdata.width()){ | 336 | } else if (x+w>_pdata.width()){ |
305 | x = _pdata.width()-w; | 337 | x = _pdata.width()-w; |
306 | } | 338 | } |
307 | if (h>_pdata.height()) { | 339 | if (h>_pdata.height()) { |
308 | h=_pdata.height(); | 340 | h=_pdata.height(); |
309 | y = 0; | 341 | y = 0; |
310 | erase = true; | 342 | erase = true; |
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! */ |
321 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | 353 | void 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) { |
335 | diffx=0-xbar->value(); | 368 | diffx=0-xbar->value(); |
336 | } | 369 | } |
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 | ||
349 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * ) | 382 | void 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 | ||
360 | void ImageScrollView::setDestructiveClose() { | 394 | void 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,64 +1,71 @@ | |||
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 | |||
10 | class QPainter; | 14 | class QPainter; |
11 | 15 | ||
12 | class ImageScrollView:public QScrollView | 16 | class ImageScrollView:public QScrollView |
13 | { | 17 | { |
14 | Q_OBJECT | 18 | Q_OBJECT |
15 | public: | 19 | public: |
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&); |
22 | virtual void setImage( const QString& path ); | 26 | virtual void setImage( const QString& path ); |
23 | virtual void setDestructiveClose(); | 27 | virtual void setDestructiveClose(); |
24 | 28 | ||
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 | ||
35 | signals: | 39 | signals: |
36 | void sig_return(); | 40 | void sig_return(); |
41 | void imageSizeChanged( const QSize& ); | ||
42 | void viewportSizeChanged( const QSize& ); | ||
37 | 43 | ||
38 | protected: | 44 | protected: |
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); |
54 | 61 | ||
55 | virtual void rotate_into_data(Rotation r); | 62 | virtual void rotate_into_data(Rotation r); |
56 | virtual void generateImage(); | 63 | virtual void generateImage(); |
57 | 64 | ||
58 | protected slots: | 65 | protected slots: |
59 | virtual void viewportMouseMoveEvent(QMouseEvent* e); | 66 | virtual void viewportMouseMoveEvent(QMouseEvent* e); |
60 | virtual void contentsMousePressEvent ( QMouseEvent * e); | 67 | virtual void contentsMousePressEvent ( QMouseEvent * e); |
61 | virtual void resizeEvent(QResizeEvent * e); | 68 | virtual void resizeEvent(QResizeEvent * e); |
62 | virtual void keyPressEvent(QKeyEvent * e); | 69 | virtual void keyPressEvent(QKeyEvent * e); |
63 | }; | 70 | }; |
64 | #endif | 71 | #endif |
diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp index 178fbd4..ffa3c0c 100644 --- a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp +++ b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp | |||
@@ -1,60 +1,64 @@ | |||
1 | #include "oimagezoomer.h" | 1 | #include "oimagezoomer.h" |
2 | 2 | ||
3 | #include <qimage.h> | 3 | #include <qimage.h> |
4 | #include <qpixmap.h> | 4 | #include <qpixmap.h> |
5 | #include <qpainter.h> | 5 | #include <qpainter.h> |
6 | #include <qrect.h> | 6 | #include <qrect.h> |
7 | #include <qpoint.h> | 7 | #include <qpoint.h> |
8 | #include <qsize.h> | 8 | #include <qsize.h> |
9 | 9 | ||
10 | namespace Opie { | 10 | namespace Opie { |
11 | namespace MM { | 11 | namespace MM { |
12 | OImageZoomer::OImageZoomer( QWidget* parent, const char* name, WFlags fl ) | 12 | OImageZoomer::OImageZoomer( QWidget* parent, const char* name, WFlags fl ) |
13 | : QFrame( parent, name, fl ) { | 13 | : QFrame( parent, name, fl ) { |
14 | init(); | 14 | init(); |
15 | } | 15 | } |
16 | 16 | ||
17 | OImageZoomer::OImageZoomer( const QPixmap& pix, QWidget* par, const char* name, WFlags fl ) | 17 | OImageZoomer::OImageZoomer( const QPixmap& pix, QWidget* par, const char* name, WFlags fl ) |
18 | : QFrame( par, name, fl ) { | 18 | : QFrame( par, name, fl ) { |
19 | init(); | 19 | init(); |
20 | setImage( pix ); | 20 | setImage( pix ); |
21 | } | 21 | } |
22 | 22 | ||
23 | OImageZoomer::OImageZoomer( const QSize& pSize, const QSize& vSize, QWidget* par, | 23 | OImageZoomer::OImageZoomer( const QSize& pSize, const QSize& vSize, QWidget* par, |
24 | const char* name, WFlags fl ) | 24 | const char* name, WFlags fl ) |
25 | : QFrame( par, name, fl ), m_imgSize( pSize ),m_visSize( vSize ) { | 25 | : QFrame( par, name, fl ), m_imgSize( pSize ),m_visSize( vSize ) { |
26 | init(); | 26 | init(); |
27 | } | 27 | } |
28 | 28 | ||
29 | OImageZoomer::~OImageZoomer() { | ||
30 | |||
31 | } | ||
32 | |||
29 | void OImageZoomer::init() { | 33 | void OImageZoomer::init() { |
30 | setFrameStyle( Panel | Sunken ); | 34 | setFrameStyle( Panel | Sunken ); |
31 | } | 35 | } |
32 | 36 | ||
33 | void OImageZoomer::setImageSize( const QSize& size ) { | 37 | void OImageZoomer::setImageSize( const QSize& size ) { |
34 | m_imgSize = size; | 38 | m_imgSize = size; |
35 | repaint(); | 39 | repaint(); |
36 | } | 40 | } |
37 | void OImageZoomer::setViewPortSize( const QSize& size ) { | 41 | void OImageZoomer::setViewPortSize( const QSize& size ) { |
38 | m_visSize = size; | 42 | m_visSize = size; |
39 | repaint(); | 43 | repaint(); |
40 | } | 44 | } |
41 | 45 | ||
42 | void OImageZoomer::setVisiblePoint( const QPoint& pt ) { | 46 | void OImageZoomer::setVisiblePoint( const QPoint& pt ) { |
43 | m_visPt = pt; | 47 | m_visPt = pt; |
44 | repaint(); | 48 | repaint(); |
45 | } | 49 | } |
46 | 50 | ||
47 | void OImageZoomer::setImage( const QImage& img) { | 51 | void OImageZoomer::setImage( const QImage& img) { |
48 | m_img = img; | 52 | m_img = img; |
49 | resizeEvent( 0 ); | 53 | resizeEvent( 0 ); |
50 | repaint(); | 54 | repaint(); |
51 | } | 55 | } |
52 | 56 | ||
53 | void OImageZoomer::setImage( const QPixmap& pix) { | 57 | void OImageZoomer::setImage( const QPixmap& pix) { |
54 | setImage( pix.convertToImage() ); | 58 | setImage( pix.convertToImage() ); |
55 | } | 59 | } |
56 | 60 | ||
57 | void OImageZoomer::resizeEvent( QResizeEvent* ev ) { | 61 | void OImageZoomer::resizeEvent( QResizeEvent* ev ) { |
58 | QFrame::resizeEvent( ev ); | 62 | QFrame::resizeEvent( ev ); |
59 | setBackgroundOrigin( QWidget::WidgetOrigin ); | 63 | setBackgroundOrigin( QWidget::WidgetOrigin ); |
60 | // TODO Qt3 use PalettePixmap and use size | 64 | // TODO Qt3 use PalettePixmap and use size |
@@ -64,53 +68,53 @@ void OImageZoomer::resizeEvent( QResizeEvent* ev ) { | |||
64 | 68 | ||
65 | void OImageZoomer::drawContents( QPainter* p ) { | 69 | void OImageZoomer::drawContents( QPainter* p ) { |
66 | /* | 70 | /* |
67 | * if the page size | 71 | * if the page size |
68 | */ | 72 | */ |
69 | if ( m_imgSize.isEmpty() ) | 73 | if ( m_imgSize.isEmpty() ) |
70 | return; | 74 | return; |
71 | 75 | ||
72 | /* | 76 | /* |
73 | * paint a red rect which represents the visible size | 77 | * paint a red rect which represents the visible size |
74 | * | 78 | * |
75 | * We need to recalculate x,y and width and height of the | 79 | * We need to recalculate x,y and width and height of the |
76 | * rect. So image size relates to contentRect | 80 | * rect. So image size relates to contentRect |
77 | * | 81 | * |
78 | */ | 82 | */ |
79 | QRect c( contentsRect() ); | 83 | QRect c( contentsRect() ); |
80 | p->setPen( Qt::red ); | 84 | p->setPen( Qt::red ); |
81 | 85 | ||
82 | int len = m_imgSize.width(); | 86 | int len = m_imgSize.width(); |
83 | int x = (c.width()*m_visPt.x())/len + c.x(); | 87 | int x = (c.width()*m_visPt.x())/len + c.x(); |
84 | int w = (c.width()*m_visSize.width() )/len + c.x(); | 88 | int w = (c.width()*m_visSize.width() )/len + c.x(); |
85 | if ( w > c.width() ) w = c.width(); | 89 | if ( w > c.width() ) w = c.width(); |
86 | 90 | ||
87 | len = m_imgSize.height(); | 91 | len = m_imgSize.height(); |
88 | int y = (c.height()*m_visPt.y() )/len + c.y(); | 92 | int y = (c.height()*m_visPt.y() )/len + c.y(); |
89 | int h = (c.height()*m_visSize.height() )/len + c.y(); | 93 | int h = (c.height()*m_visSize.height() )/len + c.y(); |
90 | if ( h > c.height() ) h = c.height(); | 94 | if ( h > c.height() ) h = c.height(); |
91 | 95 | ||
92 | p->drawRect( x, y, w, h ); | 96 | p->drawRect( x, y, w, h ); |
93 | } | 97 | } |
94 | 98 | ||
95 | void OImageZoomer::mousePressEvent( QMouseEvent* ) { | 99 | void OImageZoomer::mousePressEvent( QMouseEvent* ) { |
96 | 100 | m_mouseX = m_mouseY = -1; | |
97 | } | 101 | } |
98 | 102 | ||
99 | void OImageZoomer::mouseMoveEvent( QMouseEvent* ev ) { | 103 | void OImageZoomer::mouseMoveEvent( QMouseEvent* ev ) { |
100 | int mx, my; | 104 | int mx, my; |
101 | mx = ev->x(); | 105 | mx = ev->x(); |
102 | my = ev->y(); | 106 | my = ev->y(); |
103 | 107 | ||
104 | if ( m_mouseX != -1 && m_mouseY != -1 ) { | 108 | if ( m_mouseX != -1 && m_mouseY != -1 ) { |
105 | int diffx = m_mouseX-mx; | 109 | int diffx = ( mx - m_mouseX ) * m_imgSize.width() / width(); |
106 | int diffy = m_mouseY-my; | 110 | int diffy = ( my - m_mouseY ) * m_imgSize.height() / height(); |
107 | // emit zoomAreaRel( diffx, diffy ); | 111 | emit zoomAreaRel( diffx, diffy ); |
108 | // emit zoomArea( | 112 | emit zoomArea(m_visPt.x()+diffx, m_visPt.y()+diffy ); |
109 | } | 113 | } |
110 | m_mouseX = mx; | 114 | m_mouseX = mx; |
111 | m_mouseY = my; | 115 | m_mouseY = my; |
112 | } | 116 | } |
113 | 117 | ||
114 | 118 | ||
115 | } | 119 | } |
116 | } | 120 | } |