Diffstat (limited to 'libopie2/opiemm/oimagezoomer.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiemm/oimagezoomer.h | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/libopie2/opiemm/oimagezoomer.h b/libopie2/opiemm/oimagezoomer.h new file mode 100644 index 0000000..0b356c9 --- a/dev/null +++ b/libopie2/opiemm/oimagezoomer.h | |||
@@ -0,0 +1,141 @@ | |||
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 | ||