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