From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kalarm/lib/colourcombo.h | 102 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 kalarm/lib/colourcombo.h (limited to 'kalarm/lib/colourcombo.h') diff --git a/kalarm/lib/colourcombo.h b/kalarm/lib/colourcombo.h new file mode 100644 index 00000000..f3e4ebca --- /dev/null +++ b/kalarm/lib/colourcombo.h @@ -0,0 +1,102 @@ +/* + * colourcombo.h - colour selection combo box + * Program: kalarm + * Copyright © 2001-2003,2005,2006 by David Jarvie + * + * 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 +#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 + */ +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 -- cgit v1.2.3