author | llornkcor <llornkcor> | 2002-11-03 17:59:00 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-03 17:59:00 (UTC) |
commit | 16e8fad81f7ee6045990f48edc84542638bf07d7 (patch) (unidiff) | |
tree | 96d836f914e0d1104d7c84830acac08a43ee4ac2 /noncore/multimedia/showimg/showimg.cpp | |
parent | 2981b8f55f4a33860452f4571ef9f04781267489 (diff) | |
download | opie-16e8fad81f7ee6045990f48edc84542638bf07d7.zip opie-16e8fad81f7ee6045990f48edc84542638bf07d7.tar.gz opie-16e8fad81f7ee6045990f48edc84542638bf07d7.tar.bz2 |
added preferences dialog, and added slidshow
Diffstat (limited to 'noncore/multimedia/showimg/showimg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/showimg/showimg.cpp | 279 |
1 files changed, 242 insertions, 37 deletions
diff --git a/noncore/multimedia/showimg/showimg.cpp b/noncore/multimedia/showimg/showimg.cpp index d7d53ec..0fbffe7 100644 --- a/noncore/multimedia/showimg/showimg.cpp +++ b/noncore/multimedia/showimg/showimg.cpp | |||
@@ -15,55 +15,60 @@ | |||
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | // | 21 | // |
22 | // Full-screen and rotation options contributed by Robert Wittams <robert@wittams.com> | 22 | // Full-screen and rotation options contributed by Robert Wittams <robert@wittams.com> |
23 | // | 23 | // |
24 | 24 | ||
25 | #include "showimg.h" | 25 | #include "showimg.h" |
26 | #include "ImageFileSelector.h" | 26 | #include "ImageFileSelector.h" |
27 | #include "settingsdialog.h" | ||
28 | |||
27 | 29 | ||
30 | #include <opie/ofiledialog.h> | ||
31 | |||
32 | #include <qpe/qpeapplication.h> | ||
28 | #include <qpe/config.h> | 33 | #include <qpe/config.h> |
29 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
30 | #include <qpe/fileselector.h> | 35 | #include <qpe/fileselector.h> |
31 | #include <qpe/applnk.h> | 36 | #include <qpe/applnk.h> |
32 | #include <qfileinfo.h> | 37 | #include <qfileinfo.h> |
33 | #include <math.h> | 38 | #include <math.h> |
34 | #include <qpe/qpemenubar.h> | 39 | #include <qpe/qpemenubar.h> |
35 | #include <qwidgetstack.h> | 40 | #include <qwidgetstack.h> |
36 | #include <qpe/qpetoolbar.h> | 41 | #include <qpe/qpetoolbar.h> |
37 | #include <qaction.h> | 42 | #include <qaction.h> |
38 | #include <qfiledialog.h> | 43 | #include <qfiledialog.h> |
39 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
40 | #include <qpopupmenu.h> | 45 | #include <qpopupmenu.h> |
41 | #include <qscrollview.h> | 46 | #include <qscrollview.h> |
42 | #include <qlabel.h> | 47 | #include <qlabel.h> |
43 | #include <qpainter.h> | 48 | #include <qpainter.h> |
44 | #include <qkeycode.h> | 49 | #include <qkeycode.h> |
45 | #include <qapplication.h> | 50 | #include <qapplication.h> |
46 | #include <qclipboard.h> | 51 | #include <qclipboard.h> |
47 | #include <qtimer.h> | 52 | #include <qtimer.h> |
48 | #include <qspinbox.h> | 53 | #include <qspinbox.h> |
49 | 54 | ||
50 | 55 | ||
51 | 56 | ||
52 | ControlsDialog::ControlsDialog(const QString &caption,QImage image,int *brightness,QWidget *parent):QDialog(parent,0,true) | 57 | ControlsDialog::ControlsDialog(const QString &caption,QImage image,int *brightness,QWidget *parent) |
58 | : QDialog(parent,0,true) | ||
53 | { | 59 | { |
54 | setCaption(caption); | 60 | setCaption(caption); |
55 | 61 | ||
56 | if ( parent ) | 62 | if ( parent ) { |
57 | { | ||
58 | setPalette(parent->palette()); | 63 | setPalette(parent->palette()); |
59 | } | 64 | } |
60 | 65 | ||
61 | b=brightness; | 66 | b=brightness; |
62 | img=image; | 67 | img=image; |
63 | 68 | ||
64 | setMinimumSize(140,80); | 69 | setMinimumSize(140,80); |
65 | 70 | ||
66 | QGridLayout *gl= new QGridLayout(this,2,2,4,4); | 71 | QGridLayout *gl= new QGridLayout(this,2,2,4,4); |
67 | 72 | ||
68 | pixmap =new ImageWidget(this);; | 73 | pixmap =new ImageWidget(this);; |
69 | QPixmap pm; | 74 | QPixmap pm; |
@@ -92,27 +97,28 @@ void ControlsDialog::bValueChanged(int value) | |||
92 | pixmap->setPixmap(pm); | 97 | pixmap->setPixmap(pm); |
93 | pixmap->repaint(false); | 98 | pixmap->repaint(false); |
94 | 99 | ||
95 | 100 | ||
96 | } | 101 | } |
97 | 102 | ||
98 | void ControlsDialog::accept() | 103 | void ControlsDialog::accept() |
99 | { | 104 | { |
100 | *b=spb->value(); | 105 | *b=spb->value(); |
101 | done(1); | 106 | done(1); |
102 | } | 107 | } |
103 | 108 | ||
109 | //=========================================================================== | ||
104 | 110 | ||
105 | 111 | InfoDialog::InfoDialog(const QString &caption, const QStringList text,QWidget *parent) | |
106 | InfoDialog::InfoDialog(const QString &caption, const QStringList text,QWidget *parent):QDialog(parent,0,true) | 112 | : QDialog(parent,0,true) |
107 | { | 113 | { |
108 | setCaption(caption); | 114 | setCaption(caption); |
109 | 115 | ||
110 | if ( parent ) | 116 | if ( parent ) |
111 | { | 117 | { |
112 | setPalette(parent->palette()); | 118 | setPalette(parent->palette()); |
113 | } | 119 | } |
114 | 120 | ||
115 | const char *labels[]={"File Name","Format","File Size","Size","Colors","Alpha"}; | 121 | const char *labels[]={"File Name","Format","File Size","Size","Colors","Alpha"}; |
116 | 122 | ||
117 | setMinimumSize(180,80); | 123 | setMinimumSize(180,80); |
118 | int num=ImageViewer::LAST+1; | 124 | int num=ImageViewer::LAST+1; |
@@ -140,24 +146,26 @@ InfoDialog::InfoDialog(const QString &caption, const QStringList text,QWidget *p | |||
140 | 146 | ||
141 | } | 147 | } |
142 | 148 | ||
143 | } | 149 | } |
144 | 150 | ||
145 | void InfoDialog::displayInfo(const QString &caption, const QStringList text, QWidget *parent) | 151 | void InfoDialog::displayInfo(const QString &caption, const QStringList text, QWidget *parent) |
146 | { | 152 | { |
147 | InfoDialog *dlg=new InfoDialog(caption,text,parent); | 153 | InfoDialog *dlg=new InfoDialog(caption,text,parent); |
148 | dlg->exec(); | 154 | dlg->exec(); |
149 | delete dlg; | 155 | delete dlg; |
150 | } | 156 | } |
151 | 157 | ||
158 | //=========================================================================== | ||
159 | |||
152 | 160 | ||
153 | ImagePane::ImagePane( QWidget *parent ) : QWidget( parent ) | 161 | ImagePane::ImagePane( QWidget *parent ) : QWidget( parent ) |
154 | { | 162 | { |
155 | vb = new QVBoxLayout( this ); | 163 | vb = new QVBoxLayout( this ); |
156 | 164 | ||
157 | image = new QScrollView(this,0,WResizeNoErase|WNorthWestGravity); | 165 | image = new QScrollView(this,0,WResizeNoErase|WNorthWestGravity); |
158 | pic=new ImageWidget(image); | 166 | pic=new ImageWidget(image); |
159 | image->addChild(pic); | 167 | image->addChild(pic); |
160 | 168 | ||
161 | connect(pic, SIGNAL( clicked() ), this, SLOT( imageClicked() )); | 169 | connect(pic, SIGNAL( clicked() ), this, SLOT( imageClicked() )); |
162 | 170 | ||
163 | vb->addWidget( image ); | 171 | vb->addWidget( image ); |
@@ -220,44 +228,51 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags ) | |||
220 | 228 | ||
221 | toolBar = new QPEToolBar( this ); | 229 | toolBar = new QPEToolBar( this ); |
222 | toolBar->setHorizontalStretchable( TRUE ); | 230 | toolBar->setHorizontalStretchable( TRUE ); |
223 | 231 | ||
224 | menuBar = new QPEMenuBar( toolBar ); | 232 | menuBar = new QPEMenuBar( toolBar ); |
225 | 233 | ||
226 | current=menuBar; | 234 | current=menuBar; |
227 | 235 | ||
228 | 236 | ||
229 | 237 | ||
230 | fileMenuFile = new QPopupMenu(this); | 238 | fileMenuFile = new QPopupMenu(this); |
231 | //menuBarmenubarFile->insertItem( tr("File"), fileMenu ); | 239 | //menuBarmenubarFile->insertItem( tr("File"), fileMenu ); |
232 | fileMenuFile->insertItem(tr("Open"), this, SLOT(openFile()), 0); | 240 | fileMenuFile->insertItem(tr("Open"), |
241 | this, SLOT(openFile()), 0); | ||
233 | 242 | ||
234 | viewMenuFile = new QPopupMenu( this ); | 243 | viewMenuFile = new QPopupMenu( this ); |
235 | //menubarFile->insertItem( tr("View"), viewMenu ); | 244 | //menubarFile->insertItem( tr("View"), viewMenu ); |
236 | viewMenuFile->insertItem( tr("Thumbnail View"), this, SLOT(switchThumbView()), 0, SHOW_THUMBNAILS ); | 245 | viewMenuFile->insertItem( tr("Thumbnail View"), |
246 | this, SLOT(switchThumbView()), 0, SHOW_THUMBNAILS ); | ||
237 | 247 | ||
238 | viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView ); | 248 | viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView ); |
239 | 249 | ||
240 | 250 | ||
241 | 251 | ||
242 | 252 | ||
243 | optionsMenuFile = new QPopupMenu( this); | 253 | optionsMenuFile = new QPopupMenu( this); |
244 | //menubarFile->insertItem( tr("Options"),optionsMenu ); | 254 | //menubarFile->insertItem( tr("Options"),optionsMenu ); |
245 | optionsMenuFile->insertItem( tr("Slideshow") ); | 255 | slideAction = new QAction( tr( "Slide show" ), Resource::loadIconSet( "slideshow" ), |
246 | optionsMenuFile->insertSeparator(); | 256 | QString::null, 0, this, 0 ); |
247 | optionsMenuFile->insertItem( tr("Preferences..")); | 257 | slideAction->setToggleAction( TRUE ); |
248 | optionsMenuFile->insertItem( tr("Help")); | 258 | connect( slideAction, SIGNAL( toggled(bool) ), this, SLOT( slideShow(bool) ) ); |
249 | 259 | slideAction->addTo( optionsMenuFile); | |
260 | // slideAction->addTo( toolBar ); | ||
250 | 261 | ||
251 | 262 | ||
263 | // optionsMenuFile->insertItem( tr("Slideshow") ); | ||
264 | optionsMenuFile->insertSeparator(); | ||
265 | optionsMenuFile->insertItem( tr("Preferences.."), this, SLOT(settings()), 0); | ||
266 | // optionsMenuFile->insertItem( tr("Help"), this, SLOT(help()), 0); | ||
252 | 267 | ||
253 | QStrList fmt = QImage::outputFormats(); | 268 | QStrList fmt = QImage::outputFormats(); |
254 | 269 | ||
255 | 270 | ||
256 | fileMenuView = new QPopupMenu( this ); | 271 | fileMenuView = new QPopupMenu( this ); |
257 | //menubarView->insertItem( tr("File"),fileMenu ); | 272 | //menubarView->insertItem( tr("File"),fileMenu ); |
258 | fileMenuView->insertItem( tr("Image Info ..."),this, SLOT(displayInfoDialog()),0 ); | 273 | fileMenuView->insertItem( tr("Image Info ..."),this, SLOT(displayInfoDialog()),0 ); |
259 | fileMenuView->insertSeparator(); | 274 | fileMenuView->insertSeparator(); |
260 | 275 | ||
261 | viewMenuView = new QPopupMenu(this ); | 276 | viewMenuView = new QPopupMenu(this ); |
262 | viewMenuView->setCheckable ( true ); | 277 | viewMenuView->setCheckable ( true ); |
263 | 278 | ||
@@ -282,25 +297,29 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags ) | |||
282 | 297 | ||
283 | qDebug("cv = %d",cv); | 298 | qDebug("cv = %d",cv); |
284 | 299 | ||
285 | fileSelector = new ImageFileSelector( cv,stack, "fs"); | 300 | fileSelector = new ImageFileSelector( cv,stack, "fs"); |
286 | 301 | ||
287 | //switchThumbView(); | 302 | //switchThumbView(); |
288 | 303 | ||
289 | 304 | ||
290 | //fileSelector = new ImageFileSelector("image/*", stack, "fs"); | 305 | //fileSelector = new ImageFileSelector("image/*", stack, "fs"); |
291 | //fileSelector->setNewVisible(FALSE); | 306 | //fileSelector->setNewVisible(FALSE); |
292 | //fileSelector->setCloseVisible(FALSE); | 307 | //fileSelector->setCloseVisible(FALSE); |
293 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( closeFileSelector() ) ); | 308 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( closeFileSelector() ) ); |
294 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); | 309 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), |
310 | this, SLOT( openFile( const DocLnk & ) ) ); | ||
311 | |||
312 | imageList = fileSelector->fileList(); | ||
313 | slideAction->setEnabled( imageList.count() != 0); | ||
295 | 314 | ||
296 | iconToolBar = new QPEToolBar(this); | 315 | iconToolBar = new QPEToolBar(this); |
297 | 316 | ||
298 | QAction *a; | 317 | QAction *a; |
299 | 318 | ||
300 | a = new QAction( tr( "Open ..." ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 319 | a = new QAction( tr( "Open ..." ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
301 | connect( a, SIGNAL( activated() ), this, SLOT( open() ) ); | 320 | connect( a, SIGNAL( activated() ), this, SLOT( open() ) ); |
302 | a->addTo( fileMenuView); | 321 | a->addTo( fileMenuView); |
303 | a->addTo( iconToolBar ); | 322 | a->addTo( iconToolBar ); |
304 | 323 | ||
305 | 324 | ||
306 | a = new QAction( tr( "Rotate 90"), Resource::loadPixmap( "rotate90" ), QString::null, 0, this, 0); | 325 | a = new QAction( tr( "Rotate 90"), Resource::loadPixmap( "rotate90" ), QString::null, 0, this, 0); |
@@ -327,84 +346,145 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags ) | |||
327 | viewMenuView->insertSeparator(); | 346 | viewMenuView->insertSeparator(); |
328 | 347 | ||
329 | 348 | ||
330 | sss = new QAction( tr( "Scale to Screen"), Resource::loadPixmap( "scale" ), QString::null, 0, this, 0,true); | 349 | sss = new QAction( tr( "Scale to Screen"), Resource::loadPixmap( "scale" ), QString::null, 0, this, 0,true); |
331 | connect( sss, SIGNAL( activated() ), this, SLOT( switchSizeToScreen() ) ); | 350 | connect( sss, SIGNAL( activated() ), this, SLOT( switchSizeToScreen() ) ); |
332 | sss->addTo( iconToolBar ); | 351 | sss->addTo( iconToolBar ); |
333 | sss->addTo( viewMenuView ); | 352 | sss->addTo( viewMenuView ); |
334 | 353 | ||
335 | sss->setOn(isSized); | 354 | sss->setOn(isSized); |
336 | viewMenuView->insertSeparator(); | 355 | viewMenuView->insertSeparator(); |
337 | 356 | ||
338 | 357 | ||
339 | a = new QAction( tr( "Fullscreen" ), Resource::loadPixmap( "fullscreen" ), QString::null, 0, this, 0 ); | 358 | a = new QAction( tr( "Fullscreen" ), Resource::loadPixmap( "fullscreen" ), |
359 | QString::null, 0, this, 0 ); | ||
340 | connect( a, SIGNAL( activated() ), this, SLOT( fullScreen() ) ); | 360 | connect( a, SIGNAL( activated() ), this, SLOT( fullScreen() ) ); |
341 | a->addTo( iconToolBar ); | 361 | a->addTo( iconToolBar ); |
342 | a->addTo( viewMenuView); | 362 | a->addTo( viewMenuView); |
343 | 363 | ||
364 | a = new QAction( tr( "Stop Slideshow" ), Resource::loadPixmap( "quit_icon" ), | ||
365 | QString::null, 0, this, 0 ); | ||
366 | connect( a, SIGNAL( activated() ), this, SLOT( stopSlideShow() ) ); | ||
367 | a->addTo( iconToolBar ); | ||
368 | a->addTo( viewMenuView); | ||
369 | |||
370 | |||
371 | Config config( "ImageViewer" ); | ||
372 | config.setGroup( "SlideShow" ); | ||
373 | slideDelay = config.readNumEntry( "Delay", 2); | ||
374 | slideRepeat = config.readBoolEntry( "Repeat", FALSE ); | ||
375 | slideReverse = config.readBoolEntry("Reverse", FALSE); | ||
376 | |||
377 | config.setGroup("Default"); | ||
378 | rotateOnLoad = config.readBoolEntry("Rotate", FALSE); | ||
379 | fastLoad = config.readBoolEntry("FastLoad", TRUE); | ||
380 | slideTimer = new QTimer( this ); | ||
381 | connect( slideTimer, SIGNAL(timeout()), this, SLOT(slideUpdate()) ); | ||
382 | |||
344 | switchToFileSelector(); | 383 | switchToFileSelector(); |
345 | 384 | ||
346 | setMouseTracking( TRUE ); | 385 | setMouseTracking( TRUE ); |
347 | 386 | ||
348 | 387 | ||
349 | } | 388 | } |
350 | 389 | ||
351 | ImageViewer::~ImageViewer() | 390 | ImageViewer::~ImageViewer() |
352 | { | 391 | { |
353 | Config cfg("Image Viewer"); | 392 | Config cfg("Image Viewer"); |
354 | cfg.setGroup("Image Viewer"); | 393 | cfg.setGroup("Image Viewer"); |
355 | 394 | ||
356 | cfg.writeEntry("ShowThumbnails",(int)showThumbView); | 395 | cfg.writeEntry("ShowThumbnails",(int)showThumbView); |
357 | cfg.writeEntry("SizeToScreen",(int)isSized); | 396 | cfg.writeEntry("SizeToScreen",(int)isSized); |
358 | 397 | ||
398 | cfg.setGroup( "SlideShow" ); | ||
399 | cfg.writeEntry( "Delay", slideDelay); | ||
400 | cfg.writeEntry( "Repeat", slideRepeat ); | ||
401 | cfg.writeEntry("Reverse", slideReverse); | ||
402 | |||
403 | cfg.setGroup("Default"); | ||
404 | cfg.writeEntry("Rotate", rotateOnLoad); | ||
405 | cfg.writeEntry("FastLoad", fastLoad); | ||
406 | |||
359 | delete imagePanel; // in case it is fullscreen | 407 | delete imagePanel; // in case it is fullscreen |
360 | } | 408 | } |
361 | 409 | ||
410 | void ImageViewer::help() { | ||
411 | |||
412 | } | ||
413 | |||
414 | |||
415 | void ImageViewer::settings() | ||
416 | { | ||
417 | SettingsDialog dlg( this, 0, TRUE ); | ||
418 | dlg.setDelay( slideDelay ); | ||
419 | dlg.setRepeat( slideRepeat ); | ||
420 | dlg.setReverse( slideReverse ); | ||
421 | dlg.setRotate(rotateOnLoad); | ||
422 | dlg.setFastLoad(fastLoad); | ||
423 | |||
424 | if ( QPEApplication::execDialog(&dlg) == QDialog::Accepted ) { | ||
425 | qDebug("<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>"); | ||
426 | slideDelay = dlg.delay(); | ||
427 | slideRepeat = dlg.repeat(); | ||
428 | slideReverse = dlg.reverse(); | ||
429 | rotateOnLoad = dlg.rotate(); | ||
430 | fastLoad = dlg.fastLoad(); | ||
431 | |||
432 | Config config( "ImageViewer" ); | ||
433 | config.setGroup( "SlideShow" ); | ||
434 | config.writeEntry( "Delay", slideDelay ); | ||
435 | config.writeEntry( "Repeat", slideRepeat ); | ||
436 | config.writeEntry("Reverse", slideReverse); | ||
437 | |||
438 | config.setGroup("Default"); | ||
439 | config.writeEntry("Rotate", rotateOnLoad); | ||
440 | config.writeEntry("FastLoad", fastLoad); | ||
441 | } | ||
442 | } | ||
443 | |||
362 | void ImageViewer::switchSizeToScreen() | 444 | void ImageViewer::switchSizeToScreen() |
363 | { | 445 | { |
364 | isSized=!isSized; | 446 | isSized=!isSized; |
365 | sss->setOn(isSized); | 447 | sss->setOn(isSized); |
366 | updateImage(); | 448 | updateImage(); |
367 | } | 449 | } |
368 | 450 | ||
369 | void ImageViewer::updateImage() | 451 | void ImageViewer::updateImage() |
370 | { | 452 | { |
371 | if ( isSized ) | 453 | if ( isSized ) { |
372 | { | ||
373 | imagePanel->setPixmap(pmScaled); | 454 | imagePanel->setPixmap(pmScaled); |
374 | } | 455 | } else { |
375 | else | ||
376 | { | ||
377 | imagePanel->setPixmap(pm); | 456 | imagePanel->setPixmap(pm); |
378 | } | 457 | } |
379 | } | 458 | } |
380 | 459 | ||
381 | void ImageViewer::switchThumbView() | 460 | void ImageViewer::switchThumbView() |
382 | { | 461 | { |
383 | 462 | ||
384 | showThumbView=!showThumbView; | 463 | showThumbView=!showThumbView; |
385 | viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView ); | 464 | viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView ); |
386 | fileSelector->switchView(); | 465 | fileSelector->switchView(); |
387 | 466 | ||
388 | } | 467 | } |
389 | 468 | ||
390 | void ImageViewer::switchToFileSelector() | 469 | void ImageViewer::switchToFileSelector() |
391 | { | 470 | { |
392 | stack->raiseWidget(fileSelector); | 471 | stack->raiseWidget(fileSelector); |
393 | menuBar->clear(); | 472 | menuBar->clear(); |
394 | menuBar->insertItem( tr("File"), fileMenuFile ); | 473 | menuBar->insertItem( tr("File"), fileMenuFile ); |
395 | menuBar->insertItem( tr("View"), viewMenuFile ); | 474 | menuBar->insertItem( tr("View"), viewMenuFile ); |
396 | menuBar->insertItem( tr("Options"), optionsMenuFile ); | 475 | menuBar->insertItem( tr("Options"), optionsMenuFile ); |
397 | iconToolBar->hide(); | 476 | iconToolBar->hide(); |
398 | imagePanel->disable(); | 477 | imagePanel->disable(); |
478 | slideShow(false); | ||
399 | 479 | ||
400 | } | 480 | } |
401 | 481 | ||
402 | void ImageViewer::switchToImageView() | 482 | void ImageViewer::switchToImageView() |
403 | { | 483 | { |
404 | stack->raiseWidget(imagePanel); | 484 | stack->raiseWidget(imagePanel); |
405 | 485 | ||
406 | menuBar->clear(); | 486 | menuBar->clear(); |
407 | menuBar->insertItem( tr("File"), fileMenuView ); | 487 | menuBar->insertItem( tr("File"), fileMenuView ); |
408 | menuBar->insertItem( tr("View"), viewMenuView ); | 488 | menuBar->insertItem( tr("View"), viewMenuView ); |
409 | viewMenuView->setItemEnabled(BLACKANDWHITE,true); | 489 | viewMenuView->setItemEnabled(BLACKANDWHITE,true); |
410 | iconToolBar->show(); | 490 | iconToolBar->show(); |
@@ -425,45 +505,61 @@ void ImageViewer::doDelayedLoad() | |||
425 | { | 505 | { |
426 | show(delayLoad); | 506 | show(delayLoad); |
427 | } | 507 | } |
428 | 508 | ||
429 | void ImageViewer::show() | 509 | void ImageViewer::show() |
430 | { | 510 | { |
431 | normalView(); | 511 | normalView(); |
432 | QMainWindow::show(); | 512 | QMainWindow::show(); |
433 | } | 513 | } |
434 | 514 | ||
435 | void ImageViewer::show(const QString& fileref) | 515 | void ImageViewer::show(const QString& fileref) |
436 | { | 516 | { |
517 | // qDebug("Show "+fileref); | ||
437 | bFromDocView = TRUE; | 518 | bFromDocView = TRUE; |
438 | closeFileSelector(); | 519 | closeFileSelector(); |
439 | DocLnk link(fileref); | 520 | DocLnk link(fileref); |
440 | if ( link.isValid() ) | 521 | if ( link.isValid() ) { |
441 | { | ||
442 | openFile(link); | 522 | openFile(link); |
443 | } | 523 | } else { |
444 | else | ||
445 | { | ||
446 | filename = fileref; | 524 | filename = fileref; |
447 | updateCaption( fileref ); | 525 | updateCaption( fileref ); |
448 | loadImage( fileref ); | 526 | loadImage( fileref ); |
449 | } | 527 | } |
450 | } | 528 | } |
451 | 529 | ||
452 | void ImageViewer::openFile( const DocLnk &file ) | 530 | void ImageViewer::openFile() { |
531 | MimeTypes types; | ||
532 | QStringList image; | ||
533 | image << "image/*"; | ||
534 | types.insert("Images", image); | ||
535 | |||
536 | QString str = OFileDialog::getOpenFileName( 1,QPEApplication::documentDir(),"", types, 0 ); | ||
537 | DocLnk link(str); | ||
538 | if ( link.isValid() ) | ||
539 | openFile(link); | ||
540 | |||
541 | } | ||
542 | |||
543 | void ImageViewer::openFile( const DocLnk &link ) | ||
453 | { | 544 | { |
454 | closeFileSelector(); | 545 | closeFileSelector(); |
455 | DocLnk link(file); | 546 | // DocLnk link(file); |
547 | qDebug("open "+link.name()); | ||
456 | updateCaption( link.name() ); | 548 | updateCaption( link.name() ); |
457 | loadImage( link.file() ); | 549 | loadImage( link.file() ); |
550 | if (slideTimer->isActive()) { | ||
551 | slideTimer->start(slideDelay * 1000, FALSE); | ||
552 | } | ||
553 | |||
458 | } | 554 | } |
459 | 555 | ||
460 | void ImageViewer::open() | 556 | void ImageViewer::open() |
461 | { | 557 | { |
462 | switchToFileSelector(); | 558 | switchToFileSelector(); |
463 | } | 559 | } |
464 | 560 | ||
465 | void ImageViewer::closeFileSelector() | 561 | void ImageViewer::closeFileSelector() |
466 | { | 562 | { |
467 | switchToImageView(); | 563 | switchToImageView(); |
468 | } | 564 | } |
469 | 565 | ||
@@ -473,42 +569,53 @@ void ImageViewer::updateCaption( QString name ) | |||
473 | if ( sep >= 0 ) | 569 | if ( sep >= 0 ) |
474 | name = name.mid( sep+1 ); | 570 | name = name.mid( sep+1 ); |
475 | setCaption( name + tr(" - Image Viewer") ); | 571 | setCaption( name + tr(" - Image Viewer") ); |
476 | } | 572 | } |
477 | 573 | ||
478 | /* | 574 | /* |
479 | This function loads an image from a file. | 575 | This function loads an image from a file. |
480 | */ | 576 | */ |
481 | 577 | ||
482 | void ImageViewer::loadImage( const char *fileName ) | 578 | void ImageViewer::loadImage( const char *fileName ) |
483 | { | 579 | { |
484 | filename = fileName; | 580 | filename = fileName; |
485 | if ( filename ) | 581 | if ( filename ) { |
486 | { | ||
487 | QApplication::setOverrideCursor( waitCursor ); // this might take time | 582 | QApplication::setOverrideCursor( waitCursor ); // this might take time |
488 | //imagePanel->statusLabel()->setText( tr("Loading image...") ); | 583 | //imagePanel->statusLabel()->setText( tr("Loading image...") ); |
489 | qApp->processEvents(); | 584 | qApp->processEvents(); |
490 | bool ok = image.load(filename, 0); | 585 | bool ok = image.load(filename, 0); |
491 | if ( ok ) | 586 | if ( ok ) { |
492 | { | ||
493 | ok = reconvertImage(); | 587 | ok = reconvertImage(); |
494 | updateImageInfo(filename); | 588 | updateImageInfo(filename); |
495 | } | 589 | } |
496 | if ( !ok ) | 590 | if ( !ok ) { |
497 | { | ||
498 | pm.resize(0,0); // couldn't load image | 591 | pm.resize(0,0); // couldn't load image |
499 | update(); | 592 | update(); |
500 | } | 593 | } |
501 | QApplication::restoreOverrideCursor(); // restore original cursor | 594 | QApplication::restoreOverrideCursor(); // restore original cursor |
502 | } | 595 | } |
596 | |||
597 | // fastLoad ? ", Fast" : "", | ||
598 | // fastLoad ? QMAX(imagewidth/maxsize, imageheight/maxsize) : 1); | ||
599 | |||
600 | |||
601 | // matrix.reset(); | ||
602 | rotated90 = FALSE; | ||
603 | |||
604 | if (rotateOnLoad) { | ||
605 | rotated90 = TRUE; | ||
606 | rot90(); | ||
607 | // matrix.rotate( -90.0 ); | ||
608 | } | ||
609 | |||
503 | switchToImageView(); | 610 | switchToImageView(); |
504 | updateImage(); | 611 | updateImage(); |
505 | 612 | ||
506 | } | 613 | } |
507 | 614 | ||
508 | bool ImageViewer::loadSelected() | 615 | bool ImageViewer::loadSelected() |
509 | { | 616 | { |
510 | bool ok = false; | 617 | bool ok = false; |
511 | if ( stack->visibleWidget() == fileSelector ) | 618 | if ( stack->visibleWidget() == fileSelector ) |
512 | { | 619 | { |
513 | const DocLnk *link = fileSelector->selected(); | 620 | const DocLnk *link = fileSelector->selected(); |
514 | if ( link ) | 621 | if ( link ) |
@@ -610,79 +717,81 @@ void ImageViewer::resizeEvent( QResizeEvent * ) | |||
610 | 717 | ||
611 | if ( imagePanel->paneWidth() != pmScaled.width() || h != pmScaled.height() ) | 718 | if ( imagePanel->paneWidth() != pmScaled.width() || h != pmScaled.height() ) |
612 | { // if new size, | 719 | { // if new size, |
613 | scale(); // scale pmScaled to window | 720 | scale(); // scale pmScaled to window |
614 | } | 721 | } |
615 | if ( image.hasAlphaBuffer() ) | 722 | if ( image.hasAlphaBuffer() ) |
616 | erase(); | 723 | erase(); |
617 | } | 724 | } |
618 | 725 | ||
619 | 726 | ||
620 | void ImageViewer::hFlip() | 727 | void ImageViewer::hFlip() |
621 | { | 728 | { |
729 | // matrix.scale( -1.0, 1.0 ); | ||
730 | |||
622 | setImage(image.mirror(TRUE,FALSE)); | 731 | setImage(image.mirror(TRUE,FALSE)); |
623 | } | 732 | } |
624 | 733 | ||
625 | void ImageViewer::vFlip() | 734 | void ImageViewer::vFlip() |
626 | { | 735 | { |
736 | // matrix.scale( 1.0, -1.0 ); | ||
627 | setImage(image.mirror(FALSE,TRUE)); | 737 | setImage(image.mirror(FALSE,TRUE)); |
628 | } | 738 | } |
629 | 739 | ||
630 | void ImageViewer::rot180() | 740 | void ImageViewer::rot180() |
631 | { | 741 | { |
632 | 742 | // matrix.rotate( 180.0 ); | |
633 | setImage(image.mirror(TRUE,TRUE)); | 743 | setImage(image.mirror(TRUE,TRUE)); |
634 | } | 744 | } |
635 | 745 | ||
636 | void ImageViewer::rot90() | 746 | void ImageViewer::rot90() |
637 | { | 747 | { |
638 | QImage oldimage; | 748 | QImage oldimage; |
639 | oldimage = image.convertDepth(32); | 749 | oldimage = image.convertDepth(32); |
750 | // matrix.rotate( -90.0 ); | ||
640 | setImage(rotate(oldimage,Rotate90)); | 751 | setImage(rotate(oldimage,Rotate90)); |
641 | 752 | ||
642 | } | 753 | } |
643 | void ImageViewer::rot270() | 754 | void ImageViewer::rot270() |
644 | { | 755 | { |
645 | 756 | ||
646 | QImage oldimage; | 757 | QImage oldimage; |
647 | oldimage = image.convertDepth(32); | 758 | oldimage = image.convertDepth(32); |
759 | // matrix.rotate(90.0); | ||
648 | setImage(rotate(oldimage,Rotate270)); | 760 | setImage(rotate(oldimage,Rotate270)); |
649 | 761 | ||
650 | } | 762 | } |
651 | 763 | ||
652 | void ImageViewer::blackAndWhite() | 764 | void ImageViewer::blackAndWhite() |
653 | { | 765 | { |
654 | 766 | ||
655 | viewMenuView->setItemEnabled(BLACKANDWHITE,false); | 767 | viewMenuView->setItemEnabled(BLACKANDWHITE,false); |
656 | setImage(toGray(image,false)); | 768 | setImage(toGray(image,false)); |
657 | |||
658 | |||
659 | } | 769 | } |
660 | 770 | ||
661 | void ImageViewer::displayControlsDialog() | 771 | void ImageViewer::displayControlsDialog() |
662 | { | 772 | { |
663 | int w=80; | 773 | int w=80; |
664 | int h=w; | 774 | int h=w; |
665 | QImage small; | 775 | QImage small; |
666 | 776 | ||
667 | if ( image.width()<w ||image.height()<h ) | 777 | if ( image.width()<w ||image.height()<h ) |
668 | small=image.smoothScale(w,h); | 778 | small=image.smoothScale(w,h); |
669 | else | 779 | else |
670 | small=image.copy(0,0,w,h); | 780 | small=image.copy(0,0,w,h); |
671 | 781 | ||
672 | int newB=0; | 782 | int newB=0; |
673 | ControlsDialog *dlg=new ControlsDialog("Image Viewer",small,&newB,this); | 783 | ControlsDialog *dlg=new ControlsDialog("Image Viewer",small,&newB,this); |
674 | dlg->exec(); | 784 | dlg->exec(); |
675 | if ( newB ) | 785 | if ( newB ) { |
676 | { | ||
677 | intensity(image,(float)newB/100); | 786 | intensity(image,(float)newB/100); |
678 | setImage(image); | 787 | setImage(image); |
679 | } | 788 | } |
680 | 789 | ||
681 | } | 790 | } |
682 | 791 | ||
683 | 792 | ||
684 | void ImageViewer::displayInfoDialog() | 793 | void ImageViewer::displayInfoDialog() |
685 | { | 794 | { |
686 | 795 | ||
687 | QStringList ls; | 796 | QStringList ls; |
688 | 797 | ||
@@ -698,24 +807,29 @@ void ImageViewer::normalView() | |||
698 | 807 | ||
699 | isFullScreen = FALSE; | 808 | isFullScreen = FALSE; |
700 | stack->addWidget( imagePanel, 1 ); | 809 | stack->addWidget( imagePanel, 1 ); |
701 | switchToImageView(); | 810 | switchToImageView(); |
702 | if ( isSized ) | 811 | if ( isSized ) |
703 | scale(); | 812 | scale(); |
704 | 813 | ||
705 | updateImage(); | 814 | updateImage(); |
706 | 815 | ||
707 | } | 816 | } |
708 | } | 817 | } |
709 | 818 | ||
819 | void ImageViewer::stopSlideShow() { | ||
820 | if (slideTimer->isActive()) | ||
821 | slideTimer->stop(); | ||
822 | } | ||
823 | |||
710 | void ImageViewer::fullScreen() | 824 | void ImageViewer::fullScreen() |
711 | { | 825 | { |
712 | // Full-screen option | 826 | // Full-screen option |
713 | // contributed by Robert Wittams <robert@wittams.com> | 827 | // contributed by Robert Wittams <robert@wittams.com> |
714 | if ( imagePanel->parentWidget() && loadSelected() ) | 828 | if ( imagePanel->parentWidget() && loadSelected() ) |
715 | { | 829 | { |
716 | isFullScreen = TRUE; | 830 | isFullScreen = TRUE; |
717 | imagePanel->reparent(0,QPoint(0,0)); | 831 | imagePanel->reparent(0,QPoint(0,0)); |
718 | imagePanel->resize(qApp->desktop()->width(), qApp->desktop()->height()); | 832 | imagePanel->resize(qApp->desktop()->width(), qApp->desktop()->height()); |
719 | 833 | ||
720 | if ( isSized ) | 834 | if ( isSized ) |
721 | scale(); | 835 | scale(); |
@@ -1025,20 +1139,111 @@ QImage ImageViewer::rotate(QImage &img, RotateDirection r) | |||
1025 | destData = (unsigned char *)dest.scanLine(img.width()-x-1); | 1139 | destData = (unsigned char *)dest.scanLine(img.width()-x-1); |
1026 | destData[y] = srcData[x]; | 1140 | destData[y] = srcData[x]; |
1027 | } | 1141 | } |
1028 | } | 1142 | } |
1029 | break; | 1143 | break; |
1030 | default: | 1144 | default: |
1031 | dest = img; | 1145 | dest = img; |
1032 | break; | 1146 | break; |
1033 | } | 1147 | } |
1034 | 1148 | ||
1035 | } | 1149 | } |
1036 | return (dest); | 1150 | return (dest); |
1151 | } | ||
1152 | |||
1153 | void ImageViewer::slideShow( bool on ) | ||
1154 | { | ||
1155 | if (on) { | ||
1156 | if (!imageList.isEmpty()) { | ||
1157 | slideTimer->start(slideDelay * 1000, FALSE); | ||
1158 | filename = ""; // force restart | ||
1159 | slideReverse ? prevImage() : nextImage(); | ||
1160 | } | ||
1161 | } else { | ||
1162 | slideTimer->stop(); | ||
1163 | slideAction->setOn( false); | ||
1164 | } | ||
1165 | } | ||
1166 | |||
1167 | void ImageViewer::slideUpdate() | ||
1168 | { | ||
1169 | bool final_image = slideReverse ? prevImage() : nextImage(); | ||
1170 | |||
1171 | if (final_image && !slideRepeat) { | ||
1172 | slideTimer->stop(); | ||
1173 | slideAction->setOn(FALSE); | ||
1174 | } | ||
1175 | } | ||
1037 | 1176 | ||
1177 | // | ||
1178 | // Display the image after the current one in the image list. | ||
1179 | // Return TRUE if the next call to nextImage() will wrap around to the | ||
1180 | // first image in the list (ie. we're now viewing the last image in the list). | ||
1181 | // | ||
1182 | bool ImageViewer::nextImage(void) | ||
1183 | { | ||
1184 | int idx = 0; | ||
1185 | |||
1186 | if (imageList.count() > 0) { | ||
1187 | idx = imageIndex(); | ||
1188 | if (idx != -1) { | ||
1189 | if (idx == int(imageList.count() - 1)) { | ||
1190 | idx = 0; | ||
1191 | } else { | ||
1192 | idx++; | ||
1193 | } | ||
1194 | } else { | ||
1195 | idx = 0; | ||
1196 | } | ||
1197 | openFile(imageList[idx]); | ||
1198 | } | ||
1038 | 1199 | ||
1200 | return idx == int(imageList.count() - 1) ? TRUE : FALSE; | ||
1039 | } | 1201 | } |
1040 | 1202 | ||
1203 | // | ||
1204 | // Display the image preceeding the current one in the image list. | ||
1205 | // Return TRUE if the next call to prevImage() will wrap around to the last | ||
1206 | // image in the list (ie. we're now viewing the first image in the list). | ||
1207 | // | ||
1208 | bool ImageViewer::prevImage(void) | ||
1209 | { | ||
1210 | int idx = -1; | ||
1211 | |||
1212 | if (imageList.count() > 0) { | ||
1213 | idx = imageIndex(); | ||
1214 | if (idx != -1) { | ||
1215 | if (idx == 0) { | ||
1216 | idx = imageList.count() - 1; | ||
1217 | } else { | ||
1218 | idx--; | ||
1219 | } | ||
1220 | } else { | ||
1221 | idx = imageList.count() - 1; | ||
1222 | } | ||
1223 | openFile(imageList[idx]); | ||
1224 | } | ||
1041 | 1225 | ||
1226 | return idx == 0 ? TRUE : FALSE; | ||
1227 | } | ||
1042 | 1228 | ||
1229 | // | ||
1230 | // Return the index into the imageList of the currently viewed | ||
1231 | // image (ie. ImageViewer::filename in ImageViewer::imageList). | ||
1232 | // | ||
1233 | int ImageViewer::imageIndex(void) | ||
1234 | { | ||
1235 | QValueListConstIterator<DocLnk> i; | ||
1236 | int index; | ||
1043 | 1237 | ||
1238 | if (imageList.count() == 0) { | ||
1239 | return -1; | ||
1240 | } | ||
1044 | 1241 | ||
1242 | for (index = 0, i = imageList.begin(); i != imageList.end(); ++i, index++) { | ||
1243 | if ((*i).file() == filename) { | ||
1244 | return index; | ||
1245 | } | ||
1246 | } | ||
1247 | |||
1248 | return -1; | ||
1249 | } | ||