File indexing completed on 2023-10-03 03:28:39
0001 /*************************************************************************** 0002 cmapwidget.h 0003 ------------------- 0004 begin : Sun Mar 18 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 CMAPWIDGET_H 0019 #define CMAPWIDGET_H 0020 0021 #include <QWidget> 0022 #include <QMenu> 0023 0024 #include <kaction.h> 0025 #include <klocale.h> 0026 0027 0028 class CMapManager; 0029 class CMapElement; 0030 class CMapLevel; 0031 class CMapView; 0032 0033 /**This is that map widget used for displaying a view of the map 0034 *@author Kmud Developer Team 0035 */ 0036 class CMapWidget : public QWidget 0037 { 0038 Q_OBJECT 0039 public: 0040 CMapWidget(CMapView *view,CMapManager *manager,QWidget *parent=nullptr); 0041 ~CMapWidget() override; 0042 0043 /** Used to get the views */ 0044 CMapView *getView(void); 0045 0046 protected: 0047 /** This is used to display custop tooltips. */ 0048 bool event (QEvent *e) override; 0049 /** This is called when the mouse leaves the widget */ 0050 void leaveEvent(QEvent *e) override; 0051 /** This is called when the mouse enters the widget */ 0052 void enterEvent(QEvent *e) override; 0053 /** draw the map widget */ 0054 void paintEvent(QPaintEvent *) override; 0055 /** The mouse release event */ 0056 void mouseReleaseEvent(QMouseEvent *e) override; 0057 /** The mouse press event */ 0058 void mousePressEvent(QMouseEvent *e) override; 0059 /** Called when the mouse is being moved */ 0060 void mouseMoveEvent(QMouseEvent *e) override; 0061 /** double click event */ 0062 void mouseDoubleClickEvent(QMouseEvent *e) override; 0063 /** Called when a key is pressed */ 0064 void keyPressEvent(QKeyEvent *e) override; 0065 /** Called when a key is released */ 0066 void keyReleaseEvent(QKeyEvent *e) override; 0067 0068 /** Used to display the text context menu */ 0069 void showTextContextMenu(void); 0070 /** Used to display the path context menu */ 0071 void showPathContextMenu(void); 0072 /** Used to display the Room context menu */ 0073 void showRoomContextMenu(void); 0074 /** Used to display the context menu for other / no elements */ 0075 void showOtherContextMenu(void); 0076 void showContextMenu(QMenu *menu); 0077 0078 /** Draw the map elements */ 0079 virtual void drawElements(QPainter *p); 0080 /** Draw the grid if it's visible */ 0081 virtual void drawGrid(QPainter* p); 0082 0083 private: 0084 /** Show the context menus */ 0085 void showContexMenu(QMouseEvent *e); 0086 /** Used to create the element context menus */ 0087 void initContexMenus(void); 0088 /** This method is used to tell the plugins a menu is about to open then open the menu */ 0089 void popupMenu(CMapElement *element,QMenu *menu,QPoint pos); 0090 friend class CMapView; 0091 private: 0092 QPoint selectedPos; 0093 /** true when the map is being moved by mouse */ 0094 bool bMouseDrag; 0095 /** y position of last mouse drag event */ 0096 int nMouseDragPosY; 0097 /** x position of last mouse drag event */ 0098 int nMouseDragPosX; 0099 /** The Cursor used when move draging the map */ 0100 QCursor* mouseDragCursor; 0101 0102 // Menus 0103 QMenu *room_menu; 0104 QMenu *path_menu; 0105 QMenu *text_menu; 0106 QMenu *empty_menu; 0107 0108 /** A pointer to the map manager */ 0109 CMapManager *mapManager; 0110 /** A pointer to the mapview */ 0111 CMapView *viewWidget; 0112 }; 0113 0114 #endif