~ubuntu-branches/ubuntu/saucy/koffice/saucy

« back to all changes in this revision

Viewing changes to krita/ui/flake/kis_shape_selection.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-12-06 15:30:09 UTC
  • mfrom: (0.13.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101206153009-yf0dqbp9l7fzwxi8
Tags: 1:2.2.91-0ubuntu1
New upstream RC release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (c) 2007 Sven Langkamp <sven.langkamp@gmail.com>
 
2
 *  Copyright (c) 2010 Sven Langkamp <sven.langkamp@gmail.com>
3
3
 *
4
4
 *  This program is free software; you can redistribute it and/or modify
5
5
 *  it under the terms of the GNU General Public License as published by
21
21
 
22
22
#include <QPainter>
23
23
#include <QTimer>
 
24
#include <QUndoCommand>
24
25
 
25
26
#include <ktemporaryfile.h>
26
27
 
44
45
#include <KoShapeController.h>
45
46
#include <KoShapeSavingContext.h>
46
47
#include <KoStoreDevice.h>
47
 
 
 
48
#include <KoShapeTransformCommand.h>
48
49
 
49
50
#include "kis_painter.h"
50
51
#include "kis_paint_device.h"
53
54
#include "kis_selection.h"
54
55
#include "kis_shape_selection_canvas.h"
55
56
#include "kis_shape_layer_paste.h"
 
57
#include "kis_image_view_converter.h"
56
58
 
57
59
#include <kis_debug.h>
58
60
 
64
66
    setShapeId("KisShapeSelection");
65
67
    setSelectable(false);
66
68
    m_dirty = false;
 
69
    m_converter = new KisImageViewConverter(image);
67
70
    m_canvas = new KisShapeSelectionCanvas();
68
71
    m_canvas->shapeManager()->addShape(this);
69
72
 
73
76
{
74
77
    m_model->setShapeSelection(0);
75
78
    delete m_canvas;
 
79
    delete m_converter;
76
80
}
77
81
 
78
82
KisShapeSelection::KisShapeSelection(const KisShapeSelection& rhs, KisSelection* selection)
80
84
{
81
85
    m_dirty = rhs.m_dirty;
82
86
    m_image = rhs.m_image;
 
87
    m_converter = new KisImageViewConverter(m_image);
83
88
    m_canvas = new KisShapeSelectionCanvas();
84
89
    m_canvas->shapeManager()->addShape(this);
85
90
 
399
404
    }
400
405
}
401
406
 
 
407
// TODO same code as in shape layer, refactor!
 
408
QUndoCommand* KisShapeSelection::transform(double  xscale, double  yscale, double  xshear, double  yshear, double angle, qint32  translatex, qint32  translatey) {
 
409
 
 
410
    Q_UNUSED(xshear);
 
411
    Q_UNUSED(yshear);
 
412
    QPointF transF =  m_converter->viewToDocument(QPoint(translatex, translatey));
 
413
    QList<KoShape*> shapes = m_canvas->shapeManager()->shapes();
 
414
    if(shapes.isEmpty())
 
415
        return 0;
 
416
 
 
417
    QTransform matrix;
 
418
    matrix.translate(transF.x(), transF.y());
 
419
    matrix.scale(xscale,yscale);
 
420
    matrix.rotate(angle*180/M_PI);
 
421
 
 
422
    QList<QTransform> oldTransformations;
 
423
    QList<QTransform> newTransformations;
 
424
 
 
425
    // this code won't work if there are shapes, that inherit the transformation from the parent container.
 
426
    // the chart and tree shapes are examples for that, but they aren't used in krita and there are no other shapes like that.
 
427
    foreach(const KoShape* shape, shapes) {
 
428
        QTransform oldTransform = shape->transformation();
 
429
        oldTransformations.append(oldTransform);
 
430
 
 
431
 
 
432
        newTransformations.append(oldTransform*matrix);
 
433
    }
 
434
 
 
435
    return new KoShapeTransformCommand(shapes, oldTransformations, newTransformations);
 
436
}
 
437
 
402
438
 
403
439
#include "kis_shape_selection.moc"