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> | ||||
49 | 50 | | |||
50 | #include "dolphin_informationpanelsettings.h" | 51 | #include "dolphin_informationpanelsettings.h" | ||
51 | #include "phononwidget.h" | 52 | #include "phononwidget.h" | ||
52 | #include "pixmapviewer.h" | 53 | #include "pixmapviewer.h" | ||
53 | 54 | | |||
54 | InformationPanelContent::InformationPanelContent(QWidget* parent) : | 55 | InformationPanelContent::InformationPanelContent(QWidget* parent) : | ||
55 | QWidget(parent), | 56 | QWidget(parent), | ||
56 | m_item(), | 57 | m_item(), | ||
57 | m_previewJob(nullptr), | 58 | m_previewJob(nullptr), | ||
58 | m_outdatedPreviewTimer(nullptr), | 59 | m_outdatedPreviewTimer(nullptr), | ||
59 | m_preview(nullptr), | 60 | m_preview(nullptr), | ||
60 | m_phononWidget(nullptr), | 61 | m_phononWidget(nullptr), | ||
61 | m_nameLabel(nullptr), | 62 | m_nameLabel(nullptr), | ||
62 | m_metaDataWidget(nullptr), | 63 | m_metaDataWidget(nullptr), | ||
63 | m_metaDataArea(nullptr), | 64 | m_metaDataArea(nullptr), | ||
64 | m_placesItemModel(nullptr) | 65 | m_placesItemModel(nullptr), | ||
66 | m_usePhonon(false) | ||||
65 | { | 67 | { | ||
66 | parent->installEventFilter(this); | 68 | parent->installEventFilter(this); | ||
67 | 69 | | |||
68 | // Initialize timer for disabling an outdated preview with a small | 70 | // Initialize timer for disabling an outdated preview with a small | ||
69 | // delay. This prevents flickering if the new preview can be generated | 71 | // delay. This prevents flickering if the new preview can be generated | ||
70 | // within a very small timeframe. | 72 | // within a very small timeframe. | ||
71 | m_outdatedPreviewTimer = new QTimer(this); | 73 | m_outdatedPreviewTimer = new QTimer(this); | ||
72 | m_outdatedPreviewTimer->setInterval(300); | 74 | m_outdatedPreviewTimer->setInterval(300); | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 163 | if (item != m_item) { | |||
163 | 165 | | |||
164 | refreshPreview(); | 166 | refreshPreview(); | ||
165 | refreshMetaData(); | 167 | refreshMetaData(); | ||
166 | } | 168 | } | ||
167 | } | 169 | } | ||
168 | 170 | | |||
169 | void InformationPanelContent::refreshPreview() | 171 | void InformationPanelContent::refreshPreview() | ||
170 | { | 172 | { | ||
171 | // If there is a preview job, kill it to prevent that we have jobs for | 173 | // 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). | 174 | // 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) { | 175 | if (m_previewJob) { | ||
174 | m_previewJob->kill(); | 176 | m_previewJob->kill(); | ||
175 | } | 177 | } | ||
176 | 178 | | |||
179 | m_preview->setCursor(Qt::ArrowCursor); | ||||
180 | m_usePhonon = false; | ||||
177 | setNameLabelText(m_item.text()); | 181 | setNameLabelText(m_item.text()); | ||
178 | if (InformationPanelSettings::previewsShown()) { | 182 | if (InformationPanelSettings::previewsShown()) { | ||
179 | 183 | | |||
180 | const QUrl itemUrl = m_item.url(); | 184 | const QUrl itemUrl = m_item.url(); | ||
181 | const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty(); | 185 | const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty(); | ||
182 | if (isSearchUrl) { | 186 | if (isSearchUrl) { | ||
183 | m_preview->show(); | 187 | m_preview->show(); | ||
184 | 188 | | |||
Show All 26 Lines | 194 | } else { | |||
211 | 215 | | |||
212 | connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, | 216 | connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, | ||
213 | this, &InformationPanelContent::showPreview); | 217 | this, &InformationPanelContent::showPreview); | ||
214 | connect(m_previewJob.data(), &KIO::PreviewJob::failed, | 218 | connect(m_previewJob.data(), &KIO::PreviewJob::failed, | ||
215 | this, &InformationPanelContent::showIcon); | 219 | this, &InformationPanelContent::showIcon); | ||
216 | 220 | | |||
217 | const QString mimeType = m_item.mimetype(); | 221 | const QString mimeType = m_item.mimetype(); | ||
218 | const bool isVideo = mimeType.startsWith(QLatin1String("video/")); | 222 | const bool isVideo = mimeType.startsWith(QLatin1String("video/")); | ||
219 | const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo; | 223 | m_usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo; | ||
220 | 224 | | |||
221 | if (usePhonon) { | 225 | if (m_usePhonon) { | ||
226 | // change the cursor | ||||
227 | m_preview->setCursor(Qt::PointingHandCursor); | ||||
222 | 228 | | |||
223 | if (InformationPanelSettings::previewsAutoPlay() && isVideo) { | 229 | if (InformationPanelSettings::previewsAutoPlay() && isVideo) { | ||
224 | // hides the preview now to avoid flickering when the autoplay video starts | 230 | // hides the preview now to avoid flickering when the autoplay video starts | ||
225 | m_preview->hide(); | 231 | m_preview->hide(); | ||
226 | } else { | 232 | } else { | ||
227 | // the video won't play before the preview is displayed | 233 | // the video won't play before the preview is displayed | ||
228 | m_preview->show(); | 234 | m_preview->show(); | ||
235 | m_preview->installEventFilter(m_phononWidget); | ||||
229 | } | 236 | } | ||
230 | 237 | | |||
231 | m_phononWidget->show(); | 238 | m_phononWidget->show(); | ||
232 | m_phononWidget->setUrl(m_item.targetUrl(), isVideo ? PhononWidget::MediaKind::Video : PhononWidget::MediaKind::Audio); | 239 | m_phononWidget->setUrl(m_item.targetUrl(), isVideo ? PhononWidget::MediaKind::Video : PhononWidget::MediaKind::Audio); | ||
233 | m_phononWidget->setVideoSize(m_preview->size()); | 240 | m_phononWidget->setVideoSize(m_preview->size()); | ||
234 | } else { | 241 | } else { | ||
235 | // When we don't need it, hide the phonon widget first to avoid flickering | 242 | // When we don't need it, hide the phonon widget first to avoid flickering | ||
236 | m_phononWidget->hide(); | 243 | m_phononWidget->hide(); | ||
237 | m_preview->show(); | 244 | m_preview->show(); | ||
245 | m_preview->removeEventFilter(m_phononWidget); | ||||
238 | } | 246 | } | ||
239 | } | 247 | } | ||
240 | } else { | 248 | } else { | ||
241 | m_preview->hide(); | 249 | m_preview->hide(); | ||
242 | m_phononWidget->hide(); | 250 | m_phononWidget->hide(); | ||
243 | } | 251 | } | ||
244 | } | 252 | } | ||
245 | 253 | | |||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | |||||
318 | void InformationPanelContent::showPreview(const KFileItem& item, | 326 | void InformationPanelContent::showPreview(const KFileItem& item, | ||
319 | const QPixmap& pixmap) | 327 | const QPixmap& pixmap) | ||
320 | { | 328 | { | ||
321 | m_outdatedPreviewTimer->stop(); | 329 | m_outdatedPreviewTimer->stop(); | ||
322 | Q_UNUSED(item); | 330 | Q_UNUSED(item); | ||
323 | 331 | | |||
324 | QPixmap p = pixmap; | 332 | QPixmap p = pixmap; | ||
325 | KIconLoader::global()->drawOverlays(item.overlays(), p, KIconLoader::Desktop); | 333 | KIconLoader::global()->drawOverlays(item.overlays(), p, KIconLoader::Desktop); | ||
334 | | ||||
335 | if (m_usePhonon) { | ||||
336 | // adds a play arrow | ||||
337 | auto icon = QIcon::fromTheme(QStringLiteral("media-playback-start")); | ||||
338 | auto pixicon = icon.pixmap(64, 64); | ||||
339 | | ||||
340 | QPainter painter(&p); | ||||
elvisangelaccio: Please always use camelCase. | |||||
341 | painter.drawPixmap(pixmap.width() / 2 - static_cast<int>(pixicon.width() / 2 / pixicon.devicePixelRatio()), | ||||
342 | pixmap.height() / 2 - static_cast<int>(pixicon.height() / 2 / pixicon.devicePixelRatio()), | ||||
elvisangelaccio: Is it possible to not hardcode these numbers? | |||||
343 | pixicon); | ||||
344 | } | ||||
345 | | ||||
326 | m_preview->setPixmap(p); | 346 | m_preview->setPixmap(p); | ||
327 | } | 347 | } | ||
328 | 348 | | |||
329 | void InformationPanelContent::markOutdatedPreview() | 349 | void InformationPanelContent::markOutdatedPreview() | ||
elvisangelaccio: Coding style: opening brace should go to the end of previous line. | |||||
330 | { | 350 | { | ||
331 | KIconEffect *iconEffect = KIconLoader::global()->iconEffect(); | 351 | KIconEffect *iconEffect = KIconLoader::global()->iconEffect(); | ||
332 | QPixmap disabledPixmap = iconEffect->apply(m_preview->pixmap(), | 352 | QPixmap disabledPixmap = iconEffect->apply(m_preview->pixmap(), | ||
333 | KIconLoader::Desktop, | 353 | KIconLoader::Desktop, | ||
334 | KIconLoader::DisabledState); | 354 | KIconLoader::DisabledState); | ||
335 | m_preview->setPixmap(disabledPixmap); | 355 | m_preview->setPixmap(disabledPixmap); | ||
336 | } | 356 | } | ||
337 | 357 | | |||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
Why remove this comment? We are still killing the preview job here, aren't we?