21 #include <tqobjectlist.h>
23 #include <tqgroupbox.h>
24 #include <tqpushbutton.h>
28 #include <tqwhatsthis.h>
30 #include <tdeglobal.h>
31 #include <tdelocale.h>
32 #include <kcolordialog.h>
35 #include "preferences.h"
36 #include "colourcombo.h"
38 #include "fontcolour.moc"
41 FontColourChooser::FontColourChooser(TQWidget *parent,
const char *name,
42 bool onlyFixed,
const TQStringList &fontList,
43 const TQString& frameLabel,
bool editColours,
bool fg,
bool defaultFont,
45 : TQWidget(parent, name),
47 mRemoveColourButton(0),
48 mColourList(Preferences::messageColours()),
51 TQVBoxLayout* topLayout =
new TQVBoxLayout(
this, 0, KDialog::spacingHint());
52 TQWidget* page =
this;
53 if (!frameLabel.isNull())
55 page =
new TQGroupBox(frameLabel,
this);
56 topLayout->addWidget(page);
57 topLayout =
new TQVBoxLayout(page, KDialog::marginHint(), KDialog::spacingHint());
58 topLayout->addSpacing(fontMetrics().height() - KDialog::marginHint() + KDialog::spacingHint());
60 TQHBoxLayout* hlayout =
new TQHBoxLayout(topLayout);
61 TQVBoxLayout* colourLayout =
new TQVBoxLayout(hlayout);
64 TQHBox* box =
new TQHBox(page);
65 box->setSpacing(KDialog::spacingHint()/2);
66 colourLayout->addWidget(box);
68 TQLabel* label =
new TQLabel(i18n(
"&Foreground color:"), box);
69 box->setStretchFactor(
new TQWidget(box), 0);
70 mFgColourButton =
new ColourCombo(box);
71 connect(mFgColourButton, TQ_SIGNAL(activated(
const TQString&)), TQ_SLOT(setSampleColour()));
72 label->setBuddy(mFgColourButton);
73 TQWhatsThis::add(box, i18n(
"Select the alarm message foreground color"));
76 TQHBox* box =
new TQHBox(page);
77 box->setSpacing(KDialog::spacingHint()/2);
78 colourLayout->addWidget(box);
80 TQLabel* label =
new TQLabel(i18n(
"&Background color:"), box);
81 box->setStretchFactor(
new TQWidget(box), 0);
82 mBgColourButton =
new ColourCombo(box);
83 connect(mBgColourButton, TQ_SIGNAL(activated(
const TQString&)), TQ_SLOT(setSampleColour()));
84 label->setBuddy(mBgColourButton);
85 TQWhatsThis::add(box, i18n(
"Select the alarm message background color"));
86 hlayout->addStretch();
90 TQHBoxLayout* layout =
new TQHBoxLayout(topLayout);
91 TQPushButton* button =
new TQPushButton(i18n(
"Add Co&lor..."), page);
92 button->setFixedSize(button->sizeHint());
93 connect(button, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddColour()));
94 TQWhatsThis::add(button, i18n(
"Choose a new color to add to the color selection list."));
95 layout->addWidget(button);
97 mRemoveColourButton =
new TQPushButton(i18n(
"&Remove Color"), page);
98 mRemoveColourButton->setFixedSize(mRemoveColourButton->sizeHint());
99 connect(mRemoveColourButton, TQ_SIGNAL(clicked()), TQ_SLOT(slotRemoveColour()));
100 TQWhatsThis::add(mRemoveColourButton,
101 i18n(
"Remove the color currently shown in the background color chooser, from the color selection list."));
102 layout->addWidget(mRemoveColourButton);
107 TQHBoxLayout* layout =
new TQHBoxLayout(topLayout);
108 mDefaultFont =
new CheckBox(i18n(
"Use &default font"), page);
109 mDefaultFont->setMinimumSize(mDefaultFont->sizeHint());
110 connect(mDefaultFont, TQ_SIGNAL(toggled(
bool)), TQ_SLOT(slotDefaultFontToggled(
bool)));
111 TQWhatsThis::add(mDefaultFont,
112 i18n(
"Check to use the default font current at the time the alarm is displayed."));
113 layout->addWidget(mDefaultFont);
114 layout->addWidget(
new TQWidget(page));
119 mFontChooser =
new TDEFontChooser(page, name, onlyFixed, fontList,
false, visibleListSize);
120 mFontChooser->installEventFilter(
this);
121 const TQObjectList* kids = mFontChooser->queryList();
122 for (TQObjectList::ConstIterator it = kids->constBegin(); it != kids->constEnd(); ++it)
123 (*it)->installEventFilter(
this);
124 topLayout->addWidget(mFontChooser);
126 slotDefaultFontToggled(
false);
129 void FontColourChooser::setDefaultFont()
132 mDefaultFont->setChecked(
true);
135 void FontColourChooser::setFont(
const TQFont& font,
bool onlyFixed)
138 mDefaultFont->setChecked(
false);
139 mFontChooser->setFont(font, onlyFixed);
142 bool FontColourChooser::defaultFont()
const
144 return mDefaultFont ? mDefaultFont->isChecked() :
false;
147 TQFont FontColourChooser::font()
const
149 return (mDefaultFont && mDefaultFont->isChecked()) ? TQFont() : mFontChooser->font();
152 void FontColourChooser::setBgColour(
const TQColor& colour)
154 mBgColourButton->setColor(colour);
155 mFontChooser->setBackgroundColor(colour);
158 void FontColourChooser::setSampleColour()
160 TQColor bg = mBgColourButton->color();
161 mFontChooser->setBackgroundColor(bg);
162 TQColor fg = fgColour();
163 mFontChooser->setColor(fg);
164 if (mRemoveColourButton)
165 mRemoveColourButton->setEnabled(!mBgColourButton->isCustomColour());
168 TQColor FontColourChooser::bgColour()
const
170 return mBgColourButton->color();
173 TQColor FontColourChooser::fgColour()
const
176 return mFgColourButton->color();
179 TQColor bg = mBgColourButton->color();
180 TQPalette pal(bg, bg);
181 return pal.color(TQPalette::Active, TQColorGroup::Text);
185 TQString FontColourChooser::sampleText()
const
187 return mFontChooser->sampleText();
190 void FontColourChooser::setSampleText(
const TQString& text)
192 mFontChooser->setSampleText(text);
195 void FontColourChooser::setFgColour(
const TQColor& colour)
199 mFgColourButton->setColor(colour);
200 mFontChooser->setColor(colour);
204 void FontColourChooser::setReadOnly(
bool ro)
210 mFgColourButton->setReadOnly(ro);
211 mBgColourButton->setReadOnly(ro);
212 mDefaultFont->setReadOnly(ro);
216 bool FontColourChooser::eventFilter(TQObject*, TQEvent* e)
222 case TQEvent::MouseButtonPress:
223 case TQEvent::MouseButtonRelease:
224 case TQEvent::MouseButtonDblClick:
225 case TQEvent::KeyPress:
226 case TQEvent::KeyRelease:
235 void FontColourChooser::slotDefaultFontToggled(
bool on)
237 mFontChooser->setEnabled(!on);
240 void FontColourChooser::setColours(
const ColourList& colours)
242 mColourList = colours;
243 mBgColourButton->setColours(mColourList);
244 mFontChooser->setBackgroundColor(mBgColourButton->color());
247 void FontColourChooser::slotAddColour()
250 if (KColorDialog::getColor(colour,
this) == TQDialog::Accepted)
252 mColourList.insert(colour);
253 mBgColourButton->setColours(mColourList);
257 void FontColourChooser::slotRemoveColour()
259 if (!mBgColourButton->isCustomColour())
261 mColourList.remove(mBgColourButton->color());
262 mBgColourButton->setColours(mColourList);
the KAlarm application object