colourcombo.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00047
00048
00049 void ColourCombo::deleteColours()
00050 {
00051
00052
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 }
This file is part of the documentation for kdelibs Version 3.1.5.