kaddressbook

configurecardviewdialog.cpp
1/*
2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of TQt, and distribute the resulting executable,
21 without including the source code for TQt in the source distribution.
22*/
23
24#include <tqstring.h>
25#include <tqlayout.h>
26#include <tqlabel.h>
27#include <tqcheckbox.h>
28#include <tqvbox.h>
29#include <tqgroupbox.h>
30#include <tqspinbox.h>
31#include <tqtabwidget.h>
32#include <tqwhatsthis.h>
33
34#include <kdebug.h>
35#include <tdeglobal.h>
36#include <tdeglobalsettings.h>
37#include <tdelocale.h>
38#include <kiconloader.h>
39#include <tdeconfig.h>
40#include <tdefontdialog.h>
41#include <kpushbutton.h>
42
43#include "colorlistbox.h"
44
45#include "configurecardviewdialog.h"
46
48// ConfigureCardViewDialog
49
50ConfigureCardViewWidget::ConfigureCardViewWidget( TDEABC::AddressBook *ab, TQWidget *parent,
51 const char *name )
52 : ViewConfigureWidget( ab, parent, name )
53{
54 TQWidget *page = addPage( i18n( "Look & Feel" ), TQString(),
55 DesktopIcon( "preferences-desktop" ) );
56 mAdvancedPage = new CardViewLookNFeelPage( page );
57}
58
59ConfigureCardViewWidget::~ConfigureCardViewWidget()
60{
61}
62
64{
66
67 mAdvancedPage->restoreSettings( config );
68}
69
71{
73
74 mAdvancedPage->saveSettings( config );
75}
76
78// CardViewLookNFeelPage
79CardViewLookNFeelPage::CardViewLookNFeelPage( TQWidget *parent, const char *name )
80 : TQVBox( parent, name )
81{
82 initGUI();
83}
84
85CardViewLookNFeelPage::~CardViewLookNFeelPage()
86{
87}
88
89void CardViewLookNFeelPage::restoreSettings( TDEConfig *config )
90{
91 // colors
92 cbEnableCustomColors->setChecked( config->readBoolEntry( "EnableCustomColors", false ) );
93 TQColor c;
94 c = TDEGlobalSettings::baseColor();
95 lbColors->insertItem( new ColorListItem( i18n("Background Color"),
96 config->readColorEntry( "BackgroundColor", &c ) ) );
97 c = colorGroup().foreground();
98 lbColors->insertItem( new ColorListItem( i18n("Text Color"),
99 config->readColorEntry( "TextColor", &c ) ) );
100 c = colorGroup().button();
101 lbColors->insertItem( new ColorListItem( i18n("Header, Border & Separator Color"),
102 config->readColorEntry( "HeaderColor", &c ) ) );
103 c = colorGroup().buttonText();
104 lbColors->insertItem( new ColorListItem( i18n("Header Text Color"),
105 config->readColorEntry( "HeaderTextColor", &c ) ) );
106 c = colorGroup().highlight();
107 lbColors->insertItem( new ColorListItem( i18n("Highlight Color"),
108 config->readColorEntry( "HighlightColor", &c ) ) );
109 c = colorGroup().highlightedText();
110 lbColors->insertItem( new ColorListItem( i18n("Highlighted Text Color"),
111 config->readColorEntry( "HighlightedTextColor", &c ) ) );
112
113 enableColors();
114
115 // fonts
116 TQFont fnt = font();
117 updateFontLabel( config->readFontEntry( "TextFont", &fnt ), (TQLabel*)lTextFont );
118 fnt.setBold( true );
119 updateFontLabel( config->readFontEntry( "HeaderFont", &fnt ), (TQLabel*)lHeaderFont );
120 cbEnableCustomFonts->setChecked( config->readBoolEntry( "EnableCustomFonts", false ) );
121 enableFonts();
122
123 // layout
124 sbMargin->setValue( config->readNumEntry( "ItemMargin", 0 ) );
125 sbSpacing->setValue( config->readNumEntry( "ItemSpacing", 10 ) );
126 sbSepWidth->setValue( config->readNumEntry( "SeparatorWidth", 2 ) );
127 cbDrawSeps->setChecked( config->readBoolEntry( "DrawSeparators", true ) );
128 cbDrawBorders->setChecked( config->readBoolEntry( "DrawBorder", true ) );
129
130 // behaviour
131 cbShowFieldLabels->setChecked( config->readBoolEntry( "DrawFieldLabels", false ) );
132 cbShowEmptyFields->setChecked( config->readBoolEntry( "ShowEmptyFields", false ) );
133}
134
135void CardViewLookNFeelPage::saveSettings( TDEConfig *config )
136{
137 // colors
138 config->writeEntry( "EnableCustomColors", cbEnableCustomColors->isChecked() );
139 if ( cbEnableCustomColors->isChecked() ) // ?? - Hmmm.
140 {
141 config->writeEntry( "BackgroundColor", lbColors->color( 0 ) );
142 config->writeEntry( "TextColor", lbColors->color( 1 ) );
143 config->writeEntry( "HeaderColor", lbColors->color( 2 ) );
144 config->writeEntry( "HeaderTextColor", lbColors->color( 3 ) );
145 config->writeEntry( "HighlightColor", lbColors->color( 4 ) );
146 config->writeEntry( "HighlightedTextColor", lbColors->color( 5 ) );
147 }
148 // fonts
149 config->writeEntry( "EnableCustomFonts", cbEnableCustomFonts->isChecked() );
150 if ( cbEnableCustomFonts->isChecked() )
151 {
152 config->writeEntry( "TextFont", lTextFont->font() );
153 config->writeEntry( "HeaderFont", lHeaderFont->font() );
154 }
155 // layout
156 config->writeEntry( "ItemMargin", sbMargin->value() );
157 config->writeEntry( "ItemSpacing", sbSpacing->value() );
158 config->writeEntry( "SeparatorWidth", sbSepWidth->value() );
159 config->writeEntry("DrawBorder", cbDrawBorders->isChecked());
160 config->writeEntry("DrawSeparators", cbDrawSeps->isChecked());
161
162 // behaviour
163 config->writeEntry("DrawFieldLabels", cbShowFieldLabels->isChecked());
164 config->writeEntry("ShowEmptyFields", cbShowEmptyFields->isChecked());
165}
166
167void CardViewLookNFeelPage::setTextFont()
168{
169 TQFont f( lTextFont->font() );
170 if ( TDEFontDialog::getFont( f, false, this ) == TQDialog::Accepted )
171 updateFontLabel( f, lTextFont );
172}
173
174void CardViewLookNFeelPage::setHeaderFont()
175{
176 TQFont f( lHeaderFont->font() );
177 if ( TDEFontDialog::getFont( f,false, this ) == TQDialog::Accepted )
178 updateFontLabel( f, lHeaderFont );
179}
180
181void CardViewLookNFeelPage::enableFonts()
182{
183 vbFonts->setEnabled( cbEnableCustomFonts->isChecked() );
184}
185
186void CardViewLookNFeelPage::enableColors()
187{
188 lbColors->setEnabled( cbEnableCustomColors->isChecked() );
189}
190
191void CardViewLookNFeelPage::initGUI()
192{
193 int spacing = KDialog::spacingHint();
194 int margin = KDialog::marginHint();
195
196 TQTabWidget *tabs = new TQTabWidget( this );
197
198 // Layout
199 TQVBox *loTab = new TQVBox( this, "layouttab" );
200
201 loTab->setSpacing( spacing );
202 loTab->setMargin( margin );
203
204 TQGroupBox *gbGeneral = new TQGroupBox( 1, TQt::Horizontal, i18n("General"), loTab );
205
206 cbDrawSeps = new TQCheckBox( i18n("Draw &separators"), gbGeneral );
207
208 TQHBox *hbSW = new TQHBox( gbGeneral );
209 TQLabel *lSW = new TQLabel( i18n("Separator &width:"), hbSW );
210 sbSepWidth = new TQSpinBox( 1, 50, 1, hbSW );
211 lSW->setBuddy( sbSepWidth);
212
213 TQHBox *hbPadding = new TQHBox( gbGeneral );
214 TQLabel *lSpacing = new TQLabel( i18n("&Padding:"), hbPadding );
215 sbSpacing = new TQSpinBox( 0, 100, 1, hbPadding );
216 lSpacing->setBuddy( sbSpacing );
217
218 TQGroupBox *gbCards = new TQGroupBox( 1, TQt::Horizontal, i18n("Cards"), loTab );
219
220 TQHBox *hbMargin = new TQHBox( gbCards );
221 TQLabel *lMargin = new TQLabel( i18n("&Margin:"), hbMargin );
222 sbMargin = new TQSpinBox( 0, 100, 1, hbMargin );
223 lMargin->setBuddy( sbMargin );
224
225 cbDrawBorders = new TQCheckBox( i18n("Draw &borders"), gbCards );
226
227 loTab->setStretchFactor( new TQWidget( loTab ), 1 );
228
229 TQWhatsThis::add( sbMargin, i18n(
230 "The item margin is the distance (in pixels) between the item edge and the item data. Most noticeably, "
231 "incrementing the item margin will add space between the focus rectangle and the item data."
232 ) );
233 TQWhatsThis::add( lMargin, TQWhatsThis::textFor( sbMargin ) );
234 TQWhatsThis::add( sbSpacing, i18n(
235 "The item spacing decides the distance (in pixels) between the items and anything else: the view "
236 "borders, other items or column separators."
237 ) );
238 TQWhatsThis::add( lSpacing, TQWhatsThis::textFor( sbSpacing ) );
239 TQWhatsThis::add( sbSepWidth, i18n("Sets the width of column separators") );
240 TQWhatsThis::add( lSW, TQWhatsThis::textFor( sbSepWidth ) );
241
242 tabs->addTab( loTab, i18n("&Layout") );
243
244 // Colors
245 TQVBox *colorTab = new TQVBox( this, "colortab" );
246 colorTab->setSpacing( spacing );
247 colorTab->setMargin( spacing );
248 cbEnableCustomColors = new TQCheckBox( i18n("&Enable custom colors"), colorTab );
249 connect( cbEnableCustomColors, TQ_SIGNAL(clicked()), this, TQ_SLOT(enableColors()) );
250 lbColors = new ColorListBox( colorTab );
251 tabs->addTab( colorTab, i18n("&Colors") );
252
253 TQWhatsThis::add( cbEnableCustomColors, i18n(
254 "If custom colors is enabled, you may choose the colors for the view below. "
255 "Otherwise colors from your current TDE color scheme are used."
256 ) );
257 TQWhatsThis::add( lbColors, i18n(
258 "Double click or press RETURN on a item to select a color for the related strings in the view."
259 ) );
260
261 // Fonts
262 TQVBox *fntTab = new TQVBox( this, "fonttab" );
263
264 fntTab->setSpacing( spacing );
265 fntTab->setMargin( spacing );
266
267 cbEnableCustomFonts = new TQCheckBox( i18n("&Enable custom fonts"), fntTab );
268 connect( cbEnableCustomFonts, TQ_SIGNAL(clicked()), this, TQ_SLOT(enableFonts()) );
269
270 vbFonts = new TQWidget( fntTab );
271 TQGridLayout *gFnts = new TQGridLayout( vbFonts, 2, 3 );
272 gFnts->setSpacing( spacing );
273 gFnts->setAutoAdd( true );
274 gFnts->setColStretch( 1, 1 );
275 TQLabel *lTFnt = new TQLabel( i18n("&Text font:"), vbFonts );
276 lTextFont = new TQLabel( vbFonts );
277 lTextFont->setFrameStyle( TQFrame::Panel|TQFrame::Sunken );
278 btnFont = new KPushButton( i18n("Choose..."), vbFonts );
279 lTFnt->setBuddy( btnFont );
280 connect( btnFont, TQ_SIGNAL(clicked()), this, TQ_SLOT(setTextFont()) );
281
282 TQLabel *lHFnt = new TQLabel( i18n("&Header font:"), vbFonts );
283 lHeaderFont = new TQLabel( vbFonts );
284 lHeaderFont->setFrameStyle( TQFrame::Panel|TQFrame::Sunken );
285 btnHeaderFont = new KPushButton( i18n("Choose..."), vbFonts );
286 lHFnt->setBuddy( btnHeaderFont );
287 connect( btnHeaderFont, TQ_SIGNAL(clicked()), this, TQ_SLOT(setHeaderFont()) );
288
289 fntTab->setStretchFactor( new TQWidget( fntTab ), 1 );
290
291 TQWhatsThis::add( cbEnableCustomFonts, i18n(
292 "If custom fonts are enabled, you may choose which fonts to use for this view below. "
293 "Otherwise the default TDE font will be used, in bold style for the header and "
294 "normal style for the data."
295 ) );
296
297 tabs->addTab( fntTab, i18n("&Fonts") );
298
299 // Behaviour
300 TQVBox *behaviourTab = new TQVBox( this );
301 behaviourTab->setMargin( margin );
302 behaviourTab->setSpacing( spacing );
303
304 cbShowEmptyFields = new TQCheckBox( i18n("Show &empty fields"), behaviourTab );
305 cbShowFieldLabels = new TQCheckBox( i18n("Show field &labels"), behaviourTab );
306
307 behaviourTab->setStretchFactor( new TQWidget( behaviourTab ), 1 );
308
309 tabs->addTab( behaviourTab, i18n("Be&havior") );
310
311}
312
313void CardViewLookNFeelPage::updateFontLabel( TQFont fnt, TQLabel *l )
314{
315 l->setFont( fnt );
316 l->setText( TQString( fnt.family() + " %1" ).arg( fnt.pointSize() ) );
317}
318
319#include "configurecardviewdialog.moc"
Card View Advanced LookNFeel settings widget: this is a tabbed widget with 3 tabs: Fonts text font he...
virtual void saveSettings(TDEConfig *)
Writes the configuration from the GUI to the config object.
virtual void restoreSettings(TDEConfig *)
Reads the configuration from the config object and sets the values in the GUI.
This widget is the base class for all view configuration widgets.
virtual void restoreSettings(TDEConfig *config)
Reads the configuration from the config object and sets the values in the GUI.
virtual void saveSettings(TDEConfig *config)
Writes the configuration from the GUI to the config object.