File indexing completed on 2024-04-28 04:02:52

0001 /***************************************************************************
0002                           dlgmappathproperties.cpp  -  description
0003                              -------------------
0004     begin                : Thu Mar 8 2001
0005     copyright            : (C) 2001 by KMud Development Team
0006     email                : kmud-devel@kmud.de
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "dlgmappathproperties.h"
0019 
0020 #include <qlineedit.h>
0021 #include <qradiobutton.h>
0022 #include <qpushbutton.h>
0023 #include <qlabel.h>
0024 #include <qtabwidget.h>
0025 #include <QLocale>
0026 #include <QDebug>
0027 
0028 #include "../cmapmanager.h"
0029 #include "../cmapcmdelementcreate.h"
0030 #include "../cmapcmdelementdelete.h"
0031 #include "../cmapcmdelementproperties.h"
0032 #include "../cmapcmdgroup.h"
0033 #include "../cmappath.h"
0034 #include "../cmappluginbase.h"
0035 #include "../cmappropertiespanebase.h"
0036 
0037 #include <KLocalizedString>
0038 
0039 DlgMapPathProperties::DlgMapPathProperties(CMapManager *manager,KConfigGroup pathProperties,bool undoable,QWidget *parent)
0040     : QDialog(parent)
0041 {
0042   setupUi (this);
0043   connect(this, SIGNAL(accepted()), this, SLOT(slotAccept()));
0044 
0045     useProperties = true;
0046     properties = pathProperties;
0047     pathUndoable = undoable;
0048     mapManager = manager;
0049         path = nullptr;
0050 
0051     txtSrcBefore->setText(properties.readEntry("SrcBeforeCommand",""));
0052     txtSrcAfter->setText(properties.readEntry("SrcAfterCommand",""));
0053     txtDestBefore->setText(properties.readEntry("DestBeforeCommand",""));
0054     txtDestAfter->setText(properties.readEntry("DestAfterCommand",""));
0055 
0056         bool twoWay = properties.readEntry("PathTwoWay", manager->getMapData()->defaultPathTwoWay);
0057         directionTyp srcDir = (directionTyp) properties.readEntry("SrcDir", (int) SPECIAL);
0058         if (srcDir != SPECIAL) setSrcDirection(srcDir);
0059         directionTyp destDir = (directionTyp) properties.readEntry("DestDir", (int) SPECIAL);
0060         if (destDir != SPECIAL) setDestDirection(destDir);
0061 
0062     optTwoWay->setChecked(twoWay);
0063     slotDirectionChange();
0064 
0065     txtSpecialSrc->setText(properties.readEntry("SpecialCmdSrc"));
0066     txtSpecialDest->setText(properties.readEntry("SpecialCmdDest"));
0067     bool specialExit = properties.readEntry("SpecialExit",false);
0068 
0069     chkNormal->setChecked(!specialExit);
0070     chkSpecial->setChecked(specialExit);
0071 
0072     slotExitTypeChange();
0073 
0074     // Get the extension panels from the plugins
0075     QList<CMapPropertiesPaneBase *> paneList = mapManager->createPropertyPanes(PATH,nullptr,(QWidget *)tabPaths);
0076     foreach (CMapPropertiesPaneBase *pane, paneList)
0077     {
0078         tabPaths->addTab(pane,pane->getTitle());
0079         connect(cmdOK,SIGNAL(clicked()),pane,SLOT(slotOk()));
0080         connect(cmdCancel,SIGNAL(clicked()),pane,SLOT(slotCancel()));
0081     }
0082 }
0083 
0084 DlgMapPathProperties::DlgMapPathProperties(CMapManager *manager,CMapPath *pathElement,bool undoable,QWidget *parent)
0085     : QDialog(parent)
0086 {
0087   setupUi (this);
0088   connect(this, SIGNAL(accepted()), this, SLOT(slotAccept()));
0089 
0090     useProperties = false;
0091     pathUndoable = undoable;
0092     path = pathElement;
0093     mapManager = manager;
0094 
0095     txtSpecialSrc->setText(path->getSpecialCmd());
0096     txtSrcBefore->setText(path->getBeforeCommand());
0097     txtSrcAfter->setText(path->getAfterCommand());
0098 
0099     if (path->getOpsitePath())
0100     {
0101         txtDestBefore->setText(path->getOpsitePath()->getBeforeCommand());
0102         txtDestAfter->setText(path->getOpsitePath()->getAfterCommand());
0103         txtSpecialDest->setText(path->getOpsitePath()->getSpecialCmd());
0104         optTwoWay->setChecked(true);
0105     }
0106     else
0107     {
0108         fraDestSrcCommands->setEnabled(false);
0109         txtSpecialSrc->setEnabled(false);
0110         optTwoWay->setChecked(false);
0111     }
0112 
0113 
0114     chkNormal->setChecked(!path->getSpecialExit());
0115     chkSpecial->setChecked(path->getSpecialExit());
0116 
0117     setSrcDirection(path->getSrcDir());
0118     setDestDirection(path->getDestDir());
0119 
0120     slotExitTypeChange();
0121 
0122     // Get the extension panels from the plugins
0123     QList<CMapPropertiesPaneBase *> paneList = mapManager->createPropertyPanes(PATH,(CMapElement*)pathElement,(QWidget *)tabPaths);
0124     foreach (CMapPropertiesPaneBase *pane, paneList)
0125     {
0126         tabPaths->addTab(pane,pane->getTitle());
0127         connect(cmdOK,SIGNAL(clicked()),pane,SLOT(slotOk()));
0128         connect(cmdCancel,SIGNAL(clicked()),pane,SLOT(slotCancel()));
0129     }
0130 
0131 qDebug()<<optTwoWay->isChecked();
0132 }
0133 
0134 DlgMapPathProperties::~DlgMapPathProperties()
0135 {
0136 }
0137 
0138 void DlgMapPathProperties::setSrcDirection(directionTyp direction)
0139 {
0140     cmdSrcN->setChecked(false);
0141     cmdSrcS->setChecked(false);
0142     cmdSrcE->setChecked(false);
0143     cmdSrcW->setChecked(false);
0144     cmdSrcSE->setChecked(false);
0145     cmdSrcNE->setChecked(false);
0146     cmdSrcSW->setChecked(false);
0147     cmdSrcNW->setChecked(false);
0148     cmdSrcUp->setChecked(false);
0149     cmdSrcDown->setChecked(false);
0150 
0151     switch (direction)
0152     {
0153         case NORTH     : cmdSrcN->setChecked(true); break;
0154         case SOUTH     : cmdSrcS->setChecked(true); break;
0155         case EAST      : cmdSrcE->setChecked(true); break;
0156         case WEST      : cmdSrcW->setChecked(true); break;
0157         case SOUTHEAST : cmdSrcSE->setChecked(true); break;
0158         case NORTHEAST : cmdSrcNE->setChecked(true); break;
0159         case SOUTHWEST : cmdSrcSW->setChecked(true); break;
0160         case NORTHWEST : cmdSrcNW->setChecked(true); break;
0161         case UP        : cmdSrcUp->setChecked(true); break;
0162         case DOWN      : cmdSrcDown->setChecked(true); break;
0163         case SPECIAL   : break;
0164     }
0165 }
0166 
0167 void DlgMapPathProperties::setDestDirection(directionTyp direction)
0168 {
0169     cmdDestN->setChecked(false);
0170     cmdDestS->setChecked(false);
0171     cmdDestE->setChecked(false);
0172     cmdDestW->setChecked(false);
0173     cmdDestSE->setChecked(false);
0174     cmdDestNE->setChecked(false);
0175     cmdDestSW->setChecked(false);
0176     cmdDestNW->setChecked(false);
0177     cmdDestUp->setChecked(false);
0178     cmdDestDown->setChecked(false);
0179 
0180     switch (direction)
0181     {
0182         case NORTH     : cmdDestN->setChecked(true); break;
0183         case SOUTH     : cmdDestS->setChecked(true); break;
0184         case EAST      : cmdDestE->setChecked(true); break;
0185         case WEST      : cmdDestW->setChecked(true); break;
0186         case SOUTHEAST : cmdDestSE->setChecked(true); break;
0187         case NORTHEAST : cmdDestNE->setChecked(true); break;
0188         case SOUTHWEST : cmdDestSW->setChecked(true); break;
0189         case NORTHWEST : cmdDestNW->setChecked(true); break;
0190         case UP        : cmdDestUp->setChecked(true); break;
0191         case DOWN      : cmdDestDown->setChecked(true); break;
0192         case SPECIAL   : break;
0193     }
0194 }
0195 
0196 directionTyp DlgMapPathProperties::getSrcDirection(void)
0197 {
0198     if (chkSpecial->isChecked()) return SPECIAL;
0199     if (cmdSrcNE->isChecked()) return NORTHEAST;
0200     if (cmdSrcE->isChecked()) return EAST;
0201     if (cmdSrcSE->isChecked()) return SOUTHEAST;
0202     if (cmdSrcS->isChecked()) return SOUTH;
0203     if (cmdSrcSW->isChecked()) return SOUTHWEST;
0204     if (cmdSrcW->isChecked()) return WEST;
0205     if (cmdSrcNW->isChecked()) return NORTHWEST;
0206     if (cmdSrcN->isChecked()) return NORTH;
0207     if (cmdSrcDown->isChecked()) return DOWN;
0208     if (cmdSrcUp->isChecked()) return UP;
0209     return SPECIAL;
0210 }
0211 
0212 directionTyp DlgMapPathProperties::getDestDirection(void)
0213 {
0214     if (chkSpecial->isChecked()) return SPECIAL;
0215     if (cmdDestNE->isChecked()) return NORTHEAST;
0216     if (cmdDestE->isChecked()) return EAST;
0217     if (cmdDestSE->isChecked()) return SOUTHEAST;
0218     if (cmdDestS->isChecked()) return SOUTH;
0219     if (cmdDestSW->isChecked()) return SOUTHWEST;
0220     if (cmdDestW->isChecked()) return WEST;
0221     if (cmdDestNW->isChecked()) return NORTHWEST;
0222     if (cmdDestN->isChecked()) return NORTH;
0223     if (cmdDestDown->isChecked()) return DOWN;
0224     if (cmdDestUp->isChecked()) return UP;
0225     return SPECIAL;
0226 }
0227 
0228 void DlgMapPathProperties::propertiesAccept(QString)
0229 {
0230     properties.writeEntry("SrcBeforeCommand",txtSrcBefore->text().trimmed());
0231     properties.writeEntry("SrcAfterCommand",txtSrcAfter->text().trimmed());
0232     properties.writeEntry("SrcDir",(int)getSrcDirection());
0233     properties.writeEntry("DestDir",(int)getDestDirection());
0234     properties.writeEntry("SpecialExit",chkSpecial->isChecked());
0235     properties.writeEntry("SpecialCmdSrc",txtSpecialSrc->text().trimmed());
0236 
0237         properties.writeEntry("PathTwoWay", optTwoWay->isChecked());
0238 
0239     properties.writeEntry("DestBeforeCommand",txtDestBefore->text().trimmed());
0240     properties.writeEntry("DestAfterCommand",txtDestAfter->text().trimmed());
0241     properties.writeEntry("SpecialCmdDest",txtSpecialDest->text().trimmed());
0242 }
0243 
0244 void DlgMapPathProperties::pathAccept(QString cmdName)
0245 {
0246     if (pathUndoable)
0247         mapManager->openCommandGroup(cmdName);
0248 
0249     CMapCmdElementProperties *command = new CMapCmdElementProperties(mapManager,cmdName,path);
0250 
0251     command->compare("SrcBeforeCommand",path->getBeforeCommand(),txtSrcBefore->text().trimmed());
0252     command->compare("SrcAfterCommand",path->getAfterCommand(),txtSrcAfter->text().trimmed());
0253     command->compare("SrcDir",(int)path->getSrcDir(),(int)getSrcDirection());
0254     command->compare("DestDir",(int)path->getDestDir(),(int)getDestDirection());
0255     command->compare("SpecialExit",path->getSpecialExit(),chkSpecial->isChecked());
0256     command->compare("SpecialCmdSrc",path->getSpecialCmd(),txtSpecialSrc->text().trimmed());
0257         CMapPath *op = path->getOpsitePath();
0258     command->compare("PathTwoWay", op != nullptr, optTwoWay->isChecked());
0259 
0260     command->compare("DestBeforeCommand", op ? op->getBeforeCommand() : QString(), txtDestBefore->text().trimmed());
0261     command->compare("DestAfterCommand", op ? op->getAfterCommand() : QString(), txtDestAfter->text().trimmed());
0262     command->compare("SpecialCmdDest", op ? op->getSpecialCmd() : QString(), txtSpecialDest->text().trimmed());
0263 
0264     if (pathUndoable)
0265         mapManager->addCommand(command);
0266     else
0267         command->redo();
0268 
0269     if (pathUndoable)
0270         mapManager->closeCommandGroup();
0271 
0272 }
0273 
0274 bool DlgMapPathProperties::getTwoWay(void)
0275 {
0276     return optTwoWay->isChecked();
0277 }
0278 
0279 QString DlgMapPathProperties::getDestBeforeCmd(void)
0280 {
0281     return txtDestBefore->text().trimmed();
0282 }
0283 
0284 QString DlgMapPathProperties::getDestAfterCmd(void)
0285 {
0286     return txtDestAfter->text().trimmed();
0287 }
0288 
0289 QString DlgMapPathProperties::getSpecialCmdDest(void)
0290 {
0291     return txtSpecialDest->text().trimmed();
0292 }
0293 
0294 
0295 void DlgMapPathProperties::slotAccept()
0296 {
0297     if (useProperties)
0298         propertiesAccept(i18n("Changed Path Properties"));
0299     else
0300         pathAccept(i18n("Changed Path Properties"));
0301 }
0302 
0303 void DlgMapPathProperties::slotDirectionChange()
0304 {
0305     fraDestSrcCommands->setEnabled(optTwoWay->isChecked());
0306     if ( !chkNormal->isChecked() )
0307     {
0308         txtSpecialDest->setEnabled(optTwoWay->isChecked());
0309         lblDestToSrc->setEnabled(optTwoWay->isChecked());
0310     }
0311 }
0312 
0313 void DlgMapPathProperties::slotExitTypeChange()
0314 {
0315     bool normal = chkNormal->isChecked();
0316 
0317     cmdSrcDown->setEnabled(normal);
0318     cmdSrcUp->setEnabled(normal);
0319     cmdSrcN->setEnabled(normal);
0320     cmdSrcNE->setEnabled(normal);
0321     cmdSrcE->setEnabled(normal);
0322     cmdSrcSE->setEnabled(normal);
0323     cmdSrcS->setEnabled(normal);
0324     cmdSrcSW->setEnabled(normal);
0325     cmdSrcW->setEnabled(normal);
0326     cmdSrcNW->setEnabled(normal);
0327 
0328     cmdDestDown->setEnabled(normal);
0329     cmdDestUp->setEnabled(normal);
0330     cmdDestN->setEnabled(normal);
0331     cmdDestNE->setEnabled(normal);
0332     cmdDestE->setEnabled(normal);
0333     cmdDestSE->setEnabled(normal);
0334     cmdDestS->setEnabled(normal);
0335     cmdDestSW->setEnabled(normal);
0336     cmdDestW->setEnabled(normal);
0337     cmdDestNW->setEnabled(normal);
0338 
0339     lblSrc->setEnabled(normal);
0340     lblDest->setEnabled(normal);
0341 
0342     lblSpecial->setEnabled(!normal);
0343     txtSpecialSrc->setEnabled(!normal);
0344     lblSrcToDest->setEnabled(!normal);
0345 
0346     lblDestToSrc->setEnabled(!normal && optTwoWay->isChecked());
0347     txtSpecialDest->setEnabled(!normal && optTwoWay->isChecked());
0348 
0349 }
0350 
0351 void DlgMapPathProperties::slotDestDown()
0352 {
0353     setDestDirection(DOWN);
0354 }
0355 
0356 void DlgMapPathProperties::slotDestE()
0357 {
0358     setDestDirection(EAST);
0359 }
0360 
0361 void DlgMapPathProperties::slotDestN()
0362 {
0363     setDestDirection(NORTH);
0364 }
0365 
0366 void DlgMapPathProperties::slotDestNE()
0367 {
0368     setDestDirection(NORTHEAST);
0369 }
0370 
0371 void DlgMapPathProperties::slotDestNW()
0372 {
0373     setDestDirection(NORTHWEST);
0374 }
0375 
0376 void DlgMapPathProperties::slotDestS()
0377 {
0378     setDestDirection(SOUTH);
0379 }
0380 
0381 void DlgMapPathProperties::slotDestSE()
0382 {
0383     setDestDirection(SOUTHEAST);
0384 }
0385 
0386 void DlgMapPathProperties::slotDestSW()
0387 {
0388     setDestDirection(SOUTHWEST);
0389 }
0390 
0391 void DlgMapPathProperties::slotDestUp()
0392 {
0393     setDestDirection(UP);
0394 }
0395 
0396 void DlgMapPathProperties::slotDestW()
0397 {
0398     setDestDirection(WEST);
0399 }
0400 
0401 void DlgMapPathProperties::slotSrcDown()
0402 {
0403     setSrcDirection(DOWN);
0404 }
0405 
0406 void DlgMapPathProperties::slotSrcE()
0407 {
0408     setSrcDirection(EAST);
0409 }
0410 
0411 void DlgMapPathProperties::slotSrcN()
0412 {
0413     setSrcDirection(NORTH);
0414 }
0415 
0416 void DlgMapPathProperties::slotSrcNE()
0417 {
0418     setSrcDirection(NORTHEAST);
0419 }
0420 
0421 void DlgMapPathProperties::slotSrcNW()
0422 {
0423     setSrcDirection(NORTHWEST);
0424 }
0425 
0426 void DlgMapPathProperties::slotSrcS()
0427 {
0428     setSrcDirection(SOUTH);
0429 }
0430 
0431 void DlgMapPathProperties::slotSrcSE()
0432 {
0433     setSrcDirection(SOUTHEAST);
0434 }
0435 
0436 void DlgMapPathProperties::slotSrcSW()
0437 {
0438     setSrcDirection(SOUTHWEST);
0439 }
0440 
0441 void DlgMapPathProperties::slotSrcUp()
0442 {
0443     setSrcDirection(UP);
0444 }
0445 
0446 void DlgMapPathProperties::slotSrcW()
0447 {
0448     setSrcDirection(WEST);
0449 }
0450 
0451 #include "moc_dlgmappathproperties.cpp"