File indexing completed on 2023-10-01 04:14:09

0001 /***************************************************************************
0002                                cmapview.cpp
0003                              -------------------
0004     begin                : Mon Mar 19 2001
0005     copyright            : (C) 2001 by Kmud Developer Team
0006                            (C) 2007 Tomas Mecir <kmuddy@kmuddy.net>
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 "cmapview.h"
0020 
0021 #include <QAction>
0022 #include <QPushButton>
0023 #include <QScrollArea>
0024 #include <QActionGroup>
0025 
0026 #include "cmapmanager.h"
0027 #include "cmapzone.h"
0028 #include "cmapzonemanager.h"
0029 #include "cmaplevel.h"
0030 #include "cmappath.h"
0031 #include "cmapview.h"
0032 #include "cmapelement.h"
0033 #include "cmapwidget.h"
0034 #include "cmapviewstatusbar.h"
0035 #include "cmaptoolbase.h"
0036 #include "cmapclipboard.h"
0037 #include "cmapcmdelementproperties.h"
0038 
0039 #include <kselectaction.h>
0040 #include <ktoggleaction.h>
0041 #include <kactioncollection.h>
0042 #include <kdebug.h>
0043 #include <kiconloader.h>
0044 #include <klocale.h>
0045 #include <kmessagebox.h>
0046 #include <kstandarddirs.h>
0047 #include <kundostack.h>
0048 #include <kinputdialog.h>
0049 
0050 CMapView::CMapView(CMapManager *manager,QWidget *parent) : KXmlGuiWindow(parent)
0051 {
0052   kDebug() << "CMapView::CMapView create view";
0053 
0054   setCaption (i18n ("Mapper"));
0055   setAttribute (Qt::WA_DeleteOnClose, false);  // do not delete on close
0056 
0057   mapManager = manager;
0058   currentLevel = nullptr;
0059   setFocusPolicy(Qt::StrongFocus);
0060   setWindowFlags (Qt::Widget);
0061 
0062   m_clipboard = new CMapClipboard(mapManager, this, actionCollection());
0063   initMenus();
0064 
0065   // set up the menus
0066   setHelpMenuEnabled (false);
0067 
0068   scroller = new QScrollArea(this);
0069   scroller->setWidgetResizable(true);
0070   scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
0071   scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
0072   setCentralWidget(scroller);
0073 
0074   mapWidget = new CMapWidget(this, mapManager, scroller);
0075   scroller->setWidget(mapWidget);
0076   mapWidget->show();
0077 
0078   statusbar = new CMapViewStatusbar(manager, this);
0079   setStatusBar(statusbar);
0080 
0081   cmdFollowMode = new QPushButton(i18n("Follow Moves"),statusbar);
0082   cmdFollowMode->setIcon(BarIcon("kmud_follow.png"));
0083   cmdFollowMode->setCheckable(true);
0084   cmdFollowMode->setFocusProxy(this);
0085   statusbar->addFollowButton(cmdFollowMode);
0086 
0087   cmdCreateMode = new QPushButton(i18n("Auto Create"),statusbar);
0088   cmdCreateMode->setIcon(BarIcon("kmud_create.png"));
0089   cmdCreateMode->setCheckable(true);
0090   cmdCreateMode->setFocusProxy(this);
0091   statusbar->addFollowButton(cmdCreateMode);
0092 //  getMapData()->createModeActive = m_toolsCreate->isChecked();
0093 
0094   //FIXME_jp : get settings for status bar instead of defaults
0095 
0096   //FIXME_jp : Add proper resize instead of test size
0097   changed();
0098 }
0099 
0100 CMapView::~CMapView()
0101 {
0102   kDebug() << "CMapView::~CMapView()";
0103 }
0104 
0105 void CMapView::initGUI()
0106 {
0107   createGUI(KStandardDirs::locate("appdata", "kmuddymapperpart.rc"));
0108   mapWidget->initContexMenus();
0109   enableViewControls(false);
0110 }
0111 
0112 void CMapView::initMenus()
0113 {
0114   kDebug() << "begin initMenus";
0115   kDebug() << "Main collection is "<<actionCollection();
0116 
0117   // Edit menu
0118   mapManager->getCommandHistory()->createUndoAction(actionCollection(), "editUndo");
0119   mapManager->getCommandHistory()->createRedoAction(actionCollection(), "editRedo");
0120 
0121   // Tools menu
0122   m_toolsGrid = new KToggleAction (this);
0123   m_toolsGrid->setText ( i18n("&Grid"));
0124   m_toolsGrid->setIcon (BarIcon("kmud_grid.png"));
0125   connect (m_toolsGrid, SIGNAL (triggered()), this, SLOT(slotToolsGrid()));
0126   actionCollection()->addAction ("toolsGrid", m_toolsGrid);
0127   m_toolsUpLevel = new QAction (this);
0128   m_toolsUpLevel->setText ( i18n("Display Upper Level"));
0129   m_toolsUpLevel->setIcon (BarIcon("arrow-up"));
0130   connect (m_toolsUpLevel, SIGNAL (triggered()), this, SLOT(slotToolsLevelUp()));
0131   actionCollection()->addAction ("toolsLevelUp", m_toolsUpLevel);
0132   m_toolsDownLevel = new QAction (this);
0133   m_toolsDownLevel->setText ( i18n("Display Lower Level"));
0134   m_toolsDownLevel->setIcon (BarIcon("arrow-down"));
0135   connect (m_toolsDownLevel, SIGNAL (triggered()), this, SLOT(slotToolsLevelDown()));
0136   actionCollection()->addAction ("toolsLevelDown", m_toolsDownLevel);
0137   m_toolsDeleteLevel = new QAction (this);
0138   m_toolsDeleteLevel->setText ( i18n("Delete Current Level"));
0139   m_toolsDeleteLevel->setIcon (BarIcon("edit-delete"));
0140   connect (m_toolsDeleteLevel, SIGNAL (triggered()), this, SLOT(slotToolsLevelDelete()));
0141   actionCollection()->addAction ("toolsLevelDelete", m_toolsDeleteLevel);
0142   m_toolsCreateZone = new QAction (this);
0143   m_toolsCreateZone->setText ( i18n("Create New Zone"));
0144   m_toolsCreateZone->setIcon (BarIcon("task-new"));
0145   connect (m_toolsCreateZone, SIGNAL (triggered()), this, SLOT(slotToolsZoneCreate()));
0146   actionCollection()->addAction ("toolsZoneCreate", m_toolsCreateZone);
0147   m_toolsDeleteZone = new QAction (this);
0148   m_toolsDeleteZone->setText ( i18n("Delete Current Zone"));
0149   m_toolsDeleteZone->setIcon (BarIcon("edit-delete"));
0150   connect (m_toolsDeleteZone, SIGNAL (triggered()), this, SLOT(slotToolsZoneDelete()));
0151   actionCollection()->addAction ("toolsZoneDelete", m_toolsDeleteZone);
0152 
0153   // View menu
0154   m_viewUpperLevel = new KToggleAction (this);
0155   m_viewUpperLevel->setText ( i18n("Map Upper Level"));
0156   connect  (m_viewUpperLevel, SIGNAL (triggered()), this, SLOT(slotViewUpperLevel()));
0157   actionCollection()->addAction ("viewUpperLevel", m_viewUpperLevel);
0158   m_viewLowerLevel = new KToggleAction (this);
0159   m_viewLowerLevel->setText ( i18n("Map Lower Level"));
0160   connect  (m_viewLowerLevel, SIGNAL (triggered()), this, SLOT(slotViewLowerLevel()));
0161   actionCollection()->addAction ("viewLowerLevel", m_viewLowerLevel);
0162 
0163   // Room Popup Actions
0164   QAction *action;
0165   action = new QAction (this);
0166   action->setText (i18n("Set &Current Position"));
0167   connect (action, SIGNAL (triggered()), this, SLOT(slotRoomSetCurrentPos()));
0168   actionCollection()->addAction ("roomCurrentPos", action);
0169   action = new QAction (this);
0170   action->setText (i18n("Set Room to &Login Point"));
0171   connect (action, SIGNAL (triggered()), this, SLOT(slotRoomSetLogin()));
0172   actionCollection()->addAction ("roomLoginPoint", action);
0173   action = new QAction (this);
0174   action->setText (i18n("&Speed walk to room"));
0175   connect (action, SIGNAL (triggered()), this, SLOT(slotRoomSpeedwalkTo()));
0176   actionCollection()->addAction ("roomWalkTo", action);
0177   action = new QAction (this);
0178   action->setText (i18n("&Delete room"));
0179   action->setIcon (SmallIcon("edit-delete"));
0180   connect (action, SIGNAL (triggered()), this, SLOT(slotRoomDelete()));
0181   actionCollection()->addAction ("roomDelete", action);
0182   action = new QAction (this);
0183   action->setText (i18n("&Properties"));
0184   action->setIcon (SmallIcon("document-properties"));
0185   connect (action, SIGNAL (triggered()), this, SLOT(slotRoomProperties()));
0186   actionCollection()->addAction ("roomProperties", action);
0187 
0188   // Text Popup Actions
0189   action = new QAction (this);
0190   action->setText (i18n("&Delete Text"));
0191   action->setIcon (SmallIcon("edit-delete"));
0192   connect (action, SIGNAL (triggered()), this, SLOT(slotTextDelete()));
0193   actionCollection()->addAction ("textDelete", action);
0194   action = new QAction (this);
0195   action->setText (i18n("&Properties"));
0196   action->setIcon (SmallIcon("document-properties"));
0197   connect (action, SIGNAL (triggered()), this, SLOT(slotTextProperties()));
0198   actionCollection()->addAction ("textProperties", action);
0199 
0200   // Path Popup Actions
0201   action = new KToggleAction (this);
0202   action->setText (i18n("&One way"));
0203   connect (action, SIGNAL (triggered()), this, SLOT(slotPathOneWay()));
0204   actionCollection()->addAction ("pathOneWay", action);
0205   action = new KToggleAction (this);
0206   action->setText (i18n("&Two way"));
0207   connect (action, SIGNAL (triggered()), this, SLOT(slotPathTwoWay()));
0208   actionCollection()->addAction ("pathTwoWay", action);
0209   action = new QAction (this);
0210   action->setText (i18n("&Add Bend"));
0211   connect (action, SIGNAL (triggered()), this, SLOT(slotPathAddBend()));
0212   actionCollection()->addAction ("pathAddBend", action);
0213   action = new QAction (this);
0214   action->setText (i18n("&Remove Segment"));
0215   connect (action, SIGNAL (triggered()), this, SLOT(slotPathDelBend()));
0216   actionCollection()->addAction ("pathDelBend", action);
0217   action = new QAction (this);
0218   action->setText (i18n("&Edit Bends"));
0219   connect (action, SIGNAL (triggered()), this, SLOT(slotPathEditBends()));
0220   actionCollection()->addAction ("pathEditBends", action);
0221   action = new QAction (this);
0222   action->setText (i18n("&Delete Path"));
0223   action->setIcon (SmallIcon("edit-delete"));
0224   connect (action, SIGNAL (triggered()), this, SLOT(slotPathDelete()));
0225   actionCollection()->addAction ("pathDelete", action);
0226   action = new QAction (this);
0227   action->setText (i18n("&Properties"));
0228   connect (action, SIGNAL (triggered()), this, SLOT(slotPathProperties()));
0229   actionCollection()->addAction ("pathPorperties", action);
0230 
0231   QStringList labelPos;
0232   labelPos.append(i18n("Hide"));
0233   labelPos.append(mapManager->directionToText(NORTH,""));
0234   labelPos.append(mapManager->directionToText(NORTHEAST,""));
0235   labelPos.append(mapManager->directionToText(EAST,""));
0236   labelPos.append(mapManager->directionToText(SOUTHEAST,""));
0237   labelPos.append(mapManager->directionToText(SOUTH,""));
0238   labelPos.append(mapManager->directionToText(SOUTHWEST,""));
0239   labelPos.append(mapManager->directionToText(WEST,""));
0240   labelPos.append(mapManager->directionToText(NORTHWEST,""));
0241   labelPos.append(i18n("Custom"));
0242   
0243   labelMenu = new KSelectAction (this);
0244   labelMenu->setText (i18n("&Label"));
0245   connect (labelMenu, SIGNAL (triggered()), this, SLOT(slotChangeLabelPos()));
0246   actionCollection()->addAction ("labelMenu", labelMenu);
0247   labelMenu->setItems(labelPos);
0248 
0249   // tool action group
0250   m_toolGroup = new QActionGroup (this);
0251 }
0252 
0253 
0254 void CMapView::readOptions()
0255 {
0256   CMapData *data = mapManager->getMapData();
0257   m_toolsGrid->setChecked(data->gridVisable);
0258   m_viewLowerLevel->setChecked(data->showLowerLevel);
0259   m_viewUpperLevel->setChecked(data->showUpperLevel);
0260 }
0261 
0262 /** Used to get the currently viewed zone */
0263 CMapZone *CMapView::getCurrentlyViewedZone()
0264 {
0265   return currentLevel ? currentLevel->getZone() : nullptr;
0266 }
0267 
0268 /** Used to get the currently viewed level */
0269 CMapLevel *CMapView::getCurrentlyViewedLevel()
0270 {
0271   return currentLevel;
0272 }
0273 
0274 /** Used to set the current level. This is for internal use */
0275 void CMapView::setLevel(CMapLevel *level)
0276 {
0277   currentLevel = level;
0278 }
0279 
0280 void CMapView::playerPositionChanged(CMapRoom *room)
0281 {
0282   if (!room) return;
0283   if (room->getLevel() != currentLevel)
0284     showPosition(room->getLevel(), false);
0285 }
0286 
0287 void CMapView::setSelectedElement(CMapElement *element)
0288 {
0289   m_selectedElement = element;  
0290 }
0291 
0292 void CMapView::setSelectedPos(QPoint pos)
0293 {
0294   m_selectedPos = pos;
0295 }
0296 
0297 CMapElement *CMapView::getSelectedElement()
0298 {
0299   return m_selectedElement;
0300 }
0301 
0302 
0303 /** Used to let the map manager know if it should register the focus of this widget */
0304 bool CMapView::acceptFocus()
0305 {
0306   return true;
0307 }
0308 
0309 /** This method is called when an element is added */
0310 void CMapView::addedElement(CMapElement *element)
0311 {
0312   if (isElementVisible(element))
0313   {
0314     checkSize(element->getHighPos());
0315     mapWidget->update();
0316   }
0317 }
0318 
0319 /** This method is called when an element is deleted */
0320 void CMapView::deletedElement(CMapLevel *deletedFromLevel)
0321 {
0322   CMapLevel *upperLevel = getCurrentlyViewedLevel()->getNextLevel();
0323   CMapLevel *lowerLevel = getCurrentlyViewedLevel()->getPrevLevel();
0324 
0325   if (deletedFromLevel == getCurrentlyViewedLevel())
0326     mapWidget->update();
0327 
0328   if (upperLevel && mapManager->getMapData()->showUpperLevel)
0329     if (deletedFromLevel == upperLevel)
0330       mapWidget->update();
0331 
0332   if (lowerLevel && mapManager->getMapData()->showLowerLevel)
0333     if (deletedFromLevel == lowerLevel)
0334       mapWidget->update();
0335 }
0336 
0337 /** This method is called when an element is changed */
0338 void CMapView::changedElement(CMapElement *element)
0339 {
0340   if (isElementVisible(element))
0341   {
0342     checkSize(element->getHighPos());
0343     mapWidget->update();
0344   }
0345 
0346   if (element == mapManager->getCurrentRoom())
0347     statusbar->setRoom(mapManager->getCurrentRoom()->getLabel());
0348 }
0349 
0350 /** This method is called when a map level is changed */
0351 void CMapView::changedLevel(CMapLevel *level)
0352 {
0353   if (!isLevelVisible(level)) return;
0354   changed();
0355 }
0356 
0357 /** Used to find out if a level is visible in the view */
0358 bool CMapView::isLevelVisible(CMapLevel *level)
0359 {
0360   CMapLevel *vlevel = getCurrentlyViewedLevel();
0361   if (!vlevel) return false;
0362   if (level == vlevel)
0363     return true;
0364   if (level == vlevel->getPrevLevel())
0365     return true;
0366   if (level == vlevel->getNextLevel())
0367     return true;
0368 
0369   return false;
0370 }
0371 
0372 /** Used to find out if a element is visiable in the view */
0373 bool CMapView::isElementVisible(CMapElement *element)
0374 {
0375   return isLevelVisible(element->getLevel());
0376 }
0377 
0378 /**
0379  * Used to enable/disable the view actions
0380  * @param If true then enable the actions otherwise disable the actions
0381  */
0382 void CMapView::enableViewControls(bool enabled)
0383 {
0384   if (!mapManager->getMapData()) return;  // if we don't have mapData, we're going down
0385   enableNonViewActions(enabled);
0386   m_clipboard->enableActions(enabled);
0387   m_toolsUpLevel->setEnabled(enabled);
0388   m_toolsDownLevel->setEnabled(enabled);
0389   m_toolsDeleteLevel->setEnabled(enabled);
0390   m_toolsCreateZone->setEnabled(enabled);
0391   m_toolsDeleteZone->setEnabled(enabled);
0392 }
0393 
0394 /**
0395  * This method is used to disable/enable mapper actions that are not done by enableViewControls()
0396  * @param If true then enable the actions otherwise disable the actions
0397  */
0398 void CMapView::enableNonViewActions(bool enabled)
0399 {
0400   m_toolsGrid->setEnabled(enabled);
0401 }
0402 
0403 
0404 void CMapView::requestPaint()
0405 {
0406   mapWidget->update();
0407 }
0408 
0409 void CMapView::changed()
0410 {
0411   maxSize = QSize(0,0);
0412 
0413   CMapLevel *level = getCurrentlyViewedLevel();
0414   if (!level) {
0415     mapWidget->update();
0416     return;
0417   }
0418 
0419   CMapLevel *upperLevel = level->getNextLevel();
0420   CMapLevel *lowerLevel = level->getPrevLevel();
0421 
0422   QPoint size(0,0);
0423 
0424   // Calc the size the widget should be
0425   QList<CMapElement *> lst = level->getAllElements();
0426   foreach (CMapElement *element, lst)
0427   {
0428     if (element->getHighX()>size.x()) size.setX(element->getHighX());
0429     if (element->getHighY()>size.y()) size.setY(element->getHighY());
0430   }
0431 
0432   if (upperLevel && mapManager->getMapData()->showUpperLevel)
0433   {
0434     lst = upperLevel->getAllElements();
0435     foreach (CMapElement *element, lst)
0436     {
0437       if (element->getHighX()>size.x()) size.setX(element->getHighX());
0438       if (element->getHighY()>size.y()) size.setY(element->getHighY());
0439     }
0440   }
0441 
0442   if (lowerLevel && mapManager->getMapData()->showLowerLevel)
0443   {
0444     lst = lowerLevel->getAllElements();
0445     foreach (CMapElement *element, lst)
0446     {
0447       if (element->getHighX()>size.x()) size.setX(element->getHighX());
0448       if (element->getHighY()>size.y()) size.setY(element->getHighY());
0449     }
0450   }
0451 
0452   checkSize(size);
0453   mapWidget->update();
0454 }
0455 
0456 
0457 /** Tell this map widget to display a different level. view wiil
0458   * center on the first room */
0459 void CMapView::showPosition(CMapLevel *level,bool centerView)
0460 {
0461   QPoint pos(0,0);
0462   if (!level->getRoomList()->isEmpty())
0463   {
0464     CMapRoom *room = level->getRoomList()->first();
0465     pos.setX(room->getX());
0466     pos.setY(room->getY());
0467   }
0468   showPosition(pos,level,centerView);
0469 }
0470 
0471 void CMapView::showPosition(CMapRoom *room,bool centerView)
0472 {
0473   QPoint pos(0,0);  
0474   if (room)  
0475   {
0476     pos.setX(room->getX());
0477     pos.setY(room->getY());
0478     showPosition(pos,room->getLevel(),centerView);
0479   }  
0480 }
0481 
0482 /** Tell this map widget to display a different zone */
0483 void CMapView::showPosition(QPoint pos,CMapLevel *level,bool centerView)
0484 {
0485   if ((!centerView) && (getCurrentlyViewedLevel() == level)) return;
0486 
0487   if (!level) { changed(); return; }
0488 
0489   setLevel(level);
0490 
0491   changed();
0492 
0493   enableViewControls(true);
0494   // Center on the position
0495   if (centerView)
0496     scroller->ensureVisible(pos.x(),pos.y(), width()/2, height()/2);
0497 
0498   // Update the status bar
0499   statusbar->setZone(mapManager->getZone());
0500   statusbar->setLevel(level);
0501   CMapRoom *cur = mapManager->getCurrentRoom();
0502   statusbar->setRoom(cur ? cur->getLabel() : "");
0503 
0504   mapManager->activeViewChanged();
0505 }
0506 
0507 /** This is used ensure a location is visiable for views that scroll */
0508 void CMapView::ensureVisible(QPoint pos)
0509 {
0510   scroller->ensureVisible(pos.x(),pos.y(),10,10);
0511 }
0512 
0513 /** Used to calculate the correct size for the widget */
0514 void CMapView::checkSize(QPoint pos)
0515 {
0516   if (pos.x() > maxSize.width()) maxSize.setWidth(pos.x());
0517   if (pos.y() > maxSize.height()) maxSize.setHeight(pos.y());
0518 
0519   int view_x = width();
0520   int view_y = height();
0521 
0522   if (maxSize.width() > view_x)
0523     view_x = maxSize.width();
0524 
0525   if (maxSize.height() > view_y)
0526     view_y = maxSize.height();
0527 
0528   QSize grid = mapManager->getMapData()->gridSize;
0529   view_x += grid.width() * 3;
0530   view_y += grid.height() * 3;
0531 
0532   if (view_y != mapWidget->height() || view_x != mapWidget->width())
0533     mapWidget->setFixedSize(view_x, view_y);
0534 }
0535 
0536 /** Get the max x cord of all elements */
0537 int CMapView::getMaxX(void)
0538 {
0539         return maxSize.width();
0540 }
0541 
0542 /** Get the max y cord of all elements */
0543 int CMapView::getMaxY(void)
0544 {
0545         return maxSize.height();
0546 }
0547 
0548 void CMapView::setFollowMode(bool follow)
0549 {
0550   cmdFollowMode->setChecked(follow);
0551 }
0552 
0553 bool CMapView::getFollowMode(void)
0554 {
0555   return cmdFollowMode->isChecked();
0556 }
0557 
0558 void CMapView::setCreateMode(bool follow)
0559 {
0560   cmdCreateMode->setChecked(follow);
0561 }
0562 
0563 bool CMapView::getCreateMode(void)
0564 {
0565   return cmdCreateMode->isChecked();
0566 }
0567 
0568 // Tools slots
0569 
0570 void CMapView::slotToolsGrid()
0571 {
0572   mapManager->getMapData()->gridVisable = m_toolsGrid->isChecked();
0573   mapManager->redrawAllViews();
0574 }
0575 
0576 void CMapView::levelShift(bool up)
0577 {
0578   CMapLevel *level = getCurrentlyViewedLevel();
0579   level = up ? level->getNextLevel() : level->getPrevLevel();
0580   if (level) {
0581     showPosition(level, false);
0582     return;
0583   }
0584 
0585   if (KMessageBox::warningYesNo (nullptr, i18n("There is no level in that direction. Do you want to create a new one?"),i18n("KMuddy Mapper")) != KMessageBox::Yes) return;
0586 
0587   mapManager->createLevel(up ? UP : DOWN);
0588 }
0589 
0590 void CMapView::slotToolsLevelUp()
0591 {
0592   levelShift(true);
0593 }
0594 
0595 void CMapView::slotToolsLevelDown()
0596 {
0597   levelShift(false);
0598 }
0599 
0600 void CMapView::slotToolsLevelDelete()
0601 {
0602   CMapLevel *level = getCurrentlyViewedLevel();
0603   if (!level) return;
0604   int count = mapManager->getZone()->levelCount();
0605   if (count <= 1) return;
0606 
0607   if (KMessageBox::warningYesNo (nullptr,i18n("Are you sure that you want to delete the current level?"),i18n("KMuddy Mapper")) != KMessageBox::Yes) return;
0608   mapManager->deleteLevel(level);
0609 }
0610 
0611 void CMapView::slotToolsZoneCreate()
0612 {
0613   bool ok;
0614   QString name = KInputDialog::getText(i18n("KMuddy Mapper"), i18n("Please enter the name of the new zone:"), QString(), &ok);
0615   if (!ok) return;
0616   if (!name.length()) return;
0617   mapManager->zoneManager()->createZone(name);
0618 }
0619 
0620 void CMapView::slotToolsZoneDelete()
0621 {
0622   CMapZoneManager *zm = mapManager->zoneManager();
0623   if (KMessageBox::warningYesNo (nullptr,i18n("Are you sure that you want to delete the current zone? This cannot be undone."),i18n("KMuddy Mapper")) != KMessageBox::Yes) return;
0624   zm->deleteZone(zm->activeZone());
0625 }
0626 
0627 void CMapView::slotViewUpperLevel()
0628 {
0629   mapManager->getMapData()->showUpperLevel = m_viewUpperLevel->isChecked();
0630   mapManager->redrawAllViews();
0631 }
0632 
0633 void CMapView::slotViewLowerLevel()
0634 {
0635   mapManager->getMapData()->showLowerLevel = m_viewLowerLevel->isChecked();
0636   mapManager->redrawAllViews();
0637 }
0638 
0639 /** Used to room under the point the current room */
0640 void CMapView::slotRoomSetCurrentPos(void)
0641 {
0642   mapManager->setCurrentRoom((CMapRoom *)m_selectedElement);
0643 }
0644 
0645 /** Used to room under the point the login room */
0646 void CMapView::slotRoomSetLogin(void)
0647 {
0648   mapManager->setLoginRoom((CMapRoom *)m_selectedElement);
0649 }
0650 
0651 /** Used to set speedwalk to the room under the pointer */
0652 void CMapView::slotRoomSpeedwalkTo(void)
0653 {
0654   mapManager->walkPlayerTo((CMapRoom *)m_selectedElement);
0655 }
0656 
0657 /** Used to delete the room under the pointer */
0658 void CMapView::slotRoomDelete(void)
0659 {
0660   mapManager->deleteElement(m_selectedElement);
0661 }
0662 
0663 /** Used to display the properties of the room under the pointer */
0664 void CMapView::slotRoomProperties(void)
0665 {
0666   mapManager->propertiesRoom((CMapRoom *)m_selectedElement);
0667 }
0668 
0669 /** Used to make the path under the pointer one way */
0670 void CMapView::slotPathOneWay(void)
0671 {
0672   mapManager->makePathOneWay((CMapPath *)m_selectedElement);
0673 }
0674 
0675 /** Used to make the path under the pointer two way */
0676 void CMapView::slotPathTwoWay(void)
0677 {
0678   mapManager->makePathTwoWay((CMapPath *)m_selectedElement);
0679 }
0680 
0681 /** Used to add a bend to the path under the pointer */
0682 void CMapView::slotPathAddBend(void)
0683 {
0684   kDebug() << "CMapView::CMapManager slotPathAddBend";
0685   mapManager->openCommandGroup(i18n("Add Bend"));
0686   CMapPath *path = (CMapPath *)m_selectedElement;
0687 
0688   path->addBendWithUndo(m_selectedPos);
0689   if (path->getOpsitePath())
0690   {
0691     path->getOpsitePath()->addBendWithUndo(m_selectedPos);
0692   }
0693   m_clipboard->slotUnselectAll();
0694   path->setEditMode(true);
0695   changedElement(path);
0696 
0697   mapManager->closeCommandGroup();
0698 }
0699 
0700 /** Used to delete the path segment under the pointer */
0701 void CMapView::slotPathDelBend(void)
0702 {
0703   mapManager->openCommandGroup(i18n("Delete Path Segment"));
0704   CMapPath *path = (CMapPath *)m_selectedElement;
0705 
0706   int seg = path->mouseInPathSeg(m_selectedPos, getCurrentlyViewedZone());
0707 
0708   path->deletePathSegWithUndo(seg);
0709   if (path->getOpsitePath())
0710   {
0711     int seg = path->getOpsitePath()->mouseInPathSeg(m_selectedPos, getCurrentlyViewedZone());
0712     path->getOpsitePath()->deletePathSegWithUndo(seg);
0713   }
0714 
0715   mapManager->changedElement(path);
0716   mapManager->closeCommandGroup();
0717 }
0718 
0719 /** Used to edit the bends of the path under the pointer */
0720 void CMapView::slotPathEditBends(void)
0721 {
0722   CMapPath *path = (CMapPath *)m_selectedElement;
0723 
0724   m_clipboard->slotUnselectAll();
0725   path->setEditMode(true);
0726   mapManager->changedElement(path);
0727 }
0728 
0729 /** Used to delete the path under the pointer */
0730 void CMapView::slotPathDelete(void)
0731 {
0732   mapManager->deleteElement(m_selectedElement);
0733 }
0734 
0735 /** Used to display the properties of the path under the pointer */
0736 void CMapView::slotPathProperties(void)
0737 {
0738   mapManager->propertiesPath((CMapPath *)m_selectedElement);
0739 }
0740 
0741 /** Used to delete the text element under the pointer */
0742 void CMapView::slotTextDelete(void)
0743 {
0744   mapManager->deleteElement(m_selectedElement);
0745 }
0746 
0747 /** Used to display the text properties of the text element under the pointer */
0748 void CMapView::slotTextProperties(void)
0749 {
0750   mapManager->propertiesText((CMapText *)m_selectedElement);
0751 }
0752 
0753 /** Used to change the position of room/zone labels */
0754 void CMapView::slotChangeLabelPos()
0755 {
0756   if (m_selectedElement->getElementType()==ROOM)
0757   {
0758     CMapRoom *room = (CMapRoom *)m_selectedElement;
0759 
0760     CMapCmdElementProperties *command = new CMapCmdElementProperties(mapManager,i18n("Change room label position"),room);
0761 
0762     command->getOrgProperties().writeEntry("LabelPos",(int)room->getLabelPosition());
0763 
0764     switch(labelMenu->currentItem())
0765     {
0766       case 0 : command->getNewProperties().writeEntry("LabelPos",(int)CMapRoom::HIDE); break;
0767       case 1 : command->getNewProperties().writeEntry("LabelPos",(int)CMapRoom::NORTH); break;
0768       case 2 : command->getNewProperties().writeEntry("LabelPos",(int)CMapRoom::NORTHEAST); break;
0769       case 3 : command->getNewProperties().writeEntry("LabelPos",(int)CMapRoom::EAST); break;
0770       case 4 : command->getNewProperties().writeEntry("LabelPos",(int)CMapRoom::SOUTHEAST); break;
0771       case 5 : command->getNewProperties().writeEntry("LabelPos",(int)CMapRoom::SOUTH); break;
0772       case 6 : command->getNewProperties().writeEntry("LabelPos",(int)CMapRoom::SOUTHWEST); break;
0773       case 7 : command->getNewProperties().writeEntry("LabelPos",(int)CMapRoom::WEST); break;
0774       case 8 : command->getNewProperties().writeEntry("LabelPos",(int)CMapRoom::NORTHWEST); break;
0775       case 9 : command->getNewProperties().writeEntry("LabelPos",(int)CMapRoom::CUSTOM); break;
0776       default : command->getNewProperties().writeEntry("LabelPos",(int)CMapRoom::HIDE); break;
0777     }
0778 
0779     mapManager->addCommand(command);
0780   }
0781 
0782   if (m_selectedElement->getElementType()==ZONE)
0783   {
0784     CMapZone *zone = (CMapZone *)m_selectedElement;
0785 
0786     CMapCmdElementProperties *command = new CMapCmdElementProperties(mapManager,i18n("Change zone label position"),zone);
0787 
0788     command->getOrgProperties().writeEntry("LabelPos",(int)zone->getLabelPosition());
0789 
0790     switch(labelMenu->currentItem())
0791     {
0792       case 0 : command->getNewProperties().writeEntry("LabelPos",(int)CMapZone::HIDE); break;
0793       case 1 : command->getNewProperties().writeEntry("LabelPos",(int)CMapZone::NORTH); break;
0794       case 2 : command->getNewProperties().writeEntry("LabelPos",(int)CMapZone::NORTHEAST); break;
0795       case 3 : command->getNewProperties().writeEntry("LabelPos",(int)CMapZone::EAST); break;
0796       case 4 : command->getNewProperties().writeEntry("LabelPos",(int)CMapZone::SOUTHEAST); break;
0797       case 5 : command->getNewProperties().writeEntry("LabelPos",(int)CMapZone::SOUTH); break;
0798       case 6 : command->getNewProperties().writeEntry("LabelPos",(int)CMapZone::SOUTHWEST); break;
0799       case 7 : command->getNewProperties().writeEntry("LabelPos",(int)CMapZone::WEST); break;
0800       case 8 : command->getNewProperties().writeEntry("LabelPos",(int)CMapZone::NORTHWEST); break;
0801       case 9 : command->getNewProperties().writeEntry("LabelPos",(int)CMapZone::CUSTOM); break;
0802       default : command->getNewProperties().writeEntry("LabelPos",(int)CMapZone::HIDE); break;
0803     }
0804     mapManager->addCommand(command);
0805   }
0806 }
0807 
0808 
0809 int CMapView::getWidth(void)
0810 {
0811   if (mapWidget->width() > scroller->viewport()->width())
0812     return mapWidget->width();
0813   return scroller->viewport()->width();
0814 }
0815 
0816 int CMapView::getHeight(void)
0817 {
0818   if (mapWidget->height() > scroller->viewport()->height())
0819     return mapWidget->height();
0820   return scroller->viewport()->height();
0821 }
0822 
0823 void CMapView::setCursor ( const QCursor & cursor)
0824 {
0825   if (mapWidget)
0826     mapWidget->setCursor(cursor);
0827 }
0828 
0829 void CMapView::resizeEvent (QResizeEvent *)
0830 {
0831   changed();
0832 }
0833 
0834 /** Used to set the view to active */
0835 void CMapView::focusInEvent(QFocusEvent *)
0836 {
0837 }
0838 
0839 void CMapView::closeEvent(QCloseEvent *)
0840 {
0841 }
0842 
0843 void CMapView::slotWidgetBeingClosed()
0844 {
0845 }
0846 
0847 void CMapView::slotDockWindowClose()
0848 {
0849 }
0850 
0851 bool CMapView::queryClose()
0852 {
0853   emit closed();
0854   return true;
0855 }
0856 
0857 #include "moc_cmapview.cpp"