24 #include <tqpainter.h>
26 #include <tdelocale.h>
27 #include <kcolordialog.h>
29 #include "kalarm/preferences.h"
30 #include "colourcombo.moc"
34 : TQComboBox(parent, name),
35 mColourList(Preferences::messageColours()),
36 mSelectedColour(defaultColour),
37 mCustomColour(255, 255, 255),
42 connect(
this, TQ_SIGNAL(
activated(
int)), TQ_SLOT(slotActivated(
int)));
43 connect(
this, TQ_SIGNAL(
highlighted(
int)), TQ_SLOT(slotHighlighted(
int)));
44 Preferences::connect(TQ_SIGNAL(preferencesChanged()),
this, TQ_SLOT(slotPreferencesChanged()));
58 mColourList = colours;
59 if (mSelectedColour != mCustomColour
60 && !mColourList.
contains(mSelectedColour))
63 mSelectedColour = mColourList.
count() ? mColourList.
first() : mCustomColour;
72 void ColourCombo::slotPreferencesChanged()
74 const ColourList& prefColours = Preferences::messageColours();
75 if (prefColours != mColourList)
85 if (enable && mDisabled)
90 else if (!enable && !mDisabled)
92 mSelectedColour =
color();
97 TQPixmap pm = *pixmap(1);
98 pm.fill(paletteBackgroundColor());
104 TQComboBox::setEnabled(enable);
107 void ColourCombo::slotActivated(
int index)
110 mSelectedColour = mColourList[index - 1];
113 if (KColorDialog::getColor(mCustomColour,
this) == TQDialog::Accepted)
116 drawCustomItem(rect,
false);
118 mSelectedColour = mCustomColour;
123 void ColourCombo::slotHighlighted(
int index)
125 mSelectedColour = index ? mColourList[index - 1] : mCustomColour;
132 void ColourCombo::addColours()
136 for (ColourList::const_iterator it = mColourList.
begin(); ; ++it)
138 if (it == mColourList.
end())
140 mCustomColour = mSelectedColour;
143 if (mSelectedColour == *it)
148 drawCustomItem(rect,
true);
151 TQPixmap pixmap(rect.width(), rect.height());
153 for (ColourList::const_iterator it = mColourList.
begin(); it != mColourList.
end(); ++i, ++it)
155 painter.begin(&pixmap);
157 painter.fillRect(rect, brush);
163 if (*it == mSelectedColour.rgb())
168 void ColourCombo::drawCustomItem(TQRect& rect,
bool insert)
171 if (tqGray(mCustomColour.rgb()) < 128)
172 pen.setColor(TQt::white);
174 pen.setColor(TQt::black);
177 TQFontMetrics fm = TQFontMetrics(painter.font());
178 rect.setRect(0, 0, width(), fm.height() + 4);
179 TQPixmap pixmap(rect.width(), rect.height());
181 painter.begin(&pixmap);
182 TQBrush brush(mCustomColour);
183 painter.fillRect(rect, brush);
185 painter.drawText(2, fm.ascent() + 2, i18n(
"Custom..."));
191 changeItem(pixmap, 0);
200 void ColourCombo::resizeEvent(TQResizeEvent* re)
202 TQComboBox::resizeEvent(re);
206 void ColourCombo::mousePressEvent(TQMouseEvent* e)
211 if (e->button() == TQt::LeftButton)
214 TQComboBox::mousePressEvent(e);
217 void ColourCombo::mouseReleaseEvent(TQMouseEvent* e)
220 TQComboBox::mouseReleaseEvent(e);
223 void ColourCombo::mouseMoveEvent(TQMouseEvent* e)
226 TQComboBox::mouseMoveEvent(e);
229 void ColourCombo::keyPressEvent(TQKeyEvent* e)
231 if (!mReadOnly || e->key() == TQt::Key_Escape)
232 TQComboBox::keyPressEvent(e);
235 void ColourCombo::keyReleaseEvent(TQKeyEvent* e)
238 TQComboBox::keyReleaseEvent(e);
void activated(const TQColor &)
Signal emitted when a new colour has been selected.
void setColours(const ColourList &list)
Initialises the list of colours to list.
TQColor colour() const
Returns the selected colour.
TQColor color() const
Returns the selected colour.
virtual void setEnabled(bool enabled)
Enables or disables the widget.
virtual void setReadOnly(bool readOnly)
Sets whether the combo box can be changed by the user.
void highlighted(const TQColor &)
Signal emitted when a new colour has been highlighted.
void setColour(const TQColor &c)
Sets the selected colour to c.
ColourCombo(TQWidget *parent=0, const char *name=0, const TQColor &defaultColour=0xFFFFFF)
Constructor.
Represents a sorted list of colours.
size_type contains(const TQColor &c) const
Returns true if the list contains the colour c.
size_type count() const
Returns the number of colours in the list.
const_iterator begin() const
Returns an iterator pointing to the first colour in the list.
const_iterator end() const
Returns an iterator pointing past the last colour in the list.
TQColor first() const
Returns the first colour in the list.