#include <KIO/PreviewJob>
#include <KIconEffect>
#include <KIconLoader>
+#include <KIconUtils>
#include <KJobWidgets>
#include <KLocalizedString>
#include <KSeparator>
#include <Baloo/FileMetaDataWidget>
-#include <phonon/BackendCapabilities>
-#include <phonon/MediaObject>
-
#include <QDialogButtonBox>
#include <QGesture>
#include <QLabel>
#include <QVBoxLayout>
#include "dolphin_informationpanelsettings.h"
-#include "phononwidget.h"
+#include "mediawidget.h"
#include "pixmapviewer.h"
const int PLAY_ARROW_SIZE = 24;
, m_previewJob(nullptr)
, m_outdatedPreviewTimer(nullptr)
, m_preview(nullptr)
- , m_phononWidget(nullptr)
+ , m_mediaWidget(nullptr)
, m_nameLabel(nullptr)
, m_metaDataWidget(nullptr)
, m_metaDataArea(nullptr)
m_preview->setMinimumWidth(minPreviewWidth);
m_preview->setMinimumHeight(KIconLoader::SizeEnormous);
- m_phononWidget = new PhononWidget(parent);
- m_phononWidget->hide();
- m_phononWidget->setMinimumWidth(minPreviewWidth);
- m_phononWidget->setAutoPlay(InformationPanelSettings::previewsAutoPlay());
- connect(m_phononWidget, &PhononWidget::hasVideoChanged, this, &InformationPanelContent::slotHasVideoChanged);
+ m_mediaWidget = new MediaWidget(parent);
+ m_mediaWidget->hide();
+ m_mediaWidget->setMinimumWidth(minPreviewWidth);
+ m_mediaWidget->setAutoPlay(InformationPanelSettings::previewsAutoPlay());
+ connect(m_mediaWidget, &MediaWidget::hasVideoChanged, this, &InformationPanelContent::slotHasVideoChanged);
// name
m_nameLabel = new QLabel(parent);
viewport->installEventFilter(this);
layout->addWidget(m_preview);
- layout->addWidget(m_phononWidget);
+ layout->addWidget(m_mediaWidget);
layout->addWidget(m_nameLabel);
layout->addWidget(new KSeparator());
layout->addWidget(m_configureLabel);
m_previewJob = new KIO::PreviewJob(KFileItemList() << m_item, QSize(m_preview->width(), m_preview->height()), &plugins);
m_previewJob->setScaleType(KIO::PreviewJob::Unscaled);
m_previewJob->setIgnoreMaximumSize(m_item.isLocalFile() && !m_item.isSlow());
+ m_previewJob->setDevicePixelRatio(devicePixelRatioF());
if (m_previewJob->uiDelegate()) {
KJobWidgets::setWindow(m_previewJob, this);
}
const bool isSearchUrl = itemUrl.scheme().contains(QLatin1String("search")) && m_item.localPath().isEmpty();
if (isSearchUrl) {
m_preview->show();
- m_phononWidget->hide();
+ m_mediaWidget->hide();
// in the case of a search-URL the URL is not readable for humans
// (at least not useful to show in the Information Panel)
const QString mimeType = m_item.mimetype();
const bool isAnimatedImage = m_preview->isAnimatedMimeType(mimeType);
m_isVideo = !isAnimatedImage && mimeType.startsWith(QLatin1String("video/"));
- bool usePhonon = m_isVideo || mimeType.startsWith(QLatin1String("audio/"));
+ bool useMedia = m_isVideo || mimeType.startsWith(QLatin1String("audio/"));
- if (usePhonon) {
+ if (useMedia) {
// change the cursor of the preview
m_preview->setCursor(Qt::PointingHandCursor);
- m_preview->installEventFilter(m_phononWidget);
- m_phononWidget->show();
+ m_preview->installEventFilter(m_mediaWidget);
+
+ m_mediaWidget->show();
// if the video is playing, has been paused or stopped
- // we don't need to update the preview/phonon widget states
+ // we don't need to update the preview/media widget states
// unless the previewed file has changed,
// or the setting previewshown has changed
- if ((m_phononWidget->state() != Phonon::State::PlayingState && m_phononWidget->state() != Phonon::State::PausedState
- && m_phononWidget->state() != Phonon::State::StoppedState)
- || m_item.targetUrl() != m_phononWidget->url() || (!m_preview->isVisible() && !m_phononWidget->isVisible())) {
+ if ((m_mediaWidget->state() != QMediaPlayer::PlayingState && m_mediaWidget->state() != QMediaPlayer::PausedState
+ && m_mediaWidget->state() != QMediaPlayer::StoppedState)
+ || m_item.targetUrl() != m_mediaWidget->url() || (!m_preview->isVisible() && !m_mediaWidget->isVisible())) {
if (InformationPanelSettings::previewsAutoPlay() && m_isVideo) {
// hides the preview now to avoid flickering when the autoplay video starts
m_preview->hide();
m_preview->show();
}
- m_phononWidget->setUrl(m_item.targetUrl(), m_isVideo ? PhononWidget::MediaKind::Video : PhononWidget::MediaKind::Audio);
+ m_mediaWidget->setUrl(m_item.targetUrl(), m_isVideo ? MediaWidget::MediaKind::Video : MediaWidget::MediaKind::Audio);
adjustWidgetSizes(parentWidget()->width());
}
} else {
if (isAnimatedImage) {
m_preview->setAnimatedImageFileName(itemUrl.toLocalFile());
}
- // When we don't need it, hide the phonon widget first to avoid flickering
- m_phononWidget->hide();
+ // When we don't need it, hide the media widget first to avoid flickering
+ m_mediaWidget->hide();
m_preview->show();
- m_preview->removeEventFilter(m_phononWidget);
- m_phononWidget->clearUrl();
+ m_preview->removeEventFilter(m_mediaWidget);
+ m_mediaWidget->clearUrl();
}
}
} else {
m_preview->stopAnimatedImage();
m_preview->hide();
- m_phononWidget->hide();
+ m_mediaWidget->hide();
}
}
m_metaDataWidget->setItems(items);
- m_phononWidget->hide();
+ m_mediaWidget->hide();
m_item = KFileItem();
}
void InformationPanelContent::showIcon(const KFileItem &item)
{
m_outdatedPreviewTimer->stop();
- QPixmap pixmap = QIcon::fromTheme(item.iconName()).pixmap(m_preview->height(), m_preview->width());
- KIconLoader::global()->drawOverlays(item.overlays(), pixmap, KIconLoader::Desktop);
+ QIcon icon = QIcon::fromTheme(item.iconName());
+ QPixmap pixmap = KIconUtils::addOverlays(icon, item.overlays()).pixmap(m_preview->size(), devicePixelRatioF());
+ pixmap.setDevicePixelRatio(devicePixelRatioF());
m_preview->setPixmap(pixmap);
}
m_outdatedPreviewTimer->stop();
QPixmap p = pixmap;
- KIconLoader::global()->drawOverlays(item.overlays(), p, KIconLoader::Desktop);
+ if (!item.overlays().isEmpty()) {
+ // Avoid scaling the images that are smaller than the preview size, to be consistent when there is no overlays
+ if (pixmap.height() < m_preview->height() && pixmap.width() < m_preview->width()) {
+ p = QPixmap(m_preview->size() * devicePixelRatioF());
+ p.fill(Qt::transparent);
+ p.setDevicePixelRatio(devicePixelRatioF());
+
+ QPainter painter(&p);
+ painter.drawPixmap(QPointF{m_preview->width() / 2.0 - pixmap.width() / pixmap.devicePixelRatioF() / 2,
+ m_preview->height() / 2.0 - pixmap.height() / pixmap.devicePixelRatioF() / 2}
+ .toPoint(),
+ pixmap);
+ }
+ p = KIconUtils::addOverlays(p, item.overlays()).pixmap(m_preview->size(), devicePixelRatioF());
+ p.setDevicePixelRatio(devicePixelRatioF());
+ }
if (m_isVideo) {
// adds a play arrow overlay
auto arrowSize = qMax(PLAY_ARROW_SIZE, maxDim / 8);
// compute relative pixel positions
- const int zeroX = static_cast<int>((p.width() / 2 - arrowSize / 2) / pixmap.devicePixelRatio());
- const int zeroY = static_cast<int>((p.height() / 2 - arrowSize / 2) / pixmap.devicePixelRatio());
+ const int zeroX = static_cast<int>((p.width() / 2 - arrowSize / 2) / p.devicePixelRatio());
+ const int zeroY = static_cast<int>((p.height() / 2 - arrowSize / 2) / p.devicePixelRatio());
QPolygon arrow;
arrow << QPoint(zeroX, zeroY);
// use it until the preview is done
showIcon(m_item);
} else {
- KIconEffect *iconEffect = KIconLoader::global()->iconEffect();
- QPixmap disabledPixmap = iconEffect->apply(m_preview->pixmap(), KIconLoader::Desktop, KIconLoader::DisabledState);
+ QPixmap disabledPixmap = m_preview->pixmap();
+ KIconEffect::toDisabled(disabledPixmap);
m_preview->setPixmap(disabledPixmap);
}
}
void InformationPanelContent::setPreviewAutoPlay(bool autoPlay)
{
- m_phononWidget->setAutoPlay(autoPlay);
+ m_mediaWidget->setAutoPlay(autoPlay);
}
void InformationPanelContent::setNameLabelText(const QString &text)
// try to increase the preview as large as possible
m_preview->setSizeHint(QSize(maxWidth, maxWidth));
- if (m_phononWidget->isVisible()) {
+ if (m_mediaWidget->isVisible()) {
// assure that the size of the video player is the same as the preview size
- m_phononWidget->setVideoSize(QSize(maxWidth, maxWidth));
+ m_mediaWidget->setVideoSize(QSize(maxWidth, maxWidth));
}
}
+
+#include "moc_informationpanelcontent.cpp"