File indexing completed on 2024-04-28 03:59:02

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 1997 Martin Jones <mjones@kde.org>
0004     SPDX-FileCopyrightText: 2007 David Jarvie <djarvie@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 //-----------------------------------------------------------------------------
0009 // KDE color selection combo box
0010 
0011 // layout management added Oct 1997 by Mario Weilguni
0012 // <mweilguni@sime.com>
0013 
0014 #ifndef KCOLORCOMBO_H
0015 #define KCOLORCOMBO_H
0016 
0017 #include <QComboBox>
0018 #include <QList>
0019 
0020 #include <kwidgetsaddons_export.h>
0021 
0022 #include <memory>
0023 
0024 /**
0025  * @class KColorCombo kcolorcombo.h KColorCombo
0026  *
0027  * Combobox for colors.
0028  *
0029  * The combobox provides some preset colors to be selected, and an entry to
0030  * select a custom color using a color dialog.
0031  *
0032  * \image html kcolorcombo.png "KColorCombo Widget"
0033  */
0034 class KWIDGETSADDONS_EXPORT KColorCombo : public QComboBox
0035 {
0036     Q_OBJECT
0037     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY activated USER true)
0038     Q_PROPERTY(QList<QColor> colors READ colors WRITE setColors)
0039 
0040 public:
0041     /**
0042      * Constructs a color combo box.
0043      */
0044     explicit KColorCombo(QWidget *parent = nullptr);
0045     ~KColorCombo() override;
0046 
0047     /**
0048      * Selects the color @p col.
0049      */
0050     void setColor(const QColor &col);
0051 
0052     /**
0053      * Returns the currently selected color.
0054      */
0055     QColor color() const;
0056 
0057     /**
0058      * Find whether the currently selected color is a custom color selected
0059      * using a color dialog.
0060      */
0061     bool isCustomColor() const;
0062 
0063     /**
0064      * Set a custom list of colors to choose from, in place of the standard
0065      * list.
0066      * @param colors list of colors. If empty, the selection list reverts to
0067      *             the standard list.
0068      */
0069     void setColors(const QList<QColor> &colors);
0070 
0071     /**
0072      * Return the list of colors available for selection.
0073      * @return list of colors
0074      */
0075     QList<QColor> colors() const;
0076 
0077     /**
0078      * Clear the color list and don't show it, till the next setColor() call
0079      */
0080     void showEmptyList();
0081 
0082 Q_SIGNALS:
0083     /**
0084      * Emitted when a new color box has been selected.
0085      */
0086     void activated(const QColor &col);
0087     /**
0088      * Emitted when a new item has been highlighted.
0089      */
0090     void highlighted(const QColor &col);
0091 
0092 protected:
0093     void paintEvent(QPaintEvent *event) override;
0094 
0095 private:
0096     friend class KColorComboPrivate;
0097     std::unique_ptr<class KColorComboPrivate> const d;
0098 
0099     Q_DISABLE_COPY(KColorCombo)
0100 };
0101 
0102 #endif // KCOLORCOMBO_H