diff --git a/README.md b/README.md index da2f9f0..8521979 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,15 @@ Simple slideshow showing random images from specified directory slide /path/to/images ``` +## Dependencies + +* libexif +* qt5 + +``` +sudo apt install libexif-dev qtdeclarative5-dev-tools +``` + ## Build ``` diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 308a5e6..1fe18e7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -18,7 +20,7 @@ MainWindow::MainWindow(QWidget *parent) : QApplication::setOverrideCursor(Qt::BlankCursor); QLabel *label = this->findChild("image"); setCentralWidget(label); - label->setStyleSheet("QLabel { background-color: rgba(0, 0, 0, 230);}"); + label->setStyleSheet("QLabel { background-color: rgba(0, 0, 0, 180);}"); label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); update(); @@ -51,32 +53,84 @@ void MainWindow::setImage(std::string path) updateImage(); } +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() { if (currentImage == "") - { return; - } - QLabel *label = this->findChild("image"); + QPixmap p( currentImage.c_str() ); - int w = label->width(); - int h = label->height(); - QPixmap scaled = p.scaled(w,h,Qt::KeepAspectRatio); + QPixmap rotated = getRotatedPixmap(p); + QPixmap scaled = getScaledPixmap(rotated); + + QLabel *label = this->findChild("image"); label->setPixmap(scaled); + drawBackground(rotated, scaled); + update(); +} +QPixmap MainWindow::getRotatedPixmap(const QPixmap& p) +{ + QMatrix matrix; + matrix.rotate(getImageRotation()); + return p.transformed(matrix); +} + +QPixmap MainWindow::getScaledPixmap(const QPixmap& p) +{ + int w = width(); + int h = height(); + return p.scaled(w, h, Qt::KeepAspectRatio); +} + +void MainWindow::drawBackground(const QPixmap& originalSize, const QPixmap& scaled) +{ QPalette palette; if (scaled.width() < width()) { - QPixmap background = p.scaledToWidth(width()); + QPixmap background = originalSize.scaledToWidth(width()); QRect rect(0, (background.height() - height())/2, width(), height()); background = background.copy(rect); palette.setBrush(QPalette::Background, background); } else { - QPixmap background = p.scaledToHeight(height()); + QPixmap background = originalSize.scaledToHeight(height()); QRect rect((background.width() - width())/2, 0, width(), height()); background = background.copy(rect); palette.setBrush(QPalette::Background, background); } this->setPalette(palette); - update(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 4c24c07..e6d88db 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include +#include namespace Ui { class MainWindow; @@ -25,6 +26,11 @@ private: QLabel *image; std::string currentImage; void updateImage(); + int getImageRotation(); + + QPixmap getRotatedPixmap(const QPixmap& p); + QPixmap getScaledPixmap(const QPixmap& p); + void drawBackground(const QPixmap& originalSize, const QPixmap& scaled); }; #endif // MAINWINDOW_H diff --git a/src/slide.pro b/src/slide.pro index 5142755..e0d3bdc 100644 --- a/src/slide.pro +++ b/src/slide.pro @@ -37,3 +37,5 @@ FORMS += \ target.path = /usr/local/bin/ INSTALLS += target + +unix|win32: LIBS += -lexif diff --git a/src/slide.pro.user b/src/slide.pro.user new file mode 100644 index 0000000..4c24fa9 --- /dev/null +++ b/src/slide.pro.user @@ -0,0 +1,336 @@ + + + + + + EnvironmentId + {d48a34de-ff8d-4757-9c3b-132a14098d6d} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {608421ee-2bdd-4e28-85e9-148db782e738} + 0 + 0 + 0 + + /home/manuel/slide/build-slide-Desktop-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Erstellen + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Bereinigen + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/manuel/slide/build-slide-Desktop-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Erstellen + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Bereinigen + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/manuel/slide/build-slide-Desktop-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Erstellen + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Bereinigen + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deployment + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deployment-Konfiguration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + slide + + Qt4ProjectManager.Qt4RunConfiguration:/home/manuel/slide/src/slide.pro + true + + slide.pro + false + + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + +