summaryrefslogtreecommitdiff
authoralwin <alwin>2004-04-13 21:44:12 (UTC)
committer alwin <alwin>2004-04-13 21:44:12 (UTC)
commite61f3d63c310e4e560bc38f41c1390f246b5f670 (patch) (unidiff)
tree2403a3b3ba1a47e6122d259b6b761f45c37f504d
parent482750c5b2494b7b2b94c13bf4743349b67d188a (diff)
downloadopie-e61f3d63c310e4e560bc38f41c1390f246b5f670.zip
opie-e61f3d63c310e4e560bc38f41c1390f246b5f670.tar.gz
opie-e61f3d63c310e4e560bc38f41c1390f246b5f670.tar.bz2
zoomer widget better integrated, size of it depends on the size of the displayed image,
may switched off by user and so on.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp44
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h4
-rw-r--r--noncore/graphics/opie-eye/gui/mainwindow.cpp15
-rw-r--r--noncore/graphics/opie-eye/gui/mainwindow.h2
4 files changed, 56 insertions, 9 deletions
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
index 5b12258..2f16d82 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp
@@ -4,33 +4,33 @@
4 4
5using namespace Opie::Core; 5using namespace Opie::Core;
6 6
7#include <qimage.h> 7#include <qimage.h>
8#include <qlayout.h> 8#include <qlayout.h>
9 9
10ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) 10ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f )
11 :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), 11 :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true),
12 rotate_to_fit(true),first_resize_done(false),m_lastName("") 12 rotate_to_fit(true),show_zoomer(true),first_resize_done(false),m_lastName("")
13{ 13{
14 init(); 14 init();
15} 15}
16 16
17ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) 17ImageScrollView::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), 18 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale),
19 rotate_to_fit(rfit),first_resize_done(false),m_lastName("") 19 rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("")
20{ 20{
21 _original_data.convertDepth(QPixmap::defaultDepth()); 21 _original_data.convertDepth(QPixmap::defaultDepth());
22 _original_data.setAlphaBuffer(false); 22 _original_data.setAlphaBuffer(false);
23 init(); 23 init();
24} 24}
25 25
26ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) 26ImageScrollView::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), 27 :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(),scale_to_fit(always_scale),
28 rotate_to_fit(rfit),first_resize_done(false),m_lastName("") 28 rotate_to_fit(rfit),show_zoomer(true),first_resize_done(false),m_lastName("")
29{ 29{
30 init(); 30 init();
31 setImage(img); 31 setImage(img);
32} 32}
33 33
34void ImageScrollView::setImage(const QImage&img) 34void ImageScrollView::setImage(const QImage&img)
35{ 35{
36 _image_data = QImage(); 36 _image_data = QImage();
@@ -75,18 +75,18 @@ void ImageScrollView::init()
75 connect(this,SIGNAL(viewportSizeChanged(const QSize&)), 75 connect(this,SIGNAL(viewportSizeChanged(const QSize&)),
76 _zoomer, SLOT(setViewPortSize(const QSize&)) ); 76 _zoomer, SLOT(setViewPortSize(const QSize&)) );
77 77
78 viewport()->setBackgroundColor(white); 78 viewport()->setBackgroundColor(white);
79 setFocusPolicy(QWidget::StrongFocus); 79 setFocusPolicy(QWidget::StrongFocus);
80 if (first_resize_done) { 80 if (first_resize_done) {
81 last_rot = Rotate0; 81 last_rot = Rotate0;
82 generateImage(); 82 generateImage();
83 odebug << "reinit display " << oendl;
84 } else if (_original_data.size().isValid()) { 83 } else if (_original_data.size().isValid()) {
84 if (image_fit_into(_original_data.size()) || !show_zoomer) _zoomer->hide();
85 resizeContents(_original_data.width(),_original_data.height()); 85 resizeContents(_original_data.width(),_original_data.height());
86 } 86 }
87} 87}
88 88
89void ImageScrollView::setAutoRotate(bool how) 89void ImageScrollView::setAutoRotate(bool how)
90{ 90{
91 /* to avoid double repaints */ 91 /* to avoid double repaints */
92 if (rotate_to_fit != how) { 92 if (rotate_to_fit != how) {
@@ -261,42 +261,45 @@ void ImageScrollView::generateImage()
261 _image_data = _original_data; 261 _image_data = _original_data;
262 } else { 262 } else {
263 rotate_into_data(r); 263 rotate_into_data(r);
264 } 264 }
265 last_rot = r; 265 last_rot = r;
266 resizeContents(_image_data.width(),_image_data.height()); 266 resizeContents(_image_data.width(),_image_data.height());
267 } 267 }
268 _pdata.convertFromImage(_image_data); 268 _pdata.convertFromImage(_image_data);
269
269 270
270 /* 271 /*
271 * update the zoomer 272 * update the zoomer
272 */ 273 */
274 check_zoomer();
273 emit imageSizeChanged( _image_data.size() ); 275 emit imageSizeChanged( _image_data.size() );
274 rescaleImage( 128, 128 ); 276 rescaleImage( 128, 128 );
277 /*
278 * move scrollbar
279 */
280 _zoomer->setGeometry( viewport()->width()-_image_data.width()/2, viewport()->height()-_image_data.height()/2,
281 _image_data.width()/2, _image_data.height()/2 );
282
275 _zoomer->setImage( _image_data ); 283 _zoomer->setImage( _image_data );
276
277 /* 284 /*
278 * invalidate 285 * invalidate
279 */ 286 */
280 _image_data=QImage(); 287 _image_data=QImage();
281} 288}
282 289
283void ImageScrollView::resizeEvent(QResizeEvent * e) 290void ImageScrollView::resizeEvent(QResizeEvent * e)
284{ 291{
285 odebug << "ImageScrollView resizeEvent" << oendl; 292 odebug << "ImageScrollView resizeEvent" << oendl;
286 QScrollView::resizeEvent(e); 293 QScrollView::resizeEvent(e);
287 generateImage(); 294 generateImage();
288 first_resize_done = true; 295 first_resize_done = true;
289 emit viewportSizeChanged( viewport()->size() ); 296 emit viewportSizeChanged( viewport()->size() );
290 297
291 /*
292 * move scrollbar
293 */
294 _zoomer->setGeometry( viewport()->width()-100, viewport()->height()-50, 100, 50 );
295} 298}
296 299
297void ImageScrollView::keyPressEvent(QKeyEvent * e) 300void ImageScrollView::keyPressEvent(QKeyEvent * e)
298{ 301{
299 if (!e) return; 302 if (!e) return;
300 int dx = horizontalScrollBar()->lineStep(); 303 int dx = horizontalScrollBar()->lineStep();
301 int dy = verticalScrollBar()->lineStep(); 304 int dy = verticalScrollBar()->lineStep();
302 if (e->key()==Qt::Key_Right) { 305 if (e->key()==Qt::Key_Right) {
@@ -393,8 +396,31 @@ void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e)
393 396
394void ImageScrollView::setDestructiveClose() { 397void ImageScrollView::setDestructiveClose() {
395 WFlags fl = getWFlags(); 398 WFlags fl = getWFlags();
396 /* clear it just in case */ 399 /* clear it just in case */
397 fl &= ~WDestructiveClose; 400 fl &= ~WDestructiveClose;
398 fl |= WDestructiveClose; 401 fl |= WDestructiveClose;
399 setWFlags( fl ); 402 setWFlags( fl );
400} 403}
404
405bool ImageScrollView::image_fit_into(const QSize&s )
406{
407 if (s.width()>width()||s.height()>height()) {
408 return false;
409 }
410 return true;
411}
412
413void ImageScrollView::setShowZoomer(bool how)
414{
415 show_zoomer = how;
416 check_zoomer();
417}
418
419void ImageScrollView::check_zoomer()
420{
421 if ( (!show_zoomer||image_fit_into(_pdata.size()) ) && _zoomer->isVisible()) {
422 _zoomer->hide();
423 } else if ( show_zoomer && !image_fit_into(_pdata.size()) && _zoomer->isHidden()){
424 _zoomer->show();
425 }
426}
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h
index 1b25103..e209dfb 100644
--- a/noncore/graphics/opie-eye/gui/imagescrollview.h
+++ b/noncore/graphics/opie-eye/gui/imagescrollview.h
@@ -23,16 +23,17 @@ public:
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 32
32 enum Rotation { 33 enum Rotation {
33 Rotate0, 34 Rotate0,
34 Rotate90, 35 Rotate90,
35 Rotate180, 36 Rotate180,
36 Rotate270 37 Rotate270
37 }; 38 };
38 39
@@ -49,23 +50,26 @@ protected:
49 QImage _image_data; 50 QImage _image_data;
50 QImage _original_data; 51 QImage _original_data;
51 QPixmap _pdata; 52 QPixmap _pdata;
52 53
53 int _mouseStartPosX,_mouseStartPosY; 54 int _mouseStartPosX,_mouseStartPosY;
54 55
55 bool scale_to_fit; 56 bool scale_to_fit;
56 bool rotate_to_fit; 57 bool rotate_to_fit;
58 bool show_zoomer;
57 bool first_resize_done; 59 bool first_resize_done;
58 Rotation last_rot; 60 Rotation last_rot;
59 QString m_lastName; 61 QString m_lastName;
60 virtual void rescaleImage(int w, int h); 62 virtual void rescaleImage(int w, int h);
61 63
62 virtual void rotate_into_data(Rotation r); 64 virtual void rotate_into_data(Rotation r);
63 virtual void generateImage(); 65 virtual void generateImage();
66 bool image_fit_into(const QSize&s);
67 void check_zoomer();
64 68
65protected slots: 69protected slots:
66 virtual void viewportMouseMoveEvent(QMouseEvent* e); 70 virtual void viewportMouseMoveEvent(QMouseEvent* e);
67 virtual void contentsMousePressEvent ( QMouseEvent * e); 71 virtual void contentsMousePressEvent ( QMouseEvent * e);
68 virtual void resizeEvent(QResizeEvent * e); 72 virtual void resizeEvent(QResizeEvent * e);
69 virtual void keyPressEvent(QKeyEvent * e); 73 virtual void keyPressEvent(QKeyEvent * e);
70}; 74};
71#endif 75#endif
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.cpp b/noncore/graphics/opie-eye/gui/mainwindow.cpp
index 3650493..ef23f79 100644
--- a/noncore/graphics/opie-eye/gui/mainwindow.cpp
+++ b/noncore/graphics/opie-eye/gui/mainwindow.cpp
@@ -101,22 +101,36 @@ PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style)
101 101
102 btn = new QToolButton(bar); 102 btn = new QToolButton(bar);
103 btn->setIconSet( Resource::loadIconSet( "1to1" ) ); 103 btn->setIconSet( Resource::loadIconSet( "1to1" ) );
104 btn->setToggleButton(true); 104 btn->setToggleButton(true);
105 btn->setOn(false); 105 btn->setOn(false);
106 connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotScaleToggled(bool))); 106 connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotScaleToggled(bool)));
107 autoScale = true; 107 autoScale = true;
108 108
109 btn = new QToolButton(bar);
110 btn->setIconSet( Resource::loadIconSet( "mag" ) );
111 btn->setToggleButton(true);
112 btn->setOn(true);
113 connect(btn,SIGNAL(toggled(bool)),this,SLOT(slotZoomerToggled(bool)));
114 zoomerOn = true;
109} 115}
110 116
111PMainWindow::~PMainWindow() { 117PMainWindow::~PMainWindow() {
112 odebug << "Shutting down" << oendl; 118 odebug << "Shutting down" << oendl;
113} 119}
114 120
121void PMainWindow::slotZoomerToggled(bool how)
122{
123 zoomerOn = how;
124 if (m_disp) {
125 m_disp->setShowZoomer(zoomerOn);
126 }
127}
128
115void PMainWindow::slotRotateToggled(bool how) 129void PMainWindow::slotRotateToggled(bool how)
116{ 130{
117 autoRotate = how; 131 autoRotate = how;
118 if (m_disp) { 132 if (m_disp) {
119 m_disp->setAutoRotate(how); 133 m_disp->setAutoRotate(how);
120 } 134 }
121} 135}
122 136
@@ -226,16 +240,17 @@ void PMainWindow::initInfo() {
226 initT<imageinfo>( "Image Info", &m_info, ImageInfo ); 240 initT<imageinfo>( "Image Info", &m_info, ImageInfo );
227 connect(m_info,SIGNAL(dispImage(const QString&)),this,SLOT(slotDisplay(const QString&))); 241 connect(m_info,SIGNAL(dispImage(const QString&)),this,SLOT(slotDisplay(const QString&)));
228} 242}
229void PMainWindow::initDisp() { 243void PMainWindow::initDisp() {
230 initT<ImageView>( "Image ScrollView", &m_disp, ImageDisplay ); 244 initT<ImageView>( "Image ScrollView", &m_disp, ImageDisplay );
231 if (m_disp) { 245 if (m_disp) {
232 m_disp->setAutoScale(autoScale); 246 m_disp->setAutoScale(autoScale);
233 m_disp->setAutoRotate(autoRotate); 247 m_disp->setAutoRotate(autoRotate);
248 m_disp->setShowZoomer(zoomerOn);
234 connect(m_disp,SIGNAL(dispImageInfo(const QString&)),this,SLOT(slotShowInfo(const QString&))); 249 connect(m_disp,SIGNAL(dispImageInfo(const QString&)),this,SLOT(slotShowInfo(const QString&)));
235 } 250 }
236} 251}
237 252
238/** 253/**
239 * With big Screen the plan could be to 'detach' the image 254 * With big Screen the plan could be to 'detach' the image
240 * window if visible and to create a ne wone 255 * window if visible and to create a ne wone
241 * init* already supports it but I make no use of it for 256 * init* already supports it but I make no use of it for
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.h b/noncore/graphics/opie-eye/gui/mainwindow.h
index 59dba30..e9b16d0 100644
--- a/noncore/graphics/opie-eye/gui/mainwindow.h
+++ b/noncore/graphics/opie-eye/gui/mainwindow.h
@@ -36,16 +36,17 @@ signals:
36 void configChanged(); 36 void configChanged();
37 37
38public slots: 38public slots:
39 void slotShowInfo( const QString& inf ); 39 void slotShowInfo( const QString& inf );
40 void slotDisplay( const QString& inf ); 40 void slotDisplay( const QString& inf );
41 void slotReturn(); 41 void slotReturn();
42 void slotRotateToggled(bool); 42 void slotRotateToggled(bool);
43 void slotScaleToggled(bool); 43 void slotScaleToggled(bool);
44 void slotZoomerToggled(bool);
44 void setDocument( const QString& ); 45 void setDocument( const QString& );
45 46
46protected: 47protected:
47 void raiseIconView(); 48 void raiseIconView();
48 void closeEvent( QCloseEvent* ); 49 void closeEvent( QCloseEvent* );
49 50
50private: 51private:
51 template<class T> void initT( const char* name, T**, int ); 52 template<class T> void initT( const char* name, T**, int );
@@ -55,16 +56,17 @@ private:
55private: 56private:
56 Opie::Core::OConfig *m_cfg; 57 Opie::Core::OConfig *m_cfg;
57 Opie::Ui::OWidgetStack *m_stack; 58 Opie::Ui::OWidgetStack *m_stack;
58 PIconView* m_view; 59 PIconView* m_view;
59 imageinfo *m_info; 60 imageinfo *m_info;
60 ImageView *m_disp; 61 ImageView *m_disp;
61 bool autoRotate; 62 bool autoRotate;
62 bool autoScale; 63 bool autoScale;
64 bool zoomerOn;
63 QToolButton*rotateButton; 65 QToolButton*rotateButton;
64 66
65 67
66private slots: 68private slots:
67 void slotConfig(); 69 void slotConfig();
68}; 70};
69 71
70#endif 72#endif