summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-05 22:09:25 (UTC)
committer alwin <alwin>2004-04-05 22:09:25 (UTC)
commit266b184c615022484b988e1638be768b11c0c19b (patch) (unidiff)
treeb2560b3a64c49db414fa950fc3ef4670e25cd5ca
parent930abeed35ee6dd3aaec491f13d400f825b9d9d1 (diff)
downloadopie-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)
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
@@ -32,22 +32,52 @@ void ImageScrollView::setImage(const QImage&img)
32{ 32{
33 _image_data = QImage(); 33 _image_data = QImage();
34 _original_data=img; 34 _original_data=img;
35 first_resize_done = false; 35 if (first_resize_done) {
36 init(); 36 generateImage();
37 }
37} 38}
38 39
39void ImageScrollView::setImage( const QString& path ) { 40void ImageScrollView::setImage( const QString& path ) {
40 41 odebug << "load new image " << oendl;
42 _original_data.load(path);
43 _image_data = QImage();
44 if (first_resize_done) {
45 generateImage();
46 }
41} 47}
42 48
43/* should be called every time the QImage changed it content */ 49/* should be called every time the QImage changed it content */
44void ImageScrollView::init() 50void ImageScrollView::init()
45{ 51{
52 odebug << "init " << oendl;
46 viewport()->setBackgroundColor(white); 53 viewport()->setBackgroundColor(white);
47 if (_original_data.size().isValid()) { 54 if (first_resize_done) {
55 last_rot = Rotate0;
56 generateImage();
57 odebug << "reinit display " << oendl;
58 } else if (_original_data.size().isValid()) {
48 resizeContents(_original_data.width(),_original_data.height()); 59 resizeContents(_original_data.width(),_original_data.height());
49 } 60 }
50 last_rot = Rotate0; 61}
62
63void ImageScrollView::setAutoRotate(bool how)
64{
65 /* to avoid double repaints */
66 if (rotate_to_fit != how) {
67 rotate_to_fit = how;
68 _image_data = QImage();
69 generateImage();
70 }
71}
72
73void ImageScrollView::setAutoScale(bool how)
74{
75 scale_to_fit = how;
76 if (!how) {
77 rotate_to_fit = false;
78 }
79 _image_data = QImage();
80 generateImage();
51} 81}
52 82
53ImageScrollView::~ImageScrollView() 83ImageScrollView::~ImageScrollView()
@@ -181,10 +211,8 @@ void ImageScrollView::rotate_into_data(Rotation r)
181 _image_data = dest; 211 _image_data = dest;
182} 212}
183 213
184void ImageScrollView::resizeEvent(QResizeEvent * e) 214void ImageScrollView::generateImage()
185{ 215{
186 odebug << "ImageScrollView resizeEvent" << oendl;
187 QScrollView::resizeEvent(e);
188 Rotation r = Rotate0; 216 Rotation r = Rotate0;
189 if (width()>height()&&_original_data.width()<_original_data.height() || 217 if (width()>height()&&_original_data.width()<_original_data.height() ||
190 width()<height()&&_original_data.width()>_original_data.height()) { 218 width()<height()&&_original_data.width()>_original_data.height()) {
@@ -193,6 +221,7 @@ void ImageScrollView::resizeEvent(QResizeEvent * e)
193 odebug << " r = " << r << oendl; 221 odebug << " r = " << r << oendl;
194 if (scale_to_fit) { 222 if (scale_to_fit) {
195 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { 223 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) {
224 odebug << "Rescaling data" << oendl;
196 if (r==Rotate0) { 225 if (r==Rotate0) {
197 _image_data = _original_data; 226 _image_data = _original_data;
198 } else { 227 } else {
@@ -200,8 +229,8 @@ void ImageScrollView::resizeEvent(QResizeEvent * e)
200 } 229 }
201 } 230 }
202 rescaleImage(width(),height()); 231 rescaleImage(width(),height());
203 resizeContents(width()-10,height()-10); 232 resizeContents(_image_data.width(),_image_data.height());
204 } else if (!first_resize_done||r!=last_rot) { 233 } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) {
205 if (r==Rotate0) { 234 if (r==Rotate0) {
206 _image_data = _original_data; 235 _image_data = _original_data;
207 } else { 236 } else {
@@ -210,6 +239,13 @@ void ImageScrollView::resizeEvent(QResizeEvent * e)
210 last_rot = r; 239 last_rot = r;
211 resizeContents(_image_data.width(),_image_data.height()); 240 resizeContents(_image_data.width(),_image_data.height());
212 } 241 }
242}
243
244void ImageScrollView::resizeEvent(QResizeEvent * e)
245{
246 odebug << "ImageScrollView resizeEvent" << oendl;
247 QScrollView::resizeEvent(e);
248 generateImage();
213 first_resize_done = true; 249 first_resize_done = true;
214} 250}
215 251
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
@@ -21,6 +21,9 @@ public:
21 void setImage( const QString& path ); 21 void setImage( const QString& path );
22 void setDestructiveClose(); 22 void setDestructiveClose();
23 23
24 void setAutoRotate(bool);
25 void setAutoScale(bool);
26
24 enum Rotation { 27 enum Rotation {
25 Rotate0, 28 Rotate0,
26 Rotate90, 29 Rotate90,
@@ -48,6 +51,7 @@ protected:
48 void rescaleImage(int w, int h); 51 void rescaleImage(int w, int h);
49 52
50 void rotate_into_data(Rotation r); 53 void rotate_into_data(Rotation r);
54 void generateImage();
51 55
52protected slots: 56protected slots:
53 virtual void viewportMouseMoveEvent(QMouseEvent* e); 57 virtual void viewportMouseMoveEvent(QMouseEvent* 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
@@ -92,6 +92,20 @@ PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style)
92 btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) ); 92 btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) );
93 connect( btn, SIGNAL(clicked() ), 93 connect( btn, SIGNAL(clicked() ),
94 this, SLOT(slotConfig() ) ); 94 this, SLOT(slotConfig() ) );
95
96 rotateButton = new QToolButton(bar);
97 rotateButton->setIconSet( Resource::loadIconSet( "rotate" ) );
98 rotateButton->setToggleButton(true);
99 rotateButton->setOn(true);
100 connect(rotateButton,SIGNAL(toggled(bool)),this,SLOT(slotRotateToggled(bool)));
101 autoRotate = true;
102
103 btn = new QToolButton(bar);
104 btn->setIconSet( Resource::loadIconSet( "1to1" ) );
105 btn->setToggleButton(true);
106 btn->setOn(false);
107 connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotScaleToggled(bool)));
108 autoScale = true;
95 109
96} 110}
97 111
@@ -99,6 +113,25 @@ PMainWindow::~PMainWindow() {
99 odebug << "Shutting down" << oendl; 113 odebug << "Shutting down" << oendl;
100} 114}
101 115
116void PMainWindow::slotRotateToggled(bool how)
117{
118 autoRotate = how;
119 if (m_disp) {
120 m_disp->setAutoRotate(how);
121 }
122}
123
124void PMainWindow::slotScaleToggled(bool how)
125{
126 autoScale = !how;
127 if (m_disp) {
128 m_disp->setAutoScale(autoScale);
129 }
130 if (!autoScale && autoRotate) {
131 rotateButton->setOn(false);
132 }
133 rotateButton->setEnabled(!how);
134}
102 135
103void PMainWindow::slotConfig() { 136void PMainWindow::slotConfig() {
104 /* 137 /*
@@ -180,6 +213,11 @@ void PMainWindow::initInfo() {
180} 213}
181void PMainWindow::initDisp() { 214void PMainWindow::initDisp() {
182 initT<ImageScrollView>( "Image ScrollView", &m_disp, ImageDisplay ); 215 initT<ImageScrollView>( "Image ScrollView", &m_disp, ImageDisplay );
216 if (m_disp) {
217 m_disp->setAutoScale(autoScale);
218 m_disp->setAutoRotate(autoRotate);
219 }
220
183} 221}
184 222
185/** 223/**
@@ -198,8 +236,9 @@ void PMainWindow::slotShowInfo( const QString& inf ) {
198} 236}
199 237
200void PMainWindow::slotDisplay( const QString& inf ) { 238void PMainWindow::slotDisplay( const QString& inf ) {
201 if ( !m_disp ) 239 if ( !m_disp ) {
202 initDisp(); 240 initDisp();
241 }
203 m_disp->setImage( inf ); 242 m_disp->setImage( inf );
204 m_stack->raiseWidget( ImageDisplay ); 243 m_stack->raiseWidget( ImageDisplay );
205} 244}
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
@@ -37,6 +37,8 @@ public slots:
37 void slotShowInfo( const QString& inf ); 37 void slotShowInfo( const QString& inf );
38 void slotDisplay( const QString& inf ); 38 void slotDisplay( const QString& inf );
39 void slotReturn(); 39 void slotReturn();
40 void slotRotateToggled(bool);
41 void slotScaleToggled(bool);
40 42
41protected: 43protected:
42 void raiseIconView(); 44 void raiseIconView();
@@ -53,6 +55,9 @@ private:
53 PIconView* m_view; 55 PIconView* m_view;
54 imageinfo *m_info; 56 imageinfo *m_info;
55 ImageScrollView *m_disp; 57 ImageScrollView *m_disp;
58 bool autoRotate;
59 bool autoScale;
60 QToolButton*rotateButton;
56 61
57 62
58private slots: 63private slots: