File indexing completed on 2024-04-28 04:21:23
0001 // SPDX-FileCopyrightText: 2003-2020 The KPhotoAlbum Development Team 0002 // SPDX-FileCopyrightText: 2021-2022 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0003 // 0004 // SPDX-License-Identifier: GPL-2.0-or-later 0005 0006 #ifndef THUMBNAILVIEW_THUMBNAILWIDGET_H 0007 #define THUMBNAILVIEW_THUMBNAILWIDGET_H 0008 0009 #include "GridResizeInteraction.h" 0010 #include "MouseTrackingInteraction.h" 0011 #include "SelectionInteraction.h" 0012 #include "ThumbnailComponent.h" 0013 #include "VideoThumbnailCycler.h" 0014 #include "enums.h" 0015 0016 #include <QListView> 0017 #include <QScopedPointer> 0018 0019 class QTimer; 0020 namespace Utilities 0021 { 0022 class FastDateTime; 0023 } 0024 0025 namespace DB 0026 { 0027 class ImageDate; 0028 class Id; 0029 class FileNameList; 0030 } 0031 0032 namespace ThumbnailView 0033 { 0034 class ThumbnailPainter; 0035 class CellGeometry; 0036 class ThumbnailModel; 0037 class ThumbnailFactory; 0038 class KeyboardEventHandler; 0039 class ThumbnailDND; 0040 0041 class ThumbnailWidget : public QListView, private ThumbnailComponent 0042 { 0043 Q_OBJECT 0044 0045 public: 0046 explicit ThumbnailWidget(ThumbnailFactory *factory); 0047 0048 void reload(SelectionUpdateMethod method); 0049 DB::FileName mediaIdUnderCursor() const; 0050 QModelIndex indexUnderCursor() const; 0051 0052 bool isMouseOverStackIndicator(const QPoint &point); 0053 bool isGridResizing() const; 0054 void setCurrentItem(const DB::FileName &fileName); 0055 DB::FileName currentItem() const; 0056 void changeSingleSelection(const DB::FileName &fileName); 0057 0058 // Misc 0059 int cellWidth() const; 0060 void showEvent(QShowEvent *) override; 0061 DB::FileNameList selection(ThumbnailView::SelectionMode mode) const; 0062 bool isSelected(const DB::FileName &id) const; 0063 void select(const DB::FileNameList &); 0064 bool isItemUnderCursorSelected() const; 0065 0066 public Q_SLOTS: 0067 void gotoDate(const DB::ImageDate &date, bool includeRanges); 0068 /** 0069 * @brief setExternallyResizing 0070 * Used by the GridResizeSlider to indicate that the grid is being resized. 0071 * @param state true, if the grid is being resized by an external widget, false if not 0072 */ 0073 void setExternallyResizing(bool state); 0074 0075 Q_SIGNALS: 0076 void showImage(const DB::FileName &id); 0077 void showSelection(); 0078 void showSearch(); 0079 void fileIdUnderCursorChanged(const DB::FileName &id); 0080 void currentDateChanged(const Utilities::FastDateTime &); 0081 void selectionCountChanged(int numberOfItemsSelected); 0082 0083 protected: 0084 // event handlers 0085 void keyPressEvent(QKeyEvent *) override; 0086 void keyReleaseEvent(QKeyEvent *) override; 0087 void mousePressEvent(QMouseEvent *) override; 0088 void mouseMoveEvent(QMouseEvent *) override; 0089 void mouseReleaseEvent(QMouseEvent *) override; 0090 void mouseDoubleClickEvent(QMouseEvent *) override; 0091 void wheelEvent(QWheelEvent *) override; 0092 0093 // Drag and drop 0094 void dragEnterEvent(QDragEnterEvent *event) override; 0095 void dragMoveEvent(QDragMoveEvent *) override; 0096 void dragLeaveEvent(QDragLeaveEvent *) override; 0097 void dropEvent(QDropEvent *) override; 0098 0099 private Q_SLOTS: 0100 void emitDateChange(); 0101 void scheduleDateChangeSignal(); 0102 void emitSelectionChangedSignal(); 0103 0104 private: 0105 friend class GridResizeInteraction; 0106 inline ThumbnailModel *model() { return ThumbnailComponent::model(); } 0107 inline const ThumbnailModel *model() const { return ThumbnailComponent::model(); } 0108 void updatePalette(); 0109 void setupDateChangeTimer(); 0110 0111 /** 0112 * When the user selects a date on the date bar the thumbnail view will 0113 * position itself accordingly. As a consequence, the thumbnail view 0114 * is telling the date bar which date it moved to. This is all fine 0115 * except for the fact that the date selected in the date bar, may be 0116 * for an image which is in the middle of a line, while the date 0117 * emitted from the thumbnail view is for the top most image in 0118 * the view (that is the first image on the line), which results in a 0119 * different cell being selected in the date bar, than what the user 0120 * selected. 0121 * Therefore we need this variable to disable the emission of the date 0122 * change while setting the date. 0123 */ 0124 bool m_isSettingDate; 0125 0126 GridResizeInteraction m_gridResizeInteraction; 0127 bool m_wheelResizing; 0128 bool m_externallyResizing; 0129 SelectionInteraction m_selectionInteraction; 0130 MouseTrackingInteraction m_mouseTrackingHandler; 0131 MouseInteraction *m_mouseHandler; 0132 ThumbnailDND *m_dndHandler; 0133 bool m_pressOnStackIndicator; 0134 0135 QTimer *m_dateChangedTimer; 0136 0137 friend class SelectionInteraction; 0138 friend class KeyboardEventHandler; 0139 friend class ThumbnailDND; 0140 friend class ThumbnailModel; 0141 KeyboardEventHandler *m_keyboardHandler; 0142 QScopedPointer<VideoThumbnailCycler> m_videoThumbnailCycler; 0143 }; 0144 } 0145 0146 #endif /* THUMBNAILVIEW_THUMBNAILWIDGET_H */ 0147 0148 // vi:expandtab:tabstop=4 shiftwidth=4: