File indexing completed on 2024-04-14 03:40:31
0001 /*************************************************************************** 0002 * Copyright (C) 2004-2007 by Albert Astals Cid * 0003 * aacid@kde.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #ifndef PLACEMAPWIDGET_H 0012 #define PLACEMAPWIDGET_H 0013 0014 #include <QGraphicsView> 0015 0016 #include "map.h" 0017 0018 class QGraphicsRectItem; 0019 class QGraphicsScene; 0020 0021 class placeMapWidget : public QGraphicsView 0022 { 0023 Q_OBJECT 0024 public: 0025 explicit placeMapWidget(QWidget *parent); 0026 ~placeMapWidget(); 0027 0028 void init(KGmap *map, QImage* mapImage); 0029 0030 void setMapMove(bool b); 0031 void setMapZoom(bool b); 0032 0033 void setCurrentDivisionImage(QImage *divisionImage); 0034 void placeDivision(QRect& position); 0035 QSize mapSize() const; 0036 0037 size_t nbPixels(int pixelIndex) const; 0038 size_t nbBorderPixels(int pixelIndex1, int pixelIndex2) const; 0039 const QVector<uchar> outerPixelIndices() const { return p_outerPixelIndices;} 0040 0041 public Q_SLOTS: 0042 void setGameImage(); 0043 void setAutomaticZoom(bool b); 0044 0045 Q_SIGNALS: 0046 void setMoveActionChecked(bool b); 0047 void setZoomActionChecked(bool b); 0048 void setMoveActionEnabled(bool b); 0049 // color, widget position and map position 0050 void clicked(QRgb, const QPoint&, const QPointF &); 0051 0052 protected: 0053 void mousePressEvent(QMouseEvent *e) override; 0054 void mouseMoveEvent(QMouseEvent *e) override; 0055 void mouseReleaseEvent(QMouseEvent *e) override; 0056 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 0057 void enterEvent(QEnterEvent *e) override; 0058 #else 0059 void enterEvent(QEvent *e) override; 0060 #endif 0061 void leaveEvent(QEvent *e) override; 0062 void wheelEvent(QWheelEvent *e) override; 0063 void resizeEvent(QResizeEvent *e) override; 0064 void createGameMapImage(); 0065 void updateCursor(); 0066 0067 private: 0068 0069 /** 0070 * Updates the move and zoom toggle states from the current mode. 0071 */ 0072 void updateActions(); 0073 void updateZoom(); 0074 0075 enum Mode { Zooming, WantZoom, Moving, WantMove, None }; 0076 Mode p_mode, p_modeBeforeMidClick; 0077 KGmap *p_map; 0078 QImage *p_mapImage; 0079 QImage *p_gameImage; 0080 QImage *p_currentDivisionImage; 0081 QCursor *p_currentCursor; 0082 QGraphicsRectItem *p_zoomRect; 0083 QGraphicsScene *p_scene; 0084 QPointF p_initial; // for rubberbanding, in scene coords 0085 QPoint p_prev; // for moving, in view coords 0086 bool p_automaticZoom; 0087 QGraphicsPixmapItem *p_currentDivisionItem; 0088 QPoint lastMouseEvent; // to first show the division under the mouse 0089 0090 QVector<uchar> p_outerPixelIndices; 0091 QVector<size_t> p_pixelsStats; // how many pixels have given indexed val 0092 QVector<size_t> p_bordersStats;// how many border-like pixels have indexed vals pair 0093 }; 0094 0095 #endif