File indexing completed on 2024-12-01 06:51:45
0001 /*************************************************************************** 0002 cmaptext.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 CMAPTEXT_H 0019 #define CMAPTEXT_H 0020 0021 #include "cmapelement.h" 0022 0023 /**The class used to store text data 0024 *@author Kmud Developer Team 0025 */ 0026 0027 class QString; 0028 class QStringList; 0029 class QColor; 0030 class QFont; 0031 class QPoint; 0032 0033 #include "kmemconfig.h" 0034 0035 class KMUDDY_EXPORT CMapText : public CMapElement 0036 { 0037 public: 0038 CMapText(QString str,QFont f,QColor col,CMapManager *manager,QPoint pos,CMapLevel *level); 0039 CMapText(QString str,CMapManager *manager,QPoint pos,CMapLevel *level); 0040 ~CMapText() override; 0041 0042 elementTyp getElementType(void) override { return TEXT ; } 0043 void setLevel(CMapLevel *level) override; 0044 0045 /** Sets the text of the text element 0046 * @param str The new string that the text element should be set to 0047 */ 0048 void setText(QString str); 0049 /** Gets the text of the text element 0050 * @return The text 0051 */ 0052 QString getText(void); 0053 /** Used to set the font of the text. This font is used when drawing the text. 0054 * @param f The required font of the text 0055 */ 0056 void setFont(QFont f); 0057 /** This menthod will return the font used to display the text 0058 * @return The font used to display text 0059 */ 0060 QFont getFont(void); 0061 /** This is used to return the color of the text 0062 * @return The color of the text 0063 */ 0064 QColor getColor(void); 0065 /** This method is used to set the color of the text 0066 * @param color The color to set the text to 0067 */ 0068 void setColor(QColor color); 0069 0070 /** Used to paint the text on the map 0071 * @param p The painter used to paint the text 0072 * @param zone The zone the text is being painted in 0073 */ 0074 void paint(QPainter *p,CMapZone *zone) override; 0075 void dragPaint(QPoint offset,QPainter *p,CMapZone *zone) override; 0076 void lowerPaint(QPainter *p,CMapZone *zone) override; 0077 void higherPaint(QPainter *p,CMapZone *zone) override; 0078 0079 /** This is used to create a new copy of the text element and return 0080 * a pointer to the new text element 0081 * @return A pointer to the copy of the text element. 0082 */ 0083 CMapElement *copy(void) override; 0084 0085 void setLinkElement (CMapElement *element) { m_linkElement = element; } 0086 CMapElement *getLinkElement(void) { return m_linkElement; } 0087 void updateLinkElements(void); 0088 0089 /** This is used to set the cursor position within the text element 0090 * @param pos The cursor position 0091 */ 0092 void setCursor(QPoint pos); 0093 /** This is used to return the color of the text 0094 * @return The color of the text 0095 */ 0096 QPoint getCursor(void); 0097 /** This is used to return the actual cords in the view of the cursor 0098 * @return the cords */ 0099 QPoint getCursorCords(void); 0100 /** Move the cursor left */ 0101 void cursorLeft(void); 0102 /** Move the cursor right */ 0103 void cursorRight(void); 0104 /** Move the cursor up */ 0105 void cursorUp(void); 0106 /** Move the cursor down */ 0107 void cursorDown(void); 0108 /** Move the cursor to the end */ 0109 void cursorEnd(void); 0110 /** this will insert a caridge return at the cursor */ 0111 void insertCR(void); 0112 /** This will delete a character behind the cursor */ 0113 void deleteChar(void); 0114 /** This will delete a character infront of the cursor */ 0115 void backspace(void); 0116 0117 /** Used to load the properties of the element from a list of properties 0118 * @param properties The properties to load into the element */ 0119 void loadProperties(KConfigGroup properties) override; 0120 /** Used to save the properties of the element to a list of properties 0121 * @param properties The properties to load into the element */ 0122 void saveProperties(KConfigGroup properties) override; 0123 /** Used to save the element as an XML object 0124 * @param properties The XML object to save the properties too 0125 * @param doc The XML Document */ 0126 void saveQDomElement(QDomDocument *doc,QDomElement *properties) override; 0127 /** Used to load the properties from a XML object 0128 * @param properties The XML object to load the properties from */ 0129 void loadQDomElement(QDomElement *properties) override; 0130 0131 /** This is used to convert mouse cordinates into a cursor position 0132 * @param mousePos The position of the mose */ 0133 QPoint convertPosToCursor(QPoint mousePos); 0134 /** This is used to conver a offset from the element orgin into a cursor position 0135 * @param offset The offset of the curosr */ 0136 QPoint convertOffsetToCursor(QPoint offset); 0137 0138 /** This method is called to insert a string at the cursor position 0139 * @param s The string to insert */ 0140 void insertString(QString s); 0141 /** This method is called to restore the orginal text of the element. When editing, if 0142 * esc is pressed, then this method is called to restore the text to the value it had 0143 * before editing */ 0144 void restoreText(void); 0145 0146 /** This is used to convert a Actual size to it's closet font size 0147 * @param size The actual size of the font 0148 * @param font The text font 0149 * @return The closet matching font size */ 0150 static int getActualToFontSize(QSize size,QFont font,QStringList *text); 0151 /** This is used to paint the text. It is capable of painting multiline 0152 * of text. It is static so that it can be called with out creating a instance of CMapText 0153 * @param p The painter used to paint the text 0154 * @param col The color to paint the text 0155 * @param pos The position to paint the text 0156 * @param font The Font used to paint the text 0157 * @param text A point to the text list 0158 * @param size The size of the text */ 0159 static void paintText(QPainter *p,QColor col,QPoint pos,QFont font,QStringList *text,QSize size); 0160 /** This method is used to convert a text string into a text list 0161 * @param str The string of text 0162 * @param textList The list to add the text to 0163 */ 0164 static void stringToList(QString str,QStringList *textList); 0165 /** This is used to get a unique ID for the text */ 0166 unsigned int getTextID(void) { return m_ID; } 0167 /** This is used to set the ID of the text */ 0168 void setTextID(unsigned int id); 0169 0170 0171 protected: 0172 /** This method is called when the element looses it's edit mode */ 0173 void editModeUnsetEvent(void) override; 0174 /** This method is called when the element gains it's edit mode */ 0175 void editModeSetEvent(void) override; 0176 /** Used to paint the element at a given location and size 0177 * @param p The painer to paint the element to 0178 * @param pos The position to paint the elmenet 0179 * @param size The size the element should be draw 0180 * @param zone The current zone being viewed */ 0181 void paintElementResize(QPainter *p,QPoint pos,QSize size,CMapZone *zone) override; 0182 0183 private: 0184 /** This used internaly to calculate the offset of the cursor */ 0185 void setActualCursorPosition(void); 0186 /** This is used to paint the text. It is capable of painting multiline 0187 * of text. It is static so that it can be called with out creating a instance of CMapText 0188 * @param p The painter used to paint the text 0189 * @param col The color to paint the text 0190 * @param pos The position to paint the text 0191 * @param font The Font used to paint the text 0192 * @param text A point to the text list */ 0193 static void paintText(QPainter *p,QColor col,QPoint pos,QFont font,QStringList *text); 0194 /** This method is used to update the size of the text element */ 0195 void setTextSize(void); 0196 0197 private: 0198 QString m_orgText; 0199 QColor m_col; 0200 QStringList m_text; 0201 QFont m_font; 0202 CMapElement *m_linkElement; 0203 QPoint m_cursorPos; 0204 QPoint m_cursorOffset; 0205 unsigned int m_ID; 0206 }; 0207 0208 #endif