1 /* This file is part of KsirK.
2    Copyright (C) 2008 Gael de Chalendar <kleag@free.fr>
3 
4    KsirK is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public
6    License as published by the Free Software Foundation, either version 2
7    of the License, or (at your option) any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17    02110-1301, USA
18 */
19 
20 // application specific includes
21 #include "mainwindow.h"
22 #include "ksirkSkinEditorConfigDialog.h"
23 #include "ksirkskineditorsettings.h"
24 #include "ksirkskineditorscene.h"
25 #include "ksirkskindefinition.h"
26 #include "ksirkcountrydefinition.h"
27 #include "ksirkcontinentdefinition.h"
28 #include "ksirkgoaldefinition.h"
29 #include "ksirknationalitydefinition.h"
30 #include "ksirkspritesdefinition.h"
31 #include "ksirkskineditorpixmapitem.h"
32 #include "ksirkskineditortextitem.h"
33 #include "ksirkskineditorcountriesselectiondialog.h"
34 #include "skinSpritesData.h"
35 #include "goal.h"
36 
37 //include files for QT
38 #include <QAction>
39 #include <QDockWidget>
40 #include <QFileDialog>
41 #include <QTreeView>
42 #include <QGridLayout>
43 #include <QString>
44 #include <QMovie>
45 #include <QGraphicsScene>
46 #include <QGraphicsView>
47 #include <QGraphicsPixmapItem>
48 #include <QGraphicsSvgItem>
49 #include <QBitmap>
50 #include <QInputDialog>
51 #include <QMenuBar>
52 #include <QStatusBar>
53 #include <QSvgRenderer>
54 
55 // include files for KDE
56 #include <KMessageBox>
57 #include <KLocalizedString>
58 #include <KConfig>
59 #include <KStandardGameAction>
60 #include <KStandardAction>
61 #include <KActionCollection>
62 #include "ksirkskineditor_debug.h"
63 #include <phonon/mediaobject.h>
64 #include <KToolBar>
65 #include <KAboutApplicationDialog>
66 #include <KRecentFilesAction>
67 
68 
69 #include <assert.h>
70 
71 
72 namespace KsirkSkinEditor
73 {
74 
MainWindow(QWidget * parent)75 MainWindow::MainWindow(QWidget* parent) :
76   KXmlGuiWindow(parent),
77   m_selectedSprite(None),
78   m_onu(0),
79   m_rfa(0),
80   m_mapItem(0),
81   m_updateHighlightPosition(false)
82 {
83   qCDebug(KSIRKSKINEDITOR_LOG) << "MainWindow constructor begin";
84   KSirkSkinEditorWidget* mainWidget = new KSirkSkinEditorWidget(this);
85   setCentralWidget(mainWidget);
86 
87   m_mapScene = new Scene(0,0,1024,768,this);
88   connect(m_mapScene,SIGNAL(position(QPointF)),this,SLOT(slotPosition(QPointF)));
89   connect(m_mapScene,SIGNAL(pressPosition(QPointF)),this,SLOT(slotPressPosition(QPointF)));
90   connect(m_mapScene,SIGNAL(releasePosition(QPointF)),this,SLOT(slotReleasePosition(QPointF)));
91   m_mapView = new QGraphicsView(m_mapScene,mainWidget->mapScrollArea);
92   m_mapView->setInteractive(true);
93 
94   mainWidget->mapScrollArea->setBackgroundRole(QPalette::Dark);
95   mainWidget->mapScrollArea->setWidget(m_mapView);
96 
97   QHBoxLayout* layout = new QHBoxLayout;
98   mainWidget->buttonsScrollArea->setLayout(layout);
99 
100   m_flagButton = new QPushButton(mainWidget->buttonsScrollArea);
101   layout->addWidget(m_flagButton);
102   m_flagButton->setCheckable(true);
103   m_flagButton->setEnabled(false);
104   connect(m_flagButton,&QAbstractButton::clicked,this,&MainWindow::slotFlagButtonClicked);
105 
106   m_infantryButton = new QPushButton(mainWidget->buttonsScrollArea);
107   layout->addWidget(m_infantryButton);
108   m_infantryButton->setCheckable(true);
109   m_infantryButton->setEnabled(false);
110   connect(m_infantryButton,&QAbstractButton::clicked,this,&MainWindow::slotInfantryButtonClicked);
111 
112   m_cavalryButton = new QPushButton(mainWidget->buttonsScrollArea);
113   layout->addWidget(m_cavalryButton);
114   m_cavalryButton->setCheckable(true);
115   m_cavalryButton->setEnabled(false);
116   connect(m_cavalryButton,&QAbstractButton::clicked,this,&MainWindow::slotCavalryButtonClicked);
117 
118   m_cannonButton = new QPushButton(mainWidget->buttonsScrollArea);
119   layout->addWidget(m_cannonButton);
120   m_cannonButton->setCheckable(true);
121   m_cannonButton->setEnabled(false);
122   connect(m_cannonButton,&QAbstractButton::clicked,this,&MainWindow::slotCannonButtonClicked);
123 
124   QString anchorFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("cross.png"));
125   if (anchorFileName.isNull())
126   {
127     KMessageBox::error(0, i18n("Cannot load anchor icon<br>Program cannot continue"), i18n("Error"));
128     exit(2);
129   }
130   QPixmap anchorPix = QPixmap(anchorFileName);
131   m_anchorButton = new QPushButton(mainWidget->buttonsScrollArea);
132   m_anchorButton->setIcon(anchorPix);
133   layout->addWidget(m_anchorButton);
134   m_anchorButton->setCheckable(true);
135   m_anchorButton->setEnabled(false);
136   connect(m_anchorButton,&QAbstractButton::clicked,this,&MainWindow::slotAnchorButtonClicked);
137 
138   QString centerFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("target.png"));
139   if (centerFileName.isNull())
140   {
141     KMessageBox::error(0, i18n("Cannot load center icon<br>Program cannot continue"), i18n("Error"));
142     exit(2);
143   }
144   QPixmap centerPix = QPixmap(centerFileName);
145   m_centerButton = new QPushButton(mainWidget->buttonsScrollArea);
146   m_centerButton->setIcon(centerPix);
147   layout->addWidget(m_centerButton);
148   m_centerButton->setCheckable(true);
149   m_centerButton->setEnabled(false);
150   connect(m_centerButton,&QAbstractButton::clicked,this,&MainWindow::slotCenterButtonClicked);
151 
152 
153   //   m_accels.setEnabled(true);
154 
155   QString iconFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("ksirkskineditor.png"));
156 /*  if (iconFileName.isNull())
157   {
158       KMessageBox::error(0, i18n("Cannot load icon<br>Program cannot continue"), i18n("Error"));
159       exit(2);
160   }*/
161   QPixmap icon(iconFileName);
162 
163 //    qCDebug(KSIRKSKINEDITOR_LOG) << "Before initActions";
164   initActions();
165 
166   m_skinDefWidget = new KSirkSkinDefinitionWidget(this);
167   addDockWidget ( Qt::LeftDockWidgetArea, m_skinDefWidget);
168 
169   connect(m_skinDefWidget->fontrequester, &KFontRequester::fontSelected, this, &MainWindow::slotFontSelected);
170   connect(m_skinDefWidget->fgcolorbutton, &KColorButton::changed, this, &MainWindow::slotFgSelected);
171   connect(m_skinDefWidget->bgcolorbutton, &KColorButton::changed, this, &MainWindow::slotBgColorSelected);
172 
173   m_countryDefWidget = new KsirkCountryDefinitionWidget(this);
174   m_countryDefWidget->neighbourslist->setSortingEnabled(true);
175   m_countryDefWidget->neighbourslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
176   addDockWidget ( Qt::RightDockWidgetArea, m_countryDefWidget);
177   m_countryDefWidget->hide();
178 
179   m_continentDefWidget = new KsirkContinentDefinitionWidget(this);
180   m_continentDefWidget->countrieslist->setSortingEnabled(true);
181   m_continentDefWidget->countrieslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
182   addDockWidget ( Qt::RightDockWidgetArea, m_continentDefWidget);
183   m_continentDefWidget->hide();
184 
185   m_goalDefWidget = new KsirkGoalDefinitionWidget(this);
186   addDockWidget ( Qt::RightDockWidgetArea, m_goalDefWidget);
187   m_goalDefWidget->hide();
188   connect(m_goalDefWidget->worldtype,&QAbstractButton::clicked,this,&MainWindow::slotGoalTypeWorldClicked);
189   connect(m_goalDefWidget->playertype,&QAbstractButton::clicked,this,&MainWindow::slotGoalTypePlayerClicked);
190   connect(m_goalDefWidget->countriestype,&QAbstractButton::clicked,this,&MainWindow::slotGoalTypeCountriesClicked);
191   connect(m_goalDefWidget->continentstype,&QAbstractButton::clicked,this,&MainWindow::slotGoalTypeContinentsClicked);
192   connect (m_goalDefWidget->description,&QTextEdit::textChanged, this, &MainWindow::slotGoalDescriptionEdited);
193   connect (m_goalDefWidget->nbcountries,SIGNAL(valueChanged(int)), this, SLOT(slotGoalNbCountriesChanged(int)));
194   connect (m_goalDefWidget->armiesbycountry,SIGNAL(valueChanged(int)), this, SLOT(slotGoalNbArmiesByCountryChanged(int)));
195   connect (m_goalDefWidget->anycontinent,&QCheckBox::stateChanged, this, &MainWindow::slotGoalAnyContinentChanged);
196   connect (m_goalDefWidget->selectcontinentsbutton, &QAbstractButton::clicked, this, &MainWindow::slotGoalContinents);
197   connect(m_skinDefWidget->newGoalButton, &QAbstractButton::clicked, this, &MainWindow::slotNewGoal);
198   connect(m_skinDefWidget->deleteGoalButton, &QAbstractButton::clicked, this, &MainWindow::slotDeleteGoal);
199 
200   m_nationalityDefWidget = new KsirkNationalityDefinitionWidget(this);
201   addDockWidget ( Qt::RightDockWidgetArea, m_nationalityDefWidget);
202   m_nationalityDefWidget->hide();
203 
204   m_spritesDefWidget = new KsirkSpritesDefinitionWidget(this);
205   addDockWidget ( Qt::RightDockWidgetArea, m_spritesDefWidget);
206   m_spritesDefWidget->hide();
207   connect(m_spritesDefWidget->flagw, SIGNAL(valueChanged(int)), this, SLOT(slotFlagWidthChanged(int)));
208   connect(m_spritesDefWidget->flagh, SIGNAL(valueChanged(int)), this, SLOT(slotFlagHeightChanged(int)));
209   connect(m_spritesDefWidget->flagf, SIGNAL(valueChanged(int)), this, SLOT(slotFlagFramesChanged(int)));
210   connect(m_spritesDefWidget->flagv, SIGNAL(valueChanged(int)), this, SLOT(slotFlagVersionsChanged(int)));
211 
212   connect(m_spritesDefWidget->infantryw, SIGNAL(valueChanged(int)), this, SLOT(slotInfantryWidthChanged(int)));
213   connect(m_spritesDefWidget->infantryh, SIGNAL(valueChanged(int)), this, SLOT(slotInfantryHeightChanged(int)));
214   connect(m_spritesDefWidget->infantryf, SIGNAL(valueChanged(int)), this, SLOT(slotInfantryFramesChanged(int)));
215   connect(m_spritesDefWidget->infantryv, SIGNAL(valueChanged(int)), this, SLOT(slotInfantryVersionsChanged(int)));
216 
217   connect(m_spritesDefWidget->cavalryw, SIGNAL(valueChanged(int)), this, SLOT(slotCavalryWidthChanged(int)));
218   connect(m_spritesDefWidget->cavalryh, SIGNAL(valueChanged(int)), this, SLOT(slotCavalryHeightChanged(int)));
219   connect(m_spritesDefWidget->cavalryf, SIGNAL(valueChanged(int)), this, SLOT(slotCavalryFramesChanged(int)));
220   connect(m_spritesDefWidget->cavalryv, SIGNAL(valueChanged(int)), this, SLOT(slotCavalryVersionsChanged(int)));
221 
222   connect(m_spritesDefWidget->cannonw, SIGNAL(valueChanged(int)), this, SLOT(slotCannonWidthChanged(int)));
223   connect(m_spritesDefWidget->cannonh, SIGNAL(valueChanged(int)), this, SLOT(slotCannonHeightChanged(int)));
224   connect(m_spritesDefWidget->cannonf, SIGNAL(valueChanged(int)), this, SLOT(slotCannonFramesChanged(int)));
225   connect(m_spritesDefWidget->cannonv, SIGNAL(valueChanged(int)), this, SLOT(slotCannonVersionsChanged(int)));
226 
227   connect(m_spritesDefWidget->firingw, SIGNAL(valueChanged(int)), this, SLOT(slotFiringWidthChanged(int)));
228   connect(m_spritesDefWidget->firingh, SIGNAL(valueChanged(int)), this, SLOT(slotFiringHeightChanged(int)));
229   connect(m_spritesDefWidget->firingf, SIGNAL(valueChanged(int)), this, SLOT(slotFiringFramesChanged(int)));
230   connect(m_spritesDefWidget->firingv, SIGNAL(valueChanged(int)), this, SLOT(slotFiringVersionsChanged(int)));
231 
232   connect(m_spritesDefWidget->explodingw, SIGNAL(valueChanged(int)), this, SLOT(slotExplodingWidthChanged(int)));
233   connect(m_spritesDefWidget->explodingh, SIGNAL(valueChanged(int)), this, SLOT(slotExplodingHeightChanged(int)));
234   connect(m_spritesDefWidget->explodingf, SIGNAL(valueChanged(int)), this, SLOT(slotExplodingFramesChanged(int)));
235   connect(m_spritesDefWidget->explodingv, SIGNAL(valueChanged(int)), this, SLOT(slotExplodingVersionsChanged(int)));
236 
237 
238   connect(m_skinDefWidget->qtabwidget, &QTabWidget::currentChanged, this, &MainWindow::slotSkinPartTabChanged);
239   m_skinDefWidget->qtabwidget-> setCurrentIndex(0);
240 
241   m_skinDefWidget->countrieslist->setSortingEnabled (true);
242   connect(m_skinDefWidget->countrieslist, &QListWidget::itemClicked, this, &MainWindow::slotCountrySelected);
243 
244   connect(m_skinDefWidget->goalslist, &QListWidget::itemClicked, this, &MainWindow::slotGoalSelected);
245 
246   connect (m_countryDefWidget->neighboursbutton, &QAbstractButton::clicked, this, &MainWindow::slotNeighbours);
247   connect (m_countryDefWidget->flagx, SIGNAL(valueChanged(int)), this, SLOT(slotFLagxValueChanged(int)));
248   connect (m_countryDefWidget->flagy, SIGNAL(valueChanged(int)), this, SLOT(slotFLagyValueChanged(int)));
249   connect (m_countryDefWidget->centerx, SIGNAL(valueChanged(int)), this, SLOT(slotCenterxValueChanged(int)));
250   connect (m_countryDefWidget->centery, SIGNAL(valueChanged(int)), this, SLOT(slotCenteryValueChanged(int)));
251   connect (m_countryDefWidget->anchorx, SIGNAL(valueChanged(int)), this, SLOT(slotAnchorxValueChanged(int)));
252   connect (m_countryDefWidget->anchory, SIGNAL(valueChanged(int)), this, SLOT(slotAnchoryValueChanged(int)));
253   connect (m_countryDefWidget->infantryx, SIGNAL(valueChanged(int)), this, SLOT(slotInfantryxValueChanged(int)));
254   connect (m_countryDefWidget->infantryy, SIGNAL(valueChanged(int)), this, SLOT(slotInfantryyValueChanged(int)));
255   connect (m_countryDefWidget->cavalryx, SIGNAL(valueChanged(int)), this, SLOT(slotCavalryxValueChanged(int)));
256   connect (m_countryDefWidget->cavalryy, SIGNAL(valueChanged(int)), this, SLOT(slotCavalryyValueChanged(int)));
257   connect (m_countryDefWidget->cannonx, SIGNAL(valueChanged(int)), this, SLOT(slotCannonxValueChanged(int)));
258   connect (m_countryDefWidget->cannony, SIGNAL(valueChanged(int)), this, SLOT(slotCannonyValueChanged(int)));
259 
260 
261   connect (m_skinDefWidget->skinNameLineEdit, &QLineEdit::editingFinished, this, &MainWindow::slotSkinNameEdited);
262 
263   connect (m_skinDefWidget->widthLineEdit, SIGNAL(valueChanged(int)), this, SLOT(slotSkinWidthEdited(int)));
264   connect (m_skinDefWidget->heightLineEdit, SIGNAL(valueChanged(int)), this, SLOT(slotSkinHeightEdited(int)));
265 
266   connect (m_skinDefWidget->descriptionTextEdit,&QTextEdit::textChanged, this, &MainWindow::slotSkinDescriptionEdited);
267 
268   QIntValidator* widthDiffValidator = new QIntValidator(this);
269   m_spritesDefWidget->widthDiffLineEdit->setValidator(widthDiffValidator);
270   connect (m_spritesDefWidget->widthDiffLineEdit, &QLineEdit::editingFinished, this, &MainWindow::slotSkinWidthDiffEdited);
271 
272   m_skinDefWidget->nationalitieslist->setSortingEnabled (true);
273   connect(m_skinDefWidget->nationalitieslist, &QListWidget::itemClicked, this, &MainWindow::slotNationalitySelected);
274   connect(m_skinDefWidget->newNationalityButton, &QAbstractButton::clicked, this, &MainWindow::slotNewNationality);
275   connect(m_skinDefWidget->deleteNationalityButton, &QAbstractButton::clicked, this, &MainWindow::slotDeleteNationality);
276 
277   connect(m_nationalityDefWidget->name,&QLineEdit::editingFinished, this, &MainWindow::slotNationalityNameEdited);
278   connect(m_nationalityDefWidget->leader,&QLineEdit::editingFinished, this, &MainWindow::slotNationalityLeaderNameEdited);
279   connect(m_nationalityDefWidget->flag,SIGNAL(currentIndexChanged(int)), this, SLOT(slotNationalityFlagEdited(int)));
280 
281 
282   connect(m_skinDefWidget->newCountryButton, &QAbstractButton::clicked, this, &MainWindow::slotNewCountry);
283   connect(m_skinDefWidget->deleteCountryButton, &QAbstractButton::clicked, this, &MainWindow::slotDeleteCountry);
284 
285   m_skinDefWidget->continentslist->setSortingEnabled (true);
286   connect(m_skinDefWidget->continentslist, &QListWidget::itemClicked, this, &MainWindow::slotContinentSelected);
287 
288   connect(m_skinDefWidget->newContinentButton, &QAbstractButton::clicked, this, &MainWindow::slotNewContinent);
289   connect(m_skinDefWidget->deleteContinentButton, &QAbstractButton::clicked, this, &MainWindow::slotDeleteContinent);
290 
291   connect (m_continentDefWidget->selectcountriesbutton, &QAbstractButton::clicked, this, &MainWindow::slotContinentCountries);
292 
293   connect (m_continentDefWidget->bonus, SIGNAL(valueChanged(int)), this, SLOT(slotContinentBonusEdited(int)));
294 
295   qCDebug(KSIRKSKINEDITOR_LOG) << "Setting up GUI";
296   setupGUI();
297 
298   //    qCDebug(KSIRKSKINEDITOR_LOG) << "Before initStatusBar";
299   initStatusBar();
300 
301   menuBar()-> show();
302 
303   setMouseTracking(true);
304 
305 }
306 
~MainWindow()307 MainWindow::~MainWindow()
308 {
309   qCDebug(KSIRKSKINEDITOR_LOG);
310   KSharedConfig::Ptr config = KSharedConfig::openConfig();
311   if (m_rfa != 0)
312   {
313     qCDebug(KSIRKSKINEDITOR_LOG) << "saving recent files";
314     m_rfa->saveEntries(KSharedConfig::openConfig()->group("ksirkskineditor"));
315   }
316 }
317 
initActions()318 void MainWindow::initActions()
319 {
320   QAction *action;
321   // standard game actions
322   action = KStandardGameAction::load(this, SLOT(slotOpenSkin()), this);
323   actionCollection()->addAction(action->objectName(), action);
324   action->setToolTip(i18n("Open a saved skin..."));
325 
326   m_rfa = KStandardGameAction::loadRecent (this, SLOT(slotURLSelected(QUrl)), this);
327   actionCollection()->addAction(m_rfa->objectName(), m_rfa);
328   m_rfa->setText(i18n("Load &Recent"));
329   m_rfa->setToolTip(i18n("Open a recently saved skin..."));
330 
331   KSharedConfig::Ptr config = KSharedConfig::openConfig();
332   qCDebug(KSIRKSKINEDITOR_LOG) << "loading recent files";
333   m_rfa->loadEntries(KSharedConfig::openConfig()->group("ksirkskineditor"));
334 
335   m_saveGameAction = KStandardGameAction::save(this, SLOT(slotSaveSkin()), this);
336   actionCollection()->addAction(m_saveGameAction->objectName(), m_saveGameAction);
337   m_saveGameAction->setToolTip(i18n("Save the current skin"));
338 
339   action = KStandardGameAction::quit(this, SLOT(close()), this);
340   actionCollection()->addAction(action->objectName(), action);
341 
342 //   action = KStandardGameAction::gameNew(this, SLOT(slotNewGame()), this);
343 //   actionCollection()->addAction(action->objectName(), action);
344 
345 //   action = KStandardAction::zoomIn(this, SLOT(slotZoomIn()), this);
346 //   actionCollection()->addAction(action->objectName(), action);
347 
348 //   action = KStandardAction::zoomOut(this, SLOT(slotZoomOut()), this);
349 //   actionCollection()->addAction(action->objectName(), action);
350 
351   KStandardAction::preferences( this, SLOT(optionsConfigure()), actionCollection() );
352 
353 }
354 
initStatusBar()355 void MainWindow::initStatusBar()
356 {
357   statusBar()-> setSizeGripEnabled(true);
358 }
359 
slotOpenSkin(const QString & dir)360 void MainWindow::slotOpenSkin(const QString& dir)
361 {
362   qCDebug(KSIRKSKINEDITOR_LOG) << dir;
363   QString skinDir = dir;
364   if (dir.isNull())
365   {
366     skinDir = QFileDialog::getExistingDirectory(this, i18nc("@title:window", "Choose the Root Folder of the Skin to Open"), QString());
367   }
368   if (skinDir.isEmpty())
369   {
370     return;
371   }
372 
373   if (m_rfa != 0)
374   {
375     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding" << skinDir << "to recent files";
376     m_rfa->addUrl(QUrl::fromLocalFile(skinDir));
377   }
378 
379   m_mapScene->clear();
380   m_skinDefWidget->countrieslist->clear();
381   m_skinDefWidget->continentslist->clear();
382   m_skinDefWidget->goalslist->clear();
383 
384   delete m_onu;
385   m_onu = new ONU(skinDir, this);
386 
387   m_skinDefWidget->fontrequester->setFont(m_onu->foregroundFont());
388   m_skinDefWidget->fgcolorbutton->setColor(m_onu->foregroundColor());
389   m_skinDefWidget->bgcolorbutton->setColor(m_onu->backgroundColor());
390 
391   m_skinDefWidget->skinNameLineEdit->setText(m_onu->name());
392   m_skinDefWidget->widthLineEdit->setValue(m_onu->width());
393   m_skinDefWidget->heightLineEdit->setValue(m_onu->height());
394   m_skinDefWidget->descriptionTextEdit->setText(m_onu->description());
395   m_spritesDefWidget->widthDiffLineEdit->setText(QString::number(SkinSpritesData::changeable().intData(QStringLiteral("width-between-flag-and-fighter"))));
396 
397   m_spritesDefWidget->flagw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("flag-width")));
398   m_spritesDefWidget->flagh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("flag-height")));
399   m_spritesDefWidget->flagf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("flag-frames")));
400   m_spritesDefWidget->flagv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("flag-versions")));
401 
402   m_spritesDefWidget->infantryw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("infantry-width")));
403   m_spritesDefWidget->infantryh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("infantry-height")));
404   m_spritesDefWidget->infantryf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("infantry-frames")));
405   m_spritesDefWidget->infantryv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("infantry-versions")));
406 
407   m_spritesDefWidget->cavalryw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cavalry-width")));
408   m_spritesDefWidget->cavalryh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cavalry-height")));
409   m_spritesDefWidget->cavalryf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cavalry-frames")));
410   m_spritesDefWidget->cavalryv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cavalry-versions")));
411 
412   m_spritesDefWidget->cannonw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cannon-width")));
413   m_spritesDefWidget->cannonh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cannon-height")));
414   m_spritesDefWidget->cannonf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cannon-frames")));
415   m_spritesDefWidget->cannonv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cannon-versions")));
416 
417   m_spritesDefWidget->firingw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("firing-width")));
418   m_spritesDefWidget->firingh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("firing-height")));
419   m_spritesDefWidget->firingf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("firing-frames")));
420   m_spritesDefWidget->firingv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("firing-versions")));
421 
422   m_spritesDefWidget->explodingw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("exploding-width")));
423   m_spritesDefWidget->explodingh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("exploding-height")));
424   m_spritesDefWidget->explodingf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("exploding-frames")));
425   m_spritesDefWidget->explodingv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("exploding-versions")));
426 
427   m_nationalityDefWidget->flag->clear();
428   foreach(const QString& key, m_onu->poolIds())
429   {
430     int flagWidth = SkinSpritesData::changeable().intData(QStringLiteral("flag-width"));
431     int flagHeight = SkinSpritesData::changeable().intData(QStringLiteral("flag-height"));
432     int flagFrames = SkinSpritesData::changeable().intData(QStringLiteral("flag-frames"));
433     int flagVersions = SkinSpritesData::changeable().intData(QStringLiteral("flag-versions"));
434     QPixmap flagIcon = m_onu->pixmapForId(key,flagWidth*flagFrames,flagHeight*flagVersions).copy(0,0,flagWidth,flagHeight);
435     m_nationalityDefWidget->flag->insertItem(m_nationalityDefWidget->flag->count(),QIcon(flagIcon),key);
436   }
437 
438 
439   QPixmap mapPixmap(m_onu->pixmapForId(QStringLiteral("map"), m_onu->width(), m_onu->height()));
440   m_mapItem = m_mapScene->addPixmap(mapPixmap);
441 
442   m_flagButton->setIcon(m_onu->flagIcon());
443   //   m_flagButton->setIconSize(QSize(flagWidth,flagHeight));
444 
445   m_infantryButton->setIcon(m_onu->infantryIcon());
446   //   m_infantryButton->setIconSize(QSize(infantryWidth,infantryHeight));
447 
448   m_cavalryButton->setIcon(m_onu->cavalryIcon());
449   //   m_cavalryButton->setIconSize(QSize(cavalryWidth,cavalryHeight));
450 
451   m_cannonButton->setIcon(m_onu->cannonIcon());
452   //   m_cannonButton->setIconSize(QSize(cannonWidth,cannonHeight));
453 
454   qCDebug(KSIRKSKINEDITOR_LOG) << "Adding nationalities items";
455   foreach (Nationality* nationality, m_onu->nationalities())
456   {
457     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding "<<nationality->name()<<" items";
458     m_skinDefWidget->nationalitieslist->addItem(nationality->name());
459   }
460 
461   qCDebug(KSIRKSKINEDITOR_LOG) << "Adding countries items";
462   foreach (Country* country, m_onu->countries())
463   {
464     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding "<<country->name()<<" items";
465     m_skinDefWidget->countrieslist->addItem(country->name());
466 
467     if (!country->pointFlag().isNull())
468     {
469       createPixmapFor(country, Flag);
470     }
471     if (!country->pointInfantry().isNull())
472     {
473       createPixmapFor(country, Infantry);
474     }
475     if (!country->pointCavalry().isNull())
476     {
477       createPixmapFor(country, Cavalry);
478     }
479     if (!country->pointCannon().isNull())
480     {
481       createPixmapFor(country, Cannon);
482     }
483     if (!country->anchorPoint().isNull())
484     {
485       createPixmapFor(country, Anchor);
486     }
487     if (!country->centralPoint().isNull())
488     {
489       createPixmapFor(country, Center);
490     }
491   }
492 
493   qCDebug(KSIRKSKINEDITOR_LOG) << "Adding continents items";
494   foreach (Continent* continent, m_onu->continents())
495   {
496     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding "<<continent<<" items";
497     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding "<<continent->name()<<" items";
498     m_skinDefWidget->continentslist->addItem(continent->name());
499   }
500 
501   qCDebug(KSIRKSKINEDITOR_LOG) << "Adding goals items";
502   for (int i = 1; i <= m_onu->goals().size(); i++)
503   {
504     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding goal"<<i<<" items";
505     m_skinDefWidget->goalslist->addItem("goal" + QString::number(i));
506   }
507 }
508 
slotSaveSkin()509 void MainWindow::slotSaveSkin()
510 {
511   qCDebug(KSIRKSKINEDITOR_LOG);
512   m_onu->saveConfig();
513 }
514 
515 /**
516   * Reimplementation of the inherited function called when a window close event arise
517   */
queryClose()518 bool MainWindow::queryClose()
519 {
520   qCDebug(KSIRKSKINEDITOR_LOG);
521   // TODO : Test si jeu en cours
522   if (m_onu && m_onu->dirty())
523   {
524     switch (KMessageBox::warningYesNoCancel(this,i18n("There are unsaved changes. What do you want to do?"),
525       i18n("Exit Anyway?"),
526                                              KGuiItem(i18n("Quit without saving")),
527                                              KGuiItem(i18n("Save then quit")),
528                                              KGuiItem(i18n("Do not quit"))))
529     {
530       case KMessageBox::Yes:
531         return true;
532         break;
533       case KMessageBox::No:
534         m_onu->saveConfig();
535         return true;
536         break;
537       default:
538         return false;
539     }
540   }
541   KSharedConfig::openConfig()->sync();
542   return true;
543 }
544 
optionsConfigure()545 void MainWindow::optionsConfigure()
546 {
547   //An instance of your dialog could be already created and could be cached,
548   //in which case you want to display the cached dialog instead of creating
549   //another one
550   if ( KsirkSkinEditorConfigurationDialog::showDialog( QStringLiteral("settings") ) )
551     return;
552 
553   //KConfigDialog didn't find an instance of this dialog, so lets create it :
554   KsirkSkinEditorConfigurationDialog* dialog = new KsirkSkinEditorConfigurationDialog(
555       this, "settings",
556       KsirkSkinEditorSettings::self() );
557 
558   dialog->show();
559 }
560 
561 // void MainWindow::slotZoomIn()
562 // {
563 //   qCDebug(KSIRKSKINEDITOR_LOG);
564 // }
565 
566 // void MainWindow::slotZoomOut()
567 // {
568 //   qCDebug(KSIRKSKINEDITOR_LOG);
569 // }
570 
slotShowAboutApplication()571 void MainWindow::slotShowAboutApplication()
572 {
573 #if 0 //QT5
574   KAboutApplicationDialog dialog(KGlobal::mainComponent().aboutData(), this);
575   dialog.exec();
576 #endif
577 }
578 
slotFlagButtonClicked()579 void MainWindow::slotFlagButtonClicked()
580 {
581   m_infantryButton->setChecked(false);
582   m_cavalryButton->setChecked(false);
583   m_cannonButton->setChecked(false);
584   m_anchorButton->setChecked(false);
585   m_centerButton->setChecked(false);
586   if (m_selectedSprite == Flag)
587   {
588     m_flagButton->setChecked(false);
589     m_mapView->unsetCursor();
590   }
591   else if (m_skinDefWidget->countrieslist->currentItem()!=0)
592   {
593     m_mapView->setCursor(QCursor(m_onu->flagIcon(),0,0));
594     m_selectedSprite = Flag;
595     m_flagButton->setChecked(true);
596   }
597 }
598 
slotInfantryButtonClicked()599 void MainWindow::slotInfantryButtonClicked()
600 {
601   m_flagButton->setChecked(false);
602   m_cavalryButton->setChecked(false);
603   m_cannonButton->setChecked(false);
604   m_anchorButton->setChecked(false);
605   m_centerButton->setChecked(false);
606   if (m_selectedSprite == Infantry)
607   {
608     m_infantryButton->setChecked(false);
609     m_mapView->unsetCursor();
610   }
611   else if (m_skinDefWidget->countrieslist->currentItem()!=0)
612   {
613     m_mapView->setCursor(QCursor(m_onu->infantryIcon(),0,0));
614     m_selectedSprite = Infantry;
615     m_infantryButton->setChecked(true);
616   }
617 }
618 
slotCavalryButtonClicked()619 void MainWindow::slotCavalryButtonClicked()
620 {
621   m_flagButton->setChecked(false);
622   m_infantryButton->setChecked(false);
623   m_cannonButton->setChecked(false);
624   m_anchorButton->setChecked(false);
625   m_centerButton->setChecked(false);
626   if (m_selectedSprite == Cavalry)
627   {
628     m_cavalryButton->setChecked(false);
629     m_mapView->unsetCursor();
630   }
631   else if (m_skinDefWidget->countrieslist->currentItem()!=0)
632   {
633     m_mapView->setCursor(QCursor(m_onu->cavalryIcon(),0,0));
634     m_selectedSprite = Cavalry;
635     m_cavalryButton->setChecked(true);
636   }
637 }
638 
slotCannonButtonClicked()639 void MainWindow::slotCannonButtonClicked()
640 {
641   m_flagButton->setChecked(false);
642   m_infantryButton->setChecked(false);
643   m_cavalryButton->setChecked(false);
644   m_anchorButton->setChecked(false);
645   m_centerButton->setChecked(false);
646   if (m_selectedSprite == Cannon)
647   {
648     m_cannonButton->setChecked(false);
649     m_mapView->unsetCursor();
650   }
651   else if (m_skinDefWidget->countrieslist->currentItem()!=0)
652   {
653     m_mapView->setCursor(QCursor(m_onu->cannonIcon(),0,0));
654     m_selectedSprite = Cannon;
655     m_cannonButton->setChecked(true);
656   }
657 }
658 
slotAnchorButtonClicked()659 void MainWindow::slotAnchorButtonClicked()
660 {
661   m_flagButton->setChecked(false);
662   m_infantryButton->setChecked(false);
663   m_cavalryButton->setChecked(false);
664   m_cannonButton->setChecked(false);
665   m_centerButton->setChecked(false);
666   if (m_selectedSprite == Anchor)
667   {
668     m_anchorButton->setChecked(false);
669     m_mapView->unsetCursor();
670   }
671   else if (m_skinDefWidget->countrieslist->currentItem()!=0)
672   {
673     QString anchorFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("cross.png"));
674     if (anchorFileName.isNull())
675     {
676       KMessageBox::error(0, i18n("Cannot load anchor icon<br>Program cannot continue"), i18n("Error"));
677       exit(2);
678     }
679     QPixmap anchorPix = QPixmap(anchorFileName);
680     anchorPix = anchorPix.scaled(16,16);
681 
682     m_mapView->setCursor(QCursor(anchorPix,0,0));
683     m_selectedSprite = Anchor;
684     m_anchorButton->setChecked(true);
685   }
686 }
687 
slotCenterButtonClicked()688 void MainWindow::slotCenterButtonClicked()
689 {
690   m_flagButton->setChecked(false);
691   m_infantryButton->setChecked(false);
692   m_cavalryButton->setChecked(false);
693   m_cannonButton->setChecked(false);
694   m_anchorButton->setChecked(false);
695   if (m_selectedSprite == Center)
696   {
697     m_centerButton->setChecked(false);
698     m_mapView->unsetCursor();
699   }
700   else if (m_skinDefWidget->countrieslist->currentItem()!=0)
701   {
702     QString centerFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("target.png"));
703     if (centerFileName.isNull())
704     {
705       KMessageBox::error(0, i18n("Cannot load center icon<br>Program cannot continue"), i18n("Error"));
706       exit(2);
707     }
708     QPixmap centerPix = QPixmap(centerFileName);
709     centerPix = centerPix.scaled(16,16);
710     m_mapView->setCursor(QCursor(centerPix,0,0));
711     m_selectedSprite = Center;
712     m_centerButton->setChecked(true);
713   }
714 }
715 
slotPosition(const QPointF & point)716 void MainWindow::slotPosition(const QPointF& point)
717 {
718   QString message(QLatin1String(""));
719   QTextStream ts( &message );
720   ts << point.x() << " x " << point.y();
721   statusBar()->showMessage(message);
722 //   qCDebug(KSIRKSKINEDITOR_LOG) << "selected sprite:" << m_selectedSprite;
723   if (currentCountry() != 0 && m_selectedSprite == Anchor
724     && m_onu->itemFor(currentCountry(), m_selectedSprite) != 0 && m_updateHighlightPosition
725     && currentCountry()->highlighting() != 0)
726   {
727     qCDebug(KSIRKSKINEDITOR_LOG) << point << (void*)currentCountry() << (void*)m_onu->itemFor(currentCountry(), m_selectedSprite);
728     QGraphicsItem* anchorItem = m_onu->itemFor(currentCountry(), Anchor);
729     qCDebug(KSIRKSKINEDITOR_LOG) << "anchorItem=" << anchorItem;
730     currentCountry()->anchorPoint(point);
731     QPointF anchorPoint = currentCountry()->anchorPoint();
732 
733     double hw = currentCountry()->highlighting()->boundingRect().width();
734     double hh = currentCountry()->highlighting()->boundingRect().height();
735     currentCountry()->highlighting()->setPos(anchorPoint - QPointF(hw/2,hh/2 ));
736 
737     return;
738   }
739 }
740 
slotPressPosition(const QPointF & clickedPoint)741 void MainWindow::slotPressPosition(const QPointF& clickedPoint)
742 {
743   qCDebug(KSIRKSKINEDITOR_LOG) << clickedPoint << (void*)currentCountry() << m_selectedSprite;
744   QPixmap pix;
745   QPixmap alphacopy;
746   QString fileName;
747   QPointF point = clickedPoint;
748   m_updateHighlightPosition = true;
749   if (currentCountry() == 0
750     || m_onu->itemFor(currentCountry(), m_selectedSprite) != 0)
751   {
752     qCDebug(KSIRKSKINEDITOR_LOG) << (void*)currentCountry() << (void*)m_onu->itemFor(currentCountry(), m_selectedSprite);
753     if (currentCountry() != 0)
754     {
755       currentCountry()->clearHighlighting();
756     }
757     return;
758   }
759   PixmapItem* item = new PixmapItem();
760   item->setZValue(10);
761   connect(item, &PixmapItem::pressed,this, &MainWindow::slotItemPressed);
762   connect(item, &PixmapItem::placed,this, &MainWindow::slotItemPlaced);
763 
764   switch (m_selectedSprite)
765   {
766     case Flag:
767       pix = m_onu->flagIcon();
768 //       pix = pix.scaled(20,20);
769       m_countryDefWidget->flagx->setValue(point.x());
770       m_countryDefWidget->flagy->setValue(point.y());
771       currentCountry()->pointFlag(point);
772       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Flag));
773       break;
774     case Infantry:
775       pix = m_onu->infantryIcon();
776 //       pix = pix.scaled(23,32);
777       m_countryDefWidget->infantryx->setValue(point.x());
778       m_countryDefWidget->infantryy->setValue(point.y());
779       currentCountry()->pointInfantry(point);
780       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Infantry));
781       break;
782     case Cavalry:
783       pix = m_onu->cavalryIcon();
784 //       pix = pix.scaled(32,32);
785       m_countryDefWidget->cavalryx->setValue(point.x());
786       m_countryDefWidget->cavalryy->setValue(point.y());
787       currentCountry()->pointCavalry(point);
788       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Cavalry));
789       break;
790     case Cannon:
791       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding cannon";
792       pix = m_onu->cannonIcon();
793 //       pix = pix.scaled(32,32);
794       m_countryDefWidget->cannonx->setValue(point.x());
795       m_countryDefWidget->cannony->setValue(point.y());
796       currentCountry()->pointCannon(point);
797       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Cannon));
798       break;
799     case Anchor:
800       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding anchor";
801       fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("cross.png"));
802       if (fileName.isNull())
803       {
804         KMessageBox::error(0, i18n("Cannot load anchor icon<br>Program cannot continue"), i18n("Error"));
805         exit(2);
806       }
807       pix = QPixmap(fileName);
808       pix = pix.scaled(16,16);
809       point += QPointF(-pix.width()/2,-pix.height()/2);
810       m_countryDefWidget->anchorx->setValue(point.x());
811       m_countryDefWidget->anchory->setValue(point.y());
812       currentCountry()->anchorPoint(point);
813       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Anchor));
814       m_updateHighlightPosition = true;
815       break;
816     case Center:
817       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding center";
818       fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("target.png"));
819       if (fileName.isNull())
820       {
821         KMessageBox::error(0, i18n("Cannot load center icon<br>Program cannot continue"), i18n("Error"));
822         exit(2);
823       }
824       pix = QPixmap(fileName);
825       pix = pix.scaled(16,16);
826       point += QPointF(-pix.width()/2,-pix.height()/2);
827       m_countryDefWidget->centerx->setValue(point.x());
828       m_countryDefWidget->centery->setValue(point.y());
829       currentCountry()->centralPoint(point);
830       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Center));
831       break;
832     default: ;
833   }
834   if (item != 0)
835   {
836     item->setPixmap(pix);
837     m_mapScene->addItem(item);
838     item->setFlag(QGraphicsItem::ItemIsMovable, true);
839     item->setFlag(QGraphicsItem::ItemIsSelectable, true);
840     item->setPos(point);
841   }
842 }
843 
slotReleasePosition(const QPointF & point)844 void MainWindow::slotReleasePosition(const QPointF& point)
845 {
846   qCDebug(KSIRKSKINEDITOR_LOG) << point;
847   m_updateHighlightPosition = false;
848 
849   qCDebug(KSIRKSKINEDITOR_LOG) << "selected sprite:" << m_selectedSprite;
850   if (currentCountry() != 0 && m_selectedSprite == Anchor
851     && m_onu->itemFor(currentCountry(), m_selectedSprite) != 0 && m_updateHighlightPosition
852     && currentCountry()->highlighting() != 0)
853   {
854     qCDebug(KSIRKSKINEDITOR_LOG) << (void*)currentCountry() << (void*)m_onu->itemFor(currentCountry(), m_selectedSprite);
855     currentCountry()->anchorPoint(point);
856     currentCountry()->highlighting()->setPos((currentCountry()->anchorPoint().x()-currentCountry()->highlighting()->boundingRect().width()/2),(currentCountry()->anchorPoint().y()-currentCountry()->highlighting()->boundingRect().height()/2));
857 
858     return;
859   }
860 }
861 
slotNationalitySelected(QListWidgetItem * item)862 void MainWindow::slotNationalitySelected(QListWidgetItem* item)
863 {
864   qCDebug(KSIRKSKINEDITOR_LOG);
865   Nationality* nationality = m_onu->nationalityNamed(item->text());
866   if (nationality != 0)
867   {
868     initNationalityWidgetWith(nationality);
869   }
870 }
871 
initNationalityWidgetWith(Nationality * nationality)872 void MainWindow::initNationalityWidgetWith(Nationality* nationality)
873 {
874   qCDebug(KSIRKSKINEDITOR_LOG);
875   m_nationalityDefWidget->name->setText(nationality->name());
876   m_nationalityDefWidget->leader->setText(nationality->leaderName());
877   int item = m_nationalityDefWidget->flag->findText(nationality->flagFileName());
878   if (item != -1)
879   {
880       m_nationalityDefWidget->flag->setCurrentIndex(item);
881   }
882 }
883 
slotCountrySelected(QListWidgetItem * item)884 void MainWindow::slotCountrySelected(QListWidgetItem* item)
885 {
886   qCDebug(KSIRKSKINEDITOR_LOG);
887   Country* country = m_onu->countryNamed(item->text());
888   if (country != 0)
889   {
890     m_countryDefWidget->initWith(country);
891     initSpritesButtonsWith(country);
892   }
893 }
894 
slotContinentSelected(QListWidgetItem * item)895 void MainWindow::slotContinentSelected(QListWidgetItem* item)
896 {
897   qCDebug(KSIRKSKINEDITOR_LOG);
898   Continent* continent = m_onu->continentNamed(item->text());
899   if (continent != 0)
900   {
901     initContinentWidgetWith(continent);
902   }
903 }
904 
initContinentWidgetWith(Continent * continent)905 void MainWindow::initContinentWidgetWith(Continent* continent)
906 {
907   qCDebug(KSIRKSKINEDITOR_LOG);
908   m_continentDefWidget->bonus->setValue(continent->bonus());
909 
910   m_continentDefWidget->countrieslist->clear();
911   foreach(Country* country, continent->members())
912   {
913     m_continentDefWidget->countrieslist->addItem(country->name());
914   }
915 }
916 
slotGoalSelected(QListWidgetItem * item)917 void MainWindow::slotGoalSelected(QListWidgetItem* item)
918 {
919   qCDebug(KSIRKSKINEDITOR_LOG);
920   int row = m_skinDefWidget->goalslist->row(item);
921   Goal* goal = m_onu->goals()[row];
922   if (goal != 0)
923   {
924     initGoalWidgetWith(goal);
925   }
926 }
927 
initGoalWidgetWith(Goal * goal)928 void MainWindow::initGoalWidgetWith(Goal* goal)
929 {
930   qCDebug(KSIRKSKINEDITOR_LOG);
931   switch (goal->type())
932   {
933     case Goal::NoGoal:
934       m_goalDefWidget->worldtype->setChecked(true);
935       m_goalDefWidget->playertype->setChecked(false);
936       m_goalDefWidget->countriestype->setChecked(false);
937       m_goalDefWidget->continentstype->setChecked(false);
938       break;
939     case Goal::GoalPlayer:
940       m_goalDefWidget->worldtype->setChecked(false);
941       m_goalDefWidget->playertype->setChecked(true);
942       m_goalDefWidget->countriestype->setChecked(false);
943       m_goalDefWidget->continentstype->setChecked(false);
944       break;
945     case Goal::Countries:
946       m_goalDefWidget->worldtype->setChecked(false);
947       m_goalDefWidget->playertype->setChecked(false);
948       m_goalDefWidget->countriestype->setChecked(true);
949       m_goalDefWidget->continentstype->setChecked(false);
950       break;
951     case Goal::Continents:
952       m_goalDefWidget->worldtype->setChecked(false);
953       m_goalDefWidget->playertype->setChecked(false);
954       m_goalDefWidget->countriestype->setChecked(false);
955       m_goalDefWidget->continentstype->setChecked(true);
956       break;
957     default:;
958   }
959   m_goalDefWidget->description->setText(goal->description());
960   m_goalDefWidget->nbcountries->setValue(goal->nbCountries());
961   m_goalDefWidget->armiesbycountry->setValue(goal->nbArmiesByCountry());
962   m_goalDefWidget->anycontinent->setChecked(false);
963   m_goalDefWidget->continentslist->clear();
964   foreach(const QString& id, goal->continents())
965   {
966     qCDebug(KSIRKSKINEDITOR_LOG) << "continent" << id;
967     if (id.isNull())
968     {
969       m_goalDefWidget->anycontinent->setChecked(true);
970     }
971     foreach(Continent* continent, m_onu->continents())
972     {
973       if (continent->name() == id)
974       {
975         m_goalDefWidget->continentslist->addItem(continent->name());
976       }
977     }
978   }
979 }
980 
currentCountry()981 Country* MainWindow::currentCountry()
982 {
983   if (m_skinDefWidget->countrieslist->currentItem() == 0)
984     return 0;
985 //   qCDebug(KSIRKSKINEDITOR_LOG) << m_skinDefWidget->countrieslist->currentItem()->text();
986   return m_onu->countryNamed(m_skinDefWidget->countrieslist->currentItem()->text());
987 }
988 
slotItemPlaced(QGraphicsItem * item,const QPointF &)989 void MainWindow::slotItemPlaced(QGraphicsItem* item, const QPointF&)
990 {
991   qCDebug(KSIRKSKINEDITOR_LOG);
992   if (m_onu->itemsMap().contains(item))
993   {
994     Country* country = m_onu->itemsMap()[item].first;
995     SpriteType type = m_onu->itemsMap()[item].second;
996     m_countryDefWidget->initWith(country);
997     for (int i = 0; i != m_skinDefWidget->countrieslist->count(); i++)
998     {
999       if (m_skinDefWidget->countrieslist->item(i)->text() == country->name())
1000       {
1001         m_skinDefWidget->countrieslist->setCurrentRow (i, QItemSelectionModel::ClearAndSelect);
1002         break;
1003       }
1004     }
1005     QPointF anchorPos;
1006     QPointF centerPos;
1007     switch (type)
1008     {
1009       case Flag:
1010         country->pointFlag(item->scenePos());
1011         m_countryDefWidget->flagx->setValue(item->scenePos().x());
1012         m_countryDefWidget->flagy->setValue(item->scenePos().y());
1013         m_flagButton->setChecked(false);
1014         m_flagButton->setEnabled(false);
1015         m_mapView->unsetCursor();
1016         break;
1017       case Infantry:
1018         country->pointInfantry(item->scenePos());
1019         m_countryDefWidget->infantryx->setValue(item->scenePos().x());
1020         m_countryDefWidget->infantryy->setValue(item->scenePos().y());
1021         m_infantryButton->setChecked(false);
1022         m_infantryButton->setEnabled(false);
1023         m_mapView->unsetCursor();
1024         break;
1025       case Cavalry:
1026         country->pointCavalry(item->scenePos());
1027         m_countryDefWidget->cavalryx->setValue(item->scenePos().x());
1028         m_countryDefWidget->cavalryy->setValue(item->scenePos().y());
1029         m_cavalryButton->setChecked(false);
1030         m_cavalryButton->setEnabled(false);
1031         m_mapView->unsetCursor();
1032         break;
1033       case Cannon:
1034         country->pointCannon(item->scenePos());
1035         m_countryDefWidget->cannonx->setValue(item->scenePos().x());
1036         m_countryDefWidget->cannony->setValue(item->scenePos().y());
1037         m_cannonButton->setChecked(false);
1038         m_cannonButton->setEnabled(false);
1039         m_mapView->unsetCursor();
1040         break;
1041       case Anchor:
1042         anchorPos = QPointF(item->scenePos().x()+(item->boundingRect().width()/2),item->scenePos().y()+(item->boundingRect().height()/2));
1043         country->anchorPoint(anchorPos);
1044         m_countryDefWidget->anchorx->setValue(anchorPos.x());
1045         m_countryDefWidget->anchory->setValue(anchorPos.y());
1046         m_anchorButton->setChecked(false);
1047         m_anchorButton->setEnabled(false);
1048         m_mapView->unsetCursor();
1049         break;
1050       case Center:
1051         centerPos = QPointF(item->scenePos().x()+(item->boundingRect().width()/2),item->scenePos().y()+(item->boundingRect().height()/2));
1052         country->centralPoint(centerPos);
1053         m_countryDefWidget->centerx->setValue(centerPos.x());
1054         m_countryDefWidget->centery->setValue(centerPos.y());
1055         m_centerButton->setChecked(false);
1056         m_centerButton->setEnabled(false);
1057         m_mapView->unsetCursor();
1058         break;
1059       default:;
1060     }
1061   }
1062 }
1063 
slotItemPressed(QGraphicsItem * item,const QPointF & point)1064 void MainWindow::slotItemPressed(QGraphicsItem* item, const QPointF& point)
1065 {
1066   qCDebug(KSIRKSKINEDITOR_LOG);
1067   if (m_onu->itemsMap().contains(item))
1068   {
1069     Country* country = m_onu->itemsMap()[item].first;
1070     m_countryDefWidget->initWith(country);
1071     for (int i = 0; i != m_skinDefWidget->countrieslist->count(); i++)
1072     {
1073       if (m_skinDefWidget->countrieslist->item(i)->text() == country->name())
1074       {
1075         m_skinDefWidget->countrieslist->setCurrentRow (i, QItemSelectionModel::ClearAndSelect);
1076         break;
1077       }
1078     }
1079     switch (m_onu->itemsMap()[item].second)
1080     {
1081       case Flag:
1082         m_selectedSprite = Flag;
1083         country->clearHighlighting();
1084         break;
1085       case Infantry:
1086         m_selectedSprite = Infantry;
1087         country->clearHighlighting();
1088         break;
1089       case Cavalry:
1090         m_selectedSprite = Cavalry;
1091         country->clearHighlighting();
1092         break;
1093       case Cannon:
1094         m_selectedSprite = Cannon;
1095         country->clearHighlighting();
1096         break;
1097       case Anchor:
1098         m_selectedSprite = Anchor;
1099         item = m_onu->itemFor(country, Anchor);
1100         if (item == 0)
1101         {
1102           qCCritical(KSIRKSKINEDITOR_LOG) << "item " << Anchor << "not found for" << country->name();
1103           break;
1104         }
1105         country->anchorPoint(point);
1106         item->setPos( point - QPointF(item->boundingRect().width()/2, item->boundingRect().height()/2) );
1107         country->highlight(m_mapScene, m_onu, Qt::white,128);
1108 //         item->setPos((country->anchorPoint().x()-country->highlighting()->boundingRect().width()/2),
1109 //                      (country->anchorPoint().y()-country->highlighting()->boundingRect().height()/2));
1110         break;
1111       case Center:
1112         m_selectedSprite = Center;
1113         country->clearHighlighting();
1114         break;
1115       default:
1116         m_selectedSprite = None;
1117         country->clearHighlighting();
1118     }
1119   }
1120 }
1121 
createPixmapFor(Country * country,SpriteType type)1122 void MainWindow::createPixmapFor(Country* country, SpriteType type)
1123 {
1124   qCDebug(KSIRKSKINEDITOR_LOG) << country->name() << type;
1125   QPixmap pix;
1126   QPixmap alphacopy;
1127   QPointF point;
1128   QString fileName;
1129   if (country == 0
1130     || m_onu->itemFor(country, type) != 0)
1131   {
1132     qCDebug(KSIRKSKINEDITOR_LOG) << (void*)country << (void*)m_onu->itemFor(country, type);
1133     return;
1134   }
1135   QGraphicsItem* item = 0;
1136 
1137   switch (type)
1138   {
1139     case Flag:
1140       item = new PixmapItem();
1141       item->setZValue(3);
1142       pix = m_onu->flagIcon();
1143       ((PixmapItem*)item)->setPixmap(pix);
1144       //       pix = pix.scaled(20,20);
1145       point = country->pointFlag();
1146       m_countryDefWidget->flagx->setValue(point.x());
1147       m_countryDefWidget->flagy->setValue(point.y());
1148       m_onu->itemsMap().insert(item,qMakePair(country,Flag));
1149       break;
1150     case Infantry:
1151       item = new PixmapItem();
1152       item->setZValue(3);
1153       pix = m_onu->infantryIcon();
1154       ((PixmapItem*)item)->setPixmap(pix);
1155       point = country->pointInfantry();
1156       //       pix = pix.scaled(23,32);
1157       m_countryDefWidget->infantryx->setValue(point.x());
1158       m_countryDefWidget->infantryy->setValue(point.y());
1159       m_onu->itemsMap().insert(item,qMakePair(country,Infantry));
1160       break;
1161     case Cavalry:
1162       item = new PixmapItem();
1163       item->setZValue(3);
1164       pix = m_onu->cavalryIcon();
1165       ((PixmapItem*)item)->setPixmap(pix);
1166       point = country->pointCavalry();
1167       //       pix = pix.scaled(32,32);
1168       m_countryDefWidget->cavalryx->setValue(point.x());
1169       m_countryDefWidget->cavalryy->setValue(point.y());
1170       m_onu->itemsMap().insert(item,qMakePair(country,Cavalry));
1171       break;
1172     case Cannon:
1173       item = new PixmapItem();
1174       item->setZValue(3);
1175       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding cannon";
1176       pix = m_onu->cannonIcon();
1177       ((PixmapItem*)item)->setPixmap(pix);
1178       point = country->pointCannon();
1179       //       pix = pix.scaled(32,32);
1180       m_countryDefWidget->cannonx->setValue(point.x());
1181       m_countryDefWidget->cannony->setValue(point.y());
1182       m_onu->itemsMap().insert(item,qMakePair(country,Cannon));
1183       break;
1184     case Anchor:
1185       item = new PixmapItem();
1186       item->setZValue(3);
1187       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding anchor";
1188       fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("cross.png"));
1189       if (fileName.isNull())
1190       {
1191         KMessageBox::error(0, i18n("Cannot load anchor icon<br>Program cannot continue"), i18n("Error"));
1192         exit(2);
1193       }
1194       pix = QPixmap(fileName);
1195       pix = pix.scaled(16,16);
1196       ((PixmapItem*)item)->setPixmap(pix);
1197       point = country->anchorPoint() - QPointF(item->boundingRect().width()/2, item->boundingRect().height()/2);
1198       m_countryDefWidget->anchorx->setValue(point.x());
1199       m_countryDefWidget->anchory->setValue(point.y());
1200       m_onu->itemsMap().insert(item,qMakePair(country,Anchor));
1201       break;
1202     case Center:
1203       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding center";
1204       item = new TextItem();
1205       item->setZValue(2);
1206       ((TextItem*)item)->setFont(m_onu->foregroundFont());
1207       ((TextItem*)item)->setPlainText(country->name());
1208       point = country->centralPoint() - QPointF(item->boundingRect().width()/2, item->boundingRect().height()/2);
1209       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding center" << country->centralPoint() << point;
1210       m_countryDefWidget->centerx->setValue(point.x());
1211       m_countryDefWidget->centery->setValue(point.y());
1212       m_onu->itemsMap().insert(item,qMakePair(country,Center));
1213       break;
1214     default: ;
1215   }
1216   if (item != 0 && !point.isNull())
1217   {
1218     item->setPos(point);
1219     if (dynamic_cast<PixmapItem*>(item) != 0)
1220     {
1221       connect(dynamic_cast<PixmapItem*>(item),&PixmapItem::pressed,this, &MainWindow::slotItemPressed);
1222       connect(dynamic_cast<PixmapItem*>(item),&PixmapItem::placed,this, &MainWindow::slotItemPlaced);
1223     }
1224     else if (dynamic_cast<TextItem*>(item) != 0)
1225     {
1226       connect(dynamic_cast<TextItem*>(item),&TextItem::pressed,this, &MainWindow::slotItemPressed);
1227       connect(dynamic_cast<TextItem*>(item), &TextItem::placed,this, &MainWindow::slotItemPlaced);
1228     }
1229     m_mapScene->addItem(item);
1230     item->setFlag(QGraphicsItem::ItemIsMovable, true);
1231     item->setFlag(QGraphicsItem::ItemIsSelectable, true);
1232   }
1233 }
1234 
slotURLSelected(const QUrl & url)1235 void MainWindow::slotURLSelected(const QUrl &url)
1236 {
1237   qCDebug(KSIRKSKINEDITOR_LOG);
1238   if ( url.isLocalFile() )
1239   {
1240     QString path = url.path();
1241     slotOpenSkin(path);
1242   }
1243 }
1244 
slotSkinNameEdited()1245 void MainWindow::slotSkinNameEdited()
1246 {
1247   if (m_onu == 0) return;
1248   m_onu->setName(m_skinDefWidget->skinNameLineEdit->text());
1249 }
1250 
slotSkinWidthEdited(int v)1251 void MainWindow::slotSkinWidthEdited(int v)
1252 {
1253   if (m_onu == 0) return;
1254   m_onu->setWidth(v);
1255 
1256   QRectF rect = m_mapScene->sceneRect();
1257   rect.setWidth(v);
1258   m_mapScene->setSceneRect(rect);
1259 
1260   if (m_mapItem != 0)
1261   {
1262     QPixmap mapPixmap(m_onu->pixmapForId(QStringLiteral("map"), m_onu->width(), m_onu->height()));
1263     m_mapItem->setPixmap(mapPixmap);
1264   }
1265 }
1266 
slotSkinHeightEdited(int v)1267 void MainWindow::slotSkinHeightEdited(int v)
1268 {
1269   if (m_onu == 0) return;
1270   m_onu->setHeight(v);
1271 
1272   QRectF rect = m_mapScene->sceneRect();
1273   rect.setHeight(v);
1274   m_mapScene->setSceneRect(rect);
1275 
1276   if (m_mapItem != 0)
1277   {
1278     QPixmap mapPixmap(m_onu->pixmapForId(QStringLiteral("map"), m_onu->width(), m_onu->height()));
1279     m_mapItem->setPixmap(mapPixmap);
1280   }
1281 }
1282 
slotSkinDescriptionEdited()1283 void MainWindow::slotSkinDescriptionEdited()
1284 {
1285   if (m_onu == 0) return;
1286   qCDebug(KSIRKSKINEDITOR_LOG) << m_skinDefWidget->descriptionTextEdit->toPlainText();
1287   m_onu->setDescription(m_skinDefWidget->descriptionTextEdit->toPlainText());
1288 }
1289 
slotSkinWidthDiffEdited()1290 void MainWindow::slotSkinWidthDiffEdited()
1291 {
1292   if (m_onu == 0) return;
1293   qCDebug(KSIRKSKINEDITOR_LOG);
1294   bool ok = false;
1295   int wd = m_spritesDefWidget->widthDiffLineEdit->text().toInt(&ok);
1296   SkinSpritesData::changeable().intData(QStringLiteral("width-between-flag-and-fighter"), wd);
1297 }
1298 
slotNewCountry()1299 void MainWindow::slotNewCountry()
1300 {
1301   if (m_onu == 0) return;
1302   qCDebug(KSIRKSKINEDITOR_LOG);
1303   QString newCountryName = QInputDialog::getText(this, i18n("New country name"), i18n("Enter the name of the new country"));
1304   m_onu->createCountry(newCountryName);
1305   m_skinDefWidget->countrieslist->addItem(newCountryName);
1306 }
1307 
slotDeleteCountry()1308 void MainWindow::slotDeleteCountry()
1309 {
1310   if (m_onu == 0) return;
1311   if (!m_skinDefWidget->countrieslist->currentItem()) return;
1312   qCDebug(KSIRKSKINEDITOR_LOG);
1313   int answer = KMessageBox::warningContinueCancel(this, i18n("Do you really want to delete country '%1'?", m_skinDefWidget->countrieslist->currentItem()->text()), i18n("Really delete country?"));
1314   if (answer == KMessageBox::Cancel)
1315   {
1316     return;
1317   }
1318 
1319   int row = m_skinDefWidget->countrieslist->row(m_skinDefWidget->countrieslist->currentItem());
1320   QListWidgetItem* item = m_skinDefWidget->countrieslist->takeItem(row);
1321 
1322   Country* country = m_onu->countryNamed(item->text());
1323   m_onu->deleteCountry(country);
1324 
1325   delete item;
1326 }
1327 
slotNewContinent()1328 void MainWindow::slotNewContinent()
1329 {
1330   if (m_onu == 0) return;
1331   qCDebug(KSIRKSKINEDITOR_LOG);
1332   QString newContinentName = QInputDialog::getText(this, i18n("New continent name"), i18n("Enter the name of the new continent"));
1333   m_onu->createContinent(newContinentName);
1334   m_skinDefWidget->continentslist->addItem(newContinentName);
1335 }
1336 
slotDeleteContinent()1337 void MainWindow::slotDeleteContinent()
1338 {
1339   if (m_onu == 0) return;
1340   if (!m_skinDefWidget->continentslist->currentItem()) return;
1341   qCDebug(KSIRKSKINEDITOR_LOG);
1342   int answer = KMessageBox::warningContinueCancel(this, i18n("Do you really want to delete continent '%1'?", m_skinDefWidget->continentslist->currentItem()->text()), i18n("Really delete continent?"));
1343   if (answer == KMessageBox::Cancel)
1344   {
1345     return;
1346   }
1347 
1348   int row = m_skinDefWidget->continentslist->row(m_skinDefWidget->continentslist->currentItem());
1349   QListWidgetItem* item = m_skinDefWidget->continentslist->takeItem(row);
1350 
1351   Continent* continent = m_onu->continentNamed(item->text());
1352   m_onu->deleteContinent(continent);
1353 
1354   delete item;
1355 }
1356 
slotNeighbours()1357 void MainWindow::slotNeighbours()
1358 {
1359   if (m_onu == 0) return;
1360   qCDebug(KSIRKSKINEDITOR_LOG);
1361   if (m_skinDefWidget->countrieslist->currentItem() == 0)
1362   {
1363     return;
1364   }
1365 
1366   KsirkSkinEditorCountriesSelectionDialog* dialog = new KsirkSkinEditorCountriesSelectionDialog(this);
1367   dialog->countriesList->setSortingEnabled(true);
1368   dialog->countriesList->setSelectionMode(QAbstractItemView::ExtendedSelection);
1369   foreach (Country* country, m_onu->countries())
1370   {
1371     if (country->name() != m_skinDefWidget->countrieslist->currentItem()->text())
1372     {
1373       dialog->countriesList->addItem(country->name());
1374     }
1375   }
1376   foreach (Country* country, m_onu->countryNamed(m_skinDefWidget->countrieslist->currentItem()->text())->neighbours())
1377   {
1378     QList<QListWidgetItem *> list = dialog->countriesList->findItems(country->name(),Qt::MatchExactly);
1379     foreach (QListWidgetItem* item, list)
1380     {
1381       dialog->countriesList->setCurrentItem(item,QItemSelectionModel::Select);
1382     }
1383   }
1384   if (dialog->exec())
1385   {
1386     QList<QListWidgetItem *> list = dialog->countriesList->selectedItems();
1387     Country* country =  m_onu->countryNamed(m_skinDefWidget->countrieslist->currentItem()->text());
1388     QList<Country*> newNeighbours;
1389     m_countryDefWidget->neighbourslist->clear();
1390     foreach (QListWidgetItem* item, list)
1391     {
1392       Country* neighbour = m_onu->countryNamed(item->text());
1393       newNeighbours.push_back(neighbour);
1394       m_countryDefWidget->neighbourslist->addItem(neighbour->name());
1395     }
1396     country->neighbours() = newNeighbours;
1397   }
1398   delete dialog;
1399 }
1400 
slotSkinPartTabChanged(int index)1401 void MainWindow::slotSkinPartTabChanged(int index)
1402 {
1403   qCDebug(KSIRKSKINEDITOR_LOG);
1404 
1405   switch (index)
1406   {
1407     case 0:
1408       m_spritesDefWidget->show();
1409       m_nationalityDefWidget->hide();
1410       m_countryDefWidget->hide();
1411       m_continentDefWidget->hide();
1412       m_goalDefWidget->hide();
1413       break;
1414     case 1:
1415       m_spritesDefWidget->hide();
1416       m_nationalityDefWidget->show();
1417       m_countryDefWidget->hide();
1418       m_continentDefWidget->hide();
1419       m_goalDefWidget->hide();
1420       break;
1421     case 2:
1422       m_spritesDefWidget->hide();
1423       m_nationalityDefWidget->hide();
1424       m_countryDefWidget->show();
1425       m_continentDefWidget->hide();
1426       m_goalDefWidget->hide();
1427       break;
1428     case 3:
1429       m_spritesDefWidget->hide();
1430       m_nationalityDefWidget->hide();
1431       m_countryDefWidget->hide();
1432       m_continentDefWidget->show();
1433       m_goalDefWidget->hide();
1434       break;
1435     case 4:
1436       m_spritesDefWidget->hide();
1437       m_nationalityDefWidget->hide();
1438       m_countryDefWidget->hide();
1439       m_continentDefWidget->hide();
1440       m_goalDefWidget->show();
1441       break;
1442     default:
1443       m_countryDefWidget->hide();
1444       m_nationalityDefWidget->hide();
1445       m_continentDefWidget->hide();
1446       m_goalDefWidget->hide();
1447       m_spritesDefWidget->hide();
1448   }
1449 }
1450 
slotContinentCountries()1451 void MainWindow::slotContinentCountries()
1452 {
1453   if (m_onu == 0) return;
1454   qCDebug(KSIRKSKINEDITOR_LOG);
1455   if (m_skinDefWidget->continentslist->currentItem() == 0)
1456   {
1457     return;
1458   }
1459 
1460   KsirkSkinEditorCountriesSelectionDialog* dialog = new KsirkSkinEditorCountriesSelectionDialog(this);
1461   dialog->countriesList->setSortingEnabled(true);
1462   dialog->countriesList->setSelectionMode(QAbstractItemView::ExtendedSelection);
1463   foreach (Country* country, m_onu->countries())
1464   {
1465     dialog->countriesList->addItem(country->name());
1466   }
1467   foreach (Country* country, m_onu->continentNamed(m_skinDefWidget->continentslist->currentItem()->text())->members())
1468   {
1469     QList<QListWidgetItem*> list = dialog->countriesList->findItems(country->name(),Qt::MatchExactly);
1470     foreach (QListWidgetItem* item, list)
1471     {
1472       dialog->countriesList->setCurrentItem(item,QItemSelectionModel::Select);
1473     }
1474   }
1475   if (dialog->exec())
1476   {
1477     QList<QListWidgetItem *> list = dialog->countriesList->selectedItems();
1478     qCDebug(KSIRKSKINEDITOR_LOG) << list.size();
1479     Continent* continent =  m_onu->continentNamed(m_skinDefWidget->continentslist->currentItem()->text());
1480     qCDebug(KSIRKSKINEDITOR_LOG) << (void*)continent;
1481     qCDebug(KSIRKSKINEDITOR_LOG) << continent->name();
1482     QList<Country*> newCountries;
1483     m_continentDefWidget->countrieslist->clear();
1484     foreach (QListWidgetItem* item, list)
1485     {
1486       Country* country = m_onu->countryNamed(item->text());
1487       qCDebug(KSIRKSKINEDITOR_LOG) << (void*)country;
1488       qCDebug(KSIRKSKINEDITOR_LOG) << country->name();
1489       newCountries.push_back(country);
1490       m_continentDefWidget->countrieslist->addItem(country->name());
1491     }
1492     qCDebug(KSIRKSKINEDITOR_LOG) << "set members";
1493     continent->members() = newCountries;
1494   }
1495   delete dialog;
1496 }
1497 
slotContinentBonusEdited(int v)1498 void MainWindow::slotContinentBonusEdited(int v)
1499 {
1500   qCDebug(KSIRKSKINEDITOR_LOG);
1501   if (m_onu == 0 || m_skinDefWidget->continentslist->currentItem() == 0) return;
1502   Continent* continent =  m_onu->continentNamed(m_skinDefWidget->continentslist->currentItem()->text());
1503   continent->setBonus(v);
1504   m_onu->setDirty();
1505 }
1506 
slotFlagWidthChanged(int v)1507 void MainWindow::slotFlagWidthChanged(int v)
1508 {
1509   qCDebug(KSIRKSKINEDITOR_LOG);
1510   SkinSpritesData::changeable().intData(QStringLiteral("flag-width"), v);
1511   updateSprites(Flag);
1512 }
1513 
slotFlagHeightChanged(int v)1514 void MainWindow::slotFlagHeightChanged(int v)
1515 {
1516   qCDebug(KSIRKSKINEDITOR_LOG);
1517   SkinSpritesData::changeable().intData(QStringLiteral("flag-height"), v);
1518   updateSprites(Flag);
1519 }
1520 
slotFlagFramesChanged(int v)1521 void MainWindow::slotFlagFramesChanged(int v)
1522 {
1523   qCDebug(KSIRKSKINEDITOR_LOG);
1524   SkinSpritesData::changeable().intData(QStringLiteral("flag-frames"), v);
1525   updateSprites(Flag);
1526 }
1527 
slotFlagVersionsChanged(int v)1528 void MainWindow::slotFlagVersionsChanged(int v)
1529 {
1530   qCDebug(KSIRKSKINEDITOR_LOG);
1531   SkinSpritesData::changeable().intData(QStringLiteral("flag-versions"), v);
1532   updateSprites(Flag);
1533 }
1534 
1535 
slotInfantryWidthChanged(int v)1536 void MainWindow::slotInfantryWidthChanged(int v)
1537 {
1538   qCDebug(KSIRKSKINEDITOR_LOG);
1539   SkinSpritesData::changeable().intData(QStringLiteral("infantry-width"), v);
1540   updateSprites(Infantry);
1541 }
1542 
slotInfantryHeightChanged(int v)1543 void MainWindow::slotInfantryHeightChanged(int v)
1544 {
1545   qCDebug(KSIRKSKINEDITOR_LOG);
1546   SkinSpritesData::changeable().intData(QStringLiteral("infantry-height"), v);
1547   updateSprites(Infantry);
1548 }
1549 
slotInfantryFramesChanged(int v)1550 void MainWindow::slotInfantryFramesChanged(int v)
1551 {
1552   qCDebug(KSIRKSKINEDITOR_LOG);
1553   SkinSpritesData::changeable().intData(QStringLiteral("infantry-frames"), v);
1554   updateSprites(Infantry);
1555 }
1556 
slotInfantryVersionsChanged(int v)1557 void MainWindow::slotInfantryVersionsChanged(int v)
1558 {
1559   qCDebug(KSIRKSKINEDITOR_LOG);
1560   SkinSpritesData::changeable().intData(QStringLiteral("infantry-versions"), v);
1561   updateSprites(Infantry);
1562 }
1563 
1564 
slotCavalryWidthChanged(int v)1565 void MainWindow::slotCavalryWidthChanged(int v)
1566 {
1567   qCDebug(KSIRKSKINEDITOR_LOG);
1568   SkinSpritesData::changeable().intData(QStringLiteral("cavalry-width"), v);
1569   updateSprites(Cavalry);
1570 }
1571 
slotCavalryHeightChanged(int v)1572 void MainWindow::slotCavalryHeightChanged(int v)
1573 {
1574   qCDebug(KSIRKSKINEDITOR_LOG);
1575   SkinSpritesData::changeable().intData(QStringLiteral("cavalry-height"), v);
1576   updateSprites(Cavalry);
1577 }
1578 
slotCavalryFramesChanged(int v)1579 void MainWindow::slotCavalryFramesChanged(int v)
1580 {
1581   qCDebug(KSIRKSKINEDITOR_LOG);
1582   SkinSpritesData::changeable().intData(QStringLiteral("cavalry-frames"), v);
1583   updateSprites(Cavalry);
1584 }
1585 
slotCavalryVersionsChanged(int v)1586 void MainWindow::slotCavalryVersionsChanged(int v)
1587 {
1588   qCDebug(KSIRKSKINEDITOR_LOG);
1589   SkinSpritesData::changeable().intData(QStringLiteral("cavalry-versions"), v);
1590   updateSprites(Cavalry);
1591 }
1592 
1593 
slotCannonWidthChanged(int v)1594 void MainWindow::slotCannonWidthChanged(int v)
1595 {
1596   qCDebug(KSIRKSKINEDITOR_LOG);
1597   SkinSpritesData::changeable().intData(QStringLiteral("cannon-width"), v);
1598   updateSprites(Cannon);
1599 }
1600 
slotCannonHeightChanged(int v)1601 void MainWindow::slotCannonHeightChanged(int v)
1602 {
1603   qCDebug(KSIRKSKINEDITOR_LOG);
1604   SkinSpritesData::changeable().intData(QStringLiteral("cannon-height"), v);
1605   updateSprites(Cannon);
1606 }
1607 
slotCannonFramesChanged(int v)1608 void MainWindow::slotCannonFramesChanged(int v)
1609 {
1610   qCDebug(KSIRKSKINEDITOR_LOG);
1611   SkinSpritesData::changeable().intData(QStringLiteral("cannon-frames"), v);
1612   updateSprites(Cannon);
1613 }
1614 
slotCannonVersionsChanged(int v)1615 void MainWindow::slotCannonVersionsChanged(int v)
1616 {
1617   qCDebug(KSIRKSKINEDITOR_LOG);
1618   SkinSpritesData::changeable().intData(QStringLiteral("cannon-versions"), v);
1619   updateSprites(Cannon);
1620 }
1621 
slotFiringWidthChanged(int v)1622 void MainWindow::slotFiringWidthChanged(int v)
1623 {
1624   qCDebug(KSIRKSKINEDITOR_LOG);
1625   SkinSpritesData::changeable().intData(QStringLiteral("firing-width"), v);
1626 }
1627 
slotFiringHeightChanged(int v)1628 void MainWindow::slotFiringHeightChanged(int v)
1629 {
1630   qCDebug(KSIRKSKINEDITOR_LOG);
1631   SkinSpritesData::changeable().intData(QStringLiteral("firing-height"), v);
1632 }
1633 
slotFiringFramesChanged(int v)1634 void MainWindow::slotFiringFramesChanged(int v)
1635 {
1636   qCDebug(KSIRKSKINEDITOR_LOG);
1637   SkinSpritesData::changeable().intData(QStringLiteral("firing-frames"), v);
1638 }
1639 
slotFiringVersionsChanged(int v)1640 void MainWindow::slotFiringVersionsChanged(int v)
1641 {
1642   qCDebug(KSIRKSKINEDITOR_LOG);
1643   SkinSpritesData::changeable().intData(QStringLiteral("firing-versions"), v);
1644 }
1645 
slotExplodingWidthChanged(int v)1646 void MainWindow::slotExplodingWidthChanged(int v)
1647 {
1648   qCDebug(KSIRKSKINEDITOR_LOG);
1649   SkinSpritesData::changeable().intData(QStringLiteral("exploding-width"), v);
1650 }
1651 
slotExplodingHeightChanged(int v)1652 void MainWindow::slotExplodingHeightChanged(int v)
1653 {
1654   qCDebug(KSIRKSKINEDITOR_LOG);
1655   SkinSpritesData::changeable().intData(QStringLiteral("exploding-height"), v);
1656 }
1657 
slotExplodingFramesChanged(int v)1658 void MainWindow::slotExplodingFramesChanged(int v)
1659 {
1660   qCDebug(KSIRKSKINEDITOR_LOG);
1661   SkinSpritesData::changeable().intData(QStringLiteral("exploding-frames"), v);
1662 }
1663 
slotExplodingVersionsChanged(int v)1664 void MainWindow::slotExplodingVersionsChanged(int v)
1665 {
1666   qCDebug(KSIRKSKINEDITOR_LOG);
1667   SkinSpritesData::changeable().intData(QStringLiteral("exploding-versions"), v);
1668 }
1669 
updateSprites(SpriteType type)1670 void MainWindow::updateSprites(SpriteType type)
1671 {
1672   qCDebug(KSIRKSKINEDITOR_LOG) << type;
1673   QPixmap pix;
1674   QPixmap alphacopy;
1675   QPointF point;
1676   QString fileName;
1677 
1678   m_onu->updateIcon(type);
1679   switch (type)
1680   {
1681     case Flag:
1682       m_flagButton->setIcon(m_onu->flagIcon());
1683       break;
1684     case Infantry:
1685       m_infantryButton->setIcon(m_onu->infantryIcon());
1686       break;
1687     case Cavalry:
1688       m_cavalryButton->setIcon(m_onu->cavalryIcon());
1689       break;
1690     case Cannon:
1691       m_cannonButton->setIcon(m_onu->cannonIcon());
1692       break;
1693     default: ;
1694   }
1695   foreach (Country* country, m_onu->countries())
1696   {
1697     QGraphicsItem* item = m_onu->itemFor(country, type);
1698     if (item == 0)
1699     {
1700       qCCritical(KSIRKSKINEDITOR_LOG) << "item " << type << "not found for" << country->name();
1701       continue;
1702     }
1703     switch (type)
1704     {
1705       case Flag:
1706         pix = m_onu->flagIcon();
1707         ((PixmapItem*)item)->setPixmap(pix);
1708         break;
1709       case Infantry:
1710         pix = m_onu->infantryIcon();
1711         ((PixmapItem*)item)->setPixmap(pix);
1712         break;
1713       case Cavalry:
1714         pix = m_onu->cavalryIcon();
1715         ((PixmapItem*)item)->setPixmap(pix);
1716         break;
1717       case Cannon:
1718         pix = m_onu->cannonIcon();
1719         ((PixmapItem*)item)->setPixmap(pix);
1720         break;
1721       case Anchor:
1722         ((TextItem*)item)->setFont(m_onu->foregroundFont());
1723         break;
1724       default: ;
1725     }
1726   }
1727 }
1728 
slotGoalTypeWorldClicked()1729 void MainWindow::slotGoalTypeWorldClicked()
1730 {
1731   if (m_onu == 0) return;
1732   qCDebug(KSIRKSKINEDITOR_LOG);
1733   if (m_skinDefWidget->goalslist->currentItem() == 0)
1734   {
1735     return;
1736   }
1737   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1738   Goal* goal = m_onu->goals()[row];
1739   goal->setType(Goal::NoGoal);
1740 }
1741 
slotGoalTypePlayerClicked()1742 void MainWindow::slotGoalTypePlayerClicked()
1743 {
1744   if (m_onu == 0) return;
1745   qCDebug(KSIRKSKINEDITOR_LOG);
1746   if (m_skinDefWidget->goalslist->currentItem() == 0)
1747   {
1748     return;
1749   }
1750   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1751   Goal* goal = m_onu->goals()[row];
1752   goal->setType(Goal::GoalPlayer);
1753 }
1754 
slotGoalTypeCountriesClicked()1755 void MainWindow::slotGoalTypeCountriesClicked()
1756 {
1757   if (m_onu == 0) return;
1758   qCDebug(KSIRKSKINEDITOR_LOG);
1759   if (m_skinDefWidget->goalslist->currentItem() == 0)
1760   {
1761     return;
1762   }
1763   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1764   Goal* goal = m_onu->goals()[row];
1765   goal->setType(Goal::Countries);
1766 }
1767 
slotGoalTypeContinentsClicked()1768 void MainWindow::slotGoalTypeContinentsClicked()
1769 {
1770   if (m_onu == 0) return;
1771   qCDebug(KSIRKSKINEDITOR_LOG);
1772   if (m_skinDefWidget->goalslist->currentItem() == 0)
1773   {
1774     return;
1775   }
1776   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1777   Goal* goal = m_onu->goals()[row];
1778   goal->setType(Goal::Continents);
1779 }
1780 
slotGoalDescriptionEdited()1781 void MainWindow::slotGoalDescriptionEdited()
1782 {
1783   if (m_onu == 0 || m_skinDefWidget->goalslist->currentItem() == 0) return;
1784   qCDebug(KSIRKSKINEDITOR_LOG);
1785   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1786   Goal* goal = m_onu->goals()[row];
1787   goal->setDescription(m_goalDefWidget->description->toPlainText());
1788 }
1789 
slotGoalNbCountriesChanged(int)1790 void MainWindow::slotGoalNbCountriesChanged(int)
1791 {
1792   if (m_onu == 0 || m_skinDefWidget->goalslist->currentItem() == 0) return;
1793   qCDebug(KSIRKSKINEDITOR_LOG);
1794   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1795   Goal* goal = m_onu->goals()[row];
1796   goal->setNbCountries(m_goalDefWidget->nbcountries->value());
1797 }
1798 
slotGoalNbArmiesByCountryChanged(int)1799 void MainWindow::slotGoalNbArmiesByCountryChanged(int)
1800 {
1801   if (m_onu == 0 || m_skinDefWidget->goalslist->currentItem() == 0) return;
1802   qCDebug(KSIRKSKINEDITOR_LOG);
1803   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1804   Goal* goal = m_onu->goals()[row];
1805   goal->setNbArmiesByCountry(m_goalDefWidget->armiesbycountry->value());
1806 }
1807 
slotGoalAnyContinentChanged(int state)1808 void MainWindow::slotGoalAnyContinentChanged(int state)
1809 {
1810   if (m_onu == 0 || m_skinDefWidget->goalslist->currentItem() == 0) return;
1811   qCDebug(KSIRKSKINEDITOR_LOG);
1812   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1813   Goal* goal = m_onu->goals()[row];
1814   switch (state)
1815   {
1816     case Qt::Unchecked:
1817       goal->continents().removeAll(QString());
1818       break;
1819     case Qt::Checked:
1820       if (!goal->continents().contains(QString()))
1821       {
1822         goal->continents().push_back(QString());
1823       }
1824       break;
1825     default:;
1826   }
1827   goal->setNbArmiesByCountry(m_goalDefWidget->armiesbycountry->value());
1828 }
1829 
slotGoalContinents()1830 void MainWindow::slotGoalContinents()
1831 {
1832   if (m_onu == 0) return;
1833   qCDebug(KSIRKSKINEDITOR_LOG);
1834   if (m_skinDefWidget->goalslist->currentItem() == 0)
1835   {
1836     return;
1837   }
1838 
1839   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1840   Goal* goal = m_onu->goals()[row];
1841 
1842   KsirkSkinEditorCountriesSelectionDialog* dialog = new KsirkSkinEditorCountriesSelectionDialog(this);
1843   dialog->countriesList->setSortingEnabled(true);
1844   dialog->countriesList->setSelectionMode(QAbstractItemView::ExtendedSelection);
1845   foreach (Continent* continent, m_onu->continents())
1846   {
1847     dialog->countriesList->addItem(continent->name());
1848   }
1849   foreach (const QString& continentName, goal->continents())
1850   {
1851     QList<QListWidgetItem*> list = dialog->countriesList->findItems(continentName,Qt::MatchExactly);
1852     foreach (QListWidgetItem* item, list)
1853     {
1854       dialog->countriesList->setCurrentItem(item,QItemSelectionModel::Select);
1855     }
1856   }
1857   if (dialog->exec())
1858   {
1859     QList<QListWidgetItem *> list = dialog->countriesList->selectedItems();
1860     qCDebug(KSIRKSKINEDITOR_LOG) << list.size();
1861     QList<QString> newContinents;
1862     m_goalDefWidget->continentslist->clear();
1863     foreach (QListWidgetItem* item, list)
1864     {
1865       Continent* continent = m_onu->continentNamed(item->text());
1866       qCDebug(KSIRKSKINEDITOR_LOG) << (void*)continent;
1867       qCDebug(KSIRKSKINEDITOR_LOG) << continent->name();
1868       newContinents.push_back(continent->name());
1869       m_goalDefWidget->continentslist->addItem(continent->name());
1870     }
1871     qCDebug(KSIRKSKINEDITOR_LOG) << "set members";
1872     goal->continents() = newContinents;
1873   }
1874   delete dialog;
1875 }
1876 
slotNewGoal()1877 void MainWindow::slotNewGoal()
1878 {
1879   if (m_onu == 0) return;
1880   qCDebug(KSIRKSKINEDITOR_LOG);
1881   QString newGoalName = QStringLiteral("goal") + QString::number(m_skinDefWidget->goalslist->count()+1);
1882   m_onu->createGoal();
1883   m_skinDefWidget->goalslist->addItem(newGoalName);
1884 }
1885 
slotDeleteGoal()1886 void MainWindow::slotDeleteGoal()
1887 {
1888   if (m_onu == 0) return;
1889   if (!m_skinDefWidget->goalslist->currentItem()) return;
1890   qCDebug(KSIRKSKINEDITOR_LOG);
1891   int answer = KMessageBox::warningContinueCancel(this, i18n("Do you really want to delete goal '%1'?", m_skinDefWidget->goalslist->currentItem()->text()), i18n("Really delete goal?"));
1892   if (answer == KMessageBox::Cancel)
1893   {
1894     return;
1895   }
1896 
1897   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1898   qCDebug(KSIRKSKINEDITOR_LOG) << "row=" << row;
1899   QListWidgetItem* item = m_skinDefWidget->goalslist->takeItem(m_skinDefWidget->goalslist->count()-1);
1900   qCDebug(KSIRKSKINEDITOR_LOG) << "item=" << item;
1901 
1902   m_onu->deleteGoal(row);
1903   qCDebug(KSIRKSKINEDITOR_LOG) << "goal deleted";
1904 
1905   delete item;
1906 }
1907 
slotNationalityNameEdited()1908 void MainWindow::slotNationalityNameEdited()
1909 {
1910   if (m_onu == 0 || m_skinDefWidget->nationalitieslist->currentItem() ==0) return;
1911   qCDebug(KSIRKSKINEDITOR_LOG) << m_skinDefWidget->nationalitieslist->currentItem()->text();
1912   Nationality* nationality =  m_onu->nationalityNamed(m_skinDefWidget->nationalitieslist->currentItem()->text());
1913   nationality->setName(m_nationalityDefWidget->name->text());
1914   m_skinDefWidget->nationalitieslist->currentItem()->setText(m_nationalityDefWidget->name->text());
1915 }
1916 
slotNationalityLeaderNameEdited()1917 void MainWindow::slotNationalityLeaderNameEdited()
1918 {
1919   if (m_onu == 0 || m_skinDefWidget->nationalitieslist->currentItem() ==0) return;
1920   qCDebug(KSIRKSKINEDITOR_LOG) << m_skinDefWidget->nationalitieslist->currentItem()->text();
1921   qCDebug(KSIRKSKINEDITOR_LOG) << m_nationalityDefWidget->leader->text();
1922   Nationality* nationality =  m_onu->nationalityNamed(m_skinDefWidget->nationalitieslist->currentItem()->text());
1923   qCDebug(KSIRKSKINEDITOR_LOG) << nationality;
1924   nationality->setLeaderName(m_nationalityDefWidget->leader->text());
1925 }
1926 
slotNationalityFlagEdited(int)1927 void MainWindow::slotNationalityFlagEdited(int)
1928 {
1929   if (m_onu == 0 || m_skinDefWidget->nationalitieslist->currentItem() ==0) return;
1930   qCDebug(KSIRKSKINEDITOR_LOG) << m_skinDefWidget->nationalitieslist->currentItem()->text();
1931   Nationality* nationality =  m_onu->nationalityNamed(m_skinDefWidget->nationalitieslist->currentItem()->text());
1932   QString previousFlagFileName = nationality->flagFileName();
1933   if (previousFlagFileName == m_nationalityDefWidget->flag->currentText())
1934   {
1935     return;
1936   }
1937   nationality->setFlagFileName(m_nationalityDefWidget->flag->currentText());
1938   m_onu->setDirty();
1939 
1940   if (previousFlagFileName.isEmpty() && !nationality->flagFileName().isEmpty())
1941   {
1942     updateSprites(Flag);
1943   }
1944 }
1945 
slotNewNationality()1946 void MainWindow::slotNewNationality()
1947 {
1948   if (m_onu == 0) return;
1949   qCDebug(KSIRKSKINEDITOR_LOG);
1950   QString newNationalityName = QInputDialog::getText(this, i18n("New nationality name"), i18n("Enter the name of the new nationality"));
1951   m_onu->createNationality(newNationalityName);
1952   m_skinDefWidget->nationalitieslist->addItem(newNationalityName);
1953 }
1954 
slotDeleteNationality()1955 void MainWindow::slotDeleteNationality()
1956 {
1957   if (m_onu == 0) return;
1958   if (!m_skinDefWidget->nationalitieslist->currentItem()) return;
1959   qCDebug(KSIRKSKINEDITOR_LOG);
1960   int answer = KMessageBox::warningContinueCancel(this, i18n("Do you really want to delete nationality '%1'?", m_skinDefWidget->nationalitieslist->currentItem()->text()), i18n("Really delete nationality?"));
1961   if (answer == KMessageBox::Cancel)
1962   {
1963     return;
1964   }
1965 
1966   int row = m_skinDefWidget->nationalitieslist->row(m_skinDefWidget->nationalitieslist->currentItem());
1967   QListWidgetItem* item = m_skinDefWidget->nationalitieslist->takeItem(row);
1968 
1969   Nationality* nationality = m_onu->nationalityNamed(item->text());
1970   m_onu->deleteNationality(nationality);
1971 
1972   delete item;
1973 }
1974 
slotFontSelected(const QFont & font)1975 void MainWindow::slotFontSelected(const QFont &font)
1976 {
1977   if (m_onu == 0) return;
1978   qCDebug(KSIRKSKINEDITOR_LOG);
1979   m_onu->setFont(font);
1980   updateSprites(Anchor);
1981 }
1982 
slotFgSelected(const QColor & color)1983 void MainWindow::slotFgSelected(const QColor& color)
1984 {
1985   if (m_onu == 0) return;
1986   qCDebug(KSIRKSKINEDITOR_LOG);
1987   m_onu->setFontFgColor(color);
1988   updateSprites(Anchor);
1989 }
1990 
slotBgColorSelected(const QColor & color)1991 void MainWindow::slotBgColorSelected(const QColor& color)
1992 {
1993   if (m_onu == 0) return;
1994   qCDebug(KSIRKSKINEDITOR_LOG);
1995   m_onu->setFontBgColor(color);
1996   updateSprites(Anchor);
1997 }
1998 
initSpritesButtonsWith(const Country * country)1999 void MainWindow::initSpritesButtonsWith(const Country* country)
2000 {
2001   m_flagButton->setEnabled(m_onu->itemFor(country, Flag) == 0);
2002   m_infantryButton->setEnabled(m_onu->itemFor(country, Infantry) == 0);
2003   m_cavalryButton->setEnabled(m_onu->itemFor(country, Cavalry) == 0);
2004   m_cannonButton->setEnabled(m_onu->itemFor(country, Cannon) == 0);
2005   m_anchorButton->setEnabled(m_onu->itemFor(country, Anchor) == 0);
2006   m_centerButton->setEnabled(m_onu->itemFor(country, Center) == 0);
2007 }
2008 
slotFLagxValueChanged(int v)2009 void MainWindow::slotFLagxValueChanged(int v)
2010 {
2011   qCDebug(KSIRKSKINEDITOR_LOG);
2012   if (currentCountry() != 0)
2013   {
2014     currentCountry()->pointFlag(QPointF(v,currentCountry()->pointFlag().y()));
2015     if (m_onu->itemFor(currentCountry(), Flag) != 0)
2016       m_onu->itemFor(currentCountry(), Flag)->setPos(currentCountry()->pointFlag());
2017     m_onu->setDirty();
2018   }
2019 }
2020 
slotFLagyValueChanged(int v)2021 void MainWindow::slotFLagyValueChanged(int v)
2022 {
2023   qCDebug(KSIRKSKINEDITOR_LOG);
2024   if (currentCountry() != 0)
2025   {
2026     currentCountry()->pointFlag(QPointF(currentCountry()->pointFlag().x(),v));
2027     if (m_onu->itemFor(currentCountry(), Flag) != 0)
2028       m_onu->itemFor(currentCountry(), Flag)->setPos(currentCountry()->pointFlag());
2029     m_onu->setDirty();
2030   }
2031 }
2032 
slotCenterxValueChanged(int v)2033 void MainWindow::slotCenterxValueChanged(int v)
2034 {
2035   qCDebug(KSIRKSKINEDITOR_LOG);
2036   if (currentCountry() != 0)
2037   {
2038     currentCountry()->centralPoint(QPointF(v,currentCountry()->centralPoint().y()));
2039     if (m_onu->itemFor(currentCountry(), Center) != 0)
2040       m_onu->itemFor(currentCountry(), Center)->setPos(currentCountry()->centralPoint());
2041     m_onu->setDirty();
2042   }
2043 }
2044 
slotCenteryValueChanged(int v)2045 void MainWindow::slotCenteryValueChanged(int v)
2046 {
2047   qCDebug(KSIRKSKINEDITOR_LOG);
2048   if (currentCountry() != 0)
2049   {
2050     currentCountry()->centralPoint(QPointF(currentCountry()->centralPoint().x(),v));
2051     if (m_onu->itemFor(currentCountry(), Center) != 0)
2052       m_onu->itemFor(currentCountry(), Center)->setPos(currentCountry()->centralPoint());
2053     m_onu->setDirty();
2054   }
2055 }
2056 
slotAnchorxValueChanged(int v)2057 void MainWindow::slotAnchorxValueChanged(int v)
2058 {
2059   qCDebug(KSIRKSKINEDITOR_LOG);
2060   if (currentCountry() != 0)
2061   {
2062     currentCountry()->anchorPoint(QPointF(v,currentCountry()->anchorPoint().y()));
2063     if (m_onu->itemFor(currentCountry(), Anchor) != 0)
2064       m_onu->itemFor(currentCountry(), Anchor)->setPos(currentCountry()->anchorPoint());
2065     m_onu->setDirty();
2066   }
2067 }
2068 
slotAnchoryValueChanged(int v)2069 void MainWindow::slotAnchoryValueChanged(int v)
2070 {
2071   qCDebug(KSIRKSKINEDITOR_LOG);
2072   if (currentCountry() != 0)
2073   {
2074     currentCountry()->anchorPoint(QPointF(currentCountry()->anchorPoint().x(),v));
2075     if (m_onu->itemFor(currentCountry(), Anchor) != 0)
2076       m_onu->itemFor(currentCountry(), Anchor)->setPos(currentCountry()->anchorPoint());
2077     m_onu->setDirty();
2078   }
2079 }
2080 
slotInfantryxValueChanged(int v)2081 void MainWindow::slotInfantryxValueChanged(int v)
2082 {
2083   qCDebug(KSIRKSKINEDITOR_LOG);
2084   if (currentCountry() != 0)
2085   {
2086     currentCountry()->pointInfantry(QPointF(v,currentCountry()->pointInfantry().y()));
2087     if (m_onu->itemFor(currentCountry(), Infantry) != 0)
2088       m_onu->itemFor(currentCountry(), Infantry)->setPos(currentCountry()->pointInfantry());
2089     m_onu->setDirty();
2090   }
2091 }
2092 
slotInfantryyValueChanged(int v)2093 void MainWindow::slotInfantryyValueChanged(int v)
2094 {
2095   qCDebug(KSIRKSKINEDITOR_LOG);
2096   if (currentCountry() != 0)
2097   {
2098     currentCountry()->pointInfantry(QPointF(currentCountry()->pointInfantry().x(),v));
2099     if (m_onu->itemFor(currentCountry(), Infantry) != 0)
2100       m_onu->itemFor(currentCountry(), Infantry)->setPos(currentCountry()->pointInfantry());
2101     m_onu->setDirty();
2102   }
2103 }
2104 
slotCavalryxValueChanged(int v)2105 void MainWindow::slotCavalryxValueChanged(int v)
2106 {
2107   qCDebug(KSIRKSKINEDITOR_LOG);
2108   if (currentCountry() != 0)
2109   {
2110     currentCountry()->pointCavalry(QPointF(v,currentCountry()->pointCavalry().y()));
2111     if (m_onu->itemFor(currentCountry(), Cavalry) != 0)
2112       m_onu->itemFor(currentCountry(), Cavalry)->setPos(currentCountry()->pointCavalry());
2113     m_onu->setDirty();
2114   }
2115 }
slotCavalryyValueChanged(int v)2116 void MainWindow::slotCavalryyValueChanged(int v)
2117 {
2118   qCDebug(KSIRKSKINEDITOR_LOG);
2119   if (currentCountry() != 0)
2120   {
2121     currentCountry()->pointCavalry(QPointF(currentCountry()->pointCavalry().x(),v));
2122     if (m_onu->itemFor(currentCountry(), Cavalry) != 0)
2123       m_onu->itemFor(currentCountry(), Cavalry)->setPos(currentCountry()->pointCavalry());
2124     m_onu->setDirty();
2125   }
2126 }
2127 
slotCannonxValueChanged(int v)2128 void MainWindow::slotCannonxValueChanged(int v)
2129 {
2130   qCDebug(KSIRKSKINEDITOR_LOG);
2131   if (currentCountry() != 0)
2132   {
2133     currentCountry()->pointCannon(QPointF(v,currentCountry()->pointCannon().y()));
2134     if (m_onu->itemFor(currentCountry(), Cannon) != 0)
2135       m_onu->itemFor(currentCountry(), Cannon)->setPos(currentCountry()->pointCannon());
2136     m_onu->setDirty();
2137   }
2138 }
2139 
slotCannonyValueChanged(int v)2140 void MainWindow::slotCannonyValueChanged(int v)
2141 {
2142   qCDebug(KSIRKSKINEDITOR_LOG);
2143   if (currentCountry() != 0)
2144   {
2145     currentCountry()->pointCannon(QPointF(currentCountry()->pointCannon().x(),v));
2146     if (m_onu->itemFor(currentCountry(), Cannon) != 0)
2147       m_onu->itemFor(currentCountry(), Cannon)->setPos(currentCountry()->pointCannon());
2148     m_onu->setDirty();
2149   }
2150 }
2151 
2152 
2153 } // closing namespace
2154 
2155 
2156