Changeset View
Changeset View
Standalone View
Standalone View
src/panels/information/informationpanelcontent.cpp
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 65 | { | |||
---|---|---|---|---|---|
81 | 81 | | |||
82 | m_preview = new PixmapViewer(parent); | 82 | m_preview = new PixmapViewer(parent); | ||
83 | m_preview->setMinimumWidth(minPreviewWidth); | 83 | m_preview->setMinimumWidth(minPreviewWidth); | ||
84 | m_preview->setMinimumHeight(KIconLoader::SizeEnormous); | 84 | m_preview->setMinimumHeight(KIconLoader::SizeEnormous); | ||
85 | 85 | | |||
86 | m_phononWidget = new PhononWidget(parent); | 86 | m_phononWidget = new PhononWidget(parent); | ||
87 | m_phononWidget->hide(); | 87 | m_phononWidget->hide(); | ||
88 | m_phononWidget->setMinimumWidth(minPreviewWidth); | 88 | m_phononWidget->setMinimumWidth(minPreviewWidth); | ||
89 | m_phononWidget->setAutoPlay(InformationPanelSettings::previewsAutoPlay()); | ||||
89 | connect(m_phononWidget, &PhononWidget::hasVideoChanged, | 90 | connect(m_phononWidget, &PhononWidget::hasVideoChanged, | ||
90 | this, &InformationPanelContent::slotHasVideoChanged); | 91 | this, &InformationPanelContent::slotHasVideoChanged); | ||
91 | 92 | | |||
92 | // name | 93 | // name | ||
93 | m_nameLabel = new QLabel(parent); | 94 | m_nameLabel = new QLabel(parent); | ||
94 | QFont font = m_nameLabel->font(); | 95 | QFont font = m_nameLabel->font(); | ||
95 | font.setBold(true); | 96 | font.setBold(true); | ||
96 | m_nameLabel->setFont(font); | 97 | m_nameLabel->setFont(font); | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | |||||
152 | 153 | | |||
153 | InformationPanelContent::~InformationPanelContent() | 154 | InformationPanelContent::~InformationPanelContent() | ||
154 | { | 155 | { | ||
155 | InformationPanelSettings::self()->save(); | 156 | InformationPanelSettings::self()->save(); | ||
156 | } | 157 | } | ||
157 | 158 | | |||
158 | void InformationPanelContent::showItem(const KFileItem& item) | 159 | void InformationPanelContent::showItem(const KFileItem& item) | ||
159 | { | 160 | { | ||
161 | if (item != m_item) { | ||||
160 | m_item = item; | 162 | m_item = item; | ||
161 | 163 | | |||
162 | refreshPreview(); | 164 | refreshPreview(); | ||
163 | refreshMetaData(); | 165 | refreshMetaData(); | ||
164 | } | 166 | } | ||
167 | } | ||||
165 | 168 | | |||
166 | void InformationPanelContent::refreshPreview() | 169 | void InformationPanelContent::refreshPreview() | ||
167 | { | 170 | { | ||
168 | // If there is a preview job, kill it to prevent that we have jobs for | 171 | // If there is a preview job, kill it to prevent that we have jobs for | ||
169 | // multiple items running, and thus a race condition (bug 250787). | 172 | // multiple items running, and thus a race condition (bug 250787). | ||
170 | if (m_previewJob) { | 173 | if (m_previewJob) { | ||
171 | m_previewJob->kill(); | 174 | m_previewJob->kill(); | ||
172 | } | 175 | } | ||
173 | 176 | | |||
174 | setNameLabelText(m_item.text()); | 177 | setNameLabelText(m_item.text()); | ||
175 | if (InformationPanelSettings::previewsShown()) { | 178 | if (InformationPanelSettings::previewsShown()) { | ||
176 | m_preview->show(); | | |||
177 | 179 | | |||
178 | const QUrl itemUrl = m_item.url(); | 180 | const QUrl itemUrl = m_item.url(); | ||
179 | const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty(); | 181 | const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty(); | ||
180 | if (isSearchUrl) { | 182 | if (isSearchUrl) { | ||
183 | m_preview->show(); | ||||
184 | | ||||
181 | // in the case of a search-URL the URL is not readable for humans | 185 | // in the case of a search-URL the URL is not readable for humans | ||
182 | // (at least not useful to show in the Information Panel) | 186 | // (at least not useful to show in the Information Panel) | ||
183 | m_preview->setPixmap( | 187 | m_preview->setPixmap( | ||
184 | QIcon::fromTheme(QStringLiteral("nepomuk")).pixmap(KIconLoader::SizeEnormous, KIconLoader::SizeEnormous) | 188 | QIcon::fromTheme(QStringLiteral("nepomuk")).pixmap(KIconLoader::SizeEnormous, KIconLoader::SizeEnormous) | ||
185 | ); | 189 | ); | ||
186 | } else { | 190 | } else { | ||
187 | // try to get a preview pixmap from the item... | 191 | // try to get a preview pixmap from the item... | ||
188 | 192 | | |||
Show All 17 Lines | |||||
206 | } | 210 | } | ||
207 | 211 | | |||
208 | connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, | 212 | connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, | ||
209 | this, &InformationPanelContent::showPreview); | 213 | this, &InformationPanelContent::showPreview); | ||
210 | connect(m_previewJob.data(), &KIO::PreviewJob::failed, | 214 | connect(m_previewJob.data(), &KIO::PreviewJob::failed, | ||
211 | this, &InformationPanelContent::showIcon); | 215 | this, &InformationPanelContent::showIcon); | ||
212 | 216 | | |||
213 | const QString mimeType = m_item.mimetype(); | 217 | const QString mimeType = m_item.mimetype(); | ||
214 | const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || mimeType.startsWith(QLatin1String("video/")); | 218 | const bool isVideo = mimeType.startsWith(QLatin1String("video/")); | ||
219 | const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo; | ||||
220 | | ||||
215 | if (usePhonon) { | 221 | if (usePhonon) { | ||
222 | | ||||
223 | if (InformationPanelSettings::previewsAutoPlay() && isVideo) { | ||||
224 | // hides the preview now to avoid flickering when the autoplay video starts | ||||
225 | m_preview->hide(); | ||||
226 | } else { | ||||
227 | // the video won't play before the preview is displayed | ||||
228 | m_preview->show(); | ||||
229 | } | ||||
230 | | ||||
216 | m_phononWidget->show(); | 231 | m_phononWidget->show(); | ||
217 | m_phononWidget->setUrl(m_item.targetUrl()); | 232 | m_phononWidget->setUrl(m_item.targetUrl(), isVideo ? PhononWidget::MediaKind::Video : PhononWidget::MediaKind::Audio); | ||
218 | m_phononWidget->setVideoSize(m_preview->size()); | 233 | m_phononWidget->setVideoSize(m_preview->size()); | ||
219 | } else { | 234 | } else { | ||
235 | // When we don't need it, hide the phonon widget first to avoid flickering | ||||
220 | m_phononWidget->hide(); | 236 | m_phononWidget->hide(); | ||
237 | m_preview->show(); | ||||
221 | } | 238 | } | ||
222 | } | 239 | } | ||
223 | } else { | 240 | } else { | ||
224 | m_preview->hide(); | 241 | m_preview->hide(); | ||
225 | m_phononWidget->hide(); | 242 | m_phononWidget->hide(); | ||
226 | } | 243 | } | ||
227 | } | 244 | } | ||
228 | 245 | | |||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | 339 | { | |||
323 | return m_metaDataWidget->items(); | 340 | return m_metaDataWidget->items(); | ||
324 | } | 341 | } | ||
325 | 342 | | |||
326 | void InformationPanelContent::slotHasVideoChanged(bool hasVideo) | 343 | void InformationPanelContent::slotHasVideoChanged(bool hasVideo) | ||
327 | { | 344 | { | ||
328 | m_preview->setVisible(InformationPanelSettings::previewsShown() && !hasVideo); | 345 | m_preview->setVisible(InformationPanelSettings::previewsShown() && !hasVideo); | ||
329 | } | 346 | } | ||
330 | 347 | | |||
348 | void InformationPanelContent::setPreviewAutoPlay(bool autoPlay) { | ||||
349 | m_phononWidget->setAutoPlay(autoPlay); | ||||
350 | } | ||||
351 | | ||||
331 | void InformationPanelContent::setNameLabelText(const QString& text) | 352 | void InformationPanelContent::setNameLabelText(const QString& text) | ||
332 | { | 353 | { | ||
333 | QTextOption textOption; | 354 | QTextOption textOption; | ||
334 | textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); | 355 | textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); | ||
335 | 356 | | |||
336 | const QString processedText = Qt::mightBeRichText(text) ? text : KStringHandler::preProcessWrap(text); | 357 | const QString processedText = Qt::mightBeRichText(text) ? text : KStringHandler::preProcessWrap(text); | ||
337 | 358 | | |||
338 | QTextLayout textLayout(processedText); | 359 | QTextLayout textLayout(processedText); | ||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |