Changeset View
Changeset View
Standalone View
Standalone View
src/panels/information/informationpanelcontent.cpp
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Line(s) | 64 | { | |||
---|---|---|---|---|---|
80 | 80 | | |||
81 | m_preview = new PixmapViewer(parent); | 81 | m_preview = new PixmapViewer(parent); | ||
82 | m_preview->setMinimumWidth(minPreviewWidth); | 82 | m_preview->setMinimumWidth(minPreviewWidth); | ||
83 | m_preview->setMinimumHeight(KIconLoader::SizeEnormous); | 83 | m_preview->setMinimumHeight(KIconLoader::SizeEnormous); | ||
84 | 84 | | |||
85 | m_phononWidget = new PhononWidget(parent); | 85 | m_phononWidget = new PhononWidget(parent); | ||
86 | m_phononWidget->hide(); | 86 | m_phononWidget->hide(); | ||
87 | m_phononWidget->setMinimumWidth(minPreviewWidth); | 87 | m_phononWidget->setMinimumWidth(minPreviewWidth); | ||
88 | m_phononWidget->setAutoPlay(InformationPanelSettings::previewsAutoPlay()); | ||||
88 | connect(m_phononWidget, &PhononWidget::hasVideoChanged, | 89 | connect(m_phononWidget, &PhononWidget::hasVideoChanged, | ||
89 | this, &InformationPanelContent::slotHasVideoChanged); | 90 | this, &InformationPanelContent::slotHasVideoChanged); | ||
90 | 91 | | |||
91 | // name | 92 | // name | ||
92 | m_nameLabel = new QLabel(parent); | 93 | m_nameLabel = new QLabel(parent); | ||
93 | QFont font = m_nameLabel->font(); | 94 | QFont font = m_nameLabel->font(); | ||
94 | font.setBold(true); | 95 | font.setBold(true); | ||
95 | m_nameLabel->setFont(font); | 96 | m_nameLabel->setFont(font); | ||
Show All 40 Lines | |||||
136 | 137 | | |||
137 | InformationPanelContent::~InformationPanelContent() | 138 | InformationPanelContent::~InformationPanelContent() | ||
138 | { | 139 | { | ||
139 | InformationPanelSettings::self()->save(); | 140 | InformationPanelSettings::self()->save(); | ||
140 | } | 141 | } | ||
141 | 142 | | |||
142 | void InformationPanelContent::showItem(const KFileItem& item) | 143 | void InformationPanelContent::showItem(const KFileItem& item) | ||
143 | { | 144 | { | ||
145 | if (item != m_item) { | ||||
144 | m_item = item; | 146 | m_item = item; | ||
145 | 147 | | |||
146 | refreshPreview(); | 148 | refreshPreview(); | ||
147 | refreshMetaData(); | 149 | refreshMetaData(); | ||
148 | } | 150 | } | ||
151 | } | ||||
149 | 152 | | |||
150 | void InformationPanelContent::refreshPreview() { | 153 | void InformationPanelContent::refreshPreview() { | ||
151 | // If there is a preview job, kill it to prevent that we have jobs for | 154 | // If there is a preview job, kill it to prevent that we have jobs for | ||
152 | // multiple items running, and thus a race condition (bug 250787). | 155 | // multiple items running, and thus a race condition (bug 250787). | ||
153 | if (m_previewJob) { | 156 | if (m_previewJob) { | ||
154 | m_previewJob->kill(); | 157 | m_previewJob->kill(); | ||
155 | } | 158 | } | ||
156 | 159 | | |||
157 | if (InformationPanelSettings::previewsShown()) { | 160 | if (InformationPanelSettings::previewsShown()) { | ||
158 | m_preview->show(); | | |||
159 | 161 | | |||
160 | const QUrl itemUrl = m_item.url(); | 162 | const QUrl itemUrl = m_item.url(); | ||
161 | const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty(); | 163 | const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty(); | ||
162 | setNameLabelText(m_item.text()); | 164 | setNameLabelText(m_item.text()); | ||
163 | if (isSearchUrl) { | 165 | if (isSearchUrl) { | ||
166 | m_preview->show(); | ||||
167 | | ||||
164 | // in the case of a search-URL the URL is not readable for humans | 168 | // in the case of a search-URL the URL is not readable for humans | ||
165 | // (at least not useful to show in the Information Panel) | 169 | // (at least not useful to show in the Information Panel) | ||
166 | m_preview->setPixmap( | 170 | m_preview->setPixmap( | ||
167 | QIcon::fromTheme(QStringLiteral("nepomuk")).pixmap(KIconLoader::SizeEnormous, KIconLoader::SizeEnormous) | 171 | QIcon::fromTheme(QStringLiteral("nepomuk")).pixmap(KIconLoader::SizeEnormous, KIconLoader::SizeEnormous) | ||
168 | ); | 172 | ); | ||
169 | } else { | 173 | } else { | ||
170 | // try to get a preview pixmap from the item... | 174 | // try to get a preview pixmap from the item... | ||
171 | 175 | | |||
Show All 17 Lines | |||||
189 | } | 193 | } | ||
190 | 194 | | |||
191 | connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, | 195 | connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, | ||
192 | this, &InformationPanelContent::showPreview); | 196 | this, &InformationPanelContent::showPreview); | ||
193 | connect(m_previewJob.data(), &KIO::PreviewJob::failed, | 197 | connect(m_previewJob.data(), &KIO::PreviewJob::failed, | ||
194 | this, &InformationPanelContent::showIcon); | 198 | this, &InformationPanelContent::showIcon); | ||
195 | 199 | | |||
196 | const QString mimeType = m_item.mimetype(); | 200 | const QString mimeType = m_item.mimetype(); | ||
197 | const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || mimeType.startsWith(QLatin1String("video/")); | 201 | const bool isVideo = mimeType.startsWith(QLatin1String("video/")); | ||
202 | const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo; | ||||
203 | | ||||
198 | if (usePhonon) { | 204 | if (usePhonon) { | ||
205 | // Clicking on the preview can toggle media preview playback | ||||
206 | m_preview->installEventFilter(m_phononWidget); | ||||
207 | m_preview->setToolTip(i18n("Click to play")); | ||||
208 | | ||||
209 | if (InformationPanelSettings::previewsAutoPlay() && isVideo) { | ||||
210 | // hides the preview now to avoid flickering when the autoplay video starts | ||||
211 | m_preview->hide(); | ||||
212 | } else { | ||||
213 | // the video won't play before the preview is displayed | ||||
214 | m_preview->show(); | ||||
215 | } | ||||
216 | | ||||
199 | m_phononWidget->show(); | 217 | m_phononWidget->show(); | ||
200 | m_phononWidget->setUrl(m_item.targetUrl()); | 218 | m_phononWidget->setUrl(m_item.targetUrl(), isVideo ? PhononWidget::MediaKind::Video : PhononWidget::MediaKind::Audio); | ||
201 | m_phononWidget->setVideoSize(m_preview->size()); | 219 | m_phononWidget->setVideoSize(m_preview->size()); | ||
202 | } else { | 220 | } else { | ||
221 | // When we don't need it, hide the phonon widget first to avoid flickering | ||||
203 | m_phononWidget->hide(); | 222 | m_phononWidget->hide(); | ||
223 | m_preview->show(); | ||||
224 | | ||||
225 | m_preview->removeEventFilter(m_phononWidget); | ||||
226 | m_preview->setToolTip(QString()); | ||||
204 | } | 227 | } | ||
205 | } | 228 | } | ||
206 | } else { | 229 | } else { | ||
207 | m_preview->hide(); | 230 | m_preview->hide(); | ||
208 | m_phononWidget->hide(); | 231 | m_phononWidget->hide(); | ||
209 | } | 232 | } | ||
210 | } | 233 | } | ||
211 | 234 | | |||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 323 | KFileItemList InformationPanelContent::items() { | |||
301 | return m_metaDataWidget->items(); | 324 | return m_metaDataWidget->items(); | ||
302 | } | 325 | } | ||
303 | 326 | | |||
304 | void InformationPanelContent::slotHasVideoChanged(bool hasVideo) | 327 | void InformationPanelContent::slotHasVideoChanged(bool hasVideo) | ||
305 | { | 328 | { | ||
306 | m_preview->setVisible(InformationPanelSettings::previewsShown() && !hasVideo); | 329 | m_preview->setVisible(InformationPanelSettings::previewsShown() && !hasVideo); | ||
307 | } | 330 | } | ||
308 | 331 | | |||
332 | void InformationPanelContent::setPreviewAutoPlay(bool autoPlay) { | ||||
333 | m_phononWidget->setAutoPlay(autoPlay); | ||||
334 | } | ||||
335 | | ||||
309 | void InformationPanelContent::setNameLabelText(const QString& text) | 336 | void InformationPanelContent::setNameLabelText(const QString& text) | ||
310 | { | 337 | { | ||
311 | QTextOption textOption; | 338 | QTextOption textOption; | ||
312 | textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); | 339 | textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); | ||
313 | 340 | | |||
314 | const QString processedText = Qt::mightBeRichText(text) ? text : KStringHandler::preProcessWrap(text); | 341 | const QString processedText = Qt::mightBeRichText(text) ? text : KStringHandler::preProcessWrap(text); | ||
315 | 342 | | |||
316 | QTextLayout textLayout(processedText); | 343 | QTextLayout textLayout(processedText); | ||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |