- Split ImageAspect into 2 types, ImageAspect for images and ImageAspectScreenFilter for screens
- Change ImageDetails into a class and add some accessors for the filtering logic for screen aspect and image aspect
This commit is contained in:
@@ -14,21 +14,21 @@
|
|||||||
|
|
||||||
const std::string AppConfig::valid_aspects = "alpm"; // all, landscape, portait, monitor
|
const std::string AppConfig::valid_aspects = "alpm"; // all, landscape, portait, monitor
|
||||||
|
|
||||||
ImageAspect parseAspectFromString(char aspect) {
|
ImageAspectScreenFilter parseAspectFromString(char aspect) {
|
||||||
switch(aspect)
|
switch(aspect)
|
||||||
{
|
{
|
||||||
case 'l':
|
case 'l':
|
||||||
return ImageAspect_Landscape;
|
return ImageAspectScreenFilter_Landscape;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
return ImageAspect_Portrait;
|
return ImageAspectScreenFilter_Portrait;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
return ImageAspect_Monitor;
|
return ImageAspectScreenFilter_Monitor;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case 'a':
|
case 'a':
|
||||||
return ImageAspect_Any;
|
return ImageAspectScreenFilter_Any;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ struct AppConfig : public Config {
|
|||||||
AppConfig loadAppConfiguration(const AppConfig &commandLineConfig);
|
AppConfig loadAppConfiguration(const AppConfig &commandLineConfig);
|
||||||
Config getConfigurationForFolder(const std::string &folderPath, const Config ¤tConfig);
|
Config getConfigurationForFolder(const std::string &folderPath, const Config ¤tConfig);
|
||||||
|
|
||||||
ImageAspect parseAspectFromString(char aspect);
|
ImageAspectScreenFilter parseAspectFromString(char aspect);
|
||||||
QString getAppConfigFilePath(const std::string &configPath);
|
QString getAppConfigFilePath(const std::string &configPath);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -100,13 +100,6 @@ ImageDetails ImageSelector::populateImageDetails(const std::string&fileName, con
|
|||||||
imageDetails.width = imageWidth;
|
imageDetails.width = imageWidth;
|
||||||
imageDetails.height = imageHeight;
|
imageDetails.height = imageHeight;
|
||||||
imageDetails.rotation = degrees;
|
imageDetails.rotation = degrees;
|
||||||
if (imageWidth > imageHeight) {
|
|
||||||
imageDetails.aspect = ImageAspect_Landscape;
|
|
||||||
} else if (imageHeight > imageWidth) {
|
|
||||||
imageDetails.aspect = ImageAspect_Portrait;
|
|
||||||
} else {
|
|
||||||
imageDetails.aspect = ImageAspect_Any;
|
|
||||||
}
|
|
||||||
|
|
||||||
imageDetails.options = pathTraverser->UpdateOptionsForImage(imageDetails.filename, baseOptions);
|
imageDetails.options = pathTraverser->UpdateOptionsForImage(imageDetails.filename, baseOptions);
|
||||||
|
|
||||||
@@ -161,8 +154,7 @@ bool ImageSelector::imageMatchesFilter(const ImageDetails& imageDetails)
|
|||||||
|
|
||||||
bool ImageSelector::imageValidForAspect(const ImageDetails& imageDetails)
|
bool ImageSelector::imageValidForAspect(const ImageDetails& imageDetails)
|
||||||
{
|
{
|
||||||
if (imageDetails.options.onlyAspect == ImageAspect_Any ||
|
if (imageDetails.isValidForScreenAspect(imageDetails.options.onlyAspect))
|
||||||
imageDetails.aspect == imageDetails.options.onlyAspect)
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
54
src/imagestructs.cpp
Normal file
54
src/imagestructs.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
#include "imagestructs.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
ImageDetails::ImageDetails()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageDetails::~ImageDetails()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageAspect ImageDetails::aspect() const
|
||||||
|
{
|
||||||
|
if (width > height)
|
||||||
|
{
|
||||||
|
return ImageAspect_Landscape;
|
||||||
|
}
|
||||||
|
else if (height > width)
|
||||||
|
{
|
||||||
|
return ImageAspect_Portrait;
|
||||||
|
}
|
||||||
|
|
||||||
|
// must be square, so just pick something
|
||||||
|
return ImageAspect_Portrait;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ImageDetails::isValidForScreenAspect(const ImageAspectScreenFilter aspectScreen) const
|
||||||
|
{
|
||||||
|
if(aspectScreen == ImageAspectScreenFilter_Any)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(aspectScreen == ImageAspectScreenFilter_Monitor)
|
||||||
|
{
|
||||||
|
Log("Error: invalid aspect of ImageAspectScreenFilter_Monitor" );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (width > height)
|
||||||
|
{
|
||||||
|
return aspectScreen == ImageAspectScreenFilter_Landscape;
|
||||||
|
}
|
||||||
|
else if (height > width)
|
||||||
|
{
|
||||||
|
return aspectScreen == ImageAspectScreenFilter_Portrait;
|
||||||
|
}
|
||||||
|
|
||||||
|
// must be square so let is always display
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -6,7 +6,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// possible aspect ratios of an image
|
// possible aspect ratios of an image
|
||||||
enum ImageAspect { ImageAspect_Landscape = 0, ImageAspect_Portrait, ImageAspect_Any, ImageAspect_Monitor /* match monitors aspect */ };
|
enum ImageAspect { ImageAspect_Landscape = 0, ImageAspect_Portrait};
|
||||||
|
enum ImageAspectScreenFilter { ImageAspectScreenFilter_Landscape = 0, ImageAspectScreenFilter_Portrait, ImageAspectScreenFilter_Any, ImageAspectScreenFilter_Monitor /* match monitors aspect */ };
|
||||||
|
|
||||||
struct DisplayTimeWindow
|
struct DisplayTimeWindow
|
||||||
{
|
{
|
||||||
@@ -22,18 +23,24 @@ struct DisplayTimeWindow
|
|||||||
// options to consider when displaying an image
|
// options to consider when displaying an image
|
||||||
struct ImageDisplayOptions
|
struct ImageDisplayOptions
|
||||||
{
|
{
|
||||||
ImageAspect onlyAspect = ImageAspect_Any;
|
ImageAspectScreenFilter onlyAspect = ImageAspectScreenFilter_Any;
|
||||||
bool fitAspectAxisToWindow = false;
|
bool fitAspectAxisToWindow = false;
|
||||||
QVector<DisplayTimeWindow> timeWindows;
|
QVector<DisplayTimeWindow> timeWindows;
|
||||||
};
|
};
|
||||||
|
|
||||||
// details of a particular image
|
// details of a particular image
|
||||||
struct ImageDetails
|
class ImageDetails
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
ImageDetails();
|
||||||
|
~ImageDetails();
|
||||||
|
bool isValidForScreenAspect(const ImageAspectScreenFilter aspectDisplay) const;
|
||||||
|
ImageAspect aspect() const;
|
||||||
|
|
||||||
|
public:
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
int rotation = 0;
|
int rotation = 0;
|
||||||
ImageAspect aspect = ImageAspect_Any;
|
|
||||||
std::string filename;
|
std::string filename;
|
||||||
ImageDisplayOptions options;
|
ImageDisplayOptions options;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ bool parseCommandLine(AppConfig &appConfig, int argc, char *argv[]) {
|
|||||||
if (appConfig.valid_aspects.find(optarg[0]) == std::string::npos)
|
if (appConfig.valid_aspects.find(optarg[0]) == std::string::npos)
|
||||||
{
|
{
|
||||||
std::cout << "Invalid Aspect option, defaulting to all" << std::endl;
|
std::cout << "Invalid Aspect option, defaulting to all" << std::endl;
|
||||||
appConfig.baseDisplayOptions.onlyAspect = ImageAspect_Any;
|
appConfig.baseDisplayOptions.onlyAspect = ImageAspectScreenFilter_Any;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ void MainWindow::checkWindowSize()
|
|||||||
if (imageAspectMatchesMonitor)
|
if (imageAspectMatchesMonitor)
|
||||||
{
|
{
|
||||||
bool isLandscape = screenSize.width() > screenSize.height();
|
bool isLandscape = screenSize.width() > screenSize.height();
|
||||||
ImageAspect newAspect = isLandscape ? ImageAspect_Landscape : ImageAspect_Portrait;
|
ImageAspectScreenFilter newAspect = isLandscape ? ImageAspectScreenFilter_Landscape : ImageAspectScreenFilter_Portrait;
|
||||||
if (newAspect != baseImageOptions.onlyAspect)
|
if (newAspect != baseImageOptions.onlyAspect)
|
||||||
{
|
{
|
||||||
Log("Changing image orientation to ", newAspect);
|
Log("Changing image orientation to ", newAspect);
|
||||||
@@ -218,14 +218,6 @@ void MainWindow::updateImage(bool immediately)
|
|||||||
currentImage.width = p.width();
|
currentImage.width = p.width();
|
||||||
currentImage.height = p.height();
|
currentImage.height = p.height();
|
||||||
currentImage.rotation = 0;
|
currentImage.rotation = 0;
|
||||||
if (currentImage.width > currentImage.height) {
|
|
||||||
currentImage.aspect = ImageAspect_Landscape;
|
|
||||||
} else if (currentImage.height > currentImage.width) {
|
|
||||||
currentImage.aspect = ImageAspect_Portrait;
|
|
||||||
} else {
|
|
||||||
currentImage.aspect = ImageAspect_Any;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -331,13 +323,13 @@ QPixmap MainWindow::getScaledPixmap(const QPixmap& p)
|
|||||||
{
|
{
|
||||||
if (currentImage.options.fitAspectAxisToWindow)
|
if (currentImage.options.fitAspectAxisToWindow)
|
||||||
{
|
{
|
||||||
if (currentImage.aspect == ImageAspect_Portrait)
|
if (currentImage.aspect() == ImageAspect_Portrait)
|
||||||
{
|
{
|
||||||
// potrait mode, make height of image fit screen and crop top/bottom
|
// potrait mode, make height of image fit screen and crop top/bottom
|
||||||
QPixmap pTemp = p.scaledToHeight(height(), Qt::SmoothTransformation);
|
QPixmap pTemp = p.scaledToHeight(height(), Qt::SmoothTransformation);
|
||||||
return pTemp.copy(0,0,width(),height());
|
return pTemp.copy(0,0,width(),height());
|
||||||
}
|
}
|
||||||
else if (currentImage.aspect == ImageAspect_Landscape)
|
else if (currentImage.aspect() == ImageAspect_Landscape)
|
||||||
{
|
{
|
||||||
// landscape mode, make width of image fit screen and crop top/bottom
|
// landscape mode, make width of image fit screen and crop top/bottom
|
||||||
QPixmap pTemp = p.scaledToWidth(width(), Qt::SmoothTransformation);
|
QPixmap pTemp = p.scaledToWidth(width(), Qt::SmoothTransformation);
|
||||||
@@ -410,10 +402,10 @@ void MainWindow::warn(std::string text)
|
|||||||
void MainWindow::setBaseOptions(const ImageDisplayOptions &baseOptionsIn)
|
void MainWindow::setBaseOptions(const ImageDisplayOptions &baseOptionsIn)
|
||||||
{
|
{
|
||||||
baseImageOptions = baseOptionsIn;
|
baseImageOptions = baseOptionsIn;
|
||||||
if(baseImageOptions.onlyAspect == ImageAspect_Monitor)
|
if(baseImageOptions.onlyAspect == ImageAspectScreenFilter_Monitor)
|
||||||
{
|
{
|
||||||
imageAspectMatchesMonitor = true;
|
imageAspectMatchesMonitor = true;
|
||||||
baseImageOptions.onlyAspect = width() >= height() ? ImageAspect_Landscape : ImageAspect_Portrait;
|
baseImageOptions.onlyAspect = width() >= height() ? ImageAspectScreenFilter_Landscape : ImageAspectScreenFilter_Portrait;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ SOURCES += \
|
|||||||
overlay.cpp \
|
overlay.cpp \
|
||||||
imageselector.cpp \
|
imageselector.cpp \
|
||||||
appconfig.cpp \
|
appconfig.cpp \
|
||||||
|
imagestructs.cpp \
|
||||||
logger.cpp
|
logger.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
|||||||
Reference in New Issue
Block a user