File indexing completed on 2024-05-12 17:18:50

0001 /*
0002  * SPDX-FileCopyrightText: 2009-2010 Peter Penz <peter.penz19@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef INFORMATIONPANELCONTENT_H
0008 #define INFORMATIONPANELCONTENT_H
0009 
0010 #include "config-dolphin.h"
0011 #include <KFileItem>
0012 
0013 #include <QPointer>
0014 #include <QUrl>
0015 #include <QWidget>
0016 
0017 class KFileItemList;
0018 class PhononWidget;
0019 class PixmapViewer;
0020 class QPixmap;
0021 class QDialogButtonBox;
0022 class QString;
0023 class QLabel;
0024 class QScrollArea;
0025 class QGestureEvent;
0026 
0027 namespace KIO
0028 {
0029 class PreviewJob;
0030 }
0031 
0032 namespace Baloo
0033 {
0034 class FileMetaDataWidget;
0035 }
0036 
0037 /**
0038  * @brief Manages the widgets that display the meta information
0039 *         for file items of the Information Panel.
0040  */
0041 class InformationPanelContent : public QWidget
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     explicit InformationPanelContent(QWidget *parent = nullptr);
0047     ~InformationPanelContent() override;
0048 
0049     /**
0050      * Shows the meta information for the item \p item.
0051      * The preview of the item is generated asynchronously,
0052      * the other meta information are fetched synchronously.
0053      */
0054     void showItem(const KFileItem &item);
0055 
0056     /**
0057      * Shows the meta information for the items \p items and its preview
0058      */
0059     void showItems(const KFileItemList &items);
0060 
0061     KFileItemList items();
0062 
0063     /**
0064      * Refreshes the preview display, hiding it if needed
0065      */
0066     void refreshPreview();
0067 
0068     /**
0069      * Switch the metadatawidget into configuration mode
0070      */
0071     void configureShownProperties();
0072 
0073     /*
0074      * Set the auto play media mode for the file previewed
0075      * Eventually starting media playback when turning it on
0076      * But not stopping it when turning it off
0077      */
0078     void setPreviewAutoPlay(bool autoPlay);
0079 
0080 Q_SIGNALS:
0081     void urlActivated(const QUrl &url);
0082     void configurationFinished();
0083     void contextMenuRequested(const QPoint &pos);
0084 
0085 public Q_SLOTS:
0086     /**
0087      * Is invoked after the file meta data configuration dialog has been
0088      * closed and refreshes the displayed meta data by the panel.
0089      */
0090     void refreshMetaData();
0091 
0092 protected:
0093     /** @see QObject::eventFilter() */
0094     bool eventFilter(QObject *obj, QEvent *event) override;
0095 
0096     bool event(QEvent *event) override;
0097 
0098 private Q_SLOTS:
0099     /**
0100      * Is invoked if no preview is available for the item. In this
0101      * case the icon will be shown.
0102      */
0103     void showIcon(const KFileItem &item);
0104 
0105     /**
0106      * Is invoked if a preview is available for the item. The preview
0107      * \a pixmap is shown inside the info page.
0108      */
0109     void showPreview(const KFileItem &item, const QPixmap &pixmap);
0110 
0111     /**
0112      * Marks the currently shown preview as outdated
0113      * by greying the content.
0114      */
0115     void markOutdatedPreview();
0116 
0117     void slotHasVideoChanged(bool hasVideo);
0118 
0119 private:
0120     /**
0121      * Sets the text for the label \a m_nameLabel and assures that the
0122      * text is split in a way that it can be wrapped within the
0123      * label width (QLabel::setWordWrap() does not work if the
0124      * text represents one extremely long word).
0125      */
0126     void setNameLabelText(const QString &text);
0127 
0128     /**
0129      * Adjusts the sizes of the widgets dependent on the available
0130      * width given by \p width.
0131      */
0132     void adjustWidgetSizes(int width);
0133 
0134     /**
0135      * Refreshes the image in the PixmapViewer
0136      */
0137     void refreshPixmapView();
0138 
0139     bool gestureEvent(QGestureEvent *event);
0140 
0141 private:
0142     KFileItem m_item;
0143 
0144     QPointer<KIO::PreviewJob> m_previewJob;
0145     QTimer *m_outdatedPreviewTimer;
0146 
0147     PixmapViewer *m_preview;
0148     PhononWidget *m_phononWidget;
0149     QLabel *m_nameLabel;
0150     Baloo::FileMetaDataWidget *m_metaDataWidget;
0151     QScrollArea *m_metaDataArea;
0152     QLabel *m_configureLabel;
0153     QDialogButtonBox *m_configureButtons;
0154 
0155     bool m_isVideo;
0156 };
0157 
0158 #endif // INFORMATIONPANELCONTENT_H