summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-05 00:09:04 (UTC)
committer alwin <alwin>2004-04-05 00:09:04 (UTC)
commitb0ceb8843ebe9ee3054faa98f08bd255df955aa3 (patch) (unidiff)
tree0ff209155b8b442b7810bc33b5e49cdd34d1fad2
parent7485cd42befd86ad035ef4fa29d6e8f728b1e211 (diff)
downloadopie-b0ceb8843ebe9ee3054faa98f08bd255df955aa3.zip
opie-b0ceb8843ebe9ee3054faa98f08bd255df955aa3.tar.gz
opie-b0ceb8843ebe9ee3054faa98f08bd255df955aa3.tar.bz2
ok, found the problem with moving the image via pen/mouse
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp22
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h4
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,37 +1,41 @@
1#include "imagescrollview.h" 1#include "imagescrollview.h"
2 2
3#include <opie2/odebug.h>
4
5using namespace Opie::Core;
6
3#include <qimage.h> 7#include <qimage.h>
4#include <qlayout.h> 8#include <qlayout.h>
5 9
6ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f) 10ImageScrollView::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
12ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f) 16ImageScrollView::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
18void ImageScrollView::setImage(const QImage&img) 22void 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 */
25void ImageScrollView::init() 29void ImageScrollView::init()
26{ 30{
27 viewport()->setBackgroundColor(white); 31 viewport()->setBackgroundColor(white);
28 resizeContents(_image_data.width(),_image_data.height()); 32 resizeContents(_image_data.width(),_image_data.height());
29} 33}
30 34
31ImageScrollView::~ImageScrollView() 35ImageScrollView::~ImageScrollView()
32{ 36{
33} 37}
34 38
35void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) 39void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph)
36{ 40{
37 int w = clipw; 41 int w = clipw;
@@ -39,59 +43,63 @@ void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw
39 int x = clipx; 43 int x = clipx;
40 int y = clipy; 44 int y = clipy;
41 bool erase = false; 45 bool erase = false;
42 46
43 if (w>_image_data.width()) { 47 if (w>_image_data.width()) {
44 w=_image_data.width(); 48 w=_image_data.width();
45 x = 0; 49 x = 0;
46 erase = true; 50 erase = true;
47 } else if (x+w>_image_data.width()){ 51 } else if (x+w>_image_data.width()){
48 x = _image_data.width()-w; 52 x = _image_data.width()-w;
49 } 53 }
50 if (h>_image_data.height()) { 54 if (h>_image_data.height()) {
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! */
63void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) 68void 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
74void ImageScrollView::contentsMouseReleaseEvent ( QMouseEvent * e) 80void 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
79void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) 86void 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 */
85ImageDlg::ImageDlg(const QString&fname,QWidget * parent, const char * name) 93ImageDlg::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}
94 102
95ImageDlg::~ImageDlg() 103ImageDlg::~ImageDlg()
96{ 104{
97} 105}
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,26 +1,26 @@
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
9class QPainter; 9class QPainter;
10 10
11class ImageScrollView:public QScrollView 11class ImageScrollView:public QScrollView
12{ 12{
13 Q_OBJECT 13 Q_OBJECT
14public: 14public:
15 ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0 ); 15 ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0 );
16 ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0 ); 16 ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0 );
17 virtual ~ImageScrollView(); 17 virtual ~ImageScrollView();
18 18
19 void setImage(const QImage&); 19 void setImage(const QImage&);
20protected: 20protected:
21 virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); 21 virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
22 void init(); 22 void init();
23 23
24 QImage _image_data; 24 QImage _image_data;
25 25
26 int _mouseStartPosX,_mouseStartPosY; 26 int _mouseStartPosX,_mouseStartPosY;