Diffstat (limited to 'noncore/graphics/opie-eye/lib') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.cpp | 233 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.h | 141 |
2 files changed, 0 insertions, 374 deletions
diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp deleted file mode 100644 index d1eec67..0000000 --- a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp +++ b/dev/null | |||
@@ -1,233 +0,0 @@ | |||
1 | #include "oimagezoomer.h" | ||
2 | |||
3 | #include <opie2/odebug.h> | ||
4 | |||
5 | #include <qimage.h> | ||
6 | #include <qpixmap.h> | ||
7 | #include <qpainter.h> | ||
8 | #include <qrect.h> | ||
9 | #include <qpoint.h> | ||
10 | #include <qsize.h> | ||
11 | |||
12 | namespace Opie { | ||
13 | namespace MM { | ||
14 | |||
15 | /** | ||
16 | * \brief The most simple c'tor | ||
17 | * The main c'tor. You still need to set a QPixmap/QIMage, | ||
18 | * setImageSize,setViewPortSize,setVisiblePoint | ||
19 | * | ||
20 | * @param parent The parent widget | ||
21 | * @param name A name for this widget | ||
22 | * @param fl The widget flags | ||
23 | * | ||
24 | */ | ||
25 | OImageZoomer::OImageZoomer( QWidget* parent, const char* name, WFlags fl ) | ||
26 | : QFrame( parent, name, fl ) { | ||
27 | init(); | ||
28 | } | ||
29 | |||
30 | |||
31 | /** | ||
32 | * \brief This c'tor takes a QPixmap additional | ||
33 | * | ||
34 | * You initially set the QPixmap but you still need to provide | ||
35 | * the additional data to make this widget useful | ||
36 | * | ||
37 | * @param pix A Pixmap it'll be converted to a QImage later! | ||
38 | * @param par The parent widget | ||
39 | * @param name The name of this widget | ||
40 | * @param fl The widget flags | ||
41 | */ | ||
42 | OImageZoomer::OImageZoomer( const QPixmap& pix, QWidget* par, const char* name, WFlags fl ) | ||
43 | : QFrame( par, name, fl ) { | ||
44 | init(); | ||
45 | setImage( pix ); | ||
46 | } | ||
47 | |||
48 | |||
49 | /** | ||
50 | * \brief This c'tor takes a QImage instead | ||
51 | * You just provide a QImage which is saved. It behaves the same as the others. | ||
52 | * | ||
53 | * @param img A Image which will be used for the zoomer content | ||
54 | * @param par The parent of the widget | ||
55 | * @param name The name of the widget | ||
56 | * @param fl The widgets flags | ||
57 | */ | ||
58 | OImageZoomer::OImageZoomer( const QImage& img, QWidget* par, const char* name, WFlags fl) | ||
59 | : QFrame( par, name, fl ) { | ||
60 | init(); | ||
61 | setImage( img ); | ||
62 | } | ||
63 | |||
64 | |||
65 | /** | ||
66 | * \brief overloaded c'tor | ||
67 | * | ||
68 | * This differs only in the arguments it takes | ||
69 | * | ||
70 | * | ||
71 | * @param pSize The size of the Page you show | ||
72 | * @param vSize The size of the viewport. The size of the visible part of the widget | ||
73 | * @param par The parent of the widget | ||
74 | * @param name The name | ||
75 | * @param fl The window flags | ||
76 | */ | ||
77 | OImageZoomer::OImageZoomer( const QSize& pSize, const QSize& vSize, QWidget* par, | ||
78 | const char* name, WFlags fl ) | ||
79 | : QFrame( par, name, fl ), m_imgSize( pSize ),m_visSize( vSize ) { | ||
80 | init(); | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * d'tor | ||
85 | */ | ||
86 | OImageZoomer::~OImageZoomer() { | ||
87 | |||
88 | } | ||
89 | |||
90 | void OImageZoomer::init() { | ||
91 | m_mevent = false; | ||
92 | setFrameStyle( Panel | Sunken ); | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
97 | * \brief set the page/image size | ||
98 | * Tell us the QSize of the Data you show to the user. We need this | ||
99 | * to do the calculations | ||
100 | * | ||
101 | * @param size The size of the stuff you want to zoom on | ||
102 | */ | ||
103 | void OImageZoomer::setImageSize( const QSize& size ) { | ||
104 | m_imgSize = size; | ||
105 | repaint(); | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * \brief Set the size of the viewport | ||
110 | * Tell us the QSize of the viewport. The viewport is the part | ||
111 | * of the widget which is exposed on the screen | ||
112 | * | ||
113 | * @param size Te size of the viewport | ||
114 | * | ||
115 | * @see QScrollView::viewport() | ||
116 | */ | ||
117 | void OImageZoomer::setViewPortSize( const QSize& size ) { | ||
118 | m_visSize = size; | ||
119 | repaint(); | ||
120 | } | ||
121 | |||
122 | /** | ||
123 | * \brief the point in the topleft corner which is currently visible | ||
124 | * Set the visible point. This most of the times relate to QScrollView::contentsX() | ||
125 | * and QScrollView::contentsY() | ||
126 | * | ||
127 | * @see setVisiblePoint(int,int) | ||
128 | */ | ||
129 | void OImageZoomer::setVisiblePoint( const QPoint& pt ) { | ||
130 | m_visPt = pt; | ||
131 | repaint(); | ||
132 | } | ||
133 | |||
134 | |||
135 | /** | ||
136 | * Set the Image. The image will be resized on resizeEvent | ||
137 | * and it'll set the QPixmap background | ||
138 | * | ||
139 | * @param img The image will be stored internally and used as the background | ||
140 | */ | ||
141 | void OImageZoomer::setImage( const QImage& img) { | ||
142 | m_img = img; | ||
143 | resizeEvent( 0 ); | ||
144 | repaint(); | ||
145 | } | ||
146 | |||
147 | /** | ||
148 | * overloaded function it calls the QImage version | ||
149 | */ | ||
150 | void OImageZoomer::setImage( const QPixmap& pix) { | ||
151 | setImage( pix.convertToImage() ); | ||
152 | } | ||
153 | |||
154 | void OImageZoomer::resizeEvent( QResizeEvent* ev ) { | ||
155 | QFrame::resizeEvent( ev ); | ||
156 | setBackgroundOrigin( QWidget::WidgetOrigin ); | ||
157 | // TODO Qt3 use PalettePixmap and use size | ||
158 | QPixmap pix; pix.convertFromImage( m_img.smoothScale( size().width(), size().height() ) ); | ||
159 | setBackgroundPixmap( pix); | ||
160 | } | ||
161 | |||
162 | void OImageZoomer::drawContents( QPainter* p ) { | ||
163 | /* | ||
164 | * if the page size | ||
165 | */ | ||
166 | if ( m_imgSize.isEmpty() ) | ||
167 | return; | ||
168 | |||
169 | /* | ||
170 | * paint a red rect which represents the visible size | ||
171 | * | ||
172 | * We need to recalculate x,y and width and height of the | ||
173 | * rect. So image size relates to contentRect | ||
174 | * | ||
175 | */ | ||
176 | QRect c( contentsRect() ); | ||
177 | p->setPen( Qt::red ); | ||
178 | |||
179 | /* | ||
180 | * the contentRect is set equal to the size of the image | ||
181 | * Rect/Original = NewRectORWidth/OriginalVisibleStuff and then simply we | ||
182 | * need to add the c.y/x due usage of QFrame | ||
183 | * For x and y we use the visiblePoint | ||
184 | * For height and width we use the size of the viewport | ||
185 | * if width/height would be bigger than our widget we use this width/height | ||
186 | * | ||
187 | */ | ||
188 | int len = m_imgSize.width(); | ||
189 | int x = (c.width()*m_visPt.x())/len + c.x(); | ||
190 | int w = (c.width()*m_visSize.width() )/len + c.x(); | ||
191 | if ( w > c.width() ) w = c.width(); | ||
192 | |||
193 | len = m_imgSize.height(); | ||
194 | int y = (c.height()*m_visPt.y() )/len + c.y(); | ||
195 | int h = (c.height()*m_visSize.height() )/len + c.y(); | ||
196 | if ( h > c.height() ) h = c.height(); | ||
197 | |||
198 | p->drawRect( x, y, w, h ); | ||
199 | } | ||
200 | |||
201 | void OImageZoomer::mousePressEvent( QMouseEvent*ev) { | ||
202 | m_mouseX = m_mouseY = -1; | ||
203 | m_mevent = true; | ||
204 | } | ||
205 | |||
206 | void OImageZoomer::mouseReleaseEvent( QMouseEvent*ev) { | ||
207 | if (!m_mevent) return; | ||
208 | int mx, my; | ||
209 | mx = ev->x(); | ||
210 | my = ev->y(); | ||
211 | int diffx = (mx) * m_imgSize.width() / width(); | ||
212 | int diffy = (my) * m_imgSize.height() / height(); | ||
213 | emit zoomArea(diffx,diffy); | ||
214 | } | ||
215 | |||
216 | void OImageZoomer::mouseMoveEvent( QMouseEvent* ev ) { | ||
217 | int mx, my; | ||
218 | mx = ev->x(); | ||
219 | my = ev->y(); | ||
220 | |||
221 | if ( m_mouseX != -1 && m_mouseY != -1 ) { | ||
222 | m_mevent = false; | ||
223 | int diffx = ( mx - m_mouseX ) * m_imgSize.width() / width(); | ||
224 | int diffy = ( my - m_mouseY ) * m_imgSize.height() / height(); | ||
225 | emit zoomAreaRel( diffx, diffy ); | ||
226 | } | ||
227 | m_mouseX = mx; | ||
228 | m_mouseY = my; | ||
229 | } | ||
230 | |||
231 | |||
232 | } | ||
233 | } | ||
diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.h b/noncore/graphics/opie-eye/lib/oimagezoomer.h deleted file mode 100644 index 0b356c9..0000000 --- a/noncore/graphics/opie-eye/lib/oimagezoomer.h +++ b/dev/null | |||
@@ -1,141 +0,0 @@ | |||
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 Page | ||
17 | * | ||
18 | * This class represents your page but smaller. | ||
19 | * It can draw a Rect on top of an Image/Pixmap you supply | ||
20 | * and you can allow the user easily zooming/moving | ||
21 | * over your widget. | ||
22 | * All you need to do is to supply a image/pixmap, the visible size | ||
23 | * and the original image/pixmap size and the current visible top/left | ||
24 | * position. | ||
25 | * | ||
26 | * This Image works perfectly with QScrollView as you can connect | ||
27 | * QScrollView::contentsMoving to setVisiblePoint slot and the zoomAreRel | ||
28 | * to the QScrollView::scrollBy slot. Now you would only need to watch | ||
29 | * the resize event anf give us the new information about QScrollView::viewport | ||
30 | * | ||
31 | * You need to position and set the size of this widget! using setFixedSize() is quite | ||
32 | * a good idea for this widget | ||
33 | * | ||
34 | * @see QScrollView | ||
35 | * @see QScrollView::viewport() | ||
36 | * | ||
37 | * @since 1.2 | ||
38 | * | ||
39 | */ | ||
40 | class OImageZoomer : public QFrame { | ||
41 | Q_OBJECT | ||
42 | public: | ||
43 | OImageZoomer( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | ||
44 | OImageZoomer( const QPixmap&,QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | ||
45 | OImageZoomer( const QImage&, QWidget* parent = 0, const char* name= 0, WFlags fl = 0 ); | ||
46 | OImageZoomer( const QSize&, const QSize&, QWidget* par, const char*, WFlags fl ); | ||
47 | ~OImageZoomer(); | ||
48 | |||
49 | public slots: | ||
50 | void setImageSize( const QSize& ); | ||
51 | void setViewPortSize( const QSize& ); | ||
52 | void setVisiblePoint( const QPoint& ); | ||
53 | void setVisiblePoint( int x, int y ); | ||
54 | void setImage( const QImage& ); | ||
55 | void setImage( const QPixmap& ); | ||
56 | |||
57 | signals: | ||
58 | /** | ||
59 | * Relative movement in the coordinates of the viewport | ||
60 | * This signal can easily be connected to QScrollView::scrollBy. | ||
61 | * This signal is emitted from within the mouseMoveEvent of this widget | ||
62 | * | ||
63 | * | ||
64 | * @param x The way to move relative on the X-Axis | ||
65 | * @param y The way to move relative on the Y-Axis | ||
66 | * | ||
67 | * @see setVisiblePoint | ||
68 | * @see QScrollView::scrollBy | ||
69 | */ | ||
70 | void zoomAreaRel( int x,int y); | ||
71 | |||
72 | /** | ||
73 | * Here you get absolute coordinates. | ||
74 | * This slot will be emitted from within the mouseReleaseEvent of this widget. | ||
75 | * if no mouse move where done. | ||
76 | * So you may not delete this widget | ||
77 | * | ||
78 | * @param x The absolute X Coordinate to scroll to. | ||
79 | * @param y The absolute Y Coordinate to scroll to. | ||
80 | * | ||
81 | */ | ||
82 | void zoomArea( int x,int y); | ||
83 | |||
84 | public: | ||
85 | /** | ||
86 | * make sure to call these if you reimplement | ||
87 | * @internal | ||
88 | */ | ||
89 | void resizeEvent( QResizeEvent* ); | ||
90 | |||
91 | protected: | ||
92 | /** | ||
93 | * make sure to call these if you reimplement | ||
94 | * @internal | ||
95 | */ | ||
96 | void drawContents( QPainter* p ); | ||
97 | |||
98 | /** | ||
99 | * make sure to call these if you reimplememt | ||
100 | * @internal | ||
101 | */ | ||
102 | virtual void mousePressEvent( QMouseEvent* ev ); | ||
103 | /** | ||
104 | * make sure to call these if you reimplement | ||
105 | * @internal | ||
106 | */ | ||
107 | virtual void mouseMoveEvent( QMouseEvent* ev ); | ||
108 | /** | ||
109 | * make sure to call these if you reimplement | ||
110 | * @internal | ||
111 | */ | ||
112 | virtual void mouseReleaseEvent( QMouseEvent* ev ); | ||
113 | |||
114 | private: | ||
115 | /** | ||
116 | * @internal | ||
117 | */ | ||
118 | void init(); | ||
119 | QImage m_img; | ||
120 | QSize m_imgSize, m_visSize; | ||
121 | QPoint m_visPt; | ||
122 | int m_mouseX, m_mouseY; | ||
123 | bool m_mevent; | ||
124 | }; | ||
125 | |||
126 | /** | ||
127 | * This slot is present for convience. You can connect the | ||
128 | * QScrollView::contentsMoved to this slot and it calls the QPoint | ||
129 | * version for you | ||
130 | * This realtes to QScrollView::contentsX() and QScrollView::contentsY() | ||
131 | * | ||
132 | * @param x The top left x coordinate | ||
133 | * @param y The top left y coorisnate | ||
134 | */ | ||
135 | inline void OImageZoomer::setVisiblePoint( int x, int y ) { | ||
136 | setVisiblePoint( QPoint( x, y ) ); | ||
137 | } | ||
138 | |||
139 | } | ||
140 | } | ||
141 | #endif | ||