summaryrefslogtreecommitdiffstats
path: root/chalk/ui/kis_tool.h
blob: c217e3071b7cf1aa780a25fc6088d5226ad38f02 (plain)
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) 1999 Matthias Elter  <[email protected]>
 *  Copyright (c) 2002, 2003 Patrick Julien <[email protected]>
 *
 *  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_H_
#define KIS_TOOL_H_

#include <tqobject.h>
#include <tqstring.h>

#include <ksharedptr.h>
#include <tdeaction.h>

#include "kis_shared_ptr_vector.h"
#include "kis_canvas_observer.h"

class TQCursor;
class TQEvent;
class TQKeyEvent;
class TQRect;
class TQWidget;
class TDEActionCollection;
class TDERadioAction;
class KDialog;
class KisBrush;
class KisGradient;
class KisPattern;
class KisButtonPressEvent;
class KisButtonReleaseEvent;
class KisDoubleClickEvent;
class KisMoveEvent;
class KisCanvasPainter;

enum enumToolType {
    TOOL_SHAPE = 0,   // Geometric shapes like ellipses and lines
    TOOL_FREEHAND = 1, // Freehand drawing tools
    TOOL_TRANSFORM = 2, // Tools that transform the layer
    TOOL_FILL = 3, // Tools that fill parts of the canvas
    TOOL_VIEW = 4,   // Tools that affect the canvas: pan, zoom, etc.
    TOOL_SELECT = 5

};

const TQ_UINT8 NUMBER_OF_TOOLTYPES = 6;

class KisTool : public TQObject, public KisCanvasObserver, public TDEShared {
    Q_OBJECT
  

public:
    KisTool(const TQString & name);
    virtual ~KisTool();

public:

    virtual void paint(KisCanvasPainter& gc) = 0;
    virtual void paint(KisCanvasPainter& gc, const TQRect& rc) = 0;

    /**
     * This function is called after the creation of a tool to create the TDEAction corresponding
     * to the tool.
     *
     * The code should look like :
     * @code
     * 
     * @endcode
     */
    virtual void setup(TDEActionCollection *collection) = 0;

    virtual void buttonPress(KisButtonPressEvent *e) = 0;
    virtual void move(KisMoveEvent *e) = 0;
    virtual void buttonRelease(KisButtonReleaseEvent *e) = 0;
    virtual void doubleClick(KisDoubleClickEvent *e) = 0;
    virtual void keyPress(TQKeyEvent *e) = 0;
    virtual void keyRelease(TQKeyEvent *e) = 0;

    virtual TQCursor cursor() = 0;
    virtual void setCursor(const TQCursor& cursor) = 0;
    /**
     * This function is called to create the configuration widget of the tool.
     * @param parent the parent of the widget
     */
    virtual TQWidget* createOptionWidget(TQWidget* parent);
    /**
     * @return the current configuration widget.
     */
    virtual TQWidget* optionWidget();
    TDERadioAction *action() const { return m_action; }

    /**
     * Return true if this tool wants auto canvas-scrolling to 
     * work when this tool is active.
     */
    virtual bool wantsAutoScroll() const { return true; }

    // Methods for integration with karbon-style toolbox
    virtual TQ_UINT32 priority() { return 0; }
    virtual enumToolType toolType() { return TOOL_FREEHAND; }
    virtual TQString icon() { return m_action->icon(); }
    virtual TQString quickHelp() const { return ""; }

public slots:
    /**
     * This slot is called when the tool is selected in the toolbox
     */
    virtual void activate() = 0;
    
    /**
     * deactivate is called when the tool gets deactivated because another
     * tool is selected. Tools can then clean up after themselves.
     */
    virtual void deactivate() = 0;

private:
    KisTool(const KisTool&);
    KisTool& operator=(const KisTool&);

protected:
    TDERadioAction *m_action;
    bool m_ownAction;

private:
    class KisToolPrivate;
    KisToolPrivate * d;
    
};

#endif // KIS_TOOL_H_