File indexing completed on 2025-02-23 04:08:58

0001 /*
0002  * SPDX-FileCopyrightText: 2008 Cyrille Berger <cberger@cberger.net>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef _KIS_CANVAS_DECORATION_H_
0008 #define _KIS_CANVAS_DECORATION_H_
0009 
0010 #include <QObject>
0011 #include <QPointer>
0012 
0013 #include <kritaui_export.h>
0014 #include <kis_image.h>
0015 #include "KisView.h"
0016 #include <kis_shared.h>
0017 
0018 class KisCanvas2;
0019 class QRectF;
0020 class QPainter;
0021 class KisCoordinatesConverter;
0022 
0023 class KisCanvasDecoration;
0024 typedef KisSharedPtr<KisCanvasDecoration> KisCanvasDecorationSP;
0025 
0026 /**
0027  * This class is the base class for object that draw a decoration on the canvas,
0028  * for instance, selections, grids, tools, ...
0029  */
0030 class KRITAUI_EXPORT KisCanvasDecoration : public QObject, public KisShared
0031 {
0032     Q_OBJECT
0033 public:
0034     KisCanvasDecoration(const QString& id, QPointer<KisView>parent);
0035 
0036     ~KisCanvasDecoration() override;
0037 
0038     void setView(QPointer<KisView> imageView);
0039 
0040     const QString& id() const;
0041 
0042     /**
0043      * @return whether the decoration is visible.
0044      */
0045     bool visible() const;
0046 
0047     /**
0048      * Will paint the decoration on the QPainter, if the visible is set to @c true.
0049      *
0050      * @param gc the painter
0051      * @param updateRect dirty rect in document pixels
0052      * @param converter coordinate converter
0053      * @param canvas the canvas
0054      */
0055     void paint(QPainter& gc, const QRectF& updateRect, const KisCoordinatesConverter *converter,KisCanvas2* canvas);
0056 
0057     /**
0058      * Return z-order priority of the decoration. The higher the priority, the higher
0059      * the decoration is painted.
0060      */
0061     int priority() const;
0062 
0063     static bool comparePriority(KisCanvasDecorationSP decoration1, KisCanvasDecorationSP decoration2);
0064 
0065     virtual void notifyWindowMinimized(bool minimized);
0066 
0067 public Q_SLOTS:
0068     /**
0069      * Set if the decoration is visible or not.
0070      */
0071     virtual void setVisible(bool v);
0072     /**
0073      * If decoration is visible, hide it, if not show it.
0074      */
0075     void toggleVisibility();
0076 protected:
0077     virtual void drawDecoration(QPainter& gc, const QRectF& updateArea, const KisCoordinatesConverter *converter,KisCanvas2* canvas) = 0;
0078 
0079     /**
0080      * @return the parent KisView
0081      */
0082     QPointer<KisView> view() const;
0083 
0084     /**
0085      * Set the priority of the decoration. The higher the priority, the higher
0086      * the decoration is painted.
0087      */
0088     void setPriority(int value);
0089 
0090     // returns the minimum decoration thickness, somewhat equivelant to the display scaling.
0091     int decorationThickness() const;
0092 
0093 private:
0094     struct Private;
0095     Private* const d;
0096 };
0097 
0098 #endif