File indexing completed on 2024-09-29 03:42:59
0001 /*************************************************************************** 0002 cmappath.h 0003 ------------------- 0004 begin : Sat Mar 10 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 #ifndef CMAPPATH_H 0019 #define CMAPPATH_H 0020 0021 #include <qrect.h> 0022 #include <QList> 0023 0024 #include "cmapelement.h" 0025 0026 #include "kmemconfig.h" 0027 #include <kconfiggroup.h> 0028 0029 class CMapRoom; 0030 0031 /**The class used to store path data 0032 *@author Kmud Developer Team 0033 */ 0034 class KMUDDY_EXPORT CMapPath : public CMapElement 0035 { 0036 public: 0037 CMapPath(CMapManager *manager,CMapRoom *srcRoom,directionTyp srcDir,CMapRoom *destRoom,directionTyp destDir, bool twoWay); 0038 CMapPath(CMapManager *manager,CMapRoom *srcRoom,CMapRoom *destRoom); 0039 ~CMapPath() override; 0040 0041 elementTyp getElementType(void) override { return PATH ; } 0042 /** This method is used to set the cords of the path */ 0043 void setCords(void); 0044 0045 bool getDone(void) { return done; } 0046 void setDone(bool set) { done = set; } 0047 0048 void paint(QPainter *p,CMapZone *zone) override; 0049 /** Used to paint the element while it is bined resized */ 0050 void resizePaint(QPoint offset,QPainter *p,CMapZone *currentZone,int resizeId) override; 0051 void dragPaint(QPoint offset,QPainter *p,CMapZone *zone) override; 0052 void lowerPaint(QPainter *p,CMapZone *zone) override; 0053 void higherPaint(QPainter *p,CMapZone *zone) override; 0054 void editPaint(QPoint pos,QPainter *p,CMapZone *,int editBox); 0055 0056 /** Used to find out if the mouse is in the element */ 0057 bool mouseInElement(QPoint mousePos) override; 0058 0059 /** Used to create a deep copy of the path */ 0060 CMapElement *copy(void) override; 0061 0062 /** Get the directions of the start and finish directions of the path */ 0063 directionTyp getSrcDir(void) { return srcDir; } 0064 directionTyp getDestDir(void) { return destDir; } 0065 0066 void setOpsitePath(CMapPath *path) { opsitePath = path; } 0067 CMapPath *getOpsitePath(void) { return opsitePath; } 0068 0069 /** Get a pointer to the destination room */ 0070 CMapRoom *getDestRoom(void) { return destRoom; } 0071 CMapRoom *getSrcRoom(void) { return srcRoom; } 0072 0073 /** Set the source direction of the path */ 0074 void setSrcDir(directionTyp SrcDir); 0075 /** Set the destination directions of the path */ 0076 void setDestDir(directionTyp DestDir); 0077 0078 /** Set a pointer to the destination room */ 0079 void setDestRoom(CMapRoom *DestRoom); 0080 /** Set a pointer to the source room */ 0081 void setSrcRoom(CMapRoom *SrcRoom); 0082 0083 void makeOneWay(); 0084 void makeTwoWay(); 0085 0086 /** Set the special exit command string */ 0087 void setSpecialCmd(QString cmd) { specialCmd = cmd; } 0088 /** Return the special exit command string */ 0089 QString getSpecialCmd(void) { return specialCmd; } 0090 0091 /** Tell the mapp if this path is a special exit */ 0092 void setSpecialExit(bool special) { bSpecialExit = special; } 0093 /** Return if this path is a special exit */ 0094 bool getSpecialExit(void) { return bSpecialExit; } 0095 0096 /** Get a list of bends in the path */ 0097 int getBendCount(void) { return bendList.count(); } 0098 /** Used to set the before walking command */ 0099 void setBeforeCommand(QString command) { beforeCommand = command; } 0100 /** Used to get the before walking commnad */ 0101 QString getBeforeCommand(void) { return beforeCommand; } 0102 /** Used to set the after walking command */ 0103 void setAfterCommand(QString command) { afterCommand = command; } 0104 /** Used to get the before walking commnad */ 0105 QString getAfterCommand(void) { return afterCommand; } 0106 0107 /** Used to load the properties of the element from a list of properties */ 0108 void loadProperties(KConfigGroup grp) override; 0109 /** Used to save the properties of the element to a list of properties */ 0110 void saveProperties(KConfigGroup grp) override; 0111 /** Used to save the element as an XML object 0112 * @param properties The XML object to save the properties too 0113 * @param doc The XML Document */ 0114 void saveQDomElement(QDomDocument *doc,QDomElement *properties) override; 0115 /** Used to load the properties from a XML object 0116 * @param properties The XML object to load the properties from */ 0117 void loadQDomElement(QDomElement *properties) override; 0118 0119 /** Used to move the element relative to it's current position */ 0120 void moveBy(QPoint offset) override; 0121 0122 /** This is overridden to stop a path be resized */ 0123 void resize(QPoint,int) override { } 0124 /** Used to find out if the mouse is in the resize box 0125 * @param mousePos The position of the mouse pointer 0126 * @param currentZone A pointer to the current zone 0127 * @return the ID of the resize box, or 0 if not in any */ 0128 int mouseInResize(QPoint mousePos,CMapZone *currentZone) override; 0129 /** 0130 * This method is used to find out if the mouse pointer is in a path segment. 0131 * @param mousePos The position of the mouse 0132 * @param currentZone The current zone being viewed 0133 * @return 0 if not in any segament, otherwise return the number of the segment 0134 */ 0135 int mouseInPathSeg(QPoint mousePos,CMapZone *currentZone); 0136 0137 /** Used to find out if the mosuse is in the edit box of the path 0138 * @param mousePos The position of the mouse pointer 0139 * @param currentZone A pointer to the current zone 0140 * @return the ID of the edit box, or 0 if not in any */ 0141 int mouseInEditBox(QPoint mousePos ,CMapZone *); 0142 0143 void setDontPaintBend(int bend); 0144 /** Used to add a bend to the path */ 0145 void addBendWithUndo(QPoint pos); 0146 /** Used to move a bend to a new position */ 0147 void moveBendWithUndo(int bend, QPoint pos); 0148 /** This method is used to delete bends from a path 0149 * @param seg The path segment number to delete */ 0150 void deletePathSegWithUndo(int seg); 0151 0152 0153 protected: 0154 void deleteBend(QPoint bend); 0155 /** Used to add a bend to the path */ 0156 int addBend(QPoint pos); 0157 /** Used to move a bend to a new position */ 0158 void moveBend(int bend, QPoint pos); 0159 /** This method is used to delete bends from a path 0160 * @param seg The path segment number to delete */ 0161 QPoint deletePathSeg(int seg); 0162 0163 /** This method is used to calculate the positions of the resize handles */ 0164 void generateResizePositions(void) override; 0165 /** Used to paint the element at a given location and size 0166 * @param p The painer to paint the element to 0167 * @param pos The position to paint the elmenet 0168 * @param size The size the element should be draw 0169 * @param zone The current zone being viewed */ 0170 void paintElementResize(QPainter *p,QPoint pos,QSize size,CMapZone *zone) override; 0171 0172 private: 0173 /** This method is used to calcualte the distance from a path segment */ 0174 int getDistance (int x,int y,int x1,int x2,int y1,int y2); 0175 directionTyp generatePath(); 0176 /** Used to draw an arrow head */ 0177 void drawArrow(directionTyp dir,QPainter *p,QPoint end); 0178 QPoint getIndent(directionTyp dir,QPoint pos); 0179 /** Used to draw the path */ 0180 void drawPath(QPainter *p,CMapZone *zone,QPoint offset,QColor color,int editBox=0,QPoint editPos=QPoint(0,0)); 0181 0182 QRect getBoundRectOfSeg(QPoint pos1,QPoint pos2); 0183 0184 private: 0185 typedef QList<QPoint> PointList; 0186 0187 /** If this is greater than 0 then the bend will not be painted */ 0188 int m_dontPaintBend; 0189 0190 /** This is used to store a tempray list of path cords */ 0191 PointList tempPathCords; 0192 0193 bool done; 0194 /** The commands of the path */ 0195 QString afterCommand,beforeCommand; 0196 /** A pointer to the path going in the opsite direction. Null if no path */ 0197 CMapPath *opsitePath; 0198 /** These are used to store the directions the path enters and leaves a room */ 0199 directionTyp srcDir,destDir; 0200 0201 /** Used to store a pointer to the desination room */ 0202 CMapRoom *destRoom,*srcRoom; 0203 0204 /** Used to flag if this is a special exit */ 0205 bool bSpecialExit; 0206 /** Used to store the special command string for a path */ 0207 QString specialCmd; 0208 0209 /** A list of bends in the path */ 0210 PointList bendList; 0211 }; 0212 0213 #endif