-rw-r--r-- | libopie2/opiemm/oimagescrollview.cpp | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/libopie2/opiemm/oimagescrollview.cpp b/libopie2/opiemm/oimagescrollview.cpp index 68b06af..30a8fba 100644 --- a/libopie2/opiemm/oimagescrollview.cpp +++ b/libopie2/opiemm/oimagescrollview.cpp | |||
@@ -3,242 +3,244 @@ | |||
3 | #include <opie2/oimagezoomer.h> | 3 | #include <opie2/oimagezoomer.h> |
4 | #include <opie2/odebug.h> | 4 | #include <opie2/odebug.h> |
5 | #include <opie2/oapplication.h> | 5 | #include <opie2/oapplication.h> |
6 | #include <opie2/owait.h> | 6 | #include <opie2/owait.h> |
7 | 7 | ||
8 | #include <qimage.h> | 8 | #include <qimage.h> |
9 | #include <qlayout.h> | 9 | #include <qlayout.h> |
10 | #include <qpe/qcopenvelope_qws.h> | 10 | #include <qpe/qcopenvelope_qws.h> |
11 | 11 | ||
12 | /* for usage with the bitset */ | 12 | /* for usage with the bitset */ |
13 | #define AUTO_SCALE 0 | 13 | #define AUTO_SCALE 0 |
14 | #define AUTO_ROTATE 1 | 14 | #define AUTO_ROTATE 1 |
15 | #define SHOW_ZOOMER 2 | 15 | #define SHOW_ZOOMER 2 |
16 | #define FIRST_RESIZE_DONE 3 | 16 | #define FIRST_RESIZE_DONE 3 |
17 | #define IMAGE_IS_JPEG 4 | 17 | #define IMAGE_IS_JPEG 4 |
18 | #define IMAGE_SCALED_LOADED 5 | 18 | #define IMAGE_SCALED_LOADED 5 |
19 | 19 | ||
20 | #define SCROLLVIEW_BITSET_SIZE 6 | 20 | #define SCROLLVIEW_BITSET_SIZE 6 |
21 | 21 | ||
22 | namespace Opie { | 22 | namespace Opie { |
23 | namespace MM { | 23 | namespace MM { |
24 | OImageScrollView::OImageScrollView( QWidget* parent, const char* name, WFlags f ) | 24 | OImageScrollView::OImageScrollView( QWidget* parent, const char* name, WFlags f ) |
25 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(), | 25 | :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(), |
26 | m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") | 26 | m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") |
27 | { | 27 | { |
28 | _zoomer = 0; | 28 | _zoomer = 0; |
29 | m_states[AUTO_SCALE]=true; | 29 | m_states[AUTO_SCALE]=true; |
30 | m_states[AUTO_ROTATE]=true; | 30 | m_states[AUTO_ROTATE]=true; |
31 | m_states[FIRST_RESIZE_DONE]=false; | 31 | m_states[FIRST_RESIZE_DONE]=false; |
32 | m_states[IMAGE_IS_JPEG]=false; | 32 | m_states[IMAGE_IS_JPEG]=false; |
33 | m_states[IMAGE_SCALED_LOADED]=false; | 33 | m_states[IMAGE_SCALED_LOADED]=false; |
34 | m_states[SHOW_ZOOMER]=true; | 34 | m_states[SHOW_ZOOMER]=true; |
35 | init(); | 35 | init(); |
36 | } | 36 | } |
37 | 37 | ||
38 | OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 38 | OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
39 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img), | 39 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img), |
40 | m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") | 40 | m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") |
41 | { | 41 | { |
42 | _zoomer = 0; | 42 | _zoomer = 0; |
43 | m_states[AUTO_SCALE]=always_scale; | 43 | m_states[AUTO_SCALE]=always_scale; |
44 | m_states[AUTO_ROTATE]=rfit; | 44 | m_states[AUTO_ROTATE]=rfit; |
45 | m_states[FIRST_RESIZE_DONE]=false; | 45 | m_states[FIRST_RESIZE_DONE]=false; |
46 | m_states[IMAGE_IS_JPEG]=false; | 46 | m_states[IMAGE_IS_JPEG]=false; |
47 | m_states[IMAGE_SCALED_LOADED]=false; | 47 | m_states[IMAGE_SCALED_LOADED]=false; |
48 | m_states[SHOW_ZOOMER]=true; | 48 | m_states[SHOW_ZOOMER]=true; |
49 | _original_data.convertDepth(QPixmap::defaultDepth()); | 49 | _original_data.convertDepth(QPixmap::defaultDepth()); |
50 | _original_data.setAlphaBuffer(false); | 50 | _original_data.setAlphaBuffer(false); |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) | 54 | OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) |
55 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") | 55 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("") |
56 | { | 56 | { |
57 | _zoomer = 0; | 57 | _zoomer = 0; |
58 | m_states.resize(SCROLLVIEW_BITSET_SIZE); | 58 | m_states.resize(SCROLLVIEW_BITSET_SIZE); |
59 | m_states[AUTO_SCALE]=always_scale; | 59 | m_states[AUTO_SCALE]=always_scale; |
60 | m_states[AUTO_ROTATE]=rfit; | 60 | m_states[AUTO_ROTATE]=rfit; |
61 | m_states[FIRST_RESIZE_DONE]=false; | 61 | m_states[FIRST_RESIZE_DONE]=false; |
62 | m_states[IMAGE_IS_JPEG]=false; | 62 | m_states[IMAGE_IS_JPEG]=false; |
63 | m_states[IMAGE_SCALED_LOADED]=false; | 63 | m_states[IMAGE_SCALED_LOADED]=false; |
64 | m_states[SHOW_ZOOMER]=true; | 64 | m_states[SHOW_ZOOMER]=true; |
65 | init(); | 65 | init(); |
66 | setImage(img); | 66 | setImage(img); |
67 | } | 67 | } |
68 | 68 | ||
69 | void OImageScrollView::setImage(const QImage&img) | 69 | void OImageScrollView::setImage(const QImage&img) |
70 | { | 70 | { |
71 | _image_data = QImage(); | 71 | _image_data = QImage(); |
72 | _original_data=img; | 72 | _original_data=img; |
73 | _original_data.convertDepth(QPixmap::defaultDepth()); | 73 | _original_data.convertDepth(QPixmap::defaultDepth()); |
74 | _original_data.setAlphaBuffer(false); | 74 | _original_data.setAlphaBuffer(false); |
75 | m_lastName = ""; | 75 | m_lastName = ""; |
76 | setImageIsJpeg(false); | 76 | setImageIsJpeg(false); |
77 | setImageScaledLoaded(false); | 77 | setImageScaledLoaded(false); |
78 | if (FirstResizeDone()) { | 78 | if (FirstResizeDone()) { |
79 | generateImage(); | 79 | generateImage(); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | void OImageScrollView::loadJpeg(bool interncall) | 83 | void OImageScrollView::loadJpeg(bool interncall) |
84 | { | 84 | { |
85 | if (m_lastName.isEmpty()) return; | 85 | if (m_lastName.isEmpty()) return; |
86 | QImageIO iio( m_lastName, 0l ); | 86 | QImageIO iio( m_lastName, 0l ); |
87 | QString param; | 87 | QString param; |
88 | bool real_load = false; | 88 | bool real_load = false; |
89 | if (AutoScale()) { | 89 | if (AutoScale()) { |
90 | if (!interncall) { | 90 | if (!interncall) { |
91 | int wid, hei; | 91 | int wid, hei; |
92 | wid = QApplication::desktop()->width(); | 92 | wid = QApplication::desktop()->width(); |
93 | hei = QApplication::desktop()->height(); | 93 | hei = QApplication::desktop()->height(); |
94 | if (hei>wid) { | 94 | if (hei>wid) { |
95 | wid = hei; | 95 | wid = hei; |
96 | } else { | 96 | } else { |
97 | hei = wid; | 97 | hei = wid; |
98 | } | 98 | } |
99 | param = QString( "Fast Shrink( 3 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei ); | 99 | param = QString( "Fast Shrink( 3 ) Scale( %1, %2, ScaleMin)" ).arg( wid ).arg( hei ); |
100 | odebug << "Load jpeg scaled \"" << param << "\"" << oendl; | 100 | odebug << "Load jpeg scaled \"" << param << "\"" << oendl; |
101 | iio.setParameters(param.latin1()); | 101 | iio.setParameters(param.latin1()); |
102 | setImageScaledLoaded(true); | 102 | setImageScaledLoaded(true); |
103 | real_load = true; | 103 | real_load = true; |
104 | } | 104 | } |
105 | } else { | 105 | } else { |
106 | if (ImageScaledLoaded()||!interncall) { | 106 | if (ImageScaledLoaded()||!interncall) { |
107 | odebug << "Load jpeg unscaled" << oendl; | 107 | odebug << "Load jpeg unscaled" << oendl; |
108 | real_load = true; | 108 | real_load = true; |
109 | } | 109 | } |
110 | setImageScaledLoaded(false); | 110 | setImageScaledLoaded(false); |
111 | } | 111 | } |
112 | if (real_load) { | 112 | if (real_load) { |
113 | { | 113 | { |
114 | QCopEnvelope( "QPE/System", "busy()" ); | 114 | QCopEnvelope( "QPE/System", "busy()" ); |
115 | } | 115 | } |
116 | _original_data = iio.read() ? iio.image() : QImage(); | 116 | _original_data = iio.read() ? iio.image() : QImage(); |
117 | { | 117 | { |
118 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | 118 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); |
119 | env << "Image loaded"; | 119 | env << "Image loaded"; |
120 | } | 120 | } |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
124 | void OImageScrollView::setImage( const QString& path ) { | 124 | void OImageScrollView::setImage( const QString& path ) { |
125 | odebug << "load new image " << oendl; | 125 | odebug << "load new image " << oendl; |
126 | if (m_lastName == path) return; | 126 | if (m_lastName == path) return; |
127 | m_lastName = path; | 127 | m_lastName = path; |
128 | _original_data = QImage(); | ||
128 | QString itype = QImage::imageFormat(m_lastName); | 129 | QString itype = QImage::imageFormat(m_lastName); |
129 | odebug << "Image type = " << itype << oendl; | 130 | odebug << "Image type = " << itype << oendl; |
130 | if (itype == "JPEG") { | 131 | if (itype == "JPEG") { |
131 | setImageIsJpeg(true); | 132 | setImageIsJpeg(true); |
132 | loadJpeg(); | 133 | loadJpeg(); |
133 | } else { | 134 | } else { |
134 | { | 135 | { |
135 | QCopEnvelope( "QPE/System", "busy()" ); | 136 | QCopEnvelope( "QPE/System", "busy()" ); |
136 | } | 137 | } |
137 | setImageIsJpeg(false); | 138 | setImageIsJpeg(false); |
138 | _original_data.load(path); | 139 | _original_data.load(path); |
139 | _original_data.convertDepth(QPixmap::defaultDepth()); | 140 | _original_data.convertDepth(QPixmap::defaultDepth()); |
140 | _original_data.setAlphaBuffer(false); | 141 | _original_data.setAlphaBuffer(false); |
141 | { | 142 | { |
142 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | 143 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); |
143 | env << "Image loaded"; | 144 | env << "Image loaded"; |
144 | } | 145 | } |
145 | } | 146 | } |
146 | _image_data = QImage(); | 147 | _image_data = QImage(); |
147 | if (FirstResizeDone()) { | 148 | if (FirstResizeDone()) { |
148 | generateImage(); | 149 | generateImage(); |
150 | if (isVisible()) viewport()->repaint(true); | ||
149 | } | 151 | } |
150 | } | 152 | } |
151 | 153 | ||
152 | /* should be called every time the QImage changed it content */ | 154 | /* should be called every time the QImage changed it content */ |
153 | void OImageScrollView::init() | 155 | void OImageScrollView::init() |
154 | { | 156 | { |
155 | odebug << "init " << oendl; | 157 | odebug << "init " << oendl; |
156 | 158 | ||
157 | /* | 159 | /* |
158 | * create the zoomer | 160 | * create the zoomer |
159 | * and connect ther various signals | 161 | * and connect ther various signals |
160 | */ | 162 | */ |
161 | _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); | 163 | _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); |
162 | connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), | 164 | connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), |
163 | this, SLOT(scrollBy(int,int)) ); | 165 | this, SLOT(scrollBy(int,int)) ); |
164 | connect(_zoomer, SIGNAL( zoomArea(int,int)), | 166 | connect(_zoomer, SIGNAL( zoomArea(int,int)), |
165 | this, SLOT(center(int,int)) ); | 167 | this, SLOT(center(int,int)) ); |
166 | connect(this,SIGNAL(contentsMoving(int,int)), | 168 | connect(this,SIGNAL(contentsMoving(int,int)), |
167 | _zoomer, (SLOT(setVisiblePoint(int,int))) ); | 169 | _zoomer, (SLOT(setVisiblePoint(int,int))) ); |
168 | connect(this,SIGNAL(imageSizeChanged(const QSize&)), | 170 | connect(this,SIGNAL(imageSizeChanged(const QSize&)), |
169 | _zoomer, SLOT(setImageSize(const QSize&)) ); | 171 | _zoomer, SLOT(setImageSize(const QSize&)) ); |
170 | connect(this,SIGNAL(viewportSizeChanged(const QSize&)), | 172 | connect(this,SIGNAL(viewportSizeChanged(const QSize&)), |
171 | _zoomer, SLOT(setViewPortSize(const QSize&)) ); | 173 | _zoomer, SLOT(setViewPortSize(const QSize&)) ); |
172 | 174 | ||
173 | viewport()->setBackgroundColor(white); | 175 | viewport()->setBackgroundColor(white); |
174 | setFocusPolicy(QWidget::StrongFocus); | 176 | setFocusPolicy(QWidget::StrongFocus); |
175 | setImageScaledLoaded(false); | 177 | setImageScaledLoaded(false); |
176 | setImageIsJpeg(false); | 178 | setImageIsJpeg(false); |
177 | if (FirstResizeDone()) { | 179 | if (FirstResizeDone()) { |
178 | m_last_rot = Rotate0; | 180 | m_last_rot = Rotate0; |
179 | generateImage(); | 181 | generateImage(); |
180 | } else if (_original_data.size().isValid()) { | 182 | } else if (_original_data.size().isValid()) { |
181 | if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide(); | 183 | if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide(); |
182 | resizeContents(_original_data.width(),_original_data.height()); | 184 | resizeContents(_original_data.width(),_original_data.height()); |
183 | } | 185 | } |
184 | } | 186 | } |
185 | 187 | ||
186 | void OImageScrollView::setAutoRotate(bool how) | 188 | void OImageScrollView::setAutoRotate(bool how) |
187 | { | 189 | { |
188 | /* to avoid double repaints */ | 190 | /* to avoid double repaints */ |
189 | if (AutoRotate() != how) { | 191 | if (AutoRotate() != how) { |
190 | m_states.setBit(AUTO_ROTATE,how); | 192 | m_states.setBit(AUTO_ROTATE,how); |
191 | _image_data = QImage(); | 193 | _image_data = QImage(); |
192 | generateImage(); | 194 | generateImage(); |
193 | } | 195 | } |
194 | } | 196 | } |
195 | 197 | ||
196 | bool OImageScrollView::AutoRotate()const | 198 | bool OImageScrollView::AutoRotate()const |
197 | { | 199 | { |
198 | return m_states.testBit(AUTO_ROTATE); | 200 | return m_states.testBit(AUTO_ROTATE); |
199 | } | 201 | } |
200 | 202 | ||
201 | void OImageScrollView::setAutoScale(bool how) | 203 | void OImageScrollView::setAutoScale(bool how) |
202 | { | 204 | { |
203 | m_states.setBit(AUTO_SCALE,how); | 205 | m_states.setBit(AUTO_SCALE,how); |
204 | if (!how) { | 206 | if (!how) { |
205 | setAutoRotate(false); | 207 | setAutoRotate(false); |
206 | } | 208 | } |
207 | _image_data = QImage(); | 209 | _image_data = QImage(); |
208 | if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) { | 210 | if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) { |
209 | loadJpeg(true); | 211 | loadJpeg(true); |
210 | } | 212 | } |
211 | generateImage(); | 213 | generateImage(); |
212 | } | 214 | } |
213 | 215 | ||
214 | bool OImageScrollView::AutoScale()const | 216 | bool OImageScrollView::AutoScale()const |
215 | { | 217 | { |
216 | return m_states.testBit(AUTO_SCALE); | 218 | return m_states.testBit(AUTO_SCALE); |
217 | } | 219 | } |
218 | 220 | ||
219 | OImageScrollView::~OImageScrollView() | 221 | OImageScrollView::~OImageScrollView() |
220 | { | 222 | { |
221 | } | 223 | } |
222 | 224 | ||
223 | void OImageScrollView::rescaleImage(int w, int h) | 225 | void OImageScrollView::rescaleImage(int w, int h) |
224 | { | 226 | { |
225 | if (_image_data.width()==w && _image_data.height()==h) { | 227 | if (_image_data.width()==w && _image_data.height()==h) { |
226 | return; | 228 | return; |
227 | } | 229 | } |
228 | double hs = (double)h / (double)_image_data.height() ; | 230 | double hs = (double)h / (double)_image_data.height() ; |
229 | double ws = (double)w / (double)_image_data.width() ; | 231 | double ws = (double)w / (double)_image_data.width() ; |
230 | double scaleFactor = (hs > ws) ? ws : hs; | 232 | double scaleFactor = (hs > ws) ? ws : hs; |
231 | int smoothW = (int)(scaleFactor * _image_data.width()); | 233 | int smoothW = (int)(scaleFactor * _image_data.width()); |
232 | int smoothH = (int)(scaleFactor * _image_data.height()); | 234 | int smoothH = (int)(scaleFactor * _image_data.height()); |
233 | _image_data = _image_data.smoothScale(smoothW,smoothH); | 235 | _image_data = _image_data.smoothScale(smoothW,smoothH); |
234 | } | 236 | } |
235 | 237 | ||
236 | void OImageScrollView::rotate_into_data(Rotation r) | 238 | void OImageScrollView::rotate_into_data(Rotation r) |
237 | { | 239 | { |
238 | /* realy - we must do this that way, 'cause when acting direct on _image_data the app will | 240 | /* realy - we must do this that way, 'cause when acting direct on _image_data the app will |
239 | segfault :( */ | 241 | segfault :( */ |
240 | QImage dest; | 242 | QImage dest; |
241 | int x, y; | 243 | int x, y; |
242 | if ( _original_data.depth() > 8 ) | 244 | if ( _original_data.depth() > 8 ) |
243 | { | 245 | { |
244 | unsigned int *srcData, *destData; | 246 | unsigned int *srcData, *destData; |
@@ -257,329 +259,319 @@ void OImageScrollView::rotate_into_data(Rotation r) | |||
257 | } | 259 | } |
258 | break; | 260 | break; |
259 | case Rotate180: | 261 | case Rotate180: |
260 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 262 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
261 | for ( y=0; y < _original_data.height(); ++y ) | 263 | for ( y=0; y < _original_data.height(); ++y ) |
262 | { | 264 | { |
263 | srcData = (unsigned int *)_original_data.scanLine(y); | 265 | srcData = (unsigned int *)_original_data.scanLine(y); |
264 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); | 266 | destData = (unsigned int *)dest.scanLine(_original_data.height()-y-1); |
265 | for ( x=0; x < _original_data.width(); ++x ) | 267 | for ( x=0; x < _original_data.width(); ++x ) |
266 | destData[_original_data.width()-x-1] = srcData[x]; | 268 | destData[_original_data.width()-x-1] = srcData[x]; |
267 | } | 269 | } |
268 | break; | 270 | break; |
269 | case Rotate270: | 271 | case Rotate270: |
270 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 272 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
271 | for ( y=0; y < _original_data.height(); ++y ) | 273 | for ( y=0; y < _original_data.height(); ++y ) |
272 | { | 274 | { |
273 | srcData = (unsigned int *)_original_data.scanLine(y); | 275 | srcData = (unsigned int *)_original_data.scanLine(y); |
274 | for ( x=0; x < _original_data.width(); ++x ) | 276 | for ( x=0; x < _original_data.width(); ++x ) |
275 | { | 277 | { |
276 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); | 278 | destData = (unsigned int *)dest.scanLine(_original_data.width()-x-1); |
277 | destData[y] = srcData[x]; | 279 | destData[y] = srcData[x]; |
278 | } | 280 | } |
279 | } | 281 | } |
280 | break; | 282 | break; |
281 | default: | 283 | default: |
282 | dest = _original_data; | 284 | dest = _original_data; |
283 | break; | 285 | break; |
284 | } | 286 | } |
285 | } | 287 | } |
286 | else | 288 | else |
287 | { | 289 | { |
288 | unsigned char *srcData, *destData; | 290 | unsigned char *srcData, *destData; |
289 | unsigned int *srcTable, *destTable; | 291 | unsigned int *srcTable, *destTable; |
290 | switch ( r ) | 292 | switch ( r ) |
291 | { | 293 | { |
292 | case Rotate90: | 294 | case Rotate90: |
293 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 295 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
294 | dest.setNumColors(_original_data.numColors()); | 296 | dest.setNumColors(_original_data.numColors()); |
295 | srcTable = (unsigned int *)_original_data.colorTable(); | 297 | srcTable = (unsigned int *)_original_data.colorTable(); |
296 | destTable = (unsigned int *)dest.colorTable(); | 298 | destTable = (unsigned int *)dest.colorTable(); |
297 | for ( x=0; x < _original_data.numColors(); ++x ) | 299 | for ( x=0; x < _original_data.numColors(); ++x ) |
298 | destTable[x] = srcTable[x]; | 300 | destTable[x] = srcTable[x]; |
299 | for ( y=0; y < _original_data.height(); ++y ) | 301 | for ( y=0; y < _original_data.height(); ++y ) |
300 | { | 302 | { |
301 | srcData = (unsigned char *)_original_data.scanLine(y); | 303 | srcData = (unsigned char *)_original_data.scanLine(y); |
302 | for ( x=0; x < _original_data.width(); ++x ) | 304 | for ( x=0; x < _original_data.width(); ++x ) |
303 | { | 305 | { |
304 | destData = (unsigned char *)dest.scanLine(x); | 306 | destData = (unsigned char *)dest.scanLine(x); |
305 | destData[_original_data.height()-y-1] = srcData[x]; | 307 | destData[_original_data.height()-y-1] = srcData[x]; |
306 | } | 308 | } |
307 | } | 309 | } |
308 | break; | 310 | break; |
309 | case Rotate180: | 311 | case Rotate180: |
310 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); | 312 | dest.create(_original_data.width(), _original_data.height(), _original_data.depth()); |
311 | dest.setNumColors(_original_data.numColors()); | 313 | dest.setNumColors(_original_data.numColors()); |
312 | srcTable = (unsigned int *)_original_data.colorTable(); | 314 | srcTable = (unsigned int *)_original_data.colorTable(); |
313 | destTable = (unsigned int *)dest.colorTable(); | 315 | destTable = (unsigned int *)dest.colorTable(); |
314 | for ( x=0; x < _original_data.numColors(); ++x ) | 316 | for ( x=0; x < _original_data.numColors(); ++x ) |
315 | destTable[x] = srcTable[x]; | 317 | destTable[x] = srcTable[x]; |
316 | for ( y=0; y < _original_data.height(); ++y ) | 318 | for ( y=0; y < _original_data.height(); ++y ) |
317 | { | 319 | { |
318 | srcData = (unsigned char *)_original_data.scanLine(y); | 320 | srcData = (unsigned char *)_original_data.scanLine(y); |
319 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); | 321 | destData = (unsigned char *)dest.scanLine(_original_data.height()-y-1); |
320 | for ( x=0; x < _original_data.width(); ++x ) | 322 | for ( x=0; x < _original_data.width(); ++x ) |
321 | destData[_original_data.width()-x-1] = srcData[x]; | 323 | destData[_original_data.width()-x-1] = srcData[x]; |
322 | } | 324 | } |
323 | break; | 325 | break; |
324 | case Rotate270: | 326 | case Rotate270: |
325 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); | 327 | dest.create(_original_data.height(), _original_data.width(), _original_data.depth()); |
326 | dest.setNumColors(_original_data.numColors()); | 328 | dest.setNumColors(_original_data.numColors()); |
327 | srcTable = (unsigned int *)_original_data.colorTable(); | 329 | srcTable = (unsigned int *)_original_data.colorTable(); |
328 | destTable = (unsigned int *)dest.colorTable(); | 330 | destTable = (unsigned int *)dest.colorTable(); |
329 | for ( x=0; x < _original_data.numColors(); ++x ) | 331 | for ( x=0; x < _original_data.numColors(); ++x ) |
330 | destTable[x] = srcTable[x]; | 332 | destTable[x] = srcTable[x]; |
331 | for ( y=0; y < _original_data.height(); ++y ) | 333 | for ( y=0; y < _original_data.height(); ++y ) |
332 | { | 334 | { |
333 | srcData = (unsigned char *)_original_data.scanLine(y); | 335 | srcData = (unsigned char *)_original_data.scanLine(y); |
334 | for ( x=0; x < _original_data.width(); ++x ) | 336 | for ( x=0; x < _original_data.width(); ++x ) |
335 | { | 337 | { |
336 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); | 338 | destData = (unsigned char *)dest.scanLine(_original_data.width()-x-1); |
337 | destData[y] = srcData[x]; | 339 | destData[y] = srcData[x]; |
338 | } | 340 | } |
339 | } | 341 | } |
340 | break; | 342 | break; |
341 | default: | 343 | default: |
342 | dest = _original_data; | 344 | dest = _original_data; |
343 | break; | 345 | break; |
344 | } | 346 | } |
345 | 347 | ||
346 | } | 348 | } |
347 | _image_data = dest; | 349 | _image_data = dest; |
348 | } | 350 | } |
349 | 351 | ||
350 | void OImageScrollView::generateImage() | 352 | void OImageScrollView::generateImage() |
351 | { | 353 | { |
352 | Rotation r = Rotate0; | 354 | Rotation r = Rotate0; |
353 | if (_original_data.isNull()) return; | 355 | _pdata = QPixmap(); |
356 | if (_original_data.isNull()) { | ||
357 | emit imageSizeChanged( _image_data.size() ); | ||
358 | if (_zoomer) _zoomer->setImage( _image_data ); | ||
359 | return; | ||
360 | } | ||
354 | { | 361 | { |
355 | QCopEnvelope( "QPE/System", "busy()" ); | 362 | QCopEnvelope( "QPE/System", "busy()" ); |
356 | } | 363 | } |
357 | if (width()>height()&&_original_data.width()<_original_data.height() || | 364 | if (width()>height()&&_original_data.width()<_original_data.height() || |
358 | width()<height()&&_original_data.width()>_original_data.height()) { | 365 | width()<height()&&_original_data.width()>_original_data.height()) { |
359 | if (AutoRotate()) r = Rotate90; | 366 | if (AutoRotate()) r = Rotate90; |
360 | } | 367 | } |
361 | 368 | ||
369 | |||
362 | odebug << " r = " << r << oendl; | 370 | odebug << " r = " << r << oendl; |
363 | if (AutoScale()) { | 371 | if (AutoScale() && (_original_data.width()>width() || _original_data.height() > height()) ) { |
364 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { | 372 | if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { |
365 | odebug << "Rescaling data" << oendl; | 373 | odebug << "Rescaling data" << oendl; |
366 | if (r==Rotate0) { | 374 | if (r==Rotate0) { |
367 | _image_data = _original_data; | 375 | _image_data = _original_data; |
368 | } else { | 376 | } else { |
369 | rotate_into_data(r); | 377 | rotate_into_data(r); |
370 | } | 378 | } |
371 | } | 379 | } |
372 | rescaleImage(width(),height()); | 380 | rescaleImage(width(),height()); |
373 | resizeContents(_image_data.width(),_image_data.height()); | 381 | resizeContents(_image_data.width(),_image_data.height()); |
374 | } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) { | 382 | } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) { |
375 | if (r==Rotate0) { | 383 | if (r==Rotate0) { |
376 | _image_data = _original_data; | 384 | _image_data = _original_data; |
377 | } else { | 385 | } else { |
378 | rotate_into_data(r); | 386 | rotate_into_data(r); |
379 | } | 387 | } |
380 | m_last_rot = r; | 388 | m_last_rot = r; |
381 | resizeContents(_image_data.width(),_image_data.height()); | 389 | resizeContents(_image_data.width(),_image_data.height()); |
382 | } | 390 | } |
383 | _pdata.convertFromImage(_image_data); | 391 | _pdata.convertFromImage(_image_data); |
384 | 392 | ||
385 | |||
386 | /* | 393 | /* |
387 | * update the zoomer | 394 | * update the zoomer |
388 | */ | 395 | */ |
389 | check_zoomer(); | 396 | check_zoomer(); |
390 | emit imageSizeChanged( _image_data.size() ); | 397 | emit imageSizeChanged( _image_data.size() ); |
391 | rescaleImage( 128, 128 ); | 398 | rescaleImage( 128, 128 ); |
392 | /* | 399 | /* |
393 | * move scrollbar | 400 | * move scrollbar |
394 | */ | 401 | */ |
395 | if (_zoomer) { | 402 | if (_zoomer) { |
396 | _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, | 403 | _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, |
397 | _image_data.width()/2, _image_data.height()/2 ); | 404 | _image_data.width()/2, _image_data.height()/2 ); |
398 | _zoomer->setImage( _image_data ); | 405 | _zoomer->setImage( _image_data ); |
399 | } | 406 | } |
400 | /* | 407 | /* |
401 | * invalidate | 408 | * invalidate |
402 | */ | 409 | */ |
403 | _image_data=QImage(); | 410 | _image_data=QImage(); |
404 | { | 411 | { |
405 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); | 412 | QCopEnvelope env( "QPE/System", "notBusy(QString)" ); |
406 | env << "Image generated"; | 413 | env << "Image generated"; |
407 | } | 414 | } |
408 | } | 415 | } |
409 | 416 | ||
410 | void OImageScrollView::resizeEvent(QResizeEvent * e) | 417 | void OImageScrollView::resizeEvent(QResizeEvent * e) |
411 | { | 418 | { |
412 | odebug << "OImageScrollView resizeEvent" << oendl; | 419 | odebug << "OImageScrollView resizeEvent" << oendl; |
413 | QScrollView::resizeEvent(e); | 420 | QScrollView::resizeEvent(e); |
414 | generateImage(); | 421 | generateImage(); |
415 | setFirstResizeDone(true); | 422 | setFirstResizeDone(true); |
416 | emit viewportSizeChanged( viewport()->size() ); | 423 | emit viewportSizeChanged( viewport()->size() ); |
417 | 424 | ||
418 | } | 425 | } |
419 | 426 | ||
420 | void OImageScrollView::keyPressEvent(QKeyEvent * e) | 427 | void OImageScrollView::keyPressEvent(QKeyEvent * e) |
421 | { | 428 | { |
422 | if (!e) return; | 429 | if (!e) return; |
423 | int dx = horizontalScrollBar()->lineStep(); | 430 | int dx = horizontalScrollBar()->lineStep(); |
424 | int dy = verticalScrollBar()->lineStep(); | 431 | int dy = verticalScrollBar()->lineStep(); |
425 | if (e->key()==Qt::Key_Right) { | 432 | if (e->key()==Qt::Key_Right) { |
426 | scrollBy(dx,0); | 433 | scrollBy(dx,0); |
427 | e->accept(); | 434 | e->accept(); |
428 | } else if (e->key()==Qt::Key_Left) { | 435 | } else if (e->key()==Qt::Key_Left) { |
429 | scrollBy(0-dx,0); | 436 | scrollBy(0-dx,0); |
430 | e->accept(); | 437 | e->accept(); |
431 | } else if (e->key()==Qt::Key_Up) { | 438 | } else if (e->key()==Qt::Key_Up) { |
432 | scrollBy(0,0-dy); | 439 | scrollBy(0,0-dy); |
433 | e->accept(); | 440 | e->accept(); |
434 | } else if (e->key()==Qt::Key_Down) { | 441 | } else if (e->key()==Qt::Key_Down) { |
435 | scrollBy(0,dy); | 442 | scrollBy(0,dy); |
436 | e->accept(); | 443 | e->accept(); |
437 | } else { | 444 | } else { |
438 | e->ignore(); | 445 | e->ignore(); |
439 | } | 446 | } |
440 | QScrollView::keyPressEvent(e); | 447 | QScrollView::keyPressEvent(e); |
441 | } | 448 | } |
442 | 449 | ||
443 | void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | 450 | void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) |
444 | { | 451 | { |
445 | int w = clipw; | 452 | int w = clipw; |
446 | int h = cliph; | 453 | int h = cliph; |
447 | int x = clipx; | 454 | int x = clipx; |
448 | int y = clipy; | 455 | int y = clipy; |
449 | bool erase = false; | 456 | bool erase = false; |
450 | 457 | ||
451 | if (!_pdata.size().isValid()) { | 458 | if (!_pdata.size().isValid()) { |
452 | p->fillRect(clipx,clipy,clipw,cliph,white); | 459 | p->fillRect(clipx,clipy,clipw,cliph,white); |
453 | return; | 460 | return; |
454 | } | 461 | } |
455 | if (w>_pdata.width()) { | 462 | if (w>_pdata.width()) { |
456 | w=_pdata.width(); | 463 | w=_pdata.width(); |
457 | x = 0; | 464 | x = 0; |
458 | erase = true; | 465 | erase = true; |
459 | } else if (x+w>_pdata.width()){ | 466 | } else if (x+w>_pdata.width()){ |
460 | x = _pdata.width()-w; | 467 | x = _pdata.width()-w; |
461 | } | 468 | } |
462 | if (h>_pdata.height()) { | 469 | if (h>_pdata.height()) { |
463 | h=_pdata.height(); | 470 | h=_pdata.height(); |
464 | y = 0; | 471 | y = 0; |
465 | erase = true; | 472 | erase = true; |
466 | } else if (y+h>_pdata.height()){ | 473 | } else if (y+h>_pdata.height()){ |
467 | y = _pdata.height()-h; | 474 | y = _pdata.height()-h; |
468 | } | 475 | } |
469 | if (erase||_original_data.hasAlphaBuffer()) { | 476 | if (erase||_original_data.hasAlphaBuffer()) { |
470 | p->fillRect(clipx,clipy,clipw,cliph,white); | 477 | p->fillRect(clipx,clipy,clipw,cliph,white); |
471 | } | 478 | } |
472 | p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); | 479 | p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); |
473 | } | 480 | } |
474 | 481 | ||
475 | /* using the real geometry points and not the translated points is wanted! */ | 482 | /* using the real geometry points and not the translated points is wanted! */ |
476 | void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | 483 | void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) |
477 | { | 484 | { |
478 | odebug << "Move X and Y " << e->x() << " " << e->y() << oendl; | ||
479 | int mx, my; | 485 | int mx, my; |
480 | mx = e->x(); | 486 | mx = e->x(); |
481 | my = e->y(); | 487 | my = e->y(); |
482 | if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { | 488 | if (_mouseStartPosX!=-1 && _mouseStartPosY!=-1) { |
483 | int diffx = _mouseStartPosX-mx; | 489 | int diffx = _mouseStartPosX-mx; |
484 | int diffy = _mouseStartPosY-my; | 490 | int diffy = _mouseStartPosY-my; |
485 | #if 0 | ||
486 | QScrollBar*xbar = horizontalScrollBar(); | ||
487 | QScrollBar*ybar = verticalScrollBar(); | ||
488 | if (xbar->value()+diffx>xbar->maxValue()) { | ||
489 | diffx = xbar->maxValue()-xbar->value(); | ||
490 | } else if (xbar->value()+diffx<0) { | ||
491 | diffx=0-xbar->value(); | ||
492 | } | ||
493 | if (ybar->value()+diffy>ybar->maxValue()) { | ||
494 | diffy = ybar->maxValue()-ybar->value(); | ||
495 | } else if (ybar->value()+diffy<0) { | ||
496 | diffy=0-ybar->value(); | ||
497 | } | ||
498 | #endif | ||
499 | scrollBy(diffx,diffy); | 491 | scrollBy(diffx,diffy); |
500 | } | 492 | } |
501 | _mouseStartPosX=mx; | 493 | _mouseStartPosX=mx; |
502 | _mouseStartPosY=my; | 494 | _mouseStartPosY=my; |
503 | } | 495 | } |
504 | 496 | ||
505 | void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e) | 497 | void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e) |
506 | { | 498 | { |
507 | odebug << " X and Y " << e->x() << " " << e->y() << oendl; | 499 | odebug << " X and Y " << e->x() << " " << e->y() << oendl; |
508 | /* this marks the beginning of a possible mouse move. Due internal reasons of QT | 500 | /* this marks the beginning of a possible mouse move. Due internal reasons of QT |
509 | the geometry values here may real differ from that set in MoveEvent (I don't know | 501 | the geometry values here may real differ from that set in MoveEvent (I don't know |
510 | why). For getting them in real context, we use the first move-event to set the start | 502 | why). For getting them in real context, we use the first move-event to set the start |
511 | position ;) | 503 | position ;) |
512 | */ | 504 | */ |
513 | _mouseStartPosX = -1; | 505 | _mouseStartPosX = -1; |
514 | _mouseStartPosY = -1; | 506 | _mouseStartPosY = -1; |
515 | } | 507 | } |
516 | 508 | ||
517 | void OImageScrollView::setDestructiveClose() { | 509 | void OImageScrollView::setDestructiveClose() { |
518 | WFlags fl = getWFlags(); | 510 | WFlags fl = getWFlags(); |
519 | /* clear it just in case */ | 511 | /* clear it just in case */ |
520 | fl &= ~WDestructiveClose; | 512 | fl &= ~WDestructiveClose; |
521 | fl |= WDestructiveClose; | 513 | fl |= WDestructiveClose; |
522 | setWFlags( fl ); | 514 | setWFlags( fl ); |
523 | } | 515 | } |
524 | 516 | ||
525 | bool OImageScrollView::image_fit_into(const QSize&s ) | 517 | bool OImageScrollView::image_fit_into(const QSize&s ) |
526 | { | 518 | { |
527 | if (s.width()>width()||s.height()>height()) { | 519 | if (s.width()>width()||s.height()>height()) { |
528 | return false; | 520 | return false; |
529 | } | 521 | } |
530 | return true; | 522 | return true; |
531 | } | 523 | } |
532 | 524 | ||
533 | void OImageScrollView::setShowZoomer(bool how) | 525 | void OImageScrollView::setShowZoomer(bool how) |
534 | { | 526 | { |
535 | m_states.setBit(SHOW_ZOOMER,how); | 527 | m_states.setBit(SHOW_ZOOMER,how); |
536 | check_zoomer(); | 528 | check_zoomer(); |
537 | } | 529 | } |
538 | 530 | ||
539 | bool OImageScrollView::ShowZoomer()const | 531 | bool OImageScrollView::ShowZoomer()const |
540 | { | 532 | { |
541 | return m_states.testBit(SHOW_ZOOMER); | 533 | return m_states.testBit(SHOW_ZOOMER); |
542 | } | 534 | } |
543 | 535 | ||
544 | void OImageScrollView::check_zoomer() | 536 | void OImageScrollView::check_zoomer() |
545 | { | 537 | { |
546 | if (!_zoomer) return; | 538 | if (!_zoomer) return; |
547 | if ( (!ShowZoomer()||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) { | 539 | if ( (!ShowZoomer()||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) { |
548 | _zoomer->hide(); | 540 | _zoomer->hide(); |
549 | } else if ( ShowZoomer() && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){ | 541 | } else if ( ShowZoomer() && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){ |
550 | _zoomer->show(); | 542 | _zoomer->show(); |
551 | } | 543 | } |
552 | } | 544 | } |
553 | 545 | ||
554 | bool OImageScrollView::FirstResizeDone()const | 546 | bool OImageScrollView::FirstResizeDone()const |
555 | { | 547 | { |
556 | return m_states.testBit(FIRST_RESIZE_DONE); | 548 | return m_states.testBit(FIRST_RESIZE_DONE); |
557 | } | 549 | } |
558 | 550 | ||
559 | void OImageScrollView::setFirstResizeDone(bool how) | 551 | void OImageScrollView::setFirstResizeDone(bool how) |
560 | { | 552 | { |
561 | m_states.setBit(FIRST_RESIZE_DONE,how); | 553 | m_states.setBit(FIRST_RESIZE_DONE,how); |
562 | } | 554 | } |
563 | 555 | ||
564 | bool OImageScrollView::ImageIsJpeg()const | 556 | bool OImageScrollView::ImageIsJpeg()const |
565 | { | 557 | { |
566 | return m_states.testBit(IMAGE_IS_JPEG); | 558 | return m_states.testBit(IMAGE_IS_JPEG); |
567 | } | 559 | } |
568 | 560 | ||
569 | void OImageScrollView::setImageIsJpeg(bool how) | 561 | void OImageScrollView::setImageIsJpeg(bool how) |
570 | { | 562 | { |
571 | m_states.setBit(IMAGE_IS_JPEG,how); | 563 | m_states.setBit(IMAGE_IS_JPEG,how); |
572 | } | 564 | } |
573 | 565 | ||
574 | bool OImageScrollView::ImageScaledLoaded()const | 566 | bool OImageScrollView::ImageScaledLoaded()const |
575 | { | 567 | { |
576 | return m_states.testBit(IMAGE_SCALED_LOADED); | 568 | return m_states.testBit(IMAGE_SCALED_LOADED); |
577 | } | 569 | } |
578 | 570 | ||
579 | void OImageScrollView::setImageScaledLoaded(bool how) | 571 | void OImageScrollView::setImageScaledLoaded(bool how) |
580 | { | 572 | { |
581 | m_states.setBit(IMAGE_SCALED_LOADED,how); | 573 | m_states.setBit(IMAGE_SCALED_LOADED,how); |
582 | } | 574 | } |
583 | 575 | ||
584 | } // namespace MM | 576 | } // namespace MM |
585 | } // namespace Opie | 577 | } // namespace Opie |