diff --git a/krita/krita.xmlgui b/krita/krita.xmlgui --- a/krita/krita.xmlgui +++ b/krita/krita.xmlgui @@ -52,6 +52,7 @@ + diff --git a/krita/kritamenu.action b/krita/kritamenu.action --- a/krita/kritamenu.action +++ b/krita/kritamenu.action @@ -426,6 +426,18 @@ false + + + Stroke selec&tion + + Stroke selection + Stroke selection + 10000000000 + 0 + + false + + Delete keyframe diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt --- a/libs/ui/CMakeLists.txt +++ b/libs/ui/CMakeLists.txt @@ -57,6 +57,8 @@ dialogs/kis_dlg_filter.cpp dialogs/kis_dlg_generator_layer.cpp dialogs/kis_dlg_file_layer.cpp + dialogs/kis_dlg_filter.cpp + dialogs/kis_dlg_stroke_selection_properties.cpp dialogs/kis_dlg_image_properties.cc dialogs/kis_dlg_layer_properties.cc dialogs/kis_dlg_preferences.cc @@ -445,6 +447,7 @@ forms/wdgdlgblacklistcleanup.ui forms/wdgrectangleconstraints.ui forms/wdgimportimagesequence.ui + forms/wdgstrokeselectionproperties.ui forms/KisDetailsPaneBase.ui forms/KisOpenPaneBase.ui dialogs/kis_delayed_save_dialog.ui diff --git a/libs/ui/actions/kis_selection_action_factories.h b/libs/ui/actions/kis_selection_action_factories.h --- a/libs/ui/actions/kis_selection_action_factories.h +++ b/libs/ui/actions/kis_selection_action_factories.h @@ -22,6 +22,7 @@ #include "operations/kis_operation.h" #include "operations/kis_operation_configuration.h" #include "operations/kis_filter_selection_operation.h" +#include "dialogs/kis_dlg_stroke_selection_properties.h" class KRITAUI_EXPORT KisNoParameterActionFactory : public KisOperation { @@ -118,6 +119,16 @@ void run(KisViewManager *view); }; +struct KRITAUI_EXPORT KisStrokeSelectionActionFactory : public KisOperation { + KisStrokeSelectionActionFactory() : KisOperation("selection-to-shape-action") {} + void run(KisViewManager *view, QPointer params); +}; + +struct KRITAUI_EXPORT KisStrokeBrushSelectionActionFactory : public KisOperation { + KisStrokeBrushSelectionActionFactory() : KisOperation("selection-to-shape-action") {} + void run(KisViewManager *view, QPointer params); +}; + #endif /* __KIS_SELECTION_ACTION_FACTORIES_H */ diff --git a/libs/ui/actions/kis_selection_action_factories.cpp b/libs/ui/actions/kis_selection_action_factories.cpp --- a/libs/ui/actions/kis_selection_action_factories.cpp +++ b/libs/ui/actions/kis_selection_action_factories.cpp @@ -69,6 +69,9 @@ #include #include +#include "kis_canvas_resource_provider.h" +#include "kis_figure_painting_tool_helper.h" + namespace ActionHelper { void copyFromDevice(KisViewManager *view, KisPaintDeviceSP device, bool makeSharpClip = false) @@ -536,3 +539,73 @@ view->document()->shapeController()->addShape(shape); } + +void KisStrokeSelectionActionFactory::run(KisViewManager *view, QPointer params) +{ + KisSelectionSP selection = view->selection(); + int size = params->getLineSize(); + QColor color = params->getSelectedColor(view->canvasBase()->resourceManager()).toQColor(); + + if (!selection->outlineCacheValid()) { + return; + } + QPainterPath selectionOutline = selection->outlineCache(); + + QTransform transform = view->canvasBase()->coordinatesConverter()->imageToDocumentTransform(); + + KoShape *shape = KoPathShape::createShapeFromPainterPath(transform.map(selectionOutline)); + shape->setShapeId(KoPathShapeId); + + //KoColor fgColor = view->canvasBase()->resourceManager()->resource(KoCanvasResourceManager::ForegroundColor).value(); + KoShapeStroke* border = new KoShapeStroke(params->getLineSize(), color); + shape->setStroke(border); + + view->document()->shapeController()->addShape(shape); +} + +void KisStrokeBrushSelectionActionFactory::run(KisViewManager *view, QPointer params) +{ + KisImageWSP image = view->image(); + if (!image ) { + + return; + } + + KisSelectionSP selection = view->selection(); + if (!selection) { + + return; + } + + KisPixelSelectionSP pixelSelection = selection->projection(); + if (!pixelSelection->outlineCacheValid()) { + pixelSelection->recalculateOutlineCache(); + } + + KisNodeSP currentNode = view->resourceProvider()->resourceManager()->resource(KisCanvasResourceProvider::CurrentKritaNode).value(); + if (!currentNode->inherits("KisShapeLayer") && currentNode->childCount() == 0) + { + KoCanvasResourceManager * rManager = view->resourceProvider()->resourceManager(); + QPainterPath outline = pixelSelection->outlineCache(); + KisPainter::StrokeStyle strokeStyle = KisPainter::StrokeStyleBrush; + KisPainter::FillStyle fillStyle = KisPainter::FillStyleNone; + KoColor color = params->getSelectedColor(view->canvasBase()->resourceManager()); + + KoColor tempColor =rManager->resource(KoCanvasResourceManager::ForegroundColor).value(); + rManager->setForegroundColor(color); + KisFigurePaintingToolHelper helper(kundo2_i18n("Draw Polyline"), + image, + currentNode, + rManager , + strokeStyle, + fillStyle); + // helper.paintPolyline(points); + rManager->setForegroundColor(tempColor); + helper.paintPainterPath(outline); + + image->setModified(); + + } + + +} diff --git a/libs/ui/dialogs/kis_dlg_stroke_selection_properties.h b/libs/ui/dialogs/kis_dlg_stroke_selection_properties.h new file mode 100644 --- /dev/null +++ b/libs/ui/dialogs/kis_dlg_stroke_selection_properties.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2016 Alexey Kapustin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef KIS_DLG_STROKE_SELECTION_PROPERTIES_H_ +#define KIS_DLG_STROKE_SELECTION_PROPERTIES_H_ + +#include +#include "KisProofingConfiguration.h" +#include +#include "ui_wdgstrokeselectionproperties.h" +#include "KoCanvasResourceManager.h" + +class KoColorSpace; +class KoColorPopupAction; + +class WdgStrokeSelection : public QWidget, public Ui::WdgStrokeSelection +{ + Q_OBJECT + +public: + WdgStrokeSelection(QWidget *parent) : QWidget(parent) { + setupUi(this); + } + +private Q_SLOTS: + void on_useBackgroundColor_toggled(bool checked); + void on_useForegroundColor_toggled(bool checked); + void on_currentBrush_toggled(bool checked); +}; + +enum class linePosition +{ + OUTSIDE, INSIDE, CENTER +}; +class KisDlgStrokeSelection : public KoDialog +{ + + Q_OBJECT + +public: + KisDlgStrokeSelection(KisImageWSP image, + QWidget *parent = 0, + const char *name = 0); + virtual ~KisDlgStrokeSelection(); + int getLineSize() const; + linePosition getLinePosition(); + bool isBrushSelected(); + KoColor getSelectedColor(KoCanvasResourceManager *resourceManager) const; + +private: + + WdgStrokeSelection * m_page; + KisImageWSP m_image; + KoColorPopupAction *m_defaultColorAction; + KoColorPopupAction *m_gamutWarning; + KisProofingConfiguration *m_proofingConfig; + QPointF m_offset; +}; + + + +#endif // KIS_DLG_STROKE_SEL_PROPERTIES_H_ + diff --git a/libs/ui/dialogs/kis_dlg_stroke_selection_properties.cpp b/libs/ui/dialogs/kis_dlg_stroke_selection_properties.cpp new file mode 100644 --- /dev/null +++ b/libs/ui/dialogs/kis_dlg_stroke_selection_properties.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2016 Kapustin Alexey + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kis_dlg_stroke_selection_properties.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +#include +#include "KoColorProfile.h" +#include "KoColorSpaceRegistry.h" +#include "KoColor.h" +#include "KoColorConversionTransformation.h" +#include "KoColorPopupAction.h" +#include "kis_icon_utils.h" +#include "KoID.h" +#include "kis_image.h" +#include "kis_annotation.h" +#include "kis_config.h" +#include "kis_signal_compressor.h" +#include "widgets/kis_cmb_idlist.h" +#include "widgets/squeezedcombobox.h" +#include "kis_layer_utils.h" +#include + +KisDlgStrokeSelection::KisDlgStrokeSelection(KisImageWSP image, QWidget *parent, const char *name) + : KoDialog(parent) +{ + setButtons(Ok | Cancel); + setDefaultButton(Ok); + setObjectName(name); + setCaption(i18n("Stroke selection properties")); + m_page = new WdgStrokeSelection(this); + + m_image = image; + + setMainWidget(m_page); + resize(m_page->sizeHint()); +} + +KisDlgStrokeSelection::~KisDlgStrokeSelection() +{ + delete m_page; +} + + KoColor KisDlgStrokeSelection::getSelectedColor(KoCanvasResourceManager *resourceManager) const +{ + KoColor color; + if (m_page->useBackgroundColor->isChecked()) + color = resourceManager->resource(KoCanvasResourceManager::BackgroundColor).value(); + else + if(m_page->useForegroundColor->isChecked()) + color = resourceManager->resource(KoCanvasResourceManager::ForegroundColor).value(); + else + color.fromQColor(m_page->colorSelector->color()); + + return color; +} + + int KisDlgStrokeSelection::getLineSize() const + { + return m_page->lineSize->value(); + } + +linePosition KisDlgStrokeSelection::getLinePosition() +{ + int index = m_page->linePosition->currentIndex(); + switch(index) + { + case(0): + return linePosition::OUTSIDE; + case(1): + return linePosition::INSIDE; + case(2): + return linePosition::CENTER; + default: + return linePosition::CENTER; + } +} + +bool KisDlgStrokeSelection::isBrushSelected() +{ + return m_page->currentBrush->isChecked(); +} + +void WdgStrokeSelection::on_useBackgroundColor_toggled(bool checked) +{ + colorSelector->setDisabled(checked); + useForegroundColor->setDisabled(checked); +} + +void WdgStrokeSelection::on_useForegroundColor_toggled(bool checked) +{ + colorSelector->setDisabled(checked); + useBackgroundColor->setDisabled(checked); +} + +void WdgStrokeSelection::on_currentBrush_toggled(bool checked) +{ + lineSize->setDisabled(checked); + linePosition->setDisabled(checked); + lineStyle->setDisabled(checked); + // useForegroundColor->setDisabled(checked); + // useBackgroundColor->setDisabled(checked); + +} diff --git a/libs/ui/forms/wdgstrokeselectionproperties.ui b/libs/ui/forms/wdgstrokeselectionproperties.ui new file mode 100644 --- /dev/null +++ b/libs/ui/forms/wdgstrokeselectionproperties.ui @@ -0,0 +1,201 @@ + + + WdgStrokeSelection + + + + 0 + 0 + 407 + 319 + + + + New Image + + + + + + Qt::Horizontal + + + + 328 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 240 + + + + + + + + Structure + + + + + + Size: + + + intSize + + + + + + + px + + + 1 + + + 1000000 + + + 1 + + + + + + + &Position: + + + cmbPosition + + + + + + + + 0 + 0 + + + + + Outside + + + + + Inside + + + + + Center + + + + + + + + Color: + + + + + + + ... + + + + + + + Use foreground color + + + + + + + Line style + + + + + + + + + + Use current brush + + + + + + + Use background color + + + + + + + + + + Qt::Vertical + + + + 20 + 269 + + + + + + + + Qt::Horizontal + + + + 328 + 20 + + + + + + + + + KColorButton + QPushButton +
kcolorbutton.h
+ 1 +
+ + KoLineStyleSelector + QComboBox +
KoLineStyleSelector.h
+
+
+ + +
diff --git a/libs/ui/kis_selection_manager.h b/libs/ui/kis_selection_manager.h --- a/libs/ui/kis_selection_manager.h +++ b/libs/ui/kis_selection_manager.h @@ -109,10 +109,13 @@ void slotToggleSelectionDecoration(); + void slotStrokeSelection(); + Q_SIGNALS: void currentSelectionChanged(); void signalUpdateGUI(); void displaySelectionChanged(); + void strokeSelected(); public: bool havePixelsSelected(); @@ -167,6 +170,8 @@ KisAction *m_strokeShapes; KisAction *m_toggleDisplaySelection; KisAction *m_toggleSelectionOverlayMode; + KisAction *m_strokeSelected; + QList m_pluginActions; QPointer m_selectionDecoration; diff --git a/libs/ui/kis_selection_manager.cc b/libs/ui/kis_selection_manager.cc --- a/libs/ui/kis_selection_manager.cc +++ b/libs/ui/kis_selection_manager.cc @@ -81,12 +81,16 @@ #include "kis_selection_filters.h" #include "kis_figure_painting_tool_helper.h" #include "KisView.h" +#include "dialogs/kis_dlg_stroke_selection_properties.h" #include "actions/kis_selection_action_factories.h" #include "kis_action.h" #include "kis_action_manager.h" #include "operations/kis_operation_configuration.h" - +//new +#include "kis_recorded_path_paint_action.h" +#include "kis_node_query_path.h" +#include "kis_tool_shape.h" KisSelectionManager::KisSelectionManager(KisViewManager * view) : m_view(view), @@ -202,6 +206,9 @@ m_toggleSelectionOverlayMode = actionManager->createAction("toggle-selection-overlay-mode"); connect(m_toggleSelectionOverlayMode, SIGNAL(triggered()), SLOT(slotToggleSelectionDecoration())); + m_strokeSelected = actionManager->createAction("stroke_selection"); + connect(m_strokeSelected, SIGNAL(triggered()), SLOT(slotStrokeSelection())); + QClipboard *cb = QApplication::clipboard(); connect(cb, SIGNAL(dataChanged()), SLOT(clipboardDataChanged())); } @@ -580,4 +587,25 @@ } return false; } +void KisSelectionManager::slotStrokeSelection() +{ + KisImageWSP image = m_view->image(); + + if (!image) return; + QPointer dlg = new KisDlgStrokeSelection(image, m_view->mainWindow()); + if (dlg->exec() == QDialog::Accepted) { + // image->convertProjectionColorSpace(dlg->colorSpace()); + if (dlg->isBrushSelected()){ + KisStrokeBrushSelectionActionFactory factory; + factory.run(m_view, dlg); + } + else { + KisStrokeSelectionActionFactory factory; + factory.run(m_view, dlg); + } + } + delete dlg; + + +}