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> | ||||
51 | #include <QLinearGradient> | ||||
52 | #include <QPolygon> | ||||
49 | 53 | | |||
50 | #include "dolphin_informationpanelsettings.h" | 54 | #include "dolphin_informationpanelsettings.h" | ||
51 | #include "phononwidget.h" | 55 | #include "phononwidget.h" | ||
52 | #include "pixmapviewer.h" | 56 | #include "pixmapviewer.h" | ||
53 | 57 | | |||
58 | const int PLAY_ARROW_SIZE = 24; | ||||
59 | const int PLAY_ARROW_BORDER_SIZE = 2; | ||||
60 | | ||||
54 | InformationPanelContent::InformationPanelContent(QWidget* parent) : | 61 | InformationPanelContent::InformationPanelContent(QWidget* parent) : | ||
55 | QWidget(parent), | 62 | QWidget(parent), | ||
56 | m_item(), | 63 | m_item(), | ||
57 | m_previewJob(nullptr), | 64 | m_previewJob(nullptr), | ||
58 | m_outdatedPreviewTimer(nullptr), | 65 | m_outdatedPreviewTimer(nullptr), | ||
59 | m_preview(nullptr), | 66 | m_preview(nullptr), | ||
60 | m_phononWidget(nullptr), | 67 | m_phononWidget(nullptr), | ||
61 | m_nameLabel(nullptr), | 68 | m_nameLabel(nullptr), | ||
62 | m_metaDataWidget(nullptr), | 69 | m_metaDataWidget(nullptr), | ||
63 | m_metaDataArea(nullptr), | 70 | m_metaDataArea(nullptr), | ||
64 | m_placesItemModel(nullptr) | 71 | m_placesItemModel(nullptr), | ||
72 | m_usePhonon(false) | ||||
65 | { | 73 | { | ||
66 | parent->installEventFilter(this); | 74 | parent->installEventFilter(this); | ||
67 | 75 | | |||
68 | // Initialize timer for disabling an outdated preview with a small | 76 | // Initialize timer for disabling an outdated preview with a small | ||
69 | // delay. This prevents flickering if the new preview can be generated | 77 | // delay. This prevents flickering if the new preview can be generated | ||
70 | // within a very small timeframe. | 78 | // within a very small timeframe. | ||
71 | m_outdatedPreviewTimer = new QTimer(this); | 79 | m_outdatedPreviewTimer = new QTimer(this); | ||
72 | m_outdatedPreviewTimer->setInterval(300); | 80 | m_outdatedPreviewTimer->setInterval(300); | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 163 | { | |||
156 | InformationPanelSettings::self()->save(); | 164 | InformationPanelSettings::self()->save(); | ||
157 | } | 165 | } | ||
158 | 166 | | |||
159 | void InformationPanelContent::showItem(const KFileItem& item) | 167 | void InformationPanelContent::showItem(const KFileItem& item) | ||
160 | { | 168 | { | ||
161 | if (item != m_item) { | 169 | if (item != m_item) { | ||
162 | m_item = item; | 170 | m_item = item; | ||
163 | 171 | | |||
164 | refreshPreview(); | | |||
165 | refreshMetaData(); | 172 | refreshMetaData(); | ||
166 | } | 173 | } | ||
174 | refreshPreview(); | ||||
167 | } | 175 | } | ||
168 | 176 | | |||
169 | void InformationPanelContent::refreshPreview() | 177 | void InformationPanelContent::refreshPreview() | ||
170 | { | 178 | { | ||
171 | // If there is a preview job, kill it to prevent that we have jobs for | 179 | // 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). | 180 | // 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) { | 181 | if (m_previewJob) { | ||
174 | m_previewJob->kill(); | 182 | m_previewJob->kill(); | ||
175 | } | 183 | } | ||
176 | 184 | | |||
185 | m_preview->setCursor(Qt::ArrowCursor); | ||||
186 | m_usePhonon = false; | ||||
177 | setNameLabelText(m_item.text()); | 187 | setNameLabelText(m_item.text()); | ||
178 | if (InformationPanelSettings::previewsShown()) { | 188 | if (InformationPanelSettings::previewsShown()) { | ||
179 | 189 | | |||
180 | const QUrl itemUrl = m_item.url(); | 190 | const QUrl itemUrl = m_item.url(); | ||
181 | const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty(); | 191 | const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty(); | ||
182 | if (isSearchUrl) { | 192 | if (isSearchUrl) { | ||
183 | m_preview->show(); | 193 | m_preview->show(); | ||
184 | 194 | | |||
Show All 26 Lines | 200 | } else { | |||
211 | 221 | | |||
212 | connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, | 222 | connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, | ||
213 | this, &InformationPanelContent::showPreview); | 223 | this, &InformationPanelContent::showPreview); | ||
214 | connect(m_previewJob.data(), &KIO::PreviewJob::failed, | 224 | connect(m_previewJob.data(), &KIO::PreviewJob::failed, | ||
215 | this, &InformationPanelContent::showIcon); | 225 | this, &InformationPanelContent::showIcon); | ||
216 | 226 | | |||
217 | const QString mimeType = m_item.mimetype(); | 227 | const QString mimeType = m_item.mimetype(); | ||
218 | const bool isVideo = mimeType.startsWith(QLatin1String("video/")); | 228 | const bool isVideo = mimeType.startsWith(QLatin1String("video/")); | ||
219 | const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo; | 229 | m_usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo; | ||
220 | 230 | | |||
221 | if (usePhonon) { | 231 | if (m_usePhonon) { | ||
232 | if (m_phononWidget->state() != Phonon::State::PlayingState || | ||||
233 | m_item.targetUrl() != m_phononWidget->url()) { | ||||
234 | // change the cursor | ||||
235 | m_preview->setCursor(Qt::PointingHandCursor); | ||||
236 | m_preview->installEventFilter(m_phononWidget); | ||||
222 | 237 | | |||
223 | if (InformationPanelSettings::previewsAutoPlay() && isVideo) { | 238 | if (InformationPanelSettings::previewsAutoPlay() && isVideo) { | ||
224 | // hides the preview now to avoid flickering when the autoplay video starts | 239 | // hides the preview now to avoid flickering when the autoplay video starts | ||
225 | m_preview->hide(); | 240 | m_preview->hide(); | ||
226 | } else { | 241 | } else { | ||
227 | // the video won't play before the preview is displayed | 242 | // the video won't play before the preview is displayed | ||
228 | m_preview->show(); | 243 | m_preview->show(); | ||
229 | } | 244 | } | ||
230 | 245 | | |||
231 | m_phononWidget->show(); | 246 | m_phononWidget->show(); | ||
232 | m_phononWidget->setUrl(m_item.targetUrl(), isVideo ? PhononWidget::MediaKind::Video : PhononWidget::MediaKind::Audio); | 247 | m_phononWidget->setUrl(m_item.targetUrl(), isVideo ? PhononWidget::MediaKind::Video : PhononWidget::MediaKind::Audio); | ||
233 | m_phononWidget->setVideoSize(m_preview->size()); | 248 | m_phononWidget->setVideoSize(m_preview->size()); | ||
249 | } | ||||
234 | } else { | 250 | } else { | ||
235 | // When we don't need it, hide the phonon widget first to avoid flickering | 251 | // When we don't need it, hide the phonon widget first to avoid flickering | ||
236 | m_phononWidget->hide(); | 252 | m_phononWidget->hide(); | ||
237 | m_preview->show(); | 253 | m_preview->show(); | ||
254 | m_preview->removeEventFilter(m_phononWidget); | ||||
238 | } | 255 | } | ||
239 | } | 256 | } | ||
240 | } else { | 257 | } else { | ||
241 | m_preview->hide(); | 258 | m_preview->hide(); | ||
242 | m_phononWidget->hide(); | 259 | m_phononWidget->hide(); | ||
243 | } | 260 | } | ||
244 | } | 261 | } | ||
245 | 262 | | |||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | |||||
318 | void InformationPanelContent::showPreview(const KFileItem& item, | 335 | void InformationPanelContent::showPreview(const KFileItem& item, | ||
319 | const QPixmap& pixmap) | 336 | const QPixmap& pixmap) | ||
320 | { | 337 | { | ||
321 | m_outdatedPreviewTimer->stop(); | 338 | m_outdatedPreviewTimer->stop(); | ||
322 | Q_UNUSED(item); | 339 | Q_UNUSED(item); | ||
323 | 340 | | |||
324 | QPixmap p = pixmap; | 341 | QPixmap p = pixmap; | ||
325 | KIconLoader::global()->drawOverlays(item.overlays(), p, KIconLoader::Desktop); | 342 | KIconLoader::global()->drawOverlays(item.overlays(), p, KIconLoader::Desktop); | ||
343 | | ||||
344 | if (m_usePhonon) { | ||||
345 | // adds a play arrow | ||||
346 | | ||||
347 | // compute relative pixel positions | ||||
348 | const int zero_x = static_cast<int>(p.width() / 2 - PLAY_ARROW_SIZE / 2 / devicePixelRatio()); | ||||
349 | const int zero_y = static_cast<int>(p.height() / 2 - PLAY_ARROW_SIZE / 2 / devicePixelRatio()); | ||||
elvisangelaccio: Please always use camelCase. | |||||
350 | | ||||
351 | QPolygon arrow; | ||||
elvisangelaccio: Is it possible to not hardcode these numbers? | |||||
352 | arrow << QPoint(zero_x, zero_y); | ||||
353 | arrow << QPoint(zero_x, zero_y + PLAY_ARROW_SIZE); | ||||
354 | arrow << QPoint(zero_x + PLAY_ARROW_SIZE, zero_y + PLAY_ARROW_SIZE / 2); | ||||
355 | | ||||
356 | QPainterPath path; | ||||
357 | path.addPolygon(arrow); | ||||
358 | | ||||
elvisangelaccio: Coding style: opening brace should go to the end of previous line. | |||||
359 | QLinearGradient gradient(QPointF(zero_x, zero_y), | ||||
360 | QPointF(zero_x + PLAY_ARROW_SIZE,zero_y + PLAY_ARROW_SIZE)); | ||||
361 | | ||||
362 | QColor whiteColor = Qt::white; | ||||
363 | QColor blackColor = Qt::black; | ||||
364 | gradient.setColorAt(0, whiteColor); | ||||
365 | gradient.setColorAt(1, blackColor); | ||||
366 | | ||||
367 | QBrush brush(gradient); | ||||
368 | | ||||
369 | QPainter painter(&p); | ||||
370 | | ||||
371 | QPen pen(blackColor, PLAY_ARROW_BORDER_SIZE, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); | ||||
372 | painter.setPen(pen); | ||||
373 | | ||||
374 | painter.setRenderHint(QPainter::Antialiasing); | ||||
375 | painter.drawPolygon(arrow); | ||||
376 | painter.fillPath(path, brush); | ||||
377 | } | ||||
378 | | ||||
326 | m_preview->setPixmap(p); | 379 | m_preview->setPixmap(p); | ||
327 | } | 380 | } | ||
328 | 381 | | |||
329 | void InformationPanelContent::markOutdatedPreview() | 382 | void InformationPanelContent::markOutdatedPreview() | ||
330 | { | 383 | { | ||
331 | KIconEffect *iconEffect = KIconLoader::global()->iconEffect(); | 384 | KIconEffect *iconEffect = KIconLoader::global()->iconEffect(); | ||
332 | QPixmap disabledPixmap = iconEffect->apply(m_preview->pixmap(), | 385 | QPixmap disabledPixmap = iconEffect->apply(m_preview->pixmap(), | ||
333 | KIconLoader::Desktop, | 386 | 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?