summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp56
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h4
-rw-r--r--noncore/graphics/opie-eye/gui/mainwindow.cpp41
-rw-r--r--noncore/graphics/opie-eye/gui/mainwindow.h5
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
@@ -29,28 +29,58 @@ ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const cha
}
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()
{
}
@@ -178,41 +208,47 @@ void ImageScrollView::rotate_into_data(Rotation r)
}
}
_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;
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
@@ -18,12 +18,15 @@ public:
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
};
@@ -45,12 +48,13 @@ protected:
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);
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
@@ -89,19 +89,52 @@ PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style)
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
@@ -177,12 +210,17 @@ void PMainWindow::initT( const char* name, T** ptr, int id) {
}
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
@@ -195,14 +233,15 @@ void PMainWindow::slotShowInfo( const QString& inf ) {
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();
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
@@ -34,12 +34,14 @@ 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:
@@ -50,12 +52,15 @@ private:
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();
};