File indexing completed on 2024-05-12 04:21:20
0001 0002 // SYNC: Periodically merge in changes from: 0003 // 0004 // trunk/KDE/kdelibs/kdeui/colors/kcolorcollection.{h,cpp} 0005 // 0006 // which this is a fork of. 0007 // 0008 // Our changes can be merged back into KDE (grep for "Added for KolourPaint" and similar). 0009 0010 /* This file is part of the KDE libraries 0011 Copyright (C) 1999 Waldo Bastian (bastian@kde.org) 0012 Copyright (C) 2007 Clarence Dang (dang@kde.org) 0013 0014 This library is free software; you can redistribute it and/or 0015 modify it under the terms of the GNU Library General Public 0016 License as published by the Free Software Foundation; version 0017 2 of the License. 0018 0019 This library is distributed in the hope that it will be useful, 0020 but WITHOUT ANY WARRANTY; without even the implied warranty of 0021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0022 Library General Public License for more details. 0023 0024 You should have received a copy of the GNU Library General Public License 0025 along with this library; see the file COPYING.LIB. If not, write to 0026 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0027 Boston, MA 02110-1301, USA. 0028 */ 0029 //----------------------------------------------------------------------------- 0030 // KDE color collection. 0031 0032 #ifndef kpColorCollection_H 0033 #define kpColorCollection_H 0034 0035 #include <kolourpaint_lgpl_export.h> 0036 0037 #include <QColor> 0038 #include <QString> 0039 #include <QStringList> 0040 #include <QWidget> 0041 0042 class QUrl; 0043 0044 /** 0045 * Class for handling color collections ("palettes"). 0046 * 0047 * This class makes it easy to handle color collections, sometimes referred to 0048 * as "palettes". This class can read and write collections from and to a file. 0049 * 0050 * Collections that are managed by KDE have a non-empty name(). Collections 0051 * stored in regular files have an empty name(). 0052 * 0053 * This class uses the "GIMP" palette file format. 0054 * 0055 * @author Waldo Bastian (bastian@kde.org), Clarence Dang (dang@kde.org) 0056 **/ 0057 class KOLOURPAINT_LGPL_EXPORT kpColorCollection 0058 { 0059 public: 0060 /** 0061 * Query which KDE color collections are installed. 0062 * 0063 * @return A list with installed color collection names. 0064 */ 0065 static QStringList installedCollections(); 0066 0067 /** 0068 * kpColorCollection constructor 0069 * 0070 * <name> argument removed for KolourPaint. 0071 * Use openKDE() instead, which also has error handling. 0072 **/ 0073 explicit kpColorCollection(); 0074 0075 /** 0076 * kpColorCollection copy constructor. 0077 **/ 0078 kpColorCollection(const kpColorCollection &); 0079 0080 /** 0081 * kpColorCollection destructor. 0082 **/ 0083 ~kpColorCollection(); 0084 0085 /** 0086 * kpColorCollection assignment operator 0087 **/ 0088 kpColorCollection& operator=( const kpColorCollection &); 0089 0090 // On failure, this prints an error dialog and returns false. 0091 // On success, it sets the name() to an empty string and returns true. 0092 // 0093 // Added for KolourPaint. 0094 bool open(const QUrl &url, QWidget *parent); 0095 0096 // Same as open() but is given the name of a KDE palette, not a filename. 0097 // 0098 // @param name The name of collection as returned by installedCollections(). 0099 // name() is set to this. 0100 // 0101 // Added for KolourPaint. 0102 bool openKDE(const QString &name, QWidget *parent); 0103 0104 // On failure, this prints an error dialog and returns false. 0105 // If the user cancels any presented overwrite dialog, it also returns false. 0106 // On success, it returns true. 0107 // 0108 // The file can be overwritten without displaying any warning dialog, if 0109 // <showOverwritePrompt> is set to false. 0110 // 0111 // name() is set to an empty string. 0112 // 0113 // Added for KolourPaint. 0114 bool saveAs(const QUrl &url, QWidget *parent) const; 0115 0116 /** 0117 * Get the description of the collection. 0118 * @return the description of the collection. 0119 **/ 0120 QString description() const; 0121 0122 /** 0123 * Set the description of the collection. 0124 * @param desc the new description 0125 **/ 0126 void setDescription(const QString &desc); 0127 0128 /** 0129 * Get the name of the collection. 0130 * @return the name of the collection 0131 **/ 0132 QString name() const; 0133 0134 /** 0135 * Set the name of the collection. 0136 * @param name the name of the collection 0137 **/ 0138 void setName(const QString &name); 0139 0140 /** 0141 * Used to specify whether a collection may be edited. 0142 * @see editable() 0143 * @see setEditable() 0144 */ 0145 enum Editable { Yes, ///< Collection may be edited 0146 No, ///< Collection may not be edited 0147 Ask ///< Ask user before editing 0148 }; 0149 0150 /** 0151 * Returns whether the collection may be edited. 0152 * @return the state of the collection 0153 **/ 0154 Editable editable() const; 0155 0156 /** 0157 * Change whether the collection may be edited. 0158 * @param editable the state of the collection 0159 **/ 0160 void setEditable(Editable editable); 0161 0162 /** 0163 * Return the number of colors in the collection. 0164 * @return the number of colors 0165 **/ 0166 int count() const; 0167 0168 /** 0169 * Adds invalid colors or removes colors so that there will be @p newCount 0170 * colors in the color collection. 0171 * 0172 * @param target number of colors 0173 * 0174 * Added for KolourPaint. 0175 */ 0176 void resize(int newCount); 0177 0178 /** 0179 * Find color by index. 0180 * @param index the index of the desired color 0181 * @return The @p index -th color of the collection, null if not found. 0182 **/ 0183 QColor color(int index) const; 0184 0185 /** 0186 * Find index by @p color. 0187 * @param color the color to find 0188 * @return The index of the color in the collection or -1 if the 0189 * color is not found. 0190 **/ 0191 int findColor(const QColor &color) const; 0192 0193 /** 0194 * Find color name by @p index. 0195 * @param index the index of the color 0196 * @return The name of the @p index -th color. 0197 * Note that not all collections have named the colors. Null is 0198 * returned if the color does not exist or has no name. 0199 **/ 0200 QString name(int index) const; 0201 0202 /** 0203 * Find color name by @p color. 0204 * @return The name of color according to this collection. 0205 * Note that not all collections have named the colors. 0206 * Note also that each collection can give the same color 0207 * a different name. 0208 **/ 0209 QString name(const QColor &color) const; 0210 0211 /** 0212 * Add a color. 0213 * @param newColor The color to add. 0214 * @param newColorName The name of the color, null to remove 0215 * the name. 0216 * @return The index of the added color. 0217 **/ 0218 int addColor(const QColor &newColor, 0219 const QString &newColorName = QString()); 0220 0221 /** 0222 * Change a color. 0223 * @param index Index of the color to change 0224 * @param newColor The new color. 0225 * @param newColorName The new color name, null to remove 0226 * the name. 0227 * @return The index of the new color or -1 if the color couldn't 0228 * be changed. 0229 **/ 0230 int changeColor(int index, 0231 const QColor &newColor, 0232 const QString &newColorName = QString()); 0233 0234 /** 0235 * Change a color. 0236 * @param oldColor The original color 0237 * @param newColor The new color. 0238 * @param newColorName The new color name, null to remove 0239 * the name. 0240 * @return The index of the new color or -1 if the color couldn't 0241 * be changed. 0242 **/ 0243 int changeColor(const QColor &oldColor, 0244 const QColor &newColor, 0245 const QString &newColorName = QString()); 0246 0247 private: 0248 class kpColorCollectionPrivate *d; 0249 }; 0250 0251 0252 #endif // kpColorCollection_H 0253