1 /***************************************************************************
2  *   Copyright (C) 2005 by David Saxton                                    *
3  *   david@bluehaze.org                                                    *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10 
11 #ifndef COLORCOMBO_H
12 #define COLORCOMBO_H
13 
14 #include <QColor>
15 #include <QComboBox>
16 
17 /**
18 Based on KColorCombo, Copyright (C) 1997 Martin Jones (mjones@kde.org). Allows
19 which colours are displayed to be changed.
20 
21 @author David Saxton
22 */
23 class ColorCombo : public QComboBox
24 {
25 	Q_OBJECT
26 	Q_PROPERTY( QColor color READ color WRITE setColor )
27 
28 	public:
29 		enum ColorScheme
30 		{
31 			QtStandard = 0,
32 			LED = 1,
33 			NumberOfSchemes = 2 ///< for internal usage; this should be one less than the number of items in the enum
34 		};
35 
36   	 	/**
37 		 * Constructs a color combo box.
38 		 */
39 		ColorCombo( ColorScheme colorScheme, QWidget *parent, const char *name = nullptr );
40 		~ColorCombo() override;
41 
42 		/**
43 		 * Returns the currently selected color.
44 		**/
color()45 		QColor color() const { return internalColor; }
46 
47 	public slots:
48 		/**
49 		 * Selects the color @p col.
50 		 */
51 		void setColor( const QColor & col );
52 
53 	signals:
54     	/**
55 		 * Emitted when a new color box has been selected.
56 		 */
57 		void activated( const QColor &col );
58 	    /**
59 		 * Emitted when a new item has been highlighted.
60 		 */
61 		void highlighted( const QColor &col );
62 
63 	protected slots:
64 		void slotActivated( int index );
65 		void slotHighlighted( int index );
66 
67 	protected:
68 		void resizeEvent( QResizeEvent *re ) override;
69 		void addColors();
70 		void createPalettes();
71 
72 		QColor customColor;
73 		QColor internalColor;
74 		ColorScheme m_colorScheme;
75 
76 		static bool createdPalettes;
77 		static QColor * palette[ NumberOfSchemes ];
78 		static int paletteSize[ NumberOfSchemes ];
79 };
80 
81 #endif
82