diff --git a/libs/libkis/CMakeLists.txt b/libs/libkis/CMakeLists.txt index 8ef7be672b..34903a1e9f 100644 --- a/libs/libkis/CMakeLists.txt +++ b/libs/libkis/CMakeLists.txt @@ -1,34 +1,35 @@ set(kritalibkis_LIB_SRCS Action.cpp Canvas.cpp Channel.cpp DockWidget.cpp DockWidgetFactoryBase.cpp Document.cpp Filter.cpp InfoObject.cpp Krita.cpp Node.cpp Notifier.cpp PresetChooser + Palette.cpp Resource.cpp Selection.cpp View.cpp Extension.cpp Window.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/Palette.cpp b/libs/libkis/Palette.cpp new file mode 100644 index 0000000000..5d83461b5f --- /dev/null +++ b/libs/libkis/Palette.cpp @@ -0,0 +1,63 @@ +/* + * 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 + +struct Palette::Private { + KoColorSet *palette {0}; +}; + +Palette::Palette(Resource *resource): d(new Private()) { + d->palette = dynamic_cast(resource); +} + +int Palette::columnCount() +{ + return d->palette->columnCount(); +} + +void Palette::setColumnCount(int columns) +{ + d->palette->setColumnCount(columns); +} + +QString Palette::comment() +{ + return d->palette->comment(); +} + +QStringList Palette::groupNames() +{ + return d->palette->getGroupNames(); +} + +bool Palette::addGroup(QString name) +{ + return d->palette->addGroup(name); +} + +bool Palette::removeGroup(QString name, bool keepColors) +{ + return d->palette->removeGroup(name, keepColors); +} + +int Palette::colorsCountGroup(QString name) +{ + return d->palette->nColorsGroup(name); +} diff --git a/libs/libkis/Palette.h b/libs/libkis/Palette.h new file mode 100644 index 0000000000..747e6692ba --- /dev/null +++ b/libs/libkis/Palette.h @@ -0,0 +1,91 @@ +/* + * 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 "kritalibkis_export.h" +#include "libkis.h" +#include "Resource.h" +#include "KoColorSet.h" + +/** + * @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. + */ + +class KRITALIBKIS_EXPORT Palette : public QObject +{ +public: + Palette(Resource *resource); + + /** + * @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(); + //setcomment + /** + * @brief groupNames + * @return the list of group names. This is list is in the order these groups are in the file. + */ + QStringList groupNames(); + /** + * @brief addGroup + * @param name of the new group + * @return whether adding the group was succesful. + */ + 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 colorsCountGroup + * @param name of the group to check. Empty is the default group. + * @return the amount of colors within that group. + */ + int colorsCountGroup(QString name); + + //getcolorgroup + //Add + //Remove + //Insert + +private: + struct Private; + Private *const d; + +}; + +#endif // LIBKIS_PALETTE_H diff --git a/plugins/extensions/pykrita/sip/krita/Palette.sip b/plugins/extensions/pykrita/sip/krita/Palette.sip new file mode 100644 index 0000000000..7a6aa28730 --- /dev/null +++ b/plugins/extensions/pykrita/sip/krita/Palette.sip @@ -0,0 +1,17 @@ +class Palette : QObject +{ +%TypeHeaderCode +#include "Palette.h" +%End + Palette(const Palette & __0); +public: + Palette(Resource *resource); + int columnCount(); + void setColumnCount(int columns); + QString comment(); + QStringList groupNames(); + bool addGroup(QString name); + bool removeGroup(QString name, bool keepColors); + int colorsCountGroup(QString name); +private: +}; diff --git a/plugins/extensions/pykrita/sip/krita/kritamod.sip b/plugins/extensions/pykrita/sip/krita/kritamod.sip index 183b9ff102..5cf52ddd79 100644 --- a/plugins/extensions/pykrita/sip/krita/kritamod.sip +++ b/plugins/extensions/pykrita/sip/krita/kritamod.sip @@ -1,32 +1,33 @@ %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 Action.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 Notifier.sip %Include Resource.sip %Include Selection.sip %Include Extension.sip %Include PresetChooser.sip +%Include Palette.sip %Include KisCubicCurve.sip