diff --git a/libs/libkis/CMakeLists.txt b/libs/libkis/CMakeLists.txt index 2d6ed39361..d69ff46038 100644 --- a/libs/libkis/CMakeLists.txt +++ b/libs/libkis/CMakeLists.txt @@ -1,49 +1,50 @@ set(kritalibkis_LIB_SRCS Canvas.cpp Channel.cpp DockWidget.cpp DockWidgetFactoryBase.cpp Document.cpp Filter.cpp InfoObject.cpp Krita.cpp ManagedColor.cpp Node.cpp Notifier.cpp PresetChooser Palette.cpp PaletteView.cpp + Swatch.cpp Resource.cpp Selection.cpp View.cpp Extension.cpp Window.cpp GroupLayer.cpp CloneLayer.cpp FileLayer.cpp FilterLayer.cpp FillLayer.cpp VectorLayer.cpp FilterMask.cpp SelectionMask.cpp Shape.cpp GroupShape.cpp LibKisUtils.cpp ) add_library(kritalibkis SHARED ${kritalibkis_LIB_SRCS} ) generate_export_header(kritalibkis) target_link_libraries(kritalibkis kritaui kritaimage kritaversion) target_link_libraries(kritalibkis LINK_INTERFACE_LIBRARIES kritaimage kritaui) set_target_properties(kritalibkis PROPERTIES VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION} ) install(TARGETS kritalibkis ${INSTALL_TARGETS_DEFAULT_ARGS}) add_subdirectory(tests) diff --git a/libs/libkis/ManagedColor.cpp b/libs/libkis/ManagedColor.cpp index fb3b7abac1..75199bdbcd 100644 --- a/libs/libkis/ManagedColor.cpp +++ b/libs/libkis/ManagedColor.cpp @@ -1,176 +1,174 @@ /* * Copyright (C) 2017 Boudewijn Rempt * * 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 "ManagedColor.h" #include #include #include #include #include #include #include #include #include #include struct ManagedColor::Private { KoColor color; }; - - ManagedColor::ManagedColor(QObject *parent) : QObject(parent) , d(new Private()) { // Default black rgb color } ManagedColor::ManagedColor(const QString &colorModel, const QString &colorDepth, const QString &colorProfile, QObject *parent) : QObject(parent) , d(new Private()) { const KoColorSpace *colorSpace = KoColorSpaceRegistry::instance()->colorSpace(colorModel, colorDepth, colorProfile); if (colorSpace) { d->color = KoColor(colorSpace); } } ManagedColor::ManagedColor(KoColor color, QObject *parent) : QObject(parent) , d(new Private()) { d->color = color; } ManagedColor::~ManagedColor() { } bool ManagedColor::operator==(const ManagedColor &other) const { return d->color == other.d->color; } QColor ManagedColor::colorForCanvas(Canvas *canvas) const { QColor c = QColor(0,0,0); if (canvas && canvas->displayColorConverter() && canvas->displayColorConverter()->displayRendererInterface()) { KoColorDisplayRendererInterface *converter = canvas->displayColorConverter()->displayRendererInterface(); if (converter) { c = converter->toQColor(d->color); } else { c = KoDumbColorDisplayRenderer::instance()->toQColor(d->color); } } else { c = KoDumbColorDisplayRenderer::instance()->toQColor(d->color); } return c; } QString ManagedColor::colorDepth() const { return d->color.colorSpace()->colorDepthId().id(); } QString ManagedColor::colorModel() const { return d->color.colorSpace()->colorModelId().id(); } QString ManagedColor::colorProfile() const { return d->color.colorSpace()->profile()->name(); } bool ManagedColor::setColorProfile(const QString &colorProfile) { const KoColorProfile *profile = KoColorSpaceRegistry::instance()->profileByName(colorProfile); if (!profile) return false; d->color.setProfile(profile); return true; } bool ManagedColor::setColorSpace(const QString &colorModel, const QString &colorDepth, const QString &colorProfile) { const KoColorSpace *colorSpace = KoColorSpaceRegistry::instance()->colorSpace(colorModel, colorDepth, colorProfile); if (!colorSpace) return false; d->color.convertTo(colorSpace); return true; } QVector ManagedColor::components() const { QVector values(d->color.colorSpace()->channelCount()); d->color.colorSpace()->normalisedChannelsValue(d->color.data(), values); return values; } QVector ManagedColor::componentsOrdered() const { QVector valuesUnsorted = components(); QVector values(d->color.colorSpace()->channelCount()); for (int i=0; icolor.colorSpace()->channels()); values[location] = valuesUnsorted[i]; } return values; } void ManagedColor::setComponents(const QVector &values) { d->color.colorSpace()->fromNormalisedChannelsValue(d->color.data(), values); } QString ManagedColor::toXML() const { QDomDocument doc; QDomElement root = doc.createElement("Color"); root.setAttribute("bitdepth", colorDepth()); doc.appendChild(root); d->color.toXML(doc, root); return doc.toString(); } void ManagedColor::fromXML(const QString &xml) { QDomDocument doc; doc.setContent(xml); QDomElement e = doc.documentElement(); QDomElement c = e.firstChildElement("Color"); KoColor kc; if (!c.isNull()) { QString colorDepthId = c.attribute("bitdepth", Integer8BitsColorDepthID.id()); d->color = KoColor::fromXML(c, colorDepthId); } } QString ManagedColor::toQString() { return KoColor::toQString(d->color); } KoColor ManagedColor::color() const { return d->color; } diff --git a/libs/libkis/ManagedColor.h b/libs/libkis/ManagedColor.h index 2a9da5aae6..190a7e00bd 100644 --- a/libs/libkis/ManagedColor.h +++ b/libs/libkis/ManagedColor.h @@ -1,210 +1,212 @@ /* * Copyright (C) 2017 Boudewijn Rempt * * 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 MANAGEDCOLOR_H #define MANAGEDCOLOR_H #include #include #include #include "kritalibkis_export.h" #include "libkis.h" class KoColor; /** * @brief The ManagedColor class is a class to handle colors that are color managed. * A managed color is a color of which we know the model(RGB, LAB, CMYK, etc), the bitdepth and * the specific properties of its colorspace, such as the whitepoint, chromacities, trc, etc, as represented * by the color profile. * * Krita has two color management systems. LCMS and OCIO. * LCMS is the one handling the ICC profile stuff, and the major one handling that ManagedColor deals with. * OCIO support is only in the display of the colors. ManagedColor has some support for it in colorForCanvas() * * All colors in Krita are color managed. QColors are understood as RGB-type colors in the sRGB space. * * We recommend you make a color like this: * * @code * colorYellow = ManagedColor("RGBA", "U8", "") * QVector yellowComponents = colorYellow.components() * yellowComponents[0] = 1.0 * yellowComponents[1] = 1.0 * yellowComponents[2] = 0 * yellowComponents[3] = 1.0 * * colorYellow.setComponents(yellowComponents) * QColor yellow = colorYellow.colorForCanvas(canvas) * @endcode */ class KRITALIBKIS_EXPORT ManagedColor : public QObject { Q_OBJECT public: /** * @brief ManagedColor * Create a ManagedColor that is black and transparent. */ explicit ManagedColor(QObject *parent = 0); /** * @brief ManagedColor create a managed color with the given color space properties. * @see setColorModel() for more details. */ ManagedColor(const QString &colorModel, const QString &colorDepth, const QString &colorProfile, QObject *parent = 0); ManagedColor(KoColor color, QObject *parent = 0); ~ManagedColor() override; bool operator==(const ManagedColor &other) const; /** * @brief colorForCanvas * @param canvas the canvas whose color management you'd like to use. In Krita, different views have * separate canvasses, and these can have different OCIO configurations active. * @return the QColor as it would be displaying on the canvas. This result can be used to draw widgets with * the correct configuration applied. */ QColor colorForCanvas(Canvas *canvas) const; /** * colorDepth A string describing the color depth of the image: *
    *
  • U8: unsigned 8 bits integer, the most common type
  • *
  • U16: unsigned 16 bits integer
  • *
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • *
  • F32: 32 bits floating point
  • *
* @return the color depth. */ QString colorDepth() const; /** * @brief colorModel retrieve the current color model of this document: *
    *
  • A: Alpha mask
  • *
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • *
  • XYZA: XYZ with alpha channel
  • *
  • LABA: LAB with alpha channel
  • *
  • CMYKA: CMYK with alpha channel
  • *
  • GRAYA: Gray with alpha channel
  • *
  • YCbCrA: YCbCr with alpha channel
  • *
* @return the internal color model string. */ QString colorModel() const; /** * @return the name of the current color profile */ QString colorProfile() const; /** * @brief setColorProfile set the color profile of the image to the given profile. The profile has to * be registered with krita and be compatible with the current color model and depth; the image data * is not converted. * @param colorProfile * @return false if the colorProfile name does not correspond to to a registered profile or if assigning * the profile failed. */ bool setColorProfile(const QString &colorProfile); /** * @brief setColorSpace convert the nodes and the image to the given colorspace. The conversion is * done with Perceptual as intent, High Quality and No LCMS Optimizations as flags and no blackpoint * compensation. * * @param colorModel A string describing the color model of the image: *
    *
  • A: Alpha mask
  • *
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • *
  • XYZA: XYZ with alpha channel
  • *
  • LABA: LAB with alpha channel
  • *
  • CMYKA: CMYK with alpha channel
  • *
  • GRAYA: Gray with alpha channel
  • *
  • YCbCrA: YCbCr with alpha channel
  • *
* @param colorDepth A string describing the color depth of the image: *
    *
  • U8: unsigned 8 bits integer, the most common type
  • *
  • U16: unsigned 16 bits integer
  • *
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • *
  • F32: 32 bits floating point
  • *
* @param colorProfile a valid color profile for this color model and color depth combination. * @return false the combination of these arguments does not correspond to a colorspace. */ bool setColorSpace(const QString &colorModel, const QString &colorDepth, const QString &colorProfile); /** * @brief components * @return a QVector containing the channel/components of this color normalized. This includes the alphachannel. */ QVector components() const; /** * @brief componentsOrdered() * @return same as Components, except the values are ordered to the display. */ QVector componentsOrdered() const; /** * @brief setComponents * Set the channel/components with normalized values. For integer colorspace, this obviously means the limit * is between 0.0-1.0, but for floating point colorspaces, 2.4 or 103.5 are still meaningful (if bright) values. * @param values the QVector containing the new channel/component values. These should be normalized. */ void setComponents(const QVector &values); /** * Serialize this color following Create's swatch color specification available * at http://create.freedesktop.org/wiki/index.php/Swatches_-_colour_file_format */ QString toXML() const; /** * Unserialize a color following Create's swatch color specification available * at http://create.freedesktop.org/wiki/index.php/Swatches_-_colour_file_format * * @param XXX * * @return the unserialized color, or an empty color object if the function failed * to unserialize the color */ void fromXML(const QString &xml); /** * @brief toQString create a user-visible string of the channel names and the channel values * @param color the color to create the string from * @return a string that can be used to display the values of this color to the user. */ QString toQString(); private: friend class View; friend class PaletteView; + friend class Swatch; + KoColor color() const; struct Private; const QScopedPointer d; }; #endif // MANAGEDCOLOR_H diff --git a/libs/libkis/Palette.cpp b/libs/libkis/Palette.cpp index a298aaf4b2..19fc2523e4 100644 --- a/libs/libkis/Palette.cpp +++ b/libs/libkis/Palette.cpp @@ -1,163 +1,155 @@ /* * Copyright (c) 2017 Wolthera van Hövell tot Westerflier * * 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 "Palette.h" #include #include #include #include #include struct Palette::Private { KoColorSet *palette {0}; }; Palette::Palette(Resource *resource): d(new Private()) { d->palette = dynamic_cast(resource->resource()); } Palette::~Palette() { delete d; } int Palette::numberOfEntries() const { if (!d->palette) return 0; return d->palette->colorCount(); } int Palette::columnCount() { if (!d->palette) return 0; return d->palette->columnCount(); } void Palette::setColumnCount(int columns) { if (d->palette) d->palette->setColumnCount(columns); } QString Palette::comment() { if (!d->palette) return ""; return d->palette->comment(); } void Palette::setComment(QString comment) { if (!d->palette) return; return d->palette->setComment(comment); } QStringList Palette::groupNames() const { if (!d->palette) return QStringList(); return d->palette->getGroupNames(); } bool Palette::addGroup(QString name) { if (!d->palette) return false; return d->palette->addGroup(name); } bool Palette::removeGroup(QString name, bool keepColors) { if (!d->palette) return false; return d->palette->removeGroup(name, keepColors); } int Palette::colorsCountTotal() { if (!d->palette) return 0; return d->palette->colorCount(); } -KisSwatch Palette::colorSetEntryByIndex(int index) +Swatch *Palette::colorSetEntryByIndex(int index) { - if (!d->palette) return KisSwatch(); + if (!d->palette) return new Swatch(); int col = index % columnCount(); int row = (index - col) / columnCount(); - return d->palette->getColorGlobal(col, row); - return KisSwatch(); + return new Swatch(d->palette->getColorGlobal(col, row)); } -KisSwatch Palette::colorSetEntryFromGroup(int index, const QString &groupName) +Swatch *Palette::colorSetEntryFromGroup(int index, const QString &groupName) { - if (!d->palette) return KisSwatch(); + if (!d->palette) return new Swatch(); int row = index % columnCount(); - return d->palette->getColorGroup((index - row) / columnCount(), row, groupName); + return new Swatch(d->palette->getColorGroup((index - row) / columnCount(), row, groupName)); } -ManagedColor *Palette::colorForEntry(KisSwatch entry) +void Palette::addEntry(Swatch entry, QString groupName) { - if (!d->palette) return Q_NULLPTR; - ManagedColor *color = new ManagedColor(entry.color()); - return color; + d->palette->add(entry.kisSwatch(), groupName); } -void Palette::addEntry(KisSwatch entry, QString groupName) -{ - d->palette->add(entry, groupName); -} - -void Palette::removeEntry(int index, const QString &groupName) +void Palette::removeEntry(int index, const QString &/*groupName*/) { int col = index % columnCount(); int tmp = index; int row = (index - col) / columnCount(); KisSwatchGroup *groupFoundIn = Q_NULLPTR; Q_FOREACH(const QString &name, groupNames()) { KisSwatchGroup *g = d->palette->getGroup(name); tmp -= g->rowCount() * columnCount(); if (tmp < 0) { groupFoundIn = g; break; } row -= g->rowCount(); } if (!groupFoundIn) { return; } groupFoundIn->removeEntry(col, row); } bool Palette::changeGroupName(QString oldGroupName, QString newGroupName) { return d->palette->changeGroupName(oldGroupName, newGroupName); } bool Palette::moveGroup(const QString &groupName, const QString &groupNameInsertBefore) { return d->palette->moveGroup(groupName, groupNameInsertBefore); } bool Palette::save() { if (d->palette->filename().size()>0) { return d->palette->save(); } //if there's no filename the palette proly doesn't even exist... return false; } KoColorSet *Palette::colorSet() { return d->palette; } diff --git a/libs/libkis/Palette.h b/libs/libkis/Palette.h index 4fc1f30bee..d6aa1d431d 100644 --- a/libs/libkis/Palette.h +++ b/libs/libkis/Palette.h @@ -1,186 +1,180 @@ /* * Copyright (c) 2017 Wolthera van Hövell tot Westerflier * * 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_PALETTE_H #define LIBKIS_PALETTE_H #include #include #include "kritalibkis_export.h" #include "libkis.h" #include "Resource.h" #include "KoColorSet.h" +#include class ManagedColor; /** * @brief The Palette class * Palette is a resource object that stores organised color data. * It's purpose is to allow artists to save colors and store them. * * An example for printing all the palettes and the entries: * * @code import sys from krita import * resources = Application.resources("palette") for (k, v) in resources.items(): print(k) palette = Palette(v) for x in range(palette.numberOfEntries()): entry = palette.colorSetEntryByIndex(x) c = palette.colorForEntry(entry); print(x, entry.name(), entry.id(), entry.spotColor(), c.toQString()) * @endcode */ class KRITALIBKIS_EXPORT Palette : public QObject { public: Palette(Resource *resource); ~Palette() override; /** * @brief numberOfEntries * @return */ int numberOfEntries() const; /** * @brief columnCount * @return the amount of columns this palette is set to use. */ int columnCount(); /** * @brief setColumnCount * Set the amount of columns this palette should use. */ void setColumnCount(int columns); /** * @brief comment * @return the comment or description associated with the palette. */ QString comment(); /** * @brief setComment * set the comment or description associated with the palette. * @param comment */ void setComment(QString comment); /** * @brief groupNames * @return the list of group names. This is list is in the order these groups are in the file. */ QStringList groupNames() const; /** * @brief addGroup * @param name of the new group * @return whether adding the group was successful. */ bool addGroup(QString name); /** * @brief removeGroup * @param name the name of the group to remove. * @param keepColors whether or not to delete all the colors inside, or to move them to the default group. * @return */ bool removeGroup(QString name, bool keepColors = true); /** * @brief colorsCountTotal * @return the total amount of entries in the whole group */ int colorsCountTotal(); /** * @brief colorSetEntryByIndex * get the colorsetEntry from the global index. * @param index the global index * @return the colorset entry */ - KisSwatch colorSetEntryByIndex(int index); + Swatch *colorSetEntryByIndex(int index); /** * @brief colorSetEntryFromGroup * @param index index in the group. * @param groupName the name of the group to get the color from. * @return the colorsetentry. */ - KisSwatch colorSetEntryFromGroup(int index, const QString &groupName); + Swatch *colorSetEntryFromGroup(int index, const QString &groupName); - /** - * @brief colorForEntry - * special function to retrieve a ManagedColor object from the colorsetentry. - * @param entry the entry - * @return the ManagedColorObject - */ - ManagedColor *colorForEntry(KisSwatch entry); /** * @brief addEntry * add an entry to a group. Gets appended to the end. * @param entry the entry * @param groupName the name of the group to add to. */ - void addEntry(KisSwatch entry, QString groupName = QString()); + void addEntry(Swatch entry, QString groupName = QString()); /** * @brief removeEntry * remove the entry at @param index from the group @param groupName. */ void removeEntry(int index, const QString &groupName); /** * @brief changeGroupName * change the group name. * @param oldGroupName the old groupname to change. * @param newGroupName the new name to change it into. * @return whether successful. Reasons for failure include not knowing have oldGroupName */ bool changeGroupName(QString oldGroupName, QString newGroupName); /** * @brief moveGroup * move the group to before groupNameInsertBefore. * @param groupName group to move. * @param groupNameInsertBefore group to inset before. * @return whether successful. Reasons for failure include either group not existing. */ bool moveGroup(const QString &groupName, const QString &groupNameInsertBefore = QString()); /** * @brief save * save the palette * @return whether it was successful. */ bool save(); private: friend class PaletteView; struct Private; Private *const d; /** * @brief colorSet * @return gives qa KoColorSet object back */ KoColorSet *colorSet(); }; #endif // LIBKIS_PALETTE_H diff --git a/libs/libkis/PaletteView.cpp b/libs/libkis/PaletteView.cpp index 4baf186faa..2bac41c44b 100644 --- a/libs/libkis/PaletteView.cpp +++ b/libs/libkis/PaletteView.cpp @@ -1,83 +1,93 @@ /* * Copyright (c) 2017 Wolthera van Hövell tot Westerflier * * 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 #include struct PaletteView::Private { KisPaletteModel *model = 0; KisPaletteView *widget = 0; bool allowPaletteModification = true; }; PaletteView::PaletteView(QWidget *parent) : QWidget(parent), d(new Private) { d->widget = new KisPaletteView(this); d->model = new KisPaletteModel(); d->widget->setPaletteModel(d->model); this->setLayout(new QVBoxLayout()); this->layout()->addWidget(d->widget); //forward signals. connect(d->widget, SIGNAL(entrySelected(KisSwatch)), - this, SIGNAL(entrySelectedForeGround(KisSwatch))); + this, SLOT(fgSelected(KisSwatch))); connect(d->widget, SIGNAL(entrySelectedBackGround(KisSwatch)), - this, SIGNAL(entrySelectedBackGround(KisSwatch))); + this, SLOT(bgSelected(KisSwatch))); } PaletteView::~PaletteView() { delete d->model; } void PaletteView::setPalette(Palette *palette) { d->model->setPalette(palette->colorSet()); d->widget->setPaletteModel(d->model); } bool PaletteView::addEntryWithDialog(ManagedColor *color) { if (d->model->colorSet()) { return d->widget->addEntryWithDialog(color->color()); } return false; } bool PaletteView::addGroupWithDialog() { if (d->model->colorSet()) { return d->widget->addGroupWithDialog(); } return false; } bool PaletteView::removeSelectedEntryWithDialog() { if (d->model->colorSet()) { return d->widget->removeEntryWithDialog(d->widget->currentIndex()); } return false; } void PaletteView::trySelectClosestColor(ManagedColor *color) { d->widget->selectClosestColor(color->color()); } + +void PaletteView::fgSelected(KisSwatch swatch) +{ + emit entrySelectedForeGround(Swatch(swatch)); +} + +void PaletteView::bgSelected(KisSwatch swatch) +{ + emit entrySelectedBackGround(Swatch(swatch)); +} diff --git a/libs/libkis/PaletteView.h b/libs/libkis/PaletteView.h index e48e4fa892..f9ee621fd3 100644 --- a/libs/libkis/PaletteView.h +++ b/libs/libkis/PaletteView.h @@ -1,97 +1,110 @@ /* * Copyright (c) 2017 Wolthera van Hövell tot Westerflier * * 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_PALETTE_VIEW_H #define LIBKIS_PALETTE_VIEW_H #include #include #include "kritalibkis_export.h" #include "libkis.h" #include "Palette.h" #include "ManagedColor.h" #include "KoColorSet.h" #include #include +#include + +class KisSwatch; + /** * @brief The PaletteView class is a wrapper around a MVC method for handling * palettes. This class shows a nice widget that can drag and drop, edit colors in a colorset * and will handle adding and removing entries if you'd like it to. */ class KRITALIBKIS_EXPORT PaletteView : public QWidget { Q_OBJECT public: PaletteView(QWidget *parent = 0); ~PaletteView(); public Q_SLOTS: /** * @brief setPalette * Set a new palette. * @param palette */ void setPalette(Palette *palette); /** * @brief addEntryWithDialog * This gives a simple dialog for adding colors, with options like * adding name, id, and to which group the color should be added. * @param color the default color to add * @return whether it was successful. */ bool addEntryWithDialog(ManagedColor *color); /** * @brief addGroupWithDialog * gives a little dialog to ask for the desired groupname. * @return whether this was successful. */ bool addGroupWithDialog(); /** * @brief removeSelectedEntryWithDialog * removes the selected entry. If it is a group, it pop up a dialog * asking whether the colors should also be removed. * @return whether this was successful */ bool removeSelectedEntryWithDialog(); /** * @brief trySelectClosestColor * tries to select the closest color to the one given. * It does not force a change on the active color. * @param color the color to compare to. */ void trySelectClosestColor(ManagedColor *color); Q_SIGNALS: /** * @brief entrySelectedForeGround * fires when a swatch is selected with leftclick. * @param entry */ - void entrySelectedForeGround(KisSwatch entry); + void entrySelectedForeGround(Swatch entry); /** * @brief entrySelectedBackGround * fires when a swatch is selected with rightclick. * @param entry */ - void entrySelectedBackGround(KisSwatch entry); + void entrySelectedBackGround(Swatch entry); + +private Q_SLOTS: + + void fgSelected(KisSwatch swatch); + void bgSelected(KisSwatch swatch); + private: + + + struct Private; const QScopedPointer d; }; #endif // LIBKIS_PALETTE_VIEW_H diff --git a/libs/libkis/Swatch.cpp b/libs/libkis/Swatch.cpp new file mode 100644 index 0000000000..2ed0941e77 --- /dev/null +++ b/libs/libkis/Swatch.cpp @@ -0,0 +1,86 @@ +#include "Swatch.h" + +#include +#include + +struct Swatch::Private { + KisSwatch swatch; +}; + +Swatch::Swatch(const KisSwatch &kisSwatch) + : d(new Private) +{ + d->swatch = kisSwatch; +} + +Swatch::Swatch() + : d(new Private) +{ + +} + +Swatch::~Swatch() +{ + delete d; +} + +Swatch::Swatch(const Swatch &rhs) + : d(new Private) +{ + d->swatch = rhs.d->swatch; +} + +Swatch &Swatch::operator=(const Swatch &rhs) +{ + if (&rhs == this) return *this; + d->swatch = rhs.d->swatch; + return *this; +} + +QString Swatch::name() const +{ + return d->swatch.name(); +} + +void Swatch::setName(const QString &name) +{ + d->swatch.setName(name); +} + +QString Swatch::id() const +{ + return d->swatch.id(); +} +void Swatch::setId(const QString &id) +{ + d->swatch.setId(id); +} + +ManagedColor *Swatch::color() const +{ + ManagedColor *c = new ManagedColor(d->swatch.color()); + return c; +} +void Swatch::setColor(ManagedColor *color) +{ + d->swatch.setColor(color->color()); +} + +bool Swatch::spotColor() const +{ + return d->swatch.spotColor(); +} +void Swatch::setSpotColor(bool spotColor) +{ + d->swatch.setSpotColor(spotColor); +} + +bool Swatch::isValid() const +{ + return d->swatch.isValid(); +} + +KisSwatch Swatch::kisSwatch() const +{ + return d->swatch; +} diff --git a/libs/libkis/Swatch.h b/libs/libkis/Swatch.h new file mode 100644 index 0000000000..c5eac0fcc7 --- /dev/null +++ b/libs/libkis/Swatch.h @@ -0,0 +1,51 @@ +#ifndef SWATCH_H +#define SWATCH_H + +#include "ManagedColor.h" + +#include "kritalibkis_export.h" +#include "libkis.h" + +class KisSwatch; + +/** + * @brief The Swatch class is a thin wrapper around the KisSwatch class. + * + * A Swatch is a single color that is part of a palette, that has a name + * and an id. A Swatch color can be a spot color. + */ +class KRITALIBKIS_EXPORT Swatch +{ +private: + friend class Palette; + friend class PaletteView; + Swatch(const KisSwatch &kisSwatch); +public: + Swatch(); + virtual ~Swatch(); + Swatch(const Swatch &rhs); + Swatch &operator=(const Swatch &rhs); + + QString name() const; + void setName(const QString &name); + + QString id() const; + void setId(const QString &id); + + ManagedColor *color() const; + void setColor(ManagedColor *color); + + bool spotColor() const; + void setSpotColor(bool spotColor); + + bool isValid() const; + +private: + friend class Palette; + KisSwatch kisSwatch() const; + + struct Private; + Private *const d; +}; + +#endif // SWATCH_H diff --git a/plugins/extensions/pykrita/sip/krita/ManagedColor.sip b/plugins/extensions/pykrita/sip/krita/ManagedColor.sip index 5d8f9a580c..a8371be9ef 100644 --- a/plugins/extensions/pykrita/sip/krita/ManagedColor.sip +++ b/plugins/extensions/pykrita/sip/krita/ManagedColor.sip @@ -1,24 +1,24 @@ class ManagedColor : QObject { %TypeHeaderCode #include "ManagedColor.h" %End - ManagedColor(const Palette & __0); + ManagedColor(const ManagedColor & __0); public: ManagedColor(const QString &colorModel, const QString &colorDepth, const QString &colorProfile, QObject *parent = 0); bool operator==(const ManagedColor &other) const; QColor colorForCanvas(Canvas *canvas) const; QString colorDepth() const; QString colorModel() const; QString colorProfile() const; bool setColorProfile(const QString &colorProfile); bool setColorSpace(const QString &colorModel, const QString &colorDepth, const QString &colorProfile); QVector components() const; QVector componentsOrdered() const; void setComponents(const QVector &values); QString toXML() const; void fromXML(const QString &xml); QString toQString(); private: }; diff --git a/plugins/extensions/pykrita/sip/krita/Palette.sip b/plugins/extensions/pykrita/sip/krita/Palette.sip index 8c58ee94e9..f9dc8d5b1a 100644 --- a/plugins/extensions/pykrita/sip/krita/Palette.sip +++ b/plugins/extensions/pykrita/sip/krita/Palette.sip @@ -1,29 +1,26 @@ -class KisSwatch; - class Palette : QObject { %TypeHeaderCode #include "Palette.h" %End Palette(const Palette & __0); public: Palette(Resource *resource); int numberOfEntries() const; int columnCount(); void setColumnCount(int columns); QString comment(); void setComment(QString comment); QStringList groupNames(); bool addGroup(QString name); bool removeGroup(QString name, bool keepColors); int colorsCountTotal(); - KisSwatch colorSetEntryByIndex(int index); - KisSwatch colorSetEntryFromGroup(int index, const QString &groupName); - ManagedColor *colorForEntry(KisSwatch entry) /Factory/; - void addEntry(KisSwatch entry, QString groupName); + Swatch *colorSetEntryByIndex(int index) /Factory/; + Swatch *colorSetEntryFromGroup(int index, const QString &groupName) /Factory/; + void addEntry(Swatch entry, QString groupName); void removeEntry(int index, const QString &groupName); bool changeGroupName(QString oldGroupName, QString newGroupName); bool moveGroup(const QString &groupName, const QString &groupNameInsertBefore); bool save(); private: }; diff --git a/plugins/extensions/pykrita/sip/krita/PaletteView.sip b/plugins/extensions/pykrita/sip/krita/PaletteView.sip index 5714b366dd..e4521f0d08 100644 --- a/plugins/extensions/pykrita/sip/krita/PaletteView.sip +++ b/plugins/extensions/pykrita/sip/krita/PaletteView.sip @@ -1,20 +1,20 @@ class PaletteView : QWidget { %TypeHeaderCode #include "PaletteView.h" %End PaletteView(const PaletteView & __0); public: PaletteView(QWidget *parent = 0); ~PaletteView(); public Q_SLOTS: void setPalette(Palette *palette); bool addEntryWithDialog(ManagedColor *color); bool addGroupWithDialog(); bool removeSelectedEntryWithDialog(); void trySelectClosestColor(ManagedColor *color); Q_SIGNALS: - void entrySelectedForeGround(KisSwatch entry); - void entrySelectedBackGround(KisSwatch entry); + void entrySelectedForeGround(Swatch entry); + void entrySelectedBackGround(Swatch entry); private: }; diff --git a/plugins/extensions/pykrita/sip/krita/Swatch.sip b/plugins/extensions/pykrita/sip/krita/Swatch.sip new file mode 100644 index 0000000000..08eecda2a1 --- /dev/null +++ b/plugins/extensions/pykrita/sip/krita/Swatch.sip @@ -0,0 +1,19 @@ +class Swatch +{ +%TypeHeaderCode +#include "Swatch.h" +%End + Swatch(const Swatch & __0); +public: + Swatch(); + QString name() const; + void setName(const QString &name); + QString id() const; + void setId(const QString &id); + ManagedColor *color() const /Factory/; + void setColor(ManagedColor *color); + bool spotColor() const; + void setSpotColor(bool spotColor); + bool isValid() const; + +}; diff --git a/plugins/extensions/pykrita/sip/krita/kritamod.sip b/plugins/extensions/pykrita/sip/krita/kritamod.sip index 0fcd6abe0a..92fd05ad91 100644 --- a/plugins/extensions/pykrita/sip/krita/kritamod.sip +++ b/plugins/extensions/pykrita/sip/krita/kritamod.sip @@ -1,49 +1,50 @@ %Module PyKrita.krita %ModuleHeaderCode #pragma GCC visibility push(default) %End %Import QtCore/QtCoremod.sip %Import QtGui/QtGuimod.sip %Import QtXml/QtXmlmod.sip %Import QtWidgets/QtWidgetsmod.sip %Include Conversions.sip %Include Shape.sip %Include GroupShape.sip %Include Canvas.sip %Include Channel.sip %Include DockWidgetFactoryBase.sip %Include DockWidget.sip %Include Document.sip %Include Filter.sip %Include InfoObject.sip %Include Extension.sip %Include View.sip %Include Window.sip %Include Krita.sip %Include Node.sip %Include GroupLayer.sip %Include CloneLayer.sip %Include FilterLayer.sip %Include FileLayer.sip %Include FillLayer.sip %Include VectorLayer.sip %Include FilterMask.sip %Include SelectionMask.sip %Include Notifier.sip %Include Resource.sip %Include Selection.sip %Include Extension.sip %Include PresetChooser.sip %Include Palette.sip %Include PaletteView.sip %Include ManagedColor.sip +%Include Swatch.sip %Include KisCubicCurve.sip