1 | /*************************************************************************** |
2 | imagemap.h - description |
3 | ------------------- |
4 | begin : Wed Apr 4 2001 |
5 | copyright : (C) 2001 by Jan Schäfer |
6 | email : janschaefer@users.sourceforge.net |
7 | ***************************************************************************/ |
8 | |
9 | /*************************************************************************** |
10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation; either version 2 of the License, or * |
14 | * (at your option) any later version. * |
15 | * * |
16 | ***************************************************************************/ |
17 | |
18 | #ifndef DRAWZONE_H |
19 | #define DRAWZONE_H |
20 | |
21 | #include <qimage.h> |
22 | #include <qpoint.h> |
23 | #include <qrect.h> |
24 | #include <qcursor.h> |
25 | //Added by qt3to4: |
26 | #include <QMouseEvent> |
27 | #include <QDragEnterEvent> |
28 | #include <QPixmap> |
29 | #include <QResizeEvent> |
30 | #include <QDropEvent> |
31 | |
32 | #include "kdeversion.h" |
33 | |
34 | #include "kimagemapeditor.h" |
35 | |
36 | class Area; |
37 | |
38 | /** |
39 | *@short Draws the image and areas and handle the draw actions |
40 | *@author Jan Schäfer |
41 | *@internal |
42 | *@see Area |
43 | */ |
44 | class DrawZone : public QWidget { |
45 | public: |
46 | |
47 | DrawZone(QWidget *parent,KImageMapEditor* _imageMapEditor); |
48 | ~DrawZone(); |
49 | |
50 | QImage picture() const; |
51 | void repaintArea(const Area & a); |
52 | void repaintRect(const QRect & r); |
53 | void cancelDrawing(); |
54 | |
55 | void setPicture(const QImage &_image); |
56 | void setZoom(double z); |
57 | |
58 | QPoint translateFromZoom(const QPoint & p) const; |
59 | QRect translateFromZoom(const QRect & p) const; |
60 | QPoint translateToZoom(const QPoint & p) const; |
61 | QRect translateToZoom(const QRect & p) const; |
62 | |
63 | QRect getImageRect() const { |
64 | return image.rect(); |
65 | } |
66 | |
67 | virtual QSize sizeHint () const; |
68 | virtual QSize minimumSize () const; |
69 | |
70 | protected: |
71 | |
72 | virtual void mouseDoubleClickEvent(QMouseEvent*); |
73 | virtual void mousePressEvent(QMouseEvent*); |
74 | virtual void mouseReleaseEvent(QMouseEvent*); |
75 | virtual void mouseMoveEvent(QMouseEvent*); |
76 | //virtual void resizeEvent(QResizeEvent*); |
77 | virtual void paintEvent(QPaintEvent*);//,int,int,int,int); |
78 | virtual void dropEvent(QDropEvent*); |
79 | virtual void dragEnterEvent(QDragEnterEvent*); |
80 | |
81 | /** |
82 | * Represents whats currently going on |
83 | * @li None : Nothing |
84 | * @li DrawCircle : The user is drawing a circle |
85 | * @li DrawRectangle : The user is drawing a rectangle |
86 | * @li MoveSelectionPoint : The user is resizing an @ref Area or moving a polygon point |
87 | * @li MoveArea : The user is moving an @ref Area |
88 | * @li DoSelect : The user makes a selection rectangle |
89 | */ |
90 | enum DrawAction { |
91 | None, |
92 | DrawCircle, |
93 | DrawRectangle, |
94 | DrawPolygon, |
95 | DrawFreehand, |
96 | MoveSelectionPoint, |
97 | MoveArea, |
98 | DoSelect, |
99 | RemovePoint, |
100 | AddPoint |
101 | }; |
102 | |
103 | void createBorderRectangles(const QRect & r,QRect & rb,QRect & lb,QRect & tb,QRect & bb); |
104 | |
105 | private: |
106 | |
107 | DrawAction currentAction; |
108 | // The currently drawing area |
109 | Area *currentArea; |
110 | // Needed when moving selectionpoints |
111 | SelectionPoint* currentSelectionPoint; |
112 | // The point where the user clicked the mouse |
113 | QPoint drawStart; |
114 | QPoint drawCurrent; |
115 | QPoint drawLast; |
116 | // The original image |
117 | QImage image; |
118 | KImageMapEditor *imageMapEditor; |
119 | // Only the rect of the zoomed image, perhaps redundant |
120 | QRect imageRect; |
121 | // Only for repaint issues |
122 | Area *oldArea; |
123 | |
124 | QRect oldSelectionRect; |
125 | // Holds the zoomed image for efficiency reasons |
126 | QPixmap zoomedImage; |
127 | // The current zoom-factor |
128 | double _zoom; |
129 | |
130 | QCursor rectangleCursor; |
131 | QCursor circleCursor; |
132 | QCursor polygonCursor; |
133 | QCursor freehandCursor; |
134 | QCursor addPointCursor; |
135 | QCursor removePointCursor; |
136 | |
137 | void updateCursor(QPoint); |
138 | void mouseMoveSelection(QPoint); |
139 | void mouseMoveDrawCircle(QPoint); |
140 | |
141 | void mousePressNone(QMouseEvent*, QPoint startPoint, QPoint zoomedPoint); |
142 | void mousePressRightNone(QMouseEvent*,QPoint); |
143 | void mousePressLeftNone(QMouseEvent*, QPoint, QPoint); |
144 | void mousePressLeftNoneOnArea(QMouseEvent*, Area*); |
145 | void mousePressLeftNoneOnBackground(QMouseEvent*, QPoint); |
146 | |
147 | QPoint moveIntoImage(QPoint); |
148 | |
149 | QCursor getCursorOfToolType(KImageMapEditor::ToolType); |
150 | |
151 | }; |
152 | |
153 | inline QImage DrawZone::picture() const { |
154 | return image; |
155 | } |
156 | |
157 | #endif // DRAWZONE_H |
158 | |