File indexing completed on 2024-04-21 03:41:53

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 MAPWIDGET_H
0012 #define MAPWIDGET_H
0013 
0014 #include <QGraphicsView>
0015 
0016 #include "map.h"
0017 
0018 class QGraphicsRectItem;
0019 class QGraphicsScene;
0020 
0021 class mapWidget : public QGraphicsView
0022 {
0023 Q_OBJECT
0024     public:
0025         explicit mapWidget(QWidget *parent);
0026         
0027         void init(const QImage &mapImage);
0028 
0029         void setMapMove(bool b);
0030         void setMapZoom(bool b);
0031         
0032         QSize mapSize() const;
0033     
0034     public Q_SLOTS:
0035         void setOriginalImage();
0036         void setAutomaticZoom(bool b);
0037     
0038     Q_SIGNALS:
0039         void setMoveActionChecked(bool b);
0040         void setZoomActionChecked(bool b);
0041         void setMoveActionEnabled(bool b);
0042         void clicked(QRgb, const QPoint&, bool);
0043     
0044     protected:
0045         void mousePressEvent(QMouseEvent *e) override;
0046         void mouseMoveEvent(QMouseEvent *e) override;
0047         void mouseReleaseEvent(QMouseEvent *e) override;
0048         void wheelEvent(QWheelEvent *e) override;
0049         void resizeEvent(QResizeEvent *e) override;
0050     
0051     private:
0052         /**
0053          * Updates the move and zoom toggle states from the current mode.
0054          */
0055         void updateActions();
0056         void updateZoom();
0057         
0058         enum Mode { Zooming, WantZoom, Moving, WantMove, None };
0059         Mode p_mode, p_modeBeforeMidClick;
0060         QImage p_originalImage;
0061         QGraphicsRectItem *p_zoomRect;
0062         QGraphicsScene *p_scene;
0063         QPointF p_initial; // for rubberbanding, in scene coords
0064         QPoint p_prev; // for moving, in view coords
0065         bool p_automaticZoom;
0066 };
0067 
0068 #endif