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

« back to all changes in this revision

Viewing changes to krita/ui/tool/kis_selection_tool_helper.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "canvas/kis_canvas2.h"
32
32
#include "kis_view2.h"
33
33
#include "kis_selection_manager.h"
34
 
#include "kis_selection_transaction.h"
 
34
#include "kis_transaction.h"
35
35
#include "commands/kis_selection_commands.h"
36
36
#include "kis_shape_controller.h"
37
37
 
52
52
{
53
53
}
54
54
 
55
 
QUndoCommand* KisSelectionToolHelper::selectPixelSelection(KisPixelSelectionSP selection, selectionAction action)
 
55
void KisSelectionToolHelper::selectPixelSelection(KisPixelSelectionSP selection, selectionAction action)
56
56
{
 
57
    KisUndoAdapter *undoAdapter = m_layer->image()->undoAdapter();
 
58
    undoAdapter->beginMacro(m_name);
 
59
 
57
60
    bool hasSelection = m_layer->selection();
58
61
 
59
 
    QUndoCommand* selectionCmd = new QUndoCommand(m_name);
60
 
 
61
62
    if (!hasSelection)
62
 
        new KisSetGlobalSelectionCommand(m_image, selectionCmd);
63
 
 
64
 
    new KisSelectionTransaction(m_name, m_image, m_layer->selection(), selectionCmd);
65
 
 
66
 
    KisPixelSelectionSP getOrCreatePixelSelection = m_layer->selection()->getOrCreatePixelSelection();
 
63
        undoAdapter->addCommand(new KisSetGlobalSelectionCommand(m_image));
 
64
 
 
65
    KisSelectionTransaction transaction(m_name, m_image, m_layer->selection());
 
66
 
 
67
    KisPixelSelectionSP pixelSelection = m_layer->selection()->getOrCreatePixelSelection();
67
68
 
68
69
    if (! hasSelection || action == SELECTION_REPLACE) {
69
 
        getOrCreatePixelSelection->clear();
 
70
        pixelSelection->clear();
70
71
        if (action == SELECTION_SUBTRACT)
71
 
            getOrCreatePixelSelection->invert();
 
72
            pixelSelection->invert();
72
73
    }
73
 
    getOrCreatePixelSelection->applySelection(selection, action);
 
74
    pixelSelection->applySelection(selection, action);
74
75
 
 
76
    QRect dirtyRect = m_image->bounds();
75
77
    if (hasSelection && action != SELECTION_REPLACE && action != SELECTION_INTERSECT) {
76
 
        QRect rc = selection->selectedRect();
77
 
        getOrCreatePixelSelection->setDirty(rc);
78
 
        m_layer->selection()->updateProjection(rc);
79
 
        m_canvas->view()->selectionManager()->selectionChanged();
80
 
    } else {
81
 
        getOrCreatePixelSelection->setDirty(m_image->bounds());
82
 
        m_layer->selection()->updateProjection(m_image->bounds());
83
 
        m_canvas->view()->selectionManager()->selectionChanged();
 
78
        dirtyRect = selection->selectedRect();
84
79
    }
85
 
    return selectionCmd;
 
80
    m_layer->selection()->updateProjection(dirtyRect);
 
81
 
 
82
    transaction.commit(undoAdapter);
 
83
    undoAdapter->endMacro();
 
84
 
 
85
    pixelSelection->setDirty(dirtyRect);
 
86
    m_canvas->view()->selectionManager()->selectionChanged();
86
87
}
87
88
 
88
89
void KisSelectionToolHelper::addSelectionShape(KoShape* shape)
89
90
{
90
 
    bool hasSelection = m_layer->selection();
91
 
 
92
 
    m_canvas->startMacro(m_name);
93
 
 
94
 
    if (!hasSelection)
95
 
        m_canvas->addCommand(new KisSetGlobalSelectionCommand(m_image, 0));
 
91
    /**
 
92
     * Mark a shape that it belongs to a shape selection
 
93
     */
 
94
    if(!shape->userData()) {
 
95
        shape->setUserData(new KisShapeSelectionMarker);
 
96
    }
 
97
 
 
98
    KisUndoAdapter *undoAdapter = m_layer->image()->undoAdapter();
 
99
    undoAdapter->beginMacro(m_name);
 
100
 
 
101
    if (!m_layer->selection()) {
 
102
        undoAdapter->addCommand(new KisSetGlobalSelectionCommand(m_image, 0));
 
103
    }
96
104
 
97
105
    KisSelectionSP selection = m_layer->selection();
98
 
 
99
 
    if (selection->isDeselected())
100
 
        new KisSelectionTransaction(m_name, m_image, m_layer->selection());
101
 
 
102
 
    KisShapeSelection* shapeSelection;
103
 
    if (!selection->hasShapeSelection()) {
104
 
        shapeSelection = new KisShapeSelection(m_image, selection);
105
 
        selection->setShapeSelection(shapeSelection);
106
 
    } else {
107
 
        shapeSelection = static_cast<KisShapeSelection*>(selection->shapeSelection());
108
 
    }
109
 
    KoShapeControllerBase* controller = m_canvas->view()->document()->shapeController();
110
 
    KisShapeController* kiscontroller = dynamic_cast<KisShapeController*>(controller);
111
 
    if (kiscontroller)
112
 
        kiscontroller->prepareAddingSelectionShape();
113
 
 
114
 
    QUndoCommand * cmd = m_canvas->shapeController()->addShape(shape);
115
 
    m_canvas->addCommand(cmd);
116
 
 
117
 
    m_canvas->stopMacro();
 
106
    KisSelectionTransaction transaction(m_name, m_image, selection);
 
107
 
 
108
    transaction.commit(undoAdapter);
 
109
 
 
110
    QUndoCommand *cmd = m_canvas->shapeController()->addShape(shape);
 
111
    undoAdapter->addCommand(cmd);
 
112
    undoAdapter->endMacro();
118
113
}
119
114