File indexing completed on 2024-04-14 04:16:15

0001 /***************************************************************************
0002                           imagemap.h  -  description
0003                              -------------------
0004     begin                : Wed Apr 4 2001
0005     copyright            : (C) 2001 by Jan Schäfer
0006     email                : janschaefer@users.sourceforge.net
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 IMAGEMAP_H
0019 #define IMAGEMAP_H
0020 
0021 #include <QImage>
0022 #include <QMouseEvent>
0023 #include <QPixmap>
0024 #include <QPoint>
0025 #include <QRect>
0026 #include <QResizeEvent>
0027 #include <QScrollArea>
0028 
0029 /**
0030   *@author Jan Schäfer
0031   */
0032 class KImageMapEditor;
0033 class Area;
0034 
0035 class ImageMap : public QScrollArea  {
0036 public:
0037     enum DrawAction { None, DrawCircle, DrawRectangle, DrawPolygon, MoveSelectionPoint, MoveArea };
0038 private:
0039     QRect imageRect;
0040     QPoint drawStart;
0041     QPoint drawCurrent;
0042     QPoint drawEnd;
0043     bool eraseOldArea;
0044     Area *oldArea;
0045     // Holds the original image
0046     QImage image;
0047     // Holds the zoomed image for efficiency reasons
0048     QPixmap zoomedImage;
0049     Area *currentArea;
0050     DrawAction currentAction;
0051     QRect *currentSelectionPoint;
0052     KImageMapEditor *imageMapEditor;
0053     double _zoom;
0054 public:
0055     ImageMap(QWidget *parent,KImageMapEditor* _imageMapEditor);
0056     ~ImageMap();
0057     void setZoom(double z);
0058     void setPicture(const QImage &_image);
0059     void repaintArea(const Area & a);
0060     QImage picture() const;
0061     QPoint translateFromZoom(const QPoint & p) const;
0062     QPoint translateToZoom(const QPoint & p) const;
0063     QRect translateToZoom(const QRect & p) const;
0064 protected:
0065     virtual void mousePressEvent(QMouseEvent* e);
0066     virtual void mouseDoubleClickEvent(QMouseEvent* e);
0067     virtual void mouseReleaseEvent(QMouseEvent *e);
0068     virtual void mouseMoveEvent(QMouseEvent *e);
0069     virtual void resizeEvent(QResizeEvent* e);
0070     virtual void drawContents(QPainter* p,int clipx,int clipy,int clipw,int cliph);
0071 };
0072 
0073 inline QImage ImageMap::picture() const {
0074     return image;
0075 }
0076 
0077 
0078 #endif