kis_painting_assistants_decoration.h 4.8 KB
Newer Older
1 2
/*
 *  Copyright (c) 2009 Cyrille Berger <cberger@cberger.net>
3
 *  Copyright (c) 2017 Scott Petrovic <scottpetrovic@gmail.com>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

20 21
#ifndef _KIS_PAINTING_ASSISTANTS_MANAGER_H_
#define _KIS_PAINTING_ASSISTANTS_MANAGER_H_
22 23

#include <QPointF>
24
#include <QColor>
25 26 27 28

#include "KoPointerEvent.h"
#include "KoSnapGuide.h"

29
#include "canvas/kis_canvas_decoration.h"
Cyrille Berger's avatar
Cyrille Berger committed
30
#include "kis_painting_assistant.h"
31
#include <kritaui_export.h>
Cyrille Berger's avatar
Cyrille Berger committed
32

33
class KisView;
34

35 36 37
class KisPaintingAssistantsDecoration;
typedef KisSharedPtr<KisPaintingAssistantsDecoration> KisPaintingAssistantsDecorationSP;

38 39 40 41 42 43 44 45 46 47
/// data for editor widget. This is shared between the decoration and assistant tool which needs hit box information
struct AssistantEditorData {
    const int moveIconSize = 32;
    const int deleteIconSize = 24;
    const int snapIconSize = 20;
    const QPointF moveIconPosition = QPointF(15, 15);
    const QPointF snapIconPosition = QPointF(54, 20);
    const QPointF deleteIconPosition = QPointF(83, 18);
};

48 49
/**
 * This class hold a list of painting assistants.
50 51 52 53 54 55
 * In the application flow, each canvas holds one of these classes to manage the assistants
 * There is an assistants manager, but that is higher up in the flow and makes sure each view gets one of these
 * Since this is off the canvas level, the decoration can be seen across all tools. The contents from here will be in
 * front of the kis_assistant_tool, which hold and displays the editor controls.
 *
 * Many of the events this recieves such as adding and removing assistants comes from kis_assistant_tool
56
 */
57
class KRITAUI_EXPORT KisPaintingAssistantsDecoration : public KisCanvasDecoration
Boudewijn Rempt's avatar
Boudewijn Rempt committed
58
{
59
    Q_OBJECT
Boudewijn Rempt's avatar
Boudewijn Rempt committed
60
public:
61
    KisPaintingAssistantsDecoration(QPointer<KisView> parent);
62
    ~KisPaintingAssistantsDecoration() override;
63 64
    void addAssistant(KisPaintingAssistantSP assistant);
    void removeAssistant(KisPaintingAssistantSP assistant);
65
    void removeAll();
66 67
    QPointF adjustPosition(const QPointF& point, const QPointF& strokeBegin);
    void endStroke();
Boudewijn Rempt's avatar
Boudewijn Rempt committed
68
    QList<KisPaintingAssistantHandleSP> handles();
69
    QList<KisPaintingAssistantSP> assistants();
70

71 72 73 74 75 76 77 78 79 80 81 82 83 84
    /// called when assistant editor is activated
    /// right now this happens when the assistants tool is selected
    void activateAssistantsEditor();


    /// called when assistant editor is deactivated
    /// right now this happens when the assistants tool is un-selected
    void deactivateAssistantsEditor();

    /// brings back if we are currently editing assistants or not
    /// useful for some assistants (like spline) that draw bezier curves
    bool isEditingAssistants();


85
    /// sets whether the main assistant is visible
86
    void setAssistantVisible(bool set);
87

88
    /// sets whether the preview is visible
89
    void setOutlineVisible(bool set);
90

91
    /// sets whether we snap to only one assistant
92
    void setOnlyOneAssistantSnap(bool assistant);
93

94
    /// returns assistant visibility
95
    bool assistantVisibility();
96

97
    /// returns preview visibility
98
    bool outlineVisibility();
99

100
    /// uncache all assistants
101
    void uncache();
102

103 104
    /// retrieves the assistants color specified in the tool options
    /// all assistants will share the same color
105 106
    QColor assistantsColor();

107 108 109 110
    int handleSize();
    void setHandleSize(int handleSize);


111
Q_SIGNALS:
112
    void assistantChanged();
113
public Q_SLOTS:
114 115

    /// toggles whether the assistant is active or not
116
    void toggleAssistantVisible();
117 118

    /// toggles whether there will be a preview of the assistant result when painting
119
    void toggleOutlineVisible();
120
    void setAssistantsColor(QColor color);
121 122 123
    QPointF snapToGuide(KoPointerEvent *e, const QPointF &offset, bool useModifiers);
    QPointF snapToGuide(const QPointF& pt, const QPointF &offset);

Boudewijn Rempt's avatar
Boudewijn Rempt committed
124
protected:
125
    void drawDecoration(QPainter& gc, const QRectF& updateRect, const KisCoordinatesConverter *converter,KisCanvas2* canvas) override;
126 127
    void drawHandles(KisPaintingAssistantSP assistant, QPainter& gc, const KisCoordinatesConverter *converter);    
    void drawEditorWidget(KisPaintingAssistantSP assistant, QPainter& gc, const KisCoordinatesConverter *converter);
128

Boudewijn Rempt's avatar
Boudewijn Rempt committed
129 130 131
private:
    struct Private;
    Private* const d;
132 133 134
};

#endif