kalarm

fontcolourbutton.cpp
1/*
2 * fontcolourbutton.cpp - pushbutton widget to select a font and colour
3 * Program: kalarm
4 * Copyright © 2003-2005,2007,2008 by David Jarvie <djarvie@kde.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#include "kalarm.h"
22
23#include <tqcheckbox.h>
24#include <tqlayout.h>
25#include <tqwhatsthis.h>
26
27#include <tdelocale.h>
28#include <kdebug.h>
29
30#include "fontcolour.h"
31#include "preferences.h"
32#include "pushbutton.h"
33#include "fontcolourbutton.moc"
34
35
36/*=============================================================================
37= Class FontColourButton
38= Font/colour selection button.
39=============================================================================*/
40
41FontColourButton::FontColourButton(TQWidget* parent, const char* name)
42 : TQFrame(parent, name),
43 mReadOnly(false)
44{
45 setFrameStyle(NoFrame);
46 TQHBoxLayout* layout = new TQHBoxLayout(this, 0, KDialog::spacingHint());
47
48 mButton = new PushButton(i18n("Font && Co&lor..."), this);
49 mButton->setFixedSize(mButton->sizeHint());
50 connect(mButton, TQ_SIGNAL(clicked()), TQ_SLOT(slotButtonPressed()));
51 TQWhatsThis::add(mButton,
52 i18n("Choose the font, and foreground and background color, for the alarm message."));
53 layout->addWidget(mButton);
54
55 // Font and colour sample display
56 mSample = new TQLineEdit(this);
57 mSample->setMinimumHeight(TQMAX(mSample->fontMetrics().lineSpacing(), mButton->height()*3/2));
58 mSample->setSizePolicy(TQSizePolicy::Ignored, TQSizePolicy::MinimumExpanding);
59 mSample->setText(i18n("The Quick Brown Fox Jumps Over The Lazy Dog"));
60 mSample->setCursorPosition(0);
61 mSample->setAlignment(TQt::AlignCenter);
62 TQWhatsThis::add(mSample,
63 i18n("This sample text illustrates the current font and color settings. "
64 "You may edit it to test special characters."));
65 layout->addWidget(mSample);
66}
67
68void FontColourButton::setDefaultFont()
69{
70 mDefaultFont = true;
71 mSample->setFont(Preferences::messageFont());
72}
73
74void FontColourButton::setFont(const TQFont& font)
75{
76 mDefaultFont = false;
77 mFont = font;
78 mSample->setFont(mFont);
79}
80
81void FontColourButton::setBgColour(const TQColor& colour)
82{
83 mBgColour = colour;
84 mSample->setPaletteBackgroundColor(mBgColour);
85}
86
87void FontColourButton::setFgColour(const TQColor& colour)
88{
89 mFgColour = colour;
90 mSample->setPaletteForegroundColor(mFgColour);
91}
92
93/******************************************************************************
94* Called when the OK button is clicked.
95* Display a font and colour selection dialog and get the selections.
96*/
97void FontColourButton::slotButtonPressed()
98{
99 FontColourDlg dlg(mBgColour, mFgColour, mFont, mDefaultFont,
100 i18n("Choose Alarm Font & Color"), this, "fontColourDlg");
101 dlg.setReadOnly(mReadOnly);
102 if (dlg.exec() == TQDialog::Accepted)
103 {
104 mDefaultFont = dlg.defaultFont();
105 mFont = dlg.font();
106 mSample->setFont(mFont);
107 mBgColour = dlg.bgColour();
108 mSample->setPaletteBackgroundColor(mBgColour);
109 mFgColour = dlg.fgColour();
110 mSample->setPaletteForegroundColor(mFgColour);
111 emit selected();
112 }
113}
114
115
116/*=============================================================================
117= Class FontColourDlg
118= Font/colour selection dialog.
119=============================================================================*/
120
121FontColourDlg::FontColourDlg(const TQColor& bgColour, const TQColor& fgColour, const TQFont& font,
122 bool defaultFont, const TQString& caption, TQWidget* parent, const char* name)
123 : KDialogBase(parent, name, true, caption, Ok|Cancel, Ok, false),
124 mReadOnly(false)
125{
126 TQWidget* page = new TQWidget(this);
127 setMainWidget(page);
128 TQVBoxLayout* layout = new TQVBoxLayout(page, 0, spacingHint());
129 mChooser = new FontColourChooser(page, 0, false, TQStringList(), TQString(), false, true, true);
130 mChooser->setBgColour(bgColour);
131 mChooser->setFgColour(fgColour);
132 if (defaultFont)
133 mChooser->setDefaultFont();
134 else
135 mChooser->setFont(font);
136 layout->addWidget(mChooser);
137 layout->addSpacing(KDialog::spacingHint());
138}
139
140/******************************************************************************
141* Called when the OK button is clicked.
142*/
143void FontColourDlg::slotOk()
144{
145 if (mReadOnly)
146 {
147 reject();
148 return;
149 }
150 mDefaultFont = mChooser->defaultFont();
151 mFont = mChooser->font();
152 mBgColour = mChooser->bgColour();
153 mFgColour = mChooser->fgColour();
154 accept();
155}
156
157void FontColourDlg::setReadOnly(bool ro)
158{
159 mReadOnly = ro;
160 mChooser->setReadOnly(mReadOnly);
161}