Diffstat (limited to 'noncore/graphics/opie-eye/lib') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.cpp | 116 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.h | 66 |
2 files changed, 182 insertions, 0 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 | ||