Krita Source Code Documentation
Loading...
Searching...
No Matches
KoColorSet Class Reference

#include <KoColorSet.h>

+ Inheritance diagram for KoColorSet:

Classes

class  Private
 

Public Types

enum  PaletteType {
  UNKNOWN = 0 , GPL , RIFF_PAL , ACT ,
  PSP_PAL , ACO , XML , KPL ,
  SBZ , ASE , ACB , CSS
}
 

Signals

void entryChanged (int column, int row)
 
void layoutAboutToChange ()
 
void layoutChanged ()
 
void modified ()
 

Public Member Functions

void addGroup (const QString &groupName, int columnCount=KisSwatchGroup::DEFAULT_COLUMN_COUNT, int rowCount=KisSwatchGroup::DEFAULT_ROW_COUNT)
 addGroup Adds a new group.
 
void addSwatch (const KisSwatch &swatch, const QString &groupName=GLOBAL_GROUP_NAME, int column=-1, int row=-1)
 Add a color to the palette.
 
void changeGroupName (const QString &oldGroupName, const QString &newGroupName)
 changeGroupName
 
void clear ()
 clears the complete colorset
 
KoResourceSP clone () const override
 
quint32 colorCount () const
 
int columnCount () const
 
QString comment ()
 
QString defaultFileExtension () const override
 
bool fromByteArray (QByteArray &data, KisResourcesInterfaceSP resourcesInterface)
 
KisSwatchGroup::SwatchInfo getClosestSwatchInfo (KoColor compare, bool useGivenColorSpace=true) const
 getIndexClosestColor function that matches the color to all colors in the colorset, and returns the index of the closest match.
 
KisSwatch getColorGlobal (quint32 column, quint32 row) const
 getColorGlobal A function for getting a color based on a global index. Useful for iterating through all color entries.
 
KisSwatchGroupSP getGlobalGroup () const
 getGlobalGroup
 
KisSwatchGroupSP getGroup (const QString &name) const
 getGroup
 
KisSwatchGroupSP getGroup (int row) const
 getGroup get the group that covers this row
 
KisSwatch getSwatchFromGroup (quint32 column, quint32 row, QString groupName=KoColorSet::GLOBAL_GROUP_NAME) const
 getColorGroup A function for getting the color from a specific group.
 
bool isGroupTitleRow (int row) const
 isGroupRow checks whether the current row is a group title
 
bool isLocked () const
 
 KoColorSet (const KoColorSet &rhs)
 Create an copied palette.
 
 KoColorSet (const QString &filename=QString())
 
bool loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
 
void moveGroup (const QString &groupName, const QString &groupNameInsertBefore=GLOBAL_GROUP_NAME)
 moveGroup Move a group in the internal stringlist.
 
KoColorSetoperator= (const KoColorSet &rhs)=delete
 
PaletteType paletteType () const
 
void removeGroup (const QString &groupName, bool keepColors=true)
 removeGroup Remove a group from the KoColorSet
 
void removeSwatch (int column, int row, KisSwatchGroupSP group)
 remove the swatch from the given group at column and row
 
QPair< QString, QString > resourceType () const override
 
int rowCount () const
 
int rowCountWithTitles () const
 
int rowNumberInGroup (int rowNumber) const
 rowNumberInGroup calculates the row number in the group from the global rownumber
 
bool saveToDevice (QIODevice *dev) const override
 
void setColumnCount (int columns)
 
void setComment (QString comment)
 
void setLocked (bool lock)
 
void setPaletteType (PaletteType paletteType)
 
quint32 slotCount () const
 
int startRowForGroup (const QString &groupName) const
 rowForNamedGroup returns the row the group's title is on
 
QStringList swatchGroupNames () const
 getGroupNames
 
KUndo2StackundoStack () const
 
void updateThumbnail () override
 updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something else than the image set with setImage.
 
 ~KoColorSet () override
 
- Public Member Functions inherited from KoResource
bool active () const
 
void addMetaData (QString key, QVariant value)
 store the given key, value pair in the resource
 
virtual void clearSideLoadedResources ()
 
virtual QList< KoResourceLoadResultembeddedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
QString filename () const
 
QImage image () const
 
bool isDirty () const
 
virtual bool isEphemeral () const
 
virtual bool isSerializable () const
 
 KoResource ()
 
 KoResource (const KoResource &rhs)
 
 KoResource (const QString &filename)
 
virtual QList< KoResourceLoadResultlinkedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
bool load (KisResourcesInterfaceSP resourcesInterface)
 
QString md5Sum (bool generateIfEmpty=true) const
 
QMap< QString, QVariant > metadata () const
 get a map with all the metadata
 
virtual QString name () const
 
KoResourceoperator= (const KoResource &rhs)=delete
 
bool permanent () const
 
virtual QList< int > requiredCanvasResources () const
 
QList< KoResourceLoadResultrequiredResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
int resourceId () const
 
bool save ()
 
void setActive (bool active)
 
void setDirty (bool value)
 Mark the preset as modified but not saved.
 
void setFilename (const QString &filename)
 
void setImage (const QImage &image)
 
void setMD5Sum (const QString &md5sum)
 Set the md5sum of this resource. It must be in hex-encoded string format.
 
void setName (const QString &name)
 
void setPermanent (bool permanent)
 
void setResourceId (int id)
 
void setStorageLocation (const QString &location)
 
void setValid (bool valid)
 
void setVersion (int version)
 
virtual QList< KoResourceLoadResultsideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
KoResourceSignature signature () const
 
QString storageLocation () const
 
QList< KoResourceLoadResulttakeSideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface)
 
virtual QImage thumbnail () const
 thumbnail the thumbnail image to use in resource selectors
 
virtual QString thumbnailPath () const
 thumbnailPath returns the path to a separate thumbnail image, outside the actual resource file itself. If the path is relative, it is supposed start in the same location as the resource itself. If it's absolute, that is, it starts with "/", it is from the root of the storage.
 
bool valid () const
 
int version () const
 Get the version of the resource.
 
virtual ~KoResource ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Static Public Attributes

static const QString GLOBAL_GROUP_NAME = QString()
 
static const QString KPL_COLOR_DEPTH_ID_ATTR = "colorDepthId"
 
static const QString KPL_COLOR_MODEL_ID_ATTR = "colorModelId"
 
static const QString KPL_GROUP_NAME_ATTR = "name"
 
static const QString KPL_GROUP_ROW_COUNT_ATTR = "rows"
 
static const QString KPL_GROUP_TAG = "Group"
 
static const QString KPL_PALETTE_COLUMN_COUNT_ATTR = "columns"
 
static const QString KPL_PALETTE_COMMENT_ATTR = "comment"
 
static const QString KPL_PALETTE_FILENAME_ATTR = "filename"
 
static const QString KPL_PALETTE_NAME_ATTR = "name"
 
static const QString KPL_PALETTE_PROFILE_TAG = "Profile"
 
static const QString KPL_PALETTE_READONLY_ATTR = "readonly"
 
static const QString KPL_PALETTE_TAG = "ColorSet"
 
static const QString KPL_SWATCH_BITDEPTH_ATTR = "bitdepth"
 
static const QString KPL_SWATCH_COL_ATTR = "column"
 
static const QString KPL_SWATCH_ID_ATTR = "id"
 
static const QString KPL_SWATCH_NAME_ATTR = "name"
 
static const QString KPL_SWATCH_POS_TAG = "Position"
 
static const QString KPL_SWATCH_ROW_ATTR = "row"
 
static const QString KPL_SWATCH_SPOT_ATTR = "spot"
 
static const QString KPL_SWATCH_TAG = "ColorSetEntry"
 
static const QString KPL_VERSION_ATTR = "version"
 

Private Slots

void canRedoChanged (bool canRedo)
 
void canUndoChanged (bool canUndo)
 

Private Member Functions

void notifySwatchChanged (const QString &groupName, int column, int row)
 
void setModified (bool)
 

Private Attributes

const QScopedPointer< Privated
 

Friends

struct AddGroupCommand
 
struct AddSwatchCommand
 
struct ChangeGroupNameCommand
 
struct ClearCommand
 
struct MoveGroupCommand
 
struct RemoveGroupCommand
 
struct RemoveSwatchCommand
 
struct SetColumnCountCommand
 
struct SetCommentCommand
 
struct SetPaletteTypeCommand
 
class TestKisPaletteModel
 
class TestKoColorSet
 

Additional Inherited Members

- Public Attributes inherited from KoResource
bool active {true}
 
QString filename
 
QImage image
 
QString md5sum
 
QMap< QString, QVariant > metadata
 
bool modified {false}
 
QString name
 
bool permanent {false}
 
int resourceId {-1}
 
QString storageLocation
 
bool valid {false}
 
int version {-1}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

Also called palette. Open Gimp, Photoshop or RIFF palette files. This is a straight port from the Gimp.

Definition at line 28 of file KoColorSet.h.

Member Enumeration Documentation

◆ PaletteType

Enumerator
UNKNOWN 
GPL 
RIFF_PAL 
ACT 
PSP_PAL 
ACO 
XML 
KPL 
SBZ 
ASE 
ACB 
CSS 

Definition at line 57 of file KoColorSet.h.

57 {
58 UNKNOWN = 0,
59 GPL, // GIMP
60 RIFF_PAL, // RIFF
61 ACT, // Photoshop binary
62 PSP_PAL, // PaintShop Pro
63 ACO, // Photoshop Swatches
64 XML, // XML palette (Scribus)
65 KPL, // KoColor-based XML palette
66 SBZ, // SwatchBooker
67 ASE, // Adobe swatch exchange
68 ACB, // Adobe Color Book.
69 CSS // CSS palette
70 };

Constructor & Destructor Documentation

◆ KoColorSet() [1/2]

KoColorSet::KoColorSet ( const QString & filename = QString())
explicit

Load a color set from a file. This can be a Gimp palette, a RIFF palette, a Photoshop palette, a Krita palette, a Scribus palette or a SwatchBooker palette.

Definition at line 561 of file KoColorSet.cpp.

562 : QObject()
564 , d(new Private(this))
565{
566 connect(&d->undoStack, SIGNAL(canUndoChanged(bool)), this, SLOT(canUndoChanged(bool)));
567 connect(&d->undoStack, SIGNAL(canRedoChanged(bool)), this, SLOT(canRedoChanged(bool)));
568}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void canUndoChanged(bool canUndo)
const QScopedPointer< Private > d
Definition KoColorSet.h:287
void canRedoChanged(bool canRedo)
QString filename

References canRedoChanged(), canUndoChanged(), connect(), and d.

◆ KoColorSet() [2/2]

KoColorSet::KoColorSet ( const KoColorSet & rhs)

Create an copied palette.

Definition at line 571 of file KoColorSet.cpp.

572 : QObject()
573 , KoResource(rhs)
574 , d(new Private(this))
575{
576 d->paletteType = rhs.d->paletteType;
577 d->data = rhs.d->data;
578 d->comment = rhs.d->comment;
579 d->swatchGroups = rhs.d->swatchGroups;
580}

References d.

◆ ~KoColorSet()

KoColorSet::~KoColorSet ( )
override

Definition at line 582 of file KoColorSet.cpp.

583{
584}

Member Function Documentation

◆ addGroup()

void KoColorSet::addGroup ( const QString & groupName,
int columnCount = KisSwatchGroup::DEFAULT_COLUMN_COUNT,
int rowCount = KisSwatchGroup::DEFAULT_ROW_COUNT )

addGroup Adds a new group.

Parameters
groupNamethe name of the new group. When not specified, this will fail.
Returns
whether the group was made.

Definition at line 842 of file KoColorSet.cpp.

843{
844 if (swatchGroupNames().contains(groupName) || d->isLocked) return;
845
846 AddGroupCommand *cmd = new AddGroupCommand(this, groupName, columnCount, rowCount);
847
848 d->undoStack.push(cmd);
849}
int rowCount() const
QStringList swatchGroupNames() const
getGroupNames
friend struct AddGroupCommand
Definition KoColorSet.h:276
int columnCount() const

References AddGroupCommand, columnCount(), d, rowCount(), and swatchGroupNames().

◆ addSwatch()

void KoColorSet::addSwatch ( const KisSwatch & swatch,
const QString & groupName = GLOBAL_GROUP_NAME,
int column = -1,
int row = -1 )

Add a color to the palette.

Parameters
cthe swatch
groupNamecolor to add the group to. If empty, it will be added to the unsorted.
column.The column in the group
row.The row in the group

Definition at line 643 of file KoColorSet.cpp.

644{
645 if (d->isLocked) return;
646
647 AddSwatchCommand *cmd = new AddSwatchCommand(this, swatch, groupName, column, row);
648
649 d->undoStack.push(cmd);
650
651}
friend struct AddSwatchCommand
Definition KoColorSet.h:273

References AddSwatchCommand, and d.

◆ canRedoChanged

void KoColorSet::canRedoChanged ( bool canRedo)
privateslot

Definition at line 794 of file KoColorSet.cpp.

795{
796 if (d->undoStack.canUndo()) {
797 setModified(true);
798 }
799 else {
800 setModified(false);
801 }
802}
void setModified(bool)

References d, and setModified().

◆ canUndoChanged

void KoColorSet::canUndoChanged ( bool canUndo)
privateslot

Definition at line 784 of file KoColorSet.cpp.

785{
786 if (canUndo) {
787 setModified(true);
788 }
789 else {
790 setModified(false);
791 }
792}

References setModified().

◆ changeGroupName()

void KoColorSet::changeGroupName ( const QString & oldGroupName,
const QString & newGroupName )

changeGroupName

Parameters
oldGroupName
newGroupName

Definition at line 804 of file KoColorSet.cpp.

805{
806 if (!swatchGroupNames().contains(oldGroupName) || (oldGroupName == newGroupName) || d->isLocked) return;
807
808 ChangeGroupNameCommand *cmd = new ChangeGroupNameCommand(this, oldGroupName, newGroupName);
809 d->undoStack.push(cmd);
810}
friend struct ChangeGroupNameCommand
Definition KoColorSet.h:275

References ChangeGroupNameCommand, d, and swatchGroupNames().

◆ clear()

void KoColorSet::clear ( )

clears the complete colorset

Definition at line 661 of file KoColorSet.cpp.

662{
663 if (d->isLocked) return;
664
665 ClearCommand *cmd = new ClearCommand(this);
666
667 d->undoStack.push(cmd);
668}
friend struct ClearCommand
Definition KoColorSet.h:278

References ClearCommand, and d.

◆ clone()

KoResourceSP KoColorSet::clone ( ) const
overridevirtual

Implements KoResource.

Definition at line 586 of file KoColorSet.cpp.

587{
588 return KoResourceSP(new KoColorSet(*this));
589}
KoColorSet(const QString &filename=QString())
QSharedPointer< KoResource > KoResourceSP

References KoColorSet().

◆ colorCount()

quint32 KoColorSet::colorCount ( ) const

Definition at line 908 of file KoColorSet.cpp.

909{
910 int colorCount = 0;
911 for (const KisSwatchGroupSP &group : d->swatchGroups) {
912 colorCount += group->colorCount();
913 }
914 return colorCount;
915}
quint32 colorCount() const

References colorCount(), and d.

◆ columnCount()

int KoColorSet::columnCount ( ) const

Definition at line 821 of file KoColorSet.cpp.

822{
823 Q_ASSERT(d->swatchGroups.size() > 0);
824
825 return d->swatchGroups.first()->columnCount();
826}

References d.

◆ comment()

QString KoColorSet::comment ( )

Definition at line 828 of file KoColorSet.cpp.

829{
830 return d->comment;
831}

References d.

◆ defaultFileExtension()

QString KoColorSet::defaultFileExtension ( ) const
overridevirtual
Returns
the default file extension which should be used when saving the resource

Reimplemented from KoResource.

Definition at line 874 of file KoColorSet.cpp.

875{
876 return (d->paletteType == GPL) ? ".gpl" : ".kpl";
877}

References d, and GPL.

◆ entryChanged

void KoColorSet::entryChanged ( int column,
int row )
signal

◆ fromByteArray()

bool KoColorSet::fromByteArray ( QByteArray & data,
KisResourcesInterfaceSP resourcesInterface )

Definition at line 621 of file KoColorSet.cpp.

622{
623 QBuffer buf(&data);
624 buf.open(QIODevice::ReadOnly);
625 return loadFromDevice(&buf, resourcesInterface);
626}
bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override

References loadFromDevice().

◆ getClosestSwatchInfo()

KisSwatchGroup::SwatchInfo KoColorSet::getClosestSwatchInfo ( KoColor compare,
bool useGivenColorSpace = true ) const

getIndexClosestColor function that matches the color to all colors in the colorset, and returns the index of the closest match.

Parameters
comparethe color you wish to compare.
useGivenColorSpacewhether to use the color space of the color given when the two colors' colorspaces don't match. Else it'll use the entry's colorspace.
Returns
returns the int of the closest match.

Definition at line 981 of file KoColorSet.cpp.

982{
983 KisSwatchGroup::SwatchInfo closestSwatch;
984
985 quint8 highestPercentage = 0;
986 quint8 testPercentage = 0;
987
988 for (const KisSwatchGroupSP &group : d->swatchGroups) {
989 for (const KisSwatchGroup::SwatchInfo &currInfo : group->infoList()) {
990 KoColor color = currInfo.swatch.color();
991 if (useGivenColorSpace == true && compare.colorSpace() != color.colorSpace()) {
992 color.convertTo(compare.colorSpace());
993
994 } else if (compare.colorSpace() != color.colorSpace()) {
995 compare.convertTo(color.colorSpace());
996 }
997 testPercentage = (255 - compare.colorSpace()->difference(compare.data(), color.data()));
998 if (testPercentage > highestPercentage)
999 {
1000 highestPercentage = testPercentage;
1001 closestSwatch = currInfo;
1002 }
1003 }
1004 }
1005 return closestSwatch;
1006}
virtual quint8 difference(const quint8 *src1, const quint8 *src2) const =0
void convertTo(const KoColorSpace *cs, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
Definition KoColor.cpp:136
quint8 * data()
Definition KoColor.h:144
const KoColorSpace * colorSpace() const
return the current colorSpace
Definition KoColor.h:82

References KoColor::colorSpace(), KoColor::convertTo(), d, KoColor::data(), and KoColorSpace::difference().

◆ getColorGlobal()

KisSwatch KoColorSet::getColorGlobal ( quint32 column,
quint32 row ) const

getColorGlobal A function for getting a color based on a global index. Useful for iterating through all color entries.

Parameters
xthe global x index over the whole palette.
ythe global y index over the whole palette.
Returns
the entry.

Definition at line 670 of file KoColorSet.cpp.

671{
672 KisSwatchGroupSP group = getGroup(row);
673 Q_ASSERT(group);
674
675 int titleRow = startRowForGroup(group->name());
676 int rowInGroup = -1;
677
678 if (group->name().isEmpty()) {
679 rowInGroup = (int)row - titleRow;
680 }
681 else {
682 rowInGroup = (int)row - (titleRow + 1);
683 }
684
685 Q_ASSERT((isGroupTitleRow(titleRow) && titleRow > 0) || titleRow == 0);
686 Q_ASSERT(rowInGroup < group->rowCount());
687
688 return group->getSwatch(column, rowInGroup);
689
690}
bool isGroupTitleRow(int row) const
isGroupRow checks whether the current row is a group title
int startRowForGroup(const QString &groupName) const
rowForNamedGroup returns the row the group's title is on
KisSwatchGroupSP getGroup(const QString &name) const
getGroup

References getGroup(), isGroupTitleRow(), rowCount(), and startRowForGroup().

◆ getGlobalGroup()

KisSwatchGroupSP KoColorSet::getGlobalGroup ( ) const

getGlobalGroup

Returns

Definition at line 974 of file KoColorSet.cpp.

975{
976 Q_ASSERT(d->swatchGroups.size() > 0);
977 Q_ASSERT(d->swatchGroups.first()->name() == GLOBAL_GROUP_NAME);
978 return d->swatchGroups.first();
979}
static const QString GLOBAL_GROUP_NAME
Definition KoColorSet.h:33

References d, and GLOBAL_GROUP_NAME.

◆ getGroup() [1/2]

KisSwatchGroupSP KoColorSet::getGroup ( const QString & name) const

getGroup

Parameters
name
Returns
the group with the name given; global group if no parameter is given null pointer if not found.

Definition at line 926 of file KoColorSet.cpp.

927{
928 for (KisSwatchGroupSP &group : d->swatchGroups) {
929 if (group->name() == name) {
930 return group;
931 }
932 }
933 return 0;
934}
QString name

References d, and KoResource::name.

◆ getGroup() [2/2]

KisSwatchGroupSP KoColorSet::getGroup ( int row) const

getGroup get the group that covers this row

Parameters
row
Returns
a swatch group

Definition at line 936 of file KoColorSet.cpp.

937{
938// qDebug() << "------------";
939
940 if (row >= rowCountWithTitles()) return nullptr;
941
942 int currentRow = 0;
943
944 for (KisSwatchGroupSP &group : d->swatchGroups) {
945
946 int groupRowCount = group->rowCount();
947 if (group->name() != KoColorSet::GLOBAL_GROUP_NAME) {
948 groupRowCount++;
949 }
950
951// qDebug() << group->name()
952// << "row" << row << "currentRow" << currentRow << "group rowcount" << groupRowCount
953// << "hit" << (currentRow <= row && row < currentRow + groupRowCount);
954
955 bool hit = (currentRow <= row && row < currentRow + groupRowCount);
956
957 if (hit) {
958 return group;
959 }
960
961 currentRow += group->rowCount();
962
963 if (group->name() != KoColorSet::GLOBAL_GROUP_NAME) {
964 currentRow += 1;
965 }
966
967 if (currentRow >= rowCountWithTitles()) return nullptr;
968 }
969
970 return nullptr;
971
972}
int rowCountWithTitles() const

References d, GLOBAL_GROUP_NAME, and rowCountWithTitles().

◆ getSwatchFromGroup()

KisSwatch KoColorSet::getSwatchFromGroup ( quint32 column,
quint32 row,
QString groupName = KoColorSet::GLOBAL_GROUP_NAME ) const

getColorGroup A function for getting the color from a specific group.

Parameters
xthe x index over the group.
ythe y index over the group.
groupNamethe name of the group, will give unsorted when not defined.
Returns
the entry

Definition at line 692 of file KoColorSet.cpp.

693{
694 KisSwatch swatch;
695 for (const KisSwatchGroupSP &group: d->swatchGroups) {
696 if (group->name() == groupName) {
697 if (group->checkSwatchExists(column, row)) {
698 swatch = group->getSwatch(column, row);
699 }
700 break;
701 }
702 }
703 return swatch;
704}

References d.

◆ isGroupTitleRow()

bool KoColorSet::isGroupTitleRow ( int row) const

isGroupRow checks whether the current row is a group title

Parameters
rowthe row to check
Returns
true if this is a group row

Definition at line 715 of file KoColorSet.cpp.

716{
717 int idx = 0;
718 for (const KisSwatchGroupSP &group : d->swatchGroups) {
719 idx += group->rowCount();
720 if (group->name() != KoColorSet::GLOBAL_GROUP_NAME) {
721 idx++;
722 }
723 if (idx == row) {
724 return true;
725 }
726 }
727 return false;
728}

References d, and GLOBAL_GROUP_NAME.

◆ isLocked()

bool KoColorSet::isLocked ( ) const

Definition at line 889 of file KoColorSet.cpp.

890{
891 return d->isLocked;
892}

References d.

◆ layoutAboutToChange

void KoColorSet::layoutAboutToChange ( )
signal

◆ layoutChanged

void KoColorSet::layoutChanged ( )
signal

◆ loadFromDevice()

bool KoColorSet::loadFromDevice ( QIODevice * dev,
KisResourcesInterfaceSP resourcesInterface )
overridevirtual

Implements KoResource.

Definition at line 591 of file KoColorSet.cpp.

592{
593 Q_UNUSED(resourcesInterface);
594
595 if (!dev->isOpen()) dev->open(QIODevice::ReadOnly);
596
597 d->data = dev->readAll();
598
599 Q_ASSERT(d->data.size() != 0);
600
601 return d->init();
602}

References d.

◆ modified

void KoColorSet::modified ( )
signal

◆ moveGroup()

void KoColorSet::moveGroup ( const QString & groupName,
const QString & groupNameInsertBefore = GLOBAL_GROUP_NAME )

moveGroup Move a group in the internal stringlist.

Parameters
groupNamethe groupname to move.
groupNameInsertBeforethe groupname to insert before. Empty means it will be added to the end.
Returns

Definition at line 851 of file KoColorSet.cpp.

852{
853 QStringList groupNames = swatchGroupNames();
854 if (!groupNames.contains(groupName)
855 || !groupNames.contains(groupNameInsertBefore)
856 || d->isLocked) return;
857
858 MoveGroupCommand *cmd = new MoveGroupCommand(this, groupName, groupNameInsertBefore);
859
860 d->undoStack.push(cmd);
861
862}
friend struct MoveGroupCommand
Definition KoColorSet.h:282

References d, MoveGroupCommand, and swatchGroupNames().

◆ notifySwatchChanged()

void KoColorSet::notifySwatchChanged ( const QString & groupName,
int column,
int row )
private

Definition at line 774 of file KoColorSet.cpp.

775{
776 int startRow = 0;
777 if (!groupName.isEmpty()) {
778 startRow = startRowForGroup(groupName) + 1;
779 }
780 Q_EMIT entryChanged(column, startRow + row);
781}
void entryChanged(int column, int row)

References entryChanged(), and startRowForGroup().

◆ operator=()

KoColorSet & KoColorSet::operator= ( const KoColorSet & rhs)
delete

◆ paletteType()

KoColorSet::PaletteType KoColorSet::paletteType ( ) const

Definition at line 628 of file KoColorSet.cpp.

629{
630 return d->paletteType;
631}

References d.

◆ removeGroup()

void KoColorSet::removeGroup ( const QString & groupName,
bool keepColors = true )

removeGroup Remove a group from the KoColorSet

Parameters
groupNamethe name of the group you want to remove.
keepColorsWhether you wish to keep the colorsetentries. These will be added to the unsorted.
Returns
whether it could find the group to remove.

Definition at line 864 of file KoColorSet.cpp.

865{
866
867 if (!swatchGroupNames().contains(groupName) || (groupName == GLOBAL_GROUP_NAME) || d->isLocked) return;
868
869 RemoveGroupCommand *cmd = new RemoveGroupCommand(this, groupName, keepColors);
870
871 d->undoStack.push(cmd);
872}
friend struct RemoveGroupCommand
Definition KoColorSet.h:277

References d, GLOBAL_GROUP_NAME, RemoveGroupCommand, and swatchGroupNames().

◆ removeSwatch()

void KoColorSet::removeSwatch ( int column,
int row,
KisSwatchGroupSP group )

remove the swatch from the given group at column and row

Definition at line 653 of file KoColorSet.cpp.

654{
655 if (d->isLocked) return;
656 RemoveSwatchCommand *cmd = new RemoveSwatchCommand(this, column, row, group);
657
658 d->undoStack.push(cmd);
659}
friend struct RemoveSwatchCommand
Definition KoColorSet.h:274

References d, and RemoveSwatchCommand.

◆ resourceType()

QPair< QString, QString > KoColorSet::resourceType ( ) const
inlineoverridevirtual
Returns
the resource type

Implements KoResource.

Definition at line 92 of file KoColorSet.h.

93 {
94 return QPair<QString, QString>(ResourceType::Palettes, "");
95 }
const QString Palettes

References ResourceType::Palettes.

◆ rowCount()

int KoColorSet::rowCount ( ) const

Definition at line 894 of file KoColorSet.cpp.

895{
896 int res = 0;
897 for (const KisSwatchGroupSP &group : d->swatchGroups) {
898 res += group->rowCount();
899 }
900 return res;
901}

References d.

◆ rowCountWithTitles()

int KoColorSet::rowCountWithTitles ( ) const

Definition at line 903 of file KoColorSet.cpp.

904{
905 return rowCount() + d->swatchGroups.size() - 1;
906}

References d, and rowCount().

◆ rowNumberInGroup()

int KoColorSet::rowNumberInGroup ( int rowNumber) const

rowNumberInGroup calculates the row number in the group from the global rownumber

Parameters
rowNumberthis is a row in rowCountWithTitles
Returns
-1 if the row is a group title row.

Definition at line 747 of file KoColorSet.cpp.

748{
749 if (isGroupTitleRow(rowNumber)) {
750 return -1;
751 }
752
753 int rowInGroup = -1;
754 for (int i = rowNumber; i > -1; i--) {
755 if (isGroupTitleRow(i)) {
756 return rowInGroup;
757 }
758 else {
759 rowInGroup++;
760 }
761 }
762
763 return rowInGroup;
764}

References isGroupTitleRow().

◆ saveToDevice()

bool KoColorSet::saveToDevice ( QIODevice * dev) const
overridevirtual

Reimplemented from KoResource.

Definition at line 604 of file KoColorSet.cpp.

605{
606 bool res = false;
607 switch(d->paletteType) {
608 case GPL:
609 res = d->saveGpl(dev);
610 break;
611 default:
612 res = d->saveKpl(dev);
613 }
614
615 if (res) const_cast<KoColorSet*>(this)->setDirty(false);
616 d->undoStack.clear();
617
618 return res;
619}
KUndo2Stack * undoStack() const
void setDirty(bool value)
Mark the preset as modified but not saved.

References KUndo2QStack::clear(), d, GPL, KoResource::setDirty(), and undoStack().

◆ setColumnCount()

void KoColorSet::setColumnCount ( int columns)

Definition at line 812 of file KoColorSet.cpp.

813{
814 if (d->isLocked || (columns == d->columns)) return;
815
816 SetColumnCountCommand *cmd = new SetColumnCountCommand (this, columns);
817
818 d->undoStack.push(cmd);
819}
friend struct SetColumnCountCommand
Definition KoColorSet.h:279

References d, and SetColumnCountCommand.

◆ setComment()

void KoColorSet::setComment ( QString comment)

Definition at line 833 of file KoColorSet.cpp.

834{
835 if (d->isLocked || comment == d->comment) return;
836
838
839 d->undoStack.push(cmd);
840}
friend struct SetCommentCommand
Definition KoColorSet.h:280
QString comment()

References comment(), d, and SetCommentCommand.

◆ setLocked()

void KoColorSet::setLocked ( bool lock)

Definition at line 884 of file KoColorSet.cpp.

885{
886 d->isLocked = lock;
887}

References d.

◆ setModified()

void KoColorSet::setModified ( bool _modified)
private

Definition at line 766 of file KoColorSet.cpp.

767{
768 setDirty(_modified);
769 if (_modified) {
770 Q_EMIT modified();
771 }
772}
void modified()

References modified(), and KoResource::setDirty().

◆ setPaletteType()

void KoColorSet::setPaletteType ( PaletteType paletteType)

Definition at line 633 of file KoColorSet.cpp.

634{
635 if (d->isLocked || paletteType == d->paletteType) return;
636
638
639 d->undoStack.push(cmd);
640}
friend struct SetPaletteTypeCommand
Definition KoColorSet.h:281
PaletteType paletteType() const

References d, paletteType(), and SetPaletteTypeCommand.

◆ slotCount()

quint32 KoColorSet::slotCount ( ) const

Definition at line 917 of file KoColorSet.cpp.

918{
919 int slotCount = 0;
920 for (const KisSwatchGroupSP &group : d->swatchGroups) {
921 slotCount += group->slotCount();
922 }
923 return slotCount;
924}
quint32 slotCount() const

References d, and slotCount().

◆ startRowForGroup()

int KoColorSet::startRowForGroup ( const QString & groupName) const

rowForNamedGroup returns the row the group's title is on

Parameters
groupName
Returns

Definition at line 730 of file KoColorSet.cpp.

731{
732 if (groupName.isEmpty()) return 0;
733
734 int row = 0;
735 for (const KisSwatchGroupSP &group : d->swatchGroups) {
736 if (group->name() == groupName) {
737 return row;
738 }
739 row += group->rowCount();
740 if (group->name() != KoColorSet::GLOBAL_GROUP_NAME) {
741 row++;
742 }
743 }
744 return row;
745}

References d, and GLOBAL_GROUP_NAME.

◆ swatchGroupNames()

QStringList KoColorSet::swatchGroupNames ( ) const

getGroupNames

Returns
returns a list of group names, excluding the unsorted group.

Definition at line 706 of file KoColorSet.cpp.

707{
708 QStringList groupNames;
709 for (const KisSwatchGroupSP &group : d->swatchGroups) {
710 groupNames << group->name();
711 }
712 return groupNames;
713}

References d.

◆ undoStack()

KUndo2Stack * KoColorSet::undoStack ( ) const

Definition at line 879 of file KoColorSet.cpp.

880{
881 return &d->undoStack;
882}

References d.

◆ updateThumbnail()

void KoColorSet::updateThumbnail ( )
overridevirtual

updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something else than the image set with setImage.

Reimplemented from KoResource.

Definition at line 1008 of file KoColorSet.cpp.

1009{
1010 int rows = 0;
1011
1012 // Determine the last filled row in each group
1013 for (const KisSwatchGroupSP &group : d->swatchGroups) {
1014 int lastRowInGroup = 0;
1015 for (const KisSwatchGroup::SwatchInfo &info : group->infoList()) {
1016 lastRowInGroup = qMax(lastRowInGroup, info.row);
1017 }
1018 rows += (lastRowInGroup + 1);
1019 }
1020
1021 QImage img(d->global()->columnCount() * 4, rows * 4, QImage::Format_ARGB32);
1022 QPainter gc(&img);
1023 gc.fillRect(img.rect(), Qt::darkGray);
1024
1025 int lastRow = 0;
1026 for (const KisSwatchGroupSP &group : d->swatchGroups) {
1027 int lastRowGroup = 0;
1028 for (const KisSwatchGroup::SwatchInfo &info : group->infoList()) {
1029 QColor c = info.swatch.color().toQColor();
1030 gc.fillRect(info.column * 4, (lastRow + info.row) * 4, 4, 4, c);
1031 lastRowGroup = qMax(lastRowGroup, info.row);
1032 }
1033 lastRow += (lastRowGroup + 1);
1034 }
1035
1036 setImage(img);
1037}
void setImage(const QImage &image)

References d, and KoResource::setImage().

Friends And Related Symbol Documentation

◆ AddGroupCommand

friend struct AddGroupCommand
friend

Definition at line 276 of file KoColorSet.h.

◆ AddSwatchCommand

friend struct AddSwatchCommand
friend

Definition at line 273 of file KoColorSet.h.

◆ ChangeGroupNameCommand

friend struct ChangeGroupNameCommand
friend

Definition at line 275 of file KoColorSet.h.

◆ ClearCommand

friend struct ClearCommand
friend

Definition at line 278 of file KoColorSet.h.

◆ MoveGroupCommand

friend struct MoveGroupCommand
friend

Definition at line 282 of file KoColorSet.h.

◆ RemoveGroupCommand

friend struct RemoveGroupCommand
friend

Definition at line 277 of file KoColorSet.h.

◆ RemoveSwatchCommand

friend struct RemoveSwatchCommand
friend

Definition at line 274 of file KoColorSet.h.

◆ SetColumnCountCommand

friend struct SetColumnCountCommand
friend

Definition at line 279 of file KoColorSet.h.

◆ SetCommentCommand

friend struct SetCommentCommand
friend

Definition at line 280 of file KoColorSet.h.

◆ SetPaletteTypeCommand

friend struct SetPaletteTypeCommand
friend

Definition at line 281 of file KoColorSet.h.

◆ TestKisPaletteModel

friend class TestKisPaletteModel
friend

Definition at line 284 of file KoColorSet.h.

◆ TestKoColorSet

friend class TestKoColorSet
friend

Definition at line 283 of file KoColorSet.h.

Member Data Documentation

◆ d

const QScopedPointer<Private> KoColorSet::d
private

Definition at line 287 of file KoColorSet.h.

◆ GLOBAL_GROUP_NAME

const QString KoColorSet::GLOBAL_GROUP_NAME = QString()
static

Definition at line 33 of file KoColorSet.h.

◆ KPL_COLOR_DEPTH_ID_ATTR

const QString KoColorSet::KPL_COLOR_DEPTH_ID_ATTR = "colorDepthId"
static

Definition at line 42 of file KoColorSet.h.

◆ KPL_COLOR_MODEL_ID_ATTR

const QString KoColorSet::KPL_COLOR_MODEL_ID_ATTR = "colorModelId"
static

Definition at line 41 of file KoColorSet.h.

◆ KPL_GROUP_NAME_ATTR

const QString KoColorSet::KPL_GROUP_NAME_ATTR = "name"
static

Definition at line 43 of file KoColorSet.h.

◆ KPL_GROUP_ROW_COUNT_ATTR

const QString KoColorSet::KPL_GROUP_ROW_COUNT_ATTR = "rows"
static

Definition at line 35 of file KoColorSet.h.

◆ KPL_GROUP_TAG

const QString KoColorSet::KPL_GROUP_TAG = "Group"
static

Definition at line 53 of file KoColorSet.h.

◆ KPL_PALETTE_COLUMN_COUNT_ATTR

const QString KoColorSet::KPL_PALETTE_COLUMN_COUNT_ATTR = "columns"
static

Definition at line 36 of file KoColorSet.h.

◆ KPL_PALETTE_COMMENT_ATTR

const QString KoColorSet::KPL_PALETTE_COMMENT_ATTR = "comment"
static

Definition at line 38 of file KoColorSet.h.

◆ KPL_PALETTE_FILENAME_ATTR

const QString KoColorSet::KPL_PALETTE_FILENAME_ATTR = "filename"
static

Definition at line 39 of file KoColorSet.h.

◆ KPL_PALETTE_NAME_ATTR

const QString KoColorSet::KPL_PALETTE_NAME_ATTR = "name"
static

Definition at line 37 of file KoColorSet.h.

◆ KPL_PALETTE_PROFILE_TAG

const QString KoColorSet::KPL_PALETTE_PROFILE_TAG = "Profile"
static

Definition at line 50 of file KoColorSet.h.

◆ KPL_PALETTE_READONLY_ATTR

const QString KoColorSet::KPL_PALETTE_READONLY_ATTR = "readonly"
static

Definition at line 40 of file KoColorSet.h.

◆ KPL_PALETTE_TAG

const QString KoColorSet::KPL_PALETTE_TAG = "ColorSet"
static

Definition at line 54 of file KoColorSet.h.

◆ KPL_SWATCH_BITDEPTH_ATTR

const QString KoColorSet::KPL_SWATCH_BITDEPTH_ATTR = "bitdepth"
static

Definition at line 49 of file KoColorSet.h.

◆ KPL_SWATCH_COL_ATTR

const QString KoColorSet::KPL_SWATCH_COL_ATTR = "column"
static

Definition at line 45 of file KoColorSet.h.

◆ KPL_SWATCH_ID_ATTR

const QString KoColorSet::KPL_SWATCH_ID_ATTR = "id"
static

Definition at line 48 of file KoColorSet.h.

◆ KPL_SWATCH_NAME_ATTR

const QString KoColorSet::KPL_SWATCH_NAME_ATTR = "name"
static

Definition at line 46 of file KoColorSet.h.

◆ KPL_SWATCH_POS_TAG

const QString KoColorSet::KPL_SWATCH_POS_TAG = "Position"
static

Definition at line 51 of file KoColorSet.h.

◆ KPL_SWATCH_ROW_ATTR

const QString KoColorSet::KPL_SWATCH_ROW_ATTR = "row"
static

Definition at line 44 of file KoColorSet.h.

◆ KPL_SWATCH_SPOT_ATTR

const QString KoColorSet::KPL_SWATCH_SPOT_ATTR = "spot"
static

Definition at line 47 of file KoColorSet.h.

◆ KPL_SWATCH_TAG

const QString KoColorSet::KPL_SWATCH_TAG = "ColorSetEntry"
static

Definition at line 52 of file KoColorSet.h.

◆ KPL_VERSION_ATTR

const QString KoColorSet::KPL_VERSION_ATTR = "version"
static

Definition at line 34 of file KoColorSet.h.


The documentation for this class was generated from the following files: