Changeset View
Changeset View
Standalone View
Standalone View
src/widgetfactory.cpp
Show All 23 Lines | |||||
24 | #include "tagwidget.h" | 24 | #include "tagwidget.h" | ||
25 | #include "kcommentwidget_p.h" | 25 | #include "kcommentwidget_p.h" | ||
26 | #include "KRatingWidget" | 26 | #include "KRatingWidget" | ||
27 | 27 | | |||
28 | #include <KFileMetaData/UserMetaData> | 28 | #include <KFileMetaData/UserMetaData> | ||
29 | 29 | | |||
30 | #include <QLabel> | 30 | #include <QLabel> | ||
31 | #include <QCollator> | 31 | #include <QCollator> | ||
32 | #include <QIcon> | ||||
32 | #include <QTime> | 33 | #include <QTime> | ||
33 | #include <QUrl> | 34 | #include <QUrl> | ||
34 | #include <QLocale> | 35 | #include <QLocale> | ||
35 | 36 | | |||
36 | #include <KJob> | 37 | #include <KJob> | ||
37 | #include <KFormat> | 38 | #include <KFormat> | ||
38 | #include <KLocalizedString> | 39 | #include <KLocalizedString> | ||
39 | 40 | | |||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 103 | { | |||
110 | } | 111 | } | ||
111 | else if (prop == QLatin1String("tags")) { | 112 | else if (prop == QLatin1String("tags")) { | ||
112 | QStringList tags = value.toStringList(); | 113 | QStringList tags = value.toStringList(); | ||
113 | QCollator coll; | 114 | QCollator coll; | ||
114 | coll.setNumericMode(true); | 115 | coll.setNumericMode(true); | ||
115 | std::sort(tags.begin(), tags.end(), [&](const QString& s1, const QString& s2){ return coll.compare(s1, s2) < 0; }); | 116 | std::sort(tags.begin(), tags.end(), [&](const QString& s1, const QString& s2){ return coll.compare(s1, s2) < 0; }); | ||
116 | widget = createTagWidget( tags, parent ); | 117 | widget = createTagWidget( tags, parent ); | ||
117 | } | 118 | } | ||
119 | else if (prop == QLatin1String("imageOrientation")) { | ||||
120 | widget = createPhotoOrientationWidget( value.toInt(), parent ); | ||||
121 | } | ||||
118 | else { | 122 | else { | ||
119 | KFormat form; | 123 | KFormat form; | ||
120 | // vHanda: FIXME: Add links! Take m_noLinks into consideration | 124 | // vHanda: FIXME: Add links! Take m_noLinks into consideration | ||
121 | QString valueString; | 125 | QString valueString; | ||
122 | 126 | | |||
123 | if (prop == QLatin1String("duration")) { | 127 | if (prop == QLatin1String("duration")) { | ||
124 | valueString = form.formatDuration(value.toInt() * 1000); | 128 | valueString = form.formatDuration(value.toInt() * 1000); | ||
125 | } else if (prop == QLatin1String("bitRate")) { | 129 | } else if (prop == QLatin1String("bitRate")) { | ||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 194 | { | |||
198 | 202 | | |||
199 | connect(ratingWidget, static_cast<void (KRatingWidget::*)(uint)>(&KRatingWidget::ratingChanged), this, &WidgetFactory::slotRatingChanged); | 203 | connect(ratingWidget, static_cast<void (KRatingWidget::*)(uint)>(&KRatingWidget::ratingChanged), this, &WidgetFactory::slotRatingChanged); | ||
200 | 204 | | |||
201 | m_ratingWidget = ratingWidget; | 205 | m_ratingWidget = ratingWidget; | ||
202 | 206 | | |||
203 | return ratingWidget; | 207 | return ratingWidget; | ||
204 | } | 208 | } | ||
205 | 209 | | |||
210 | QWidget* WidgetFactory::createPhotoOrientationWidget(int exifOrientation, QWidget *parent) | ||||
211 | { | ||||
212 | QLabel* orientationWidget = qobject_cast<QLabel*>(createValueWidget(QString(), parent)); | ||||
213 | | ||||
214 | if (exifOrientation < 1 || exifOrientation > 8) { | ||||
215 | orientationWidget->setText(i18n("Unknown")); | ||||
216 | return orientationWidget; | ||||
217 | } | ||||
218 | | ||||
219 | const QFontMetrics metrics(parent->font()); | ||||
220 | | ||||
221 | const QIcon previewIcon = QIcon::fromTheme(QStringLiteral("view-preview")); | ||||
222 | const QPixmap previewPixmap = previewIcon.pixmap(metrics.height()); | ||||
223 | | ||||
224 | QMatrix matrix; | ||||
225 | | ||||
226 | switch (exifOrientation) { | ||||
227 | case 1: // top, left (normal, no transformation) | ||||
228 | break; | ||||
229 | case 2: // top, right | ||||
230 | matrix = QMatrix(-1.0, 0.0, 0.0, 1.0, 0.0, 0.0); | ||||
231 | break; | ||||
232 | case 3: // bottom, right | ||||
233 | matrix = QMatrix(-1.0, 0.0, 0.0, -1.0, 0.0, 0.0); | ||||
234 | break; | ||||
235 | case 4: // bottom, left | ||||
236 | matrix = QMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); | ||||
237 | break; | ||||
238 | case 5: // left, top | ||||
239 | matrix = QMatrix(0.0, 1.0, 1.0, 0.0, 0.0, 0.0); | ||||
240 | break; | ||||
241 | case 6: // right, top | ||||
242 | matrix = QMatrix(0.0, -1.0, 1.0, 0.0, 0.0, 0.0); | ||||
243 | break; | ||||
244 | case 7: // right, bottom | ||||
245 | matrix = QMatrix(0.0, -1.0, -1.0, 0.0, 0.0, 0.0); | ||||
246 | break; | ||||
247 | case 8: // left, bottom | ||||
248 | matrix = QMatrix(0.0, 1.0, -1.0, 0.0, 0.0, 0.0); | ||||
249 | break; | ||||
250 | } | ||||
251 | | ||||
252 | QPixmap result = previewPixmap; | ||||
253 | if (!matrix.isIdentity()) { | ||||
254 | result = result.transformed(matrix); | ||||
255 | result.setDevicePixelRatio(previewPixmap.devicePixelRatioF()); | ||||
256 | } | ||||
257 | | ||||
258 | orientationWidget->setPixmap(result); | ||||
259 | | ||||
260 | return orientationWidget; | ||||
261 | } | ||||
206 | 262 | | |||
207 | // The default size hint of QLabel tries to return a square size. | 263 | // The default size hint of QLabel tries to return a square size. | ||
208 | // This does not work well in combination with layouts that use | 264 | // This does not work well in combination with layouts that use | ||
209 | // heightForWidth(): In this case it is possible that the content | 265 | // heightForWidth(): In this case it is possible that the content | ||
210 | // of a label might get clipped. By specifying a size hint | 266 | // of a label might get clipped. By specifying a size hint | ||
211 | // with a maximum width that is necessary to contain the whole text, | 267 | // with a maximum width that is necessary to contain the whole text, | ||
212 | // using heightForWidth() assures having a non-clipped text. | 268 | // using heightForWidth() assures having a non-clipped text. | ||
213 | class ValueWidget : public QLabel | 269 | class ValueWidget : public QLabel | ||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |