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