- Add support for per folder image display options. The file called options.json contains json keys to control image options when displaying files in this folder. Currently a singled option, fitAspectAxisToWindow, is supported
- Remove duplicated image rotation reading code, have the image selector logic just pass this up via the per image options
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
#include <algorithm> // std::shuffle
|
||||
#include <random> // std::default_random_engine
|
||||
|
||||
ImageSelector::ImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspectIn):
|
||||
pathTraverser(pathTraverser), aspect(aspectIn)
|
||||
ImageSelector::ImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspectIn, bool fitAspectAxisToWindowIn):
|
||||
pathTraverser(pathTraverser), aspect(aspectIn), fitAspectAxisToWindow(fitAspectAxisToWindowIn)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -50,12 +50,11 @@ int ImageSelector::getImageRotation(const std::string &fileName)
|
||||
return degrees;
|
||||
}
|
||||
|
||||
bool ImageSelector::imageValidForAspect(const std::string &fileName)
|
||||
bool ImageSelector::imageValidForAspect(const std::string &fileName, const int rotation)
|
||||
{
|
||||
QPixmap p( fileName.c_str() );
|
||||
int imageWidth = p.width();
|
||||
int imageHeight = p.height();
|
||||
int rotation = getImageRotation(fileName);
|
||||
if ( rotation == 90 || rotation == 270 )
|
||||
{
|
||||
std::swap(imageWidth,imageHeight);
|
||||
@@ -83,15 +82,15 @@ bool ImageSelector::imageValidForAspect(const std::string &fileName)
|
||||
}
|
||||
|
||||
|
||||
RandomImageSelector::RandomImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect):
|
||||
ImageSelector(pathTraverser, aspect)
|
||||
RandomImageSelector::RandomImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect, bool fitAspectAxisToWindow):
|
||||
ImageSelector(pathTraverser, aspect, fitAspectAxisToWindow)
|
||||
{
|
||||
srand (time(NULL));
|
||||
}
|
||||
|
||||
RandomImageSelector::~RandomImageSelector(){}
|
||||
|
||||
std::string RandomImageSelector::getNextImage()
|
||||
const std::string RandomImageSelector::getNextImage(ImageOptions_t &options)
|
||||
{
|
||||
std:: string filename;
|
||||
try
|
||||
@@ -101,7 +100,8 @@ std::string RandomImageSelector::getNextImage()
|
||||
QStringList images = pathTraverser->getImages();
|
||||
unsigned int selectedImage = selectRandom(images);
|
||||
filename = pathTraverser->getImagePath(images.at(selectedImage).toStdString());
|
||||
if (!imageValidForAspect(filename))
|
||||
options.rotation = getImageRotation(filename);
|
||||
if (!imageValidForAspect(filename, options.rotation))
|
||||
{
|
||||
filename.clear();
|
||||
}
|
||||
@@ -113,6 +113,9 @@ std::string RandomImageSelector::getNextImage()
|
||||
std::cerr << "Error: " << err << std::endl;
|
||||
}
|
||||
std::cout << "updating image: " << filename << std::endl;
|
||||
options.aspect = aspect;
|
||||
options.fitAspectAxisToWindow = fitAspectAxisToWindow;
|
||||
pathTraverser->UpdateOptionsForImage(filename, options);
|
||||
return filename;
|
||||
}
|
||||
|
||||
@@ -129,8 +132,8 @@ unsigned int RandomImageSelector::selectRandom(const QStringList& images) const
|
||||
return rand() % images.size();
|
||||
}
|
||||
|
||||
ShuffleImageSelector::ShuffleImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect):
|
||||
ImageSelector(pathTraverser, aspect),
|
||||
ShuffleImageSelector::ShuffleImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect, bool fitAspectAxisToWindow):
|
||||
ImageSelector(pathTraverser, aspect, fitAspectAxisToWindow),
|
||||
current_image_shuffle(-1),
|
||||
images()
|
||||
{
|
||||
@@ -141,7 +144,7 @@ ShuffleImageSelector::~ShuffleImageSelector()
|
||||
{
|
||||
}
|
||||
|
||||
std::string ShuffleImageSelector::getNextImage()
|
||||
const std::string ShuffleImageSelector::getNextImage(ImageOptions_t &options)
|
||||
{
|
||||
if (images.size() == 0 || current_image_shuffle >= images.size())
|
||||
{
|
||||
@@ -164,24 +167,28 @@ std::string ShuffleImageSelector::getNextImage()
|
||||
std::cout << "file not found: " << filename << std::endl;
|
||||
}
|
||||
current_image_shuffle = current_image_shuffle + 1; // ignore and move to next image
|
||||
return getNextImage();
|
||||
return getNextImage(options);
|
||||
}
|
||||
if (!imageValidForAspect(filename))
|
||||
options.rotation = getImageRotation(filename);
|
||||
if (!imageValidForAspect(filename, options.rotation))
|
||||
{
|
||||
if(debugMode)
|
||||
{
|
||||
std::cout << "image has invalid aspect: " << filename << "(images left:" << (images.size()-current_image_shuffle) << ")" << std::endl;
|
||||
}
|
||||
current_image_shuffle = current_image_shuffle + 1; // ignore and move to next image
|
||||
return getNextImage();
|
||||
return getNextImage(options);
|
||||
}
|
||||
std::cout << "updating image: " << filename << std::endl;
|
||||
current_image_shuffle = current_image_shuffle + 1;
|
||||
options.aspect = aspect;
|
||||
options.fitAspectAxisToWindow = fitAspectAxisToWindow;
|
||||
pathTraverser->UpdateOptionsForImage(filename, options);
|
||||
return filename;
|
||||
}
|
||||
|
||||
SortedImageSelector::SortedImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect):
|
||||
ImageSelector(pathTraverser, aspect),
|
||||
SortedImageSelector::SortedImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect, bool fitAspectAxisToWindow):
|
||||
ImageSelector(pathTraverser, aspect, fitAspectAxisToWindow),
|
||||
images()
|
||||
{
|
||||
srand (time(NULL));
|
||||
@@ -203,7 +210,7 @@ bool operator<(const QString& lhs, const QString& rhs) noexcept{
|
||||
|
||||
}
|
||||
|
||||
std::string SortedImageSelector::getNextImage()
|
||||
const std::string SortedImageSelector::getNextImage(ImageOptions_t &options)
|
||||
{
|
||||
if (images.size() == 0)
|
||||
{
|
||||
@@ -229,17 +236,21 @@ std::string SortedImageSelector::getNextImage()
|
||||
{
|
||||
std::cout << "file not found: " << filename << std::endl;
|
||||
}
|
||||
return getNextImage();
|
||||
return getNextImage(options);
|
||||
}
|
||||
if (!imageValidForAspect(filename))
|
||||
options.rotation = getImageRotation(filename);
|
||||
if (!imageValidForAspect(filename, options.rotation))
|
||||
{
|
||||
if(debugMode)
|
||||
{
|
||||
std::cout << "image has invalid aspect: " << filename << std::endl;
|
||||
}
|
||||
return getNextImage();
|
||||
return getNextImage(options);
|
||||
}
|
||||
|
||||
std::cout << "updating image: " << filename << std::endl;
|
||||
options.aspect = aspect;
|
||||
options.fitAspectAxisToWindow = fitAspectAxisToWindow;
|
||||
pathTraverser->UpdateOptionsForImage(filename, options);
|
||||
return filename;
|
||||
}
|
||||
|
||||
@@ -8,28 +8,36 @@
|
||||
class MainWindow;
|
||||
class PathTraverser;
|
||||
|
||||
struct ImageOptions_t
|
||||
{
|
||||
char aspect;
|
||||
bool fitAspectAxisToWindow;
|
||||
int rotation;
|
||||
};
|
||||
|
||||
class ImageSelector
|
||||
{
|
||||
public:
|
||||
ImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspectIn);
|
||||
ImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspectIn, bool fitAspectAxisToWindow);
|
||||
virtual ~ImageSelector();
|
||||
virtual std::string getNextImage() = 0;
|
||||
virtual const std::string getNextImage(ImageOptions_t &options) = 0;
|
||||
void setDebugMode(bool debugModeIn) { debugMode = debugModeIn;}
|
||||
|
||||
protected:
|
||||
int getImageRotation(const std::string &fileName);
|
||||
bool imageValidForAspect(const std::string &fileName);
|
||||
bool imageValidForAspect(const std::string &fileName, const int rotation);
|
||||
std::unique_ptr<PathTraverser>& pathTraverser;
|
||||
char aspect;
|
||||
bool fitAspectAxisToWindow = false;
|
||||
bool debugMode = false;
|
||||
};
|
||||
|
||||
class RandomImageSelector : public ImageSelector
|
||||
{
|
||||
public:
|
||||
RandomImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect);
|
||||
RandomImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect, bool fitAspectAxisToWindow);
|
||||
virtual ~RandomImageSelector();
|
||||
virtual std::string getNextImage();
|
||||
virtual const std::string getNextImage(ImageOptions_t &options);
|
||||
|
||||
private:
|
||||
unsigned int selectRandom(const QStringList& images) const;
|
||||
@@ -38,9 +46,9 @@ private:
|
||||
class ShuffleImageSelector : public ImageSelector
|
||||
{
|
||||
public:
|
||||
ShuffleImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect);
|
||||
ShuffleImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect, bool fitAspectAxisToWindow);
|
||||
virtual ~ShuffleImageSelector();
|
||||
virtual std::string getNextImage();
|
||||
virtual const std::string getNextImage(ImageOptions_t &options);
|
||||
|
||||
private:
|
||||
int current_image_shuffle;
|
||||
@@ -50,9 +58,9 @@ private:
|
||||
class SortedImageSelector : public ImageSelector
|
||||
{
|
||||
public:
|
||||
SortedImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect);
|
||||
SortedImageSelector(std::unique_ptr<PathTraverser>& pathTraverser, char aspect, bool fitAspectAxisToWindow);
|
||||
virtual ~SortedImageSelector();
|
||||
virtual std::string getNextImage();
|
||||
virtual const std::string getNextImage(ImageOptions_t &options);
|
||||
|
||||
private:
|
||||
QStringList images;
|
||||
|
||||
@@ -21,7 +21,8 @@ ImageSwitcher::ImageSwitcher(MainWindow& w, unsigned int timeout, std::unique_pt
|
||||
|
||||
void ImageSwitcher::updateImage()
|
||||
{
|
||||
std::string filename(selector->getNextImage());
|
||||
ImageOptions_t options;
|
||||
std::string filename(selector->getNextImage(options));
|
||||
if (filename == "")
|
||||
{
|
||||
window.warn("No image found.");
|
||||
@@ -29,7 +30,7 @@ void ImageSwitcher::updateImage()
|
||||
}
|
||||
else
|
||||
{
|
||||
window.setImage(filename);
|
||||
window.setImage(filename, options);
|
||||
timerNoContent.stop(); // we have loaded content so stop the fast polling
|
||||
}
|
||||
}
|
||||
|
||||
14
src/main.cpp
14
src/main.cpp
@@ -116,29 +116,29 @@ int main(int argc, char *argv[])
|
||||
std::unique_ptr<PathTraverser> pathTraverser;
|
||||
if (!imageList.empty())
|
||||
{
|
||||
pathTraverser = std::unique_ptr<PathTraverser>(new ImageListPathTraverser(imageList));
|
||||
pathTraverser = std::unique_ptr<PathTraverser>(new ImageListPathTraverser(imageList, debugMode));
|
||||
}
|
||||
else if (recursive)
|
||||
{
|
||||
pathTraverser = std::unique_ptr<PathTraverser>(new RecursivePathTraverser(path));
|
||||
pathTraverser = std::unique_ptr<PathTraverser>(new RecursivePathTraverser(path, debugMode));
|
||||
}
|
||||
else
|
||||
{
|
||||
pathTraverser = std::unique_ptr<PathTraverser>(new DefaultPathTraverser(path));
|
||||
pathTraverser = std::unique_ptr<PathTraverser>(new DefaultPathTraverser(path, debugMode));
|
||||
}
|
||||
|
||||
std::unique_ptr<ImageSelector> selector;
|
||||
if (sorted)
|
||||
{
|
||||
selector = std::unique_ptr<ImageSelector>(new SortedImageSelector(pathTraverser, aspect));
|
||||
selector = std::unique_ptr<ImageSelector>(new SortedImageSelector(pathTraverser, aspect, fitAspectAxisToWindow));
|
||||
}
|
||||
else if (shuffle)
|
||||
{
|
||||
selector = std::unique_ptr<ImageSelector>(new ShuffleImageSelector(pathTraverser, aspect));
|
||||
selector = std::unique_ptr<ImageSelector>(new ShuffleImageSelector(pathTraverser, aspect, fitAspectAxisToWindow));
|
||||
}
|
||||
else
|
||||
{
|
||||
selector = std::unique_ptr<ImageSelector>(new RandomImageSelector(pathTraverser, aspect));
|
||||
selector = std::unique_ptr<ImageSelector>(new RandomImageSelector(pathTraverser, aspect, fitAspectAxisToWindow));
|
||||
}
|
||||
selector->setDebugMode(debugMode);
|
||||
if(debugMode)
|
||||
@@ -149,9 +149,7 @@ int main(int argc, char *argv[])
|
||||
Overlay o(overlay);
|
||||
o.setDebugMode(debugMode);
|
||||
w.setOverlay(&o);
|
||||
w.setAspect(aspect);
|
||||
w.setDebugMode(debugMode);
|
||||
w.setFitAspectAxisToWindow(fitAspectAxisToWindow);
|
||||
w.show();
|
||||
|
||||
ImageSwitcher switcher(w, rotationSeconds * 1000, selector);
|
||||
|
||||
@@ -53,47 +53,13 @@ void MainWindow::resizeEvent(QResizeEvent* event)
|
||||
updateImage(true);
|
||||
}
|
||||
|
||||
void MainWindow::setImage(std::string path)
|
||||
void MainWindow::setImage(const std::string& path, const ImageOptions_t& options)
|
||||
{
|
||||
currentImage = path;
|
||||
imageOptions = options;
|
||||
updateImage(false);
|
||||
}
|
||||
|
||||
int MainWindow::getImageRotation()
|
||||
{
|
||||
if (currentImage == "")
|
||||
return 0;
|
||||
|
||||
int orientation = 0;
|
||||
ExifData *exifData = exif_data_new_from_file(currentImage.c_str());
|
||||
if (exifData)
|
||||
{
|
||||
ExifByteOrder byteOrder = exif_data_get_byte_order(exifData);
|
||||
ExifEntry *exifEntry = exif_data_get_entry(exifData, EXIF_TAG_ORIENTATION);
|
||||
|
||||
if (exifEntry)
|
||||
{
|
||||
orientation = exif_get_short(exifEntry->data, byteOrder);
|
||||
}
|
||||
exif_data_free(exifData);
|
||||
}
|
||||
|
||||
int degrees = 0;
|
||||
switch(orientation) {
|
||||
case 8:
|
||||
degrees = 270;
|
||||
break;
|
||||
case 3:
|
||||
degrees = 180;
|
||||
break;
|
||||
case 6:
|
||||
degrees = 90;
|
||||
break;
|
||||
}
|
||||
|
||||
return degrees;
|
||||
}
|
||||
|
||||
void MainWindow::updateImage(bool immediately)
|
||||
{
|
||||
if (currentImage == "")
|
||||
@@ -184,11 +150,6 @@ void MainWindow::setOverlay(Overlay* o)
|
||||
overlay = o;
|
||||
}
|
||||
|
||||
void MainWindow::setAspect(char aspectIn)
|
||||
{
|
||||
aspect = aspectIn;
|
||||
}
|
||||
|
||||
QPixmap MainWindow::getBlurredBackground(const QPixmap& originalSize, const QPixmap& scaled)
|
||||
{
|
||||
if (scaled.width() < width()) {
|
||||
@@ -206,21 +167,21 @@ QPixmap MainWindow::getBlurredBackground(const QPixmap& originalSize, const QPix
|
||||
QPixmap MainWindow::getRotatedPixmap(const QPixmap& p)
|
||||
{
|
||||
QMatrix matrix;
|
||||
matrix.rotate(getImageRotation());
|
||||
matrix.rotate(imageOptions.rotation);
|
||||
return p.transformed(matrix);
|
||||
}
|
||||
|
||||
QPixmap MainWindow::getScaledPixmap(const QPixmap& p)
|
||||
{
|
||||
if (fitAspectAxisToWindow)
|
||||
if (imageOptions.fitAspectAxisToWindow)
|
||||
{
|
||||
if ( aspect == 'p')
|
||||
if (imageOptions.aspect == 'p')
|
||||
{
|
||||
// potrait mode, make height of image fit screen and crop top/bottom
|
||||
QPixmap pTemp = p.scaledToHeight(height(), Qt::SmoothTransformation);
|
||||
return pTemp.copy(0,0,width(),height());
|
||||
}
|
||||
else if ( aspect == 'l')
|
||||
else if (imageOptions.aspect == 'l')
|
||||
{
|
||||
// landscape mode, make width of image fit screen and crop top/bottom
|
||||
QPixmap pTemp = p.scaledToWidth(width(), Qt::SmoothTransformation);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QPixmap>
|
||||
#include "imageselector.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@@ -20,23 +21,20 @@ public:
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
~MainWindow();
|
||||
void setImage(std::string path);
|
||||
void setImage(const std::string& path, const ImageOptions_t &options);
|
||||
void setBlurRadius(unsigned int blurRadius);
|
||||
void setBackgroundOpacity(unsigned int opacity);
|
||||
void warn(std::string text);
|
||||
void setOverlay(Overlay* overlay);
|
||||
void setAspect(char aspectIn);
|
||||
void setDebugMode(bool debugModeIn) {debugMode = debugModeIn;}
|
||||
void setFitAspectAxisToWindow(bool fitAspectAxisToWindowIn) { fitAspectAxisToWindow = fitAspectAxisToWindowIn; }
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
std::string currentImage;
|
||||
unsigned int blurRadius = 20;
|
||||
unsigned int backgroundOpacity = 150;
|
||||
char aspect = 'a';
|
||||
ImageOptions_t imageOptions;
|
||||
bool debugMode = false;
|
||||
bool fitAspectAxisToWindow = false;
|
||||
|
||||
Overlay* overlay;
|
||||
|
||||
|
||||
@@ -4,11 +4,16 @@
|
||||
#include <QTimer>
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <iostream>
|
||||
#include <stdlib.h> /* srand, rand */
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
PathTraverser::PathTraverser(const std::string path):
|
||||
path(path)
|
||||
PathTraverser::PathTraverser(const std::string path, bool debugModeIn):
|
||||
path(path), debugMode(debugModeIn)
|
||||
{}
|
||||
|
||||
PathTraverser::~PathTraverser() {}
|
||||
@@ -20,8 +25,38 @@ QStringList PathTraverser::getImageFormats() const {
|
||||
return imageFormats;
|
||||
}
|
||||
|
||||
RecursivePathTraverser::RecursivePathTraverser(const std::string path):
|
||||
PathTraverser(path)
|
||||
void PathTraverser::LoadOptionsForDirectory(const std::string &directoryPath, ImageOptions_t &options) const
|
||||
{
|
||||
QDir directory(directoryPath.c_str());
|
||||
QString jsonFile = directory.filePath(QString("options.json"));
|
||||
if(directory.exists(jsonFile))
|
||||
{
|
||||
if(debugMode)
|
||||
{
|
||||
std::cout << "Found options file" << std::endl;
|
||||
}
|
||||
QString val;
|
||||
QFile file;
|
||||
file.setFileName(jsonFile);
|
||||
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
val = file.readAll();
|
||||
file.close();
|
||||
QJsonDocument d = QJsonDocument::fromJson(val.toUtf8());
|
||||
QJsonObject jsonDoc = d.object();
|
||||
if(jsonDoc.contains("fitAspectAxisToWindow") && jsonDoc["fitAspectAxisToWindow"].isBool())
|
||||
{
|
||||
options.fitAspectAxisToWindow = jsonDoc["fitAspectAxisToWindow"].toBool();
|
||||
if(debugMode)
|
||||
{
|
||||
std::cout << "Fit Aspect:" << options.fitAspectAxisToWindow << std::endl;
|
||||
}
|
||||
}
|
||||
// read json
|
||||
}
|
||||
}
|
||||
|
||||
RecursivePathTraverser::RecursivePathTraverser(const std::string path,bool debugMode):
|
||||
PathTraverser(path,debugMode)
|
||||
{}
|
||||
|
||||
RecursivePathTraverser::~RecursivePathTraverser() {}
|
||||
@@ -44,8 +79,14 @@ const std::string RecursivePathTraverser::getImagePath(const std::string image)
|
||||
return image;
|
||||
}
|
||||
|
||||
DefaultPathTraverser::DefaultPathTraverser(const std::string path):
|
||||
PathTraverser(path),
|
||||
void RecursivePathTraverser::UpdateOptionsForImage(const std::string& filename, ImageOptions_t& options) const
|
||||
{
|
||||
QDir d = QFileInfo(filename.c_str()).absoluteDir();
|
||||
LoadOptionsForDirectory(d.absolutePath().toStdString(), options);
|
||||
}
|
||||
|
||||
DefaultPathTraverser::DefaultPathTraverser(const std::string path,bool debugMode):
|
||||
PathTraverser(path,debugMode),
|
||||
directory(path.c_str())
|
||||
{}
|
||||
|
||||
@@ -62,9 +103,14 @@ const std::string DefaultPathTraverser::getImagePath(const std::string image) co
|
||||
return directory.filePath(QString(image.c_str())).toStdString();
|
||||
}
|
||||
|
||||
void DefaultPathTraverser::UpdateOptionsForImage(const std::string& filename, ImageOptions_t& options) const
|
||||
{
|
||||
UNUSED(filename);
|
||||
LoadOptionsForDirectory(directory.absolutePath().toStdString(), options);
|
||||
}
|
||||
|
||||
ImageListPathTraverser::ImageListPathTraverser(const std::string &imageListString):
|
||||
PathTraverser("")
|
||||
ImageListPathTraverser::ImageListPathTraverser(const std::string &imageListString,bool debugMode):
|
||||
PathTraverser("",debugMode)
|
||||
{
|
||||
QString str = QString(imageListString.c_str());
|
||||
imageList = str.split(QLatin1Char(','));
|
||||
@@ -81,4 +127,11 @@ QStringList ImageListPathTraverser::getImages() const
|
||||
const std::string ImageListPathTraverser::getImagePath(const std::string image) const
|
||||
{
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageListPathTraverser::UpdateOptionsForImage(const std::string& filename, ImageOptions_t& options) const
|
||||
{
|
||||
// no per file options modification supported
|
||||
UNUSED(filename);
|
||||
UNUSED(options);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <iostream>
|
||||
#include <QDir>
|
||||
#include <QStringList>
|
||||
#include "imageselector.h"
|
||||
|
||||
static const QStringList supportedFormats={"jpg","jpeg","png","tif","tiff"};
|
||||
|
||||
@@ -11,32 +12,37 @@ class MainWindow;
|
||||
class PathTraverser
|
||||
{
|
||||
public:
|
||||
PathTraverser(const std::string path);
|
||||
PathTraverser(const std::string path, bool debugModeIn);
|
||||
virtual ~PathTraverser();
|
||||
virtual QStringList getImages() const = 0;
|
||||
virtual const std::string getImagePath(const std::string image) const = 0;
|
||||
virtual void UpdateOptionsForImage(const std::string& filename, ImageOptions_t& options) const = 0;
|
||||
|
||||
protected:
|
||||
const std::string path;
|
||||
bool debugMode = false;
|
||||
QStringList getImageFormats() const;
|
||||
void LoadOptionsForDirectory(const std::string &directoryPath, ImageOptions_t &options) const;
|
||||
};
|
||||
|
||||
class RecursivePathTraverser : public PathTraverser
|
||||
{
|
||||
public:
|
||||
RecursivePathTraverser(const std::string path);
|
||||
RecursivePathTraverser(const std::string path, bool debugModeIn);
|
||||
virtual ~RecursivePathTraverser();
|
||||
QStringList getImages() const;
|
||||
virtual const std::string getImagePath(const std::string image) const;
|
||||
virtual void UpdateOptionsForImage(const std::string& filename, ImageOptions_t& options) const;
|
||||
};
|
||||
|
||||
class DefaultPathTraverser : public PathTraverser
|
||||
{
|
||||
public:
|
||||
DefaultPathTraverser(const std::string path);
|
||||
DefaultPathTraverser(const std::string path, bool debugModeIn);
|
||||
virtual ~DefaultPathTraverser();
|
||||
QStringList getImages() const;
|
||||
virtual const std::string getImagePath(const std::string image) const;
|
||||
virtual void UpdateOptionsForImage(const std::string& filename, ImageOptions_t& options) const;
|
||||
private:
|
||||
QDir directory;
|
||||
};
|
||||
@@ -44,10 +50,11 @@ class DefaultPathTraverser : public PathTraverser
|
||||
class ImageListPathTraverser : public PathTraverser
|
||||
{
|
||||
public:
|
||||
ImageListPathTraverser(const std::string &imageListString);
|
||||
ImageListPathTraverser(const std::string &imageListString, bool debugModeIn);
|
||||
virtual ~ImageListPathTraverser();
|
||||
QStringList getImages() const;
|
||||
virtual const std::string getImagePath(const std::string image) const;
|
||||
virtual void UpdateOptionsForImage(const std::string& filename, ImageOptions_t& options) const;
|
||||
private:
|
||||
QStringList imageList;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user