00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qobjectlist.h>
00022 #include <qwidget.h>
00023 #include <qgroupbox.h>
00024 #include <qpushbutton.h>
00025 #include <qhbox.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qwhatsthis.h>
00029
00030 #include <kglobal.h>
00031 #include <klocale.h>
00032 #include <kcolordialog.h>
00033
00034 #include "kalarmapp.h"
00035 #include "preferences.h"
00036 #include "colourcombo.h"
00037 #include "checkbox.h"
00038 #include "fontcolour.moc"
00039
00040
00041 FontColourChooser::FontColourChooser(QWidget *parent, const char *name,
00042 bool onlyFixed, const QStringList &fontList,
00043 const QString& frameLabel, bool editColours, bool fg, bool defaultFont,
00044 int visibleListSize)
00045 : QWidget(parent, name),
00046 mFgColourButton(0),
00047 mRemoveColourButton(0),
00048 mColourList(Preferences::messageColours()),
00049 mReadOnly(false)
00050 {
00051 QVBoxLayout* topLayout = new QVBoxLayout(this, 0, KDialog::spacingHint());
00052 QWidget* page = this;
00053 if (!frameLabel.isNull())
00054 {
00055 page = new QGroupBox(frameLabel, this);
00056 topLayout->addWidget(page);
00057 topLayout = new QVBoxLayout(page, KDialog::marginHint(), KDialog::spacingHint());
00058 topLayout->addSpacing(fontMetrics().height() - KDialog::marginHint() + KDialog::spacingHint());
00059 }
00060 if (fg)
00061 {
00062 QBoxLayout* layout = new QHBoxLayout(topLayout);
00063 QHBox* box = new QHBox(page);
00064 box->setSpacing(KDialog::spacingHint());
00065 layout->addWidget(box);
00066
00067 QLabel* label = new QLabel(i18n("&Foreground color:"), box);
00068 label->setMinimumSize(label->sizeHint());
00069 mFgColourButton = new ColourCombo(box);
00070 mFgColourButton->setMinimumSize(mFgColourButton->sizeHint());
00071 connect(mFgColourButton, SIGNAL(activated(const QString&)), SLOT(setSampleColour()));
00072 label->setBuddy(mFgColourButton);
00073 QWhatsThis::add(box, i18n("Select the alarm message foreground color"));
00074 layout->addStretch();
00075 }
00076
00077 QBoxLayout* layout = new QHBoxLayout(topLayout);
00078 QHBox* box = new QHBox(page);
00079 box->setSpacing(KDialog::spacingHint());
00080 layout->addWidget(box);
00081
00082 QLabel* label = new QLabel(i18n("&Background color:"), box);
00083 label->setMinimumSize(label->sizeHint());
00084 mBgColourButton = new ColourCombo(box);
00085 mBgColourButton->setMinimumSize(mBgColourButton->sizeHint());
00086 connect(mBgColourButton, SIGNAL(activated(const QString&)), SLOT(setSampleColour()));
00087 label->setBuddy(mBgColourButton);
00088 QWhatsThis::add(box, i18n("Select the alarm message background color"));
00089 layout->addStretch();
00090
00091 if (editColours)
00092 {
00093 layout = new QHBoxLayout(topLayout);
00094 QPushButton* button = new QPushButton(i18n("Add Co&lor..."), page);
00095 button->setFixedSize(button->sizeHint());
00096 connect(button, SIGNAL(clicked()), SLOT(slotAddColour()));
00097 QWhatsThis::add(button, i18n("Choose a new color to add to the color selection list."));
00098 layout->addWidget(button);
00099
00100 mRemoveColourButton = new QPushButton(i18n("&Remove Color"), page);
00101 mRemoveColourButton->setFixedSize(mRemoveColourButton->sizeHint());
00102 connect(mRemoveColourButton, SIGNAL(clicked()), SLOT(slotRemoveColour()));
00103 QWhatsThis::add(mRemoveColourButton,
00104 i18n("Remove the color currently shown in the background color chooser, from the color selection list."));
00105 layout->addWidget(mRemoveColourButton);
00106 }
00107
00108 if (defaultFont)
00109 {
00110 layout = new QHBoxLayout(topLayout);
00111 mDefaultFont = new CheckBox(i18n("Use &default font"), page);
00112 mDefaultFont->setMinimumSize(mDefaultFont->sizeHint());
00113 connect(mDefaultFont, SIGNAL(toggled(bool)), SLOT(slotDefaultFontToggled(bool)));
00114 QWhatsThis::add(mDefaultFont,
00115 i18n("Check to use the default font current at the time the alarm is displayed."));
00116 layout->addWidget(mDefaultFont);
00117 layout->addWidget(new QWidget(page));
00118 }
00119 else
00120 mDefaultFont = 0;
00121
00122 mFontChooser = new KFontChooser(page, name, onlyFixed, fontList, false, visibleListSize);
00123 mFontChooser->installEventFilter(this);
00124 const QObjectList* kids = mFontChooser->queryList();
00125 for (QObjectList::ConstIterator it = kids->constBegin(); it != kids->constEnd(); ++it)
00126 (*it)->installEventFilter(this);
00127 topLayout->addWidget(mFontChooser);
00128
00129 slotDefaultFontToggled(false);
00130 }
00131
00132 void FontColourChooser::setDefaultFont()
00133 {
00134 if (mDefaultFont)
00135 mDefaultFont->setChecked(true);
00136 }
00137
00138 void FontColourChooser::setFont(const QFont& font, bool onlyFixed)
00139 {
00140 if (mDefaultFont)
00141 mDefaultFont->setChecked(false);
00142 mFontChooser->setFont(font, onlyFixed);
00143 }
00144
00145 bool FontColourChooser::defaultFont() const
00146 {
00147 return mDefaultFont ? mDefaultFont->isChecked() : false;
00148 }
00149
00150 QFont FontColourChooser::font() const
00151 {
00152 return (mDefaultFont && mDefaultFont->isChecked()) ? QFont() : mFontChooser->font();
00153 }
00154
00155 void FontColourChooser::setBgColour(const QColor& colour)
00156 {
00157 mBgColourButton->setColor(colour);
00158 mFontChooser->setBackgroundColor(colour);
00159 }
00160
00161 void FontColourChooser::setSampleColour()
00162 {
00163 QColor bg = mBgColourButton->color();
00164 mFontChooser->setBackgroundColor(bg);
00165 QColor fg = fgColour();
00166 mFontChooser->setColor(fg);
00167 if (mRemoveColourButton)
00168 mRemoveColourButton->setEnabled(!mBgColourButton->isCustomColour());
00169 }
00170
00171 QColor FontColourChooser::bgColour() const
00172 {
00173 return mBgColourButton->color();
00174 }
00175
00176 QColor FontColourChooser::fgColour() const
00177 {
00178 if (mFgColourButton)
00179 return mFgColourButton->color();
00180 else
00181 {
00182 QColor bg = mBgColourButton->color();
00183 QPalette pal(bg, bg);
00184 return pal.color(QPalette::Active, QColorGroup::Text);
00185 }
00186 }
00187
00188 QString FontColourChooser::sampleText() const
00189 {
00190 return mFontChooser->sampleText();
00191 }
00192
00193 void FontColourChooser::setSampleText(const QString& text)
00194 {
00195 mFontChooser->setSampleText(text);
00196 }
00197
00198 void FontColourChooser::setFgColour(const QColor& colour)
00199 {
00200 if (mFgColourButton)
00201 {
00202 mFgColourButton->setColor(colour);
00203 mFontChooser->setColor(colour);
00204 }
00205 }
00206
00207 void FontColourChooser::setReadOnly(bool ro)
00208 {
00209 if (ro != mReadOnly)
00210 {
00211 mReadOnly = ro;
00212 if (mFgColourButton)
00213 mFgColourButton->setReadOnly(ro);
00214 mBgColourButton->setReadOnly(ro);
00215 mDefaultFont->setReadOnly(ro);
00216 }
00217 }
00218
00219 bool FontColourChooser::eventFilter(QObject*, QEvent* e)
00220 {
00221 if (mReadOnly)
00222 {
00223 switch (e->type())
00224 {
00225 case QEvent::MouseButtonPress:
00226 case QEvent::MouseButtonRelease:
00227 case QEvent::MouseButtonDblClick:
00228 case QEvent::KeyPress:
00229 case QEvent::KeyRelease:
00230 return true;
00231 default:
00232 break;
00233 }
00234 }
00235 return false;
00236 }
00237
00238 void FontColourChooser::slotDefaultFontToggled(bool on)
00239 {
00240 mFontChooser->setEnabled(!on);
00241 }
00242
00243 void FontColourChooser::setColours(const ColourList& colours)
00244 {
00245 mColourList = colours;
00246 mBgColourButton->setColours(mColourList);
00247 mFontChooser->setBackgroundColor(mBgColourButton->color());
00248 }
00249
00250 void FontColourChooser::slotAddColour()
00251 {
00252 QColor colour;
00253 if (KColorDialog::getColor(colour, this) == QDialog::Accepted)
00254 {
00255 mColourList.insert(colour);
00256 mBgColourButton->setColours(mColourList);
00257 }
00258 }
00259
00260 void FontColourChooser::slotRemoveColour()
00261 {
00262 if (!mBgColourButton->isCustomColour())
00263 {
00264 mColourList.remove(mBgColourButton->color());
00265 mBgColourButton->setColours(mColourList);
00266 }
00267 }
00268