Fix include
[kdeartwork.git] / kscreensaver / kdesavers / slideshow.cpp
blobe8d0392318c9c3d4d87d3701b6651652c1786211
1 /* Slide Show Screen Saver
2 * (C) 1999 Stefan Taferner <taferner@kde.org>
3 * (C) 2001 Martin R. Jones <mjones@kde.org>
4 * (C) 2003 Chris Howells <howells@kde.org>
5 * (C) 2003 Sven Leiber <s.leiber@web.de>
7 * This code is under GPL
9 * 2001/03/04 Converted to libkscreensaver by Martin R. Jones.
13 #include <qdir.h>
14 #include <qcolor.h>
15 #include <qlabel.h>
16 #include <qlayout.h>
17 #include <qfile.h>
18 #include <qcheckbox.h>
19 #include <qcombobox.h>
20 #include <qspinbox.h>
21 #include <qdesktopwidget.h>
22 #include <QImage>
23 #include <QPixmap>
24 #include <QPolygon>
27 #include <kconfig.h>
28 #include <kglobal.h>
29 #include <kapplication.h>
30 #include <klocale.h>
31 #include <kmessagebox.h>
32 #include <kimageio.h>
33 #include <kfiledialog.h>
34 #include <kstandarddirs.h>
35 #include <kurlrequester.h>
36 #include <kaboutdata.h>
37 #include <kaboutapplicationdialog.h>
38 #include <kdebug.h>
39 #include <krandom.h>
41 #include <stdlib.h>
42 #include <assert.h>
43 #include <math.h>
44 #include <time.h>
46 #include "slideshow.h"
47 #include "slideshow.moc"
50 #define SLIDESHOW_VERSION "2.3.0"
51 static const char version[] = SLIDESHOW_VERSION;
52 static const char description[] = I18N_NOOP("KSlideshow");
54 static KAboutData* s_aboutData = 0;
56 // libkscreensaver interface
57 class KSlideShowSaverInterface : public KScreenSaverInterface
59 public:
60 virtual KAboutData* aboutData() {
61 return s_aboutData;
64 virtual KScreenSaver* create( WId id )
66 return new kSlideShowSaver( id );
69 virtual QDialog* setup()
71 return new kSlideShowSetup();
75 int main( int argc, char *argv[] )
77 s_aboutData = new KAboutData( "kslideshow.kss", 0, ki18n("SlideShow"),
78 version, ki18n(description), KAboutData::License_GPL,
79 ki18n("(c) 1999-2003, The KDE Team") );
80 s_aboutData->addAuthor(ki18n("Stefan Taferner"), KLocalizedString(), "taferner@kde.org");
81 s_aboutData->addAuthor(ki18n("Chris Howells"), KLocalizedString(), "howells@kde.org");
82 s_aboutData->addAuthor(ki18n("Sven Leiber"), KLocalizedString(), "s.leiber@web.de");
84 KSlideShowSaverInterface kss;
85 return kScreenSaverMain( argc, argv, kss );
89 //=============================================================================
90 // Class kSlideShowSaver
91 //=============================================================================
92 kSlideShowSaver::kSlideShowSaver( WId id ): KScreenSaver(id)
94 mEffect = NULL;
95 mNumEffects = 0;
96 mIntArray = NULL;
97 registerEffects();
99 readConfig();
100 initNextScreen();
102 mFileIdx = 0;
104 mEffectRunning = false;
106 mTimer.start(10, true);
107 connect(&mTimer, SIGNAL(timeout()), SLOT(slotTimeout()));
109 QDesktopWidget *d = QApplication::desktop();
110 if(geometry() == d->geometry() && d->numScreens() > 1)
112 for(int i = 0; i < d->numScreens(); ++i)
114 QRect s = d->screenGeometry(i);
115 mGeoList.append(mScreenGeo(s.width(), s.height(), s.topLeft().x(), s.topLeft().y()));
118 else
120 mGeoList.append(mScreenGeo(width(), height(), 0, 0));
122 createNextScreen();
126 //----------------------------------------------------------------------------
127 kSlideShowSaver::~kSlideShowSaver()
129 delete [] mIntArray;
130 delete [] mEffectList;
132 mTimer.stop();
133 if (mPainter.isActive()) mPainter.end();
137 //-----------------------------------------------------------------------------
138 void kSlideShowSaver::initNextScreen()
140 int w, h;
142 w = width();
143 h = height();
144 mNextScreen = QPixmap(w, h);
148 //-----------------------------------------------------------------------------
149 void kSlideShowSaver::readConfig()
151 KConfigGroup config(KGlobal::config(), "Settings");
152 mShowRandom = config.readEntry("ShowRandom", true);
153 mZoomImages = config.readEntry("ZoomImages", false);
154 mPrintName = config.readEntry("PrintName", true);
155 mDirectory = config.readPathEntry("Directory", KGlobal::dirs()->findDirs("wallpaper", "").last());
156 mDelay = config.readEntry("Delay", 10) * 1000;
157 mSubdirectory = config.readEntry("SubDirectory", false);
158 mRandomPosition = config.readEntry("RandomPosition", false);
160 loadDirectory();
164 //----------------------------------------------------------------------------
165 void kSlideShowSaver::registerEffects()
167 int i = 0;
169 mEffectList = new EffectMethod[64];
170 mEffectList[i++] = &kSlideShowSaver::effectChessboard;
171 mEffectList[i++] = &kSlideShowSaver::effectMultiCircleOut;
172 mEffectList[i++] = &kSlideShowSaver::effectSpiralIn;
173 mEffectList[i++] = &kSlideShowSaver::effectSweep;
174 mEffectList[i++] = &kSlideShowSaver::effectMeltdown;
175 mEffectList[i++] = &kSlideShowSaver::effectCircleOut;
176 mEffectList[i++] = &kSlideShowSaver::effectBlobs;
177 mEffectList[i++] = &kSlideShowSaver::effectHorizLines;
178 mEffectList[i++] = &kSlideShowSaver::effectVertLines;
179 mEffectList[i++] = &kSlideShowSaver::effectRandom;
180 mEffectList[i++] = &kSlideShowSaver::effectGrowing;
181 mEffectList[i++] = &kSlideShowSaver::effectIncomingEdges;
183 mNumEffects = i;
184 // mNumEffects = 1; //...for testing
188 //----------------------------------------------------------------------------
189 int kSlideShowSaver::effectMultiCircleOut(bool aInit)
191 int x, y, i;
192 double alpha;
193 static QPolygon pa(4);
195 if (aInit)
197 startPainter();
198 mw = width();
199 mh = height();
200 mx = mw;
201 my = mh>>1;
202 pa.setPoint(0, mw>>1, mh>>1);
203 pa.setPoint(3, mw>>1, mh>>1);
204 mfy = sqrt((double)mw*mw + mh*mh) / 2;
205 mi = KRandom::random()%15 + 2;
206 mfd = M_PI*2/mi;
207 mAlpha = mfd;
208 mwait = 10 * mi;
209 mfx = M_PI/32; // divisor must be powers of 8
212 if (mAlpha < 0)
214 mPainter.end();
215 showNextScreen();
216 return -1;
219 for (alpha=mAlpha, i=mi; i>=0; i--, alpha+=mfd)
221 x = (mw>>1) + (int)(mfy * cos(-alpha));
222 y = (mh>>1) + (int)(mfy * sin(-alpha));
224 mx = (mw>>1) + (int)(mfy * cos(-alpha + mfx));
225 my = (mh>>1) + (int)(mfy * sin(-alpha + mfx));
227 pa.setPoint(1, x, y);
228 pa.setPoint(2, mx, my);
230 mPainter.drawPolygon(pa);
232 mAlpha -= mfx;
234 return mwait;
238 //----------------------------------------------------------------------------
239 int kSlideShowSaver::effectSpiralIn(bool aInit)
241 if (aInit)
243 startPainter();
244 mw = width();
245 mh = height();
246 mix = mw / 8;
247 miy = mh / 8;
248 mx0 = 0;
249 mx1 = mw - mix;
250 my0 = miy;
251 my1 = mh - miy;
252 mdx = mix;
253 mdy = 0;
254 mi = 0;
255 mj = 16 * 16;
256 mx = 0;
257 my = 0;
260 if (mi==0 && mx0>=mx1)
262 mPainter.end();
263 showNextScreen();
264 return -1;
267 if (mi==0 && mx>=mx1) // switch to: down on right side
269 mi = 1;
270 mdx = 0;
271 mdy = miy;
272 mx1 -= mix;
274 else if (mi==1 && my>=my1) // switch to: right to left on bottom side
276 mi = 2;
277 mdx = -mix;
278 mdy = 0;
279 my1 -= miy;
281 else if (mi==2 && mx<=mx0) // switch to: up on left side
283 mi = 3;
284 mdx = 0;
285 mdy = -miy;
286 mx0 += mix;
288 else if (mi==3 && my<=my0) // switch to: left to right on top side
290 mi = 0;
291 mdx = mix;
292 mdy = 0;
293 my0 += miy;
296 bitBlt(this, mx, my, &mNextScreen, mx, my, mix, miy);
298 mx += mdx;
299 my += mdy;
300 mj--;
302 return 8;
306 //----------------------------------------------------------------------------
307 int kSlideShowSaver::effectMeltdown(bool aInit)
309 int i, x, y;
310 bool done;
312 if (aInit)
314 delete [] mIntArray;
315 mw = width();
316 mh = height();
317 mdx = 4;
318 mdy = 16;
319 mix = mw / mdx;
320 mIntArray = new int[mix];
321 for (i=mix-1; i>=0; i--)
322 mIntArray[i] = 0;
325 done = true;
326 for (i=0,x=0; i<mix; i++,x+=mdx)
328 y = mIntArray[i];
329 if (y >= mh) continue;
330 done = false;
331 if ((KRandom::random()&15) < 6) continue;
332 bitBlt(this, x, y+mdy, this, x, y, mdx, mh-y-mdy);
333 bitBlt(this, x, y, &mNextScreen, x, y, mdx, mdy);
334 mIntArray[i] += mdy;
337 if (done)
339 delete [] mIntArray;
340 mIntArray = NULL;
341 return -1;
344 return 15;
348 //----------------------------------------------------------------------------
349 int kSlideShowSaver::effectCircleOut(bool aInit)
351 int x, y;
352 static QPolygon pa(4);
354 if (aInit)
356 startPainter();
357 mw = width();
358 mh = height();
359 mx = mw;
360 my = mh>>1;
361 mAlpha = 2*M_PI;
362 pa.setPoint(0, mw>>1, mh>>1);
363 pa.setPoint(3, mw>>1, mh>>1);
364 mfx = M_PI/16; // divisor must be powers of 8
365 mfy = sqrt((double)mw*mw + mh*mh) / 2;
368 if (mAlpha < 0)
370 mPainter.end();
371 showNextScreen();
372 return -1;
375 x = mx;
376 y = my;
377 mx = (mw>>1) + (int)(mfy * cos(mAlpha));
378 my = (mh>>1) + (int)(mfy * sin(mAlpha));
379 mAlpha -= mfx;
381 pa.setPoint(1, x, y);
382 pa.setPoint(2, mx, my);
384 mPainter.drawPolygon(pa);
386 return 20;
390 //----------------------------------------------------------------------------
391 int kSlideShowSaver::effectSweep(bool aInit)
393 int w, h, x, y, i;
395 if (aInit)
397 // subtype: 0=sweep right to left, 1=sweep left to right
398 // 2=sweep bottom to top, 3=sweep top to bottom
399 mSubType = KRandom::random() % 4;
400 mw = width();
401 mh = height();
402 mdx = (mSubType==1 ? 16 : -16);
403 mdy = (mSubType==3 ? 16 : -16);
404 mx = (mSubType==1 ? 0 : mw);
405 my = (mSubType==3 ? 0 : mh);
408 if (mSubType==0 || mSubType==1)
410 // horizontal sweep
411 if ((mSubType==0 && mx < -64) ||
412 (mSubType==1 && mx > mw+64))
414 return -1;
416 for (w=2,i=4,x=mx; i>0; i--, w<<=1, x-=mdx)
418 bitBlt(this, x, 0, &mNextScreen, x, 0, w, mh);
420 mx += mdx;
422 else
424 // vertical sweep
425 if ((mSubType==2 && my < -64) ||
426 (mSubType==3 && my > mh+64))
428 return -1;
430 for (h=2,i=4,y=my; i>0; i--, h<<=1, y-=mdy)
432 bitBlt(this, 0, y, &mNextScreen, 0, y, mw, h);
434 my += mdy;
437 return 20;
441 //----------------------------------------------------------------------------
442 int kSlideShowSaver::effectBlobs(bool aInit)
444 int r;
446 if (aInit)
448 startPainter();
449 mAlpha = M_PI * 2;
450 mw = width();
451 mh = height();
452 mi = 150;
455 if (mi <= 0)
457 mPainter.end();
458 showNextScreen();
459 return -1;
462 mx = KRandom::random() % mw;
463 my = KRandom::random() % mh;
464 r = (KRandom::random() % 200) + 50;
466 mPainter.drawEllipse(mx-r, my-r, r, r);
467 mi--;
469 return 10;
473 //----------------------------------------------------------------------------
474 int kSlideShowSaver::effectRandom(bool /*aInit*/)
476 int x, y, i, w, h, fact, sz;
478 fact = (KRandom::random() % 3) + 1;
480 w = width() >> fact;
481 h = height() >> fact;
482 sz = 1 << fact;
484 for (i = (w*h)<<1; i > 0; i--)
486 x = (KRandom::random() % w) << fact;
487 y = (KRandom::random() % h) << fact;
488 bitBlt(this, x, y, &mNextScreen, x, y, sz, sz);
490 showNextScreen();
492 return -1;
496 //----------------------------------------------------------------------------
497 int kSlideShowSaver::effectGrowing(bool aInit)
499 if (aInit)
501 mw = width();
502 mh = height();
503 mx = mw >> 1;
504 my = mh >> 1;
505 mi = 0;
506 mfx = mx / 100.0;
507 mfy = my / 100.0;
510 mx = (mw>>1) - (int)(mi * mfx);
511 my = (mh>>1) - (int)(mi * mfy);
512 mi++;
514 if (mx<0 || my<0)
516 showNextScreen();
517 return -1;
520 bitBlt(this, mx, my, &mNextScreen, mx, my,
521 mw - (mx<<1), mh - (my<<1));
523 return 20;
527 //----------------------------------------------------------------------------
528 int kSlideShowSaver::effectChessboard(bool aInit)
530 int y;
532 if (aInit)
534 mw = width();
535 mh = height();
536 mdx = 8; // width of one tile
537 mdy = 8; // height of one tile
538 mj = (mw+mdx-1)/mdx; // number of tiles
539 mx = mj*mdx; // shrinking x-offset from screen border
540 mix = 0; // growing x-offset from screen border
541 miy = 0; // 0 or mdy for growing tiling effect
542 my = mj&1 ? 0 : mdy; // 0 or mdy for shrinking tiling effect
543 mwait = 800 / mj; // timeout between effects
546 if (mix >= mw)
548 showNextScreen();
549 return -1;
552 mix += mdx;
553 mx -= mdx;
554 miy = miy ? 0 : mdy;
555 my = my ? 0 : mdy;
557 for (y=0; y<mw; y+=(mdy<<1))
559 bitBlt(this, mix, y+miy, &mNextScreen, mix, y+miy,
560 mdx, mdy);
561 bitBlt(this, mx, y+my, &mNextScreen, mx, y+my,
562 mdx, mdy);
565 return mwait;
569 //----------------------------------------------------------------------------
570 int kSlideShowSaver::effectIncomingEdges(bool aInit)
572 int x1, y1;
574 if (aInit)
576 mw = width();
577 mh = height();
578 mix = mw >> 1;
579 miy = mh >> 1;
580 mfx = mix / 100.0;
581 mfy = miy / 100.0;
582 mi = 0;
583 mSubType = KRandom::random() & 1;
586 mx = (int)(mfx * mi);
587 my = (int)(mfy * mi);
589 if (mx>mix || my>miy)
591 showNextScreen();
592 return -1;
595 x1 = mw - mx;
596 y1 = mh - my;
597 mi++;
599 if (mSubType)
601 // moving image edges
602 bitBlt(this, 0, 0, &mNextScreen, mix-mx, miy-my, mx, my);
603 bitBlt(this, x1, 0, &mNextScreen, mix, miy-my, mx, my);
604 bitBlt(this, 0, y1, &mNextScreen, mix-mx, miy, mx, my);
605 bitBlt(this, x1, y1, &mNextScreen, mix, miy, mx, my);
607 else
609 // fixed image edges
610 bitBlt(this, 0, 0, &mNextScreen, 0, 0, mx, my);
611 bitBlt(this, x1, 0, &mNextScreen, x1, 0, mx, my);
612 bitBlt(this, 0, y1, &mNextScreen, 0, y1, mx, my);
613 bitBlt(this, x1, y1, &mNextScreen, x1, y1, mx, my);
615 return 20;
619 //----------------------------------------------------------------------------
620 int kSlideShowSaver::effectHorizLines(bool aInit)
622 static int iyPos[] = { 0, 4, 2, 6, 1, 5, 3, 7, -1 };
623 int y;
625 if (aInit)
627 mw = width();
628 mh = height();
629 mi = 0;
632 if (iyPos[mi] < 0) return -1;
634 for (y=iyPos[mi]; y<mh; y+=8)
636 bitBlt(this, 0, y, &mNextScreen, 0, y, mw, 1);
639 mi++;
640 if (iyPos[mi] >= 0) return 160;
641 return -1;
645 //----------------------------------------------------------------------------
646 int kSlideShowSaver::effectVertLines(bool aInit)
648 static int ixPos[] = { 0, 4, 2, 6, 1, 5, 3, 7, -1 };
649 int x;
651 if (aInit)
653 mw = width();
654 mh = height();
655 mi = 0;
658 if (ixPos[mi] < 0) return -1;
660 for (x=ixPos[mi]; x<mw; x+=8)
662 bitBlt(this, x, 0, &mNextScreen, x, 0, 1, mh);
665 mi++;
666 if (ixPos[mi] >= 0) return 160;
667 return -1;
671 //-----------------------------------------------------------------------------
672 void kSlideShowSaver::startPainter(Qt::PenStyle aPen)
674 QBrush brush;
675 brush.setPixmap(mNextScreen);
676 if (mPainter.isActive()) mPainter.end();
677 mPainter.begin(this);
678 mPainter.setBrush(brush);
679 mPainter.setPen(aPen);
683 //-----------------------------------------------------------------------------
684 void kSlideShowSaver::restart()
686 mEffectRunning = false;
687 mEffect = NULL;
688 blank();
689 slotTimeout();
693 //-----------------------------------------------------------------------------
694 void kSlideShowSaver::slotTimeout()
696 int tmout = -1;
697 int i;
699 if (mEffectRunning)
701 tmout = (this->*mEffect)(false);
703 else
705 loadNextImage();
706 createNextScreen();
708 if (mNumEffects > 1) i = KRandom::random() % mNumEffects;
709 else i = 0;
711 mEffect = mEffectList[i];
712 mEffectRunning = true;
713 tmout = (this->*mEffect)(true);
715 if (tmout <= 0)
717 tmout = mDelay;
718 mEffectRunning = false;
720 mTimer.start(tmout, true);
724 //----------------------------------------------------------------------------
725 void kSlideShowSaver::showNextScreen()
727 bitBlt(this, 0, 0, &mNextScreen, 0, 0,
728 mNextScreen.width(), mNextScreen.height());
732 //----------------------------------------------------------------------------
733 void kSlideShowSaver::createNextScreen()
735 QPainter p;
736 int ww, wh, iw, ih, x, y;
737 double fx, fy;
739 if (mNextScreen.size() != size())
740 mNextScreen.resize(size());
742 mNextScreen.fill(Qt::black);
744 p.begin(&mNextScreen);
746 foreach( const mScreenGeo& geo, mGeoList )
748 loadNextImage();
750 iw = mImage.width();
751 ih = mImage.height();
752 ww = geo.mW;
753 wh = geo.mH;
755 if (mFileList.isEmpty())
757 p.setPen(QColor("white"));
758 p.drawText(20 + (KRandom::random() % (ww>>1)), 20 + (KRandom::random() % (wh>>1)),
759 i18n("No images found"));
761 else
763 if (mZoomImages)
765 fx = (double)ww / iw;
766 fy = (double)wh / ih;
767 if (fx > fy) fx = fy;
768 if (fx > 2) fx = 2;
769 iw = (int)(iw * fx);
770 ih = (int)(ih * fx);
771 QImage scaledImg = mImage.smoothScale(iw, ih);
773 x = ((ww - iw) >> 1) + geo.mXorg;
774 y = ((wh - ih) >> 1) + geo.mYorg;
776 p.drawImage(x, y, scaledImg);
778 else
780 if(iw >= ww || ih >= wh)
782 fx = (double)ww / iw;
783 fy = (double)wh / ih;
784 if (fx > fy) fx = fy;
785 if (fx > 2) fx = 2;
786 iw = (int)(iw * fx);
787 ih = (int)(ih * fx);
788 QImage scaledImg = mImage.smoothScale(iw, ih);
790 x = ((ww - iw) >> 1) + geo.mXorg;
791 y = ((wh - ih) >> 1) + geo.mYorg;
793 p.drawImage(x, y, scaledImg);
795 else
797 if(mRandomPosition)
799 x = (KRandom::random() % (ww - iw)) + geo.mXorg;
800 y = (KRandom::random() % (wh - ih)) + geo.mYorg;
802 else
804 x = ((ww - iw) >> 1) + geo.mXorg;
805 y = ((wh - ih) >> 1) + geo.mYorg;
808 // bitBlt(&mNextScreen, x, y, &mImage, 0, 0, iw, ih);
809 p.drawImage(x, y, mImage);
813 if (mPrintName)
815 p.setPen(QColor("black"));
816 for (x=9; x<=11; x++)
817 for (y=21; y>=19; y--)
818 p.drawText(x + geo.mXorg, wh-y+geo.mYorg, mImageName);
819 p.setPen(QColor("white"));
820 p.drawText(10 + geo.mXorg, wh-20 + geo.mYorg, mImageName);
824 p.end();
828 //----------------------------------------------------------------------------
829 void kSlideShowSaver::loadNextImage()
831 QString fname;
832 int num;
834 num = mFileList.count();
835 if (num <= 0) //no files in the directory
837 return;
840 if (mShowRandom)
842 mFileIdx = KRandom::random() % num;
843 fname = mFileList[mFileIdx];
844 mFileList.remove(fname);
845 if (num == 1) //we're about to run out of images
847 mFileList = mRandomList;
850 else
852 if (mFileIdx >= num) mFileIdx = 0;
853 fname = mFileList[mFileIdx];
856 if (!mImage.load(fname))
858 kDebug() << "Failed to load image " << fname;
859 mFileList.remove(fname);
860 mRandomList.remove(fname);
861 if (!mFileList.isEmpty())
862 loadNextImage();
863 return;
865 mFileIdx++;
867 int i, j;
868 i = fname.findRev('.');
869 if (i < 0) i = 32767;
870 j = fname.findRev('/') + 1;
871 if (j < 0) j = 0;
872 mImageName = fname.mid(j, i-j);
876 //----------------------------------------------------------------------------
877 void kSlideShowSaver::loadDirectory()
879 mFileIdx = 0;
880 mFileList.clear();
881 traverseDirectory(mDirectory);
882 mRandomList = mFileList;
885 void kSlideShowSaver::traverseDirectory(const QString &dirName)
887 QDir dir(dirName);
888 if (!dir.exists())
890 return ;
892 dir.setFilter(QDir::Dirs | QDir::Files);
894 QFileInfoList fileinfolist = dir.entryInfoList();
895 QFileInfoListIterator it = fileinfolist.begin();
896 while ( it != fileinfolist.end())
898 if (it->fileName() == "." || it->fileName() == "..")
900 ++it;
901 continue;
903 if (it->isDir() && it->isReadable() && mSubdirectory)
905 traverseDirectory(it->filePath());
907 else
909 if (!it->isDir())
911 mFileList.append(it->filePath());
914 ++it;
919 //-----------------------------------------------------------------------------
920 void kSlideShowSaver::blank()
922 erase();
926 //=============================================================================
927 // Class kSlideShowSetup
928 //=============================================================================
929 kSlideShowSetup::kSlideShowSetup(QWidget *aParent, const char *aName)
930 : KDialog(aParent)
932 setCaption(i18n( "Setup Slide Show Screen Saver" ));
933 setButtons(Ok|Cancel|Help);
934 setDefaultButton(Ok);
935 setModal(true);
936 setButtonText( Help, i18n( "A&bout" ) );
938 QWidget *main = new QWidget(this);
939 setMainWidget(main);
940 cfg = new SlideShowCfg();
941 cfg->setupUi( main );
943 cfg->mPreview->setFixedSize(220, 170);
944 cfg->mPreview->setBackgroundColor(Qt::black);
945 cfg->mPreview->show(); // otherwise saver does not get correct size
946 mSaver = new kSlideShowSaver(cfg->mPreview->winId());
948 cfg->mDirChooser->setMode(KFile::Directory | KFile::ExistingOnly);
949 connect(cfg->mDirChooser, SIGNAL(returnPressed(const QString &)),
950 SLOT(slotDirSelected(const QString &)));
951 connect(cfg->mDirChooser, SIGNAL(urlSelected(const KUrl &)),
952 SLOT(slotDirSelected(const KUrl &)));
953 connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
954 connect(this,SIGNAL(helpClicked()),this,SLOT(slotHelp()));
955 readSettings();
958 kSlideShowSetup::~kSlideShowSetup()
960 delete mSaver;
963 //-----------------------------------------------------------------------------
964 void kSlideShowSetup::readSettings()
966 KConfigGroup config( KGlobal::config(), "Settings");
968 cfg->mCbxRandom->setChecked(config.readEntry("ShowRandom", true));
969 cfg->mCbxZoom->setChecked(config.readEntry("ZoomImages", false));
970 cfg->mCbxShowName->setChecked(config.readEntry("PrintName", true));
971 cfg->mDelay->setValue(config.readEntry("Delay", 20));
972 cfg->mDirChooser->setPath(config.readPathEntry("Directory", QString()));
973 cfg->mCbxSubdirectory->setChecked(config.readEntry("SubDirectory", false));
974 cfg->mCbxRandomPosition->setChecked(config.readEntry("RandomPosition", false));
978 //-----------------------------------------------------------------------------
979 void kSlideShowSetup::writeSettings()
981 KConfigGroup config( KGlobal::config(), "Settings");
983 config.writeEntry("ShowRandom", cfg->mCbxRandom->isChecked());
984 config.writeEntry("ZoomImages", cfg->mCbxZoom->isChecked());
985 config.writeEntry("PrintName", cfg->mCbxShowName->isChecked());
986 config.writeEntry("Delay", cfg->mDelay->value());
987 config.writePathEntry("Directory", cfg->mDirChooser->url().path());
988 config.writeEntry("SubDirectory", cfg->mCbxSubdirectory->isChecked());
989 config.writeEntry("RandomPosition", cfg->mCbxRandomPosition->isChecked());
991 config.sync();
993 if (mSaver)
995 mSaver->readConfig();
996 mSaver->restart();
1001 //-----------------------------------------------------------------------------
1003 void kSlideShowSetup::slotDirSelected(const KUrl &)
1005 writeSettings();
1008 void kSlideShowSetup::slotDirSelected(const QString &)
1010 writeSettings();
1014 //-----------------------------------------------------------------------------
1015 void kSlideShowSetup::slotOk()
1017 writeSettings();
1018 accept();
1022 //-----------------------------------------------------------------------------
1023 void kSlideShowSetup::slotHelp()
1025 KAboutApplicationDialog mAbout(s_aboutData, this);
1026 mAbout.exec();