kaddressbook Library API Documentation

configurecardviewdialog.cpp

00001 /*
00002     This file is part of KAddressBook.                                  
00003     Copyright (c) 2002 Mike Pilone <mpilone@slac.com>                   
00004                                                                         
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or   
00008     (at your option) any later version.                                 
00009                                                                         
00010     This program is distributed in the hope that it will be useful,     
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of      
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the        
00013     GNU General Public License for more details.                        
00014                                                                         
00015     You should have received a copy of the GNU General Public License   
00016     along with this program; if not, write to the Free Software         
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           
00018                                                                         
00019     As a special exception, permission is given to link this program    
00020     with any edition of Qt, and distribute the resulting executable,    
00021     without including the source code for Qt in the source distribution.
00022 */                                                                      
00023 
00024 #include <qstring.h>
00025 #include <qlayout.h>
00026 #include <qlabel.h>
00027 #include <qcheckbox.h>
00028 #include <qvbox.h>
00029 #include <qgroupbox.h>
00030 #include <qspinbox.h>
00031 #include <qtabwidget.h>
00032 #include <qwhatsthis.h>
00033 
00034 #include <kdebug.h>
00035 #include <kglobal.h>
00036 #include <kglobalsettings.h>
00037 #include <klocale.h>
00038 #include <kiconloader.h>
00039 #include <kconfig.h>
00040 #include <kfontdialog.h>
00041 #include <kpushbutton.h>
00042 
00043 #include "colorlistbox.h"
00044 
00045 #include "configurecardviewdialog.h"
00046 
00048 // ConfigureCardViewDialog
00049 
00050 ConfigureCardViewWidget::ConfigureCardViewWidget( KABC::AddressBook *ab, QWidget *parent, 
00051                                                   const char *name )
00052   : ViewConfigureWidget( ab, parent, name )
00053 {
00054   QWidget *page = addPage( i18n( "Look & Feel" ), QString::null,
00055                            DesktopIcon( "looknfeel" ) );
00056   mAdvancedPage = new CardViewLookNFeelPage( page );
00057 }
00058                                            
00059 ConfigureCardViewWidget::~ConfigureCardViewWidget()
00060 {
00061 }
00062     
00063 void ConfigureCardViewWidget::restoreSettings( KConfig *config )
00064 {
00065   ViewConfigureWidget::restoreSettings( config );
00066 
00067   mAdvancedPage->restoreSettings( config );
00068 }
00069 
00070 void ConfigureCardViewWidget::saveSettings( KConfig *config )
00071 {
00072   ViewConfigureWidget::saveSettings( config );
00073 
00074   mAdvancedPage->saveSettings( config );
00075 }
00076     
00078 // CardViewLookNFeelPage
00079 CardViewLookNFeelPage::CardViewLookNFeelPage( QWidget *parent, const char *name )
00080   : QVBox( parent, name )
00081 {
00082   initGUI();
00083 }
00084 
00085 CardViewLookNFeelPage::~CardViewLookNFeelPage()
00086 {
00087 }
00088 
00089 void CardViewLookNFeelPage::restoreSettings( KConfig *config )
00090 {
00091   // colors
00092   cbEnableCustomColors->setChecked( config->readBoolEntry( "EnableCustomColors", false ) );
00093   QColor c;
00094   c = KGlobalSettings::baseColor();
00095   lbColors->insertItem( new ColorListItem( i18n("Background Color"),
00096         config->readColorEntry( "BackgroundColor", &c ) ) );
00097   c = colorGroup().foreground();
00098   lbColors->insertItem( new ColorListItem( i18n("Text Color"),
00099         config->readColorEntry( "TextColor", &c ) ) );
00100   c = colorGroup().button();
00101   lbColors->insertItem( new ColorListItem( i18n("Header, Border & Separator Color"),
00102         config->readColorEntry( "HeaderColor", &c ) ) );
00103   c = colorGroup().buttonText();
00104   lbColors->insertItem( new ColorListItem( i18n("Header Text Color"),
00105         config->readColorEntry( "HeaderTextColor", &c ) ) );
00106   c = colorGroup().highlight();
00107   lbColors->insertItem( new ColorListItem( i18n("Highlight Color"),
00108         config->readColorEntry( "HighlightColor", &c ) ) );
00109   c = colorGroup().highlightedText();
00110   lbColors->insertItem( new ColorListItem( i18n("Highlighted Text Color"),
00111         config->readColorEntry( "HighlightedTextColor", &c ) ) );  
00112   
00113   enableColors();
00114   
00115   // fonts
00116   QFont fnt = font();
00117   updateFontLabel( config->readFontEntry( "TextFont", &fnt ), (QLabel*)lTextFont );
00118   fnt.setBold( true );
00119   updateFontLabel( config->readFontEntry( "HeaderFont",  &fnt ), (QLabel*)lHeaderFont );
00120   cbEnableCustomFonts->setChecked( config->readBoolEntry( "EnableCustomFonts", false ) );
00121   enableFonts();
00122   
00123   // layout
00124   sbMargin->setValue( config->readNumEntry( "ItemMargin", 0 ) );
00125   sbSpacing->setValue( config->readNumEntry( "ItemSpacing", 10 ) );
00126   sbSepWidth->setValue( config->readNumEntry( "SeparatorWidth", 2 ) );
00127   cbDrawSeps->setChecked( config->readBoolEntry( "DrawSeparators", true ) );
00128   cbDrawBorders->setChecked( config->readBoolEntry( "DrawBorder", true ) );
00129   
00130   // behaviour
00131   cbShowFieldLabels->setChecked( config->readBoolEntry( "DrawFieldLabels", false ) );
00132   cbShowEmptyFields->setChecked( config->readBoolEntry( "ShowEmptyFields", false ) );
00133 }
00134 
00135 void CardViewLookNFeelPage::saveSettings( KConfig *config )
00136 {
00137   // colors
00138   config->writeEntry( "EnableCustomColors", cbEnableCustomColors->isChecked() );
00139   if ( cbEnableCustomColors->isChecked() ) // ?? - Hmmm.
00140   {
00141     config->writeEntry( "BackgroundColor", lbColors->color( 0 ) );
00142     config->writeEntry( "TextColor", lbColors->color( 1 ) );
00143     config->writeEntry( "HeaderColor", lbColors->color( 2 ) );
00144     config->writeEntry( "HeaderTextColor", lbColors->color( 3 ) );
00145     config->writeEntry( "HighlightColor", lbColors->color( 4 ) );
00146     config->writeEntry( "HighlightedTextColor", lbColors->color( 5 ) );
00147   }
00148   // fonts
00149   config->writeEntry( "EnableCustomFonts", cbEnableCustomFonts->isChecked() );
00150   if ( cbEnableCustomFonts->isChecked() )
00151   {
00152     config->writeEntry( "TextFont", lTextFont->font() );
00153     config->writeEntry( "HeaderFont", lHeaderFont->font() );
00154   }
00155   // layout
00156   config->writeEntry( "ItemMargin", sbMargin->value() );
00157   config->writeEntry( "ItemSpacing", sbSpacing->value() );
00158   config->writeEntry( "SeparatorWidth", sbSepWidth->value() );
00159   config->writeEntry("DrawBorder", cbDrawBorders->isChecked());
00160   config->writeEntry("DrawSeparators", cbDrawSeps->isChecked());
00161   
00162   // behaviour
00163   config->writeEntry("DrawFieldLabels", cbShowFieldLabels->isChecked());
00164   config->writeEntry("ShowEmptyFields", cbShowEmptyFields->isChecked());
00165 }
00166 
00167 void CardViewLookNFeelPage::setTextFont()
00168 {
00169   QFont f( lTextFont->font() );
00170   if ( KFontDialog::getFont( f, false, this ) == QDialog::Accepted )
00171     updateFontLabel( f, lTextFont );
00172 }
00173 
00174 void CardViewLookNFeelPage::setHeaderFont()
00175 {
00176   QFont f( lHeaderFont->font() );
00177   if ( KFontDialog::getFont( f,false, this ) == QDialog::Accepted )
00178     updateFontLabel( f, lHeaderFont );
00179 }
00180 
00181 void CardViewLookNFeelPage::enableFonts()
00182 {
00183   vbFonts->setEnabled( cbEnableCustomFonts->isChecked() );
00184 }
00185 
00186 void CardViewLookNFeelPage::enableColors()
00187 {
00188   lbColors->setEnabled( cbEnableCustomColors->isChecked() );
00189 }
00190 
00191 void CardViewLookNFeelPage::initGUI()
00192 {
00193   int spacing = KDialog::spacingHint();
00194   int margin = KDialog::marginHint();
00195   
00196   QTabWidget *tabs = new QTabWidget( this );
00197 
00198   // Layout
00199   QVBox *loTab = new QVBox( this, "layouttab" );
00200   
00201   loTab->setSpacing( spacing );
00202   loTab->setMargin( margin );
00203   
00204   QGroupBox *gbGeneral = new QGroupBox( 1, Qt::Horizontal, i18n("General"), loTab );
00205   
00206   cbDrawSeps = new QCheckBox( i18n("Draw &separators"), gbGeneral );
00207 
00208   QHBox *hbSW = new QHBox( gbGeneral );
00209   QLabel *lSW = new QLabel( i18n("Separator &width:"), hbSW );
00210   sbSepWidth = new QSpinBox( 1, 50, 1, hbSW );
00211   lSW->setBuddy( sbSepWidth);
00212 
00213   QHBox *hbPadding = new QHBox( gbGeneral );
00214   QLabel *lSpacing = new QLabel( i18n("&Padding:"), hbPadding );
00215   sbSpacing = new QSpinBox( 0, 100, 1, hbPadding );
00216   lSpacing->setBuddy( sbSpacing );
00217 
00218   QGroupBox *gbCards = new QGroupBox( 1, Qt::Horizontal, i18n("Cards"), loTab );
00219 
00220   QHBox *hbMargin = new QHBox( gbCards );
00221   QLabel *lMargin = new QLabel( i18n("&Margin:"), hbMargin );
00222   sbMargin = new QSpinBox( 0, 100, 1, hbMargin );
00223   lMargin->setBuddy( sbMargin );
00224 
00225   cbDrawBorders = new QCheckBox( i18n("Draw &borders"), gbCards );
00226 
00227   loTab->setStretchFactor( new QWidget( loTab ), 1 );
00228   
00229   QWhatsThis::add( sbMargin, i18n(
00230         "The item margin is the distance (in pixels) between the item edge and the item data. Most noticeably, "
00231         "incrementing the item margin will add space between the focus rectangle and the item data."
00232         ) );
00233   QWhatsThis::add( lMargin, QWhatsThis::textFor( sbMargin ) );
00234   QWhatsThis::add( sbSpacing, i18n(
00235         "The item spacing decides the distance (in pixels) between the items and anything else: the view "
00236         "borders, other items or column separators."
00237         ) );
00238   QWhatsThis::add( lSpacing, QWhatsThis::textFor( sbSpacing ) );
00239   QWhatsThis::add( sbSepWidth, i18n("Sets the width of column separators") );
00240   QWhatsThis::add( lSW, QWhatsThis::textFor( sbSepWidth ) );
00241   
00242   tabs->addTab( loTab, i18n("&Layout") );
00243     
00244   // Colors
00245   QVBox *colorTab = new QVBox( this, "colortab" );
00246   colorTab->setSpacing( spacing );
00247   colorTab->setMargin( spacing );
00248   cbEnableCustomColors = new QCheckBox( i18n("&Enable custom colors"), colorTab );
00249   connect( cbEnableCustomColors, SIGNAL(clicked()), this, SLOT(enableColors()) );
00250   lbColors = new ColorListBox( colorTab );
00251   tabs->addTab( colorTab, i18n("&Colors") );
00252   
00253   QWhatsThis::add( cbEnableCustomColors, i18n(
00254         "If custom colors are enabled, you may choose the colors for the view below. "
00255         "Otherwise colors from your current KDE color scheme are used."
00256         ) );
00257   QWhatsThis::add( lbColors, i18n(
00258         "Double click or press RETURN on a item to select a color for the related strings in the view."
00259         ) );
00260   
00261   // Fonts
00262   QVBox *fntTab = new QVBox( this, "fonttab" );
00263   
00264   fntTab->setSpacing( spacing );
00265   fntTab->setMargin( spacing );
00266   
00267   cbEnableCustomFonts = new QCheckBox( i18n("&Enable custom fonts"), fntTab );
00268   connect( cbEnableCustomFonts, SIGNAL(clicked()), this, SLOT(enableFonts()) );
00269   
00270   vbFonts = new QWidget( fntTab );
00271   QGridLayout *gFnts = new QGridLayout( vbFonts, 2, 3 );
00272   gFnts->setSpacing( spacing );
00273   gFnts->setAutoAdd( true );
00274   gFnts->setColStretch( 1, 1 );  
00275   QLabel *lTFnt = new QLabel( i18n("&Text font:"), vbFonts );
00276   lTextFont = new QLabel( vbFonts );
00277   lTextFont->setFrameStyle( QFrame::Panel|QFrame::Sunken );
00278   btnFont = new KPushButton( i18n("Choose..."), vbFonts );
00279   lTFnt->setBuddy( btnFont );
00280   connect( btnFont, SIGNAL(clicked()), this, SLOT(setTextFont()) );
00281   
00282   QLabel *lHFnt = new QLabel( i18n("&Header font:"), vbFonts );
00283   lHeaderFont = new QLabel( vbFonts );
00284   lHeaderFont->setFrameStyle( QFrame::Panel|QFrame::Sunken );
00285   btnHeaderFont = new KPushButton( i18n("Choose..."), vbFonts );
00286   lHFnt->setBuddy( btnHeaderFont );
00287   connect( btnHeaderFont, SIGNAL(clicked()), this, SLOT(setHeaderFont()) );
00288   
00289   fntTab->setStretchFactor( new QWidget( fntTab ), 1 );
00290 
00291   QWhatsThis::add( cbEnableCustomFonts, i18n(
00292         "If custom fonts are enabled, you may choose which fonts to use for this view below. "
00293         "Otherwise the default KDE font will be used, in bold style for the header and "
00294         "normal style for the data."
00295         ) );
00296           
00297   tabs->addTab( fntTab, i18n("&Fonts") );
00298   
00299   // Behaviour
00300   QVBox *behaviourTab = new QVBox( this );
00301   behaviourTab->setMargin( margin );
00302   behaviourTab->setSpacing( spacing );
00303   
00304   cbShowEmptyFields = new QCheckBox( i18n("Show &empty fields"), behaviourTab );
00305   cbShowFieldLabels = new QCheckBox( i18n("Show field &labels"), behaviourTab );
00306 
00307   behaviourTab->setStretchFactor( new QWidget( behaviourTab ), 1 );
00308 
00309   tabs->addTab( behaviourTab, i18n("Be&havior") );
00310     
00311 }
00312 
00313 void CardViewLookNFeelPage::updateFontLabel( QFont fnt, QLabel *l )
00314 {
00315   l->setFont( fnt );
00316   l->setText(  QString( fnt.family() + " %1" ).arg( fnt.pointSize() ) );
00317 }
00318 
00319 #include "configurecardviewdialog.moc"
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:50 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003