- Add new aspect mode EImageAspect_Monitor , match the aspect of the monitor
- Added code to make sure the QMainWindow matches the screen size, dynamic rotation of the monitor caused incorrect screen sizes
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
|
||||
// possible aspect ratios of an image
|
||||
enum EImageAspect { EImageAspect_Landscape = 0, EImageAspect_Portrait, EImageAspect_Any };
|
||||
enum EImageAspect { EImageAspect_Landscape = 0, EImageAspect_Portrait, EImageAspect_Any, EImageAspect_Monitor /* match monitors aspect */ };
|
||||
|
||||
// options to consider when displaying an image
|
||||
struct ImageDisplayOptions_t
|
||||
|
||||
@@ -32,7 +32,7 @@ int main(int argc, char *argv[])
|
||||
bool sorted = false;
|
||||
bool debugMode = false;
|
||||
ImageDisplayOptions_t baseDisplayOptions;
|
||||
std::string valid_aspects = "alp"; // all, landscape, portait
|
||||
std::string valid_aspects = "alpm"; // all, landscape, portait
|
||||
std::string overlay = "";
|
||||
std::string imageList = ""; // comma delimited list of images to show
|
||||
int debugInt = 0;
|
||||
@@ -71,6 +71,9 @@ int main(int argc, char *argv[])
|
||||
case 'p':
|
||||
baseDisplayOptions.onlyAspect = EImageAspect_Portrait;
|
||||
break;
|
||||
case 'm':
|
||||
baseDisplayOptions.onlyAspect = EImageAspect_Monitor;
|
||||
break;
|
||||
default:
|
||||
case 'a':
|
||||
baseDisplayOptions.onlyAspect = EImageAspect_Any;
|
||||
@@ -168,6 +171,7 @@ int main(int argc, char *argv[])
|
||||
w.show();
|
||||
|
||||
ImageSwitcher switcher(w, rotationSeconds * 1000, selector);
|
||||
w.setImageSwitcher(&switcher);
|
||||
switcher.start();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "overlay.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "imageswitcher.h"
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QBitmap>
|
||||
@@ -14,6 +15,7 @@
|
||||
#include <QRect>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QDesktopWidget>
|
||||
#include <sstream>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
@@ -105,9 +107,42 @@ bool MainWindow::event(QEvent* event)
|
||||
void MainWindow::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
QMainWindow::resizeEvent(event);
|
||||
// the window size in this event may not match the monitor size, so use QDesktopWidget to find the true monitor size
|
||||
QDesktopWidget desktop;
|
||||
QSize screenSize = desktop.screenGeometry(this).size();
|
||||
bool isLandscape = screenSize.width() > screenSize.height();
|
||||
if (imageAspectMatchesMonitor)
|
||||
{
|
||||
baseImageOptions.onlyAspect = isLandscape ? EImageAspect_Landscape : EImageAspect_Portrait;
|
||||
}
|
||||
if(debugMode)
|
||||
{
|
||||
std::cout << "Got resize:" << this << " " << screenSize.width() << "," << screenSize.height() << " , is landscape? " << (isLandscape ? "y" : "n") << std::endl;
|
||||
}
|
||||
updateImage(true);
|
||||
QTimer::singleShot(5, this, SLOT(checkWindowSize()));
|
||||
if(lastScreenSize != screenSize && switcher != nullptr)
|
||||
{
|
||||
lastScreenSize = screenSize;
|
||||
switcher->updateImage();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::checkWindowSize()
|
||||
{
|
||||
QDesktopWidget desktop;
|
||||
QRect screenSize = desktop.screenGeometry(this);
|
||||
if(size() != screenSize.size())
|
||||
{
|
||||
if(debugMode)
|
||||
{
|
||||
std::cout << "Resizing Window" << screenSize.width() << "," << screenSize.height() << std::endl;
|
||||
}
|
||||
setFixedSize(screenSize.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::setImage(const ImageDetails_t &imageDetails)
|
||||
{
|
||||
currentImage = imageDetails;
|
||||
@@ -116,6 +151,7 @@ void MainWindow::setImage(const ImageDetails_t &imageDetails)
|
||||
|
||||
void MainWindow::updateImage(bool immediately)
|
||||
{
|
||||
checkWindowSize();
|
||||
if (currentImage.filename == "")
|
||||
return;
|
||||
|
||||
@@ -131,7 +167,7 @@ void MainWindow::updateImage(bool immediately)
|
||||
QPixmap p( currentImage.filename.c_str() );
|
||||
if(debugMode)
|
||||
{
|
||||
std::cout << "size:" << p.width() << "x" << p.height() << std::endl;
|
||||
std::cout << "size:" << p.width() << "x" << p.height() << "(window:" << width() << "," << height() << ")" << std::endl;
|
||||
}
|
||||
|
||||
QPixmap rotated = getRotatedPixmap(p);
|
||||
@@ -302,3 +338,13 @@ void MainWindow::warn(std::string text)
|
||||
QLabel *label = this->findChild<QLabel*>("image");
|
||||
label->setText(text.c_str());
|
||||
}
|
||||
|
||||
void MainWindow::setBaseOptions(const ImageDisplayOptions_t &baseOptionsIn)
|
||||
{
|
||||
baseImageOptions = baseOptionsIn;
|
||||
if(baseImageOptions.onlyAspect == EImageAspect_Monitor)
|
||||
{
|
||||
imageAspectMatchesMonitor = true;
|
||||
baseImageOptions.onlyAspect = width() >= height() ? EImageAspect_Landscape : EImageAspect_Portrait;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ class MainWindow;
|
||||
class QLabel;
|
||||
class QKeyEvent;
|
||||
class Overlay;
|
||||
class ImageSwitcher;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
@@ -29,18 +30,24 @@ public:
|
||||
void warn(std::string text);
|
||||
void setOverlay(Overlay* overlay);
|
||||
void setDebugMode(bool debugModeIn) {debugMode = debugModeIn;}
|
||||
void setBaseOptions(const ImageDisplayOptions_t &baseOptionsIn) { baseImageOptions = baseOptionsIn; }
|
||||
void setBaseOptions(const ImageDisplayOptions_t &baseOptionsIn);
|
||||
const ImageDisplayOptions_t &getBaseOptions() { return baseImageOptions; }
|
||||
void setImageSwitcher(ImageSwitcher *switcherIn) { switcher = switcherIn; }
|
||||
public slots:
|
||||
void checkWindowSize();
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
unsigned int blurRadius = 20;
|
||||
unsigned int backgroundOpacity = 150;
|
||||
ImageDisplayOptions_t baseImageOptions;
|
||||
bool imageAspectMatchesMonitor = false;
|
||||
ImageDetails_t currentImage;
|
||||
bool debugMode = false;
|
||||
QSize lastScreenSize = {0,0};
|
||||
|
||||
Overlay* overlay;
|
||||
Overlay* overlay = nullptr;
|
||||
ImageSwitcher *switcher = nullptr;
|
||||
|
||||
void drawText(QPixmap& image, int margin, int fontsize, QString text, int alignment);
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ void PathTraverser::LoadOptionsForDirectory(const std::string &directoryPath, Im
|
||||
std::cout << "Fit Aspect:" << options.fitAspectAxisToWindow << std::endl;
|
||||
}
|
||||
}
|
||||
// read json
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user