[krita] /: FEATURE: Convert to Raster/Vector Selection menu actions
Dmitry Kazakov
null at kde.org
Tue Sep 4 10:40:36 BST 2018
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 at 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="http://www.kde.org/standards/kxmlgui/1.0 http://www.kde.org
<Action name="reselect"/>
<Action name="invert_selection"/>
<Action name="convert_to_vector_selection"/>
+ <Action name="convert_to_raster_selection"/>
<Action name="convert_shapes_to_vector_selection"/>
<Action name="convert_selection_to_shape"/>
<Separator/>
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 @@
<whatsThis></whatsThis>
<toolTip>Convert to Vector Selection</toolTip>
<iconText>Convert to Vector Selection</iconText>
- <activationFlags>10000000000</activationFlags>
+ <activationFlags>100000000000000000</activationFlags>
+ <activationConditions>0</activationConditions>
+ <shortcut></shortcut>
+ <isCheckable>false</isCheckable>
+ <statusTip></statusTip>
+ </Action>
+ <Action name="convert_to_raster_selection">
+ <icon></icon>
+ <text>&Convert to Raster Selection</text>
+ <whatsThis></whatsThis>
+ <toolTip>Convert to Raster Selection</toolTip>
+ <iconText>Convert to Raster Selection</iconText>
+ <activationFlags>10000000000000000</activationFlags>
<activationConditions>0</activationConditions>
<shortcut></shortcut>
<isCheckable>false</isCheckable>
diff --git a/libs/ui/actions/kis_selection_action_factories.cpp b/libs/ui/actions/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(KisViewManager *view)
endAction(ap, KisOperationConfiguration(id()).toXML());
}
+void KisSelectionToRasterActionFactory::run(KisViewManager *view)
+{
+ KisSelectionSP selection = view->selection();
+
+ if (!selection->hasShapeSelection()) {
+ view->showFloatingMessage(i18nc("floating message",
+ "Selection is already in a raster format "),
+ QIcon(), 2000, KisFloatingMessage::Low);
+ return;
+ }
+
+ KisProcessingApplicator *ap = 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<KoShape*> originalShapes = view->canvasBase()->shapeManager()->selection()->selectedShapes();
diff --git a/libs/ui/actions/kis_selection_action_factories.h b/libs/ui/actions/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 KisFilterSelectionOperation {
};
struct KRITAUI_EXPORT KisSelectionToVectorActionFactory : public KisNoParameterActionFactory {
- KisSelectionToVectorActionFactory() : KisNoParameterActionFactory("paste-new-ui-action") {}
+ KisSelectionToVectorActionFactory() : KisNoParameterActionFactory("selection-to-vector") {}
+ void run(KisViewManager *view) override;
+};
+
+struct KRITAUI_EXPORT KisSelectionToRasterActionFactory : public KisNoParameterActionFactory {
+ KisSelectionToRasterActionFactory() : KisNoParameterActionFactory("selection-to-raster") {}
void run(KisViewManager *view) override;
};
struct KRITAUI_EXPORT KisShapesToVectorSelectionActionFactory : public KisNoParameterActionFactory {
- KisShapesToVectorSelectionActionFactory() : KisNoParameterActionFactory("paste-new-ui-action") {}
+ KisShapesToVectorSelectionActionFactory() : KisNoParameterActionFactory("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 = 0x0020, ///< Activate if the current node is a layer (vector or pixel)
ACTIVE_TRANSPARENCY_MASK = 0x0040, ///< Activate if the current node is a transparency mask
ACTIVE_SHAPE_LAYER = 0x0080, ///< Activate if the current node is a vector layer
- PIXELS_SELECTED = 0x0100, ///< Activate if there is an active pixel selection
- SHAPES_SELECTED = 0x0200, ///< Activate if there is an active vector selection
- PIXEL_SELECTION_WITH_PIXELS = 0x0400, ///< ???
+ PIXELS_SELECTED = 0x0100, ///< Activate if any pixels are selcted (with any kind of selection)
+ SHAPES_SELECTED = 0x0200, ///< Activate if any vector shape is selected
+ ANY_SELECTION_WITH_PIXELS = 0x0400, ///< ???
PIXELS_IN_CLIPBOARD = 0x0800, ///< Activate if the clipboard contains pixels
SHAPES_IN_CLIPBOARD = 0x1000, ///< Activate if the clipboard contains vector data
NEVER_ACTIVATE = 0x2000, ///< ???
LAYERS_IN_CLIPBOARD = 0x4000, ///< ???
IMAGE_HAS_ANIMATION = 0x8000, ///< Activate if the image has an animation
+ SHAPE_SELECTION_WITH_SHAPES = 0x10000, ///< Activate there is a vector selection active
+ PIXEL_SELECTION_WITH_PIXELS = 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 |= KisAction::SHAPES_SELECTED;
}
- if (selectionManager->havePixelSelectionWithPixels()) {
+ if (selectionManager->haveAnySelectionWithPixels()) {
+ flags |= KisAction::ANY_SELECTION_WITH_PIXELS;
+ }
+
+ if (selectionManager->haveShapeSelectionWithShapes()) {
+ flags |= KisAction::SHAPE_SELECTION_WITH_SHAPES;
+ }
+
+ if (selectionManager->haveRasterSelectionWithPixels()) {
flags |= 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_manager.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* actionManager)
action = actionManager->createAction("convert_to_vector_selection");
connect(action, SIGNAL(triggered()), SLOT(convertToVectorSelection()));
+ action = actionManager->createAction("convert_to_raster_selection");
+ connect(action, SIGNAL(triggered()), SLOT(convertToRasterSelection()));
+
action = actionManager->createAction("convert_shapes_to_vector_selection");
connect(action, SIGNAL(triggered()), SLOT(convertShapesToVectorSelection()));
@@ -279,13 +282,22 @@ bool KisSelectionManager::haveShapesInClipboard()
return paste.hasShapes();
}
-bool KisSelectionManager::havePixelSelectionWithPixels()
+bool KisSelectionManager::haveAnySelectionWithPixels()
{
KisSelectionSP selection = m_view->selection();
- if (selection && selection->hasPixelSelection()) {
- return !selection->pixelSelection()->selectedRect().isEmpty();
- }
- return false;
+ return selection && selection->hasPixelSelection();
+}
+
+bool KisSelectionManager::haveShapeSelectionWithShapes()
+{
+ KisSelectionSP selection = m_view->selection();
+ return selection && selection->hasShapeSelection();
+}
+
+bool KisSelectionManager::haveRasterSelectionWithPixels()
+{
+ KisSelectionSP selection = m_view->selection();
+ return selection && selection->hasPixelSelection() && !selection->hasShapeSelection();
}
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_manager.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 selected in the pixel selection
- bool havePixelSelectionWithPixels();
+ bool haveAnySelectionWithPixels();
+ bool haveShapeSelectionWithShapes();
+ bool haveRasterSelectionWithPixels();
private:
void fill(const KoColor& color, bool fillWithPattern, const QString& transactionText);
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 = 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::getSelectionContextMenu(KisCanvas2* canvas)
m_contextMenu->addSeparator();
- QMenu *transformMenu = 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 = canvas->viewManager()->selection();
+ if (selection && canvas->viewManager()->selectionEditable()) {
+ if (!selection->hasShapeSelection()) {
+ m_contextMenu->addAction(actionMan->actionByName("convert_to_vector_selection"));
+ } else {
+ m_contextMenu->addAction(actionMan->actionByName("convert_to_raster_selection"));
+ }
- m_contextMenu->addSeparator();
+ QMenu *transformMenu = 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("resizeimagetoselection"));
More information about the kimageshop
mailing list