krop's commit fixes my problem in a better way, reverting
[kdepim.git] / knotes / knoteconfigdlg.cpp
blobfff6134ce8c0fda5bedd06583fdd871e3f4c1f7e
1 /*******************************************************************
2 KNotes -- Notes for the KDE project
4 Copyright (c) 1997-2005, The KNotes Developers
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************/
22 #include "knoteconfigdlg.h"
23 #include "knote.h"
24 #include "knotesglobalconfig.h"
25 #include "version.h"
27 #include <kapplication.h>
28 #include <kcolorbutton.h>
29 #include <kconfig.h>
30 #include <kfontrequester.h>
31 #include <kiconloader.h>
32 #include <klineedit.h>
33 #include <klocale.h>
34 #include <knuminput.h>
35 #include <kwindowsystem.h>
37 #include <QCheckBox>
38 #include <QComboBox>
39 #include <QGridLayout>
40 #include <QGroupBox>
41 #include <QHBoxLayout>
42 #include <QLabel>
43 #include <QVBoxLayout>
46 KNoteSimpleConfigDlg::KNoteSimpleConfigDlg( KNoteConfig *config, const QString &title,
47 QWidget *parent, const QString &name )
48 : KConfigDialog( parent, name, config )
50 setFaceType( KPageDialog::List );
51 setButtons( Default | Ok | Apply | Cancel );
52 setDefaultButton( Ok );
54 setCaption( title );
55 #ifdef Q_WS_X11
56 KWindowSystem::setIcons( winId(),
57 qApp->windowIcon().pixmap(
58 IconSize( KIconLoader::Desktop ),
59 IconSize( KIconLoader::Desktop ) ),
60 qApp->windowIcon().pixmap(
61 IconSize( KIconLoader::Small ),
62 IconSize( KIconLoader::Small ) ) );
63 #endif
64 showButtonSeparator( true );
66 addPage( new KNoteDisplayConfigWidget( false ), i18n( "Display" ), "knotes",
67 i18n( "Display Settings" ) );
68 addPage( new KNoteEditorConfigWidget( false ), i18n( "Editor" ), "accessories-text-editor",
69 i18n( "Editor Settings" ) );
70 config->setVersion( KNOTES_VERSION );
74 void KNoteSimpleConfigDlg::slotUpdateCaption(const QString & name)
76 setCaption( name );
80 KNoteConfigDlg::KNoteConfigDlg( const QString &title,
81 QWidget *parent )
82 : KCMultiDialog( parent )
84 setFaceType( KPageDialog::List );
85 setButtons( Default | Ok | Cancel );
86 setDefaultButton( Ok );
88 setCaption( title );
89 #ifdef Q_WS_X11
90 KWindowSystem::setIcons( winId(),
91 qApp->windowIcon().pixmap(
92 IconSize( KIconLoader::Desktop ),
93 IconSize( KIconLoader::Desktop ) ),
94 qApp->windowIcon().pixmap(
95 IconSize( KIconLoader::Small ),
96 IconSize( KIconLoader::Small ) ) );
97 #endif
98 //setIconListAllVisible( true );
99 showButtonSeparator( true );
101 addModule( "knote_config_display" );
102 addModule( "knote_config_editor" );
103 addModule( "knote_config_action" );
104 addModule( "knote_config_network" );
105 addModule( "knote_config_style" );
107 KNotesGlobalConfig::self()->setVersion( KNOTES_VERSION );
108 connect( this, SIGNAL(okClicked()), SLOT(slotOk()) );
112 KNoteConfigDlg::~KNoteConfigDlg()
116 void KNoteConfigDlg::slotOk() {
117 KNotesGlobalConfig::self()->writeConfig();
118 emit configWrote();
122 extern "C"
124 KDE_EXPORT KCModule *create_knote_config_display( QWidget *parent )
126 KComponentData instance( "kcmnote_config_display" );
127 return new KNoteDisplayConfig( instance, parent );
131 extern "C"
133 KDE_EXPORT KCModule *create_knote_config_editor( QWidget *parent )
135 KComponentData instance( "kcmnote_config_editor" );
136 return new KNoteEditorConfig( instance, parent );
140 extern "C"
142 KDE_EXPORT KCModule *create_knote_config_action( QWidget *parent )
144 KComponentData instance( "kcmnote_config_action" );
145 return new KNoteActionConfig( instance, parent );
149 extern "C"
151 KDE_EXPORT KCModule *create_knote_config_network( QWidget *parent )
153 KComponentData instance( "kcmnote_config_network" );
154 return new KNoteNetworkConfig( instance, parent );
159 extern "C"
161 KDE_EXPORT KCModule *create_knote_config_style( QWidget *parent )
163 KComponentData instance( "kcmnote_config_style" );
164 return new KNoteStyleConfig( instance, parent );
168 KNoteDisplayConfigWidget::KNoteDisplayConfigWidget( bool defaults )
169 :QWidget( 0 )
171 QGridLayout *layout = new QGridLayout( this );
172 layout->setSpacing( KDialog::spacingHint() );
173 layout->setMargin( defaults ? KDialog::marginHint() : 0 );
175 QLabel *label_FgColor = new QLabel( i18n( "&Text color:" ),this );
176 label_FgColor->setObjectName( "label_FgColor" );
177 layout->addWidget( label_FgColor, 0, 0 );
179 KColorButton *kcfg_FgColor = new KColorButton( this );
180 kcfg_FgColor->setObjectName( "kcfg_FgColor" );
181 label_FgColor->setBuddy( kcfg_FgColor );
182 layout->addWidget( kcfg_FgColor, 0, 1 );
184 QLabel *label_BgColor = new QLabel( i18n( "&Background color:" ),
185 this );
186 label_BgColor->setObjectName( "label_BgColor" );
187 layout->addWidget( label_BgColor, 1, 0 );
189 KColorButton *kcfg_BgColor = new KColorButton( this );
190 kcfg_BgColor->setObjectName( "kcfg_BgColor" );
191 label_BgColor->setBuddy( kcfg_BgColor );
192 layout->addWidget( kcfg_BgColor, 1, 1 );
194 QCheckBox *kcfg_ShowInTaskbar =
195 new QCheckBox( i18n( "&Show note in taskbar" ), this );
196 kcfg_ShowInTaskbar->setObjectName( "kcfg_ShowInTaskbar" );
197 #ifdef Q_WS_X11
198 QCheckBox *kcfg_RememberDesktop =
199 new QCheckBox( i18n( "&Remember desktop" ), this );
200 kcfg_RememberDesktop->setObjectName( "kcfg_RememberDesktop" );
201 #endif
202 if ( defaults ) {
203 QLabel *label_Width = new QLabel( i18n( "Default &width:" ), this );
205 label_Width->setObjectName( "label_Width" );
206 layout->addWidget( label_Width, 2, 0 );
208 KIntNumInput *kcfg_Width = new KIntNumInput( this );
209 kcfg_Width->setObjectName( "kcfg_Width" );
210 label_Width->setBuddy( kcfg_Width );
211 kcfg_Width->setRange( 50, 2000, 10 );
212 kcfg_Width->setSliderEnabled( false );
213 layout->addWidget( kcfg_Width, 2, 1 );
215 QLabel *label_Height = new QLabel( i18n( "Default &height:" ),
216 this );
217 label_Height->setObjectName( "label_Height" );
218 layout->addWidget( label_Height, 3, 0 );
220 KIntNumInput *kcfg_Height = new KIntNumInput( this );
221 kcfg_Height->setObjectName( "kcfg_Height" );
222 kcfg_Height->setRange( 50, 2000, 10 );
223 kcfg_Height->setSliderEnabled( false );
224 label_Height->setBuddy( kcfg_Height );
225 layout->addWidget( kcfg_Height, 3, 1 );
227 layout->addWidget( kcfg_ShowInTaskbar, 4, 0 );
228 #ifdef Q_WS_X11
229 layout->addWidget( kcfg_RememberDesktop, 5, 0 );
230 #endif
231 } else {
232 layout->addWidget( kcfg_ShowInTaskbar, 2, 0 );
233 #ifdef Q_WS_X11
234 layout->addWidget( kcfg_RememberDesktop, 3, 0 );
235 #endif
239 KNoteDisplayConfig::KNoteDisplayConfig( const KComponentData &inst, QWidget *parent )
240 :KCModule( inst, parent )
242 QHBoxLayout *lay = new QHBoxLayout( this );
243 QWidget * w = new KNoteDisplayConfigWidget( true );
244 lay->addWidget( w );
245 addConfig( KNotesGlobalConfig::self(), w );
246 load();
249 void KNoteDisplayConfig::load()
251 KCModule::load();
254 void KNoteDisplayConfig::save()
256 KCModule::save();
259 KNoteEditorConfigWidget::KNoteEditorConfigWidget( bool defaults )
260 :QWidget( 0 )
262 QGridLayout *layout = new QGridLayout( this );
263 layout->setSpacing( KDialog::spacingHint() );
264 layout->setMargin( defaults ? KDialog::marginHint() : 0 );
266 QLabel *label_TabSize = new QLabel( i18n( "&Tab size:" ), this );
267 label_TabSize->setObjectName( "label_TabSize" );
268 layout->addWidget( label_TabSize, 0, 0, 1, 2 );
270 KIntNumInput *kcfg_TabSize = new KIntNumInput( this );
271 kcfg_TabSize->setObjectName( "kcfg_TabSize" );
272 kcfg_TabSize->setRange( 0, 40 );
273 kcfg_TabSize->setSliderEnabled( false );
274 label_TabSize->setBuddy( kcfg_TabSize );
275 layout->addWidget( kcfg_TabSize, 0, 2 );
277 QCheckBox *kcfg_AutoIndent = new QCheckBox( i18n( "Auto &indent" ),
278 this );
279 kcfg_AutoIndent->setObjectName( "kcfg_AutoIndent" );
280 layout->addWidget( kcfg_AutoIndent, 1, 0, 1, 2 );
282 QCheckBox *kcfg_RichText = new QCheckBox( i18n( "&Rich text" ), this );
283 kcfg_RichText->setObjectName( "kcfg_RichText" );
284 layout->addWidget( kcfg_RichText, 1, 2 );
286 QLabel *label_Font = new QLabel( i18n( "Text font:" ), this );
287 label_Font->setObjectName( "label_Font" );
288 layout->addWidget( label_Font, 3, 0 );
290 KFontRequester *kcfg_Font = new KFontRequester( this );
291 kcfg_Font->setObjectName( "kcfg_Font" );
292 kcfg_Font->setSizePolicy( QSizePolicy( QSizePolicy::Minimum,
293 QSizePolicy::Fixed ) );
294 layout->addWidget( kcfg_Font, 3, 1, 1, 2 );
296 QLabel *label_TitleFont = new QLabel( i18n( "Title font:" ), this );
297 label_TitleFont->setObjectName( "label_TitleFont" );
298 layout->addWidget( label_TitleFont, 2, 0 );
300 KFontRequester *kcfg_TitleFont = new KFontRequester( this );
301 kcfg_TitleFont->setObjectName( "kcfg_TitleFont" );
302 kcfg_TitleFont->setSizePolicy( QSizePolicy( QSizePolicy::Minimum,
303 QSizePolicy::Fixed ) );
304 layout->addWidget( kcfg_TitleFont, 2, 1, 1, 2 );
308 KNoteEditorConfig::KNoteEditorConfig( const KComponentData &inst, QWidget *parent )
309 :KCModule( inst, parent )
311 QHBoxLayout *lay = new QHBoxLayout( this );
312 QWidget * w = new KNoteEditorConfigWidget( true );
313 lay->addWidget( w );
314 addConfig( KNotesGlobalConfig::self(), w );
315 load();
318 void KNoteEditorConfig::save()
320 KCModule::save();
323 void KNoteEditorConfig::load()
325 KCModule::load();
328 KNoteActionConfig::KNoteActionConfig(const KComponentData &inst, QWidget *parent )
329 :KCModule( inst, parent )
331 QHBoxLayout *lay = new QHBoxLayout( this );
332 QWidget * w = new QWidget( this );
333 lay->addWidget( w );
334 QGridLayout *layout = new QGridLayout( w );
335 layout->setSpacing( KDialog::spacingHint() );
336 layout->setMargin( 0 );
338 QLabel *label_MailAction = new QLabel( i18n( "&Mail action:" ), this );
339 label_MailAction->setObjectName( "label_MailAction" );
340 layout->addWidget( label_MailAction, 0, 0 );
342 KLineEdit *kcfg_MailAction = new KLineEdit( this );
343 kcfg_MailAction->setObjectName( "kcfg_MailAction" );
344 label_MailAction->setBuddy( kcfg_MailAction );
345 layout->addWidget( kcfg_MailAction, 0, 1 );
346 addConfig( KNotesGlobalConfig::self(), w );
347 load();
350 void KNoteActionConfig::save()
352 KCModule::save();
355 void KNoteActionConfig::load()
357 KCModule::load();
360 KNoteNetworkConfig::KNoteNetworkConfig(const KComponentData &inst, QWidget *parent )
361 :KCModule( inst, parent )
363 QHBoxLayout *lay = new QHBoxLayout( this );
364 QWidget * w = new QWidget( this );
365 lay->addWidget( w );
366 QVBoxLayout *layout = new QVBoxLayout( w );
367 layout->setSpacing( KDialog::spacingHint() );
368 layout->setMargin( 0 );
370 QGroupBox *incoming = new QGroupBox( i18n( "Incoming Notes" ) );
371 QHBoxLayout *tmpLayout = new QHBoxLayout;
373 QCheckBox *tmpChkB=new QCheckBox( i18n( "Accept incoming notes" ) );
374 tmpChkB->setObjectName( "kcfg_ReceiveNotes" );
375 tmpLayout->addWidget( tmpChkB );
376 incoming->setLayout( tmpLayout );
377 layout->addWidget( incoming );
379 QGroupBox *outgoing = new QGroupBox( i18n( "Outgoing Notes" ) );
380 tmpLayout = new QHBoxLayout;
382 QLabel *label_SenderID = new QLabel( i18n( "&Sender ID:" ) );
383 label_SenderID->setObjectName( "label_SenderID" );
384 KLineEdit *kcfg_SenderID = new KLineEdit;
385 kcfg_SenderID->setObjectName( "kcfg_SenderID" );
386 label_SenderID->setBuddy( kcfg_SenderID );
387 tmpLayout->addWidget( label_SenderID );
388 tmpLayout->addWidget( kcfg_SenderID );
389 outgoing->setLayout( tmpLayout );
390 layout->addWidget( outgoing );
392 tmpLayout = new QHBoxLayout;
394 QLabel *label_Port = new QLabel( i18n( "&Port:" ) );
395 label_Port->setObjectName( "label_Port" );
397 tmpLayout->addWidget( label_Port );
399 KIntNumInput *kcfg_Port = new KIntNumInput;
400 kcfg_Port->setObjectName( "kcfg_Port" );
401 kcfg_Port->setRange( 0, 65535 );
402 kcfg_Port->setSliderEnabled( false );
403 label_Port->setBuddy( kcfg_Port );
404 tmpLayout->addWidget( kcfg_Port );
405 layout->addLayout( tmpLayout );
406 addConfig( KNotesGlobalConfig::self(), w );
407 load();
410 void KNoteNetworkConfig::save()
412 KCModule::save();
415 void KNoteNetworkConfig::load()
417 KCModule::load();
420 KNoteStyleConfig::KNoteStyleConfig(const KComponentData &inst, QWidget *parent )
421 :KCModule( inst, parent )
423 QHBoxLayout *lay = new QHBoxLayout( this );
424 QWidget * w = new QWidget( this );
425 lay->addWidget( w );
426 QGridLayout *layout = new QGridLayout( w );
427 layout->setSpacing( KDialog::spacingHint() );
428 layout->setMargin( 0 );
430 QLabel *label_Style = new QLabel( i18n( "&Style:" ), this );
431 label_Style->setObjectName( "label_Style" );
432 layout->addWidget( label_Style, 0, 0 );
434 QComboBox *kcfg_Style = new QComboBox( this );
435 kcfg_Style->setObjectName( "kcfg_Style" );
436 QStringList list;
437 list << i18n( "Plain" );
438 kcfg_Style->addItems( list );
439 label_Style->setBuddy( kcfg_Style );
440 layout->addWidget( kcfg_Style, 0, 1 );
441 addConfig( KNotesGlobalConfig::self(), w );
442 load();
445 void KNoteStyleConfig::save()
447 KCModule::save();
450 void KNoteStyleConfig::load()
452 KCModule::load();
455 #include "knoteconfigdlg.moc"