author | alwin <alwin> | 2004-04-07 20:28:21 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-04-07 20:28:21 (UTC) |
commit | 52ccc71e2859ae9d738629249baeef3e3df992a2 (patch) (unidiff) | |
tree | 7315f7b6810cb246296fea30e35c4f1205be97f3 | |
parent | f8e633dea182beabbb665a25136b43a9dd7d0558 (diff) | |
download | opie-52ccc71e2859ae9d738629249baeef3e3df992a2.zip opie-52ccc71e2859ae9d738629249baeef3e3df992a2.tar.gz opie-52ccc71e2859ae9d738629249baeef3e3df992a2.tar.bz2 |
speed up painting a lot - drawing QImage seems to be a real bad idea.
Painting QPixmap instead.
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 30 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 2 |
2 files changed, 21 insertions, 11 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp index 98054ff..ad19219 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp | |||
@@ -9,50 +9,56 @@ using namespace Opie::Core; | |||
9 | 9 | ||
10 | ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) | 10 | ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) |
11 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), | 11 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), |
12 | rotate_to_fit(true),first_resize_done(false),m_lastName("") | 12 | rotate_to_fit(true),first_resize_done(false),m_lastName("") |
13 | { | 13 | { |
14 | init(); | 14 | init(); |
15 | } | 15 | } |
16 | 16 | ||
17 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 17 | 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), | 18 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), |
19 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") | 19 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") |
20 | { | 20 | { |
21 | _original_data.convertDepth(QPixmap::defaultDepth()); | ||
22 | _original_data.setAlphaBuffer(false); | ||
21 | init(); | 23 | init(); |
22 | } | 24 | } |
23 | 25 | ||
24 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 26 | 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(),scale_to_fit(always_scale), | 27 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale), |
26 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") | 28 | rotate_to_fit(rfit),first_resize_done(false),m_lastName("") |
27 | { | 29 | { |
28 | init(); | 30 | init(); |
29 | setImage(img); | 31 | setImage(img); |
30 | } | 32 | } |
31 | 33 | ||
32 | void ImageScrollView::setImage(const QImage&img) | 34 | void ImageScrollView::setImage(const QImage&img) |
33 | { | 35 | { |
34 | _image_data = QImage(); | 36 | _image_data = QImage(); |
35 | _original_data=img; | 37 | _original_data=img; |
38 | _original_data.convertDepth(QPixmap::defaultDepth()); | ||
39 | _original_data.setAlphaBuffer(false); | ||
36 | m_lastName = ""; | 40 | m_lastName = ""; |
37 | if (first_resize_done) { | 41 | if (first_resize_done) { |
38 | generateImage(); | 42 | generateImage(); |
39 | } | 43 | } |
40 | } | 44 | } |
41 | 45 | ||
42 | void ImageScrollView::setImage( const QString& path ) { | 46 | void ImageScrollView::setImage( const QString& path ) { |
43 | odebug << "load new image " << oendl; | 47 | odebug << "load new image " << oendl; |
44 | if (m_lastName == path) return; | 48 | if (m_lastName == path) return; |
45 | m_lastName = path; | 49 | m_lastName = path; |
46 | _original_data.load(path); | 50 | _original_data.load(path); |
51 | _original_data.convertDepth(QPixmap::defaultDepth()); | ||
52 | _original_data.setAlphaBuffer(false); | ||
47 | _image_data = QImage(); | 53 | _image_data = QImage(); |
48 | if (first_resize_done) { | 54 | if (first_resize_done) { |
49 | generateImage(); | 55 | generateImage(); |
50 | } | 56 | } |
51 | } | 57 | } |
52 | 58 | ||
53 | /* should be called every time the QImage changed it content */ | 59 | /* should be called every time the QImage changed it content */ |
54 | void ImageScrollView::init() | 60 | void ImageScrollView::init() |
55 | { | 61 | { |
56 | odebug << "init " << oendl; | 62 | odebug << "init " << oendl; |
57 | viewport()->setBackgroundColor(white); | 63 | viewport()->setBackgroundColor(white); |
58 | setFocusPolicy(QWidget::StrongFocus); | 64 | setFocusPolicy(QWidget::StrongFocus); |
@@ -235,24 +241,26 @@ void ImageScrollView::generateImage() | |||
235 | } | 241 | } |
236 | rescaleImage(width(),height()); | 242 | rescaleImage(width(),height()); |
237 | resizeContents(_image_data.width(),_image_data.height()); | 243 | resizeContents(_image_data.width(),_image_data.height()); |
238 | } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { | 244 | } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { |
239 | if (r==Rotate0) { | 245 | if (r==Rotate0) { |
240 | _image_data = _original_data; | 246 | _image_data = _original_data; |
241 | } else { | 247 | } else { |
242 | rotate_into_data(r); | 248 | rotate_into_data(r); |
243 | } | 249 | } |
244 | last_rot = r; | 250 | last_rot = r; |
245 | resizeContents(_image_data.width(),_image_data.height()); | 251 | resizeContents(_image_data.width(),_image_data.height()); |
246 | } | 252 | } |
253 | _pdata.convertFromImage(_image_data); | ||
254 | _image_data=QImage(); | ||
247 | } | 255 | } |
248 | 256 | ||
249 | void ImageScrollView::resizeEvent(QResizeEvent * e) | 257 | void ImageScrollView::resizeEvent(QResizeEvent * e) |
250 | { | 258 | { |
251 | odebug << "ImageScrollView resizeEvent" << oendl; | 259 | odebug << "ImageScrollView resizeEvent" << oendl; |
252 | QScrollView::resizeEvent(e); | 260 | QScrollView::resizeEvent(e); |
253 | generateImage(); | 261 | generateImage(); |
254 | first_resize_done = true; | 262 | first_resize_done = true; |
255 | } | 263 | } |
256 | 264 | ||
257 | void ImageScrollView::keyPressEvent(QKeyEvent * e) | 265 | void ImageScrollView::keyPressEvent(QKeyEvent * e) |
258 | { | 266 | { |
@@ -276,46 +284,46 @@ void ImageScrollView::keyPressEvent(QKeyEvent * e) | |||
276 | } | 284 | } |
277 | QScrollView::keyPressEvent(e); | 285 | QScrollView::keyPressEvent(e); |
278 | } | 286 | } |
279 | 287 | ||
280 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | 288 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) |
281 | { | 289 | { |
282 | int w = clipw; | 290 | int w = clipw; |
283 | int h = cliph; | 291 | int h = cliph; |
284 | int x = clipx; | 292 | int x = clipx; |
285 | int y = clipy; | 293 | int y = clipy; |
286 | bool erase = false; | 294 | bool erase = false; |
287 | 295 | ||
288 | if (!_image_data.size().isValid()) { | 296 | if (!_pdata.size().isValid()) { |
289 | p->fillRect(clipx,clipy,clipw,cliph,white); | 297 | p->fillRect(clipx,clipy,clipw,cliph,white); |
290 | return; | 298 | return; |
291 | } | 299 | } |
292 | if (w>_image_data.width()) { | 300 | if (w>_pdata.width()) { |
293 | w=_image_data.width(); | 301 | w=_pdata.width(); |
294 | x = 0; | 302 | x = 0; |
295 | erase = true; | 303 | erase = true; |
296 | } else if (x+w>_image_data.width()){ | 304 | } else if (x+w>_pdata.width()){ |
297 | x = _image_data.width()-w; | 305 | x = _pdata.width()-w; |
298 | } | 306 | } |
299 | if (h>_image_data.height()) { | 307 | if (h>_pdata.height()) { |
300 | h=_image_data.height(); | 308 | h=_pdata.height(); |
301 | y = 0; | 309 | y = 0; |
302 | erase = true; | 310 | erase = true; |
303 | } else if (y+h>_image_data.height()){ | 311 | } else if (y+h>_pdata.height()){ |
304 | y = _image_data.height()-h; | 312 | y = _pdata.height()-h; |
305 | } | 313 | } |
306 | if (erase||_image_data.hasAlphaBuffer()) { | 314 | if (erase||_original_data.hasAlphaBuffer()) { |
307 | p->fillRect(clipx,clipy,clipw,cliph,white); | 315 | p->fillRect(clipx,clipy,clipw,cliph,white); |
308 | } | 316 | } |
309 | p->drawImage(clipx,clipy,_image_data,x,y,w,h); | 317 | p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); |
310 | } | 318 | } |
311 | 319 | ||
312 | /* using the real geometry points and not the translated points is wanted! */ | 320 | /* using the real geometry points and not the translated points is wanted! */ |
313 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | 321 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) |
314 | { | 322 | { |
315 | int mx, my; | 323 | int mx, my; |
316 | mx = e->x(); | 324 | mx = e->x(); |
317 | my = e->y(); | 325 | my = e->y(); |
318 | if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { | 326 | if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { |
319 | int diffx = _mouseStartPosX-mx; | 327 | int diffx = _mouseStartPosX-mx; |
320 | int diffy = _mouseStartPosY-my; | 328 | int diffy = _mouseStartPosY-my; |
321 | #if 0 | 329 | #if 0 |
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h index 17e2f5f..eb91dbd 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.h +++ b/noncore/graphics/opie-eye/gui/imagescrollview.h | |||
@@ -1,17 +1,18 @@ | |||
1 | #ifndef _IMAGE_SCROLL_VIEW_H | 1 | #ifndef _IMAGE_SCROLL_VIEW_H |
2 | #define _IMAGE_SCROLL_VIEW_H | 2 | #define _IMAGE_SCROLL_VIEW_H |
3 | 3 | ||
4 | #include <qscrollview.h> | 4 | #include <qscrollview.h> |
5 | #include <qimage.h> | 5 | #include <qimage.h> |
6 | #include <qpixmap.h> | ||
6 | #include <qstring.h> | 7 | #include <qstring.h> |
7 | #include <qdialog.h> | 8 | #include <qdialog.h> |
8 | 9 | ||
9 | class QPainter; | 10 | class QPainter; |
10 | 11 | ||
11 | class ImageScrollView:public QScrollView | 12 | class ImageScrollView:public QScrollView |
12 | { | 13 | { |
13 | Q_OBJECT | 14 | Q_OBJECT |
14 | public: | 15 | public: |
15 | ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); | 16 | ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); |
16 | ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | 17 | ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); |
17 | ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); | 18 | ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); |
@@ -31,24 +32,25 @@ public: | |||
31 | Rotate270 | 32 | Rotate270 |
32 | }; | 33 | }; |
33 | 34 | ||
34 | signals: | 35 | signals: |
35 | void sig_return(); | 36 | void sig_return(); |
36 | 37 | ||
37 | protected: | 38 | protected: |
38 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); | 39 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); |
39 | void init(); | 40 | void init(); |
40 | 41 | ||
41 | QImage _image_data; | 42 | QImage _image_data; |
42 | QImage _original_data; | 43 | QImage _original_data; |
44 | QPixmap _pdata; | ||
43 | 45 | ||
44 | int _mouseStartPosX,_mouseStartPosY; | 46 | int _mouseStartPosX,_mouseStartPosY; |
45 | 47 | ||
46 | bool scale_to_fit; | 48 | bool scale_to_fit; |
47 | bool rotate_to_fit; | 49 | bool rotate_to_fit; |
48 | bool first_resize_done; | 50 | bool first_resize_done; |
49 | Rotation last_rot; | 51 | Rotation last_rot; |
50 | QString m_lastName; | 52 | QString m_lastName; |
51 | virtual void rescaleImage(int w, int h); | 53 | virtual void rescaleImage(int w, int h); |
52 | 54 | ||
53 | virtual void rotate_into_data(Rotation r); | 55 | virtual void rotate_into_data(Rotation r); |
54 | virtual void generateImage(); | 56 | virtual void generateImage(); |