kimagemapeditor.cpp 77.8 KB
Newer Older
Jan Schäfer's avatar
Jan Schäfer committed
1
2
3
4
/***************************************************************************
                          imagemapeditor.cpp  -  description
                            -------------------
    begin                : Wed Apr 4 2001
Jens Herden's avatar
Jens Herden committed
5
    copyright            : (C) 2001 by Jan Sch�er
Jan Schäfer's avatar
Jan Schäfer committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    email                : j_schaef@informatik.uni-kl.de
***************************************************************************/

/***************************************************************************
*                                                                         *
*   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.                                   *
*                                                                         *
***************************************************************************/

#include <iostream>
#include <assert.h>

// QT
22
23
#include <QScrollArea>

Jan Schäfer's avatar
Jan Schäfer committed
24
#include <qlayout.h>
Jan Schäfer's avatar
Jan Schäfer committed
25
#include <QListWidget>
Jan Schäfer's avatar
Jan Schäfer committed
26
27
28
29
30
31
#include <qpushbutton.h>
#include <qpixmap.h>
#include <qcombobox.h>
#include <qsplitter.h>
#include <qfileinfo.h>
#include <qtextstream.h>
Laurent Montel's avatar
Laurent Montel committed
32
#include <QMenu>
Jan Schäfer's avatar
Jan Schäfer committed
33
34
35
36
#include <qtooltip.h>
#include <qpainter.h>
#include <qtabwidget.h>
#include <qfontdatabase.h>
37
#include <qfile.h>
Jan Schäfer's avatar
Jan Schäfer committed
38
#include <QLinkedList>
Jan Schäfer's avatar
Jan Schäfer committed
39
40

// KDE
41
#include <kundostack.h>
Jan Schäfer's avatar
Jan Schäfer committed
42
43
44
#include <kdebug.h>
#include <klocale.h>
#include <kaction.h>
Aaron J. Seigo's avatar
Aaron J. Seigo committed
45
#include <kstandardaction.h>
Jan Schäfer's avatar
Jan Schäfer committed
46
47
48
#include <kiconloader.h>
#include <kfiledialog.h>
#include <kmessagebox.h>
49
#include <kapplication.h>
Jan Schäfer's avatar
Jan Schäfer committed
50
#include <kedittoolbar.h>
Stephan Kulow's avatar
Stephan Kulow committed
51
#include <kactioncollection.h>
Jan Schäfer's avatar
Jan Schäfer committed
52
#include <kglobal.h>
53
#include <kstandarddirs.h>
Jan Schäfer's avatar
Jan Schäfer committed
54
55
56
#include <kstatusbar.h>
#include <kxmlguifactory.h>
#include <kio/job.h>
57
#include <kinputdialog.h>
Laurent Montel's avatar
Laurent Montel committed
58
59
#include <ktoggleaction.h>
#include <krecentfilesaction.h>
Laurent Montel's avatar
Laurent Montel committed
60
#include <kxmlguiwindow.h>
Jan Schäfer's avatar
Jan Schäfer committed
61
62
63
64
65
66
// local
#include "kimagemapeditor.h"
#include "kimagemapeditor.moc"
#include "drawzone.h"
#include "kimedialogs.h"
#include "kimecommands.h"
Stephan Kulow's avatar
Stephan Kulow committed
67
#include <kicon.h>
Jan Schäfer's avatar
Jan Schäfer committed
68
69
70
71
72
#include "areacreator.h"
#include "arealistview.h"
#include "imageslistview.h"
#include "mapslistview.h"
#include "kimecommon.h"
73
74
#include "imagemapchoosedialog.h"

Laurent Montel's avatar
Laurent Montel committed
75
76
#include <QTextEdit>

Jan Schäfer's avatar
Jan Schäfer committed
77
#include <kparts/genericfactory.h>
Matthias Kretz's avatar
Matthias Kretz committed
78
#include <kcomponentdata.h>
Jan Schäfer's avatar
Jan Schäfer committed
79
80
81

// Factory code for KDE 3
typedef KParts::GenericFactory<KImageMapEditor> KimeFactory;
Dirk Mueller's avatar
Dirk Mueller committed
82
K_EXPORT_COMPONENT_FACTORY( libkimagemapeditor , KimeFactory )
Jan Schäfer's avatar
Jan Schäfer committed
83

Laurent Montel's avatar
Laurent Montel committed
84
85
KImageMapEditor::KImageMapEditor(QWidget *parentWidget,
            QObject *parent, const QStringList & )
Andras Mantia's avatar
Andras Mantia committed
86
  : KParts::ReadWritePart(parent)
Jan Schäfer's avatar
Jan Schäfer committed
87
{
Matthias Kretz's avatar
Matthias Kretz committed
88
  setComponentData( KimeFactory::componentData() );
Jan Schäfer's avatar
Jan Schäfer committed
89
90

//  KDockMainWindow* mainWidget;
Jonathan Riddell's avatar
Jonathan Riddell committed
91

Laurent Montel's avatar
Laurent Montel committed
92
  mainWindow = dynamic_cast<KXmlGuiWindow*>(parent) ;
Jan Schäfer's avatar
Jan Schäfer committed
93
  QSplitter * splitter = 0L;
94
  tabWidget = 0L;
Jan Schäfer's avatar
Jan Schäfer committed
95

96
  if (mainWindow) {
Laurent Montel's avatar
Laurent Montel committed
97
//    kDebug() << "KImageMapEditor: We got a KDockMainWindow !";
Jonathan Riddell's avatar
Jonathan Riddell committed
98

99
100
101
102
103
104
105
106
107
108
109
110
111
//    K3DockWidget* parentDock = mainDock->getMainDockWidget();
    areaDock = new QDockWidget(i18n("Areas"),mainWindow);
    mapsDock = new QDockWidget(i18n("Maps"),mainWindow);
    imagesDock = new QDockWidget(i18n("Images"),mainWindow);

    // Needed to save their state
    areaDock->setObjectName("areaDock");
    mapsDock->setObjectName("mapsDock");
    imagesDock->setObjectName("imagesDock");

    mainWindow->addDockWidget( Qt::LeftDockWidgetArea, areaDock);
    mainWindow->addDockWidget( Qt::LeftDockWidgetArea, mapsDock);
    mainWindow->addDockWidget( Qt::LeftDockWidgetArea, imagesDock);
Jonathan Riddell's avatar
Jonathan Riddell committed
112

Jens Herden's avatar
Jens Herden committed
113
114
115
    areaListView = new AreaListView(areaDock);
    mapsListView = new MapsListView(mapsDock);
    imagesListView = new ImagesListView(imagesDock);
Jan Schäfer's avatar
Jan Schäfer committed
116
117
118
119

    areaDock->setWidget(areaListView);
    mapsDock->setWidget(mapsListView);
    imagesDock->setWidget(imagesListView);
Jonathan Riddell's avatar
Jonathan Riddell committed
120
121
122
123

  }
  else
  {
Jan Schäfer's avatar
Jan Schäfer committed
124
125
126
127
    areaDock = 0L;
    mapsDock = 0L;
    imagesDock = 0L;
    splitter = new QSplitter(parentWidget);
Jonathan Riddell's avatar
Jonathan Riddell committed
128
    tabWidget = new QTabWidget(splitter);
Jens Herden's avatar
Jens Herden committed
129
130
131
    areaListView = new AreaListView(tabWidget);
    mapsListView = new MapsListView(tabWidget);
    imagesListView = new ImagesListView(tabWidget);
Jonathan Riddell's avatar
Jonathan Riddell committed
132

Jan Schäfer's avatar
Jan Schäfer committed
133
    tabWidget->addTab(areaListView,i18n("Areas"));
Jonathan Riddell's avatar
Jonathan Riddell committed
134
    tabWidget->addTab(mapsListView,i18n("Maps"));
Jan Schäfer's avatar
Jan Schäfer committed
135
    tabWidget->addTab(imagesListView,i18n("Images"));
Jonathan Riddell's avatar
Jonathan Riddell committed
136
137
138
  }


Jan Schäfer's avatar
Jan Schäfer committed
139
  connect( areaListView->listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotSelectionChanged()));
140
  connect( areaListView->listView,
141
           SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
142
           this,
Jan Schäfer's avatar
Jan Schäfer committed
143
144
           SLOT(showTagEditor(QTreeWidgetItem*)));
  connect( areaListView->listView,
145
           SIGNAL(customContextMenuRequested(const QPoint&)),
Jan Schäfer's avatar
Jan Schäfer committed
146
147
           this,
           SLOT(slotShowPopupMenu(const QPoint &)));
Jonathan Riddell's avatar
Jonathan Riddell committed
148

Jan Schäfer's avatar
Jan Schäfer committed
149
150
  connect( mapsListView, SIGNAL( mapSelected(const QString &)),
           this, SLOT( setMap(const QString &)));
Jonathan Riddell's avatar
Jonathan Riddell committed
151

Jan Schäfer's avatar
Jan Schäfer committed
152
153
154
  connect( mapsListView, SIGNAL( mapRenamed(const QString &)),
           this, SLOT( setMapName(const QString &)));

Jan Schäfer's avatar
Jan Schäfer committed
155
  connect( mapsListView->listView(),
156
           SIGNAL(customContextMenuRequested(const QPoint &)),
Jan Schäfer's avatar
Jan Schäfer committed
157
158
           this,
           SLOT(slotShowMapPopupMenu(const QPoint &)));
Jonathan Riddell's avatar
Jonathan Riddell committed
159

Laurent Montel's avatar
Laurent Montel committed
160
161
  connect( imagesListView, SIGNAL( imageSelected(const KUrl &)),
           this, SLOT( setPicture(const KUrl &)));
Jonathan Riddell's avatar
Jonathan Riddell committed
162

163
164
  connect( imagesListView,
           SIGNAL(customContextMenuRequested(const QPoint &)),
Jan Schäfer's avatar
Jan Schäfer committed
165
166
           this,
           SLOT(slotShowImagePopupMenu(const QPoint &)));
Jonathan Riddell's avatar
Jonathan Riddell committed
167

Jan Schäfer's avatar
Jan Schäfer committed
168
169
  if (splitter) {
    drawZone = new DrawZone(splitter,this);
170
171
    splitter->setStretchFactor(splitter->indexOf(tabWidget), 0);
    splitter->setStretchFactor(splitter->indexOf(drawZone), 1);
Jan Schäfer's avatar
Jan Schäfer committed
172
173
    setWidget(splitter);
  } else {
174
175
176
177
    QScrollArea *sa = new QScrollArea(mainWindow);
    drawZone = new DrawZone(0L,this);
    mainWindow->setCentralWidget(sa);
    sa->setWidget(drawZone);
178
    setWidget(mainWindow);
179
    //    sa->setWidgetResizable(true);
Jan Schäfer's avatar
Jan Schäfer committed
180
181
182
183
184
185
186
187
188
  }


  areas = new AreaList();
  currentSelected= new AreaSelection();
  _currentToolType=KImageMapEditor::Selection;
  copyArea=0L;
  defaultArea=0L;
  currentMapElement = 0L;
Jonathan Riddell's avatar
Jonathan Riddell committed
189

Jan Schäfer's avatar
Jan Schäfer committed
190
191
192
193
194
195
  setupActions();
  setupStatusBar();

  setXMLFile("kimagemapeditorpartui.rc");

  setPicture(getBackgroundImage());
Jonathan Riddell's avatar
Jonathan Riddell committed
196

Jan Schäfer's avatar
Jan Schäfer committed
197
198
199
200
201
202
203
204
  init();
  readConfig();
}

KImageMapEditor::~KImageMapEditor() {
  writeConfig();

  delete areas;
Jonathan Riddell's avatar
Jonathan Riddell committed
205

Jan Schäfer's avatar
Jan Schäfer committed
206
  delete currentSelected;
207
208
  delete copyArea;
  delete defaultArea;
Jonathan Riddell's avatar
Jonathan Riddell committed
209

Jan Schäfer's avatar
Jan Schäfer committed
210
211
212
213
214
  // Delete our DockWidgets
  if (areaDock) {
    areaDock->hide();
    mapsDock->hide();
    imagesDock->hide();
Jonathan Riddell's avatar
Jonathan Riddell committed
215

Jan Schäfer's avatar
Jan Schäfer committed
216
217
218
219
    delete areaDock;
    delete mapsDock;
    delete imagesDock;
  }
Jonathan Riddell's avatar
Jonathan Riddell committed
220

Jan Schäfer's avatar
Jan Schäfer committed
221
222
223
224
}

MapTag::MapTag() {
  modified = false;
Jens Herden's avatar
Jens Herden committed
225
  name.clear();
Jan Schäfer's avatar
Jan Schäfer committed
226
227
228
229
230
}

void KImageMapEditor::init()
{
  _htmlContent.clear();
Jens Herden's avatar
Jens Herden committed
231
  _imageUrl.clear();
232
  //  closeUrl();
Jan Schäfer's avatar
Jan Schäfer committed
233
234
235
236
237
238
239
240
241
242
  HtmlElement* el = new HtmlElement("<html>\n");
  _htmlContent.append(el);
  el = new HtmlElement("<head>\n");
  _htmlContent.append(el);
  el = new HtmlElement("</head>\n");
  _htmlContent.append(el);
  el = new HtmlElement("<body>\n");
  _htmlContent.append(el);

  addMap(i18n("unnamed"));
Jonathan Riddell's avatar
Jonathan Riddell committed
243

Jan Schäfer's avatar
Jan Schäfer committed
244
245
246
247
  el = new HtmlElement("</body>\n");
  _htmlContent.append(el);
  el = new HtmlElement("</html>\n");
  _htmlContent.append(el);
Jonathan Riddell's avatar
Jonathan Riddell committed
248

Jan Schäfer's avatar
Jan Schäfer committed
249
250
251
252
253
254
  setImageActionsEnabled(false);
}

KAboutData* KImageMapEditor::createAboutData()
{
    KAboutData* aboutData =
255
256
              new KAboutData( "kimagemapeditor", 0, ki18n("KImageMapEditor"),
              "1.0", ki18n( "An HTML imagemap editor" ),
Jan Schäfer's avatar
Jan Schäfer committed
257
              KAboutData::License_GPL,
258
              ki18n("(c) 2001-2003 Jan Sch&auml;fer <email>janschaefer@users.sourceforge.net</email>"));
Jan Schäfer's avatar
Jan Schäfer committed
259
260
261
262
263
264
    return aboutData;
}


void KImageMapEditor::setReadWrite(bool)
{
Jonathan Riddell's avatar
Jonathan Riddell committed
265

Frederik Schwarzer's avatar
Frederik Schwarzer committed
266
  // For now it does not matter if it is readwrite or readonly
Jan Schäfer's avatar
Jan Schäfer committed
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
  // it is always readwrite, because Quanta only supports ReadOnlyParts
  // at this moment and in that case it should be readwrite, too.
  ReadWritePart::setReadWrite(true);
  /*
    if (rw)
      ;
    else
    {
     actionCollection()->remove(arrowAction);
     actionCollection()->remove(circleAction);
     actionCollection()->remove(rectangleAction);
     actionCollection()->remove(polygonAction);
     actionCollection()->remove(freehandAction);
     actionCollection()->remove(addPointAction);
     actionCollection()->remove(removePointAction);

     actionCollection()->remove(cutAction);
     actionCollection()->remove(deleteAction);
     actionCollection()->remove(copyAction);
     actionCollection()->remove(pasteAction);
Jonathan Riddell's avatar
Jonathan Riddell committed
287

Jan Schäfer's avatar
Jan Schäfer committed
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
     actionCollection()->remove(mapNewAction);
     actionCollection()->remove(mapDeleteAction);
     actionCollection()->remove(mapNameAction);
     actionCollection()->remove(mapDefaultAreaAction);

     actionCollection()->remove(areaPropertiesAction);

     actionCollection()->remove(moveLeftAction);
     actionCollection()->remove(moveRightAction);
     actionCollection()->remove(moveUpAction);
     actionCollection()->remove(moveDownAction);

     actionCollection()->remove(increaseWidthAction);
     actionCollection()->remove(decreaseWidthAction);
     actionCollection()->remove(increaseHeightAction);
     actionCollection()->remove(decreaseHeightAction);

     actionCollection()->remove(toFrontAction);
     actionCollection()->remove(toBackAction);
     actionCollection()->remove(forwardOneAction);
     actionCollection()->remove(backOneAction);
Jonathan Riddell's avatar
Jonathan Riddell committed
309

Jan Schäfer's avatar
Jan Schäfer committed
310
311
312
     actionCollection()->remove(imageRemoveAction);
     actionCollection()->remove(imageAddAction);
     actionCollection()->remove(imageUsemapAction);
Jonathan Riddell's avatar
Jonathan Riddell committed
313

Jan Schäfer's avatar
Jan Schäfer committed
314
315
    }
  */
Jonathan Riddell's avatar
Jonathan Riddell committed
316

Jan Schäfer's avatar
Jan Schäfer committed
317
318
319
320
321
}

void KImageMapEditor::setModified(bool modified)
{
    // get a handle on our Save action and make sure it is valid
322
    QAction *save = actionCollection()->action(KStandardAction::name(KStandardAction::Save));
Jan Schäfer's avatar
Jan Schäfer committed
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
    if (!save)
        return;

    // if so, we either enable or disable it based on the current
    // state
    if (modified)
        save->setEnabled(true);
    else
        save->setEnabled(false);

    // in any event, we want our parent to do it's thing
    ReadWritePart::setModified(modified);
}


KConfig *KImageMapEditor::config()
{
Matthias Kretz's avatar
Matthias Kretz committed
340
341
    KSharedConfigPtr tmp = KimeFactory::componentData().config();
    return tmp.data();
Jan Schäfer's avatar
Jan Schäfer committed
342
343
}

344
void KImageMapEditor::readConfig(const KConfigGroup &config) {
345
  KConfigGroup data = config.parent().group( "Data" );
Stephan Kulow's avatar
Stephan Kulow committed
346
  recentFilesAction->loadEntries( data );
Jan Schäfer's avatar
Jan Schäfer committed
347
348
}

349
350
351
void KImageMapEditor::writeConfig(KConfigGroup& config) {
  config.writeEntry("highlightareas",highlightAreasAction->isChecked());
  config.writeEntry("showalt",showAltAction->isChecked());
352
  KConfigGroup data = config.parent().group( "Data" );
Stephan Kulow's avatar
Stephan Kulow committed
353
  recentFilesAction->saveEntries( data );
Jan Schäfer's avatar
Jan Schäfer committed
354
  saveLastURL(config);
Jonathan Riddell's avatar
Jonathan Riddell committed
355

Jan Schäfer's avatar
Jan Schäfer committed
356
357
358
}

void KImageMapEditor::readConfig() {
Stephan Kulow's avatar
Stephan Kulow committed
359
  readConfig(config()->group("General Options" ) );
Jan Schäfer's avatar
Jan Schäfer committed
360
361
362
363
  slotConfigChanged();
}

void KImageMapEditor::writeConfig() {
364
365
  KConfigGroup cg( config(), "General Options");
  writeConfig( cg );
Jan Schäfer's avatar
Jan Schäfer committed
366
367
368
369
  config()->sync();
}


370
void KImageMapEditor::saveProperties(KConfigGroup &config)
Jan Schäfer's avatar
Jan Schäfer committed
371
372
373
374
{
  saveLastURL(config);
}

375
void KImageMapEditor::readProperties(const KConfigGroup& config)
Jan Schäfer's avatar
Jan Schäfer committed
376
377
378
379
380
381
{
  openLastURL(config);
}

void KImageMapEditor::slotConfigChanged()
{
Laurent Montel's avatar
Laurent Montel committed
382
383
384
385
  KConfigGroup group = config()->group("Appearance");
  int newHeight=group.readEntry("maximum-preview-height",50);
  group = config()->group("General Options");
  _commandHistory->setUndoLimit(group.readEntry("undo-level",100));
386
#if 0
Laurent Montel's avatar
Laurent Montel committed
387
  _commandHistory->setRedoLimit(group.readEntry("redo-level",100));
388
#endif
Laurent Montel's avatar
Laurent Montel committed
389
  Area::highlightArea = group.readEntry("highlightareas",true);
Jan Schäfer's avatar
Jan Schäfer committed
390
  highlightAreasAction->setChecked(Area::highlightArea);
Laurent Montel's avatar
Laurent Montel committed
391
  Area::showAlt = group.readEntry("showalt",true);
Jan Schäfer's avatar
Jan Schäfer committed
392
393
394
395
396
  showAltAction->setChecked(Area::showAlt);

  // if the image preview size changed update all images
  if (maxAreaPreviewHeight!=newHeight) {
    maxAreaPreviewHeight=newHeight;
397
    areaListView->listView->setIconSize(QSize(newHeight,newHeight));
Jan Schäfer's avatar
Jan Schäfer committed
398
399
400
  }

  updateAllAreas();
401
  drawZone->repaint();
Jan Schäfer's avatar
Jan Schäfer committed
402
403
}

404
void KImageMapEditor::openLastURL(const KConfigGroup & config) {
405
  KUrl lastURL ( config.readPathEntry("lastopenurl", QString()) );
406
  QString lastMap = config.readEntry("lastactivemap");
407
  QString lastImage = config.readPathEntry("lastactiveimage", QString());
Jonathan Riddell's avatar
Jonathan Riddell committed
408
409


Laurent Montel's avatar
Laurent Montel committed
410
//  kDebug() << "loading from group : " << config.group();
Jonathan Riddell's avatar
Jonathan Riddell committed
411

Laurent Montel's avatar
Laurent Montel committed
412
//  kDebug() << "loading entry lastopenurl : " << lastURL.path();
413
//  KMessageBox::information(0L, config.group()+" "+lastURL.path());
Jan Schäfer's avatar
Jan Schäfer committed
414
  if (!lastURL.isEmpty()) {
415
416
417
418
419
    openUrl(lastURL);
    if (!lastMap.isEmpty())
      mapsListView->selectMap(lastMap);
    if (!lastImage.isEmpty())
      setPicture(lastImage);
Laurent Montel's avatar
Laurent Montel committed
420
//    kDebug() << "opening HTML file with map " << lastMap << " and image " << lastImage;
421
422
423
424
425
//    if (! openHTMLFile(lastURL, lastMap, lastImage) )
//      closeUrl();
      //openUrl(lastURL);
      //    else
      //closeUrl();
Jan Schäfer's avatar
Jan Schäfer committed
426
427
428
  }
}

Stephan Kulow's avatar
Stephan Kulow committed
429
void KImageMapEditor::saveLastURL(KConfigGroup & config) {
Laurent Montel's avatar
Laurent Montel committed
430
  kDebug() << "saveLastURL: " << url().path();
Stephan Kulow's avatar
Stephan Kulow committed
431
432
433
  config.writePathEntry("lastopenurl",url().path());
  config.writeEntry("lastactivemap",mapName());
  config.writePathEntry("lastactiveimage",_imageUrl.path());
Laurent Montel's avatar
Laurent Montel committed
434
435
436
//  kDebug() << "writing entry lastopenurl : " << url().path();
//  kDebug() << "writing entry lastactivemap : " << mapName();
//  kDebug() << "writing entry lastactiveimage : " << _imageUrl.path();
Stephan Kulow's avatar
Stephan Kulow committed
437
  //KMessageBox::information(0L, QString("Group: %1 Saving ... %2").arg(config.group()).arg(url().path()));
Jan Schäfer's avatar
Jan Schäfer committed
438
439
440
441
442
}

void KImageMapEditor::setupActions()
{
	// File Open
443
444
  QAction *temp =
    KStandardAction::open(this, SLOT(fileOpen()),
Jan Schäfer's avatar
Jan Schäfer committed
445
446
447
448
449
			  actionCollection());
  temp->setWhatsThis(i18n("<h3>Open File</h3>Click this to <em>open</em> a new picture or HTML file."));
  temp->setToolTip(i18n("Open new picture or HTML file"));

  // File Open Recent
Aaron J. Seigo's avatar
Aaron J. Seigo committed
450
  recentFilesAction = KStandardAction::openRecent(this, SLOT(openURL(const KUrl&)),
Jan Schäfer's avatar
Jan Schäfer committed
451
452
                                      actionCollection());
	// File Save
Aaron J. Seigo's avatar
Aaron J. Seigo committed
453
  temp =KStandardAction::save(this, SLOT(fileSave()), actionCollection());
454
455
	temp->setWhatsThis(i18n("<h3>Save File</h3>Click this to <em>save</em> the changes to the HTML file."));
	temp->setToolTip(i18n("Save HTML file"));
Jan Schäfer's avatar
Jan Schäfer committed
456
457
458


	// File Save As
Aaron J. Seigo's avatar
Aaron J. Seigo committed
459
  (void)KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
Jan Schäfer's avatar
Jan Schäfer committed
460
461

	// File Close
Aaron J. Seigo's avatar
Aaron J. Seigo committed
462
  temp=KStandardAction::close(this, SLOT(fileClose()), actionCollection());
463
464
	temp->setWhatsThis(i18n("<h3>Close File</h3>Click this to <em>close</em> the currently open HTML file."));
	temp->setToolTip(i18n("Close HTML file"));
Jan Schäfer's avatar
Jan Schäfer committed
465
466

  // Edit Copy
Aaron J. Seigo's avatar
Aaron J. Seigo committed
467
  copyAction=KStandardAction::copy(this, SLOT(slotCopy()), actionCollection());
Jan Schäfer's avatar
Jan Schäfer committed
468
469
  copyAction->setWhatsThis(i18n("<h3>Copy</h3>"
                          "Click this to <em>copy</em> the selected area."));
Jonathan Riddell's avatar
Jonathan Riddell committed
470
  copyAction->setEnabled(false);
Jan Schäfer's avatar
Jan Schäfer committed
471
472

  // Edit Cut
Aaron J. Seigo's avatar
Aaron J. Seigo committed
473
  cutAction=KStandardAction::cut(this, SLOT(slotCut()), actionCollection());
Jan Schäfer's avatar
Jan Schäfer committed
474
475
  cutAction->setWhatsThis(i18n("<h3>Cut</h3>"
                          "Click this to <em>cut</em> the selected area."));
Jonathan Riddell's avatar
Jonathan Riddell committed
476
  cutAction->setEnabled(false);
Jan Schäfer's avatar
Jan Schäfer committed
477

Jonathan Riddell's avatar
Jonathan Riddell committed
478
  // Edit Paste
Aaron J. Seigo's avatar
Aaron J. Seigo committed
479
  pasteAction=KStandardAction::paste(this, SLOT(slotPaste()), actionCollection());
Jan Schäfer's avatar
Jan Schäfer committed
480
481
482
483
484
485
  pasteAction->setWhatsThis(i18n("<h3>Paste</h3>"
                          "Click this to <em>paste</em> the copied area."));
  pasteAction->setEnabled(false);


  // Edit Delete
Aaron J. Seigo's avatar
Aaron J. Seigo committed
486
  deleteAction = new KAction(KIcon("edit-delete"),
Jan Schäfer's avatar
Jan Schäfer committed
487
488
      i18n("&Delete"), this);
  actionCollection()->addAction("edit_delete", deleteAction );
489
  connect(deleteAction, SIGNAL(triggered(bool) ), SLOT (slotDelete()));
490
  deleteAction->setShortcut(QKeySequence(Qt::Key_Delete));
Jan Schäfer's avatar
Jan Schäfer committed
491
492
  deleteAction->setWhatsThis(i18n("<h3>Delete</h3>"
                          "Click this to <em>delete</em> the selected area."));
Jonathan Riddell's avatar
Jonathan Riddell committed
493
  deleteAction->setEnabled(false);
Jan Schäfer's avatar
Jan Schäfer committed
494
495

  // Edit Undo/Redo
496
497
498
  _commandHistory = new KUndoStack(this);
  _commandHistory->createUndoAction(actionCollection());
  _commandHistory->createRedoAction(actionCollection());
Jan Schäfer's avatar
Jan Schäfer committed
499
500

  // Edit Properties
Laurent Montel's avatar
Laurent Montel committed
501
502
    areaPropertiesAction  = new KAction(i18n("Pr&operties"), this);
    actionCollection()->addAction("edit_properties", areaPropertiesAction );
Stephan Kulow's avatar
Stephan Kulow committed
503
  connect(areaPropertiesAction, SIGNAL(triggered(bool)), SLOT(showTagEditor()));
Jonathan Riddell's avatar
Jonathan Riddell committed
504
  areaPropertiesAction->setEnabled(false);
Jan Schäfer's avatar
Jan Schäfer committed
505

Jonathan Riddell's avatar
Jonathan Riddell committed
506
  // View Zoom In
Aaron J. Seigo's avatar
Aaron J. Seigo committed
507
  zoomInAction=KStandardAction::zoomIn(this, SLOT(slotZoomIn()), actionCollection());
Jonathan Riddell's avatar
Jonathan Riddell committed
508
  // View Zoom Out
Aaron J. Seigo's avatar
Aaron J. Seigo committed
509
  zoomOutAction=KStandardAction::zoomOut(this, SLOT(slotZoomOut()), actionCollection());
Jan Schäfer's avatar
Jan Schäfer committed
510
511

  // View Zoom
Jan Schäfer's avatar
Jan Schäfer committed
512
513
514
  zoomAction  = new KSelectAction(i18n("Zoom"), this);
  actionCollection()->addAction("view_zoom", zoomAction );
  connect(zoomAction, SIGNAL(triggered(int)), this, SLOT (slotZoom()));
Jan Schäfer's avatar
Jan Schäfer committed
515
516
517
  zoomAction->setWhatsThis(i18n("<h3>Zoom</h3>"
                          "Choose the desired zoom level."));
  zoomAction->setItems(QStringList()
518
519
520
521
522
523
524
525
526
527
    << i18n("25%")
    << i18n("50%")
    << i18n("100%")
    << i18n("150%")
    << i18n("200%")
    << i18n("250%")
    << i18n("300%")
    << i18n("500%")
    << i18n("750%")
    << i18n("1000%"));
Jan Schäfer's avatar
Jan Schäfer committed
528
529
530

  zoomAction->setCurrentItem(2);

Laurent Montel's avatar
Laurent Montel committed
531
532
  highlightAreasAction = actionCollection()->add<KToggleAction>("view_highlightareas");
  highlightAreasAction->setText(i18n("Highlight Areas"));
533

534
  connect(highlightAreasAction, SIGNAL(toggled(bool)),
535
	  this, SLOT(slotHighlightAreas(bool)));
Jan Schäfer's avatar
Jan Schäfer committed
536

Laurent Montel's avatar
Laurent Montel committed
537
538
  showAltAction =   actionCollection()->add<KToggleAction>("view_showalt");
  showAltAction->setText(i18n("Show Alt Tag"));
539
  connect(showAltAction, SIGNAL(toggled(bool)),this, SLOT (slotShowAltTag(bool)));
Jan Schäfer's avatar
Jan Schäfer committed
540

Laurent Montel's avatar
Laurent Montel committed
541
542
    mapNameAction  = new KAction(i18n("Map &Name..."), this);
    actionCollection()->addAction("map_name", mapNameAction );
Stephan Kulow's avatar
Stephan Kulow committed
543
  connect(mapNameAction, SIGNAL(triggered(bool)), SLOT(mapEditName()));
Jan Schäfer's avatar
Jan Schäfer committed
544

Laurent Montel's avatar
Laurent Montel committed
545
546
    mapNewAction  = new KAction(i18n("Ne&w Map..."), this);
    actionCollection()->addAction("map_new", mapNewAction );
Stephan Kulow's avatar
Stephan Kulow committed
547
  connect(mapNewAction, SIGNAL(triggered(bool)), SLOT(mapNew()));
Jan Schäfer's avatar
Jan Schäfer committed
548
549
  mapNewAction->setToolTip(i18n("Create a new map"));

Laurent Montel's avatar
Laurent Montel committed
550
551
    mapDeleteAction  = new KAction(i18n("D&elete Map"), this);
    actionCollection()->addAction("map_delete", mapDeleteAction );
Stephan Kulow's avatar
Stephan Kulow committed
552
  connect(mapDeleteAction, SIGNAL(triggered(bool)), SLOT(mapDelete()));
Jan Schäfer's avatar
Jan Schäfer committed
553
554
  mapDeleteAction->setToolTip(i18n("Delete the current active map"));

Laurent Montel's avatar
Laurent Montel committed
555
556
    mapDefaultAreaAction  = new KAction(i18n("Edit &Default Area..."), this);
    actionCollection()->addAction("map_defaultarea", mapDefaultAreaAction );
Stephan Kulow's avatar
Stephan Kulow committed
557
  connect(mapDefaultAreaAction, SIGNAL(triggered(bool)), SLOT(mapDefaultArea()));
Jan Schäfer's avatar
Jan Schäfer committed
558
559
  mapDefaultAreaAction->setToolTip(i18n("Edit the default area of the current active map"));

Laurent Montel's avatar
Laurent Montel committed
560
561
    temp  = new KAction(i18n("&Preview"), this);
    actionCollection()->addAction("map_preview", temp );
Stephan Kulow's avatar
Stephan Kulow committed
562
  connect(temp, SIGNAL(triggered(bool)), SLOT(mapPreview()));
Jan Schäfer's avatar
Jan Schäfer committed
563
564
565
566
567
  temp->setToolTip(i18n("Show a preview"));

  // IMAGE
  i18n("&Image");

Jan Schäfer's avatar
Jan Schäfer committed
568
569
  imageAddAction  = new KAction(i18n("Add Image..."), this);
  actionCollection()->addAction("image_add", imageAddAction );
Stephan Kulow's avatar
Stephan Kulow committed
570
  connect(imageAddAction, SIGNAL(triggered(bool)), SLOT(imageAdd()));
Jonathan Riddell's avatar
Jonathan Riddell committed
571
  imageAddAction->setToolTip(i18n("Add a new image"));
Jan Schäfer's avatar
Jan Schäfer committed
572

Laurent Montel's avatar
Laurent Montel committed
573
574
    imageRemoveAction  = new KAction(i18n("Remove Image"), this);
    actionCollection()->addAction("image_remove", imageRemoveAction );
Stephan Kulow's avatar
Stephan Kulow committed
575
  connect(imageRemoveAction, SIGNAL(triggered(bool)), SLOT(imageRemove()));
Jonathan Riddell's avatar
Jonathan Riddell committed
576
577
  imageRemoveAction->setToolTip(i18n("Remove the current visible image"));

Laurent Montel's avatar
Laurent Montel committed
578
579
    imageUsemapAction  = new KAction(i18n("Edit Usemap..."), this);
    actionCollection()->addAction("image_usemap", imageUsemapAction );
Stephan Kulow's avatar
Stephan Kulow committed
580
  connect(imageUsemapAction, SIGNAL(triggered(bool)), SLOT(imageUsemap()));
Jonathan Riddell's avatar
Jonathan Riddell committed
581
582
  imageUsemapAction->setToolTip(i18n("Edit the usemap tag of the current visible image"));

Laurent Montel's avatar
Laurent Montel committed
583
584
    temp  = new KAction(i18n("Show &HTML"), this);
    actionCollection()->addAction("map_showhtml", temp );
Stephan Kulow's avatar
Stephan Kulow committed
585
  connect(temp, SIGNAL(triggered(bool)), SLOT(mapShowHTML()));
Jan Schäfer's avatar
Jan Schäfer committed
586
587


Jens Herden's avatar
Jens Herden committed
588
  QActionGroup *drawingGroup = new QActionGroup(this);
Jan Schäfer's avatar
Jan Schäfer committed
589
  // Selection Tool
Jan Schäfer's avatar
Jan Schäfer committed
590
591
592
  arrowAction = new KToggleAction(KIcon("arrow"), i18n("&Selection"), this);
  arrowAction->setShortcut(QKeySequence("s"));
  actionCollection()->addAction("tool_arrow", arrowAction);
Jens Herden's avatar
Jens Herden committed
593
  connect(arrowAction, SIGNAL(triggered(bool)), SLOT (slotDrawArrow()));
Jan Schäfer's avatar
Jan Schäfer committed
594
595
  arrowAction->setWhatsThis(i18n("<h3>Selection</h3>"
                          "Click this to select areas."));
Jens Herden's avatar
Jens Herden committed
596
  drawingGroup->addAction(arrowAction);
Jan Schäfer's avatar
Jan Schäfer committed
597
598
599
  arrowAction->setChecked(true);

  // Circle
Jan Schäfer's avatar
Jan Schäfer committed
600
601
602
603
  circleAction = new KToggleAction(KIcon( "circle"), i18n("&Circle"), this);
  circleAction->setShortcut(QKeySequence("c"));

  actionCollection()->addAction("tool_circle", circleAction);
604
  connect(circleAction, SIGNAL(triggered(bool)), this, SLOT(slotDrawCircle()));
Jan Schäfer's avatar
Jan Schäfer committed
605
606
  circleAction->setWhatsThis(i18n("<h3>Circle</h3>"
                          "Click this to start drawing a circle."));
Jens Herden's avatar
Jens Herden committed
607
  drawingGroup->addAction(circleAction);
Jan Schäfer's avatar
Jan Schäfer committed
608
609

  // Rectangle
Jan Schäfer's avatar
Jan Schäfer committed
610
611
    rectangleAction = new KToggleAction(KIcon("rectangle"), i18n("&Rectangle"), this);
  rectangleAction->setShortcut(QKeySequence("r"));
Laurent Montel's avatar
Laurent Montel committed
612
    actionCollection()->addAction("tool_rectangle", rectangleAction);
613
  connect(rectangleAction, SIGNAL(triggered(bool)), this, SLOT(slotDrawRectangle()));
Jan Schäfer's avatar
Jan Schäfer committed
614
615
  rectangleAction->setWhatsThis(i18n("<h3>Rectangle</h3>"
                          "Click this to start drawing a rectangle."));
Jens Herden's avatar
Jens Herden committed
616
  drawingGroup->addAction(rectangleAction);
Jan Schäfer's avatar
Jan Schäfer committed
617
618

  // Polygon
Jan Schäfer's avatar
Jan Schäfer committed
619
620
    polygonAction = new KToggleAction(KIcon("polygon"), i18n("&Polygon"), this);
  polygonAction->setShortcut(QKeySequence("p"));
Laurent Montel's avatar
Laurent Montel committed
621
    actionCollection()->addAction("tool_polygon", polygonAction);
622
  connect(polygonAction, SIGNAL(triggered(bool)), SLOT(slotDrawPolygon()));
Jan Schäfer's avatar
Jan Schäfer committed
623
624
  polygonAction->setWhatsThis(i18n("<h3>Polygon</h3>"
                          "Click this to start drawing a polygon."));
Jens Herden's avatar
Jens Herden committed
625
  drawingGroup->addAction(polygonAction);
Jan Schäfer's avatar
Jan Schäfer committed
626
627

  // Freehand
Jan Schäfer's avatar
Jan Schäfer committed
628
629
    freehandAction = new KToggleAction(KIcon("freehand"), i18n("&Freehand Polygon"), this);
  freehandAction->setShortcut(QKeySequence("f"));
Laurent Montel's avatar
Laurent Montel committed
630
    actionCollection()->addAction("tool_freehand", freehandAction);
631
  connect(freehandAction, SIGNAL(triggered(bool)), SLOT(slotDrawFreehand()));
Jan Schäfer's avatar
Jan Schäfer committed
632
633
  freehandAction->setWhatsThis(i18n("<h3>Freehandpolygon</h3>"
                          "Click this to start drawing a freehand polygon."));
Jens Herden's avatar
Jens Herden committed
634
  drawingGroup->addAction(freehandAction);
Jan Schäfer's avatar
Jan Schäfer committed
635
636

  // Add Point
Jan Schäfer's avatar
Jan Schäfer committed
637
638
    addPointAction = new KToggleAction(KIcon("addpoint"), i18n("&Add Point"), this);
  addPointAction->setShortcut(QKeySequence("a"));
Laurent Montel's avatar
Laurent Montel committed
639
    actionCollection()->addAction("tool_addpoint", addPointAction);
640
  connect(addPointAction, SIGNAL(triggered(bool)), SLOT(slotDrawAddPoint()));
Jan Schäfer's avatar
Jan Schäfer committed
641
642
  addPointAction->setWhatsThis(i18n("<h3>Add Point</h3>"
                          "Click this to add points to a polygon."));
Jens Herden's avatar
Jens Herden committed
643
  drawingGroup->addAction(addPointAction);
Jan Schäfer's avatar
Jan Schäfer committed
644
645

  // Remove Point
646
  removePointAction = new KToggleAction(KIcon("removepoint"), i18n("&Remove Point"), this);
Jan Schäfer's avatar
Jan Schäfer committed
647
  removePointAction->setShortcut(QKeySequence("e"));
648
649
650
  actionCollection()->addAction("tool_removepoint", removePointAction);
  connect(removePointAction, SIGNAL(triggered(bool)), 
          SLOT(slotDrawRemovePoint()));
Jan Schäfer's avatar
Jan Schäfer committed
651
652
  removePointAction->setWhatsThis(i18n("<h3>Remove Point</h3>"
                          "Click this to remove points from a polygon."));
Jens Herden's avatar
Jens Herden committed
653
  drawingGroup->addAction(removePointAction);
Jan Schäfer's avatar
Jan Schäfer committed
654

Laurent Montel's avatar
Laurent Montel committed
655
656
    KAction *action  = new KAction(i18n("Cancel Drawing"), this);
    actionCollection()->addAction("canceldrawing", action );
Stephan Kulow's avatar
Stephan Kulow committed
657
  connect(action, SIGNAL(triggered(bool)), SLOT( slotCancelDrawing() ));
658
  action->setShortcut(QKeySequence(Qt::Key_Escape));
Jan Schäfer's avatar
Jan Schäfer committed
659

Jan Schäfer's avatar
Jan Schäfer committed
660
661
  moveLeftAction  = new KAction(i18n("Move Left"), this);
  actionCollection()->addAction("moveleft", moveLeftAction );
662
  connect(moveLeftAction, SIGNAL(triggered(bool)),
Jan Schäfer's avatar
Jan Schäfer committed
663
         SLOT( slotMoveLeft() ));
664
  moveLeftAction->setShortcut(KShortcut(QKeySequence(Qt::Key_Left)));
Jan Schäfer's avatar
Jan Schäfer committed
665

Laurent Montel's avatar
Laurent Montel committed
666
667
    moveRightAction  = new KAction(i18n("Move Right"), this);
    actionCollection()->addAction("moveright", moveRightAction );
Stephan Kulow's avatar
Stephan Kulow committed
668
  connect(moveRightAction, SIGNAL(triggered(bool)), SLOT( slotMoveRight() ));
669
  moveRightAction->setShortcut(QKeySequence(Qt::Key_Right));
Jan Schäfer's avatar
Jan Schäfer committed
670

Laurent Montel's avatar
Laurent Montel committed
671
672
    moveUpAction  = new KAction(i18n("Move Up"), this);
    actionCollection()->addAction("moveup", moveUpAction );
Stephan Kulow's avatar
Stephan Kulow committed
673
  connect(moveUpAction, SIGNAL(triggered(bool)), SLOT( slotMoveUp() ));
674
  moveUpAction->setShortcut(QKeySequence(Qt::Key_Up));
Jan Schäfer's avatar
Jan Schäfer committed
675

Laurent Montel's avatar
Laurent Montel committed
676
677
    moveDownAction  = new KAction(i18n("Move Down"), this);
    actionCollection()->addAction("movedown", moveDownAction );
Stephan Kulow's avatar
Stephan Kulow committed
678
  connect(moveDownAction, SIGNAL(triggered(bool)), SLOT( slotMoveDown() ));
679
  moveDownAction->setShortcut(QKeySequence(Qt::Key_Down));
Jan Schäfer's avatar
Jan Schäfer committed
680

Laurent Montel's avatar
Laurent Montel committed
681
682
    increaseWidthAction  = new KAction(i18n("Increase Width"), this);
    actionCollection()->addAction("increasewidth", increaseWidthAction );
Stephan Kulow's avatar
Stephan Kulow committed
683
  connect(increaseWidthAction, SIGNAL(triggered(bool)), SLOT( slotIncreaseWidth() ));
684
  increaseWidthAction->setShortcut(QKeySequence(Qt::Key_Right + Qt::SHIFT));
Jan Schäfer's avatar
Jan Schäfer committed
685

Laurent Montel's avatar
Laurent Montel committed
686
687
    decreaseWidthAction  = new KAction(i18n("Decrease Width"), this);
    actionCollection()->addAction("decreasewidth", decreaseWidthAction );
Stephan Kulow's avatar
Stephan Kulow committed
688
  connect(decreaseWidthAction, SIGNAL(triggered(bool)), SLOT( slotDecreaseWidth() ));
689
  decreaseWidthAction->setShortcut(QKeySequence(Qt::Key_Left + Qt::SHIFT));
Jan Schäfer's avatar
Jan Schäfer committed
690

Laurent Montel's avatar
Laurent Montel committed
691
692
    increaseHeightAction  = new KAction(i18n("Increase Height"), this);
    actionCollection()->addAction("increaseheight", increaseHeightAction );
Stephan Kulow's avatar
Stephan Kulow committed
693
  connect(increaseHeightAction, SIGNAL(triggered(bool)), SLOT( slotIncreaseHeight() ));
694
  increaseHeightAction->setShortcut(QKeySequence(Qt::Key_Up + Qt::SHIFT));
Jan Schäfer's avatar
Jan Schäfer committed
695

Laurent Montel's avatar
Laurent Montel committed
696
697
    decreaseHeightAction  = new KAction(i18n("Decrease Height"), this);
    actionCollection()->addAction("decreaseheight", decreaseHeightAction );
Stephan Kulow's avatar
Stephan Kulow committed
698
  connect(decreaseHeightAction, SIGNAL(triggered(bool)), SLOT( slotDecreaseHeight() ));
699
  decreaseHeightAction->setShortcut(QKeySequence(Qt::Key_Down + Qt::SHIFT));
Jan Schäfer's avatar
Jan Schäfer committed
700

Laurent Montel's avatar
Laurent Montel committed
701
702
    toFrontAction  = new KAction(i18n("Bring to Front"), this);
    actionCollection()->addAction("tofront", toFrontAction );
Stephan Kulow's avatar
Stephan Kulow committed
703
  connect(toFrontAction, SIGNAL(triggered(bool)), SLOT( slotToFront() ));
Jan Schäfer's avatar
Jan Schäfer committed
704

Laurent Montel's avatar
Laurent Montel committed
705
706
    toBackAction  = new KAction(i18n("Send to Back"), this);
    actionCollection()->addAction("toback", toBackAction );
Stephan Kulow's avatar
Stephan Kulow committed
707
  connect(toBackAction, SIGNAL(triggered(bool)), SLOT( slotToBack() ));
Jan Schäfer's avatar
Jan Schäfer committed
708

Laurent Montel's avatar
Laurent Montel committed
709
710
    forwardOneAction  = new KAction(KIcon("raise"), i18n("Bring Forward One"), this);
    actionCollection()->addAction("forwardone", forwardOneAction );
711
  connect(forwardOneAction, SIGNAL(triggered(bool) ), SLOT( slotForwardOne() ));
Laurent Montel's avatar
Laurent Montel committed
712
713
    backOneAction  = new KAction(KIcon("lower"), i18n("Send Back One"), this);
    actionCollection()->addAction("backone", backOneAction );
714
  connect(backOneAction, SIGNAL(triggered(bool) ), SLOT( slotBackOne() ));
Jan Schäfer's avatar
Jan Schäfer committed
715

Simon Hausmann's avatar
Simon Hausmann committed
716
717
  areaListView->upBtn->addAction(forwardOneAction);
  areaListView->downBtn->addAction(backOneAction);
Jan Schäfer's avatar
Jan Schäfer committed
718

719
720
  connect( areaListView->upBtn, SIGNAL(pressed()), forwardOneAction, SLOT(trigger()));
  connect( areaListView->downBtn, SIGNAL(pressed()), backOneAction, SLOT(trigger()));
Jan Schäfer's avatar
Jan Schäfer committed
721

Laurent Montel's avatar
Laurent Montel committed
722
723
    action  = new KAction(KIcon("configure"), i18n("Configure KImageMapEditor..."), this);
    actionCollection()->addAction("configure_kimagemapeditor", action );
724
  connect(action, SIGNAL(triggered(bool) ), SLOT(slotShowPreferences()));
Jan Schäfer's avatar
Jan Schäfer committed
725

Laurent Montel's avatar
Laurent Montel committed
726
  kDebug() << "KImageMapEditor: 1";
727

Jonathan Riddell's avatar
Jonathan Riddell committed
728
729
  if (areaDock) {

Jan Schäfer's avatar
Jan Schäfer committed
730
731
    QAction* a =  areaDock->toggleViewAction();
    a->setText(i18n("Show Area List"));
732
    actionCollection()->addAction("configure_show_arealist",
Jan Schäfer's avatar
Jan Schäfer committed
733
				  a);
Jan Schäfer's avatar
Jan Schäfer committed
734

Jan Schäfer's avatar
Jan Schäfer committed
735
736
737
    a = mapsDock->toggleViewAction();
    a->setText(i18n("Show Map List"));
    actionCollection()->addAction("configure_show_maplist", a );
738

Jan Schäfer's avatar
Jan Schäfer committed
739
740
    a = imagesDock->toggleViewAction();
    a->setText(i18n("Show Image List"));
741
    actionCollection()->addAction("configure_show_imagelist", a );
Jonathan Riddell's avatar
Jonathan Riddell committed
742
743
  }

Laurent Montel's avatar
Laurent Montel committed
744
  kDebug() << "KImageMapEditor: 2";
Jan Schäfer's avatar
Jan Schäfer committed
745
  updateActionAccess();
Laurent Montel's avatar
Laurent Montel committed
746
  kDebug() << "KImageMapEditor: 3";
Jan Schäfer's avatar
Jan Schäfer committed
747
748
749
750
751
752
753
754
}

void KImageMapEditor::setupStatusBar()
{

//  We can't do this with a KPart !
//	widget()->statusBar()->insertItem(i18n(" Cursor")+" : x: 0 ,y: 0",STATUS_CURSOR);
//	widget()->statusBar()->insertItem(i18n(" Selection")+" : - ",STATUS_SELECTION);
755
  emit setStatusBarText( i18n(" Selection: -  Cursor: x: 0, y: 0 "));
Jan Schäfer's avatar
Jan Schäfer committed
756
757
758
759
760
}

void KImageMapEditor::slotShowPreferences()
{
  PreferencesDialog *dialog = new PreferencesDialog(widget(),config());
761
  connect(dialog, SIGNAL(preferencesChanged()), this, SLOT(slotConfigChanged()));
Jan Schäfer's avatar
Jan Schäfer committed
762
763
764
765
766
767
768
  dialog->exec();
  delete dialog;
}


void KImageMapEditor::showPopupMenu(const QPoint & pos, const QString & name)
{
Jan Schäfer's avatar
Jan Schäfer committed
769
  QMenu* pop = static_cast<QMenu *>(factory()->container(name, this));
Jan Schäfer's avatar
Jan Schäfer committed
770
771

  if (!pop) {
Laurent Montel's avatar
Laurent Montel committed
772
      kWarning() << QString("KImageMapEditorPart: Missing XML definition for %1\n").arg(name);
Jan Schäfer's avatar
Jan Schäfer committed
773
774
775
776
777
778
779
780
781
782
783
      return;
  }

  pop->popup(pos);
}

void KImageMapEditor::slotShowMainPopupMenu(const QPoint & pos)
{
  showPopupMenu(pos,"popup_main");
}

Jan Schäfer's avatar
Jan Schäfer committed
784
void KImageMapEditor::slotShowMapPopupMenu(const QPoint & pos)
Jan Schäfer's avatar
Jan Schäfer committed
785
{
Laurent Montel's avatar
Laurent Montel committed
786
  kDebug() << "slotShowMapPopupMenu";
Jan Schäfer's avatar
Jan Schäfer committed
787
  QTreeWidgetItem* item = mapsListView->listView()->itemAt(pos);
788

Jan Schäfer's avatar
Jan Schäfer committed
789
790
791
792
793
794
795
  if (isReadWrite()) {
    mapDeleteAction->setEnabled(item);
    mapNameAction->setEnabled(item);
    mapDefaultAreaAction->setEnabled(item);
  }

  if (item)
Jonathan Riddell's avatar
Jonathan Riddell committed
796
797
     mapsListView->selectMap(item);

Jan Schäfer's avatar
Jan Schäfer committed
798
  showPopupMenu(mapsListView->listView()->viewport()->mapToGlobal(pos),"popup_map");
Jan Schäfer's avatar
Jan Schäfer committed
799
800
}

Jan Schäfer's avatar
Jan Schäfer committed
801
void KImageMapEditor::slotShowImagePopupMenu(const QPoint & pos)
Jan Schäfer's avatar
Jan Schäfer committed
802
{
Laurent Montel's avatar
Laurent Montel committed
803
  kDebug() << "slotShowImagePopupMenu";
Jan Schäfer's avatar
Jan Schäfer committed
804
805
  QTreeWidgetItem* item = imagesListView->itemAt(pos);

Jan Schäfer's avatar
Jan Schäfer committed
806
807
808
809
  imageRemoveAction->setEnabled(item);
  imageUsemapAction->setEnabled(item);

  if (item)
Jan Schäfer's avatar
Jan Schäfer committed
810
     imagesListView->setCurrentItem(item);
Jonathan Riddell's avatar
Jonathan Riddell committed
811

Jan Schäfer's avatar
Jan Schäfer committed
812
  showPopupMenu(imagesListView->viewport()->mapToGlobal(pos),"popup_image");
Jan Schäfer's avatar
Jan Schäfer committed
813
814
}

Jan Schäfer's avatar
Jan Schäfer committed
815
void KImageMapEditor::slotShowPopupMenu(const QPoint & p)
Jan Schäfer's avatar
Jan Schäfer committed
816
{
Jan Schäfer's avatar
Jan Schäfer committed
817
818
  QTreeWidgetItem* item = areaListView->listView->itemAt(p);

Jan Schäfer's avatar
Jan Schäfer committed
819
820
821
822
823
824
825
826
827
  if (!item)
    return;

  if (!item->isSelected())
  {
    deselectAll();
    select(item);
  }

Jan Schäfer's avatar
Jan Schäfer committed
828
  slotShowMainPopupMenu(areaListView->listView->viewport()->mapToGlobal(p));
Jan Schäfer's avatar
Jan Schäfer committed
829
830
831
832
833
834
835
}

void KImageMapEditor::updateStatusBar()
{
  emit setStatusBarText(selectionStatusText+"  "+cursorStatusText);
}

Jonathan Riddell's avatar
Jonathan Riddell committed
836
void KImageMapEditor::slotChangeStatusCoords(int x,int y)
Jan Schäfer's avatar
Jan Schäfer committed
837
838
{
//	statusBar()->changeItem(QString(" Cursor : x: %1 ,y: %2 ").arg(x).arg(y),STATUS_CURSOR);
839
  cursorStatusText = i18n(" Cursor: x: %1, y: %2 ", x, y);
Jan Schäfer's avatar
Jan Schäfer committed
840
841
842
843
844
845
846
  updateStatusBar();
}

void KImageMapEditor::slotUpdateSelectionCoords() {
  if (selected()->count()>0) {
    QRect r=selected()->rect();
//		statusBar()->changeItem(
847
    selectionStatusText = i18n(" Selection: x: %1, y: %2, w: %3, h: %4 ", r.left(), r.top(), r.width(), r.height());
Jan Schäfer's avatar
Jan Schäfer committed
848
849
850
851

//		  ,STATUS_SELECTION);
    kapp->processEvents();
  } else
852
    selectionStatusText = i18n(" Selection: - ");
Jan Schäfer's avatar
Jan Schäfer committed
853
854
    //statusBar()->changeItem(" Selection : - ",STATUS_SELECTION);

Jonathan Riddell's avatar
Jonathan Riddell committed
855
  updateStatusBar();
Jan Schäfer's avatar
Jan Schäfer committed
856
857
858
859
}

void KImageMapEditor::slotUpdateSelectionCoords( const QRect & r )
{
860
  selectionStatusText = i18n(" Selection: x: %1, y: %2, w: %3, h: %4 ", r.left(), r.top(), r.width(), r.height());
Jan Schäfer's avatar
Jan Schäfer committed
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
  updateStatusBar();
  kapp->processEvents();
}

KApplication* KImageMapEditor::app() const
{
  return kapp;
}


void KImageMapEditor::drawToCenter(QPainter* p, const QString & str, int y, int width) {
  int xmid = width / 2;

  QFontMetrics fm = p->fontMetrics();
  QRect strBounds = fm.boundingRect(str);

  p->drawText(xmid-(strBounds.width()/2),y,str);
}


QImage KImageMapEditor::getBackgroundImage() {
Jonathan Riddell's avatar
Jonathan Riddell committed
882

Jan Schäfer's avatar
Jan Schäfer committed
883
884
  // Lazy initialisation
  if ( _backgroundImage.isNull() ) {
Jonathan Riddell's avatar
Jonathan Riddell committed
885
886


Jan Schäfer's avatar
Jan Schäfer committed
887
//  QString filename = QString("dropimage_")+KGlobal::locale()->language()+".png";
888
//  QString path = QString(); //KGlobal::dirs()->findResourceDir( "data", "kimagemapeditor/"+filename ) + "kimagemapeditor/"+filename;
Laurent Montel's avatar
Laurent Montel committed
889
//  kDebug() << "getBackgroundPic : loaded image : " << path;
Jonathan Riddell's avatar
Jonathan Riddell committed
890

Jan Schäfer's avatar
Jan Schäfer committed
891
892
893
894
895
//  if ( ! QFileInfo(path).exists() ) {
    int width = 400;
    int height = 400;
    int border = 20;
    int fontSize = 58;
Jonathan Riddell's avatar
Jonathan Riddell committed
896

Jan Schäfer's avatar
Jan Schäfer committed
897
898
899
    QPixmap pix(width,height);
    pix.fill(QColor(74,76,74));
    QPainter p(&pix);
Jonathan Riddell's avatar
Jonathan Riddell committed
900

901
902
903
904
    //    QFont font = QFontDatabase().font("Luxi Sans","Bold",fontSize);
    QFont font;
    font.setBold(true);
    font.setPixelSize(fontSize);
Jan Schäfer's avatar
Jan Schäfer committed
905
    p.setFont( font );
Andras Mantia's avatar
Andras Mantia committed
906
    p.setCompositionMode(QPainter::CompositionMode_Source);
Jan Schäfer's avatar
Jan Schäfer committed
907
    p.setPen(QPen(QColor(112,114,112),1));
Jonathan Riddell's avatar
Jonathan Riddell committed
908

Jan Schäfer's avatar
Jan Schäfer committed
909
910
    // The translated string must be divided into
    // parts with about the same size that fit to the image
911
    QString str = i18n("Drop an image or HTML file");
912
    const QStringList strList = str.split(" ");
Jonathan Riddell's avatar
Jonathan Riddell committed
913

Jan Schäfer's avatar
Jan Schäfer committed
914
    // Get the string parts
915
    QString tmp;
Jan Schäfer's avatar
Jan Schäfer committed
916
917
    QStringList outputStrList;
    QFontMetrics fm = p.fontMetrics();
Jonathan Riddell's avatar
Jonathan Riddell committed
918

919
    for ( QStringList::ConstIterator it = strList.begin(); it != strList.end(); ++it ) {
Jan Schäfer's avatar
Jan Schäfer committed
920
      QString tmp2 = tmp + *it;
Jonathan Riddell's avatar
Jonathan Riddell committed
921
922

        if (fm.boundingRect(tmp2).width() > width-border) {
Jan Schäfer's avatar
Jan Schäfer committed
923
           outputStrList.append(tmp);
Jens Herden's avatar
Jens Herden committed
924
           tmp = *it + ' ';
Jan Schäfer's avatar
Jan Schäfer committed
925
926
        }
        else
Jens Herden's avatar
Jens Herden committed
927
          tmp = tmp2 + ' ';
Jan Schäfer's avatar
Jan Schäfer committed
928
    }
Jonathan Riddell's avatar
Jonathan Riddell committed
929

Jan Schäfer's avatar
Jan Schäfer committed
930
931
932
933
934
935
    // Last one was forgotten so add it.
    outputStrList.append(tmp);

    // Try to adjust the text vertically centered
    int step = myround(float(height) / (outputStrList.size()+1));
    int y = step;
Jonathan Riddell's avatar
Jonathan Riddell committed
936

Jan Schäfer's avatar
Jan Schäfer committed
937
938
939
940
    for ( QStringList::Iterator it = outputStrList.begin(); it != outputStrList.end(); ++it ) {
        drawToCenter(&p, *it, y, pix.width());
        y += step;
    }
Jonathan Riddell's avatar
Jonathan Riddell committed
941

Jan Schäfer's avatar
Jan Schäfer committed
942
943
    p.end();

944
    _backgroundImage = pix.toImage();
Jan Schäfer's avatar
Jan Schäfer committed
945
946
947
948
  }


  return _backgroundImage;
Jonathan Riddell's avatar
Jonathan Riddell committed
949
950

/*
Jan Schäfer's avatar
Jan Schäfer committed
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
        QFontDatabase fdb;
    QStringList families = fdb.families();
    for ( QStringList::Iterator f = families.begin(); f != families.end(); ++f ) {
        QString family = *f;
        qDebug( family );
        QStringList styles = fdb.styles( family );
        for ( QStringList::Iterator s = styles.begin(); s != styles.end(); ++s ) {
            QString style = *s;
            QString dstyle = "\t" + style + " (";
            QValueList<int> smoothies = fdb.smoothSizes( family, style );
            for ( QValueList<int>::Iterator points = smoothies.begin();
                  points != smoothies.end(); ++points ) {
                dstyle += QString::number( *points ) + " ";
            }
            dstyle = dstyle.left( dstyle.length() - 1 ) + ")";
            qDebug( dstyle );
        }
    }
Jonathan Riddell's avatar
Jonathan Riddell committed
969
970


Jan Schäfer's avatar
Jan Schäfer committed
971
    path = KGlobal::dirs()->saveLocation( "data", "kimagemapeditor/" ) +filename;
Laurent Montel's avatar
Laurent Montel committed
972
    kDebug() << "getBackgroundPic : save new image to : " << path;
Jan Schäfer's avatar
Jan Schäfer committed
973
    pix.save(path,"PNG",100);
Jonathan Riddell's avatar
Jonathan Riddell committed
974
  }
Jan Schäfer's avatar
Jan Schäfer committed
975
976

  if ( ! QFileInfo(path).exists() ) {
977
      kError() << "Couldn't find needed " << filename << " file in "
Jan Schäfer's avatar
Jan Schäfer committed
978
979
                   "the data directory of KImageMapEditor.\n"
                   "Perhaps you have forgotten to do a make install !" << endl;
Jonathan Riddell's avatar
Jonathan Riddell committed
980
      exit(1);
Jan Schäfer's avatar
Jan Schäfer committed
981
  }
Jonathan Riddell's avatar
Jonathan Riddell committed
982
*/
Jan Schäfer's avatar
Jan Schäfer committed
983
984
985
986
987
988
989
990
991
992
993
994
}


void KImageMapEditor::addArea(Area* area) {
  if (!area) return;

  // Perhaps we've got a selection of areas
  // so test it and add all areas of the selection
  // nested selections are possible but doesn't exist
  AreaSelection *selection=0L;
  if ( (selection = dynamic_cast <AreaSelection*> ( area ) ) )
  {
Jan Schäfer's avatar
Jan Schäfer committed
995
996
    AreaListIterator it = selection->getAreaListIterator();
    while (it.hasNext()) {
997
      Area* a = it.next();
Jan Schäfer's avatar
Jan Schäfer committed
998
      areas->prepend(a);
Jan Schäfer's avatar
Jan Schäfer committed
999
1000
1001
1002
      a->setListViewItem(new QTreeWidgetItem(
          areaListView->listView,
          QStringList(a->attribute("href"))));
      a->listViewItem()->setIcon(1,QIcon(makeListViewPix(*a)));
Jan Schäfer's avatar
Jan Schäfer committed
1003
1004
1005
1006
1007
    }
  }
  else
  {
    areas->prepend(area);
Jan Schäfer's avatar
Jan Schäfer committed
1008
1009
1010
1011
    area->setListViewItem(new QTreeWidgetItem(
      areaListView->listView,
      QStringList(area->attribute("href"))));
    area->listViewItem()->setIcon(1,QIcon(makeListViewPix(*area)));
Jan Schäfer's avatar
Jan Schäfer committed
1012
1013
1014
1015
1016
1017
1018
1019
1020
  }

  setModified(true);

}

void KImageMapEditor::addAreaAndEdit(Area* s)
{
  areas->prepend(s);
Jan Schäfer's avatar
Jan Schäfer committed
1021
1022
1023