1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/*
* colourcombo.h - colour selection combo box
* Program: kalarm
* Copyright © 2001-2003,2005,2006 by David Jarvie <software@astrojar.org.uk>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef COLOURCOMBO_H
#define COLOURCOMBO_H
#include <qcombobox.h>
#include "colourlist.h"
/**
* @short A colour selection combo box whose colour list can be specified.
*
* The ColourCombo class is a combo box allowing the user to select a colour.
*
* It is similar to KColorCombo but allows the list of colours to be restricted to those
* which are specified. The first item in the list is a custom colour entry, which allows
* the user to define an arbitrary colour. The remaining entries in the list are preset
* by the program.
*
* The widget may be set as read-only. This has the same effect as disabling it, except
* that its appearance is unchanged.
*
* @author David Jarvie <software@astrojar.org.uk>
*/
class ColourCombo : public QComboBox
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor)
public:
/** Constructor.
* @param parent The parent object of this widget.
* @param name The name of this widget.
* @param defaultColour The colour which is selected by default.
*/
explicit ColourCombo(QWidget* parent = 0, const char* name = 0, const QColor& defaultColour = 0xFFFFFF);
/** Returns the selected colour. */
QColor color() const { return mSelectedColour; }
/** Returns the selected colour. */
QColor colour() const { return mSelectedColour; }
/** Sets the selected colour to @p c. */
void setColor(const QColor& c) { setColour(c); }
/** Sets the selected colour to @p c. */
void setColour(const QColor& c);
/** Initialises the list of colours to @p list. */
void setColours(const ColourList& list);
/** Returns true if the first entry in the list, i.e. the custom colour, is selected. */
bool isCustomColour() const { return !currentItem(); }
/** Returns true if the widget is read only. */
bool isReadOnly() const { return mReadOnly; }
/** Sets whether the combo box can be changed by the user.
* @param readOnly True to set the widget read-only, false to set it read-write.
*/
virtual void setReadOnly(bool readOnly);
signals:
/** Signal emitted when a new colour has been selected. */
void activated(const QColor&); // a new colour box has been selected
/** Signal emitted when a new colour has been highlighted. */
void highlighted(const QColor&); // a new item has been highlighted
public slots:
/** Enables or disables the widget. */
virtual void setEnabled(bool enabled);
protected:
virtual void resizeEvent(QResizeEvent*);
virtual void mousePressEvent(QMouseEvent*);
virtual void mouseReleaseEvent(QMouseEvent*);
virtual void mouseMoveEvent(QMouseEvent*);
virtual void keyPressEvent(QKeyEvent*);
virtual void keyReleaseEvent(QKeyEvent*);
private slots:
void slotActivated(int index);
void slotHighlighted(int index);
void slotPreferencesChanged();
private:
void addColours();
void drawCustomItem(QRect&, bool insert);
ColourList mColourList; // the sorted colours to display
QColor mSelectedColour; // currently selected colour
QColor mCustomColour; // current colour of the Custom item
bool mReadOnly; // value cannot be changed
bool mDisabled;
};
#endif // COLOURCOMBO_H
|