kgeography.cpp 16.9 KB
Newer Older
Albert Astals Cid's avatar
Albert Astals Cid committed
1
/***************************************************************************
2
 *   Copyright (C) 2004-2007 by Albert Astals Cid                          *
3
 *   aacid@kde.org                                                         *
Albert Astals Cid's avatar
Albert Astals Cid committed
4
5
6
7
8
9
10
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

Albert Astals Cid's avatar
Albert Astals Cid committed
11
12
#include "kgeography.h"

13
#include <kconfigdialog.h>
Albert Astals Cid's avatar
Albert Astals Cid committed
14
#include <kmessagebox.h>
Aaron J. Seigo's avatar
Aaron J. Seigo committed
15
#include <kstandardaction.h>
16
#include <ktoggleaction.h>
Anne-Marie Mahfouf's avatar
compile    
Anne-Marie Mahfouf committed
17
#include <ktoolbar.h>
Laurent Montel's avatar
Laurent Montel committed
18
#include <kactioncollection.h>
19
#include <klocalizedstring.h>
David Gil's avatar
David Gil committed
20
21

#include <qmenubar.h>
22
#include <qfile.h>
Albert Astals Cid's avatar
Albert Astals Cid committed
23
#include <qlabel.h>
24
#include <qlayout.h>
25
#include <qsize.h>
26
#include <qtimer.h>
David Gil's avatar
David Gil committed
27
#include <qpushbutton.h>
28

29
#include "answersdialog.h"
30
#include "capitaldivisionasker.h"
31
#include "divisioncapitalasker.h"
Albert Astals Cid's avatar
Albert Astals Cid committed
32
#include "divisionflagasker.h"
Albert Astals Cid's avatar
Albert Astals Cid committed
33
#include "flagdivisionasker.h"
34
#include "settings.h"
Albert Astals Cid's avatar
Albert Astals Cid committed
35
#include "mapasker.h"
Albert Astals Cid's avatar
Albert Astals Cid committed
36
37
38
#include "mapchooser.h"
#include "mapparser.h"
#include "map.h"
39
#include "placeasker.h"
40
#include "integerinputdialog.h"
Albert Astals Cid's avatar
Albert Astals Cid committed
41
#include "ui_kgeographyoptions.h"
Albert Astals Cid's avatar
Albert Astals Cid committed
42

Laurent Montel's avatar
Laurent Montel committed
43
kgeography::kgeography() : KXmlGuiWindow(), p_firstShow(true), p_mustShowResultsDialog(false)
Albert Astals Cid's avatar
Albert Astals Cid committed
44
45
{
	p_map = 0;
Albert Astals Cid's avatar
Albert Astals Cid committed
46
	p_askWidget = 0;
47

48
49
50
	p_bigWidget = new QWidget(this);
	QHBoxLayout *bigWidgetLayout = new QHBoxLayout(p_bigWidget);
	bigWidgetLayout -> setSpacing(0);
Laurent Montel's avatar
Laurent Montel committed
51
	bigWidgetLayout -> setContentsMargins(0, 0, 0, 0);
Laurent Montel's avatar
Laurent Montel committed
52

53
54
55
56
57
	QWidget *leftWidget = new QWidget(p_bigWidget);
	QVBoxLayout *leftWidgetLayout = new QVBoxLayout(leftWidget);

	p_currentMap = new QLabel(leftWidget);
	p_currentMap -> setAlignment(Qt::AlignCenter);
David Gil's avatar
David Gil committed
58
	p_consult = new QPushButton(i18n("E&xplore Map"), leftWidget);
Pino Toscano's avatar
Pino Toscano committed
59
	p_consult->setWhatsThis(i18n("In this section left click on any part of the map to learn about the divisions" ));
60
61
	QLabel * testYourselfLabel = new QLabel( i18n("Test Yourself:"), this );
	testYourselfLabel->setAlignment( Qt::AlignHCenter );
David Gil's avatar
David Gil committed
62
	p_askMap = new QPushButton(i18n("&Location of Regions"), leftWidget);
63
	p_askMap->setWhatsThis(i18n("In this challenge you are given a division name on the left under the menu and you must find it on the map and click on it"));
David Gil's avatar
David Gil committed
64
	p_askPlaceMap = new QPushButton(i18n("&Place Regions in the Map"), leftWidget);
Albert Astals Cid's avatar
Albert Astals Cid committed
65
	p_askPlaceMap->setWhatsThis(i18n("In this challenge you are given the shape of a region and you must place it on the map"));
David Gil's avatar
David Gil committed
66
	p_askCapitalDivisions = new QPushButton(i18n("&Regions by Capital"), leftWidget);
Pino Toscano's avatar
Pino Toscano committed
67
	p_askCapitalDivisions->setWhatsThis(i18n("In this quiz you have to guess the division name given its capital"));
David Gil's avatar
David Gil committed
68
	p_askDivisionCapitals = new QPushButton(i18n("&Capitals of Regions"), leftWidget);
Pino Toscano's avatar
Pino Toscano committed
69
	p_askDivisionCapitals->setWhatsThis(i18n("In this quiz you have to guess the capital of a given division name"));
David Gil's avatar
David Gil committed
70
	p_askFlagDivisions = new QPushButton(i18n("Re&gions by Flag"), leftWidget);
Pino Toscano's avatar
Pino Toscano committed
71
	p_askFlagDivisions->setWhatsThis(i18n("In this quiz you have to guess the division name given its flag"));
David Gil's avatar
David Gil committed
72
	p_askDivisionFlags = new QPushButton(i18n("&Flags of Regions"), leftWidget);
Pino Toscano's avatar
Pino Toscano committed
73
	p_askDivisionFlags->setWhatsThis(i18n("In this quiz you have to guess the flag of a division given its name"));
74
	p_underLeftWidget = new QWidget(leftWidget);
75
	// where the number of answers will be shown
Albert Astals Cid's avatar
Albert Astals Cid committed
76
	m_underLeftWidgetLayout = new QVBoxLayout(p_underLeftWidget);
Laurent Montel's avatar
Laurent Montel committed
77
	m_underLeftWidgetLayout->setContentsMargins(0, 0, 0, 0);
78

79
80
	leftWidgetLayout -> addWidget(p_currentMap);
	leftWidgetLayout -> addWidget(p_consult);
81
82
	leftWidgetLayout -> addSpacing(10);
	leftWidgetLayout -> addWidget(testYourselfLabel);
83
	leftWidgetLayout -> addWidget(p_askMap);
84
	leftWidgetLayout -> addWidget(p_askPlaceMap);
85
86
87
88
	leftWidgetLayout -> addWidget(p_askCapitalDivisions);
	leftWidgetLayout -> addWidget(p_askDivisionCapitals);
	leftWidgetLayout -> addWidget(p_askFlagDivisions);
	leftWidgetLayout -> addWidget(p_askDivisionFlags);
89
90
91
92
93
94
95
	leftWidgetLayout -> addWidget(p_underLeftWidget);

	// Make p_underLeftWidget as thin as possible, and always be shown in the same place
	QWidget* p_underUnderLeftWidget = new QWidget(leftWidget);
	QVBoxLayout *underUnderLeftWidgetLayout = new QVBoxLayout(p_underUnderLeftWidget);
	underUnderLeftWidgetLayout -> addStretch(1);
	leftWidgetLayout -> addWidget(p_underUnderLeftWidget);
96
97

	bigWidgetLayout -> addWidget(leftWidget);
98
	setCentralWidget(p_bigWidget);
99

100
101
102
103
104
105
106
	connect(p_consult, &QPushButton::clicked, this, &kgeography::consult);
	connect(p_askMap, &QPushButton::clicked, this, &kgeography::askMap);
	connect(p_askPlaceMap, &QPushButton::clicked, this, &kgeography::askPlaceMap);
	connect(p_askCapitalDivisions, &QPushButton::clicked, this, &kgeography::askCapitalDivisions);
	connect(p_askDivisionCapitals, &QPushButton::clicked, this, &kgeography::askDivisionCapitals);
	connect(p_askFlagDivisions, &QPushButton::clicked, this, &kgeography::askFlagDivisions);
	connect(p_askDivisionFlags, &QPushButton::clicked, this, &kgeography::askDivisionFlags);
107

Laurent Montel's avatar
Laurent Montel committed
108
	QAction *a = KStandardAction::open(this, SLOT(openMap()), actionCollection());
109
	a -> setText(i18n("&Open Map..."));
110

111
112
	a = KStandardAction::quit(this, SLOT(close()), actionCollection());
	
Laurent Montel's avatar
Laurent Montel committed
113
	p_zoom =  actionCollection()->add<KToggleAction>( QStringLiteral("zoom_select") );
114
	p_zoom -> setText(i18n("&Zoom") );
Laurent Montel's avatar
Laurent Montel committed
115
	p_zoom -> setIcon( QIcon::fromTheme(QStringLiteral("zoom-in")) );
116
	p_zoom -> setEnabled(false);
Laurent Montel's avatar
Laurent Montel committed
117

Laurent Montel's avatar
Laurent Montel committed
118
	p_zoomOriginal = actionCollection()->addAction( QStringLiteral("zoom_original") );
119
	p_zoomOriginal -> setText( i18n("&Original Size") );
Laurent Montel's avatar
Laurent Montel committed
120
	p_zoomOriginal -> setIcon( QIcon::fromTheme(QStringLiteral("zoom-original")) );
121
	p_zoomOriginal -> setEnabled(false);
Laurent Montel's avatar
Laurent Montel committed
122

Laurent Montel's avatar
Laurent Montel committed
123
	p_zoomAutomatic = actionCollection()->add<KToggleAction>( QStringLiteral("zoom_automatic") );
124
	p_zoomAutomatic -> setText(  i18n("&Automatic Zoom") );
Laurent Montel's avatar
Laurent Montel committed
125
	p_zoomAutomatic -> setIcon( QIcon::fromTheme(QStringLiteral("zoom-fit-best")) );
126
	p_zoomAutomatic -> setEnabled(false);
127

Laurent Montel's avatar
Laurent Montel committed
128
	p_move = actionCollection()->add<KToggleAction>( QStringLiteral("move") );
129
	p_move->setText( i18n("&Move") );
Laurent Montel's avatar
Laurent Montel committed
130
	p_move->setIcon( QIcon::fromTheme(QStringLiteral("transform-move")) );
Albert Astals Cid's avatar
Albert Astals Cid committed
131
	p_move -> setEnabled(false);
132

Laurent Montel's avatar
Laurent Montel committed
133
	a = actionCollection()->addAction( QStringLiteral("disclaimer") );
134
	a->setText( i18n("Disclaimer") );
135
	connect(a, &QAction::triggered, this, &kgeography::disclaimer);
136
	
Laurent Montel's avatar
Laurent Montel committed
137
	p_showAuthor = actionCollection()->addAction( QStringLiteral("author") );
138
139
	p_showAuthor->setText( i18n("Map author") );
	p_showAuthor->setEnabled(false);
140
	connect(p_showAuthor, &QAction::triggered, this, &kgeography::showMapAuthor);
141

142
	KStandardAction::preferences(this, SLOT(showPreferencesDialog()), actionCollection());
143

144
	setupGUI(Keys | ToolBar | Save | Create);
145

146
	show();
Albert Astals Cid's avatar
Albert Astals Cid committed
147
148
149
150
}

kgeography::~kgeography()
{
151
	delete p_askWidget;
Albert Astals Cid's avatar
Albert Astals Cid committed
152
153
154
	delete p_map;
}

155
156
void kgeography::showPreferencesDialog()
{
Laurent Montel's avatar
Laurent Montel committed
157
	if ( KConfigDialog::showDialog( QStringLiteral("settings") ) )
158
159
160
161
		return; 

	// KConfigDialog didn't find an instance of this dialog, so lets
	// create it : 
Laurent Montel's avatar
Laurent Montel committed
162
	KConfigDialog* dialog = new KConfigDialog(this, QStringLiteral("settings"),
163
											  kgeographySettings::self()); 
David Gil's avatar
David Gil committed
164
165
//	FIXME: Waiting for the answer from Kévin about what to do with it
//	dialog->setHelp("configuration", "kgeography");
166
167
168
169
	QWidget *w = new QWidget();
	Ui::Options confWdg;
	confWdg.setupUi(w);

Laurent Montel's avatar
Laurent Montel committed
170
	dialog->addPage(w, i18n("General"), QStringLiteral("kgeography") ); 
171
172
173

	// User edited the configuration - update your local copies of the 
	// configuration data 
174
	connect(dialog, &KConfigDialog::settingsChanged, this, &kgeography::updateConfiguration);
175
176
177
178

	dialog->show();
}

Laurent G's avatar
Laurent G committed
179
180
void kgeography::updateConfiguration()
{
Albert Astals Cid's avatar
Albert Astals Cid committed
181
182
183
184
	boxAsker *aBoxAsker = dynamic_cast<boxAsker*>(p_askWidget);
	if ( aBoxAsker != NULL ) {
		aBoxAsker->updateLayout();
	}
Laurent G's avatar
Laurent G committed
185
186
}

187
188
189
190
191
void kgeography::showEvent(QShowEvent *)
{
	if (p_firstShow)
	{
		QString file = kgeographySettings::self() -> lastMap();
Laurent Montel's avatar
Laurent Montel committed
192

193
194
195
		if (QFile::exists(file))
		{
			mapReader reader;
196
197
			KGmap *kgmap = reader.parseMap(file);
			if (kgmap)
198
			{
199
				setMap(kgmap);
200
201
202
			}
			else
			{
203
				KMessageBox::error(this, i18n("Could not open last used map. Error parsing %1: %2", file, reader.getError()));
204
205
206
207
208
209
210
211
212
213
				openMap();
			}
		}
		else openMap();

		if (!p_map)
		{
			p_currentMap -> setText(i18n("There is no current map"));
			p_consult -> setEnabled(false);
			p_askMap -> setEnabled(false);
214
			p_askPlaceMap -> setEnabled(false);
215
216
217
218
219
220
221
			p_askFlagDivisions -> setEnabled(false);
			p_askDivisionFlags -> setEnabled(false);
			p_askCapitalDivisions -> setEnabled(false);
			p_askDivisionCapitals -> setEnabled(false);
		}
		// if anyone can explain why with the slot works and now without
		// i'll be glad to learn
Laurent Montel's avatar
Laurent Montel committed
222
		QTimer::singleShot(0, this, &kgeography::resizeMainWindow);
223
// 		resizeMainWindow();
Laurent Montel's avatar
Laurent Montel committed
224

225
226
227
228
		p_firstShow = false;
	}
}

Albert Astals Cid's avatar
Albert Astals Cid committed
229
230
231
232
233
void kgeography::openMap()
{
	mapChooser mp(this);
	if (mp.exec() == mapChooser::Accepted)
	{
Albert Astals Cid's avatar
crash--    
Albert Astals Cid committed
234
		showResultsDialog();
235
		setMap(mp.getMap());
Albert Astals Cid's avatar
Albert Astals Cid committed
236
237
		// if anyone can explain why with the slot works and now without
		// i'll be glad to learn
Laurent Montel's avatar
Laurent Montel committed
238
		QTimer::singleShot(0, this, &kgeography::resizeMainWindow);
Albert Astals Cid's avatar
Albert Astals Cid committed
239
// 		resizeMainWindow();
Albert Astals Cid's avatar
Albert Astals Cid committed
240
241
242
243
244
	}
}

void kgeography::consult()
{
245
246
247
	// No need to create another map viewer if we are already in it
	mapAsker *ma = dynamic_cast<mapAsker*>(p_askWidget);
	if (ma && !ma -> isAsker()) return;
Laurent Montel's avatar
Laurent Montel committed
248

249
	showResultsDialog();
250
	removeOldAskWidget();
251
	p_askWidget = new mapAsker(p_bigWidget, p_map, p_underLeftWidget, false);
252
	p_zoom -> setEnabled(true);
253
	p_zoomOriginal -> setEnabled(true);
254
	p_zoomAutomatic -> setEnabled(true);
Albert Astals Cid's avatar
Albert Astals Cid committed
255
	putAskWidget();
Albert Astals Cid's avatar
Albert Astals Cid committed
256
257
}

258
259
260
261
int kgeography::askQuestionNumber(int upto, bool *rOK)
{
	int i;
	bool ok;
262
	i = IntegerInputDialog::GetInteger(this, i18n("Number of Questions"),
263
					   i18n("How many questions do you want? (1 to %1)", upto),
264
					   1, upto, upto, &ok);
265
266
267
268
	if ( rOK != NULL ) *rOK = ok;
	return i;
}

269
void kgeography::askCapitalDivisions()
270
271
272
{
	int i;
	bool ok;
273
	showResultsDialog();
274
	i = askQuestionNumber(p_map -> count(division::eCapital), &ok);
275
276
	if (ok)
	{
277
		removeOldAskWidget();
278
		p_askWidget = new capitalDivisionAsker(p_bigWidget, p_map, p_underLeftWidget, i);
279
		putAskWidget();
280
		p_mustShowResultsDialog = true;
281
	}
282
	else consult();
283
284
}

285
286
287
288
void kgeography::askDivisionCapitals()
{
	int i;
	bool ok;
289
	showResultsDialog();
290
	i = askQuestionNumber(p_map -> count(division::eCapital), &ok);
291
292
	if (ok)
	{
293
		removeOldAskWidget();
294
		p_askWidget = new divisionCapitalAsker(p_bigWidget, p_map, p_underLeftWidget, i);
295
		putAskWidget();
296
		p_mustShowResultsDialog = true;
297
	}
298
	else consult();
299
300
}

Albert Astals Cid's avatar
Albert Astals Cid committed
301
void kgeography::askMap()
Albert Astals Cid's avatar
Albert Astals Cid committed
302
{
Albert Astals Cid's avatar
Albert Astals Cid committed
303
304
	int i;
	bool ok;
305
	showResultsDialog();
306
	i = askQuestionNumber(p_map -> count(division::eClick), &ok);
Albert Astals Cid's avatar
Albert Astals Cid committed
307
	if (ok)
Albert Astals Cid's avatar
Albert Astals Cid committed
308
	{
309
		removeOldAskWidget();
310
		p_askWidget = new mapAsker(p_bigWidget, p_map, p_underLeftWidget, true, i);
311
		p_zoom -> setEnabled(true);
312
		p_zoomOriginal -> setEnabled(true);
313
		p_zoomAutomatic -> setEnabled(true);
Albert Astals Cid's avatar
Albert Astals Cid committed
314
		putAskWidget();
315
		p_mustShowResultsDialog = true;
Albert Astals Cid's avatar
Albert Astals Cid committed
316
	}
317
	else consult();
Albert Astals Cid's avatar
Albert Astals Cid committed
318
319
}

320
321
322
323
324
void kgeography::askPlaceMap()
{
	int i;
	bool ok;
	showResultsDialog();
325
	i = askQuestionNumber(p_map -> count(division::eClick), &ok);
326
327
328
	if (ok)
	{
		removeOldAskWidget();
329
		p_askWidget = new placeAsker(p_bigWidget, p_map, p_underLeftWidget, i);
330
331
332
333
334
335
336
337
338
		p_zoom -> setEnabled(true);
		p_zoomOriginal -> setEnabled(true);
		p_zoomAutomatic -> setEnabled(true);
		putAskWidget();
		p_mustShowResultsDialog = true;
	}
	else consult();
}

Albert Astals Cid's avatar
Albert Astals Cid committed
339
void kgeography::askFlagDivisions()
Albert Astals Cid's avatar
Albert Astals Cid committed
340
{
Albert Astals Cid's avatar
Albert Astals Cid committed
341
342
	int i;
	bool ok;
343
	showResultsDialog();
344
	i = askQuestionNumber(p_map -> count(division::eFlag), &ok);
Albert Astals Cid's avatar
Albert Astals Cid committed
345
	if (ok)
Albert Astals Cid's avatar
Albert Astals Cid committed
346
	{
347
		removeOldAskWidget();
348
		p_askWidget = new flagDivisionAsker(p_bigWidget, p_map, p_underLeftWidget, i);
Albert Astals Cid's avatar
Albert Astals Cid committed
349
		putAskWidget();
350
		p_mustShowResultsDialog = true;
Albert Astals Cid's avatar
Albert Astals Cid committed
351
	}
352
	else consult();
Albert Astals Cid's avatar
Albert Astals Cid committed
353
354
}

Albert Astals Cid's avatar
Albert Astals Cid committed
355
356
357
358
void kgeography::askDivisionFlags()
{
	int i;
	bool ok;
359
	showResultsDialog();
360
	i = askQuestionNumber(p_map -> count(division::eFlag), &ok);
Albert Astals Cid's avatar
Albert Astals Cid committed
361
362
	if (ok)
	{
363
		removeOldAskWidget();
364
		p_askWidget = new divisionFlagAsker(p_bigWidget, p_map, p_underLeftWidget, i);
Albert Astals Cid's avatar
Albert Astals Cid committed
365
		putAskWidget();
366
		p_mustShowResultsDialog = true;
Albert Astals Cid's avatar
Albert Astals Cid committed
367
	}
368
	else consult();
Albert Astals Cid's avatar
Albert Astals Cid committed
369
370
}

371
void kgeography::removeOldAskWidget()
Albert Astals Cid's avatar
Albert Astals Cid committed
372
{
373
374
375
	// next lines because setZoom(true) (may have) put cursor at application level
	if ( p_askWidget != NULL )
		p_askWidget->setZoom(false);
Albert Astals Cid's avatar
Albert Astals Cid committed
376
	delete p_askWidget;
377
	p_askWidget = 0;
378
	p_zoom -> setEnabled(false);
379
	p_zoomOriginal -> setEnabled(false);
380
	p_zoomAutomatic -> setEnabled(false);
381
382
383
	p_move -> setEnabled(false);
	p_zoom -> setChecked(false);
	p_move -> setChecked(false);
Albert Astals Cid's avatar
Albert Astals Cid committed
384
385
}

386
387
388
389
390
391
392
QSize kgeography::getPreferredSize()
{
	int ySize = menuBar() -> size().height() + toolBar() -> size().height() + ((mapAsker*) p_askWidget)->mapSize().height();
	int xSize = p_underLeftWidget -> parentWidget()-> size().width() + ((mapAsker*) p_askWidget)->mapSize().width();
	return QSize(xSize + 10, ySize + 10);
}

Albert Astals Cid's avatar
Albert Astals Cid committed
393
void kgeography::putAskWidget()
Albert Astals Cid's avatar
Albert Astals Cid committed
394
{
395
	static_cast<QBoxLayout*>(p_bigWidget -> layout()) -> addWidget(p_askWidget, 1);
396
	p_askWidget -> setAutomaticZoom(p_zoomAutomatic -> isChecked());
397
	p_askWidget -> show();
398
399
400
	connect(p_askWidget, &askWidget::setZoomActionChecked, p_zoom, &KToggleAction::setChecked);
	connect(p_zoom, &KToggleAction::toggled, p_askWidget, &askWidget::setZoom);
	connect(p_zoomOriginal, &QAction::triggered, p_askWidget, &askWidget::setOriginalZoom);
401
	connect(p_zoomOriginal, &QAction::triggered, p_zoomAutomatic, &QAction::setChecked);
402
403
404
405
406
	connect(p_zoomAutomatic, &KToggleAction::toggled, this, &kgeography::setAutomaticZoom);
	connect(p_askWidget, &askWidget::setMoveActionEnabled, this, &kgeography::setMoveActionEnabled);
	connect(p_askWidget, &askWidget::setMoveActionChecked, p_move, &KToggleAction::setChecked);
	connect(p_move, &KToggleAction::toggled, p_askWidget, &askWidget::setMovement);
	connect(p_askWidget, &askWidget::questionsEnded, this, &kgeography::questionsEnded);
Albert Astals Cid's avatar
Albert Astals Cid committed
407
}
Laurent Montel's avatar
Laurent Montel committed
408

Albert Astals Cid's avatar
Albert Astals Cid committed
409
void kgeography::setMap(KGmap *m)
410
{
411
	removeOldAskWidget();
412
413
	kgeographySettings *set = kgeographySettings::self();
	set -> setLastMap(m -> getFile());
Albert Astals Cid's avatar
Albert Astals Cid committed
414
	set -> save();
415
	delete p_map;
416
	p_map = m;
417
	p_showAuthor->setEnabled(m);
Laurent Montel's avatar
Laurent Montel committed
418

419
420
421
422
423
	QString mapName = i18nc(p_map -> getFileName().toUtf8(), p_map -> getName().toUtf8());
	QString divisionType = i18nc(p_map -> getFileName().toUtf8(), p_map->getDivisionsString().toUtf8());

	p_askMap->setText(i18n("&Location of %1", divisionType));
	p_askPlaceMap->setText(i18n("&Place %1 in the Map", divisionType));
424
	p_askCapitalDivisions->setText(p_map->getCapitalToDivisionTitle());
425
	p_askDivisionCapitals->setText(i18nc("@title", p_map->getDivisionToCapitalTitle().toUtf8()));
426
427
	p_askFlagDivisions->setText(i18n("%1 by Flag", divisionType));
	p_askDivisionFlags->setText(i18n("&Flags of %1", divisionType));
Chusslove Illich's avatar
Chusslove Illich committed
428

Albert Astals Cid's avatar
Albert Astals Cid committed
429
	p_currentMap -> setText(i18n("<qt>Current map:<br /><b>%1</b></qt>", mapName));
430
	p_consult -> setEnabled(true);
431
432
	p_askMap -> setEnabled(m -> count(division::eClick) > 0);
	p_askPlaceMap -> setEnabled(m -> count(division::eClick) > 0);
433
	// as we always want to let user choose among 4 choices, verify we have the ammunition
434
435
436
437
	p_askFlagDivisions -> setEnabled(m -> count(division::eFlag) > 3);
	p_askDivisionFlags -> setEnabled(m -> count(division::eFlag) > 3);
	p_askCapitalDivisions -> setEnabled(m -> count(division::eCapital) > 3);
	p_askDivisionCapitals -> setEnabled(m -> count(division::eCapital) > 3);
438
	consult();
439
440
441

	// set a maximum width for the under left widget, enabling the labels wordwrap and
	// avoiding the move of the map in case of large division names.
442
443
444
445
446
447
	int width = qMax(p_askMap->sizeHint().width(), p_askPlaceMap->sizeHint().width());
	width = qMax(width, p_askCapitalDivisions->sizeHint().width());
	width = qMax(width, p_askDivisionCapitals->sizeHint().width());
	width = qMax(width, p_askFlagDivisions->sizeHint().width());
	width = qMax(width, p_askDivisionFlags->sizeHint().width());
	p_underLeftWidget->setMaximumWidth(width);
448
449
}

450
451
void kgeography::disclaimer()
{
452
453
	KMessageBox::information(this, i18n("Maps, flags, translations, etc. are as accurate as their respective authors could achieve,"
					    " but KGeography should not be taken as an authoritative source."), i18n("Disclaimer"));
454
455
}

456
457
458
459
460
461
462
463
void kgeography::showMapAuthor()
{
	if (p_map)
	{
		KMessageBox::information(this, i18n("This map has been created by %1.", p_map->getAuthor()), i18n("Map Author"));
	}
}

464
void kgeography::resizeMainWindow()
465
{
466
	if (p_askWidget && width() ) resize(getPreferredSize().expandedTo(size()));
467
468
}

469
470
471
472
473
474
void kgeography::questionsEnded()
{
	showResultsDialog();
	consult();
}

475
476
477
478
479
480
481
482
void kgeography::setAutomaticZoom(bool b)
{
	p_zoom->setChecked(false);
	p_askWidget->setAutomaticZoom(b);
}

void kgeography::setMoveActionEnabled(bool b)
{
483
	p_move->setEnabled(b);
484
485
486
487
488
489
490
491
492
	if (b && p_zoomAutomatic->isChecked())
	{
		// we don't want the unchecking to bring us to the original zoom state
		p_zoomAutomatic->blockSignals(true);
		p_zoomAutomatic->setChecked(false);
		p_zoomAutomatic->blockSignals(false);
	}
}

493
494
495
496
497
498
499
void kgeography::showResultsDialog()
{
	if (p_mustShowResultsDialog)
	{
		p_mustShowResultsDialog = false;
		int ca = p_askWidget -> correctAnswers();
		QString q = p_askWidget -> getQuestionHook();
500
		QVector<userAnswer> ua = p_askWidget -> userAnswers();
Laurent Montel's avatar
Laurent Montel committed
501

502
503
504
505
506
507
		answersDialog *ad = new answersDialog(this, ua, q, ca);
		ad -> exec();
		delete ad;
	}
}

508