diff --git a/libs/libkis/Scratchpad.cpp b/libs/libkis/Scratchpad.cpp index 8e1b477803..ca0a8d9acc 100644 --- a/libs/libkis/Scratchpad.cpp +++ b/libs/libkis/Scratchpad.cpp @@ -1,58 +1,60 @@ /* * Copyright (c) 2020 Scott Petrovic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser 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 Lesser 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 "Scratchpad.h" #include #include #include "kis_scratch_pad.h" #include "Resource.h" #include "View.h" #include "Canvas.h" #include #include #include -Scratchpad::Scratchpad(View *view, const QString & defaultColor, QWidget *parent) +Scratchpad::Scratchpad(View *view, const QColor & defaultColor, QWidget *parent) : KisScratchPad(parent) -{ - - // todo hook this up later to override - const QColor backgroundColor = QColor(Qt::white); - - KisScratchPad::setupScratchPad(view->view()->resourceProvider(), backgroundColor); +{ + KisScratchPad::setupScratchPad(view->view()->resourceProvider(), defaultColor); KisScratchPad::setMinimumSize(50, 50); } Scratchpad::~Scratchpad() { } void Scratchpad::setModeManually(bool value) { KisScratchPad::setModeManually(value); } void Scratchpad::setMode(QString modeType) { KisScratchPad::setModeType(modeType); } void Scratchpad::clear() { + // need ability to set color KisScratchPad::fillDefault(); } + +void Scratchpad::setFillColor(QColor color) +{ + KisScratchPad::setFillColor(color); +} diff --git a/libs/libkis/Scratchpad.h b/libs/libkis/Scratchpad.h index 8b95e6f1bc..248c3f7e9f 100644 --- a/libs/libkis/Scratchpad.h +++ b/libs/libkis/Scratchpad.h @@ -1,65 +1,67 @@ /* * Copyright (c) 2020 Scott Petrovic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser 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 Lesser 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 LIBKIS_SCRATCHPAD_H #define LIBKIS_SCRATCHPAD_H #include #include #include #include "kritalibkis_export.h" #include "libkis.h" #include "kis_scratch_pad.h" #include "View.h" class KoCanvasBase; class Canvas; // This comes from Python. This would be maybe better class KisView; /** * @brief The Scratchpad class * A scratchpad is a type of blank canvas area that can be painted on * with the normal painting devices * */ class KRITALIBKIS_EXPORT Scratchpad: public KisScratchPad { Q_OBJECT public: - Scratchpad(View *view, const QString & defaultColor, QWidget *parent = 0); + Scratchpad(View *view, const QColor & defaultColor, QWidget *parent = 0); ~Scratchpad(); public Q_SLOTS: /** - * clears out scratchpad with whatever default color was set during setup + * clears out scratchpad with color specfified set during setup */ void clear(); + void setFillColor(QColor color); + /** Switches between a GUI controlling the current mode and when mouse clicks control mode * Setting to true allows GUI to control the mode with explicity setting mode */ void setModeManually(bool value); /// Manually set what mode scratchpad is in. Ignored if "setModeManually is set to false void setMode(QString modeName); }; #endif // LIBKIS_SCRATCHPAD_H diff --git a/libs/libkis/View.cpp b/libs/libkis/View.cpp index 4dd5ce08a2..6152d92113 100644 --- a/libs/libkis/View.cpp +++ b/libs/libkis/View.cpp @@ -1,298 +1,298 @@ /* * Copyright (c) 2016 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser 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 Lesser 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 "View.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Document.h" #include "Canvas.h" #include "Scratchpad.h" #include "Window.h" #include "Resource.h" #include "ManagedColor.h" #include "LibKisUtils.h" struct View::Private { Private() {} QPointer view; QList scratchpads; }; View::View(KisView* view, QObject *parent) : QObject(parent) , d(new Private) { d->view = view; } View::~View() { delete d; } bool View::operator==(const View &other) const { return (d->view == other.d->view); } bool View::operator!=(const View &other) const { return !(operator==(other)); } Window* View::window() const { if (!d->view) return 0; KisMainWindow *mainwin = d->view->mainWindow(); Window *win = new Window(mainwin); return win; } Document* View::document() const { if (!d->view) return 0; Document *doc = new Document(d->view->document(), false); return doc; } void View::setDocument(Document *document) { if (!d->view || !document || !document->document()) return; d->view = d->view->replaceBy(document->document()); } bool View::visible() const { if (!d->view) return false; return d->view->isVisible(); } void View::setVisible() { if (!d->view) return; KisMainWindow *mainwin = d->view->mainWindow(); mainwin->setActiveView(d->view); mainwin->subWindowActivated(); } Canvas* View::canvas() const { if (!d->view) return 0; Canvas *c = new Canvas(d->view->canvasBase()); return c; } KisView *View::view() { return d->view; } void View::activateResource(Resource *resource) { if (!d->view) return; if (!resource) return; KoResourceSP r = resource->resource(); if (!r) return; if (r.dynamicCast()) { QVariant v; v.setValue(r); d->view->canvasBase()->resourceManager()->setResource(KisCanvasResourceProvider::CurrentPattern, v); } else if (r.dynamicCast()) { QVariant v; v.setValue(r); d->view->canvasBase()->resourceManager()->setResource(KisCanvasResourceProvider::CurrentGradient, v); } else if (r.dynamicCast()) { d->view->viewManager()->paintOpBox()->resourceSelected(r); } } -Scratchpad *View::createScratchpad(QString bgColor) +Scratchpad *View::createScratchpad(QColor bgColor) { if(view()) { - d->scratchpads.append(new Scratchpad(this->canvas()->view(), "white")); + d->scratchpads.append(new Scratchpad(this->canvas()->view(), bgColor)); } return d->scratchpads.last(); } ManagedColor *View::foregroundColor() const { if (!d->view) return 0; return new ManagedColor(d->view->resourceProvider()->fgColor()); } void View::setForeGroundColor(ManagedColor *color) { if (!d->view) return; d->view->resourceProvider()->setFGColor(color->color()); } ManagedColor *View::backgroundColor() const { if (!d->view) return 0; return new ManagedColor(d->view->resourceProvider()->bgColor()); } void View::setBackGroundColor(ManagedColor *color) { if (!d->view) return; d->view->resourceProvider()->setBGColor(color->color()); } Resource *View::currentBrushPreset() const { if (!d->view) return 0; return new Resource(d->view->resourceProvider()->currentPreset(), ResourceType::PaintOpPresets); } void View::setCurrentBrushPreset(Resource *resource) { activateResource(resource); } Resource *View::currentPattern() const { if (!d->view) return 0; return new Resource(d->view->resourceProvider()->currentPattern(), ResourceType::Patterns); } void View::setCurrentPattern(Resource *resource) { activateResource(resource); } Resource *View::currentGradient() const { if (!d->view) return 0; return new Resource(d->view->resourceProvider()->currentGradient(), ResourceType::Gradients); } void View::setCurrentGradient(Resource *resource) { activateResource(resource); } QString View::currentBlendingMode() const { if (!d->view) return ""; return d->view->resourceProvider()->currentCompositeOp(); } void View::setCurrentBlendingMode(const QString &blendingMode) { if (!d->view) return; d->view->resourceProvider()->setCurrentCompositeOp(blendingMode); } float View::HDRExposure() const { if (!d->view) return 0.0; return d->view->resourceProvider()->HDRExposure(); } void View::setHDRExposure(float exposure) { if (!d->view) return; d->view->resourceProvider()->setHDRExposure(exposure); } float View::HDRGamma() const { if (!d->view) return 0.0; return d->view->resourceProvider()->HDRGamma(); } void View::setHDRGamma(float gamma) { if (!d->view) return; d->view->resourceProvider()->setHDRGamma(gamma); } qreal View::paintingOpacity() const { if (!d->view) return 0.0; return d->view->resourceProvider()->opacity(); } void View::setPaintingOpacity(qreal opacity) { if (!d->view) return; d->view->resourceProvider()->setOpacity(opacity); } qreal View::brushSize() const { if (!d->view) return 0.0; return d->view->resourceProvider()->size(); } void View::setBrushSize(qreal brushSize) { if (!d->view) return; d->view->resourceProvider()->setSize(brushSize); } qreal View::paintingFlow() const { if (!d->view) return 0.0; return d->view->resourceProvider()->flow(); } void View::setPaintingFlow(qreal flow) { if (!d->view) return; d->view->resourceProvider()->setFlow(flow); } QList View::selectedNodes() const { if (!d->view) return QList(); if (!d->view->viewManager()) return QList(); if (!d->view->viewManager()->nodeManager()) return QList(); KisNodeList selectedNodes = d->view->viewManager()->nodeManager()->selectedNodes(); return LibKisUtils::createNodeList(selectedNodes, d->view->image()); } QList View::scratchpads() const { if (!d->view) return QList(); if (!d->view->viewManager()) return QList(); return d->scratchpads; } diff --git a/libs/libkis/View.h b/libs/libkis/View.h index cd60a42578..a70950d5c7 100644 --- a/libs/libkis/View.h +++ b/libs/libkis/View.h @@ -1,173 +1,173 @@ /* * Copyright (c) 2016 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser 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 Lesser 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 LIBKIS_VIEW_H #define LIBKIS_VIEW_H #include #include "kritalibkis_export.h" #include "libkis.h" class ManagedColor; class Resource; class Scratchpad; class Node; class KisView; /** * View represents one view on a document. A document can be * shown in more than one view at a time. */ class KRITALIBKIS_EXPORT View : public QObject { Q_OBJECT Q_DISABLE_COPY(View) public: explicit View(KisView *view, QObject *parent = 0); ~View() override; bool operator==(const View &other) const; bool operator!=(const View &other) const; public Q_SLOTS: /** * @return the window this view is shown in. */ Window* window() const; /** * @return the document this view is showing. */ Document* document() const; /** * Reset the view to show @p document. */ void setDocument(Document *document); /** * @return true if the current view is visible, false if not. */ bool visible() const; /** * Make the current view visible. */ void setVisible(); /** * @return the canvas this view is showing. The canvas controls * things like zoom and rotation. */ Canvas* canvas() const; /** * @brief activateResource activates the given resource. * @param resource: a pattern, gradient or paintop preset */ void activateResource(Resource *resource); /** * @brief creates a scratchpad widget to draw on. * It is stored in the scratchpad list for reference */ - Scratchpad *createScratchpad(QString bgColor); + Scratchpad *createScratchpad(QColor bgColor); /** * @brief foregroundColor allows access to the currently active color. * This is nominally per canvas/view, but in practice per mainwindow. * @code color = Application.activeWindow().activeView().foregroundColor() components = color.components() components[0] = 1.0 components[1] = 0.6 components[2] = 0.7 color.setComponents(components) Application.activeWindow().activeView().setForeGroundColor(color) * @endcode */ ManagedColor *foregroundColor() const; void setForeGroundColor(ManagedColor *color); ManagedColor *backgroundColor() const; void setBackGroundColor(ManagedColor *color); Resource *currentBrushPreset() const; void setCurrentBrushPreset(Resource *resource); Resource *currentPattern() const; void setCurrentPattern(Resource *resource); Resource *currentGradient() const; void setCurrentGradient(Resource *resource); QString currentBlendingMode() const; void setCurrentBlendingMode(const QString &blendingMode); float HDRExposure() const; void setHDRExposure(float exposure); float HDRGamma() const; void setHDRGamma(float gamma); qreal paintingOpacity() const; void setPaintingOpacity(qreal opacity); qreal brushSize() const; void setBrushSize(qreal brushSize); qreal paintingFlow() const; void setPaintingFlow(qreal flow); /** * @brief selectedNodes returns a list of Nodes that are selected in this view. * * @code from krita import * w = Krita.instance().activeWindow() v = w.activeView() selected_nodes = v.selectedNodes() print(selected_nodes) @endcode * * * @return a list of Node objects which may be empty. */ QList selectedNodes() const; /** * @brief Stores scratchpad widgets to draw on */ QList scratchpads() const; private: friend class Window; friend class Scratchpad; KisView *view(); struct Private; Private *const d; }; #endif // LIBKIS_VIEW_H diff --git a/libs/ui/widgets/kis_scratch_pad.cpp b/libs/ui/widgets/kis_scratch_pad.cpp index c0f90c3ca2..d8a71ede68 100644 --- a/libs/ui/widgets/kis_scratch_pad.cpp +++ b/libs/ui/widgets/kis_scratch_pad.cpp @@ -1,608 +1,613 @@ /* This file is part of the KDE project * Copyright 2010 (C) Boudewijn Rempt * Copyright 2011 (C) Dmitry Kazakov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kis_scratch_pad.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kis_config.h" #include "kis_image.h" #include "kis_undo_stores.h" #include "kis_update_scheduler.h" #include "kis_post_execution_undo_adapter.h" #include "kis_scratch_pad_event_filter.h" #include "kis_painting_information_builder.h" #include "kis_tool_freehand_helper.h" #include "kis_image_patch.h" #include "kis_canvas_widget_base.h" #include "kis_layer_projection_plane.h" #include "kis_node_graph_listener.h" #include "kis_transaction.h" class KisScratchPadNodeListener : public KisNodeGraphListener { public: KisScratchPadNodeListener(KisScratchPad *scratchPad) : m_scratchPad(scratchPad) { } void requestProjectionUpdate(KisNode *node, const QVector &rects, bool resetAnimationCache) override { KisNodeGraphListener::requestProjectionUpdate(node, rects, resetAnimationCache); QMutexLocker locker(&m_lock); Q_FOREACH (const QRect &rc, rects) { m_scratchPad->imageUpdated(rc); } } private: KisScratchPad *m_scratchPad; QMutex m_lock; }; class KisScratchPadDefaultBounds : public KisDefaultBounds { public: KisScratchPadDefaultBounds(KisScratchPad *scratchPad) : m_scratchPad(scratchPad) { } ~KisScratchPadDefaultBounds() override {} QRect bounds() const override { return m_scratchPad->imageBounds(); } void * sourceCookie() const override { return m_scratchPad; } private: Q_DISABLE_COPY(KisScratchPadDefaultBounds) KisScratchPad *m_scratchPad; }; KisScratchPad::KisScratchPad(QWidget *parent) : QWidget(parent) , m_toolMode(HOVERING) , m_paintLayer(0) , m_displayProfile(0) , m_resourceProvider(0) { setAutoFillBackground(false); setMouseTracking(true); m_cursor = KisCursor::load("tool_freehand_cursor.png", 5, 5); m_colorPickerCursor = KisCursor::load("color-picker_image_foreground.xpm", 5, 5); setCursor(m_cursor); KisConfig cfg(true); QImage checkImage = KisCanvasWidgetBase::createCheckersImage(cfg.checkSize()); m_checkBrush = QBrush(checkImage); // We are not supposed to use updates here, // so just set the listener to null m_updateScheduler = new KisUpdateScheduler(0); m_undoStore = new KisSurrogateUndoStore(); m_undoAdapter = new KisPostExecutionUndoAdapter(m_undoStore, m_updateScheduler); m_nodeListener = new KisScratchPadNodeListener(this); connect(this, SIGNAL(sigUpdateCanvas(QRect)), SLOT(slotUpdateCanvas(QRect)), Qt::QueuedConnection); // filter will be deleted by the QObject hierarchy m_eventFilter = new KisScratchPadEventFilter(this); m_infoBuilder = new KisPaintingInformationBuilder(); m_scaleBorderWidth = 1; } KisScratchPad::~KisScratchPad() { delete m_infoBuilder; delete m_undoAdapter; delete m_undoStore; delete m_updateScheduler; delete m_nodeListener; } KisScratchPad::Mode KisScratchPad::modeFromButton(Qt::MouseButton button) const { return button == Qt::NoButton ? HOVERING : button == Qt::MidButton ? PANNING : button == Qt::RightButton ? PICKING : PAINTING; } void KisScratchPad::pointerPress(KoPointerEvent *event) { if (isModeManuallySet == false) { if (m_toolMode != HOVERING) return; m_toolMode = modeFromButton(event->button()); } // see if we are pressing down with a button if (event->button() == Qt::LeftButton || event->button() == Qt::MidButton || event->button() == Qt::RightButton) { isMouseDown = true; } else { isMouseDown = false; } // if mouse is down, we are doing one of three things if(isMouseDown) { if (m_toolMode == PAINTING) { beginStroke(event); event->accept(); } else if (m_toolMode == PANNING) { beginPan(event); event->accept(); } else if (m_toolMode == PICKING) { pick(event); event->accept(); } } } void KisScratchPad::pointerRelease(KoPointerEvent *event) { isMouseDown = false; if (isModeManuallySet == false) { if (modeFromButton(event->button()) != m_toolMode) return; if (m_toolMode == PAINTING) { endStroke(event); m_toolMode = HOVERING; event->accept(); } else if (m_toolMode == PANNING) { endPan(event); m_toolMode = HOVERING; event->accept(); } else if (m_toolMode == PICKING) { event->accept(); m_toolMode = HOVERING; } } else { if (m_toolMode == PAINTING) { endStroke(event); } else if (m_toolMode == PANNING) { endPan(event); } event->accept(); } } void KisScratchPad::pointerMove(KoPointerEvent *event) { if(event && event->point.isNull() == false) { m_helper->cursorMoved(documentToWidget().map(event->point)); } if (isMouseDown) { if (m_toolMode == PAINTING) { doStroke(event); event->accept(); } else if (m_toolMode == PANNING) { doPan(event); event->accept(); } else if (m_toolMode == PICKING) { pick(event); event->accept(); } } } void KisScratchPad::beginStroke(KoPointerEvent *event) { m_helper->initPaint(event, documentToWidget().map(event->point), 0, 0, m_updateScheduler, m_paintLayer, m_paintLayer->paintDevice()->defaultBounds()); } void KisScratchPad::doStroke(KoPointerEvent *event) { m_helper->paintEvent(event); } void KisScratchPad::endStroke(KoPointerEvent *event) { Q_UNUSED(event); m_helper->endPaint(); } void KisScratchPad::beginPan(KoPointerEvent *event) { setCursor(QCursor(Qt::ClosedHandCursor)); m_panDocPoint = event->point; } void KisScratchPad::doPan(KoPointerEvent *event) { QPointF docOffset = event->point - m_panDocPoint; m_translateTransform.translate(-docOffset.x(), -docOffset.y()); updateTransformations(); update(); } void KisScratchPad::endPan(KoPointerEvent *event) { Q_UNUSED(event); // the normal brush editor scratchpad reverts back to paint mode when done if(isModeManuallySet) { setCursor(QCursor(Qt::OpenHandCursor)); } else { setCursor(m_cursor); } } void KisScratchPad::pick(KoPointerEvent *event) { KoColor color; if (KisToolUtils::pickColor(color, m_paintLayer->projection(), event->point.toPoint())) { emit colorSelected(color); } } void KisScratchPad::setOnScreenResolution(qreal scaleX, qreal scaleY) { m_scaleBorderWidth = BORDER_SIZE(qMax(scaleX, scaleY)); m_scaleTransform = QTransform::fromScale(scaleX, scaleY); updateTransformations(); update(); } QTransform KisScratchPad::documentToWidget() const { return m_translateTransform.inverted() * m_scaleTransform; } QTransform KisScratchPad::widgetToDocument() const { return m_scaleTransform.inverted() * m_translateTransform; } void KisScratchPad::updateTransformations() { m_eventFilter->setWidgetToDocumentTransform(widgetToDocument()); } QRect KisScratchPad::imageBounds() const { return widgetToDocument().mapRect(rect()); } void KisScratchPad::imageUpdated(const QRect &rect) { emit sigUpdateCanvas(documentToWidget().mapRect(QRectF(rect)).toAlignedRect()); } void KisScratchPad::slotUpdateCanvas(const QRect &rect) { update(rect); } void KisScratchPad::paintEvent ( QPaintEvent * event ) { if(!m_paintLayer) return; QRectF imageRect = widgetToDocument().mapRect(QRectF(event->rect())); QRect alignedImageRect = imageRect.adjusted(-m_scaleBorderWidth, -m_scaleBorderWidth, m_scaleBorderWidth, m_scaleBorderWidth).toAlignedRect(); QPointF offset = alignedImageRect.topLeft(); m_paintLayer->projectionPlane()->recalculate(alignedImageRect, m_paintLayer); KisPaintDeviceSP projection = m_paintLayer->projection(); QImage image = projection->convertToQImage(m_displayProfile, alignedImageRect.x(), alignedImageRect.y(), alignedImageRect.width(), alignedImageRect.height(), KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags()); QPainter gc(this); gc.fillRect(event->rect(), m_checkBrush); gc.setRenderHints(QPainter::SmoothPixmapTransform); gc.drawImage(QRectF(event->rect()), image, imageRect.translated(-offset)); QBrush brush(Qt::lightGray); QPen pen(brush, 1, Qt::DotLine); gc.setPen(pen); if (m_cutoutOverlay.isValid()) { gc.drawRect(m_cutoutOverlay); } if(!isEnabled()) { QColor color(Qt::lightGray); color.setAlphaF(0.5); QBrush disabledBrush(color); gc.fillRect(event->rect(), disabledBrush); } gc.end(); } void KisScratchPad::setupScratchPad(KisCanvasResourceProvider* resourceProvider, const QColor &defaultColor) { m_resourceProvider = resourceProvider; KisConfig cfg(true); setDisplayProfile(cfg.displayProfile(QApplication::desktop()->screenNumber(this))); connect(m_resourceProvider, SIGNAL(sigDisplayProfileChanged(const KoColorProfile*)), SLOT(setDisplayProfile(const KoColorProfile*))); connect(m_resourceProvider, SIGNAL(sigOnScreenResolutionChanged(qreal,qreal)), SLOT(setOnScreenResolution(qreal,qreal))); connect(this, SIGNAL(colorSelected(KoColor)), m_resourceProvider, SLOT(slotSetFGColor(KoColor))); m_helper.reset(new KisToolFreehandHelper(m_infoBuilder, m_resourceProvider->resourceManager())); - m_defaultColor = KoColor(defaultColor, KoColorSpaceRegistry::instance()->rgb8()); + setFillColor(defaultColor); KisPaintDeviceSP paintDevice = new KisPaintDevice(m_defaultColor.colorSpace(), "scratchpad"); m_paintLayer = new KisPaintLayer(0, "ScratchPad", OPACITY_OPAQUE_U8, paintDevice); m_paintLayer->setGraphListener(m_nodeListener); m_paintLayer->paintDevice()->setDefaultBounds(new KisScratchPadDefaultBounds(this)); fillDefault(); } void KisScratchPad::setCutoutOverlayRect(const QRect& rc) { m_cutoutOverlay = rc; } void KisScratchPad::setModeManually(bool value) { isModeManuallySet = value; } void KisScratchPad::setModeType(QString mode) { if (mode.toLower() == "painting") { m_toolMode = PAINTING; setCursor(m_cursor); } else if (mode.toLower() == "panning") { m_toolMode = PANNING; setCursor(Qt::OpenHandCursor); } else if (mode.toLower() == "colorpicking") { m_toolMode = PICKING; setCursor(m_colorPickerCursor); } } QImage KisScratchPad::cutoutOverlay() const { if(!m_paintLayer) return QImage(); KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice(); QRect rc = widgetToDocument().mapRect(m_cutoutOverlay); QImage rawImage = paintDevice->convertToQImage(0, rc.x(), rc.y(), rc.width(), rc.height(), KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags()); QImage scaledImage = rawImage.scaled(m_cutoutOverlay.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); return scaledImage; } void KisScratchPad::setPresetImage(const QImage& image) { m_presetImage = image; } void KisScratchPad::paintCustomImage(const QImage& loadedImage) { // this is 99% copied from the normal paintPresetImage() // we don't want to save over the preset image, so we don't // want to store it in the m_presetImage if(!m_paintLayer) return; KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice(); QRect overlayRect = widgetToDocument().mapRect(m_cutoutOverlay); QRect imageRect(QPoint(), overlayRect.size()); QImage scaledImage = loadedImage.scaled(overlayRect.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); KisPaintDeviceSP device = new KisPaintDevice(paintDevice->colorSpace()); device->convertFromQImage(scaledImage, 0); KisPainter painter(paintDevice); painter.beginTransaction(); painter.bitBlt(overlayRect.topLeft(), device, imageRect); painter.deleteTransaction(); update(); } void KisScratchPad::paintPresetImage() { if(!m_paintLayer) return; KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice(); QRect overlayRect = widgetToDocument().mapRect(m_cutoutOverlay); QRect imageRect(QPoint(), overlayRect.size()); QImage scaledImage = m_presetImage.scaled(overlayRect.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); KisPaintDeviceSP device = new KisPaintDevice(paintDevice->colorSpace()); device->convertFromQImage(scaledImage, 0); KisPainter painter(paintDevice); painter.beginTransaction(); painter.bitBlt(overlayRect.topLeft(), device, imageRect); painter.deleteTransaction(); update(); } void KisScratchPad::setDisplayProfile(const KoColorProfile *colorProfile) { if (colorProfile) { m_displayProfile = colorProfile; QWidget::update(); } } void KisScratchPad::fillDefault() { if(!m_paintLayer) return; KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice(); KisTransaction t(paintDevice); paintDevice->setDefaultPixel(m_defaultColor); paintDevice->clear(); t.end(); update(); } void KisScratchPad::fillTransparent() { if(!m_paintLayer) return; KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice(); QColor transQColor(0,0,0,0); KoColor transparentColor(transQColor, KoColorSpaceRegistry::instance()->rgb8()); transparentColor.setOpacity(0.0); KisTransaction t(paintDevice); paintDevice->setDefaultPixel(transparentColor); paintDevice->clear(); t.end(); update(); } +void KisScratchPad::setFillColor(QColor newColor) +{ + m_defaultColor = KoColor(newColor, KoColorSpaceRegistry::instance()->rgb8()); +} + void KisScratchPad::fillGradient() { if(!m_paintLayer) return; KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice(); KoAbstractGradientSP gradient = m_resourceProvider->currentGradient(); QRect gradientRect = widgetToDocument().mapRect(rect()); KisTransaction t(paintDevice); paintDevice->clear(); KisGradientPainter painter(paintDevice); painter.setGradient(gradient); painter.setGradientShape(KisGradientPainter::GradientShapeLinear); painter.paintGradient(gradientRect.topLeft(), gradientRect.bottomRight(), KisGradientPainter::GradientRepeatNone, 0.2, false, gradientRect.left(), gradientRect.top(), gradientRect.width(), gradientRect.height()); t.end(); update(); } void KisScratchPad::fillBackground() { if(!m_paintLayer) return; KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice(); KisTransaction t(paintDevice); paintDevice->setDefaultPixel(m_resourceProvider->bgColor()); paintDevice->clear(); t.end(); update(); } void KisScratchPad::fillLayer() { if(!m_paintLayer) return; KisPaintDeviceSP paintDevice = m_paintLayer->paintDevice(); QRect sourceRect(0, 0, paintDevice->exactBounds().width(), paintDevice->exactBounds().height()); KisPainter painter(paintDevice); painter.beginTransaction(); painter.bitBlt(QPoint(0, 0), m_resourceProvider->currentImage()->projection(), sourceRect); painter.deleteTransaction(); update(); } diff --git a/libs/ui/widgets/kis_scratch_pad.h b/libs/ui/widgets/kis_scratch_pad.h index 42b2eb0b7c..a3d56cfe86 100644 --- a/libs/ui/widgets/kis_scratch_pad.h +++ b/libs/ui/widgets/kis_scratch_pad.h @@ -1,197 +1,199 @@ /* This file is part of the KDE project * Copyright 2010 (C) Boudewijn Rempt * Copyright 2011 (C) Dmitry Kazakov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIS_SCRATCH_PAD_H #define KIS_SCRATCH_PAD_H #include #include #include #include #include #include #include class QColor; class KoColorProfile; class KoPointerEvent; class KisCanvasResourceProvider; class KisUpdateScheduler; class KisUndoStore; class KisPostExecutionUndoAdapter; class KisScratchPadEventFilter; class KisPaintingInformationBuilder; class KisToolFreehandHelper; class KisNodeGraphListener; /** * A scratchpad is a painting canvas with only one zoomlevel and based on * a paint layer, not on a KisImage. It can have a blank, tiled background or * a gradient background. */ class KRITAUI_EXPORT KisScratchPad : public QWidget { Q_OBJECT public: void setupScratchPad(KisCanvasResourceProvider* resourceProvider, const QColor &defaultColor); KisScratchPad(QWidget *parent = 0); ~KisScratchPad() override; /// set the specified rect as the area taken for @see cutoutOverlay void setCutoutOverlayRect(const QRect&rc); /** * keep track of if our scratchpad is in paint, pan, or color pick mode * Set to true if there is a GUI controlling current mode * If this is false, the modes are only changed with various mouse click shortcuts */ void setModeManually(bool value); /** * @brief change the mode explicitly to paint, mix, or pan * @param what mode to change it to */ void setModeType(QString modeName); /// return the contents of the area under the cutoutOverlay rect QImage cutoutOverlay() const; // A callback for our own node graph listener void imageUpdated(const QRect &rect); // A callback for scratch pad default bounds QRect imageBounds() const; // Called by the event filter void pointerPress(KoPointerEvent *event); void pointerRelease(KoPointerEvent *event); void pointerMove(KoPointerEvent *event); public Q_SLOTS: void fillDefault(); void fillGradient(); void fillBackground(); void fillTransparent(); + void setFillColor(QColor newColor); + /// Fill the area with what is on your current canvas void fillLayer(); /** * Set the icon of the current preset */ void setPresetImage(const QImage& image); /** * Paint the icon of the current preset inside the * cutout overlay * * \see setPresetImage */ void paintPresetImage(); /** * Paint the icon of a custom image that is being loaded * */ void paintCustomImage(const QImage& loadedImage); private Q_SLOTS: void setOnScreenResolution(qreal scaleX, qreal scaleY); void setDisplayProfile(const KoColorProfile* colorProfile); void slotUpdateCanvas(const QRect &rect); Q_SIGNALS: void colorSelected(const KoColor& color); void sigUpdateCanvas(const QRect &rect); protected: void paintEvent ( QPaintEvent * event ) override; private: void beginStroke(KoPointerEvent *event); void doStroke(KoPointerEvent *event); void endStroke(KoPointerEvent *event); void beginPan(KoPointerEvent *event); void doPan(KoPointerEvent *event); void endPan(KoPointerEvent *event); void pick(KoPointerEvent *event); void updateTransformations(); QTransform documentToWidget() const; QTransform widgetToDocument() const; private: enum Mode { PAINTING, HOVERING, PANNING, PICKING }; Mode modeFromButton(Qt::MouseButton button) const; private: KoColor m_defaultColor; Mode m_toolMode; bool isModeManuallySet = false; bool isMouseDown = false; KisPaintLayerSP m_paintLayer; const KoColorProfile* m_displayProfile; QCursor m_cursor; QCursor m_colorPickerCursor; QRect m_cutoutOverlay; QBrush m_checkBrush; KisCanvasResourceProvider* m_resourceProvider; KisUpdateScheduler *m_updateScheduler; KisUndoStore *m_undoStore; KisPostExecutionUndoAdapter *m_undoAdapter; KisNodeGraphListener *m_nodeListener; KisScratchPadEventFilter *m_eventFilter; QScopedPointer m_helper; KisPaintingInformationBuilder *m_infoBuilder; QTransform m_scaleTransform; QTransform m_translateTransform; QPointF m_panDocPoint; int m_scaleBorderWidth; QImage m_presetImage; }; #endif // KIS_SCRATCH_PAD_H diff --git a/plugins/extensions/pykrita/sip/krita/Scratchpad.sip b/plugins/extensions/pykrita/sip/krita/Scratchpad.sip index 1210b0b6c9..6c60816a26 100644 --- a/plugins/extensions/pykrita/sip/krita/Scratchpad.sip +++ b/plugins/extensions/pykrita/sip/krita/Scratchpad.sip @@ -1,15 +1,16 @@ class Scratchpad : public QWidget /NoDefaultCtors/ { %TypeHeaderCode #include "Scratchpad.h" %End public: Scratchpad(View* view , const QString & defaultColor, QWidget* parent /TransferThis/ = 0); virtual ~Scratchpad(); public Q_SLOTS: void clear(); void setModeManually(bool value); void setMode(QString modeName); + void setFillColor(QColor color); };