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/image/kis_painter.h b/libs/image/kis_painter.h --- a/libs/image/kis_painter.h +++ b/libs/image/kis_painter.h @@ -664,7 +664,7 @@ FillStylePattern, FillStyleGradient, FillStyleStrokes, - FillStyleGenerator + FillStyleGenerator, }; /// Set the current style with which to fill diff --git a/libs/image/kis_painter.cc b/libs/image/kis_painter.cc --- a/libs/image/kis_painter.cc +++ b/libs/image/kis_painter.cc @@ -92,6 +92,7 @@ KisPaintOp* paintOp; KoColor paintColor; KoColor backgroundColor; + KoColor customColor; const KisFilterConfiguration* generator; KisPaintLayer* sourceLayer; FillStyle fillStyle; 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 @@ -453,6 +455,7 @@ forms/wdgdlgblacklistcleanup.ui forms/wdgrectangleconstraints.ui forms/wdgimportimagesequence.ui + forms/wdgstrokeselectionproperties.ui forms/KisDetailsPaneBase.ui forms/KisOpenPaneBase.ui brushhud/kis_dlg_brush_hud_config.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, StrokeSelectionOptions params); +}; + +struct KRITAUI_EXPORT KisStrokeBrushSelectionActionFactory : public KisOperation { + KisStrokeBrushSelectionActionFactory() : KisOperation("selection-to-shape-action") {} + void run(KisViewManager *view, StrokeSelectionOptions 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,110 @@ view->document()->shapeController()->addShape(shape); } + +void KisStrokeSelectionActionFactory::run(KisViewManager *view, StrokeSelectionOptions params) +{ + KisImageWSP image = view->image(); + if (!image ) { + + return; + } + + KisSelectionSP selection = view->selection(); + if (!selection) { + + return; + } + + int size = params.lineSize; + + KisPixelSelectionSP pixelSelection = selection->projection(); if (!pixelSelection->outlineCacheValid()) { + pixelSelection->recalculateOutlineCache(); + } + + QPainterPath outline = pixelSelection->outlineCache(); + QColor color = params.color.toQColor(); + + + KisNodeSP currentNode = view->resourceProvider()->resourceManager()->resource(KisCanvasResourceProvider::CurrentKritaNode).value(); + if (!currentNode->inherits("KisShapeLayer") && currentNode->childCount() == 0) { + KoCanvasResourceManager * rManager = view->resourceProvider()->resourceManager(); + KisPainter::StrokeStyle strokeStyle = KisPainter::StrokeStyleBrush; + KisPainter::FillStyle fillStyle = params.fillStyle(); + + KisFigurePaintingToolHelper helper(kundo2_i18n("Draw Polyline"), + image, + currentNode, + rManager , + strokeStyle, + fillStyle); + helper.setFGColorOverride(params.color); + helper.setSelectionOverride(0); + QPen pen(Qt::red, size); + pen.setJoinStyle(Qt::RoundJoin); + + if (fillStyle != KisPainter::FillStyleNone) { + helper.paintPainterPathQPenFill(outline, pen, params.fillColor); + } + else { + helper.paintPainterPathQPen(outline, pen, params.fillColor); + } + } + else { + + QTransform transform = view->canvasBase()->coordinatesConverter()->imageToDocumentTransform(); + + KoShape *shape = KoPathShape::createShapeFromPainterPath(transform.map(outline)); + shape->setShapeId(KoPathShapeId); + + KoShapeStroke* border = new KoShapeStroke(size, color); + shape->setStroke(border); + + view->document()->shapeController()->addShape(shape); + } + image->setModified(); + +} + +void KisStrokeBrushSelectionActionFactory::run(KisViewManager *view, StrokeSelectionOptions 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.color; + + KisFigurePaintingToolHelper helper(kundo2_i18n("Draw Polyline"), + image, + currentNode, + rManager , + strokeStyle, + fillStyle); + helper.setFGColorOverride(color); + helper.setSelectionOverride(0); + 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,113 @@ +/* + * 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 "KisViewManager.h" +#include "KoStrokeConfigWidget.h" +#include "ui_wdgstrokeselectionproperties.h" +#include +#include + +class KoColorSpace; +class KoColorPopupAction; + +enum class linePosition +{ + OUTSIDE, INSIDE, CENTER +}; + +enum class drawType{ + brushDraw, lineDraw +}; +enum class colorFillSource { + None, PaintColor, BGColor, CustomColor, FGColor +}; + +struct StrokeSelectionOptions { + StrokeSelectionOptions (); + int lineSize; + int _colorFillSource; + int lineColorSource; + bool brushSelected; + int lineDimension; + KoColor color; + KoColor fillColor; + KoColor customColor; + KisPainter::FillStyle fillStyle() const; + void lock(); +}; + +class WdgStrokeSelection : public QWidget, public Ui::WdgStrokeSelection +{ + Q_OBJECT + + +public: + WdgStrokeSelection(QWidget *parent) ; + StrokeSelectionOptions m_options; + +Q_SIGNALS: + void colorFillSelectorChanged(); + void colorSelectorChanged(); + +private Q_SLOTS: + void on_fillBox_currentIndexChanged(int index); + void on_typeBox_currentIndexChanged(const QString &arg1); + void on_lineColorBox_currentIndexChanged(const QString &arg1); + +}; + + +class KisDlgStrokeSelection : public KoDialog +{ + + Q_OBJECT + + +public: + KisDlgStrokeSelection(KisImageWSP image, KisViewManager *view, bool isVectorLayer); + virtual ~KisDlgStrokeSelection(); + int getLineSize() const; + linePosition getLinePosition() const; + KoColor getSelectedColor() const; + bool isBrushSelected() const; + KoColor getFillSelectedColor() const; + StrokeSelectionOptions getParams() const; + void lockVectorLayerFunctions(); + void unlockVectorLayerFunctions(); + +private: + WdgStrokeSelection * m_page; + KisImageWSP m_image; + KoCanvasResourceManager *m_resourceManager; + KisDisplayColorConverter *converter; + +private Q_SLOTS: + void setColorFillButton(); + void setColorButton(); + void colorChanged(const QColor &newColor); + void colorFillChanged(const QColor &newColor); +}; + + + +#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,397 @@ +/* + * 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 +#include "kis_canvas_resource_provider.h" +#include "KoUnit.h" +#include "kis_display_color_converter.h" + +KisDlgStrokeSelection::KisDlgStrokeSelection(KisImageWSP image, KisViewManager *view, bool isVectorLayer) + : KoDialog(view->mainWindow()) +{ + m_resourceManager = view->mainWindow()->resourceManager(); + + converter = view->canvasBase()->displayColorConverter(); + setButtons(Ok | Cancel); + setDefaultButton(Ok); + setCaption(i18n("Stroke selection properties")); + m_page = new WdgStrokeSelection(this); + + m_image = image; + + setMainWidget(m_page); + resize(m_page->sizeHint()); + + QString filterConfig = KisConfig().exportConfiguration("StrokeSelection"); + KisPropertiesConfiguration cfg; + cfg.fromXML(filterConfig); + + auto &m_options = m_page->m_options; + m_options.color = cfg.getColor("color"); + m_options.lineColorSource = cfg.getInt("lineColorSource"); + m_page->lineColorBox->setCurrentIndex(m_options.lineColorSource); + + m_page->colorSelector->setColor(getSelectedColor().toQColor()); + + m_options.brushSelected = cfg.getBool("useBrush", 0); + m_page->typeBox->setCurrentIndex(m_options.brushSelected? 0 : 1); + + m_options._colorFillSource = cfg.getInt("colorFillSource", 0); + m_page->fillBox->setCurrentIndex(m_options._colorFillSource); + m_options.customColor = cfg.getColor("customColor"); + if (m_options._colorFillSource == static_cast(colorFillSource::CustomColor)) { + m_page->colorFillSelector->setColor(m_options.customColor.toQColor()); + } + else { + m_page->colorFillSelector->setColor(getFillSelectedColor().toQColor()); + } + + m_options.fillColor = cfg.getColor("fillColor"); + if (m_options._colorFillSource == static_cast(colorFillSource::None)) { + m_page->colorFillSelector->setDisabled(true); + } + else { + m_page->colorFillSelector->setDisabled(false); } + + m_options.lineSize = cfg.getInt("lineSize", 1); + m_page->lineSize->setValue(m_options.lineSize); + if (m_options.brushSelected) { + m_page->lineSize->setDisabled(true); + m_page->fillBox->setDisabled(true); + m_page->colorFillSelector->setDisabled(true); + m_page->sizeBox->setDisabled(true); + } + + m_options.lineDimension = cfg.getInt("lineDimension", 0); + m_page->sizeBox->setCurrentIndex(m_options.lineDimension); + + connect(m_page, SIGNAL(colorSelectorChanged()), SLOT(setColorButton())); + connect(m_page, SIGNAL(colorFillSelectorChanged()), SLOT(setColorFillButton())); + connect(m_page->colorFillSelector, SIGNAL(changed(const QColor&)), SLOT(colorFillChanged(const QColor&))); + connect(m_page->colorSelector, SIGNAL(changed(const QColor&)), SLOT(colorChanged(const QColor&))); + + if (isVectorLayer) { + lockVectorLayerFunctions(); + } +} + +KisDlgStrokeSelection::~KisDlgStrokeSelection() +{ + auto &m_options = m_page->m_options; + m_options.lineSize = m_page->lineSize->value(); + + m_options.lineDimension = m_page->sizeBox->currentIndex(); + m_options.lineColorSource = m_page->lineColorBox->currentIndex(); + + KisPropertiesConfiguration cfg; + cfg.setProperty("lineSize", m_options.lineSize); + cfg.setProperty("colorFillSource", m_options._colorFillSource); + cfg.setProperty("useBrush", m_options.brushSelected); + cfg.setProperty("lineDimension", m_options.lineDimension); + cfg.setProperty("lineColorSource", m_options.lineColorSource); + + QVariant colorVariant("KoColor"); + colorVariant.setValue(m_options.customColor); + cfg.setProperty("customColor", colorVariant); + + QVariant _colorVariant("KoColor"); + _colorVariant.setValue(m_options.color); + cfg.setProperty("color", _colorVariant); + + QVariant _cVariant("KoColor"); + _cVariant.setValue(m_options.fillColor); + cfg.setProperty("fillColor", _cVariant); + + KisConfig().setExportConfiguration("StrokeSelection", cfg); + + delete m_page; +} + +KoColor KisDlgStrokeSelection::getSelectedColor() const +{ + KoColor color; + + QString currentSource = m_page->lineColorBox->currentText(); + + if (currentSource == "Foreground color") { + color = m_resourceManager->resource(KoCanvasResourceManager::ForegroundColor).value(); + } + else if (currentSource == "Background color") { + color = m_resourceManager->resource(KoCanvasResourceManager::BackgroundColor).value(); + } + else { + color = m_page->m_options.color; + } + + return color; +} + +KoColor KisDlgStrokeSelection::getFillSelectedColor() const +{ + KoColor color; + + colorFillSource currentSource = static_cast(m_page->fillBox->currentIndex()); + + if (currentSource == colorFillSource::FGColor) { + color = m_resourceManager->resource(KoCanvasResourceManager::ForegroundColor).value(); + } + else if (currentSource == colorFillSource::BGColor) { + color = m_resourceManager->resource(KoCanvasResourceManager::BackgroundColor).value(); + } + else if (currentSource == colorFillSource::PaintColor) { + color = converter->approximateFromRenderedQColor(m_page->colorSelector->color()); + } + else { + color = m_page->m_options.customColor; + } + + return color; +} + + +bool KisDlgStrokeSelection::isBrushSelected() const +{ + int index = m_page->typeBox->currentIndex(); + drawType type = static_cast(index); + + if (type == drawType::brushDraw){ + return true; + } + else { + return false; + } +} + +StrokeSelectionOptions KisDlgStrokeSelection::getParams() const + { + StrokeSelectionOptions params; + + params.lineSize = getLineSize(); + params.color = getSelectedColor(); + params.brushSelected = isBrushSelected(); + params.fillColor = getFillSelectedColor(); + params._colorFillSource = m_page->m_options._colorFillSource; + return params; + +} + +void KisDlgStrokeSelection::lockVectorLayerFunctions() +{ + m_page->colorFillSelector->setEnabled(false); + m_page->lineSize->setEnabled(false); + m_page->sizeBox->setEnabled(false); + m_page->fillBox->setEnabled(false); + m_page->typeBox->setEnabled(false); +} + +void KisDlgStrokeSelection::unlockVectorLayerFunctions() +{ + m_page->colorFillSelector->setEnabled(true); + m_page->lineSize->setEnabled(true); + m_page->sizeBox->setEnabled(true); + m_page->fillBox->setEnabled(true); + m_page->typeBox->setEnabled(true); +} + +void KisDlgStrokeSelection::setColorFillButton() +{ + m_page->colorFillSelector->setColor(getFillSelectedColor().toQColor()); +} + +void KisDlgStrokeSelection::setColorButton() +{ + m_page->colorSelector->setColor(getSelectedColor().toQColor()); +} + + +int KisDlgStrokeSelection::getLineSize() const +{ + int value = m_page->lineSize->value(); + + if (m_page->sizeBox->currentText() == "px") { + return value; + } + else if (m_page->sizeBox->currentText() == "mm"){ + int pixels = static_cast(KoUnit::convertFromUnitToUnit(value,KoUnit(KoUnit::Millimeter), KoUnit(KoUnit::Pixel))); + return pixels; + } + else { + int pixels = static_cast(KoUnit::convertFromUnitToUnit(value, KoUnit(KoUnit::Inch), KoUnit(KoUnit::Pixel))); + return pixels; + } +} + +linePosition KisDlgStrokeSelection::getLinePosition() const +{/* TODO + 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; + }*/ + return linePosition::CENTER; +} + +void KisDlgStrokeSelection::colorChanged(const QColor &newColor) +{ + if (m_page->fillBox->currentText() == "Paint color") { + m_page->colorFillSelector->setColor(newColor); + } + QColor BGColor = m_resourceManager->resource(KoCanvasResourceManager::BackgroundColor).value().toQColor(); + QColor FGColor = m_resourceManager->resource(KoCanvasResourceManager::ForegroundColor).value().toQColor(); + KoColor tempColor= converter->approximateFromRenderedQColor(newColor); + + + if (!(newColor == BGColor) && !(newColor == FGColor)) { + m_page->m_options.color = tempColor; + m_page->lineColorBox->setCurrentIndex(2); //custom color + } +} + +void KisDlgStrokeSelection::colorFillChanged(const QColor &newColor) +{ + QColor PaintColor = m_page->colorSelector->color(); + QColor BGcolor = m_resourceManager->resource(KoCanvasResourceManager::BackgroundColor).value().toQColor(); + QColor FGColor = m_resourceManager->resource(KoCanvasResourceManager::ForegroundColor).value().toQColor(); + KoColor tempColor= converter->approximateFromRenderedQColor(newColor); + + if (!(newColor == FGColor) && !(newColor == BGcolor) && !(newColor == PaintColor)) { + m_page->m_options.customColor = tempColor; + m_page->fillBox->setCurrentIndex(static_cast(colorFillSource::CustomColor)); + } + m_page->m_options.fillColor = tempColor; +} + + + +WdgStrokeSelection::WdgStrokeSelection(QWidget *parent) : QWidget(parent) +{ + setupUi(this); +} + +void WdgStrokeSelection::on_fillBox_currentIndexChanged(int index) +{ + if (index == static_cast(colorFillSource::None)) { + colorFillSelector->setDisabled(true); + } + else { + colorFillSelector->setDisabled(false); + emit colorFillSelectorChanged(); + } + m_options._colorFillSource = index; +} + +void WdgStrokeSelection::on_typeBox_currentIndexChanged(const QString &arg1) +{ + if (arg1 == "Current Brush") { + m_options.brushSelected = true; + lineSize->setDisabled(true); + fillBox->setDisabled(true); + colorFillSelector->setDisabled(true); + sizeBox->setDisabled(true); + } + else { + m_options.brushSelected = false; + lineSize->setDisabled(false); + fillBox->setDisabled(false); + colorFillSelector->setDisabled(false); + sizeBox->setDisabled(false); + } +} + +void WdgStrokeSelection::on_lineColorBox_currentIndexChanged(const QString &arg1) +{ + emit colorSelectorChanged(); +} + + +StrokeSelectionOptions ::StrokeSelectionOptions(): + lineSize(1), + brushSelected(false), + _colorFillSource(0), + lineColorSource(0), + lineDimension(0) +{ + color.fromQColor(Qt::black); + fillColor.fromQColor(Qt::black); + customColor.fromQColor(Qt::black); +} + +KisPainter::FillStyle StrokeSelectionOptions::fillStyle() const +{ + colorFillSource tempColor = static_cast(_colorFillSource); + KisPainter::FillStyle style; + + switch (tempColor) { + case colorFillSource::PaintColor: + style = KisPainter::FillStyleForegroundColor; + break; + case colorFillSource::BGColor: + style = KisPainter::FillStyleBackgroundColor; + break; + case colorFillSource::CustomColor: + style = KisPainter::FillStyleBackgroundColor; + break; + case colorFillSource::None: + style = KisPainter::FillStyleNone; + break; + case colorFillSource::FGColor: + style = KisPainter::FillStyleBackgroundColor; + break; + default: + style = KisPainter::FillStyleBackgroundColor; + } + return style; +} + + 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,210 @@ + + + WdgStrokeSelection + + + + 0 + 0 + 869 + 601 + + + + + 0 + 0 + + + + New Image + + + + + + 0 + + + + Stroke + + + + + + + + 0 + + + + Current Brush + + + + + Line selection + + + + + + + + Fill: + + + + + + + Type: + + + + + + + + + + 1 + + + 1000000 + + + 1 + + + + + + + Width: + + + intSize + + + + + + + + px + + + + + mm + + + + + inch + + + + + + + + + None + + + + + Paint color + + + + + Background color + + + + + Custom color + + + + + Foreground color + + + + + + + + Line: + + + + + + + Color + + + false + + + false + + + false + + + false + + + + + + + + Foreground color + + + + + Background color + + + + + Custom color + + + + + + + + Color + + + + + + + + + + + + + + KColorButton + QPushButton +
kcolorbutton.h
+ 1 +
+
+ + +
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,34 @@ } return false; } +void KisSelectionManager::slotStrokeSelection() +{ + KisImageWSP image = m_view->image(); + + if (!image ) { + + return; + } + KisNodeSP currentNode = m_view->resourceProvider()->resourceManager()->resource(KisCanvasResourceProvider::CurrentKritaNode).value(); + bool isVectorLayer = false; + if (currentNode->inherits("KisShapeLayer")) { + isVectorLayer = true; + } + QPointer dlg = new KisDlgStrokeSelection(image, m_view, isVectorLayer); + + if (dlg->exec() == QDialog::Accepted) { + StrokeSelectionOptions params = dlg->getParams(); + if (params.brushSelected){ + KisStrokeBrushSelectionActionFactory factory; + factory.run(m_view, params); + } + else { + KisStrokeSelectionActionFactory factory; + factory.run(m_view, params); + } + } + delete dlg; + + +} diff --git a/libs/ui/tool/kis_figure_painting_tool_helper.h b/libs/ui/tool/kis_figure_painting_tool_helper.h --- a/libs/ui/tool/kis_figure_painting_tool_helper.h +++ b/libs/ui/tool/kis_figure_painting_tool_helper.h @@ -49,6 +49,12 @@ void paintRect(const QRectF &rect); void paintEllipse(const QRectF &rect); void paintPainterPath(const QPainterPath &path); + void setFGColorOverride(const KoColor &color); + void setBGColorOverride(const KoColor &color); + void setSelectionOverride(KisSelectionSP m_selection); + void setBrush(const KisPaintOpPresetSP &brush); + void paintPainterPathQPen(const QPainterPath, const QPen &pen, const KoColor &color); + void paintPainterPathQPenFill(const QPainterPath, const QPen &pen, const KoColor &color); private: KisStrokeId m_strokeId; diff --git a/libs/ui/tool/kis_figure_painting_tool_helper.cpp b/libs/ui/tool/kis_figure_painting_tool_helper.cpp --- a/libs/ui/tool/kis_figure_painting_tool_helper.cpp +++ b/libs/ui/tool/kis_figure_painting_tool_helper.cpp @@ -113,3 +113,40 @@ path)); } +void KisFigurePaintingToolHelper::setFGColorOverride(const KoColor &color) +{ + m_resources->setFGColorOverride(color); +} + +void KisFigurePaintingToolHelper::setBGColorOverride(const KoColor &color) +{ + m_resources->setBGColorOverride(color); +} + +void KisFigurePaintingToolHelper::setSelectionOverride(KisSelectionSP m_selection) +{ + m_resources->setSelectionOverride(m_selection); +} + +void KisFigurePaintingToolHelper::setBrush(const KisPaintOpPresetSP &brush) +{ + m_resources->setBrush(brush); +} + +void KisFigurePaintingToolHelper::paintPainterPathQPen(const QPainterPath path, const QPen &pen, const KoColor &color) +{ + m_strokesFacade->addJob(m_strokeId, + new FreehandStrokeStrategy::Data(m_resources->currentNode(), + 0, + FreehandStrokeStrategy::Data::QPAINTER_PATH, + path, pen, color)); +} + +void KisFigurePaintingToolHelper::paintPainterPathQPenFill(const QPainterPath path, const QPen &pen, const KoColor &color) +{ + m_strokesFacade->addJob(m_strokeId, + new FreehandStrokeStrategy::Data(m_resources->currentNode(), + 0, + FreehandStrokeStrategy::Data::QPAINTER_PATH_FILL, + path, pen, color)); +} diff --git a/libs/ui/tool/kis_resources_snapshot.h b/libs/ui/tool/kis_resources_snapshot.h --- a/libs/ui/tool/kis_resources_snapshot.h +++ b/libs/ui/tool/kis_resources_snapshot.h @@ -86,6 +86,11 @@ qreal effectiveZoom() const; bool presetAllowsLod() const; + void setFGColorOverride(const KoColor &color); + void setBGColorOverride(const KoColor &color); + void setSelectionOverride(KisSelectionSP selection); + void setBrush(const KisPaintOpPresetSP &brush); + private: struct Private; Private * const m_d; diff --git a/libs/ui/tool/kis_resources_snapshot.cpp b/libs/ui/tool/kis_resources_snapshot.cpp --- a/libs/ui/tool/kis_resources_snapshot.cpp +++ b/libs/ui/tool/kis_resources_snapshot.cpp @@ -71,6 +71,7 @@ bool globalAlphaLock; qreal effectiveZoom; bool presetAllowsLod; + KisSelectionSP selection; }; KisResourcesSnapshot::KisResourcesSnapshot(KisImageSP image, KisNodeSP currentNode, KisPostExecutionUndoAdapter *undoAdapter, KoCanvasResourceManager *resourceManager, KisDefaultBoundsBaseSP bounds) @@ -82,7 +83,6 @@ } m_d->bounds = bounds; m_d->undoAdapter = undoAdapter; - m_d->currentFgColor = resourceManager->resource(KoCanvasResourceManager::ForegroundColor).value(); m_d->currentBgColor = resourceManager->resource(KoCanvasResourceManager::BackgroundColor).value(); m_d->currentPattern = resourceManager->resource(KisCanvasResourceProvider::CurrentPattern).value(); @@ -131,6 +131,7 @@ m_d->globalAlphaLock = resourceManager->resource(KisCanvasResourceProvider::GlobalAlphaLock).toBool(); m_d->effectiveZoom = resourceManager->resource(KisCanvasResourceProvider::EffectiveZoom).toDouble(); m_d->presetAllowsLod = resourceManager->resource(KisCanvasResourceProvider::PresetAllowsLod).toBool(); + m_d->selection = m_d->image->globalSelection(); } KisResourcesSnapshot::~KisResourcesSnapshot() @@ -237,19 +238,24 @@ * It is possible to have/use the snapshot without the image. Such * usecase is present for example in the scratchpad. */ - KisSelectionSP selection = m_d->image ? m_d->image->globalSelection() : 0; + if (!m_d->selection) { + + return 0; + } + + m_d->selection = m_d->image ? m_d->image->globalSelection() : 0; KisLayerSP layer = dynamic_cast(m_d->currentNode.data()); KisSelectionMaskSP mask; if((layer = dynamic_cast(m_d->currentNode.data()))) { - selection = layer->selection(); + m_d->selection = layer->selection(); } else if ((mask = dynamic_cast(m_d->currentNode.data())) && - mask->selection() == selection) { + mask->selection() == m_d->selection) { - selection = 0; + m_d->selection = 0; } - return selection; + return m_d->selection; } bool KisResourcesSnapshot::needsAirbrushing() const @@ -325,3 +331,23 @@ { return m_d->presetAllowsLod; } + +void KisResourcesSnapshot::setFGColorOverride(const KoColor &color) +{ + m_d->currentFgColor = color; +} + +void KisResourcesSnapshot::setBGColorOverride(const KoColor &color) +{ + m_d->currentBgColor = color; +} + +void KisResourcesSnapshot::setSelectionOverride(KisSelectionSP m_selection) +{ + m_d->selection = m_selection; +} + +void KisResourcesSnapshot::setBrush(const KisPaintOpPresetSP &brush) +{ + m_d->currentPaintOpPreset = brush; +} diff --git a/libs/ui/tool/strokes/freehand_stroke.h b/libs/ui/tool/strokes/freehand_stroke.h --- a/libs/ui/tool/strokes/freehand_stroke.h +++ b/libs/ui/tool/strokes/freehand_stroke.h @@ -26,6 +26,7 @@ #include #include #include "kis_lod_transform.h" +#include "KoColor.h" @@ -42,7 +43,9 @@ POLYGON, RECT, ELLIPSE, - PAINTER_PATH + PAINTER_PATH, + QPAINTER_PATH, + QPAINTER_PATH_FILL }; Data(KisNodeSP _node, int _painterInfoId, @@ -89,6 +92,15 @@ type(_type), path(_path) {} + Data(KisNodeSP _node, int _painterInfoId, + DabType _type, + const QPainterPath &_path, + const QPen &_pen, const KoColor &_customColor) + : node(_node), painterInfoId(_painterInfoId), + type(_type), path(_path), + pen(_pen), customColor(_customColor) + {} + KisStrokeJobData* createLodClone(int levelOfDetail) { return new Data(*this, levelOfDetail); } @@ -145,6 +157,8 @@ vQPointF points; QRectF rect; QPainterPath path; + QPen pen; + KoColor customColor; }; public: diff --git a/libs/ui/tool/strokes/freehand_stroke.cpp b/libs/ui/tool/strokes/freehand_stroke.cpp --- a/libs/ui/tool/strokes/freehand_stroke.cpp +++ b/libs/ui/tool/strokes/freehand_stroke.cpp @@ -124,6 +124,15 @@ break; case Data::PAINTER_PATH: info->painter->paintPainterPath(d->path); + break; + case Data::QPAINTER_PATH: + info->painter->drawPainterPath(d->path, d->pen); + break; + case Data::QPAINTER_PATH_FILL: { + info->painter->setBackgroundColor(d->customColor); + info->painter->fillPainterPath(d->path);} + info->painter->drawPainterPath(d->path, d->pen); + }; QVector dirtyRects = info->painter->takeDirtyRegion();