diff --git a/libs/libkis/View.cpp b/libs/libkis/View.cpp index 57571f78c4..ce7006c7ab 100644 --- a/libs/libkis/View.cpp +++ b/libs/libkis/View.cpp @@ -1,317 +1,309 @@ /* * 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 "kis_scratch_pad.h" #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; }; 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(QColor bgColor) +Scratchpad *View::createScratchpad() { - if(d->view) { - - d->view->addScratchPad(); - - // KisScratchPad *newScratchpad = new KisScratchPad(d->view); // = new KisScratchPad(d->view); - // d->view->scratchpads().append(new KisScratchPad(d->view)); - // d->view->scratchpads.last()->setupScratchPad(d->view->resourceProvider(), bgColor); - } + if (!d->view) return 0; - return dynamic_cast(d->view->scratchpads().last()); + d->view->addScratchPad(); + return static_cast(d->view->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(); - qDebug() << "how many scratchpads are there C++ " << QString::number(d->view->scratchpads().size() ); + // qDebug() << "how many scratchpads are there C++ " << QString::number(d->view->scratchpads().size() ); // create python object from C++ object and calls QList newList; for (int i = 0; i < d->view->scratchpads().size(); ++i) { newList.append(new Scratchpad(this->canvas()->view(), Qt::white)); // maybe also need to set properties this way from teh scratchpad... setting image data, and other properties // newList.last().loadScratchpad(....) } - - return newList; } diff --git a/libs/libkis/View.h b/libs/libkis/View.h index a70950d5c7..5973de72c4 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(QColor bgColor); + Scratchpad *createScratchpad(); /** * @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/plugins/extensions/pykrita/sip/krita/View.sip b/plugins/extensions/pykrita/sip/krita/View.sip index 98dcc42afd..c0c676ecb5 100644 --- a/plugins/extensions/pykrita/sip/krita/View.sip +++ b/plugins/extensions/pykrita/sip/krita/View.sip @@ -1,56 +1,57 @@ class View : QObject { %TypeHeaderCode #include "View.h" %End View(const View & __0); public: bool operator==(const View &other) const; bool operator!=(const View &other) const; public Q_SLOTS: Window * window() const /Factory/; Document * document() const /Factory/; void setDocument(Document *document); bool visible() const; void setVisible(); Canvas * canvas() const /Factory/; void activateResource(Resource *resource); + Scratchpad * createScratchpad(); ManagedColor *foregroundColor() const /Factory/; void setForeGroundColor(ManagedColor *color); ManagedColor *backgroundColor() const /Factory/; void setBackGroundColor(ManagedColor *color); Resource *currentBrushPreset() const /Factory/; void setCurrentBrushPreset(Resource *resource); Resource *currentPattern() const /Factory/; void setCurrentPattern(Resource *resournce); Resource *currentGradient() const /Factory/; 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); QList selectedNodes() const /Factory/; QList scratchpads() const; private: };