File indexing completed on 2024-10-13 03:57:39

0001 /***************************************************************************
0002                           kimedialogs.cpp  -  description
0003                             -------------------
0004     begin                : Tue Apr 17 2001
0005     copyright            : (C) 2001 by Jan Schäfer
0006     email                : j_schaef@informatik.uni-kl.de
0007 ***************************************************************************/
0008 
0009 /***************************************************************************
0010 *                                                                         *
0011 *   This program is free software; you can redistribute it and/or modify  *
0012 *   it under the terms of the GNU General Public License as published by  *
0013 *   the Free Software Foundation; either version 2 of the License, or     *
0014 *   (at your option) any later version.                                   *
0015 *                                                                         *
0016 ***************************************************************************/
0017 
0018 // LOCAL
0019 #include "kimedialogs.h"
0020 
0021 // Qt
0022 #include <QCheckBox>
0023 #include <QDialogButtonBox>
0024 #include <QFileDialog>
0025 #include <QFormLayout>
0026 #include <QFrame>
0027 #include <QHeaderView>
0028 #include <QImage>
0029 #include <QLabel>
0030 #include <QLayout>
0031 #include <QLineEdit>
0032 #include <QListWidget>
0033 #include <QPixmap>
0034 #include <QPushButton>
0035 #include <QSpinBox>
0036 #include <QTableWidget>
0037 #include <QTemporaryFile>
0038 #include <QVBoxLayout>
0039 
0040 // KDE Frameworks
0041 #include "kimagemapeditor_debug.h"
0042 #include <KConfigGroup>
0043 #include <KLocalizedString>
0044 #include <KSharedConfig>
0045 
0046 CoordsEdit::CoordsEdit(QWidget *parent, Area* a)
0047   : QWidget(parent)
0048 {
0049   area=a;
0050 }
0051 
0052 void CoordsEdit::applyChanges() {
0053   return;
0054 }
0055 
0056 void CoordsEdit::slotTriggerUpdate() {
0057   applyChanges();
0058   emit update();
0059 }
0060 
0061 CoordsEdit::~CoordsEdit()
0062 {
0063 }
0064 
0065 RectCoordsEdit::RectCoordsEdit(QWidget *parent, Area* a)
0066   : CoordsEdit(parent,a)
0067 {
0068   QFormLayout *layout= new QFormLayout(this);
0069 
0070   topXSpin = new QSpinBox(this);
0071   topXSpin->setMaximum(INT_MAX);
0072   topXSpin->setMinimum(0);
0073   topXSpin->setValue(a->rect().left());
0074   connect( topXSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
0075   layout->addRow(i18n("Top &X:"), topXSpin);
0076 
0077   topYSpin = new QSpinBox(this);
0078   topYSpin->setMaximum(INT_MAX);
0079   topYSpin->setMinimum(0);
0080   topYSpin->setValue(a->rect().top());
0081   connect( topYSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
0082   layout->addRow(i18n("Top &Y:"), topYSpin);
0083 
0084   widthSpin = new QSpinBox(this);
0085   widthSpin->setMaximum(INT_MAX);
0086   widthSpin->setMinimum(0);
0087   widthSpin->setValue(a->rect().width());
0088   connect( widthSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
0089   layout->addRow(i18n("&Width:"), widthSpin);
0090 
0091   heightSpin = new QSpinBox(this);
0092   heightSpin->setMaximum(INT_MAX);
0093   heightSpin->setMinimum(0);
0094   heightSpin->setValue(a->rect().height());
0095   connect( heightSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
0096   layout->addRow(i18n("Hei&ght:"), heightSpin);
0097 }
0098 
0099 void RectCoordsEdit::applyChanges() {
0100   QRect r;
0101   r.setLeft(topXSpin->text().toInt());
0102   r.setTop(topYSpin->text().toInt());
0103   r.setWidth(widthSpin->text().toInt());
0104   r.setHeight(heightSpin->text().toInt());
0105   area->setRect(r);
0106 }
0107 
0108 CircleCoordsEdit::CircleCoordsEdit(QWidget *parent, Area* a)
0109   : CoordsEdit(parent,a)
0110 {
0111   QFormLayout *layout = new QFormLayout(this);
0112 
0113   centerXSpin = new QSpinBox(this);
0114   centerXSpin->setMaximum(INT_MAX);
0115   centerXSpin->setMinimum(0);
0116   centerXSpin->setValue(a->rect().center().x());
0117   connect( centerXSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
0118   layout->addRow(i18n("Center &X:"), centerXSpin);
0119 
0120   centerYSpin = new QSpinBox(this);
0121   centerYSpin->setMaximum(INT_MAX);
0122   centerYSpin->setMinimum(0);
0123   centerYSpin->setValue(a->rect().center().y());
0124   connect( centerYSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
0125   layout->addRow(i18n("Center &Y:"), centerYSpin);
0126 
0127   radiusSpin = new QSpinBox(this);
0128   radiusSpin->setMaximum(INT_MAX);
0129   radiusSpin->setMinimum(0);
0130   radiusSpin->setValue(a->rect().width()/2);
0131   connect( radiusSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
0132   layout->addRow(i18n("&Radius:"), radiusSpin);
0133 
0134 }
0135 
0136 void CircleCoordsEdit::applyChanges() {
0137   QRect r;
0138   r.setWidth(radiusSpin->text().toInt()*2);
0139   r.setHeight(radiusSpin->text().toInt()*2);
0140   r.moveCenter(QPoint(centerXSpin->text().toInt(),
0141                       centerYSpin->text().toInt()));
0142   area->setRect(r);
0143 }
0144 
0145 PolyCoordsEdit::PolyCoordsEdit(QWidget *parent, Area* a)
0146   : CoordsEdit(parent,a)
0147 {
0148   if (!a) return;
0149   QVBoxLayout *layout = new QVBoxLayout(this);
0150 
0151   coordsTable = new QTableWidget(0, 2);
0152   coordsTable->verticalHeader()->hide();
0153   coordsTable->setSelectionMode( QTableWidget::SingleSelection );
0154   connect( coordsTable, SIGNAL(currentChanged(int,int)), this, SLOT(slotHighlightPoint(int)));
0155 
0156   updatePoints();
0157 //  coordsTable->setMinimumHeight(50);
0158 //  coordsTable->setMaximumHeight(400);
0159 //  coordsTable->resizeContents(100,100);
0160   coordsTable->resize(coordsTable->width(), 100);
0161   layout->addWidget(coordsTable);
0162   layout->setStretchFactor(coordsTable, -1);
0163 
0164   QHBoxLayout *hbox = new QHBoxLayout;
0165   QPushButton *addBtn = new QPushButton(i18n("Add"));
0166   hbox->addWidget(addBtn);
0167   connect( addBtn, SIGNAL(pressed()), this, SLOT(slotAddPoint()));
0168   QPushButton *removeBtn = new QPushButton(i18n("Remove"));
0169   hbox->addWidget(removeBtn);
0170   connect( removeBtn, SIGNAL(pressed()), this, SLOT(slotRemovePoint()));
0171 
0172   layout->addLayout(hbox);
0173 
0174   slotHighlightPoint(1);
0175 }
0176 
0177 PolyCoordsEdit::~PolyCoordsEdit() {
0178 }
0179 
0180 void PolyCoordsEdit::slotHighlightPoint(int row) {
0181   if (!area) return;
0182   area->highlightSelectionPoint(row);
0183   emit update();
0184 }
0185 
0186 
0187 void PolyCoordsEdit::updatePoints() {
0188   coordsTable->clear();
0189 
0190   int count=area->coords().size();
0191 
0192   coordsTable->setHorizontalHeaderLabels(QStringList() << "X" << "Y");
0193   coordsTable->setRowCount(count);
0194 
0195   for (int i=0;i<count;i++) {
0196     coordsTable->setItem(i,0, new QTableWidgetItem(QString::number(area->coords().point(i).x()) ));
0197     coordsTable->setItem(i,1, new QTableWidgetItem(QString::number(area->coords().point(i).y()) ));
0198   }
0199 
0200   emit update();
0201 }
0202 
0203 void PolyCoordsEdit::slotAddPoint() {
0204   int newPos= coordsTable->currentRow();
0205   if (newPos < 0 || newPos >= area->coords().size())
0206     newPos = area->coords().size();
0207 
0208   QPoint currentPoint=area->coords().point(newPos);
0209   area->insertCoord(newPos,currentPoint);
0210   updatePoints();
0211 
0212 }
0213 
0214 void PolyCoordsEdit::slotRemovePoint() {
0215   int currentPos= coordsTable->currentRow();
0216   if (currentPos < 0 || currentPos >= area->coords().size())
0217     return;
0218   area->removeCoord(currentPos);
0219   updatePoints();
0220 }
0221 
0222 void PolyCoordsEdit::applyChanges() {
0223   int count=coordsTable->rowCount();
0224 
0225   for (int i=0;i<count;i++) {
0226     QPoint newPoint( coordsTable->item(i,0)->text().toInt(),
0227                     coordsTable->item(i,1)->text().toInt());
0228 
0229     area->moveCoord(i,newPoint);
0230   }
0231 }
0232 
0233 SelectionCoordsEdit::SelectionCoordsEdit(QWidget *parent, Area* a)
0234   : CoordsEdit(parent,a)
0235 {
0236   QFormLayout *layout = new QFormLayout(this);
0237 
0238   topXSpin = new QSpinBox(this);
0239   topXSpin->setMaximum(INT_MAX);
0240   topXSpin->setMinimum(0);
0241   topXSpin->setValue(a->rect().left());
0242   connect( topXSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
0243   layout->addRow(i18n("Top &X"), topXSpin);
0244 
0245   topYSpin = new QSpinBox(this);
0246   topYSpin->setMaximum(INT_MAX);
0247   topYSpin->setMinimum(0);
0248   topYSpin->setValue(a->rect().top());
0249   connect( topYSpin, SIGNAL(valueChanged(QString)), this, SLOT(slotTriggerUpdate()));
0250 
0251   layout->addRow(i18n("Top &Y"), topYSpin);
0252 }
0253 
0254 void SelectionCoordsEdit::applyChanges() {
0255   area->moveTo(topXSpin->text().toInt(), topYSpin->text().toInt());
0256 }
0257 
0258 
0259 
0260 QLineEdit* AreaDialog::createLineEdit(QFormLayout *layout, const QString &value, const QString &name)
0261 {
0262   QLineEdit *edit = new QLineEdit(value);
0263   layout->addRow(name, edit);
0264   return edit;
0265 }
0266 
0267 QWidget* AreaDialog::createGeneralPage()
0268 {
0269   QFrame *page = new QFrame(this);
0270   QFormLayout *layout = new QFormLayout(page);
0271 
0272   // A separate widget, not just a layout, is needed so that
0273   // the accelerator for the row is working
0274   QWidget *hbox = new QWidget;
0275   QHBoxLayout *hboxLayout = new QHBoxLayout(hbox);
0276   hboxLayout->setContentsMargins(0, 0, 0, 0);
0277   hrefEdit = new QLineEdit(area->attribute("href"));
0278   hboxLayout->addWidget(hrefEdit);
0279   QPushButton *btn = new QPushButton;
0280   btn->setIcon(QIcon::fromTheme("document-open"));
0281   connect( btn, SIGNAL(pressed()), this, SLOT(slotChooseHref()));
0282   hboxLayout->addWidget(btn);
0283 
0284   QLabel *lblHREF = new QLabel(i18n("&HREF:"));
0285   lblHREF->setBuddy(hrefEdit);
0286   layout->addRow(lblHREF, hbox);
0287 
0288   altEdit = createLineEdit(layout,
0289                area->attribute("alt"),
0290                i18n("Alt. &Text:"));
0291   targetEdit = createLineEdit(layout,
0292                   area->attribute("target"),
0293                   i18n("Tar&get:"));
0294   titleEdit = createLineEdit(layout,
0295                  area->attribute("title"),
0296                  i18n("Tit&le:"));
0297 
0298   if (area->type() == Area::Default) {
0299     defaultAreaChk = new QCheckBox(i18n("On"));
0300     if (area->finished()) {
0301       defaultAreaChk->setChecked(true);
0302     }
0303     layout->addRow(i18n("Enable default map"), defaultAreaChk);
0304   }
0305 
0306   return page;
0307 }
0308 
0309 QWidget* AreaDialog::createCoordsPage()
0310 {
0311   QFrame* page = new QFrame(this);
0312   QVBoxLayout *layout = new QVBoxLayout(page);
0313   layout->setContentsMargins(5, 5, 5, 5);
0314 
0315   coordsEdit = createCoordsEdit(page, area);
0316   layout->addWidget(coordsEdit);
0317   connect( coordsEdit, SIGNAL(update()), this, SLOT(slotUpdateArea()));
0318 
0319   return page;
0320 }
0321 
0322 QWidget* AreaDialog::createJavascriptPage()
0323 {
0324   QFrame *page = new QFrame(this);
0325   QFormLayout *layout = new QFormLayout(page);
0326 
0327   onClickEdit = createLineEdit(layout, area->attribute("onClick"), i18n("OnClick:"));
0328   onDblClickEdit = createLineEdit(layout, area->attribute("onDblClick"), i18n("OnDblClick:"));
0329   onMouseDownEdit = createLineEdit(layout, area->attribute("onMouseDown"), i18n("OnMouseDown:"));
0330   onMouseUpEdit = createLineEdit(layout, area->attribute("onMouseUp"), i18n("OnMouseUp:"));
0331   onMouseOverEdit = createLineEdit(layout, area->attribute("onMouseOver"), i18n("OnMouseOver:"));
0332   onMouseMoveEdit = createLineEdit(layout, area->attribute("onMouseMove"), i18n("OnMouseMove:"));
0333   onMouseOutEdit = createLineEdit(layout, area->attribute("onMouseOut"), i18n("OnMouseOut:"));
0334 
0335   return page;
0336 }
0337 
0338 AreaDialog::AreaDialog(KImageMapEditor* parent, Area* a)
0339   : QDialog(parent->widget())
0340 {
0341   setWindowTitle(i18n("Area Tag Editor"));
0342   //  setFaceType( KPageDialog::Tabbed );
0343   setObjectName( "Area Tag Editor" );
0344   setModal(true);
0345 
0346   _document = parent;
0347 
0348   if (!a) {
0349       slotCancel();
0350       return;
0351   }
0352 
0353   area = a;
0354   QString shape("Default");
0355   areaCopy = a->clone();
0356   oldArea = new Area();
0357   oldArea->setRect( a->rect() );
0358 
0359   switch (a->type()) {
0360     case Area::Rectangle: shape = i18n("Rectangle"); break;
0361     case Area::Circle: shape = i18n("Circle"); break;
0362     case Area::Polygon: shape = i18n("Polygon"); break;
0363     case Area::Selection: shape = i18n("Selection"); break;
0364     default: break;
0365   }
0366 
0367   QVBoxLayout *layout = new QVBoxLayout(this);
0368 
0369   // To get a margin around everything
0370   layout->setContentsMargins(5, 5, 5, 5);
0371 
0372   QLabel *lbl = new QLabel("<b>"+shape+"</b>");
0373   lbl->setTextFormat(Qt::RichText);
0374   layout->addWidget(lbl);
0375 
0376   QFrame *line = new QFrame;
0377   line->setFrameStyle(QFrame::HLine | QFrame::Sunken);
0378   line->setFixedHeight(10);
0379   layout->addWidget(line);
0380 
0381   QTabWidget *tab = new QTabWidget;
0382   tab->addTab(createGeneralPage(), i18n("&General"));
0383   layout->addWidget(tab);
0384 
0385   if (a->type() == Area::Default) {
0386     // FIXME? Why this useless assignment?
0387     shape = i18n("Default");
0388   } else {
0389     tab->addTab(createCoordsPage(), i18n("Coor&dinates"));
0390   }
0391   tab->addTab(createJavascriptPage(), i18n("&JavaScript"));
0392 
0393   QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply);
0394   QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0395   okButton->setDefault(true);
0396   okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0397   layout->addWidget(buttonBox);
0398 
0399   connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotOk()));
0400   connect(buttonBox, SIGNAL(rejected()), this, SLOT(slotCancel()));
0401   connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotApply()));
0402 
0403   setMinimumHeight(360);
0404   setMinimumWidth(327);
0405 
0406   resize(327,360);
0407 }
0408 
0409 AreaDialog::~AreaDialog() {
0410   delete areaCopy;
0411   delete oldArea;
0412 }
0413 
0414 CoordsEdit* AreaDialog::createCoordsEdit(QWidget *parent, Area *a) {
0415   if (!a) return nullptr;
0416   switch (a->type()) {
0417     case Area::Rectangle :
0418         return new RectCoordsEdit(parent,a);
0419       break;
0420     case Area::Circle :
0421         return new CircleCoordsEdit(parent,a);
0422       break;
0423     case Area::Polygon :
0424         return new PolyCoordsEdit(parent,a);
0425       break;
0426     case Area::Selection :
0427         return new SelectionCoordsEdit(parent,a);
0428       break;
0429     case Area::Default : return new CoordsEdit(parent,a); break;
0430     default : return new CoordsEdit(parent,a);break;
0431   }
0432 }
0433 
0434 void AreaDialog::slotChooseHref() {
0435   QUrl url = QFileDialog::getOpenFileUrl(this, i18n("Choose File"), QUrl(), i18n("All Files (*)"));
0436   if (!url.isEmpty()) {
0437     hrefEdit->setText(url.url());
0438   }
0439 }
0440 
0441 void AreaDialog::slotOk() {
0442   if (area)
0443   {
0444     area->highlightSelectionPoint(-1);
0445     if (area->type()==Area::Default)
0446       area->setFinished(defaultAreaChk->isChecked());
0447   }
0448   slotApply();
0449   accept();
0450 
0451 }
0452 
0453 void AreaDialog::slotApply() {
0454   if (area) {
0455     if (area->type()!=Area::Default)
0456       coordsEdit->applyChanges();
0457 
0458     area->setAttribute("href",hrefEdit->text());
0459     area->setAttribute("alt",altEdit->text());
0460     area->setAttribute("target",targetEdit->text());
0461     area->setAttribute("title",titleEdit->text());
0462     area->setAttribute("onclick",onClickEdit->text());
0463     area->setAttribute("ondblclick",onDblClickEdit->text());
0464     area->setAttribute("onmousedown",onMouseDownEdit->text());
0465     area->setAttribute("onmouseup",onMouseUpEdit->text());
0466     area->setAttribute("onmousemove",onMouseMoveEdit->text());
0467     area->setAttribute("onmouseover",onMouseOverEdit->text());
0468     area->setAttribute("onmouseout",onMouseOutEdit->text());
0469 
0470     // redraw old area to get rid of it
0471     emit areaChanged(oldArea);
0472     // draw new area
0473     emit areaChanged(area);
0474     oldArea->setRect(area->rect());
0475   }
0476 }
0477 
0478 void AreaDialog::slotCancel() {
0479   if (area) {
0480     AreaSelection *selection = nullptr;
0481     if ( (selection=dynamic_cast<AreaSelection*>(areaCopy)) )
0482       area->setArea(*selection);
0483     else
0484       area->setArea(*areaCopy);
0485     area->highlightSelectionPoint(-1);
0486     emit areaChanged(oldArea);
0487     emit areaChanged(area);
0488   }
0489   reject();
0490 }
0491 
0492 void AreaDialog::slotUpdateArea() {
0493     emit areaChanged(oldArea);
0494     // draw new area
0495     emit areaChanged(area);
0496     oldArea->setRect(area->rect());
0497 }
0498 
0499 
0500 PreferencesDialog::PreferencesDialog(QWidget *parent, KConfig* conf)
0501   : QDialog(parent)
0502 {
0503   config = conf;
0504   setWindowTitle(i18n("Preferences"));
0505   setModal(true);
0506 
0507   QVBoxLayout *mainLayout = new QVBoxLayout(this);
0508 
0509   QFormLayout *optionsLayout = new QFormLayout;
0510   mainLayout->addLayout(optionsLayout);
0511 
0512   rowHeightSpinBox = new QSpinBox;
0513   int maxPrevHeight = config->group("Appearance").readEntry("maximum-preview-height",50);
0514   rowHeightSpinBox->setMaximum(1000);
0515   rowHeightSpinBox->setMinimum(15);
0516   rowHeightSpinBox->setFixedWidth(60);
0517   rowHeightSpinBox->setValue(maxPrevHeight);
0518   optionsLayout->addRow(i18n("&Maximum image preview height:"), rowHeightSpinBox);
0519 
0520   KConfigGroup general = config->group("General");
0521 
0522   undoSpinBox = new QSpinBox;
0523   undoSpinBox->setFixedWidth(60);
0524   undoSpinBox->setMaximum(100);
0525   undoSpinBox->setMinimum(1);
0526   undoSpinBox->setValue(general.readEntry("undo-level",20));
0527   optionsLayout->addRow(i18n("&Undo limit:"), undoSpinBox);
0528 
0529   redoSpinBox = new QSpinBox;
0530   redoSpinBox->setFixedWidth(60);
0531   redoSpinBox->setMaximum(100);
0532   redoSpinBox->setMinimum(1);
0533   redoSpinBox->setValue(general.readEntry("redo-level",20));
0534   optionsLayout->addRow(i18n("&Redo limit:"), redoSpinBox);
0535 
0536   startWithCheck = new QCheckBox(i18n("On"));
0537   startWithCheck->setChecked(general.readEntry("start-with-last-used-document",true));
0538   optionsLayout->addRow(i18n("&Start with last used document"), startWithCheck);
0539 
0540 /*
0541   colorizeAreaChk = new QCheckBox(i18n("On"));
0542   colorizeAreaChk->setFixedWidth(60);
0543   colorizeAreaChk->setChecked(KSharedConfig::openConfig()->readEntry("highlightareas",true));
0544   optionsLayout->addRow(i18n("Highlight Areas"), colorizeAreaChk);
0545 
0546   showAltChk = new QCheckBox(i18n("On"));
0547   showAltChk->setFixedWidth(60);
0548   showAltChk->setChecked(KSharedConfig::openConfig()->readEntry("showalt",true));
0549   optionsLayout->addRow(i18n("Show alternative text"), showAltChk);
0550 */
0551 
0552   QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Apply);
0553   mainLayout->addWidget(buttonBox);
0554   QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0555   okButton->setDefault(true);
0556   okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0557   connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotOk()));
0558   connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
0559   connect(buttonBox->button(QDialogButtonBox::Apply),SIGNAL(clicked()),this,SLOT(slotApply()));
0560 
0561 }
0562 
0563 PreferencesDialog::~PreferencesDialog() {
0564 }
0565 
0566 void PreferencesDialog::slotDefault( void ) {
0567   rowHeightSpinBox->setValue(50);
0568 }
0569 
0570 void PreferencesDialog::slotOk( void ) {
0571   slotApply();
0572   accept();
0573 }
0574 
0575 void PreferencesDialog::slotApply( void ) {
0576   KConfigGroup group = config->group("Appearance");
0577   group.writeEntry("maximum-preview-height",rowHeightSpinBox->cleanText().toInt());
0578 
0579   group = config->group("General Options");
0580   group.writeEntry("undo-level",undoSpinBox->cleanText().toInt());
0581   group.writeEntry("redo-level",redoSpinBox->cleanText().toInt());
0582   group.writeEntry("start-with-last-used-document", startWithCheck->isChecked());
0583 
0584   config->sync();
0585   emit preferencesChanged();
0586 }
0587 
0588 HTMLPreviewDialog::HTMLPreviewDialog(QWidget* parent, const QString & htmlCode)
0589   : QDialog(parent)
0590 {
0591   tempFile = new QTemporaryFile(QDir::tempPath() + QLatin1String("/kime_preview_XXXXXX.html"));
0592   tempFile->open();
0593   setWindowTitle(i18n("Preview"));
0594   setModal(true);
0595   QTextStream stream(tempFile);
0596   stream << htmlCode;
0597   qCDebug(KIMAGEMAPEDITOR_LOG) << "HTMLPreviewDialog: TempFile : " << tempFile->fileName();
0598   stream.flush();
0599 
0600   QVBoxLayout *mainLayout = new QVBoxLayout(this);
0601 
0602   htmlPart = new QWebEngineView;
0603   mainLayout->addWidget(htmlPart);
0604   htmlPart->load(QUrl::fromLocalFile(tempFile->fileName()));
0605   QLabel *lbl = new QLabel;
0606   lbl->setObjectName( "urllabel" );
0607   mainLayout->addWidget(lbl);
0608 
0609   QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
0610   QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0611   okButton->setDefault(true);
0612   okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0613   connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
0614   mainLayout->addWidget(buttonBox);
0615 
0616   connect( htmlPart->page(), &QWebEnginePage::linkHovered, lbl, &QLabel::setText);
0617 
0618   resize(800,600);
0619 }
0620 
0621 HTMLPreviewDialog::~HTMLPreviewDialog() {
0622   delete tempFile;
0623 }
0624