[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
klfsettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * file klfsettings.cpp
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist@bluewin.ch
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 /* $Id: klfsettings.cpp 603 2011-02-26 23:14:55Z phfaist $ */
23 
24 #include <stdlib.h>
25 
26 #include <QDialog>
27 #include <QCheckBox>
28 #include <QSpinBox>
29 #include <QLineEdit>
30 #include <QFontDatabase>
31 #include <QFontDialog>
32 #include <QString>
33 #include <QMessageBox>
34 #include <QFileInfo>
35 #include <QDir>
36 #include <QFileDialog>
37 #include <QWhatsThis>
38 #include <QResource>
39 #include <QEvent>
40 #include <QListView> // QListView::LeftToRight|TopToBottom
41 #include <QMouseEvent>
42 #include <QDesktopServices>
43 
44 #include <klfcolorchooser.h>
45 #include <klfpathchooser.h>
46 
47 #include <klfbackend.h>
48 
49 #include <ui_klfsettings.h>
50 
51 #include "klfmain.h"
52 #include "klfmainwin.h"
53 #include "klfconfig.h"
54 #include "klfmime.h"
55 #include "klfpluginiface.h"
56 #include "klflatexedit.h"
57 #include "klfsettings.h"
58 
59 
60 #define KLFSETTINGS_ROLE_PLUGNAME (Qt::UserRole + 5300)
61 #define KLFSETTINGS_ROLE_PLUGINDEX (KLFSETTINGS_ROLE_PLUGNAME + 1)
62 
63 #define KLFSETTINGS_ROLE_ADDONINDEX (Qt::UserRole + 5400)
64 
65 
66 #define REG_SH_TEXTFORMATENSEMBLE(x) \
67  _textformats.append( TextFormatEnsemble( & klfconfig.SyntaxHighlighter.fmt##x , \
68  u->colSH##x, u->colSH##x##Bg , u->chkSH##x##B , u->chkSH##x##I ) );
69 
70 
71 
72 
74  : QDialog(parent)
75 {
76  u = new Ui::KLFSettings;
77  u->setupUi(this);
78  setObjectName("KLFSettings");
79 
80  _mainwin = parent;
81 
82  pUserSetDefaultAppFont = false;
83 
84  u->cbxLibIconViewFlow->setEnumValues(QList<int>()<<QListView::TopToBottom<<QListView::LeftToRight,
85  QStringList()<<tr("Top to Bottom")<<tr("Left to Right"));
86 
87  reset();
88 
89  u->btns->clear();
90 
91  // QPushButton *b;
92  // b = new QPushButton(QIcon(":/pics/closehide.png"), QString("cancel"), u->btns);
93  // u->btns->addButton(b, QDialogButtonBox::RejectRole);
94  // connect(b, SIGNAL(clicked()), this, SLOT(reject()));
95  // b = new QPushButton(QIcon(":/pics/apply.png"), QString("apply"), u->btns);
96  // u->btns->addButton(b, QDialogButtonBox::ApplyRole);
97  // connect(b, SIGNAL(clicked()), this, SLOT(apply()));
98  // b = new QPushButton(QIcon(":/pics/ok.png"), QString("ok"), u->btns);
99  // u->btns->addButton(b, QDialogButtonBox::AcceptRole);
100  // connect(b, SIGNAL(clicked()), this, SLOT(accept()));
101  QAbstractButton *b;
102  b = u->btns->addButton(QDialogButtonBox::Cancel);
103  b->setIcon(QIcon(":/pics/closehide.png"));
104  connect(b, SIGNAL(clicked()), this, SLOT(reject()));
105  b = u->btns->addButton(QDialogButtonBox::Apply);
106  b->setIcon(QIcon(":/pics/apply.png"));
107  connect(b, SIGNAL(clicked()), this, SLOT(apply()));
108  b = u->btns->addButton(QDialogButtonBox::Ok);
109  b->setIcon(QIcon(":/pics/ok.png"));
110  connect(b, SIGNAL(clicked()), this, SLOT(accept()));
111 
114 
115  // set some smaller fonts for small titles
116  QFont f = this->font();
117  f.setPointSize(QFontInfo(f).pointSize() - 1);
118  u->lblSHForeground->setFont(f);
119  u->lblSHBackground->setFont(f);
120 
121  connect(u->btnPathsReset, SIGNAL(clicked()), this, SLOT(setDefaultPaths()));
122 
123  connect(u->lstPlugins, SIGNAL(itemSelectionChanged()), this, SLOT(refreshPluginSelected()));
124  connect(u->lstAddOns, SIGNAL(itemSelectionChanged()), this, SLOT(refreshAddOnSelected()));
125  connect(u->btnImportAddOn, SIGNAL(clicked()), this, SLOT(importAddOn()));
126  connect(u->btnRemoveAddOn, SIGNAL(clicked()), this, SLOT(removeAddOn()));
127  // connect(u->btnRemovePlugin, SIGNAL(clicked()), this, SLOT(removePlugin()));
128 
129  u->lstPlugins->installEventFilter(this);
130  u->lstPlugins->viewport()->installEventFilter(this);
131  u->lstAddOns->installEventFilter(this);
132  u->lstAddOns->viewport()->installEventFilter(this);
133 
134  connect(u->btnAppFont, SIGNAL(clicked()), this, SLOT(slotChangeFontSender()));
135  connect(u->btnEditorFont, SIGNAL(clicked()), this, SLOT(slotChangeFontSender()));
136  connect(u->btnPreambleFont, SIGNAL(clicked()), this, SLOT(slotChangeFontSender()));
137 
138  // prepare some actions as shortcuts for standard fonts
139  QFontDatabase fdb;
140  u->aFontCMU->setEnabled( fdb.families().contains("CMU Sans Serif") );
141  pFontBasePresetActions["CMU"] = u->aFontCMU;
142  pFontBasePresetActions["TT"] = u->aFontTT;
143  pFontBasePresetActions["Std"] = u->aFontStd;
144  pFontButtons["AppFont"] = u->btnAppFont;
145  pFontButtons["EditorFont"] = u->btnEditorFont;
146  pFontButtons["PreambleFont"] = u->btnPreambleFont;
147  QAction *a = NULL;
148  QMenu *fontPresetMenu = NULL;
149  QVariantMap vmap;
150  // remember: action text/icon/font/... is set in retranslateUi().
151  // -- AppFont --
152  fontPresetMenu = new QMenu(this);
153  a = new QAction(this);
154  vmap["Action"] = "CMU";
155  vmap["Font"] = klfconfig.defaultCMUFont;
156  vmap["Button"] = QVariant("AppFont");
157  a->setData(QVariant(vmap));
158  a->setEnabled(u->aFontCMU->isEnabled());
159  fontPresetMenu->addAction(a);
160  connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
161  pFontSetActions << a;
162  a = new QAction(this);
163  vmap["Action"] = "Std";
164  vmap["Font"] = klfconfig.defaultStdFont;
165  vmap["Button"] = QVariant("AppFont");
166  vmap["isSystemDefaultAppFont"] = QVariant(true);
167  a->setData(QVariant(vmap));
168  connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
169  pFontSetActions << a;
170  fontPresetMenu->addAction(a);
171  u->btnAppFontChoose->setMenu(fontPresetMenu);
172  // -- EditorFont --
173  fontPresetMenu = new QMenu(this);
174  a = new QAction(this);
175  vmap["Action"] = "TT";
176  vmap["Font"] = klfconfig.defaultTTFont;
177  vmap["Button"] = QVariant("EditorFont");
178  a->setData(QVariant(vmap));
179  connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
180  pFontSetActions << a;
181  fontPresetMenu->addAction(a);
182  a = new QAction(this);
183  vmap["Action"] = "CMU";
184  vmap["Font"] = klfconfig.defaultCMUFont;
185  vmap["Button"] = QVariant("EditorFont");
186  a->setData(QVariant(vmap));
187  a->setEnabled(u->aFontCMU->isEnabled());
188  connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
189  pFontSetActions << a;
190  fontPresetMenu->addAction(a);
191  a = new QAction(this);
192  vmap["Action"] = "Std";
193  vmap["Font"] = klfconfig.defaultStdFont;
194  vmap["Button"] = QVariant("EditorFont");
195  a->setData(QVariant(vmap));
196  connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
197  pFontSetActions << a;
198  fontPresetMenu->addAction(a);
199  u->btnEditorFontChoose->setMenu(fontPresetMenu);
200  // -- PreambleFont --
201  fontPresetMenu = new QMenu(this);
202  a = new QAction(this);
203  vmap["Action"] = "TT";
204  vmap["Font"] = klfconfig.defaultTTFont;
205  vmap["Button"] = QVariant("PreambleFont");
206  a->setData(QVariant(vmap));
207  connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
208  pFontSetActions << a;
209  fontPresetMenu->addAction(a);
210  a = new QAction(this);
211  vmap["Action"] = "CMU";
212  vmap["Font"] = klfconfig.defaultCMUFont;
213  vmap["Button"] = QVariant("PreambleFont");
214  a->setData(QVariant(vmap));
215  a->setEnabled(u->aFontCMU->isEnabled());
216  connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
217  pFontSetActions << a;
218  fontPresetMenu->addAction(a);
219  a = new QAction(this);
220  vmap["Action"] = "Std";
221  vmap["Font"] = klfconfig.defaultStdFont;
222  vmap["Button"] = QVariant("PreambleFont");
223  a->setData(QVariant(vmap));
224  connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
225  pFontSetActions << a;
226  fontPresetMenu->addAction(a);
227  u->btnPreambleFontChoose->setMenu(fontPresetMenu);
228 
229 
230  REG_SH_TEXTFORMATENSEMBLE(Keyword);
231  REG_SH_TEXTFORMATENSEMBLE(Comment);
232  REG_SH_TEXTFORMATENSEMBLE(ParenMatch);
233  REG_SH_TEXTFORMATENSEMBLE(ParenMismatch);
234  REG_SH_TEXTFORMATENSEMBLE(LonelyParen);
235 
236  u->btnImportAddOn->setEnabled(klf_addons_canimport);
237  u->btnRemoveAddOn->setEnabled(klf_addons_canimport);
238 
242 
243 
244  // remove default Qt Designer Page
245  QWidget * w = u->tbxPluginsConfig->widget(u->tbxPluginsConfig->currentIndex());
246  u->tbxPluginsConfig->removeItem(u->tbxPluginsConfig->currentIndex());
247  delete w;
248 
249  u->lstPlugins->setColumnWidth(0, 185);
250 
251  // dont load plugin data here as this dialog is created BEFORE plugins are loaded
252  _pluginstuffloaded = false;
253 
254  retranslateUi(false);
255 }
256 
257 void KLFSettings::retranslateUi(bool alsoBaseUi)
258 {
259  if (alsoBaseUi)
260  u->retranslateUi(this);
261 
262  // translate our preset actions
263  int k;
264  for (k = 0; k < pFontSetActions.size(); ++k) {
265  QAction *a = pFontSetActions[k];
266  QVariantMap vmap = a->data().toMap();
267  QString refAKey = vmap["Action"].toString();
268  KLF_ASSERT_CONDITION(pFontBasePresetActions.contains(refAKey),
269  "Base Reference Preset Action not found: "<<refAKey<<" ?!?",
270  continue ) ;
271  QAction *refA = pFontBasePresetActions[refAKey];
272  a->setText(refA->text());
273  a->setIcon(refA->icon());
274  a->setToolTip(refA->toolTip());
275  QFont f = vmap["Font"].value<QFont>();
276  a->setFont(f);
277  }
278 }
279 
280 
282 {
283  delete u;
284 }
285 
287 {
289 
290  u->cbxLocale->clear();
291  // application language : populate combo box
292  u->cbxLocale->addItem( QLatin1String("English Default"), QVariant::fromValue<QString>("en_US") );
293  int k;
294  for (k = 0; k < klf_avail_translations.size(); ++k) {
296  u->cbxLocale->addItem( ti.translatedname, QVariant(ti.localename) );
297  klfDbg("Added translation "<< ti.translatedname <<" ("<<ti.localename<<")") ;
298  }
299 
300  // Select the current locale. This is also done in reset(), but these lines are needed here
301  // for when this function is called within importAddOn().
302  k = u->cbxLocale->findData(klfconfig.UI.locale);
303  if (k == -1) {
304  k = 0;
305  }
306  u->cbxLocale->setCurrentIndex(k);
307 }
308 
310 {
312 
313  u->cbxCopyExportProfile->clear();
314  u->cbxDragExportProfile->clear();
315  int k;
316  for (k = 0; k < eplist.size(); ++k) {
317  u->cbxCopyExportProfile->addItem(eplist[k].description(), QVariant(eplist[k].profileName()));
318  u->cbxDragExportProfile->addItem(eplist[k].description(), QVariant(eplist[k].profileName()));
319  }
320 }
321 
322 
324 {
325  klfDbg("show called.") ;
327 
328  reset();
329 
330  if (!_pluginstuffloaded)
332  else
334 
335  QDialog::show();
336 }
337 
338 
340 #define __KLF_SHOW_SETTINGS_CONTROL( tab , focuswidget ) \
341  u->tabs->setCurrentWidget( u->tab ); \
342  u->focuswidget->setFocus(Qt::OtherFocusReason);
343 
344 void KLFSettings::showControl(int control)
345 {
346  switch (control) {
347  case AppLanguage:
348  __KLF_SHOW_SETTINGS_CONTROL(tabAppearance, cbxLocale) ;
349  break;
350  case AppFonts:
351  __KLF_SHOW_SETTINGS_CONTROL(tabAppearance, btnAppFont) ;
352  break;
353  case Preview:
354  __KLF_SHOW_SETTINGS_CONTROL(tabAppearance, chkEnableRealTimePreview) ;
355  break;
356  case TooltipPreview:
357  __KLF_SHOW_SETTINGS_CONTROL(tabAppearance, chkEnableToolTipPreview) ;
358  break;
359  case SyntaxHighlighting:
360  __KLF_SHOW_SETTINGS_CONTROL(tabSyntaxHighlighting, chkSHEnable) ;
361  break;
362  case ExecutablePaths:
363  __KLF_SHOW_SETTINGS_CONTROL(tabAdvanced, pathTempDir) ;
364  break;
365  case ExpandEPSBBox:
366  __KLF_SHOW_SETTINGS_CONTROL(tabAdvanced, spnLBorderOffset) ;
367  break;
368  case ExportProfiles:
369  __KLF_SHOW_SETTINGS_CONTROL(tabAdvanced, cbxCopyExportProfile) ;
370  break;
371  case LibrarySettings:
372  __KLF_SHOW_SETTINGS_CONTROL(tabLibBrowser, chkLibRestoreURLs) ;
373  break;
374  case ManageAddOns:
375  __KLF_SHOW_SETTINGS_CONTROL(tabAddOns, lstAddOns) ;
376  break;
377  case ManagePlugins:
378  __KLF_SHOW_SETTINGS_CONTROL(tabAddOns, lstPlugins) ;
379  break;
380  case PluginsConfig:
381  __KLF_SHOW_SETTINGS_CONTROL(tabPlugins, tbxPluginsConfig->currentWidget()) ;
382  break;
383  default:
384  qWarning()<<KLF_FUNC_NAME<<": unknown control number requested : "<<control;
385  }
386 }
387 
389 #define __KLF_SETTINGS_TEST_STR_CONTROL( controlName, controlNum ) \
390  if (controlName == QLatin1String(#controlNum)) { \
391  showControl(controlNum); \
392  return; \
393  }
394 
395 void KLFSettings::showControl(const QString& controlName)
396 {
398  __KLF_SETTINGS_TEST_STR_CONTROL( controlName, AppFonts ) ;
399  __KLF_SETTINGS_TEST_STR_CONTROL( controlName, Preview ) ;
408 }
409 
410 static bool treeMaybeUnselect(QTreeWidget *tree, QEvent *event)
411 {
412  // tree is non-NULL as ensured by caller.
413 
414  if (event->type() != QEvent::MouseButtonPress)
415  return false;
416  QMouseEvent * e = (QMouseEvent*) event;
417  if (e->button() != Qt::LeftButton)
418  return false;
419  QTreeWidgetItem *itemAtClick = tree->itemAt(e->pos());
420  if ( itemAtClick ) {
421  // user clicked on an item, let Qt handle the event and select item etc.
422  return false;
423  }
424  // user clicked out of an item, change Qt's default behavior and un-select all items.
425  QList<QTreeWidgetItem*> selitems = tree->selectedItems();
426  int k;
427  for (k = 0; k < selitems.size(); ++k) {
428  selitems[k]->setSelected(false);
429  }
430  return true;
431 }
432 
434 {
435  // test for one the the treeWidgets
436  QTreeWidget * tree = NULL;
437  if (object == u->lstPlugins || object == u->lstPlugins->viewport())
438  tree = u->lstPlugins;
439  if (object == u->lstAddOns || object == u->lstAddOns->viewport())
440  tree = u->lstAddOns;
441 
442  if ( tree )
443  if ( treeMaybeUnselect(tree, event) )
444  return true;
445  return QDialog::eventFilter(object, event);
446 }
447 
449 {
450  int k;
452 
453  k = u->cbxLocale->findData(klfconfig.UI.locale);
454  if (k == -1) {
455  k = 0;
456  }
457  u->cbxLocale->setCurrentIndex(k);
458 
459  u->pathTempDir->setPath(QDir::toNativeSeparators(s.tempdir));
460  u->pathLatex->setPath(s.latexexec);
461  u->pathDvips->setPath(s.dvipsexec);
462  u->pathGs->setPath(s.gsexec);
463  u->pathEpstopdf->setPath(s.epstopdfexec);
464  u->chkEpstopdf->setChecked( ! s.epstopdfexec.isEmpty() );
467  u->spnLBorderOffset->setValue( (int)(s.lborderoffset+0.5) );
468  u->spnTBorderOffset->setValue( (int)(s.tborderoffset+0.5) );
469  u->spnRBorderOffset->setValue( (int)(s.rborderoffset+0.5) );
470  u->spnBBorderOffset->setValue( (int)(s.bborderoffset+0.5) );
471  u->chkOutlineFonts->setChecked( s.outlineFonts );
472 
473  u->chkSHEnable->setChecked(klfconfig.SyntaxHighlighter.configFlags
475  u->chkSHHighlightParensOnly->setChecked(klfconfig.SyntaxHighlighter.configFlags
477  u->chkSHHighlightLonelyParen->setChecked(klfconfig.SyntaxHighlighter.configFlags
479 
480  for (k = 0; k < _textformats.size(); ++k) {
481  if (_textformats[k].fmt->hasProperty(QTextFormat::ForegroundBrush))
482  _textformats[k].fg->setColor(_textformats[k].fmt->foreground().color());
483  else
484  _textformats[k].fg->setColor(QColor());
485  if (_textformats[k].fmt->hasProperty(QTextFormat::BackgroundBrush))
486  _textformats[k].bg->setColor(_textformats[k].fmt->background().color());
487  else
488  _textformats[k].bg->setColor(QColor());
489  if (_textformats[k].fmt->hasProperty(QTextFormat::FontWeight))
490  _textformats[k].chkB->setChecked(_textformats[k].fmt->fontWeight() > 60);
491  else
492  _textformats[k].chkB->setCheckState(Qt::PartiallyChecked);
493  if (_textformats[k].fmt->hasProperty(QTextFormat::FontItalic))
494  _textformats[k].chkI->setChecked(_textformats[k].fmt->fontItalic());
495  else
496  _textformats[k].chkI->setCheckState(Qt::PartiallyChecked);
497  }
498 
499  pUserSetDefaultAppFont = klfconfig.UI.useSystemAppFont;
500  u->btnAppFont->setFont(klfconfig.UI.applicationFont);
501  u->btnAppFont->setProperty("selectedFont", QVariant(klfconfig.UI.applicationFont));
502  u->btnEditorFont->setFont(klfconfig.UI.latexEditFont);
503  u->btnEditorFont->setProperty("selectedFont", QVariant(klfconfig.UI.latexEditFont));
504  u->btnPreambleFont->setFont(klfconfig.UI.preambleEditFont);
505  u->btnPreambleFont->setProperty("selectedFont", QVariant(klfconfig.UI.preambleEditFont));
506 
507  u->chkEnableRealTimePreview->setChecked(klfconfig.UI.enableRealTimePreview);
508  u->spnPreviewWidth->setValue(klfconfig.UI.labelOutputFixedSize.width());
509  u->spnPreviewHeight->setValue(klfconfig.UI.labelOutputFixedSize.height());
510 
511  u->chkEnableToolTipPreview->setChecked(klfconfig.UI.enableToolTipPreview);
512  u->spnToolTipMaxWidth->setValue(klfconfig.UI.previewTooltipMaxSize.width());
513  u->spnToolTipMaxHeight->setValue(klfconfig.UI.previewTooltipMaxSize.height());
514 
515  u->chkShowHintPopups->setChecked(klfconfig.UI.showHintPopups);
516  u->chkClearLatexOnly->setChecked(klfconfig.UI.clearLatexOnly);
517  u->chkGlowEffect->setChecked(klfconfig.UI.glowEffect);
518 
519  int copyi = u->cbxCopyExportProfile->findData(QVariant(klfconfig.UI.copyExportProfile));
520  u->cbxCopyExportProfile->setCurrentIndex(copyi);
521  int dragi = u->cbxDragExportProfile->findData(QVariant(klfconfig.UI.dragExportProfile));
522  u->cbxDragExportProfile->setCurrentIndex(dragi);
523  // u->chkShowExportProfilesLabel->setChecked(klfconfig.UI.showExportProfilesLabel);
524  u->chkMenuExportProfileAffectsDrag->setChecked(klfconfig.UI.menuExportProfileAffectsDrag);
525  u->chkMenuExportProfileAffectsCopy->setChecked(klfconfig.UI.menuExportProfileAffectsCopy);
526 
527  u->chkLibRestoreURLs->setChecked(klfconfig.LibraryBrowser.restoreURLs);
528  u->chkLibConfirmClose->setChecked(klfconfig.LibraryBrowser.confirmClose);
529  u->chkLibHistoryTagCopyToArchive->setChecked(klfconfig.LibraryBrowser.historyTagCopyToArchive);
530  // u->chkLibGroupSubCategories->setChecked(klfconfig.LibraryBrowser.groupSubCategories);
531  u->cbxLibIconViewFlow->setSelectedValue(klfconfig.LibraryBrowser.iconViewFlow);
532 }
533 
534 
536 {
537  if (_pluginstuffloaded)
538  return;
539  _pluginstuffloaded = true;
540 
541  int j;
542  int n_pluginconfigpages = 0;
543  QTreeWidgetItem *litem;
544  for (j = 0; j < klf_plugins.size(); ++j) {
545  QString name = klf_plugins[j].name;
546  QString title = klf_plugins[j].title;
547  QString description = klf_plugins[j].description;
548  KLFPluginGenericInterface *instance = klf_plugins[j].instance;
549 
550  litem = new QTreeWidgetItem(u->lstPlugins);
551  litem->setCheckState(0,
552  klfconfig.Plugins.pluginConfig[name]["__loadenabled"].toBool() ?
553  Qt::Checked : Qt::Unchecked);
554  litem->setText(0, title);
555 
556  litem->setData(0, KLFSETTINGS_ROLE_PLUGNAME, name);
557  litem->setData(0, KLFSETTINGS_ROLE_PLUGINDEX, j);
558 
559  mPluginListItems[name] = litem;
560 
561  if ( instance != NULL ) {
562  mPluginConfigWidgets[name] = instance->createConfigWidget( NULL );
563  u->tbxPluginsConfig->addItem( mPluginConfigWidgets[name] , QIcon(":/pics/bullet22.png"), title );
565  instance->loadFromConfig(mPluginConfigWidgets[name], &pconfa);
566  n_pluginconfigpages++;
567  }
568  }
569  if (n_pluginconfigpages == 0) {
570  QLabel * lbl;
571  lbl = new QLabel(tr("No Plugins have been loaded. Please install and enable individual plugins "
572  "first, then come back to this page to configure them."), u->tbxPluginsConfig);
573  lbl->hide();
574  lbl->setWordWrap(true);
575  lbl->setMargin(20);
576  u->tbxPluginsConfig->addItem(lbl, tr("No Plugins Loaded"));
577  }
578 }
579 
581 {
582  // go through all plugins, and load their configs into their corresponding config widget
583  // and see if they are loaded (corresponding checkbox)
584  int k;
585  for (k = 0; k < klf_plugins.size(); ++k) {
586  QString name = klf_plugins[k].name;
587  KLFPluginGenericInterface *instance = klf_plugins[k].instance;
588 
589  KLF_ASSERT_CONDITION(mPluginListItems.contains(name),
590  "Plugin "<<name<<" does not have its corresponding check item!",
591  continue ;) ;
592 
593  mPluginListItems[name]->setCheckState(0,
594  klfconfig.Plugins.pluginConfig[name]["__loadenabled"].toBool() ?
595  Qt::Checked : Qt::Unchecked);
596 
597  if (instance != NULL) {
598  if (!mPluginConfigWidgets.contains(name)) {
599  qWarning()<<KLF_FUNC_NAME<<": Plugin "<<name<<" does not have its config widget !?!?!";
600  continue;
601  }
602  QWidget *widget = mPluginConfigWidgets[name];
603  // load the config into the widget
605  instance->loadFromConfig(widget, &pconfa);
606  }
607  }
608 }
609 
611 {
612  QList<QTreeWidgetItem*> sel = u->lstPlugins->selectedItems();
613  if (sel.size() != 1) {
614  // u->btnRemovePlugin->setEnabled(false);
615  u->lblPluginInfo->setText("");
616  return;
617  }
618  int k = sel[0]->data(0, KLFSETTINGS_ROLE_PLUGINDEX).toInt();
619  if (k < 0 || k >= klf_plugins.size()) {
620  // u->btnRemovePlugin->setEnabled(false);
621  u->lblPluginInfo->setText("");
622  return;
623  }
624 
625  // u->btnRemovePlugin->setEnabled(true);
626  int smallpointsize = QFontInfo(font()).pointSize() - 1;
627  u->lblPluginInfo->setText(tr("<p style=\"-qt-block-indent: 0; text-indent: 0px; margin-bottom: 0px;\">\n"
628  "<tt>Name:</tt> <span style=\"font-weight:600;\">%1</span><br />\n"
629  "<tt>Author:</tt> <span style=\"font-weight:600;\">%2</span><br />\n"
630  "<tt>Description:</tt></p>\n"
631  "<p style=\"font-weight: 600; margin-top: 2px; margin-left: 25px;"
632  " margin-bottom: 0px;\">%3</p>\n"
633  "<p style=\"-qt-block-indent: 0; text-indent: 0px; margin-top: 2px;\">\n"
634  "<tt>File Location:</tt> <span style=\"font-size: %4pt;\">%5</span>\n")
635  .arg(Qt::escape(klf_plugins[k].title)).arg(Qt::escape(klf_plugins[k].author))
636  .arg(Qt::escape(klf_plugins[k].description))
637  .arg(smallpointsize)
638  .arg(Qt::escape(QDir::toNativeSeparators(QFileInfo(klf_plugins[k].fpath)
639  .canonicalFilePath())))
640  );
641 }
642 
644 {
645  // THIS FUNCTION IS NO LONGER USED. PLUGINS ARE AUTOMATICALLY REMOVED WHEN THE CORRESPONDING
646  // ADD-ON IS REMOVED. THIS FUNCTION IS KEPT IN CASE I CHANGE SOMETHING IN THE FUTURE.
647 
648  QList<QTreeWidgetItem*> sel = u->lstPlugins->selectedItems();
649  if (sel.size() != 1) {
650  qWarning("KLFSettings::removePlugin: No Selection or many selection");
651  return;
652  }
653  QTreeWidgetItem * selectedItem = sel[0];
654  int k = selectedItem->data(0, KLFSETTINGS_ROLE_PLUGINDEX).toInt();
655  if (k < 0 || k >= klf_plugins.size()) {
656  qWarning("KLFSettings::removePlugin: Error: What's going on?? k=%d > klf_plugins.size=%d", k, klf_plugins.size());
657  return;
658  }
659 
660  QMessageBox confirmdlg(this);
661  confirmdlg.setIcon(QMessageBox::Warning);
662  confirmdlg.setWindowTitle(tr("Remove Plugin?"));
663  confirmdlg.setText(tr("<qt>Are you sure you want to remove Plugin <i>%1</i>?</qt>").arg(klf_plugins[k].title));
664  confirmdlg.setDetailedText(tr("The Plugin File %1 will be removed from disk.").arg(klf_plugins[k].fpath));
665  confirmdlg.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
666  confirmdlg.setEscapeButton(QMessageBox::Cancel);
667  confirmdlg.setDefaultButton(QMessageBox::Cancel);
668 
669  int confirmation = confirmdlg.exec();
670  if (confirmation != QMessageBox::Yes) {
671  // action cancelled by user
672  return;
673  }
674 
675  bool r = QFile::remove(klf_plugins[k].fpath);
676 
677  if ( r ) {
678  QMessageBox::information(this, tr("Remove Plugin"),
679  tr("<p style=\"-qt-block-indent: 0; text-indent: 0px;\">Please note the following:<br />\n"
680  "<ul><li>You need to restart KLatexFormula for changes to take effect\n"
681  "<li>If this plugin was privided in an add-on, you need to remove the corresponding "
682  "add-on too or the plugin will be automatically re-installed."
683  "</p>"));
684  // remove plugin list item
685  delete selectedItem;
686  } else {
687  qWarning("Failed to remove plugin '%s'", qPrintable(klf_plugins[k].fpath));
688  QMessageBox::critical(this, tr("Error"), tr("Failed to remove Plugin."));
689  }
690 
693 }
694 
696 {
697  int k;
698  klfDbg("removing plugin "<<fname<<" from plugins. Dumping plugin list: ");
699  for (k = 0; k < klf_plugins.size(); ++k) {
700  klfDbg(" --> plugin: fname="<<klf_plugins[k].fname) ;
701  }
702 
703  for (k = 0; k < klf_plugins.size() && klf_plugins[k].fname != fname; ++k)
704  ;
705  if (k < 0 || k >= klf_plugins.size()) {
706  qWarning("KLFSettings::removePlugin: internal error: didn't find plugin name %s", qPrintable(fname));
707  return;
708  }
709 
710  bool r = QFile::remove(klf_plugins[k].fpath);
711 
712  if ( r ) {
713  // find corresponding tree widget item
714  QTreeWidgetItemIterator it(u->lstPlugins);
715  while (*it) {
716  if ( (*it)->data(0, KLFSETTINGS_ROLE_PLUGINDEX).toInt() == k ) {
717  // remove plugin list item
718  delete (*it);
719  break;
720  }
721  ++it;
722  }
723  } else {
724  qWarning("Failed to remove plugin '%s'", qPrintable(klf_plugins[k].fpath));
725  QMessageBox::critical(this, tr("Error"), tr("Failed to remove Plugin %1.").arg(klf_plugins[k].title));
726  }
727 }
728 
729 
730 bool KLFSettings::setDefaultFor(const QString& progname, const QString& guessedprog, bool required,
731  KLFPathChooser *destination)
732 {
733  QString progpath = guessedprog;
734  if (progpath.isEmpty()) {
735  if (QFileInfo(destination->path()).isExecutable()) {
736  // field already has a valid value, don't touch it and don't complain
737  return true;
738  }
739  if ( ! required )
740  return false;
741  QMessageBox msgbox(QMessageBox::Critical, tr("Error"), tr("Could not find %1 executable !")
742  .arg(progname), QMessageBox::Ok);
743  msgbox.setInformativeText(tr("Please check your installation and specify the path"
744  " to %1 executable manually if it is not installed"
745  " in $PATH.").arg(progname));
746  msgbox.setDefaultButton(QMessageBox::Ok);
747  msgbox.setEscapeButton(QMessageBox::Ok);
748  msgbox.exec();
749  return false;
750  }
751 
752  destination->setPath(progpath);
753  return true;
754 }
755 
757 {
758  KLFBackend::klfSettings defaultsettings;
759  KLFBackend::detectSettings(&defaultsettings);
760  if ( ! QFileInfo(u->pathTempDir->path()).isDir() )
761  u->pathTempDir->setPath(QDir::toNativeSeparators(defaultsettings.tempdir));
762  setDefaultFor("latex", defaultsettings.latexexec, true, u->pathLatex);
763  setDefaultFor("dvips", defaultsettings.dvipsexec, true, u->pathDvips);
764  setDefaultFor("gs", defaultsettings.gsexec, true, u->pathGs);
765  bool r = setDefaultFor("epstopdf", defaultsettings.epstopdfexec, false, u->pathEpstopdf);
766  u->chkEpstopdf->setChecked(r);
767 }
768 
769 
771 {
772  u->lstAddOns->clear();
773  u->lstAddOns->setColumnWidth(0, 160);
774 
775  // explore all addons
776  int k;
777  for (k = 0; k < klf_addons.size(); ++k) {
778  QTreeWidgetItem *item = new QTreeWidgetItem(u->lstAddOns);
779  item->setData(0, KLFSETTINGS_ROLE_ADDONINDEX, QVariant((int)k));
780 
781  item->setText(0, klf_addons[k].title());
782  item->setText(1, klf_addons[k].description());
783 
784  // set background color to indicate if status is fresh,
785  // and/or if plugin is installed locally
786  if (klf_addons[k].isfresh()) {
787  item->setBackground(0, QColor(200, 255, 200));
788  item->setBackground(1, QColor(200, 255, 200));
789  } /* // color locally installed plug-ins [ don't, it's unaesthetic ! ]
790  else if (klf_addons[k].islocal()) {
791  item->setBackground(0, QColor(200, 200, 255));
792  item->setBackground(1, QColor(200, 200, 255));
793  } */
794  }
795 }
796 
798 {
799  QList<QTreeWidgetItem*> sel = u->lstAddOns->selectedItems();
800  if (sel.size() != 1) {
801  u->lblAddOnInfo->setText("");
802  u->btnRemoveAddOn->setEnabled(false);
803  return;
804  }
805  int k = sel[0]->data(0, KLFSETTINGS_ROLE_ADDONINDEX).toInt();
806  if (k < 0 || k >= klf_addons.size()) {
807  u->lblAddOnInfo->setText("");
808  u->btnRemoveAddOn->setEnabled(false);
809  return;
810  }
811 
812  // enable remove button only if this addon is "local", i.e. precisely removable
813  u->btnRemoveAddOn->setEnabled(klf_addons[k].islocal());
814 
815  int smallpointsize = QFontInfo(font()).pointSize() - 1;
816  u->lblAddOnInfo->setText(tr("<p style=\"-qt-block-indent: 0; text-indent: 0px; margin-bottom: 0px\">\n"
817  "<tt>Name:</tt> <span style=\"font-weight:600;\">%1</span><br />\n"
818  "<tt>Author:</tt> <span style=\"font-weight:600;\">%2</span><br />\n"
819  "<tt>Description:</tt></p>\n"
820  "<p style=\"font-weight: 600; margin-top: 2px; margin-left: 25px;"
821  " margin-bottom: 0px;\">%3</p>\n"
822  "<p style=\"-qt-block-indent: 0; text-indent: 0px; margin-top: 2px;\">\n"
823  "<tt>File Name:</tt> <span style=\"font-size: %5pt;\">%4</span><br />\n"
824  "<tt>File Location:</tt> <span style=\"font-size: %5pt;\">%6</span><br />\n"
825  "<tt><i>%7</i></tt>").arg(Qt::escape(klf_addons[k].title()))
826  .arg(Qt::escape(klf_addons[k].author())).arg(Qt::escape(klf_addons[k].description()))
827  .arg(Qt::escape(klf_addons[k].fname()))
828  .arg(smallpointsize)
829  .arg(Qt::escape(QDir::toNativeSeparators(QFileInfo(klf_addons[k].dir())
830  .canonicalFilePath()) + QDir::separator()))
831  .arg( klf_addons[k].islocal() ?
832  tr("Add-On installed locally") :
833  tr("Add-On installed globally on system") )
834  );
835 
836 }
837 
838 
840 {
841  QStringList efnames =
842  QFileDialog::getOpenFileNames(this, tr("Please select add-on file(s) to import"),
843  QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation),
844  "Qt Resource Files (*.rcc)");
845  int i;
846  for (i = 0; i < efnames.size(); ++i) {
847  importAddOn(efnames[i], false);
848  }
849  // display message to user to restart KLatexFormula, if needed
850  if (i > 0) {
851  QMessageBox::information(this, tr("Import"), tr("Please restart KLatexFormula for changes to take effect."));
852  }
853 }
854 
855 void KLFSettings::importAddOn(const QString& fileName, bool suggestRestart)
856 {
858  klfDbg("fileName="<<fileName<<", suggestRestart="<<suggestRestart) ;
859 
860  QFileInfo fi(fileName);
861  if (!fi.exists() || !fi.isReadable()) {
862  QMessageBox::critical(this, tr("Error"), tr("File %1 cannot be accessed.").arg(fileName));
863  return;
864  }
865  QString destination = klfconfig.homeConfigDirRCCResources+"/";
866  QString destfpath = destination + QFileInfo(fileName).fileName();
867  if ( QFile::exists(destfpath) ) {
868  QMessageBox::critical(this, tr("Error"),
869  tr("An Add-On with the same file name has already been imported."));
870  return;
871  }
872  bool r = QFile::copy(fileName, destfpath);
873  if ( !r ) {
874  QMessageBox::critical(this, tr("Error"), tr("Import of add-on file %1 failed.").arg(fileName));
875  return;
876  }
877 
878  // import succeeded, show the add-on as fresh.
879  KLFAddOnInfo addoninfo(destfpath, true);
880  if (!addoninfo.klfminversion().isEmpty() &&
881  klfVersionCompareLessThan(KLF_VERSION_STRING, addoninfo.klfminversion())) {
882  // add-on too recent
883  QMessageBox::critical(this, tr("Error"),
884  tr("This add-on requires a more recent version of KLatexFormula.\n"
885  "Required version: %1\n"
886  "This version: %2").arg(addoninfo.klfminversion(), KLF_VERSION_STRING));
887  return;
888  }
889  // if we have new translations, add them to our translation combo box, and prompt user to change to that
890  // language. (It is highly reasonable that if he installed the translation add-on, it's to use it...!)
891  int k;
892  QStringList trlist = addoninfo.translations();
893  KLFI18nFile *detectedI18nFile = NULL;
894  for (k = 0; k < trlist.size(); ++k) {
895  KLFI18nFile i18nfile(addoninfo.rccmountroot()+"/i18n/"+trlist[k]);
896  if ( u->cbxLocale->findData(i18nfile.locale) == -1 ) {
897  klfDbg("found translation: "<<i18nfile.locale) ;
898  klf_add_avail_translation(i18nfile);
899  if (detectedI18nFile == NULL)
900  detectedI18nFile = new KLFI18nFile(i18nfile);
901  }
902  }
903  if (detectedI18nFile != NULL) {
904  klfDbg("translation(s) found. first one found was: "<<detectedI18nFile->locale) ;
905  // update the translation list
907  // find the translation
908  for (k = 0; k < klf_avail_translations.size(); ++k) {
909  if (klf_avail_translations[k].localename == detectedI18nFile->locale)
910  break;
911  }
912  int cbxindex = u->cbxLocale->findData(detectedI18nFile->locale);
913  if (k >= 0 && k < klf_avail_translations.size() && cbxindex >= 0) {
914  if (QMessageBox::question(this, tr("Change Language"), tr("Change application language to <b>%1</b>?")
915  .arg(klf_avail_translations[k].translatedname),
916  QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes)
917  == QMessageBox::Yes) {
918  u->cbxLocale->setCurrentIndex(cbxindex);
919  apply();
920  // a message warning the user to restart has already been displayed in the apply() above.
921  suggestRestart = false;
922  }
923  }
924  delete detectedI18nFile;
925  detectedI18nFile = NULL;
926  }
927  klf_addons.append(addoninfo);
929 
930  if (suggestRestart) {
931  QMessageBox::information(this, tr("Import"), tr("Please restart KLatexFormula for changes to take effect."));
932  }
933 }
934 
936 {
937  QList<QTreeWidgetItem*> sel = u->lstAddOns->selectedItems();
938  if (sel.size() != 1) {
939  qWarning("Expected single add-on selection for removal !");
940  return;
941  }
942 
943  int k = sel[0]->data(0, KLFSETTINGS_ROLE_ADDONINDEX).toInt();
944  if (k < 0 || k >= klf_addons.size()) {
945  // what's going on ???
946  return;
947  }
948 
949  QMessageBox confirmdlg(this);
950  confirmdlg.setIcon(QMessageBox::Warning);
951  confirmdlg.setWindowTitle(tr("Remove Add-On?"));
952  confirmdlg.setText(tr("<qt>Are you sure you want to remove Add-On <i>%1</i>?</qt>")
953  .arg(klf_addons[k].title()));
954  QStringList ourplugins = klf_addons[k].localPluginList();
955  QString msg;
956  if (ourplugins.size()) {
957  msg = tr("The Add-On File %1 will be removed from disk, along with plugin(s) %2.")
958  .arg(klf_addons[k].fpath(), ourplugins.join(", "));
959  } else {
960  msg = tr("The Add-On File %1 will be removed from disk.").arg(klf_addons[k].fpath());
961  }
962  confirmdlg.setDetailedText(msg);
963  confirmdlg.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
964  confirmdlg.setEscapeButton(QMessageBox::Cancel);
965  confirmdlg.setDefaultButton(QMessageBox::Cancel);
966 
967  int confirmation = confirmdlg.exec();
968  if (confirmation != QMessageBox::Yes) {
969  // action cancelled by user
970  return;
971  }
972 
973  bool r = QFile::remove(klf_addons[k].fpath());
974  // remove all corresponding plugins too
975  int j;
976  if ( r ) {
977  QMessageBox::information(this, tr("Remove Add-On"),
978  tr("Please restart KLatexFormula for changes to take effect."));
979  } else {
980  qWarning("Failed to remove add-on '%s'", qPrintable(klf_addons[k].fpath()));
981  QMessageBox::critical(this, tr("Error"), tr("Failed to remove Add-On."));
982  return;
983  }
984 
985  // remove all corresponding plug-ins
986  QStringList lplugins = klf_addons[k].localPluginList();
987  for (j = 0; j < lplugins.size(); ++j)
988  removePlugin(lplugins[j]);
989 
990  klf_addons.removeAt(k);
991 
994 }
995 
997 {
998  QAction *a = qobject_cast<QAction*>(sender());
999  if (a == 0)
1000  return;
1001  const QVariantMap vmap = a->data().toMap();
1002  klfDbg("Set font from action with data "<<vmap) ;
1003  QString btnkey = vmap["Button"].toString();
1004  KLF_ASSERT_CONDITION(pFontButtons.contains(btnkey), "Unknown button "<<btnkey<<" !", return ) ;
1005  QFont f = vmap["Font"].value<QFont>();
1006  slotChangeFont(pFontButtons[btnkey], f);
1007  if (vmap.contains("isSystemDefaultAppFont") && vmap["isSystemDefaultAppFont"].toBool()) {
1008  klfDbg("Set default application font.") ;
1009  pUserSetDefaultAppFont = true;
1010  }
1011 }
1013 {
1014  QPushButton *w = qobject_cast<QPushButton*>(sender());
1015  if ( w == 0 )
1016  return;
1017  QFont fnt = QFontDialog::getFont(0, w->property("selectedFont").value<QFont>(), this);
1018  slotChangeFont(w, fnt);
1019 }
1021 {
1022  if ( w == 0 )
1023  return;
1024  w->setFont(fnt);
1025  w->setProperty("selectedFont", QVariant(fnt));
1026  if (w == u->btnAppFont)
1027  pUserSetDefaultAppFont = false;
1028 }
1029 
1031 {
1032  int k;
1033  // apply settings here
1034 
1035  // the settings object that we will fill, and set to _mainwin
1036  KLFBackend::klfSettings s = _mainwin->currentSettings();
1037 
1038  s.tempdir = QDir::fromNativeSeparators(u->pathTempDir->path());
1039  s.latexexec = u->pathLatex->path();
1040  s.dvipsexec = u->pathDvips->path();
1041  s.gsexec = u->pathGs->path();
1042  s.epstopdfexec = QString();
1043  if (u->chkEpstopdf->isChecked()) {
1044  s.epstopdfexec = u->pathEpstopdf->path();
1045  }
1046  // detect environment for those settings (in particular mgs.exe for ghostscript ...)
1047 
1048  klf_detect_execenv(&s);
1049 
1050  s.lborderoffset = u->spnLBorderOffset->value();
1051  s.tborderoffset = u->spnTBorderOffset->value();
1052  s.rborderoffset = u->spnRBorderOffset->value();
1053  s.bborderoffset = u->spnBBorderOffset->value();
1054  s.outlineFonts = u->chkOutlineFonts->isChecked();
1055 
1056  _mainwin->applySettings(s);
1057 
1058  if (u->chkSHEnable->isChecked())
1060  else
1062  if (u->chkSHHighlightParensOnly->isChecked())
1064  else
1066  if (u->chkSHHighlightLonelyParen->isChecked())
1068  else
1070 
1071  for (k = 0; k < _textformats.size(); ++k) {
1072  QColor c = _textformats[k].fg->color();
1073  if (c.isValid())
1074  _textformats[k].fmt->setForeground(c);
1075  else
1076  _textformats[k].fmt->clearForeground();
1077  c = _textformats[k].bg->color();
1078  if (c.isValid())
1079  _textformats[k].fmt->setBackground(c);
1080  else
1081  _textformats[k].fmt->clearBackground();
1082  Qt::CheckState b = _textformats[k].chkB->checkState();
1083  if (b == Qt::PartiallyChecked)
1084  _textformats[k].fmt->clearProperty(QTextFormat::FontWeight);
1085  else if (b == Qt::Checked)
1086  _textformats[k].fmt->setFontWeight(QFont::Bold);
1087  else
1088  _textformats[k].fmt->setFontWeight(QFont::Normal);
1089  Qt::CheckState it = _textformats[k].chkI->checkState();
1090  if (it == Qt::PartiallyChecked)
1091  _textformats[k].fmt->clearProperty(QTextFormat::FontItalic);
1092  else
1093  _textformats[k].fmt->setFontItalic( it == Qt::Checked );
1094  }
1095 
1096  // language settings
1097  QString localename = u->cbxLocale->itemData(u->cbxLocale->currentIndex()).toString();
1098  klfDbg("New locale name: "<<localename);
1099  bool localechanged = false;
1100  if (klfconfig.UI.locale != localename) {
1101  if ((!klfconfig.UI.locale.isEmpty() && klfconfig.UI.locale != "C" && klfconfig.UI.locale != "en_US") ||
1102  (!localename.isEmpty() && localename != "C" && localename != "en_US"))
1103  localechanged = true; // not just switching from "C" to "en_US" which is not a locale change...
1104  }
1105  klfconfig.UI.locale = localename;
1107  _mainwin->setApplicationLocale(localename);
1108  if (localechanged) {
1109  QMessageBox::information(this, tr("Language changed"),
1110  tr("You may need to restart KLatexFormula for your new language "
1111  "settings to fully take effect."));
1112  }
1113  // klf_main_do_the_change_of_locale_and_load_translators(...);
1114  // QList<QWidget*> uilist;
1115  // uilist << _mainwin << _mainwin->libraryBrowserWidget() << _mainwin->latexSymbolsWidget()
1116  // << _mainwin->styleManagerWidget() << this ;
1117  // for (k = 0; k < uilist.size(); ++k) {
1118  // uilist[k]->retranlsateUi(uilist[k]);
1119  // }
1120 
1121 
1122  // font settings
1123  QFont curAppFont = klfconfig.UI.applicationFont;
1124  QFont newAppFont = u->btnAppFont->property("selectedFont").value<QFont>();
1125  if (curAppFont != newAppFont || pUserSetDefaultAppFont != klfconfig.UI.useSystemAppFont) {
1126  klfconfig.UI.useSystemAppFont = pUserSetDefaultAppFont;
1127  klfconfig.UI.applicationFont = newAppFont;
1129  qApp->setFont(klfconfig.defaultStdFont);
1130  qApp->setFont(QFont());
1131  } else {
1132  qApp->setFont(klfconfig.UI.applicationFont);
1133  }
1134  // Style sheet refresh is needed to force font (?)
1135  qApp->setStyleSheet(qApp->styleSheet());
1136  _mainwin->refreshAllWindowStyleSheets();
1137  }
1138  klfconfig.UI.latexEditFont = u->btnEditorFont->property("selectedFont").value<QFont>();
1140  klfconfig.UI.preambleEditFont = u->btnPreambleFont->property("selectedFont").value<QFont>();
1142 
1143  klfconfig.UI.labelOutputFixedSize = QSize(u->spnPreviewWidth->value(), u->spnPreviewHeight->value());
1144  klfconfig.UI.enableRealTimePreview = u->chkEnableRealTimePreview->isChecked();
1145 
1146  klfconfig.UI.previewTooltipMaxSize = QSize(u->spnToolTipMaxWidth->value(), u->spnToolTipMaxHeight->value());
1147  klfconfig.UI.enableToolTipPreview = u->chkEnableToolTipPreview->isChecked();
1148 
1149  klfconfig.UI.showHintPopups = u->chkShowHintPopups->isChecked();
1150  klfconfig.UI.clearLatexOnly = u->chkClearLatexOnly->isChecked();
1151  klfconfig.UI.glowEffect = u->chkGlowEffect->isChecked();
1152 
1154  u->cbxCopyExportProfile->itemData(u->cbxCopyExportProfile->currentIndex()).toString();
1156  u->cbxDragExportProfile->itemData(u->cbxDragExportProfile->currentIndex()).toString();
1157  // klfconfig.UI.showExportProfilesLabel = u->chkShowExportProfilesLabel->isChecked();
1158  klfconfig.UI.menuExportProfileAffectsDrag = u->chkMenuExportProfileAffectsDrag->isChecked();
1159  klfconfig.UI.menuExportProfileAffectsCopy = u->chkMenuExportProfileAffectsCopy->isChecked();
1160 
1161  klfconfig.LibraryBrowser.restoreURLs = u->chkLibRestoreURLs->isChecked();
1162  klfconfig.LibraryBrowser.confirmClose = u->chkLibConfirmClose->isChecked();
1163  klfconfig.LibraryBrowser.historyTagCopyToArchive = u->chkLibHistoryTagCopyToArchive->isChecked();
1164  // klfconfig.LibraryBrowser.groupSubCategories = u->chkLibGroupSubCategories->isChecked();
1165  klfconfig.LibraryBrowser.iconViewFlow = u->cbxLibIconViewFlow->selectedValue();
1166 
1167  // save plugin config
1168  bool warnneedrestart = false;
1169  QTreeWidgetItemIterator it(u->lstPlugins);
1170  while (*it) {
1171  int j = (*it)->data(0, KLFSETTINGS_ROLE_PLUGINDEX).toInt();
1172  QString name = (*it)->data(0, KLFSETTINGS_ROLE_PLUGNAME).toString();
1173  bool loadenable = ( (*it)->checkState(0) == Qt::Checked ) ;
1174  if (loadenable != klfconfig.Plugins.pluginConfig[name]["__loadenabled"])
1175  warnneedrestart = true;
1176  klfconfig.Plugins.pluginConfig[name]["__loadenabled"] = loadenable;
1177 
1178  if (klf_plugins[j].instance != NULL) {
1180  klf_plugins[j].instance->saveToConfig(mPluginConfigWidgets[name], &pconfa);
1181  }
1182 
1183  ++it;
1184  }
1185  if (warnneedrestart) {
1186  QMessageBox::information(this, tr("Restart KLatexFormula"),
1187  tr("You need to restart KLatexFormula for your changes to take effect."));
1188  }
1189 
1190  _mainwin->refreshShowCorrectClearButton();
1191  _mainwin->saveSettings();
1192 
1193  // recalculate window sizes etc.
1194  _mainwin->refreshWindowSizes();
1195 
1196  // in case eg. the plugins re-change klfconfig in some way (skin does this for syntax highlighting)
1197  // -> refresh
1198  reset();
1199 }
1200 
1202 {
1203  // apply settings
1204  apply();
1205  // and exit dialog
1206  QDialog::accept();
1207 }
1208 
1210 {
1212 }
1213 
1214 
1215 
1216 
QStringList translations()
Definition: klfmain.h:135
void removeAddOn()
bool menuExportProfileAffectsDrag
Definition: klfconfig.h:202
QFont defaultCMUFont
Definition: klfconfig.h:259
#define KLF_ASSERT_CONDITION(expr, msg, failaction)
toNativeSeparators(const QString &pathName)
setPointSize(int pointSize)
setBackground(int column, const QBrush &brush)
QString locale
When setting this, don&#39;t forget to call QLocale::setDefault().
Definition: klfconfig.h:177
contains(const Key &key)
setDefaultButton(QPushButton *button)
fromNativeSeparators(const QString &pathName)
bool KLF_EXPORT klf_detect_execenv(KLFBackend::klfSettings *settings)
QFont applicationFont
Definition: klfconfig.h:179
QFont defaultTTFont
Definition: klfconfig.h:263
QString homeConfigDirRCCResources
Definition: klfconfig.h:155
bool menuExportProfileAffectsCopy
Definition: klfconfig.h:203
QMap< QString, QMap< QString, QVariant > > pluginConfig
Definition: klfconfig.h:254
unsigned int configFlags
Definition: klfconfig.h:209
QString locale
Locale Name (e.g. "fr" or "fr_CH")
Definition: klfmain.h:246
void refreshShowCorrectClearButton()
Definition: klfmainwin.cpp:572
KLFConfig klfconfig
Definition: klfconfig.cpp:88
bool showHintPopups
Definition: klfconfig.h:193
bool glowEffect
Definition: klfconfig.h:197
#define __KLF_SHOW_SETTINGS_CONTROL(tab, focuswidget)
QString klfminversion()
Definition: klfmain.h:100
void populateLocaleCombo()
struct KLFConfig::@1 UI
QString translatedname
Definition: klfmain.h:217
arg(const QString &a, int fieldWidth=0, const QChar &fillChar=QLatin1Char( ' ')
void slotChangeFontPresetSender()
QFont latexEditFont
Definition: klfconfig.h:180
#define klfDbg(streamableItems)
#define KLF_DEBUG_BLOCK(msg)
setData(int column, int role, const QVariant &value)
QFont preambleEditFont
Definition: klfconfig.h:181
KLFSettings(KLFMainWin *parent=0)
Definition: klfsettings.cpp:73
join(const QString &separator)
void setTxtLatexFont(const QFont &f)
Utility class for plugins to access their configuration space in KLFConfig.
Definition: klfconfig.h:61
virtual void loadFromConfig(QWidget *configWidget, KLFPluginConfigAccess *config)=0
data(int column, int role)
void refreshAllWindowStyleSheets()
bool restoreURLs
Definition: klfconfig.h:239
separator()
information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
addAction(const QString &text)
copy(const QString &newName)
#define __KLF_SETTINGS_TEST_STR_CONTROL(controlName, controlNum)
QString localename
Definition: klfmain.h:216
QFont defaultStdFont
Definition: klfconfig.h:261
static QList< KLFMimeExportProfile > exportProfileList()
Definition: klfmime.cpp:271
KLF_EXPORT bool klfVersionCompareLessThan(const QString &v1, const QString &v2)
bool historyTagCopyToArchive
Definition: klfconfig.h:243
#define REG_SH_TEXTFORMATENSEMBLE(x)
Definition: klfsettings.cpp:66
#define KLFSETTINGS_ROLE_ADDONINDEX
Definition: klfsettings.cpp:63
bool confirmClose
Definition: klfconfig.h:240
void populateExportProfilesCombos()
void setDefaultPaths()
question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
setWindowTitle(const QString &title)
setDefault(const QLocale &locale)
QSize previewTooltipMaxSize
Definition: klfconfig.h:182
int iconViewFlow
Definition: klfconfig.h:242
QString dragExportProfile
Definition: klfconfig.h:196
setEscapeButton(QAbstractButton *button)
itemAt(const QPoint &p)
bool useSystemAppFont
Definition: klfconfig.h:178
virtual void accept()
void setTxtPreambleFont(const QFont &f)
void klf_add_avail_translation(KLFI18nFile i18nfile)
Definition: klfmain.cpp:324
void slotChangeFont(QPushButton *btn, const QFont &f)
bool clearLatexOnly
Definition: klfconfig.h:194
void showControl(int controlNum)
void applySettings(const KLFBackend::klfSettings &s)
Small minimalist structure to store basic information about available translations.
Definition: klfmain.h:212
setData(const QVariant &userData)
#define KLF_FUNC_NAME
struct KLFConfig::@2 SyntaxHighlighter
KLF_EXPORT QList< KLFTranslationInfo > klf_avail_translations
Definition: klfmain.cpp:42
void importAddOn()
QList< KLFPluginInfo > klf_plugins
Definition: klfmain.cpp:50
void refreshAddOnSelected()
KLFBackend::klfSettings currentSettings() const
Definition: klfmainwin.h:239
Small structure to store information for a translation file (.qm)
Definition: klfmain.h:239
setCheckState(int column, Qt::CheckState state)
void initPluginControls()
void refreshWindowSizes()
Definition: klfmainwin.cpp:555
static bool treeMaybeUnselect(QTreeWidget *tree, QEvent *event)
virtual QWidget * createConfigWidget(QWidget *parent)=0
enterWhatsThisMode()
void resetPluginControls()
families(WritingSystem writingSystem=Any)
QString copyExportProfile
Definition: klfconfig.h:195
QList< KLFAddOnInfo > klf_addons
Definition: klfmain.cpp:54
void retranslateUi(bool alsoBaseUi=true)
setText(int column, const QString &text)
critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
KLFPluginConfigAccess getPluginConfigAccess(const QString &name)
Definition: klfconfig.cpp:712
void removePlugin()
void slotChangeFontSender()
QSize labelOutputFixedSize
Definition: klfconfig.h:183
bool klf_addons_canimport
Definition: klfmain.cpp:55
void setApplicationLocale(const QString &locale)
static bool detectSettings(klfSettings *settings, const QString &extraPath=QString())
struct KLFConfig::@4 LibraryBrowser
bool eventFilter(QObject *object, QEvent *event)
void refreshAddOnList()
void saveSettings()
Definition: klfmainwin.cpp:621
virtual void setPath(const QString &path)
bool enableRealTimePreview
Definition: klfconfig.h:191
struct KLFConfig::@5 Plugins
QString rccmountroot()
where in the resource tree this rcc resource data is mounted
Definition: klfmain.h:103
bool enableToolTipPreview
Definition: klfconfig.h:190
getOpenFileNames(QWidget *parent=0, const QString &caption=QString()
getFont(bool *ok, const QFont &initial, QWidget *parent, const QString &caption)
#define KLFSETTINGS_ROLE_PLUGINDEX
Definition: klfsettings.cpp:61
#define KLFSETTINGS_ROLE_PLUGNAME
Definition: klfsettings.cpp:60
void refreshPluginSelected()

Generated by doxygen 1.8.11