-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 22 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 4 |
2 files changed, 17 insertions, 9 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp index f36b717..019f376 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp | |||
@@ -1,25 +1,29 @@ | |||
1 | #include "imagescrollview.h" | 1 | #include "imagescrollview.h" |
2 | 2 | ||
3 | #include <opie2/odebug.h> | ||
4 | |||
5 | using namespace Opie::Core; | ||
6 | |||
3 | #include <qimage.h> | 7 | #include <qimage.h> |
4 | #include <qlayout.h> | 8 | #include <qlayout.h> |
5 | 9 | ||
6 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f) | 10 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f) |
7 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(img) | 11 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(img) |
8 | { | 12 | { |
9 | init(); | 13 | init(); |
10 | } | 14 | } |
11 | 15 | ||
12 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f) | 16 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f) |
13 | :QScrollView(parent,name,f/*|Qt::WRepaintNoErase*/),_image_data(img) | 17 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(img) |
14 | { | 18 | { |
15 | init(); | 19 | init(); |
16 | } | 20 | } |
17 | 21 | ||
18 | void ImageScrollView::setImage(const QImage&img) | 22 | void ImageScrollView::setImage(const QImage&img) |
19 | { | 23 | { |
20 | _image_data = img; | 24 | _image_data = img; |
21 | init(); | 25 | init(); |
22 | } | 26 | } |
23 | 27 | ||
24 | /* should be called every time the QImage changed it content */ | 28 | /* should be called every time the QImage changed it content */ |
25 | void ImageScrollView::init() | 29 | void ImageScrollView::init() |
@@ -51,43 +55,47 @@ void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw | |||
51 | h=_image_data.height(); | 55 | h=_image_data.height(); |
52 | y = 0; | 56 | y = 0; |
53 | erase = true; | 57 | erase = true; |
54 | } else if (y+h>_image_data.height()){ | 58 | } else if (y+h>_image_data.height()){ |
55 | y = _image_data.height()-h; | 59 | y = _image_data.height()-h; |
56 | } | 60 | } |
57 | if (erase) { | 61 | if (erase) { |
58 | p->fillRect(clipx,clipy,clipw,cliph,white); | 62 | p->fillRect(clipx,clipy,clipw,cliph,white); |
59 | } | 63 | } |
60 | p->drawImage(clipx,clipy,_image_data,x,y,w,h); | 64 | p->drawImage(clipx,clipy,_image_data,x,y,w,h); |
61 | } | 65 | } |
62 | 66 | ||
67 | /* using the real geometry points and not the translated points is wanted! */ | ||
63 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | 68 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) |
64 | { | 69 | { |
65 | int mx, my; | 70 | int mx, my; |
66 | viewportToContents( e->x(), e->y(), mx, my ); | 71 | mx = e->x(); |
67 | 72 | my = e->y(); | |
68 | scrollBy(_mouseStartPosX-mx,my-_mouseStartPosY); | 73 | int diffx = _mouseStartPosX-mx; |
69 | 74 | int diffy = _mouseStartPosY-my; | |
75 | scrollBy(diffx,diffy); | ||
70 | _mouseStartPosX=mx; | 76 | _mouseStartPosX=mx; |
71 | _mouseStartPosY=my; | 77 | _mouseStartPosY=my; |
72 | } | 78 | } |
73 | 79 | ||
74 | void ImageScrollView::contentsMouseReleaseEvent ( QMouseEvent * e) | 80 | void ImageScrollView::contentsMouseReleaseEvent ( QMouseEvent * e) |
75 | { | 81 | { |
76 | viewportToContents( e->x(), e->y(), _mouseStartPosX,_mouseStartPosY ); | 82 | _mouseStartPosX = e->x(); |
83 | _mouseStartPosY = e->y(); | ||
77 | } | 84 | } |
78 | 85 | ||
79 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) | 86 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) |
80 | { | 87 | { |
81 | viewportToContents( e->x(), e->y(), _mouseStartPosX,_mouseStartPosY ); | 88 | _mouseStartPosX = e->x(); |
89 | _mouseStartPosY = e->y(); | ||
82 | } | 90 | } |
83 | 91 | ||
84 | /* for testing */ | 92 | /* for testing */ |
85 | ImageDlg::ImageDlg(const QString&fname,QWidget * parent, const char * name) | 93 | ImageDlg::ImageDlg(const QString&fname,QWidget * parent, const char * name) |
86 | :QDialog(parent,name,true,WStyle_ContextHelp) | 94 | :QDialog(parent,name,true,WStyle_ContextHelp) |
87 | { | 95 | { |
88 | QVBoxLayout*dlglayout = new QVBoxLayout(this); | 96 | QVBoxLayout*dlglayout = new QVBoxLayout(this); |
89 | dlglayout->setSpacing(2); | 97 | dlglayout->setSpacing(2); |
90 | dlglayout->setMargin(1); | 98 | dlglayout->setMargin(1); |
91 | ImageScrollView*inf = new ImageScrollView(fname,this); | 99 | ImageScrollView*inf = new ImageScrollView(fname,this); |
92 | dlglayout->addWidget(inf); | 100 | dlglayout->addWidget(inf); |
93 | } | 101 | } |
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h index 5836c8d..edea235 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.h +++ b/noncore/graphics/opie-eye/gui/imagescrollview.h | |||
@@ -1,14 +1,14 @@ | |||
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 <qscrollview.h> | 4 | #include <qscrollview.h> |
5 | #include <qimage.h> | 5 | #include <qimage.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qdialog.h> | 7 | #include <qdialog.h> |
8 | 8 | ||
9 | class QPainter; | 9 | class QPainter; |
10 | 10 | ||
11 | class ImageScrollView:public QScrollView | 11 | class ImageScrollView:public QScrollView |
12 | { | 12 | { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | public: | 14 | public: |