summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-06 15:35:17 (UTC)
committer alwin <alwin>2004-04-06 15:35:17 (UTC)
commit9273c064f2ae699885ddef32155df4f5aab9d574 (patch) (unidiff)
tree72bb117b9ca1888215a47edfb6ec3355309261bd
parent6821faed5fd1db0861dff48a5660a3336211b3be (diff)
downloadopie-9273c064f2ae699885ddef32155df4f5aab9d574.zip
opie-9273c064f2ae699885ddef32155df4f5aab9d574.tar.gz
opie-9273c064f2ae699885ddef32155df4f5aab9d574.tar.bz2
saves the last loaded image name so will somewhat faster
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,233 +1,238 @@
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) {
90 return; 95 return;
91 } 96 }
92 double hs = (double)h / (double)_image_data.height() ; 97 double hs = (double)h / (double)_image_data.height() ;
93 double ws = (double)w / (double)_image_data.width() ; 98 double ws = (double)w / (double)_image_data.width() ;
94 double scaleFactor = (hs > ws) ? ws : hs; 99 double scaleFactor = (hs > ws) ? ws : hs;
95 int smoothW = (int)(scaleFactor * _image_data.width()); 100 int smoothW = (int)(scaleFactor * _image_data.width());
96 int smoothH = (int)(scaleFactor * _image_data.height()); 101 int smoothH = (int)(scaleFactor * _image_data.height());
97 _image_data = _image_data.smoothScale(smoothW,smoothH); 102 _image_data = _image_data.smoothScale(smoothW,smoothH);
98} 103}
99 104
100void ImageScrollView::rotate_into_data(Rotation r) 105void ImageScrollView::rotate_into_data(Rotation r)
101{ 106{
102 /* realy - we must do this that way, 'cause when acting direct on _image_data the app will 107 /* realy - we must do this that way, 'cause when acting direct on _image_data the app will
103 segfault :( */ 108 segfault :( */
104 QImage dest; 109 QImage dest;
105 int x, y; 110 int x, y;
106 if ( _original_data.depth() > 8 ) 111 if ( _original_data.depth() > 8 )
107 { 112 {
108 unsigned int *srcData, *destData; 113 unsigned int *srcData, *destData;
109 switch ( r ) 114 switch ( r )
110 { 115 {
111 case Rotate90: 116 case Rotate90:
112 dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); 117 dest.create(_original_data.height(), _original_data.width(), _original_data.depth());
113 for ( y=0; y < _original_data.height(); ++y ) 118 for ( y=0; y < _original_data.height(); ++y )
114 { 119 {
115 srcData = (unsigned int *)_original_data.scanLine(y); 120 srcData = (unsigned int *)_original_data.scanLine(y);
116 for ( x=0; x < _original_data.width(); ++x ) 121 for ( x=0; x < _original_data.width(); ++x )
117 { 122 {
118 destData = (unsigned int *)dest.scanLine(x); 123 destData = (unsigned int *)dest.scanLine(x);
119 destData[_original_data.height()-y-1] = srcData[x]; 124 destData[_original_data.height()-y-1] = srcData[x];
120 } 125 }
121 } 126 }
122 break; 127 break;
123 case Rotate180: 128 case Rotate180:
124 dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); 129 dest.create(_original_data.width(), _original_data.height(), _original_data.depth());
125 for ( y=0; y < _original_data.height(); ++y ) 130 for ( y=0; y < _original_data.height(); ++y )
126 { 131 {
127 srcData = (unsigned int *)_original_data.scanLine(y); 132 srcData = (unsigned int *)_original_data.scanLine(y);
128 destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); 133 destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1);
129 for ( x=0; x < _original_data.width(); ++x ) 134 for ( x=0; x < _original_data.width(); ++x )
130 destData[_original_data.width()-x-1] = srcData[x]; 135 destData[_original_data.width()-x-1] = srcData[x];
131 } 136 }
132 break; 137 break;
133 case Rotate270: 138 case Rotate270:
134 dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); 139 dest.create(_original_data.height(), _original_data.width(), _original_data.depth());
135 for ( y=0; y < _original_data.height(); ++y ) 140 for ( y=0; y < _original_data.height(); ++y )
136 { 141 {
137 srcData = (unsigned int *)_original_data.scanLine(y); 142 srcData = (unsigned int *)_original_data.scanLine(y);
138 for ( x=0; x < _original_data.width(); ++x ) 143 for ( x=0; x < _original_data.width(); ++x )
139 { 144 {
140 destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); 145 destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1);
141 destData[y] = srcData[x]; 146 destData[y] = srcData[x];
142 } 147 }
143 } 148 }
144 break; 149 break;
145 default: 150 default:
146 dest = _original_data; 151 dest = _original_data;
147 break; 152 break;
148 } 153 }
149 } 154 }
150 else 155 else
151 { 156 {
152 unsigned char *srcData, *destData; 157 unsigned char *srcData, *destData;
153 unsigned int *srcTable, *destTable; 158 unsigned int *srcTable, *destTable;
154 switch ( r ) 159 switch ( r )
155 { 160 {
156 case Rotate90: 161 case Rotate90:
157 dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); 162 dest.create(_original_data.height(), _original_data.width(), _original_data.depth());
158 dest.setNumColors(_original_data.numColors()); 163 dest.setNumColors(_original_data.numColors());
159 srcTable = (unsigned int *)_original_data.colorTable(); 164 srcTable = (unsigned int *)_original_data.colorTable();
160 destTable = (unsigned int *)dest.colorTable(); 165 destTable = (unsigned int *)dest.colorTable();
161 for ( x=0; x < _original_data.numColors(); ++x ) 166 for ( x=0; x < _original_data.numColors(); ++x )
162 destTable[x] = srcTable[x]; 167 destTable[x] = srcTable[x];
163 for ( y=0; y < _original_data.height(); ++y ) 168 for ( y=0; y < _original_data.height(); ++y )
164 { 169 {
165 srcData = (unsigned char *)_original_data.scanLine(y); 170 srcData = (unsigned char *)_original_data.scanLine(y);
166 for ( x=0; x < _original_data.width(); ++x ) 171 for ( x=0; x < _original_data.width(); ++x )
167 { 172 {
168 destData = (unsigned char *)dest.scanLine(x); 173 destData = (unsigned char *)dest.scanLine(x);
169 destData[_original_data.height()-y-1] = srcData[x]; 174 destData[_original_data.height()-y-1] = srcData[x];
170 } 175 }
171 } 176 }
172 break; 177 break;
173 case Rotate180: 178 case Rotate180:
174 dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); 179 dest.create(_original_data.width(), _original_data.height(), _original_data.depth());
175 dest.setNumColors(_original_data.numColors()); 180 dest.setNumColors(_original_data.numColors());
176 srcTable = (unsigned int *)_original_data.colorTable(); 181 srcTable = (unsigned int *)_original_data.colorTable();
177 destTable = (unsigned int *)dest.colorTable(); 182 destTable = (unsigned int *)dest.colorTable();
178 for ( x=0; x < _original_data.numColors(); ++x ) 183 for ( x=0; x < _original_data.numColors(); ++x )
179 destTable[x] = srcTable[x]; 184 destTable[x] = srcTable[x];
180 for ( y=0; y < _original_data.height(); ++y ) 185 for ( y=0; y < _original_data.height(); ++y )
181 { 186 {
182 srcData = (unsigned char *)_original_data.scanLine(y); 187 srcData = (unsigned char *)_original_data.scanLine(y);
183 destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); 188 destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1);
184 for ( x=0; x < _original_data.width(); ++x ) 189 for ( x=0; x < _original_data.width(); ++x )
185 destData[_original_data.width()-x-1] = srcData[x]; 190 destData[_original_data.width()-x-1] = srcData[x];
186 } 191 }
187 break; 192 break;
188 case Rotate270: 193 case Rotate270:
189 dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); 194 dest.create(_original_data.height(), _original_data.width(), _original_data.depth());
190 dest.setNumColors(_original_data.numColors()); 195 dest.setNumColors(_original_data.numColors());
191 srcTable = (unsigned int *)_original_data.colorTable(); 196 srcTable = (unsigned int *)_original_data.colorTable();
192 destTable = (unsigned int *)dest.colorTable(); 197 destTable = (unsigned int *)dest.colorTable();
193 for ( x=0; x < _original_data.numColors(); ++x ) 198 for ( x=0; x < _original_data.numColors(); ++x )
194 destTable[x] = srcTable[x]; 199 destTable[x] = srcTable[x];
195 for ( y=0; y < _original_data.height(); ++y ) 200 for ( y=0; y < _original_data.height(); ++y )
196 { 201 {
197 srcData = (unsigned char *)_original_data.scanLine(y); 202 srcData = (unsigned char *)_original_data.scanLine(y);
198 for ( x=0; x < _original_data.width(); ++x ) 203 for ( x=0; x < _original_data.width(); ++x )
199 { 204 {
200 destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); 205 destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1);
201 destData[y] = srcData[x]; 206 destData[y] = srcData[x];
202 } 207 }
203 } 208 }
204 break; 209 break;
205 default: 210 default:
206 dest = _original_data; 211 dest = _original_data;
207 break; 212 break;
208 } 213 }
209 214
210 } 215 }
211 _image_data = dest; 216 _image_data = dest;
212} 217}
213 218
214void ImageScrollView::generateImage() 219void ImageScrollView::generateImage()
215{ 220{
216 Rotation r = Rotate0; 221 Rotation r = Rotate0;
217 if (width()>height()&&_original_data.width()<_original_data.height() || 222 if (width()>height()&&_original_data.width()<_original_data.height() ||
218 width()<height()&&_original_data.width()>_original_data.height()) { 223 width()<height()&&_original_data.width()>_original_data.height()) {
219 if (rotate_to_fit) r = Rotate90; 224 if (rotate_to_fit) r = Rotate90;
220 } 225 }
221 odebug << " r = " << r << oendl; 226 odebug << " r = " << r << oendl;
222 if (scale_to_fit) { 227 if (scale_to_fit) {
223 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { 228 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) {
224 odebug << "Rescaling data" << oendl; 229 odebug << "Rescaling data" << oendl;
225 if (r==Rotate0) { 230 if (r==Rotate0) {
226 _image_data = _original_data; 231 _image_data = _original_data;
227 } else { 232 } else {
228 rotate_into_data(r); 233 rotate_into_data(r);
229 } 234 }
230 } 235 }
231 rescaleImage(width(),height()); 236 rescaleImage(width(),height());
232 resizeContents(_image_data.width(),_image_data.height()); 237 resizeContents(_image_data.width(),_image_data.height());
233 } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { 238 } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) {
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
@@ -1,72 +1,72 @@
1#ifndef _IMAGE_SCROLL_VIEW_H 1#ifndef _IMAGE_SCROLL_VIEW_H
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