void KisSelectionToolHelper::addSelectionShape(KoShape* shape) { KisView2* view = m_canvas->view(); /** * Mark a shape that it belongs to a shape selection */ if(!shape->userData()) { shape->setUserData(new KisShapeSelectionMarker); } KisUndoAdapter *undoAdapter = view->image()->undoAdapter(); undoAdapter->beginMacro(m_name); if (!view->selection()) { undoAdapter->addCommand(new KisSetEmptyGlobalSelectionCommand(m_image)); } KisSelectionSP selection = view->selection(); KisSelectionTransaction transaction(m_name, m_image->undoAdapter(), selection); transaction.commit(undoAdapter); KUndo2Command *cmd = m_canvas->shapeController()->addShape(shape); undoAdapter->addCommand(cmd); undoAdapter->endMacro(); }
void KisSelectionToolHelper::selectPixelSelection(KisPixelSelectionSP selection, SelectionAction action) { KisView2* view = m_canvas->view(); if (selection->selectedRect().isEmpty()) { m_canvas->view()->selectionManager()->deselect(); return; } KisUndoAdapter *undoAdapter = view->image()->undoAdapter(); undoAdapter->beginMacro(m_name); bool hasSelection = view->selection(); if (!hasSelection) { undoAdapter->addCommand(new KisSetEmptyGlobalSelectionCommand(m_image)); } KisSelectionTransaction transaction(m_name, m_image->undoAdapter(), view->selection()); KisPixelSelectionSP pixelSelection = view->selection()->getOrCreatePixelSelection(); if (!hasSelection && action == SELECTION_SUBTRACT) { pixelSelection->invert(); } pixelSelection->applySelection(selection, action); QRect dirtyRect = m_image->bounds(); if (hasSelection && action != SELECTION_REPLACE && action != SELECTION_INTERSECT) { dirtyRect = selection->selectedRect(); } view->selection()->updateProjection(dirtyRect); transaction.commit(undoAdapter); undoAdapter->endMacro(); pixelSelection->setDirty(dirtyRect); m_canvas->view()->selectionManager()->selectionChanged(); }