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

« back to all changes in this revision

Viewing changes to karbon/plugins/tools/CalligraphyTool/KarbonCalligraphyTool.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <KoSelection.h>
33
33
#include <KarbonCurveFit.h>
34
34
#include <KoColorBackground.h>
35
 
#include <KoCanvasResourceProvider.h>
 
35
#include <KoResourceManager.h>
36
36
#include <KoColor.h>
37
37
 
38
38
#include <KAction>
49
49
 
50
50
 
51
51
KarbonCalligraphyTool::KarbonCalligraphyTool(KoCanvasBase *canvas)
52
 
    : KoTool(canvas), m_shape(0), m_angle(0),
53
 
      m_selectedPath(0), m_isDrawing(false), m_speed(0, 0), m_lastShape(0)
 
52
        : KoToolBase(canvas), m_shape(0), m_angle(0),
 
53
        m_selectedPath(0), m_isDrawing(false), m_speed(0, 0), m_lastShape(0)
54
54
{
55
 
    connect( m_canvas->shapeManager(), SIGNAL(selectionChanged()),
56
 
             SLOT(updateSelectedPath()) );
 
55
    connect(canvas->shapeManager(), SIGNAL(selectionChanged()),
 
56
            SLOT(updateSelectedPath()));
57
57
 
58
58
    updateSelectedPath();
59
59
    createOptionWidget(); // initialize the option widget
63
63
{
64
64
}
65
65
 
66
 
void KarbonCalligraphyTool::paint( QPainter &painter,
67
 
                                   const KoViewConverter &converter )
 
66
void KarbonCalligraphyTool::paint(QPainter &painter,
 
67
                                  const KoViewConverter &converter)
68
68
{
69
 
    if ( m_selectedPath )
70
 
    {
 
69
    if (m_selectedPath) {
71
70
        painter.save();
72
 
        painter.setRenderHints( QPainter::Antialiasing, false );
73
 
        painter.setPen( Qt::red ); // TODO make configurable
 
71
        painter.setRenderHints(QPainter::Antialiasing, false);
 
72
        painter.setPen(Qt::red);   // TODO make configurable
74
73
        QRectF rect = m_selectedPath->boundingRect();
75
 
        QPointF p1 = converter.documentToView( rect.topLeft() );
76
 
        QPointF p2 = converter.documentToView( rect.bottomRight() );
77
 
        painter.drawRect( QRectF(p1, p2) );
 
74
        QPointF p1 = converter.documentToView(rect.topLeft());
 
75
        QPointF p2 = converter.documentToView(rect.bottomRight());
 
76
        painter.drawRect(QRectF(p1, p2));
78
77
        painter.restore();
79
78
    }
80
79
 
81
 
    if ( ! m_shape )
 
80
    if (! m_shape)
82
81
        return;
83
82
 
84
83
    painter.save();
85
84
 
86
 
    painter.setMatrix( m_shape->absoluteTransformation(&converter) *
87
 
                       painter.matrix() );
88
 
    m_shape->paint( painter, converter );
 
85
    painter.setMatrix(m_shape->absoluteTransformation(&converter) *
 
86
                      painter.matrix());
 
87
    m_shape->paint(painter, converter);
89
88
 
90
89
    painter.restore();
91
90
}
92
91
 
93
 
void KarbonCalligraphyTool::mousePressEvent( KoPointerEvent *event )
 
92
void KarbonCalligraphyTool::mousePressEvent(KoPointerEvent *event)
94
93
{
95
 
    if ( m_isDrawing ) 
 
94
    if (m_isDrawing)
96
95
        return;
97
96
 
98
97
    m_lastPoint = event->point;
100
99
 
101
100
    m_isDrawing = true;
102
101
    m_pointCount = 0;
103
 
    m_shape = new KarbonCalligraphicShape( m_caps );
104
 
    m_shape->setBackground( new KoColorBackground( m_canvas->resourceProvider()->backgroundColor().toQColor() ) );
 
102
    m_shape = new KarbonCalligraphicShape(m_caps);
 
103
    m_shape->setBackground(new KoColorBackground(canvas()->resourceManager()->backgroundColor().toQColor()));
105
104
    //addPoint( event );
106
105
}
107
106
 
108
 
void KarbonCalligraphyTool::mouseMoveEvent( KoPointerEvent *event )
 
107
void KarbonCalligraphyTool::mouseMoveEvent(KoPointerEvent *event)
109
108
{
110
 
    if ( ! m_isDrawing )
 
109
    if (! m_isDrawing)
111
110
        return;
112
111
 
113
 
    addPoint( event );
 
112
    addPoint(event);
114
113
}
115
114
 
116
 
void KarbonCalligraphyTool::mouseReleaseEvent( KoPointerEvent *event )
 
115
void KarbonCalligraphyTool::mouseReleaseEvent(KoPointerEvent *event)
117
116
{
118
 
    if ( ! m_isDrawing )
 
117
    if (! m_isDrawing)
119
118
        return;
120
119
 
121
 
    if ( m_pointCount == 0 )
122
 
    {
 
120
    if (m_pointCount == 0) {
123
121
        // handle click: select shape (if any)
124
 
        if ( event->point == m_lastPoint )
125
 
        {
126
 
            KoShapeManager *shapeManager = m_canvas->shapeManager();
127
 
            KoShape *selectedShape = shapeManager->shapeAt( event->point );
128
 
            if ( selectedShape != 0 )
129
 
            {
 
122
        if (event->point == m_lastPoint) {
 
123
            KoShapeManager *shapeManager = canvas()->shapeManager();
 
124
            KoShape *selectedShape = shapeManager->shapeAt(event->point);
 
125
            if (selectedShape != 0) {
130
126
                shapeManager->selection()->deselectAll();
131
 
                shapeManager->selection()->select( selectedShape );
 
127
                shapeManager->selection()->select(selectedShape);
132
128
            }
133
129
        }
134
130
 
136
132
        m_shape = 0;
137
133
        m_isDrawing = false;
138
134
        return;
139
 
    }
140
 
    else
141
 
    {
 
135
    } else {
142
136
        m_endOfPath = false;    // allow last point being added
143
 
        addPoint( event );      // add last point
 
137
        addPoint(event);        // add last point
144
138
        m_isDrawing = false;
145
139
    }
146
140
 
147
141
    m_shape->simplifyGuidePath();
148
142
 
149
 
    QUndoCommand * cmd = m_canvas->shapeController()->addShape( m_shape );
150
 
    if( cmd )
151
 
    {
 
143
    QUndoCommand * cmd = canvas()->shapeController()->addShape(m_shape);
 
144
    if (cmd) {
152
145
        m_lastShape = m_shape;
153
 
        m_canvas->addCommand( cmd );
154
 
        m_canvas->updateCanvas( m_shape->boundingRect() );
155
 
    }
156
 
    else
157
 
    {
 
146
        canvas()->addCommand(cmd);
 
147
        canvas()->updateCanvas(m_shape->boundingRect());
 
148
    } else {
158
149
        // TODO: when may this happen????
159
150
        delete m_shape;
160
151
    }
162
153
    m_shape = 0;
163
154
}
164
155
 
165
 
void KarbonCalligraphyTool::addPoint( KoPointerEvent *event )
 
156
void KarbonCalligraphyTool::addPoint(KoPointerEvent *event)
166
157
{
167
 
    if ( m_pointCount == 0 )
168
 
    {
169
 
        if ( m_usePath && m_selectedPath )
 
158
    if (m_pointCount == 0) {
 
159
        if (m_usePath && m_selectedPath)
170
160
            m_selectedPathOutline = m_selectedPath->outline();
171
161
        m_pointCount = 1;
172
162
        m_endOfPath = false;
173
163
        m_followPathPosition = 0;
174
164
        m_lastMousePos = event->point;
175
 
        m_lastPoint = calculateNewPoint( event->point, &m_speed );
176
 
        m_deviceSupportsTilt = ( event->xTilt() != 0 || event->yTilt() != 0 );
 
165
        m_lastPoint = calculateNewPoint(event->point, &m_speed);
 
166
        m_deviceSupportsTilt = (event->xTilt() != 0 || event->yTilt() != 0);
177
167
        return;
178
168
    }
179
169
 
180
 
    if ( m_endOfPath )
 
170
    if (m_endOfPath)
181
171
        return;
182
172
 
183
173
    ++m_pointCount;
184
174
 
185
 
    setAngle( event );
 
175
    setAngle(event);
186
176
 
187
177
    QPointF newSpeed;
188
 
    QPointF newPoint= calculateNewPoint( event->point, &newSpeed );
189
 
    qreal width = calculateWidth( event->pressure() );
190
 
    qreal angle = calculateAngle( m_speed, newSpeed );
 
178
    QPointF newPoint = calculateNewPoint(event->point, &newSpeed);
 
179
    qreal width = calculateWidth(event->pressure());
 
180
    qreal angle = calculateAngle(m_speed, newSpeed);
191
181
 
192
182
    // add the previous point
193
 
    m_shape->appendPoint( m_lastPoint, angle, width );
 
183
    m_shape->appendPoint(m_lastPoint, angle, width);
194
184
 
195
185
    m_speed = newSpeed;
196
186
    m_lastPoint = newPoint;
197
 
    m_canvas->updateCanvas( m_shape->lastPieceBoundingRect() );
 
187
    canvas()->updateCanvas(m_shape->lastPieceBoundingRect());
198
188
 
199
 
    if ( m_usePath && m_selectedPath )
 
189
    if (m_usePath && m_selectedPath)
200
190
        m_speed = QPointF(0, 0); // following path
201
191
}
202
192
 
203
 
void KarbonCalligraphyTool::setAngle( KoPointerEvent *event )
 
193
void KarbonCalligraphyTool::setAngle(KoPointerEvent *event)
204
194
{
205
 
    if ( ! m_useAngle )
206
 
    {
 
195
    if (! m_useAngle) {
207
196
        m_angle = (360 - m_customAngle + 90) / 180.0 * M_PI;
208
197
        return;
209
198
    }
210
199
 
211
200
    // setting m_angle to the angle of the device
212
 
    if ( event->xTilt() != 0 || event->yTilt() != 0 )
 
201
    if (event->xTilt() != 0 || event->yTilt() != 0)
213
202
        m_deviceSupportsTilt = false;
214
203
 
215
 
    if ( m_deviceSupportsTilt )
216
 
    {
217
 
        if ( event->xTilt() == 0 && event->yTilt() == 0 )
 
204
    if (m_deviceSupportsTilt) {
 
205
        if (event->xTilt() == 0 && event->yTilt() == 0)
218
206
            return; // leave as is
219
207
        kDebug(38000) << "using tilt" << m_angle;
220
208
 
221
 
        if ( event->x() == 0 )
222
 
        {
223
 
            m_angle = M_PI/2;
 
209
        if (event->x() == 0) {
 
210
            m_angle = M_PI / 2;
224
211
            return;
225
212
        }
226
213
 
227
214
        // y is inverted in qt painting
228
 
        m_angle = std::atan( static_cast<double>(-event->yTilt() / event->xTilt()) ) + M_PI/2;
229
 
    }
230
 
    else
231
 
    {
232
 
        m_angle = event->rotation() + M_PI/2;
 
215
        m_angle = std::atan(static_cast<double>(-event->yTilt() / event->xTilt())) + M_PI / 2;
 
216
    } else {
 
217
        m_angle = event->rotation() + M_PI / 2;
233
218
        kDebug(38000) << "using rotation" << m_angle;
234
219
    }
235
220
}
236
221
 
237
222
 
238
 
QPointF KarbonCalligraphyTool::calculateNewPoint( const QPointF &mousePos,
239
 
                                                  QPointF *speed )
 
223
QPointF KarbonCalligraphyTool::calculateNewPoint(const QPointF &mousePos,
 
224
        QPointF *speed)
240
225
{
241
 
    if ( !m_usePath || !m_selectedPath ) // don't follow path
242
 
    {
 
226
    if (!m_usePath || !m_selectedPath) { // don't follow path
243
227
        QPointF force = mousePos - m_lastPoint;
244
228
        QPointF dSpeed = force / m_mass;
245
229
        *speed = m_speed * (1.0 - m_drag) + dSpeed;
246
 
        return m_lastPoint + *speed; 
 
230
        return m_lastPoint + *speed;
247
231
    }
248
232
 
249
233
    QPointF sp = mousePos - m_lastMousePos;
250
234
    m_lastMousePos = mousePos;
251
235
 
252
236
    // follow selected path
253
 
    qreal step = QLineF(QPointF(0,0), sp).length();
 
237
    qreal step = QLineF(QPointF(0, 0), sp).length();
254
238
    m_followPathPosition += step;
255
239
 
256
240
    qreal t;
257
 
    if (m_followPathPosition >= m_selectedPathOutline.length())
258
 
    {
 
241
    if (m_followPathPosition >= m_selectedPathOutline.length()) {
259
242
        t = 1.0;
260
243
        m_endOfPath = true;
261
 
    }
262
 
    else
263
 
    {
264
 
        t = m_selectedPathOutline.percentAtLength( m_followPathPosition );
 
244
    } else {
 
245
        t = m_selectedPathOutline.percentAtLength(m_followPathPosition);
265
246
    }
266
247
 
267
248
    QPointF res = m_selectedPathOutline.pointAtPercent(t)
270
251
    return res;
271
252
}
272
253
 
273
 
qreal KarbonCalligraphyTool::calculateWidth( qreal pressure )
 
254
qreal KarbonCalligraphyTool::calculateWidth(qreal pressure)
274
255
{
275
256
    // calculate the modulo of the speed
276
 
    qreal speed = std::sqrt( pow(m_speed.x(), 2) + pow(m_speed.y(), 2) );
 
257
    qreal speed = std::sqrt(pow(m_speed.x(), 2) + pow(m_speed.y(), 2));
277
258
    qreal thinning =  m_thinning * (speed + 1) / 10.0; // can be negative
278
259
 
279
 
    if ( thinning > 1 )
 
260
    if (thinning > 1)
280
261
        thinning = 1;
281
262
 
282
 
    if ( ! m_usePressure )
 
263
    if (! m_usePressure)
283
264
        pressure = 1.0;
284
265
 
285
266
    qreal strokeWidth = m_strokeWidth * pressure * (1 - thinning);
286
267
 
287
268
    const qreal MINIMUM_STROKE_WIDTH = 1.0;
288
 
    if ( strokeWidth < MINIMUM_STROKE_WIDTH )
 
269
    if (strokeWidth < MINIMUM_STROKE_WIDTH)
289
270
        strokeWidth = MINIMUM_STROKE_WIDTH;
290
271
 
291
272
    return strokeWidth;
292
273
}
293
274
 
294
275
 
295
 
qreal KarbonCalligraphyTool::calculateAngle( const QPointF &oldSpeed,
296
 
                                              const QPointF &newSpeed )
 
276
qreal KarbonCalligraphyTool::calculateAngle(const QPointF &oldSpeed,
 
277
        const QPointF &newSpeed)
297
278
{
298
279
    // calculate the avarage of the speed (sum of the normalized values)
299
 
    qreal oldLength = QLineF( QPointF(0,0), oldSpeed ).length();
300
 
    qreal newLength = QLineF( QPointF(0,0), newSpeed ).length();
 
280
    qreal oldLength = QLineF(QPointF(0, 0), oldSpeed).length();
 
281
    qreal newLength = QLineF(QPointF(0, 0), newSpeed).length();
301
282
    QPointF oldSpeedNorm = !qFuzzyCompare(oldLength + 1, 1) ?
302
 
                            oldSpeed/oldLength : QPointF(0, 0);
 
283
                           oldSpeed / oldLength : QPointF(0, 0);
303
284
    QPointF newSpeedNorm = !qFuzzyCompare(newLength + 1, 1) ?
304
 
                            newSpeed/newLength : QPointF(0, 0);
 
285
                           newSpeed / newLength : QPointF(0, 0);
305
286
    QPointF speed = oldSpeedNorm + newSpeedNorm;
306
287
 
307
288
    // angle solely based on the speed
308
289
    qreal speedAngle = 0;
309
 
    if ( speed.x() != 0 ) // avoid division by zero
310
 
    {
311
 
        speedAngle = std::atan( speed.y() / speed.x() );
312
 
    }
313
 
    else if ( speed.y() > 0 )
314
 
    {
315
 
        // x == 0 && y != 0
316
 
        speedAngle = M_PI/2;
317
 
    }
318
 
    else if ( speed.y() < 0 )
319
 
    {
320
 
        // x == 0 && y != 0
321
 
        speedAngle = -M_PI/2;
322
 
    }
323
 
    if ( speed.x() < 0 )
 
290
    if (speed.x() != 0) { // avoid division by zero
 
291
        speedAngle = std::atan(speed.y() / speed.x());
 
292
    } else if (speed.y() > 0) {
 
293
        // x == 0 && y != 0
 
294
        speedAngle = M_PI / 2;
 
295
    } else if (speed.y() < 0) {
 
296
        // x == 0 && y != 0
 
297
        speedAngle = -M_PI / 2;
 
298
    }
 
299
    if (speed.x() < 0)
324
300
        speedAngle += M_PI;
325
301
 
326
302
    // move 90 degrees
327
 
    speedAngle += M_PI/2;
 
303
    speedAngle += M_PI / 2;
328
304
 
329
305
    qreal fixedAngle = m_angle;
330
306
    // check if the fixed angle needs to be flipped
331
307
    qreal diff = fixedAngle - speedAngle;
332
 
    while ( diff >= M_PI ) // normalize diff between -180 and 180
333
 
        diff -= 2*M_PI;
334
 
    while ( diff < -M_PI )
335
 
        diff += 2*M_PI;
 
308
    while (diff >= M_PI)   // normalize diff between -180 and 180
 
309
        diff -= 2 * M_PI;
 
310
    while (diff < -M_PI)
 
311
        diff += 2 * M_PI;
336
312
 
337
 
    if ( std::abs(diff) > M_PI/2 ) // if absolute value < 90
 
313
    if (std::abs(diff) > M_PI / 2) // if absolute value < 90
338
314
        fixedAngle += M_PI; // += 180
339
315
 
340
316
    qreal dAngle = speedAngle - fixedAngle;
341
317
 
342
318
    // normalize dAngle between -90 and +90
343
 
    while ( dAngle >= M_PI/2 )
 
319
    while (dAngle >= M_PI / 2)
344
320
        dAngle -= M_PI;
345
 
    while ( dAngle < -M_PI/2 )
 
321
    while (dAngle < -M_PI / 2)
346
322
        dAngle += M_PI;
347
323
 
348
 
    qreal angle = fixedAngle + dAngle*(1.0 - m_fixation);
 
324
    qreal angle = fixedAngle + dAngle * (1.0 - m_fixation);
349
325
 
350
326
    return angle;
351
327
}
352
328
 
353
 
void KarbonCalligraphyTool::activate( bool )
 
329
void KarbonCalligraphyTool::activate(ToolActivation, const QSet<KoShape*> &)
354
330
{
355
 
    useCursor(Qt::ArrowCursor, true);
 
331
    useCursor(Qt::ArrowCursor);
356
332
    m_lastShape = 0;
357
333
}
358
334
 
359
335
void KarbonCalligraphyTool::deactivate()
360
336
{
361
 
    if ( m_lastShape )
362
 
    {
363
 
        KoSelection *selection = m_canvas->shapeManager()->selection();
 
337
    if (m_lastShape && canvas()->shapeManager()->shapes().contains(m_lastShape)) {
 
338
        KoSelection *selection = canvas()->shapeManager()->selection();
364
339
        selection->deselectAll();
365
 
        selection->select( m_lastShape );
 
340
        selection->select(m_lastShape);
366
341
    }
367
342
}
368
343
 
370
345
{
371
346
    // if the widget don't exists yet create it
372
347
    KarbonCalligraphyOptionWidget *widget = new KarbonCalligraphyOptionWidget;
373
 
    connect( widget, SIGNAL(usePathChanged(bool)),
 
348
    connect(widget, SIGNAL(usePathChanged(bool)),
374
349
            this, SLOT(setUsePath(bool)));
375
350
 
376
 
    connect( widget, SIGNAL(usePressureChanged(bool)),
 
351
    connect(widget, SIGNAL(usePressureChanged(bool)),
377
352
            this, SLOT(setUsePressure(bool)));
378
353
 
379
 
    connect( widget, SIGNAL(useAngleChanged(bool)),
 
354
    connect(widget, SIGNAL(useAngleChanged(bool)),
380
355
            this, SLOT(setUseAngle(bool)));
381
356
 
382
 
    connect( widget, SIGNAL(widthChanged(double)),
383
 
             this, SLOT(setStrokeWidth(double)));
384
 
 
385
 
    connect( widget, SIGNAL(thinningChanged(double)),
386
 
             this, SLOT(setThinning(double)));
387
 
 
388
 
    connect( widget, SIGNAL(angleChanged(int)),
389
 
             this, SLOT(setAngle(int)));
390
 
 
391
 
    connect( widget, SIGNAL(fixationChanged(double)),
392
 
             this, SLOT(setFixation(double)));
393
 
 
394
 
    connect( widget, SIGNAL(capsChanged(double)),
395
 
             this, SLOT(setCaps(double)));
396
 
 
397
 
    connect( widget, SIGNAL(massChanged(double)),
398
 
             this, SLOT(setMass(double)));
399
 
 
400
 
    connect( widget, SIGNAL(dragChanged(double)),
401
 
             this, SLOT(setDrag(double)));
402
 
 
403
 
    connect( this, SIGNAL(pathSelectedChanged(bool)),
404
 
             widget, SLOT(setUsePathEnabled(bool)) );
 
357
    connect(widget, SIGNAL(widthChanged(double)),
 
358
            this, SLOT(setStrokeWidth(double)));
 
359
 
 
360
    connect(widget, SIGNAL(thinningChanged(double)),
 
361
            this, SLOT(setThinning(double)));
 
362
 
 
363
    connect(widget, SIGNAL(angleChanged(int)),
 
364
            this, SLOT(setAngle(int)));
 
365
 
 
366
    connect(widget, SIGNAL(fixationChanged(double)),
 
367
            this, SLOT(setFixation(double)));
 
368
 
 
369
    connect(widget, SIGNAL(capsChanged(double)),
 
370
            this, SLOT(setCaps(double)));
 
371
 
 
372
    connect(widget, SIGNAL(massChanged(double)),
 
373
            this, SLOT(setMass(double)));
 
374
 
 
375
    connect(widget, SIGNAL(dragChanged(double)),
 
376
            this, SLOT(setDrag(double)));
 
377
 
 
378
    connect(this, SIGNAL(pathSelectedChanged(bool)),
 
379
            widget, SLOT(setUsePathEnabled(bool)));
405
380
 
406
381
    // add shortcuts
407
 
    KAction *action = new KAction( i18n("Calligraphy: increase width"), this );
408
 
    action->setShortcut( Qt::Key_Right );
409
 
    connect( action, SIGNAL(triggered()), widget, SLOT(increaseWidth()) );
410
 
    addAction( "calligraphy_increase_width", action );
411
 
 
412
 
    action = new KAction( i18n("Calligraphy: decrease width"), this );
413
 
    action->setShortcut( Qt::Key_Left );
414
 
    connect( action, SIGNAL(triggered()), widget, SLOT(decreaseWidth()) );
415
 
    addAction( "calligraphy_decrease_width", action );
416
 
 
417
 
    action = new KAction( i18n("Calligraphy: increase angle"), this );
418
 
    action->setShortcut( Qt::Key_Up );
419
 
    connect( action, SIGNAL(triggered()), widget, SLOT(increaseAngle()) );
420
 
    addAction( "calligraphy_increase_angle", action );
421
 
 
422
 
    action = new KAction( i18n("Calligraphy: decrease angle"), this );
423
 
    action->setShortcut( Qt::Key_Down );
424
 
    connect( action, SIGNAL(triggered()), widget, SLOT(decreaseAngle()) );
425
 
    addAction( "calligraphy_decrease_angle", action );
 
382
    KAction *action = new KAction(i18n("Calligraphy: increase width"), this);
 
383
    action->setShortcut(Qt::Key_Right);
 
384
    connect(action, SIGNAL(triggered()), widget, SLOT(increaseWidth()));
 
385
    addAction("calligraphy_increase_width", action);
 
386
 
 
387
    action = new KAction(i18n("Calligraphy: decrease width"), this);
 
388
    action->setShortcut(Qt::Key_Left);
 
389
    connect(action, SIGNAL(triggered()), widget, SLOT(decreaseWidth()));
 
390
    addAction("calligraphy_decrease_width", action);
 
391
 
 
392
    action = new KAction(i18n("Calligraphy: increase angle"), this);
 
393
    action->setShortcut(Qt::Key_Up);
 
394
    connect(action, SIGNAL(triggered()), widget, SLOT(increaseAngle()));
 
395
    addAction("calligraphy_increase_angle", action);
 
396
 
 
397
    action = new KAction(i18n("Calligraphy: decrease angle"), this);
 
398
    action->setShortcut(Qt::Key_Down);
 
399
    connect(action, SIGNAL(triggered()), widget, SLOT(decreaseAngle()));
 
400
    addAction("calligraphy_decrease_angle", action);
426
401
 
427
402
    // sync all parameters with the loaded profile
428
403
    widget->emitAll();
430
405
    return widget;
431
406
}
432
407
 
433
 
void KarbonCalligraphyTool::setStrokeWidth( double width )
 
408
void KarbonCalligraphyTool::setStrokeWidth(double width)
434
409
{
435
410
    m_strokeWidth = width;
436
411
}
437
412
 
438
 
void KarbonCalligraphyTool::setThinning( double thinning )
 
413
void KarbonCalligraphyTool::setThinning(double thinning)
439
414
{
440
415
    m_thinning = thinning;
441
416
}
442
417
 
443
 
void KarbonCalligraphyTool::setAngle( int angle )
 
418
void KarbonCalligraphyTool::setAngle(int angle)
444
419
{
445
420
    m_customAngle = angle;
446
421
}
447
422
 
448
 
void KarbonCalligraphyTool::setFixation( double fixation )
 
423
void KarbonCalligraphyTool::setFixation(double fixation)
449
424
{
450
425
    m_fixation = fixation;
451
426
}
452
427
 
453
 
void KarbonCalligraphyTool::setMass( double mass )
 
428
void KarbonCalligraphyTool::setMass(double mass)
454
429
{
455
430
    m_mass = mass * mass + 1;
456
431
}
457
432
 
458
 
void KarbonCalligraphyTool::setDrag( double drag )
 
433
void KarbonCalligraphyTool::setDrag(double drag)
459
434
{
460
435
    m_drag = drag;
461
436
}
462
437
 
463
 
void KarbonCalligraphyTool::setUsePath( bool usePath )
 
438
void KarbonCalligraphyTool::setUsePath(bool usePath)
464
439
{
465
440
    m_usePath = usePath;
466
441
    //if ( m_selectedPath )
467
 
    //    m_canvas->updateCanvas( m_selectedPath->boundingRect() );
 
442
    //    canvas()->updateCanvas( m_selectedPath->boundingRect() );
468
443
}
469
444
 
470
 
void KarbonCalligraphyTool::setUsePressure( bool usePressure )
 
445
void KarbonCalligraphyTool::setUsePressure(bool usePressure)
471
446
{
472
447
    m_usePressure = usePressure;
473
448
}
474
449
 
475
 
void KarbonCalligraphyTool::setUseAngle(bool useAngle )
 
450
void KarbonCalligraphyTool::setUseAngle(bool useAngle)
476
451
{
477
452
    m_useAngle = useAngle;
478
453
}
479
454
 
480
 
void KarbonCalligraphyTool::setCaps( double caps )
 
455
void KarbonCalligraphyTool::setCaps(double caps)
481
456
{
482
457
    m_caps = caps;
483
458
}
486
461
{
487
462
    KoPathShape *oldSelectedPath = m_selectedPath; // save old value
488
463
 
489
 
    KoSelection *selection = m_canvas->shapeManager()->selection();
 
464
    KoSelection *selection = canvas()->shapeManager()->selection();
490
465
 
491
466
    // null pointer if it the selection isn't a KoPathShape
492
467
    // or if the selection is empty
493
468
    m_selectedPath =
494
 
                dynamic_cast<KoPathShape *>( selection->firstSelectedShape() );
 
469
        dynamic_cast<KoPathShape *>(selection->firstSelectedShape());
495
470
 
496
471
    // or if it's a KoPathShape but with no or more than one subpaths
497
 
    if ( m_selectedPath && m_selectedPath->subpathCount() != 1 )
 
472
    if (m_selectedPath && m_selectedPath->subpathCount() != 1)
498
473
        m_selectedPath = 0;
499
474
 
500
475
    // or if there ora none or more than 1 shapes selected
501
 
    if ( selection->count() != 1 )
 
476
    if (selection->count() != 1)
502
477
        m_selectedPath = 0;
503
478
 
504
479
    // emit signal it there wasn't a selected path and now there is
505
480
    // or the other way around
506
 
    if ( (m_selectedPath != 0) != (oldSelectedPath != 0) )
507
 
        emit pathSelectedChanged( m_selectedPath != 0 );
 
481
    if ((m_selectedPath != 0) != (oldSelectedPath != 0))
 
482
        emit pathSelectedChanged(m_selectedPath != 0);
508
483
}