File indexing completed on 2025-01-05 04:02:16

0001 /*
0002 Gwenview: an image viewer
0003 Copyright 2007 Aurélien Gâteau <agateau@kde.org>
0004 
0005 This program is free software; you can redistribute it and/or
0006 modify it under the terms of the GNU General Public License
0007 as published by the Free Software Foundation; either version 2
0008 of the License, or (at your option) any later version.
0009 
0010 This program is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 GNU General Public License for more details.
0014 
0015 You should have received a copy of the GNU General Public License
0016 along with this program; if not, write to the Free Software
0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018 
0019 */
0020 #ifndef THUMBNAILVIEW_H
0021 #define THUMBNAILVIEW_H
0022 
0023 #include <lib/gwenviewlib_export.h>
0024 
0025 // Qt
0026 #include <QListView>
0027 #include <QUrl>
0028 
0029 // KF
0030 
0031 class KFileItem;
0032 class QDragEnterEvent;
0033 class QDragMoveEvent;
0034 class QDropEvent;
0035 class QPixmap;
0036 
0037 namespace Gwenview
0038 {
0039 class AbstractDocumentInfoProvider;
0040 class AbstractThumbnailViewHelper;
0041 class ThumbnailProvider;
0042 
0043 struct ThumbnailViewPrivate;
0044 class GWENVIEWLIB_EXPORT ThumbnailView : public QListView
0045 {
0046     Q_OBJECT
0047 public:
0048     enum {
0049         MinThumbnailSize = 48,
0050         MaxThumbnailSize = 1024,
0051     };
0052 
0053     enum ThumbnailScaleMode {
0054         ScaleToSquare,
0055         ScaleToHeight,
0056         ScaleToWidth,
0057         ScaleToFit,
0058     };
0059     explicit ThumbnailView(QWidget *parent);
0060     ~ThumbnailView() override;
0061 
0062     void setThumbnailViewHelper(AbstractThumbnailViewHelper *helper);
0063 
0064     AbstractThumbnailViewHelper *thumbnailViewHelper() const;
0065 
0066     void setDocumentInfoProvider(AbstractDocumentInfoProvider *provider);
0067 
0068     AbstractDocumentInfoProvider *documentInfoProvider() const;
0069 
0070     ThumbnailScaleMode thumbnailScaleMode() const;
0071 
0072     void setThumbnailScaleMode(ThumbnailScaleMode);
0073 
0074     /**
0075      * Returns the thumbnail size.
0076      */
0077     QSize thumbnailSize() const;
0078 
0079     /**
0080      * Returns the aspect ratio of the thumbnail.
0081      */
0082     qreal thumbnailAspectRatio() const;
0083 
0084     QPixmap thumbnailForIndex(const QModelIndex &, QSize *fullSize = nullptr);
0085 
0086     /**
0087      * Returns true if the document pointed by the index has been modified
0088      * inside Gwenview.
0089      */
0090     bool isModified(const QModelIndex &) const;
0091 
0092     /**
0093      * Returns true if the document pointed by the index is currently busy
0094      * (loading, saving, rotating...)
0095      */
0096     bool isBusy(const QModelIndex &index) const;
0097 
0098     void setModel(QAbstractItemModel *model) override;
0099 
0100     void setThumbnailProvider(ThumbnailProvider *thumbnailProvider);
0101 
0102     /**
0103      * Publish this method so that delegates can call it.
0104      */
0105     using QListView::scheduleDelayedItemsLayout;
0106 
0107     /**
0108      * Returns the current pixmap to paint when drawing a busy index.
0109      */
0110     QPixmap busySequenceCurrentPixmap() const;
0111 
0112     void reloadThumbnail(const QModelIndex &);
0113 
0114     void updateThumbnailSize();
0115 
0116     void setCreateThumbnailsForRemoteUrls(bool createRemoteThumbs);
0117 
0118 Q_SIGNALS:
0119     /**
0120      * It seems we can't use the 'activated()' signal for now because it does
0121      * not know about KDE single vs doubleclick settings. The indexActivated()
0122      * signal replaces it.
0123      */
0124     void indexActivated(const QModelIndex &);
0125 
0126     void thumbnailSizeChanged(const QSize &);
0127     void thumbnailWidthChanged(int);
0128 
0129     /**
0130      * Emitted whenever selectionChanged() is called.
0131      * This signal is suffixed with "Signal" because
0132      * QAbstractItemView::selectionChanged() is a slot.
0133      */
0134     void selectionChangedSignal(const QItemSelection &, const QItemSelection &);
0135 
0136     /**
0137      * Forward some signals from model, so that the delegate can use them
0138      */
0139     void rowsRemovedSignal(const QModelIndex &parent, int start, int end);
0140 
0141     void rowsInsertedSignal(const QModelIndex &parent, int start, int end);
0142 
0143 public Q_SLOTS:
0144     /**
0145      * Sets the thumbnail's width, in pixels. Keeps aspect ratio unchanged.
0146      */
0147     void setThumbnailWidth(int width);
0148 
0149     /**
0150      * Sets the thumbnail's aspect ratio. Keeps width unchanged.
0151      */
0152     void setThumbnailAspectRatio(qreal ratio);
0153 
0154     void scrollToSelectedIndex();
0155 
0156     void generateThumbnailsForItems();
0157 
0158 protected:
0159     void dragEnterEvent(QDragEnterEvent *) override;
0160 
0161     void dragMoveEvent(QDragMoveEvent *) override;
0162 
0163     void dropEvent(QDropEvent *) override;
0164 
0165     void keyPressEvent(QKeyEvent *) override;
0166 
0167     void resizeEvent(QResizeEvent *) override;
0168 
0169     void scrollContentsBy(int dx, int dy) override;
0170 
0171     void showEvent(QShowEvent *) override;
0172 
0173     void wheelEvent(QWheelEvent *) override;
0174 
0175     void startDrag(Qt::DropActions) override;
0176 
0177     void mousePressEvent(QMouseEvent *) override;
0178 
0179 protected Q_SLOTS:
0180     void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
0181     void rowsInserted(const QModelIndex &parent, int start, int end) override;
0182     void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
0183     void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
0184 
0185 private Q_SLOTS:
0186     void startDragFromTouch(const QPoint &pos);
0187     void tapGesture(const QPoint &pos);
0188     void setZoomParameter();
0189     void zoomGesture(qreal newZoom, const QPoint &pos);
0190     void showContextMenu();
0191     void emitIndexActivatedIfNoModifiers(const QModelIndex &);
0192     void setThumbnail(const KFileItem &, const QPixmap &, const QSize &, qulonglong fileSize);
0193     void setBrokenThumbnail(const KFileItem &);
0194 
0195     /**
0196      * Generate thumbnail for url.
0197      */
0198     void updateThumbnail(const QUrl &url);
0199 
0200     /**
0201      * Tells the view the busy state of the document pointed by the url has changed.
0202      */
0203     void updateThumbnailBusyState(const QUrl &url, bool);
0204 
0205     /*
0206      * Cause a repaint of all busy indexes
0207      */
0208     void updateBusyIndexes();
0209 
0210     void smoothNextThumbnail();
0211 
0212 private:
0213     friend struct ThumbnailViewPrivate;
0214     ThumbnailViewPrivate *const d;
0215 };
0216 
0217 } // namespace
0218 
0219 #endif /* THUMBNAILVIEW_H */