fontcolourbutton.cpp
00001 /* 00002 * fontcolourbutton.cpp - pushbutton widget to select a font and colour 00003 * Program: kalarm 00004 * Copyright © 2003-2005,2007,2008 by David Jarvie <djarvie@kde.org> 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 <tqcheckbox.h> 00024 #include <tqlayout.h> 00025 #include <tqwhatsthis.h> 00026 00027 #include <klocale.h> 00028 #include <kdebug.h> 00029 00030 #include "fontcolour.h" 00031 #include "preferences.h" 00032 #include "pushbutton.h" 00033 #include "fontcolourbutton.moc" 00034 00035 00036 /*============================================================================= 00037 = Class FontColourButton 00038 = Font/colour selection button. 00039 =============================================================================*/ 00040 00041 FontColourButton::FontColourButton(TQWidget* parent, const char* name) 00042 : TQFrame(parent, name), 00043 mReadOnly(false) 00044 { 00045 setFrameStyle(NoFrame); 00046 TQHBoxLayout* layout = new TQHBoxLayout(this, 0, KDialog::spacingHint()); 00047 00048 mButton = new PushButton(i18n("Font && Co&lor..."), this); 00049 mButton->setFixedSize(mButton->sizeHint()); 00050 connect(mButton, TQT_SIGNAL(clicked()), TQT_SLOT(slotButtonPressed())); 00051 TQWhatsThis::add(mButton, 00052 i18n("Choose the font, and foreground and background color, for the alarm message.")); 00053 layout->addWidget(mButton); 00054 00055 // Font and colour sample display 00056 mSample = new TQLineEdit(this); 00057 mSample->setMinimumHeight(TQMAX(mSample->fontMetrics().lineSpacing(), mButton->height()*3/2)); 00058 mSample->setSizePolicy(TQSizePolicy::Ignored, TQSizePolicy::MinimumExpanding); 00059 mSample->setText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog")); 00060 mSample->setCursorPosition(0); 00061 mSample->setAlignment(TQt::AlignCenter); 00062 TQWhatsThis::add(mSample, 00063 i18n("This sample text illustrates the current font and color settings. " 00064 "You may edit it to test special characters.")); 00065 layout->addWidget(mSample); 00066 } 00067 00068 void FontColourButton::setDefaultFont() 00069 { 00070 mDefaultFont = true; 00071 mSample->setFont(Preferences::messageFont()); 00072 } 00073 00074 void FontColourButton::setFont(const TQFont& font) 00075 { 00076 mDefaultFont = false; 00077 mFont = font; 00078 mSample->setFont(mFont); 00079 } 00080 00081 void FontColourButton::setBgColour(const TQColor& colour) 00082 { 00083 mBgColour = colour; 00084 mSample->setPaletteBackgroundColor(mBgColour); 00085 } 00086 00087 void FontColourButton::setFgColour(const TQColor& colour) 00088 { 00089 mFgColour = colour; 00090 mSample->setPaletteForegroundColor(mFgColour); 00091 } 00092 00093 /****************************************************************************** 00094 * Called when the OK button is clicked. 00095 * Display a font and colour selection dialog and get the selections. 00096 */ 00097 void FontColourButton::slotButtonPressed() 00098 { 00099 FontColourDlg dlg(mBgColour, mFgColour, mFont, mDefaultFont, 00100 i18n("Choose Alarm Font & Color"), this, "fontColourDlg"); 00101 dlg.setReadOnly(mReadOnly); 00102 if (dlg.exec() == TQDialog::Accepted) 00103 { 00104 mDefaultFont = dlg.defaultFont(); 00105 mFont = dlg.font(); 00106 mSample->setFont(mFont); 00107 mBgColour = dlg.bgColour(); 00108 mSample->setPaletteBackgroundColor(mBgColour); 00109 mFgColour = dlg.fgColour(); 00110 mSample->setPaletteForegroundColor(mFgColour); 00111 emit selected(); 00112 } 00113 } 00114 00115 00116 /*============================================================================= 00117 = Class FontColourDlg 00118 = Font/colour selection dialog. 00119 =============================================================================*/ 00120 00121 FontColourDlg::FontColourDlg(const TQColor& bgColour, const TQColor& fgColour, const TQFont& font, 00122 bool defaultFont, const TQString& caption, TQWidget* parent, const char* name) 00123 : KDialogBase(parent, name, true, caption, Ok|Cancel, Ok, false), 00124 mReadOnly(false) 00125 { 00126 TQWidget* page = new TQWidget(this); 00127 setMainWidget(page); 00128 TQVBoxLayout* layout = new TQVBoxLayout(page, 0, spacingHint()); 00129 mChooser = new FontColourChooser(page, 0, false, TQStringList(), TQString(), false, true, true); 00130 mChooser->setBgColour(bgColour); 00131 mChooser->setFgColour(fgColour); 00132 if (defaultFont) 00133 mChooser->setDefaultFont(); 00134 else 00135 mChooser->setFont(font); 00136 layout->addWidget(mChooser); 00137 layout->addSpacing(KDialog::spacingHint()); 00138 } 00139 00140 /****************************************************************************** 00141 * Called when the OK button is clicked. 00142 */ 00143 void FontColourDlg::slotOk() 00144 { 00145 if (mReadOnly) 00146 { 00147 reject(); 00148 return; 00149 } 00150 mDefaultFont = mChooser->defaultFont(); 00151 mFont = mChooser->font(); 00152 mBgColour = mChooser->bgColour(); 00153 mFgColour = mChooser->fgColour(); 00154 accept(); 00155 } 00156 00157 void FontColourDlg::setReadOnly(bool ro) 00158 { 00159 mReadOnly = ro; 00160 mChooser->setReadOnly(mReadOnly); 00161 }