- 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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user