summaryrefslogtreecommitdiffstats
path: root/kimagemapeditor/kimagemapeditor.h
blob: d500c09945cd4bbed96a91f0fccaed41113e3a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
/***************************************************************************
                          imagemapeditor.h  -  description
                             -------------------
    begin                : Wed Apr 4 2001
    copyright            : (C) 2001 by Jan SchÃ?fer
    email                : janschaefer@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KIMAGEMAPDIALOG_H
#define KIMAGEMAPDIALOG_H

#include <tqptrlist.h>
#include <tqobjectlist.h>
#include <tqdict.h>
#include <tqimage.h>
#include <kurl.h>
#include <tdeparts/part.h>
#include <tdeparts/browserextension.h>
#include <tdeparts/factory.h>

#include <tdeversion.h>

#include "kimearea.h"

/**
  *@author Jan Schaefer
  */


class TQListView;
class TQPushButton;
class DrawZone;
class TQComboBox;
class TQListViewItem;
class TDEToggleAction;




/**
 * Stores an area tag and all its attributes
 */
typedef TQDict<TQString> AreaTag;

/**
 * Stores an image tag and all its attributes
 * the origcode attribute hold the original htmlcode
 * of this tag
 */
typedef TQDict<TQString> ImageTag;

/**
 * Only a small class to give a list of AreaTags a name
 */
class MapTag : public TQPtrList<AreaTag> {
public:
    MapTag();
    TQString name;
    bool modified;
};


class HtmlElement {
public:
    HtmlElement(const TQString & s) {
        htmlCode = s;
    };
    virtual ~HtmlElement() {}
    ;
    TQString htmlCode;
};

class HtmlMapElement : public HtmlElement {
public:
    HtmlMapElement(const TQString & s) : HtmlElement(s) {
        mapTag = 0L;
    };

    virtual ~HtmlMapElement() {};

    MapTag *mapTag;
};

class HtmlImgElement : public HtmlElement {
public:
HtmlImgElement(const TQString & s) : HtmlElement(s) {
        imgTag = 0L;
    };
    virtual ~HtmlImgElement() {}
    ;
    ImageTag *imgTag;
};

/**
 * Stores the hole HTML content in a List.
 */
class HtmlContent : public TQPtrList<HtmlElement> {}
;


class TDESelectAction;
class TDERadioAction;
class TDERecentFilesAction;
class TDEAction;
#if TDE_VERSION < 300
  class TDEAccel;
#endif
///class TQListViewItem;
class KCommandHistory;
class TDEApplication;
class TQTabWidget;
class AreaListView;
class ImagesListView;
class MapsListView;
class KDockWidget;
class KDockMainWindow;

// needed by the statusbar
#define STATUS_CURSOR 1000
#define STATUS_SELECTION 1001

class KImageMapEditor : public KParts::ReadWritePart {
    Q_OBJECT
  
public :
    enum ToolType { Selection, Rectangle, Circle, Polygon, Freehand, AddPoint, RemovePoint };

    KImageMapEditor(TQWidget *parentWidget, const char *,
                    TQObject *parent, const char *name, const TQStringList & args = TQStringList());
    virtual ~KImageMapEditor();

    static TDEAboutData *createAboutData();
    static TDEConfig *config();

    /**
    * Makes sure, that the actions cut, copy, delete and
    * show properties
    * can only be executed if sth. is selected.
    **/
    void updateActionAccess();

    DrawZone* getDrawZone() {
        return drawZone;
    };

    void addAreaAndEdit(Area*);
    void addArea(Area*);
    AreaListIterator areaList() const;
    KImageMapEditor::ToolType currentToolType() const;
    void deleteSelected();
    void deleteArea( Area * area);
    void deleteAllAreas();
    void deselectAll();
    void deselect(Area* s);
    void deselectWithoutUpdate(Area*);
    TQString getHTMLImageMap() const;
    Area* onArea(const TQPoint & p) const;
    TQPixmap makeListViewPix(Area &) ;
    TQString mapName() const;
    void select(Area*);
    void selectWithoutUpdate(Area*);
    void select(TQListViewItem*);
    AreaSelection* selected() const;
    void setPicture(const TQImage & pix);
    int showTagEditor(Area *);
    KCommandHistory *commandHistory() const;

    TDEApplication* app() const;

    // Only refreshes the listView
    void updateSelection() const;

    void readConfig();
    void writeConfig();

    virtual void readProperties(TDEConfig *);
    virtual void saveProperties(TDEConfig *);
    virtual bool closeURL();
    bool queryClose();
    virtual void setReadWrite(bool);
    TQString getHtmlCode();

    /**
     * Reimplemented to disable and enable Save action
     */
    virtual void setModified(bool);

    /**
     * Opens the given file.
     * If it's an HTML file openURL is called
     * If it's an Image, the image is added to the image list
     */
    void openFile(const KURL &);

    /**
     * Opens the last URL the user worked with.
     * Sets also, the last map and the last image
     */
    void openLastURL(TDEConfig*);

    void readConfig(TDEConfig*);
    void writeConfig(TDEConfig*);

    virtual bool openURL(const KURL & url);

protected:
    void init();
    bool openHTMLFile(const KURL &, const TQString & mapName = TQString(), const TQString & imagePath = TQString());
    void saveImageMap(const KURL &);

    /**
     * Returns a language dependend background picture, with
     * the text : Drop an image or html file
     */
    TQImage getBackgroundImage();


    /**
     * Saves information to restore the last working state
     */
    void saveLastURL(TDEConfig*);


private:
    // Stores the hole html file in a List
    // The entries are either a MapTag an ImageTag or a TQString
    HtmlContent _htmlContent;

    // the url of the working image;
    KURL _imageUrl;
    TQString _mapName;
    TQImage _backgroundImage;

    bool backupFileCreated;

    KImageMapEditor::ToolType _currentToolType;
    AreaList *areas;
    AreaSelection *currentSelected;
    AreaSelection *copyArea;
    Area *defaultArea;
    DrawZone* drawZone;
    TQTabWidget* tabWidget;
    AreaListView *areaListView;
    ImagesListView* imagesListView;
    MapsListView* mapsListView;
    HtmlMapElement* currentMapElement;

    //
    // Actions
    //
    TDESelectAction* zoomAction;
    TDERadioAction *arrowAction;
    TDERadioAction *circleAction;
    TDERadioAction *rectangleAction;
    TDERadioAction *polygonAction;
    TDERadioAction *freehandAction;
    TDERadioAction *addPointAction;
    TDERadioAction *removePointAction;

    TDEAction *cutAction;
    TDEAction *deleteAction;
    TDEAction *copyAction;
    TDEAction *pasteAction;
    TDEAction *zoomInAction;
    TDEAction *zoomOutAction;

    TDEAction *mapNewAction;
    TDEAction *mapDeleteAction;
    TDEAction *mapNameAction;
    TDEAction *mapDefaultAreaAction;

    TDEAction *imageAddAction;
    TDEAction *imageRemoveAction;
    TDEAction *imageUsemapAction;

    TDEToggleAction *highlightAreasAction;
    TDEToggleAction *showAltAction;

    TDEAction *areaPropertiesAction;

    TDEAction *moveLeftAction;
    TDEAction *moveRightAction;
    TDEAction *moveUpAction;
    TDEAction *moveDownAction;

    TDEAction *increaseWidthAction;
    TDEAction *decreaseWidthAction;
    TDEAction *increaseHeightAction;
    TDEAction *decreaseHeightAction;

    TDEAction *toFrontAction;
    TDEAction *toBackAction;
    TDEAction *forwardOneAction;
    TDEAction *backOneAction;

    TDEToggleAction* configureShowAreaListAction;
    TDEToggleAction* configureShowMapListAction;
    TDEToggleAction* configureShowImageListAction;


  	TDERecentFilesAction* recentFilesAction;

    #if TDE_VERSION < 300
      TDEAccel *accel;
    #endif

    KDockMainWindow *mainDock;
    KDockWidget* areaDock;
    KDockWidget* mapsDock;
    KDockWidget* imagesDock;

    KCommandHistory *_commandHistory;
    int maxAreaPreviewHeight;

    TQString cursorStatusText;
    TQString selectionStatusText;

    void setupActions();
    void setupStatusBar();
    void updateStatusBar();
    /* refreshes all Areas, only used by preferences dialog
     * updates only the preview pictures*/
    void updateAllAreas();
    void updateUpDownBtn();

    TQDict<TQString> getTagAttributes(TQTextStream & s,TQString &);

    void setMap(HtmlMapElement*);
    void setMap(MapTag*);
    void addMap(const TQString &);

    // Returns the entire html file as a String
    HtmlElement* findHtmlElement(const TQString &);
    HtmlImgElement* findHtmlImgElement(ImageTag*);
    HtmlMapElement* findHtmlMapElement(const TQString &);
    void deleteAllMaps();
    void addImage(const KURL &);
    void setImageActionsEnabled(bool);
    void setMapActionsEnabled(bool);

    void saveAreasToMapTag(MapTag*);
    void showPopupMenu(const TQPoint &, const TQString &);
    void drawToCenter(TQPainter* p, const TQString & str, int y, int width);

public slots:
    void slotChangeStatusCoords(int x,int y);
    void slotUpdateSelectionCoords();
    void slotUpdateSelectionCoords( const TQRect &);
    void slotAreaChanged(Area *);
    void slotShowMainPopupMenu(const TQPoint &);
    void slotShowMapPopupMenu(TQListViewItem *, const TQPoint &);
    void slotShowImagePopupMenu(TQListViewItem *, const TQPoint &);
    void slotConfigChanged();
    void setPicture(const KURL & url);
    void setMap(const TQString &);
    void setMapName(const TQString & s);


protected slots:
    // overriden from KReadWritePart
    virtual bool openFile();

    virtual bool saveFile() {
        saveImageMap( url() );
//        setModified(false);
        return true;
    }

    void fileOpen();
    void fileSaveAs();
    void fileSave();
    void fileClose();

    void slotShowPopupMenu(TQListViewItem*,const TQPoint &);
    void slotShowPreferences();
    void slotHightlightAreas();
    void slotShowAltTag();
    void slotSelectionChanged();

    int showTagEditor(TQListViewItem *item);
    int showTagEditor();

    void slotZoom();
    void slotZoomIn();
    void slotZoomOut();

    void slotCut();
    void slotCopy();
    void slotPaste();
    void slotDelete();

    void slotDrawArrow();
    void slotDrawCircle();
    void slotDrawRectangle();
    void slotDrawPolygon();
    void slotDrawFreehand();
    void slotDrawAddPoint();
    void slotDrawRemovePoint();

    void mapDefaultArea();
    void mapNew();
    void mapDelete();
    void mapEditName();
    void mapShowHTML();
    void mapPreview();

    void slotBackOne();
    void slotForwardOne();
    void slotToBack();
    void slotToFront();

    void slotMoveUp();
    void slotMoveDown();
    void slotMoveLeft();
    void slotMoveRight();

    void slotIncreaseHeight();
    void slotDecreaseHeight();
    void slotIncreaseWidth();
    void slotDecreaseWidth();

    void slotCancelDrawing();

    void configureShowAreaList();
    void configureShowMapList();
    void configureShowImageList();


    //	void slotPreferences();
    void imageAdd();
    void imageRemove();
    void imageUsemap();

    void dockingStateChanged();

};


inline KImageMapEditor::ToolType KImageMapEditor::currentToolType() const {
    return _currentToolType;
}

inline TQString KImageMapEditor::mapName() const {
    return _mapName;
}

inline KCommandHistory* KImageMapEditor::commandHistory() const {
    return _commandHistory;
}


#endif