From kde-kimageshop Tue Jun 04 11:55:32 2013 From: Dmitry Kazakov Date: Tue, 04 Jun 2013 11:55:32 +0000 To: kde-kimageshop Subject: [calligra] krita: Added UI for converting a Pixel Selection into a Vector Selection Message-Id: <20130604115532.59FF3A6067 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-kimageshop&m=137034695311838 Git commit d605242fb18d0deee45829c03ad9ad46400d37b7 by Dmitry Kazakov. Committed on 04/06/2013 at 13:50. Pushed by dkazakov into branch 'master'. Added UI for converting a Pixel Selection into a Vector Selection Now you can click the menu and your selection will be converted into a vector one. After this action you can edit it with a shape editing tooleasily: rotate, scale, edid vertices. DRAWBACK: you lose information about semi-transparent pixels during this conversion! The backward conversion (vector->pixel) happens automatically when you start painting on a vector selection. CCMAIL:kimageshop@kde.org M +1 -1 krita/krita.rc M +35 -0 krita/ui/actions/kis_selection_action_factories.cpp M +5 -0 krita/ui/actions/kis_selection_action_factories.h M +2 -0 krita/ui/flake/kis_shape_selection.cpp M +3 -3 krita/ui/flake/kis_shape_selection_model.cpp M +1 -1 krita/ui/flake/kis_shape_selection_model.h M +10 -0 krita/ui/kis_selection_manager.cc M +1 -0 krita/ui/kis_selection_manager.h http://commits.kde.org/calligra/d605242fb18d0deee45829c03ad9ad46400d37b7 diff --git a/krita/krita.rc b/krita/krita.rc index 6f45ac3..387c9ef 100644 --- a/krita/krita.rc +++ b/krita/krita.rc @@ -123,7 +123,7 @@ - + diff --git a/krita/ui/actions/kis_selection_action_factories.cpp b/krita/ui/actions/kis_selection_action_factories.cpp index eb3dfa6..bf49d0a 100644 --- a/krita/ui/actions/kis_selection_action_factories.cpp +++ b/krita/ui/actions/kis_selection_action_factories.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include "kis_view2.h" #include "kis_canvas_resource_provider.h" @@ -44,6 +46,7 @@ #include "kis_selection_manager.h" #include "kis_transaction_based_command.h" #include "kis_selection_filters.h" +#include "kis_shape_selection.h" namespace ActionHelper { @@ -361,3 +364,35 @@ void KisInvertSelectionOperaton::runFromXML(KisView2* view, const KisOperationCo KisSelectionFilter* filter = new KisInvertSelectionFilter(); runFilter(filter, view, config); } + +void KisSelectionToVectorActionFactory::run(KisView2 *view) +{ + KisSelectionSP selection = view->selection(); + + if (selection->hasShapeSelection() || + !selection->outlineCacheValid()) { + + return; + } + + QPainterPath selectionOutline = selection->outlineCache(); + QTransform transform = view->canvasBase()->coordinatesConverter()->imageToDocumentTransform(); + + KoShape *shape = KoPathShape::createShapeFromPainterPath(transform.map(selectionOutline)); + shape->setShapeId(KoPathShapeId); + + /** + * Mark a shape that it belongs to a shape selection + */ + if(!shape->userData()) { + shape->setUserData(new KisShapeSelectionMarker); + } + + KisProcessingApplicator *ap = beginAction(view, i18n("Convert to Vector Selection")); + + ap->applyCommand(view->canvasBase()->shapeController()->addShape(shape), + KisStrokeJobData::SEQUENTIAL, + KisStrokeJobData::EXCLUSIVE); + + endAction(ap, KisOperationConfiguration(id()).toXML()); +} diff --git a/krita/ui/actions/kis_selection_action_factories.h b/krita/ui/actions/kis_selection_action_factories.h index afd5a1b..2ca04f8 100644 --- a/krita/ui/actions/kis_selection_action_factories.h +++ b/krita/ui/actions/kis_selection_action_factories.h @@ -103,4 +103,9 @@ struct KisInvertSelectionOperaton : public KisFilterSelectionOperation { void runFromXML(KisView2 *view, const KisOperationConfiguration &config); }; +struct KRITAUI_EXPORT KisSelectionToVectorActionFactory : public KisNoParameterActionFactory { + KisSelectionToVectorActionFactory() : KisNoParameterActionFactory("paste-new-ui-action") {} + void run(KisView2 *view); +}; + #endif /* __KIS_SELECTION_ACTION_FACTORIES_H */ diff --git a/krita/ui/flake/kis_shape_selection.cpp b/krita/ui/flake/kis_shape_selection.cpp index 24618f4..d825fef 100644 --- a/krita/ui/flake/kis_shape_selection.cpp +++ b/krita/ui/flake/kis_shape_selection.cpp @@ -77,6 +77,8 @@ KisShapeSelection::KisShapeSelection(KisImageWSP image, KisSelectionWSP selectio m_canvas = new KisShapeSelectionCanvas(); m_canvas->shapeManager()->addShape(this); + m_model->moveToThread(image->thread()); + m_canvas->moveToThread(image->thread()); } KisShapeSelection::~KisShapeSelection() diff --git a/krita/ui/flake/kis_shape_selection_model.cpp b/krita/ui/flake/kis_shape_selection_model.cpp index d0e7a3d..4c59ad0 100644 --- a/krita/ui/flake/kis_shape_selection_model.cpp +++ b/krita/ui/flake/kis_shape_selection_model.cpp @@ -32,10 +32,10 @@ KisShapeSelectionModel::KisShapeSelectionModel(KisImageWSP image, KisSelectionWS : m_image(image) , m_parentSelection(selection) , m_shapeSelection(shapeSelection) - , m_updateSignalCompressor(300, false) + , m_updateSignalCompressor(new KisSignalCompressor(300, false, this)) , m_updatesEnabled(true) { - connect(&m_updateSignalCompressor, SIGNAL(timeout()), SLOT(startUpdateJob())); + connect(m_updateSignalCompressor, SIGNAL(timeout()), SLOT(startUpdateJob())); } KisShapeSelectionModel::~KisShapeSelectionModel() @@ -50,7 +50,7 @@ void KisShapeSelectionModel::requestUpdate(const QRect &updateRect) if (m_updatesEnabled) { m_updateRect = !updateRect.isEmpty() ? m_updateRect | updateRect : QRect(); - m_updateSignalCompressor.start(); + m_updateSignalCompressor->start(); } } diff --git a/krita/ui/flake/kis_shape_selection_model.h b/krita/ui/flake/kis_shape_selection_model.h index 85b6503..05b8646 100644 --- a/krita/ui/flake/kis_shape_selection_model.h +++ b/krita/ui/flake/kis_shape_selection_model.h @@ -65,7 +65,7 @@ private: KisSelectionWSP m_parentSelection; KisShapeSelection* m_shapeSelection; - KisSignalCompressor m_updateSignalCompressor; + KisSignalCompressor *m_updateSignalCompressor; QRect m_updateRect; bool m_updatesEnabled; }; diff --git a/krita/ui/kis_selection_manager.cc b/krita/ui/kis_selection_manager.cc index e0b653e..4d0f955 100644 --- a/krita/ui/kis_selection_manager.cc +++ b/krita/ui/kis_selection_manager.cc @@ -220,6 +220,11 @@ void KisSelectionManager::setup(KActionCollection * collection, KisActionManager actionManager->addAction("resizeimagetoselection", m_imageResizeToSelection, collection); connect(m_imageResizeToSelection, SIGNAL(triggered()), this, SLOT(imageResizeToSelection())); + KisAction *action = new KisAction(i18n("Convert to Vector Selection"), this); + action->setActivationFlags(KisAction::PIXEL_SELECTION_WITH_PIXELS); + actionManager->addAction("convert_to_vector_selection", action, collection); + connect(action, SIGNAL(triggered()), SLOT(convertToVectorSelection())); + // m_load // = new KAction(i18n("Load..."), // 0, 0, @@ -390,6 +395,11 @@ void KisSelectionManager::reselect() factory.run(m_view); } +void KisSelectionManager::convertToVectorSelection() +{ + KisSelectionToVectorActionFactory factory; + factory.run(m_view); +} void KisSelectionManager::clear() { diff --git a/krita/ui/kis_selection_manager.h b/krita/ui/kis_selection_manager.h index e990e9a..6dd4ec7 100644 --- a/krita/ui/kis_selection_manager.h +++ b/krita/ui/kis_selection_manager.h @@ -83,6 +83,7 @@ public slots: void fillBackgroundColor(); void fillPattern(); void reselect(); + void convertToVectorSelection(); void copySelectionToNewLayer(); void toggleDisplaySelection(); _______________________________________________ Krita mailing list kimageshop@kde.org https://mail.kde.org/mailman/listinfo/kimageshop