-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 86 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 3 |
2 files changed, 83 insertions, 6 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp index 2f16d82..d034ee0 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp | |||
@@ -1,121 +1,187 @@ | |||
1 | #include "imagescrollview.h" | 1 | #include "imagescrollview.h" |
2 | 2 | ||
3 | #include <opie2/odebug.h> | 3 | #include <opie2/odebug.h> |
4 | #include <opie2/oapplication.h> | ||
5 | #include <opie2/owait.h> | ||
4 | 6 | ||
5 | using namespace Opie::Core; | 7 | using namespace Opie::Core; |
6 | 8 | ||
7 | #include <qimage.h> | 9 | #include <qimage.h> |
8 | #include <qlayout.h> | 10 | #include <qlayout.h> |
11 | #include <qpe/qcopenvelope_qws.h> | ||
9 | 12 | ||
10 | ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) | 13 | ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) |
11 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), | 14 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), |
12 | rotate_to_fit(true),show_zoomer(true),first_resize_done(false),m_lastName("") | 15 | rotate_to_fit(true),show_zoomer(true),first_resize_done(false),m_lastName("") |
13 | { | 16 | { |
14 | init(); | 17 | init(); |
15 | } | 18 | } |
16 | 19 | ||
17 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 20 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
18 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), | 21 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), |
19 | rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("") | 22 | rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("") |
20 | { | 23 | { |
21 | _original_data.convertDepth(QPixmap::defaultDepth()); | 24 | _original_data.convertDepth(QPixmap::defaultDepth()); |
22 | _original_data.setAlphaBuffer(false); | 25 | _original_data.setAlphaBuffer(false); |
23 | init(); | 26 | init(); |
24 | } | 27 | } |
25 | 28 | ||
26 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 29 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
27 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale), | 30 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale), |
28 | rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("") | 31 | rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("") |
29 | { | 32 | { |
30 | init(); | 33 | init(); |
31 | setImage(img); | 34 | setImage(img); |
32 | } | 35 | } |
33 | 36 | ||
34 | void ImageScrollView::setImage(const QImage&img) | 37 | void ImageScrollView::setImage(const QImage&img) |
35 | { | 38 | { |
36 | _image_data = QImage(); | 39 | _image_data = QImage(); |
37 | _original_data=img; | 40 | _original_data=img; |
38 | _original_data.convertDepth(QPixmap::defaultDepth()); | 41 | _original_data.convertDepth(QPixmap::defaultDepth()); |
39 | _original_data.setAlphaBuffer(false); | 42 | _original_data.setAlphaBuffer(false); |
40 | m_lastName = ""; | 43 | m_lastName = ""; |
44 | image_is_jpeg = false; | ||
45 | image_scaled_loaded = false; | ||
41 | if (first_resize_done) { | 46 | if (first_resize_done) { |
42 | generateImage(); | 47 | generateImage(); |
43 | } | 48 | } |
44 | } | 49 | } |
45 | 50 | ||
51 | void ImageScrollView::loadJpeg(bool interncall) | ||
52 | { | ||
53 | if (m_lastName.isEmpty()) return; | ||
54 | QImageIO iio( m_lastName, 0l ); | ||
55 | QString param; | ||
56 | bool real_load = false; | ||
57 | if (scale_to_fit) { | ||
58 | if (!interncall) { | ||
59 | int wid, hei; | ||
60 | wid = QApplication::desktop()->width(); | ||
61 | hei = QApplication::desktop()->height(); | ||
62 | if (hei>wid) { | ||
63 | wid = hei; | ||
64 | } else { | ||
65 | hei = wid; | ||
66 | } | ||
67 | param = QString( "Fast Shrink( 7 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei ); | ||
68 | odebug << "Load jpeg scaled \"" << param << "\"" << oendl; | ||
69 | iio.setParameters(param.latin1()); | ||
70 | image_scaled_loaded = true; | ||
71 | real_load = true; | ||
72 | } | ||
73 | } else { | ||
74 | if (image_scaled_loaded||!interncall) { | ||
75 | odebug << "Load jpeg unscaled" << oendl; | ||
76 | real_load = true; | ||
77 | } | ||
78 | image_scaled_loaded = false; | ||
79 | } | ||
80 | if (real_load) { | ||
81 | { | ||
82 | QCopEnvelope( "QPE/System", "busy()" ); | ||
83 | } | ||
84 | _original_data = iio.read() ? iio.image() : QImage(); | ||
85 | { | ||
86 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | ||
87 | env << "Image loaded"; | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | |||
46 | void ImageScrollView::setImage( const QString& path ) { | 92 | void ImageScrollView::setImage( const QString& path ) { |
47 | odebug << "load new image " << oendl; | 93 | odebug << "load new image " << oendl; |
48 | if (m_lastName == path) return; | 94 | if (m_lastName == path) return; |
49 | m_lastName = path; | 95 | m_lastName = path; |
50 | _original_data.load(path); | 96 | QString itype = QImage::imageFormat(m_lastName); |
51 | _original_data.convertDepth(QPixmap::defaultDepth()); | 97 | odebug << "Image type = " << itype << oendl; |
52 | _original_data.setAlphaBuffer(false); | 98 | if (itype == "JPEG") { |
99 | image_is_jpeg = true; | ||
100 | loadJpeg(); | ||
101 | } else { | ||
102 | { | ||
103 | QCopEnvelope( "QPE/System", "busy()" ); | ||
104 | } | ||
105 | image_is_jpeg = false; | ||
106 | _original_data.load(path); | ||
107 | _original_data.convertDepth(QPixmap::defaultDepth()); | ||
108 | _original_data.setAlphaBuffer(false); | ||
109 | { | ||
110 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | ||
111 | env << "Image loaded"; | ||
112 | } | ||
113 | } | ||
53 | _image_data = QImage(); | 114 | _image_data = QImage(); |
54 | if (first_resize_done) { | 115 | if (first_resize_done) { |
55 | generateImage(); | 116 | generateImage(); |
56 | } | 117 | } |
57 | } | 118 | } |
58 | 119 | ||
59 | /* should be called every time the QImage changed it content */ | 120 | /* should be called every time the QImage changed it content */ |
60 | void ImageScrollView::init() | 121 | void ImageScrollView::init() |
61 | { | 122 | { |
62 | odebug << "init " << oendl; | 123 | odebug << "init " << oendl; |
63 | 124 | ||
64 | /* | 125 | /* |
65 | * create the zoomer | 126 | * create the zoomer |
66 | * and connect ther various signals | 127 | * and connect ther various signals |
67 | */ | 128 | */ |
68 | _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); | 129 | _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); |
69 | connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), | 130 | connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), |
70 | this, SLOT(scrollBy(int,int)) ); | 131 | this, SLOT(scrollBy(int,int)) ); |
71 | connect(this,SIGNAL(contentsMoving(int,int)), | 132 | connect(this,SIGNAL(contentsMoving(int,int)), |
72 | _zoomer, (SLOT(setVisiblePoint(int,int))) ); | 133 | _zoomer, (SLOT(setVisiblePoint(int,int))) ); |
73 | connect(this,SIGNAL(imageSizeChanged(const QSize&)), | 134 | connect(this,SIGNAL(imageSizeChanged(const QSize&)), |
74 | _zoomer, SLOT(setImageSize(const QSize&)) ); | 135 | _zoomer, SLOT(setImageSize(const QSize&)) ); |
75 | connect(this,SIGNAL(viewportSizeChanged(const QSize&)), | 136 | connect(this,SIGNAL(viewportSizeChanged(const QSize&)), |
76 | _zoomer, SLOT(setViewPortSize(const QSize&)) ); | 137 | _zoomer, SLOT(setViewPortSize(const QSize&)) ); |
77 | 138 | ||
78 | viewport()->setBackgroundColor(white); | 139 | viewport()->setBackgroundColor(white); |
79 | setFocusPolicy(QWidget::StrongFocus); | 140 | setFocusPolicy(QWidget::StrongFocus); |
141 | image_scaled_loaded = false; | ||
142 | image_is_jpeg = false; | ||
80 | if (first_resize_done) { | 143 | if (first_resize_done) { |
81 | last_rot = Rotate0; | 144 | last_rot = Rotate0; |
82 | generateImage(); | 145 | generateImage(); |
83 | } else if (_original_data.size().isValid()) { | 146 | } else if (_original_data.size().isValid()) { |
84 | if (image_fit_into(_original_data.size()) || !show_zoomer) _zoomer->hide(); | 147 | if (image_fit_into(_original_data.size()) || !show_zoomer) _zoomer->hide(); |
85 | resizeContents(_original_data.width(),_original_data.height()); | 148 | resizeContents(_original_data.width(),_original_data.height()); |
86 | } | 149 | } |
87 | } | 150 | } |
88 | 151 | ||
89 | void ImageScrollView::setAutoRotate(bool how) | 152 | void ImageScrollView::setAutoRotate(bool how) |
90 | { | 153 | { |
91 | /* to avoid double repaints */ | 154 | /* to avoid double repaints */ |
92 | if (rotate_to_fit != how) { | 155 | if (rotate_to_fit != how) { |
93 | rotate_to_fit = how; | 156 | rotate_to_fit = how; |
94 | _image_data = QImage(); | 157 | _image_data = QImage(); |
95 | generateImage(); | 158 | generateImage(); |
96 | } | 159 | } |
97 | } | 160 | } |
98 | 161 | ||
99 | void ImageScrollView::setAutoScale(bool how) | 162 | void ImageScrollView::setAutoScale(bool how) |
100 | { | 163 | { |
101 | scale_to_fit = how; | 164 | scale_to_fit = how; |
102 | if (!how) { | 165 | if (!how) { |
103 | rotate_to_fit = false; | 166 | rotate_to_fit = false; |
104 | } | 167 | } |
105 | _image_data = QImage(); | 168 | _image_data = QImage(); |
169 | if (image_is_jpeg && how == false && image_scaled_loaded==true) { | ||
170 | loadJpeg(true); | ||
171 | } | ||
106 | generateImage(); | 172 | generateImage(); |
107 | } | 173 | } |
108 | 174 | ||
109 | ImageScrollView::~ImageScrollView() | 175 | ImageScrollView::~ImageScrollView() |
110 | { | 176 | { |
111 | } | 177 | } |
112 | 178 | ||
113 | void ImageScrollView::rescaleImage(int w, int h) | 179 | void ImageScrollView::rescaleImage(int w, int h) |
114 | { | 180 | { |
115 | if (_image_data.width()==w && _image_data.height()==h) { | 181 | if (_image_data.width()==w && _image_data.height()==h) { |
116 | return; | 182 | return; |
117 | } | 183 | } |
118 | double hs = (double)h / (double)_image_data.height() ; | 184 | double hs = (double)h / (double)_image_data.height() ; |
119 | double ws = (double)w / (double)_image_data.width() ; | 185 | double ws = (double)w / (double)_image_data.width() ; |
120 | double scaleFactor = (hs > ws) ? ws : hs; | 186 | double scaleFactor = (hs > ws) ? ws : hs; |
121 | int smoothW = (int)(scaleFactor * _image_data.width()); | 187 | int smoothW = (int)(scaleFactor * _image_data.width()); |
@@ -227,77 +293,85 @@ void ImageScrollView::rotate_into_data(Rotation r) | |||
227 | destData[y] = srcData[x]; | 293 | destData[y] = srcData[x]; |
228 | } | 294 | } |
229 | } | 295 | } |
230 | break; | 296 | break; |
231 | default: | 297 | default: |
232 | dest = _original_data; | 298 | dest = _original_data; |
233 | break; | 299 | break; |
234 | } | 300 | } |
235 | 301 | ||
236 | } | 302 | } |
237 | _image_data = dest; | 303 | _image_data = dest; |
238 | } | 304 | } |
239 | 305 | ||
240 | void ImageScrollView::generateImage() | 306 | void ImageScrollView::generateImage() |
241 | { | 307 | { |
242 | Rotation r = Rotate0; | 308 | Rotation r = Rotate0; |
309 | { | ||
310 | QCopEnvelope( "QPE/System", "busy()" ); | ||
311 | } | ||
243 | if (width()>height()&&_original_data.width()<_original_data.height() || | 312 | if (width()>height()&&_original_data.width()<_original_data.height() || |
244 | width()<height()&&_original_data.width()>_original_data.height()) { | 313 | width()<height()&&_original_data.width()>_original_data.height()) { |
245 | if (rotate_to_fit) r = Rotate90; | 314 | if (rotate_to_fit) r = Rotate90; |
246 | } | 315 | } |
316 | |||
247 | odebug << " r = " << r << oendl; | 317 | odebug << " r = " << r << oendl; |
248 | if (scale_to_fit) { | 318 | if (scale_to_fit) { |
249 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { | 319 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { |
250 | odebug << "Rescaling data" << oendl; | 320 | odebug << "Rescaling data" << oendl; |
251 | if (r==Rotate0) { | 321 | if (r==Rotate0) { |
252 | _image_data = _original_data; | 322 | _image_data = _original_data; |
253 | } else { | 323 | } else { |
254 | rotate_into_data(r); | 324 | rotate_into_data(r); |
255 | } | 325 | } |
256 | } | 326 | } |
257 | rescaleImage(width(),height()); | 327 | rescaleImage(width(),height()); |
258 | resizeContents(_image_data.width(),_image_data.height()); | 328 | resizeContents(_image_data.width(),_image_data.height()); |
259 | } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { | 329 | } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { |
260 | if (r==Rotate0) { | 330 | if (r==Rotate0) { |
261 | _image_data = _original_data; | 331 | _image_data = _original_data; |
262 | } else { | 332 | } else { |
263 | rotate_into_data(r); | 333 | rotate_into_data(r); |
264 | } | 334 | } |
265 | last_rot = r; | 335 | last_rot = r; |
266 | resizeContents(_image_data.width(),_image_data.height()); | 336 | resizeContents(_image_data.width(),_image_data.height()); |
267 | } | 337 | } |
268 | _pdata.convertFromImage(_image_data); | 338 | _pdata.convertFromImage(_image_data); |
269 | 339 | ||
270 | 340 | ||
271 | /* | 341 | /* |
272 | * update the zoomer | 342 | * update the zoomer |
273 | */ | 343 | */ |
274 | check_zoomer(); | 344 | check_zoomer(); |
275 | emit imageSizeChanged( _image_data.size() ); | 345 | emit imageSizeChanged( _image_data.size() ); |
276 | rescaleImage( 128, 128 ); | 346 | rescaleImage( 128, 128 ); |
277 | /* | 347 | /* |
278 | * move scrollbar | 348 | * move scrollbar |
279 | */ | 349 | */ |
280 | _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, | 350 | _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, |
281 | _image_data.width()/2, _image_data.height()/2 ); | 351 | _image_data.width()/2, _image_data.height()/2 ); |
282 | 352 | ||
283 | _zoomer->setImage( _image_data ); | 353 | _zoomer->setImage( _image_data ); |
284 | /* | 354 | /* |
285 | * invalidate | 355 | * invalidate |
286 | */ | 356 | */ |
287 | _image_data=QImage(); | 357 | _image_data=QImage(); |
358 | { | ||
359 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | ||
360 | env << "Image generated"; | ||
361 | } | ||
288 | } | 362 | } |
289 | 363 | ||
290 | void ImageScrollView::resizeEvent(QResizeEvent * e) | 364 | void ImageScrollView::resizeEvent(QResizeEvent * e) |
291 | { | 365 | { |
292 | odebug << "ImageScrollView resizeEvent" << oendl; | 366 | odebug << "ImageScrollView resizeEvent" << oendl; |
293 | QScrollView::resizeEvent(e); | 367 | QScrollView::resizeEvent(e); |
294 | generateImage(); | 368 | generateImage(); |
295 | first_resize_done = true; | 369 | first_resize_done = true; |
296 | emit viewportSizeChanged( viewport()->size() ); | 370 | emit viewportSizeChanged( viewport()->size() ); |
297 | 371 | ||
298 | } | 372 | } |
299 | 373 | ||
300 | void ImageScrollView::keyPressEvent(QKeyEvent * e) | 374 | void ImageScrollView::keyPressEvent(QKeyEvent * e) |
301 | { | 375 | { |
302 | if (!e) return; | 376 | if (!e) return; |
303 | int dx = horizontalScrollBar()->lineStep(); | 377 | int dx = horizontalScrollBar()->lineStep(); |
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h index e209dfb..f6e187d 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.h +++ b/noncore/graphics/opie-eye/gui/imagescrollview.h | |||
@@ -44,32 +44,35 @@ signals: | |||
44 | 44 | ||
45 | protected: | 45 | protected: |
46 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); | 46 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); |
47 | void init(); | 47 | void init(); |
48 | 48 | ||
49 | Opie::MM::OImageZoomer *_zoomer; | 49 | Opie::MM::OImageZoomer *_zoomer; |
50 | QImage _image_data; | 50 | QImage _image_data; |
51 | QImage _original_data; | 51 | QImage _original_data; |
52 | QPixmap _pdata; | 52 | QPixmap _pdata; |
53 | 53 | ||
54 | int _mouseStartPosX,_mouseStartPosY; | 54 | int _mouseStartPosX,_mouseStartPosY; |
55 | 55 | ||
56 | bool scale_to_fit; | 56 | bool scale_to_fit; |
57 | bool rotate_to_fit; | 57 | bool rotate_to_fit; |
58 | bool show_zoomer; | 58 | bool show_zoomer; |
59 | bool first_resize_done; | 59 | bool first_resize_done; |
60 | bool image_is_jpeg; | ||
61 | bool image_scaled_loaded; | ||
60 | Rotation last_rot; | 62 | Rotation last_rot; |
61 | QString m_lastName; | 63 | QString m_lastName; |
62 | virtual void rescaleImage(int w, int h); | 64 | virtual void rescaleImage(int w, int h); |
63 | 65 | ||
64 | virtual void rotate_into_data(Rotation r); | 66 | virtual void rotate_into_data(Rotation r); |
65 | virtual void generateImage(); | 67 | virtual void generateImage(); |
68 | virtual void loadJpeg(bool interncall = false); | ||
66 | bool image_fit_into(const QSize&s); | 69 | bool image_fit_into(const QSize&s); |
67 | void check_zoomer(); | 70 | void check_zoomer(); |
68 | 71 | ||
69 | protected slots: | 72 | protected slots: |
70 | virtual void viewportMouseMoveEvent(QMouseEvent* e); | 73 | virtual void viewportMouseMoveEvent(QMouseEvent* e); |
71 | virtual void contentsMousePressEvent ( QMouseEvent * e); | 74 | virtual void contentsMousePressEvent ( QMouseEvent * e); |
72 | virtual void resizeEvent(QResizeEvent * e); | 75 | virtual void resizeEvent(QResizeEvent * e); |
73 | virtual void keyPressEvent(QKeyEvent * e); | 76 | virtual void keyPressEvent(QKeyEvent * e); |
74 | }; | 77 | }; |
75 | #endif | 78 | #endif |