2
* kis_tool_brush.cc - part of Krita
4
* Copyright (c) 2003-2004 Boudewijn Rempt <boud@valdyas.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
#include <qpushbutton.h>
28
#include <qcheckbox.h>
35
#include "kis_config.h"
36
#include "kis_brush.h"
37
#include "kis_paintop.h"
38
#include "kis_paintop_registry.h"
39
#include "kis_cmb_composite.h"
40
#include "kis_cursor.h"
41
#include "kis_painter.h"
42
#include "kis_tool_brush.h"
43
#include "kis_canvas_subject.h"
44
#include "kis_boundary.h"
45
#include "kis_move_event.h"
46
#include "kis_canvas.h"
47
#include "kis_layer.h"
49
KisToolBrush::KisToolBrush()
50
: super(i18n("Brush"))
52
setName("tool_brush");
53
setCursor(KisCursor::load("tool_freehand_cursor.png", 5, 5));
54
m_rate = 100; // Conveniently hardcoded for now
55
m_timer = new QTimer(this);
58
connect(m_timer, SIGNAL(timeout()), this, SLOT(timeoutPaint()));
62
KisToolBrush::~KisToolBrush()
68
void KisToolBrush::timeoutPaint()
70
if (currentImage() && painter()) {
71
painter()->paintAt(m_prevPos, m_prevPressure, m_prevXTilt, m_prevYTilt);
72
currentImage()->activeLayer()->setDirty(painter()->dirtyRect());
77
void KisToolBrush::update(KisCanvasSubject *subject)
79
super::update(subject);
82
void KisToolBrush::initPaint(KisEvent *e)
87
kdWarning() << "Didn't create a painter! Something is wrong!\n";
90
KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), m_painter);
93
m_subject->canvasController()->kiscanvas()->update(); // remove the outline
95
painter()->setPaintOp(op); // And now the painter owns the op and will destroy it.
97
if (op->incremental()) {
98
m_timer->start( m_rate );
103
void KisToolBrush::endPaint()
110
void KisToolBrush::setup(KActionCollection *collection)
113
m_action = static_cast<KRadioAction *>(collection->action(name()));
116
m_action = new KRadioAction(i18n("&Brush"),
117
"tool_freehand", Qt::Key_B, this,
118
SLOT(activate()), collection,
120
m_action->setToolTip(i18n("Draw freehand"));
121
m_action->setExclusiveGroup("tools");
126
void KisToolBrush::move(KisMoveEvent *e) {
127
KisToolFreehand::move(e);
129
if (m_mode != PAINT && cfg.cursorStyle() == CURSOR_STYLE_OUTLINE)
130
paintOutline(e->pos());
133
void KisToolBrush::leave(QEvent */*e*/) {
134
m_subject->canvasController()->kiscanvas()->update(); // remove the outline
138
void KisToolBrush::slotSetPaintingMode( int mode )
140
if (mode == QButton::On) {
142
m_paintIncremental = true;
145
m_paintIncremental = false;
150
QWidget* KisToolBrush::createOptionWidget(QWidget* parent)
152
QWidget *widget = super::createOptionWidget(parent);
153
m_chkDirect = new QCheckBox(i18n("Paint direct"), widget, "chkDirect");
154
m_chkDirect->setChecked(true);
155
connect(m_chkDirect, SIGNAL(stateChanged(int)), this, SLOT(slotSetPaintingMode(int)));
157
m_optionLayout = new QGridLayout(widget, 3, 2, 0, 6);
158
Q_CHECK_PTR(m_optionLayout);
160
super::addOptionWidgetLayout(m_optionLayout);
161
m_optionLayout->addWidget(m_chkDirect, 0, 0);
166
#include "kis_tool_brush.moc"