1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
<appendix id="src-examples">
<title>Source and Header Examples</title>
<para>
This appendix contains an example of a
<link linkend="header-example">header file listing</link> and a
<link linkend="source-example">source file listing</link>.
</para>
<section id="header-example">
<title>Header File Example</title>
<screen>
/***************************************************************************
ksettingsdlg.h
-------------------
copyright : (C) 2000,2001 by Michael Edwardes
email : mte@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef KSETTINGSDLG_H
#define KSETTINGSDLG_H
// ----------------------------------------------------------------------------
// QT Includes
#include <qcheckbox.h>
#include <qradiobutton.h>
#include <qbuttongroup.h>
#include <qcolor.h>
#include <qfont.h>
// ----------------------------------------------------------------------------
// KDE Includes
#include <kdialogbase.h>
#include <tdefontdialog.h>
#include <kcolorbutton.h>
#include <klineedit.h>
// ----------------------------------------------------------------------------
// Project Includes
/**
* This class is used to manipulate all the settings available for
* KMyMoney2. It currently stores the values for the list settings
* and whether to show the start dialog when KMyMoney2 starts.
*
* It uses KDialogBase to implement it's interface.
*
* It uses the global TDEConfig object to read and write the application
* settings.
*
* @see KDialogBase
*
* @author Michael Edwardes 2000-2001
* $Id: src-examples.docbook,v 1.3 2005/05/27 19:05:18 ipwizard Exp $
*
* @short A class to manipulate the settings needed for running KMyMoney2
**/
class KSettingsDlg : public KDialogBase {
Q_OBJECT
private:
/** Start prompt dialog */
QRadioButton *m_qradiobuttonStartPrompt;
/** Start file */
QRadioButton *m_qradiobuttonStartFile;
/** Color list */
KColorButton *m_kcolorbuttonList;
/** Color background */
KColorButton *m_kcolorbuttonBack;
/** Select font header */
TDEFontChooser *m_tdefontchooserHeader;
/** Font cell setting */
TDEFontChooser *m_tdefontchooserCell;
/** No rows to show in register */
KLineEdit *m_klineeditRowCount;
/** Show grid in register ? */
QCheckBox *m_qcheckboxShowGrid;
QRadioButton *m_qradiobuttonPerTransaction;
QRadioButton *m_qradiobuttonOtherRow;
/** Set page general */
void setPageGeneral();
/** Set page list settings */
void setPageList();
/** Write settings */
void configWrite();
/** Read settings */
void configRead();
/** Attributes to store the variables so they can be undone when
* cancelling the apply.
**/
QColor m_qcolorTempList;
QColor m_qcolorTempListBG;
QFont m_qfontTempHeader;
QFont m_qfontTempCell;
QString m_qstringTempRowCount;
bool m_bTempShowGrid;
bool m_bTempColourPerTransaction;
bool m_bTempStartPrompt;
bool m_bDoneApply;
private slots:
/** Called when OK pressed */
void slotOk();
/** Called when Apply pressed */
void slotApply();
/** Called when Cancel pressed */
void slotCancel();
/** Called when Reset pressed */
void slotUser1();
public:
/**
* Standard constructor.
*
* @param parent The QWidget this is used in.
* @param name The QT name.
* @param modal True if we want the dialog to be application modal.
*
* @return An object of type KSettingsDlg.
*
* @see ~KSettingsDlg
**/
KSettingsDlg(QWidget *parent=0, const char *name=0, bool modal=true);
/**
* Standard destructor.
*
* @return Nothing.
*
* @see KSettingsDlg
**/
~KSettingsDlg();
signals:
/**
* Emitted when the Apply button is clicked to allow the application to
* show the changes without having to close the dialog.
*
* @return Nothing
**/
void signalApply();
};
#endif
</screen>
</section>
<section id="source-example">
<title>Source File Example</title>
<screen>
/***************************************************************************
ksettingsdlg.cpp
-------------------
copyright : (C) 2000,2001 by Michael Edwardes
email : mte@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify
* *
* it under the terms of the GNU General Public License as published by
* *
* the Free Software Foundation; either version 2 of the License, or
* *
* (at your option) any later version.
* *
* *
***************************************************************************/
// ----------------------------------------------------------------------------
// QT Includes
#include <qlayout.h>
#include <qvbox.h>
#include <qlabel.h>
#include <qgroupbox.h>
#include <qtabwidget.h>
#include <qvalidator.h>
// ----------------------------------------------------------------------------
// KDE Includes
#include <tdelocale.h>
#include <kstddirs.h>
#include <kiconloader.h>
#include <tdeconfig.h>
#include <kcolorbutton.h>
#include <tdemessagebox.h>
// ----------------------------------------------------------------------------
// Project Includes
#include "ksettingsdlg.h"
/** Standard constructor for the class.
* The constructor passes some additional parameters to the base class
* KDialogBase
* to set the buttons to be showed and the type of dialog to be shown.
**/
KSettingsDlg::KSettingsDlg(QWidget *parent, const char *name, bool modal)
: KDialogBase(IconList, i18n("Configure"), Ok|Cancel|Apply|User1, Ok, parent,
name, modal, true, i18n("&Reset"))
{
// Setup the pages and then read the configuration object.
setPageGeneral();
setPageList();
configRead();
m_bDoneApply=false;
}
/** Standard destructor for the class.
**/
KSettingsDlg::~KSettingsDlg()
{
}
/** Called to create the General page to be shown in the dialog.
**/
void KSettingsDlg::setPageGeneral()
{
// Create the main frame to hold the widgets
QVBox *qvboxMainFrame = addVBoxPage( i18n("General"), i18n("General settings"),
DesktopIcon("misc"));
// Create a group box to hold the available options
QButtonGroup *qbuttongroup = new QButtonGroup(qvboxMainFrame, "GroupBox1");
qbuttongroup->setTitle( i18n( "Startup options" ) );
qbuttongroup->setColumnLayout(0, Qt::Vertical );
qbuttongroup->layout()->setSpacing( 0 );
qbuttongroup->layout()->setMargin( 0 );
// Create a layout to organize the widgets.
QVBoxLayout *qvboxlayout = new QVBoxLayout(qbuttongroup->layout());
qvboxlayout->setAlignment( Qt::AlignTop );
qvboxlayout->setSpacing( 6 );
qvboxlayout->setMargin( 11 );
// Create a check box to be in the group box
m_qradiobuttonStartPrompt = new QRadioButton("start_prompt", qbuttongroup);
m_qradiobuttonStartPrompt->setText( i18n( "Start with dialog prompt (default)" ) );
qvboxlayout->addWidget(m_qradiobuttonStartPrompt);
// Create another check box to the group box
m_qradiobuttonStartFile = new QRadioButton("start_file", qbuttongroup);
m_qradiobuttonStartFile->setText( i18n( "Start with last file used" ) );
qvboxlayout->addWidget(m_qradiobuttonStartFile);
}
/** Called to create the Main List page shown in the dialog.
**/
void KSettingsDlg::setPageList()
{
// Create the page.
QVBox *qvboxMainFrame = addVBoxPage( i18n("Main List"), i18n("List settings"),
locate("appdata", "pics/setting_list.png"));
// Create the tab widget
QTabWidget *qtabwidget = new QTabWidget(qvboxMainFrame, "TabWidget2");
// Create the first page
QWidget *qwidgetPage = new QWidget(this);
// Create the layout for the page
QVBoxLayout *qvboxlayoutPage = new QVBoxLayout(qwidgetPage);
qvboxlayoutPage->setSpacing( 6 );
qvboxlayoutPage->setMargin( 11 );
// Create a horizontal layout to hold two widgets
QHBoxLayout *qhboxlayout = new QHBoxLayout;
qhboxlayout->setSpacing( 6 );
qhboxlayout->setMargin( 0 );
// Create the first widget
QLabel *qlabel = new QLabel(i18n("Number of lines in the register view:"),
qwidgetPage);
qhboxlayout->addWidget(qlabel);
// Create the second widget
m_klineeditRowCount = new KLineEdit(qwidgetPage);
QIntValidator *qintvalidator = new QIntValidator(1, 3, m_klineeditRowCount);
m_klineeditRowCount->setValidator(qintvalidator);
qhboxlayout->addWidget(m_klineeditRowCount);
// Add the horizontal layout
qvboxlayoutPage->addLayout(qhboxlayout);
// Ceate another widget
m_qcheckboxShowGrid = new QCheckBox(i18n("Show a grid in the register view"),
qwidgetPage);
qvboxlayoutPage->addWidget(m_qcheckboxShowGrid);
// Create a group to hold two radio buttons
QButtonGroup *qbuttongroup = new QButtonGroup(qwidgetPage, "ButtonGroup1");
qbuttongroup->setTitle(i18n("Row Colour options"));
qbuttongroup->setColumnLayout(0, Qt::Vertical );
qbuttongroup->layout()->setSpacing( 0 );
qbuttongroup->layout()->setMargin( 0 );
// Create a layout
QVBoxLayout *qvboxlayout = new QVBoxLayout(qbuttongroup->layout());
qvboxlayout->setAlignment( Qt::AlignTop );
qvboxlayout->setSpacing( 6 );
qvboxlayout->setMargin( 11 );
// Add the first radio button
m_qradiobuttonPerTransaction = new QRadioButton(qbuttongroup, "m_per_trans");
m_qradiobuttonPerTransaction->setText( i18n("Use one colour per transaction") );
qvboxlayout->addWidget(m_qradiobuttonPerTransaction);
// Add the second radio button
m_qradiobuttonOtherRow = new QRadioButton(qbuttongroup, "m_every_other");
m_qradiobuttonOtherRow->setText( i18n( "Change colour every other row" ));
qvboxlayout->addWidget(m_qradiobuttonOtherRow);
qvboxlayoutPage->addWidget(qbuttongroup);
// Add a vertical spacer to take up the remaining available space
QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum,
QSizePolicy::Expanding );
qvboxlayoutPage->addItem( spacer );
// Add the page to the tab
qtabwidget->insertTab(qwidgetPage, i18n("General"));
// Create a new tab for the colour options
QWidget *qwidgetColour = new QWidget(qtabwidget, "tab");
// Create a vertical layout
QVBoxLayout *qvboxlayoutColour = new QVBoxLayout(qwidgetColour);
qvboxlayoutColour->setSpacing( 6 );
qvboxlayoutColour->setMargin( 11 );
// Create a horizontal layout to include the label and button
QHBoxLayout *qhboxlayoutColour = new QHBoxLayout;
qhboxlayoutColour->setSpacing( 6 );
qhboxlayoutColour->setMargin( 0 );
// Add the label and button
QLabel *qlabelListColour = new QLabel(i18n( "List view colour :" ),
qwidgetColour);
qhboxlayoutColour->addWidget(qlabelListColour);
m_kcolorbuttonList = new KColorButton(qwidgetColour, "colour_list");
qhboxlayoutColour->addWidget(m_kcolorbuttonList);
// Add the horizontal layout
qvboxlayoutColour->addLayout(qhboxlayoutColour);
// Create another horizontal layout to include the label and button
QHBoxLayout *qhboxlayoutBGColour = new QHBoxLayout;
qhboxlayoutBGColour->setSpacing( 6 );
qhboxlayoutBGColour->setMargin( 0 );
// Add the label and button
QLabel *qlabelListBGColour = new QLabel(i18n( "List background colour :"),
qwidgetColour);
qhboxlayoutBGColour->addWidget(qlabelListBGColour);
m_kcolorbuttonBack = new KColorButton(qwidgetColour, "colour_back");
qhboxlayoutBGColour->addWidget(m_kcolorbuttonBack);
// Add the horizontal layout
qvboxlayoutColour->addLayout(qhboxlayoutBGColour);
// Add a vertical spacer to take up the remaining available space
QSpacerItem* qspaceritemColour = new QSpacerItem( 20, 20,
QSizePolicy::Minimum, QSizePolicy::Expanding );
qvboxlayoutColour->addItem( qspaceritemColour );
// Add the page to the tab widget
qtabwidget->insertTab(qwidgetColour, i18n( "Color"));
// Create another tab adding a font chooser widget
QVBox *qvboxInsideTab1 = new QVBox( this, "tab1" );
qvboxInsideTab1->setSpacing( 6 );
qvboxInsideTab1->setMargin( 11 );
m_tdefontchooserHeader = new TDEFontChooser(qvboxInsideTab1);
qtabwidget->insertTab(qvboxInsideTab1, i18n("Header Font"));
// Create another tab adding a font chooser widget
QVBox *qvboxInsideTab2 = new QVBox( this, "tab2" );
qvboxInsideTab2->setSpacing( 6 );
qvboxInsideTab2->setMargin( 11 );
m_tdefontchooserCell = new TDEFontChooser(qvboxInsideTab2);
qtabwidget->addTab(qvboxInsideTab2, i18n("Cell Font"));
}
/** Read all the settings in from the global TDEConfig object and set all the
* widgets appropriately.
**/
void KSettingsDlg::configRead()
{
TDEConfig *tdeconfig = TDEGlobal::config();
tdeconfig->setGroup("Settings Dialog");
QSize *qsizeDefaultSize = new QSize(470,470);
this->resize(tdeconfig->readSizeEntry("Geometry", qsizeDefaultSize));
tdeconfig->setGroup("General Options");
m_bTempStartPrompt = tdeconfig->readBoolEntry("StartDialog", true);
m_qradiobuttonStartPrompt->setChecked(m_bTempStartPrompt);
m_qradiobuttonStartFile->setChecked(!m_bTempStartPrompt);
tdeconfig->setGroup("List Options");
QFont qfontDefault = QFont("helvetica", 12);
QColor qcolorDefault = Qt::white;
QColor qcolorDefaultBG = Qt::gray;
m_qcolorTempList = tdeconfig->readColorEntry("listColor", &qcolorDefault);
m_kcolorbuttonList->setColor(m_qcolorTempList);
m_qcolorTempListBG = tdeconfig->readColorEntry("listBGColor",
&qcolorDefaultBG);
m_kcolorbuttonBack->setColor(m_qcolorTempListBG);
m_qfontTempHeader = tdeconfig->readFontEntry("listHeaderFont",
&qfontDefault);
m_tdefontchooserHeader->setFont(m_qfontTempHeader);
m_qfontTempCell = tdeconfig->readFontEntry("listCellFont", &qfontDefault);
m_tdefontchooserCell->setFont(m_qfontTempCell);
m_qstringTempRowCount = tdeconfig->readEntry("RowCount", "2");
m_klineeditRowCount->setText(m_qstringTempRowCount);
m_bTempShowGrid = tdeconfig->readBoolEntry("ShowGrid", true);
m_qcheckboxShowGrid->setChecked(m_bTempShowGrid);
m_bTempColourPerTransaction =
tdeconfig->readBoolEntry("ColourPerTransaction", true);
m_qradiobuttonPerTransaction->setChecked(m_bTempColourPerTransaction);
m_qradiobuttonOtherRow->setChecked(!m_bTempColourPerTransaction);
}
/** Write out all the settings to the global TDEConfig object.
**/
void KSettingsDlg::configWrite()
{
TDEConfig *tdeconfig = TDEGlobal::config();
tdeconfig->setGroup("Settings Dialog");
tdeconfig->writeEntry("Geometry", this->size() );
tdeconfig->setGroup("List Options");
tdeconfig->writeEntry("listColor", m_kcolorbuttonList->color());
tdeconfig->writeEntry("listBGColor", m_kcolorbuttonBack->color());
tdeconfig->writeEntry("listHeaderFont", m_tdefontchooserHeader->font());
tdeconfig->writeEntry("listCellFont", m_tdefontchooserCell->font());
tdeconfig->writeEntry("RowCount", m_klineeditRowCount->text());
tdeconfig->writeEntry("ShowGrid", m_qcheckboxShowGrid->isChecked());
tdeconfig->writeEntry("ColourPerTransaction",
m_qradiobuttonPerTransaction->isChecked());
tdeconfig->setGroup("General Options");
tdeconfig->writeEntry("StartDialog",
m_qradiobuttonStartPrompt->isChecked());
tdeconfig->sync();
}
/** Called on OK being pressed */
void KSettingsDlg::slotOk()
{
int nCount = m_klineeditRowCount->text().toInt();
if (nCount <= 0 || nCount >= 4) {
KMessageBox::information(this, i18n("The row count has to be between 1
and 3"));
m_klineeditRowCount->setFocus();
return;
}
configWrite();
this->accept();
}
/** Called on Apply being pressed */
void KSettingsDlg::slotApply()
{
int nCount = m_klineeditRowCount->text().toInt();
if (nCount <= 0 || nCount >= 4) {
KMessageBox::information(this, i18n("The row count has to be between 1
and 3"));
m_klineeditRowCount->setFocus();
return;
}
m_bDoneApply = true;
configWrite();
emit signalApply();
}
/** Called on Cancel being pressed.
* It writes out all the original settings read when it was created.
**/
void KSettingsDlg::slotCancel()
{
// make sure the config object is the same as we left it
TDEConfig *tdeconfig = TDEGlobal::config();
tdeconfig->setGroup("List Options");
tdeconfig->writeEntry("listColor", m_qcolorTempList);
tdeconfig->writeEntry("listBGColor", m_qcolorTempListBG);
tdeconfig->writeEntry("listHeaderFont", m_qfontTempHeader);
tdeconfig->writeEntry("listCellFont", m_qfontTempCell);
tdeconfig->writeEntry("RowCount", m_qstringTempRowCount);
tdeconfig->writeEntry("ShowGrid", m_bTempShowGrid);
tdeconfig->writeEntry("ColourPerTransaction", m_bTempColourPerTransaction);
tdeconfig->setGroup("General Options");
tdeconfig->writeEntry("StartDialog", m_bTempStartPrompt);
tdeconfig->sync();
if (m_bDoneApply)
accept();
else
reject();
}
/** Called when the user presses the User1 button. In our case that is the
* reset button.
*
* It just resets all the attributes to the values read on creation.
**/
void KSettingsDlg::slotUser1()
{
m_qradiobuttonStartPrompt->setChecked(m_bTempStartPrompt);
m_kcolorbuttonList->setColor(m_qcolorTempList);
m_kcolorbuttonBack->setColor(m_qcolorTempListBG);
m_tdefontchooserHeader->setFont(m_qfontTempHeader);
m_tdefontchooserCell->setFont(m_qfontTempCell);
m_klineeditRowCount->setText(m_qstringTempRowCount);
m_qcheckboxShowGrid->setChecked(m_bTempShowGrid);
m_qradiobuttonPerTransaction->setChecked(m_bTempColourPerTransaction);
m_qradiobuttonOtherRow->setChecked(!m_bTempColourPerTransaction);
}
</screen>
</section>
</appendix>
|