File indexing completed on 2024-04-28 04:21:26

0001 // SPDX-FileCopyrightText: 2003-2010 Jesper K. Pedersen <blackie@kde.org>
0002 // SPDX-FileCopyrightText: 2022-2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0003 //
0004 // SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 #ifndef IMAGEDISPLAY_H
0007 #define IMAGEDISPLAY_H
0008 
0009 #include "AbstractDisplay.h"
0010 
0011 #include <DB/ImageInfoPtr.h>
0012 #include <ImageManager/ImageClientInterface.h>
0013 #include <kpabase/FileNameList.h>
0014 #include <kpabase/SettingsData.h>
0015 
0016 #include <QMouseEvent>
0017 #include <QPaintEvent>
0018 #include <QResizeEvent>
0019 #include <qimage.h>
0020 #include <qpixmap.h>
0021 class QTimer;
0022 
0023 namespace DB
0024 {
0025 class ImageInfo;
0026 }
0027 
0028 namespace Viewer
0029 {
0030 class ViewHandler;
0031 class ViewerWidget;
0032 
0033 struct ViewPreloadInfo {
0034     ViewPreloadInfo() { }
0035     ViewPreloadInfo(const QImage &img, const QSize &size, int angle)
0036         : img(img)
0037         , size(size)
0038         , angle(angle)
0039     {
0040     }
0041     QImage img;
0042     QSize size;
0043     int angle = 0;
0044 };
0045 
0046 class ImageDisplay : public Viewer::AbstractDisplay, public ImageManager::ImageClientInterface
0047 {
0048     Q_OBJECT
0049 public:
0050     explicit ImageDisplay(QWidget *parent);
0051     QImage currentViewAsThumbnail() const;
0052     void pixmapLoaded(ImageManager::ImageRequest *request, const QImage &image) override;
0053     void setImageList(const DB::FileNameList &list);
0054 
0055     void filterNone();
0056     void filterSelected();
0057     bool filterMono();
0058     bool filterBW();
0059     bool filterContrastStretch();
0060     bool filterHistogramEqualization();
0061 
0062 public Q_SLOTS:
0063     void zoomIn() override;
0064     void zoomOut() override;
0065     void zoomFull() override;
0066     void zoomPixelForPixel() override;
0067     void stop() override { }
0068     void rotate(const DB::ImageInfoPtr &info) override;
0069 
0070 protected Q_SLOTS:
0071     bool setImageImpl(DB::ImageInfoPtr info, bool forward) override;
0072 
0073 Q_SIGNALS:
0074     void possibleChange();
0075     void imageReady();
0076     void imageZoomCaptionChanged(const QString &info);
0077     void viewGeometryChanged(QSize viewSize, QRect zoomWindow, double sizeRatio);
0078 
0079 protected:
0080     void mousePressEvent(QMouseEvent *event) override;
0081     void mouseMoveEvent(QMouseEvent *event) override;
0082     void mouseReleaseEvent(QMouseEvent *event) override;
0083     void resizeEvent(QResizeEvent *event) override;
0084     void paintEvent(QPaintEvent *event) override;
0085     void hideEvent(QHideEvent *) override;
0086     QPoint mapPos(QPoint);
0087     QPoint offset(int logicalWidth, int logicalHeight, int physicalWidth, int physicalHeight, double *ratio);
0088     void cropAndScale();
0089     void updatePreload();
0090     int indexOf(const DB::FileName &fileName);
0091     void requestImage(const DB::ImageInfoPtr &info, bool priority = false);
0092 
0093     /** display zoom factor in title of display window */
0094     void updateZoomCaption();
0095 
0096     friend class ViewHandler;
0097     void zoom(QPoint p1, QPoint p2);
0098     void normalize(QPoint &p1, QPoint &p2);
0099     void pan(const QPoint &);
0100     void busy();
0101     void unbusy();
0102     bool isImageZoomed(const Settings::StandardViewSize type, const QSize &imgSize);
0103     void updateZoomPoints(const Settings::StandardViewSize type, const QSize &imgSize);
0104     void potentiallyLoadFullSize();
0105     double sizeRatio(const QSize &baseSize, const QSize &newSize) const;
0106 
0107 private:
0108     QImage m_loadedImage;
0109     QImage m_croppedAndScaledImg;
0110 
0111     ViewHandler *m_viewHandler;
0112 
0113     // zoom points in the coordinate system of the image.
0114     QPoint m_zStart;
0115     QPoint m_zEnd;
0116 
0117     QMap<int, ViewPreloadInfo> m_cache;
0118     DB::FileNameList m_imageList;
0119     QMap<QString, DB::ImageInfoPtr> m_loadMap;
0120     bool m_reloadImageInProgress;
0121     bool m_forward;
0122     int m_curIndex;
0123     bool m_busy;
0124     ViewerWidget *m_viewer;
0125 };
0126 }
0127 
0128 #endif /* IMAGEDISPLAY_H */
0129 
0130 // vi:expandtab:tabstop=4 shiftwidth=4: