split imageselector

* image updating in seperate class ImageSwitcher
 * image selection in class ImageSelector
This commit is contained in:
Manuel
2020-01-02 23:33:39 +01:00
parent eec0eb8998
commit bc9dd90acc
8 changed files with 94 additions and 34 deletions

39
src/imageswitcher.cpp Normal file
View File

@@ -0,0 +1,39 @@
#include "imageswitcher.h"
#include "imageselector.h"
#include "mainwindow.h"
#include <QDirIterator>
#include <QTimer>
#include <QApplication>
#include <QDir>
#include <iostream>
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
ImageSwitcher::ImageSwitcher(MainWindow& w, unsigned int timeout, const ImageSelector& selector):
QObject::QObject(),
window(w),
timeout(timeout),
selector(selector),
timer(this)
{
}
void ImageSwitcher::updateImage()
{
std::string filename(selector.getNextImage());
if (filename == "")
{
window.warn("No image found.");
}
else
{
window.setImage(filename);
}
}
void ImageSwitcher::start()
{
updateImage();
connect(&timer, SIGNAL(timeout()), this, SLOT(updateImage()));
timer.start(timeout);
}