author | alwin <alwin> | 2004-04-16 07:39:26 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-04-16 07:39:26 (UTC) |
commit | 9692c199f1f8b4c334687081e0d75bfbf9375ad8 (patch) (side-by-side diff) | |
tree | 3ab64a3de58d5f266229d99d0eeae20a1d49f254 /libopie2 | |
parent | 7c29eeaecc8301fb500851382b3d94092ae72719 (diff) | |
download | opie-9692c199f1f8b4c334687081e0d75bfbf9375ad8.zip opie-9692c199f1f8b4c334687081e0d75bfbf9375ad8.tar.gz opie-9692c199f1f8b4c334687081e0d75bfbf9375ad8.tar.bz2 |
- displaying a busy makes no sense here. It results in double paintings
- method to set autoscale/autorotate at once
-rw-r--r-- | libopie2/opiemm/oimagescrollview.cpp | 31 | ||||
-rw-r--r-- | libopie2/opiemm/oimagescrollview.h | 13 |
2 files changed, 19 insertions, 25 deletions
diff --git a/libopie2/opiemm/oimagescrollview.cpp b/libopie2/opiemm/oimagescrollview.cpp index 30a8fba..61b2062 100644 --- a/libopie2/opiemm/oimagescrollview.cpp +++ b/libopie2/opiemm/oimagescrollview.cpp @@ -1,34 +1,33 @@ #include "oimagescrollview.h" #include <opie2/oimagezoomer.h> #include <opie2/odebug.h> #include <opie2/oapplication.h> #include <opie2/owait.h> #include <qimage.h> #include <qlayout.h> -#include <qpe/qcopenvelope_qws.h> /* for usage with the bitset */ #define AUTO_SCALE 0 #define AUTO_ROTATE 1 #define SHOW_ZOOMER 2 #define FIRST_RESIZE_DONE 3 #define IMAGE_IS_JPEG 4 #define IMAGE_SCALED_LOADED 5 #define SCROLLVIEW_BITSET_SIZE 6 namespace Opie { namespace MM { OImageScrollView::OImageScrollView( QWidget* parent, const char* name, WFlags f ) :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(), m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") { _zoomer = 0; m_states[AUTO_SCALE]=true; m_states[AUTO_ROTATE]=true; m_states[FIRST_RESIZE_DONE]=false; m_states[IMAGE_IS_JPEG]=false; m_states[IMAGE_SCALED_LOADED]=false; m_states[SHOW_ZOOMER]=true; @@ -89,81 +88,67 @@ void OImageScrollView::loadJpeg(bool interncall) if (AutoScale()) { if (!interncall) { int wid, hei; wid = QApplication::desktop()->width(); hei = QApplication::desktop()->height(); if (hei>wid) { wid = hei; } else { hei = wid; } param = QString( "Fast Shrink( 3 ) Scale( %1, %2, ScaleMin)" ).arg( wid ).arg( hei ); odebug << "Load jpeg scaled \"" << param << "\"" << oendl; iio.setParameters(param.latin1()); setImageScaledLoaded(true); real_load = true; } } else { if (ImageScaledLoaded()||!interncall) { odebug << "Load jpeg unscaled" << oendl; real_load = true; } setImageScaledLoaded(false); } if (real_load) { - { - QCopEnvelope( "QPE/System", "busy()" ); - } _original_data = iio.read() ? iio.image() : QImage(); - { - QCopEnvelope env( "QPE/System", "notBusy(QString)" ); - env << "Image loaded"; - } } } void OImageScrollView::setImage( const QString& path ) { odebug << "load new image " << oendl; if (m_lastName == path) return; m_lastName = path; _original_data = QImage(); QString itype = QImage::imageFormat(m_lastName); odebug << "Image type = " << itype << oendl; if (itype == "JPEG") { setImageIsJpeg(true); loadJpeg(); } else { - { - QCopEnvelope( "QPE/System", "busy()" ); - } setImageIsJpeg(false); _original_data.load(path); _original_data.convertDepth(QPixmap::defaultDepth()); _original_data.setAlphaBuffer(false); - { - QCopEnvelope env( "QPE/System", "notBusy(QString)" ); - env << "Image loaded"; - } } _image_data = QImage(); if (FirstResizeDone()) { generateImage(); if (isVisible()) viewport()->repaint(true); } } /* should be called every time the QImage changed it content */ void OImageScrollView::init() { odebug << "init " << oendl; /* * create the zoomer * and connect ther various signals */ _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), this, SLOT(scrollBy(int,int)) ); connect(_zoomer, SIGNAL( zoomArea(int,int)), this, SLOT(center(int,int)) ); connect(this,SIGNAL(contentsMoving(int,int)), _zoomer, (SLOT(setVisiblePoint(int,int))) ); @@ -179,54 +164,57 @@ void OImageScrollView::init() if (FirstResizeDone()) { m_last_rot = Rotate0; generateImage(); } else if (_original_data.size().isValid()) { if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide(); resizeContents(_original_data.width(),_original_data.height()); } } void OImageScrollView::setAutoRotate(bool how) { /* to avoid double repaints */ if (AutoRotate() != how) { m_states.setBit(AUTO_ROTATE,how); _image_data = QImage(); generateImage(); } } bool OImageScrollView::AutoRotate()const { return m_states.testBit(AUTO_ROTATE); } +void OImageScrollView::setAutoScaleRotate(bool scale, bool rotate) +{ + m_states.setBit(AUTO_ROTATE,rotate); + setAutoScale(scale); +} + void OImageScrollView::setAutoScale(bool how) { m_states.setBit(AUTO_SCALE,how); - if (!how) { - setAutoRotate(false); - } _image_data = QImage(); if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) { loadJpeg(true); } generateImage(); } bool OImageScrollView::AutoScale()const { return m_states.testBit(AUTO_SCALE); } OImageScrollView::~OImageScrollView() { } void OImageScrollView::rescaleImage(int w, int h) { if (_image_data.width()==w && _image_data.height()==h) { return; } double hs = (double)h / (double)_image_data.height() ; double ws = (double)w / (double)_image_data.width() ; double scaleFactor = (hs > ws) ? ws : hs; @@ -337,102 +325,95 @@ void OImageScrollView::rotate_into_data(Rotation r) { destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); destData[y] = srcData[x]; } } break; default: dest = _original_data; break; } } _image_data = dest; } void OImageScrollView::generateImage() { Rotation r = Rotate0; _pdata = QPixmap(); if (_original_data.isNull()) { emit imageSizeChanged( _image_data.size() ); if (_zoomer) _zoomer->setImage( _image_data ); return; } - { - QCopEnvelope( "QPE/System", "busy()" ); - } if (width()>height()&&_original_data.width()<_original_data.height() || width()<height()&&_original_data.width()>_original_data.height()) { if (AutoRotate()) r = Rotate90; } odebug << " r = " << r << oendl; if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) { if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { odebug << "Rescaling data" << oendl; if (r==Rotate0) { _image_data = _original_data; } else { rotate_into_data(r); } } rescaleImage(width(),height()); resizeContents(_image_data.width(),_image_data.height()); } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) { if (r==Rotate0) { _image_data = _original_data; } else { rotate_into_data(r); } m_last_rot = r; resizeContents(_image_data.width(),_image_data.height()); } _pdata.convertFromImage(_image_data); /* * update the zoomer */ check_zoomer(); emit imageSizeChanged( _image_data.size() ); rescaleImage( 128, 128 ); /* * move scrollbar */ if (_zoomer) { _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, _image_data.width()/2, _image_data.height()/2 ); _zoomer->setImage( _image_data ); } /* * invalidate */ _image_data=QImage(); - { - QCopEnvelope env( "QPE/System", "notBusy(QString)" ); - env << "Image generated"; - } } void OImageScrollView::resizeEvent(QResizeEvent * e) { odebug << "OImageScrollView resizeEvent" << oendl; QScrollView::resizeEvent(e); generateImage(); setFirstResizeDone(true); emit viewportSizeChanged( viewport()->size() ); } void OImageScrollView::keyPressEvent(QKeyEvent * e) { if (!e) return; int dx = horizontalScrollBar()->lineStep(); int dy = verticalScrollBar()->lineStep(); if (e->key()==Qt::Key_Right) { scrollBy(dx,0); e->accept(); } else if (e->key()==Qt::Key_Left) { scrollBy(0-dx,0); e->accept(); } else if (e->key()==Qt::Key_Up) { diff --git a/libopie2/opiemm/oimagescrollview.h b/libopie2/opiemm/oimagescrollview.h index 94fddb6..01a2d56 100644 --- a/libopie2/opiemm/oimagescrollview.h +++ b/libopie2/opiemm/oimagescrollview.h @@ -67,48 +67,61 @@ public: /** * sets the WDestructiveClose flag to the view */ virtual void setDestructiveClose(); /** * set if the image should be rotate to best fit * and repaint it if set to a new value. * * Be carefull - autorating real large images cost time! * @param how if true then autorotate otherwise not */ virtual void setAutoRotate(bool how); /** * set if the image should be scaled to the size of the viewport if larger(!) * * if autoscaling is set when loading a jpeg image, it will use a feature of * jpeg lib to load the image scaled to display size. If switch of later the * image will reloaded. * * @param how true - display image scaled down otherwise not */ virtual void setAutoScale(bool how); /** + * set if the image should be scaled to the size of the viewport if larger(!) + * and/or rotate to best fit. You avoid double repainting when you want to switch + * booth values. + * + * if autoscaling is set when loading a jpeg image, it will use a feature of + * jpeg lib to load the image scaled to display size. If switch of later the + * image will reloaded. + * + * @param scale true - display image scaled down otherwise not + * @param rotate true - the image will rotate for best fit + */ + virtual void setAutoScaleRotate(bool scale, bool rotate); + /** * set if there should be displayed a small zoomer widget at the right bottom of * the view when the image is larger than the viewport. * * @param how true - display zoomer */ virtual void setShowZoomer(bool how); /** * return the current value of the autorotate flag. */ virtual bool AutoRotate()const; /** * return the current value of the autoscale flag. */ virtual bool AutoScale()const; /** * return the current value of the show zoomer flag. */ virtual bool ShowZoomer()const; public slots: /** * Displays a new image, calculations will made immediately. * |