kimedialogs.cpp 19.1 KB
Newer Older
Jan Schäfer's avatar
Jan Schäfer committed
1
2
3
4
/***************************************************************************
                          kimedialogs.cpp  -  description
                            -------------------
    begin                : Tue Apr 17 2001
5
    copyright            : (C) 2001 by Jan Schäfer
Jan Schäfer's avatar
Jan Schäfer committed
6
7
8
9
10
11
12
13
14
15
16
17
    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.                                   *
*                                                                         *
***************************************************************************/

Yuri Chornoivan's avatar
Yuri Chornoivan committed
18
19
20
// LOCAL
#include "kimedialogs.h"

Luigi Toscano's avatar
Luigi Toscano committed
21
// Qt
Yuri Chornoivan's avatar
Yuri Chornoivan committed
22
#include <QCheckBox>
23
24
25
#include <QDialogButtonBox>
#include <QFileDialog>
#include <QFormLayout>
Yuri Chornoivan's avatar
Yuri Chornoivan committed
26
27
28
#include <QFrame>
#include <QHeaderView>
#include <QImage>
Yuri Chornoivan's avatar
Yuri Chornoivan committed
29
#include <QLabel>
Yuri Chornoivan's avatar
Yuri Chornoivan committed
30
#include <QLayout>
Yuri Chornoivan's avatar
Yuri Chornoivan committed
31
#include <QLineEdit>
Yuri Chornoivan's avatar
Yuri Chornoivan committed
32
#include <QLinkedList>
Jan Schäfer's avatar
Jan Schäfer committed
33
#include <QListWidget>
Yuri Chornoivan's avatar
Yuri Chornoivan committed
34
#include <QPixmap>
35
#include <QPushButton>
Yuri Chornoivan's avatar
Yuri Chornoivan committed
36
37
#include <QSpinBox>
#include <QTableWidget>
38
#include <QTemporaryFile>
39
40
#include <QVBoxLayout>

Luigi Toscano's avatar
Luigi Toscano committed
41
// KDE Frameworks
42
#include "kimagemapeditor_debug.h"
43
#include <KConfigGroup>
44
45
#include <KLocalizedString>
#include <KSharedConfig>
Jan Schäfer's avatar
Jan Schäfer committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

CoordsEdit::CoordsEdit(QWidget *parent, Area* a)
  : QWidget(parent)
{
  area=a;
}

void CoordsEdit::applyChanges() {
  return;
}

void CoordsEdit::slotTriggerUpdate() {
  applyChanges();
  emit update();
}

CoordsEdit::~CoordsEdit()
{
}

RectCoordsEdit::RectCoordsEdit(QWidget *parent, Area* a)
  : CoordsEdit(parent,a)
{
69
  QFormLayout *layout= new QFormLayout(this);
Jan Schäfer's avatar
Jan Schäfer committed
70
71

  topXSpin = new QSpinBox(this);
Albert Astals Cid's avatar
Albert Astals Cid committed
72
  topXSpin->setMaximum(INT_MAX);
Jens Herden's avatar
Jens Herden committed
73
  topXSpin->setMinimum(0);
Jan Schäfer's avatar
Jan Schäfer committed
74
  topXSpin->setValue(a->rect().left());
Yuri Chornoivan's avatar
Yuri Chornoivan committed
75
  connect( topXSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
76
  layout->addRow(i18n("Top &X:"), topXSpin);
Jan Schäfer's avatar
Jan Schäfer committed
77
78

  topYSpin = new QSpinBox(this);
Albert Astals Cid's avatar
Albert Astals Cid committed
79
  topYSpin->setMaximum(INT_MAX);
Jens Herden's avatar
Jens Herden committed
80
  topYSpin->setMinimum(0);
Jan Schäfer's avatar
Jan Schäfer committed
81
  topYSpin->setValue(a->rect().top());
Yuri Chornoivan's avatar
Yuri Chornoivan committed
82
  connect( topYSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
83
  layout->addRow(i18n("Top &Y:"), topYSpin);
Jan Schäfer's avatar
Jan Schäfer committed
84
85

  widthSpin = new QSpinBox(this);
Albert Astals Cid's avatar
Albert Astals Cid committed
86
  widthSpin->setMaximum(INT_MAX);
Jens Herden's avatar
Jens Herden committed
87
  widthSpin->setMinimum(0);
Jan Schäfer's avatar
Jan Schäfer committed
88
  widthSpin->setValue(a->rect().width());
Yuri Chornoivan's avatar
Yuri Chornoivan committed
89
  connect( widthSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
90
  layout->addRow(i18n("&Width:"), widthSpin);
Jan Schäfer's avatar
Jan Schäfer committed
91
92

  heightSpin = new QSpinBox(this);
Albert Astals Cid's avatar
Albert Astals Cid committed
93
  heightSpin->setMaximum(INT_MAX);
Jens Herden's avatar
Jens Herden committed
94
  heightSpin->setMinimum(0);
Jan Schäfer's avatar
Jan Schäfer committed
95
  heightSpin->setValue(a->rect().height());
Yuri Chornoivan's avatar
Yuri Chornoivan committed
96
  connect( heightSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
97
  layout->addRow(i18n("Hei&ght:"), heightSpin);
Jan Schäfer's avatar
Jan Schäfer committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
}

void RectCoordsEdit::applyChanges() {
  QRect r;
  r.setLeft(topXSpin->text().toInt());
  r.setTop(topYSpin->text().toInt());
  r.setWidth(widthSpin->text().toInt());
  r.setHeight(heightSpin->text().toInt());
  area->setRect(r);
}

CircleCoordsEdit::CircleCoordsEdit(QWidget *parent, Area* a)
  : CoordsEdit(parent,a)
{
112
  QFormLayout *layout = new QFormLayout(this);
Jan Schäfer's avatar
Jan Schäfer committed
113
114

  centerXSpin = new QSpinBox(this);
Albert Astals Cid's avatar
Albert Astals Cid committed
115
  centerXSpin->setMaximum(INT_MAX);
Jens Herden's avatar
Jens Herden committed
116
  centerXSpin->setMinimum(0);
Jan Schäfer's avatar
Jan Schäfer committed
117
  centerXSpin->setValue(a->rect().center().x());
Yuri Chornoivan's avatar
Yuri Chornoivan committed
118
  connect( centerXSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
119
  layout->addRow(i18n("Center &X:"), centerXSpin);
Jan Schäfer's avatar
Jan Schäfer committed
120
121

  centerYSpin = new QSpinBox(this);
Albert Astals Cid's avatar
Albert Astals Cid committed
122
  centerYSpin->setMaximum(INT_MAX);
Jens Herden's avatar
Jens Herden committed
123
  centerYSpin->setMinimum(0);
Jan Schäfer's avatar
Jan Schäfer committed
124
  centerYSpin->setValue(a->rect().center().y());
Yuri Chornoivan's avatar
Yuri Chornoivan committed
125
  connect( centerYSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
126
  layout->addRow(i18n("Center &Y:"), centerYSpin);
Jan Schäfer's avatar
Jan Schäfer committed
127
128

  radiusSpin = new QSpinBox(this);
Albert Astals Cid's avatar
Albert Astals Cid committed
129
  radiusSpin->setMaximum(INT_MAX);
Jens Herden's avatar
Jens Herden committed
130
  radiusSpin->setMinimum(0);
Jan Schäfer's avatar
Jan Schäfer committed
131
  radiusSpin->setValue(a->rect().width()/2);
Yuri Chornoivan's avatar
Yuri Chornoivan committed
132
  connect( radiusSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
Yuri Chornoivan's avatar
Yuri Chornoivan committed
133
  layout->addRow(i18n("&Radius:"), radiusSpin);
Jan Schäfer's avatar
Jan Schäfer committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

}

void CircleCoordsEdit::applyChanges() {
  QRect r;
  r.setWidth(radiusSpin->text().toInt()*2);
  r.setHeight(radiusSpin->text().toInt()*2);
  r.moveCenter(QPoint(centerXSpin->text().toInt(),
                      centerYSpin->text().toInt()));
  area->setRect(r);
}

PolyCoordsEdit::PolyCoordsEdit(QWidget *parent, Area* a)
  : CoordsEdit(parent,a)
{
  if (!a) return;
150
151
152
  QVBoxLayout *layout = new QVBoxLayout(this);

  coordsTable = new QTableWidget(0, 2);
Jan Schäfer's avatar
Jan Schäfer committed
153
  coordsTable->verticalHeader()->hide();
154
  coordsTable->setSelectionMode( QTableWidget::SingleSelection );
Jan Schäfer's avatar
Jan Schäfer committed
155
156
  connect( coordsTable, SIGNAL(currentChanged(int,int)), this, SLOT(slotHighlightPoint(int)));

157
  updatePoints();
Jan Schäfer's avatar
Jan Schäfer committed
158
159
160
//	coordsTable->setMinimumHeight(50);
//	coordsTable->setMaximumHeight(400);
//	coordsTable->resizeContents(100,100);
161
  coordsTable->resize(coordsTable->width(), 100);
Jan Schäfer's avatar
Jan Schäfer committed
162
  layout->addWidget(coordsTable);
163
164
165
166
167
  layout->setStretchFactor(coordsTable, -1);

  QHBoxLayout *hbox = new QHBoxLayout;
  QPushButton *addBtn = new QPushButton(i18n("Add"));
  hbox->addWidget(addBtn);
Jan Schäfer's avatar
Jan Schäfer committed
168
  connect( addBtn, SIGNAL(pressed()), this, SLOT(slotAddPoint()));
169
170
  QPushButton *removeBtn = new QPushButton(i18n("Remove"));
  hbox->addWidget(removeBtn);
Jan Schäfer's avatar
Jan Schäfer committed
171
172
  connect( removeBtn, SIGNAL(pressed()), this, SLOT(slotRemovePoint()));

173
174
  layout->addLayout(hbox);

Jan Schäfer's avatar
Jan Schäfer committed
175
176
177
178
179
180
181
182
183
184
185
186
187
  slotHighlightPoint(1);
}

PolyCoordsEdit::~PolyCoordsEdit() {
}

void PolyCoordsEdit::slotHighlightPoint(int row) {
  if (!area) return;
  area->highlightSelectionPoint(row);
  emit update();
}


188
189
void PolyCoordsEdit::updatePoints() {
  coordsTable->clear();
Jan Schäfer's avatar
Jan Schäfer committed
190

191
  int count=area->coords().size();
Jan Schäfer's avatar
Jan Schäfer committed
192

193
194
  coordsTable->setHorizontalHeaderLabels(QStringList() << "X" << "Y");
  coordsTable->setRowCount(count);
Jan Schäfer's avatar
Jan Schäfer committed
195
196

  for (int i=0;i<count;i++) {
197
198
    coordsTable->setItem(i,0, new QTableWidgetItem(QString::number(area->coords().point(i).x()) ));
    coordsTable->setItem(i,1, new QTableWidgetItem(QString::number(area->coords().point(i).y()) ));
Jan Schäfer's avatar
Jan Schäfer committed
199
200
201
202
203
  }

  emit update();
}

204
205
void PolyCoordsEdit::slotAddPoint() {
  int newPos= coordsTable->currentRow();
206
  if (newPos < 0 || newPos >= area->coords().size())
207
    newPos = area->coords().size();
Jan Schäfer's avatar
Jan Schäfer committed
208

209
210
211
  QPoint currentPoint=area->coords().point(newPos);
  area->insertCoord(newPos,currentPoint);
  updatePoints();
Jan Schäfer's avatar
Jan Schäfer committed
212

213
}
Jan Schäfer's avatar
Jan Schäfer committed
214

215
216
217
218
219
220
void PolyCoordsEdit::slotRemovePoint() {
  int currentPos= coordsTable->currentRow();
  if (currentPos < 0 || currentPos >= area->coords().size())
    return;
  area->removeCoord(currentPos);
  updatePoints();
Jan Schäfer's avatar
Jan Schäfer committed
221
222
223
}

void PolyCoordsEdit::applyChanges() {
224
  int count=coordsTable->rowCount();
Jan Schäfer's avatar
Jan Schäfer committed
225
226

  for (int i=0;i<count;i++) {
227
228
    QPoint newPoint( coordsTable->item(i,0)->text().toInt(),
                    coordsTable->item(i,1)->text().toInt());
Jan Schäfer's avatar
Jan Schäfer committed
229
230

    area->moveCoord(i,newPoint);
Stephan Binner's avatar
Stephan Binner committed
231
  }
Jan Schäfer's avatar
Jan Schäfer committed
232
233
234
235
236
}

SelectionCoordsEdit::SelectionCoordsEdit(QWidget *parent, Area* a)
  : CoordsEdit(parent,a)
{
237
  QFormLayout *layout = new QFormLayout(this);
Jan Schäfer's avatar
Jan Schäfer committed
238
239

  topXSpin = new QSpinBox(this);
Albert Astals Cid's avatar
Albert Astals Cid committed
240
  topXSpin->setMaximum(INT_MAX);
Jens Herden's avatar
Jens Herden committed
241
  topXSpin->setMinimum(0);
Jan Schäfer's avatar
Jan Schäfer committed
242
  topXSpin->setValue(a->rect().left());
Yuri Chornoivan's avatar
Yuri Chornoivan committed
243
  connect( topXSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
244
  layout->addRow(i18n("Top &X"), topXSpin);
Jan Schäfer's avatar
Jan Schäfer committed
245
246

  topYSpin = new QSpinBox(this);
Albert Astals Cid's avatar
Albert Astals Cid committed
247
  topYSpin->setMaximum(INT_MAX);
Jens Herden's avatar
Jens Herden committed
248
  topYSpin->setMinimum(0);
Jan Schäfer's avatar
Jan Schäfer committed
249
  topYSpin->setValue(a->rect().top());
Yuri Chornoivan's avatar
Yuri Chornoivan committed
250
  connect( topYSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
Jan Schäfer's avatar
Jan Schäfer committed
251

252
  layout->addRow(i18n("Top &Y"), topYSpin);
Jan Schäfer's avatar
Jan Schäfer committed
253
254
255
256
257
258
259
260
}

void SelectionCoordsEdit::applyChanges() {
  area->moveTo(topXSpin->text().toInt(), topYSpin->text().toInt());
}



261
QLineEdit* AreaDialog::createLineEdit(QFormLayout *layout, const QString &value, const QString &name)
Jan Schäfer's avatar
Jan Schäfer committed
262
{
263
264
  QLineEdit *edit = new QLineEdit(value);
  layout->addRow(name, edit);
Jan Schäfer's avatar
Jan Schäfer committed
265
266
267
268
269
  return edit;
}

QWidget* AreaDialog::createGeneralPage()
{
270
271
272
273
274
275
276
  QFrame *page = new QFrame(this);
  QFormLayout *layout = new QFormLayout(page);

  // A separate widget, not just a layout, is needed so that
  // the accelerator for the row is working
  QWidget *hbox = new QWidget;
  QHBoxLayout *hboxLayout = new QHBoxLayout(hbox);
Laurent Montel's avatar
Laurent Montel committed
277
  hboxLayout->setContentsMargins(0, 0, 0, 0);
278
279
280
  hrefEdit = new QLineEdit(area->attribute("href"));
  hboxLayout->addWidget(hrefEdit);
  QPushButton *btn = new QPushButton;
281
  btn->setIcon(QIcon::fromTheme("document-open"));
Jan Schäfer's avatar
Jan Schäfer committed
282
  connect( btn, SIGNAL(pressed()), this, SLOT(slotChooseHref()));
283
  hboxLayout->addWidget(btn);
Jan Schäfer's avatar
Jan Schäfer committed
284

285
286
287
  QLabel *lblHREF = new QLabel(i18n("&HREF:"));
  lblHREF->setBuddy(hrefEdit);
  layout->addRow(lblHREF, hbox);
Jan Schäfer's avatar
Jan Schäfer committed
288

289
  altEdit = createLineEdit(layout,
Jan Schäfer's avatar
Jan Schäfer committed
290
291
			   area->attribute("alt"),
			   i18n("Alt. &Text:"));
292
  targetEdit = createLineEdit(layout,
Jan Schäfer's avatar
Jan Schäfer committed
293
294
			      area->attribute("target"),
			      i18n("Tar&get:"));
295
  titleEdit = createLineEdit(layout,
Jan Schäfer's avatar
Jan Schäfer committed
296
297
			     area->attribute("title"),
			     i18n("Tit&le:"));
Jan Schäfer's avatar
Jan Schäfer committed
298

299
300
301
  if (area->type() == Area::Default) {
    defaultAreaChk = new QCheckBox(i18n("On"));
    if (area->finished()) {
Jan Schäfer's avatar
Jan Schäfer committed
302
      defaultAreaChk->setChecked(true);
303
304
    }
    layout->addRow(i18n("Enable default map"), defaultAreaChk);
Jan Schäfer's avatar
Jan Schäfer committed
305
306
307
308
309
310
311
  }

  return page;
}

QWidget* AreaDialog::createCoordsPage()
{
312
313
  QFrame* page = new QFrame(this);
  QVBoxLayout *layout = new QVBoxLayout(page);
Laurent Montel's avatar
Laurent Montel committed
314
  layout->setContentsMargins(5, 5, 5, 5);
Jan Schäfer's avatar
Jan Schäfer committed
315

316
  coordsEdit = createCoordsEdit(page, area);
Jan Schäfer's avatar
Jan Schäfer committed
317
318
319
320
321
322
323
324
  layout->addWidget(coordsEdit);
  connect( coordsEdit, SIGNAL(update()), this, SLOT(slotUpdateArea()));

  return page;
}

QWidget* AreaDialog::createJavascriptPage()
{
325
326
  QFrame *page = new QFrame(this);
  QFormLayout *layout = new QFormLayout(page);
Jan Schäfer's avatar
Jan Schäfer committed
327

328
329
330
331
332
333
334
  onClickEdit = createLineEdit(layout, area->attribute("onClick"), i18n("OnClick:"));
  onDblClickEdit = createLineEdit(layout, area->attribute("onDblClick"), i18n("OnDblClick:"));
  onMouseDownEdit = createLineEdit(layout, area->attribute("onMouseDown"), i18n("OnMouseDown:"));
  onMouseUpEdit = createLineEdit(layout, area->attribute("onMouseUp"), i18n("OnMouseUp:"));
  onMouseOverEdit = createLineEdit(layout, area->attribute("onMouseOver"), i18n("OnMouseOver:"));
  onMouseMoveEdit = createLineEdit(layout, area->attribute("onMouseMove"), i18n("OnMouseMove:"));
  onMouseOutEdit = createLineEdit(layout, area->attribute("onMouseOut"), i18n("OnMouseOut:"));
Jan Schäfer's avatar
Jan Schäfer committed
335
336
337
338

  return page;
}

339
340
AreaDialog::AreaDialog(KImageMapEditor* parent, Area* a)
  : QDialog(parent->widget())
Jan Schäfer's avatar
Jan Schäfer committed
341
{
342
  setWindowTitle(i18n("Area Tag Editor"));
343
344
345
  //  setFaceType( KPageDialog::Tabbed );
  setObjectName( "Area Tag Editor" );
  setModal(true);
346
347

  _document = parent;
Jan Schäfer's avatar
Jan Schäfer committed
348

349
350
351
352
353
  if (!a) {
      slotCancel();
      return;
  }

354
355
356
357
  area = a;
  QString shape("Default");
  areaCopy = a->clone();
  oldArea = new Area();
Jan Schäfer's avatar
Jan Schäfer committed
358
359
360
  oldArea->setRect( a->rect() );

  switch (a->type()) {
361
362
363
364
365
    case Area::Rectangle: shape = i18n("Rectangle"); break;
    case Area::Circle: shape = i18n("Circle"); break;
    case Area::Polygon: shape = i18n("Polygon"); break;
    case Area::Selection: shape = i18n("Selection"); break;
    default: break;
Jan Schäfer's avatar
Jan Schäfer committed
366
367
  }

368
  QVBoxLayout *layout = new QVBoxLayout(this);
Jan Schäfer's avatar
Jan Schäfer committed
369
370

  // To get a margin around everything
Laurent Montel's avatar
Laurent Montel committed
371
  layout->setContentsMargins(5, 5, 5, 5);
Jan Schäfer's avatar
Jan Schäfer committed
372

373
  QLabel *lbl = new QLabel("<b>"+shape+"</b>");
Jan Schäfer's avatar
Jan Schäfer committed
374
375
376
  lbl->setTextFormat(Qt::RichText);
  layout->addWidget(lbl);

377
378
  QFrame *line = new QFrame;
  line->setFrameStyle(QFrame::HLine | QFrame::Sunken);
Jan Schäfer's avatar
Jan Schäfer committed
379
380
381
  line->setFixedHeight(10);
  layout->addWidget(line);

382
383
  QTabWidget *tab = new QTabWidget;
  tab->addTab(createGeneralPage(), i18n("&General"));
Jan Schäfer's avatar
Jan Schäfer committed
384
385
  layout->addWidget(tab);

386
  if (a->type() == Area::Default) {
Yuri Chornoivan's avatar
Yuri Chornoivan committed
387
    // FIXME? Why this useless assignment?
388
389
390
    shape = i18n("Default");
  } else {
    tab->addTab(createCoordsPage(), i18n("Coor&dinates"));
Stephan Binner's avatar
Stephan Binner committed
391
  }
392
393
394
395
396
397
398
  tab->addTab(createJavascriptPage(), i18n("&JavaScript"));

  QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply);
  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
  okButton->setDefault(true);
  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
  layout->addWidget(buttonBox);
Jan Schäfer's avatar
Jan Schäfer committed
399

400
401
402
  connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotOk()));
  connect(buttonBox, SIGNAL(rejected()), this, SLOT(slotCancel()));
  connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotApply()));
Jan Schäfer's avatar
Jan Schäfer committed
403
404
405
406
407
408
409
410
411
412
413
414
415

  setMinimumHeight(360);
  setMinimumWidth(327);

  resize(327,360);
}

AreaDialog::~AreaDialog() {
  delete areaCopy;
  delete oldArea;
}

CoordsEdit* AreaDialog::createCoordsEdit(QWidget *parent, Area *a) {
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
416
  if (!a) return nullptr;
Jan Schäfer's avatar
Jan Schäfer committed
417
418
  switch (a->type()) {
    case Area::Rectangle :
Stephan Binner's avatar
Stephan Binner committed
419
        return new RectCoordsEdit(parent,a);
Jan Schäfer's avatar
Jan Schäfer committed
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
      break;
    case Area::Circle :
        return new CircleCoordsEdit(parent,a);
      break;
    case Area::Polygon :
        return new PolyCoordsEdit(parent,a);
      break;
    case Area::Selection :
        return new SelectionCoordsEdit(parent,a);
      break;
    case Area::Default : return new CoordsEdit(parent,a); break;
    default : return new CoordsEdit(parent,a);break;
  }
}

void AreaDialog::slotChooseHref() {
436
  QUrl url = QFileDialog::getOpenFileUrl(this, i18n("Choose File"), QUrl(), i18n("All Files (*)"));
Jan Schäfer's avatar
Jan Schäfer committed
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
462
  if (!url.isEmpty()) {
    hrefEdit->setText(url.url());
  }
}

void AreaDialog::slotOk() {
  if (area)
  {
    area->highlightSelectionPoint(-1);
    if (area->type()==Area::Default)
      area->setFinished(defaultAreaChk->isChecked());
  }
  slotApply();
  accept();

}

void AreaDialog::slotApply() {
  if (area) {
    if (area->type()!=Area::Default)
      coordsEdit->applyChanges();

    area->setAttribute("href",hrefEdit->text());
    area->setAttribute("alt",altEdit->text());
    area->setAttribute("target",targetEdit->text());
    area->setAttribute("title",titleEdit->text());
463
464
    area->setAttribute("onclick",onClickEdit->text());
    area->setAttribute("ondblclick",onDblClickEdit->text());
Jan Schäfer's avatar
Jan Schäfer committed
465
466
467
468
469
470
471
472
473
474
475
    area->setAttribute("onmousedown",onMouseDownEdit->text());
    area->setAttribute("onmouseup",onMouseUpEdit->text());
    area->setAttribute("onmousemove",onMouseMoveEdit->text());
    area->setAttribute("onmouseover",onMouseOverEdit->text());
    area->setAttribute("onmouseout",onMouseOutEdit->text());

    // redraw old area to get rid of it
    emit areaChanged(oldArea);
    // draw new area
    emit areaChanged(area);
    oldArea->setRect(area->rect());
Stephan Binner's avatar
Stephan Binner committed
476
  }
Jan Schäfer's avatar
Jan Schäfer committed
477
478
479
480
}

void AreaDialog::slotCancel() {
  if (area) {
Friedrich W. H. Kossebau's avatar
Friedrich W. H. Kossebau committed
481
    AreaSelection *selection = nullptr;
Jan Schäfer's avatar
Jan Schäfer committed
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
    if ( (selection=dynamic_cast<AreaSelection*>(areaCopy)) )
      area->setArea(*selection);
    else
      area->setArea(*areaCopy);
    area->highlightSelectionPoint(-1);
    emit areaChanged(oldArea);
    emit areaChanged(area);
  }
  reject();
}

void AreaDialog::slotUpdateArea() {
    emit areaChanged(oldArea);
    // draw new area
    emit areaChanged(area);
    oldArea->setRect(area->rect());
}


PreferencesDialog::PreferencesDialog(QWidget *parent, KConfig* conf)
502
  : QDialog(parent)
Jan Schäfer's avatar
Jan Schäfer committed
503
504
{
  config = conf;
505
  setWindowTitle(i18n("Preferences"));
Laurent Montel's avatar
Laurent Montel committed
506
  setModal(true);
Jan Schäfer's avatar
Jan Schäfer committed
507

508
  QVBoxLayout *mainLayout = new QVBoxLayout(this);
Jan Schäfer's avatar
Jan Schäfer committed
509

510
511
  QFormLayout *optionsLayout = new QFormLayout;
  mainLayout->addLayout(optionsLayout);
Jan Schäfer's avatar
Jan Schäfer committed
512

513
  rowHeightSpinBox = new QSpinBox;
514
  int maxPrevHeight = config->group("Appearance").readEntry("maximum-preview-height",50);
Jens Herden's avatar
Jens Herden committed
515
516
  rowHeightSpinBox->setMaximum(1000);
  rowHeightSpinBox->setMinimum(15);
Jan Schäfer's avatar
Jan Schäfer committed
517
  rowHeightSpinBox->setFixedWidth(60);
518
  rowHeightSpinBox->setValue(maxPrevHeight);
519
  optionsLayout->addRow(i18n("&Maximum image preview height:"), rowHeightSpinBox);
Jan Schäfer's avatar
Jan Schäfer committed
520

521
  KConfigGroup general = config->group("General");
Jan Schäfer's avatar
Jan Schäfer committed
522

523
  undoSpinBox = new QSpinBox;
Jan Schäfer's avatar
Jan Schäfer committed
524
  undoSpinBox->setFixedWidth(60);
Jens Herden's avatar
Jens Herden committed
525
526
  undoSpinBox->setMaximum(100);
  undoSpinBox->setMinimum(1);
527
  undoSpinBox->setValue(general.readEntry("undo-level",20));
528
  optionsLayout->addRow(i18n("&Undo limit:"), undoSpinBox);
Jan Schäfer's avatar
Jan Schäfer committed
529

530
  redoSpinBox = new QSpinBox;
Jan Schäfer's avatar
Jan Schäfer committed
531
  redoSpinBox->setFixedWidth(60);
Jens Herden's avatar
Jens Herden committed
532
533
  redoSpinBox->setMaximum(100);
  redoSpinBox->setMinimum(1);
534
  redoSpinBox->setValue(general.readEntry("redo-level",20));
535
  optionsLayout->addRow(i18n("&Redo limit:"), redoSpinBox);
Stephan Binner's avatar
Stephan Binner committed
536

537
  startWithCheck = new QCheckBox(i18n("On"));
538
  startWithCheck->setChecked(general.readEntry("start-with-last-used-document",true));
539
  optionsLayout->addRow(i18n("&Start with last used document"), startWithCheck);
Jan Schäfer's avatar
Jan Schäfer committed
540

Stephan Binner's avatar
Stephan Binner committed
541
/*
542
  colorizeAreaChk = new QCheckBox(i18n("On"));
Jan Schäfer's avatar
Jan Schäfer committed
543
  colorizeAreaChk->setFixedWidth(60);
Luigi Toscano's avatar
Luigi Toscano committed
544
  colorizeAreaChk->setChecked(KSharedConfig::openConfig()->readEntry("highlightareas",true));
545
  optionsLayout->addRow(i18n("Highlight Areas"), colorizeAreaChk);
Jan Schäfer's avatar
Jan Schäfer committed
546

547
  showAltChk = new QCheckBox(i18n("On"));
Jan Schäfer's avatar
Jan Schäfer committed
548
  showAltChk->setFixedWidth(60);
Luigi Toscano's avatar
Luigi Toscano committed
549
  showAltChk->setChecked(KSharedConfig::openConfig()->readEntry("showalt",true));
550
  optionsLayout->addRow(i18n("Show alternative text"), showAltChk);
Jan Schäfer's avatar
Jan Schäfer committed
551
*/
552
553
554
555
556
557
558
559
560
561

  QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply);
  mainLayout->addWidget(buttonBox);
  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
  okButton->setDefault(true);
  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
  connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotOk()));
  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
  connect(buttonBox->button(QDialogButtonBox::Apply),SIGNAL(clicked()),this,SLOT(slotApply()));

Jan Schäfer's avatar
Jan Schäfer committed
562
563
564
565
566
567
}

PreferencesDialog::~PreferencesDialog() {
}

void PreferencesDialog::slotDefault( void ) {
Stephan Binner's avatar
Stephan Binner committed
568
  rowHeightSpinBox->setValue(50);
Jan Schäfer's avatar
Jan Schäfer committed
569
570
571
572
573
574
575
576
}

void PreferencesDialog::slotOk( void ) {
  slotApply();
  accept();
}

void PreferencesDialog::slotApply( void ) {
Laurent Montel's avatar
Laurent Montel committed
577
578
  KConfigGroup group = config->group("Appearance");
  group.writeEntry("maximum-preview-height",rowHeightSpinBox->cleanText().toInt());
Jan Schäfer's avatar
Jan Schäfer committed
579

Laurent Montel's avatar
Laurent Montel committed
580
581
582
583
  group = config->group("General Options");
  group.writeEntry("undo-level",undoSpinBox->cleanText().toInt());
  group.writeEntry("redo-level",redoSpinBox->cleanText().toInt());
  group.writeEntry("start-with-last-used-document", startWithCheck->isChecked());
584

Jan Schäfer's avatar
Jan Schäfer committed
585
  config->sync();
586
  emit preferencesChanged();
Jan Schäfer's avatar
Jan Schäfer committed
587
588
}

589
HTMLPreviewDialog::HTMLPreviewDialog(QWidget* parent, const QString & htmlCode)
590
  : QDialog(parent)
Jan Schäfer's avatar
Jan Schäfer committed
591
{
592
  tempFile = new QTemporaryFile(QDir::tempPath() + QLatin1String("/kime_preview_XXXXXX.html"));
Jaison Lee's avatar
Jaison Lee committed
593
  tempFile->open();
594
  setWindowTitle(i18n("Preview"));
Laurent Montel's avatar
Laurent Montel committed
595
  setModal(true);
Jaison Lee's avatar
Jaison Lee committed
596
597
  QTextStream stream(tempFile);
  stream << htmlCode;
598
  qCDebug(KIMAGEMAPEDITOR_LOG) << "HTMLPreviewDialog: TempFile : " << tempFile->fileName();
Jaison Lee's avatar
Jaison Lee committed
599
  stream.flush();
Jan Schäfer's avatar
Jan Schäfer committed
600

601
  QVBoxLayout *mainLayout = new QVBoxLayout(this);
Jan Schäfer's avatar
Jan Schäfer committed
602

603
604
  htmlPart = new QWebEngineView;
  mainLayout->addWidget(htmlPart);
Jan Schäfer's avatar
Jan Schäfer committed
605
//  htmlView = new KHTMLView(htmlPart, page);
606
//  mainLayout->addWidget(htmlView);
Jan Schäfer's avatar
Jan Schäfer committed
607
608
609
610
//  htmlView->setVScrollBarMode(QScrollView::Auto);
//  htmlView->setHScrollBarMode(QScrollView::Auto);
//  dialog->resize(dialog->calculateSize(edit->maxLineWidth(),edit->numLines()*));
//	dialog->adjustSize();
611
  htmlPart->load(QUrl::fromLocalFile(tempFile->fileName()));
612
  QLabel *lbl = new QLabel;
Stephan Kulow's avatar
Stephan Kulow committed
613
  lbl->setObjectName( "urllabel" );
614
615
616
617
618
619
620
621
  mainLayout->addWidget(lbl);

  QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
  okButton->setDefault(true);
  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
  connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
  mainLayout->addWidget(buttonBox);
Jan Schäfer's avatar
Jan Schäfer committed
622

623
  connect( htmlPart->page(), &QWebEnginePage::linkHovered, lbl, &QLabel::setText);
Pino Toscano's avatar
Pino Toscano committed
624
625

  resize(800,600);
Jan Schäfer's avatar
Jan Schäfer committed
626
627
628
629
630
631
}

HTMLPreviewDialog::~HTMLPreviewDialog() {
  delete tempFile;
}