summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/lib/oimagezoomer.cpp
Unidiff
Diffstat (limited to 'noncore/graphics/opie-eye/lib/oimagezoomer.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/lib/oimagezoomer.cpp116
1 files changed, 116 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
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}