File indexing completed on 2024-05-12 04:03:59
0001 /*************************************************************************** 0002 cmappluginstandard.cpp 0003 ------------------- 0004 begin : Mon Aug 6 2001 0005 copyright : (C) 2001 by Kmud Developer 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 "cmappluginstandard.h" 0019 0020 #include "tools/cmaptoolselect.h" 0021 #include "tools/cmaptoolroom.h" 0022 #include "tools/cmaptoolpath.h" 0023 #include "tools/cmaptooltext.h" 0024 #include "tools/cmaptooleraser.h" 0025 #include "propertyPanes/cmapnotespane.h" 0026 0027 #include "../../cmapmanager.h" 0028 #include "../../cmaplevel.h" 0029 #include "../../cmapzone.h" 0030 #include "../../cmaproom.h" 0031 #include "../../cmaptext.h" 0032 #include "../../cmappath.h" 0033 #include "../../cmapview.h" 0034 0035 #include <QIcon> 0036 0037 #include <KLocalizedString> 0038 #include <kactioncollection.h> 0039 0040 CMapPluginStandard::CMapPluginStandard(QObject *parent) : CMapPluginBase(parent) 0041 { 0042 CMapView *view = dynamic_cast<CMapView *>(parent); 0043 CMapManager *manager = view->getManager(); 0044 KActionCollection *acol = view->actionCollection(); 0045 0046 // Create and Add the tools to the tools list 0047 toolList.append(new CMapToolSelect(acol,manager)); 0048 toolList.append(new CMapToolRoom(acol,manager)); 0049 toolList.append(new CMapToolPath(acol,manager)); 0050 toolList.append(new CMapToolText(acol,manager)); 0051 toolList.append(new CMapToolEraser(acol,manager)); 0052 0053 acol->action("toolsEraser")->setEnabled(true); 0054 acol->action("toolsPath")->setEnabled(true); 0055 acol->action("toolsRoom")->setEnabled(true); 0056 acol->action("toolsSelect")->setEnabled(true); 0057 acol->action("toolsText")->setEnabled(true); 0058 } 0059 0060 CMapPluginStandard::~CMapPluginStandard() 0061 { 0062 } 0063 0064 /** Used to get a list of the property pages for a map element */ 0065 QList<CMapPropertiesPaneBase *> CMapPluginStandard::createPropertyPanes(elementTyp type,CMapElement *element,QWidget *parent) 0066 { 0067 QList<CMapPropertiesPaneBase *> list; 0068 0069 if (type == ROOM || type == ZONE) 0070 list.append(new CMapNotesPane(this,i18n("Notes"),nullptr,type,element,parent)); 0071 0072 return list; 0073 } 0074 0075 /** This is called when the character or mud profiles change */ 0076 void CMapPluginStandard::profileChanged(void) 0077 { 0078 /* 0079 actionCollection()->action("toolsEraser")->setEnabled(true); 0080 actionCollection()->action("toolsPath")->setEnabled(true); 0081 actionCollection()->action("toolsRoom")->setEnabled(true); 0082 actionCollection()->action("toolsSelect")->setEnabled(true); 0083 actionCollection()->action("toolsText")->setEnabled(true); 0084 */ 0085 } 0086 0087 /** 0088 * This method is used to add a note or change a exsiting note 0089 * @param elemenet The element the note is for 0090 * @param note The next of the note 0091 */ 0092 void CMapPluginStandard::addNote(CMapElement *element,QString note) 0093 { 0094 if (note.isEmpty()) removeNote(element); 0095 else m_noteList[element] = note; 0096 } 0097 0098 /** This method is used to remove a note 0099 * @param element The note to remove 0100 */ 0101 void CMapPluginStandard::removeNote(CMapElement *element) 0102 { 0103 m_noteList.remove(element); 0104 } 0105 0106 /** 0107 * This method is used to get a note for the given element 0108 * @param element The element to get the note of 0109 * @return The note or empty string if there is no note 0110 */ 0111 QString CMapPluginStandard::getNote(CMapElement *element) 0112 { 0113 return m_noteList.value(element); 0114 } 0115 0116 /** This method is used to get a list of new properties for a element 0117 * It will usally be called when saving map data to file 0118 * @param element The element being saved 0119 * @param properties When method exits this should contain the new properties 0120 */ 0121 void CMapPluginStandard::saveElementProperties(CMapElement *element,KMemConfig *properties) 0122 { 0123 QString note = getNote(element); 0124 if (note.isEmpty()) return; 0125 properties->group("Properties").writeEntry("Note",note); 0126 } 0127 0128 /** This method is used to update an element with the properties load from a file 0129 * It will usally be called when loading map data to file 0130 * @param element The element being loaded 0131 * @param properties The properties being loaded from the file 0132 */ 0133 void CMapPluginStandard::loadElementProperties(CMapElement *element,KMemConfig *properties) 0134 { 0135 if (properties->group("Properties").hasKey("Note")) 0136 { 0137 QString note = properties->group("Properties").readEntry("Note",""); 0138 addNote(element,note); 0139 } 0140 } 0141 0142 /** This is called before a element is deleted 0143 * @param element The element about to be deleted */ 0144 void CMapPluginStandard::beforeElementDeleted(CMapElement *element) 0145 { 0146 QString note = getNote(element); 0147 if (note.isEmpty()) return; 0148 0149 DeletedElement e; 0150 e.type = (int)element->getElementType(); 0151 0152 if (element->getElementType() == ROOM) 0153 { 0154 e.id = ((CMapRoom *)element)->getRoomID(); 0155 e.level = element->getLevel()->getLevelID(); 0156 e.note = note; 0157 m_deletedElements.push_back(e); 0158 } 0159 0160 if (element->getElementType() == ZONE) 0161 { 0162 e.id = ((CMapZone *)element)->getZoneID(); 0163 e.note = note; 0164 m_deletedElements.push_back(e); 0165 } 0166 0167 removeNote(element); 0168 } 0169 0170 /** This method is called after undoing a delete action 0171 * @param element The elemening being restored */ 0172 void CMapPluginStandard::afterElementUndeleted(CMapElement *element) 0173 { 0174 DeletedElementList::iterator e; 0175 bool found = false; 0176 0177 if (element->getElementType() == ROOM) 0178 { 0179 e = findRoom(element->getLevel()->getLevelID(),((CMapRoom*)element)->getRoomID(),&found); 0180 } 0181 0182 if (element->getElementType()== ZONE) 0183 { 0184 e = findZone(((CMapZone*)element)->getZoneID(),&found); 0185 } 0186 0187 if (found) 0188 { 0189 addNote(element,(*e).note); 0190 m_deletedElements.erase(e); 0191 } 0192 } 0193 0194 /** 0195 * This is called when the map is about to be loaded from file 0196 */ 0197 void CMapPluginStandard::loadAboutToStart() 0198 { 0199 m_deletedElements.clear(); 0200 m_noteList.clear(); 0201 } 0202 0203 /** 0204 * This is called when the map is about to be saved to file 0205 */ 0206 void CMapPluginStandard::saveAboutToStart(void) 0207 { 0208 m_deletedElements.clear(); 0209 } 0210 0211 /** 0212 * This is called when a new map is created 0213 */ 0214 void CMapPluginStandard::newMapCreated(void) 0215 { 0216 m_deletedElements.clear(); 0217 m_noteList.clear(); 0218 } 0219 0220 0221 CMapPluginStandard::DeletedElementList::iterator CMapPluginStandard::findRoom(int level,int id,bool *found) 0222 { 0223 DeletedElementList::iterator it; 0224 for ( it = m_deletedElements.begin(); it != m_deletedElements.end(); ++it ) 0225 { 0226 if ((*it).level == level && (*it).id == id) 0227 { 0228 *found = true; 0229 return it; 0230 } 0231 } 0232 0233 return m_deletedElements.end(); 0234 } 0235 0236 CMapPluginStandard::DeletedElementList::iterator CMapPluginStandard::findZone(int id,bool *found) 0237 { 0238 DeletedElementList::iterator it; 0239 for ( it = m_deletedElements.begin(); it != m_deletedElements.end(); ++it ) 0240 { 0241 if ((*it).id == id) 0242 { 0243 *found = true; 0244 return it; 0245 } 0246 } 0247 0248 return m_deletedElements.end(); 0249 } 0250 0251 #include "moc_cmappluginstandard.cpp"