File indexing completed on 2023-10-03 03:28:39
0001 /*************************************************************************** 0002 cmapview.h 0003 ------------------- 0004 begin : Mon Mar 19 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 CMAPVIEW_H 0019 #define CMAPVIEW_H 0020 0021 #include <qlayout.h> 0022 0023 #include <kxmlguiwindow.h> 0024 #include <klocale.h> 0025 #include <kmuddy_export.h> 0026 0027 class QLabel; 0028 class QScrollArea; 0029 class QPushButton; 0030 class QAction; 0031 class KToggleAction; 0032 class KSelectAction; 0033 class QActionGroup; 0034 0035 class CMapWidget; 0036 class CMapManager; 0037 class CMapElement; 0038 class CMapLevel; 0039 class CMapRoom; 0040 class CMapZone; 0041 class CMapViewStatusbar; 0042 class HVBoxLayout; 0043 class CMapClipboard; 0044 0045 0046 /**This widget is used as a view of the map. 0047 *It should be create only from the map manager. 0048 *@author Kmud Developer Team 0049 */ 0050 class KMUDDY_EXPORT CMapView : public KXmlGuiWindow 0051 { 0052 Q_OBJECT 0053 0054 public: 0055 CMapView(CMapManager *manager, QWidget *parent); 0056 ~CMapView() override; 0057 0058 void initGUI(); 0059 0060 CMapWidget *getMapWidget() { return mapWidget; } 0061 CMapManager *getManager() { return mapManager; } 0062 0063 // FIXME: Follow/create mode needs to be saved/restored somewere 0064 /** Set the state of the follow combo box */ 0065 void setFollowMode(bool follow); 0066 /** Get the state of the follow combo box */ 0067 bool getFollowMode(); 0068 /** Set the state of the create combo box */ 0069 void setCreateMode(bool create); 0070 /** Get the state of the create combo box */ 0071 bool getCreateMode(); 0072 0073 /** Used to let the map manager know if it should register the focus of this widget */ 0074 virtual bool acceptFocus(); 0075 0076 /** Used to get the currently viewed zone */ 0077 virtual CMapZone *getCurrentlyViewedZone(void); 0078 /** Used to get the currently viewed level */ 0079 virtual CMapLevel *getCurrentlyViewedLevel(void); 0080 /** This method is called when the current position of the player changes */ 0081 virtual void playerPositionChanged(CMapRoom *); 0082 /** Used to set the current level. This is for internal use */ 0083 virtual void setLevel(CMapLevel *level); 0084 0085 /** Tell this map view to display a different level. view wiil 0086 * center on the first room */ 0087 void showPosition(CMapLevel *level,bool centerView=true); 0088 /** Tell this map view to display the level with a given room in it 0089 * @param room The room to center on 0090 * @param centerView used to tell center view 0091 */ 0092 void showPosition(CMapRoom *room,bool centerView=true); 0093 /** Tell this map widget to display a different zone */ 0094 virtual void showPosition(QPoint pos,CMapLevel *level,bool centerView=true); 0095 /** This method is used to set the element when that a popup menu is to be showed for */ 0096 void setSelectedElement(CMapElement *element); 0097 /** This methid is used to set the position that a element was selected when the contex menu is shown */ 0098 void setSelectedPos(QPoint pos); 0099 /** This method is used to get the element that a popup menu is being displayed for */ 0100 CMapElement *getSelectedElement(); 0101 0102 /** This method is called when an element is added */ 0103 virtual void addedElement(CMapElement *element); 0104 /** This method is called when an element is deleted */ 0105 virtual void deletedElement(CMapLevel *deletedFromLevel); 0106 /** This method is called when an element is changed */ 0107 virtual void changedElement(CMapElement *element); 0108 /** This method is called when a map level is changed */ 0109 virtual void changedLevel(CMapLevel *level); 0110 /** This method is called when something else is changed, it should trigger a repaint */ 0111 virtual void changed(); 0112 /** Asks the widget to repaint itself */ 0113 virtual void requestPaint(); 0114 /** Get the max x cord of all elements */ 0115 int getMaxX(void); 0116 /** Get the max y cord of all elements */ 0117 int getMaxY(void); 0118 0119 /** Used to find out if a element is visible in the view */ 0120 virtual bool isElementVisible(CMapElement *element); 0121 /** Used to find out if a level is visible in the view */ 0122 virtual bool isLevelVisible(CMapLevel *level); 0123 0124 /* Used to calculate the correct size for the widget */ 0125 void checkSize(QPoint pos); 0126 0127 /** This is used ensure a location is visiable for views that scroll */ 0128 virtual void ensureVisible(QPoint pos); 0129 0130 /** This will pass cursor changes to the mapWidet */ 0131 void setCursor ( const QCursor & cursor); 0132 0133 void readOptions(); 0134 0135 QActionGroup *toolGroup () { return m_toolGroup; } 0136 0137 protected: 0138 /** Used to get the width of the widget */ 0139 virtual int getWidth(void); 0140 /** Used to gt the height of the widget */ 0141 virtual int getHeight(void); 0142 void resizeEvent (QResizeEvent *) override; 0143 virtual void slotWidgetBeingClosed(); 0144 virtual void slotDockWindowClose(); 0145 void closeEvent ( QCloseEvent *e) override; 0146 /** Used to set the view to active */ 0147 void focusInEvent(QFocusEvent *e) override; 0148 0149 private slots: 0150 void slotToolsGrid(); 0151 void slotToolsLevelUp(); 0152 void slotToolsLevelDown(); 0153 void slotToolsLevelDelete(); 0154 void slotToolsZoneCreate(); 0155 void slotToolsZoneDelete(); 0156 0157 void slotViewUpperLevel(); 0158 void slotViewLowerLevel(); 0159 0160 /** Used to change the position of room/zone labels */ 0161 void slotChangeLabelPos(); 0162 /** Used to room under the point the current room */ 0163 void slotRoomSetCurrentPos(void); 0164 /** Used to room under the point the login room */ 0165 void slotRoomSetLogin(void); 0166 /** Used to set speedwalk to the room under the pointer */ 0167 void slotRoomSpeedwalkTo(void); 0168 /** Used to delete the room under the pointer */ 0169 void slotRoomDelete(void); 0170 /** Used to display the properties of the room under the pointer */ 0171 void slotRoomProperties(void); 0172 /** Used to make the path under the pointer one way */ 0173 void slotPathOneWay(void); 0174 /** Used to make the path under the pointer two way */ 0175 void slotPathTwoWay(void); 0176 /** Used to add a bend to the path under the pointer */ 0177 void slotPathAddBend(void); 0178 /** Used to delete the path segment under the pointer */ 0179 void slotPathDelBend(void); 0180 /** Used to edit the bends of the path under the pointer */ 0181 void slotPathEditBends(void); 0182 /** Used to delete the path under the pointer */ 0183 void slotPathDelete(void); 0184 /** Used to display the properties of the path under the pointer */ 0185 void slotPathProperties(void); 0186 /** Used to delete the text element under the pointer */ 0187 void slotTextDelete(void); 0188 /** Used to display the text properties of the text element under the pointer */ 0189 void slotTextProperties(void); 0190 0191 signals: 0192 void closed (); 0193 0194 private: 0195 void initMenus(); 0196 /** Used by slotToolsLevel(Up/Down) */ 0197 void levelShift(bool up); 0198 bool queryClose () override; 0199 0200 /** 0201 * Used to enable/disable the view actions 0202 * @param If true then enable the actions otherwise disable the actions 0203 */ 0204 void enableViewControls(bool enable); 0205 /** 0206 * This method is used to disable/enable mapper actions that are not done by enableViewControls() 0207 * @param If true then enable the actions otherwise disable the actions 0208 */ 0209 void enableNonViewActions(bool enabled); 0210 0211 0212 private: 0213 /** A pointer to the map manager */ 0214 CMapManager *mapManager; 0215 /** A pointer to the current level for this map widget */ 0216 CMapLevel *currentLevel; 0217 0218 /** The element that is selected ( when the right mouse button menu is show for it) */ 0219 CMapElement *m_selectedElement; 0220 /** The position that the mouse is in when the context menu is show for a element */ 0221 QPoint m_selectedPos; 0222 0223 /** This is the map clipboard used for copy and paste actions */ 0224 CMapClipboard *m_clipboard; 0225 /** Main layout */ 0226 HVBoxLayout *layout; 0227 /** A toggle button to tell the map view to follow the player. */ 0228 QPushButton *cmdFollowMode; 0229 /** A toggle button to automatically create rooms as we walk. */ 0230 QPushButton *cmdCreateMode; 0231 /** The scrolling area wrapping the map widget */ 0232 QScrollArea *scroller; 0233 /** The Widget used to draw the map */ 0234 CMapWidget *mapWidget; 0235 /** The status bar */ 0236 CMapViewStatusbar *statusbar; 0237 /** The max size of all the components */ 0238 QSize maxSize; 0239 0240 //Actions 0241 KToggleAction *m_toolsGrid; 0242 QAction *m_toolsUpLevel; 0243 QAction *m_toolsDownLevel; 0244 QAction *m_toolsDeleteLevel; 0245 QAction *m_toolsCreateZone; 0246 QAction *m_toolsDeleteZone; 0247 0248 KToggleAction *m_viewLowerLevel; 0249 KToggleAction *m_viewUpperLevel; 0250 0251 KSelectAction *labelMenu; 0252 0253 QActionGroup *m_toolGroup; 0254 0255 0256 }; 0257 0258 #endif 0259