From kde-kimageshop Tue Sep 04 09:40:36 2018 From: Dmitry Kazakov Date: Tue, 04 Sep 2018 09:40:36 +0000 To: kde-kimageshop Subject: [krita] /: FEATURE: Convert to Raster/Vector Selection menu actions Message-Id: X-MARC-Message: https://marc.info/?l=kde-kimageshop&m=153605406422081 Git commit 6018f2bb123444cfc8f86a3e1e50acca5203abc4 by Dmitry Kazakov. Committed on 04/09/2018 at 09:39. Pushed by dkazakov into branch 'master'. FEATURE: Convert to Raster/Vector Selection menu actions Now the menu has two actions: Convert to Raster and Convert to Vector selection. Previously, there was only the latter one present. These actions are also now available in the context menu in the selection tools. CC:kimageshop@kde.org Ref T9486 M +1 -0 krita/krita4.xmlgui M +13 -1 krita/kritamenu.action M +34 -0 libs/ui/actions/kis_selection_action_factories.cpp M +7 -2 libs/ui/actions/kis_selection_action_factories.h M +5 -3 libs/ui/kis_action.h M +11 -3 libs/ui/kis_action_manager.cpp M +23 -5 libs/ui/kis_selection_manager.cc M +4 -1 libs/ui/kis_selection_manager.h M +18 -10 libs/ui/tool/kis_selection_tool_helper.cpp https://commits.kde.org/krita/6018f2bb123444cfc8f86a3e1e50acca5203abc4 diff --git a/krita/krita4.xmlgui b/krita/krita4.xmlgui index bbf33693991..020d78ddb57 100644 --- a/krita/krita4.xmlgui +++ b/krita/krita4.xmlgui @@ -269,6 +269,7 @@ xsi:schemaLocation=3D"http://www.kde.org/standards/kxml= gui/1.0 http://www.kde.org + diff --git a/krita/kritamenu.action b/krita/kritamenu.action index cdfdfa9470b..3b2fce8b2ed 100644 --- a/krita/kritamenu.action +++ b/krita/kritamenu.action @@ -1241,7 +1241,19 @@ Convert to Vector Selection Convert to Vector Selection - 10000000000 + 100000000000000000 + 0 + + false + + + + + &Convert to Raster Selection + + Convert to Raster Selection + Convert to Raster Selection + 10000000000000000 0 false diff --git a/libs/ui/actions/kis_selection_action_factories.cpp b/libs/ui/a= ctions/kis_selection_action_factories.cpp index 5bf61127e78..5a0b4bb13b3 100644 --- a/libs/ui/actions/kis_selection_action_factories.cpp +++ b/libs/ui/actions/kis_selection_action_factories.cpp @@ -465,6 +465,40 @@ void KisSelectionToVectorActionFactory::run(KisViewMan= ager *view) endAction(ap, KisOperationConfiguration(id()).toXML()); } = +void KisSelectionToRasterActionFactory::run(KisViewManager *view) +{ + KisSelectionSP selection =3D view->selection(); + + if (!selection->hasShapeSelection()) { + view->showFloatingMessage(i18nc("floating message", + "Selection is already in a raster = format "), + QIcon(), 2000, KisFloatingMessage::Low); + return; + } + + KisProcessingApplicator *ap =3D beginAction(view, kundo2_i18n("Convert= to Vector Selection")); + + struct RasterizeSelection : public KisTransactionBasedCommand { + RasterizeSelection(KisSelectionSP sel) + : m_sel(sel) {} + KisSelectionSP m_sel; + + KUndo2Command* paint() override { + // just create an empty transaction: it will rasterize the + // selection and emit the necessary signals + + KisTransaction transaction(m_sel->pixelSelection()); + return transaction.endAndTake(); + } + }; + + ap->applyCommand(new RasterizeSelection(selection), + KisStrokeJobData::SEQUENTIAL, + KisStrokeJobData::EXCLUSIVE); + + endAction(ap, KisOperationConfiguration(id()).toXML()); +} + void KisShapesToVectorSelectionActionFactory::run(KisViewManager* view) { const QList originalShapes =3D view->canvasBase()->shapeMana= ger()->selection()->selectedShapes(); diff --git a/libs/ui/actions/kis_selection_action_factories.h b/libs/ui/act= ions/kis_selection_action_factories.h index adfe7dcbac8..8fe9e3d39bc 100644 --- a/libs/ui/actions/kis_selection_action_factories.h +++ b/libs/ui/actions/kis_selection_action_factories.h @@ -100,12 +100,17 @@ struct KisInvertSelectionOperation : public KisFilter= SelectionOperation { }; = struct KRITAUI_EXPORT KisSelectionToVectorActionFactory : public KisNoPara= meterActionFactory { - KisSelectionToVectorActionFactory() : KisNoParameterActionFactory("pas= te-new-ui-action") {} + KisSelectionToVectorActionFactory() : KisNoParameterActionFactory("sel= ection-to-vector") {} + void run(KisViewManager *view) override; +}; + +struct KRITAUI_EXPORT KisSelectionToRasterActionFactory : public KisNoPara= meterActionFactory { + KisSelectionToRasterActionFactory() : KisNoParameterActionFactory("sel= ection-to-raster") {} void run(KisViewManager *view) override; }; = struct KRITAUI_EXPORT KisShapesToVectorSelectionActionFactory : public Kis= NoParameterActionFactory { - KisShapesToVectorSelectionActionFactory() : KisNoParameterActionFactor= y("paste-new-ui-action") {} + KisShapesToVectorSelectionActionFactory() : KisNoParameterActionFactor= y("shapes-to-vector-selection") {} void run(KisViewManager *view) override; }; = diff --git a/libs/ui/kis_action.h b/libs/ui/kis_action.h index 623fd713e8a..8777a09e8b3 100644 --- a/libs/ui/kis_action.h +++ b/libs/ui/kis_action.h @@ -60,14 +60,16 @@ public: ACTIVE_LAYER =3D 0x0020, ///< Activate if the curre= nt node is a layer (vector or pixel) ACTIVE_TRANSPARENCY_MASK =3D 0x0040, ///< Activate if the curre= nt node is a transparency mask ACTIVE_SHAPE_LAYER =3D 0x0080, ///< Activate if the curre= nt node is a vector layer - PIXELS_SELECTED =3D 0x0100, ///< Activate if there is = an active pixel selection - SHAPES_SELECTED =3D 0x0200, ///< Activate if there is = an active vector selection - PIXEL_SELECTION_WITH_PIXELS =3D 0x0400, ///< ??? + PIXELS_SELECTED =3D 0x0100, ///< Activate if any pixel= s are selcted (with any kind of selection) + SHAPES_SELECTED =3D 0x0200, ///< Activate if any vecto= r shape is selected + ANY_SELECTION_WITH_PIXELS =3D 0x0400, ///< ??? PIXELS_IN_CLIPBOARD =3D 0x0800, ///< Activate if the clipb= oard contains pixels SHAPES_IN_CLIPBOARD =3D 0x1000, ///< Activate if the clipb= oard contains vector data NEVER_ACTIVATE =3D 0x2000, ///< ??? LAYERS_IN_CLIPBOARD =3D 0x4000, ///< ??? IMAGE_HAS_ANIMATION =3D 0x8000, ///< Activate if the image= has an animation + SHAPE_SELECTION_WITH_SHAPES =3D 0x10000, ///< Activate there is a = vector selection active + PIXEL_SELECTION_WITH_PIXELS =3D 0x20000, ///< Activate there is a = raster selection active }; Q_DECLARE_FLAGS(ActivationFlags, ActivationFlag) = diff --git a/libs/ui/kis_action_manager.cpp b/libs/ui/kis_action_manager.cpp index b6aea8507b5..3ad124c55ac 100644 --- a/libs/ui/kis_action_manager.cpp +++ b/libs/ui/kis_action_manager.cpp @@ -275,7 +275,15 @@ void KisActionManager::updateGUI() flags |=3D KisAction::SHAPES_SELECTED; } = - if (selectionManager->havePixelSelectionWithPixels()) { + if (selectionManager->haveAnySelectionWithPixels()) { + flags |=3D KisAction::ANY_SELECTION_WITH_PIXELS; + } + + if (selectionManager->haveShapeSelectionWithShapes()) { + flags |=3D KisAction::SHAPE_SELECTION_WITH_SHAPES; + } + + if (selectionManager->haveRasterSelectionWithPixels()) { flags |=3D KisAction::PIXEL_SELECTION_WITH_PIXELS; } = @@ -449,8 +457,8 @@ void KisActionManager::dumpActionFlags() if (flags & KisAction::SHAPES_SELECTED) { out << " Shapes selected\n"; } - if (flags & KisAction::PIXEL_SELECTION_WITH_PIXELS) { - out << " Pixel selection with pixels\n"; + if (flags & KisAction::ANY_SELECTION_WITH_PIXELS) { + out << " Any selection with pixels\n"; } if (flags & KisAction::PIXELS_IN_CLIPBOARD) { out << " Pixels in clipboard\n"; diff --git a/libs/ui/kis_selection_manager.cc b/libs/ui/kis_selection_manag= er.cc index b7ff5766631..ab79dacfe5a 100644 --- a/libs/ui/kis_selection_manager.cc +++ b/libs/ui/kis_selection_manager.cc @@ -198,6 +198,9 @@ void KisSelectionManager::setup(KisActionManager* actio= nManager) action =3D actionManager->createAction("convert_to_vector_selection"); connect(action, SIGNAL(triggered()), SLOT(convertToVectorSelection())); = + action =3D actionManager->createAction("convert_to_raster_selection"); + connect(action, SIGNAL(triggered()), SLOT(convertToRasterSelection())); + action =3D actionManager->createAction("convert_shapes_to_vector_selec= tion"); connect(action, SIGNAL(triggered()), SLOT(convertShapesToVectorSelecti= on())); = @@ -279,13 +282,22 @@ bool KisSelectionManager::haveShapesInClipboard() return paste.hasShapes(); } = -bool KisSelectionManager::havePixelSelectionWithPixels() +bool KisSelectionManager::haveAnySelectionWithPixels() { KisSelectionSP selection =3D m_view->selection(); - if (selection && selection->hasPixelSelection()) { - return !selection->pixelSelection()->selectedRect().isEmpty(); - } - return false; + return selection && selection->hasPixelSelection(); +} + +bool KisSelectionManager::haveShapeSelectionWithShapes() +{ + KisSelectionSP selection =3D m_view->selection(); + return selection && selection->hasShapeSelection(); +} + +bool KisSelectionManager::haveRasterSelectionWithPixels() +{ + KisSelectionSP selection =3D m_view->selection(); + return selection && selection->hasPixelSelection() && !selection->hasS= hapeSelection(); } = void KisSelectionManager::updateGUI() @@ -415,6 +427,12 @@ void KisSelectionManager::convertToVectorSelection() factory.run(m_view); } = +void KisSelectionManager::convertToRasterSelection() +{ + KisSelectionToRasterActionFactory factory; + factory.run(m_view); +} + void KisSelectionManager::convertShapesToVectorSelection() { KisShapesToVectorSelectionActionFactory factory; diff --git a/libs/ui/kis_selection_manager.h b/libs/ui/kis_selection_manage= r.h index bd165eb9522..3aaa4f45099 100644 --- a/libs/ui/kis_selection_manager.h +++ b/libs/ui/kis_selection_manager.h @@ -98,6 +98,7 @@ public Q_SLOTS: void fillPatternOpacity(); void reselect(); void convertToVectorSelection(); + void convertToRasterSelection(); void convertShapesToVectorSelection(); void convertToShape(); = @@ -127,7 +128,9 @@ public: bool haveShapesInClipboard(); = /// Checks if the current selection is editable and has some pixels se= lected in the pixel selection - bool havePixelSelectionWithPixels(); + bool haveAnySelectionWithPixels(); + bool haveShapeSelectionWithShapes(); + bool haveRasterSelectionWithPixels(); = private: void fill(const KoColor& color, bool fillWithPattern, const QString& t= ransactionText); diff --git a/libs/ui/tool/kis_selection_tool_helper.cpp b/libs/ui/tool/kis_= selection_tool_helper.cpp index dab79c1e49c..6133454f5ec 100644 --- a/libs/ui/tool/kis_selection_tool_helper.cpp +++ b/libs/ui/tool/kis_selection_tool_helper.cpp @@ -296,7 +296,6 @@ QMenu* KisSelectionToolHelper::getSelectionContextMenu(= KisCanvas2* canvas) = KisActionManager * actionMan =3D canvas->viewManager()->actionManager(= ); = - m_contextMenu->addAction(actionMan->actionByName("deselect")); m_contextMenu->addAction(actionMan->actionByName("invert")); m_contextMenu->addAction(actionMan->actionByName("select_all")); @@ -308,16 +307,25 @@ QMenu* KisSelectionToolHelper::getSelectionContextMen= u(KisCanvas2* canvas) = m_contextMenu->addSeparator(); = - QMenu *transformMenu =3D m_contextMenu->addMenu(i18n("Transform")); - transformMenu->addAction(actionMan->actionByName("selectionscale")); - transformMenu->addAction(actionMan->actionByName("growselection")); - transformMenu->addAction(actionMan->actionByName("shrinkselection")); - transformMenu->addAction(actionMan->actionByName("borderselection")); - transformMenu->addAction(actionMan->actionByName("smoothselection")); - transformMenu->addAction(actionMan->actionByName("featherselection")); - transformMenu->addAction(actionMan->actionByName("stroke_selection")); + KisSelectionSP selection =3D canvas->viewManager()->selection(); + if (selection && canvas->viewManager()->selectionEditable()) { + if (!selection->hasShapeSelection()) { + m_contextMenu->addAction(actionMan->actionByName("convert_to_v= ector_selection")); + } else { + m_contextMenu->addAction(actionMan->actionByName("convert_to_r= aster_selection")); + } = - m_contextMenu->addSeparator(); + QMenu *transformMenu =3D m_contextMenu->addMenu(i18n("Transform")); + transformMenu->addAction(actionMan->actionByName("selectionscale")= ); + transformMenu->addAction(actionMan->actionByName("growselection")); + transformMenu->addAction(actionMan->actionByName("shrinkselection"= )); + transformMenu->addAction(actionMan->actionByName("borderselection"= )); + transformMenu->addAction(actionMan->actionByName("smoothselection"= )); + transformMenu->addAction(actionMan->actionByName("featherselection= ")); + transformMenu->addAction(actionMan->actionByName("stroke_selection= ")); + + m_contextMenu->addSeparator(); + } = m_contextMenu->addAction(actionMan->actionByName("resizeimagetoselecti= on")); =20