~ubuntu-branches/ubuntu/raring/qgo/raring

« back to all changes in this revision

Viewing changes to src/preferences.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin A. Godisch
  • Date: 2005-01-01 23:07:10 UTC
  • Revision ID: james.westby@ubuntu.com-20050101230710-fhng6yidm47xlb2i
Tags: upstream-1.0.0-r2
ImportĀ upstreamĀ versionĀ 1.0.0-r2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* preferences.cpp
 
3
*/
 
4
 
 
5
#include "preferences.h"
 
6
#include "mainwindow.h"
 
7
#include "qgo.h"
 
8
#include "mainwin.h"
 
9
#include <qlistbox.h>
 
10
#include <qcheckbox.h>
 
11
#include <qwhatsthis.h>
 
12
#include <qcombobox.h>
 
13
#include <qlineedit.h>
 
14
#include <qfontdialog.h>
 
15
#include <qcolordialog.h>
 
16
#include <qcolor.h>
 
17
#include <qpalette.h>
 
18
#include <qlabel.h>
 
19
#include <qpushbutton.h>
 
20
#include <stdlib.h>
 
21
#include <time.h>
 
22
#include <qvalidator.h>
 
23
#include <qlistview.h>
 
24
#include <qbuttongroup.h>
 
25
#include <qtooltip.h> 
 
26
#include <qtoolbutton.h>
 
27
#include <qobjectlist.h>
 
28
 
 
29
/* 
 
30
*  Constructs a PreferencesDialog which is a child of 'parent', with the 
 
31
*  name 'name' and widget flags set to 'f' 
 
32
*
 
33
*  The dialog will by default be modeless, unless you set 'modal' to
 
34
*  TRUE to construct a modal dialog.
 
35
*/
 
36
PreferencesDialog::PreferencesDialog(QWidget* parent,  const char* name, bool modal, WFlags fl)
 
37
        : PreferencesDialogGui( parent, name, modal, fl )
 
38
{
 
39
 
 
40
  ListView_buttons->setColumnWidth(4,0);
 
41
 
 
42
  // pointer to ClientWindow
 
43
        parent_cw = setting->cw;
 
44
        CHECK_PTR(parent_cw);
 
45
 
 
46
        if (parent_cw->getPrefSize().width() > 0)
 
47
        {
 
48
                resize(parent_cw->getPrefSize());
 
49
                move(parent_cw->getPrefPos());
 
50
        }
 
51
 
 
52
        // set hostlist
 
53
        parent_cw->hostlist;
 
54
 
 
55
        // set connection titles to listview
 
56
        for (Host *h = parent_cw->hostlist.first(); h != 0; h = parent_cw->hostlist.next())
 
57
                new QListViewItem(ListView_hosts,
 
58
                        h->title(),
 
59
                        h->host(),
 
60
                        QString::number(h->port()),
 
61
                        h->loginName(),
 
62
                        (h->password().length() ? "***" : ""));
 
63
                //cb_title->insertItem(h->title());
 
64
 
 
65
   // set the user toolbar list 
 
66
   QPixmap p;
 
67
   QToolButton *b0 ;
 
68
   QListViewItem *lvi;
 
69
   QObjectList *bl = parent_cw->UserToolbar->queryList( "QToolButton" ,NULL,true,false);
 
70
    
 
71
         for ( b0 = (QToolButton*)bl->first(); b0 != 0; b0 = (QToolButton*)bl->next())
 
72
      {
 
73
      lvi = new  QListViewItem(ListView_buttons,
 
74
                          "", //first column is for pixmap
 
75
        b0->textLabel(),
 
76
        b0->caption(),
 
77
                          QToolTip::textFor (b0),
 
78
        b0->iconText() );
 
79
 
 
80
        if (p.load(b0->iconText()))
 
81
          lvi->setPixmap(0,p);
 
82
      }      
 
83
        // init random-number generator
 
84
        srand( (unsigned)time( NULL ) );
 
85
 
 
86
        insertStandardHosts();
 
87
 
 
88
        // set valid port range
 
89
        val = new QIntValidator(0, 9999, this);
 
90
        LineEdit_port->setValidator(val);
 
91
 
 
92
        // clear edit field
 
93
        LineEdit_title->clear();
 
94
 
 
95
        fontStandardButton->setText(setting->fontToString(setting->fontStandard));
 
96
        fontMarksButton->setText(setting->fontToString(setting->fontMarks));
 
97
        fontCommentsButton->setText(setting->fontToString(setting->fontComments));
 
98
        fontListsButton->setText(setting->fontToString(setting->fontLists));
 
99
        fontClocksButton->setText(setting->fontToString(setting->fontClocks));
 
100
  fontConsoleButton->setText(setting->fontToString(setting->fontConsole));
 
101
 
 
102
        fontStandardButton->setFont(setting->fontStandard);
 
103
        fontMarksButton->setFont(setting->fontMarks);
 
104
        fontCommentsButton->setFont(setting->fontComments);
 
105
        fontListsButton->setFont(setting->fontLists);
 
106
        fontClocksButton->setFont(setting->fontClocks);
 
107
  fontConsoleButton->setFont(setting->fontConsole);
 
108
  
 
109
        QPalette pal = colorBackgroundButton->palette();
 
110
        pal.setColor(QColorGroup::Button, setting->colorBackground);
 
111
        colorBackgroundButton->setPalette(pal);
 
112
 
 
113
#ifdef QGO_NOSTYLES
 
114
        styleListBox->setDisabled(true);
 
115
#endif
 
116
}
 
117
 
 
118
/*  
 
119
*  Destroys the object and frees any allocated resources
 
120
*/
 
121
PreferencesDialog::~PreferencesDialog()
 
122
{
 
123
        // no need to delete child widgets, Qt does it all for us
 
124
}
 
125
 
 
126
 
 
127
/*****************************************************************
 
128
*
 
129
*               Overwritten own implementations
 
130
*
 
131
*****************************************************************/
 
132
 
 
133
void PreferencesDialog::apply()
 
134
{
 
135
        ((MainWindow*)parentWidget())->preferencesSave(this);
 
136
        ((MainWindow*)parentWidget())->preferencesAccept();
 
137
}
 
138
 
 
139
void PreferencesDialog::startHelpMode()
 
140
{
 
141
        QWhatsThis::enterWhatsThisMode();
 
142
}
 
143
 
 
144
void PreferencesDialog::selectFont(int selector)
 
145
{
 
146
        // Open a font dialog to select a new font
 
147
        bool ok;
 
148
        QFont f;
 
149
        switch (selector)
 
150
        {
 
151
        case 0:
 
152
                f = QFontDialog::getFont(&ok, setting->fontStandard, this);
 
153
                if (ok)  // Accepted
 
154
                {
 
155
                        setting->fontStandard = f;
 
156
                        fontStandardButton->setText(setting->fontToString(f));
 
157
                        fontStandardButton->setFont(f);
 
158
                }
 
159
                break;
 
160
 
 
161
        case 1:
 
162
                f = QFontDialog::getFont(&ok, setting->fontMarks, this);
 
163
                if (ok)  // Accepted
 
164
                {
 
165
                        setting->fontMarks = f;
 
166
                        fontMarksButton->setText(setting->fontToString(f));
 
167
                        fontMarksButton->setFont(f);
 
168
                }
 
169
                break;
 
170
 
 
171
        case 2:
 
172
                f = QFontDialog::getFont(&ok, setting->fontComments, this);
 
173
                if (ok)  // Accepted
 
174
                {
 
175
                        setting->fontComments = f;
 
176
                        fontCommentsButton->setText(setting->fontToString(f));
 
177
                        fontCommentsButton->setFont(f);
 
178
                }
 
179
                break;
 
180
 
 
181
        case 3:
 
182
                f = QFontDialog::getFont(&ok, setting->fontLists, this);
 
183
                if (ok)  // Accepted
 
184
                {
 
185
                        setting->fontLists = f;
 
186
                        fontListsButton->setText(setting->fontToString(f));
 
187
                        fontListsButton->setFont(f);
 
188
                }
 
189
                break;
 
190
 
 
191
        case 4:
 
192
                f = QFontDialog::getFont(&ok, setting->fontClocks, this);
 
193
                if (ok)  // Accepted
 
194
                {
 
195
                        setting->fontClocks = f;
 
196
                        fontClocksButton->setText(setting->fontToString(f));
 
197
                        fontClocksButton->setFont(f);
 
198
                }
 
199
                break;
 
200
 
 
201
        case 5:
 
202
                f = QFontDialog::getFont(&ok, setting->fontConsole, this);
 
203
                if (ok)  // Accepted
 
204
                {
 
205
                        setting->fontConsole = f;
 
206
                        fontConsoleButton->setText(setting->fontToString(f));
 
207
                        fontConsoleButton->setFont(f);
 
208
                }
 
209
                break;
 
210
    
 
211
        default:
 
212
                break;
 
213
        }
 
214
}
 
215
 
 
216
void PreferencesDialog::selectColor()
 
217
{
 
218
        // Open a font dialog to select a new font
 
219
        QColor c = QColorDialog::getColor(setting->colorBackground, this);
 
220
        if (c.isValid())  // Accepted
 
221
        {
 
222
                setting->colorBackground = c;
 
223
 
 
224
                // set button color
 
225
                QPalette pal = colorBackgroundButton->palette();
 
226
                pal.setColor(QColorGroup::Button, setting->colorBackground);
 
227
                colorBackgroundButton->setPalette(pal);
 
228
        }
 
229
}
 
230
 
 
231
void PreferencesDialog::slot_accept()
 
232
{
 
233
        saveSizes();
 
234
 
 
235
        // save settings
 
236
        parent_cw->saveSettings();
 
237
 
 
238
        accept();
 
239
}
 
240
 
 
241
void PreferencesDialog::slot_reject()
 
242
{
 
243
        saveSizes();
 
244
        reject();
 
245
}
 
246
 
 
247
void PreferencesDialog::saveSizes()
 
248
{
 
249
        // save size and position of window
 
250
        parent_cw->savePrefFrame(pos(), size());
 
251
 
 
252
        // update hosts
 
253
        parent_cw->slot_cbconnect(QString());
 
254
}
 
255
 
 
256
void PreferencesDialog::insertStandardHosts()
 
257
{
 
258
        // standard hosts
 
259
        new QListViewItem(ListView_hosts, "-- Aurora --");
 
260
        new QListViewItem(ListView_hosts, "-- CTN --");
 
261
        new QListViewItem(ListView_hosts, "-- CWS --");
 
262
        new QListViewItem(ListView_hosts, "-- EGF --");
 
263
        new QListViewItem(ListView_hosts, "-- IGS --");
 
264
        new QListViewItem(ListView_hosts, "-- LGS --");
 
265
        new QListViewItem(ListView_hosts, "-- NNGS --");
 
266
        new QListViewItem(ListView_hosts, "-- WING --");
 
267
}
 
268
 
 
269
// button "add" clicked or "ok" pressed
 
270
void PreferencesDialog::slot_add()
 
271
{
 
272
        // check if at least title and host inserted
 
273
        if (!LineEdit_title->text().isEmpty() && !LineEdit_host->text().isEmpty())
 
274
        {
 
275
                // check if title already exists
 
276
                bool found = false;
 
277
                bool check;
 
278
                unsigned int tmp = LineEdit_port->text().toUInt(&check);
 
279
                if (!check)
 
280
                {
 
281
                        tmp = 0;
 
282
                        qWarning("Failed to convert port to integer!");
 
283
                }
 
284
 
 
285
                for (Host *h = parent_cw->hostlist.first(); !found && h != 0; h = parent_cw->hostlist.next())
 
286
                {
 
287
                        if (h->title() == LineEdit_title->text())
 
288
                        {
 
289
                                found = true;
 
290
                                // if found, insert at current pos, and remove old item
 
291
                                parent_cw->hostlist.remove();
 
292
                        }
 
293
                }
 
294
                
 
295
                // insert host at it's sorted position
 
296
                parent_cw->hostlist.inSort(new Host(LineEdit_title->text(),
 
297
                                LineEdit_host->text(),
 
298
                                tmp,
 
299
                                LineEdit_login->text(),
 
300
                                LineEdit_pass->text()));
 
301
                // create entry in listview
 
302
                if (!found)
 
303
                        new QListViewItem(ListView_hosts,
 
304
                                LineEdit_title->text(),
 
305
                                LineEdit_host->text(),
 
306
                                QString::number(tmp),
 
307
                                LineEdit_login->text(),
 
308
                                (LineEdit_pass->text().length() ? "***" : ""));
 
309
                else
 
310
                {
 
311
                        ListView_hosts->currentItem()->setText(0, LineEdit_title->text());
 
312
                        ListView_hosts->currentItem()->setText(1, LineEdit_host->text());
 
313
                        ListView_hosts->currentItem()->setText(2, QString::number(tmp));
 
314
                        ListView_hosts->currentItem()->setText(3, LineEdit_login->text());
 
315
                        ListView_hosts->currentItem()->setText(4, (LineEdit_pass->text().length() ? "***" : ""));
 
316
                }
 
317
                ListView_hosts->repaint();
 
318
//                      cb_title->insertItem(LineEdit_title->text(), 0);
 
319
 
 
320
                // add to ClientWindow hostlist       !!! does not seem to be used !
 
321
                emit signal_addHost(LineEdit_title->text(),
 
322
                                    LineEdit_host->text(),
 
323
                                    tmp,
 
324
                                    LineEdit_login->text(),
 
325
                                    LineEdit_pass->text());
 
326
 
 
327
        }
 
328
 
 
329
        // init insertion fields
 
330
        slot_cbtitle(QString());
 
331
}
 
332
 
 
333
// button "delete" clicked
 
334
void PreferencesDialog::slot_delete()
 
335
{
 
336
        bool found = false;
 
337
        Host *h;
 
338
        for (h = parent_cw->hostlist.first(); !found && h != 0; h = parent_cw->hostlist.next())
 
339
        {
 
340
                if (h->title() == LineEdit_title->text())
 
341
                {
 
342
                        found = true;
 
343
                        // if found, delete current entry
 
344
                        parent_cw->hostlist.remove();
 
345
                        emit signal_delHost(LineEdit_title->text());
 
346
                }
 
347
        }
 
348
 
 
349
        // set connection titles to listview
 
350
        QListViewItemIterator lv(ListView_hosts);
 
351
        for (QListViewItem *lvi; (lvi = lv.current());)
 
352
        {
 
353
                lv++;
 
354
                delete lvi;
 
355
        }
 
356
 
 
357
        // clear entries
 
358
        slot_cbtitle(QString());
 
359
 
 
360
        for (h = parent_cw->hostlist.first(); h != 0; h = parent_cw->hostlist.next())
 
361
                new QListViewItem(ListView_hosts,
 
362
                        h->title(),
 
363
                        h->host(),
 
364
                        QString::number(h->port()),
 
365
                        h->loginName(),
 
366
                        (h->password().length() ? "***" : ""));
 
367
 
 
368
        insertStandardHosts();
 
369
}
 
370
 
 
371
void PreferencesDialog::slot_new()
 
372
{
 
373
        slot_cbtitle(QString());
 
374
}
 
375
 
 
376
void PreferencesDialog::slot_clickedListView(QListViewItem *lvi, const QPoint&, int)
 
377
{
 
378
        if (!lvi)
 
379
                return;
 
380
 
 
381
        slot_cbtitle(lvi->text(0));
 
382
}
 
383
 
 
384
void PreferencesDialog::slot_cbtitle(const QString &txt)
 
385
{
 
386
        LineEdit_pass->clear();
 
387
        if (txt.isEmpty() || txt.isNull())
 
388
        {
 
389
                LineEdit_title->clear();
 
390
                LineEdit_host->clear();
 
391
                LineEdit_port->clear();
 
392
                LineEdit_login->clear();
 
393
        }
 
394
        // fix coding: standard servers
 
395
        else if (txt == QString("-- Aurora --"))
 
396
        {
 
397
                LineEdit_title->clear();
 
398
                LineEdit_host->setText("aurora.go.art.pl");
 
399
                LineEdit_port->setText("9696");
 
400
                LineEdit_login->setText("guest");
 
401
        }
 
402
        else if (txt == QString("-- CTN --"))
 
403
        {
 
404
                LineEdit_title->clear();
 
405
                LineEdit_host->setText("weiqi.online.sh.cn");
 
406
                LineEdit_port->setText("8888");
 
407
                LineEdit_login->setText("guest");
 
408
        }
 
409
        else if (txt == QString("-- CWS --"))
 
410
        {
 
411
                LineEdit_title->clear();
 
412
                LineEdit_host->setText("cws.weiqi.net");
 
413
                LineEdit_port->setText("9696");
 
414
                LineEdit_login->setText("qGo" + QString::number(rand() % 10000));
 
415
        }
 
416
        else if (txt == QString("-- LGS --"))
 
417
        {
 
418
                LineEdit_title->clear();
 
419
                LineEdit_host->setText("lgs.taiwango.net");
 
420
                LineEdit_port->setText("9696");
 
421
                LineEdit_login->setText("guest");
 
422
        }
 
423
        else if (txt == QString("-- WING --"))
 
424
        {
 
425
                LineEdit_title->clear();
 
426
                LineEdit_host->setText("wing.gr.jp");
 
427
                LineEdit_port->setText("1515");
 
428
                LineEdit_login->setText("guest");
 
429
        }
 
430
        else if (txt == QString("-- IGS --"))
 
431
        {
 
432
                LineEdit_title->clear();
 
433
                LineEdit_host->setText("igs.joyjoy.net");
 
434
                LineEdit_port->setText("7777");
 
435
                LineEdit_login->setText("guest");
 
436
        }
 
437
        else if (txt == QString("-- NNGS --"))
 
438
        {
 
439
                LineEdit_title->clear();
 
440
                LineEdit_host->setText("nngs.cosmic.org");
 
441
                LineEdit_port->setText("9696");
 
442
                LineEdit_login->setText("qGo" + QString::number(rand() % 10000));
 
443
        }
 
444
        else if (txt == QString("-- EGF --"))
 
445
        {
 
446
                LineEdit_title->clear();
 
447
                LineEdit_host->setText("server.european-go.org");
 
448
                LineEdit_port->setText("6969");
 
449
                LineEdit_login->setText("qGo" + QString::number(rand() % 10000));
 
450
        }
 
451
        else if (!txt.isEmpty())
 
452
        {
 
453
                // fill host info of selected title
 
454
                Host *h = parent_cw->hostlist.first();
 
455
                bool found = false;
 
456
                while (h != 0)
 
457
                {
 
458
                        if (h->title() == txt)
 
459
                        {
 
460
                                LineEdit_title->setText(h->title());
 
461
                                LineEdit_host->setText(h->host());
 
462
                                LineEdit_port->setText(QString::number(h->port()));
 
463
                                LineEdit_login->setText(h->loginName());
 
464
                                LineEdit_pass->setText(h->password());
 
465
                                found = true;
 
466
                        }
 
467
 
 
468
                        h = parent_cw->hostlist.next();
 
469
                }
 
470
        }
 
471
}
 
472
 
 
473
void PreferencesDialog::slot_textChanged(const QString &title)
 
474
{
 
475
        bool found = false;
 
476
        Host *h;
 
477
        for (h = parent_cw->hostlist.first(); !found && h != 0; h = parent_cw->hostlist.next())
 
478
        {
 
479
                if (h->title() == title)
 
480
                        found = true;
 
481
        }
 
482
 
 
483
        if (found)
 
484
                pb_add->setText(tr("Change"));
 
485
        else
 
486
                pb_add->setText(tr("Add"));
 
487
}
 
488
 
 
489
// play the sound if check box has been clicked
 
490
void PreferencesDialog::slot_clickedSoundCheckBox(int boxID)
 
491
{
 
492
        qDebug("boxID = " + QString::number(boxID));
 
493
        QButton *cb = soundButtonGroups->find(boxID);
 
494
        qDebug("button text = " + cb->text());
 
495
 
 
496
        if (cb->text() == tr("Stones"))
 
497
                setting->qgo->playClick();
 
498
        else if (cb->text() == tr("Pass"))
 
499
                setting->qgo->playPassSound();
 
500
        else if (cb->text() == tr("Autoplay"))
 
501
                setting->qgo->playAutoPlayClick();
 
502
        else if (cb->text() == tr("Time"))
 
503
                setting->qgo->playTimeSound();
 
504
        else if (cb->text() == tr("Talk"))
 
505
                setting->qgo->playTalkSound();
 
506
        else if (cb->text() == tr("Say"))
 
507
                setting->qgo->playSaySound();
 
508
        else if (cb->text() == tr("Match"))
 
509
                setting->qgo->playMatchSound();
 
510
        else if (cb->text() == tr("Enter"))
 
511
                setting->qgo->playEnterSound();
 
512
        else if (cb->text() == tr("Game end"))
 
513
                setting->qgo->playGameEndSound();
 
514
        else if (cb->text() == tr("Leave"))
 
515
                setting->qgo->playLeaveSound();
 
516
        else if (cb->text() == tr("Disconnect"))
 
517
                setting->qgo->playDisConnectSound();
 
518
        else if (cb->text() == tr("Connect"))
 
519
                setting->qgo->playConnectSound();
 
520
}
 
521
 
 
522
void PreferencesDialog::slot_getComputerPath()
 
523
{
 
524
        QString fileName(QFileDialog::getOpenFileName(setting->readEntry("LAST_DIR"),
 
525
                tr("All Files (*)"), this));
 
526
        if (fileName.isEmpty())
 
527
                return;
 
528
 
 
529
  LineEdit_computer->setText(fileName);
 
530
}
 
531
 
 
532
void PreferencesDialog::slot_getPixmapPath()
 
533
{
 
534
        QString fileName(QFileDialog::getOpenFileName("",tr("Images (*.png *.jpg *.xpm *.ico)"), this));
 
535
        if (fileName.isEmpty())
 
536
                return;
 
537
 
 
538
  LineEdit_pixfile->setText(fileName);
 
539
 
 
540
  QPixmap p;
 
541
  p.load(fileName);
 
542
  
 
543
  pixmapLabel->setPixmap(p);
 
544
}
 
545
 
 
546
 
 
547
void PreferencesDialog::slot_text_buttonChanged(const QString &title)
 
548
{
 
549
        if (ListView_buttons->findItem(title,1))
 
550
                pb_add_2->setText(tr("Change"));
 
551
        else
 
552
                pb_add_2->setText(tr("Add"));
 
553
}
 
554
 
 
555
void PreferencesDialog::slot_new_button()
 
556
{
 
557
                LineEdit_label->clear();
 
558
                LineEdit_help->clear();
 
559
                LineEdit_pixfile->clear();
 
560
                LineEdit_command->clear();
 
561
    pixmapLabel->setPixmap(NULL);
 
562
}
 
563
 
 
564
// button "add" clicked or "ok" pressed
 
565
void PreferencesDialog::slot_add_button()
 
566
{
 
567
  QToolButton *b,*b0;
 
568
  QObjectList *bl = parent_cw->UserToolbar->queryList( "QToolButton" ,NULL,true,false);
 
569
  bool found = false;
 
570
  // check if at least title and host inserted
 
571
        if (!LineEdit_label->text().isEmpty() && !LineEdit_command->text().isEmpty())
 
572
        {
 
573
    // check if label already exists
 
574
 
 
575
          for ( b0 = (QToolButton*)bl->first(); (b0 != 0) && !found; b0 = (QToolButton*)bl->next())
 
576
                {
 
577
      if (b0->textLabel() == LineEdit_label->text())
 
578
                        {
 
579
                                found = true;
 
580
                                // if found, remove old item
 
581
                                parent_cw->userButtonGroup->remove(b0);
 
582
        delete b0;
 
583
                        }  
 
584
                }
 
585
 
 
586
    QPixmap p;
 
587
 
 
588
    b=new QToolButton(parent_cw->UserToolbar) ;
 
589
    b->setTextLabel(LineEdit_label->text());   //label of the button
 
590
    b->setText(LineEdit_label->text());
 
591
    b->setCaption(LineEdit_command->text()); //dirty but handy
 
592
    b->setIconText(LineEdit_pixfile->text()); //dirty also but handy
 
593
    QToolTip::add(b,LineEdit_help->text());
 
594
    b->setMinimumWidth(25);
 
595
   
 
596
   if ( p.load(LineEdit_pixfile->text()))
 
597
      b->setPixmap(p);  
 
598
    parent_cw->userButtonGroup->insert(b,-1);
 
599
    
 
600
 
 
601
   if (!found)
 
602
    {
 
603
      QListViewItem *buttonItem = new QListViewItem(ListView_buttons,
 
604
                                "",
 
605
                                LineEdit_label->text(),
 
606
                                LineEdit_command->text(),
 
607
                                LineEdit_help->text(),
 
608
        LineEdit_pixfile->text());   
 
609
        buttonItem->setPixmap(0,p);
 
610
    }
 
611
   else
 
612
    {
 
613
                        ListView_buttons->currentItem()->setText(1, LineEdit_label->text());
 
614
                        ListView_buttons->currentItem()->setText(2, LineEdit_command->text());
 
615
                        ListView_buttons->currentItem()->setText(3, LineEdit_help->text());
 
616
                        ListView_buttons->currentItem()->setText(4, LineEdit_pixfile->text());
 
617
      ListView_buttons->currentItem()->setPixmap(0,p);
 
618
    }
 
619
 
 
620
  }
 
621
  slot_new_button();    
 
622
}
 
623
 
 
624
 
 
625
void PreferencesDialog::slot_clicked_buttonListView(QListViewItem *lvi, const QPoint&, int)
 
626
{
 
627
        if (!lvi)
 
628
                return;
 
629
  LineEdit_label->setText(lvi->text(1));
 
630
  LineEdit_command->setText(lvi->text(2));
 
631
  LineEdit_help->setText(lvi->text(3));
 
632
  LineEdit_pixfile->setText(lvi->text(4));
 
633
  
 
634
 
 
635
  QPixmap p;
 
636
  p.load(LineEdit_pixfile->text());
 
637
 
 
638
  pixmapLabel->setPixmap(p);
 
639
}
 
640
 
 
641
 
 
642
void PreferencesDialog::slot_delete_button()
 
643
{
 
644
        QObjectList *bl = parent_cw->UserToolbar->queryList( "QToolButton" ,NULL,true,false);
 
645
        bool found=false;
 
646
        QToolButton  *b0;
 
647
        
 
648
        // check if at least title and host inserted
 
649
        if (!LineEdit_label->text().isEmpty() )//&& !LineEdit_command->text().isEmpty())
 
650
        {
 
651
                // check if label already exists
 
652
                
 
653
                QListViewItem *lvi = ListView_buttons->findItem(LineEdit_label->text(),1);
 
654
                
 
655
                // if found, remove old item and clear fields       
 
656
                if(lvi)
 
657
                {
 
658
                        for ( b0 = (QToolButton*)bl->first(); (b0 != 0) && !found; b0 = (QToolButton*)bl->next())
 
659
                        {
 
660
                                //QString sb= b0->text();
 
661
                                //QString sl = LineEdit_label->text();
 
662
                                if (b0->textLabel() == LineEdit_label->text())
 
663
                                {
 
664
                                        found = true;
 
665
                                        // if found, remove old item
 
666
                                        parent_cw->userButtonGroup->remove(b0);
 
667
                                        delete b0;
 
668
                                }
 
669
                        }
 
670
                        
 
671
                        ListView_buttons->takeItem(lvi);
 
672
                        slot_new_button();
 
673
                }
 
674
        }
 
675
        
 
676
}