File indexing completed on 2024-04-28 04:41:03
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 1997 Martin Jones (mjones@kde.org) 0003 Copyright (c) 2007 David Jarvie (software@astrojar.org.uk) 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 //----------------------------------------------------------------------------- 0021 // KDE color selection combo box 0022 0023 // layout management added Oct 1997 by Mario Weilguni 0024 // <mweilguni@sime.com> 0025 0026 #ifndef KCOLORCOMBO_H 0027 #define KCOLORCOMBO_H 0028 0029 #include <QComboBox> 0030 #include <QList> 0031 0032 class KColorComboPrivate; 0033 0034 /** 0035 * Combobox for colors. 0036 * 0037 * The combobox provides some preset colors to be selected, and an entry to 0038 * select a custom color using a color dialog. 0039 * 0040 * \image html kcolorcombo.png "KDE Color Combo Box" 0041 */ 0042 class KColorCombo : public QComboBox 0043 { 0044 Q_OBJECT 0045 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY activated USER true) 0046 Q_PROPERTY(QList<QColor> colors READ colors WRITE setColors) 0047 0048 public: 0049 /** 0050 * Constructs a color combo box. 0051 */ 0052 explicit KColorCombo(QWidget *parent = 0); 0053 ~KColorCombo(); 0054 0055 /** 0056 * Selects the color @p col. 0057 */ 0058 void setColor(const QColor &col); 0059 0060 /** 0061 * Returns the currently selected color. 0062 **/ 0063 QColor color() const; 0064 0065 /** 0066 * Find whether the currently selected color is a custom color selected 0067 * using a color dialog. 0068 **/ 0069 bool isCustomColor() const; 0070 0071 /** 0072 * Set a custom list of colors to choose from, in place of the standard 0073 * list. 0074 * @param cols list of colors. If empty, the selection list reverts to 0075 * the standard list. 0076 **/ 0077 void setColors(const QList<QColor> &colors); 0078 0079 /** 0080 * Return the list of colors available for selection. 0081 * @return list of colors 0082 **/ 0083 QList<QColor> colors() const; 0084 0085 /** 0086 * Clear the color list and don't show it, till the next setColor() call 0087 **/ 0088 void showEmptyList(); 0089 0090 Q_SIGNALS: 0091 /** 0092 * Emitted when a new color box has been selected. 0093 */ 0094 void activated(const QColor &col); 0095 /** 0096 * Emitted when a new item has been highlighted. 0097 */ 0098 void highlighted(const QColor &col); 0099 0100 protected: 0101 void paintEvent(QPaintEvent *event) override; 0102 0103 private: 0104 friend class KColorComboPrivate; 0105 KColorComboPrivate *const d; 0106 0107 Q_DISABLE_COPY(KColorCombo) 0108 0109 Q_PRIVATE_SLOT(d, void _k_slotActivated(int)) 0110 Q_PRIVATE_SLOT(d, void _k_slotHighlighted(int)) 0111 }; 0112 0113 #endif // KCOLORCOMBO_H