00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qlabel.h>
00022 #include <qlayout.h>
00023 #include <qcheckbox.h>
00024
00025 #include <kconfig.h>
00026 #include <klocale.h>
00027 #include <kcolorbutton.h>
00028 #include <knuminput.h>
00029 #include <klineedit.h>
00030 #include <kfontdialog.h>
00031 #include <kiconloader.h>
00032
00033 #include "knoteconfigdlg.h"
00034 #include "version.h"
00035
00036 KNoteConfigDlg::KNoteConfigDlg( const QString& configfile, const QString& title,
00037 bool global, QWidget* parent, const char* name )
00038 : KDialogBase( IconList, title, Ok|Apply|Cancel, Ok, parent, name, true, true )
00039 {
00040 setIconListAllVisible( true );
00041 _config = new KConfig( configfile, false, false );
00042 _global = global;
00043
00044 makeDisplayPage();
00045 makeEditorPage();
00046 makeActionsPage();
00047 }
00048
00049 KNoteConfigDlg::~KNoteConfigDlg()
00050 {
00051
00052
00053 delete _config;
00054 }
00055
00056 void KNoteConfigDlg::makeDisplayPage()
00057 {
00058 _config->setGroup( "Display" );
00059
00060
00061 QPixmap icon = KGlobal::iconLoader()->loadIcon( "appearance", KIcon::Toolbar, KIcon::SizeMedium );
00062 QFrame* displayPage = addPage( i18n( "Display" ), i18n("Display Settings"), icon );
00063
00064
00065 QVBoxLayout* topLevel = new QVBoxLayout( displayPage, 0, spacingHint() );
00066 QGridLayout* glay = new QGridLayout( topLevel, 5, 3 );
00067 glay->setColStretch( 1, 1 );
00068
00069 QLabel* l_fgcolor = new QLabel( i18n("&Text color:"), displayPage );
00070 QLabel* l_bgcolor = new QLabel( i18n("&Background color:"), displayPage );
00071
00072 QColor fgcolor = _config->readColorEntry( "fgcolor", &(Qt::black) );
00073 QColor bgcolor = _config->readColorEntry( "bgcolor", &(Qt::yellow) );
00074 _fgColor = new KColorButton( fgcolor, displayPage );
00075 _bgColor = new KColorButton( bgcolor, displayPage );
00076 connect( _fgColor, SIGNAL( changed(const QColor&)),
00077 this, SLOT( slotFGColor(const QColor&) ) );
00078 connect( _bgColor, SIGNAL( changed(const QColor&)),
00079 this, SLOT( slotBGColor(const QColor&) ) );
00080
00081 l_fgcolor->setBuddy( _fgColor );
00082 l_bgcolor->setBuddy( _bgColor );
00083
00084 glay->addWidget( l_fgcolor, 0, 0 );
00085 glay->addWidget( l_bgcolor, 1, 0 );
00086 glay->addWidget( _fgColor, 0, 2 );
00087 glay->addWidget( _bgColor, 1, 2 );
00088
00089 if ( _global )
00090 {
00091 QLabel* l_width = new QLabel( i18n("Default &width:"), displayPage );
00092 QLabel* l_height = new QLabel( i18n("Default &height:"), displayPage );
00093
00094 uint width = _config->readUnsignedNumEntry( "width", 200 );
00095 uint height = _config->readUnsignedNumEntry( "height", 200 );
00096
00097 _widthEdit = new KIntNumInput( width, displayPage );
00098 _widthEdit->setRange( 100, 2000, 10, false );
00099 _heightEdit = new KIntNumInput( height, displayPage );
00100 _heightEdit->setRange( 100, 2000, 10, false );
00101
00102 l_width->setBuddy( _widthEdit );
00103 l_height->setBuddy( _heightEdit );
00104
00105 glay->addWidget( l_width, 2, 0 );
00106 glay->addWidget( _widthEdit, 2, 2 );
00107 glay->addWidget( l_height, 3, 0 );
00108 glay->addWidget( _heightEdit, 3, 2 );
00109 }
00110 }
00111
00112 void KNoteConfigDlg::makeEditorPage()
00113 {
00114 _config->setGroup( "Editor" );
00115
00116
00117 QPixmap icon = KGlobal::iconLoader()->loadIcon( "edit", KIcon::Toolbar, KIcon::SizeMedium );
00118 QFrame* editorPage = addPage( i18n( "Editor" ), i18n("Editor Settings"), icon );
00119
00120
00121 QVBoxLayout* topLevel = new QVBoxLayout( editorPage, 0, spacingHint() );
00122 QGridLayout* glay = new QGridLayout( topLevel, 4, 3 );
00123 glay->setColStretch( 1, 1 );
00124
00125 QLabel* l_tabsize = new QLabel( i18n( "&Tab size:" ), editorPage );
00126 glay->addWidget( l_tabsize, 0, 0 );
00127
00128 int tabsize = _config->readUnsignedNumEntry( "tabsize", 4 );
00129 _tabEdit = new KIntNumInput( tabsize, editorPage );
00130 _tabEdit->setRange( 0, 20, 1, false );
00131 glay->addWidget( _tabEdit, 0, 2 );
00132 l_tabsize->setBuddy( _tabEdit );
00133
00134 bool check_val = _config->readBoolEntry( "autoindent", true );
00135 _autoIndentSwitch = new QCheckBox( i18n("Auto &indent"), editorPage );
00136 _autoIndentSwitch->setChecked( check_val );
00137 glay->addWidget( _autoIndentSwitch, 1, 0, AlignCenter );
00138
00139 check_val = _config->readBoolEntry( "richtext", false );
00140 _richTextSwitch = new QCheckBox( i18n("&Rich Text"), editorPage );
00141 _richTextSwitch->setChecked( check_val );
00142 _richTextSwitch->setEnabled( false );
00143 glay->addWidget( _richTextSwitch, 1, 2, AlignCenter );
00144
00145 _titleFont = new QPushButton( editorPage );
00146 QFont def_font(KGlobalSettings::generalFont());
00147 QFont currfont = _config->readFontEntry( "titlefont", &def_font );
00148 _titleFont->setFont( currfont );
00149 _titleFont->setText( i18n( "Title Font: Click to Change..." ) );
00150 glay->addMultiCellWidget( _titleFont, 2, 2, 0, 2 );
00151 connect( _titleFont, SIGNAL(clicked()), this, SLOT(slotChangeTitleFont()) );
00152
00153 _textFont = new QPushButton( editorPage );
00154 currfont = _config->readFontEntry( "font", &def_font );
00155 _textFont->setFont( currfont );
00156 _textFont->setText( i18n( "Text Font: Click to Change..." ) );
00157 glay->addMultiCellWidget( _textFont, 3, 3, 0, 2 );
00158 connect( _textFont, SIGNAL(clicked()), this, SLOT(slotChangeTextFont()) );
00159 }
00160
00161 void KNoteConfigDlg::makeActionsPage()
00162 {
00163 _config->setGroup( "Actions" );
00164
00165
00166 QPixmap icon = KGlobal::iconLoader()->loadIcon( "misc", KIcon::Toolbar, KIcon::SizeMedium );
00167 QFrame* actionsPage = addPage( i18n( "Actions" ), i18n("Action Settings"), icon );
00168
00169
00170 QVBoxLayout* topLevel = new QVBoxLayout( actionsPage, 0, spacingHint() );
00171 QGridLayout* glay = new QGridLayout( topLevel, 2, 2 );
00172 glay->setColStretch( 1, 1 );
00173
00174 QLabel* l_mail = new QLabel( i18n("&Mail action:"), actionsPage );
00175 QString mailstr = _config->readEntry( "mail", "kmail --msg %f" );
00176 _mailEdit = new KLineEdit( mailstr, actionsPage );
00177 l_mail->setBuddy( _mailEdit );
00178 glay->addWidget( l_mail, 0, 0 );
00179 glay->addWidget( _mailEdit, 0, 1 );
00180 }
00181
00182 void KNoteConfigDlg::storeSettings()
00183 {
00184
00185 _config->setGroup( "General" );
00186
00187 _config->writeEntry( "version", KNOTES_VERSION );
00188
00189
00190 _config->setGroup( "Display" );
00191
00192 _config->writeEntry( "fgcolor", _fgColor->color() );
00193 _config->writeEntry( "bgcolor", _bgColor->color() );
00194
00195 if ( _global )
00196 {
00197 _config->writeEntry( "height", _heightEdit->value() );
00198 _config->writeEntry( "width", _widthEdit->value() );
00199 }
00200
00201
00202 _config->setGroup( "Editor" );
00203
00204 _config->writeEntry( "titlefont", _titleFont->font() );
00205 _config->writeEntry( "font", _textFont->font() );
00206 _config->writeEntry( "autoindent", _autoIndentSwitch->isChecked() );
00207 _config->writeEntry( "richtext", _richTextSwitch->isChecked() );
00208 _config->writeEntry( "tabsize", _tabEdit->value() );
00209
00210
00211 _config->setGroup( "Actions" );
00212
00213 _config->writeEntry( "mail", _mailEdit->text() );
00214
00215
00216 _config->deleteEntry( "print" );
00217
00218 _config->sync();
00219 }
00220
00221 void KNoteConfigDlg::slotOk()
00222 {
00223
00224 storeSettings();
00225 emit updateConfig();
00226
00227 accept();
00228 }
00229
00230 void KNoteConfigDlg::slotApply()
00231 {
00232 storeSettings();
00233 emit updateConfig();
00234 }
00235
00236 void KNoteConfigDlg::slotChangeTitleFont()
00237 {
00238 QFont newfont = _titleFont->font();
00239 KFontDialog::getFont( newfont );
00240
00241 _titleFont->setFont( newfont );
00242 }
00243
00244 void KNoteConfigDlg::slotChangeTextFont()
00245 {
00246 QFont newfont = _textFont->font();
00247 KFontDialog::getFont( newfont );
00248
00249 _textFont->setFont( newfont );
00250 }
00251
00252 void KNoteConfigDlg::slotFGColor( const QColor& c )
00253 {
00254 _fgColor->setBackgroundColor( c );
00255 }
00256
00257 void KNoteConfigDlg::slotBGColor( const QColor& c )
00258 {
00259 _bgColor->setBackgroundColor( c );
00260 }
00261
00262
00263 #include "knoteconfigdlg.moc"