summaryrefslogtreecommitdiff
path: root/noncore/multimedia/showimg/showimg.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/showimg/showimg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/showimg/showimg.cpp279
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
@@ -26,3 +26,8 @@
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>
@@ -51,3 +56,4 @@
51 56
52ControlsDialog::ControlsDialog(const QString &caption,QImage image,int *brightness,QWidget *parent):QDialog(parent,0,true) 57ControlsDialog::ControlsDialog(const QString &caption,QImage image,int *brightness,QWidget *parent)
58 : QDialog(parent,0,true)
53{ 59{
@@ -55,4 +61,3 @@ ControlsDialog::ControlsDialog(const QString &caption,QImage image,int *brightne
55 61
56 if ( parent ) 62 if ( parent ) {
57 {
58 setPalette(parent->palette()); 63 setPalette(parent->palette());
@@ -103,5 +108,6 @@ void ControlsDialog::accept()
103 108
109//===========================================================================
104 110
105 111InfoDialog::InfoDialog(const QString &caption, const QStringList text,QWidget *parent)
106InfoDialog::InfoDialog(const QString &caption, const QStringList text,QWidget *parent):QDialog(parent,0,true) 112 : QDialog(parent,0,true)
107{ 113{
@@ -151,2 +157,4 @@ void InfoDialog::displayInfo(const QString &caption, const QStringList text, QWi
151 157
158//===========================================================================
159
152 160
@@ -231,3 +239,4 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
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
@@ -235,3 +244,4 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
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
@@ -244,9 +254,14 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
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
@@ -293,3 +308,7 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
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
@@ -338,3 +357,4 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
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() ) );
@@ -343,2 +363,21 @@ ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags )
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();
@@ -358,2 +397,11 @@ ImageViewer::~ImageViewer()
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
@@ -361,2 +409,36 @@ ImageViewer::~ImageViewer()
361 409
410void ImageViewer::help() {
411
412}
413
414
415void 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
362void ImageViewer::switchSizeToScreen() 444void ImageViewer::switchSizeToScreen()
@@ -370,8 +452,5 @@ 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);
@@ -398,2 +477,3 @@ void ImageViewer::switchToFileSelector()
398 imagePanel->disable(); 477 imagePanel->disable();
478 slideShow(false);
399 479
@@ -436,2 +516,3 @@ void ImageViewer::show(const QString& fileref)
436{ 516{
517// qDebug("Show "+fileref);
437 bFromDocView = TRUE; 518 bFromDocView = TRUE;
@@ -439,8 +520,5 @@ void ImageViewer::show(const QString& fileref)
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;
@@ -451,8 +529,26 @@ void ImageViewer::show(const QString& fileref)
451 529
452void ImageViewer::openFile( const DocLnk &file ) 530void 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
543void 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}
@@ -484,4 +580,3 @@ void ImageViewer::loadImage( const char *fileName )
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
@@ -490,4 +585,3 @@ void ImageViewer::loadImage( const char *fileName )
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();
@@ -495,4 +589,3 @@ void ImageViewer::loadImage( const char *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
@@ -502,2 +595,16 @@ void ImageViewer::loadImage( const char *fileName )
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();
@@ -621,2 +728,4 @@ 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));
@@ -626,2 +735,3 @@ void ImageViewer::vFlip()
626{ 735{
736// matrix.scale( 1.0, -1.0 );
627 setImage(image.mirror(FALSE,TRUE)); 737 setImage(image.mirror(FALSE,TRUE));
@@ -631,3 +741,3 @@ void ImageViewer::rot180()
631{ 741{
632 742// matrix.rotate( 180.0 );
633 setImage(image.mirror(TRUE,TRUE)); 743 setImage(image.mirror(TRUE,TRUE));
@@ -639,2 +749,3 @@ void ImageViewer::rot90()
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));
@@ -647,2 +758,3 @@ void ImageViewer::rot270()
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));
@@ -656,4 +768,2 @@ void ImageViewer::blackAndWhite()
656 setImage(toGray(image,false)); 768 setImage(toGray(image,false));
657
658
659} 769}
@@ -674,4 +784,3 @@ void ImageViewer::displayControlsDialog()
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);
@@ -709,2 +818,7 @@ void ImageViewer::normalView()
709 818
819void ImageViewer::stopSlideShow() {
820 if (slideTimer->isActive())
821 slideTimer->stop();
822}
823
710void ImageViewer::fullScreen() 824void ImageViewer::fullScreen()
@@ -1036,9 +1150,100 @@ QImage ImageViewer::rotate(QImage &img, RotateDirection r)
1036 return (dest); 1150 return (dest);
1151}
1152
1153void 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
1167void 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//
1182bool 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//
1208bool 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//
1233int 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}