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