summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-07 20:28:21 (UTC)
committer alwin <alwin>2004-04-07 20:28:21 (UTC)
commit52ccc71e2859ae9d738629249baeef3e3df992a2 (patch) (side-by-side diff)
tree7315f7b6810cb246296fea30e35c4f1205be97f3
parentf8e633dea182beabbb665a25136b43a9dd7d0558 (diff)
downloadopie-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.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp30
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h2
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
@@ -5,58 +5,64 @@
using namespace Opie::Core;
#include <qimage.h>
#include <qlayout.h>
ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f )
:QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true),
rotate_to_fit(true),first_resize_done(false),m_lastName("")
{
init();
}
ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit)
:QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale),
rotate_to_fit(rfit),first_resize_done(false),m_lastName("")
{
+ _original_data.convertDepth(QPixmap::defaultDepth());
+ _original_data.setAlphaBuffer(false);
init();
}
ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit)
:QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale),
rotate_to_fit(rfit),first_resize_done(false),m_lastName("")
{
init();
setImage(img);
}
void ImageScrollView::setImage(const QImage&img)
{
_image_data = QImage();
_original_data=img;
+ _original_data.convertDepth(QPixmap::defaultDepth());
+ _original_data.setAlphaBuffer(false);
m_lastName = "";
if (first_resize_done) {
generateImage();
}
}
void ImageScrollView::setImage( const QString& path ) {
odebug << "load new image " << oendl;
if (m_lastName == path) return;
m_lastName = path;
_original_data.load(path);
+ _original_data.convertDepth(QPixmap::defaultDepth());
+ _original_data.setAlphaBuffer(false);
_image_data = QImage();
if (first_resize_done) {
generateImage();
}
}
/* should be called every time the QImage changed it content */
void ImageScrollView::init()
{
odebug << "init " << oendl;
viewport()->setBackgroundColor(white);
setFocusPolicy(QWidget::StrongFocus);
if (first_resize_done) {
last_rot = Rotate0;
generateImage();
odebug << "reinit display " << oendl;
@@ -231,32 +237,34 @@ void ImageScrollView::generateImage()
_image_data = _original_data;
} else {
rotate_into_data(r);
}
}
rescaleImage(width(),height());
resizeContents(_image_data.width(),_image_data.height());
} else if (!first_resize_done||r!=last_rot||_image_data.width()==0) {
if (r==Rotate0) {
_image_data = _original_data;
} else {
rotate_into_data(r);
}
last_rot = r;
resizeContents(_image_data.width(),_image_data.height());
}
+ _pdata.convertFromImage(_image_data);
+ _image_data=QImage();
}
void ImageScrollView::resizeEvent(QResizeEvent * e)
{
odebug << "ImageScrollView resizeEvent" << oendl;
QScrollView::resizeEvent(e);
generateImage();
first_resize_done = true;
}
void ImageScrollView::keyPressEvent(QKeyEvent * e)
{
if (!e) return;
int dx = horizontalScrollBar()->lineStep();
int dy = verticalScrollBar()->lineStep();
if (e->key()==Qt::Key_Right) {
@@ -272,54 +280,54 @@ void ImageScrollView::keyPressEvent(QKeyEvent * e)
scrollBy(0,dy);
e->accept();
} else {
e->ignore();
}
QScrollView::keyPressEvent(e);
}
void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph)
{
int w = clipw;
int h = cliph;
int x = clipx;
int y = clipy;
bool erase = false;
- if (!_image_data.size().isValid()) {
+ if (!_pdata.size().isValid()) {
p->fillRect(clipx,clipy,clipw,cliph,white);
return;
}
- if (w>_image_data.width()) {
- w=_image_data.width();
+ if (w>_pdata.width()) {
+ w=_pdata.width();
x = 0;
erase = true;
- } else if (x+w>_image_data.width()){
- x = _image_data.width()-w;
+ } else if (x+w>_pdata.width()){
+ x = _pdata.width()-w;
}
- if (h>_image_data.height()) {
- h=_image_data.height();
+ if (h>_pdata.height()) {
+ h=_pdata.height();
y = 0;
erase = true;
- } else if (y+h>_image_data.height()){
- y = _image_data.height()-h;
+ } else if (y+h>_pdata.height()){
+ y = _pdata.height()-h;
}
- if (erase||_image_data.hasAlphaBuffer()) {
+ if (erase||_original_data.hasAlphaBuffer()) {
p->fillRect(clipx,clipy,clipw,cliph,white);
}
- p->drawImage(clipx,clipy,_image_data,x,y,w,h);
+ p->drawPixmap(clipx,clipy,_pdata,x,y,w,h);
}
/* using the real geometry points and not the translated points is wanted! */
void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
{
int mx, my;
mx = e->x();
my = e->y();
if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) {
int diffx = _mouseStartPosX-mx;
int diffy = _mouseStartPosY-my;
#if 0
QScrollBar*xbar = horizontalScrollBar();
QScrollBar*ybar = verticalScrollBar();
if (xbar->value()+diffx>xbar->maxValue()) {
diffx = xbar->maxValue()-xbar->value();
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,21 +1,22 @@
#ifndef _IMAGE_SCROLL_VIEW_H
#define _IMAGE_SCROLL_VIEW_H
#include <qscrollview.h>
#include <qimage.h>
+#include <qpixmap.h>
#include <qstring.h>
#include <qdialog.h>
class QPainter;
class ImageScrollView:public QScrollView
{
Q_OBJECT
public:
ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 );
ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
virtual ~ImageScrollView();
virtual void setImage(const QImage&);
virtual void setImage( const QString& path );
@@ -27,32 +28,33 @@ public:
enum Rotation {
Rotate0,
Rotate90,
Rotate180,
Rotate270
};
signals:
void sig_return();
protected:
virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
void init();
QImage _image_data;
QImage _original_data;
+ QPixmap _pdata;
int _mouseStartPosX,_mouseStartPosY;
bool scale_to_fit;
bool rotate_to_fit;
bool first_resize_done;
Rotation last_rot;
QString m_lastName;
virtual void rescaleImage(int w, int h);
virtual void rotate_into_data(Rotation r);
virtual void generateImage();
protected slots:
virtual void viewportMouseMoveEvent(QMouseEvent* e);
virtual void contentsMousePressEvent ( QMouseEvent * e);