File indexing completed on 2024-04-28 15:40:29
0001 // SPDX-FileCopyrightText: 2003-2023 The KPhotoAlbum Development Team 0002 // 0003 // SPDX-License-Identifier: GPL-2.0-or-later 0004 0005 #ifndef VIEWER_H 0006 #define VIEWER_H 0007 0008 #include <DB/ImageInfo.h> 0009 #include <DB/ImageInfoPtr.h> 0010 #include <MainWindow/CopyLinkEngine.h> 0011 #include <kpabase/CrashSentinel.h> 0012 #include <kpabase/FileNameList.h> 0013 0014 #include <QImage> 0015 #include <QMap> 0016 #include <QPixmap> 0017 #include <QPointer> 0018 #include <QStackedWidget> 0019 0020 class KActionCollection; 0021 class QAction; 0022 class QContextMenuEvent; 0023 class QKeyEvent; 0024 class QMenu; 0025 class QResizeEvent; 0026 class QStackedWidget; 0027 class QWheelEvent; 0028 class CursorVisibilityHandler; 0029 class QLabel; 0030 0031 namespace DB 0032 { 0033 class ImageInfo; 0034 class Id; 0035 } 0036 namespace MainWindow 0037 { 0038 class ExternalPopup; 0039 class CategoryImagePopup; 0040 } 0041 namespace Exif 0042 { 0043 class InfoDialog; 0044 } 0045 namespace Viewer 0046 { 0047 0048 class AnnotationHandler; 0049 class AbstractDisplay; 0050 class ImageDisplay; 0051 class InfoBox; 0052 class TransientDisplay; 0053 class TextDisplay; 0054 class VideoDisplay; 0055 class VideoShooter; 0056 0057 class ViewerWidget : public QStackedWidget 0058 { 0059 Q_OBJECT 0060 public: 0061 enum class UsageType { CompactPreview, //< Preview ViewerWidget with no (internal) controls. As used in the annotation dialog preview dock. 0062 FullsizePreview, ///< Preview ViewerWidget with minimal context menu that can be used for a full size window. As used in the "fullscreen" preview of tha annotation dialog. 0063 FullFeaturedViewer ///< Full featured ViewerWidget. 0064 }; 0065 0066 ViewerWidget(UsageType type = UsageType::FullFeaturedViewer); 0067 ~ViewerWidget() override; 0068 static ViewerWidget *latest(); 0069 void load(const DB::FileNameList &list, int index = 0); 0070 void infoBoxMove(); 0071 bool showingFullScreen() const; 0072 void setShowFullScreen(bool on); 0073 void show(bool slideShow); 0074 KActionCollection *actions(); 0075 void setCopyLinkEngine(MainWindow::CopyLinkEngine *copyLinkEngine); 0076 0077 /** 0078 * @brief setTaggedAreasFromImage 0079 * Clear existing areas and set them based on the currentInfo(). 0080 */ 0081 void setTaggedAreasFromImage(); 0082 /** 0083 * @brief addAdditionalTaggedAreas adds additional areas and marks them as highlighted. 0084 * @param taggedAreas 0085 */ 0086 void addAdditionalTaggedAreas(DB::TaggedAreas taggedAreas); 0087 0088 public Q_SLOTS: 0089 void updateInfoBox(); 0090 void test(); 0091 void moveInfoBox(int); 0092 void stopPlayback(); 0093 void remapAreas(QSize viewSize, QRect zoomWindow, double sizeRatio); 0094 0095 Q_SIGNALS: 0096 void soughtTo(const DB::FileName &id); 0097 void imageRotated(const DB::FileName &id); 0098 0099 protected: 0100 void closeEvent(QCloseEvent *event) override; 0101 void contextMenuEvent(QContextMenuEvent *e) override; 0102 void resizeEvent(QResizeEvent *) override; 0103 void keyPressEvent(QKeyEvent *) override; 0104 void wheelEvent(QWheelEvent *event) override; 0105 0106 void moveInfoBox(); 0107 0108 enum class AreaType { Standard, 0109 Highlighted }; 0110 /** 0111 * @brief addTaggedAreas adds tagged areas to the viewer. 0112 * @param taggedAreas Map(category -> Map(tagname, area)) 0113 * @param type AreaType::Standard is for areas that are part of the Image; AreaType::Highlight is for additional areas 0114 */ 0115 void addTaggedAreas(DB::TaggedAreas taggedAreas, AreaType type); 0116 void load(); 0117 void setupContextMenu(); 0118 void createShowContextMenu(); 0119 void createInvokeExternalMenu(); 0120 void createRotateMenu(); 0121 void createSkipMenu(); 0122 void createZoomMenu(); 0123 void createSlideShowMenu(); 0124 void createVideoMenu(); 0125 void createCategoryImageMenu(); 0126 void createFilterMenu(); 0127 void changeSlideShowInterval(int delta); 0128 void createVideoViewer(); 0129 void createAnnotationMenu(); 0130 void inhibitScreenSaver(bool inhibit); 0131 /** 0132 * @brief currentFileName accesses the current file name in a safe way. 0133 * If the current index is invalid, a \c null DB::FileName is returned. 0134 * @return the current DB::FileName 0135 */ 0136 DB::FileName currentFileName() const; 0137 /** 0138 * @brief currentInfo queries the database for the ImageInfo for the current file. 0139 * If the current index is invalid, a \c null DB::ImageInfoPtr is returned. 0140 * @return the ImageInfoPtr for the current DB::FileName. 0141 */ 0142 DB::ImageInfoPtr currentInfo() const; 0143 friend class InfoBox; 0144 0145 void updatePalette(); 0146 0147 private: 0148 void showNextN(int); 0149 void showPrevN(int); 0150 void invalidateThumbnail() const; 0151 enum RemoveAction { RemoveImageFromDatabase, 0152 OnlyRemoveFromViewer }; 0153 void removeOrDeleteCurrent(RemoveAction); 0154 0155 enum class TagMode { Locked, 0156 Annotating, 0157 Tokenizing }; 0158 void setTagMode(TagMode tagMode); 0159 void updateContextMenuState(bool isVideo); 0160 0161 protected Q_SLOTS: 0162 void showNext(); 0163 void showNext10(); 0164 void showNext100(); 0165 void showNext1000(); 0166 void showPrev(); 0167 void showPrev10(); 0168 void showPrev100(); 0169 void showPrev1000(); 0170 void showFirst(); 0171 void showLast(); 0172 void deleteCurrent(); 0173 void removeCurrent(); 0174 void rotate(int angle); 0175 void toggleFullScreen(); 0176 void slotStartStopSlideShow(); 0177 void slotSlideShowNext(); 0178 void slotSlideShowNextFromTimer(); 0179 void slotSlideShowFaster(); 0180 void slotSlideShowSlower(); 0181 void editImage(); 0182 void filterNone(); 0183 void filterSelected(); 0184 void filterBW(); 0185 void filterContrastStretch(); 0186 void filterHistogramEqualization(); 0187 void filterMono(); 0188 void slotSetStackHead(); 0189 void updateCategoryConfig(); 0190 void populateExternalPopup(); 0191 void populateCategoryImagePopup(); 0192 void videoStopped(); 0193 void showExifViewer(); 0194 void zoomIn(); 0195 void zoomOut(); 0196 void zoomFull(); 0197 void zoomPixelForPixel(); 0198 void makeThumbnailImage(); 0199 void addTag(); 0200 void editDescription(); 0201 void showAnnotationHelp(); 0202 0203 /** Set the current window title (filename) and add the given detail */ 0204 void setCaptionWithDetail(const QString &detail); 0205 0206 /** 0207 * @brief slotRemoveDeletedImages removes all deleted images from the viewer playback list. 0208 * @param imageList 0209 */ 0210 void slotRemoveDeletedImages(const DB::FileNameList &imageList); 0211 0212 void triggerCopyLinkAction(MainWindow::CopyLinkEngine::Action action); 0213 void toggleTag(const QString &category, const QString &value); 0214 void copyTagsFromPreviousImage(); 0215 0216 private: 0217 static ViewerWidget *s_latest; 0218 friend class VideoShooter; 0219 friend class TemporarilyDisableCursorHandling; 0220 0221 QList<QAction *> m_forwardActions; 0222 QList<QAction *> m_backwardActions; 0223 0224 QAction *m_startStopSlideShow; 0225 QAction *m_slideShowRunFaster; 0226 QAction *m_slideShowRunSlower; 0227 QAction *m_setStackHead; 0228 QAction *m_filterNone; 0229 QAction *m_filterSelected; 0230 QAction *m_filterBW; 0231 QAction *m_filterContrastStretch; 0232 QAction *m_filterHistogramEqualization; 0233 QAction *m_filterMono; 0234 0235 AbstractDisplay *m_display; 0236 ImageDisplay *m_imageDisplay; 0237 VideoDisplay *m_videoDisplay; 0238 TextDisplay *m_textDisplay; 0239 0240 KPABase::CrashSentinel m_crashSentinel; 0241 0242 int m_screenSaverCookie; 0243 DB::FileNameList m_list; 0244 DB::FileNameList m_removed; 0245 int m_current; 0246 QRect m_textRect; 0247 QMenu *m_popup; 0248 QMenu *m_rotateMenu; 0249 QMenu *m_filterMenu; 0250 MainWindow::ExternalPopup *m_externalPopup; 0251 MainWindow::CategoryImagePopup *m_categoryImagePopup; 0252 int m_width; 0253 int m_height; 0254 QPixmap m_pixmap; 0255 0256 QAction *m_delete; 0257 QAction *m_showExifViewer; 0258 QPointer<Exif::InfoDialog> m_exifViewer; 0259 0260 QAction *m_copyToAction; 0261 QAction *m_linkToAction; 0262 0263 InfoBox *m_infoBox; 0264 0265 bool m_showingFullScreen; 0266 0267 int m_slideShowPause; 0268 TransientDisplay *m_transientDisplay; 0269 KActionCollection *m_actions; 0270 bool m_forward; 0271 QTimer *m_slideShowTimer; 0272 bool m_isRunningSlideShow; 0273 0274 QList<QAction *> m_videoActions; 0275 QAction *m_stop; 0276 QAction *m_playPause; 0277 QAction *m_makeThumbnailImage; 0278 bool m_videoPlayerStoppedManually; 0279 UsageType m_type; 0280 0281 MainWindow::CopyLinkEngine *m_copyLinkEngine; 0282 CursorVisibilityHandler *m_cursorHandlerForImageDisplay; 0283 CursorVisibilityHandler *m_cursorHandlerForVideoDisplay; 0284 AnnotationHandler *m_annotationHandler; 0285 0286 TagMode m_tagMode = TagMode::Locked; 0287 QAction *m_addTagAction; 0288 QAction *m_copyAction; 0289 QAction *m_addDescriptionAction; 0290 }; 0291 0292 } 0293 0294 #endif /* VIEWER_H */ 0295 0296 // vi:expandtab:tabstop=4 shiftwidth=4: