Diffstat (limited to 'noncore/graphics/opie-eye/gui') (more/less context) (ignore whitespace changes)
-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 @@ -33,10 +33,16 @@ 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(); + } } @@ -44,9 +50,33 @@ void ImageScrollView::setImage( const QString& path ) { 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(); } @@ -182,8 +212,6 @@ void ImageScrollView::rotate_into_data(Rotation r) } -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() || @@ -194,4 +222,5 @@ void ImageScrollView::resizeEvent(QResizeEvent * e) 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; @@ -201,6 +230,6 @@ void ImageScrollView::resizeEvent(QResizeEvent * e) } 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; @@ -211,4 +240,11 @@ void ImageScrollView::resizeEvent(QResizeEvent * e) resizeContents(_image_data.width(),_image_data.height()); } +} + +void ImageScrollView::resizeEvent(QResizeEvent * e) +{ + odebug << "ImageScrollView resizeEvent" << oendl; + QScrollView::resizeEvent(e); + generateImage(); first_resize_done = true; } 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 @@ -22,4 +22,7 @@ public: void setDestructiveClose(); + void setAutoRotate(bool); + void setAutoScale(bool); + enum Rotation { Rotate0, @@ -49,4 +52,5 @@ protected: void rotate_into_data(Rotation r); + void generateImage(); protected slots: 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 @@ -93,4 +93,18 @@ PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style) 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; } @@ -100,4 +114,23 @@ PMainWindow::~PMainWindow() { } +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() { @@ -181,4 +214,9 @@ void PMainWindow::initInfo() { void PMainWindow::initDisp() { initT<ImageScrollView>( "Image ScrollView", &m_disp, ImageDisplay ); + if (m_disp) { + m_disp->setAutoScale(autoScale); + m_disp->setAutoRotate(autoRotate); + } + } @@ -199,6 +237,7 @@ void PMainWindow::slotShowInfo( const QString& inf ) { void PMainWindow::slotDisplay( const QString& inf ) { - if ( !m_disp ) + if ( !m_disp ) { initDisp(); + } m_disp->setImage( inf ); m_stack->raiseWidget( ImageDisplay ); 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 @@ -38,4 +38,6 @@ public slots: void slotDisplay( const QString& inf ); void slotReturn(); + void slotRotateToggled(bool); + void slotScaleToggled(bool); protected: @@ -54,4 +56,7 @@ private: imageinfo *m_info; ImageScrollView *m_disp; + bool autoRotate; + bool autoScale; + QToolButton*rotateButton; |