author | alwin <alwin> | 2004-04-04 23:02:29 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-04-04 23:02:29 (UTC) |
commit | 318c10ce368a6bf99f3412a2ff1ef0a9177c965a (patch) (unidiff) | |
tree | a38485b18eb9a2cd4a8bb5bccde0f91df3c0521e /noncore/graphics/opie-eye/gui/imagescrollview.cpp | |
parent | 9242abc186f0acc3df7020aaa219c435c2e00672 (diff) | |
download | opie-318c10ce368a6bf99f3412a2ff1ef0a9177c965a.zip opie-318c10ce368a6bf99f3412a2ff1ef0a9177c965a.tar.gz opie-318c10ce368a6bf99f3412a2ff1ef0a9177c965a.tar.bz2 |
ok, the first - realy first - working shot of a special
ImageScrollView. But the most important things are working now and
can be used.
Todo:
- check on a pda(!) doublebuffering (bitBlt) - may be it will paint faster
- implemented mouseEvents seems not working good, its just a first try.
Diffstat (limited to 'noncore/graphics/opie-eye/gui/imagescrollview.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp new file mode 100644 index 0000000..f36b717 --- a/dev/null +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp | |||
@@ -0,0 +1,97 @@ | |||
1 | #include "imagescrollview.h" | ||
2 | |||
3 | #include <qimage.h> | ||
4 | #include <qlayout.h> | ||
5 | |||
6 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f) | ||
7 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(img) | ||
8 | { | ||
9 | init(); | ||
10 | } | ||
11 | |||
12 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f) | ||
13 | :QScrollView(parent,name,f/*|Qt::WRepaintNoErase*/),_image_data(img) | ||
14 | { | ||
15 | init(); | ||
16 | } | ||
17 | |||
18 | void ImageScrollView::setImage(const QImage&img) | ||
19 | { | ||
20 | _image_data = img; | ||
21 | init(); | ||
22 | } | ||
23 | |||
24 | /* should be called every time the QImage changed it content */ | ||
25 | void ImageScrollView::init() | ||
26 | { | ||
27 | viewport()->setBackgroundColor(white); | ||
28 | resizeContents(_image_data.width(),_image_data.height()); | ||
29 | } | ||
30 | |||
31 | ImageScrollView::~ImageScrollView() | ||
32 | { | ||
33 | } | ||
34 | |||
35 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | ||
36 | { | ||
37 | int w = clipw; | ||
38 | int h = cliph; | ||
39 | int x = clipx; | ||
40 | int y = clipy; | ||
41 | bool erase = false; | ||
42 | |||
43 | if (w>_image_data.width()) { | ||
44 | w=_image_data.width(); | ||
45 | x = 0; | ||
46 | erase = true; | ||
47 | } else if (x+w>_image_data.width()){ | ||
48 | x = _image_data.width()-w; | ||
49 | } | ||
50 | if (h>_image_data.height()) { | ||
51 | h=_image_data.height(); | ||
52 | y = 0; | ||
53 | erase = true; | ||
54 | } else if (y+h>_image_data.height()){ | ||
55 | y = _image_data.height()-h; | ||
56 | } | ||
57 | if (erase) { | ||
58 | p->fillRect(clipx,clipy,clipw,cliph,white); | ||
59 | } | ||
60 | p->drawImage(clipx,clipy,_image_data,x,y,w,h); | ||
61 | } | ||
62 | |||
63 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | ||
64 | { | ||
65 | int mx, my; | ||
66 | viewportToContents( e->x(), e->y(), mx, my ); | ||
67 | |||
68 | scrollBy(_mouseStartPosX-mx,my-_mouseStartPosY); | ||
69 | |||
70 | _mouseStartPosX=mx; | ||
71 | _mouseStartPosY=my; | ||
72 | } | ||
73 | |||
74 | void ImageScrollView::contentsMouseReleaseEvent ( QMouseEvent * e) | ||
75 | { | ||
76 | viewportToContents( e->x(), e->y(), _mouseStartPosX,_mouseStartPosY ); | ||
77 | } | ||
78 | |||
79 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) | ||
80 | { | ||
81 | viewportToContents( e->x(), e->y(), _mouseStartPosX,_mouseStartPosY ); | ||
82 | } | ||
83 | |||
84 | /* for testing */ | ||
85 | ImageDlg::ImageDlg(const QString&fname,QWidget * parent, const char * name) | ||
86 | :QDialog(parent,name,true,WStyle_ContextHelp) | ||
87 | { | ||
88 | QVBoxLayout*dlglayout = new QVBoxLayout(this); | ||
89 | dlglayout->setSpacing(2); | ||
90 | dlglayout->setMargin(1); | ||
91 | ImageScrollView*inf = new ImageScrollView(fname,this); | ||
92 | dlglayout->addWidget(inf); | ||
93 | } | ||
94 | |||
95 | ImageDlg::~ImageDlg() | ||
96 | { | ||
97 | } | ||