File indexing completed on 2025-02-23 04:09:01
0001 /* 0002 * SPDX-FileCopyrightText: 2006 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef KIS_PRESCALED_PROJECTION_H 0007 #define KIS_PRESCALED_PROJECTION_H 0008 0009 #include <QObject> 0010 0011 #include <kritaui_export.h> 0012 #include <kis_shared.h> 0013 0014 #include "KoColorConversionTransformation.h" 0015 class QImage; 0016 class QRect; 0017 class QSize; 0018 class QPainter; 0019 0020 class KoColorProfile; 0021 class KisCoordinatesConverter; 0022 class KisDisplayFilter; 0023 0024 #include <kis_types.h> 0025 #include "kis_ui_types.h" 0026 0027 0028 0029 /** 0030 * KisPrescaledProjection is responsible for keeping around a 0031 * prescaled QImage representation that is always suitable for 0032 * painting onto the canvas. 0033 * 0034 * Note: the export macro is only for the unittest. 0035 */ 0036 class KRITAUI_EXPORT KisPrescaledProjection : public QObject, public KisShared 0037 { 0038 Q_OBJECT 0039 public: 0040 0041 KisPrescaledProjection(); 0042 ~KisPrescaledProjection() override; 0043 0044 void setImage(KisImageWSP image); 0045 0046 /** 0047 * Return the prescaled QImage. The prescaled image is exactly as big as 0048 * the canvas widget in pixels. 0049 */ 0050 QImage prescaledQImage() const; 0051 0052 void setCoordinatesConverter(KisCoordinatesConverter *coordinatesConverter); 0053 0054 public Q_SLOTS: 0055 0056 /** 0057 * Retrieves image's data from KisImage object and updates 0058 * internal cache 0059 * @param dirtyImageRect the rect changed on the image 0060 * @see recalculateCache 0061 */ 0062 KisUpdateInfoSP updateCache(const QRect &dirtyImageRect); 0063 0064 /** 0065 * Updates the prescaled cache at current zoom level 0066 * @param info update structure returned by updateCache 0067 * @see updateCache 0068 */ 0069 void recalculateCache(KisUpdateInfoSP info); 0070 0071 /** 0072 * Called whenever the configuration settings change. 0073 */ 0074 void updateSettings(); 0075 0076 /** 0077 * Called whenever the view widget needs to show a different part of 0078 * the document 0079 */ 0080 void viewportMoved(const QPointF &offset); 0081 0082 /** 0083 * Called whenever the size of the KisImage changes. 0084 * It is a part of a complex update ritual, when the size 0085 * fo the image changes. This method just resizes the storage 0086 * for the image cache, it doesn't update any cached data. 0087 */ 0088 void slotImageSizeChanged(qint32 w, qint32 h); 0089 0090 /** 0091 * Checks whether it is needed to resize the prescaled image and 0092 * updates it. The size is given in canvas widget pixels. 0093 */ 0094 void notifyCanvasSizeChanged(const QSize &widgetSize); 0095 0096 void notifyZoomChanged(); 0097 0098 /** 0099 * Set the current monitor profile 0100 */ 0101 void setMonitorProfile(const KoColorProfile *monitorProfile, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags); 0102 0103 void setChannelFlags(const QBitArray &channelFlags); 0104 0105 void setDisplayFilter(QSharedPointer<KisDisplayFilter> displayFilter); 0106 0107 /** 0108 * Called whenever the zoom level changes or another chunk of the 0109 * image becomes visible. The currently visible area of the image 0110 * is complete scaled again. 0111 */ 0112 void preScale(); 0113 0114 private: 0115 0116 friend class KisPrescaledProjectionTest; 0117 0118 KisPrescaledProjection(const KisPrescaledProjection &); 0119 KisPrescaledProjection operator=(const KisPrescaledProjection &); 0120 0121 void updateViewportSize(); 0122 0123 /** 0124 * This creates an empty update information and fills it with the only 0125 * parameter: @p dirtyImageRect 0126 * This function is supposed to be run in the context of the image 0127 * threads, so it does no accesses to zoom or any UI specific values. 0128 * All the needed information for zooming will be fetched in the context 0129 * of the UI thread in fillInUpdateInformation(). 0130 * 0131 * @see fillInUpdateInformation() 0132 */ 0133 KisPPUpdateInfoSP getInitialUpdateInformation(const QRect &dirtyImageRect); 0134 0135 /** 0136 * Prepare all the information about rects needed during 0137 * projection updating. 0138 * 0139 * @param viewportRect the part of the viewport that has to be updated 0140 * @param info the structure to be filled in. It's member dirtyImageRect 0141 * is supposed to have already been set up in the previous step of the 0142 * update in getInitialUpdateInformation(). Though it is allowed to 0143 * be null rect. 0144 * 0145 * @see getInitialUpdateInformation() 0146 */ 0147 void fillInUpdateInformation(const QRect &viewportRect, 0148 KisPPUpdateInfoSP info); 0149 0150 /** 0151 * Initiates the process of prescaled image update 0152 * 0153 * @param info prepared information 0154 */ 0155 void updateScaledImage(KisPPUpdateInfoSP info); 0156 0157 /** 0158 * Actual drawing is done here 0159 * @param info prepared information 0160 * @param gc The painter we draw on 0161 */ 0162 void drawUsingBackend(QPainter &gc, KisPPUpdateInfoSP info); 0163 0164 struct Private; 0165 Private * const m_d; 0166 }; 0167 0168 #endif