diff --git a/libs/libkis/Selection.cpp b/libs/libkis/Selection.cpp index 4621fa8f65..0d4ed320fd 100644 --- a/libs/libkis/Selection.cpp +++ b/libs/libkis/Selection.cpp @@ -1,199 +1,194 @@ /* * 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 "Selection.h" #include #include #include #include #include struct Selection::Private { Private() {} KisSelectionSP selection; }; Selection::Selection(KisSelectionSP selection, QObject *parent) : QObject(parent) , d(new Private) { d->selection = selection; } Selection::Selection(QObject *parent) : QObject(parent) , d(new Private) { d->selection = new KisSelection(); } Selection::~Selection() { delete d; } int Selection::width() const { if (!d->selection) return 0; return d->selection->selectedExactRect().width(); } int Selection::height() const { if (!d->selection) return 0; return d->selection->selectedExactRect().height(); } int Selection::x() const { if (!d->selection) return 0; return d->selection->x(); } int Selection::y() const { if (!d->selection) return 0; return 0; } void Selection::move(int x, int y) { if (!d->selection) return; } void Selection::clear() { if (!d->selection) return; d->selection->clear(); } void Selection::contract(int value) { } void Selection::cut(Node* node) { } void Selection::paste(Node *source, Node*destination) { } void Selection::deselect() { if (!d->selection) return; } void Selection::expand(int value) { if (!d->selection) return; } void Selection::feather(int value) { if (!d->selection) return; } void Selection::fill(Node* node) { if (!d->selection) return; } void Selection::grow(int value) { if (!d->selection) return; } void Selection::invert() { if (!d->selection) return; } void Selection::resize(int w, int h) { if (!d->selection) return; } -void Selection::rotate(int degrees) -{ - if (!d->selection) return; -} - void Selection::select(int x, int y, int w, int h, int value) { if (!d->selection) return; d->selection->pixelSelection()->select(QRect(x, y, w, h), value); } void Selection::selectAll(Node *node, int value) { if (!d->selection) return; d->selection->pixelSelection()->select(node->node()->exactBounds(), value); } void Selection::replace(Selection *selection) { d->selection->pixelSelection()->applySelection(selection->selection(), SELECTION_REPLACE); } void Selection::add(Selection *selection) { d->selection->pixelSelection()->applySelection(selection->selection(), SELECTION_ADD); } void Selection::subtract(Selection *selection) { d->selection->pixelSelection()->applySelection(selection->selection(), SELECTION_SUBTRACT); } void Selection::intersect(Selection *selection) { d->selection->pixelSelection()->applySelection(selection->selection(), SELECTION_INTERSECT); } QByteArray Selection::pixelData(int x, int y, int w, int h) const { QByteArray ba; if (!d->selection) return ba; KisPaintDeviceSP dev = d->selection->projection(); quint8 *data = new quint8[w * h]; dev->readBytes(data, x, y, w, h); ba = QByteArray((const char*)data, (int)(w * h)); delete[] data; return ba; } void Selection::setPixelData(QByteArray value, int x, int y, int w, int h) { if (!d->selection) return; KisPixelSelectionSP dev = d->selection->pixelSelection(); if (!dev) return; dev->writeBytes((const quint8*)value.constData(), x, y, w, h); } KisSelectionSP Selection::selection() const { return d->selection; } diff --git a/libs/libkis/Selection.h b/libs/libkis/Selection.h index c4cda378c5..0ca74972fe 100644 --- a/libs/libkis/Selection.h +++ b/libs/libkis/Selection.h @@ -1,129 +1,127 @@ /* * 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_SELECTION_H #define LIBKIS_SELECTION_H #include #include "kritalibkis_export.h" #include "libkis.h" #include /** * Selection */ class KRITALIBKIS_EXPORT Selection : public QObject { Q_OBJECT public: Selection(KisSelectionSP selection, QObject *parent = 0); explicit Selection(QObject *parent = 0); virtual ~Selection(); public Q_SLOTS: int width() const; int height() const; int x() const; int y() const; void move(int x, int y); void clear(); void contract(int value); void cut(Node* node); void paste(Node *source, Node* destination); void deselect(); void expand(int value); void feather(int value); void fill(Node* node); void grow(int value); void invert(); void resize(int w, int h); - void rotate(int degrees); - void select(int x, int y, int w, int h, int value); void selectAll(Node *node, int value); void replace(Selection *selection); void add(Selection *selection); void subtract(Selection *selection); void intersect(Selection *selection); /** * @brief pixelData reads the given rectangle from the Selection's mask and returns it as a * byte array. The pixel data starts top-left, and is ordered row-first. * * The byte array will contain one byte for every pixel, representing the selectedness. 0 * is totally unselected, 255 is fully selected. * * You can read outside the Selection's boundaries; those pixels will be unselected. * * The byte array is a copy of the original selection data. * @param x x position from where to start reading * @param y y position from where to start reading * @param w row length to read * @param h number of rows to read * @return a QByteArray with the pixel data. The byte array may be empty. */ QByteArray pixelData(int x, int y, int w, int h) const; /** * @brief setPixelData writes the given bytes, of which there must be enough, into the * Selection. * * @param value the byte array representing the pixels. There must be enough bytes available. * Krita will take the raw pointer from the QByteArray and start reading, not stopping before * (w * h) bytes are read. * * @param x the x position to start writing from * @param y the y position to start writing from * @param w the width of each row * @param h the number of rows to write */ void setPixelData(QByteArray value, int x, int y, int w, int h); private: KisSelectionSP selection() const; struct Private; Private *const d; }; #endif // LIBKIS_SELECTION_H diff --git a/plugins/extensions/pykrita/sip/krita/Selection.sip b/plugins/extensions/pykrita/sip/krita/Selection.sip index f8a8778794..fc87585157 100644 --- a/plugins/extensions/pykrita/sip/krita/Selection.sip +++ b/plugins/extensions/pykrita/sip/krita/Selection.sip @@ -1,37 +1,36 @@ class Selection : QObject { %TypeHeaderCode #include "Selection.h" %End Selection(const Selection & __0); public: Selection(QObject* parent /TransferThis/ = 0); virtual ~Selection(); public Q_SLOTS: int width() const; int height() const; int x() const; int y() const; void move(int x, int y); void clear(); void contract(int value); void cut(Node *node); void paste(Node *source, Node*destination); void deselect(); void expand(int value); void feather(int value); void fill(Node* node); void grow(int value); void invert(); void resize(int w, int h); - void rotate(int degrees); void select(int x, int y, int w, int h, int value); void selectAll(Node* node, int value); void replace(Selection *selection); void add(Selection *selection); void subtract(Selection *selection); void intersect(Selection *selection); QByteArray pixelData(int x, int y, int w, int h) const; void setPixelData(QByteArray value, int x, int y, int w, int h); private: };