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