1 | /*************************************************************************** |
2 | imagemapeditor.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 KIMAGEMAPEDITOR_H |
19 | #define KIMAGEMAPEDITOR_H |
20 | |
21 | #include <QDockWidget> |
22 | #include <QLinkedList> |
23 | #include <QObject> |
24 | #include <QHash> |
25 | #include <QImage> |
26 | #include <QPixmap> |
27 | #include <QTextStream> |
28 | |
29 | #include <kurl.h> |
30 | #include <kparts/part.h> |
31 | #include <kparts/browserextension.h> |
32 | #include <kparts/factory.h> |
33 | |
34 | #include <kdeversion.h> |
35 | |
36 | #include "kimearea.h" |
37 | |
38 | /** |
39 | *@author Jan Schaefer |
40 | */ |
41 | |
42 | // #define WITH_TABWIDGET |
43 | |
44 | |
45 | class QTreeWidget; |
46 | class DrawZone; |
47 | class QTreeWidgetItem; |
48 | class KToggleAction; |
49 | class KXmlGuiWindow; |
50 | |
51 | |
52 | |
53 | /** |
54 | * Stores an area tag and all its attributes |
55 | */ |
56 | typedef QHash<QString,QString> AreaTag; |
57 | |
58 | /** |
59 | * Stores an image tag and all its attributes |
60 | * the origcode attribute hold the original htmlcode |
61 | * of this tag |
62 | */ |
63 | typedef QHash<QString,QString> ImageTag; |
64 | |
65 | /** |
66 | * Only a small class to give a list of AreaTags a name |
67 | */ |
68 | class MapTag : public QLinkedList<AreaTag> { |
69 | public: |
70 | MapTag(); |
71 | QString name; |
72 | bool modified; |
73 | }; |
74 | |
75 | |
76 | class HtmlElement { |
77 | public: |
78 | HtmlElement(const QString & s) { |
79 | htmlCode = s; |
80 | }; |
81 | virtual ~HtmlElement() {} |
82 | ; |
83 | QString htmlCode; |
84 | }; |
85 | |
86 | class HtmlMapElement : public HtmlElement { |
87 | public: |
88 | explicit HtmlMapElement(const QString & s) : HtmlElement(s) { |
89 | mapTag = 0L; |
90 | }; |
91 | |
92 | virtual ~HtmlMapElement() {}; |
93 | |
94 | MapTag* mapTag; |
95 | }; |
96 | |
97 | class HtmlImgElement : public HtmlElement { |
98 | public: |
99 | HtmlImgElement(const QString & s) : HtmlElement(s) { |
100 | imgTag = 0L; |
101 | }; |
102 | virtual ~HtmlImgElement() {} |
103 | ; |
104 | ImageTag* imgTag; |
105 | }; |
106 | |
107 | /** |
108 | * Stores the hole HTML content in a List. |
109 | */ |
110 | typedef QList<HtmlElement*> HtmlContent; |
111 | |
112 | |
113 | class KSelectAction; |
114 | class KAction; |
115 | class KRecentFilesAction; |
116 | class KAction; |
117 | ///class QListViewItem; |
118 | class KUndoStack; |
119 | class KApplication; |
120 | class QTabWidget; |
121 | class AreaListView; |
122 | class ImagesListView; |
123 | class MapsListView; |
124 | class KAboutData; |
125 | |
126 | // needed by the statusbar |
127 | #define STATUS_CURSOR 1000 |
128 | #define STATUS_SELECTION 1001 |
129 | |
130 | class KImageMapEditor : public KParts::ReadWritePart { |
131 | Q_OBJECT |
132 | public : |
133 | enum ToolType { Selection, |
134 | Rectangle, |
135 | Circle, |
136 | Polygon, |
137 | Freehand, |
138 | AddPoint, |
139 | RemovePoint }; |
140 | |
141 | KImageMapEditor(QWidget *parentWidget, |
142 | QObject *parent, const QStringList & args = QStringList()); |
143 | virtual ~KImageMapEditor(); |
144 | |
145 | static KAboutData *createAboutData(); |
146 | static KConfig *config(); |
147 | |
148 | /** |
149 | * Makes sure, that the actions cut, copy, delete and |
150 | * show properties |
151 | * can only be executed if sth. is selected. |
152 | **/ |
153 | void updateActionAccess(); |
154 | |
155 | DrawZone* getDrawZone() { |
156 | return drawZone; |
157 | }; |
158 | |
159 | void addAreaAndEdit(Area*); |
160 | void addArea(Area*); |
161 | AreaListIterator areaList() const; |
162 | KImageMapEditor::ToolType currentToolType() const; |
163 | void deleteSelected(); |
164 | void deleteArea( Area * area); |
165 | void deleteAllAreas(); |
166 | void deselectAll(); |
167 | void deselect(Area* s); |
168 | void deselectWithoutUpdate(Area*); |
169 | QString getHTMLImageMap() const; |
170 | Area* onArea(const QPoint & p) const; |
171 | QPixmap makeListViewPix(Area &) ; |
172 | QString mapName() const; |
173 | void select(Area*); |
174 | void selectWithoutUpdate(Area*); |
175 | void select(QTreeWidgetItem*); |
176 | AreaSelection* selected() const; |
177 | void setPicture(const QImage & pix); |
178 | int showTagEditor(Area *); |
179 | KUndoStack *commandHistory() const; |
180 | |
181 | KApplication* app() const; |
182 | |
183 | // Only refreshes the listView |
184 | void updateSelection() const; |
185 | |
186 | void readConfig(); |
187 | void writeConfig(); |
188 | |
189 | virtual void readProperties(const KConfigGroup &); |
190 | virtual void saveProperties(KConfigGroup &); |
191 | using KParts::ReadWritePart::closeUrl; |
192 | virtual bool closeUrl(); |
193 | bool queryClose(); |
194 | virtual void setReadWrite(bool); |
195 | QString getHtmlCode(); |
196 | |
197 | /** |
198 | * Reimplemented to disable and enable Save action |
199 | */ |
200 | virtual void setModified(bool); |
201 | |
202 | /** |
203 | * Opens the given file. |
204 | * If it's an HTML file openURL is called |
205 | * If it's an Image, the image is added to the image list |
206 | */ |
207 | void openFile(const KUrl &); |
208 | |
209 | /** |
210 | * Opens the last URL the user worked with. |
211 | * Sets also, the last map and the last image |
212 | */ |
213 | void openLastURL(const KConfigGroup &); |
214 | |
215 | void readConfig(const KConfigGroup &); |
216 | void writeConfig(KConfigGroup &); |
217 | |
218 | |
219 | protected: |
220 | void init(); |
221 | bool openHTMLFile(const KUrl &); |
222 | void saveImageMap(const KUrl &); |
223 | |
224 | /** |
225 | * Returns a language dependent background picture, with |
226 | * the text : Drop an image or html file |
227 | */ |
228 | QImage getBackgroundImage(); |
229 | |
230 | |
231 | /** |
232 | * Saves information to restore the last working state |
233 | */ |
234 | void saveLastURL(KConfigGroup&); |
235 | |
236 | |
237 | private: |
238 | // Stores the hole html file in a List |
239 | // The entries are either a MapTag an ImageTag or a QString |
240 | HtmlContent _htmlContent; |
241 | |
242 | // the url of the working image; |
243 | KUrl _imageUrl; |
244 | QString _mapName; |
245 | QImage _backgroundImage; |
246 | |
247 | bool backupFileCreated; |
248 | |
249 | KImageMapEditor::ToolType _currentToolType; |
250 | AreaList *areas; |
251 | AreaSelection *currentSelected; |
252 | AreaSelection *copyArea; |
253 | Area *defaultArea; |
254 | DrawZone* drawZone; |
255 | QTabWidget* tabWidget; |
256 | AreaListView *areaListView; |
257 | ImagesListView* imagesListView; |
258 | MapsListView* mapsListView; |
259 | HtmlMapElement* currentMapElement; |
260 | |
261 | // |
262 | // Actions |
263 | // |
264 | KSelectAction* zoomAction; |
265 | KAction *arrowAction; |
266 | KAction *circleAction; |
267 | KAction *rectangleAction; |
268 | KAction *polygonAction; |
269 | KAction *freehandAction; |
270 | KAction *addPointAction; |
271 | KAction *removePointAction; |
272 | |
273 | KAction *cutAction; |
274 | KAction *deleteAction; |
275 | KAction *copyAction; |
276 | KAction *pasteAction; |
277 | KAction *zoomInAction; |
278 | KAction *zoomOutAction; |
279 | |
280 | KAction *mapNewAction; |
281 | KAction *mapDeleteAction; |
282 | KAction *mapNameAction; |
283 | KAction *mapDefaultAreaAction; |
284 | |
285 | KAction *imageAddAction; |
286 | KAction *imageRemoveAction; |
287 | KAction *imageUsemapAction; |
288 | |
289 | KToggleAction *highlightAreasAction; |
290 | KToggleAction *showAltAction; |
291 | |
292 | KAction *areaPropertiesAction; |
293 | |
294 | KAction *moveLeftAction; |
295 | KAction *moveRightAction; |
296 | KAction *moveUpAction; |
297 | KAction *moveDownAction; |
298 | |
299 | KAction *increaseWidthAction; |
300 | KAction *decreaseWidthAction; |
301 | KAction *increaseHeightAction; |
302 | KAction *decreaseHeightAction; |
303 | |
304 | KAction *toFrontAction; |
305 | KAction *toBackAction; |
306 | KAction *forwardOneAction; |
307 | KAction *backOneAction; |
308 | |
309 | KToggleAction* configureShowAreaListAction; |
310 | KToggleAction* configureShowMapListAction; |
311 | KToggleAction* configureShowImageListAction; |
312 | |
313 | |
314 | KRecentFilesAction* recentFilesAction; |
315 | |
316 | KXmlGuiWindow *mainWindow; |
317 | QDockWidget* areaDock; |
318 | QDockWidget* mapsDock; |
319 | QDockWidget* imagesDock; |
320 | |
321 | KUndoStack *_commandHistory; |
322 | int maxAreaPreviewHeight; |
323 | |
324 | QString cursorStatusText; |
325 | QString selectionStatusText; |
326 | |
327 | void setupActions(); |
328 | void setupStatusBar(); |
329 | void updateStatusBar(); |
330 | /* refreshes all Areas, only used by preferences dialog |
331 | * updates only the preview pictures*/ |
332 | void updateAllAreas(); |
333 | void updateUpDownBtn(); |
334 | |
335 | QHash<QString,QString> getTagAttributes(QTextStream & s,QString &); |
336 | |
337 | void setMap(HtmlMapElement*); |
338 | void setMap(MapTag*); |
339 | void addMap(const QString &); |
340 | |
341 | // Returns the entire html file as a String |
342 | HtmlElement* findHtmlElement(const QString &); |
343 | HtmlImgElement* findHtmlImgElement(ImageTag*); |
344 | HtmlMapElement* findHtmlMapElement(const QString &); |
345 | void deleteAllMaps(); |
346 | void addImage(const KUrl &); |
347 | void setImageActionsEnabled(bool); |
348 | void setMapActionsEnabled(bool); |
349 | |
350 | void saveAreasToMapTag(MapTag*); |
351 | void (const QPoint &, const QString &); |
352 | void drawToCenter(QPainter* p, const QString & str, int y, int width); |
353 | |
354 | public slots: |
355 | virtual bool openURL(const KUrl & url); |
356 | void slotChangeStatusCoords(int x,int y); |
357 | void slotUpdateSelectionCoords(); |
358 | void slotUpdateSelectionCoords( const QRect &); |
359 | void slotAreaChanged(Area *); |
360 | void slotShowMainPopupMenu(const QPoint &); |
361 | void (const QPoint &); |
362 | void (const QPoint &); |
363 | void slotConfigChanged(); |
364 | void setPicture(const KUrl & url); |
365 | void setMap(const QString &); |
366 | void setMapName(const QString & s); |
367 | |
368 | |
369 | protected slots: |
370 | // overridden from KReadWritePart |
371 | virtual bool openFile(); |
372 | |
373 | virtual bool saveFile() { |
374 | saveImageMap( url() ); |
375 | // setModified(false); |
376 | return true; |
377 | } |
378 | |
379 | void fileOpen(); |
380 | void fileSaveAs(); |
381 | void fileSave(); |
382 | void fileClose(); |
383 | |
384 | void (const QPoint &); |
385 | void slotShowPreferences(); |
386 | void slotHighlightAreas(bool b); |
387 | void slotShowAltTag(bool b); |
388 | void slotSelectionChanged(); |
389 | |
390 | int showTagEditor(QTreeWidgetItem *item); |
391 | int showTagEditor(); |
392 | |
393 | void slotZoom(); |
394 | void slotZoomIn(); |
395 | void slotZoomOut(); |
396 | |
397 | void slotCut(); |
398 | void slotCopy(); |
399 | void slotPaste(); |
400 | void slotDelete(); |
401 | |
402 | void slotDrawArrow(); |
403 | void slotDrawCircle(); |
404 | void slotDrawRectangle(); |
405 | void slotDrawPolygon(); |
406 | void slotDrawFreehand(); |
407 | void slotDrawAddPoint(); |
408 | void slotDrawRemovePoint(); |
409 | |
410 | void mapDefaultArea(); |
411 | void mapNew(); |
412 | void mapDelete(); |
413 | void mapEditName(); |
414 | void mapShowHTML(); |
415 | void mapPreview(); |
416 | |
417 | void slotBackOne(); |
418 | void slotForwardOne(); |
419 | void slotToBack(); |
420 | void slotToFront(); |
421 | |
422 | void slotMoveUp(); |
423 | void slotMoveDown(); |
424 | void slotMoveLeft(); |
425 | void slotMoveRight(); |
426 | |
427 | void slotIncreaseHeight(); |
428 | void slotDecreaseHeight(); |
429 | void slotIncreaseWidth(); |
430 | void slotDecreaseWidth(); |
431 | |
432 | void slotCancelDrawing(); |
433 | |
434 | // void slotPreferences(); |
435 | void imageAdd(); |
436 | void imageRemove(); |
437 | void imageUsemap(); |
438 | |
439 | }; |
440 | |
441 | |
442 | inline KImageMapEditor::ToolType KImageMapEditor::currentToolType() const { |
443 | return _currentToolType; |
444 | } |
445 | |
446 | inline QString KImageMapEditor::mapName() const { |
447 | return _mapName; |
448 | } |
449 | |
450 | inline KUndoStack* KImageMapEditor::commandHistory() const { |
451 | return _commandHistory; |
452 | } |
453 | |
454 | #endif // IMAGEMAPEDITOR_H |
455 | |