Changeset View
Changeset View
Standalone View
Standalone View
src/panels/information/informationpanelcontent.cpp
Show All 40 Lines | |||||
41 | 41 | | |||
42 | #include <QLabel> | 42 | #include <QLabel> | ||
43 | #include <QDialogButtonBox> | 43 | #include <QDialogButtonBox> | ||
44 | #include <QScrollArea> | 44 | #include <QScrollArea> | ||
45 | #include <QTextLayout> | 45 | #include <QTextLayout> | ||
46 | #include <QTimer> | 46 | #include <QTimer> | ||
47 | #include <QVBoxLayout> | 47 | #include <QVBoxLayout> | ||
48 | #include <QStyle> | 48 | #include <QStyle> | ||
49 | #include <QPainter> | ||||
50 | #include <QBitmap> | ||||
49 | 51 | | |||
50 | #include "dolphin_informationpanelsettings.h" | 52 | #include "dolphin_informationpanelsettings.h" | ||
51 | #include "phononwidget.h" | 53 | #include "phononwidget.h" | ||
52 | #include "pixmapviewer.h" | 54 | #include "pixmapviewer.h" | ||
53 | 55 | | |||
54 | InformationPanelContent::InformationPanelContent(QWidget* parent) : | 56 | InformationPanelContent::InformationPanelContent(QWidget* parent) : | ||
55 | QWidget(parent), | 57 | QWidget(parent), | ||
56 | m_item(), | 58 | m_item(), | ||
57 | m_previewJob(nullptr), | 59 | m_previewJob(nullptr), | ||
58 | m_outdatedPreviewTimer(nullptr), | 60 | m_outdatedPreviewTimer(nullptr), | ||
59 | m_preview(nullptr), | 61 | m_preview(nullptr), | ||
60 | m_phononWidget(nullptr), | 62 | m_phononWidget(nullptr), | ||
61 | m_nameLabel(nullptr), | 63 | m_nameLabel(nullptr), | ||
62 | m_metaDataWidget(nullptr), | 64 | m_metaDataWidget(nullptr), | ||
63 | m_metaDataArea(nullptr), | 65 | m_metaDataArea(nullptr), | ||
64 | m_placesItemModel(nullptr) | 66 | m_placesItemModel(nullptr), | ||
67 | m_usePhonon(false) | ||||
65 | { | 68 | { | ||
66 | parent->installEventFilter(this); | 69 | parent->installEventFilter(this); | ||
67 | 70 | | |||
68 | // Initialize timer for disabling an outdated preview with a small | 71 | // Initialize timer for disabling an outdated preview with a small | ||
69 | // delay. This prevents flickering if the new preview can be generated | 72 | // delay. This prevents flickering if the new preview can be generated | ||
70 | // within a very small timeframe. | 73 | // within a very small timeframe. | ||
71 | m_outdatedPreviewTimer = new QTimer(this); | 74 | m_outdatedPreviewTimer = new QTimer(this); | ||
72 | m_outdatedPreviewTimer->setInterval(300); | 75 | m_outdatedPreviewTimer->setInterval(300); | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 158 | { | |||
156 | InformationPanelSettings::self()->save(); | 159 | InformationPanelSettings::self()->save(); | ||
157 | } | 160 | } | ||
158 | 161 | | |||
159 | void InformationPanelContent::showItem(const KFileItem& item) | 162 | void InformationPanelContent::showItem(const KFileItem& item) | ||
160 | { | 163 | { | ||
161 | if (item != m_item) { | 164 | if (item != m_item) { | ||
162 | m_item = item; | 165 | m_item = item; | ||
163 | 166 | | |||
164 | refreshPreview(); | | |||
165 | refreshMetaData(); | 167 | refreshMetaData(); | ||
166 | } | 168 | } | ||
169 | refreshPreview(); | ||||
167 | } | 170 | } | ||
168 | 171 | | |||
169 | void InformationPanelContent::refreshPreview() | 172 | void InformationPanelContent::refreshPreview() | ||
170 | { | 173 | { | ||
171 | // If there is a preview job, kill it to prevent that we have jobs for | 174 | // If there is a preview job, kill it to prevent that we have jobs for | ||
172 | // multiple items running, and thus a race condition (bug 250787). | 175 | // multiple items running, and thus a race condition (bug 250787). | ||
elvisangelaccio: Why remove this comment? We are still killing the preview job here, aren't we? | |||||
The comment was moved to InformationPanelContent::refreshPreview but I have re-added it here as well. meven: The comment was moved to InformationPanelContent::refreshPreview but I have re-added it here as… | |||||
173 | if (m_previewJob) { | 176 | if (m_previewJob) { | ||
174 | m_previewJob->kill(); | 177 | m_previewJob->kill(); | ||
175 | } | 178 | } | ||
176 | 179 | | |||
180 | m_preview->setCursor(Qt::ArrowCursor); | ||||
181 | m_usePhonon = false; | ||||
177 | setNameLabelText(m_item.text()); | 182 | setNameLabelText(m_item.text()); | ||
178 | if (InformationPanelSettings::previewsShown()) { | 183 | if (InformationPanelSettings::previewsShown()) { | ||
179 | 184 | | |||
180 | const QUrl itemUrl = m_item.url(); | 185 | const QUrl itemUrl = m_item.url(); | ||
181 | const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty(); | 186 | const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty(); | ||
182 | if (isSearchUrl) { | 187 | if (isSearchUrl) { | ||
183 | m_preview->show(); | 188 | m_preview->show(); | ||
184 | 189 | | |||
Show All 26 Lines | 195 | } else { | |||
211 | 216 | | |||
212 | connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, | 217 | connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, | ||
213 | this, &InformationPanelContent::showPreview); | 218 | this, &InformationPanelContent::showPreview); | ||
214 | connect(m_previewJob.data(), &KIO::PreviewJob::failed, | 219 | connect(m_previewJob.data(), &KIO::PreviewJob::failed, | ||
215 | this, &InformationPanelContent::showIcon); | 220 | this, &InformationPanelContent::showIcon); | ||
216 | 221 | | |||
217 | const QString mimeType = m_item.mimetype(); | 222 | const QString mimeType = m_item.mimetype(); | ||
218 | const bool isVideo = mimeType.startsWith(QLatin1String("video/")); | 223 | const bool isVideo = mimeType.startsWith(QLatin1String("video/")); | ||
219 | const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo; | 224 | m_usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo; | ||
220 | 225 | | |||
221 | if (usePhonon) { | 226 | if (m_usePhonon) { | ||
227 | // change the cursor | ||||
228 | m_preview->setCursor(Qt::PointingHandCursor); | ||||
222 | 229 | | |||
223 | if (InformationPanelSettings::previewsAutoPlay() && isVideo) { | 230 | if (InformationPanelSettings::previewsAutoPlay() && isVideo) { | ||
224 | // hides the preview now to avoid flickering when the autoplay video starts | 231 | // hides the preview now to avoid flickering when the autoplay video starts | ||
225 | m_preview->hide(); | 232 | m_preview->hide(); | ||
226 | } else { | 233 | } else { | ||
227 | // the video won't play before the preview is displayed | 234 | // the video won't play before the preview is displayed | ||
228 | m_preview->show(); | 235 | m_preview->show(); | ||
236 | m_preview->installEventFilter(m_phononWidget); | ||||
229 | } | 237 | } | ||
230 | 238 | | |||
231 | m_phononWidget->show(); | 239 | m_phononWidget->show(); | ||
232 | m_phononWidget->setUrl(m_item.targetUrl(), isVideo ? PhononWidget::MediaKind::Video : PhononWidget::MediaKind::Audio); | 240 | m_phononWidget->setUrl(m_item.targetUrl(), isVideo ? PhononWidget::MediaKind::Video : PhononWidget::MediaKind::Audio); | ||
233 | m_phononWidget->setVideoSize(m_preview->size()); | 241 | m_phononWidget->setVideoSize(m_preview->size()); | ||
234 | } else { | 242 | } else { | ||
235 | // When we don't need it, hide the phonon widget first to avoid flickering | 243 | // When we don't need it, hide the phonon widget first to avoid flickering | ||
236 | m_phononWidget->hide(); | 244 | m_phononWidget->hide(); | ||
237 | m_preview->show(); | 245 | m_preview->show(); | ||
246 | m_preview->removeEventFilter(m_phononWidget); | ||||
238 | } | 247 | } | ||
239 | } | 248 | } | ||
240 | } else { | 249 | } else { | ||
241 | m_preview->hide(); | 250 | m_preview->hide(); | ||
242 | m_phononWidget->hide(); | 251 | m_phononWidget->hide(); | ||
243 | } | 252 | } | ||
244 | } | 253 | } | ||
245 | 254 | | |||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | |||||
318 | void InformationPanelContent::showPreview(const KFileItem& item, | 327 | void InformationPanelContent::showPreview(const KFileItem& item, | ||
319 | const QPixmap& pixmap) | 328 | const QPixmap& pixmap) | ||
320 | { | 329 | { | ||
321 | m_outdatedPreviewTimer->stop(); | 330 | m_outdatedPreviewTimer->stop(); | ||
322 | Q_UNUSED(item); | 331 | Q_UNUSED(item); | ||
323 | 332 | | |||
324 | QPixmap p = pixmap; | 333 | QPixmap p = pixmap; | ||
325 | KIconLoader::global()->drawOverlays(item.overlays(), p, KIconLoader::Desktop); | 334 | KIconLoader::global()->drawOverlays(item.overlays(), p, KIconLoader::Desktop); | ||
335 | | ||||
336 | if (m_usePhonon) { | ||||
337 | // adds a play arrow | ||||
338 | auto icon = QIcon::fromTheme(QStringLiteral("media-playback-start")); | ||||
339 | | ||||
340 | // inner arrow | ||||
341 | auto pixicon = icon.pixmap(44, 44); | ||||
elvisangelaccio: Please always use camelCase. | |||||
342 | // border of the arrow | ||||
343 | auto pixborder = icon.pixmap(48, 48); | ||||
elvisangelaccio: Is it possible to not hardcode these numbers? | |||||
344 | | ||||
345 | QImage img = pixborder.toImage(); | ||||
346 | for(int i=0; i<pixborder.width(); i++) | ||||
347 | for(int j=0; j<pixborder.height(); j++) | ||||
348 | { | ||||
349 | if(qAlpha(img.pixel(i,j)) != 0) | ||||
350 | { | ||||
elvisangelaccio: Coding style: opening brace should go to the end of previous line. | |||||
351 | // invert the color | ||||
352 | QColor c = img.pixelColor(i,j); | ||||
353 | c.setRed(255 - c.red()); | ||||
354 | c.setGreen(255 - c.green()); | ||||
355 | c.setBlue(255 - c.blue()); | ||||
356 | img.setPixelColor(i,j, c); | ||||
357 | } | ||||
358 | } | ||||
359 | pixborder = QPixmap::fromImage(img); | ||||
360 | | ||||
361 | QPainter painter(&p); | ||||
362 | | ||||
363 | painter.drawPixmap(p.width() / 2 - static_cast<int>(pixborder.width() / 2 / p.devicePixelRatio()), | ||||
364 | p.height() / 2 - static_cast<int>(pixborder.height() / 2 / p.devicePixelRatio()), | ||||
365 | pixborder); | ||||
366 | | ||||
367 | painter.drawPixmap(p.width() / 2 - static_cast<int>(pixicon.width() / 2 / p.devicePixelRatio()), | ||||
368 | p.height() / 2 - static_cast<int>(pixicon.height() / 2 / p.devicePixelRatio()), | ||||
369 | pixicon); | ||||
370 | | ||||
371 | } | ||||
372 | | ||||
326 | m_preview->setPixmap(p); | 373 | m_preview->setPixmap(p); | ||
327 | } | 374 | } | ||
328 | 375 | | |||
329 | void InformationPanelContent::markOutdatedPreview() | 376 | void InformationPanelContent::markOutdatedPreview() | ||
330 | { | 377 | { | ||
331 | KIconEffect *iconEffect = KIconLoader::global()->iconEffect(); | 378 | KIconEffect *iconEffect = KIconLoader::global()->iconEffect(); | ||
332 | QPixmap disabledPixmap = iconEffect->apply(m_preview->pixmap(), | 379 | QPixmap disabledPixmap = iconEffect->apply(m_preview->pixmap(), | ||
333 | KIconLoader::Desktop, | 380 | KIconLoader::Desktop, | ||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |
Why remove this comment? We are still killing the preview job here, aren't we?