kalarm/lib

colourcombo.h

00001 /*
00002  *  colourcombo.h  -  colour selection combo box
00003  *  Program:  kalarm
00004  *  Copyright © 2001-2003,2005,2006 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef COLOURCOMBO_H
00022 #define COLOURCOMBO_H
00023 
00024 #include <tqcombobox.h>
00025 #include "colourlist.h"
00026 
00027 
00043 class ColourCombo : public TQComboBox
00044 {
00045         Q_OBJECT
00046   TQ_OBJECT
00047         TQ_PROPERTY(TQColor color READ color WRITE setColor)
00048     public:
00054         explicit ColourCombo(TQWidget* parent = 0, const char* name = 0, const TQColor& defaultColour = 0xFFFFFF);
00056         TQColor       color() const               { return mSelectedColour; }
00058         TQColor       colour() const              { return mSelectedColour; }
00060         void         setColor(const TQColor& c)   { setColour(c); }
00062         void         setColour(const TQColor& c);
00064         void         setColours(const ColourList& list);
00066         bool         isCustomColour() const      { return !currentItem(); }
00068         bool         isReadOnly() const          { return mReadOnly; }
00072         virtual void setReadOnly(bool readOnly);
00073     signals:
00075         void         activated(const TQColor&);    // a new colour box has been selected
00077         void         highlighted(const TQColor&);  // a new item has been highlighted
00078     public slots:
00080         virtual void setEnabled(bool enabled);
00081     protected:
00082         virtual void resizeEvent(TQResizeEvent*);
00083         virtual void mousePressEvent(TQMouseEvent*);
00084         virtual void mouseReleaseEvent(TQMouseEvent*);
00085         virtual void mouseMoveEvent(TQMouseEvent*);
00086         virtual void keyPressEvent(TQKeyEvent*);
00087         virtual void keyReleaseEvent(TQKeyEvent*);
00088     private slots:
00089         void         slotActivated(int index);
00090         void         slotHighlighted(int index);
00091         void         slotPreferencesChanged();
00092     private:
00093         void         addColours();
00094         void         drawCustomItem(TQRect&, bool insert);
00095 
00096         ColourList   mColourList;      // the sorted colours to display
00097         TQColor       mSelectedColour;  // currently selected colour
00098         TQColor       mCustomColour;    // current colour of the Custom item
00099         bool         mReadOnly;        // value cannot be changed
00100         bool         mDisabled;
00101 };
00102 
00103 #endif // COLOURCOMBO_H