diff --git a/src/widgetfactory.h b/src/widgetfactory.h --- a/src/widgetfactory.h +++ b/src/widgetfactory.h @@ -70,6 +70,7 @@ QWidget* createRatingWidget(int rating, QWidget* parent); QWidget* createTagWidget(const QStringList& tags, QWidget* parent); QWidget* createCommentWidget(const QString& comment, QWidget* parent); + QWidget* createPhotoOrientationWidget(int exifOrientation, QWidget* parent); QWidget* createValueWidget(const QString& value, QWidget* parent); TagWidget* m_tagWidget; diff --git a/src/widgetfactory.cpp b/src/widgetfactory.cpp --- a/src/widgetfactory.cpp +++ b/src/widgetfactory.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -115,6 +116,9 @@ std::sort(tags.begin(), tags.end(), [&](const QString& s1, const QString& s2){ return coll.compare(s1, s2) < 0; }); widget = createTagWidget( tags, parent ); } + else if (prop == QLatin1String("imageOrientation")) { + widget = createPhotoOrientationWidget( value.toInt(), parent ); + } else { KFormat form; // vHanda: FIXME: Add links! Take m_noLinks into consideration @@ -203,6 +207,58 @@ return ratingWidget; } +QWidget* WidgetFactory::createPhotoOrientationWidget(int exifOrientation, QWidget *parent) +{ + QLabel* orientationWidget = qobject_cast(createValueWidget(QString(), parent)); + + if (exifOrientation < 1 || exifOrientation > 8) { + orientationWidget->setText(i18n("Unknown")); + return orientationWidget; + } + + const QFontMetrics metrics(parent->font()); + + const QIcon previewIcon = QIcon::fromTheme(QStringLiteral("view-preview")); + const QPixmap previewPixmap = previewIcon.pixmap(metrics.height()); + + QMatrix matrix; + + switch (exifOrientation) { + case 1: // top, left (normal, no transformation) + break; + case 2: // top, right + matrix = QMatrix(-1.0, 0.0, 0.0, 1.0, 0.0, 0.0); + break; + case 3: // bottom, right + matrix = QMatrix(-1.0, 0.0, 0.0, -1.0, 0.0, 0.0); + break; + case 4: // bottom, left + matrix = QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); + break; + case 5: // left, top + matrix = QMatrix(0.0, 1.0, 1.0, 0.0, 0.0, 0.0); + break; + case 6: // right, top + matrix = QMatrix(0.0, -1.0, 1.0, 0.0, 0.0, 0.0); + break; + case 7: // right, bottom + matrix = QMatrix(0.0, -1.0, -1.0, 0.0, 0.0, 0.0); + break; + case 8: // left, bottom + matrix = QMatrix(0.0, 1.0, -1.0, 0.0, 0.0, 0.0); + break; + } + + QPixmap result = previewPixmap; + if (!matrix.isIdentity()) { + result = result.transformed(matrix); + result.setDevicePixelRatio(previewPixmap.devicePixelRatioF()); + } + + orientationWidget->setPixmap(result); + + return orientationWidget; +} // The default size hint of QLabel tries to return a square size. // This does not work well in combination with layouts that use