Diffstat (limited to 'noncore/graphics/opie-eye/gui/imagescrollview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp index 7d83e29..ee20f40 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp | |||
@@ -23,40 +23,70 @@ ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char | |||
23 | 23 | ||
24 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 24 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
25 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), | 25 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), |
26 | rotate_to_fit(rfit),first_resize_done(false) | 26 | rotate_to_fit(rfit),first_resize_done(false) |
27 | { | 27 | { |
28 | init(); | 28 | init(); |
29 | } | 29 | } |
30 | 30 | ||
31 | void ImageScrollView::setImage(const QImage&img) | 31 | void ImageScrollView::setImage(const QImage&img) |
32 | { | 32 | { |
33 | _image_data = QImage(); | 33 | _image_data = QImage(); |
34 | _original_data=img; | 34 | _original_data=img; |
35 | first_resize_done = false; | 35 | if (first_resize_done) { |
36 | init(); | 36 | generateImage(); |
37 | } | ||
37 | } | 38 | } |
38 | 39 | ||
39 | void ImageScrollView::setImage( const QString& path ) { | 40 | void ImageScrollView::setImage( const QString& path ) { |
40 | 41 | odebug << "load new image " << oendl; | |
42 | _original_data.load(path); | ||
43 | _image_data = QImage(); | ||
44 | if (first_resize_done) { | ||
45 | generateImage(); | ||
46 | } | ||
41 | } | 47 | } |
42 | 48 | ||
43 | /* should be called every time the QImage changed it content */ | 49 | /* should be called every time the QImage changed it content */ |
44 | void ImageScrollView::init() | 50 | void ImageScrollView::init() |
45 | { | 51 | { |
52 | odebug << "init " << oendl; | ||
46 | viewport()->setBackgroundColor(white); | 53 | viewport()->setBackgroundColor(white); |
47 | if (_original_data.size().isValid()) { | 54 | if (first_resize_done) { |
55 | last_rot = Rotate0; | ||
56 | generateImage(); | ||
57 | odebug << "reinit display " << oendl; | ||
58 | } else if (_original_data.size().isValid()) { | ||
48 | resizeContents(_original_data.width(),_original_data.height()); | 59 | resizeContents(_original_data.width(),_original_data.height()); |
49 | } | 60 | } |
50 | last_rot = Rotate0; | 61 | } |
62 | |||
63 | void ImageScrollView::setAutoRotate(bool how) | ||
64 | { | ||
65 | /* to avoid double repaints */ | ||
66 | if (rotate_to_fit != how) { | ||
67 | rotate_to_fit = how; | ||
68 | _image_data = QImage(); | ||
69 | generateImage(); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | void ImageScrollView::setAutoScale(bool how) | ||
74 | { | ||
75 | scale_to_fit = how; | ||
76 | if (!how) { | ||
77 | rotate_to_fit = false; | ||
78 | } | ||
79 | _image_data = QImage(); | ||
80 | generateImage(); | ||
51 | } | 81 | } |
52 | 82 | ||
53 | ImageScrollView::~ImageScrollView() | 83 | ImageScrollView::~ImageScrollView() |
54 | { | 84 | { |
55 | } | 85 | } |
56 | 86 | ||
57 | void ImageScrollView::rescaleImage(int w, int h) | 87 | void ImageScrollView::rescaleImage(int w, int h) |
58 | { | 88 | { |
59 | if (_image_data.width()==w && _image_data.height()==h) { | 89 | if (_image_data.width()==w && _image_data.height()==h) { |
60 | return; | 90 | return; |
61 | } | 91 | } |
62 | double hs = (double)h / (double)_image_data.height() ; | 92 | double hs = (double)h / (double)_image_data.height() ; |
@@ -172,53 +202,59 @@ void ImageScrollView::rotate_into_data(Rotation r) | |||
172 | } | 202 | } |
173 | } | 203 | } |
174 | break; | 204 | break; |
175 | default: | 205 | default: |
176 | dest = _original_data; | 206 | dest = _original_data; |
177 | break; | 207 | break; |
178 | } | 208 | } |
179 | 209 | ||
180 | } | 210 | } |
181 | _image_data = dest; | 211 | _image_data = dest; |
182 | } | 212 | } |
183 | 213 | ||
184 | void ImageScrollView::resizeEvent(QResizeEvent * e) | 214 | void ImageScrollView::generateImage() |
185 | { | 215 | { |
186 | odebug << "ImageScrollView resizeEvent" << oendl; | ||
187 | QScrollView::resizeEvent(e); | ||
188 | Rotation r = Rotate0; | 216 | Rotation r = Rotate0; |
189 | if (width()>height()&&_original_data.width()<_original_data.height() || | 217 | if (width()>height()&&_original_data.width()<_original_data.height() || |
190 | width()<height()&&_original_data.width()>_original_data.height()) { | 218 | width()<height()&&_original_data.width()>_original_data.height()) { |
191 | if (rotate_to_fit) r = Rotate90; | 219 | if (rotate_to_fit) r = Rotate90; |
192 | } | 220 | } |
193 | odebug << " r = " << r << oendl; | 221 | odebug << " r = " << r << oendl; |
194 | if (scale_to_fit) { | 222 | if (scale_to_fit) { |
195 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { | 223 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { |
224 | odebug << "Rescaling data" << oendl; | ||
196 | if (r==Rotate0) { | 225 | if (r==Rotate0) { |
197 | _image_data = _original_data; | 226 | _image_data = _original_data; |
198 | } else { | 227 | } else { |
199 | rotate_into_data(r); | 228 | rotate_into_data(r); |
200 | } | 229 | } |
201 | } | 230 | } |
202 | rescaleImage(width(),height()); | 231 | rescaleImage(width(),height()); |
203 | resizeContents(width()-10,height()-10); | 232 | resizeContents(_image_data.width(),_image_data.height()); |
204 | } else if (!first_resize_done||r!=last_rot) { | 233 | } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { |
205 | if (r==Rotate0) { | 234 | if (r==Rotate0) { |
206 | _image_data = _original_data; | 235 | _image_data = _original_data; |
207 | } else { | 236 | } else { |
208 | rotate_into_data(r); | 237 | rotate_into_data(r); |
209 | } | 238 | } |
210 | last_rot = r; | 239 | last_rot = r; |
211 | resizeContents(_image_data.width(),_image_data.height()); | 240 | resizeContents(_image_data.width(),_image_data.height()); |
212 | } | 241 | } |
242 | } | ||
243 | |||
244 | void ImageScrollView::resizeEvent(QResizeEvent * e) | ||
245 | { | ||
246 | odebug << "ImageScrollView resizeEvent" << oendl; | ||
247 | QScrollView::resizeEvent(e); | ||
248 | generateImage(); | ||
213 | first_resize_done = true; | 249 | first_resize_done = true; |
214 | } | 250 | } |
215 | 251 | ||
216 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | 252 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) |
217 | { | 253 | { |
218 | int w = clipw; | 254 | int w = clipw; |
219 | int h = cliph; | 255 | int h = cliph; |
220 | int x = clipx; | 256 | int x = clipx; |
221 | int y = clipy; | 257 | int y = clipy; |
222 | bool erase = false; | 258 | bool erase = false; |
223 | 259 | ||
224 | if (!_image_data.size().isValid()) { | 260 | if (!_image_data.size().isValid()) { |