From kde-kimageshop Tue Aug 21 12:24:46 2018 From: Dmitry Kazakov Date: Tue, 21 Aug 2018 12:24:46 +0000 To: kde-kimageshop Subject: [krita] /: Implement different types of Select Opaque action Message-Id: X-MARC-Message: https://marc.info/?l=kde-kimageshop&m=153485430425647 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@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 @@ false - - - &Select Opaque - - Select Opaque - Select Opaque - 100000 - 100 - - false - - &Show Global Selection Mask 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=3D"http://www.kde.org/standards/kxm= lgui/1.0 http://www.kde.org - + + Select &Opaque + + + + + + 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 @@ false + + + Select Opaque (&Add) + + Select Opaque (Add) + Select Opaque (Add) + 10000 + 100 + + false + + + + + Select Opaque (&Subtract) + + Select Opaque (Subtract) + Select Opaque (Subtract) + 10000 + 100 + + false + + + + + Select Opaque (&Intersect) + + Select Opaque (Intersect) + Select Opaque (Intersect) + 10000 + 100 + + false + + &Grow Selection... diff --git a/plugins/dockers/defaultdockers/kis_layer_box.cpp b/plugins/doc= kers/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(slot= CompositeOpChanged(int))); = - m_selectOpaque =3D 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(slotSelect= Opaque())); - m_actions.append(m_selectOpaque); - m_newLayerMenu =3D 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/docke= rs/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 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/extensio= ns/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 +#include = K_PLUGIN_FACTORY_WITH_JSON(ColorRangeFactory, "kritacolorrange.json", regi= sterPlugin();) = @@ -49,8 +50,25 @@ ColorRange::ColorRange(QObject *parent, const QVariantLi= st &) KisAction* action =3D createAction("colorrange"); connect(action, SIGNAL(triggered()), this, SLOT(slotActivated())); = + + QSignalMapper *mapper =3D new QSignalMapper(this); + connect(mapper, SIGNAL(mapped(int)), SLOT(selectOpaque(int))); + action =3D createAction("selectopaque"); - connect(action, SIGNAL(triggered()), this, SLOT(selectOpaque())); + mapper->setMapping(action, int(SELECTION_REPLACE)); + connect(action, SIGNAL(triggered(bool)), mapper, SLOT(map())); + + action =3D createAction("selectopaque_add"); + mapper->setMapping(action, int(SELECTION_ADD)); + connect(action, SIGNAL(triggered(bool)), mapper, SLOT(map())); + + action =3D createAction("selectopaque_subtract"); + mapper->setMapping(action, int(SELECTION_SUBTRACT)); + connect(action, SIGNAL(triggered(bool)), mapper, SLOT(map())); + + action =3D 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 =3D viewManager()->canvasBase(); KisPaintDeviceSP device =3D viewManager()->activeNode()->projection(); @@ -76,7 +99,31 @@ void ColorRange::selectOpaque() QRect rc =3D 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 =3D SELECTION_REPLACE; + } + + KUndo2MagicString actionName; + + switch (action) { + case SELECTION_ADD: + actionName =3D kundo2_i18n("Select Opaque (Add)"); + break; + case SELECTION_SUBTRACT: + actionName =3D kundo2_i18n("Select Opaque (Subtract)"); + break; + case SELECTION_INTERSECT: + actionName =3D kundo2_i18n("Select Opaque (Intersect)"); + break; + default: + actionName =3D 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/extension= s/colorrange/colorrange.h index 878a355b3d8..e373ef0fa0e 100644 --- a/plugins/extensions/colorrange/colorrange.h +++ b/plugins/extensions/colorrange/colorrange.h @@ -25,6 +25,9 @@ = #include = +#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