File indexing completed on 2024-04-21 04:40:59

0001 /* This file is part of the KDE libraries
0002     Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation; version
0007     2 of the License.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 //-----------------------------------------------------------------------------
0020 // KDE color collection.
0021 
0022 #ifndef KDELIBS_KCOLORCOLLECTION_H
0023 #define KDELIBS_KCOLORCOLLECTION_H
0024 
0025 #include <QColor>
0026 #include <QStringList>
0027 
0028 /**
0029  * Class for handling color collections ("palettes").
0030  *
0031  * This class makes it easy to handle color collections, sometimes referred to
0032  * as "palettes". This class can read and write collections from and to a file.
0033  *
0034  * This class uses the "GIMP" palette file format.
0035  *
0036  * @author Waldo Bastian (bastian@kde.org)
0037  **/
0038 class KColorCollection
0039 {
0040 public:
0041     /**
0042      * Query which KDE color collections are installed.
0043      *
0044      * @return A list with installed color collection names.
0045      */
0046     static QStringList installedCollections();
0047 
0048     /**
0049      * KColorCollection constructor. Creates a KColorCollection from a file
0050      * the filename is derived from the name.
0051      * @param name The name of collection as returned by installedCollections()
0052      **/
0053     explicit KColorCollection(const QString &name = QString());
0054 
0055     /**
0056      * KColorCollection copy constructor.
0057      **/
0058     KColorCollection(const KColorCollection &);
0059 
0060     /**
0061      * KColorCollection destructor.
0062      **/
0063     ~KColorCollection();
0064 
0065     /**
0066      * KColorCollection assignment operator
0067      **/
0068     KColorCollection &operator=(const KColorCollection &);
0069 
0070     /**
0071      * Save the collection
0072      *
0073      * @return 'true' if successful
0074      **/
0075     bool save();
0076 
0077     /**
0078      * Get the description of the collection.
0079      * @return the description of the collection.
0080      **/
0081     QString description() const;
0082 
0083     /**
0084      * Set the description of the collection.
0085      * @param desc the new description
0086      **/
0087     void setDescription(const QString &desc);
0088 
0089     /**
0090      * Get the name of the collection.
0091      * @return the name of the collection
0092      **/
0093     QString name() const;
0094 
0095     /**
0096      * Set the name of the collection.
0097      * @param name the name of the collection
0098      **/
0099     void setName(const QString &name);
0100 
0101     /**
0102      * Used to specify whether a collection may be edited.
0103      * @see editable()
0104      * @see setEditable()
0105      */
0106     enum Editable { Yes, ///< Collection may be edited
0107                     No,  ///< Collection may not be edited
0108                     Ask  ///< Ask user before editing
0109                   };
0110 
0111     /**
0112      * Returns whether the collection may be edited.
0113      * @return the state of the collection
0114      **/
0115     Editable editable() const;
0116 
0117     /**
0118      * Change whether the collection may be edited.
0119      * @param editable the state of the collection
0120      **/
0121     void setEditable(Editable editable);
0122 
0123     /**
0124      * Return the number of colors in the collection.
0125      * @return the number of colors
0126      **/
0127     int count() const;
0128 
0129     /**
0130      * Find color by index.
0131      * @param index the index of the desired color
0132      * @return The @p index -th color of the collection, null if not found.
0133      **/
0134     QColor color(int index) const;
0135 
0136     /**
0137      * Find index by @p color.
0138      * @param color the color to find
0139      * @return The index of the color in the collection or -1 if the
0140      * color is not found.
0141      **/
0142     int findColor(const QColor &color) const;
0143 
0144     /**
0145      * Find color name by @p index.
0146      * @param index the index of the color
0147      * @return The name of the @p index -th color.
0148      * Note that not all collections have named the colors. Null is
0149      * returned if the color does not exist or has no name.
0150      **/
0151     QString name(int index) const;
0152 
0153     /**
0154      * Find color name by @p color.
0155      * @return The name of color according to this collection.
0156      * Note that not all collections have named the colors.
0157      * Note also that each collection can give the same color
0158      * a different name.
0159      **/
0160     QString name(const QColor &color) const;
0161 
0162     /**
0163      * Add a color.
0164      * @param newColor The color to add.
0165      * @param newColorName The name of the color, null to remove
0166      *                     the name.
0167      * @return The index of the added color.
0168      **/
0169     int addColor(const QColor &newColor,
0170                  const QString &newColorName = QString());
0171 
0172     /**
0173      * Change a color.
0174      * @param index Index of the color to change
0175      * @param newColor The new color.
0176      * @param newColorName The new color name, null to remove
0177      *                     the name.
0178      * @return The index of the new color or -1 if the color couldn't
0179      * be changed.
0180      **/
0181     int changeColor(int index,
0182                     const QColor &newColor,
0183                     const QString &newColorName = QString());
0184 
0185     /**
0186      * Change a color.
0187      * @param oldColor The original color
0188      * @param newColor The new color.
0189      * @param newColorName The new color name, null to remove
0190      *                     the name.
0191      * @return The index of the new color or -1 if the color couldn't
0192      * be changed.
0193      **/
0194     int changeColor(const QColor &oldColor,
0195                     const QColor &newColor,
0196                     const QString &newColorName = QString());
0197 
0198 private:
0199     class KColorCollectionPrivate *d;
0200 };
0201 
0202 #endif // KDELIBS_KCOLORCOLLECTION_H
0203