File indexing completed on 2024-12-08 06:46:41

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