File indexing completed on 2024-05-05 04:22:00

0001 // SPDX-FileCopyrightText: 2003-2019 The KPhotoAlbum Development Team
0002 // SPDX-FileCopyrightText: 2022 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0003 //
0004 // SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006 #ifndef IMAGEREQUEST_H
0007 #define IMAGEREQUEST_H
0008 #include "enums.h"
0009 
0010 #include <kpabase/FileName.h>
0011 
0012 #include <QHash>
0013 #include <qsize.h>
0014 #include <qstring.h>
0015 
0016 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
0017 //
0018 // This class is shared among the image loader thead and the GUI tread, if
0019 // you don't know the implication of this stay out of this class!
0020 //
0021 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
0022 
0023 namespace ImageManager
0024 {
0025 class ImageClientInterface;
0026 
0027 class ImageRequest
0028 {
0029 public:
0030     enum class RequestType {
0031         ImageRequest,
0032         ExitRequest
0033     };
0034     ImageRequest(const DB::FileName &fileName, const QSize &size, int angle, ImageClientInterface *client);
0035     virtual ~ImageRequest() { }
0036     /**
0037      * @brief Create a special request.
0038      * This constructor can be used to create an ExitRequest.
0039      * You must not use this constructor with a request Type of ImageRequest - use the file name based constructor for an actual ImageRequest instead.
0040      * @param type ExitRequest
0041      */
0042     ImageRequest(RequestType type);
0043 
0044     /** This is the filename that the media is known by in the database.
0045         See \ref fileSystemFileName for details
0046     **/
0047     DB::FileName databaseFileName() const;
0048 
0049     /**
0050         This is the file name that needs to be loaded using the image loader.
0051         In case of a video file where we are loading the snapshot from a prerendered
0052         image, this file name may be different than the one returned from dabataseFileName.
0053         In that example, databaseFileName() returns the path to the video file,
0054         while fileSystemFileName returns the path to the prerendered image.
0055     **/
0056     virtual DB::FileName fileSystemFileName() const;
0057 
0058     int width() const;
0059     int height() const;
0060     QSize size() const;
0061     int angle() const;
0062 
0063     ImageClientInterface *client() const;
0064 
0065     QSize fullSize() const;
0066     void setFullSize(const QSize &);
0067     void setLoadedOK(bool ok);
0068     bool loadedOK() const;
0069 
0070     void setPriority(const Priority prio);
0071     Priority priority() const;
0072 
0073     bool operator<(const ImageRequest &other) const;
0074     bool operator==(const ImageRequest &other) const;
0075 
0076     virtual bool stillNeeded() const;
0077 
0078     bool doUpScale() const;
0079     void setUpScale(bool b);
0080 
0081     void setIsThumbnailRequest(bool);
0082     bool isThumbnailRequest() const;
0083     bool isExitRequest() const;
0084 
0085     /**
0086      * @brief imageIsPreRotated is set when the loaded image is already rotated correctly.
0087      * This is usually the case for decoded raw images.
0088      * @return \c true, if the image is already rotated and does not need additional rotation, \c false otherwise
0089      */
0090     bool imageIsPreRotated() const;
0091     void setImageIsPreRotated(bool imageIsPreRotated);
0092 
0093 private:
0094     const RequestType m_type;
0095     DB::FileName m_fileName;
0096 
0097     int m_width;
0098     int m_height;
0099     ImageClientInterface *m_client;
0100     int m_angle;
0101     QSize m_fullSize;
0102     Priority m_priority;
0103     bool m_loadedOK;
0104     bool m_dontUpScale;
0105     bool m_isThumbnailRequest;
0106     bool m_imageIsPreRotated;
0107 };
0108 
0109 inline uint qHash(const ImageRequest &ir)
0110 {
0111     return DB::qHash(ir.databaseFileName()) ^ ::qHash(ir.width()) ^ ::qHash(ir.angle());
0112 }
0113 
0114 }
0115 
0116 #endif /* IMAGEREQUEST_H */
0117 // vi:expandtab:tabstop=4 shiftwidth=4: