File indexing completed on 2024-04-28 07:54:20

0001 /* This file is part of KsirK.
0002    Copyright (C) 2008 Gael de Chalendar <kleag@free.fr>
0003 
0004    KsirK is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation, either version 2
0007    of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    General Public License for more details.
0013 
0014    You should have received a copy of the GNU General Public License
0015    along with this program; if not, write to the Free Software
0016    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017    02110-1301, USA
0018 */
0019 
0020 // application specific includes
0021 #include "mainwindow.h"
0022 #include "ksirkSkinEditorConfigDialog.h"
0023 #include "ksirkskineditorsettings.h"
0024 #include "ksirkskineditorscene.h"
0025 #include "ksirkskindefinition.h"
0026 #include "ksirkcountrydefinition.h"
0027 #include "ksirkcontinentdefinition.h"
0028 #include "ksirkgoaldefinition.h"
0029 #include "ksirknationalitydefinition.h"
0030 #include "ksirkspritesdefinition.h"
0031 #include "ksirkskineditorpixmapitem.h"
0032 #include "ksirkskineditortextitem.h"
0033 #include "ksirkskineditorcountriesselectiondialog.h"
0034 #include "skinSpritesData.h"
0035 #include "goal.h"
0036 
0037 //include files for QT
0038 #include <QAction>
0039 #include <QDockWidget>
0040 #include <QFileDialog>
0041 #include <QTreeView>
0042 #include <QGridLayout>
0043 #include <QString>
0044 #include <QMovie>
0045 #include <QGraphicsScene>
0046 #include <QGraphicsView>
0047 #include <QGraphicsPixmapItem>
0048 #include <QGraphicsSvgItem>
0049 #include <QBitmap>
0050 #include <QPixmap>
0051 #include <QInputDialog>
0052 #include <QMenuBar>
0053 #include <QStatusBar>
0054 #include <QSvgRenderer>
0055 
0056 // include files for KDE
0057 #include <KMessageBox>
0058 #include <KLocalizedString>
0059 #include <KConfig>
0060 #include <KGameStandardAction>
0061 #include <KStandardAction>
0062 #include <KActionCollection>
0063 #include "ksirkskineditor_debug.h"
0064 #include <KToolBar>
0065 #include <KAboutApplicationDialog>
0066 #include <KRecentFilesAction>
0067 
0068 
0069 #include <assert.h>
0070 
0071 
0072 namespace KsirkSkinEditor
0073 {
0074 
0075 MainWindow::MainWindow(QWidget* parent) :
0076   KXmlGuiWindow(parent),
0077   m_selectedSprite(None),
0078   m_onu(nullptr),
0079   m_rfa(nullptr),
0080   m_mapItem(nullptr),
0081   m_updateHighlightPosition(false)
0082 {
0083   qCDebug(KSIRKSKINEDITOR_LOG) << "MainWindow constructor begin";
0084   KSirkSkinEditorWidget* mainWidget = new KSirkSkinEditorWidget(this);
0085   setCentralWidget(mainWidget);
0086   
0087   m_mapScene = new Scene(0,0,1024,768,this);
0088   connect(m_mapScene, &Scene::position, this, &MainWindow::slotPosition);
0089   connect(m_mapScene, &Scene::pressPosition, this, &MainWindow::slotPressPosition);
0090   connect(m_mapScene, &Scene::releasePosition, this, &MainWindow::slotReleasePosition);
0091   m_mapView = new QGraphicsView(m_mapScene,mainWidget->mapScrollArea);
0092   m_mapView->setInteractive(true);
0093 
0094   mainWidget->mapScrollArea->setBackgroundRole(QPalette::Dark);
0095   mainWidget->mapScrollArea->setWidget(m_mapView);
0096   
0097   QHBoxLayout* layout = new QHBoxLayout;
0098   mainWidget->buttonsScrollArea->setLayout(layout);
0099 
0100   m_flagButton = new QPushButton(mainWidget->buttonsScrollArea);
0101   layout->addWidget(m_flagButton);
0102   m_flagButton->setCheckable(true);
0103   m_flagButton->setEnabled(false);
0104   connect(m_flagButton,&QAbstractButton::clicked,this,&MainWindow::slotFlagButtonClicked);
0105 
0106   m_infantryButton = new QPushButton(mainWidget->buttonsScrollArea);
0107   layout->addWidget(m_infantryButton);
0108   m_infantryButton->setCheckable(true);
0109   m_infantryButton->setEnabled(false);
0110   connect(m_infantryButton,&QAbstractButton::clicked,this,&MainWindow::slotInfantryButtonClicked);
0111 
0112   m_cavalryButton = new QPushButton(mainWidget->buttonsScrollArea);
0113   layout->addWidget(m_cavalryButton);
0114   m_cavalryButton->setCheckable(true);
0115   m_cavalryButton->setEnabled(false);
0116   connect(m_cavalryButton,&QAbstractButton::clicked,this,&MainWindow::slotCavalryButtonClicked);
0117 
0118   m_cannonButton = new QPushButton(mainWidget->buttonsScrollArea);
0119   layout->addWidget(m_cannonButton);
0120   m_cannonButton->setCheckable(true);
0121   m_cannonButton->setEnabled(false);
0122   connect(m_cannonButton,&QAbstractButton::clicked,this,&MainWindow::slotCannonButtonClicked);
0123 
0124   QString anchorFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("cross.png"));
0125   if (anchorFileName.isNull())
0126   {
0127     KMessageBox::error(nullptr, i18n("Cannot load anchor icon<br>Program cannot continue"), i18n("Error"));
0128     exit(2);
0129   }
0130   QPixmap anchorPix = QPixmap(anchorFileName);
0131   m_anchorButton = new QPushButton(mainWidget->buttonsScrollArea);
0132   m_anchorButton->setIcon(anchorPix);
0133   layout->addWidget(m_anchorButton);
0134   m_anchorButton->setCheckable(true);
0135   m_anchorButton->setEnabled(false);
0136   connect(m_anchorButton,&QAbstractButton::clicked,this,&MainWindow::slotAnchorButtonClicked);
0137   
0138   QString centerFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("target.png"));
0139   if (centerFileName.isNull())
0140   {
0141     KMessageBox::error(nullptr, i18n("Cannot load center icon<br>Program cannot continue"), i18n("Error"));
0142     exit(2);
0143   }
0144   QPixmap centerPix = QPixmap(centerFileName);
0145   m_centerButton = new QPushButton(mainWidget->buttonsScrollArea);
0146   m_centerButton->setIcon(centerPix);
0147   layout->addWidget(m_centerButton);
0148   m_centerButton->setCheckable(true);
0149   m_centerButton->setEnabled(false);
0150   connect(m_centerButton,&QAbstractButton::clicked,this,&MainWindow::slotCenterButtonClicked);
0151 
0152   
0153   //   m_accels.setEnabled(true);
0154   
0155   QString iconFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("ksirkskineditor.png"));
0156 /*  if (iconFileName.isNull())
0157   {
0158       KMessageBox::error(0, i18n("Cannot load icon<br>Program cannot continue"), i18n("Error"));
0159       exit(2);
0160   }*/
0161   QPixmap icon(iconFileName);
0162 
0163 //    qCDebug(KSIRKSKINEDITOR_LOG) << "Before initActions";
0164   initActions();
0165 
0166   m_skinDefWidget = new KSirkSkinDefinitionWidget(this);
0167   addDockWidget ( Qt::LeftDockWidgetArea, m_skinDefWidget);
0168   
0169   connect(m_skinDefWidget->fontrequester, &KFontRequester::fontSelected, this, &MainWindow::slotFontSelected);
0170   connect(m_skinDefWidget->fgcolorbutton, &KColorButton::changed, this, &MainWindow::slotFgSelected);
0171   connect(m_skinDefWidget->bgcolorbutton, &KColorButton::changed, this, &MainWindow::slotBgColorSelected);
0172 
0173   m_countryDefWidget = new KsirkCountryDefinitionWidget(this);
0174   m_countryDefWidget->neighbourslist->setSortingEnabled(true);
0175   m_countryDefWidget->neighbourslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
0176   addDockWidget ( Qt::RightDockWidgetArea, m_countryDefWidget);
0177   m_countryDefWidget->hide();
0178   
0179   m_continentDefWidget = new KsirkContinentDefinitionWidget(this);
0180   m_continentDefWidget->countrieslist->setSortingEnabled(true);
0181   m_continentDefWidget->countrieslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
0182   addDockWidget ( Qt::RightDockWidgetArea, m_continentDefWidget);
0183   m_continentDefWidget->hide();
0184   
0185   m_goalDefWidget = new KsirkGoalDefinitionWidget(this);
0186   addDockWidget ( Qt::RightDockWidgetArea, m_goalDefWidget);
0187   m_goalDefWidget->hide();
0188   connect(m_goalDefWidget->worldtype,&QAbstractButton::clicked,this,&MainWindow::slotGoalTypeWorldClicked);
0189   connect(m_goalDefWidget->playertype,&QAbstractButton::clicked,this,&MainWindow::slotGoalTypePlayerClicked);
0190   connect(m_goalDefWidget->countriestype,&QAbstractButton::clicked,this,&MainWindow::slotGoalTypeCountriesClicked);
0191   connect(m_goalDefWidget->continentstype,&QAbstractButton::clicked,this,&MainWindow::slotGoalTypeContinentsClicked);
0192   connect (m_goalDefWidget->description,&QTextEdit::textChanged, this, &MainWindow::slotGoalDescriptionEdited);
0193   connect (m_goalDefWidget->nbcountries, &QSpinBox::valueChanged, this, &MainWindow::slotGoalNbCountriesChanged);
0194   connect (m_goalDefWidget->armiesbycountry, &QSpinBox::valueChanged, this, &MainWindow::slotGoalNbArmiesByCountryChanged);
0195   connect (m_goalDefWidget->anycontinent,&QCheckBox::stateChanged, this, &MainWindow::slotGoalAnyContinentChanged);
0196   connect (m_goalDefWidget->selectcontinentsbutton, &QAbstractButton::clicked, this, &MainWindow::slotGoalContinents);
0197   connect(m_skinDefWidget->newGoalButton, &QAbstractButton::clicked, this, &MainWindow::slotNewGoal);
0198   connect(m_skinDefWidget->deleteGoalButton, &QAbstractButton::clicked, this, &MainWindow::slotDeleteGoal);
0199   
0200   m_nationalityDefWidget = new KsirkNationalityDefinitionWidget(this);
0201   addDockWidget ( Qt::RightDockWidgetArea, m_nationalityDefWidget);
0202   m_nationalityDefWidget->hide();
0203   
0204   m_spritesDefWidget = new KsirkSpritesDefinitionWidget(this);
0205   addDockWidget ( Qt::RightDockWidgetArea, m_spritesDefWidget);
0206   m_spritesDefWidget->hide();
0207   connect(m_spritesDefWidget->flagw, &QSpinBox::valueChanged, this, &MainWindow::slotFlagWidthChanged);
0208   connect(m_spritesDefWidget->flagh, &QSpinBox::valueChanged, this, &MainWindow::slotFlagHeightChanged);
0209   connect(m_spritesDefWidget->flagf, &QSpinBox::valueChanged, this, &MainWindow::slotFlagFramesChanged);
0210   connect(m_spritesDefWidget->flagv, &QSpinBox::valueChanged, this, &MainWindow::slotFlagVersionsChanged);
0211 
0212   connect(m_spritesDefWidget->infantryw, &QSpinBox::valueChanged, this, &MainWindow::slotInfantryWidthChanged);
0213   connect(m_spritesDefWidget->infantryh, &QSpinBox::valueChanged, this, &MainWindow::slotInfantryHeightChanged);
0214   connect(m_spritesDefWidget->infantryf, &QSpinBox::valueChanged, this, &MainWindow::slotInfantryFramesChanged);
0215   connect(m_spritesDefWidget->infantryv, &QSpinBox::valueChanged, this, &MainWindow::slotInfantryVersionsChanged);
0216   
0217   connect(m_spritesDefWidget->cavalryw, &QSpinBox::valueChanged, this, &MainWindow::slotCavalryWidthChanged);
0218   connect(m_spritesDefWidget->cavalryh, &QSpinBox::valueChanged, this, &MainWindow::slotCavalryHeightChanged);
0219   connect(m_spritesDefWidget->cavalryf, &QSpinBox::valueChanged, this, &MainWindow::slotCavalryFramesChanged);
0220   connect(m_spritesDefWidget->cavalryv, &QSpinBox::valueChanged, this, &MainWindow::slotCavalryVersionsChanged);
0221   
0222   connect(m_spritesDefWidget->cannonw, &QSpinBox::valueChanged, this, &MainWindow::slotCannonWidthChanged);
0223   connect(m_spritesDefWidget->cannonh, &QSpinBox::valueChanged, this, &MainWindow::slotCannonHeightChanged);
0224   connect(m_spritesDefWidget->cannonf, &QSpinBox::valueChanged, this, &MainWindow::slotCannonFramesChanged);
0225   connect(m_spritesDefWidget->cannonv, &QSpinBox::valueChanged, this, &MainWindow::slotCannonVersionsChanged);
0226   
0227   connect(m_spritesDefWidget->firingw, &QSpinBox::valueChanged, this, &MainWindow::slotFiringWidthChanged);
0228   connect(m_spritesDefWidget->firingh, &QSpinBox::valueChanged, this, &MainWindow::slotFiringHeightChanged);
0229   connect(m_spritesDefWidget->firingf, &QSpinBox::valueChanged, this, &MainWindow::slotFiringFramesChanged);
0230   connect(m_spritesDefWidget->firingv, &QSpinBox::valueChanged, this, &MainWindow::slotFiringVersionsChanged);
0231   
0232   connect(m_spritesDefWidget->explodingw, &QSpinBox::valueChanged, this, &MainWindow::slotExplodingWidthChanged);
0233   connect(m_spritesDefWidget->explodingh, &QSpinBox::valueChanged, this, &MainWindow::slotExplodingHeightChanged);
0234   connect(m_spritesDefWidget->explodingf, &QSpinBox::valueChanged, this, &MainWindow::slotExplodingFramesChanged);
0235   connect(m_spritesDefWidget->explodingv, &QSpinBox::valueChanged, this, &MainWindow::slotExplodingVersionsChanged);
0236   
0237   
0238   connect(m_skinDefWidget->qtabwidget, &QTabWidget::currentChanged, this, &MainWindow::slotSkinPartTabChanged);
0239   m_skinDefWidget->qtabwidget-> setCurrentIndex(0);
0240   
0241   m_skinDefWidget->countrieslist->setSortingEnabled (true);
0242   connect(m_skinDefWidget->countrieslist, &QListWidget::itemClicked, this, &MainWindow::slotCountrySelected);
0243 
0244   connect(m_skinDefWidget->goalslist, &QListWidget::itemClicked, this, &MainWindow::slotGoalSelected);
0245   
0246   connect (m_countryDefWidget->neighboursbutton, &QAbstractButton::clicked, this, &MainWindow::slotNeighbours);
0247   connect(m_countryDefWidget->flagx, &QSpinBox::valueChanged, this, &MainWindow::slotFLagxValueChanged);
0248   connect(m_countryDefWidget->flagy, &QSpinBox::valueChanged, this, &MainWindow::slotFLagyValueChanged);
0249   connect(m_countryDefWidget->centerx, &QSpinBox::valueChanged, this, &MainWindow::slotCenterxValueChanged);
0250   connect(m_countryDefWidget->centery, &QSpinBox::valueChanged, this, &MainWindow::slotCenteryValueChanged);
0251   connect(m_countryDefWidget->anchorx, &QSpinBox::valueChanged, this, &MainWindow::slotAnchorxValueChanged);
0252   connect(m_countryDefWidget->anchory, &QSpinBox::valueChanged, this, &MainWindow::slotAnchoryValueChanged);
0253   connect(m_countryDefWidget->infantryx, &QSpinBox::valueChanged, this, &MainWindow::slotInfantryxValueChanged);
0254   connect(m_countryDefWidget->infantryy, &QSpinBox::valueChanged, this, &MainWindow::slotInfantryyValueChanged);
0255   connect(m_countryDefWidget->cavalryx, &QSpinBox::valueChanged, this, &MainWindow::slotCavalryxValueChanged);
0256   connect(m_countryDefWidget->cavalryy, &QSpinBox::valueChanged, this, &MainWindow::slotCavalryyValueChanged);
0257   connect(m_countryDefWidget->cannonx, &QSpinBox::valueChanged, this, &MainWindow::slotCannonxValueChanged);
0258   connect(m_countryDefWidget->cannony, &QSpinBox::valueChanged, this, &MainWindow::slotCannonyValueChanged);
0259   
0260 
0261   connect (m_skinDefWidget->skinNameLineEdit, &QLineEdit::editingFinished, this, &MainWindow::slotSkinNameEdited);
0262 
0263   connect (m_skinDefWidget->widthLineEdit, &QSpinBox::valueChanged, this, &MainWindow::slotSkinWidthEdited);
0264   connect (m_skinDefWidget->heightLineEdit, &QSpinBox::valueChanged, this, &MainWindow::slotSkinHeightEdited);
0265 
0266   connect (m_skinDefWidget->descriptionTextEdit,&QTextEdit::textChanged, this, &MainWindow::slotSkinDescriptionEdited);
0267 
0268   QIntValidator* widthDiffValidator = new QIntValidator(this);
0269   m_spritesDefWidget->widthDiffLineEdit->setValidator(widthDiffValidator);
0270   connect (m_spritesDefWidget->widthDiffLineEdit, &QLineEdit::editingFinished, this, &MainWindow::slotSkinWidthDiffEdited);
0271 
0272   m_skinDefWidget->nationalitieslist->setSortingEnabled (true);
0273   connect(m_skinDefWidget->nationalitieslist, &QListWidget::itemClicked, this, &MainWindow::slotNationalitySelected);
0274   connect(m_skinDefWidget->newNationalityButton, &QAbstractButton::clicked, this, &MainWindow::slotNewNationality);
0275   connect(m_skinDefWidget->deleteNationalityButton, &QAbstractButton::clicked, this, &MainWindow::slotDeleteNationality);
0276 
0277   connect(m_nationalityDefWidget->name,&QLineEdit::editingFinished, this, &MainWindow::slotNationalityNameEdited);
0278   connect(m_nationalityDefWidget->leader,&QLineEdit::editingFinished, this, &MainWindow::slotNationalityLeaderNameEdited);
0279   connect(m_nationalityDefWidget->flag, &KComboBox::currentIndexChanged, this, &MainWindow::slotNationalityFlagEdited);
0280   
0281   
0282   connect(m_skinDefWidget->newCountryButton, &QAbstractButton::clicked, this, &MainWindow::slotNewCountry);
0283   connect(m_skinDefWidget->deleteCountryButton, &QAbstractButton::clicked, this, &MainWindow::slotDeleteCountry);    
0284 
0285   m_skinDefWidget->continentslist->setSortingEnabled (true);
0286   connect(m_skinDefWidget->continentslist, &QListWidget::itemClicked, this, &MainWindow::slotContinentSelected);
0287 
0288   connect(m_skinDefWidget->newContinentButton, &QAbstractButton::clicked, this, &MainWindow::slotNewContinent);
0289   connect(m_skinDefWidget->deleteContinentButton, &QAbstractButton::clicked, this, &MainWindow::slotDeleteContinent);
0290   
0291   connect (m_continentDefWidget->selectcountriesbutton, &QAbstractButton::clicked, this, &MainWindow::slotContinentCountries);
0292   
0293   connect(m_continentDefWidget->bonus, &QSpinBox::valueChanged, this, &MainWindow::slotContinentBonusEdited);
0294   
0295   qCDebug(KSIRKSKINEDITOR_LOG) << "Setting up GUI";
0296   setupGUI();
0297   
0298   //    qCDebug(KSIRKSKINEDITOR_LOG) << "Before initStatusBar";
0299   initStatusBar();
0300   
0301   menuBar()-> show();
0302   
0303   setMouseTracking(true);
0304   
0305 }
0306 
0307 MainWindow::~MainWindow()
0308 {
0309   qCDebug(KSIRKSKINEDITOR_LOG);
0310   KSharedConfig::Ptr config = KSharedConfig::openConfig();
0311   if (m_rfa != nullptr)
0312   {
0313     qCDebug(KSIRKSKINEDITOR_LOG) << "saving recent files";
0314     m_rfa->saveEntries(KSharedConfig::openConfig()->group(QStringLiteral("ksirkskineditor")));
0315   }
0316 }
0317 
0318 void MainWindow::initActions()
0319 {
0320   QAction *action;
0321   // standard game actions
0322   action = KGameStandardAction::load(this, &MainWindow::slotOpenSkin, this);
0323   actionCollection()->addAction(action->objectName(), action);
0324   action->setToolTip(i18n("Open a saved skin..."));
0325 
0326   m_rfa = KGameStandardAction::loadRecent (this, &MainWindow::slotURLSelected, this);
0327   actionCollection()->addAction(m_rfa->objectName(), m_rfa);
0328   m_rfa->setText(i18n("Load &Recent"));
0329   m_rfa->setToolTip(i18n("Open a recently saved skin..."));
0330 
0331   KSharedConfig::Ptr config = KSharedConfig::openConfig();
0332   qCDebug(KSIRKSKINEDITOR_LOG) << "loading recent files";
0333   m_rfa->loadEntries(KSharedConfig::openConfig()->group(QStringLiteral("ksirkskineditor")));
0334   
0335   m_saveGameAction = KGameStandardAction::save(this, &MainWindow::slotSaveSkin, this);
0336   actionCollection()->addAction(m_saveGameAction->objectName(), m_saveGameAction);
0337   m_saveGameAction->setToolTip(i18n("Save the current skin"));
0338 
0339   action = KGameStandardAction::quit(this, &MainWindow::close, this);
0340   actionCollection()->addAction(action->objectName(), action);
0341 
0342 //   action = KGameStandardAction::gameNew(this, &MainWindow::slotNewGame, this);
0343 //   actionCollection()->addAction(action->objectName(), action);
0344 
0345 //   action = KStandardAction::zoomIn(this, &MainWindow::slotZoomIn, this);
0346 //   actionCollection()->addAction(action->objectName(), action);
0347 
0348 //   action = KStandardAction::zoomOut(this, &MainWindow::slotZoomOut, this);
0349 //   actionCollection()->addAction(action->objectName(), action);
0350 
0351   KStandardAction::preferences( this, &MainWindow::optionsConfigure, actionCollection() );
0352 
0353 }
0354 
0355 void MainWindow::initStatusBar()
0356 {
0357   statusBar()-> setSizeGripEnabled(true);
0358 }
0359 
0360 void MainWindow::slotOpenSkin()
0361 {
0362   const QString skinDir = QFileDialog::getExistingDirectory(this, i18nc("@title:window", "Choose the Root Folder of the Skin to Open"), QString());
0363   if (skinDir.isEmpty())
0364   {
0365     return;
0366   }
0367 
0368   openSkin(skinDir);
0369 }
0370 
0371 void MainWindow::openSkin(const QString& skinDir)
0372 {
0373   qCDebug(KSIRKSKINEDITOR_LOG) << skinDir;
0374   if (m_rfa != nullptr)
0375   {
0376     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding" << skinDir << "to recent files";
0377     m_rfa->addUrl(QUrl::fromLocalFile(skinDir));
0378   }
0379   
0380   m_mapScene->clear();
0381   m_skinDefWidget->countrieslist->clear();
0382   m_skinDefWidget->continentslist->clear();
0383   m_skinDefWidget->goalslist->clear();
0384   
0385   delete m_onu;
0386   m_onu = new ONU(skinDir, this);
0387 
0388   m_skinDefWidget->fontrequester->setFont(m_onu->foregroundFont());
0389   m_skinDefWidget->fgcolorbutton->setColor(m_onu->foregroundColor());
0390   m_skinDefWidget->bgcolorbutton->setColor(m_onu->backgroundColor());
0391   
0392   m_skinDefWidget->skinNameLineEdit->setText(m_onu->name());
0393   m_skinDefWidget->widthLineEdit->setValue(m_onu->width());
0394   m_skinDefWidget->heightLineEdit->setValue(m_onu->height());
0395   m_skinDefWidget->descriptionTextEdit->setText(m_onu->description());
0396   m_spritesDefWidget->widthDiffLineEdit->setText(QString::number(SkinSpritesData::changeable().intData(QStringLiteral("width-between-flag-and-fighter"))));
0397 
0398   m_spritesDefWidget->flagw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("flag-width")));
0399   m_spritesDefWidget->flagh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("flag-height")));
0400   m_spritesDefWidget->flagf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("flag-frames")));
0401   m_spritesDefWidget->flagv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("flag-versions")));
0402   
0403   m_spritesDefWidget->infantryw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("infantry-width")));
0404   m_spritesDefWidget->infantryh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("infantry-height")));
0405   m_spritesDefWidget->infantryf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("infantry-frames")));
0406   m_spritesDefWidget->infantryv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("infantry-versions")));
0407   
0408   m_spritesDefWidget->cavalryw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cavalry-width")));
0409   m_spritesDefWidget->cavalryh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cavalry-height")));
0410   m_spritesDefWidget->cavalryf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cavalry-frames")));
0411   m_spritesDefWidget->cavalryv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cavalry-versions")));
0412   
0413   m_spritesDefWidget->cannonw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cannon-width")));
0414   m_spritesDefWidget->cannonh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cannon-height")));
0415   m_spritesDefWidget->cannonf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cannon-frames")));
0416   m_spritesDefWidget->cannonv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("cannon-versions")));
0417   
0418   m_spritesDefWidget->firingw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("firing-width")));
0419   m_spritesDefWidget->firingh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("firing-height")));
0420   m_spritesDefWidget->firingf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("firing-frames")));
0421   m_spritesDefWidget->firingv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("firing-versions")));
0422   
0423   m_spritesDefWidget->explodingw->setValue(SkinSpritesData::changeable().intData(QStringLiteral("exploding-width")));
0424   m_spritesDefWidget->explodingh->setValue(SkinSpritesData::changeable().intData(QStringLiteral("exploding-height")));
0425   m_spritesDefWidget->explodingf->setValue(SkinSpritesData::changeable().intData(QStringLiteral("exploding-frames")));
0426   m_spritesDefWidget->explodingv->setValue(SkinSpritesData::changeable().intData(QStringLiteral("exploding-versions")));
0427 
0428   m_nationalityDefWidget->flag->clear();
0429   foreach(const QString& key, m_onu->poolIds())
0430   {
0431     int flagWidth = SkinSpritesData::changeable().intData(QStringLiteral("flag-width"));
0432     int flagHeight = SkinSpritesData::changeable().intData(QStringLiteral("flag-height"));
0433     int flagFrames = SkinSpritesData::changeable().intData(QStringLiteral("flag-frames"));
0434     int flagVersions = SkinSpritesData::changeable().intData(QStringLiteral("flag-versions"));
0435     QPixmap flagIcon = m_onu->pixmapForId(key,flagWidth*flagFrames,flagHeight*flagVersions).copy(0,0,flagWidth,flagHeight);
0436     m_nationalityDefWidget->flag->insertItem(m_nationalityDefWidget->flag->count(),QIcon(flagIcon),key);
0437   }
0438 
0439   
0440   QPixmap mapPixmap(m_onu->pixmapForId(QStringLiteral("map"), m_onu->width(), m_onu->height()));
0441   m_mapItem = m_mapScene->addPixmap(mapPixmap);
0442   
0443   m_flagButton->setIcon(m_onu->flagIcon());
0444   //   m_flagButton->setIconSize(QSize(flagWidth,flagHeight));
0445   
0446   m_infantryButton->setIcon(m_onu->infantryIcon());
0447   //   m_infantryButton->setIconSize(QSize(infantryWidth,infantryHeight));
0448   
0449   m_cavalryButton->setIcon(m_onu->cavalryIcon());
0450   //   m_cavalryButton->setIconSize(QSize(cavalryWidth,cavalryHeight));
0451   
0452   m_cannonButton->setIcon(m_onu->cannonIcon());
0453   //   m_cannonButton->setIconSize(QSize(cannonWidth,cannonHeight));
0454   
0455   qCDebug(KSIRKSKINEDITOR_LOG) << "Adding nationalities items";
0456   foreach (Nationality* nationality, m_onu->nationalities())
0457   {
0458     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding "<<nationality->name()<<" items";
0459     m_skinDefWidget->nationalitieslist->addItem(nationality->name());
0460   }
0461   
0462   qCDebug(KSIRKSKINEDITOR_LOG) << "Adding countries items";
0463   foreach (Country* country, m_onu->countries())
0464   {
0465     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding "<<country->name()<<" items";
0466     m_skinDefWidget->countrieslist->addItem(country->name());
0467     
0468     if (!country->pointFlag().isNull())
0469     {
0470       createPixmapFor(country, Flag);
0471     }
0472     if (!country->pointInfantry().isNull())
0473     {
0474       createPixmapFor(country, Infantry);
0475     }
0476     if (!country->pointCavalry().isNull())
0477     {
0478       createPixmapFor(country, Cavalry);
0479     }
0480     if (!country->pointCannon().isNull())
0481     {
0482       createPixmapFor(country, Cannon);
0483     }
0484     if (!country->anchorPoint().isNull())
0485     {
0486       createPixmapFor(country, Anchor);
0487     }
0488     if (!country->centralPoint().isNull())
0489     {
0490       createPixmapFor(country, Center);
0491     }
0492   }
0493 
0494   qCDebug(KSIRKSKINEDITOR_LOG) << "Adding continents items";
0495   foreach (Continent* continent, m_onu->continents())
0496   {
0497     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding "<<continent<<" items";
0498     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding "<<continent->name()<<" items";
0499     m_skinDefWidget->continentslist->addItem(continent->name());
0500   }
0501 
0502   qCDebug(KSIRKSKINEDITOR_LOG) << "Adding goals items";
0503   for (int i = 1; i <= m_onu->goals().size(); i++)
0504   {
0505     qCDebug(KSIRKSKINEDITOR_LOG) << "Adding goal"<<i<<" items";
0506     m_skinDefWidget->goalslist->addItem("goal" + QString::number(i));
0507   }
0508 }
0509 
0510 void MainWindow::slotSaveSkin()
0511 {
0512   qCDebug(KSIRKSKINEDITOR_LOG);
0513   m_onu->saveConfig();
0514 }
0515 
0516 /**
0517   * Reimplementation of the inherited function called when a window close event arise
0518   */
0519 bool MainWindow::queryClose()
0520 {
0521   qCDebug(KSIRKSKINEDITOR_LOG);
0522   // TODO : Test si jeu en cours
0523   if (m_onu && m_onu->dirty())
0524   {
0525     switch (KMessageBox::warningTwoActionsCancel(this,
0526                                              i18n("There are unsaved changes. What do you want to do?"),
0527                                              i18n("Exit Anyway?"),
0528                                              KGuiItem(i18n("Quit without saving")),
0529                                              KGuiItem(i18n("Save then quit")),
0530                                              KGuiItem(i18n("Do not quit"))))
0531     {
0532       case KMessageBox::PrimaryAction:
0533         return true;
0534         break;
0535       case KMessageBox::SecondaryAction:
0536         m_onu->saveConfig();
0537         return true;
0538         break;
0539       default:
0540         return false;
0541     }
0542   }
0543   KSharedConfig::openConfig()->sync();
0544   return true;
0545 }
0546 
0547 void MainWindow::optionsConfigure()
0548 {
0549   //An instance of your dialog could be already created and could be cached, 
0550   //in which case you want to display the cached dialog instead of creating 
0551   //another one 
0552   if ( KsirkSkinEditorConfigurationDialog::showDialog( QStringLiteral("settings") ) ) 
0553     return;
0554  
0555   //KConfigDialog didn't find an instance of this dialog, so lets create it : 
0556   KsirkSkinEditorConfigurationDialog* dialog = new KsirkSkinEditorConfigurationDialog(
0557       this, "settings",
0558       KsirkSkinEditorSettings::self() ); 
0559 
0560   dialog->show();
0561 }
0562 
0563 // void MainWindow::slotZoomIn()
0564 // {
0565 //   qCDebug(KSIRKSKINEDITOR_LOG);
0566 // }
0567 
0568 // void MainWindow::slotZoomOut()
0569 // {
0570 //   qCDebug(KSIRKSKINEDITOR_LOG);
0571 // }
0572 
0573 void MainWindow::slotShowAboutApplication()
0574 {
0575 #if 0 //QT5
0576   KAboutApplicationDialog dialog(KGlobal::mainComponent().aboutData(), this);
0577   dialog.exec();
0578 #endif
0579 }
0580 
0581 void MainWindow::slotFlagButtonClicked()
0582 {
0583   m_infantryButton->setChecked(false);
0584   m_cavalryButton->setChecked(false);
0585   m_cannonButton->setChecked(false);
0586   m_anchorButton->setChecked(false);
0587   m_centerButton->setChecked(false);
0588   if (m_selectedSprite == Flag)
0589   {
0590     m_flagButton->setChecked(false);
0591     m_mapView->unsetCursor();
0592   }
0593   else if (m_skinDefWidget->countrieslist->currentItem()!=nullptr)
0594   {
0595     m_mapView->setCursor(QCursor(m_onu->flagIcon(),0,0));
0596     m_selectedSprite = Flag;
0597     m_flagButton->setChecked(true);
0598   }
0599 }
0600 
0601 void MainWindow::slotInfantryButtonClicked()
0602 {
0603   m_flagButton->setChecked(false);
0604   m_cavalryButton->setChecked(false);
0605   m_cannonButton->setChecked(false);
0606   m_anchorButton->setChecked(false);
0607   m_centerButton->setChecked(false);
0608   if (m_selectedSprite == Infantry)
0609   {
0610     m_infantryButton->setChecked(false);
0611     m_mapView->unsetCursor();
0612   }
0613   else if (m_skinDefWidget->countrieslist->currentItem()!=nullptr)
0614   {
0615     m_mapView->setCursor(QCursor(m_onu->infantryIcon(),0,0));
0616     m_selectedSprite = Infantry;
0617     m_infantryButton->setChecked(true);
0618   }
0619 }
0620 
0621 void MainWindow::slotCavalryButtonClicked()
0622 {
0623   m_flagButton->setChecked(false);
0624   m_infantryButton->setChecked(false);
0625   m_cannonButton->setChecked(false);
0626   m_anchorButton->setChecked(false);
0627   m_centerButton->setChecked(false);
0628   if (m_selectedSprite == Cavalry)
0629   {
0630     m_cavalryButton->setChecked(false);
0631     m_mapView->unsetCursor();
0632   }
0633   else if (m_skinDefWidget->countrieslist->currentItem()!=nullptr)
0634   {
0635     m_mapView->setCursor(QCursor(m_onu->cavalryIcon(),0,0));
0636     m_selectedSprite = Cavalry;
0637     m_cavalryButton->setChecked(true);
0638   }
0639 }
0640 
0641 void MainWindow::slotCannonButtonClicked()
0642 {
0643   m_flagButton->setChecked(false);
0644   m_infantryButton->setChecked(false);
0645   m_cavalryButton->setChecked(false);
0646   m_anchorButton->setChecked(false);
0647   m_centerButton->setChecked(false);
0648   if (m_selectedSprite == Cannon)
0649   {
0650     m_cannonButton->setChecked(false);
0651     m_mapView->unsetCursor();
0652   }
0653   else if (m_skinDefWidget->countrieslist->currentItem()!=nullptr)
0654   {
0655     m_mapView->setCursor(QCursor(m_onu->cannonIcon(),0,0));
0656     m_selectedSprite = Cannon;
0657     m_cannonButton->setChecked(true);
0658   }
0659 }
0660 
0661 void MainWindow::slotAnchorButtonClicked()
0662 {
0663   m_flagButton->setChecked(false);
0664   m_infantryButton->setChecked(false);
0665   m_cavalryButton->setChecked(false);
0666   m_cannonButton->setChecked(false);
0667   m_centerButton->setChecked(false);
0668   if (m_selectedSprite == Anchor)
0669   {
0670     m_anchorButton->setChecked(false);
0671     m_mapView->unsetCursor();
0672   }
0673   else if (m_skinDefWidget->countrieslist->currentItem()!=nullptr)
0674   {
0675     QString anchorFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("cross.png"));
0676     if (anchorFileName.isNull())
0677     {
0678       KMessageBox::error(nullptr, i18n("Cannot load anchor icon<br>Program cannot continue"), i18n("Error"));
0679       exit(2);
0680     }
0681     QPixmap anchorPix = QPixmap(anchorFileName);
0682     anchorPix = anchorPix.scaled(16,16);
0683     
0684     m_mapView->setCursor(QCursor(anchorPix,0,0));
0685     m_selectedSprite = Anchor;
0686     m_anchorButton->setChecked(true);
0687   }
0688 }
0689 
0690 void MainWindow::slotCenterButtonClicked()
0691 {
0692   m_flagButton->setChecked(false);
0693   m_infantryButton->setChecked(false);
0694   m_cavalryButton->setChecked(false);
0695   m_cannonButton->setChecked(false);
0696   m_anchorButton->setChecked(false);
0697   if (m_selectedSprite == Center)
0698   {
0699     m_centerButton->setChecked(false);
0700     m_mapView->unsetCursor();
0701   }
0702   else if (m_skinDefWidget->countrieslist->currentItem()!=nullptr)
0703   {
0704     QString centerFileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("target.png"));
0705     if (centerFileName.isNull())
0706     {
0707       KMessageBox::error(nullptr, i18n("Cannot load center icon<br>Program cannot continue"), i18n("Error"));
0708       exit(2);
0709     }
0710     QPixmap centerPix = QPixmap(centerFileName);
0711     centerPix = centerPix.scaled(16,16);
0712     m_mapView->setCursor(QCursor(centerPix,0,0));
0713     m_selectedSprite = Center;
0714     m_centerButton->setChecked(true);
0715   }
0716 }
0717 
0718 void MainWindow::slotPosition(const QPointF& point)
0719 {
0720   QString message(QLatin1String(""));
0721   QTextStream ts( &message );
0722   ts << point.x() << " x " << point.y();
0723   statusBar()->showMessage(message);
0724 //   qCDebug(KSIRKSKINEDITOR_LOG) << "selected sprite:" << m_selectedSprite;
0725   if (currentCountry() != nullptr && m_selectedSprite == Anchor
0726     && m_onu->itemFor(currentCountry(), m_selectedSprite) != nullptr && m_updateHighlightPosition
0727     && currentCountry()->highlighting() != nullptr)
0728   {
0729     qCDebug(KSIRKSKINEDITOR_LOG) << point << (void*)currentCountry() << (void*)m_onu->itemFor(currentCountry(), m_selectedSprite);
0730     QGraphicsItem* anchorItem = m_onu->itemFor(currentCountry(), Anchor);
0731     qCDebug(KSIRKSKINEDITOR_LOG) << "anchorItem=" << anchorItem;
0732     currentCountry()->anchorPoint(point);
0733     QPointF anchorPoint = currentCountry()->anchorPoint();
0734 
0735     double hw = currentCountry()->highlighting()->boundingRect().width();
0736     double hh = currentCountry()->highlighting()->boundingRect().height();
0737     currentCountry()->highlighting()->setPos(anchorPoint - QPointF(hw/2,hh/2 ));
0738 
0739     return;
0740   }
0741 }
0742 
0743 void MainWindow::slotPressPosition(const QPointF& clickedPoint)
0744 {
0745   qCDebug(KSIRKSKINEDITOR_LOG) << clickedPoint << (void*)currentCountry() << m_selectedSprite;
0746   QPixmap pix;
0747   QPixmap alphacopy;
0748   QString fileName;
0749   QPointF point = clickedPoint;
0750   m_updateHighlightPosition = true;
0751   if (currentCountry() == nullptr
0752     || m_onu->itemFor(currentCountry(), m_selectedSprite) != nullptr)
0753   {
0754     qCDebug(KSIRKSKINEDITOR_LOG) << (void*)currentCountry() << (void*)m_onu->itemFor(currentCountry(), m_selectedSprite);
0755     if (currentCountry() != nullptr)
0756     {
0757       currentCountry()->clearHighlighting();
0758     }
0759     return;
0760   }
0761   PixmapItem* item = new PixmapItem();
0762   item->setZValue(10);
0763   connect(item, &PixmapItem::pressed,this, &MainWindow::slotItemPressed);
0764   connect(item, &PixmapItem::placed,this, &MainWindow::slotItemPlaced);
0765   
0766   switch (m_selectedSprite)
0767   {
0768     case Flag:
0769       pix = m_onu->flagIcon();
0770 //       pix = pix.scaled(20,20);
0771       m_countryDefWidget->flagx->setValue(point.x());
0772       m_countryDefWidget->flagy->setValue(point.y());
0773       currentCountry()->pointFlag(point);
0774       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Flag));
0775       break;
0776     case Infantry:
0777       pix = m_onu->infantryIcon();
0778 //       pix = pix.scaled(23,32);
0779       m_countryDefWidget->infantryx->setValue(point.x());
0780       m_countryDefWidget->infantryy->setValue(point.y());
0781       currentCountry()->pointInfantry(point);
0782       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Infantry));
0783       break;
0784     case Cavalry:
0785       pix = m_onu->cavalryIcon();
0786 //       pix = pix.scaled(32,32);
0787       m_countryDefWidget->cavalryx->setValue(point.x());
0788       m_countryDefWidget->cavalryy->setValue(point.y());
0789       currentCountry()->pointCavalry(point);
0790       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Cavalry));
0791       break;
0792     case Cannon:
0793       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding cannon";
0794       pix = m_onu->cannonIcon();
0795 //       pix = pix.scaled(32,32);
0796       m_countryDefWidget->cannonx->setValue(point.x());
0797       m_countryDefWidget->cannony->setValue(point.y());
0798       currentCountry()->pointCannon(point);
0799       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Cannon));
0800       break;
0801     case Anchor:
0802       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding anchor";
0803       fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("cross.png"));
0804       if (fileName.isNull())
0805       {
0806         KMessageBox::error(nullptr, i18n("Cannot load anchor icon<br>Program cannot continue"), i18n("Error"));
0807         exit(2);
0808       }
0809       pix = QPixmap(fileName);
0810       pix = pix.scaled(16,16);
0811       point += QPointF(-pix.width()/2,-pix.height()/2);
0812       m_countryDefWidget->anchorx->setValue(point.x());
0813       m_countryDefWidget->anchory->setValue(point.y());
0814       currentCountry()->anchorPoint(point);
0815       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Anchor));
0816       m_updateHighlightPosition = true;
0817       break;
0818     case Center:
0819       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding center";
0820       fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("target.png"));
0821       if (fileName.isNull())
0822       {
0823         KMessageBox::error(nullptr, i18n("Cannot load center icon<br>Program cannot continue"), i18n("Error"));
0824         exit(2);
0825       }
0826       pix = QPixmap(fileName);
0827       pix = pix.scaled(16,16);
0828       point += QPointF(-pix.width()/2,-pix.height()/2);
0829       m_countryDefWidget->centerx->setValue(point.x());
0830       m_countryDefWidget->centery->setValue(point.y());
0831       currentCountry()->centralPoint(point);
0832       m_onu->itemsMap().insert(item,qMakePair(currentCountry(),Center));
0833       break;
0834     default: ;
0835   }
0836   if (item != nullptr)
0837   {
0838     item->setPixmap(pix);
0839     m_mapScene->addItem(item);
0840     item->setFlag(QGraphicsItem::ItemIsMovable, true);
0841     item->setFlag(QGraphicsItem::ItemIsSelectable, true);
0842     item->setPos(point);
0843   }
0844 }
0845 
0846 void MainWindow::slotReleasePosition(const QPointF& point)
0847 {
0848   qCDebug(KSIRKSKINEDITOR_LOG) << point;
0849   m_updateHighlightPosition = false;
0850 
0851   qCDebug(KSIRKSKINEDITOR_LOG) << "selected sprite:" << m_selectedSprite;
0852   if (currentCountry() != nullptr && m_selectedSprite == Anchor
0853     && m_onu->itemFor(currentCountry(), m_selectedSprite) != nullptr && m_updateHighlightPosition
0854     && currentCountry()->highlighting() != nullptr)
0855   {
0856     qCDebug(KSIRKSKINEDITOR_LOG) << (void*)currentCountry() << (void*)m_onu->itemFor(currentCountry(), m_selectedSprite);
0857     currentCountry()->anchorPoint(point);
0858     currentCountry()->highlighting()->setPos((currentCountry()->anchorPoint().x()-currentCountry()->highlighting()->boundingRect().width()/2),(currentCountry()->anchorPoint().y()-currentCountry()->highlighting()->boundingRect().height()/2));
0859     
0860     return;
0861   }
0862 }
0863 
0864 void MainWindow::slotNationalitySelected(QListWidgetItem* item)
0865 {
0866   qCDebug(KSIRKSKINEDITOR_LOG);
0867   Nationality* nationality = m_onu->nationalityNamed(item->text());
0868   if (nationality != nullptr)
0869   {
0870     initNationalityWidgetWith(nationality);
0871   }
0872 }
0873 
0874 void MainWindow::initNationalityWidgetWith(Nationality* nationality)
0875 {
0876   qCDebug(KSIRKSKINEDITOR_LOG);
0877   m_nationalityDefWidget->name->setText(nationality->name());
0878   m_nationalityDefWidget->leader->setText(nationality->leaderName());
0879   int item = m_nationalityDefWidget->flag->findText(nationality->flagFileName());
0880   if (item != -1)
0881   {
0882       m_nationalityDefWidget->flag->setCurrentIndex(item);
0883   }
0884 }
0885 
0886 void MainWindow::slotCountrySelected(QListWidgetItem* item)
0887 {
0888   qCDebug(KSIRKSKINEDITOR_LOG);
0889   Country* country = m_onu->countryNamed(item->text());
0890   if (country != nullptr)
0891   {
0892     m_countryDefWidget->initWith(country);
0893     initSpritesButtonsWith(country);
0894   }
0895 }
0896 
0897 void MainWindow::slotContinentSelected(QListWidgetItem* item)
0898 {
0899   qCDebug(KSIRKSKINEDITOR_LOG);
0900   Continent* continent = m_onu->continentNamed(item->text());
0901   if (continent != nullptr)
0902   {
0903     initContinentWidgetWith(continent);
0904   }
0905 }
0906 
0907 void MainWindow::initContinentWidgetWith(Continent* continent)
0908 {
0909   qCDebug(KSIRKSKINEDITOR_LOG);
0910   m_continentDefWidget->bonus->setValue(continent->bonus());
0911 
0912   m_continentDefWidget->countrieslist->clear();
0913   foreach(Country* country, continent->members())
0914   {
0915     m_continentDefWidget->countrieslist->addItem(country->name());
0916   }
0917 }
0918 
0919 void MainWindow::slotGoalSelected(QListWidgetItem* item)
0920 {
0921   qCDebug(KSIRKSKINEDITOR_LOG);
0922   int row = m_skinDefWidget->goalslist->row(item);
0923   Goal* goal = m_onu->goals()[row];
0924   if (goal != nullptr)
0925   {
0926     initGoalWidgetWith(goal);
0927   }
0928 }
0929 
0930 void MainWindow::initGoalWidgetWith(Goal* goal)
0931 {
0932   qCDebug(KSIRKSKINEDITOR_LOG);
0933   switch (goal->type())
0934   {
0935     case Goal::NoGoal:
0936       m_goalDefWidget->worldtype->setChecked(true);
0937       m_goalDefWidget->playertype->setChecked(false);
0938       m_goalDefWidget->countriestype->setChecked(false);
0939       m_goalDefWidget->continentstype->setChecked(false);
0940       break;
0941     case Goal::GoalPlayer:
0942       m_goalDefWidget->worldtype->setChecked(false);
0943       m_goalDefWidget->playertype->setChecked(true);
0944       m_goalDefWidget->countriestype->setChecked(false);
0945       m_goalDefWidget->continentstype->setChecked(false);
0946       break;
0947     case Goal::Countries:
0948       m_goalDefWidget->worldtype->setChecked(false);
0949       m_goalDefWidget->playertype->setChecked(false);
0950       m_goalDefWidget->countriestype->setChecked(true);
0951       m_goalDefWidget->continentstype->setChecked(false);
0952       break;
0953     case Goal::Continents:
0954       m_goalDefWidget->worldtype->setChecked(false);
0955       m_goalDefWidget->playertype->setChecked(false);
0956       m_goalDefWidget->countriestype->setChecked(false);
0957       m_goalDefWidget->continentstype->setChecked(true);
0958       break;
0959     default:;
0960   }
0961   m_goalDefWidget->description->setText(goal->description());
0962   m_goalDefWidget->nbcountries->setValue(goal->nbCountries());
0963   m_goalDefWidget->armiesbycountry->setValue(goal->nbArmiesByCountry());
0964   m_goalDefWidget->anycontinent->setChecked(false);
0965   m_goalDefWidget->continentslist->clear();
0966   foreach(const QString& id, goal->continents())
0967   {
0968     qCDebug(KSIRKSKINEDITOR_LOG) << "continent" << id;
0969     if (id.isNull())
0970     {
0971       m_goalDefWidget->anycontinent->setChecked(true);
0972     }
0973     foreach(Continent* continent, m_onu->continents())
0974     {
0975       if (continent->name() == id)
0976       {
0977         m_goalDefWidget->continentslist->addItem(continent->name());
0978       }
0979     }
0980   }
0981 }
0982 
0983 Country* MainWindow::currentCountry()
0984 {
0985   if (m_skinDefWidget->countrieslist->currentItem() == nullptr)
0986     return nullptr;
0987 //   qCDebug(KSIRKSKINEDITOR_LOG) << m_skinDefWidget->countrieslist->currentItem()->text();
0988   return m_onu->countryNamed(m_skinDefWidget->countrieslist->currentItem()->text());
0989 }
0990 
0991 void MainWindow::slotItemPlaced(QGraphicsItem* item, const QPointF&)
0992 {
0993   qCDebug(KSIRKSKINEDITOR_LOG);
0994   if (m_onu->itemsMap().contains(item))
0995   {
0996     Country* country = m_onu->itemsMap()[item].first;
0997     SpriteType type = m_onu->itemsMap()[item].second;
0998     m_countryDefWidget->initWith(country);
0999     for (int i = 0; i != m_skinDefWidget->countrieslist->count(); i++)
1000     {
1001       if (m_skinDefWidget->countrieslist->item(i)->text() == country->name())
1002       {
1003         m_skinDefWidget->countrieslist->setCurrentRow (i, QItemSelectionModel::ClearAndSelect);
1004         break;
1005       }
1006     }
1007     QPointF anchorPos;
1008     QPointF centerPos;
1009     switch (type)
1010     {
1011       case Flag:
1012         country->pointFlag(item->scenePos());
1013         m_countryDefWidget->flagx->setValue(item->scenePos().x());
1014         m_countryDefWidget->flagy->setValue(item->scenePos().y());
1015         m_flagButton->setChecked(false);
1016         m_flagButton->setEnabled(false);
1017         m_mapView->unsetCursor();
1018         break;
1019       case Infantry:
1020         country->pointInfantry(item->scenePos());
1021         m_countryDefWidget->infantryx->setValue(item->scenePos().x());
1022         m_countryDefWidget->infantryy->setValue(item->scenePos().y());
1023         m_infantryButton->setChecked(false);
1024         m_infantryButton->setEnabled(false);
1025         m_mapView->unsetCursor();
1026         break;
1027       case Cavalry:
1028         country->pointCavalry(item->scenePos());
1029         m_countryDefWidget->cavalryx->setValue(item->scenePos().x());
1030         m_countryDefWidget->cavalryy->setValue(item->scenePos().y());
1031         m_cavalryButton->setChecked(false);
1032         m_cavalryButton->setEnabled(false);
1033         m_mapView->unsetCursor();
1034         break;
1035       case Cannon:
1036         country->pointCannon(item->scenePos());
1037         m_countryDefWidget->cannonx->setValue(item->scenePos().x());
1038         m_countryDefWidget->cannony->setValue(item->scenePos().y());
1039         m_cannonButton->setChecked(false);
1040         m_cannonButton->setEnabled(false);
1041         m_mapView->unsetCursor();
1042         break;
1043       case Anchor:
1044         anchorPos = QPointF(item->scenePos().x()+(item->boundingRect().width()/2),item->scenePos().y()+(item->boundingRect().height()/2));
1045         country->anchorPoint(anchorPos);
1046         m_countryDefWidget->anchorx->setValue(anchorPos.x());
1047         m_countryDefWidget->anchory->setValue(anchorPos.y());
1048         m_anchorButton->setChecked(false);
1049         m_anchorButton->setEnabled(false);
1050         m_mapView->unsetCursor();
1051         break;
1052       case Center:
1053         centerPos = QPointF(item->scenePos().x()+(item->boundingRect().width()/2),item->scenePos().y()+(item->boundingRect().height()/2));
1054         country->centralPoint(centerPos);
1055         m_countryDefWidget->centerx->setValue(centerPos.x());
1056         m_countryDefWidget->centery->setValue(centerPos.y());
1057         m_centerButton->setChecked(false);
1058         m_centerButton->setEnabled(false);
1059         m_mapView->unsetCursor();
1060         break;
1061       default:;
1062     }
1063   }
1064 }
1065 
1066 void MainWindow::slotItemPressed(QGraphicsItem* item, const QPointF& point)
1067 {
1068   qCDebug(KSIRKSKINEDITOR_LOG);
1069   if (m_onu->itemsMap().contains(item))
1070   {
1071     Country* country = m_onu->itemsMap()[item].first;
1072     m_countryDefWidget->initWith(country);
1073     for (int i = 0; i != m_skinDefWidget->countrieslist->count(); i++)
1074     {
1075       if (m_skinDefWidget->countrieslist->item(i)->text() == country->name())
1076       {
1077         m_skinDefWidget->countrieslist->setCurrentRow (i, QItemSelectionModel::ClearAndSelect);
1078         break;
1079       }
1080     }
1081     switch (m_onu->itemsMap()[item].second)
1082     {
1083       case Flag:
1084         m_selectedSprite = Flag;
1085         country->clearHighlighting();
1086         break;
1087       case Infantry:
1088         m_selectedSprite = Infantry;
1089         country->clearHighlighting();
1090         break;
1091       case Cavalry:
1092         m_selectedSprite = Cavalry;
1093         country->clearHighlighting();
1094         break;
1095       case Cannon:
1096         m_selectedSprite = Cannon;
1097         country->clearHighlighting();
1098         break;
1099       case Anchor:
1100         m_selectedSprite = Anchor;
1101         item = m_onu->itemFor(country, Anchor);
1102         if (item == nullptr)
1103         {
1104           qCCritical(KSIRKSKINEDITOR_LOG) << "item " << Anchor << "not found for" << country->name();
1105           break;
1106         }
1107         country->anchorPoint(point);
1108         item->setPos( point - QPointF(item->boundingRect().width()/2, item->boundingRect().height()/2) );
1109         country->highlight(m_mapScene, m_onu, Qt::white,128);
1110 //         item->setPos((country->anchorPoint().x()-country->highlighting()->boundingRect().width()/2),
1111 //                      (country->anchorPoint().y()-country->highlighting()->boundingRect().height()/2));
1112         break;
1113       case Center:
1114         m_selectedSprite = Center;
1115         country->clearHighlighting();
1116         break;
1117       default:
1118         m_selectedSprite = None;
1119         country->clearHighlighting();
1120     }
1121   }
1122 }
1123 
1124 void MainWindow::createPixmapFor(Country* country, SpriteType type)
1125 {
1126   qCDebug(KSIRKSKINEDITOR_LOG) << country->name() << type;
1127   QPixmap pix;
1128   QPixmap alphacopy;
1129   QPointF point;
1130   QString fileName;
1131   if (country == nullptr
1132     || m_onu->itemFor(country, type) != nullptr)
1133   {
1134     qCDebug(KSIRKSKINEDITOR_LOG) << (void*)country << (void*)m_onu->itemFor(country, type);
1135     return;
1136   }
1137   QGraphicsItem* item = nullptr;
1138                     
1139   switch (type)
1140   {
1141     case Flag:
1142       item = new PixmapItem();
1143       item->setZValue(3);
1144       pix = m_onu->flagIcon();
1145       ((PixmapItem*)item)->setPixmap(pix);
1146       //       pix = pix.scaled(20,20);
1147       point = country->pointFlag();
1148       m_countryDefWidget->flagx->setValue(point.x());
1149       m_countryDefWidget->flagy->setValue(point.y());
1150       m_onu->itemsMap().insert(item,qMakePair(country,Flag));
1151       break;
1152     case Infantry:
1153       item = new PixmapItem();
1154       item->setZValue(3);
1155       pix = m_onu->infantryIcon();
1156       ((PixmapItem*)item)->setPixmap(pix);
1157       point = country->pointInfantry();
1158       //       pix = pix.scaled(23,32);
1159       m_countryDefWidget->infantryx->setValue(point.x());
1160       m_countryDefWidget->infantryy->setValue(point.y());
1161       m_onu->itemsMap().insert(item,qMakePair(country,Infantry));
1162       break;
1163     case Cavalry:
1164       item = new PixmapItem();
1165       item->setZValue(3);
1166       pix = m_onu->cavalryIcon();
1167       ((PixmapItem*)item)->setPixmap(pix);
1168       point = country->pointCavalry();
1169       //       pix = pix.scaled(32,32);
1170       m_countryDefWidget->cavalryx->setValue(point.x());
1171       m_countryDefWidget->cavalryy->setValue(point.y());
1172       m_onu->itemsMap().insert(item,qMakePair(country,Cavalry));
1173       break;
1174     case Cannon:
1175       item = new PixmapItem();
1176       item->setZValue(3);
1177       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding cannon";
1178       pix = m_onu->cannonIcon();
1179       ((PixmapItem*)item)->setPixmap(pix);
1180       point = country->pointCannon();
1181       //       pix = pix.scaled(32,32);
1182       m_countryDefWidget->cannonx->setValue(point.x());
1183       m_countryDefWidget->cannony->setValue(point.y());
1184       m_onu->itemsMap().insert(item,qMakePair(country,Cannon));
1185       break;
1186     case Anchor:
1187       item = new PixmapItem();
1188       item->setZValue(3);
1189       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding anchor";
1190       fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("cross.png"));
1191       if (fileName.isNull())
1192       {
1193         KMessageBox::error(nullptr, i18n("Cannot load anchor icon<br>Program cannot continue"), i18n("Error"));
1194         exit(2);
1195       }
1196       pix = QPixmap(fileName);
1197       pix = pix.scaled(16,16);
1198       ((PixmapItem*)item)->setPixmap(pix);
1199       point = country->anchorPoint() - QPointF(item->boundingRect().width()/2, item->boundingRect().height()/2);
1200       m_countryDefWidget->anchorx->setValue(point.x());
1201       m_countryDefWidget->anchory->setValue(point.y());
1202       m_onu->itemsMap().insert(item,qMakePair(country,Anchor));
1203       break;
1204     case Center:
1205       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding center";
1206       item = new TextItem();
1207       item->setZValue(2);
1208       ((TextItem*)item)->setFont(m_onu->foregroundFont());
1209       ((TextItem*)item)->setPlainText(country->name());
1210       point = country->centralPoint() - QPointF(item->boundingRect().width()/2, item->boundingRect().height()/2);
1211       qCDebug(KSIRKSKINEDITOR_LOG) << "Adding center" << country->centralPoint() << point;
1212       m_countryDefWidget->centerx->setValue(point.x());
1213       m_countryDefWidget->centery->setValue(point.y());
1214       m_onu->itemsMap().insert(item,qMakePair(country,Center));
1215       break;
1216     default: ;
1217   }
1218   if (item != nullptr && !point.isNull())
1219   {
1220     item->setPos(point);
1221     if (dynamic_cast<PixmapItem*>(item) != nullptr)
1222     {
1223       connect(dynamic_cast<PixmapItem*>(item),&PixmapItem::pressed,this, &MainWindow::slotItemPressed);
1224       connect(dynamic_cast<PixmapItem*>(item),&PixmapItem::placed,this, &MainWindow::slotItemPlaced);
1225     }
1226     else if (dynamic_cast<TextItem*>(item) != nullptr)
1227     {
1228       connect(dynamic_cast<TextItem*>(item),&TextItem::pressed,this, &MainWindow::slotItemPressed);
1229       connect(dynamic_cast<TextItem*>(item), &TextItem::placed,this, &MainWindow::slotItemPlaced);
1230     }
1231     m_mapScene->addItem(item);
1232     item->setFlag(QGraphicsItem::ItemIsMovable, true);
1233     item->setFlag(QGraphicsItem::ItemIsSelectable, true);
1234   }
1235 }
1236 
1237 void MainWindow::slotURLSelected(const QUrl &url)
1238 {
1239   qCDebug(KSIRKSKINEDITOR_LOG);
1240   if ( url.isLocalFile() )
1241   {
1242     QString path = url.path();
1243     openSkin(path);
1244   }
1245 }
1246 
1247 void MainWindow::slotSkinNameEdited()
1248 {
1249   if (m_onu == nullptr) return;
1250   m_onu->setName(m_skinDefWidget->skinNameLineEdit->text());
1251 }
1252 
1253 void MainWindow::slotSkinWidthEdited(int v)
1254 {
1255   if (m_onu == nullptr) return;
1256   m_onu->setWidth(v);
1257 
1258   QRectF rect = m_mapScene->sceneRect();
1259   rect.setWidth(v);
1260   m_mapScene->setSceneRect(rect);
1261 
1262   if (m_mapItem != nullptr)
1263   {
1264     QPixmap mapPixmap(m_onu->pixmapForId(QStringLiteral("map"), m_onu->width(), m_onu->height()));
1265     m_mapItem->setPixmap(mapPixmap);
1266   }
1267 }
1268 
1269 void MainWindow::slotSkinHeightEdited(int v)
1270 {
1271   if (m_onu == nullptr) return;
1272   m_onu->setHeight(v);
1273 
1274   QRectF rect = m_mapScene->sceneRect();
1275   rect.setHeight(v);
1276   m_mapScene->setSceneRect(rect);
1277   
1278   if (m_mapItem != nullptr)
1279   {
1280     QPixmap mapPixmap(m_onu->pixmapForId(QStringLiteral("map"), m_onu->width(), m_onu->height()));
1281     m_mapItem->setPixmap(mapPixmap);
1282   }
1283 }
1284 
1285 void MainWindow::slotSkinDescriptionEdited()
1286 {
1287   if (m_onu == nullptr) return;
1288   qCDebug(KSIRKSKINEDITOR_LOG) << m_skinDefWidget->descriptionTextEdit->toPlainText();
1289   m_onu->setDescription(m_skinDefWidget->descriptionTextEdit->toPlainText());
1290 }
1291 
1292 void MainWindow::slotSkinWidthDiffEdited()
1293 {
1294   if (m_onu == nullptr) return;
1295   qCDebug(KSIRKSKINEDITOR_LOG);
1296   bool ok = false;
1297   int wd = m_spritesDefWidget->widthDiffLineEdit->text().toInt(&ok);
1298   SkinSpritesData::changeable().intData(QStringLiteral("width-between-flag-and-fighter"), wd);
1299 }
1300 
1301 void MainWindow::slotNewCountry()
1302 {
1303   if (m_onu == nullptr) return;
1304   qCDebug(KSIRKSKINEDITOR_LOG);
1305   QString newCountryName = QInputDialog::getText(this, i18n("New country name"), i18n("Enter the name of the new country"));
1306   m_onu->createCountry(newCountryName);
1307   m_skinDefWidget->countrieslist->addItem(newCountryName);
1308 }
1309 
1310 void MainWindow::slotDeleteCountry()
1311 {
1312   if (m_onu == nullptr) return;
1313   if (!m_skinDefWidget->countrieslist->currentItem()) return;
1314   qCDebug(KSIRKSKINEDITOR_LOG);
1315   int answer = KMessageBox::warningContinueCancel(this, i18n("Do you really want to delete country '%1'?", m_skinDefWidget->countrieslist->currentItem()->text()), i18n("Really delete country?"));
1316   if (answer == KMessageBox::Cancel)
1317   {
1318     return;
1319   }
1320 
1321   int row = m_skinDefWidget->countrieslist->row(m_skinDefWidget->countrieslist->currentItem());
1322   QListWidgetItem* item = m_skinDefWidget->countrieslist->takeItem(row);
1323 
1324   Country* country = m_onu->countryNamed(item->text());
1325   m_onu->deleteCountry(country);
1326   
1327   delete item;
1328 }
1329 
1330 void MainWindow::slotNewContinent()
1331 {
1332   if (m_onu == nullptr) return;
1333   qCDebug(KSIRKSKINEDITOR_LOG);
1334   QString newContinentName = QInputDialog::getText(this, i18n("New continent name"), i18n("Enter the name of the new continent"));
1335   m_onu->createContinent(newContinentName);
1336   m_skinDefWidget->continentslist->addItem(newContinentName);
1337 }
1338 
1339 void MainWindow::slotDeleteContinent()
1340 {
1341   if (m_onu == nullptr) return;
1342   if (!m_skinDefWidget->continentslist->currentItem()) return;
1343   qCDebug(KSIRKSKINEDITOR_LOG);
1344   int answer = KMessageBox::warningContinueCancel(this, i18n("Do you really want to delete continent '%1'?", m_skinDefWidget->continentslist->currentItem()->text()), i18n("Really delete continent?"));
1345   if (answer == KMessageBox::Cancel)
1346   {
1347     return;
1348   }
1349   
1350   int row = m_skinDefWidget->continentslist->row(m_skinDefWidget->continentslist->currentItem());
1351   QListWidgetItem* item = m_skinDefWidget->continentslist->takeItem(row);
1352   
1353   Continent* continent = m_onu->continentNamed(item->text());
1354   m_onu->deleteContinent(continent);
1355   
1356   delete item;
1357 }
1358 
1359 void MainWindow::slotNeighbours()
1360 {
1361   if (m_onu == nullptr) return;
1362   qCDebug(KSIRKSKINEDITOR_LOG);
1363   if (m_skinDefWidget->countrieslist->currentItem() == nullptr)
1364   {
1365     return;
1366   }
1367 
1368   KsirkSkinEditorCountriesSelectionDialog* dialog = new KsirkSkinEditorCountriesSelectionDialog(this);
1369   dialog->countriesList->setSortingEnabled(true);
1370   dialog->countriesList->setSelectionMode(QAbstractItemView::ExtendedSelection);
1371   foreach (Country* country, m_onu->countries())
1372   {
1373     if (country->name() != m_skinDefWidget->countrieslist->currentItem()->text())
1374     {
1375       dialog->countriesList->addItem(country->name());
1376     }
1377   }
1378   foreach (Country* country, m_onu->countryNamed(m_skinDefWidget->countrieslist->currentItem()->text())->neighbours())
1379   {
1380     QList<QListWidgetItem *> list = dialog->countriesList->findItems(country->name(),Qt::MatchExactly);
1381     foreach (QListWidgetItem* item, list)
1382     {
1383       dialog->countriesList->setCurrentItem(item,QItemSelectionModel::Select);
1384     }
1385   }
1386   if (dialog->exec())
1387   {
1388     QList<QListWidgetItem *> list = dialog->countriesList->selectedItems();
1389     Country* country =  m_onu->countryNamed(m_skinDefWidget->countrieslist->currentItem()->text());
1390     QList<Country*> newNeighbours;
1391     m_countryDefWidget->neighbourslist->clear();
1392     foreach (QListWidgetItem* item, list)
1393     {
1394       Country* neighbour = m_onu->countryNamed(item->text());
1395       newNeighbours.push_back(neighbour);
1396       m_countryDefWidget->neighbourslist->addItem(neighbour->name());
1397     }
1398     country->neighbours() = newNeighbours;
1399   }
1400   delete dialog;
1401 }
1402 
1403 void MainWindow::slotSkinPartTabChanged(int index)
1404 {
1405   qCDebug(KSIRKSKINEDITOR_LOG);
1406 
1407   switch (index)
1408   {
1409     case 0:
1410       m_spritesDefWidget->show();
1411       m_nationalityDefWidget->hide();
1412       m_countryDefWidget->hide();
1413       m_continentDefWidget->hide();
1414       m_goalDefWidget->hide();
1415       break;
1416     case 1:
1417       m_spritesDefWidget->hide();
1418       m_nationalityDefWidget->show();
1419       m_countryDefWidget->hide();
1420       m_continentDefWidget->hide();
1421       m_goalDefWidget->hide();
1422       break;
1423     case 2:
1424       m_spritesDefWidget->hide();
1425       m_nationalityDefWidget->hide();
1426       m_countryDefWidget->show();
1427       m_continentDefWidget->hide();
1428       m_goalDefWidget->hide();
1429       break;
1430     case 3:
1431       m_spritesDefWidget->hide();
1432       m_nationalityDefWidget->hide();
1433       m_countryDefWidget->hide();
1434       m_continentDefWidget->show();
1435       m_goalDefWidget->hide();
1436       break;
1437     case 4:
1438       m_spritesDefWidget->hide();
1439       m_nationalityDefWidget->hide();
1440       m_countryDefWidget->hide();
1441       m_continentDefWidget->hide();
1442       m_goalDefWidget->show();
1443       break;
1444     default:
1445       m_countryDefWidget->hide();
1446       m_nationalityDefWidget->hide();
1447       m_continentDefWidget->hide();
1448       m_goalDefWidget->hide();
1449       m_spritesDefWidget->hide();
1450   }
1451 }
1452 
1453 void MainWindow::slotContinentCountries()
1454 {
1455   if (m_onu == nullptr) return;
1456   qCDebug(KSIRKSKINEDITOR_LOG);
1457   if (m_skinDefWidget->continentslist->currentItem() == nullptr)
1458   {
1459     return;
1460   }
1461   
1462   KsirkSkinEditorCountriesSelectionDialog* dialog = new KsirkSkinEditorCountriesSelectionDialog(this);
1463   dialog->countriesList->setSortingEnabled(true);
1464   dialog->countriesList->setSelectionMode(QAbstractItemView::ExtendedSelection);
1465   foreach (Country* country, m_onu->countries())
1466   {
1467     dialog->countriesList->addItem(country->name());
1468   }
1469   foreach (Country* country, m_onu->continentNamed(m_skinDefWidget->continentslist->currentItem()->text())->members())
1470   {
1471     QList<QListWidgetItem*> list = dialog->countriesList->findItems(country->name(),Qt::MatchExactly);
1472     foreach (QListWidgetItem* item, list)
1473     {
1474       dialog->countriesList->setCurrentItem(item,QItemSelectionModel::Select);
1475     }
1476   }
1477   if (dialog->exec())
1478   {
1479     QList<QListWidgetItem *> list = dialog->countriesList->selectedItems();
1480     qCDebug(KSIRKSKINEDITOR_LOG) << list.size();
1481     Continent* continent =  m_onu->continentNamed(m_skinDefWidget->continentslist->currentItem()->text());
1482     qCDebug(KSIRKSKINEDITOR_LOG) << (void*)continent;
1483     qCDebug(KSIRKSKINEDITOR_LOG) << continent->name();
1484     QList<Country*> newCountries;
1485     m_continentDefWidget->countrieslist->clear();
1486     foreach (QListWidgetItem* item, list)
1487     {
1488       Country* country = m_onu->countryNamed(item->text());
1489       qCDebug(KSIRKSKINEDITOR_LOG) << (void*)country;
1490       qCDebug(KSIRKSKINEDITOR_LOG) << country->name();
1491       newCountries.push_back(country);
1492       m_continentDefWidget->countrieslist->addItem(country->name());
1493     }
1494     qCDebug(KSIRKSKINEDITOR_LOG) << "set members";
1495     continent->members() = newCountries;
1496   }
1497   delete dialog;
1498 }
1499 
1500 void MainWindow::slotContinentBonusEdited(int v)
1501 {
1502   qCDebug(KSIRKSKINEDITOR_LOG);
1503   if (m_onu == nullptr || m_skinDefWidget->continentslist->currentItem() == nullptr) return;
1504   Continent* continent =  m_onu->continentNamed(m_skinDefWidget->continentslist->currentItem()->text());
1505   continent->setBonus(v);
1506   m_onu->setDirty();
1507 }
1508 
1509 void MainWindow::slotFlagWidthChanged(int v)
1510 {
1511   qCDebug(KSIRKSKINEDITOR_LOG);
1512   SkinSpritesData::changeable().intData(QStringLiteral("flag-width"), v);
1513   updateSprites(Flag);
1514 }
1515 
1516 void MainWindow::slotFlagHeightChanged(int v)
1517 {
1518   qCDebug(KSIRKSKINEDITOR_LOG);
1519   SkinSpritesData::changeable().intData(QStringLiteral("flag-height"), v);
1520   updateSprites(Flag);
1521 }
1522 
1523 void MainWindow::slotFlagFramesChanged(int v)
1524 {
1525   qCDebug(KSIRKSKINEDITOR_LOG);
1526   SkinSpritesData::changeable().intData(QStringLiteral("flag-frames"), v);
1527   updateSprites(Flag);
1528 }
1529 
1530 void MainWindow::slotFlagVersionsChanged(int v)
1531 {
1532   qCDebug(KSIRKSKINEDITOR_LOG);
1533   SkinSpritesData::changeable().intData(QStringLiteral("flag-versions"), v);
1534   updateSprites(Flag);
1535 }
1536 
1537 
1538 void MainWindow::slotInfantryWidthChanged(int v)
1539 {
1540   qCDebug(KSIRKSKINEDITOR_LOG);
1541   SkinSpritesData::changeable().intData(QStringLiteral("infantry-width"), v);
1542   updateSprites(Infantry);
1543 }
1544 
1545 void MainWindow::slotInfantryHeightChanged(int v)
1546 {
1547   qCDebug(KSIRKSKINEDITOR_LOG);
1548   SkinSpritesData::changeable().intData(QStringLiteral("infantry-height"), v);
1549   updateSprites(Infantry);
1550 }
1551 
1552 void MainWindow::slotInfantryFramesChanged(int v)
1553 {
1554   qCDebug(KSIRKSKINEDITOR_LOG);
1555   SkinSpritesData::changeable().intData(QStringLiteral("infantry-frames"), v);
1556   updateSprites(Infantry);
1557 }
1558 
1559 void MainWindow::slotInfantryVersionsChanged(int v)
1560 {
1561   qCDebug(KSIRKSKINEDITOR_LOG);
1562   SkinSpritesData::changeable().intData(QStringLiteral("infantry-versions"), v);
1563   updateSprites(Infantry);
1564 }
1565 
1566 
1567 void MainWindow::slotCavalryWidthChanged(int v)
1568 {
1569   qCDebug(KSIRKSKINEDITOR_LOG);
1570   SkinSpritesData::changeable().intData(QStringLiteral("cavalry-width"), v);
1571   updateSprites(Cavalry);
1572 }
1573 
1574 void MainWindow::slotCavalryHeightChanged(int v)
1575 {
1576   qCDebug(KSIRKSKINEDITOR_LOG);
1577   SkinSpritesData::changeable().intData(QStringLiteral("cavalry-height"), v);
1578   updateSprites(Cavalry);
1579 }
1580 
1581 void MainWindow::slotCavalryFramesChanged(int v)
1582 {
1583   qCDebug(KSIRKSKINEDITOR_LOG);
1584   SkinSpritesData::changeable().intData(QStringLiteral("cavalry-frames"), v);
1585   updateSprites(Cavalry);
1586 }
1587 
1588 void MainWindow::slotCavalryVersionsChanged(int v)
1589 {
1590   qCDebug(KSIRKSKINEDITOR_LOG);
1591   SkinSpritesData::changeable().intData(QStringLiteral("cavalry-versions"), v);
1592   updateSprites(Cavalry);
1593 }
1594 
1595 
1596 void MainWindow::slotCannonWidthChanged(int v)
1597 {
1598   qCDebug(KSIRKSKINEDITOR_LOG);
1599   SkinSpritesData::changeable().intData(QStringLiteral("cannon-width"), v);
1600   updateSprites(Cannon);
1601 }
1602 
1603 void MainWindow::slotCannonHeightChanged(int v)
1604 {
1605   qCDebug(KSIRKSKINEDITOR_LOG);
1606   SkinSpritesData::changeable().intData(QStringLiteral("cannon-height"), v);
1607   updateSprites(Cannon);
1608 }
1609 
1610 void MainWindow::slotCannonFramesChanged(int v)
1611 {
1612   qCDebug(KSIRKSKINEDITOR_LOG);
1613   SkinSpritesData::changeable().intData(QStringLiteral("cannon-frames"), v);
1614   updateSprites(Cannon);
1615 }
1616 
1617 void MainWindow::slotCannonVersionsChanged(int v)
1618 {
1619   qCDebug(KSIRKSKINEDITOR_LOG);
1620   SkinSpritesData::changeable().intData(QStringLiteral("cannon-versions"), v);
1621   updateSprites(Cannon);
1622 }
1623 
1624 void MainWindow::slotFiringWidthChanged(int v)
1625 {
1626   qCDebug(KSIRKSKINEDITOR_LOG);
1627   SkinSpritesData::changeable().intData(QStringLiteral("firing-width"), v);
1628 }
1629 
1630 void MainWindow::slotFiringHeightChanged(int v)
1631 {
1632   qCDebug(KSIRKSKINEDITOR_LOG);
1633   SkinSpritesData::changeable().intData(QStringLiteral("firing-height"), v);
1634 }
1635 
1636 void MainWindow::slotFiringFramesChanged(int v)
1637 {
1638   qCDebug(KSIRKSKINEDITOR_LOG);
1639   SkinSpritesData::changeable().intData(QStringLiteral("firing-frames"), v);
1640 }
1641 
1642 void MainWindow::slotFiringVersionsChanged(int v)
1643 {
1644   qCDebug(KSIRKSKINEDITOR_LOG);
1645   SkinSpritesData::changeable().intData(QStringLiteral("firing-versions"), v);
1646 }
1647 
1648 void MainWindow::slotExplodingWidthChanged(int v)
1649 {
1650   qCDebug(KSIRKSKINEDITOR_LOG);
1651   SkinSpritesData::changeable().intData(QStringLiteral("exploding-width"), v);
1652 }
1653 
1654 void MainWindow::slotExplodingHeightChanged(int v)
1655 {
1656   qCDebug(KSIRKSKINEDITOR_LOG);
1657   SkinSpritesData::changeable().intData(QStringLiteral("exploding-height"), v);
1658 }
1659 
1660 void MainWindow::slotExplodingFramesChanged(int v)
1661 {
1662   qCDebug(KSIRKSKINEDITOR_LOG);
1663   SkinSpritesData::changeable().intData(QStringLiteral("exploding-frames"), v);
1664 }
1665 
1666 void MainWindow::slotExplodingVersionsChanged(int v)
1667 {
1668   qCDebug(KSIRKSKINEDITOR_LOG);
1669   SkinSpritesData::changeable().intData(QStringLiteral("exploding-versions"), v);
1670 }
1671 
1672 void MainWindow::updateSprites(SpriteType type)
1673 {
1674   qCDebug(KSIRKSKINEDITOR_LOG) << type;
1675   QPixmap pix;
1676   QPixmap alphacopy;
1677   QPointF point;
1678   QString fileName;
1679 
1680   m_onu->updateIcon(type);
1681   switch (type)
1682   {
1683     case Flag:
1684       m_flagButton->setIcon(m_onu->flagIcon());
1685       break;
1686     case Infantry:
1687       m_infantryButton->setIcon(m_onu->infantryIcon());
1688       break;
1689     case Cavalry:
1690       m_cavalryButton->setIcon(m_onu->cavalryIcon());
1691       break;
1692     case Cannon:
1693       m_cannonButton->setIcon(m_onu->cannonIcon());
1694       break;
1695     default: ;
1696   }
1697   foreach (Country* country, m_onu->countries())
1698   {
1699     QGraphicsItem* item = m_onu->itemFor(country, type);
1700     if (item == nullptr)
1701     {
1702       qCCritical(KSIRKSKINEDITOR_LOG) << "item " << type << "not found for" << country->name();
1703       continue;
1704     }
1705     switch (type)
1706     {
1707       case Flag:
1708         pix = m_onu->flagIcon();
1709         ((PixmapItem*)item)->setPixmap(pix);
1710         break;
1711       case Infantry:
1712         pix = m_onu->infantryIcon();
1713         ((PixmapItem*)item)->setPixmap(pix);
1714         break;
1715       case Cavalry:
1716         pix = m_onu->cavalryIcon();
1717         ((PixmapItem*)item)->setPixmap(pix);
1718         break;
1719       case Cannon:
1720         pix = m_onu->cannonIcon();
1721         ((PixmapItem*)item)->setPixmap(pix);
1722         break;
1723       case Anchor:
1724         ((TextItem*)item)->setFont(m_onu->foregroundFont());
1725         break;
1726       default: ;
1727     }
1728   }
1729 }
1730 
1731 void MainWindow::slotGoalTypeWorldClicked()
1732 {
1733   if (m_onu == nullptr) return;
1734   qCDebug(KSIRKSKINEDITOR_LOG);
1735   if (m_skinDefWidget->goalslist->currentItem() == nullptr)
1736   {
1737     return;
1738   }
1739   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1740   Goal* goal = m_onu->goals()[row];
1741   goal->setType(Goal::NoGoal);
1742 }
1743 
1744 void MainWindow::slotGoalTypePlayerClicked()
1745 {
1746   if (m_onu == nullptr) return;
1747   qCDebug(KSIRKSKINEDITOR_LOG);
1748   if (m_skinDefWidget->goalslist->currentItem() == nullptr)
1749   {
1750     return;
1751   }
1752   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1753   Goal* goal = m_onu->goals()[row];
1754   goal->setType(Goal::GoalPlayer);
1755 }
1756 
1757 void MainWindow::slotGoalTypeCountriesClicked()
1758 {
1759   if (m_onu == nullptr) return;
1760   qCDebug(KSIRKSKINEDITOR_LOG);
1761   if (m_skinDefWidget->goalslist->currentItem() == nullptr)
1762   {
1763     return;
1764   }
1765   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1766   Goal* goal = m_onu->goals()[row];
1767   goal->setType(Goal::Countries);
1768 }
1769 
1770 void MainWindow::slotGoalTypeContinentsClicked()
1771 {
1772   if (m_onu == nullptr) return;
1773   qCDebug(KSIRKSKINEDITOR_LOG);
1774   if (m_skinDefWidget->goalslist->currentItem() == nullptr)
1775   {
1776     return;
1777   }
1778   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1779   Goal* goal = m_onu->goals()[row];
1780   goal->setType(Goal::Continents);
1781 }
1782 
1783 void MainWindow::slotGoalDescriptionEdited()
1784 {
1785   if (m_onu == nullptr || m_skinDefWidget->goalslist->currentItem() == nullptr) return;
1786   qCDebug(KSIRKSKINEDITOR_LOG);
1787   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1788   Goal* goal = m_onu->goals()[row];
1789   goal->setDescription(m_goalDefWidget->description->toPlainText());
1790 }
1791 
1792 void MainWindow::slotGoalNbCountriesChanged(int)
1793 {
1794   if (m_onu == nullptr || m_skinDefWidget->goalslist->currentItem() == nullptr) return;
1795   qCDebug(KSIRKSKINEDITOR_LOG);
1796   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1797   Goal* goal = m_onu->goals()[row];
1798   goal->setNbCountries(m_goalDefWidget->nbcountries->value());
1799 }
1800 
1801 void MainWindow::slotGoalNbArmiesByCountryChanged(int)
1802 {
1803   if (m_onu == nullptr || m_skinDefWidget->goalslist->currentItem() == nullptr) return;
1804   qCDebug(KSIRKSKINEDITOR_LOG);
1805   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1806   Goal* goal = m_onu->goals()[row];
1807   goal->setNbArmiesByCountry(m_goalDefWidget->armiesbycountry->value());
1808 }
1809 
1810 void MainWindow::slotGoalAnyContinentChanged(int state)
1811 {
1812   if (m_onu == nullptr || m_skinDefWidget->goalslist->currentItem() == nullptr) return;
1813   qCDebug(KSIRKSKINEDITOR_LOG);
1814   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1815   Goal* goal = m_onu->goals()[row];
1816   switch (state)
1817   {
1818     case Qt::Unchecked:
1819       goal->continents().removeAll(QString());
1820       break;
1821     case Qt::Checked:
1822       if (!goal->continents().contains(QString()))
1823       {
1824         goal->continents().push_back(QString());
1825       }
1826       break;
1827     default:;
1828   }
1829   goal->setNbArmiesByCountry(m_goalDefWidget->armiesbycountry->value());
1830 }
1831 
1832 void MainWindow::slotGoalContinents()
1833 {
1834   if (m_onu == nullptr) return;
1835   qCDebug(KSIRKSKINEDITOR_LOG);
1836   if (m_skinDefWidget->goalslist->currentItem() == nullptr)
1837   {
1838     return;
1839   }
1840 
1841   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1842   Goal* goal = m_onu->goals()[row];
1843 
1844   KsirkSkinEditorCountriesSelectionDialog* dialog = new KsirkSkinEditorCountriesSelectionDialog(this);
1845   dialog->countriesList->setSortingEnabled(true);
1846   dialog->countriesList->setSelectionMode(QAbstractItemView::ExtendedSelection);
1847   foreach (Continent* continent, m_onu->continents())
1848   {
1849     dialog->countriesList->addItem(continent->name());
1850   }
1851   foreach (const QString& continentName, goal->continents())
1852   {
1853     QList<QListWidgetItem*> list = dialog->countriesList->findItems(continentName,Qt::MatchExactly);
1854     foreach (QListWidgetItem* item, list)
1855     {
1856       dialog->countriesList->setCurrentItem(item,QItemSelectionModel::Select);
1857     }
1858   }
1859   if (dialog->exec())
1860   {
1861     QList<QListWidgetItem *> list = dialog->countriesList->selectedItems();
1862     qCDebug(KSIRKSKINEDITOR_LOG) << list.size();
1863     QList<QString> newContinents;
1864     m_goalDefWidget->continentslist->clear();
1865     foreach (QListWidgetItem* item, list)
1866     {
1867       Continent* continent = m_onu->continentNamed(item->text());
1868       qCDebug(KSIRKSKINEDITOR_LOG) << (void*)continent;
1869       qCDebug(KSIRKSKINEDITOR_LOG) << continent->name();
1870       newContinents.push_back(continent->name());
1871       m_goalDefWidget->continentslist->addItem(continent->name());
1872     }
1873     qCDebug(KSIRKSKINEDITOR_LOG) << "set members";
1874     goal->continents() = newContinents;
1875   }
1876   delete dialog;
1877 }
1878 
1879 void MainWindow::slotNewGoal()
1880 {
1881   if (m_onu == nullptr) return;
1882   qCDebug(KSIRKSKINEDITOR_LOG);
1883   QString newGoalName = QStringLiteral("goal") + QString::number(m_skinDefWidget->goalslist->count()+1);
1884   m_onu->createGoal();
1885   m_skinDefWidget->goalslist->addItem(newGoalName);
1886 }
1887 
1888 void MainWindow::slotDeleteGoal()
1889 {
1890   if (m_onu == nullptr) return;
1891   if (!m_skinDefWidget->goalslist->currentItem()) return;
1892   qCDebug(KSIRKSKINEDITOR_LOG);
1893   int answer = KMessageBox::warningContinueCancel(this, i18n("Do you really want to delete goal '%1'?", m_skinDefWidget->goalslist->currentItem()->text()), i18n("Really delete goal?"));
1894   if (answer == KMessageBox::Cancel)
1895   {
1896     return;
1897   }
1898   
1899   int row = m_skinDefWidget->goalslist->row(m_skinDefWidget->goalslist->currentItem());
1900   qCDebug(KSIRKSKINEDITOR_LOG) << "row=" << row;
1901   QListWidgetItem* item = m_skinDefWidget->goalslist->takeItem(m_skinDefWidget->goalslist->count()-1);
1902   qCDebug(KSIRKSKINEDITOR_LOG) << "item=" << item;
1903   
1904   m_onu->deleteGoal(row);
1905   qCDebug(KSIRKSKINEDITOR_LOG) << "goal deleted";
1906   
1907   delete item;
1908 }
1909 
1910 void MainWindow::slotNationalityNameEdited()
1911 {
1912   if (m_onu == nullptr || m_skinDefWidget->nationalitieslist->currentItem() ==nullptr) return;
1913   qCDebug(KSIRKSKINEDITOR_LOG) << m_skinDefWidget->nationalitieslist->currentItem()->text();
1914   Nationality* nationality =  m_onu->nationalityNamed(m_skinDefWidget->nationalitieslist->currentItem()->text());
1915   nationality->setName(m_nationalityDefWidget->name->text());
1916   m_skinDefWidget->nationalitieslist->currentItem()->setText(m_nationalityDefWidget->name->text());
1917 }
1918 
1919 void MainWindow::slotNationalityLeaderNameEdited()
1920 {
1921   if (m_onu == nullptr || m_skinDefWidget->nationalitieslist->currentItem() ==nullptr) return;
1922   qCDebug(KSIRKSKINEDITOR_LOG) << m_skinDefWidget->nationalitieslist->currentItem()->text();
1923   qCDebug(KSIRKSKINEDITOR_LOG) << m_nationalityDefWidget->leader->text();
1924   Nationality* nationality =  m_onu->nationalityNamed(m_skinDefWidget->nationalitieslist->currentItem()->text());
1925   qCDebug(KSIRKSKINEDITOR_LOG) << nationality;
1926   nationality->setLeaderName(m_nationalityDefWidget->leader->text());
1927 }
1928 
1929 void MainWindow::slotNationalityFlagEdited(int)
1930 {
1931   if (m_onu == nullptr || m_skinDefWidget->nationalitieslist->currentItem() ==nullptr) return;
1932   qCDebug(KSIRKSKINEDITOR_LOG) << m_skinDefWidget->nationalitieslist->currentItem()->text();
1933   Nationality* nationality =  m_onu->nationalityNamed(m_skinDefWidget->nationalitieslist->currentItem()->text());
1934   QString previousFlagFileName = nationality->flagFileName();
1935   if (previousFlagFileName == m_nationalityDefWidget->flag->currentText())
1936   {
1937     return;
1938   }
1939   nationality->setFlagFileName(m_nationalityDefWidget->flag->currentText());
1940   m_onu->setDirty();
1941   
1942   if (previousFlagFileName.isEmpty() && !nationality->flagFileName().isEmpty())
1943   {
1944     updateSprites(Flag);
1945   }
1946 }
1947 
1948 void MainWindow::slotNewNationality()
1949 {
1950   if (m_onu == nullptr) return;
1951   qCDebug(KSIRKSKINEDITOR_LOG);
1952   QString newNationalityName = QInputDialog::getText(this, i18n("New nationality name"), i18n("Enter the name of the new nationality"));
1953   m_onu->createNationality(newNationalityName);
1954   m_skinDefWidget->nationalitieslist->addItem(newNationalityName);
1955 }
1956 
1957 void MainWindow::slotDeleteNationality()
1958 {
1959   if (m_onu == nullptr) return;
1960   if (!m_skinDefWidget->nationalitieslist->currentItem()) return;
1961   qCDebug(KSIRKSKINEDITOR_LOG);
1962   int answer = KMessageBox::warningContinueCancel(this, i18n("Do you really want to delete nationality '%1'?", m_skinDefWidget->nationalitieslist->currentItem()->text()), i18n("Really delete nationality?"));
1963   if (answer == KMessageBox::Cancel)
1964   {
1965     return;
1966   }
1967   
1968   int row = m_skinDefWidget->nationalitieslist->row(m_skinDefWidget->nationalitieslist->currentItem());
1969   QListWidgetItem* item = m_skinDefWidget->nationalitieslist->takeItem(row);
1970   
1971   Nationality* nationality = m_onu->nationalityNamed(item->text());
1972   m_onu->deleteNationality(nationality);
1973   
1974   delete item;
1975 }
1976 
1977 void MainWindow::slotFontSelected(const QFont &font)
1978 {
1979   if (m_onu == nullptr) return;
1980   qCDebug(KSIRKSKINEDITOR_LOG);
1981   m_onu->setFont(font);
1982   updateSprites(Anchor);
1983 }
1984 
1985 void MainWindow::slotFgSelected(const QColor& color)
1986 {
1987   if (m_onu == nullptr) return;
1988   qCDebug(KSIRKSKINEDITOR_LOG);
1989   m_onu->setFontFgColor(color);
1990   updateSprites(Anchor);
1991 }
1992 
1993 void MainWindow::slotBgColorSelected(const QColor& color)
1994 {
1995   if (m_onu == nullptr) return;
1996   qCDebug(KSIRKSKINEDITOR_LOG);
1997   m_onu->setFontBgColor(color);
1998   updateSprites(Anchor);
1999 }
2000 
2001 void MainWindow::initSpritesButtonsWith(const Country* country)
2002 {
2003   m_flagButton->setEnabled(m_onu->itemFor(country, Flag) == nullptr);
2004   m_infantryButton->setEnabled(m_onu->itemFor(country, Infantry) == nullptr);
2005   m_cavalryButton->setEnabled(m_onu->itemFor(country, Cavalry) == nullptr);
2006   m_cannonButton->setEnabled(m_onu->itemFor(country, Cannon) == nullptr);
2007   m_anchorButton->setEnabled(m_onu->itemFor(country, Anchor) == nullptr);
2008   m_centerButton->setEnabled(m_onu->itemFor(country, Center) == nullptr);
2009 }
2010 
2011 void MainWindow::slotFLagxValueChanged(int v)
2012 {
2013   qCDebug(KSIRKSKINEDITOR_LOG);
2014   if (currentCountry() != nullptr)
2015   {
2016     currentCountry()->pointFlag(QPointF(v,currentCountry()->pointFlag().y()));
2017     if (m_onu->itemFor(currentCountry(), Flag) != nullptr)
2018       m_onu->itemFor(currentCountry(), Flag)->setPos(currentCountry()->pointFlag());
2019     m_onu->setDirty();
2020   }
2021 }
2022 
2023 void MainWindow::slotFLagyValueChanged(int v)
2024 {
2025   qCDebug(KSIRKSKINEDITOR_LOG);
2026   if (currentCountry() != nullptr)
2027   {
2028     currentCountry()->pointFlag(QPointF(currentCountry()->pointFlag().x(),v));
2029     if (m_onu->itemFor(currentCountry(), Flag) != nullptr)
2030       m_onu->itemFor(currentCountry(), Flag)->setPos(currentCountry()->pointFlag());
2031     m_onu->setDirty();
2032   }
2033 }
2034 
2035 void MainWindow::slotCenterxValueChanged(int v)
2036 {
2037   qCDebug(KSIRKSKINEDITOR_LOG);
2038   if (currentCountry() != nullptr)
2039   {
2040     currentCountry()->centralPoint(QPointF(v,currentCountry()->centralPoint().y()));
2041     if (m_onu->itemFor(currentCountry(), Center) != nullptr)
2042       m_onu->itemFor(currentCountry(), Center)->setPos(currentCountry()->centralPoint());
2043     m_onu->setDirty();
2044   }
2045 }
2046 
2047 void MainWindow::slotCenteryValueChanged(int v)
2048 {
2049   qCDebug(KSIRKSKINEDITOR_LOG);
2050   if (currentCountry() != nullptr)
2051   {
2052     currentCountry()->centralPoint(QPointF(currentCountry()->centralPoint().x(),v));
2053     if (m_onu->itemFor(currentCountry(), Center) != nullptr)
2054       m_onu->itemFor(currentCountry(), Center)->setPos(currentCountry()->centralPoint());
2055     m_onu->setDirty();
2056   }
2057 }
2058 
2059 void MainWindow::slotAnchorxValueChanged(int v)
2060 {
2061   qCDebug(KSIRKSKINEDITOR_LOG);
2062   if (currentCountry() != nullptr)
2063   {
2064     currentCountry()->anchorPoint(QPointF(v,currentCountry()->anchorPoint().y()));
2065     if (m_onu->itemFor(currentCountry(), Anchor) != nullptr)
2066       m_onu->itemFor(currentCountry(), Anchor)->setPos(currentCountry()->anchorPoint());
2067     m_onu->setDirty();
2068   }
2069 }
2070 
2071 void MainWindow::slotAnchoryValueChanged(int v)
2072 {
2073   qCDebug(KSIRKSKINEDITOR_LOG);
2074   if (currentCountry() != nullptr)
2075   {
2076     currentCountry()->anchorPoint(QPointF(currentCountry()->anchorPoint().x(),v));
2077     if (m_onu->itemFor(currentCountry(), Anchor) != nullptr)
2078       m_onu->itemFor(currentCountry(), Anchor)->setPos(currentCountry()->anchorPoint());
2079     m_onu->setDirty();
2080   }
2081 }
2082 
2083 void MainWindow::slotInfantryxValueChanged(int v)
2084 {
2085   qCDebug(KSIRKSKINEDITOR_LOG);
2086   if (currentCountry() != nullptr)
2087   {
2088     currentCountry()->pointInfantry(QPointF(v,currentCountry()->pointInfantry().y()));
2089     if (m_onu->itemFor(currentCountry(), Infantry) != nullptr)
2090       m_onu->itemFor(currentCountry(), Infantry)->setPos(currentCountry()->pointInfantry());
2091     m_onu->setDirty();
2092   }
2093 }
2094 
2095 void MainWindow::slotInfantryyValueChanged(int v)
2096 {
2097   qCDebug(KSIRKSKINEDITOR_LOG);
2098   if (currentCountry() != nullptr)
2099   {
2100     currentCountry()->pointInfantry(QPointF(currentCountry()->pointInfantry().x(),v));
2101     if (m_onu->itemFor(currentCountry(), Infantry) != nullptr)
2102       m_onu->itemFor(currentCountry(), Infantry)->setPos(currentCountry()->pointInfantry());
2103     m_onu->setDirty();
2104   }
2105 }
2106 
2107 void MainWindow::slotCavalryxValueChanged(int v)
2108 {
2109   qCDebug(KSIRKSKINEDITOR_LOG);
2110   if (currentCountry() != nullptr)
2111   {
2112     currentCountry()->pointCavalry(QPointF(v,currentCountry()->pointCavalry().y()));
2113     if (m_onu->itemFor(currentCountry(), Cavalry) != nullptr)
2114       m_onu->itemFor(currentCountry(), Cavalry)->setPos(currentCountry()->pointCavalry());
2115     m_onu->setDirty();
2116   }
2117 }
2118 void MainWindow::slotCavalryyValueChanged(int v)
2119 {
2120   qCDebug(KSIRKSKINEDITOR_LOG);
2121   if (currentCountry() != nullptr)
2122   {
2123     currentCountry()->pointCavalry(QPointF(currentCountry()->pointCavalry().x(),v));
2124     if (m_onu->itemFor(currentCountry(), Cavalry) != nullptr)
2125       m_onu->itemFor(currentCountry(), Cavalry)->setPos(currentCountry()->pointCavalry());
2126     m_onu->setDirty();
2127   }
2128 }
2129 
2130 void MainWindow::slotCannonxValueChanged(int v)
2131 {
2132   qCDebug(KSIRKSKINEDITOR_LOG);
2133   if (currentCountry() != nullptr)
2134   {
2135     currentCountry()->pointCannon(QPointF(v,currentCountry()->pointCannon().y()));
2136     if (m_onu->itemFor(currentCountry(), Cannon) != nullptr)
2137       m_onu->itemFor(currentCountry(), Cannon)->setPos(currentCountry()->pointCannon());
2138     m_onu->setDirty();
2139   }
2140 }
2141 
2142 void MainWindow::slotCannonyValueChanged(int v)
2143 {
2144   qCDebug(KSIRKSKINEDITOR_LOG);
2145   if (currentCountry() != nullptr)
2146   {
2147     currentCountry()->pointCannon(QPointF(currentCountry()->pointCannon().x(),v));
2148     if (m_onu->itemFor(currentCountry(), Cannon) != nullptr)
2149       m_onu->itemFor(currentCountry(), Cannon)->setPos(currentCountry()->pointCannon());
2150     m_onu->setDirty();
2151   }
2152 }
2153 
2154 
2155 } // closing namespace
2156 
2157 #include "moc_mainwindow.cpp"