author | alwin <alwin> | 2004-04-05 22:09:25 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-04-05 22:09:25 (UTC) |
commit | 266b184c615022484b988e1638be768b11c0c19b (patch) (side-by-side diff) | |
tree | b2560b3a64c49db414fa950fc3ef4670e25cd5ca | |
parent | 930abeed35ee6dd3aaec491f13d400f825b9d9d1 (diff) | |
download | opie-266b184c615022484b988e1638be768b11c0c19b.zip opie-266b184c615022484b988e1638be768b11c0c19b.tar.gz opie-266b184c615022484b988e1638be768b11c0c19b.tar.bz2 |
yeah - autoresize and autoscale now have toggle-buttons and the image display
respect these buttons
ToDo:
find a good way for prescaled loading of images if autoScale is on (in respect
to autorotate and so on)
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 56 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 4 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/mainwindow.cpp | 41 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/mainwindow.h | 5 |
4 files changed, 95 insertions, 11 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 @@ -11,64 +11,94 @@ 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) { 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) { 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(img),scale_to_fit(always_scale), rotate_to_fit(rfit),first_resize_done(false) { init(); } void ImageScrollView::setImage(const QImage&img) { _image_data = QImage(); _original_data=img; - first_resize_done = false; - init(); + if (first_resize_done) { + generateImage(); + } } void ImageScrollView::setImage( const QString& path ) { - + odebug << "load new image " << oendl; + _original_data.load(path); + _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); - if (_original_data.size().isValid()) { + if (first_resize_done) { + last_rot = Rotate0; + generateImage(); + odebug << "reinit display " << oendl; + } else if (_original_data.size().isValid()) { resizeContents(_original_data.width(),_original_data.height()); } - last_rot = Rotate0; +} + +void ImageScrollView::setAutoRotate(bool how) +{ + /* to avoid double repaints */ + if (rotate_to_fit != how) { + rotate_to_fit = how; + _image_data = QImage(); + generateImage(); + } +} + +void ImageScrollView::setAutoScale(bool how) +{ + scale_to_fit = how; + if (!how) { + rotate_to_fit = false; + } + _image_data = QImage(); + generateImage(); } ImageScrollView::~ImageScrollView() { } void ImageScrollView::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; int smoothW = (int)(scaleFactor * _image_data.width()); int smoothH = (int)(scaleFactor * _image_data.height()); _image_data = _image_data.smoothScale(smoothW,smoothH); } void ImageScrollView::rotate_into_data(Rotation r) { /* realy - we must do this that way, 'cause when acting direct on _image_data the app will segfault :( */ QImage dest; @@ -160,77 +190,83 @@ void ImageScrollView::rotate_into_data(Rotation r) dest.setNumColors(_original_data.numColors()); srcTable = (unsigned int *)_original_data.colorTable(); destTable = (unsigned int *)dest.colorTable(); for ( x=0; x < _original_data.numColors(); ++x ) destTable[x] = srcTable[x]; for ( y=0; y < _original_data.height(); ++y ) { srcData = (unsigned char *)_original_data.scanLine(y); for ( x=0; x < _original_data.width(); ++x ) { destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); destData[y] = srcData[x]; } } break; default: dest = _original_data; break; } } _image_data = dest; } -void ImageScrollView::resizeEvent(QResizeEvent * e) +void ImageScrollView::generateImage() { - odebug << "ImageScrollView resizeEvent" << oendl; - QScrollView::resizeEvent(e); Rotation r = Rotate0; if (width()>height()&&_original_data.width()<_original_data.height() || width()<height()&&_original_data.width()>_original_data.height()) { if (rotate_to_fit) r = Rotate90; } odebug << " r = " << r << oendl; if (scale_to_fit) { 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(width()-10,height()-10); - } else if (!first_resize_done||r!=last_rot) { + 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()); } +} + +void ImageScrollView::resizeEvent(QResizeEvent * e) +{ + odebug << "ImageScrollView resizeEvent" << oendl; + QScrollView::resizeEvent(e); + generateImage(); first_resize_done = true; } 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()) { p->fillRect(clipx,clipy,clipw,cliph,white); return; } if (w>_image_data.width()) { w=_image_data.width(); x = 0; erase = true; } else if (x+w>_image_data.width()){ x = _image_data.width()-w; } if (h>_image_data.height()) { h=_image_data.height(); diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h index 864a015..dcf54ce 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.h +++ b/noncore/graphics/opie-eye/gui/imagescrollview.h @@ -1,68 +1,72 @@ #ifndef _IMAGE_SCROLL_VIEW_H #define _IMAGE_SCROLL_VIEW_H #include <qscrollview.h> #include <qimage.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(); void setImage(const QImage&); void setImage( const QString& path ); void setDestructiveClose(); + void setAutoRotate(bool); + void setAutoScale(bool); + 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; int _mouseStartPosX,_mouseStartPosY; bool scale_to_fit; bool rotate_to_fit; bool first_resize_done; Rotation last_rot; void rescaleImage(int w, int h); void rotate_into_data(Rotation r); + void generateImage(); protected slots: virtual void viewportMouseMoveEvent(QMouseEvent* e); virtual void contentsMousePressEvent ( QMouseEvent * e); virtual void contentsMouseReleaseEvent ( QMouseEvent * e); virtual void resizeEvent(QResizeEvent * e); }; /* for testing */ class ImageDlg:public QDialog { Q_OBJECT public: ImageDlg(const QString&,QWidget * parent=0, const char * name=0); virtual ~ImageDlg(); }; #endif diff --git a/noncore/graphics/opie-eye/gui/mainwindow.cpp b/noncore/graphics/opie-eye/gui/mainwindow.cpp index 7f384bd..88acd59 100644 --- a/noncore/graphics/opie-eye/gui/mainwindow.cpp +++ b/noncore/graphics/opie-eye/gui/mainwindow.cpp @@ -71,55 +71,88 @@ PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style) connect( btn, SIGNAL( changeDir( const QString& ) ), m_view, SLOT(slotChangeDir( const QString& ) ) ); btn = new QToolButton( bar ); btn->setIconSet( Resource::loadIconSet( "edit" ) ); connect( btn, SIGNAL(clicked()), m_view, SLOT(slotRename()) ); if ( Ir::supported() ) { btn = new QToolButton( bar ); btn->setIconSet( Resource::loadIconSet( "beam" ) ); connect( btn, SIGNAL(clicked()), m_view, SLOT(slotBeam()) ); } btn = new QToolButton( bar ); btn->setIconSet( Resource::loadIconSet( "trash" ) ); connect( btn, SIGNAL(clicked() ), m_view, SLOT(slotTrash() ) ); btn = new QToolButton( bar ); btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) ); connect( btn, SIGNAL(clicked() ), this, SLOT(slotConfig() ) ); + + rotateButton = new QToolButton(bar); + rotateButton->setIconSet( Resource::loadIconSet( "rotate" ) ); + rotateButton->setToggleButton(true); + rotateButton->setOn(true); + connect(rotateButton,SIGNAL(toggled(bool)),this,SLOT(slotRotateToggled(bool))); + autoRotate = true; + + btn = new QToolButton(bar); + btn->setIconSet( Resource::loadIconSet( "1to1" ) ); + btn->setToggleButton(true); + btn->setOn(false); + connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotScaleToggled(bool))); + autoScale = true; } PMainWindow::~PMainWindow() { odebug << "Shutting down" << oendl; } +void PMainWindow::slotRotateToggled(bool how) +{ + autoRotate = how; + if (m_disp) { + m_disp->setAutoRotate(how); + } +} + +void PMainWindow::slotScaleToggled(bool how) +{ + autoScale = !how; + if (m_disp) { + m_disp->setAutoScale(autoScale); + } + if (!autoScale && autoRotate) { + rotateButton->setOn(false); + } + rotateButton->setEnabled(!how); +} void PMainWindow::slotConfig() { /* * have a tab with the possible views * a tab for globals image cache size.. scaled loading * and one tab for the KeyConfigs */ QDialog dlg(this, 0, true); dlg.setCaption( tr("Phunk View - Config" ) ); QHBoxLayout *lay = new QHBoxLayout(&dlg); Opie::Ui::OTabWidget *wid = new Opie::Ui::OTabWidget(&dlg ); lay->addWidget( wid ); ViewMap *vM = viewMap(); ViewMap::Iterator _it = vM->begin(); QMap<PDirView*, QWidget*> lst; for( ; _it != vM->end(); ++_it ) { PDirView *view = (_it.data())(*m_cfg); PInterfaceInfo *inf = view->interfaceInfo(); QWidget *_wid = inf->configWidget( *m_cfg ); _wid->reparent(wid, QPoint() ); lst.insert( view, _wid ); wid->addTab( _wid, "fileopen", inf->name() ); @@ -159,68 +192,74 @@ void PMainWindow::slotConfig() { /* * create a new image info component * and detach the current one * we will make the other delete on exit */ template<class T> void PMainWindow::initT( const char* name, T** ptr, int id) { if ( *ptr ) { (*ptr)->disconnect(this, SLOT(slotReturn())); (*ptr)->setDestructiveClose(); m_stack->removeWidget( *ptr ); } *ptr = new T( m_stack, name ); m_stack->addWidget( *ptr, id ); connect(*ptr, SIGNAL(sig_return()), this,SLOT(slotReturn())); } void PMainWindow::initInfo() { initT<imageinfo>( "Image Info", &m_info, ImageInfo ); } void PMainWindow::initDisp() { initT<ImageScrollView>( "Image ScrollView", &m_disp, ImageDisplay ); + if (m_disp) { + m_disp->setAutoScale(autoScale); + m_disp->setAutoRotate(autoRotate); + } + } /** * With big Screen the plan could be to 'detach' the image * window if visible and to create a ne wone * init* already supports it but I make no use of it for * now. We set filename and raise * * ### FIXME and talk to alwin */ void PMainWindow::slotShowInfo( const QString& inf ) { if ( !m_info ) initInfo(); m_info->setPath( inf ); m_stack->raiseWidget( ImageInfo ); } void PMainWindow::slotDisplay( const QString& inf ) { - if ( !m_disp ) + if ( !m_disp ) { initDisp(); + } m_disp->setImage( inf ); m_stack->raiseWidget( ImageDisplay ); } void PMainWindow::slotReturn() { raiseIconView(); } void PMainWindow::closeEvent( QCloseEvent* ev ) { /* * return from view * or properly quit */ if ( m_stack->visibleWidget() == m_info || m_stack->visibleWidget() == m_disp ) { raiseIconView(); ev->ignore(); return; } ev->accept(); QTimer::singleShot(0, qApp, SLOT(closeAllWindows())); } diff --git a/noncore/graphics/opie-eye/gui/mainwindow.h b/noncore/graphics/opie-eye/gui/mainwindow.h index 35116ae..6debf7f 100644 --- a/noncore/graphics/opie-eye/gui/mainwindow.h +++ b/noncore/graphics/opie-eye/gui/mainwindow.h @@ -16,47 +16,52 @@ namespace Opie { namespace Ui{ class OKeyConfigManager; class OWidgetStack; } } class PIconView; class imageinfo; class ImageScrollView; class PMainWindow : public QMainWindow { Q_OBJECT enum Views { IconView, ImageInfo, ImageDisplay }; public: static QString appName() { return QString::fromLatin1("opie-eye" ); } PMainWindow(QWidget*, const char*, WFlags ); ~PMainWindow(); signals: void configChanged(); public slots: void slotShowInfo( const QString& inf ); void slotDisplay( const QString& inf ); void slotReturn(); + void slotRotateToggled(bool); + void slotScaleToggled(bool); protected: void raiseIconView(); void closeEvent( QCloseEvent* ); private: template<class T> void initT( const char* name, T**, int ); void initInfo(); void initDisp(); private: Opie::Core::OConfig *m_cfg; Opie::Ui::OWidgetStack *m_stack; PIconView* m_view; imageinfo *m_info; ImageScrollView *m_disp; + bool autoRotate; + bool autoScale; + QToolButton*rotateButton; private slots: void slotConfig(); }; #endif |