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