~ubuntu-branches/ubuntu/maverick/qgo/maverick

« back to all changes in this revision

Viewing changes to src/mainwindow.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
* mainwindow.cpp - qGo's main window
 
3
*/
 
4
 
 
5
#include "misc.h"
 
6
#include "qgo.h"
 
7
#include "mainwindow.h"
 
8
#include "mainwidget.h"
 
9
#include "board.h"
 
10
#include "tip.h"
 
11
#include "setting.h"
 
12
#include "icons.h"
 
13
#include "newgame_gui.h"
 
14
#include "newlocalgame_gui.h"
 
15
#include "gameinfo_gui.h"
 
16
#include "interfacehandler.h"
 
17
#include "komispinbox.h"
 
18
#include "nthmove_gui.h"
 
19
#include "normaltools_gui.h"
 
20
#include "parserdefs.h"
 
21
#include "config.h"
 
22
#include "move.h"
 
23
#include "qnewgamedlg.h"
 
24
#include "qgo_interface.h"
 
25
#include <qaccel.h>
 
26
#include <qmenubar.h>
 
27
#include <qtoolbar.h>
 
28
#include <qstatusbar.h>
 
29
#include <qmessagebox.h>
 
30
#include <qapplication.h>
 
31
#include <qlistbox.h>
 
32
#include <qwhatsthis.h>
 
33
#include <qplatinumstyle.h>
 
34
#include <qmotifstyle.h>
 
35
#include <qmotifplusstyle.h>
 
36
#include <qcdestyle.h>
 
37
#include <qsgistyle.h>
 
38
#include <qfiledialog.h>
 
39
#include <qcheckbox.h>
 
40
#include <qsplitter.h>
 
41
//#include <qmultilineedit.h>
 
42
#include <qtextedit.h>
 
43
#include <qpushbutton.h>
 
44
#include <qradiobutton.h>
 
45
#include <qcombobox.h>
 
46
#include <qslider.h>
 
47
#include <qlineedit.h>
 
48
#include <qtimer.h>
 
49
#include <qpalette.h>
 
50
#include <qtabwidget.h>
 
51
 
 
52
#ifdef USE_XPM
 
53
#include ICON_PREFS
 
54
#include ICON_GAMEINFO
 
55
#include ICON_EXIT
 
56
#include ICON_FILENEWBOARD
 
57
#include ICON_FILENEW
 
58
#include ICON_FILEOPEN
 
59
#include ICON_FILESAVE
 
60
#include ICON_FILESAVEAS
 
61
#include ICON_TRANSFORM
 
62
#include ICON_CHARSET
 
63
#include ICON_RIGHTARROW
 
64
#include ICON_LEFTARROW
 
65
#include ICON_RIGHTCOMMENT     //added eb 2
 
66
#include ICON_LEFTCOMMENT       // end add eb 2
 
67
#include ICON_TWO_RIGHTARROW
 
68
#include ICON_TWO_LEFTARROW
 
69
#include ICON_NEXT_VAR
 
70
#include ICON_PREV_VAR
 
71
#include ICON_MAIN_BRANCH
 
72
#include ICON_START_VAR
 
73
#include ICON_NEXT_BRANCH
 
74
#include ICON_AUTOPLAY
 
75
#include ICON_CUT
 
76
#include ICON_PASTE
 
77
#include ICON_DELETE
 
78
#include ICON_INCREASE_SIZE
 
79
#include ICON_DECREASE_SIZE
 
80
#include ICON_FULLSCREEN
 
81
#include ICON_WHATSTHIS
 
82
#include ICON_MANUAL
 
83
#include ICON_NAV_INTERSECTION
 
84
#include ICON_COMPUTER_PLAY
 
85
#endif
 
86
 
 
87
 
 
88
 
 
89
MainWindow::MainWindow(QWidget* parent, const char* name, WFlags f)
 
90
: QMainWindow(parent, name, f), Misc<QString>()
 
91
{
 
92
 
 
93
  // this is very dirty : we do this because there seem to be no clean way to backtrack to the ClientWindow, which has stored the style :-(  
 
94
  style = setting->readEntry("DEFAULT_STYLE") ;
 
95
  
 
96
  setProperty("icon", setting->image0);
 
97
        parent_ = 0;
 
98
 
 
99
  
 
100
  
 
101
        isFullScreen = 0;
 
102
        setFocusPolicy(QWidget::StrongFocus);
 
103
        
 
104
        setIcon(setting->image0);
 
105
 
 
106
        initActions();
 
107
        initMenuBar();
 
108
        initToolBar();
 
109
        initStatusBar();
 
110
 
 
111
        if (!setting->readBoolEntry("FILEBAR"))
 
112
                viewFileBar->setOn(false);
 
113
        if (!setting->readBoolEntry("TOOLBAR"))
 
114
                viewToolBar->setOn(false);
 
115
        if (!setting->readBoolEntry("EDITBAR"))
 
116
                viewEditBar->setOn(false);
 
117
 
 
118
        interfaceHandler = 0;
 
119
 
 
120
        // VIEW_COMMENT: 0 = see BOARDVERTCOMMENT, 1 = hor, 2 = ver
 
121
        // BOARDVERCOMMENT: 0 = hor, 1 = ver, 2 = not shown
 
122
        if (setting->readIntEntry("VIEW_COMMENT") == 2 ||
 
123
                setting->readIntEntry("VIEW_COMMENT") == 0 && setting->readIntEntry("BOARDVERTCOMMENT_0"))
 
124
        {
 
125
                // show vertical comment
 
126
                splitter = new QSplitter(Horizontal, this);
 
127
                mainWidget = new MainWidget(splitter, "MainWidget");
 
128
                splitter_comment = new QSplitter(Vertical, splitter);
 
129
        }
 
130
        else
 
131
        {
 
132
                splitter = new QSplitter(Vertical, this);
 
133
                mainWidget = new MainWidget(splitter, "MainWidget");
 
134
                splitter_comment = new QSplitter(Horizontal, splitter);
 
135
        }
 
136
        splitter->setOpaqueResize(false);
 
137
 
 
138
//      mainWidget = new MainWidget(splitter, "MainWidget");
 
139
        
 
140
        mainWidgetGuiLayout = new QGridLayout(mainWidget, 1, 1, 0, 0);
 
141
        if (setting->readBoolEntry("SIDEBAR_LEFT"))
 
142
        {
 
143
                mainWidgetGuiLayout->addWidget(mainWidget->toolsFrame, 0, 0);
 
144
                mainWidgetGuiLayout->addWidget(mainWidget->boardFrame, 0, 1);
 
145
 
 
146
        }
 
147
        else
 
148
        {
 
149
                mainWidgetGuiLayout->addWidget(mainWidget->toolsFrame, 0, 1);
 
150
                mainWidgetGuiLayout->addWidget(mainWidget->boardFrame, 0, 0);
 
151
        }
 
152
        
 
153
        board = mainWidget->board;
 
154
        CHECK_PTR(board);
 
155
        // Connect the mouseMove event of the board with the status bar coords widget
 
156
        connect(board, SIGNAL(coordsChanged(int, int, int)), statusTip, SLOT(slotStatusTipCoords(int, int, int)));
 
157
        
 
158
        commentEdit = new QTextEdit(splitter_comment, "comments");   //eb16
 
159
        ListView_observers = new QListView(splitter_comment, "observers");
 
160
        splitter->setResizeMode(mainWidget, QSplitter::KeepSize);
 
161
        splitter_comment->setResizeMode(ListView_observers, QSplitter::KeepSize);
 
162
        ListView_observers->addColumn(tr("Observers") + "     ");
 
163
        ListView_observers->setProperty("focusPolicy", (int)QListView::NoFocus );
 
164
        ListView_observers->setProperty("resizePolicy", (int)QListView::AutoOneFit );
 
165
        ListView_observers->addColumn(tr("Rk"));
 
166
        ListView_observers->setProperty("focusPolicy", (int)QListView::NoFocus );
 
167
        ListView_observers->setProperty("resizePolicy", (int)QListView::AutoOneFit );
 
168
        ListView_observers->setSorting(1);
 
169
        // disable sorting; else sort rank would sort by rank string (col 2) instead of rank key (col 3, invisible)
 
170
        ListView_observers->setSorting(-1);
 
171
 
 
172
        commentEdit->setWordWrap(QTextEdit::WidgetWidth);
 
173
        commentEdit2 = mainWidget->commentEdit2;
 
174
        //    connect(commentEdit2, SIGNAL(returnPressed()), board, SLOT(modifiedComment()));
 
175
        connect(commentEdit, SIGNAL(textChanged()), board, SLOT(updateComment()));
 
176
        connect(commentEdit2, SIGNAL(returnPressed()), board, SLOT(updateComment2()));
 
177
        
 
178
        // Connect Ctrl-E with MainWidget 'Edit' button. We need this to control the button
 
179
        // even when the sidebar is hidden.
 
180
//      connect(toggleEdit, SIGNAL(activated()), mainWidget->modeButton, SLOT(animateClick()));
 
181
        
 
182
        setCentralWidget(splitter);
 
183
 
 
184
        interfaceHandler = mainWidget->interfaceHandler;
 
185
        CHECK_PTR(interfaceHandler);
 
186
        interfaceHandler->fileImportASCII = fileImportASCII;
 
187
        interfaceHandler->fileImportASCIIClipB = fileImportASCIIClipB;
 
188
        interfaceHandler->fileImportSgfClipB = fileImportSgfClipB;
 
189
        interfaceHandler->navForward = navForward;
 
190
        interfaceHandler->navBackward = navBackward;
 
191
        interfaceHandler->navFirst = navFirst;
 
192
        interfaceHandler->navLast = navLast;
 
193
        interfaceHandler->navNextVar = navNextVar;
 
194
        interfaceHandler->navPrevVar = navPrevVar;
 
195
        interfaceHandler->navStartVar = navStartVar;
 
196
        interfaceHandler->navMainBranch = navMainBranch;
 
197
        interfaceHandler->navNextBranch = navNextBranch;
 
198
        interfaceHandler->navPrevComment = navPrevComment;
 
199
        interfaceHandler->navNextComment = navNextComment;
 
200
        interfaceHandler->navIntersection = navIntersection;  //SL added eb 11
 
201
        interfaceHandler->editCut = editCut;
 
202
        interfaceHandler->editPaste = editPaste;
 
203
        interfaceHandler->editPasteBrother = editPasteBrother;
 
204
        interfaceHandler->editDelete = editDelete;
 
205
        interfaceHandler->navEmptyBranch = navEmptyBranch;
 
206
        interfaceHandler->navCloneNode = navCloneNode;
 
207
        interfaceHandler->navNthMove = navNthMove;
 
208
        interfaceHandler->navAutoplay = navAutoplay;
 
209
        interfaceHandler->navSwapVariations = navSwapVariations;
 
210
        interfaceHandler->commentEdit = commentEdit;
 
211
        interfaceHandler->commentEdit2 = commentEdit2;
 
212
        interfaceHandler->statusMode = statusMode;
 
213
        interfaceHandler->statusTurn = statusTurn;
 
214
        interfaceHandler->statusMark = statusMark;
 
215
        interfaceHandler->statusNav = statusNav;
 
216
        interfaceHandler->slider = mainWidget->slider;
 
217
        interfaceHandler->mainWidget = mainWidget;
 
218
        
 
219
        // Create a timer instance
 
220
        // timerInterval = 2;  // 1000 msec
 
221
        timer = new QTimer(this);
 
222
        connect(timer, SIGNAL(timeout()), this, SLOT(slotTimerForward()));
 
223
        timerIntervals[0] = (float) 0.1;
 
224
        timerIntervals[1] = 0.5;
 
225
        timerIntervals[2] = 1.0;
 
226
        timerIntervals[3] = 2.0;
 
227
        timerIntervals[4] = 3.0;
 
228
        timerIntervals[5] = 5.0;
 
229
        
 
230
        updateBoard();
 
231
 
 
232
        // restore board window
 
233
        reStoreWindowSize("0", false);
 
234
 
 
235
        updateFont();
 
236
}
 
237
 
 
238
MainWindow::~MainWindow()
 
239
{
 
240
        delete timer;
 
241
        delete commentEdit;
 
242
        delete mainWidget;
 
243
        delete splitter;
 
244
 
 
245
        // status bar
 
246
        delete statusMark;
 
247
        delete statusMode;
 
248
        delete statusNav;
 
249
        delete statusTurn;
 
250
        delete statusTip;
 
251
 
 
252
        // tool bar;
 
253
        delete editBar;
 
254
        delete toolBar;
 
255
        delete fileBar;
 
256
 
 
257
        // menu bar
 
258
        delete helpMenu;
 
259
        delete viewMenu;
 
260
        delete settingsMenu;
 
261
        delete navMenu;
 
262
        delete editMenu;
 
263
        delete fileMenu;
 
264
        delete importExportMenu;
 
265
 
 
266
        // Actions
 
267
        delete escapeFocus;
 
268
        delete toggleEdit;
 
269
        delete toggleMarks;
 
270
        delete fileNewBoard;
 
271
        delete fileNew;
 
272
        delete fileOpen;
 
273
        delete fileSave;
 
274
        delete fileSaveAs;
 
275
        delete fileClose;
 
276
        delete fileImportASCII;
 
277
        delete fileImportASCIIClipB;
 
278
        delete fileExportASCII;
 
279
        delete fileImportSgfClipB;
 
280
        delete fileExportSgfClipB;
 
281
        delete fileExportPic;
 
282
        delete fileExportPicClipB;
 
283
        delete fileQuit;
 
284
        delete editCut;
 
285
        delete editPaste;
 
286
        delete editPasteBrother;
 
287
        delete editDelete;
 
288
        delete editNumberMoves;
 
289
        delete editMarkBrothers;
 
290
        delete editMarkSons;
 
291
        delete navBackward;
 
292
        delete navForward;
 
293
        delete navFirst;
 
294
        delete navLast;
 
295
        delete navPrevVar;
 
296
        delete navNextVar;
 
297
        delete navMainBranch;
 
298
        delete navStartVar;
 
299
        delete navNextBranch;
 
300
        delete navPrevComment;
 
301
        delete navNextComment;
 
302
        delete navIntersection; //SL added eb 11
 
303
        delete navNthMove;
 
304
        delete navAutoplay;
 
305
        delete navEmptyBranch;
 
306
        delete navCloneNode;
 
307
        delete navSwapVariations;
 
308
        delete setPreferences;
 
309
        delete setGameInfo;
 
310
        delete viewFileBar;
 
311
        delete viewToolBar;
 
312
        delete viewEditBar;
 
313
        delete viewMenuBar;
 
314
        delete viewStatusBar;
 
315
        delete viewCoords;
 
316
        delete viewSidebar;
 
317
        delete viewComment;
 
318
        delete viewVertComment;
 
319
        delete viewPinComment;
 
320
        delete viewIncreaseSize;
 
321
        delete viewDecreaseSize;
 
322
        delete viewSaveSize;
 
323
        delete viewFullscreen;
 
324
        delete helpManual;
 
325
        delete helpSoundInfo;
 
326
        delete helpAboutApp;
 
327
        delete helpAboutQt;
 
328
}
 
329
 
 
330
void MainWindow::initActions()
 
331
{
 
332
        // Load the pixmaps
 
333
        QPixmap exitIcon, fileNewboardIcon, fileNewIcon, fileOpenIcon, fileSaveIcon, fileSaveAsIcon,
 
334
                transformIcon, charIcon, cutIcon, pasteIcon, deleteIcon,
 
335
                nextCommentIcon, previousCommentIcon, navIntersectionIcon,
 
336
                rightArrowIcon, leftArrowIcon,two_rightArrowIcon, two_leftArrowIcon,
 
337
                prevVarIcon, nextVarIcon, startVarIcon, mainBranchIcon, nextBranchIcon, autoplayIcon,
 
338
                prefsIcon, infoIcon, increaseIcon, decreaseIcon, fullscreenIcon, manualIcon;
 
339
#ifdef USE_XPM
 
340
        prefsIcon = QPixmap(const_cast<const char**>(package_settings_xpm));
 
341
        infoIcon = QPixmap(const_cast<const char**>(idea_xpm));
 
342
        exitIcon = QPixmap(const_cast<const char**>(exit_xpm));
 
343
        fileNewboardIcon = QPixmap(const_cast<const char**>(newboard_xpm));
 
344
        fileNewIcon = QPixmap(const_cast<const char**>(filenew_xpm));
 
345
        fileOpenIcon = QPixmap(const_cast<const char**>(fileopen_xpm));
 
346
        fileSaveIcon = QPixmap(const_cast<const char**>(filesave_xpm));
 
347
        fileSaveAsIcon = QPixmap(const_cast<const char**>(filesaveas_xpm));
 
348
        transformIcon = QPixmap(const_cast<const char**>(transform_xpm));
 
349
        charIcon = QPixmap(const_cast<const char**>(charset_xpm));
 
350
        cutIcon = QPixmap(const_cast<const char**>(editcut_xpm));
 
351
        pasteIcon = QPixmap(const_cast<const char**>(editpaste_xpm));
 
352
        deleteIcon = QPixmap(const_cast<const char**>(editdelete_xpm));
 
353
        rightArrowIcon = QPixmap(const_cast<const char**>(rightarrow_xpm));
 
354
        leftArrowIcon = QPixmap(const_cast<const char**>(leftarrow_xpm));
 
355
        nextCommentIcon = QPixmap(const_cast<const char**>(rightcomment_xpm));
 
356
        previousCommentIcon = QPixmap(const_cast<const char**>(leftcomment_xpm));     
 
357
        two_rightArrowIcon = QPixmap(const_cast<const char**>(two_rightarrow_xpm));
 
358
        two_leftArrowIcon = QPixmap(const_cast<const char**>(two_leftarrow_xpm));
 
359
        nextVarIcon = QPixmap(const_cast<const char**>(down_xpm));
 
360
        prevVarIcon = QPixmap(const_cast<const char**>(up_xpm));
 
361
        mainBranchIcon = QPixmap(const_cast<const char**>(start_xpm));
 
362
        startVarIcon = QPixmap(const_cast<const char**>(top_xpm));
 
363
        nextBranchIcon = QPixmap(const_cast<const char**>(bottom_xpm));
 
364
        increaseIcon = QPixmap(const_cast<const char**>(viewmagplus_xpm));
 
365
        decreaseIcon = QPixmap(const_cast<const char**>(viewmagminus_xpm));
 
366
        fullscreenIcon = QPixmap(const_cast<const char**>(window_fullscreen_xpm));
 
367
        manualIcon = QPixmap(const_cast<const char**>(help_xpm));
 
368
        autoplayIcon = QPixmap(const_cast<const char**>(player_pause_xpm));
 
369
        navIntersectionIcon  = QPixmap(const_cast<const char**>(navIntersection_xpm));  //SL added eb 11
 
370
  
 
371
#else
 
372
        prefsIcon = QPixmap(ICON_PREFS);
 
373
        infoIcon = QPixmap(ICON_GAMEINFO);
 
374
        exitIcon = QPixmap(ICON_EXIT);
 
375
        fileNewboardIcon = QPixmap(ICON_FILENEWBOARD);
 
376
        fileNewIcon = QPixmap(ICON_FILENEW);
 
377
        fileOpenIcon = QPixmap(ICON_FILEOPEN);
 
378
        fileSaveIcon = QPixmap(ICON_FILESAVE);
 
379
        fileSaveAsIcon = QPixmap(ICON_FILESAVEAS);
 
380
        transformIcon = QPixmap(ICON_TRANSFORM);
 
381
        charIcon = QPixmap(ICON_CHARSET);
 
382
        cutIcon = QPixmap(ICON_CUT);
 
383
        pasteIcon = QPixmap(ICON_PASTE);
 
384
        deleteIcon = QPixmap(ICON_DELETE);
 
385
        rightArrowIcon = QPixmap(ICON_RIGHTARROW);
 
386
        leftArrowIcon = QPixmap(ICON_LEFTARROW);
 
387
        nextCommentIcon = QPixmap(ICON_RIGHTCOMMENT);                   //added eb
 
388
        previousCommentIcon = QPixmap(ICON_LEFTCOMMENT);                   //added eb
 
389
        two_rightArrowIcon = QPixmap(ICON_TWO_RIGHTARROW);
 
390
        two_leftArrowIcon = QPixmap(ICON_TWO_LEFTARROW);
 
391
        nextVarIcon = QPixmap(ICON_NEXT_VAR);
 
392
        prevVarIcon = QPixmap(ICON_PREV_VAR);
 
393
        startVarIcon = QPixmap(ICON_START_VAR);
 
394
        mainBranchIcon = QPixmap(ICON_MAIN_BRANCH);
 
395
        nextBranchIcon = QPixmap(ICON_NEXT_BRANCH);
 
396
        increaseIcon = QPixmap(ICON_INCREASE_SIZE);
 
397
        decreaseIcon = QPixmap(ICON_DECREASE_SIZE);
 
398
        fullscreenIcon = QPixmap(ICON_FULLSCREEN);
 
399
        manualIcon = QPixmap(ICON_MANUAL);
 
400
        autoplayIcon = QPixmap(ICON_AUTOPLAY);
 
401
        navIntersectionIcon  = QPixmap(ICON_NAV_INTERSECTION);  //SL added eb 11
 
402
 
 
403
  
 
404
#endif
 
405
        
 
406
        /*
 
407
        * Global actions
 
408
        */
 
409
        // Escape focus: Escape key to get the focus from comment field to main window.
 
410
        escapeFocus = new QAction(this);
 
411
        escapeFocus->setAccel(Key_Escape);
 
412
        connect(escapeFocus, SIGNAL(activated()), this, SLOT(setFocus()));
 
413
        
 
414
        // Toggle game mode: Normal / Edit - Ctrl-E
 
415
        toggleEdit = new QAction(this);
 
416
        toggleEdit->setAccel(QAccel::stringToKey(tr("Ctrl+E")));
 
417
        // connect in constructor, as we need the mainwidget instance first.
 
418
        
 
419
        // Toggle through the marks - Ctrl-T
 
420
        toggleMarks = new QAction(this);
 
421
        toggleMarks->setAccel(QAccel::stringToKey(tr("Ctrl+T")));
 
422
        connect(toggleMarks, SIGNAL(activated()), this, SLOT(slotToggleMarks()));
 
423
        
 
424
        /*
 
425
        * Menu File
 
426
        */
 
427
        // File New Board
 
428
        fileNewBoard = new QAction(tr("New"), fileNewboardIcon, tr("New &Board"),
 
429
                QAccel::stringToKey(tr("Ctrl+B")), this);
 
430
        fileNewBoard->setStatusTip(tr("Creates a new board"));
 
431
        fileNewBoard->setWhatsThis(tr("New\n\nCreates a new board."));
 
432
        connect(fileNewBoard, SIGNAL(activated()), this, SLOT(slotFileNewBoard()));
 
433
        
 
434
        // File New Game
 
435
        fileNew = new QAction(tr("New game"), fileNewIcon, tr("&New game"),
 
436
                QAccel::stringToKey(tr("Ctrl+N")), this);
 
437
        fileNew->setStatusTip(tr("Creates a new game on this board"));
 
438
        fileNew->setWhatsThis(tr("New\n\nCreates a new game on this board."));
 
439
        connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNewGame()));
 
440
        
 
441
        // File Open
 
442
        fileOpen = new QAction(tr("Open"), fileOpenIcon, tr("&Open"),
 
443
                QAccel::stringToKey(tr("Ctrl+O")), this);
 
444
        fileOpen->setStatusTip(tr("Open a sgf file"));
 
445
        fileOpen->setWhatsThis(tr("Open\n\nOpen a sgf file."));
 
446
        connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
 
447
        
 
448
        // File Save
 
449
        fileSave = new QAction(tr("Save"), fileSaveIcon, tr("&Save"),
 
450
                QAccel::stringToKey(tr("Ctrl+S")), this);
 
451
        fileSave->setStatusTip(tr("Save a sgf file"));
 
452
        fileSave->setWhatsThis(tr("Save\n\nSave a sgf file."));
 
453
        connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
 
454
        
 
455
        // File SaveAs
 
456
        fileSaveAs = new QAction(tr("Save As"), fileSaveAsIcon, tr("Save &As"), 0, this);
 
457
        fileSaveAs->setStatusTip(tr("Save a sgf file under a new name"));
 
458
        fileSaveAs->setWhatsThis(tr("Save As\n\nSave a sgf file under a new name."));
 
459
        connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));
 
460
        
 
461
        // File Close
 
462
        fileClose = new QAction(tr("Close"), tr("&Close"), QAccel::stringToKey(tr("Ctrl+W")), this);
 
463
        fileClose->setStatusTip(tr("Close this board"));
 
464
        fileClose->setWhatsThis(tr("Exit\n\nClose this board."));
 
465
        connect(fileClose, SIGNAL(activated()), this, SLOT(slotFileClose()));
 
466
        
 
467
        // File ImportASCII
 
468
        fileImportASCII = new QAction(tr("Import ASCII"), charIcon, tr("Import &ASCII"), 0, this);
 
469
        fileImportASCII->setStatusTip(tr("Import an ASCII file as new variation"));
 
470
        fileImportASCII->setWhatsThis(tr("Import ASCII\n\nImport an ASCII file as new variation."));
 
471
        connect(fileImportASCII, SIGNAL(activated()), this, SLOT(slotFileImportASCII()));
 
472
 
 
473
        // File ImportASCIIClipB
 
474
        fileImportASCIIClipB = new QAction(tr("Import ASCII from clipboard"), charIcon,
 
475
                tr("Import ASCII from &clipboard"), 0, this);
 
476
        fileImportASCIIClipB->setStatusTip(tr("Import an ASCII board as new variation from the clipboard"));
 
477
        fileImportASCIIClipB->setWhatsThis(tr("Import ASCII from clipboard\n\nImport an ASCII file as new variation from the clipboard."));
 
478
        connect(fileImportASCIIClipB, SIGNAL(activated()), this, SLOT(slotFileImportASCIIClipB()));
 
479
        
 
480
        // File ExportASCII
 
481
        fileExportASCII = new QAction(tr("Export ASCII"), charIcon, tr("&Export ASCII"), 0, this);
 
482
        fileExportASCII->setStatusTip(tr("Export current board to ASCII"));
 
483
        fileExportASCII->setWhatsThis(tr("Export ASCII\n\nExport current board to ASCII."));
 
484
        connect(fileExportASCII, SIGNAL(activated()), this, SLOT(slotFileExportASCII()));
 
485
        
 
486
        // File ImportSgfClipB
 
487
        fileImportSgfClipB = new QAction(tr("Import SGF from clipboard"), fileOpenIcon,
 
488
                tr("Import SGF &from clipboard"), 0, this);
 
489
        fileImportSgfClipB->setStatusTip(tr("Import a complete game in SGF format from clipboard"));
 
490
        fileImportSgfClipB->setWhatsThis(tr("Import SGF from clipboard\n\n"
 
491
                "Import a complete game in SGF format from clipboard."));
 
492
        connect(fileImportSgfClipB, SIGNAL(activated()), this, SLOT(slotFileImportSgfClipB()));
 
493
        
 
494
        // File ExportSgfClipB
 
495
        fileExportSgfClipB = new QAction(tr("Export SGF to clipboard"), fileSaveIcon,
 
496
                tr("Export SGF &to clipboard"), 0, this);
 
497
        fileExportSgfClipB->setStatusTip(tr("Export a complete game in SGF format to clipboard"));
 
498
        fileExportSgfClipB->setWhatsThis(tr("Export SGF to clipboard\n\n"
 
499
                "Export a complete game in SGF format to clipboard."));
 
500
        connect(fileExportSgfClipB, SIGNAL(activated()), this, SLOT(slotFileExportSgfClipB()));
 
501
        
 
502
        // File ExportPic
 
503
        fileExportPic = new QAction(tr("Export Image"), transformIcon, tr("Export &Image"), 0, this);
 
504
        fileExportPic->setStatusTip(tr("Export current board to an image"));
 
505
        fileExportPic->setWhatsThis(tr("Export Image\n\nExport current board to an image."));
 
506
        connect(fileExportPic, SIGNAL(activated()), this, SLOT(slotFileExportPic()));
 
507
        
 
508
        // File ExportPic
 
509
        fileExportPicClipB = new QAction(tr("Export Image to clipboard"), transformIcon,
 
510
                tr("E&xport Image to clipboard"), 0, this);
 
511
        fileExportPicClipB->setStatusTip(tr("Export current board to the clipboard as image"));
 
512
        fileExportPicClipB->setWhatsThis(tr("Export Image to clipboard\n\nExport current board to the clipboard as image."));
 
513
        connect(fileExportPicClipB, SIGNAL(activated()), this, SLOT(slotFileExportPicClipB()));
 
514
        
 
515
        // File Quit
 
516
        fileQuit = new QAction(tr("Exit"), exitIcon, tr("E&xit"),
 
517
                QAccel::stringToKey(tr("Ctrl+Q")), this);
 
518
        fileQuit->setStatusTip(tr("Quits the application"));
 
519
        fileQuit->setWhatsThis(tr("Exit\n\nQuits the application."));
 
520
        connect(fileQuit, SIGNAL(activated()), this, SLOT(slotFileClose()));//(qGo*)qApp, SLOT(quit()));
 
521
        
 
522
        /*
 
523
        * Menu Edit
 
524
        */
 
525
        // Edit cut
 
526
        editCut = new QAction(tr("Cut"), cutIcon, tr("&Cut"),
 
527
                QAccel::stringToKey(tr("Ctrl+X")), this);
 
528
        editCut->setStatusTip(tr("Cut this and all following positions"));
 
529
        editCut->setWhatsThis(tr("Cut\n\nCut this and all following positions."));
 
530
        connect(editCut, SIGNAL(activated()), this, SLOT(slotEditCut()));
 
531
        
 
532
        // Edit paste
 
533
        editPaste = new QAction(tr("Paste"), pasteIcon, tr("&Paste"),
 
534
                QAccel::stringToKey(tr("Ctrl+P")), this);
 
535
        editPaste->setStatusTip(tr("Paste as son of the current move"));
 
536
        editPaste->setWhatsThis(tr("Paste\n\nPaste as son of the current move."));
 
537
        connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste()));
 
538
        
 
539
        // Edit paste as brother
 
540
        editPasteBrother = new QAction(tr("Paste as brother"), tr("Paste as &brother"), 0, this);
 
541
        editPasteBrother->setStatusTip(tr("Paste as brother of the current move"));
 
542
        editPasteBrother->setWhatsThis(tr("Paste\n\nPaste as brother of the current move."));
 
543
        connect(editPasteBrother, SIGNAL(activated()), this, SLOT(slotEditPasteBrother()));
 
544
        
 
545
        // Edit delete
 
546
        editDelete = new QAction(tr("Delete"), deleteIcon, tr("&Delete"),
 
547
                QAccel::stringToKey(tr("Ctrl+D")), this);
 
548
        editDelete->setStatusTip(tr("Delete this and all following positions"));
 
549
        editDelete->setWhatsThis(tr("Delete\n\nDelete this and all following positions."));
 
550
        connect(editDelete, SIGNAL(activated()), this, SLOT(slotEditDelete()));
 
551
        
 
552
        // Edit number moves
 
553
        editNumberMoves = new QAction(tr("Number Moves"), tr("&Number Moves"),
 
554
                QAccel::stringToKey(tr("Shift+F2")), this);
 
555
        editNumberMoves->setStatusTip(tr("Mark all moves with the number of their turn"));
 
556
        editNumberMoves->setWhatsThis(tr("Number moves\n\nMark all moves with the number of their turn."));
 
557
        connect(editNumberMoves, SIGNAL(activated()), this, SLOT(slotEditNumberMoves()));
 
558
        
 
559
        // Edit mark brothers
 
560
        editMarkBrothers = new QAction(tr("Mark brothers"), tr("Mark &brothers"),
 
561
                QAccel::stringToKey(tr("Shift+F3")), this);
 
562
        editMarkBrothers->setStatusTip(tr("Mark all brothers of the current move"));
 
563
        editMarkBrothers->setWhatsThis(tr("Mark brothers\n\nMark all brothers of the current move."));
 
564
        connect(editMarkBrothers, SIGNAL(activated()), this, SLOT(slotEditMarkBrothers()));
 
565
        
 
566
        // Edit mark sons
 
567
        editMarkSons = new QAction(tr("Mark sons"), tr("Mark &sons"),
 
568
                QAccel::stringToKey(tr("Shift+F4")), this);
 
569
        editMarkSons->setStatusTip(tr("Mark all sons of the current move"));
 
570
        editMarkSons->setWhatsThis(tr("Mark sons\n\nMark all sons of the current move."));
 
571
        connect(editMarkSons, SIGNAL(activated()), this, SLOT(slotEditMarkSons()));
 
572
        
 
573
        /*
 
574
        * Menu Navigation
 
575
        */
 
576
        // Navigation Backward
 
577
        navBackward = new QAction(tr("Previous move (Left)"), leftArrowIcon, tr("&Previous move") + "\t" + tr("Left"),
 
578
                0, this);
 
579
        navBackward->setStatusTip(tr("To previous move"));
 
580
        navBackward->setWhatsThis(tr("Previous move\n\nMove one move backward."));
 
581
        connect(navBackward, SIGNAL(activated()), this, SLOT(slotNavBackward()));
 
582
        
 
583
        // Navigation Forward
 
584
        navForward = new QAction(tr("Next move (Right)"), rightArrowIcon, tr("&Next move") + "\t" + tr("Right"), 0, this);
 
585
        navForward->setStatusTip(tr("To next move"));
 
586
        navForward->setWhatsThis(tr("Next move\n\nMove one move forward."));
 
587
        connect(navForward, SIGNAL(activated()), this, SLOT(slotNavForward()));
 
588
        
 
589
        // Navigation First
 
590
        navFirst = new QAction(tr("First move (Home)"), two_leftArrowIcon, tr("&First move") + "\t" + tr("Home"), 0, this);
 
591
        navFirst->setStatusTip(tr("To first move"));
 
592
        navFirst->setWhatsThis(tr("First move\n\nMove to first move."));
 
593
        connect(navFirst, SIGNAL(activated()), this, SLOT(slotNavFirst()));
 
594
        
 
595
        // Navigation Last
 
596
        navLast = new QAction(tr("Last move (End)"), two_rightArrowIcon, tr("&Last move") + "\t" + tr("End"), 0, this);
 
597
        navLast->setStatusTip(tr("To last move"));
 
598
        navLast->setWhatsThis(tr("Last move\n\nMove to last move."));
 
599
        connect(navLast, SIGNAL(activated()), this, SLOT(slotNavLast()));
 
600
        
 
601
        // Navigation previous variation
 
602
        navPrevVar = new QAction(tr("Previous variation (Up)"), prevVarIcon, tr("P&revious variation") + "\t" + tr("Up"), 0, this);
 
603
        navPrevVar->setStatusTip(tr("To previous variation"));
 
604
        navPrevVar->setWhatsThis(tr("Previous variation\n\nMove to the previous variation of this move."));
 
605
        connect(navPrevVar, SIGNAL(activated()), this, SLOT(slotNavPrevVar()));
 
606
        
 
607
        // Navigation next variation
 
608
        navNextVar = new QAction(tr("Next variation (Down)"), nextVarIcon, tr("N&ext variation") + "\t" + tr("Down"), 0, this);
 
609
        navNextVar->setStatusTip(tr("To next variation"));
 
610
        navNextVar->setWhatsThis(tr("Next variation\n\nMove to the next variation of this move."));
 
611
        connect(navNextVar, SIGNAL(activated()), this, SLOT(slotNavNextVar()));
 
612
        
 
613
        // Navigation main branch
 
614
        navMainBranch = new QAction(tr("Main Branch"), mainBranchIcon, tr("&Main branch"), Key_Insert, this);
 
615
        navMainBranch->setStatusTip(tr("To main branch"));
 
616
        navMainBranch->setWhatsThis(tr("Main Branch\n\nMove to the main branch where variation started."));
 
617
        connect(navMainBranch, SIGNAL(activated()), this, SLOT(slotNavMainBranch()));
 
618
        
 
619
        // Navigation variation start
 
620
        navStartVar = new QAction(tr("Variation start"), startVarIcon, tr("Variation &start"), Key_PageUp, this);
 
621
        navStartVar->setStatusTip(tr("To top of variation"));
 
622
        navStartVar->setWhatsThis(tr("Variation start\n\nMove to the top variation of this branch."));
 
623
        connect(navStartVar, SIGNAL(activated()), this, SLOT(slotNavStartVar()));
 
624
        
 
625
        // Navigation next branch
 
626
        navNextBranch = new QAction(tr("Next branch"), nextBranchIcon, tr("Next &branch"), Key_PageDown, this);
 
627
        navNextBranch->setStatusTip(tr("To next branch starting a variation"));
 
628
        navNextBranch->setWhatsThis(tr("Next branch\n\nMove to the next branch starting a variation."));
 
629
        connect(navNextBranch, SIGNAL(activated()), this, SLOT(slotNavNextBranch()));
 
630
        
 
631
        // Navigation goto Nth move
 
632
        navNthMove = new QAction(tr("Goto move"), tr("&Goto Move"), QAccel::stringToKey(tr("Ctrl+G")) , this);
 
633
        navNthMove->setStatusTip(tr("Goto a move of main branch by number"));
 
634
        navNthMove->setWhatsThis(tr("Goto move\n\nGoto a move of main branch by number."));
 
635
        connect(navNthMove, SIGNAL(activated()), this, SLOT(slotNavNthMove()));
 
636
        
 
637
        // Navigation Autoplay
 
638
        navAutoplay = new QAction(tr("Autoplay"), autoplayIcon, tr("&Autoplay"),
 
639
                QAccel::stringToKey(tr("Ctrl+A")), this, 0, true);
 
640
        navAutoplay->setOn(false);
 
641
        navAutoplay->setStatusTip(tr("Start/Stop autoplaying current game"));
 
642
        navAutoplay->setWhatsThis(tr("Autoplay\n\nStart/Stop autoplaying current game."));
 
643
        connect(navAutoplay, SIGNAL(toggled(bool)), this, SLOT(slotNavAutoplay(bool)));
 
644
        
 
645
        // Navigation empty branch
 
646
        navEmptyBranch = new QAction(tr("Empty branch"), tr("Empt&y branch"), 0, this);
 
647
        navEmptyBranch->setStatusTip(tr("Create an empty branch"));
 
648
        navEmptyBranch->setWhatsThis(tr("Empty branch\n\nCreate an empty branch."));
 
649
        connect(navEmptyBranch, SIGNAL(activated()), this, SLOT(slotNavEmptyBranch()));
 
650
        
 
651
        // Navigation duplicate move
 
652
        navCloneNode = new QAction(tr("Duplicate move"), tr("D&uplicate move"), 0, this);
 
653
        navCloneNode->setStatusTip(tr("Copies and duplicates this move"));
 
654
        navCloneNode->setWhatsThis(tr("Duplicate move\n\nCopies and duplicates this move."));
 
655
        connect(navCloneNode, SIGNAL(activated()), this, SLOT(slotNavCloneNode()));
 
656
        
 
657
        // Navigation swap variations
 
658
        navSwapVariations = new QAction(tr("Swap variations"), tr("S&wap variations"), 0, this);
 
659
        navSwapVariations->setStatusTip(tr("Swap current move with previous variation"));
 
660
        navSwapVariations->setWhatsThis(tr("Swap variations\n\nSwap current move with previous variation."));
 
661
        connect(navSwapVariations, SIGNAL(activated()), this, SLOT(slotNavSwapVariations()));
 
662
        
 
663
        // Navigation previous comment
 
664
        navPrevComment = new QAction(tr("Previous commented move"), previousCommentIcon, tr("Previous &commented move") , 0, this);        //added eb
 
665
        navPrevComment->setStatusTip(tr("To previous comment"));
 
666
        navPrevComment->setWhatsThis(tr("Previous comment\n\nMove to the previous move that has a comment"));
 
667
        connect(navPrevComment, SIGNAL(activated()), this, SLOT(slotNavPrevComment()));
 
668
 
 
669
        // Navigation next comment
 
670
        navNextComment = new QAction(tr("Next commented move"), nextCommentIcon, tr("Next c&ommented move") , 0, this);
 
671
        navNextComment->setStatusTip(tr("To next comment"));
 
672
        navNextComment->setWhatsThis(tr("Next comment\n\nMove to the next move that has a comment"));
 
673
        connect(navNextComment, SIGNAL(activated()), this, SLOT(slotNavNextComment()));                                            // end add eb
 
674
 
 
675
  // Navigation to clicked intersection                       added eb 11
 
676
        navIntersection = new QAction(tr("Goto stone at clicked move"), navIntersectionIcon, tr("Goto clic&ked move") , 0, this);
 
677
        navIntersection->setStatusTip(tr("To clicked move"));
 
678
        navIntersection->setWhatsThis(tr("Click on a board intersection\n\nMove to the stone played at this intersection (if any)"));
 
679
        connect(navIntersection, SIGNAL(activated()), this, SLOT(slotNavIntersection()));                                            // end add eb
 
680
                                                              // end add eb 11
 
681
  
 
682
        /*
 
683
        * Menu Settings
 
684
        */
 
685
        // Settings Preferences
 
686
        setPreferences = new QAction(tr("Preferences"), prefsIcon, tr("&Preferences"),
 
687
                QAccel::stringToKey(tr("Alt+P")), this);
 
688
        setPreferences->setStatusTip(tr("Edit the preferences"));
 
689
        setPreferences->setWhatsThis(tr("Preferences\n\nEdit the applications preferences."));
 
690
        connect(setPreferences, SIGNAL(activated()), this, SLOT(slotSetPreferences()));
 
691
        
 
692
        // Setings GameInfo
 
693
        setGameInfo = new QAction(tr("Game Info"), infoIcon, tr("&Game Info"),
 
694
                QAccel::stringToKey(tr("Ctrl+I")), this);
 
695
        setGameInfo->setStatusTip(tr("Display game information"));
 
696
        setGameInfo->setWhatsThis(tr("Game Info\n\nDisplay game information."));
 
697
        connect(setGameInfo, SIGNAL(activated()), this, SLOT(slotSetGameInfo()));
 
698
        
 
699
        /*
 
700
        * Menu View
 
701
        */
 
702
        // View Filebar toggle
 
703
        viewFileBar = new QAction(tr("File toolbar"), tr("&File toolbar"), 0, this, 0, true);
 
704
        viewFileBar->setOn(true);
 
705
        viewFileBar->setStatusTip(tr("Enables/disables the file toolbar"));
 
706
        viewFileBar->setWhatsThis(tr("File toolbar\n\nEnables/disables the file toolbar."));
 
707
        connect(viewFileBar, SIGNAL(toggled(bool)), this, SLOT(slotViewFileBar(bool)));
 
708
        
 
709
        // View Toolbar toggle
 
710
        viewToolBar = new QAction(tr("Navigation toolbar"), tr("Navigation &toolbar"), 0, this, 0, true);
 
711
        viewToolBar->setOn(true);
 
712
        viewToolBar->setStatusTip(tr("Enables/disables the navigation toolbar"));
 
713
        viewToolBar->setWhatsThis(tr("Navigation toolbar\n\nEnables/disables the navigation toolbar."));
 
714
        connect(viewToolBar, SIGNAL(toggled(bool)), this, SLOT(slotViewToolBar(bool)));
 
715
        
 
716
        // View Editbar toggle
 
717
        viewEditBar = new QAction(tr("Edit toolbar"), tr("&Edit toolbar"), 0, this, 0, true);
 
718
        viewEditBar->setOn(true);
 
719
        viewEditBar->setStatusTip(tr("Enables/disables the edit toolbar"));
 
720
        viewEditBar->setWhatsThis(tr("Edit toolbar\n\nEnables/disables the edit toolbar."));
 
721
        connect(viewEditBar, SIGNAL(toggled(bool)), this, SLOT(slotViewEditBar(bool)));
 
722
        
 
723
        // View Menubar toggle
 
724
        viewMenuBar = new QAction(tr("Menubar"), tr("&Menubar"),
 
725
                QAccel::stringToKey(tr("F7")), this, 0, true);
 
726
        viewMenuBar->setOn(true);
 
727
        viewMenuBar->setStatusTip(tr("Enables/disables the menubar"));
 
728
        viewMenuBar->setWhatsThis(tr("Menubar\n\nEnables/disables the menubar."));
 
729
        connect(viewMenuBar, SIGNAL(toggled(bool)), this, SLOT(slotViewMenuBar(bool)));
 
730
        
 
731
        // View Statusbar toggle
 
732
        viewStatusBar = new QAction(tr("Statusbar"), tr("&Statusbar"), 0, this, 0, true);
 
733
        viewStatusBar->setOn(true);
 
734
        viewStatusBar->setStatusTip(tr("Enables/disables the statusbar"));
 
735
        viewStatusBar->setWhatsThis(tr("Statusbar\n\nEnables/disables the statusbar."));
 
736
        connect(viewStatusBar, SIGNAL(toggled(bool)), this, SLOT(slotViewStatusBar(bool)));
 
737
        
 
738
        // View Coordinates toggle
 
739
        viewCoords = new QAction(tr("Coordinates"), tr("C&oordinates"),
 
740
                QAccel::stringToKey(tr("F8")), this, 0, true);
 
741
        viewCoords->setOn(false);
 
742
        viewCoords->setStatusTip(tr("Enables/disables the coordinates"));
 
743
        viewCoords->setWhatsThis(tr("Coordinates\n\nEnables/disables the coordinates."));
 
744
        connect(viewCoords, SIGNAL(toggled(bool)), this, SLOT(slotViewCoords(bool)));
 
745
        
 
746
        // View Slider toggle
 
747
        viewSlider = new QAction(tr("Slider"), tr("Sli&der"),
 
748
                QAccel::stringToKey(tr("Ctrl+F8")), this, 0, true);
 
749
        viewSlider->setOn(false);
 
750
        viewSlider->setStatusTip(tr("Enables/disables the slider"));
 
751
        viewSlider->setWhatsThis(tr("Slider\n\nEnables/disables the slider."));
 
752
        connect(viewSlider, SIGNAL(toggled(bool)), this, SLOT(slotViewSlider(bool)));
 
753
        
 
754
        // View Sidebar toggle
 
755
        viewSidebar = new QAction(tr("Sidebar"), tr("Side&bar"),
 
756
                QAccel::stringToKey(tr("F9")), this, 0, true);
 
757
        viewSidebar->setOn(true);
 
758
        viewSidebar->setStatusTip(tr("Enables/disables the sidebar"));
 
759
        viewSidebar->setWhatsThis(tr("Sidebar\n\nEnables/disables the sidebar."));
 
760
        connect(viewSidebar, SIGNAL(toggled(bool)), this, SLOT(slotViewSidebar(bool)));
 
761
        
 
762
        // View Comment toggle
 
763
        viewComment = new QAction(tr("Comment"), tr("&Comment"),
 
764
                QAccel::stringToKey(tr("F10")), this, 0, true);
 
765
        viewComment->setOn(true);
 
766
        viewComment->setStatusTip(tr("Enables/disables the comment field"));
 
767
        viewComment->setWhatsThis(tr("Comment field\n\nEnables/disables the comment field."));
 
768
        connect(viewComment, SIGNAL(toggled(bool)), this, SLOT(slotViewComment(bool)));
 
769
        
 
770
        // View Vertical Comment toggle
 
771
        viewVertComment = new QAction(tr("Vertical comment"), tr("&Vertical comment"),
 
772
                QAccel::stringToKey(tr("Shift+F10")), this, 0, true);
 
773
        viewVertComment->setOn(setting->readIntEntry("VIEW_COMMENT") == 2 ||
 
774
                setting->readIntEntry("VIEW_COMMENT") == 0 && setting->readIntEntry("BOARDVERTCOMMENT_0"));
 
775
        viewVertComment->setStatusTip(tr("Enables/disables a vertical direction of the comment field"));
 
776
        viewVertComment->setWhatsThis(tr("Vertical comment field\n\n"
 
777
                "Enables/disables a vertical direction of the comment field.\n\nNote: This setting is temporary for this board. In order to set permanent horizontal/vertical comment use 'Preferences'."));
 
778
        connect(viewVertComment, SIGNAL(toggled(bool)), this, SLOT(slotViewVertComment(bool)));
 
779
        
 
780
        // View Pin comment
 
781
        viewPinComment = new QAction(tr("Pin comment"), tr("&Pin comment"),
 
782
                QAccel::stringToKey(tr("Ctrl+F10")), this, 0, true);
 
783
        viewPinComment->setOn(false);
 
784
        viewPinComment->setStatusTip(tr("Enables/disables pinning the comment field"));
 
785
        viewPinComment->setWhatsThis(tr("Pin comment field\n\nEnables/disables pinning the comment field."));
 
786
        connect(viewPinComment, SIGNAL(toggled(bool)), this, SLOT(slotViewPinComment(bool)));
 
787
        
 
788
        // View Increase Size
 
789
        viewIncreaseSize = new QAction(tr("Zoom In"), increaseIcon, tr("Zoom &In"),
 
790
                QAccel::stringToKey(tr("Alt++")), this);
 
791
        viewIncreaseSize->setStatusTip(tr("Zooms in the board"));
 
792
        viewIncreaseSize->setWhatsThis(tr("Zoom In\n\nZooms in the board."));
 
793
        connect(viewIncreaseSize, SIGNAL(activated()), this, SLOT(slotViewIncreaseSize()));
 
794
        
 
795
        // View Decrease Size
 
796
        viewDecreaseSize = new QAction(tr("Zoom Out"), decreaseIcon, tr("Zoom &Out"),
 
797
                QAccel::stringToKey(tr("Alt+-")), this);
 
798
        viewDecreaseSize->setStatusTip(tr("Zooms out the board"));
 
799
        viewDecreaseSize->setWhatsThis(tr("Zoom Out\n\nZooms out the board."));
 
800
        connect(viewDecreaseSize, SIGNAL(activated()), this, SLOT(slotViewDecreaseSize()));
 
801
        
 
802
        // View Save Size
 
803
        viewSaveSize = new QAction(tr("Save size"), tr("Save si&ze"), 
 
804
                QAccel::stringToKey("Alt+0"), this, 0, false);
 
805
        viewSaveSize->setStatusTip(tr("Save the current window size"));
 
806
        viewSaveSize->setWhatsThis(tr("Save size\n\n"
 
807
                "Saves the current window size and restores it on the next program start.\n\nUse ALT + <number key> to store own sizes\nRestore with CTRL + <number key>\n\n<0> is default value at program start.\n<9> is default for edit window."));
 
808
        connect(viewSaveSize, SIGNAL(activated()), this, SLOT(slotViewSaveSize()));
 
809
        
 
810
        // View Fullscreen
 
811
        viewFullscreen = new QAction(tr("Fullscreen"), fullscreenIcon, tr("&Fullscreen"),
 
812
                QAccel::stringToKey(tr("F11")), this, 0, true);
 
813
        viewFullscreen->setOn(false);
 
814
        viewFullscreen->setStatusTip(tr("Enable/disable fullscreen mode"));
 
815
        viewFullscreen->setWhatsThis(tr("Fullscreen\n\nEnable/disable fullscreen mode."));
 
816
        connect(viewFullscreen, SIGNAL(toggled(bool)), this, SLOT(slotViewFullscreen(bool)));
 
817
        
 
818
        /*
 
819
        * Menu Help
 
820
        */
 
821
        // Help Manual
 
822
        helpManual = new QAction(tr("Manual"), manualIcon, tr("&Manual"),
 
823
                QAccel::stringToKey(tr("F1")), this);
 
824
        helpManual->setStatusTip(tr("Opens the manual"));
 
825
        helpManual->setWhatsThis(tr("Help\n\nOpens the manual of the application."));
 
826
        connect(helpManual, SIGNAL(activated()), this, SLOT(slotHelpManual()));
 
827
        
 
828
        // Sound Info
 
829
        helpSoundInfo = new QAction(tr("Sound Info"), tr("&Sound"), 0, this);
 
830
        helpSoundInfo->setStatusTip(tr("Short info on sound availability"));
 
831
        helpSoundInfo->setWhatsThis(tr("Sound Info\n\nViews a message box with a short comment about sound."));
 
832
        connect(helpSoundInfo, SIGNAL(activated()), this, SLOT(slotHelpSoundInfo()));
 
833
        
 
834
        // Help About
 
835
        helpAboutApp = new QAction(tr("About"), tr("&About..."), 0, this);
 
836
        helpAboutApp->setStatusTip(tr("About the application"));
 
837
        helpAboutApp->setWhatsThis(tr("About\n\nAbout the application."));
 
838
        connect(helpAboutApp, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
 
839
        
 
840
        // Help AboutQt
 
841
        helpAboutQt = new QAction(tr("About Qt"), tr("About &Qt..."), 0, this);
 
842
        helpAboutQt->setStatusTip(tr("About Qt"));
 
843
        helpAboutQt->setWhatsThis(tr("About Qt\n\nAbout Qt."));
 
844
        connect(helpAboutQt, SIGNAL(activated()), this, SLOT(slotHelpAboutQt()));
 
845
        
 
846
        // Disable some toolbuttons at startup
 
847
        navForward->setEnabled(false);
 
848
        navBackward->setEnabled(false);
 
849
        navFirst->setEnabled(false);
 
850
        navLast->setEnabled(false);
 
851
        navPrevVar->setEnabled(false);
 
852
        navNextVar->setEnabled(false);
 
853
        navMainBranch->setEnabled(false);
 
854
        navStartVar->setEnabled(false);
 
855
        navNextBranch->setEnabled(false);
 
856
        navSwapVariations->setEnabled(false);
 
857
        navPrevComment->setEnabled(false);
 
858
        navNextComment->setEnabled(false);
 
859
  navIntersection->setEnabled(false);     //SL added eb 11
 
860
        editPaste->setEnabled(false);
 
861
        editPasteBrother->setEnabled(false);
 
862
}
 
863
 
 
864
void MainWindow::initMenuBar()
 
865
{
 
866
#ifdef USE_XPM
 
867
        QIconSet wtIcon(QPixmap(const_cast<const char**>(contexthelp_xpm)));
 
868
#else
 
869
        QIconSet wtIcon(QPixmap(ICON_WHATSTHIS));
 
870
#endif
 
871
        
 
872
        // submenu Import/Export
 
873
        importExportMenu = new QPopupMenu();
 
874
        importExportMenu->insertTearOffHandle();
 
875
        fileImportASCII->addTo(importExportMenu);
 
876
        fileImportASCIIClipB->addTo(importExportMenu);
 
877
        fileExportASCII->addTo(importExportMenu);
 
878
        importExportMenu->insertSeparator();
 
879
        fileImportSgfClipB->addTo(importExportMenu);
 
880
        fileExportSgfClipB->addTo(importExportMenu);
 
881
        importExportMenu->insertSeparator();
 
882
        fileExportPic->addTo(importExportMenu);
 
883
        fileExportPicClipB->addTo(importExportMenu);
 
884
        
 
885
        // menuBar entry fileMenu
 
886
        fileMenu = new QPopupMenu();
 
887
        fileMenu->insertTearOffHandle();
 
888
        fileNewBoard->addTo(fileMenu);
 
889
        fileNew->addTo(fileMenu);
 
890
        fileOpen->addTo(fileMenu);
 
891
        fileSave->addTo(fileMenu);
 
892
        fileSaveAs->addTo(fileMenu);
 
893
        fileClose->addTo(fileMenu);
 
894
        fileMenu->insertSeparator();
 
895
        fileMenu->insertItem(tr("&Import/Export"), importExportMenu);
 
896
        fileMenu->insertSeparator();
 
897
        fileQuit->addTo(fileMenu);
 
898
        
 
899
        // menuBar entry editMenu
 
900
        editMenu = new QPopupMenu();
 
901
        editMenu->insertTearOffHandle();
 
902
        editCut->addTo(editMenu);
 
903
        editPaste->addTo(editMenu);
 
904
        editPasteBrother->addTo(editMenu);
 
905
        editDelete->addTo(editMenu);
 
906
        editMenu->insertSeparator();
 
907
        editNumberMoves->addTo(editMenu);
 
908
        editMarkBrothers->addTo(editMenu);
 
909
        editMarkSons->addTo(editMenu);
 
910
        
 
911
        // menuBar entry navMenu
 
912
        navMenu = new QPopupMenu();
 
913
        navMenu->insertTearOffHandle();
 
914
        navFirst->addTo(navMenu);
 
915
        navBackward->addTo(navMenu);
 
916
        navForward->addTo(navMenu);
 
917
        navLast->addTo(navMenu);
 
918
        navMenu->insertSeparator();
 
919
        navMainBranch->addTo(navMenu);
 
920
        navStartVar->addTo(navMenu);
 
921
        navPrevVar->addTo(navMenu);
 
922
        navNextVar->addTo(navMenu);
 
923
        navNextBranch->addTo(navMenu);
 
924
        navMenu->insertSeparator();
 
925
        navNthMove->addTo(navMenu);
 
926
        navAutoplay->addTo(navMenu);
 
927
        navMenu->insertSeparator();
 
928
        navEmptyBranch->addTo(navMenu);
 
929
        navCloneNode->addTo(navMenu);
 
930
        navSwapVariations->addTo(navMenu);
 
931
        navMenu->insertSeparator();             //added eb
 
932
        navPrevComment->addTo(navMenu);
 
933
        navNextComment->addTo(navMenu);         // end add
 
934
 
 
935
        
 
936
        // menuBar entry settingsMenu
 
937
        settingsMenu = new QPopupMenu();
 
938
        settingsMenu->insertTearOffHandle();
 
939
        setPreferences->addTo(settingsMenu);
 
940
        setGameInfo->addTo(settingsMenu);
 
941
        
 
942
        // menuBar entry viewMenu
 
943
        viewMenu = new QPopupMenu();
 
944
        viewMenu->insertTearOffHandle();
 
945
        viewFileBar->addTo(viewMenu);
 
946
        viewToolBar->addTo(viewMenu);
 
947
        viewEditBar->addTo(viewMenu);
 
948
        viewMenuBar->addTo(viewMenu);
 
949
        viewStatusBar->addTo(viewMenu);
 
950
        viewCoords->addTo(viewMenu);
 
951
        viewSlider->addTo(viewMenu);
 
952
        viewSidebar->addTo(viewMenu);
 
953
        viewComment->addTo(viewMenu);
 
954
        viewVertComment->addTo(viewMenu);
 
955
        viewPinComment->addTo(viewMenu);
 
956
        viewMenu->insertSeparator();
 
957
        viewIncreaseSize->addTo(viewMenu);
 
958
        viewDecreaseSize->addTo(viewMenu);
 
959
        viewMenu->insertSeparator();
 
960
        viewSaveSize->addTo(viewMenu);
 
961
        viewMenu->insertSeparator();
 
962
        viewFullscreen->addTo(viewMenu);
 
963
        
 
964
        // menuBar entry helpMenu
 
965
        helpMenu = new QPopupMenu();
 
966
        helpManual->addTo(helpMenu);
 
967
        helpMenu->insertItem(wtIcon, tr("What's &This?"), this, SLOT(whatsThis()), SHIFT+Key_F1);
 
968
        helpMenu->insertSeparator();
 
969
        helpSoundInfo->addTo(helpMenu);
 
970
        helpMenu->insertSeparator();
 
971
        helpAboutApp->addTo(helpMenu);
 
972
        helpAboutQt->addTo(helpMenu);
 
973
        
 
974
        // menubar configuration
 
975
        menuBar()->insertItem(tr("&File"), fileMenu);
 
976
        menuBar()->insertItem(tr("&Edit"), editMenu);
 
977
        menuBar()->insertItem(tr("&Navigation"), navMenu);
 
978
        menuBar()->insertItem(tr("&Settings"), settingsMenu);
 
979
        menuBar()->insertItem(tr("&View"), viewMenu);
 
980
        menuBar()->insertSeparator();
 
981
        menuBar()->insertItem(tr("&Help"), helpMenu);
 
982
}
 
983
 
 
984
void MainWindow::initToolBar()
 
985
{
 
986
        // File toolbar
 
987
        fileBar = new QToolBar(this, "filebar");
 
988
        
 
989
        fileNew->addTo(fileBar);
 
990
        fileOpen->addTo(fileBar);
 
991
        fileSave->addTo(fileBar);
 
992
        fileSaveAs->addTo(fileBar);
 
993
        
 
994
        // Navigation toolbar
 
995
        toolBar = new QToolBar(this, "toolbar");
 
996
        
 
997
        navFirst->addTo(toolBar);
 
998
        navBackward->addTo(toolBar);
 
999
        navForward->addTo(toolBar);
 
1000
        navLast->addTo(toolBar);
 
1001
        
 
1002
        toolBar->addSeparator();
 
1003
        
 
1004
        navMainBranch->addTo(toolBar);
 
1005
        navStartVar->addTo(toolBar);
 
1006
        navPrevVar->addTo(toolBar);
 
1007
        navNextVar->addTo(toolBar);
 
1008
        navNextBranch->addTo(toolBar);
 
1009
        
 
1010
        toolBar->addSeparator();
 
1011
        navPrevComment->addTo(toolBar);        // added eb 2
 
1012
        navNextComment->addTo(toolBar);
 
1013
        navIntersection->addTo(toolBar);       //SL added eb 11
 
1014
        toolBar->addSeparator();               //end add eb 2
 
1015
        
 
1016
        navAutoplay->addTo(toolBar);
 
1017
        
 
1018
        toolBar->addSeparator();
 
1019
        
 
1020
        QWhatsThis::whatsThisButton(toolBar);
 
1021
        
 
1022
        toolBar->addSeparator();
 
1023
 
 
1024
//      setPreferences->addTo(toolBar);
 
1025
        setGameInfo->addTo(toolBar);
 
1026
        
 
1027
        // Edit toolbar
 
1028
        editBar = new QToolBar(this, "editbar");
 
1029
        
 
1030
        editCut->addTo(editBar);
 
1031
        editPaste->addTo(editBar);
 
1032
        editDelete->addTo(editBar);
 
1033
}
 
1034
 
 
1035
void MainWindow::initStatusBar()
 
1036
{
 
1037
        // The coords widget
 
1038
        statusTip = new StatusTip(statusBar());
 
1039
        statusBar()->addWidget(statusTip);
 
1040
        statusBar()->show();
 
1041
        statusBar()->setSizeGripEnabled(true);
 
1042
        statusBar()->message(tr("Ready."));  // Normal indicator
 
1043
        connect(statusTip, SIGNAL(clearStatusBar()), statusBar(), SLOT(clear()));
 
1044
        
 
1045
        // The turn widget
 
1046
        statusTurn = new QLabel(statusBar());
 
1047
        statusTurn->setAlignment(AlignCenter | SingleLine);
 
1048
        statusTurn->setText(" 0 ");
 
1049
        statusBar()->addWidget(statusTurn, 0, true);  // Permanent indicator
 
1050
        QToolTip::add(statusTurn, tr("Current move"));
 
1051
        QWhatsThis::add(statusTurn, tr("Move\nDisplays the number of the current turn and the last move played."));
 
1052
        
 
1053
        // The nav widget
 
1054
        statusNav = new QLabel(statusBar());
 
1055
        statusNav->setAlignment(AlignCenter | SingleLine);
 
1056
        statusNav->setText(" 0/0 ");
 
1057
        statusBar()->addWidget(statusNav, 0, true);  // Permanent indicator
 
1058
        QToolTip::add(statusNav, tr("Brothers / sons"));
 
1059
        QWhatsThis::add(statusNav, tr("Navigation\nShows the brothers and sons of the current move."));
 
1060
        
 
1061
        // The mode widget
 
1062
        statusMode = new QLabel(statusBar());
 
1063
        statusMode->setAlignment(AlignCenter | SingleLine);
 
1064
        statusMode->setText(" " + QObject::tr("N", "Board status line: normal mode") + " ");
 
1065
        statusBar()->addWidget(statusMode, 0, true);  // Permanent indicator
 
1066
        QToolTip::add(statusMode, tr("Current mode"));
 
1067
        QWhatsThis::add(statusMode,
 
1068
                tr("Mode\nShows the current mode. 'N' for normal mode, 'E' for edit mode."));
 
1069
        
 
1070
        // The mark widget
 
1071
        statusMark = new QLabel(statusBar());
 
1072
        statusMark->setAlignment(AlignCenter | SingleLine);
 
1073
        statusMark->setText(" - ");
 
1074
        statusBar()->addWidget(statusMark, 0, true);  // Permanent indicator
 
1075
        QToolTip::add(statusMark, tr("Current edit mark"));
 
1076
        QWhatsThis::add(statusMark, tr("Mark\nShows the current edit mark. '-' in normal mode."));
 
1077
}
 
1078
 
 
1079
void MainWindow::slotFileNewBoard()
 
1080
{
 
1081
        setting->qgo->addBoardWindow();
 
1082
}
 
1083
 
 
1084
void MainWindow::slotFileNewGame()
 
1085
{
 
1086
        if (!checkModified())
 
1087
                return;
 
1088
        
 
1089
        if (board->getGameMode() == modeNormal)
 
1090
        {
 
1091
                NewLocalGameDialog dlg(this, tr("newgame"), true);
 
1092
                
 
1093
                if (dlg.exec() == QDialog::Accepted)
 
1094
                {
 
1095
                        GameData *d = new GameData;
 
1096
                        d->size = dlg.boardSizeSpin->value();
 
1097
                        d->komi = (float)dlg.komiSpin->value() / 10.0;
 
1098
                        d->handicap = dlg.handicapSpin->value();
 
1099
                        d->playerBlack = dlg.playerBlackEdit->text();
 
1100
                        d->rankBlack = dlg.playerBlackRkEdit->text();
 
1101
                        d->playerWhite = dlg.playerWhiteEdit->text();
 
1102
                        d->rankWhite = dlg.playerWhiteRkEdit->text();
 
1103
                        d->gameName = "";
 
1104
                        d->gameNumber = 0;
 
1105
                        d->fileName = "";
 
1106
                        d->byoTime = dlg.byoTimeSpin->value();
 
1107
                        d->style = 1;
 
1108
                        board->initGame(d);
 
1109
                }
 
1110
        }
 
1111
        else
 
1112
        {
 
1113
                NewGameDialog dlg(this, tr("newgame"), true);
 
1114
                
 
1115
                if (dlg.exec() == QDialog::Accepted)
 
1116
                {
 
1117
                        GameData *d = new GameData;
 
1118
                        d->size = dlg.boardSizeSpin->value();
 
1119
                        d->komi = (float)dlg.komiSpin->value() / 10.0;
 
1120
                        d->handicap = dlg.handicapSpin->value();
 
1121
                        d->playerBlack = dlg.playerBlackEdit->text();
 
1122
                        d->playerWhite = dlg.playerWhiteEdit->text();
 
1123
                        d->gameName = "";
 
1124
                        d->gameNumber = 0;
 
1125
                        d->fileName = "";
 
1126
                        d->byoTime = dlg.byoTimeSpin->value();
 
1127
                        d->style = 1;
 
1128
                        board->initGame(d);
 
1129
                }
 
1130
        }
 
1131
 
 
1132
        interfaceHandler->normalTools->komi->setText(QString::number(board->getGameData()->komi));
 
1133
        interfaceHandler->normalTools->handicap->setText(QString::number(board->getGameData()->handicap));
 
1134
        
 
1135
        statusBar()->message(tr("New board prepared."));
 
1136
}
 
1137
 
 
1138
void MainWindow::slotFileOpen()
 
1139
{
 
1140
        if (!checkModified())
 
1141
                return;
 
1142
        QString fileName(QFileDialog::getOpenFileName(setting->readEntry("LAST_DIR"),
 
1143
                tr("SGF Files (*.sgf);;MGT Files (*.mgt);;XML Files (*.xml);;All Files (*)"), this));
 
1144
        if (fileName.isEmpty())
 
1145
                return;
 
1146
        doOpen(fileName, getFileExtension(fileName));
 
1147
}
 
1148
 
 
1149
QString MainWindow::getFileExtension(const QString &fileName, bool defaultExt)
 
1150
{
 
1151
        QString filter;
 
1152
        if (defaultExt)
 
1153
                filter = tr("SGF");
 
1154
        else
 
1155
                filter = "";
 
1156
        
 
1157
        int pos=0, oldpos=-1, len = fileName.length();
 
1158
        
 
1159
        while ((pos = fileName.find('.', ++pos)) != -1 && pos < len)
 
1160
                oldpos = pos;
 
1161
        
 
1162
        if (oldpos != -1)
 
1163
                filter = fileName.mid(oldpos+1, fileName.length()-pos).upper();
 
1164
        
 
1165
        return filter;
 
1166
}
 
1167
 
 
1168
void MainWindow::doOpen(const QString &fileName, const QString &filter, bool storedir)
 
1169
{
 
1170
        // qDebug("doOpen - fileName: %s - filter: %s", fileName.latin1(), filter.latin1());
 
1171
        
 
1172
        if (setting->readBoolEntry("REM_DIR") && storedir)
 
1173
                rememberLastDir(fileName);
 
1174
        
 
1175
        if (board->openSGF(fileName, filter))
 
1176
                statusBar()->message(fileName + " " + tr("loaded."));
 
1177
}
 
1178
 
 
1179
bool MainWindow::startComputerPlay(QNewGameDlg * dlg, const QString &fileName, const QString &filter, const QString &computer_path)
 
1180
{
 
1181
        GameData *d = new GameData;
 
1182
        d->size = dlg->getSize();
 
1183
        d->komi = dlg->getKomi();
 
1184
        d->handicap = dlg->getHandicap();
 
1185
        d->playerBlack = dlg->getPlayerBlackName();
 
1186
        //d->rankBlack = dlg.playerBlackRkEdit->text();
 
1187
        d->playerWhite = dlg->getPlayerWhiteName();
 
1188
        //d->rankWhite = dlg.playerWhiteRkEdit->text();
 
1189
        d->gameName = "";
 
1190
        d->gameNumber = 0;
 
1191
        d->fileName = "";
 
1192
        d->byoTime = dlg->getTime();
 
1193
        d->style = 1;
 
1194
        d->oneColorGo = dlg->getOneColorGo();
 
1195
 
 
1196
        blackPlayerType = dlg->getPlayerBlackType();
 
1197
        whitePlayerType = dlg->getPlayerWhiteType();
 
1198
 
 
1199
        board->initGame(d);
 
1200
 
 
1201
        if (!board->startComputerPlay(dlg,fileName, filter, computer_path))
 
1202
                return false;
 
1203
 
 
1204
        return true;
 
1205
}
 
1206
 
 
1207
bool MainWindow::slotFileSave()
 
1208
{
 
1209
        QString fileName;
 
1210
        if ((fileName = board->getGameData()->fileName).isEmpty())
 
1211
        {
 
1212
                if (setting->readBoolEntry("REM_DIR"))
 
1213
                        fileName = setting->readEntry("LAST_DIR:");
 
1214
                else
 
1215
                        fileName = QString::null;
 
1216
                return doSave(fileName, false);
 
1217
        }
 
1218
        else
 
1219
                return doSave(board->getGameData()->fileName, true);
 
1220
}
 
1221
 
 
1222
bool MainWindow::slotFileSaveAs()
 
1223
{
 
1224
        if (setting->readBoolEntry("REM_DIR"))
 
1225
                return doSave(setting->readEntry("LAST_DIR"), false);
 
1226
        return doSave(0, false);
 
1227
}
 
1228
 
 
1229
bool MainWindow::doSave(QString fileName, bool force)
 
1230
{
 
1231
        if (!force)
 
1232
  {
 
1233
        if (fileName == NULL ||
 
1234
          fileName.isNull() ||
 
1235
          fileName.isEmpty() ||
 
1236
          QDir(fileName).exists())
 
1237
            {
 
1238
 
 
1239
              QString base = board->getCandidateFileName();
 
1240
              if (fileName == NULL || fileName.isNull() || fileName.isEmpty())
 
1241
                fileName = base;
 
1242
              else
 
1243
                fileName.append(base);
 
1244
              /*
 
1245
              int i = 1;
 
1246
              while (QFile(fileName).exists())
 
1247
              {
 
1248
 
 
1249
                QString number ;
 
1250
                number = number.number(i++);
 
1251
                fileName = base + "-";
 
1252
                fileName = fileName + number;
 
1253
                fileName = fileName + ".sgf";
 
1254
              } */
 
1255
            }   
 
1256
 
 
1257
 
 
1258
                fileName = QFileDialog::getSaveFileName(fileName,
 
1259
                  tr("SGF Files (*.sgf);;All Files (*)"),
 
1260
                  this);
 
1261
          }
 
1262
        if (fileName.isEmpty())
 
1263
                return false;
 
1264
        
 
1265
        if (getFileExtension(fileName, false).isEmpty())
 
1266
                fileName.append(".sgf");
 
1267
        
 
1268
        // Confirm overwriting file.
 
1269
        if (!force && QFile(fileName).exists())
 
1270
                if (QMessageBox::information(this, PACKAGE,
 
1271
                        tr("This file already exists. Do you want to overwrite it?"),
 
1272
                        tr("Yes"), tr("No"), 0, 0, 1) == 1)
 
1273
                        return false;
 
1274
                
 
1275
                board->getGameData()->fileName = fileName;
 
1276
                
 
1277
                if (setting->readBoolEntry("REM_DIR"))
 
1278
                        rememberLastDir(fileName);
 
1279
                
 
1280
                if (!board->saveBoard(fileName))
 
1281
                {
 
1282
                        QMessageBox::warning(this, PACKAGE, tr("Cannot save SGF file."));
 
1283
                        return false;
 
1284
                }
 
1285
                
 
1286
                statusBar()->message(fileName + " " + tr("saved."));
 
1287
                board->setModified(false);
 
1288
                return true;
 
1289
}
 
1290
 
 
1291
void MainWindow::slotFileClose()
 
1292
{
 
1293
        if (checkModified() == 1)
 
1294
        {
 
1295
                board->setModified(false);  // Prevent to ask a second time in qGo::quit()
 
1296
                close();
 
1297
        }
 
1298
}
 
1299
 
 
1300
void MainWindow::slotFileImportSgfClipB()
 
1301
{
 
1302
        // check wheter it's an edit board during online game
 
1303
        if (getInterfaceHandler()->refreshButton->text() != tr("Update") && !checkModified())
 
1304
                return;
 
1305
        
 
1306
        if (!board->importSGFClipboard())
 
1307
                QMessageBox::warning(this, PACKAGE, tr("Cannot load from clipboard. Is it empty?"));
 
1308
        else
 
1309
                statusBar()->message(tr("SGF imported."));
 
1310
}
 
1311
 
 
1312
void MainWindow::slotFileExportSgfClipB()
 
1313
{
 
1314
        if (!board->exportSGFtoClipB())
 
1315
                QMessageBox::warning(this, PACKAGE, tr("Failed to export SGF to clipboard."));
 
1316
        else
 
1317
                statusBar()->message(tr("SGF exported."));
 
1318
}
 
1319
 
 
1320
void MainWindow::slotFileImportASCII()
 
1321
{
 
1322
        QString fileName(QFileDialog::getOpenFileName(QString::null,
 
1323
                tr("Text Files (*.txt);;All Files (*)"),
 
1324
                this));
 
1325
        if (fileName.isEmpty())
 
1326
                return;
 
1327
        
 
1328
        board->importASCII(fileName);
 
1329
        statusBar()->message(tr("ASCII imported."));
 
1330
}
 
1331
 
 
1332
void MainWindow::slotFileImportASCIIClipB()
 
1333
{
 
1334
        if (!board->importASCII(NULL, true))
 
1335
                QMessageBox::warning(this, PACKAGE, tr("Importing ASCII failed. Clipboard empty?"));
 
1336
        else
 
1337
                statusBar()->message(tr("ASCII imported."));
 
1338
}
 
1339
 
 
1340
void MainWindow::slotFileExportASCII()
 
1341
{
 
1342
        board->exportASCII();
 
1343
        statusBar()->message(tr("Ready."));
 
1344
}
 
1345
 
 
1346
void MainWindow::slotFileExportPic()
 
1347
{
 
1348
   QString *filter = new QString("");
 
1349
   QString fileName = QFileDialog::getSaveFileName(
 
1350
    "",
 
1351
                "PNG (*.png);;BMP (*.bmp);;XPM (*.xpm);;XBM (*.xbm);;PNM (*.pnm);;GIF (*.gif);;JPEG (*.jpeg);;MNG (*.mng)",
 
1352
                this,
 
1353
    "qGo",
 
1354
    tr("Export image as"),
 
1355
    filter,
 
1356
    true);
 
1357
 
 
1358
 
 
1359
                if (fileName.isEmpty())
 
1360
                        return;
 
1361
 
 
1362
    //fileName.append(".").append(filter->left(3).lower());
 
1363
    
 
1364
                // Confirm overwriting file.
 
1365
                if ( QFile::exists( fileName ) )
 
1366
                        if (QMessageBox::information(this, PACKAGE,
 
1367
                                tr("This file already exists. Do you want to overwrite it?"),
 
1368
                                tr("Yes"), tr("No"), 0, 0, 1) == 1)
 
1369
                                return;
 
1370
                        
 
1371
                        //QString filter = dlg.selectedFilter().left(3);
 
1372
                        board->exportPicture(fileName, filter->left(3));
 
1373
//      }
 
1374
}
 
1375
 
 
1376
void MainWindow::slotFileExportPicClipB()
 
1377
{
 
1378
        board->exportPicture(NULL, NULL, true); 
 
1379
}
 
1380
 
 
1381
void MainWindow::slotEditCut()
 
1382
{
 
1383
        board->cutNode();
 
1384
}
 
1385
 
 
1386
void MainWindow::slotEditPaste()
 
1387
{
 
1388
        board->pasteNode();
 
1389
}
 
1390
 
 
1391
void MainWindow::slotEditPasteBrother()
 
1392
{
 
1393
        board->pasteNode(true);
 
1394
}
 
1395
 
 
1396
void MainWindow::slotEditDelete()
 
1397
{
 
1398
        board->deleteNode();
 
1399
}
 
1400
 
 
1401
void MainWindow::slotEditNumberMoves()
 
1402
{
 
1403
        board->numberMoves();
 
1404
}
 
1405
 
 
1406
void MainWindow::slotEditMarkBrothers()
 
1407
{
 
1408
        board->markVariations(false);
 
1409
}
 
1410
 
 
1411
void MainWindow::slotEditMarkSons()
 
1412
{
 
1413
        board->markVariations(true);
 
1414
}
 
1415
 
 
1416
void MainWindow::slotNavBackward()
 
1417
{
 
1418
        board->previousMove();
 
1419
}
 
1420
 
 
1421
void MainWindow::slotNavForward()
 
1422
{
 
1423
        board->nextMove();
 
1424
}
 
1425
 
 
1426
void MainWindow::slotNavFirst()
 
1427
{
 
1428
        board->gotoFirstMove();
 
1429
}
 
1430
 
 
1431
void MainWindow::slotNavLast()
 
1432
{
 
1433
        board->gotoLastMove();
 
1434
}
 
1435
 
 
1436
// this slot is used for edit window to navigate to last made move
 
1437
void MainWindow::slotNavLastByTime()
 
1438
{
 
1439
        board->gotoLastMoveByTime();
 
1440
}
 
1441
 
 
1442
void MainWindow::slotNavNextVar()
 
1443
{
 
1444
        board->nextVariation();
 
1445
}
 
1446
 
 
1447
void MainWindow::slotNavPrevVar()
 
1448
{
 
1449
        board->previousVariation();
 
1450
}
 
1451
 
 
1452
void MainWindow::slotNavNextComment()    //added eb
 
1453
{
 
1454
        board->nextComment();
 
1455
}
 
1456
 
 
1457
void MainWindow::slotNavPrevComment()
 
1458
{
 
1459
        board->previousComment();
 
1460
}                                        //end add eb
 
1461
 
 
1462
void MainWindow::slotNavStartVar()
 
1463
{
 
1464
        board->gotoVarStart();
 
1465
}
 
1466
 
 
1467
void MainWindow::slotNavMainBranch()
 
1468
{
 
1469
        board->gotoMainBranch();
 
1470
}
 
1471
 
 
1472
void MainWindow::slotNavNextBranch()
 
1473
{
 
1474
        board->gotoNextBranch();
 
1475
}
 
1476
 
 
1477
void MainWindow::slotNavIntersection()       // added eb 11
 
1478
{
 
1479
    board->navIntersection();
 
1480
}
 
1481
                                     // end add eb 11
 
1482
 
 
1483
 
 
1484
void MainWindow::slotNavNthMove()
 
1485
{
 
1486
        NthMoveDialog dlg(this, tr("entermove"), true);
 
1487
        dlg.moveSpinBox->setValue(board->getCurrentMoveNumber());
 
1488
        dlg.moveSpinBox->setFocus();
 
1489
        
 
1490
        if (dlg.exec() == QDialog::Accepted)
 
1491
                board->gotoNthMove(dlg.moveSpinBox->value());
 
1492
}
 
1493
 
 
1494
void MainWindow::slotNavAutoplay(bool toggle)
 
1495
{
 
1496
        if (!toggle)
 
1497
        {
 
1498
                timer->stop();
 
1499
                statusBar()->message(tr("Autoplay stopped."));
 
1500
        }
 
1501
        else
 
1502
        {
 
1503
                if (setting->readIntEntry("TIMER_INTERVAL") < 0)
 
1504
                        setting->writeIntEntry("TIMER_INTERVAL", 0);
 
1505
                else if (setting->readIntEntry("TIMER_INTERVAL") > 5)
 
1506
                        setting->writeIntEntry("TIMER_INTERVAL", 5);
 
1507
                // check if time info available from sgf file
 
1508
                if (setting->readBoolEntry("SGF_TIME_TAGS") && board->getGameData()->timeSystem != none)
 
1509
                        // set time to 1 sec
 
1510
                        timer->start(1000);
 
1511
                else
 
1512
                        // set time interval as selected
 
1513
                        timer->start(int(timerIntervals[setting->readIntEntry("TIMER_INTERVAL")] * 1000));
 
1514
                statusBar()->message(tr("Autoplay started."));
 
1515
        }
 
1516
}
 
1517
 
 
1518
void MainWindow::slotNavEmptyBranch()
 
1519
{
 
1520
        board->clearNode();
 
1521
}
 
1522
 
 
1523
void MainWindow::slotNavCloneNode()
 
1524
{
 
1525
        board->duplicateNode();
 
1526
        statusBar()->message(tr("Variation duplicated."));
 
1527
}
 
1528
 
 
1529
void MainWindow::slotNavSwapVariations()
 
1530
{
 
1531
        if (board->swapVariations())
 
1532
                statusBar()->message(tr("Variations swapped."));
 
1533
        else
 
1534
                statusBar()->message(tr("No previous variation available."));
 
1535
}
 
1536
 
 
1537
void MainWindow::slotSetPreferences()
 
1538
{
 
1539
        // default tab
 
1540
        dlgSetPreferences(-1);
 
1541
}
 
1542
 
 
1543
void MainWindow::dlgSetPreferences(int tab)
 
1544
{
 
1545
        PreferencesDialog dlg(this, tr("preferences"), true);
 
1546
 
 
1547
        if (tab >= 0)
 
1548
        {
 
1549
                // set to default tab - no check for Qt 2.3.x
 
1550
                if (dlg.tabWidget->count() <= tab+1)
 
1551
                        dlg.tabWidget->setCurrentPage(tab);
 
1552
        }
 
1553
 
 
1554
        // Interface tab
 
1555
        dlg.styleListBox->setCurrentItem(setting->readIntEntry("STYLE"));
 
1556
        dlg.woodListBox->setCurrentItem(setting->readIntEntry("SKIN"));
 
1557
        dlg.languageComboBox->insertStringList(setting->getAvailableLanguages());
 
1558
        dlg.languageComboBox->setCurrentItem(setting->convertLanguageCodeToNumber());
 
1559
        dlg.commentComboBox->setCurrentItem(setting->readIntEntry("VIEW_COMMENT"));
 
1560
        dlg.stonesShadowCheckBox->setChecked(setting->readBoolEntry("STONES_SHADOW"));
 
1561
        dlg.stonesShellsCheckBox->setChecked(setting->readBoolEntry("STONES_SHELLS"));
 
1562
        dlg.stoneSoundCheckBox->setChecked(setting->readBoolEntry("SOUND_STONE"));
 
1563
        dlg.autoplaySoundCheckBox->setChecked(setting->readBoolEntry("SOUND_AUTOPLAY"));
 
1564
        dlg.talkSoundCheckBox->setChecked(setting->readBoolEntry("SOUND_TALK"));
 
1565
        dlg.matchSoundCheckBox->setChecked(setting->readBoolEntry("SOUND_MATCH"));
 
1566
        dlg.passSoundCheckBox->setChecked(setting->readBoolEntry("SOUND_PASS"));
 
1567
        dlg.gameEndSoundCheckBox->setChecked(setting->readBoolEntry("SOUND_GAMEEND"));
 
1568
        dlg.timeSoundCheckBox->setChecked(setting->readBoolEntry("SOUND_TIME"));
 
1569
        dlg.saySoundCheckBox->setChecked(setting->readBoolEntry("SOUND_SAY"));
 
1570
        dlg.enterSoundCheckBox->setChecked(setting->readBoolEntry("SOUND_ENTER"));
 
1571
        dlg.leaveSoundCheckBox->setChecked(setting->readBoolEntry("SOUND_LEAVE"));
 
1572
        dlg.disConnectSoundCheckBox->setChecked(setting->readBoolEntry("SOUND_DISCONNECT"));
 
1573
        dlg.connectSoundCheckBox->setChecked(setting->readBoolEntry("SOUND_CONNECT"));
 
1574
        dlg.variationComboBox->setCurrentItem(setting->readIntEntry("VAR_GHOSTS"));
 
1575
        dlg.coordsCheckBox->setChecked(setting->readBoolEntry("BOARD_COORDS"));
 
1576
        dlg.toolTipCoordsCheckBox->setChecked(setting->readBoolEntry("BOARD_COORDS_TIP"));
 
1577
        dlg.cursorCheckBox->setChecked(setting->readBoolEntry("CURSOR"));
 
1578
        dlg.smallerMarksCheckBox->setChecked(setting->readBoolEntry("SMALL_MARKS"));
 
1579
        dlg.boldMarksCheckBox->setChecked(setting->readBoolEntry("BOLD_MARKS"));
 
1580
        dlg.adjustFontSizeCheckBox->setChecked(setting->readBoolEntry("ADJ_FONT"));
 
1581
        dlg.smallerStonesCheckBox->setChecked(setting->readBoolEntry("SMALL_STONES"));
 
1582
        dlg.tooltipsCheckBox->setChecked(!(setting->readBoolEntry("TOOLTIPS")));
 
1583
        dlg.timerComboBox->setCurrentItem(setting->readIntEntry("TIMER_INTERVAL"));
 
1584
  dlg.BYTimeSpin->setValue(setting->readIntEntry("BY_TIMER"));
 
1585
        dlg.sgfTimeTagsCheckBox->setChecked(setting->readBoolEntry("SGF_TIME_TAGS"));
 
1586
        dlg.sliderCheckBox->setChecked(setting->readBoolEntry("SLIDER"));
 
1587
        dlg.sidebarCheckBox->setChecked(setting->readBoolEntry("SIDEBAR"));
 
1588
        dlg.sidebarLeftCheckBox->setChecked(setting->readBoolEntry("SIDEBAR_LEFT"));
 
1589
//      dlg.rememberFontCheckBox->setChecked(setting->readBoolEntry("REM_FONT"));
 
1590
        dlg.variableFontCheckBox->setChecked(setting->readBoolEntry("VAR_FONT"));
 
1591
        
 
1592
        // Import tab
 
1593
        dlg.blackStoneEdit->setText(QString(QChar(setting->charset->blackStone)));
 
1594
        dlg.whiteStoneEdit->setText(QString(QChar(setting->charset->whiteStone)));
 
1595
        dlg.starPointEdit->setText(QString(QChar(setting->charset->starPoint)));
 
1596
        dlg.emptyPointEdit->setText(QString(QChar(setting->charset->emptyPoint)));
 
1597
        dlg.hBorderEdit->setText(QString(QChar(setting->charset->hBorder)));
 
1598
        dlg.vBorderEdit->setText(QString(QChar(setting->charset->vBorder)));
 
1599
        dlg.addBrotherCheckBox->setChecked(setting->addImportAsBrother);
 
1600
        
 
1601
        // SGF Loading tab
 
1602
        dlg.fastLoadCheckBox->setChecked(board->fastLoad);
 
1603
        dlg.rememberDirCheckBox->setChecked(setting->readBoolEntry("REM_DIR"));
 
1604
        dlg.codecListBox->setCurrentItem(setting->readIntEntry("CODEC"));
 
1605
 
 
1606
        // Client Window tab
 
1607
        dlg.LineEdit_watch->setText(setting->readEntry("WATCH"));
 
1608
        dlg.LineEdit_exclude->setText(setting->readEntry("EXCLUDE"));
 
1609
        dlg.CheckBox_extUserInfo->setChecked(setting->readBoolEntry("EXTUSERINFO"));
 
1610
        dlg.LineEdit_computer->setText(setting->readEntry("COMPUTER_PATH")); //SL added eb 12
 
1611
        dlg.computerButtonWhite->setChecked(setting->readBoolEntry("COMPUTER_WHITE"));
 
1612
        dlg.computerButtonBlack->setChecked(setting->readBoolEntry("COMPUTER_BLACK"));
 
1613
        dlg.humanButtonWhite->setChecked(!setting->readBoolEntry("COMPUTER_WHITE"));
 
1614
        dlg.humanButtonBlack->setChecked(!setting->readBoolEntry("COMPUTER_BLACK"));
 
1615
        dlg.computerSizeSpin->setValue(setting->readIntEntry("COMPUTER_SIZE"));
 
1616
        dlg.computerHandicapSpin->setValue(setting->readIntEntry("COMPUTER_HANDICAP")); 
 
1617
        
 
1618
        
 
1619
        
 
1620
        // Go Server tab
 
1621
        dlg.boardSizeSpin->setValue(setting->readIntEntry("DEFAULT_SIZE"));
 
1622
        dlg.timeSpin->setValue(setting->readIntEntry("DEFAULT_TIME"));
 
1623
        dlg.BYSpin->setValue(setting->readIntEntry("DEFAULT_BY"));
 
1624
        dlg.komiSpinDefault->setValue(setting->readIntEntry("DEFAULT_KOMI"));
 
1625
        dlg.automaticNegotiationCheckBox->setChecked(setting->readBoolEntry("DEFAULT_AUTONEGO"));
 
1626
 
 
1627
        /*
 
1628
        // do some size changes
 
1629
        QSize qs = dlg.pb_add->minimumSizeHint();
 
1630
        if (dlg.pb_new->minimumSizeHint().width() > qs.width())
 
1631
                qs = dlg.pb_new->minimumSizeHint();
 
1632
        if (dlg.pb_delete->minimumSizeHint().width() > qs.width())
 
1633
                qs = dlg.pb_delete->minimumSizeHint();
 
1634
 
 
1635
        if (qs.width() > 0)
 
1636
        {
 
1637
                dlg.pb_add->setMaximumSize(qs);
 
1638
                dlg.pb_new->setMaximumSize(qs);
 
1639
                dlg.pb_delete->setMaximumSize(qs);
 
1640
        }
 
1641
        dlg.pb_add->resize( QSize().expandedTo(qs));
 
1642
        dlg.pb_new->resize( QSize().expandedTo(qs));
 
1643
        dlg.pb_delete->resize( QSize().expandedTo(qs));
 
1644
*/
 
1645
        if (dlg.exec() == QDialog::Accepted)
 
1646
        {
 
1647
                preferencesSave(&dlg);
 
1648
                preferencesAccept();
 
1649
        }
 
1650
}
 
1651
 
 
1652
bool MainWindow::preferencesSave(PreferencesDialog *dlg)
 
1653
{
 
1654
        ASSERT (dlg);
 
1655
 
 
1656
        setting->writeIntEntry("STYLE", dlg->styleListBox->currentItem());
 
1657
        setting->writeIntEntry("SKIN", dlg->woodListBox->currentItem());
 
1658
        setting->writeEntry("LANG", setting->convertNumberToLanguage(dlg->languageComboBox->currentItem()));
 
1659
        setting->writeIntEntry("VIEW_COMMENT", dlg->commentComboBox->currentItem());
 
1660
        setting->writeBoolEntry("STONES_SHADOW", dlg->stonesShadowCheckBox->isChecked());
 
1661
        setting->writeBoolEntry("STONES_SHELLS", dlg->stonesShellsCheckBox->isChecked());
 
1662
        setting->writeBoolEntry("SOUND_STONE", dlg->stoneSoundCheckBox->isChecked());
 
1663
        setting->writeBoolEntry("SOUND_AUTOPLAY", dlg->autoplaySoundCheckBox->isChecked());
 
1664
        setting->writeBoolEntry("SOUND_TALK", dlg->talkSoundCheckBox->isChecked());
 
1665
        setting->writeBoolEntry("SOUND_MATCH", dlg->matchSoundCheckBox->isChecked());
 
1666
        setting->writeBoolEntry("SOUND_GAMEEND", dlg->passSoundCheckBox->isChecked());
 
1667
        setting->writeBoolEntry("SOUND_PASS", dlg->gameEndSoundCheckBox->isChecked());
 
1668
        setting->writeBoolEntry("SOUND_TIME", dlg->timeSoundCheckBox->isChecked());
 
1669
        setting->writeBoolEntry("SOUND_SAY", dlg->saySoundCheckBox->isChecked());
 
1670
        setting->writeBoolEntry("SOUND_ENTER", dlg->enterSoundCheckBox->isChecked());
 
1671
        setting->writeBoolEntry("SOUND_LEAVE", dlg->leaveSoundCheckBox->isChecked());
 
1672
        setting->writeBoolEntry("SOUND_DISCONNECT", dlg->disConnectSoundCheckBox->isChecked());
 
1673
        setting->writeBoolEntry("SOUND_CONNECT", dlg->connectSoundCheckBox->isChecked());
 
1674
        setting->writeIntEntry("VAR_GHOSTS", dlg->variationComboBox->currentItem());
 
1675
        setting->writeBoolEntry("BOARD_COORDS", dlg->coordsCheckBox->isChecked());
 
1676
        setting->writeBoolEntry("SLIDER", dlg->sliderCheckBox->isChecked());
 
1677
        setting->writeBoolEntry("SIDEBAR", dlg->sidebarCheckBox->isChecked());
 
1678
        setting->writeBoolEntry("SIDEBAR_LEFT", dlg->sidebarLeftCheckBox->isChecked());
 
1679
        setting->writeBoolEntry("BOARD_COORDS_TIP", dlg->toolTipCoordsCheckBox->isChecked());
 
1680
        setting->writeBoolEntry("CURSOR", dlg->cursorCheckBox->isChecked());
 
1681
        setting->writeBoolEntry("SMALL_MARKS", dlg->smallerMarksCheckBox->isChecked());
 
1682
        setting->writeBoolEntry("BOLD_MARKS", dlg->boldMarksCheckBox->isChecked());
 
1683
        setting->writeBoolEntry("ADJ_FONT", dlg->adjustFontSizeCheckBox->isChecked());
 
1684
        setting->writeBoolEntry("SMALL_STONES", dlg->smallerStonesCheckBox->isChecked());
 
1685
        setting->writeBoolEntry("TOOLTIPS", !(dlg->tooltipsCheckBox->isChecked()));
 
1686
        setting->writeIntEntry("BY_TIMER", dlg->BYTimeSpin->text().toInt());
 
1687
        setting->writeIntEntry("TIMER_INTERVAL", dlg->timerComboBox->currentItem());
 
1688
        setting->writeBoolEntry("SGF_TIME_TAGS", dlg->sgfTimeTagsCheckBox->isChecked());
 
1689
        setting->charset->blackStone = dlg->blackStoneEdit->text().at(0).latin1();
 
1690
        setting->charset->whiteStone = dlg->whiteStoneEdit->text().at(0).latin1();
 
1691
        setting->charset->starPoint = dlg->starPointEdit->text().at(0).latin1();
 
1692
        setting->charset->emptyPoint = dlg->emptyPointEdit->text().at(0).latin1();
 
1693
        setting->charset->hBorder = dlg->hBorderEdit->text().at(0).latin1();
 
1694
        setting->charset->vBorder = dlg->vBorderEdit->text().at(0).latin1();
 
1695
        setting->addImportAsBrother = dlg->addBrotherCheckBox->isChecked();
 
1696
        setting->fastLoad = dlg->fastLoadCheckBox->isChecked();
 
1697
        setting->writeBoolEntry("REM_DIR", dlg->rememberDirCheckBox->isChecked());
 
1698
//      setting->writeBoolEntry("REM_FONT", dlg->rememberFontCheckBox->isChecked());
 
1699
        setting->writeBoolEntry("VAR_FONT", dlg->variableFontCheckBox->isChecked());
 
1700
        setting->writeIntEntry("CODEC", dlg->codecListBox->currentItem());
 
1701
 
 
1702
        // Client Window Tab
 
1703
        setting->writeEntry("WATCH", dlg->LineEdit_watch->text());
 
1704
        setting->writeEntry("EXCLUDE", dlg->LineEdit_exclude->text());
 
1705
        setting->writeBoolEntry("EXTUSERINFO", dlg->CheckBox_extUserInfo->isChecked());
 
1706
        setting->writeIntEntry("DEFAULT_SIZE", dlg->boardSizeSpin->text().toInt());
 
1707
        setting->writeIntEntry("DEFAULT_TIME", dlg->timeSpin->text().toInt());
 
1708
        setting->writeIntEntry("DEFAULT_BY", dlg->BYSpin->text().toInt());
 
1709
        setting->writeIntEntry("DEFAULT_KOMI", dlg->komiSpinDefault->text().toFloat());
 
1710
        setting->writeBoolEntry("DEFAULT_AUTONEGO", dlg->automaticNegotiationCheckBox->isChecked());
 
1711
        
 
1712
        
 
1713
        // Computer Tab
 
1714
        setting->writeEntry("COMPUTER_PATH", dlg->LineEdit_computer->text()); //SL added eb 12
 
1715
        setting->writeBoolEntry("COMPUTER_WHITE", dlg->computerButtonWhite->isChecked());
 
1716
        setting->writeBoolEntry("COMPUTER_BLACK", dlg->computerButtonBlack->isChecked());
 
1717
        setting->writeIntEntry("COMPUTER_SIZE", dlg->computerSizeSpin->text().toInt());
 
1718
        setting->writeIntEntry("COMPUTER_HANDICAP", dlg->computerHandicapSpin->text().toInt());
 
1719
        
 
1720
        return true;
 
1721
}
 
1722
 
 
1723
void MainWindow::updateBoard()
 
1724
{
 
1725
 
 
1726
        viewSlider->setOn(setting->readBoolEntry("SLIDER"));
 
1727
        viewSidebar->setOn(setting->readBoolEntry("SIDEBAR"));
 
1728
        viewCoords->setOn(setting->readBoolEntry("BOARD_COORDS"));
 
1729
//      viewComment->setOn(setting->readIntEntry("VIEW_COMMENT"));
 
1730
 
 
1731
        if (setting->readIntEntry("VIEW_COMMENT"))
 
1732
        {
 
1733
//              viewVertComment->setEnabled(true);
 
1734
                viewVertComment->setOn(setting->readIntEntry("VIEW_COMMENT") == 2);
 
1735
        }
 
1736
 
 
1737
        
 
1738
        QToolTip::setEnabled(setting->readBoolEntry("TOOLTIPS"));
 
1739
 
 
1740
        if (timer->isActive())
 
1741
        {
 
1742
                if (setting->readBoolEntry("SGF_TIME_TAGS") && board->getGameData()->timeSystem != none)
 
1743
                        timer->changeInterval(1000);
 
1744
                else
 
1745
                        timer->changeInterval(int(timerIntervals[setting->readIntEntry("TIMER_INVERVAL")] * 1000));
 
1746
        }
 
1747
        
 
1748
        // SGF Loading tab
 
1749
        board->fastLoad = setting->fastLoad;
 
1750
 
 
1751
        slotViewLeftSidebar();
 
1752
        board->setVariationDisplay(static_cast<VariationDisplay>(setting->readIntEntry("VAR_GHOSTS")));
 
1753
        board->setShowCursor(setting->readBoolEntry("CURSOR"));
 
1754
        board->changeSize();  // For smaller stones
 
1755
}
 
1756
 
 
1757
bool MainWindow::preferencesAccept()
 
1758
{
 
1759
        // Interface tab
 
1760
        setApplicationStyle();
 
1761
 
 
1762
        // Update all boards with settings
 
1763
        setting->qgo->updateAllBoardSettings();
 
1764
        setting->qgo->updateFont();
 
1765
        
 
1766
        return true;//result;
 
1767
}
 
1768
 
 
1769
void MainWindow::slotSetGameInfo()
 
1770
{
 
1771
        GameInfoDialog dlg(this, "gameinfo", true);
 
1772
        
 
1773
        dlg.playerWhiteEdit->setText(board->getGameData()->playerWhite);
 
1774
        
 
1775
        dlg.playerBlackEdit->setText(board->getGameData()->playerBlack);
 
1776
        dlg.whiteRankEdit->setText(board->getGameData()->rankWhite);
 
1777
        dlg.blackRankEdit->setText(board->getGameData()->rankBlack);
 
1778
        dlg.komiSpin->setValue((int)(board->getGameData()->komi * 10.0));
 
1779
        dlg.handicapSpin->setValue(board->getGameData()->handicap);
 
1780
        dlg.resultEdit->setText(board->getGameData()->result);
 
1781
        dlg.dateEdit->setText(board->getGameData()->date);
 
1782
        dlg.placeEdit->setText(board->getGameData()->place);
 
1783
        dlg.copyrightEdit->setText(board->getGameData()->copyright);
 
1784
        dlg.gameNameEdit->setText(board->getGameData()->gameName);
 
1785
 
 
1786
        if (dlg.exec() == QDialog::Accepted)
 
1787
        {
 
1788
                board->getGameData()->playerWhite = dlg.playerWhiteEdit->text();
 
1789
                board->getGameData()->playerBlack = dlg.playerBlackEdit->text();
 
1790
                board->getGameData()->rankWhite = dlg.whiteRankEdit->text();
 
1791
                board->getGameData()->rankBlack = dlg.blackRankEdit->text();
 
1792
                board->getGameData()->komi = (float)dlg.komiSpin->value() / 10.0;
 
1793
                board->getGameData()->handicap = dlg.handicapSpin->value();
 
1794
                board->getGameData()->result = dlg.resultEdit->text();
 
1795
                board->getGameData()->date = dlg.dateEdit->text();
 
1796
                board->getGameData()->place = dlg.placeEdit->text();
 
1797
                board->getGameData()->copyright = dlg.copyrightEdit->text();
 
1798
                board->getGameData()->gameName = dlg.gameNameEdit->text();
 
1799
                
 
1800
                board->isModified = true;
 
1801
                board->updateCaption();  // Update caption in any case
 
1802
        }
 
1803
 
 
1804
        interfaceHandler->normalTools->komi->setText(QString::number(board->getGameData()->komi));
 
1805
        interfaceHandler->normalTools->handicap->setText(QString::number(board->getGameData()->handicap));
 
1806
}
 
1807
 
 
1808
void MainWindow::slotViewFileBar(bool toggle)
 
1809
{
 
1810
        if (!toggle)
 
1811
                fileBar->hide();
 
1812
        else
 
1813
                fileBar->show();
 
1814
        
 
1815
        setting->writeBoolEntry("FILEBAR", toggle);
 
1816
        
 
1817
        statusBar()->message(tr("Ready."));
 
1818
}
 
1819
 
 
1820
void MainWindow::slotViewToolBar(bool toggle)
 
1821
{
 
1822
 
 
1823
        if (!toggle)
 
1824
                toolBar->hide();
 
1825
        else
 
1826
                toolBar->show();
 
1827
 
 
1828
        setting->writeBoolEntry("TOOLBAR", toggle);
 
1829
        
 
1830
        statusBar()->message(tr("Ready."));
 
1831
}
 
1832
 
 
1833
void MainWindow::slotViewEditBar(bool toggle)
 
1834
{
 
1835
        if (!toggle)
 
1836
                editBar->hide();
 
1837
        else
 
1838
                editBar->show();
 
1839
        
 
1840
        setting->writeBoolEntry("EDITBAR", toggle);
 
1841
        
 
1842
        statusBar()->message(tr("Ready."));
 
1843
}
 
1844
 
 
1845
void MainWindow::slotViewMenuBar(bool toggle)
 
1846
{
 
1847
        if (!toggle)
 
1848
                menuBar()->hide();
 
1849
        else
 
1850
                menuBar()->show();
 
1851
        
 
1852
        statusBar()->message(tr("Ready."));
 
1853
}
 
1854
 
 
1855
void MainWindow::slotViewStatusBar(bool toggle)
 
1856
{
 
1857
        if (!toggle)
 
1858
        {
 
1859
                statusBar()->hide();
 
1860
                // Disconnect this signal, if the statusbar is hidden, we dont need it
 
1861
                disconnect(board, SIGNAL(coordsChanged(int, int, int)), statusTip, SLOT(slotStatusTipCoords(int, int, int)));
 
1862
        }
 
1863
        else
 
1864
        {
 
1865
                statusBar()->show();
 
1866
                // Connect the mouseMove event of the board with the status bar coords widget
 
1867
                connect(board, SIGNAL(coordsChanged(int, int, int)), statusTip, SLOT(slotStatusTipCoords(int, int, int)));
 
1868
        }
 
1869
 
 
1870
        statusBar()->message(tr("Ready."));
 
1871
}
 
1872
 
 
1873
void MainWindow::slotViewCoords(bool toggle)
 
1874
{
 
1875
        if (!toggle)
 
1876
                board->setShowCoords(false);
 
1877
        else
 
1878
                board->setShowCoords(true);
 
1879
        
 
1880
        statusBar()->message(tr("Ready."));
 
1881
}
 
1882
 
 
1883
void MainWindow::slotViewSlider(bool toggle)
 
1884
{
 
1885
        if (!toggle)
 
1886
                mainWidget->toggleSlider(false);
 
1887
        else
 
1888
                mainWidget->toggleSlider(true);
 
1889
        
 
1890
        statusBar()->message(tr("Ready."));
 
1891
}
 
1892
 
 
1893
void MainWindow::slotViewComment(bool toggle)
 
1894
{
 
1895
//      setting->writeIntEntry("VIEW_COMMENT", toggle ? viewVertComment->isOn() ? 2 : 1 : 0);
 
1896
        if (!toggle)
 
1897
        {
 
1898
                commentEdit->hide();
 
1899
                commentEdit2->hide();
 
1900
                viewVertComment->setEnabled(false);
 
1901
 
 
1902
                ListView_observers->hide();
 
1903
 
 
1904
                setFocus();
 
1905
        }
 
1906
        else
 
1907
        {
 
1908
                commentEdit->show();
 
1909
                commentEdit2->show();
 
1910
                viewVertComment->setEnabled(true);
 
1911
 
 
1912
                ListView_observers->show();
 
1913
 
 
1914
                setFocus();
 
1915
        }
 
1916
        
 
1917
        statusBar()->message(tr("Ready."));
 
1918
}
 
1919
 
 
1920
void MainWindow::slotViewVertComment(bool toggle)
 
1921
{
 
1922
//      setting->writeIntEntry("VIEW_COMMENT", toggle ? 2 : 1);
 
1923
        splitter->setOrientation(toggle ? Horizontal : Vertical);
 
1924
        splitter->setResizeMode(mainWidget, QSplitter::KeepSize);
 
1925
        splitter_comment->setOrientation(!toggle ? Horizontal : Vertical);
 
1926
        splitter_comment->setResizeMode(ListView_observers, QSplitter::KeepSize);
 
1927
}
 
1928
 
 
1929
// set sidbar left or right
 
1930
void MainWindow::slotViewLeftSidebar()
 
1931
{
 
1932
        mainWidgetGuiLayout->remove(mainWidget->boardFrame);
 
1933
        mainWidgetGuiLayout->remove(mainWidget->toolsFrame);
 
1934
 
 
1935
        if (setting->readBoolEntry("SIDEBAR_LEFT"))
 
1936
        {
 
1937
                mainWidgetGuiLayout->addWidget(mainWidget->toolsFrame, 0, 0);
 
1938
                mainWidgetGuiLayout->addWidget(mainWidget->boardFrame, 0, 1);
 
1939
 
 
1940
        }
 
1941
        else
 
1942
        {
 
1943
                mainWidgetGuiLayout->addWidget(mainWidget->toolsFrame, 0, 1);
 
1944
                mainWidgetGuiLayout->addWidget(mainWidget->boardFrame, 0, 0);
 
1945
        }
 
1946
}
 
1947
 
 
1948
void MainWindow::slotViewSidebar(bool toggle)
 
1949
{
 
1950
        interfaceHandler->toggleSidebar(toggle);
 
1951
        setting->writeBoolEntry("SIDEBAR", toggle);
 
1952
 
 
1953
        statusBar()->message(tr("Ready."));
 
1954
}
 
1955
 
 
1956
void MainWindow::slotViewPinComment(bool toggle)
 
1957
{
 
1958
        if (!toggle)
 
1959
        {
 
1960
                commentEdit->reparent(splitter, QPoint(0, 0), true);
 
1961
                viewComment->setOn(true);
 
1962
                viewVertComment->setEnabled(true);
 
1963
        }
 
1964
        else
 
1965
        {
 
1966
                commentEdit->reparent(this, WType_TopLevel, QPoint(0, 0), true);
 
1967
                commentEdit->setGeometry(200, 100, 400, 200);
 
1968
                viewComment->setOn(true);
 
1969
                viewVertComment->setEnabled(false);
 
1970
        }
 
1971
        statusBar()->message(tr("Ready."));
 
1972
}
 
1973
 
 
1974
void MainWindow::slotViewIncreaseSize()
 
1975
{
 
1976
        board->increaseSize();
 
1977
}
 
1978
 
 
1979
void MainWindow::slotViewDecreaseSize()
 
1980
{
 
1981
        board->decreaseSize();
 
1982
}
 
1983
 
 
1984
void MainWindow::slotViewSaveSize()
 
1985
{
 
1986
        reStoreWindowSize("0", true);
 
1987
}
 
1988
 
 
1989
void MainWindow::slotViewFullscreen(bool toggle)
 
1990
{
 
1991
        if (!toggle)
 
1992
                showNormal();
 
1993
        else
 
1994
                showFullScreen();
 
1995
        
 
1996
        isFullScreen = toggle;
 
1997
}
 
1998
 
 
1999
void MainWindow::slotHelpManual()
 
2000
{
 
2001
        setting->qgo->openManual();
 
2002
}
 
2003
 
 
2004
void MainWindow::slotHelpSoundInfo()
 
2005
{
 
2006
        // show info
 
2007
        setting->qgo->testSound(true);
 
2008
}
 
2009
 
 
2010
void MainWindow::slotHelpAbout()
 
2011
{
 
2012
        setting->qgo->slotHelpAbout();
 
2013
}
 
2014
 
 
2015
void MainWindow::slotHelpAboutQt()
 
2016
{
 
2017
        QMessageBox::aboutQt(this);
 
2018
}
 
2019
 
 
2020
void MainWindow::slotToggleMarks()
 
2021
{
 
2022
        interfaceHandler->toggleMarks();
 
2023
}
 
2024
 
 
2025
void MainWindow::slotTimerForward()
 
2026
{
 
2027
        static int eventCounter = 0;
 
2028
        static int moveHasTimeInfo = 0;
 
2029
 
 
2030
        if (timer->isActive() && setting->readBoolEntry("SGF_TIME_TAGS") && board->getGameData()->timeSystem != none)
 
2031
        {
 
2032
                bool isBlacksTurn = board->getBoardHandler()->getBlackTurn();
 
2033
 
 
2034
                // decrease time info
 
2035
                QString tmp;
 
2036
                int seconds;
 
2037
 
 
2038
                if (isBlacksTurn)
 
2039
                        tmp = interfaceHandler->normalTools->pb_timeBlack->text();
 
2040
                else
 
2041
                        tmp = interfaceHandler->normalTools->pb_timeWhite->text();
 
2042
 
 
2043
                int pos1 = 0;
 
2044
                int pos2;
 
2045
                seconds = 0;
 
2046
                switch (tmp.contains(":"))
 
2047
                {
 
2048
                        case 2:
 
2049
                                // case: 0:23:56
 
2050
                                pos1 = tmp.find(":") ;
 
2051
                                seconds += tmp.left(pos1).toInt()*3600;
 
2052
                                pos1++;
 
2053
                        case 1:
 
2054
                                pos2 = tmp.findRev(":", -1);
 
2055
                                seconds += tmp.mid(pos1, pos2-pos1).toInt()*60;
 
2056
                                seconds += tmp.mid(pos2+1, 2).toInt();
 
2057
                                break;
 
2058
                }
 
2059
                if (tmp.contains("-"))
 
2060
                        seconds = -seconds;
 
2061
                seconds--;
 
2062
 
 
2063
                int openMoves = ((pos1 = tmp.find("/")) != -1 ? tmp.right(tmp.length() - pos1 - 1).toInt() : -1);
 
2064
 
 
2065
                // set stones using sgf's time info
 
2066
                Move *m = board->getBoardHandler()->getTree()->getCurrent();
 
2067
 
 
2068
                interfaceHandler->setTimes(isBlacksTurn, seconds, openMoves);
 
2069
 
 
2070
                if (m->getMoveNumber() == 0)
 
2071
                        board->nextMove(setting->readBoolEntry("SOUND_AUTOPLAY"));
 
2072
                else if (m->son == 0)
 
2073
                {
 
2074
                        timer->stop();
 
2075
                        navAutoplay->setOn(false);
 
2076
                        statusBar()->message(tr("Autoplay stopped."));
 
2077
                }
 
2078
                else if (!m->son->getTimeinfo())
 
2079
                {
 
2080
                        // no time info at this node; use settings
 
2081
                        int time = int(timerIntervals[setting->readIntEntry("TIMER_INTERVAL")]);
 
2082
                        if ((time > 1 && (++eventCounter%time == 0) || time <= 1) &&
 
2083
                                !board->nextMove(setting->readBoolEntry("SOUND_AUTOPLAY")))
 
2084
                        {
 
2085
                                timer->stop();
 
2086
                                navAutoplay->setOn(false);
 
2087
                                statusBar()->message(tr("Autoplay stopped."));
 
2088
                        }
 
2089
 
 
2090
                        // indicate move to have time Info
 
2091
                        moveHasTimeInfo = 2;
 
2092
                }
 
2093
                else if (m->son->getTimeLeft() >= seconds || moveHasTimeInfo > 0)
 
2094
                {
 
2095
                        // check if byoyomi period changed
 
2096
                        if (board->getGameData()->timeSystem == canadian &&
 
2097
                                m->son->getOpenMoves() > openMoves+1 && moveHasTimeInfo == 0)
 
2098
                        {
 
2099
                                if (seconds > (m->son->getTimeLeft() - board->getGameData()->byoTime))
 
2100
                                        return;
 
2101
                        }
 
2102
 
 
2103
                        if (!board->nextMove(setting->readBoolEntry("SOUND_AUTOPLAY")))
 
2104
                        {
 
2105
                                timer->stop();
 
2106
                                navAutoplay->setOn(false);
 
2107
                                statusBar()->message(tr("Autoplay stopped."));
 
2108
                        }
 
2109
 
 
2110
                        if (moveHasTimeInfo > 0)
 
2111
                                moveHasTimeInfo--;
 
2112
                }
 
2113
        }
 
2114
        else if ((!board->nextMove(setting->readBoolEntry("SOUND_AUTOPLAY")) || !isActiveWindow())
 
2115
                && timer->isActive())
 
2116
        {
 
2117
                timer->stop();
 
2118
                navAutoplay->setOn(false);
 
2119
                statusBar()->message(tr("Autoplay stopped."));
 
2120
        }
 
2121
}
 
2122
 
 
2123
void MainWindow::setApplicationStyle()
 
2124
{
 
2125
        if (setting->readIntEntry("STYLE") < 0 || setting->readIntEntry("STYLE") > 6)
 
2126
                setting->writeEntry("STYLE", "0");
 
2127
 
 
2128
        switch (setting->readIntEntry("STYLE"))
 
2129
        {
 
2130
        case 0:
 
2131
    //qApp->setStyle(NULL);
 
2132
    qApp->setStyle(style);
 
2133
                break;
 
2134
    
 
2135
        case 1:
 
2136
                qApp->setStyle(new QWindowsStyle);
 
2137
                break;
 
2138
                
 
2139
        case 2:
 
2140
                qApp->setStyle(new QPlatinumStyle);
 
2141
                break;
 
2142
                
 
2143
        case 3:
 
2144
                qApp->setStyle(new QMotifStyle);
 
2145
                break;
 
2146
                
 
2147
        case 4:
 
2148
                qApp->setStyle(new QMotifPlusStyle);
 
2149
                break;
 
2150
                
 
2151
        case 5:
 
2152
                //qApp->setStyle(new QCDEStyle);
 
2153
                break;
 
2154
                
 
2155
        case 6:
 
2156
                //qApp->setStyle(new QSGIStyle);
 
2157
                break;
 
2158
                
 
2159
        default:
 
2160
                qWarning("Unrecognized style!");
 
2161
        }
 
2162
}
 
2163
 
 
2164
// store and restore window properties
 
2165
bool MainWindow::reStoreWindowSize(QString strKey, bool store)
 
2166
{
 
2167
        if (store)
 
2168
        {
 
2169
                // store window size, format, comment format
 
2170
                setting->writeIntEntry("BOARDVERTCOMMENT_" + strKey, !viewComment->isOn() ? 2 : viewVertComment->isOn());
 
2171
                setting->writeBoolEntry("BOARDFULLSCREEN_" + strKey, isFullScreen);
 
2172
                
 
2173
                setting->writeEntry("BOARDWINDOW_" + strKey,
 
2174
                        QString::number(pos().x()) + DELIMITER +
 
2175
                        QString::number(pos().y()) + DELIMITER +
 
2176
                        QString::number(size().width()) + DELIMITER +
 
2177
                        QString::number(size().height()));
 
2178
                
 
2179
                setting->writeEntry("BOARDSPLITTER_" + strKey,
 
2180
                        QString::number(splitter->sizes().first()) + DELIMITER +
 
2181
                        QString::number(splitter->sizes().last()) + DELIMITER +
 
2182
                        QString::number(splitter_comment->sizes().first()) + DELIMITER +
 
2183
                        QString::number(splitter_comment->sizes().last()));
 
2184
                
 
2185
                statusBar()->message(tr("Window size saved.") + " (" + strKey + ")");
 
2186
        }
 
2187
        else
 
2188
        {
 
2189
                // restore board window
 
2190
                QString s = setting->readEntry("BOARDWINDOW_" + strKey);
 
2191
                if (s.length() > 5)
 
2192
                {
 
2193
                        // do not resize until end of this procedure
 
2194
                        board->lockResize = true;
 
2195
 
 
2196
                        if (setting->readBoolEntry("BOARDFULLSCREEN_" + strKey))
 
2197
                                viewFullscreen->setOn(true);
 
2198
                        else
 
2199
                        {
 
2200
                                viewFullscreen->setOn(false);
 
2201
                                QPoint p;
 
2202
                                p.setX(element(s, 0, DELIMITER).toInt());
 
2203
                                p.setY(element(s, 1, DELIMITER).toInt());
 
2204
                                QSize sz;
 
2205
                                sz.setWidth(element(s, 2, DELIMITER).toInt());
 
2206
                                sz.setHeight(element(s, 3, DELIMITER).toInt());
 
2207
                                resize(sz);
 
2208
                                move(p);
 
2209
                        }
 
2210
 
 
2211
                        if (setting->readIntEntry("BOARDVERTCOMMENT_" + strKey) == 2)
 
2212
                        {
 
2213
                                // do not view comment
 
2214
                                viewComment->setOn(false);
 
2215
                        }
 
2216
                        else
 
2217
                        {
 
2218
                                // view comment
 
2219
                                viewComment->setOn(true);
 
2220
 
 
2221
                                viewVertComment->setOn(setting->readIntEntry("VIEW_COMMENT") == 2 ||
 
2222
                                        setting->readIntEntry("VIEW_COMMENT") == 0 && setting->readIntEntry("BOARDVERTCOMMENT_" + strKey));
 
2223
                                
 
2224
                                // restore splitter in board window
 
2225
                                s = setting->readEntry("BOARDSPLITTER_" + strKey);
 
2226
                                if (s.length() > 5)
 
2227
                                {
 
2228
                                        int i, j;
 
2229
 
 
2230
                                        i = element(s, 2, DELIMITER).toInt();
 
2231
                                        j = element(s, 3, DELIMITER).toInt();
 
2232
                                        QValueList<int> w1;
 
2233
                                        w1 << i << j;
 
2234
                                        splitter_comment->setSizes(w1);
 
2235
 
 
2236
                                        w1.clear();
 
2237
                                        i = element(s, 0, DELIMITER).toInt();
 
2238
                                        j = element(s, 1, DELIMITER).toInt();
 
2239
                                        if (i && j)
 
2240
                                                w1 << i << j;
 
2241
                                        splitter->setSizes(w1);
 
2242
                                }
 
2243
                        }
 
2244
 
 
2245
                        // do some other stuff
 
2246
                        // maybe not correct set at startup time
 
2247
                        slotViewCoords(viewCoords->isOn());
 
2248
 
 
2249
                        // ok, resize
 
2250
                        board->lockResize = false;
 
2251
                        board->changeSize();
 
2252
 
 
2253
                        statusBar()->message(tr("Window size restored.") + " (" + strKey + ")");
 
2254
 
 
2255
                        // update current move
 
2256
                        board->refreshDisplay();
 
2257
                }
 
2258
                else
 
2259
                        // window sizes not found
 
2260
                        return false;
 
2261
        }
 
2262
 
 
2263
        return true;
 
2264
}
 
2265
 
 
2266
void MainWindow::keyPressEvent(QKeyEvent *e)
 
2267
{
 
2268
        // check for window resize command = number button
 
2269
        if (e->key() >= Key_0 && e->key() <= Key_9)
 
2270
        {
 
2271
                QString strKey = QString::number(e->key() - Key_0);
 
2272
                
 
2273
                if (e->state() & AltButton)
 
2274
                {
 
2275
                        // true -> store
 
2276
                        reStoreWindowSize(strKey, true);
 
2277
                        return;
 
2278
                }
 
2279
                else if (e->state() & ControlButton)
 
2280
                {
 
2281
                        // false -> restore
 
2282
                        if (!reStoreWindowSize(strKey, false))
 
2283
                        {
 
2284
                                // sizes not found -> leave
 
2285
                                e->ignore();
 
2286
                                return;
 
2287
                        }
 
2288
                        
 
2289
                        return;
 
2290
                }
 
2291
        }
 
2292
        
 
2293
        bool localGame = true;
 
2294
        // don't view last moves while observing or playing
 
2295
        if (getBoard()->getGameMode() == modeObserve ||
 
2296
                getBoard()->getGameMode() == modeMatch ||
 
2297
                getBoard()->getGameMode() == modeTeach)
 
2298
                localGame = false;
 
2299
        
 
2300
        switch (e->key())
 
2301
        {
 
2302
/*
 
2303
                // TODO: DEBUG
 
2304
#ifndef NO_DEBUG
 
2305
        case Key_W:
 
2306
                board->debug();
 
2307
                break;
 
2308
                
 
2309
        case Key_L:
 
2310
                board->openSGF("foo.sgf");
 
2311
                break;
 
2312
                
 
2313
        case Key_S:
 
2314
                board->saveBoard("foo.sgf");
 
2315
                break;
 
2316
                
 
2317
        case Key_X:
 
2318
                board->openSGF("foo.xml", "XML");
 
2319
                break;
 
2320
                // /DEBUG
 
2321
#endif
 
2322
*/
 
2323
                
 
2324
        case Key_Left:
 
2325
                if (localGame || (getBoard()->getGameMode() == modeObserve))
 
2326
                        slotNavBackward();
 
2327
                break;
 
2328
                
 
2329
        case Key_Right:
 
2330
                if (localGame || (getBoard()->getGameMode() == modeObserve))
 
2331
                        slotNavForward();
 
2332
                break;
 
2333
                
 
2334
        case Key_Up:
 
2335
                if (localGame)
 
2336
                        slotNavPrevVar();
 
2337
                break;
 
2338
                
 
2339
        case Key_Down:
 
2340
                if (localGame)
 
2341
                        slotNavNextVar();
 
2342
                break;
 
2343
                
 
2344
        case Key_Home:
 
2345
                if (localGame)
 
2346
                        slotNavFirst();
 
2347
                break;
 
2348
                
 
2349
        case Key_End:
 
2350
                if (localGame)
 
2351
                        slotNavLast();
 
2352
                break;
 
2353
 
 
2354
        default:
 
2355
                e->ignore();
 
2356
        }
 
2357
 
 
2358
        e->accept();
 
2359
}
 
2360
 
 
2361
void MainWindow::closeEvent(QCloseEvent *e)
 
2362
{
 
2363
        // qDebug("MainWindow::closeEvent(QCloseEvent *e)");
 
2364
        if (getBoard()->getGameMode() == modeObserve || checkModified() == 1)
 
2365
        {
 
2366
                emit signal_closeevent();
 
2367
                //qGo::removeBoardWindow(this);
 
2368
                if (parent_)
 
2369
                        QTimer::singleShot(1000, (QWidget*)parent_, SLOT(slot_closeevent()));
 
2370
                else
 
2371
                        qWarning("*** BOARD CANNOT BE DELETED");
 
2372
                e->accept();
 
2373
        }
 
2374
        else
 
2375
                e->ignore();
 
2376
}
 
2377
 
 
2378
int MainWindow::checkModified(bool interactive)
 
2379
{
 
2380
        if (!board->isModified)
 
2381
                return 1;
 
2382
        
 
2383
        if (!interactive)
 
2384
                return 0;
 
2385
        
 
2386
        switch (QMessageBox::warning(this, PACKAGE,
 
2387
                tr("You modified the game.\nDo you want to save your changes?"),
 
2388
                tr("Yes"), tr("No"), tr("Cancel"),
 
2389
                0, 2))
 
2390
        {
 
2391
        case 0:
 
2392
                return slotFileSave() && !board->isModified;
 
2393
                
 
2394
        case 1:
 
2395
                return 1;
 
2396
                
 
2397
        case 2:
 
2398
                return 2;
 
2399
                
 
2400
        default:
 
2401
                qWarning("Unknown messagebox input.");
 
2402
                return 0;
 
2403
        }
 
2404
        
 
2405
        return 1;
 
2406
}
 
2407
 
 
2408
void MainWindow::rememberLastDir(const QString &file)
 
2409
{
 
2410
        int pos = 0, lastpos = -1;
 
2411
        
 
2412
        while ((pos =  file.find('/', pos)) != -1 && pos++ < static_cast<int>(file.length()))
 
2413
                lastpos = pos;
 
2414
        
 
2415
        if (lastpos == -1)
 
2416
        {
 
2417
                setting->writeEntry("LAST_DIR", "");
 
2418
        }
 
2419
        else
 
2420
                setting->writeEntry("LAST_DIR", file.left(lastpos));
 
2421
        
 
2422
        // qDebug("LAST DIR: %s", qGo::getSettings()->lastDir.latin1());
 
2423
}
 
2424
 
 
2425
void MainWindow::updateFont()
 
2426
{
 
2427
        // editable fields
 
2428
        setFont(setting->fontComments);
 
2429
 
 
2430
        // observer
 
2431
        ListView_observers->setFont(setting->fontLists);
 
2432
 
 
2433
        // rest: standard font
 
2434
        mainWidget->setFont(setting->fontStandard);
 
2435
        mainWidget->normalTools->pb_timeWhite->setFont(setting->fontClocks);
 
2436
        mainWidget->normalTools->pb_timeBlack->setFont(setting->fontClocks);
 
2437
 
 
2438
        // set some colors
 
2439
        QPalette pal = commentEdit2->palette();
 
2440
        pal.setColor(QColorGroup::Base, setting->colorBackground);
 
2441
        commentEdit2->setPalette(pal);
 
2442
        ListView_observers->setPalette(pal);
 
2443
        pal = commentEdit->palette();
 
2444
        pal.setColor(QColorGroup::Base, setting->colorBackground);
 
2445
        commentEdit->setPalette(pal);
 
2446
}
 
2447
 
 
2448
// used in slot_editBoardInNewWindow()
 
2449
void MainWindow::slot_animateClick()
 
2450
{
 
2451
        getInterfaceHandler()->refreshButton->animateClick();
 
2452
}
 
2453
 
 
2454
void MainWindow::slot_editBoardInNewWindow()
 
2455
{
 
2456
        // online mode -> don't score, open new Window instead
 
2457
        MainWindow *w = setting->qgo->addBoardWindow();
 
2458
        w->reStoreWindowSize("9", false);
 
2459
        
 
2460
        CHECK_PTR(w);
 
2461
        w->getInterfaceHandler()->toggleMode();
 
2462
        w->getInterfaceHandler()->toggleMode();
 
2463
        // create update button
 
2464
        w->getInterfaceHandler()->refreshButton->setText(tr("Update"));
 
2465
        QToolTip::add(w->getInterfaceHandler()->refreshButton, tr("Update from online game"));
 
2466
        QWhatsThis::add(w->getInterfaceHandler()->refreshButton, tr("Update from online game to local board and supersede own changes."));
 
2467
        w->getInterfaceHandler()->refreshButton->setEnabled(true);
 
2468
        connect(w->getInterfaceHandler()->refreshButton, SIGNAL(clicked()), this, SLOT(slotFileExportSgfClipB()));
 
2469
        connect(w->getInterfaceHandler()->refreshButton, SIGNAL(clicked()), w, SLOT(slotFileImportSgfClipB()));
 
2470
        connect(w->getInterfaceHandler()->refreshButton, SIGNAL(clicked()), w, SLOT(slotNavLastByTime()));
 
2471
        QTimer::singleShot(100, w, SLOT(slot_animateClick()));
 
2472
}
 
2473
 
 
2474
void MainWindow::updateObserverCnt()
 
2475
{
 
2476
        ListView_observers->setColumnText(0, tr("Observers") + " (" + QString::number(ListView_observers->childCount()) + ")");
 
2477
        ListView_observers->setSorting(2);
 
2478
        ListView_observers->sort();
 
2479
        ListView_observers->setSorting(-1);
 
2480
}
 
2481
 
 
2482
void MainWindow::addObserver(const QString &name)
 
2483
{
 
2484
        QString name_without_rank = element(name, 0);
 
2485
        QString rank = element(name, 1);
 
2486
        QString rankkey = rkToKey(rank) + name_without_rank;
 
2487
        
 
2488
        new QListViewItem(ListView_observers, name_without_rank, rank, rankkey);
 
2489
//      ListView_observer->addItem
 
2490
}
 
2491
 
 
2492
/*
 
2493
// enable/disable Menu items
 
2494
void MainWindow::setOnlineMenu(bool onlineMenu)
 
2495
{
 
2496
        if (onlineMenu)
 
2497
        {
 
2498
                fileNew->setEnabled(false);
 
2499
                fileOpen->setEnabled(false);
 
2500
                fileImportASCII->setEnabled(false);
 
2501
                fileImportASCIIClipB->setEnabled(false);
 
2502
                fileImportSgfClipB->setEnabled(false);
 
2503
                editCut->setEnabled(false);
 
2504
                editPaste->setEnabled(false);
 
2505
                editPasteBrother->setEnabled(false);
 
2506
                editDelete->setEnabled(false);
 
2507
                editNumberMoves->setEnabled(false);
 
2508
                editMarkBrothers->setEnabled(false);
 
2509
                editMarkSons->setEnabled(false);
 
2510
                navNthMove->setEnabled(false);
 
2511
                navAutoplay->setEnabled(false);
 
2512
                navEmptyBranch->setEnabled(false);
 
2513
                navCloneNode->setEnabled(false);
 
2514
                // hide some bars
 
2515
                getMainWidget()->slider->hide();
 
2516
                getMainWidget()->sliderLeftLabel->hide();
 
2517
                getMainWidget()->sliderRightLabel->hide();
 
2518
                getFileBar()->hide();
 
2519
                getToolBar()->hide();
 
2520
                getEditBar()->hide();
 
2521
        }
 
2522
        else
 
2523
        {
 
2524
                fileNew->setEnabled(true);
 
2525
                fileOpen->setEnabled(true);
 
2526
                fileImportASCII->setEnabled(true);
 
2527
                fileImportASCIIClipB->setEnabled(true);
 
2528
                fileImportSgfClipB->setEnabled(true);
 
2529
                editCut->setEnabled(true);
 
2530
                editPaste->setEnabled(true);
 
2531
                editPasteBrother->setEnabled(true);
 
2532
                editDelete->setEnabled(true);
 
2533
                editNumberMoves->setEnabled(true);
 
2534
                editMarkBrothers->setEnabled(true);
 
2535
                editMarkSons->setEnabled(true);
 
2536
                navNthMove->setEnabled(true);
 
2537
                navAutoplay->setEnabled(true);
 
2538
                navEmptyBranch->setEnabled(true);
 
2539
                navCloneNode->setEnabled(true);
 
2540
                // show some bars
 
2541
                if (setting->readBoolEntry("SLIDER"))
 
2542
                {
 
2543
                        getMainWidget()->slider->show();
 
2544
                        getMainWidget()->sliderLeftLabel->show();
 
2545
                        getMainWidget()->sliderRightLabel->show();
 
2546
                }
 
2547
                if (setting->readBoolEntry("FILEBAR"))
 
2548
                        getFileBar()->show();
 
2549
                if (setting->readBoolEntry("TOOLBAR"))
 
2550
                        getToolBar()->show();
 
2551
                if (setting->readBoolEntry("EDITBAR"))
 
2552
                        getEditBar()->show();
 
2553
        }
 
2554
}
 
2555
*/
 
2556