summaryrefslogtreecommitdiffstats
path: root/kbarcode/configdialog.cpp
blob: f632d917f1b57cf5ff4213938545990bf7b33b73 (plain)
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
/***************************************************************************
                          configdialog.cpp  -  description
                             -------------------
    begin                : Fre Apr 26 2002
    copyright            : (C) 2002 by Dominik Seichter
    email                : domseichter@web.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "configdialog.h"
#include "printersettings.h"
#include "sqltables.h"

// TQt includes
#include <tqbuttongroup.h>
#include <tqcheckbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpaintdevicemetrics.h>
#include <tqradiobutton.h>
#include <tqsqldatabase.h>
#include <tqtooltip.h>

// KDE includes
#include <kabc/addressee.h>
#include <tdeapplication.h>
#include <tdeconfig.h>
#include <kcolorbutton.h>
#include <kiconloader.h>
#include <kimageio.h>
#include <klineedit.h>
#include <klocale.h>
#include <kcombobox.h>
#include <knuminput.h>
#include <kmessagebox.h>
#include <kpushbutton.h>

const TQString cached = I18N_NOOP("There are currently %1 cached barcodes.");
using namespace KABC;

ConfigDialog::ConfigDialog( TQWidget* parent )
    : KDialogBase( IconList, i18n("Configure KBarcode"), KDialogBase::Ok|KDialogBase::Cancel,
      KDialogBase::Ok, parent, "", true, true )
{
    setupTab2(); // Printer
    setupTab1(); // SQL
    setupTab4(); // label editor
    setupTab3(); // import
    setupTab5(); // on new
}

ConfigDialog::~ConfigDialog()
{
}

void ConfigDialog::setupTab1( )
{
    TQFrame* box = addPage( i18n("SQL Settings"), "", BarIcon("connect_no") );
    TQVBoxLayout* layout = new TQVBoxLayout( box, 6, 6 );
    TQSpacerItem* spacer = new TQSpacerItem( 0, 0, TQSizePolicy::Expanding, TQSizePolicy::Expanding );

    sqlwidget = new SqlWidget( false, box, "sqlwidget" );

    layout->addWidget( sqlwidget );
    layout->addItem( spacer );
}

void ConfigDialog::setupTab2()
{
    labelprinterdata* lb = PrinterSettings::getInstance()->getData();
    
    TQFrame* box = addPage( i18n("Print Settings"), "", BarIcon("fileprint") );

    TQVBoxLayout* tabLayout = new TQVBoxLayout( box, 11, 6 );
    TQHBoxLayout* Layout0 = new TQHBoxLayout( 0, 6, 6 );
    TQHBoxLayout* Layout1 = new TQHBoxLayout( 0, 6, 6 );
    TQSpacerItem* spacer = new TQSpacerItem( 0, 0, TQSizePolicy::Expanding, TQSizePolicy::Expanding );

    printerQuality = new KComboBox( false, box );
    printerQuality->insertItem( i18n("Medium Resolution (300dpi)") );
    printerQuality->insertItem( i18n("High Resolution (600dpi)") );
    printerQuality->insertItem( i18n("Very High Resolution (1200dpi)") );

    switch( lb->quality ) {
        case PrinterSettings::Middle:
            printerQuality->setCurrentItem( 0 );
            break;
        case PrinterSettings::High:
            printerQuality->setCurrentItem( 1 );
            break;
        case PrinterSettings::VeryHigh:
            printerQuality->setCurrentItem( 2 );
            break;
        default:
            break;
    }

    pageFormat = new KComboBox( false, box );
    PrinterSettings::getInstance()->insertPageFormat( pageFormat );
    pageFormat->setCurrentItem( lb->format );
    
    Layout0->addWidget( new TQLabel( i18n("Printer Resolution:"), box ) );
    Layout0->addWidget( printerQuality );
    Layout1->addWidget( new TQLabel( i18n("Preview Page Format:"), box ) );
    Layout1->addWidget( pageFormat );
    tabLayout->addLayout( Layout0 );
    tabLayout->addLayout( Layout1 );
    tabLayout->addItem( spacer );
}

void ConfigDialog::setupTab3()
{
    labelprinterdata* lb = PrinterSettings::getInstance()->getData();

    TQFrame* box = addPage( i18n("Import"), "", BarIcon("fileimport") );
    TQGridLayout* grid = new TQGridLayout( box, 2, 2 );

    TQLabel* label = new TQLabel( box );
    label->setText( i18n("Comment:") );
    grid->addWidget( label, 0, 0 );

    comment = new KLineEdit( lb->comment, box );
    grid->addWidget( comment, 0, 1 );

    label = new TQLabel( box );
    label->setText( i18n( "Separator:" ) );
    grid->addWidget( label, 1, 0 );

    separator = new KLineEdit( lb->separator, box );
    grid->addWidget( separator, 1, 1 );

    label = new TQLabel( box );
    label->setText( i18n("Quote Character:") );
    grid->addWidget( label, 2, 0 );

    quote  = new KLineEdit( lb->quote, box );
    grid->addWidget( quote, 2, 1 );

    checkUseCustomNo = new TQCheckBox( i18n("&Use customer article no. for import"), box );
    checkUseCustomNo->setChecked( lb->useCustomNo );
    
    grid->addMultiCellWidget( checkUseCustomNo, 3, 3, 0, 2 );
    
    TQHBoxLayout* Layout1 = new TQHBoxLayout( 0, 6, 6 );
    Layout1->addWidget( new TQLabel( i18n("File Format:"), box ) );

    combo1 = new KComboBox( box );
    combo1->insertItem( i18n("Quantity") );
    combo1->insertItem( i18n("Article Number") );
    combo1->insertItem( i18n("Group") );
    Layout1->addWidget( combo1 );

    combo2 = new KComboBox( box );
    combo2->insertItem( i18n("Quantity") );
    combo2->insertItem( i18n("Article Number") );
    combo2->insertItem( i18n("Group") );
    Layout1->addWidget( combo2 );

    combo3 = new KComboBox( box );
    combo3->insertItem( i18n("Quantity") );
    combo3->insertItem( i18n("Article Number") );
    combo3->insertItem( i18n("Group") );
    Layout1->addWidget( combo3 );

    grid->addMultiCellLayout( Layout1, 4, 4, 0, 2 );
    TQSpacerItem* spacer = new TQSpacerItem( 0, 0, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
    grid->addItem( spacer, 5, 0 );    

    TDEConfig* config = kapp->config();
    config->setGroup("FileFormat");
    combo1->setCurrentItem( config->readNumEntry("Data0", 0 ) );
    combo2->setCurrentItem( config->readNumEntry("Data1", 1 ) );
    combo3->setCurrentItem( config->readNumEntry("Data2", 2 ) );
}

void ConfigDialog::setupTab4()
{
    TQFrame* box = addPage( i18n("Label Editor"), "", BarIcon("kbarcode") );
    TQGridLayout* tabLayout = new TQGridLayout( box, 11, 6 );

    checkNewDlg = new TQCheckBox( box );
    checkNewDlg->setText( i18n("&Create a new label on startup") );

    date = new KLineEdit( box );
    labelDate = new TQLabel( box );
    
    connect( date, TQT_SIGNAL( textChanged( const TQString & ) ), this, TQT_SLOT( updateDatePreview() ) );

    spinGrid = new KIntNumInput( 0, box );
    spinGrid->setLabel( i18n("Grid:" ), AlignLeft | AlignVCenter );
    spinGrid->setRange(2, 100, 1, false );

    colorGrid = new KColorButton( box );

    tabLayout->addWidget( checkNewDlg, 0, 0 );
    tabLayout->addMultiCellWidget( spinGrid, 1, 1, 0, 2 );
    tabLayout->addWidget( new TQLabel( i18n("Grid Color:"), box ), 2, 0 );
    tabLayout->addWidget( colorGrid, 2, 1 );
    tabLayout->addWidget( new TQLabel( i18n("Date Format:"), box ), 3, 0 );
    tabLayout->addWidget( date, 3, 1 );
    tabLayout->addWidget( labelDate, 3, 2 );
}

void ConfigDialog::setupTab5()
{
    labelprinterdata* lb = PrinterSettings::getInstance()->getData();
    TQFrame* box = addPage( i18n("On New"), "", BarIcon("filenew") );

    TQVBoxLayout* tabLayout = new TQVBoxLayout( box, 11, 6 );

    TQButtonGroup* bg = new TQButtonGroup( i18n("On New Article"), box );
    bg->setColumnLayout(0, Qt::Vertical );
    bg->layout()->setSpacing( 6 );
    bg->layout()->setMargin( 11 );
    TQGridLayout* bgLayout = new TQGridLayout( bg->layout() );

    TQStringList alist, glist;
    alist.append( i18n("No Line Break") );
    alist.append( i18n("Line Break") );
    alist.append( i18n("Insert Label X") );
    alist.append( i18n("New Page") );
    alist.append( i18n("Article No.") );

    glist.append( i18n("No Line Break") );
    glist.append( i18n("Line Break") );
    glist.append( i18n("Insert Label X") );
    glist.append( i18n("New Page") );
    glist.append( i18n("Group Name") );

    onNewArticle1 = new KComboBox( false, bg );
    onNewArticle2 = new KComboBox( false, bg );
    onNewArticle3 = new KComboBox( false, bg );
    onNewArticle4 = new KComboBox( false, bg );

    onNewArticle1->insertStringList( alist );
    onNewArticle2->insertStringList( alist );
    onNewArticle3->insertStringList( alist );
    onNewArticle4->insertStringList( alist );

    bgLayout->setColStretch( 1, 3 );

    bgLayout->addWidget( new TQLabel( "1.", bg ), 0, 0 );
    bgLayout->addWidget( new TQLabel( "2.", bg ), 1, 0 );
    bgLayout->addWidget( new TQLabel( "3.", bg ), 2, 0 );
    bgLayout->addWidget( new TQLabel( "4.", bg ), 3, 0 );

    bgLayout->addWidget( onNewArticle1, 0, 1 );
    bgLayout->addWidget( onNewArticle2, 1, 1 );
    bgLayout->addWidget( onNewArticle3, 2, 1 );
    bgLayout->addWidget( onNewArticle4, 3, 1 );

    TQButtonGroup* bg2 = new TQButtonGroup( i18n("On New Group"), box );
    bg2->setColumnLayout(0, Qt::Vertical );
    bg2->layout()->setSpacing( 6 );
    bg2->layout()->setMargin( 11 );
    TQGridLayout* bg2Layout = new TQGridLayout( bg2->layout() );

    onNewGroup1 = new KComboBox( false, bg2 );
    onNewGroup2 = new KComboBox( false, bg2 );
    onNewGroup3 = new KComboBox( false, bg2 );
    onNewGroup4 = new KComboBox( false, bg2 );

    onNewGroup1->insertStringList( glist );
    onNewGroup2->insertStringList( glist );
    onNewGroup3->insertStringList( glist );
    onNewGroup4->insertStringList( glist );

    bg2Layout->setColStretch( 1, 3 );

    bg2Layout->addWidget( new TQLabel( "1.", bg2 ), 0, 0 );
    bg2Layout->addWidget( new TQLabel( "2.", bg2 ), 1, 0 );
    bg2Layout->addWidget( new TQLabel( "3.", bg2 ), 2, 0 );
    bg2Layout->addWidget( new TQLabel( "4.", bg2 ), 3, 0 );

    bg2Layout->addWidget( onNewGroup1, 0, 1 );
    bg2Layout->addWidget( onNewGroup2, 1, 1 );
    bg2Layout->addWidget( onNewGroup3, 2, 1 );
    bg2Layout->addWidget( onNewGroup4, 3, 1 );

    tabLayout->addWidget( bg );
    tabLayout->addWidget( bg2 );

    onNewArticle1->setCurrentItem( lb->articleEvent1 );
    onNewArticle2->setCurrentItem( lb->articleEvent2 );
    onNewArticle3->setCurrentItem( lb->articleEvent3 );
    onNewArticle4->setCurrentItem( lb->articleEvent4 );

    onNewGroup1->setCurrentItem( lb->groupEvent1 );
    onNewGroup2->setCurrentItem( lb->groupEvent2 );
    onNewGroup3->setCurrentItem( lb->groupEvent3 );
    onNewGroup4->setCurrentItem( lb->groupEvent4 );
}

void ConfigDialog::accept()
{
    TDEConfig* config = kapp->config();
    config->setGroup("FileFormat");
    config->writeEntry("Data0", combo1->currentItem() );
    config->writeEntry("Data1", combo2->currentItem() );
    config->writeEntry("Data2", combo3->currentItem() );

    sqlwidget->save();

    labelprinterdata* lpdata = PrinterSettings::getInstance()->getData();
    lpdata->comment = comment->text();
    lpdata->separator = separator->text();
    lpdata->quote = quote->text();
    lpdata->format = pageFormat->currentItem();

    lpdata->articleEvent1 = onNewArticle1->currentItem();
    lpdata->articleEvent2 = onNewArticle2->currentItem();
    lpdata->articleEvent3 = onNewArticle3->currentItem();
    lpdata->articleEvent4 = onNewArticle4->currentItem();

    lpdata->groupEvent1 = onNewGroup1->currentItem();
    lpdata->groupEvent2 = onNewGroup2->currentItem();
    lpdata->groupEvent3 = onNewGroup3->currentItem();
    lpdata->groupEvent4 = onNewGroup4->currentItem();
    lpdata->useCustomNo = checkUseCustomNo->isChecked();

    switch( printerQuality->currentItem() ) {
        case 0:
            lpdata->quality = PrinterSettings::Middle;
            break;
        case 1:
            lpdata->quality = PrinterSettings::High;
            break;
        case 2:
            lpdata->quality = PrinterSettings::VeryHigh;
            break;
        default:
            break;
    }

    TQDialog::accept();
}

void ConfigDialog::updateDatePreview()
{
    labelDate->setText( i18n("Preview: ") + TQDateTime::currentDateTime().toString( date->text() ) );
}

#include "configdialog.moc"