summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-14 19:00:02 (UTC)
committer alwin <alwin>2004-04-14 19:00:02 (UTC)
commit26e89198404dba70a3bea2b337f6677e6b177bb2 (patch) (unidiff)
treec55849b61ff27c121fc3cc8e6954d1179323af38
parentb3156cadba8f4a397ac7d65947cdb7a33b5c3b72 (diff)
downloadopie-26e89198404dba70a3bea2b337f6677e6b177bb2.zip
opie-26e89198404dba70a3bea2b337f6677e6b177bb2.tar.gz
opie-26e89198404dba70a3bea2b337f6677e6b177bb2.tar.bz2
mostly all basics done
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp212
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h65
-rw-r--r--noncore/graphics/opie-eye/gui/imageview.cpp3
-rw-r--r--noncore/graphics/opie-eye/gui/imageview.h3
-rw-r--r--noncore/graphics/opie-eye/gui/mainwindow.cpp2
-rw-r--r--noncore/graphics/opie-eye/gui/mainwindow.h3
-rw-r--r--noncore/graphics/opie-eye/lib/oimagezoomer.cpp18
-rw-r--r--noncore/graphics/opie-eye/lib/oimagezoomer.h13
8 files changed, 221 insertions, 98 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
index d034ee0..3bb07a7 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
@@ -1,61 +1,94 @@
1#include "imagescrollview.h" 1#include "imagescrollview.h"
2 2
3#include "lib/oimagezoomer.h"
4
3#include <opie2/odebug.h> 5#include <opie2/odebug.h>
4#include <opie2/oapplication.h> 6#include <opie2/oapplication.h>
5#include <opie2/owait.h> 7#include <opie2/owait.h>
6 8
7using namespace Opie::Core;
8
9#include <qimage.h> 9#include <qimage.h>
10#include <qlayout.h> 10#include <qlayout.h>
11#include <qpe/qcopenvelope_qws.h> 11#include <qpe/qcopenvelope_qws.h>
12 12
13ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) 13/* for usage with the bitset */
14 :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), 14#define AUTO_SCALE 0
15 rotate_to_fit(true),show_zoomer(true),first_resize_done(false),m_lastName("") 15#define AUTO_ROTATE 1
16#define SHOW_ZOOMER 2
17#define FIRST_RESIZE_DONE 3
18#define IMAGE_IS_JPEG 4
19#define IMAGE_SCALED_LOADED 5
20
21#define SCROLLVIEW_BITSET_SIZE 6
22
23namespace Opie {
24namespace MM {
25OImageScrollView::OImageScrollView( QWidget* parent, const char* name, WFlags f )
26 :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),
27 m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("")
16{ 28{
29 _zoomer = 0;
30 m_states[AUTO_SCALE]=true;
31 m_states[AUTO_ROTATE]=true;
32 m_states[FIRST_RESIZE_DONE]=false;
33 m_states[IMAGE_IS_JPEG]=false;
34 m_states[IMAGE_SCALED_LOADED]=false;
35 m_states[SHOW_ZOOMER]=true;
17 init(); 36 init();
18} 37}
19 38
20ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) 39OImageScrollView::OImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit)
21 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), 40 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),
22 rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("") 41 m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("")
23{ 42{
43 _zoomer = 0;
44 m_states[AUTO_SCALE]=always_scale;
45 m_states[AUTO_ROTATE]=rfit;
46 m_states[FIRST_RESIZE_DONE]=false;
47 m_states[IMAGE_IS_JPEG]=false;
48 m_states[IMAGE_SCALED_LOADED]=false;
49 m_states[SHOW_ZOOMER]=true;
24 _original_data.convertDepth(QPixmap::defaultDepth()); 50 _original_data.convertDepth(QPixmap::defaultDepth());
25 _original_data.setAlphaBuffer(false); 51 _original_data.setAlphaBuffer(false);
26 init(); 52 init();
27} 53}
28 54
29ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) 55OImageScrollView::OImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit)
30 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale), 56 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),m_states(SCROLLVIEW_BITSET_SIZE),m_lastName("")
31 rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("")
32{ 57{
58 _zoomer = 0;
59 m_states.resize(SCROLLVIEW_BITSET_SIZE);
60 m_states[AUTO_SCALE]=always_scale;
61 m_states[AUTO_ROTATE]=rfit;
62 m_states[FIRST_RESIZE_DONE]=false;
63 m_states[IMAGE_IS_JPEG]=false;
64 m_states[IMAGE_SCALED_LOADED]=false;
65 m_states[SHOW_ZOOMER]=true;
33 init(); 66 init();
34 setImage(img); 67 setImage(img);
35} 68}
36 69
37void ImageScrollView::setImage(const QImage&img) 70void OImageScrollView::setImage(const QImage&img)
38{ 71{
39 _image_data = QImage(); 72 _image_data = QImage();
40 _original_data=img; 73 _original_data=img;
41 _original_data.convertDepth(QPixmap::defaultDepth()); 74 _original_data.convertDepth(QPixmap::defaultDepth());
42 _original_data.setAlphaBuffer(false); 75 _original_data.setAlphaBuffer(false);
43 m_lastName = ""; 76 m_lastName = "";
44 image_is_jpeg = false; 77 setImageIsJpeg(false);
45 image_scaled_loaded = false; 78 setImageScaledLoaded(false);
46 if (first_resize_done) { 79 if (FirstResizeDone()) {
47 generateImage(); 80 generateImage();
48 } 81 }
49} 82}
50 83
51void ImageScrollView::loadJpeg(bool interncall) 84void OImageScrollView::loadJpeg(bool interncall)
52{ 85{
53 if (m_lastName.isEmpty()) return; 86 if (m_lastName.isEmpty()) return;
54 QImageIO iio( m_lastName, 0l ); 87 QImageIO iio( m_lastName, 0l );
55 QString param; 88 QString param;
56 bool real_load = false; 89 bool real_load = false;
57 if (scale_to_fit) { 90 if (AutoScale()) {
58 if (!interncall) { 91 if (!interncall) {
59 int wid, hei; 92 int wid, hei;
60 wid = QApplication::desktop()->width(); 93 wid = QApplication::desktop()->width();
61 hei = QApplication::desktop()->height(); 94 hei = QApplication::desktop()->height();
@@ -66,17 +99,17 @@ void ImageScrollView::loadJpeg(bool interncall)
66 } 99 }
67 param = QString( "Fast Shrink( 7 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei ); 100 param = QString( "Fast Shrink( 7 ) Scale( %1, %2, ScaleFree)" ).arg( wid ).arg( hei );
68 odebug << "Load jpeg scaled \"" << param << "\"" << oendl; 101 odebug << "Load jpeg scaled \"" << param << "\"" << oendl;
69 iio.setParameters(param.latin1()); 102 iio.setParameters(param.latin1());
70 image_scaled_loaded = true; 103 setImageScaledLoaded(true);
71 real_load = true; 104 real_load = true;
72 } 105 }
73 } else { 106 } else {
74 if (image_scaled_loaded||!interncall) { 107 if (ImageScaledLoaded()||!interncall) {
75 odebug << "Load jpeg unscaled" << oendl; 108 odebug << "Load jpeg unscaled" << oendl;
76 real_load = true; 109 real_load = true;
77 } 110 }
78 image_scaled_loaded = false; 111 setImageScaledLoaded(false);
79 } 112 }
80 if (real_load) { 113 if (real_load) {
81 { 114 {
82 QCopEnvelope( "QPE/System", "busy()" ); 115 QCopEnvelope( "QPE/System", "busy()" );
@@ -88,22 +121,22 @@ void ImageScrollView::loadJpeg(bool interncall)
88 } 121 }
89 } 122 }
90} 123}
91 124
92void ImageScrollView::setImage( const QString& path ) { 125void OImageScrollView::setImage( const QString& path ) {
93 odebug << "load new image " << oendl; 126 odebug << "load new image " << oendl;
94 if (m_lastName == path) return; 127 if (m_lastName == path) return;
95 m_lastName = path; 128 m_lastName = path;
96 QString itype = QImage::imageFormat(m_lastName); 129 QString itype = QImage::imageFormat(m_lastName);
97 odebug << "Image type = " << itype << oendl; 130 odebug << "Image type = " << itype << oendl;
98 if (itype == "JPEG") { 131 if (itype == "JPEG") {
99 image_is_jpeg = true; 132 setImageIsJpeg(true);
100 loadJpeg(); 133 loadJpeg();
101 } else { 134 } else {
102 { 135 {
103 QCopEnvelope( "QPE/System", "busy()" ); 136 QCopEnvelope( "QPE/System", "busy()" );
104 } 137 }
105 image_is_jpeg = false; 138 setImageIsJpeg(false);
106 _original_data.load(path); 139 _original_data.load(path);
107 _original_data.convertDepth(QPixmap::defaultDepth()); 140 _original_data.convertDepth(QPixmap::defaultDepth());
108 _original_data.setAlphaBuffer(false); 141 _original_data.setAlphaBuffer(false);
109 { 142 {
@@ -111,15 +144,15 @@ void ImageScrollView::setImage( const QString& path ) {
111 env << "Image loaded"; 144 env << "Image loaded";
112 } 145 }
113 } 146 }
114 _image_data = QImage(); 147 _image_data = QImage();
115 if (first_resize_done) { 148 if (FirstResizeDone()) {
116 generateImage(); 149 generateImage();
117 } 150 }
118} 151}
119 152
120/* should be called every time the QImage changed it content */ 153/* should be called every time the QImage changed it content */
121void ImageScrollView::init() 154void OImageScrollView::init()
122{ 155{
123 odebug << "init " << oendl; 156 odebug << "init " << oendl;
124 157
125 /* 158 /*
@@ -128,8 +161,10 @@ void ImageScrollView::init()
128 */ 161 */
129 _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" ); 162 _zoomer = new Opie::MM::OImageZoomer( this, "The Zoomer" );
130 connect(_zoomer, SIGNAL( zoomAreaRel(int,int)), 163 connect(_zoomer, SIGNAL( zoomAreaRel(int,int)),
131 this, SLOT(scrollBy(int,int)) ); 164 this, SLOT(scrollBy(int,int)) );
165 connect(_zoomer, SIGNAL( zoomArea(int,int)),
166 this, SLOT(center(int,int)) );
132 connect(this,SIGNAL(contentsMoving(int,int)), 167 connect(this,SIGNAL(contentsMoving(int,int)),
133 _zoomer, (SLOT(setVisiblePoint(int,int))) ); 168 _zoomer, (SLOT(setVisiblePoint(int,int))) );
134 connect(this,SIGNAL(imageSizeChanged(const QSize&)), 169 connect(this,SIGNAL(imageSizeChanged(const QSize&)),
135 _zoomer, SLOT(setImageSize(const QSize&)) ); 170 _zoomer, SLOT(setImageSize(const QSize&)) );
@@ -137,47 +172,57 @@ void ImageScrollView::init()
137 _zoomer, SLOT(setViewPortSize(const QSize&)) ); 172 _zoomer, SLOT(setViewPortSize(const QSize&)) );
138 173
139 viewport()->setBackgroundColor(white); 174 viewport()->setBackgroundColor(white);
140 setFocusPolicy(QWidget::StrongFocus); 175 setFocusPolicy(QWidget::StrongFocus);
141 image_scaled_loaded = false; 176 setImageScaledLoaded(false);
142 image_is_jpeg = false; 177 setImageIsJpeg(false);
143 if (first_resize_done) { 178 if (FirstResizeDone()) {
144 last_rot = Rotate0; 179 m_last_rot = Rotate0;
145 generateImage(); 180 generateImage();
146 } else if (_original_data.size().isValid()) { 181 } else if (_original_data.size().isValid()) {
147 if (image_fit_into(_original_data.size()) || !show_zoomer) _zoomer->hide(); 182 if (image_fit_into(_original_data.size()) || !ShowZoomer()) _zoomer->hide();
148 resizeContents(_original_data.width(),_original_data.height()); 183 resizeContents(_original_data.width(),_original_data.height());
149 } 184 }
150} 185}
151 186
152void ImageScrollView::setAutoRotate(bool how) 187void OImageScrollView::setAutoRotate(bool how)
153{ 188{
154 /* to avoid double repaints */ 189 /* to avoid double repaints */
155 if (rotate_to_fit != how) { 190 if (AutoRotate() != how) {
156 rotate_to_fit = how; 191 m_states.setBit(AUTO_ROTATE,how);
157 _image_data = QImage(); 192 _image_data = QImage();
158 generateImage(); 193 generateImage();
159 } 194 }
160} 195}
161 196
162void ImageScrollView::setAutoScale(bool how) 197bool OImageScrollView::AutoRotate()const
198{
199 return m_states.testBit(AUTO_ROTATE);
200}
201
202void OImageScrollView::setAutoScale(bool how)
163{ 203{
164 scale_to_fit = how; 204 m_states.setBit(AUTO_SCALE,how);
165 if (!how) { 205 if (!how) {
166 rotate_to_fit = false; 206 setAutoRotate(false);
167 } 207 }
168 _image_data = QImage(); 208 _image_data = QImage();
169 if (image_is_jpeg && how == false && image_scaled_loaded==true) { 209 if (ImageIsJpeg() && how == false && ImageScaledLoaded()==true) {
170 loadJpeg(true); 210 loadJpeg(true);
171 } 211 }
172 generateImage(); 212 generateImage();
173} 213}
174 214
175ImageScrollView::~ImageScrollView() 215bool OImageScrollView::AutoScale()const
216{
217 return m_states.testBit(AUTO_SCALE);
218}
219
220OImageScrollView::~OImageScrollView()
176{ 221{
177} 222}
178 223
179void ImageScrollView::rescaleImage(int w, int h) 224void OImageScrollView::rescaleImage(int w, int h)
180{ 225{
181 if (_image_data.width()==w && _image_data.height()==h) { 226 if (_image_data.width()==w && _image_data.height()==h) {
182 return; 227 return;
183 } 228 }
@@ -188,9 +233,9 @@ void ImageScrollView::rescaleImage(int w, int h)
188 int smoothH = (int)(scaleFactor * _image_data.height()); 233 int smoothH = (int)(scaleFactor * _image_data.height());
189 _image_data = _image_data.smoothScale(smoothW,smoothH); 234 _image_data = _image_data.smoothScale(smoothW,smoothH);
190} 235}
191 236
192void ImageScrollView::rotate_into_data(Rotation r) 237void OImageScrollView::rotate_into_data(Rotation r)
193{ 238{
194 /* realy - we must do this that way, 'cause when acting direct on _image_data the app will 239 /* realy - we must do this that way, 'cause when acting direct on _image_data the app will
195 segfault :( */ 240 segfault :( */
196 QImage dest; 241 QImage dest;
@@ -302,21 +347,22 @@ void ImageScrollView::rotate_into_data(Rotation r)
302 } 347 }
303 _image_data = dest; 348 _image_data = dest;
304} 349}
305 350
306void ImageScrollView::generateImage() 351void OImageScrollView::generateImage()
307{ 352{
308 Rotation r = Rotate0; 353 Rotation r = Rotate0;
354 if (_original_data.isNull()) return;
309 { 355 {
310 QCopEnvelope( "QPE/System", "busy()" ); 356 QCopEnvelope( "QPE/System", "busy()" );
311 } 357 }
312 if (width()>height()&&_original_data.width()<_original_data.height() || 358 if (width()>height()&&_original_data.width()<_original_data.height() ||
313 width()<height()&&_original_data.width()>_original_data.height()) { 359 width()<height()&&_original_data.width()>_original_data.height()) {
314 if (rotate_to_fit) r = Rotate90; 360 if (AutoRotate()) r = Rotate90;
315 } 361 }
316 362
317 odebug << " r = " << r << oendl; 363 odebug << " r = " << r << oendl;
318 if (scale_to_fit) { 364 if (AutoScale()) {
319 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) { 365 if (!_image_data.size().isValid()||width()>_image_data.width()||height()>_image_data.height()) {
320 odebug << "Rescaling data" << oendl; 366 odebug << "Rescaling data" << oendl;
321 if (r==Rotate0) { 367 if (r==Rotate0) {
322 _image_data = _original_data; 368 _image_data = _original_data;
@@ -325,15 +371,15 @@ void ImageScrollView::generateImage()
325 } 371 }
326 } 372 }
327 rescaleImage(width(),height()); 373 rescaleImage(width(),height());
328 resizeContents(_image_data.width(),_image_data.height()); 374 resizeContents(_image_data.width(),_image_data.height());
329 } else if (!first_resize_done||r!=last_rot||_image_data.width()==0) { 375 } else if (!FirstResizeDone()||r!=m_last_rot||_image_data.width()==0) {
330 if (r==Rotate0) { 376 if (r==Rotate0) {
331 _image_data = _original_data; 377 _image_data = _original_data;
332 } else { 378 } else {
333 rotate_into_data(r); 379 rotate_into_data(r);
334 } 380 }
335 last_rot = r; 381 m_last_rot = r;
336 resizeContents(_image_data.width(),_image_data.height()); 382 resizeContents(_image_data.width(),_image_data.height());
337 } 383 }
338 _pdata.convertFromImage(_image_data); 384 _pdata.convertFromImage(_image_data);
339 385
@@ -346,12 +392,13 @@ void ImageScrollView::generateImage()
346 rescaleImage( 128, 128 ); 392 rescaleImage( 128, 128 );
347 /* 393 /*
348 * move scrollbar 394 * move scrollbar
349 */ 395 */
350 _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2, 396 if (_zoomer) {
351 _image_data.width()/2, _image_data.height()/2 ); 397 _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2,
352 398 _image_data.width()/2, _image_data.height()/2 );
353 _zoomer->setImage( _image_data ); 399 _zoomer->setImage( _image_data );
400 }
354 /* 401 /*
355 * invalidate 402 * invalidate
356 */ 403 */
357 _image_data=QImage(); 404 _image_data=QImage();
@@ -360,19 +407,19 @@ void ImageScrollView::generateImage()
360 env << "Image generated"; 407 env << "Image generated";
361 } 408 }
362} 409}
363 410
364void ImageScrollView::resizeEvent(QResizeEvent * e) 411void OImageScrollView::resizeEvent(QResizeEvent * e)
365{ 412{
366 odebug << "ImageScrollView resizeEvent" << oendl; 413 odebug << "OImageScrollView resizeEvent" << oendl;
367 QScrollView::resizeEvent(e); 414 QScrollView::resizeEvent(e);
368 generateImage(); 415 generateImage();
369 first_resize_done = true; 416 setFirstResizeDone(true);
370 emit viewportSizeChanged( viewport()->size() ); 417 emit viewportSizeChanged( viewport()->size() );
371 418
372} 419}
373 420
374void ImageScrollView::keyPressEvent(QKeyEvent * e) 421void OImageScrollView::keyPressEvent(QKeyEvent * e)
375{ 422{
376 if (!e) return; 423 if (!e) return;
377 int dx = horizontalScrollBar()->lineStep(); 424 int dx = horizontalScrollBar()->lineStep();
378 int dy = verticalScrollBar()->lineStep(); 425 int dy = verticalScrollBar()->lineStep();
@@ -393,9 +440,9 @@ void ImageScrollView::keyPressEvent(QKeyEvent * e)
393 } 440 }
394 QScrollView::keyPressEvent(e); 441 QScrollView::keyPressEvent(e);
395} 442}
396 443
397void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) 444void OImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph)
398{ 445{
399 int w = clipw; 446 int w = clipw;
400 int h = cliph; 447 int h = cliph;
401 int x = clipx; 448 int x = clipx;
@@ -426,9 +473,9 @@ void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw
426 p->drawPixmap(clipx,clipy,_pdata,x,y,w,h); 473 p->drawPixmap(clipx,clipy,_pdata,x,y,w,h);
427} 474}
428 475
429/* using the real geometry points and not the translated points is wanted! */ 476/* using the real geometry points and not the translated points is wanted! */
430void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) 477void OImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
431{ 478{
432 odebug << "Move X and Y " << e->x() << " " << e->y() << oendl; 479 odebug << "Move X and Y " << e->x() << " " << e->y() << oendl;
433 int mx, my; 480 int mx, my;
434 mx = e->x(); 481 mx = e->x();
@@ -455,9 +502,9 @@ void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
455 _mouseStartPosX=mx; 502 _mouseStartPosX=mx;
456 _mouseStartPosY=my; 503 _mouseStartPosY=my;
457} 504}
458 505
459void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) 506void OImageScrollView::contentsMousePressEvent ( QMouseEvent * e)
460{ 507{
461 odebug << " X and Y " << e->x() << " " << e->y() << oendl; 508 odebug << " X and Y " << e->x() << " " << e->y() << oendl;
462 /* this marks the beginning of a possible mouse move. Due internal reasons of QT 509 /* this marks the beginning of a possible mouse move. Due internal reasons of QT
463 the geometry values here may real differ from that set in MoveEvent (I don't know 510 the geometry values here may real differ from that set in MoveEvent (I don't know
@@ -467,34 +514,73 @@ void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e)
467 _mouseStartPosX = -1; 514 _mouseStartPosX = -1;
468 _mouseStartPosY = -1; 515 _mouseStartPosY = -1;
469} 516}
470 517
471void ImageScrollView::setDestructiveClose() { 518void OImageScrollView::setDestructiveClose() {
472 WFlags fl = getWFlags(); 519 WFlags fl = getWFlags();
473 /* clear it just in case */ 520 /* clear it just in case */
474 fl &= ~WDestructiveClose; 521 fl &= ~WDestructiveClose;
475 fl |= WDestructiveClose; 522 fl |= WDestructiveClose;
476 setWFlags( fl ); 523 setWFlags( fl );
477} 524}
478 525
479bool ImageScrollView::image_fit_into(const QSize&s ) 526bool OImageScrollView::image_fit_into(const QSize&s )
480{ 527{
481 if (s.width()>width()||s.height()>height()) { 528 if (s.width()>width()||s.height()>height()) {
482 return false; 529 return false;
483 } 530 }
484 return true; 531 return true;
485} 532}
486 533
487void ImageScrollView::setShowZoomer(bool how) 534void OImageScrollView::setShowZoomer(bool how)
488{ 535{
489 show_zoomer = how; 536 m_states.setBit(SHOW_ZOOMER,how);
490 check_zoomer(); 537 check_zoomer();
491} 538}
492 539
493void ImageScrollView::check_zoomer() 540bool OImageScrollView::ShowZoomer()const
541{
542 return m_states.testBit(SHOW_ZOOMER);
543}
544
545void OImageScrollView::check_zoomer()
494{ 546{
495 if ( (!show_zoomer||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) { 547 if (!_zoomer) return;
548 if ( (!ShowZoomer()||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) {
496 _zoomer->hide(); 549 _zoomer->hide();
497 } else if ( show_zoomer && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){ 550 } else if ( ShowZoomer() && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){
498 _zoomer->show(); 551 _zoomer->show();
499 } 552 }
500} 553}
554
555bool OImageScrollView::FirstResizeDone()const
556{
557 return m_states.testBit(FIRST_RESIZE_DONE);
558}
559
560void OImageScrollView::setFirstResizeDone(bool how)
561{
562 m_states.setBit(FIRST_RESIZE_DONE,how);
563}
564
565bool OImageScrollView::ImageIsJpeg()const
566{
567 return m_states.testBit(IMAGE_IS_JPEG);
568}
569
570void OImageScrollView::setImageIsJpeg(bool how)
571{
572 m_states.setBit(IMAGE_IS_JPEG,how);
573}
574
575bool OImageScrollView::ImageScaledLoaded()const
576{
577 return m_states.testBit(IMAGE_SCALED_LOADED);
578}
579
580void OImageScrollView::setImageScaledLoaded(bool how)
581{
582 m_states.setBit(IMAGE_SCALED_LOADED,how);
583}
584
585} // namespace MM
586} // namespace Opie
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h
index f6e187d..3d2ea38 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.h
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.h
@@ -1,45 +1,54 @@
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>
5
6#include <qscrollview.h> 4#include <qscrollview.h>
7#include <qimage.h> 5#include <qimage.h>
8#include <qpixmap.h> 6#include <qpixmap.h>
9#include <qstring.h> 7#include <qstring.h>
10#include <qdialog.h> 8#include <qdialog.h>
11 9#include <qbitarray.h>
12 10
13 11
14class QPainter; 12class QPainter;
15 13
16class ImageScrollView:public QScrollView 14namespace Opie { namespace MM {
15
16 class OImageZoomer;
17
18class OImageScrollView:public QScrollView
17{ 19{
18 Q_OBJECT 20 Q_OBJECT
19public: 21public:
20 ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); 22 enum Rotation {
21 ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); 23 Rotate0,
22 ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); 24 Rotate90,
23 virtual ~ImageScrollView(); 25 Rotate180,
26 Rotate270
27 };
28
29 OImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 );
30 OImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
31 OImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
32 virtual ~OImageScrollView();
33
24 34
25 virtual void setImage(const QImage&);
26 virtual void setImage( const QString& path );
27 virtual void setDestructiveClose(); 35 virtual void setDestructiveClose();
28 36
29 virtual void setAutoRotate(bool); 37 virtual void setAutoRotate(bool);
30 virtual void setAutoScale(bool); 38 virtual void setAutoScale(bool);
31 virtual void setShowZoomer(bool); 39 virtual void setShowZoomer(bool);
32 40
33 enum Rotation { 41 virtual bool AutoRotate()const;
34 Rotate0, 42 virtual bool AutoScale()const;
35 Rotate90, 43 virtual bool ShowZoomer()const;
36 Rotate180, 44
37 Rotate270 45public slots:
38 }; 46 virtual void setImage(const QImage&);
47 virtual void setImage( const QString& path );
48
39 49
40signals: 50signals:
41 void sig_return();
42 void imageSizeChanged( const QSize& ); 51 void imageSizeChanged( const QSize& );
43 void viewportSizeChanged( const QSize& ); 52 void viewportSizeChanged( const QSize& );
44 53
45protected: 54protected:
@@ -52,15 +61,11 @@ protected:
52 QPixmap _pdata; 61 QPixmap _pdata;
53 62
54 int _mouseStartPosX,_mouseStartPosY; 63 int _mouseStartPosX,_mouseStartPosY;
55 64
56 bool scale_to_fit; 65 QBitArray m_states;
57 bool rotate_to_fit; 66
58 bool show_zoomer; 67 Rotation m_last_rot;
59 bool first_resize_done;
60 bool image_is_jpeg;
61 bool image_scaled_loaded;
62 Rotation last_rot;
63 QString m_lastName; 68 QString m_lastName;
64 virtual void rescaleImage(int w, int h); 69 virtual void rescaleImage(int w, int h);
65 70
66 virtual void rotate_into_data(Rotation r); 71 virtual void rotate_into_data(Rotation r);
@@ -68,11 +73,23 @@ protected:
68 virtual void loadJpeg(bool interncall = false); 73 virtual void loadJpeg(bool interncall = false);
69 bool image_fit_into(const QSize&s); 74 bool image_fit_into(const QSize&s);
70 void check_zoomer(); 75 void check_zoomer();
71 76
77 /* internal bitset manipulation */
78 virtual bool ImageIsJpeg()const;
79 virtual void setImageIsJpeg(bool how);
80 virtual bool ImageScaledLoaded()const;
81 virtual void setImageScaledLoaded(bool how);
82 virtual bool FirstResizeDone()const;
83 virtual void setFirstResizeDone(bool how);
84
72protected slots: 85protected slots:
73 virtual void viewportMouseMoveEvent(QMouseEvent* e); 86 virtual void viewportMouseMoveEvent(QMouseEvent* e);
74 virtual void contentsMousePressEvent ( QMouseEvent * e); 87 virtual void contentsMousePressEvent ( QMouseEvent * e);
75 virtual void resizeEvent(QResizeEvent * e); 88 virtual void resizeEvent(QResizeEvent * e);
76 virtual void keyPressEvent(QKeyEvent * e); 89 virtual void keyPressEvent(QKeyEvent * e);
77}; 90};
91
92}
93}
94
78#endif 95#endif
diff --git a/noncore/graphics/opie-eye/gui/imageview.cpp b/noncore/graphics/opie-eye/gui/imageview.cpp
index 2078b19..db3ae74 100644
--- a/noncore/graphics/opie-eye/gui/imageview.cpp
+++ b/noncore/graphics/opie-eye/gui/imageview.cpp
@@ -8,9 +8,9 @@
8 8
9using namespace Opie::Core; 9using namespace Opie::Core;
10 10
11ImageView::ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name, WFlags fl ) 11ImageView::ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name, WFlags fl )
12 : ImageScrollView(parent,name,fl) 12 : Opie::MM::OImageScrollView(parent,name,fl)
13{ 13{
14 m_viewManager = 0; 14 m_viewManager = 0;
15 m_cfg = cfg; 15 m_cfg = cfg;
16 initKeys(); 16 initKeys();
@@ -42,9 +42,8 @@ void ImageView::initKeys()
42 lst.append( Opie::Core::OKeyPair::upArrowKey() ); 42 lst.append( Opie::Core::OKeyPair::upArrowKey() );
43 lst.append( Opie::Core::OKeyPair::downArrowKey() ); 43 lst.append( Opie::Core::OKeyPair::downArrowKey() );
44 lst.append( Opie::Core::OKeyPair::leftArrowKey() ); 44 lst.append( Opie::Core::OKeyPair::leftArrowKey() );
45 lst.append( Opie::Core::OKeyPair::rightArrowKey() ); 45 lst.append( Opie::Core::OKeyPair::rightArrowKey() );
46 lst.append( Opie::Core::OKeyPair::returnKey() );
47 46
48 m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "image_view_keys", 47 m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "image_view_keys",
49 lst, false,this, "image_view_keys" ); 48 lst, false,this, "image_view_keys" );
50 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Image Info"), "imageviewinfo", 49 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Image Info"), "imageviewinfo",
diff --git a/noncore/graphics/opie-eye/gui/imageview.h b/noncore/graphics/opie-eye/gui/imageview.h
index 87e2b32..e4f899a 100644
--- a/noncore/graphics/opie-eye/gui/imageview.h
+++ b/noncore/graphics/opie-eye/gui/imageview.h
@@ -10,9 +10,9 @@ namespace Opie {
10 class OKeyConfigManager; 10 class OKeyConfigManager;
11 } 11 }
12} 12}
13 13
14class ImageView:public ImageScrollView 14class ImageView:public Opie::MM::OImageScrollView
15{ 15{
16 Q_OBJECT 16 Q_OBJECT
17 17
18 enum ActionIds { 18 enum ActionIds {
@@ -25,9 +25,8 @@ public:
25 Opie::Core::OKeyConfigManager* manager(); 25 Opie::Core::OKeyConfigManager* manager();
26 26
27signals: 27signals:
28 void dispImageInfo(const QString&); 28 void dispImageInfo(const QString&);
29 void sig_return();
30 29
31protected: 30protected:
32 Opie::Core::OConfig * m_cfg; 31 Opie::Core::OConfig * m_cfg;
33 Opie::Core::OKeyConfigManager*m_viewManager; 32 Opie::Core::OKeyConfigManager*m_viewManager;
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.cpp b/noncore/graphics/opie-eye/gui/mainwindow.cpp
index e5921d8..09f562a 100644
--- a/noncore/graphics/opie-eye/gui/mainwindow.cpp
+++ b/noncore/graphics/opie-eye/gui/mainwindow.cpp
@@ -2,13 +2,13 @@
2 * GPLv2 zecke@handhelds.org 2 * GPLv2 zecke@handhelds.org
3 * No WArranty... 3 * No WArranty...
4 */ 4 */
5#include "mainwindow.h" 5#include "mainwindow.h"
6#include "imageview.h"
6 7
7#include "iconview.h" 8#include "iconview.h"
8#include "filesystem.h" 9#include "filesystem.h"
9#include "imageinfoui.h" 10#include "imageinfoui.h"
10#include "imageview.h"
11#include "viewmodebutton.h" 11#include "viewmodebutton.h"
12 12
13#include <iface/ifaceinfo.h> 13#include <iface/ifaceinfo.h>
14#include <iface/dirview.h> 14#include <iface/dirview.h>
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.h b/noncore/graphics/opie-eye/gui/mainwindow.h
index e9b16d0..adb5dc2 100644
--- a/noncore/graphics/opie-eye/gui/mainwindow.h
+++ b/noncore/graphics/opie-eye/gui/mainwindow.h
@@ -20,11 +20,12 @@ namespace Core{
20 class OKeyConfigManager; 20 class OKeyConfigManager;
21} 21}
22} 22}
23 23
24class ImageView;
24class PIconView; 25class PIconView;
25class imageinfo; 26class imageinfo;
26class ImageView; 27
27class PMainWindow : public QMainWindow { 28class PMainWindow : public QMainWindow {
28 Q_OBJECT 29 Q_OBJECT
29 enum Views { IconView, ImageInfo, ImageDisplay }; 30 enum Views { IconView, ImageInfo, ImageDisplay };
30public: 31public:
diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp
index 00b93e2..d1eec67 100644
--- a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp
+++ b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp
@@ -1,6 +1,8 @@
1#include "oimagezoomer.h" 1#include "oimagezoomer.h"
2 2
3#include <opie2/odebug.h>
4
3#include <qimage.h> 5#include <qimage.h>
4#include <qpixmap.h> 6#include <qpixmap.h>
5#include <qpainter.h> 7#include <qpainter.h>
6#include <qrect.h> 8#include <qrect.h>
@@ -85,8 +87,9 @@ OImageZoomer::~OImageZoomer() {
85 87
86} 88}
87 89
88void OImageZoomer::init() { 90void OImageZoomer::init() {
91 m_mevent = false;
89 setFrameStyle( Panel | Sunken ); 92 setFrameStyle( Panel | Sunken );
90} 93}
91 94
92 95
@@ -194,22 +197,33 @@ void OImageZoomer::drawContents( QPainter* p ) {
194 197
195 p->drawRect( x, y, w, h ); 198 p->drawRect( x, y, w, h );
196} 199}
197 200
198void OImageZoomer::mousePressEvent( QMouseEvent* ) { 201void OImageZoomer::mousePressEvent( QMouseEvent*ev) {
199 m_mouseX = m_mouseY = -1; 202 m_mouseX = m_mouseY = -1;
203 m_mevent = true;
204}
205
206void OImageZoomer::mouseReleaseEvent( QMouseEvent*ev) {
207 if (!m_mevent) return;
208 int mx, my;
209 mx = ev->x();
210 my = ev->y();
211 int diffx = (mx) * m_imgSize.width() / width();
212 int diffy = (my) * m_imgSize.height() / height();
213 emit zoomArea(diffx,diffy);
200} 214}
201 215
202void OImageZoomer::mouseMoveEvent( QMouseEvent* ev ) { 216void OImageZoomer::mouseMoveEvent( QMouseEvent* ev ) {
203 int mx, my; 217 int mx, my;
204 mx = ev->x(); 218 mx = ev->x();
205 my = ev->y(); 219 my = ev->y();
206 220
207 if ( m_mouseX != -1 && m_mouseY != -1 ) { 221 if ( m_mouseX != -1 && m_mouseY != -1 ) {
222 m_mevent = false;
208 int diffx = ( mx - m_mouseX ) * m_imgSize.width() / width(); 223 int diffx = ( mx - m_mouseX ) * m_imgSize.width() / width();
209 int diffy = ( my - m_mouseY ) * m_imgSize.height() / height(); 224 int diffy = ( my - m_mouseY ) * m_imgSize.height() / height();
210 emit zoomAreaRel( diffx, diffy ); 225 emit zoomAreaRel( diffx, diffy );
211 emit zoomArea(m_visPt.x()+diffx, m_visPt.y()+diffy );
212 } 226 }
213 m_mouseX = mx; 227 m_mouseX = mx;
214 m_mouseY = my; 228 m_mouseY = my;
215} 229}
diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.h b/noncore/graphics/opie-eye/lib/oimagezoomer.h
index 2516c61..0b356c9 100644
--- a/noncore/graphics/opie-eye/lib/oimagezoomer.h
+++ b/noncore/graphics/opie-eye/lib/oimagezoomer.h
@@ -70,9 +70,10 @@ signals:
70 void zoomAreaRel( int x,int y); 70 void zoomAreaRel( int x,int y);
71 71
72 /** 72 /**
73 * Here you get absolute coordinates. 73 * Here you get absolute coordinates.
74 * This slot will be emitted from within the mouseMoveEvent of this widget. 74 * This slot will be emitted from within the mouseReleaseEvent of this widget.
75 * if no mouse move where done.
75 * So you may not delete this widget 76 * So you may not delete this widget
76 * 77 *
77 * @param x The absolute X Coordinate to scroll to. 78 * @param x The absolute X Coordinate to scroll to.
78 * @param y The absolute Y Coordinate to scroll to. 79 * @param y The absolute Y Coordinate to scroll to.
@@ -97,14 +98,19 @@ protected:
97 /** 98 /**
98 * make sure to call these if you reimplememt 99 * make sure to call these if you reimplememt
99 * @internal 100 * @internal
100 */ 101 */
101 void mousePressEvent( QMouseEvent* ev ); 102 virtual void mousePressEvent( QMouseEvent* ev );
102 /** 103 /**
103 * make sure to call these if you reimplement 104 * make sure to call these if you reimplement
104 * @internal 105 * @internal
105 */ 106 */
106 void mouseMoveEvent( QMouseEvent* ev ); 107 virtual void mouseMoveEvent( QMouseEvent* ev );
108 /**
109 * make sure to call these if you reimplement
110 * @internal
111 */
112 virtual void mouseReleaseEvent( QMouseEvent* ev );
107 113
108private: 114private:
109 /** 115 /**
110 * @internal 116 * @internal
@@ -113,8 +119,9 @@ private:
113 QImage m_img; 119 QImage m_img;
114 QSize m_imgSize, m_visSize; 120 QSize m_imgSize, m_visSize;
115 QPoint m_visPt; 121 QPoint m_visPt;
116 int m_mouseX, m_mouseY; 122 int m_mouseX, m_mouseY;
123 bool m_mevent;
117}; 124};
118 125
119/** 126/**
120 * This slot is present for convience. You can connect the 127 * This slot is present for convience. You can connect the