-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.cpp | 116 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.h | 66 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/phunk_view.pro | 6 |
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 | |||
10 | namespace Opie { | ||
11 | namespace MM { | ||
12 | OImageZoomer::OImageZoomer( QWidget* parent, const char* name, WFlags fl ) | ||
13 | : QFrame( parent, name, fl ) { | ||
14 | init(); | ||
15 | } | ||
16 | |||
17 | OImageZoomer::OImageZoomer( const QPixmap& pix, QWidget* par, const char* name, WFlags fl ) | ||
18 | : QFrame( par, name, fl ) { | ||
19 | init(); | ||
20 | setImage( pix ); | ||
21 | } | ||
22 | |||
23 | OImageZoomer::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 | |||
29 | void OImageZoomer::init() { | ||
30 | setFrameStyle( Panel | Sunken ); | ||
31 | } | ||
32 | |||
33 | void OImageZoomer::setImageSize( const QSize& size ) { | ||
34 | m_imgSize = size; | ||
35 | repaint(); | ||
36 | } | ||
37 | void OImageZoomer::setViewPortSize( const QSize& size ) { | ||
38 | m_visSize = size; | ||
39 | repaint(); | ||
40 | } | ||
41 | |||
42 | void OImageZoomer::setVisiblePoint( const QPoint& pt ) { | ||
43 | m_visPt = pt; | ||
44 | repaint(); | ||
45 | } | ||
46 | |||
47 | void OImageZoomer::setImage( const QImage& img) { | ||
48 | m_img = img; | ||
49 | resizeEvent( 0 ); | ||
50 | repaint(); | ||
51 | } | ||
52 | |||
53 | void OImageZoomer::setImage( const QPixmap& pix) { | ||
54 | setImage( pix.convertToImage() ); | ||
55 | } | ||
56 | |||
57 | void 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 | |||
65 | void 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 | |||
95 | void OImageZoomer::mousePressEvent( QMouseEvent* ) { | ||
96 | |||
97 | } | ||
98 | |||
99 | void 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 | |||
7 | class QPixmap; | ||
8 | class QRect; | ||
9 | class QPoint; | ||
10 | |||
11 | |||
12 | namespace Opie { | ||
13 | namespace 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 | */ | ||
23 | class OImageZoomer : public QFrame { | ||
24 | Q_OBJECT | ||
25 | public: | ||
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 | |||
32 | public 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 | |||
40 | signals: | ||
41 | void zoomAreaRel( int,int ); | ||
42 | void zoomArea( int,int ); | ||
43 | |||
44 | public: | ||
45 | void resizeEvent( QResizeEvent* ); | ||
46 | |||
47 | protected: | ||
48 | void drawContents( QPainter* p ); | ||
49 | void mousePressEvent( QMouseEvent* ev ); | ||
50 | void mouseMoveEvent( QMouseEvent* ev ); | ||
51 | |||
52 | private: | ||
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 | |||
60 | inline 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 | |||
@@ -1,38 +1,40 @@ | |||
1 | CONFIG += qt warn_on quick-app | 1 | CONFIG += qt warn_on quick-app |
2 | DESTDIR = $(OPIEDIR)/bin | 2 | DESTDIR = $(OPIEDIR)/bin |
3 | TEMPLATE = app | 3 | TEMPLATE = app |
4 | TARGET = opie-eye | 4 | TARGET = opie-eye |
5 | # the name of the resulting object | 5 | # the name of the resulting object |
6 | 6 | ||
7 | HEADERS = gui/iconview.h gui/filesystem.h gui/mainwindow.h \ | 7 | 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 | ||
19 | SOURCES = gui/iconview.cpp gui/filesystem.cpp gui/mainwindow.cpp \ | 20 | SOURCES = 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 | ||
28 | INTERFACES = | 30 | INTERFACES = |
29 | # list of ui files | 31 | # list of ui files |
30 | 32 | ||
31 | INCLUDEPATH += . $(OPIEDIR)/include | 33 | INCLUDEPATH += . $(OPIEDIR)/include |
32 | DEPENDPATH += $(OPIEDIR)/include | 34 | DEPENDPATH += $(OPIEDIR)/include |
33 | 35 | ||
34 | 36 | ||
35 | 37 | ||
36 | LIBS += -lqpe -lopiecore2 -lopieui2 | 38 | LIBS += -lqpe -lopiecore2 -lopieui2 |
37 | 39 | ||
38 | include ( $(OPIEDIR)/include.pro ) | 40 | include ( $(OPIEDIR)/include.pro ) |