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

0001 /***************************************************************************
0002                                dlgmapmovement.cpp
0003                              -------------------
0004     begin                : Tue Mar 18 2003
0005     copyright            : (C) 2003 by Kmud Developer Team
0006                            (C) 2007 Tomas Mecir <kmuddy@kmuddy.com>
0007     email                : kmud-devel@kmud.de
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *   This program is free software; you can redistribute it and/or modify  *
0013  *   it under the terms of the GNU General Public License as published by  *
0014  *   the Free Software Foundation; either version 2 of the License, or     *
0015  *   (at your option) any later version.                                   *
0016  *                                                                         *
0017  ***************************************************************************/
0018 
0019 #include "dlgmapmovement.h"
0020 
0021 #include "../cmapmanager.h"
0022 
0023 #include <qcheckbox.h>
0024 #include <qpushbutton.h>
0025 #include <QListWidget>
0026 #include <qinputdialog.h>
0027 
0028 #include <KLocalizedString>
0029 
0030 DlgMapMovement::DlgMapMovement(CMapManager *mapManager, QWidget *parent) : QDialog(parent)
0031 {
0032   setupUi (this);
0033   connect(this, SIGNAL(accepted()), this, SLOT(slotOkPressed()));
0034 
0035     m_mapManager = mapManager;
0036 
0037     m_chkEnableValidRoomChecking->setChecked(m_mapManager->getMapData()->validRoomCheck);
0038 
0039     slotValidCheckStateChanged(m_mapManager->getMapData()->validRoomCheck);
0040 
0041         QStringList::iterator it;
0042         for (it = mapManager->getMapData()->failedMoveMsg.begin();
0043              it != mapManager->getMapData()->failedMoveMsg.end(); ++it)
0044     {
0045         QString str = *it;
0046         if (!str.isEmpty())
0047                   m_lstInvalidMoveStrs->addItem(str);
0048     }
0049 
0050     connect(m_chkEnableValidRoomChecking,SIGNAL(toggled(bool)),this,SLOT(slotValidCheckStateChanged(bool)));
0051     connect(m_cmdAdd,SIGNAL(clicked()),this,SLOT(slotAddClicked()));
0052     connect(m_cmdEdit,SIGNAL(clicked()),this,SLOT(slotEditClicked()));
0053     connect(m_cmdRemove,SIGNAL(clicked()),this,SLOT(slotRemoveClicked()));
0054 }
0055 
0056 DlgMapMovement::~DlgMapMovement()
0057 {
0058 }
0059 
0060 /** This slot is called when the OK button is pressed */
0061 void DlgMapMovement::slotOkPressed()
0062 {
0063     m_mapManager->getMapData()->validRoomCheck =  m_chkEnableValidRoomChecking->isChecked();
0064 
0065     m_mapManager->getMapData()->failedMoveMsg.clear();
0066 
0067     for (int i=0; i< m_lstInvalidMoveStrs->count();i++)
0068     {
0069         m_mapManager->getMapData()->failedMoveMsg.append(m_lstInvalidMoveStrs->item(i)->text());
0070     }
0071 }
0072 
0073 void DlgMapMovement::slotValidCheckStateChanged(bool state)
0074 {
0075     m_cmdAdd->setEnabled(state);
0076     m_cmdEdit->setEnabled(state);
0077     m_cmdRemove->setEnabled(state);
0078     m_lstInvalidMoveStrs->setEnabled(state);
0079 }
0080 
0081 void DlgMapMovement::slotAddClicked(void)
0082 {
0083   bool ok = false;  
0084 
0085   QString text = QInputDialog::getText(this, i18n("KMuddy"), i18n("Enter invalid movement string as a regular expression"), QLineEdit::Normal, QString(), &ok);
0086   if ( ok && !text.isEmpty() )
0087     m_lstInvalidMoveStrs->addItem(text);
0088 }
0089 
0090 void DlgMapMovement::slotEditClicked(void)
0091 {
0092   int current =  m_lstInvalidMoveStrs->currentRow();
0093   if (current!=-1)
0094   {
0095     bool ok;
0096     QString text = QInputDialog::getText(this, i18n("KMuddy"), i18n("Enter invalid movement string as a regular expression"), QLineEdit::Normal, m_lstInvalidMoveStrs->item(current)->text(), &ok);
0097 
0098     if ( ok && !text.isEmpty() )
0099     {
0100       m_lstInvalidMoveStrs->item(current)->setText(text);
0101     }
0102   }
0103 }
0104 
0105 void DlgMapMovement::slotRemoveClicked(void)
0106 {
0107   QListWidgetItem *item = m_lstInvalidMoveStrs->currentItem();
0108   if (item)
0109     m_lstInvalidMoveStrs->removeItemWidget(item);
0110 }
0111 
0112 #include "moc_dlgmapmovement.cpp"