summaryrefslogtreecommitdiff
authorzecke <zecke>2004-04-07 19:13:22 (UTC)
committer zecke <zecke>2004-04-07 19:13:22 (UTC)
commitf8e633dea182beabbb665a25136b43a9dd7d0558 (patch) (unidiff)
tree2bec7c5b73ec358ac44e7158cd4bc3a708521cd2
parent673b99175f7447cbae8eff237f2f9d07be8e0087 (diff)
downloadopie-f8e633dea182beabbb665a25136b43a9dd7d0558.zip
opie-f8e633dea182beabbb665a25136b43a9dd7d0558.tar.gz
opie-f8e633dea182beabbb665a25136b43a9dd7d0558.tar.bz2
Add the ImageZoomer now alwin connect some signals and slots
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/lib/oimagezoomer.cpp116
-rw-r--r--noncore/graphics/opie-eye/lib/oimagezoomer.h66
-rw-r--r--noncore/graphics/opie-eye/phunk_view.pro6
3 files changed, 186 insertions, 2 deletions
diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp
new file mode 100644
index 0000000..178fbd4
--- a/dev/null
+++ b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp
@@ -0,0 +1,116 @@
1#include "oimagezoomer.h"
2
3#include <qimage.h>
4#include <qpixmap.h>
5#include <qpainter.h>
6#include <qrect.h>
7#include <qpoint.h>
8#include <qsize.h>
9
10namespace Opie {
11namespace MM {
12OImageZoomer::OImageZoomer( QWidget* parent, const char* name, WFlags fl )
13 : QFrame( parent, name, fl ) {
14 init();
15}
16
17OImageZoomer::OImageZoomer( const QPixmap& pix, QWidget* par, const char* name, WFlags fl )
18 : QFrame( par, name, fl ) {
19 init();
20 setImage( pix );
21}
22
23OImageZoomer::OImageZoomer( const QSize& pSize, const QSize& vSize, QWidget* par,
24 const char* name, WFlags fl )
25 : QFrame( par, name, fl ), m_imgSize( pSize ),m_visSize( vSize ) {
26 init();
27}
28
29void OImageZoomer::init() {
30 setFrameStyle( Panel | Sunken );
31}
32
33void OImageZoomer::setImageSize( const QSize& size ) {
34 m_imgSize = size;
35 repaint();
36}
37void OImageZoomer::setViewPortSize( const QSize& size ) {
38 m_visSize = size;
39 repaint();
40}
41
42void OImageZoomer::setVisiblePoint( const QPoint& pt ) {
43 m_visPt = pt;
44 repaint();
45}
46
47void OImageZoomer::setImage( const QImage& img) {
48 m_img = img;
49 resizeEvent( 0 );
50 repaint();
51}
52
53void OImageZoomer::setImage( const QPixmap& pix) {
54 setImage( pix.convertToImage() );
55}
56
57void OImageZoomer::resizeEvent( QResizeEvent* ev ) {
58 QFrame::resizeEvent( ev );
59 setBackgroundOrigin( QWidget::WidgetOrigin );
60 // TODO Qt3 use PalettePixmap and use size
61 QPixmap pix; pix.convertFromImage( m_img.smoothScale( size().width(), size().height() ) );
62 setBackgroundPixmap( pix);
63}
64
65void OImageZoomer::drawContents( QPainter* p ) {
66 /*
67 * if the page size
68 */
69 if ( m_imgSize.isEmpty() )
70 return;
71
72 /*
73 * paint a red rect which represents the visible size
74 *
75 * We need to recalculate x,y and width and height of the
76 * rect. So image size relates to contentRect
77 *
78 */
79 QRect c( contentsRect() );
80 p->setPen( Qt::red );
81
82 int len = m_imgSize.width();
83 int x = (c.width()*m_visPt.x())/len + c.x();
84 int w = (c.width()*m_visSize.width() )/len + c.x();
85 if ( w > c.width() ) w = c.width();
86
87 len = m_imgSize.height();
88 int y = (c.height()*m_visPt.y() )/len + c.y();
89 int h = (c.height()*m_visSize.height() )/len + c.y();
90 if ( h > c.height() ) h = c.height();
91
92 p->drawRect( x, y, w, h );
93}
94
95void OImageZoomer::mousePressEvent( QMouseEvent* ) {
96
97}
98
99void OImageZoomer::mouseMoveEvent( QMouseEvent* ev ) {
100 int mx, my;
101 mx = ev->x();
102 my = ev->y();
103
104 if ( m_mouseX != -1 && m_mouseY != -1 ) {
105 int diffx = m_mouseX-mx;
106 int diffy = m_mouseY-my;
107// emit zoomAreaRel( diffx, diffy );
108// emit zoomArea(
109 }
110 m_mouseX = mx;
111 m_mouseY = my;
112}
113
114
115}
116}
diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.h b/noncore/graphics/opie-eye/lib/oimagezoomer.h
new file mode 100644
index 0000000..605416c
--- a/dev/null
+++ b/noncore/graphics/opie-eye/lib/oimagezoomer.h
@@ -0,0 +1,66 @@
1#ifndef OPIE_ODP_IMAGE_ZOOMER_H
2#define OPIE_ODP_IMAGE_ZOOMER_H
3
4#include <qframe.h>
5#include <qimage.h>
6
7class QPixmap;
8class QRect;
9class QPoint;
10
11
12namespace Opie {
13namespace MM {
14
15/**
16 * \brief small class to zoom over a widget
17 * This class takes a QImage or QPixmap
18 * and gets the size of the original image
19 * and provides depending of this widgets size
20 * a zoomer and emits the region which should
21 * be shown / zoomed to
22 */
23class OImageZoomer : public QFrame {
24 Q_OBJECT
25public:
26 OImageZoomer( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
27 OImageZoomer( const QPixmap&,QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
28 OImageZoomer( const QImage&, QWidget* parent = 0, const char* name= 0, WFlags fl = 0 );
29 OImageZoomer( const QSize&, const QSize&, QWidget* par, const char*, WFlags fl );
30 ~OImageZoomer();
31
32public slots:
33 void setImageSize( const QSize& );
34 void setViewPortSize( const QSize& );
35 void setVisiblePoint( const QPoint& );
36 void setVisiblePoint( int x, int y );
37 void setImage( const QImage& );
38 void setImage( const QPixmap& );
39
40signals:
41 void zoomAreaRel( int,int );
42 void zoomArea( int,int );
43
44public:
45 void resizeEvent( QResizeEvent* );
46
47protected:
48 void drawContents( QPainter* p );
49 void mousePressEvent( QMouseEvent* ev );
50 void mouseMoveEvent( QMouseEvent* ev );
51
52private:
53 void init();
54 QImage m_img;
55 QSize m_imgSize, m_visSize;
56 QPoint m_visPt;
57 int m_mouseX, m_mouseY;
58};
59
60inline void OImageZoomer::setVisiblePoint( int x, int y ) {
61 setVisiblePoint( QPoint( x, y ) );
62}
63
64}
65}
66#endif
diff --git a/noncore/graphics/opie-eye/phunk_view.pro b/noncore/graphics/opie-eye/phunk_view.pro
index a825580..e9abe72 100644
--- a/noncore/graphics/opie-eye/phunk_view.pro
+++ b/noncore/graphics/opie-eye/phunk_view.pro
@@ -8,24 +8,26 @@ HEADERS = gui/iconview.h gui/filesystem.h gui/mainwindow.h \
8 lib/imagecache.h impl/dir/dir_dirview.h \ 8 lib/imagecache.h impl/dir/dir_dirview.h \
9 iface/dirview.h iface/dirlister.h iface/ifaceinfo.h \ 9 iface/dirview.h iface/dirlister.h iface/ifaceinfo.h \
10 impl/dir/dir_lister.h impl/dir/dir_ifaceinfo.h \ 10 impl/dir/dir_lister.h impl/dir/dir_ifaceinfo.h \
11 lib/slavemaster.h \ 11 lib/slavemaster.h \
12 iface/slaveiface.h \ 12 iface/slaveiface.h \
13 gui/imageinfoui.h gui/imagescrollview.h \ 13 gui/imageinfoui.h gui/imagescrollview.h \
14 gui/imageview.h 14 gui/imageview.h \
15 lib/oimagezoomer.h
15 16
16# A list header files 17# A list header files
17 18
18 19
19SOURCES = gui/iconview.cpp gui/filesystem.cpp gui/mainwindow.cpp \ 20SOURCES = gui/iconview.cpp gui/filesystem.cpp gui/mainwindow.cpp \
20 lib/imagecache.cpp lib/viewmap.cpp \ 21 lib/imagecache.cpp lib/viewmap.cpp \
21 impl/dir/dir_dirview.cpp iface/dirlister.cpp \ 22 impl/dir/dir_dirview.cpp iface/dirlister.cpp \
22 iface/dirview.cpp impl/dir/dir_lister.cpp \ 23 iface/dirview.cpp impl/dir/dir_lister.cpp \
23 impl/dir/dir_ifaceinfo.cpp lib/slavemaster.cpp \ 24 impl/dir/dir_ifaceinfo.cpp lib/slavemaster.cpp \
24 gui/imageinfoui.cpp gui/imagescrollview.cpp \ 25 gui/imageinfoui.cpp gui/imagescrollview.cpp \
25 gui/imageview.cpp 26 gui/imageview.cpp \
27 lib/oimagezoomer.cpp
26# A list of source files 28# A list of source files
27 29
28INTERFACES = 30INTERFACES =
29# list of ui files 31# list of ui files
30 32
31INCLUDEPATH += . $(OPIEDIR)/include 33INCLUDEPATH += . $(OPIEDIR)/include