summaryrefslogtreecommitdiffabout
path: root/kaddressbook/views/configurecardviewdialog.cpp
Unidiff
Diffstat (limited to 'kaddressbook/views/configurecardviewdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/configurecardviewdialog.cpp364
1 files changed, 364 insertions, 0 deletions
diff --git a/kaddressbook/views/configurecardviewdialog.cpp b/kaddressbook/views/configurecardviewdialog.cpp
new file mode 100644
index 0000000..d518cf7
--- a/dev/null
+++ b/kaddressbook/views/configurecardviewdialog.cpp
@@ -0,0 +1,364 @@
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#include <qstring.h>
25#include <qlayout.h>
26#include <qlabel.h>
27#include <qcheckbox.h>
28#include <qvbox.h>
29#include <qgroupbox.h>
30#include <qspinbox.h>
31#include <qtabwidget.h>
32#include <qwhatsthis.h>
33
34#include <kdebug.h>
35#include <kglobal.h>
36#include <kglobalsettings.h>
37#include <klocale.h>
38#include <kiconloader.h>
39#include <kconfig.h>
40#include <kfontdialog.h>
41
42#ifndef KAB_EMBEDDED
43#include <kpushbutton.h>
44#else //KAB_EMBEDDED
45#include <qpushbutton.h>
46#endif //KAB_EMBEDDED
47
48#include "colorlistbox.h"
49
50#include "configurecardviewdialog.h"
51
52/////////////////////////////////
53// ConfigureCardViewDialog
54
55ConfigureCardViewWidget::ConfigureCardViewWidget( KABC::AddressBook *ab, QWidget *parent,
56 const char *name )
57 : ViewConfigureWidget( ab, parent, name )
58{
59#ifndef KAB_EMBEDDED
60 QWidget *page = addPage( i18n( "Look & Feel" ), QString::null,
61 DesktopIcon( "looknfeel" ) );
62#else //KAB_EMBEDDED
63 QWidget *page = addPage( i18n( "Look & Feel" ), QString::null,
64 KGlobal::iconLoader()->loadIcon( "looknfeel",
65 KIcon::Panel ) );
66#endif //KAB_EMBEDDED
67
68 mAdvancedPage = new CardViewLookNFeelPage( page );
69}
70
71ConfigureCardViewWidget::~ConfigureCardViewWidget()
72{
73}
74
75void ConfigureCardViewWidget::restoreSettings( KConfig *config )
76{
77 ViewConfigureWidget::restoreSettings( config );
78
79 mAdvancedPage->restoreSettings( config );
80}
81
82void ConfigureCardViewWidget::saveSettings( KConfig *config )
83{
84 ViewConfigureWidget::saveSettings( config );
85
86 mAdvancedPage->saveSettings( config );
87}
88
89////////////////////////
90// CardViewLookNFeelPage
91CardViewLookNFeelPage::CardViewLookNFeelPage( QWidget *parent, const char *name )
92 : QVBox( parent, name )
93{
94 initGUI();
95}
96
97CardViewLookNFeelPage::~CardViewLookNFeelPage()
98{
99}
100
101void CardViewLookNFeelPage::restoreSettings( KConfig *config )
102{
103 // colors
104 cbEnableCustomColors->setChecked( config->readBoolEntry( "EnableCustomColors", false ) );
105 QColor c;
106qDebug("CardViewLookNFeelPage::restoreSettings make base color configurable");
107
108#ifndef KAB_EMBEDDED
109 c = KGlobalSettings::baseColor();
110#else //KAB_EMBEDDED
111 c = QColor(0,0,0);
112#endif //KAB_EMBEDDED
113
114 lbColors->insertItem( new ColorListItem( i18n("Background Color"),
115 config->readColorEntry( "BackgroundColor", &c ) ) );
116 c = colorGroup().foreground();
117 lbColors->insertItem( new ColorListItem( i18n("Text Color"),
118 config->readColorEntry( "TextColor", &c ) ) );
119 c = colorGroup().button();
120 lbColors->insertItem( new ColorListItem( i18n("Header, Border and Separator Color"),
121 config->readColorEntry( "HeaderColor", &c ) ) );
122 c = colorGroup().buttonText();
123 lbColors->insertItem( new ColorListItem( i18n("Header Text Color"),
124 config->readColorEntry( "HeaderTextColor", &c ) ) );
125 c = colorGroup().highlight();
126 lbColors->insertItem( new ColorListItem( i18n("Highlight Color"),
127 config->readColorEntry( "HighlightColor", &c ) ) );
128 c = colorGroup().highlightedText();
129 lbColors->insertItem( new ColorListItem( i18n("Highlighted Text Color"),
130 config->readColorEntry( "HighlightedTextColor", &c ) ) );
131
132 enableColors();
133
134 // fonts
135 QFont fnt = font();
136 updateFontLabel( config->readFontEntry( "TextFont", &fnt ), (QLabel*)lTextFont );
137 fnt.setBold( true );
138 updateFontLabel( config->readFontEntry( "HeaderFont", &fnt ), (QLabel*)lHeaderFont );
139 cbEnableCustomFonts->setChecked( config->readBoolEntry( "EnableCustomFonts", false ) );
140 enableFonts();
141
142 // layout
143 sbMargin->setValue( config->readNumEntry( "ItemMargin", 0 ) );
144 sbSpacing->setValue( config->readNumEntry( "ItemSpacing", 10 ) );
145 sbSepWidth->setValue( config->readNumEntry( "SeparatorWidth", 2 ) );
146 cbDrawSeps->setChecked( config->readBoolEntry( "DrawSeparators", true ) );
147 cbDrawBorders->setChecked( config->readBoolEntry( "DrawBorder", true ) );
148
149 // behaviour
150 cbShowFieldLabels->setChecked( config->readBoolEntry( "DrawFieldLabels", false ) );
151 cbShowEmptyFields->setChecked( config->readBoolEntry( "ShowEmptyFields", false ) );
152}
153
154void CardViewLookNFeelPage::saveSettings( KConfig *config )
155{
156 // colors
157 config->writeEntry( "EnableCustomColors", cbEnableCustomColors->isChecked() );
158 if ( cbEnableCustomColors->isChecked() ) // ?? - Hmmm.
159 {
160 config->writeEntry( "BackgroundColor", lbColors->color( 0 ) );
161 config->writeEntry( "TextColor", lbColors->color( 1 ) );
162 config->writeEntry( "HeaderColor", lbColors->color( 2 ) );
163 config->writeEntry( "HeaderTextColor", lbColors->color( 3 ) );
164 config->writeEntry( "HighlightColor", lbColors->color( 4 ) );
165 config->writeEntry( "HighlightedTextColor", lbColors->color( 5 ) );
166 }
167 // fonts
168 config->writeEntry( "EnableCustomFonts", cbEnableCustomFonts->isChecked() );
169 if ( cbEnableCustomFonts->isChecked() )
170 {
171 config->writeEntry( "TextFont", lTextFont->font() );
172 config->writeEntry( "HeaderFont", lHeaderFont->font() );
173 }
174 // layout
175 config->writeEntry( "ItemMargin", sbMargin->value() );
176 config->writeEntry( "ItemSpacing", sbSpacing->value() );
177 config->writeEntry( "SeparatorWidth", sbSepWidth->value() );
178 config->writeEntry("DrawBorder", cbDrawBorders->isChecked());
179 config->writeEntry("DrawSeparators", cbDrawSeps->isChecked());
180
181 // behaviour
182 config->writeEntry("DrawFieldLabels", cbShowFieldLabels->isChecked());
183 config->writeEntry("ShowEmptyFields", cbShowEmptyFields->isChecked());
184}
185
186void CardViewLookNFeelPage::setTextFont()
187{
188 QFont f( lTextFont->font() );
189#ifndef KAB_EMBEDDED
190 if ( KFontDialog::getFont( f, false, this ) == QDialog::Accepted )
191 updateFontLabel( f, lTextFont );
192#else //KAB_EMBEDDED
193 bool ok;
194 QFont fout = KFontDialog::getFont( f, ok);
195 if ( ok )
196 updateFontLabel( fout, lTextFont );
197#endif //KAB_EMBEDDED
198}
199
200void CardViewLookNFeelPage::setHeaderFont()
201{
202 QFont f( lHeaderFont->font() );
203#ifndef KAB_EMBEDDED
204 if ( KFontDialog::getFont( f,false, this ) == QDialog::Accepted )
205 updateFontLabel( f, lHeaderFont );
206#else //KAB_EMBEDDED
207 bool ok;
208 QFont fout = KFontDialog::getFont( f, ok);
209 if ( ok )
210 updateFontLabel( fout, lHeaderFont );
211#endif //KAB_EMBEDDED
212}
213
214void CardViewLookNFeelPage::enableFonts()
215{
216 vbFonts->setEnabled( cbEnableCustomFonts->isChecked() );
217}
218
219void CardViewLookNFeelPage::enableColors()
220{
221 lbColors->setEnabled( cbEnableCustomColors->isChecked() );
222}
223
224void CardViewLookNFeelPage::initGUI()
225{
226 int spacing = KDialog::spacingHint();
227 int margin = KDialog::marginHint();
228
229 QTabWidget *tabs = new QTabWidget( this );
230
231 // Layout
232 QVBox *loTab = new QVBox( this, "layouttab" );
233
234 loTab->setSpacing( spacing );
235 loTab->setMargin( margin );
236
237 QGroupBox *gbGeneral = new QGroupBox( 1, Qt::Horizontal, i18n("General"), loTab );
238
239 cbDrawSeps = new QCheckBox( i18n("Draw &separators"), gbGeneral );
240
241 QHBox *hbSW = new QHBox( gbGeneral );
242 QLabel *lSW = new QLabel( i18n("Separator &width:"), hbSW );
243 sbSepWidth = new QSpinBox( 1, 50, 1, hbSW );
244 lSW->setBuddy( sbSepWidth);
245
246 QHBox *hbPadding = new QHBox( gbGeneral );
247 QLabel *lSpacing = new QLabel( i18n("&Padding:"), hbPadding );
248 sbSpacing = new QSpinBox( 0, 100, 1, hbPadding );
249 lSpacing->setBuddy( sbSpacing );
250
251 QGroupBox *gbCards = new QGroupBox( 1, Qt::Horizontal, i18n("Cards"), loTab );
252
253 QHBox *hbMargin = new QHBox( gbCards );
254 QLabel *lMargin = new QLabel( i18n("&Margin:"), hbMargin );
255 sbMargin = new QSpinBox( 0, 100, 1, hbMargin );
256 lMargin->setBuddy( sbMargin );
257
258 cbDrawBorders = new QCheckBox( i18n("Draw &borders"), gbCards );
259
260 loTab->setStretchFactor( new QWidget( loTab ), 1 );
261
262 QWhatsThis::add( sbMargin, i18n(
263 "The item margin is the distance (in pixels) between the item edge and the item data. Most noticeably, "
264 "incrementing the item margin will add space between the focus rectangle and the item data."
265 ) );
266 QWhatsThis::add( lMargin, QWhatsThis::textFor( sbMargin ) );
267 QWhatsThis::add( sbSpacing, i18n(
268 "The Item Spacing decides the distance (in pixels) between the items and anything else: the view "
269 "borders, other items or column separators."
270 ) );
271 QWhatsThis::add( lSpacing, QWhatsThis::textFor( sbSpacing ) );
272 QWhatsThis::add( sbSepWidth, i18n("Sets the width of column separators") );
273 QWhatsThis::add( lSW, QWhatsThis::textFor( sbSepWidth ) );
274
275 tabs->addTab( loTab, i18n("&Layout") );
276
277 // Colors
278 QVBox *colorTab = new QVBox( this, "colortab" );
279 colorTab->setSpacing( spacing );
280 colorTab->setMargin( spacing );
281 cbEnableCustomColors = new QCheckBox( i18n("&Enable custom Colors"), colorTab );
282 connect( cbEnableCustomColors, SIGNAL(clicked()), this, SLOT(enableColors()) );
283 lbColors = new ColorListBox( colorTab );
284 tabs->addTab( colorTab, i18n("&Colors") );
285
286 QWhatsThis::add( cbEnableCustomColors, i18n(
287 "If custom colors are enabled, you may choose the colors for the view below. "
288 "Otherwise colors from your current KDE color scheme are used."
289 ) );
290 QWhatsThis::add( lbColors, i18n(
291 "Double click or press RETURN on a item to select a color for the related strings in the view."
292 ) );
293
294 // Fonts
295 QVBox *fntTab = new QVBox( this, "fonttab" );
296
297 fntTab->setSpacing( spacing );
298 fntTab->setMargin( spacing );
299
300 cbEnableCustomFonts = new QCheckBox( i18n("&Enable custom fonts"), fntTab );
301 connect( cbEnableCustomFonts, SIGNAL(clicked()), this, SLOT(enableFonts()) );
302
303 vbFonts = new QWidget( fntTab );
304 QGridLayout *gFnts = new QGridLayout( vbFonts, 2, 3 );
305 gFnts->setSpacing( spacing );
306 gFnts->setAutoAdd( true );
307 gFnts->setColStretch( 1, 1 );
308 QLabel *lTFnt = new QLabel( i18n("&Text font:"), vbFonts );
309 lTextFont = new QLabel( vbFonts );
310 lTextFont->setFrameStyle( QFrame::Panel|QFrame::Sunken );
311#ifndef KAB_EMBEDDED
312 btnFont = new KPushButton( i18n("Choose..."), vbFonts );
313#else //KAB_EMBEDDED
314 btnFont = new QPushButton( i18n("Choose..."), vbFonts );
315#endif //KAB_EMBEDDED
316
317 lTFnt->setBuddy( btnFont );
318
319 connect( btnFont, SIGNAL(clicked()), this, SLOT(setTextFont()) );
320
321 QLabel *lHFnt = new QLabel( i18n("&Header font:"), vbFonts );
322 lHeaderFont = new QLabel( vbFonts );
323 lHeaderFont->setFrameStyle( QFrame::Panel|QFrame::Sunken );
324#ifndef KAB_EMBEDDED
325 btnHeaderFont = new KPushButton( i18n("Choose..."), vbFonts );
326#else //KAB_EMBEDDED
327 btnHeaderFont = new QPushButton( i18n("Choose..."), vbFonts );
328#endif //KAB_EMBEDDED
329 lHFnt->setBuddy( btnHeaderFont );
330 connect( btnHeaderFont, SIGNAL(clicked()), this, SLOT(setHeaderFont()) );
331
332 fntTab->setStretchFactor( new QWidget( fntTab ), 1 );
333
334 QWhatsThis::add( cbEnableCustomFonts, i18n(
335 "If custom fonts are enabled, you may choose which fonts to use for this view below. "
336 "Otherwise the default KDE font will be used, in bold style for the header and "
337 "normal style for the data."
338 ) );
339
340 tabs->addTab( fntTab, i18n("&Fonts") );
341
342 // Behaviour
343 QVBox *behaviourTab = new QVBox( this );
344 behaviourTab->setMargin( margin );
345 behaviourTab->setSpacing( spacing );
346
347 cbShowEmptyFields = new QCheckBox( i18n("Show &empty fields"), behaviourTab );
348 cbShowFieldLabels = new QCheckBox( i18n("Show field &labels"), behaviourTab );
349
350 behaviourTab->setStretchFactor( new QWidget( behaviourTab ), 1 );
351
352 tabs->addTab( behaviourTab, i18n("Be&havior") );
353
354}
355
356void CardViewLookNFeelPage::updateFontLabel( QFont fnt, QLabel *l )
357{
358 l->setFont( fnt );
359 l->setText( QString( fnt.family() + " %1" ).arg( fnt.pointSize() ) );
360}
361
362#ifndef KAB_EMBEDDED
363#include "configurecardviewdialog.moc"
364#endif //KAB_EMBEDDED