File: kis_tool_select_magnetic.h

package info (click to toggle)
calligra 1:2.8.5+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 397,516 kB
  • ctags: 185,064
  • sloc: cpp: 1,505,875; python: 45,987; ansic: 28,421; xml: 26,472; sh: 23,986; java: 18,214; objc: 3,965; makefile: 2,816; perl: 2,792; yacc: 2,601; lex: 1,410; sql: 903; ruby: 737; asm: 236; lisp: 121
file content (144 lines) | stat: -rw-r--r-- 4,966 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 *  Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org)
 *  Copyright (c) 2010 Adam Celarek <kdedev at xibo dot at>
 *
 *  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.
 */
#ifndef KIS_TOOL_SELECT_MAGNETIC_H_
#define KIS_TOOL_SELECT_MAGNETIC_H_

#include <QPainter>
#include <QPolygonF>
#include <QTransform>

#include <KoToolFactoryBase.h>
#include <KoCreatePathTool.h>
#include "flake/kis_node_shape.h"
#include "kis_tool_select_base.h"
//#include "kis_tool_select_magnetic_option_widget.h"


class QWidget;
class KoCanvasBase;
class KisSelectionOptions;
class KisRandomConstAccessor;
class KoColorTransformation;
class KoColorSpace;

namespace Ui {
    class KisToolSelectMagneticOptionWidget;
}

#include <Eigen/Core>
using namespace Eigen;

typedef Eigen::Matrix3d FilterMatrix;


/**
 * Tool to select colors by pointing at a color on the image.
 */

class KisToolSelectMagnetic : public KisToolSelectBase
{
    Q_OBJECT
public:
    KisToolSelectMagnetic(KoCanvasBase * canvas);
    virtual ~KisToolSelectMagnetic();

    virtual void paint(QPainter& gc, const KoViewConverter &converter) {m_localTool.paint(gc, converter);}
    virtual void mousePressEvent(KoPointerEvent *e) {m_localTool.mousePressEvent(e);}
    virtual void mouseMoveEvent(KoPointerEvent *e) {m_localTool.mouseMoveEvent(e);}
    virtual void mouseReleaseEvent(KoPointerEvent *e) {m_localTool.mouseReleaseEvent(e);}
    virtual void mouseDoubleClickEvent(KoPointerEvent *e) {m_localTool.mouseDoubleClickEvent(e);}
    virtual void activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes) {
        m_localTool.activate(toolActivation, shapes);
    }
    virtual void deactivate() {m_localTool.deactivate();}

    int radius() const;
    int threshold() const;
    int searchStartPoint() const;
    int colorLimitation() const;
    bool limitToCurrentLayer() const;

private:
    virtual QWidget* createOptionWidget();
    Ui::KisToolSelectMagneticOptionWidget *m_magneticOptions;

    class LocalTool : public KoCreatePathTool {
        friend class KisToolSelectPath;
    public:
        LocalTool(KoCanvasBase * canvas, KisToolSelectMagnetic* selectingTool);
        ~LocalTool();
        void activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes);
        void deactivate();

        void mouseReleaseEvent(KoPointerEvent *event);
    protected:
        void paintPath(KoPathShape &pathShape, QPainter &painter, const KoViewConverter &converter);
        void paintOutline(QPainter* painter, const QPainterPath &path, qreal zoom);
        virtual void addPathShape(KoPathShape* pathShape);
        void computeOutline(const QPainterPath &pixelPath);
        void computeEdge(const QVector2D &startPoint, const QVector2D &direction, KisRandomConstAccessorSP pixelAccessor);
        FilterMatrix getMatrixForPoint(const QVector2D &point, KisRandomConstAccessorSP pixelAccessor) const;
        FilterMatrix getHorizontalFilterMatrix() const;
        FilterMatrix getVerticalFilterMatrix() const;

        /// this function removes unneeded points in m_detectedBorder, so that it is faster to paint
        void cleanDetectedBorder();

    private:
        KisToolSelectMagnetic* const m_selectingTool;
        KoShapeStroke* m_borderBackup;
        QPolygonF m_outline;
        const KoColorSpace* m_colorSpace;
        KoColorTransformation* m_colorTransformation;
        QPolygon m_detectedBorder;
        QPolygon m_tmpDetectedBorder;
        int m_accuracy;

        //debugging
        QPolygonF m_debugPolyline;
        QPolygon m_debugScannedPoints;
    };
    LocalTool m_localTool;
};

class KisToolSelectMagneticFactory : public KoToolFactoryBase
{

public:
    KisToolSelectMagneticFactory(const QStringList&)
            : KoToolFactoryBase("KisToolSelectMagnetic") {
        setToolTip(i18n("Magnetic selection tool"));
        setToolType(TOOL_TYPE_SELECTED);
        setActivationShapeId(KRITA_TOOL_ACTIVATION_ID);
        setIcon("tool_magneticoutline_selection");
        setShortcut(KShortcut(Qt::CTRL + Qt::Key_E));
        setPriority(57);
    }

    virtual ~KisToolSelectMagneticFactory() {}

    virtual KoToolBase * createTool(KoCanvasBase *canvas) {
        return  new KisToolSelectMagnetic(canvas);
    }

};


#endif // KIS_TOOL_SELECT_MAGNETIC_H_