5
#include "preferences.h"
6
#include "mainwindow.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>
19
#include <qpushbutton.h>
22
#include <qvalidator.h>
23
#include <qlistview.h>
24
#include <qbuttongroup.h>
26
#include <qtoolbutton.h>
27
#include <qobjectlist.h>
30
* Constructs a PreferencesDialog which is a child of 'parent', with the
31
* name 'name' and widget flags set to 'f'
33
* The dialog will by default be modeless, unless you set 'modal' to
34
* TRUE to construct a modal dialog.
36
PreferencesDialog::PreferencesDialog(QWidget* parent, const char* name, bool modal, WFlags fl)
37
: PreferencesDialogGui( parent, name, modal, fl )
40
ListView_buttons->setColumnWidth(4,0);
42
// pointer to ClientWindow
43
parent_cw = setting->cw;
46
if (parent_cw->getPrefSize().width() > 0)
48
resize(parent_cw->getPrefSize());
49
move(parent_cw->getPrefPos());
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,
60
QString::number(h->port()),
62
(h->password().length() ? "***" : ""));
63
//cb_title->insertItem(h->title());
65
// set the user toolbar list
69
QObjectList *bl = parent_cw->UserToolbar->queryList( "QToolButton" ,NULL,true,false);
71
for ( b0 = (QToolButton*)bl->first(); b0 != 0; b0 = (QToolButton*)bl->next())
73
lvi = new QListViewItem(ListView_buttons,
74
"", //first column is for pixmap
77
QToolTip::textFor (b0),
80
if (p.load(b0->iconText()))
83
// init random-number generator
84
srand( (unsigned)time( NULL ) );
86
insertStandardHosts();
88
// set valid port range
89
val = new QIntValidator(0, 9999, this);
90
LineEdit_port->setValidator(val);
93
LineEdit_title->clear();
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));
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);
109
QPalette pal = colorBackgroundButton->palette();
110
pal.setColor(QColorGroup::Button, setting->colorBackground);
111
colorBackgroundButton->setPalette(pal);
114
styleListBox->setDisabled(true);
119
* Destroys the object and frees any allocated resources
121
PreferencesDialog::~PreferencesDialog()
123
// no need to delete child widgets, Qt does it all for us
127
/*****************************************************************
129
* Overwritten own implementations
131
*****************************************************************/
133
void PreferencesDialog::apply()
135
((MainWindow*)parentWidget())->preferencesSave(this);
136
((MainWindow*)parentWidget())->preferencesAccept();
139
void PreferencesDialog::startHelpMode()
141
QWhatsThis::enterWhatsThisMode();
144
void PreferencesDialog::selectFont(int selector)
146
// Open a font dialog to select a new font
152
f = QFontDialog::getFont(&ok, setting->fontStandard, this);
155
setting->fontStandard = f;
156
fontStandardButton->setText(setting->fontToString(f));
157
fontStandardButton->setFont(f);
162
f = QFontDialog::getFont(&ok, setting->fontMarks, this);
165
setting->fontMarks = f;
166
fontMarksButton->setText(setting->fontToString(f));
167
fontMarksButton->setFont(f);
172
f = QFontDialog::getFont(&ok, setting->fontComments, this);
175
setting->fontComments = f;
176
fontCommentsButton->setText(setting->fontToString(f));
177
fontCommentsButton->setFont(f);
182
f = QFontDialog::getFont(&ok, setting->fontLists, this);
185
setting->fontLists = f;
186
fontListsButton->setText(setting->fontToString(f));
187
fontListsButton->setFont(f);
192
f = QFontDialog::getFont(&ok, setting->fontClocks, this);
195
setting->fontClocks = f;
196
fontClocksButton->setText(setting->fontToString(f));
197
fontClocksButton->setFont(f);
202
f = QFontDialog::getFont(&ok, setting->fontConsole, this);
205
setting->fontConsole = f;
206
fontConsoleButton->setText(setting->fontToString(f));
207
fontConsoleButton->setFont(f);
216
void PreferencesDialog::selectColor()
218
// Open a font dialog to select a new font
219
QColor c = QColorDialog::getColor(setting->colorBackground, this);
220
if (c.isValid()) // Accepted
222
setting->colorBackground = c;
225
QPalette pal = colorBackgroundButton->palette();
226
pal.setColor(QColorGroup::Button, setting->colorBackground);
227
colorBackgroundButton->setPalette(pal);
231
void PreferencesDialog::slot_accept()
236
parent_cw->saveSettings();
241
void PreferencesDialog::slot_reject()
247
void PreferencesDialog::saveSizes()
249
// save size and position of window
250
parent_cw->savePrefFrame(pos(), size());
253
parent_cw->slot_cbconnect(QString());
256
void PreferencesDialog::insertStandardHosts()
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 --");
269
// button "add" clicked or "ok" pressed
270
void PreferencesDialog::slot_add()
272
// check if at least title and host inserted
273
if (!LineEdit_title->text().isEmpty() && !LineEdit_host->text().isEmpty())
275
// check if title already exists
278
unsigned int tmp = LineEdit_port->text().toUInt(&check);
282
qWarning("Failed to convert port to integer!");
285
for (Host *h = parent_cw->hostlist.first(); !found && h != 0; h = parent_cw->hostlist.next())
287
if (h->title() == LineEdit_title->text())
290
// if found, insert at current pos, and remove old item
291
parent_cw->hostlist.remove();
295
// insert host at it's sorted position
296
parent_cw->hostlist.inSort(new Host(LineEdit_title->text(),
297
LineEdit_host->text(),
299
LineEdit_login->text(),
300
LineEdit_pass->text()));
301
// create entry in listview
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() ? "***" : ""));
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() ? "***" : ""));
317
ListView_hosts->repaint();
318
// cb_title->insertItem(LineEdit_title->text(), 0);
320
// add to ClientWindow hostlist !!! does not seem to be used !
321
emit signal_addHost(LineEdit_title->text(),
322
LineEdit_host->text(),
324
LineEdit_login->text(),
325
LineEdit_pass->text());
329
// init insertion fields
330
slot_cbtitle(QString());
333
// button "delete" clicked
334
void PreferencesDialog::slot_delete()
338
for (h = parent_cw->hostlist.first(); !found && h != 0; h = parent_cw->hostlist.next())
340
if (h->title() == LineEdit_title->text())
343
// if found, delete current entry
344
parent_cw->hostlist.remove();
345
emit signal_delHost(LineEdit_title->text());
349
// set connection titles to listview
350
QListViewItemIterator lv(ListView_hosts);
351
for (QListViewItem *lvi; (lvi = lv.current());)
358
slot_cbtitle(QString());
360
for (h = parent_cw->hostlist.first(); h != 0; h = parent_cw->hostlist.next())
361
new QListViewItem(ListView_hosts,
364
QString::number(h->port()),
366
(h->password().length() ? "***" : ""));
368
insertStandardHosts();
371
void PreferencesDialog::slot_new()
373
slot_cbtitle(QString());
376
void PreferencesDialog::slot_clickedListView(QListViewItem *lvi, const QPoint&, int)
381
slot_cbtitle(lvi->text(0));
384
void PreferencesDialog::slot_cbtitle(const QString &txt)
386
LineEdit_pass->clear();
387
if (txt.isEmpty() || txt.isNull())
389
LineEdit_title->clear();
390
LineEdit_host->clear();
391
LineEdit_port->clear();
392
LineEdit_login->clear();
394
// fix coding: standard servers
395
else if (txt == QString("-- Aurora --"))
397
LineEdit_title->clear();
398
LineEdit_host->setText("aurora.go.art.pl");
399
LineEdit_port->setText("9696");
400
LineEdit_login->setText("guest");
402
else if (txt == QString("-- CTN --"))
404
LineEdit_title->clear();
405
LineEdit_host->setText("weiqi.online.sh.cn");
406
LineEdit_port->setText("8888");
407
LineEdit_login->setText("guest");
409
else if (txt == QString("-- CWS --"))
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));
416
else if (txt == QString("-- LGS --"))
418
LineEdit_title->clear();
419
LineEdit_host->setText("lgs.taiwango.net");
420
LineEdit_port->setText("9696");
421
LineEdit_login->setText("guest");
423
else if (txt == QString("-- WING --"))
425
LineEdit_title->clear();
426
LineEdit_host->setText("wing.gr.jp");
427
LineEdit_port->setText("1515");
428
LineEdit_login->setText("guest");
430
else if (txt == QString("-- IGS --"))
432
LineEdit_title->clear();
433
LineEdit_host->setText("igs.joyjoy.net");
434
LineEdit_port->setText("7777");
435
LineEdit_login->setText("guest");
437
else if (txt == QString("-- NNGS --"))
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));
444
else if (txt == QString("-- EGF --"))
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));
451
else if (!txt.isEmpty())
453
// fill host info of selected title
454
Host *h = parent_cw->hostlist.first();
458
if (h->title() == txt)
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());
468
h = parent_cw->hostlist.next();
473
void PreferencesDialog::slot_textChanged(const QString &title)
477
for (h = parent_cw->hostlist.first(); !found && h != 0; h = parent_cw->hostlist.next())
479
if (h->title() == title)
484
pb_add->setText(tr("Change"));
486
pb_add->setText(tr("Add"));
489
// play the sound if check box has been clicked
490
void PreferencesDialog::slot_clickedSoundCheckBox(int boxID)
492
qDebug("boxID = " + QString::number(boxID));
493
QButton *cb = soundButtonGroups->find(boxID);
494
qDebug("button text = " + cb->text());
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();
522
void PreferencesDialog::slot_getComputerPath()
524
QString fileName(QFileDialog::getOpenFileName(setting->readEntry("LAST_DIR"),
525
tr("All Files (*)"), this));
526
if (fileName.isEmpty())
529
LineEdit_computer->setText(fileName);
532
void PreferencesDialog::slot_getPixmapPath()
534
QString fileName(QFileDialog::getOpenFileName("",tr("Images (*.png *.jpg *.xpm *.ico)"), this));
535
if (fileName.isEmpty())
538
LineEdit_pixfile->setText(fileName);
543
pixmapLabel->setPixmap(p);
547
void PreferencesDialog::slot_text_buttonChanged(const QString &title)
549
if (ListView_buttons->findItem(title,1))
550
pb_add_2->setText(tr("Change"));
552
pb_add_2->setText(tr("Add"));
555
void PreferencesDialog::slot_new_button()
557
LineEdit_label->clear();
558
LineEdit_help->clear();
559
LineEdit_pixfile->clear();
560
LineEdit_command->clear();
561
pixmapLabel->setPixmap(NULL);
564
// button "add" clicked or "ok" pressed
565
void PreferencesDialog::slot_add_button()
568
QObjectList *bl = parent_cw->UserToolbar->queryList( "QToolButton" ,NULL,true,false);
570
// check if at least title and host inserted
571
if (!LineEdit_label->text().isEmpty() && !LineEdit_command->text().isEmpty())
573
// check if label already exists
575
for ( b0 = (QToolButton*)bl->first(); (b0 != 0) && !found; b0 = (QToolButton*)bl->next())
577
if (b0->textLabel() == LineEdit_label->text())
580
// if found, remove old item
581
parent_cw->userButtonGroup->remove(b0);
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);
596
if ( p.load(LineEdit_pixfile->text()))
598
parent_cw->userButtonGroup->insert(b,-1);
603
QListViewItem *buttonItem = new QListViewItem(ListView_buttons,
605
LineEdit_label->text(),
606
LineEdit_command->text(),
607
LineEdit_help->text(),
608
LineEdit_pixfile->text());
609
buttonItem->setPixmap(0,p);
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);
625
void PreferencesDialog::slot_clicked_buttonListView(QListViewItem *lvi, const QPoint&, int)
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));
636
p.load(LineEdit_pixfile->text());
638
pixmapLabel->setPixmap(p);
642
void PreferencesDialog::slot_delete_button()
644
QObjectList *bl = parent_cw->UserToolbar->queryList( "QToolButton" ,NULL,true,false);
648
// check if at least title and host inserted
649
if (!LineEdit_label->text().isEmpty() )//&& !LineEdit_command->text().isEmpty())
651
// check if label already exists
653
QListViewItem *lvi = ListView_buttons->findItem(LineEdit_label->text(),1);
655
// if found, remove old item and clear fields
658
for ( b0 = (QToolButton*)bl->first(); (b0 != 0) && !found; b0 = (QToolButton*)bl->next())
660
//QString sb= b0->text();
661
//QString sl = LineEdit_label->text();
662
if (b0->textLabel() == LineEdit_label->text())
665
// if found, remove old item
666
parent_cw->userButtonGroup->remove(b0);
671
ListView_buttons->takeItem(lvi);