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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 As a special exception, permission is given to link this program 00020 with any edition of TQt, and distribute the resulting executable, 00021 without including the source code for TQt in the source distribution. 00022 */ 00023 00024 #include <tqstring.h> 00025 #include <tqlayout.h> 00026 #include <tqlabel.h> 00027 #include <tqcheckbox.h> 00028 #include <tqvbox.h> 00029 #include <tqgroupbox.h> 00030 #include <tqspinbox.h> 00031 #include <tqtabwidget.h> 00032 #include <tqwhatsthis.h> 00033 00034 #include <kdebug.h> 00035 #include <tdeglobal.h> 00036 #include <tdeglobalsettings.h> 00037 #include <tdelocale.h> 00038 #include <kiconloader.h> 00039 #include <tdeconfig.h> 00040 #include <tdefontdialog.h> 00041 #include <kpushbutton.h> 00042 00043 #include "colorlistbox.h" 00044 00045 #include "configurecardviewdialog.h" 00046 00048 // ConfigureCardViewDialog 00049 00050 ConfigureCardViewWidget::ConfigureCardViewWidget( TDEABC::AddressBook *ab, TQWidget *parent, 00051 const char *name ) 00052 : ViewConfigureWidget( ab, parent, name ) 00053 { 00054 TQWidget *page = addPage( i18n( "Look & Feel" ), TQString(), 00055 DesktopIcon( "preferences-desktop" ) ); 00056 mAdvancedPage = new CardViewLookNFeelPage( page ); 00057 } 00058 00059 ConfigureCardViewWidget::~ConfigureCardViewWidget() 00060 { 00061 } 00062 00063 void ConfigureCardViewWidget::restoreSettings( TDEConfig *config ) 00064 { 00065 ViewConfigureWidget::restoreSettings( config ); 00066 00067 mAdvancedPage->restoreSettings( config ); 00068 } 00069 00070 void ConfigureCardViewWidget::saveSettings( TDEConfig *config ) 00071 { 00072 ViewConfigureWidget::saveSettings( config ); 00073 00074 mAdvancedPage->saveSettings( config ); 00075 } 00076 00078 // CardViewLookNFeelPage 00079 CardViewLookNFeelPage::CardViewLookNFeelPage( TQWidget *parent, const char *name ) 00080 : TQVBox( parent, name ) 00081 { 00082 initGUI(); 00083 } 00084 00085 CardViewLookNFeelPage::~CardViewLookNFeelPage() 00086 { 00087 } 00088 00089 void CardViewLookNFeelPage::restoreSettings( TDEConfig *config ) 00090 { 00091 // colors 00092 cbEnableCustomColors->setChecked( config->readBoolEntry( "EnableCustomColors", false ) ); 00093 TQColor c; 00094 c = TDEGlobalSettings::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 TQFont fnt = font(); 00117 updateFontLabel( config->readFontEntry( "TextFont", &fnt ), (TQLabel*)lTextFont ); 00118 fnt.setBold( true ); 00119 updateFontLabel( config->readFontEntry( "HeaderFont", &fnt ), (TQLabel*)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( TDEConfig *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 TQFont f( lTextFont->font() ); 00170 if ( TDEFontDialog::getFont( f, false, this ) == TQDialog::Accepted ) 00171 updateFontLabel( f, lTextFont ); 00172 } 00173 00174 void CardViewLookNFeelPage::setHeaderFont() 00175 { 00176 TQFont f( lHeaderFont->font() ); 00177 if ( TDEFontDialog::getFont( f,false, this ) == TQDialog::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 TQTabWidget *tabs = new TQTabWidget( this ); 00197 00198 // Layout 00199 TQVBox *loTab = new TQVBox( this, "layouttab" ); 00200 00201 loTab->setSpacing( spacing ); 00202 loTab->setMargin( margin ); 00203 00204 TQGroupBox *gbGeneral = new TQGroupBox( 1, Qt::Horizontal, i18n("General"), loTab ); 00205 00206 cbDrawSeps = new TQCheckBox( i18n("Draw &separators"), gbGeneral ); 00207 00208 TQHBox *hbSW = new TQHBox( gbGeneral ); 00209 TQLabel *lSW = new TQLabel( i18n("Separator &width:"), hbSW ); 00210 sbSepWidth = new TQSpinBox( 1, 50, 1, hbSW ); 00211 lSW->setBuddy( sbSepWidth); 00212 00213 TQHBox *hbPadding = new TQHBox( gbGeneral ); 00214 TQLabel *lSpacing = new TQLabel( i18n("&Padding:"), hbPadding ); 00215 sbSpacing = new TQSpinBox( 0, 100, 1, hbPadding ); 00216 lSpacing->setBuddy( sbSpacing ); 00217 00218 TQGroupBox *gbCards = new TQGroupBox( 1, Qt::Horizontal, i18n("Cards"), loTab ); 00219 00220 TQHBox *hbMargin = new TQHBox( gbCards ); 00221 TQLabel *lMargin = new TQLabel( i18n("&Margin:"), hbMargin ); 00222 sbMargin = new TQSpinBox( 0, 100, 1, hbMargin ); 00223 lMargin->setBuddy( sbMargin ); 00224 00225 cbDrawBorders = new TQCheckBox( i18n("Draw &borders"), gbCards ); 00226 00227 loTab->setStretchFactor( new TQWidget( loTab ), 1 ); 00228 00229 TQWhatsThis::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 TQWhatsThis::add( lMargin, TQWhatsThis::textFor( sbMargin ) ); 00234 TQWhatsThis::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 TQWhatsThis::add( lSpacing, TQWhatsThis::textFor( sbSpacing ) ); 00239 TQWhatsThis::add( sbSepWidth, i18n("Sets the width of column separators") ); 00240 TQWhatsThis::add( lSW, TQWhatsThis::textFor( sbSepWidth ) ); 00241 00242 tabs->addTab( loTab, i18n("&Layout") ); 00243 00244 // Colors 00245 TQVBox *colorTab = new TQVBox( this, "colortab" ); 00246 colorTab->setSpacing( spacing ); 00247 colorTab->setMargin( spacing ); 00248 cbEnableCustomColors = new TQCheckBox( i18n("&Enable custom colors"), colorTab ); 00249 connect( cbEnableCustomColors, TQT_SIGNAL(clicked()), this, TQT_SLOT(enableColors()) ); 00250 lbColors = new ColorListBox( colorTab ); 00251 tabs->addTab( colorTab, i18n("&Colors") ); 00252 00253 TQWhatsThis::add( cbEnableCustomColors, i18n( 00254 "If custom colors is enabled, you may choose the colors for the view below. " 00255 "Otherwise colors from your current TDE color scheme are used." 00256 ) ); 00257 TQWhatsThis::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 TQVBox *fntTab = new TQVBox( this, "fonttab" ); 00263 00264 fntTab->setSpacing( spacing ); 00265 fntTab->setMargin( spacing ); 00266 00267 cbEnableCustomFonts = new TQCheckBox( i18n("&Enable custom fonts"), fntTab ); 00268 connect( cbEnableCustomFonts, TQT_SIGNAL(clicked()), this, TQT_SLOT(enableFonts()) ); 00269 00270 vbFonts = new TQWidget( fntTab ); 00271 TQGridLayout *gFnts = new TQGridLayout( vbFonts, 2, 3 ); 00272 gFnts->setSpacing( spacing ); 00273 gFnts->setAutoAdd( true ); 00274 gFnts->setColStretch( 1, 1 ); 00275 TQLabel *lTFnt = new TQLabel( i18n("&Text font:"), vbFonts ); 00276 lTextFont = new TQLabel( vbFonts ); 00277 lTextFont->setFrameStyle( TQFrame::Panel|TQFrame::Sunken ); 00278 btnFont = new KPushButton( i18n("Choose..."), vbFonts ); 00279 lTFnt->setBuddy( btnFont ); 00280 connect( btnFont, TQT_SIGNAL(clicked()), this, TQT_SLOT(setTextFont()) ); 00281 00282 TQLabel *lHFnt = new TQLabel( i18n("&Header font:"), vbFonts ); 00283 lHeaderFont = new TQLabel( vbFonts ); 00284 lHeaderFont->setFrameStyle( TQFrame::Panel|TQFrame::Sunken ); 00285 btnHeaderFont = new KPushButton( i18n("Choose..."), vbFonts ); 00286 lHFnt->setBuddy( btnHeaderFont ); 00287 connect( btnHeaderFont, TQT_SIGNAL(clicked()), this, TQT_SLOT(setHeaderFont()) ); 00288 00289 fntTab->setStretchFactor( new TQWidget( fntTab ), 1 ); 00290 00291 TQWhatsThis::add( cbEnableCustomFonts, i18n( 00292 "If custom fonts are enabled, you may choose which fonts to use for this view below. " 00293 "Otherwise the default TDE 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 TQVBox *behaviourTab = new TQVBox( this ); 00301 behaviourTab->setMargin( margin ); 00302 behaviourTab->setSpacing( spacing ); 00303 00304 cbShowEmptyFields = new TQCheckBox( i18n("Show &empty fields"), behaviourTab ); 00305 cbShowFieldLabels = new TQCheckBox( i18n("Show field &labels"), behaviourTab ); 00306 00307 behaviourTab->setStretchFactor( new TQWidget( behaviourTab ), 1 ); 00308 00309 tabs->addTab( behaviourTab, i18n("Be&havior") ); 00310 00311 } 00312 00313 void CardViewLookNFeelPage::updateFontLabel( TQFont fnt, TQLabel *l ) 00314 { 00315 l->setFont( fnt ); 00316 l->setText( TQString( fnt.family() + " %1" ).arg( fnt.pointSize() ) ); 00317 } 00318 00319 #include "configurecardviewdialog.moc"