File indexing completed on 2024-10-06 07:02:27
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 DRAWZONE_H 0019 #define DRAWZONE_H 0020 0021 #include <QCursor> 0022 #include <QDragEnterEvent> 0023 #include <QDropEvent> 0024 #include <QImage> 0025 #include <QMouseEvent> 0026 #include <QPixmap> 0027 #include <QPoint> 0028 #include <QRect> 0029 #include <QResizeEvent> 0030 0031 #include "kimagemapeditor.h" 0032 0033 class Area; 0034 0035 /** 0036 *@short Draws the image and areas and handle the draw actions 0037 *@author Jan Schäfer 0038 *@internal 0039 *@see Area 0040 */ 0041 class DrawZone : public QWidget { 0042 public: 0043 0044 DrawZone(QWidget *parent,KImageMapEditor* _imageMapEditor); 0045 ~DrawZone() override; 0046 0047 QImage picture() const; 0048 void repaintArea(const Area & a); 0049 void repaintRect(const QRect & r); 0050 void cancelDrawing(); 0051 0052 void setPicture(const QImage &_image); 0053 void setZoom(double z); 0054 0055 QPoint translateFromZoom(const QPoint & p) const; 0056 QRect translateFromZoom(const QRect & p) const; 0057 QPoint translateToZoom(const QPoint & p) const; 0058 QRect translateToZoom(const QRect & p) const; 0059 0060 QRect getImageRect() const { 0061 return image.rect(); 0062 } 0063 0064 QSize sizeHint () const override; 0065 virtual QSize minimumSize () const; 0066 0067 protected: 0068 0069 void mouseDoubleClickEvent(QMouseEvent*) override; 0070 void mousePressEvent(QMouseEvent*) override; 0071 void mouseReleaseEvent(QMouseEvent*) override; 0072 void mouseMoveEvent(QMouseEvent*) override; 0073 //virtual void resizeEvent(QResizeEvent*); 0074 void paintEvent(QPaintEvent*) override;//,int,int,int,int); 0075 void dropEvent(QDropEvent*) override; 0076 void dragEnterEvent(QDragEnterEvent*) override; 0077 0078 /** 0079 * Represents whats currently going on 0080 * @li None : Nothing 0081 * @li DrawCircle : The user is drawing a circle 0082 * @li DrawRectangle : The user is drawing a rectangle 0083 * @li MoveSelectionPoint : The user is resizing an @ref Area or moving a polygon point 0084 * @li MoveArea : The user is moving an @ref Area 0085 * @li DoSelect : The user makes a selection rectangle 0086 */ 0087 enum DrawAction { 0088 None, 0089 DrawCircle, 0090 DrawRectangle, 0091 DrawPolygon, 0092 DrawFreehand, 0093 MoveSelectionPoint, 0094 MoveArea, 0095 DoSelect, 0096 RemovePoint, 0097 AddPoint 0098 }; 0099 0100 void createBorderRectangles(const QRect & r,QRect & rb,QRect & lb,QRect & tb,QRect & bb); 0101 0102 private: 0103 0104 DrawAction currentAction; 0105 // The currently drawing area 0106 Area *currentArea; 0107 // Needed when moving selectionpoints 0108 SelectionPoint* currentSelectionPoint; 0109 // The point where the user clicked the mouse 0110 QPoint drawStart; 0111 QPoint drawCurrent; 0112 QPoint drawLast; 0113 // The original image 0114 QImage image; 0115 KImageMapEditor *imageMapEditor; 0116 // Only the rect of the zoomed image, perhaps redundant 0117 QRect imageRect; 0118 // Only for repaint issues 0119 Area *oldArea; 0120 0121 QRect oldSelectionRect; 0122 // Holds the zoomed image for efficiency reasons 0123 QPixmap zoomedImage; 0124 // The current zoom-factor 0125 double _zoom; 0126 0127 QCursor rectangleCursor; 0128 QCursor circleCursor; 0129 QCursor polygonCursor; 0130 QCursor freehandCursor; 0131 QCursor addPointCursor; 0132 QCursor removePointCursor; 0133 0134 void updateCursor(QPoint); 0135 void mouseMoveSelection(QPoint); 0136 void mouseMoveDrawCircle(QPoint); 0137 0138 void mousePressNone(QMouseEvent*, QPoint startPoint, QPoint zoomedPoint); 0139 void mousePressRightNone(QMouseEvent*,QPoint); 0140 void mousePressLeftNone(QMouseEvent*, QPoint, QPoint); 0141 void mousePressLeftNoneOnArea(QMouseEvent*, Area*); 0142 void mousePressLeftNoneOnBackground(QMouseEvent*, QPoint); 0143 0144 QPoint moveIntoImage(QPoint); 0145 0146 QCursor getCursorOfToolType(KImageMapEditor::ToolType); 0147 0148 }; 0149 0150 inline QImage DrawZone::picture() const { 0151 return image; 0152 } 0153 0154 #endif // DRAWZONE_H