Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++
2.6 KB
Raw Blame
/*
 * SPDX-FileCopyrightText: 2008 Cyrille Berger <[email protected]>
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef _KIS_CANVAS_DECORATION_H_
#define _KIS_CANVAS_DECORATION_H_

#include <QObject>
#include <QPointer>

#include <kritaui_export.h>
#include <kis_image.h>
#include "KisView.h"
#include <kis_shared.h>

class KisCanvasWidgetBase;
class KisCanvas2;
class QRectF;
class QPainter;
class KisCoordinatesConverter;

class KisCanvasDecoration;
typedef KisSharedPtr<KisCanvasDecoration> KisCanvasDecorationSP;

/**
 * This class is the base class for object that draw a decoration on the canvas,
 * for instance, selections, grids, tools, ...
 */
class KRITAUI_EXPORT KisCanvasDecoration : public QObject, public KisShared
{
    Q_OBJECT
public:
    KisCanvasDecoration(const QString& id, QPointer<KisView>parent);

    ~KisCanvasDecoration() override;

    void setView(QPointer<KisView> imageView);

    const QString& id() const;

    /**
     * @return whether the decoration is visible.
     */
    bool visible() const;

    /**
     * Will paint the decoration on the QPainter, if the visible is set to @c true.
     *
     * @param gc the painter
     * @param updateRect dirty rect in document pixels
     * @param converter coordinate converter
     * @param canvas the canvas
     */
    void paint(QPainter& gc, const QRectF& updateRect, const KisCoordinatesConverter *converter,KisCanvas2* canvas);

    /**
     * Return z-order priority of the decoration. The higher the priority, the higher
     * the decoration is painted.
     */
    int priority() const;

    static bool comparePriority(KisCanvasDecorationSP decoration1, KisCanvasDecorationSP decoration2);

    virtual void notifyWindowMinimized(bool minimized);
    virtual void setCanvasWidget(KisCanvasWidgetBase* canvas) { Q_UNUSED(canvas); };

public Q_SLOTS:
    /**
     * Set if the decoration is visible or not.
     */
    virtual void setVisible(bool v);
    /**
     * If decoration is visible, hide it, if not show it.
     */
    void toggleVisibility();
protected:
    virtual void drawDecoration(QPainter& gc, const QRectF& updateArea, const KisCoordinatesConverter *converter,KisCanvas2* canvas) = 0;


    /**
     * @return the parent KisView
     */
    QPointer<KisView> view() const;

    /**
     * Set the priority of the decoration. The higher the priority, the higher
     * the decoration is painted.
     */
    void setPriority(int value);

    // returns the minimum decoration thickness, somewhat equivalent to the display scaling.
    int decorationThickness() const;

private:
    struct Private;
    Private* const d;
};

#endif