kalarm Library API Documentation

colourcombo.cpp

00001 /*
00002  *  colourcombo.cpp  -  colour selection combo box
00003  *  Program:  kalarm
00004  *  (C) 2001 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
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #include "colourcombo.h"
00022 
00023 
00024 ColourCombo::ColourCombo(QWidget* parent, const char* name, const QColor& defaultColour)
00025    :  KColorCombo(parent, name),
00026       selection(defaultColour),
00027       disabled(false)
00028 {
00029         deleteColours();
00030 }
00031 
00032 void ColourCombo::setColour(const QColor& col)
00033 {
00034         selection = col;
00035         KColorCombo::setColor(col);
00036         deleteColours();
00037 }
00038 
00039 void ColourCombo::resizeEvent(QResizeEvent* re)
00040 {
00041         KColorCombo::resizeEvent(re);
00042         deleteColours();
00043 }
00044 
00045 /******************************************************************************
00046 *  This function removes the unwanted colours which KColorCombo inserts,
00047 *  and resets the current selection to the correct item.
00048 */
00049 void ColourCombo::deleteColours()
00050 {
00051         // Remove all colours except bright ones.
00052         // Also leave the "Custom..." item, which is the first in the list.
00053         int selitem = 0;
00054         for (int i = count();  --i > 0;  )
00055         {
00056                 setCurrentItem(i);
00057                 QColor colour = color();
00058                 if (colour.red() != 255  &&  colour.green() != 255  &&  colour.blue() != 255)
00059                 {
00060                         removeItem(i);
00061                         if (selitem)
00062                                 --selitem;
00063                 }
00064                 else if (colour == selection)
00065                         selitem = i;
00066         }
00067         if (disabled)
00068                 addDisabledColour();
00069         else
00070                 setCurrentItem(selitem);
00071 }
00072 
00073 void ColourCombo::setEnabled(bool enable)
00074 {
00075         if (enable  &&  disabled)
00076         {
00077                 disabled = false;
00078                 setColour(selection);
00079         }
00080         else if (!enable  &&  !disabled)
00081         {
00082                 selection = color();
00083                 addDisabledColour();
00084                 disabled = true;
00085         }
00086         KColorCombo::setEnabled(enable);
00087 }
00088 
00089 void ColourCombo::addDisabledColour()
00090 {
00091         int end = count();
00092         if (end > 1)
00093         {
00094                 QPixmap pm = *pixmap(1);
00095                 pm.fill(backgroundColor());
00096                 insertItem(pm);
00097                 setCurrentItem(end);
00098         }
00099 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:26 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001