summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp13
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h2
2 files changed, 10 insertions, 5 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
index ee20f40..99fdc51 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
@@ -1,89 +1,94 @@
1#include "imagescrollview.h" 1#include "imagescrollview.h"
2 2
3#include <opie2/odebug.h> 3#include <opie2/odebug.h>
4 4
5using namespace Opie::Core; 5using namespace Opie::Core;
6 6
7#include <qimage.h> 7#include <qimage.h>
8#include <qlayout.h> 8#include <qlayout.h>
9 9
10ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) 10ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f )
11 :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), 11 :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true),
12 rotate_to_fit(true),first_resize_done(false) 12 rotate_to_fit(true),first_resize_done(false),m_lastName("")
13{ 13{
14 init(); 14 init();
15 qDebug("constructor done");
15} 16}
16 17
17ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) 18ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit)
18 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), 19 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale),
19 rotate_to_fit(rfit),first_resize_done(false) 20 rotate_to_fit(rfit),first_resize_done(false),m_lastName("")
20{ 21{
21 init(); 22 init();
22} 23}
23 24
24ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) 25ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit)
25 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), 26 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale),
26 rotate_to_fit(rfit),first_resize_done(false) 27 rotate_to_fit(rfit),first_resize_done(false),m_lastName("")
27{ 28{
28 init(); 29 init();
30 setImage(img);
29} 31}
30 32
31void ImageScrollView::setImage(const QImage&img) 33void ImageScrollView::setImage(const QImage&img)
32{ 34{
33 _image_data = QImage(); 35 _image_data = QImage();
34 _original_data=img; 36 _original_data=img;
37 m_lastName = "";
35 if (first_resize_done) { 38 if (first_resize_done) {
36 generateImage(); 39 generateImage();
37 } 40 }
38} 41}
39 42
40void ImageScrollView::setImage( const QString& path ) { 43void ImageScrollView::setImage( const QString& path ) {
41 odebug << "load new image " << oendl; 44 odebug << "load new image " << oendl;
45 if (m_lastName == path) return;
46 m_lastName = path;
42 _original_data.load(path); 47 _original_data.load(path);
43 _image_data = QImage(); 48 _image_data = QImage();
44 if (first_resize_done) { 49 if (first_resize_done) {
45 generateImage(); 50 generateImage();
46 } 51 }
47} 52}
48 53
49/* should be called every time the QImage changed it content */ 54/* should be called every time the QImage changed it content */
50void ImageScrollView::init() 55void ImageScrollView::init()
51{ 56{
52 odebug << "init " << oendl; 57 odebug << "init " << oendl;
53 viewport()->setBackgroundColor(white); 58 viewport()->setBackgroundColor(white);
54 if (first_resize_done) { 59 if (first_resize_done) {
55 last_rot = Rotate0; 60 last_rot = Rotate0;
56 generateImage(); 61 generateImage();
57 odebug << "reinit display " << oendl; 62 odebug << "reinit display " << oendl;
58 } else if (_original_data.size().isValid()) { 63 } else if (_original_data.size().isValid()) {
59 resizeContents(_original_data.width(),_original_data.height()); 64 resizeContents(_original_data.width(),_original_data.height());
60 } 65 }
61} 66}
62 67
63void ImageScrollView::setAutoRotate(bool how) 68void ImageScrollView::setAutoRotate(bool how)
64{ 69{
65 /* to avoid double repaints */ 70 /* to avoid double repaints */
66 if (rotate_to_fit != how) { 71 if (rotate_to_fit != how) {
67 rotate_to_fit = how; 72 rotate_to_fit = how;
68 _image_data = QImage(); 73 _image_data = QImage();
69 generateImage(); 74 generateImage();
70 } 75 }
71} 76}
72 77
73void ImageScrollView::setAutoScale(bool how) 78void ImageScrollView::setAutoScale(bool how)
74{ 79{
75 scale_to_fit = how; 80 scale_to_fit = how;
76 if (!how) { 81 if (!how) {
77 rotate_to_fit = false; 82 rotate_to_fit = false;
78 } 83 }
79 _image_data = QImage(); 84 _image_data = QImage();
80 generateImage(); 85 generateImage();
81} 86}
82 87
83ImageScrollView::~ImageScrollView() 88ImageScrollView::~ImageScrollView()
84{ 89{
85} 90}
86 91
87void ImageScrollView::rescaleImage(int w, int h) 92void ImageScrollView::rescaleImage(int w, int h)
88{ 93{
89 if (_image_data.width()==w && _image_data.height()==h) { 94 if (_image_data.width()==w && _image_data.height()==h) {
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h
index dcf54ce..44f2a64 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.h
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.h
@@ -2,71 +2,71 @@
2#define _IMAGE_SCROLL_VIEW_H 2#define _IMAGE_SCROLL_VIEW_H
3 3
4#include <qscrollview.h> 4#include <qscrollview.h>
5#include <qimage.h> 5#include <qimage.h>
6#include <qstring.h> 6#include <qstring.h>
7#include <qdialog.h> 7#include <qdialog.h>
8 8
9class QPainter; 9class QPainter;
10 10
11class ImageScrollView:public QScrollView 11class ImageScrollView:public QScrollView
12{ 12{
13 Q_OBJECT 13 Q_OBJECT
14public: 14public:
15 ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); 15 ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 );
16 ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); 16 ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
17 ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); 17 ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
18 virtual ~ImageScrollView(); 18 virtual ~ImageScrollView();
19 19
20 void setImage(const QImage&); 20 void setImage(const QImage&);
21 void setImage( const QString& path ); 21 void setImage( const QString& path );
22 void setDestructiveClose(); 22 void setDestructiveClose();
23 23
24 void setAutoRotate(bool); 24 void setAutoRotate(bool);
25 void setAutoScale(bool); 25 void setAutoScale(bool);
26 26
27 enum Rotation { 27 enum Rotation {
28 Rotate0, 28 Rotate0,
29 Rotate90, 29 Rotate90,
30 Rotate180, 30 Rotate180,
31 Rotate270 31 Rotate270
32 }; 32 };
33 33
34signals: 34signals:
35 void sig_return(); 35 void sig_return();
36 36
37protected: 37protected:
38 virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); 38 virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
39 void init(); 39 void init();
40 40
41 QImage _image_data; 41 QImage _image_data;
42 QImage _original_data; 42 QImage _original_data;
43 43
44 int _mouseStartPosX,_mouseStartPosY; 44 int _mouseStartPosX,_mouseStartPosY;
45 45
46 bool scale_to_fit; 46 bool scale_to_fit;
47 bool rotate_to_fit; 47 bool rotate_to_fit;
48 bool first_resize_done; 48 bool first_resize_done;
49 Rotation last_rot; 49 Rotation last_rot;
50 50 QString m_lastName;
51 void rescaleImage(int w, int h); 51 void rescaleImage(int w, int h);
52 52
53 void rotate_into_data(Rotation r); 53 void rotate_into_data(Rotation r);
54 void generateImage(); 54 void generateImage();
55 55
56protected slots: 56protected slots:
57 virtual void viewportMouseMoveEvent(QMouseEvent* e); 57 virtual void viewportMouseMoveEvent(QMouseEvent* e);
58 virtual void contentsMousePressEvent ( QMouseEvent * e); 58 virtual void contentsMousePressEvent ( QMouseEvent * e);
59 virtual void contentsMouseReleaseEvent ( QMouseEvent * e); 59 virtual void contentsMouseReleaseEvent ( QMouseEvent * e);
60 virtual void resizeEvent(QResizeEvent * e); 60 virtual void resizeEvent(QResizeEvent * e);
61}; 61};
62 62
63/* for testing */ 63/* for testing */
64class ImageDlg:public QDialog 64class ImageDlg:public QDialog
65{ 65{
66 Q_OBJECT 66 Q_OBJECT
67public: 67public:
68 ImageDlg(const QString&,QWidget * parent=0, const char * name=0); 68 ImageDlg(const QString&,QWidget * parent=0, const char * name=0);
69 virtual ~ImageDlg(); 69 virtual ~ImageDlg();
70}; 70};
71 71
72#endif 72#endif