[krita] /: Implement different types of Select Opaque action
Dmitry Kazakov
null at kde.org
Tue Aug 21 13:24:46 BST 2018
Git commit bb92265f455aff3a7d44fad2457f3ebfca6b49e9 by Dmitry Kazakov.
Committed on 21/08/2018 at 12:24.
Pushed by dkazakov into branch 'master'.
Implement different types of Select Opaque action
Now we have four different actions:
* Select Opaque --- replaces the current selection
* Select Opaque (Add) --- adds to the current selection
* Select Opaque (Subtract) --- Subtracts from the current selection
* Select Opaque (Intersect) --- Intersects with the current selection
BUG:346892
CC:kimageshop at kde.org
M +0 -12 krita/krita.action
M +8 -1 krita/krita4.xmlgui
M +36 -0 krita/kritamenu.action
M +1 -8 plugins/dockers/defaultdockers/kis_layer_box.cpp
M +0 -1 plugins/dockers/defaultdockers/kis_layer_box.h
M +51 -4 plugins/extensions/colorrange/colorrange.cc
M +7 -1 plugins/extensions/colorrange/colorrange.h
https://commits.kde.org/krita/bb92265f455aff3a7d44fad2457f3ebfca6b49e9
diff --git a/krita/krita.action b/krita/krita.action
index 5438902635d..ec99ee5e8bc 100644
--- a/krita/krita.action
+++ b/krita/krita.action
@@ -698,18 +698,6 @@
<isCheckable>false</isCheckable>
<statusTip></statusTip>
</Action>
- <Action name="select_opaque">
- <icon></icon>
- <text>&Select Opaque</text>
- <whatsThis></whatsThis>
- <toolTip>Select Opaque</toolTip>
- <iconText>Select Opaque</iconText>
- <activationFlags>100000</activationFlags>
- <activationConditions>100</activationConditions>
- <shortcut></shortcut>
- <isCheckable>false</isCheckable>
- <statusTip></statusTip>
- </Action>
<Action name="show-global-selection-mask">
<icon></icon>
<text>&Show Global Selection Mask</text>
diff --git a/krita/krita4.xmlgui b/krita/krita4.xmlgui
index 5cee8c5e523..bbf33693991 100644
--- a/krita/krita4.xmlgui
+++ b/krita/krita4.xmlgui
@@ -280,7 +280,14 @@ xsi:schemaLocation="http://www.kde.org/standards/kxmlgui/1.0 http://www.kde.org
<Action name="selectionscale"/>
<Separator/>
<Action name="colorrange"/>
- <Action name="selectopaque"/>
+ <Menu name="selectopaquemenu">
+ <text>Select &Opaque</text>
+ <Action name="selectopaque"/>
+ <Separator/>
+ <Action name="selectopaque_add"/>
+ <Action name="selectopaque_subtract"/>
+ <Action name="selectopaque_intersect"/>
+ </Menu>
<Separator/>
<Action name="featherselection"/>
<Action name="growselection"/>
diff --git a/krita/kritamenu.action b/krita/kritamenu.action
index 22e8e1e24da..41e94387543 100644
--- a/krita/kritamenu.action
+++ b/krita/kritamenu.action
@@ -1319,6 +1319,42 @@
<isCheckable>false</isCheckable>
<statusTip></statusTip>
</Action>
+ <Action name="selectopaque_add">
+ <icon></icon>
+ <text>Select Opaque (&Add)</text>
+ <whatsThis></whatsThis>
+ <toolTip>Select Opaque (Add)</toolTip>
+ <iconText>Select Opaque (Add)</iconText>
+ <activationFlags>10000</activationFlags>
+ <activationConditions>100</activationConditions>
+ <shortcut></shortcut>
+ <isCheckable>false</isCheckable>
+ <statusTip></statusTip>
+ </Action>
+ <Action name="selectopaque_subtract">
+ <icon></icon>
+ <text>Select Opaque (&Subtract)</text>
+ <whatsThis></whatsThis>
+ <toolTip>Select Opaque (Subtract)</toolTip>
+ <iconText>Select Opaque (Subtract)</iconText>
+ <activationFlags>10000</activationFlags>
+ <activationConditions>100</activationConditions>
+ <shortcut></shortcut>
+ <isCheckable>false</isCheckable>
+ <statusTip></statusTip>
+ </Action>
+ <Action name="selectopaque_intersect">
+ <icon></icon>
+ <text>Select Opaque (&Intersect)</text>
+ <whatsThis></whatsThis>
+ <toolTip>Select Opaque (Intersect)</toolTip>
+ <iconText>Select Opaque (Intersect)</iconText>
+ <activationFlags>10000</activationFlags>
+ <activationConditions>100</activationConditions>
+ <shortcut></shortcut>
+ <isCheckable>false</isCheckable>
+ <statusTip></statusTip>
+ </Action>
<Action name="growselection">
<icon></icon>
<text>&Grow Selection...</text>
diff --git a/plugins/dockers/defaultdockers/kis_layer_box.cpp b/plugins/dockers/defaultdockers/kis_layer_box.cpp
index 73339f829ca..5c7f23c00c9 100644
--- a/plugins/dockers/defaultdockers/kis_layer_box.cpp
+++ b/plugins/dockers/defaultdockers/kis_layer_box.cpp
@@ -201,13 +201,6 @@ KisLayerBox::KisLayerBox()
connect(m_wdgLayerBox->cmbComposite, SIGNAL(activated(int)), SLOT(slotCompositeOpChanged(int)));
- m_selectOpaque = new KisAction(i18n("&Select Opaque"), this);
- m_selectOpaque->setActivationFlags(KisAction::ACTIVE_LAYER);
- m_selectOpaque->setActivationConditions(KisAction::SELECTION_EDITABLE);
- m_selectOpaque->setObjectName("select_opaque");
- connect(m_selectOpaque, SIGNAL(triggered(bool)), this, SLOT(slotSelectOpaque()));
- m_actions.append(m_selectOpaque);
-
m_newLayerMenu = new QMenu(this);
m_wdgLayerBox->bnAdd->setMenu(m_newLayerMenu);
m_wdgLayerBox->bnAdd->setPopupMode(QToolButton::MenuButtonPopup);
@@ -675,7 +668,7 @@ void KisLayerBox::slotContextMenuRequested(const QPoint &pos, const QModelIndex
addActionToMenu(&menu, "isolate_layer");
}
- menu.addAction(m_selectOpaque);
+ addActionToMenu(&menu, "selectopaque");
}
}
menu.exec(pos);
diff --git a/plugins/dockers/defaultdockers/kis_layer_box.h b/plugins/dockers/defaultdockers/kis_layer_box.h
index 027345d39af..9cd1e51048d 100644
--- a/plugins/dockers/defaultdockers/kis_layer_box.h
+++ b/plugins/dockers/defaultdockers/kis_layer_box.h
@@ -160,7 +160,6 @@ private:
QVector<KisAction*> m_actions;
KisAction* m_removeAction;
KisAction* m_propertiesAction;
- KisAction* m_selectOpaque;
KisSignalCompressor m_thumbnailCompressor;
KisSignalCompressor m_colorLabelCompressor;
KisSignalCompressor m_thumbnailSizeCompressor;
diff --git a/plugins/extensions/colorrange/colorrange.cc b/plugins/extensions/colorrange/colorrange.cc
index a6393cbf59b..cbec33f7259 100644
--- a/plugins/extensions/colorrange/colorrange.cc
+++ b/plugins/extensions/colorrange/colorrange.cc
@@ -39,6 +39,7 @@
#include "dlg_colorrange.h"
#include <KoColorSpace.h>
+#include <QSignalMapper>
K_PLUGIN_FACTORY_WITH_JSON(ColorRangeFactory, "kritacolorrange.json", registerPlugin<ColorRange>();)
@@ -49,8 +50,25 @@ ColorRange::ColorRange(QObject *parent, const QVariantList &)
KisAction* action = createAction("colorrange");
connect(action, SIGNAL(triggered()), this, SLOT(slotActivated()));
+
+ QSignalMapper *mapper = new QSignalMapper(this);
+ connect(mapper, SIGNAL(mapped(int)), SLOT(selectOpaque(int)));
+
action = createAction("selectopaque");
- connect(action, SIGNAL(triggered()), this, SLOT(selectOpaque()));
+ mapper->setMapping(action, int(SELECTION_REPLACE));
+ connect(action, SIGNAL(triggered(bool)), mapper, SLOT(map()));
+
+ action = createAction("selectopaque_add");
+ mapper->setMapping(action, int(SELECTION_ADD));
+ connect(action, SIGNAL(triggered(bool)), mapper, SLOT(map()));
+
+ action = createAction("selectopaque_subtract");
+ mapper->setMapping(action, int(SELECTION_SUBTRACT));
+ connect(action, SIGNAL(triggered(bool)), mapper, SLOT(map()));
+
+ action = createAction("selectopaque_intersect");
+ mapper->setMapping(action, int(SELECTION_INTERSECT));
+ connect(action, SIGNAL(triggered(bool)), mapper, SLOT(map()));
}
ColorRange::~ColorRange()
@@ -65,7 +83,12 @@ void ColorRange::slotActivated()
dlgColorRange->exec();
}
-void ColorRange::selectOpaque()
+void ColorRange::selectOpaque(int id)
+{
+ selectOpaqueImpl(SelectionAction(id));
+}
+
+void ColorRange::selectOpaqueImpl(SelectionAction action)
{
KisCanvas2 *canvas = viewManager()->canvasBase();
KisPaintDeviceSP device = viewManager()->activeNode()->projection();
@@ -76,7 +99,31 @@ void ColorRange::selectOpaque()
QRect rc = device->exactBounds();
if (rc.isEmpty()) return;
- KisSelectionToolHelper helper(canvas, kundo2_i18n("Select Opaque"));
+ /**
+ * If there is nothing selected, just create a new selection
+ */
+ if (!canvas->imageView()->selection()) {
+ action = SELECTION_REPLACE;
+ }
+
+ KUndo2MagicString actionName;
+
+ switch (action) {
+ case SELECTION_ADD:
+ actionName = kundo2_i18n("Select Opaque (Add)");
+ break;
+ case SELECTION_SUBTRACT:
+ actionName = kundo2_i18n("Select Opaque (Subtract)");
+ break;
+ case SELECTION_INTERSECT:
+ actionName = kundo2_i18n("Select Opaque (Intersect)");
+ break;
+ default:
+ actionName = kundo2_i18n("Select Opaque");
+ break;
+ }
+
+ KisSelectionToolHelper helper(canvas, actionName);
qint32 x, y, w, h;
rc.getRect(&x, &y, &w, &h);
@@ -96,7 +143,7 @@ void ColorRange::selectOpaque()
}
tmpSel->invalidateOutlineCache();
- helper.selectPixelSelection(tmpSel, SELECTION_ADD);
+ helper.selectPixelSelection(tmpSel, action);
}
#include "colorrange.moc"
diff --git a/plugins/extensions/colorrange/colorrange.h b/plugins/extensions/colorrange/colorrange.h
index 878a355b3d8..e373ef0fa0e 100644
--- a/plugins/extensions/colorrange/colorrange.h
+++ b/plugins/extensions/colorrange/colorrange.h
@@ -25,6 +25,9 @@
#include <KisActionPlugin.h>
+#include "kis_selection.h"
+
+
class ColorRange : public KisActionPlugin
{
Q_OBJECT
@@ -34,7 +37,10 @@ public:
private Q_SLOTS:
void slotActivated();
- void selectOpaque();
+ void selectOpaque(int id);
+
+private:
+ void selectOpaqueImpl(SelectionAction action);
};
#endif // COLORRANGE_H
More information about the kimageshop
mailing list