kalarm

fontcolourbutton.cpp

00001 /*
00002  *  fontcolourbutton.cpp  -  pushbutton widget to select a font and colour
00003  *  Program:  kalarm
00004  *  Copyright (C) 2003 - 2005 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 along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "kalarm.h"
00022 
00023 #include <qcheckbox.h>
00024 #include <qlayout.h>
00025 #include <qwhatsthis.h>
00026 
00027 #include <klocale.h>
00028 #include <kdebug.h>
00029 
00030 #include "fontcolour.h"
00031 #include "fontcolourbutton.moc"
00032 
00033 
00034 /*=============================================================================
00035 = Class FontColourButton
00036 = Font/colour selection buttong.
00037 =============================================================================*/
00038 
00039 FontColourButton::FontColourButton(QWidget* parent, const char* name)
00040     : PushButton(i18n("Font && Co&lor..."), parent, name),
00041       mReadOnly(false)
00042 {
00043     connect(this, SIGNAL(clicked()), SLOT(slotButtonPressed()));
00044     QWhatsThis::add(this,
00045           i18n("Choose the font, and foreground and background color, for the alarm message."));
00046 }
00047 
00048 /******************************************************************************
00049 *  Called when the OK button is clicked.
00050 *  Display a font and colour selection dialog and get the selections.
00051 */
00052 void FontColourButton::slotButtonPressed()
00053 {
00054     FontColourDlg dlg(mBgColour, mFgColour, mFont, mDefaultFont,
00055                       i18n("Choose Alarm Font & Color"), this, "fontColourDlg");
00056     dlg.setReadOnly(mReadOnly);
00057     if (dlg.exec() == QDialog::Accepted)
00058     {
00059         mDefaultFont = dlg.defaultFont();
00060         mFont        = dlg.font();
00061         mBgColour    = dlg.bgColour();
00062         mFgColour    = dlg.fgColour();
00063         emit selected();
00064     }
00065 }
00066 
00067 
00068 /*=============================================================================
00069 = Class FontColourDlg
00070 = Font/colour selection dialog.
00071 =============================================================================*/
00072 
00073 FontColourDlg::FontColourDlg(const QColor& bgColour, const QColor& fgColour, const QFont& font,
00074                              bool defaultFont, const QString& caption, QWidget* parent, const char* name)
00075     : KDialogBase(parent, name, true, caption, Ok|Cancel, Ok, false),
00076       mReadOnly(false)
00077 {
00078     QWidget* page = new QWidget(this);
00079     setMainWidget(page);
00080     QVBoxLayout* layout = new QVBoxLayout(page, 0, spacingHint());
00081     mChooser = new FontColourChooser(page, 0, false, QStringList(), QString::null, false, true, true);
00082     mChooser->setBgColour(bgColour);
00083     mChooser->setFgColour(fgColour);
00084     if (defaultFont)
00085         mChooser->setDefaultFont();
00086     else
00087         mChooser->setFont(font);
00088     layout->addWidget(mChooser);
00089     layout->addSpacing(KDialog::spacingHint());
00090 }
00091 
00092 /******************************************************************************
00093 *  Called when the OK button is clicked.
00094 */
00095 void FontColourDlg::slotOk()
00096 {
00097     if (mReadOnly)
00098         reject();
00099     mDefaultFont = mChooser->defaultFont();
00100     mFont        = mChooser->font();
00101     mBgColour    = mChooser->bgColour();
00102     mFgColour    = mChooser->fgColour();
00103     accept();
00104 }
00105 
00106 void FontColourDlg::setReadOnly(bool ro)
00107 {
00108     mReadOnly = ro;
00109     mChooser->setReadOnly(mReadOnly);
00110 }
KDE Home | KDE Accessibility Home | Description of Access Keys