~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to krita/plugins/tools/defaulttools/kis_tool_brush.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  kis_tool_brush.cc - part of Krita
 
3
 *
 
4
 *  Copyright (c) 2003-2004 Boudewijn Rempt <boud@valdyas.org>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 */
 
20
#include <qevent.h>
 
21
#include <qlabel.h>
 
22
#include <qlayout.h>
 
23
#include <qwidget.h>
 
24
#include <qtimer.h>
 
25
#include <qpushbutton.h>
 
26
#include <qpainter.h>
 
27
#include <qrect.h>
 
28
#include <qcheckbox.h>
 
29
 
 
30
#include <kdebug.h>
 
31
#include <kaction.h>
 
32
#include <kcommand.h>
 
33
#include <klocale.h>
 
34
 
 
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"
 
48
 
 
49
KisToolBrush::KisToolBrush()
 
50
        : super(i18n("Brush"))
 
51
{
 
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);
 
56
    Q_CHECK_PTR(m_timer);
 
57
 
 
58
    connect(m_timer, SIGNAL(timeout()), this, SLOT(timeoutPaint()));
 
59
 
 
60
}
 
61
 
 
62
KisToolBrush::~KisToolBrush()
 
63
{
 
64
    delete m_timer;
 
65
    m_timer = 0;
 
66
}
 
67
 
 
68
void KisToolBrush::timeoutPaint()
 
69
{
 
70
    if (currentImage() && painter()) {
 
71
        painter()->paintAt(m_prevPos, m_prevPressure, m_prevXTilt, m_prevYTilt);
 
72
        currentImage()->activeLayer()->setDirty(painter()->dirtyRect());
 
73
    }
 
74
}
 
75
 
 
76
 
 
77
void KisToolBrush::update(KisCanvasSubject *subject)
 
78
{
 
79
    super::update(subject);
 
80
}
 
81
 
 
82
void KisToolBrush::initPaint(KisEvent *e)
 
83
{
 
84
    super::initPaint(e);
 
85
 
 
86
    if (!m_painter) {
 
87
        kdWarning() << "Didn't create a painter! Something is wrong!\n";
 
88
        return;
 
89
    }
 
90
    KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), m_painter);
 
91
    if (!op) return;
 
92
    
 
93
    m_subject->canvasController()->kiscanvas()->update(); // remove the outline
 
94
 
 
95
    painter()->setPaintOp(op); // And now the painter owns the op and will destroy it.
 
96
 
 
97
    if (op->incremental()) {
 
98
        m_timer->start( m_rate );
 
99
    }
 
100
}
 
101
 
 
102
 
 
103
void KisToolBrush::endPaint()
 
104
{
 
105
    m_timer->stop();
 
106
    super::endPaint();
 
107
}
 
108
 
 
109
 
 
110
void KisToolBrush::setup(KActionCollection *collection)
 
111
{
 
112
 
 
113
    m_action = static_cast<KRadioAction *>(collection->action(name()));
 
114
 
 
115
    if (m_action == 0) {
 
116
        m_action = new KRadioAction(i18n("&Brush"),
 
117
                                    "tool_freehand", Qt::Key_B, this,
 
118
                                    SLOT(activate()), collection,
 
119
                                    name());
 
120
        m_action->setToolTip(i18n("Draw freehand"));
 
121
        m_action->setExclusiveGroup("tools");
 
122
        m_ownAction = true;
 
123
    }
 
124
}
 
125
 
 
126
void KisToolBrush::move(KisMoveEvent *e) {
 
127
    KisToolFreehand::move(e);
 
128
    KisConfig cfg;
 
129
    if (m_mode != PAINT && cfg.cursorStyle() == CURSOR_STYLE_OUTLINE)
 
130
        paintOutline(e->pos());
 
131
}
 
132
 
 
133
void KisToolBrush::leave(QEvent */*e*/) {
 
134
    m_subject->canvasController()->kiscanvas()->update(); // remove the outline
 
135
}
 
136
 
 
137
 
 
138
void KisToolBrush::slotSetPaintingMode( int mode )
 
139
{
 
140
    if (mode == QButton::On) {
 
141
        // Direct painting
 
142
        m_paintIncremental = true;
 
143
    }
 
144
    else {
 
145
        m_paintIncremental = false;
 
146
    }
 
147
}
 
148
 
 
149
 
 
150
QWidget* KisToolBrush::createOptionWidget(QWidget* parent)
 
151
{
 
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)));
 
156
    
 
157
    m_optionLayout = new QGridLayout(widget, 3, 2, 0, 6);
 
158
    Q_CHECK_PTR(m_optionLayout);
 
159
 
 
160
    super::addOptionWidgetLayout(m_optionLayout);
 
161
    m_optionLayout->addWidget(m_chkDirect, 0, 0);
 
162
 
 
163
    return widget;
 
164
}
 
165
 
 
166
#include "kis_tool_brush.moc"
 
167