00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdlib.h>
00025
00026 #include <QDialog>
00027 #include <QCheckBox>
00028 #include <QSpinBox>
00029 #include <QLineEdit>
00030 #include <QFontDatabase>
00031 #include <QFontDialog>
00032 #include <QString>
00033 #include <QMessageBox>
00034 #include <QFileInfo>
00035 #include <QDir>
00036 #include <QFileDialog>
00037 #include <QWhatsThis>
00038 #include <QResource>
00039 #include <QEvent>
00040 #include <QListView>
00041 #include <QMouseEvent>
00042 #include <QDesktopServices>
00043
00044 #include <klfcolorchooser.h>
00045 #include <klfpathchooser.h>
00046
00047 #include <klfbackend.h>
00048
00049 #include <ui_klfsettings.h>
00050
00051 #include "klfmain.h"
00052 #include "klfmainwin.h"
00053 #include "klfconfig.h"
00054 #include "klfmime.h"
00055 #include "klfpluginiface.h"
00056 #include "klflatexedit.h"
00057 #include "klfsettings.h"
00058
00059
00060 #define KLFSETTINGS_ROLE_PLUGNAME (Qt::UserRole + 5300)
00061 #define KLFSETTINGS_ROLE_PLUGINDEX (KLFSETTINGS_ROLE_PLUGNAME + 1)
00062
00063 #define KLFSETTINGS_ROLE_ADDONINDEX (Qt::UserRole + 5400)
00064
00065
00066 #define REG_SH_TEXTFORMATENSEMBLE(x) \
00067 _textformats.append( TextFormatEnsemble( & klfconfig.SyntaxHighlighter.fmt##x , \
00068 u->colSH##x, u->colSH##x##Bg , u->chkSH##x##B , u->chkSH##x##I ) );
00069
00070
00071
00072
00073 KLFSettings::KLFSettings(KLFMainWin* parent)
00074 : QDialog(parent)
00075 {
00076 u = new Ui::KLFSettings;
00077 u->setupUi(this);
00078 setObjectName("KLFSettings");
00079
00080 _mainwin = parent;
00081
00082 pUserSetDefaultAppFont = false;
00083
00084 u->cbxLibIconViewFlow->setEnumValues(QList<int>()<<QListView::TopToBottom<<QListView::LeftToRight,
00085 QStringList()<<tr("Top to Bottom")<<tr("Left to Right"));
00086
00087 reset();
00088
00089 u->btns->clear();
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 QAbstractButton *b;
00102 b = u->btns->addButton(QDialogButtonBox::Cancel);
00103 b->setIcon(QIcon(":/pics/closehide.png"));
00104 connect(b, SIGNAL(clicked()), this, SLOT(reject()));
00105 b = u->btns->addButton(QDialogButtonBox::Apply);
00106 b->setIcon(QIcon(":/pics/apply.png"));
00107 connect(b, SIGNAL(clicked()), this, SLOT(apply()));
00108 b = u->btns->addButton(QDialogButtonBox::Ok);
00109 b->setIcon(QIcon(":/pics/ok.png"));
00110 connect(b, SIGNAL(clicked()), this, SLOT(accept()));
00111
00112 populateLocaleCombo();
00113 populateExportProfilesCombos();
00114
00115
00116 QFont f = this->font();
00117 f.setPointSize(QFontInfo(f).pointSize() - 1);
00118 u->lblSHForeground->setFont(f);
00119 u->lblSHBackground->setFont(f);
00120
00121 connect(u->btnPathsReset, SIGNAL(clicked()), this, SLOT(setDefaultPaths()));
00122
00123 connect(u->lstPlugins, SIGNAL(itemSelectionChanged()), this, SLOT(refreshPluginSelected()));
00124 connect(u->lstAddOns, SIGNAL(itemSelectionChanged()), this, SLOT(refreshAddOnSelected()));
00125 connect(u->btnImportAddOn, SIGNAL(clicked()), this, SLOT(importAddOn()));
00126 connect(u->btnRemoveAddOn, SIGNAL(clicked()), this, SLOT(removeAddOn()));
00127
00128
00129 u->lstPlugins->installEventFilter(this);
00130 u->lstPlugins->viewport()->installEventFilter(this);
00131 u->lstAddOns->installEventFilter(this);
00132 u->lstAddOns->viewport()->installEventFilter(this);
00133
00134 connect(u->btnAppFont, SIGNAL(clicked()), this, SLOT(slotChangeFontSender()));
00135 connect(u->btnEditorFont, SIGNAL(clicked()), this, SLOT(slotChangeFontSender()));
00136 connect(u->btnPreambleFont, SIGNAL(clicked()), this, SLOT(slotChangeFontSender()));
00137
00138
00139 QFontDatabase fdb;
00140 u->aFontCMU->setEnabled( fdb.families().contains("CMU Sans Serif") );
00141 pFontBasePresetActions["CMU"] = u->aFontCMU;
00142 pFontBasePresetActions["TT"] = u->aFontTT;
00143 pFontBasePresetActions["Std"] = u->aFontStd;
00144 pFontButtons["AppFont"] = u->btnAppFont;
00145 pFontButtons["EditorFont"] = u->btnEditorFont;
00146 pFontButtons["PreambleFont"] = u->btnPreambleFont;
00147 QAction *a = NULL;
00148 QMenu *fontPresetMenu = NULL;
00149 QVariantMap vmap;
00150
00151
00152 fontPresetMenu = new QMenu(this);
00153 a = new QAction(this);
00154 vmap["Action"] = "CMU";
00155 vmap["Font"] = klfconfig.defaultCMUFont;
00156 vmap["Button"] = QVariant("AppFont");
00157 a->setData(QVariant(vmap));
00158 a->setEnabled(u->aFontCMU->isEnabled());
00159 fontPresetMenu->addAction(a);
00160 connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
00161 pFontSetActions << a;
00162 a = new QAction(this);
00163 vmap["Action"] = "Std";
00164 vmap["Font"] = klfconfig.defaultStdFont;
00165 vmap["Button"] = QVariant("AppFont");
00166 vmap["isSystemDefaultAppFont"] = QVariant(true);
00167 a->setData(QVariant(vmap));
00168 connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
00169 pFontSetActions << a;
00170 fontPresetMenu->addAction(a);
00171 u->btnAppFontChoose->setMenu(fontPresetMenu);
00172
00173 fontPresetMenu = new QMenu(this);
00174 a = new QAction(this);
00175 vmap["Action"] = "TT";
00176 vmap["Font"] = klfconfig.defaultTTFont;
00177 vmap["Button"] = QVariant("EditorFont");
00178 a->setData(QVariant(vmap));
00179 connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
00180 pFontSetActions << a;
00181 fontPresetMenu->addAction(a);
00182 a = new QAction(this);
00183 vmap["Action"] = "CMU";
00184 vmap["Font"] = klfconfig.defaultCMUFont;
00185 vmap["Button"] = QVariant("EditorFont");
00186 a->setData(QVariant(vmap));
00187 a->setEnabled(u->aFontCMU->isEnabled());
00188 connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
00189 pFontSetActions << a;
00190 fontPresetMenu->addAction(a);
00191 a = new QAction(this);
00192 vmap["Action"] = "Std";
00193 vmap["Font"] = klfconfig.defaultStdFont;
00194 vmap["Button"] = QVariant("EditorFont");
00195 a->setData(QVariant(vmap));
00196 connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
00197 pFontSetActions << a;
00198 fontPresetMenu->addAction(a);
00199 u->btnEditorFontChoose->setMenu(fontPresetMenu);
00200
00201 fontPresetMenu = new QMenu(this);
00202 a = new QAction(this);
00203 vmap["Action"] = "TT";
00204 vmap["Font"] = klfconfig.defaultTTFont;
00205 vmap["Button"] = QVariant("PreambleFont");
00206 a->setData(QVariant(vmap));
00207 connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
00208 pFontSetActions << a;
00209 fontPresetMenu->addAction(a);
00210 a = new QAction(this);
00211 vmap["Action"] = "CMU";
00212 vmap["Font"] = klfconfig.defaultCMUFont;
00213 vmap["Button"] = QVariant("PreambleFont");
00214 a->setData(QVariant(vmap));
00215 a->setEnabled(u->aFontCMU->isEnabled());
00216 connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
00217 pFontSetActions << a;
00218 fontPresetMenu->addAction(a);
00219 a = new QAction(this);
00220 vmap["Action"] = "Std";
00221 vmap["Font"] = klfconfig.defaultStdFont;
00222 vmap["Button"] = QVariant("PreambleFont");
00223 a->setData(QVariant(vmap));
00224 connect(a, SIGNAL(triggered()), this, SLOT(slotChangeFontPresetSender()));
00225 pFontSetActions << a;
00226 fontPresetMenu->addAction(a);
00227 u->btnPreambleFontChoose->setMenu(fontPresetMenu);
00228
00229
00230 REG_SH_TEXTFORMATENSEMBLE(Keyword);
00231 REG_SH_TEXTFORMATENSEMBLE(Comment);
00232 REG_SH_TEXTFORMATENSEMBLE(ParenMatch);
00233 REG_SH_TEXTFORMATENSEMBLE(ParenMismatch);
00234 REG_SH_TEXTFORMATENSEMBLE(LonelyParen);
00235
00236 u->btnImportAddOn->setEnabled(klf_addons_canimport);
00237 u->btnRemoveAddOn->setEnabled(klf_addons_canimport);
00238
00239 refreshAddOnList();
00240 refreshAddOnSelected();
00241 refreshPluginSelected();
00242
00243
00244
00245 QWidget * w = u->tbxPluginsConfig->widget(u->tbxPluginsConfig->currentIndex());
00246 u->tbxPluginsConfig->removeItem(u->tbxPluginsConfig->currentIndex());
00247 delete w;
00248
00249 u->lstPlugins->setColumnWidth(0, 185);
00250
00251
00252 _pluginstuffloaded = false;
00253
00254 retranslateUi(false);
00255 }
00256
00257 void KLFSettings::retranslateUi(bool alsoBaseUi)
00258 {
00259 if (alsoBaseUi)
00260 u->retranslateUi(this);
00261
00262
00263 int k;
00264 for (k = 0; k < pFontSetActions.size(); ++k) {
00265 QAction *a = pFontSetActions[k];
00266 QVariantMap vmap = a->data().toMap();
00267 QString refAKey = vmap["Action"].toString();
00268 KLF_ASSERT_CONDITION(pFontBasePresetActions.contains(refAKey),
00269 "Base Reference Preset Action not found: "<<refAKey<<" ?!?",
00270 continue ) ;
00271 QAction *refA = pFontBasePresetActions[refAKey];
00272 a->setText(refA->text());
00273 a->setIcon(refA->icon());
00274 a->setToolTip(refA->toolTip());
00275 QFont f = vmap["Font"].value<QFont>();
00276 a->setFont(f);
00277 }
00278 }
00279
00280
00281 KLFSettings::~KLFSettings()
00282 {
00283 delete u;
00284 }
00285
00286 void KLFSettings::populateLocaleCombo()
00287 {
00288 KLF_DEBUG_BLOCK(KLF_FUNC_NAME) ;
00289
00290 u->cbxLocale->clear();
00291
00292 u->cbxLocale->addItem( QLatin1String("English Default"), QVariant::fromValue<QString>("en_US") );
00293 int k;
00294 for (k = 0; k < klf_avail_translations.size(); ++k) {
00295 KLFTranslationInfo ti = klf_avail_translations[k];
00296 u->cbxLocale->addItem( ti.translatedname, QVariant(ti.localename) );
00297 klfDbg("Added translation "<< ti.translatedname <<" ("<<ti.localename<<")") ;
00298 }
00299
00300
00301
00302 k = u->cbxLocale->findData(klfconfig.UI.locale);
00303 if (k == -1) {
00304 k = 0;
00305 }
00306 u->cbxLocale->setCurrentIndex(k);
00307 }
00308
00309 void KLFSettings::populateExportProfilesCombos()
00310 {
00311 QList<KLFMimeExportProfile> eplist = KLFMimeExportProfile::exportProfileList();
00312
00313 u->cbxCopyExportProfile->clear();
00314 u->cbxDragExportProfile->clear();
00315 int k;
00316 for (k = 0; k < eplist.size(); ++k) {
00317 u->cbxCopyExportProfile->addItem(eplist[k].description(), QVariant(eplist[k].profileName()));
00318 u->cbxDragExportProfile->addItem(eplist[k].description(), QVariant(eplist[k].profileName()));
00319 }
00320 }
00321
00322
00323 void KLFSettings::show()
00324 {
00325 klfDbg("show called.") ;
00326 populateExportProfilesCombos();
00327
00328 reset();
00329
00330 if (!_pluginstuffloaded)
00331 initPluginControls();
00332 else
00333 resetPluginControls();
00334
00335 QDialog::show();
00336 }
00337
00338
00340 #define __KLF_SHOW_SETTINGS_CONTROL( tab , focuswidget ) \
00341 u->tabs->setCurrentWidget( u->tab ); \
00342 u->focuswidget->setFocus(Qt::OtherFocusReason);
00343
00344 void KLFSettings::showControl(int control)
00345 {
00346 switch (control) {
00347 case AppLanguage:
00348 __KLF_SHOW_SETTINGS_CONTROL(tabAppearance, cbxLocale) ;
00349 break;
00350 case AppFonts:
00351 __KLF_SHOW_SETTINGS_CONTROL(tabAppearance, btnAppFont) ;
00352 break;
00353 case Preview:
00354 __KLF_SHOW_SETTINGS_CONTROL(tabAppearance, chkEnableRealTimePreview) ;
00355 break;
00356 case TooltipPreview:
00357 __KLF_SHOW_SETTINGS_CONTROL(tabAppearance, chkEnableToolTipPreview) ;
00358 break;
00359 case SyntaxHighlighting:
00360 __KLF_SHOW_SETTINGS_CONTROL(tabSyntaxHighlighting, chkSHEnable) ;
00361 break;
00362 case ExecutablePaths:
00363 __KLF_SHOW_SETTINGS_CONTROL(tabAdvanced, pathTempDir) ;
00364 break;
00365 case ExpandEPSBBox:
00366 __KLF_SHOW_SETTINGS_CONTROL(tabAdvanced, spnLBorderOffset) ;
00367 break;
00368 case ExportProfiles:
00369 __KLF_SHOW_SETTINGS_CONTROL(tabAdvanced, cbxCopyExportProfile) ;
00370 break;
00371 case LibrarySettings:
00372 __KLF_SHOW_SETTINGS_CONTROL(tabLibBrowser, chkLibRestoreURLs) ;
00373 break;
00374 case ManageAddOns:
00375 __KLF_SHOW_SETTINGS_CONTROL(tabAddOns, lstAddOns) ;
00376 break;
00377 case ManagePlugins:
00378 __KLF_SHOW_SETTINGS_CONTROL(tabAddOns, lstPlugins) ;
00379 break;
00380 case PluginsConfig:
00381 __KLF_SHOW_SETTINGS_CONTROL(tabPlugins, tbxPluginsConfig->currentWidget()) ;
00382 break;
00383 default:
00384 qWarning()<<KLF_FUNC_NAME<<": unknown control number requested : "<<control;
00385 }
00386 }
00387
00389 #define __KLF_SETTINGS_TEST_STR_CONTROL( controlName, controlNum ) \
00390 if (controlName == QLatin1String(#controlNum)) { \
00391 showControl(controlNum); \
00392 return; \
00393 }
00394
00395 void KLFSettings::showControl(const QString& controlName)
00396 {
00397 __KLF_SETTINGS_TEST_STR_CONTROL( controlName, AppLanguage ) ;
00398 __KLF_SETTINGS_TEST_STR_CONTROL( controlName, AppFonts ) ;
00399 __KLF_SETTINGS_TEST_STR_CONTROL( controlName, Preview ) ;
00400 __KLF_SETTINGS_TEST_STR_CONTROL( controlName, TooltipPreview ) ;
00401 __KLF_SETTINGS_TEST_STR_CONTROL( controlName, SyntaxHighlighting ) ;
00402 __KLF_SETTINGS_TEST_STR_CONTROL( controlName, ExecutablePaths ) ;
00403 __KLF_SETTINGS_TEST_STR_CONTROL( controlName, ExpandEPSBBox ) ;
00404 __KLF_SETTINGS_TEST_STR_CONTROL( controlName, LibrarySettings ) ;
00405 __KLF_SETTINGS_TEST_STR_CONTROL( controlName, ManageAddOns ) ;
00406 __KLF_SETTINGS_TEST_STR_CONTROL( controlName, ManagePlugins ) ;
00407 __KLF_SETTINGS_TEST_STR_CONTROL( controlName, PluginsConfig ) ;
00408 }
00409
00410 static bool treeMaybeUnselect(QTreeWidget *tree, QEvent *event)
00411 {
00412
00413
00414 if (event->type() != QEvent::MouseButtonPress)
00415 return false;
00416 QMouseEvent * e = (QMouseEvent*) event;
00417 if (e->button() != Qt::LeftButton)
00418 return false;
00419 QTreeWidgetItem *itemAtClick = tree->itemAt(e->pos());
00420 if ( itemAtClick ) {
00421
00422 return false;
00423 }
00424
00425 QList<QTreeWidgetItem*> selitems = tree->selectedItems();
00426 int k;
00427 for (k = 0; k < selitems.size(); ++k) {
00428 selitems[k]->setSelected(false);
00429 }
00430 return true;
00431 }
00432
00433 bool KLFSettings::eventFilter(QObject *object, QEvent *event)
00434 {
00435
00436 QTreeWidget * tree = NULL;
00437 if (object == u->lstPlugins || object == u->lstPlugins->viewport())
00438 tree = u->lstPlugins;
00439 if (object == u->lstAddOns || object == u->lstAddOns->viewport())
00440 tree = u->lstAddOns;
00441
00442 if ( tree )
00443 if ( treeMaybeUnselect(tree, event) )
00444 return true;
00445 return QDialog::eventFilter(object, event);
00446 }
00447
00448 void KLFSettings::reset()
00449 {
00450 int k;
00451 KLFBackend::klfSettings s = _mainwin->currentSettings();
00452
00453 k = u->cbxLocale->findData(klfconfig.UI.locale);
00454 if (k == -1) {
00455 k = 0;
00456 }
00457 u->cbxLocale->setCurrentIndex(k);
00458
00459 u->pathTempDir->setPath(QDir::toNativeSeparators(s.tempdir));
00460 u->pathLatex->setPath(s.latexexec);
00461 u->pathDvips->setPath(s.dvipsexec);
00462 u->pathGs->setPath(s.gsexec);
00463 u->pathEpstopdf->setPath(s.epstopdfexec);
00464 u->chkEpstopdf->setChecked( ! s.epstopdfexec.isEmpty() );
00467 u->spnLBorderOffset->setValue( (int)(s.lborderoffset+0.5) );
00468 u->spnTBorderOffset->setValue( (int)(s.tborderoffset+0.5) );
00469 u->spnRBorderOffset->setValue( (int)(s.rborderoffset+0.5) );
00470 u->spnBBorderOffset->setValue( (int)(s.bborderoffset+0.5) );
00471 u->chkOutlineFonts->setChecked( s.outlineFonts );
00472
00473 u->chkSHEnable->setChecked(klfconfig.SyntaxHighlighter.configFlags
00474 & KLFLatexSyntaxHighlighter::Enabled);
00475 u->chkSHHighlightParensOnly->setChecked(klfconfig.SyntaxHighlighter.configFlags
00476 & KLFLatexSyntaxHighlighter::HighlightParensOnly);
00477 u->chkSHHighlightLonelyParen->setChecked(klfconfig.SyntaxHighlighter.configFlags
00478 & KLFLatexSyntaxHighlighter::HighlightLonelyParen);
00479
00480 for (k = 0; k < _textformats.size(); ++k) {
00481 if (_textformats[k].fmt->hasProperty(QTextFormat::ForegroundBrush))
00482 _textformats[k].fg->setColor(_textformats[k].fmt->foreground().color());
00483 else
00484 _textformats[k].fg->setColor(QColor());
00485 if (_textformats[k].fmt->hasProperty(QTextFormat::BackgroundBrush))
00486 _textformats[k].bg->setColor(_textformats[k].fmt->background().color());
00487 else
00488 _textformats[k].bg->setColor(QColor());
00489 if (_textformats[k].fmt->hasProperty(QTextFormat::FontWeight))
00490 _textformats[k].chkB->setChecked(_textformats[k].fmt->fontWeight() > 60);
00491 else
00492 _textformats[k].chkB->setCheckState(Qt::PartiallyChecked);
00493 if (_textformats[k].fmt->hasProperty(QTextFormat::FontItalic))
00494 _textformats[k].chkI->setChecked(_textformats[k].fmt->fontItalic());
00495 else
00496 _textformats[k].chkI->setCheckState(Qt::PartiallyChecked);
00497 }
00498
00499 pUserSetDefaultAppFont = klfconfig.UI.useSystemAppFont;
00500 u->btnAppFont->setFont(klfconfig.UI.applicationFont);
00501 u->btnAppFont->setProperty("selectedFont", QVariant(klfconfig.UI.applicationFont));
00502 u->btnEditorFont->setFont(klfconfig.UI.latexEditFont);
00503 u->btnEditorFont->setProperty("selectedFont", QVariant(klfconfig.UI.latexEditFont));
00504 u->btnPreambleFont->setFont(klfconfig.UI.preambleEditFont);
00505 u->btnPreambleFont->setProperty("selectedFont", QVariant(klfconfig.UI.preambleEditFont));
00506
00507 u->chkEnableRealTimePreview->setChecked(klfconfig.UI.enableRealTimePreview);
00508 u->spnPreviewWidth->setValue(klfconfig.UI.labelOutputFixedSize.width());
00509 u->spnPreviewHeight->setValue(klfconfig.UI.labelOutputFixedSize.height());
00510
00511 u->chkEnableToolTipPreview->setChecked(klfconfig.UI.enableToolTipPreview);
00512 u->spnToolTipMaxWidth->setValue(klfconfig.UI.previewTooltipMaxSize.width());
00513 u->spnToolTipMaxHeight->setValue(klfconfig.UI.previewTooltipMaxSize.height());
00514
00515 u->chkShowHintPopups->setChecked(klfconfig.UI.showHintPopups);
00516 u->chkClearLatexOnly->setChecked(klfconfig.UI.clearLatexOnly);
00517 u->chkGlowEffect->setChecked(klfconfig.UI.glowEffect);
00518
00519 int copyi = u->cbxCopyExportProfile->findData(QVariant(klfconfig.UI.copyExportProfile));
00520 u->cbxCopyExportProfile->setCurrentIndex(copyi);
00521 int dragi = u->cbxDragExportProfile->findData(QVariant(klfconfig.UI.dragExportProfile));
00522 u->cbxDragExportProfile->setCurrentIndex(dragi);
00523
00524 u->chkMenuExportProfileAffectsDrag->setChecked(klfconfig.UI.menuExportProfileAffectsDrag);
00525 u->chkMenuExportProfileAffectsCopy->setChecked(klfconfig.UI.menuExportProfileAffectsCopy);
00526
00527 u->chkLibRestoreURLs->setChecked(klfconfig.LibraryBrowser.restoreURLs);
00528 u->chkLibConfirmClose->setChecked(klfconfig.LibraryBrowser.confirmClose);
00529 u->chkLibHistoryTagCopyToArchive->setChecked(klfconfig.LibraryBrowser.historyTagCopyToArchive);
00530
00531 u->cbxLibIconViewFlow->setSelectedValue(klfconfig.LibraryBrowser.iconViewFlow);
00532 }
00533
00534
00535 void KLFSettings::initPluginControls()
00536 {
00537 if (_pluginstuffloaded)
00538 return;
00539 _pluginstuffloaded = true;
00540
00541 int j;
00542 int n_pluginconfigpages = 0;
00543 QTreeWidgetItem *litem;
00544 for (j = 0; j < klf_plugins.size(); ++j) {
00545 QString name = klf_plugins[j].name;
00546 QString title = klf_plugins[j].title;
00547 QString description = klf_plugins[j].description;
00548 KLFPluginGenericInterface *instance = klf_plugins[j].instance;
00549
00550 litem = new QTreeWidgetItem(u->lstPlugins);
00551 litem->setCheckState(0,
00552 klfconfig.Plugins.pluginConfig[name]["__loadenabled"].toBool() ?
00553 Qt::Checked : Qt::Unchecked);
00554 litem->setText(0, title);
00555
00556 litem->setData(0, KLFSETTINGS_ROLE_PLUGNAME, name);
00557 litem->setData(0, KLFSETTINGS_ROLE_PLUGINDEX, j);
00558
00559 mPluginListItems[name] = litem;
00560
00561 if ( instance != NULL ) {
00562 mPluginConfigWidgets[name] = instance->createConfigWidget( NULL );
00563 u->tbxPluginsConfig->addItem( mPluginConfigWidgets[name] , QIcon(":/pics/bullet22.png"), title );
00564 KLFPluginConfigAccess pconfa = klfconfig.getPluginConfigAccess(name);
00565 instance->loadFromConfig(mPluginConfigWidgets[name], &pconfa);
00566 n_pluginconfigpages++;
00567 }
00568 }
00569 if (n_pluginconfigpages == 0) {
00570 QLabel * lbl;
00571 lbl = new QLabel(tr("No Plugins have been loaded. Please install and enable individual plugins "
00572 "first, then come back to this page to configure them."), u->tbxPluginsConfig);
00573 lbl->hide();
00574 lbl->setWordWrap(true);
00575 lbl->setMargin(20);
00576 u->tbxPluginsConfig->addItem(lbl, tr("No Plugins Loaded"));
00577 }
00578 }
00579
00580 void KLFSettings::resetPluginControls()
00581 {
00582
00583
00584 int k;
00585 for (k = 0; k < klf_plugins.size(); ++k) {
00586 QString name = klf_plugins[k].name;
00587 KLFPluginGenericInterface *instance = klf_plugins[k].instance;
00588
00589 KLF_ASSERT_CONDITION(mPluginListItems.contains(name),
00590 "Plugin "<<name<<" does not have its corresponding check item!",
00591 continue ;) ;
00592
00593 mPluginListItems[name]->setCheckState(0,
00594 klfconfig.Plugins.pluginConfig[name]["__loadenabled"].toBool() ?
00595 Qt::Checked : Qt::Unchecked);
00596
00597 if (instance != NULL) {
00598 if (!mPluginConfigWidgets.contains(name)) {
00599 qWarning()<<KLF_FUNC_NAME<<": Plugin "<<name<<" does not have its config widget !?!?!";
00600 continue;
00601 }
00602 QWidget *widget = mPluginConfigWidgets[name];
00603
00604 KLFPluginConfigAccess pconfa = klfconfig.getPluginConfigAccess(name);
00605 instance->loadFromConfig(widget, &pconfa);
00606 }
00607 }
00608 }
00609
00610 void KLFSettings::refreshPluginSelected()
00611 {
00612 QList<QTreeWidgetItem*> sel = u->lstPlugins->selectedItems();
00613 if (sel.size() != 1) {
00614
00615 u->lblPluginInfo->setText("");
00616 return;
00617 }
00618 int k = sel[0]->data(0, KLFSETTINGS_ROLE_PLUGINDEX).toInt();
00619 if (k < 0 || k >= klf_plugins.size()) {
00620
00621 u->lblPluginInfo->setText("");
00622 return;
00623 }
00624
00625
00626 int smallpointsize = QFontInfo(font()).pointSize() - 1;
00627 u->lblPluginInfo->setText(tr("<p style=\"-qt-block-indent: 0; text-indent: 0px; margin-bottom: 0px;\">\n"
00628 "<tt>Name:</tt> <span style=\"font-weight:600;\">%1</span><br />\n"
00629 "<tt>Author:</tt> <span style=\"font-weight:600;\">%2</span><br />\n"
00630 "<tt>Description:</tt></p>\n"
00631 "<p style=\"font-weight: 600; margin-top: 2px; margin-left: 25px;"
00632 " margin-bottom: 0px;\">%3</p>\n"
00633 "<p style=\"-qt-block-indent: 0; text-indent: 0px; margin-top: 2px;\">\n"
00634 "<tt>File Location:</tt> <span style=\"font-size: %4pt;\">%5</span>\n")
00635 .arg(Qt::escape(klf_plugins[k].title)).arg(Qt::escape(klf_plugins[k].author))
00636 .arg(Qt::escape(klf_plugins[k].description))
00637 .arg(smallpointsize)
00638 .arg(Qt::escape(QDir::toNativeSeparators(QFileInfo(klf_plugins[k].fpath)
00639 .canonicalFilePath())))
00640 );
00641 }
00642
00643 void KLFSettings::removePlugin()
00644 {
00645
00646
00647
00648 QList<QTreeWidgetItem*> sel = u->lstPlugins->selectedItems();
00649 if (sel.size() != 1) {
00650 qWarning("KLFSettings::removePlugin: No Selection or many selection");
00651 return;
00652 }
00653 QTreeWidgetItem * selectedItem = sel[0];
00654 int k = selectedItem->data(0, KLFSETTINGS_ROLE_PLUGINDEX).toInt();
00655 if (k < 0 || k >= klf_plugins.size()) {
00656 qWarning("KLFSettings::removePlugin: Error: What's going on?? k=%d > klf_plugins.size=%d", k, klf_plugins.size());
00657 return;
00658 }
00659
00660 QMessageBox confirmdlg(this);
00661 confirmdlg.setIcon(QMessageBox::Warning);
00662 confirmdlg.setWindowTitle(tr("Remove Plugin?"));
00663 confirmdlg.setText(tr("<qt>Are you sure you want to remove Plugin <i>%1</i>?</qt>").arg(klf_plugins[k].title));
00664 confirmdlg.setDetailedText(tr("The Plugin File %1 will be removed from disk.").arg(klf_plugins[k].fpath));
00665 confirmdlg.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
00666 confirmdlg.setEscapeButton(QMessageBox::Cancel);
00667 confirmdlg.setDefaultButton(QMessageBox::Cancel);
00668
00669 int confirmation = confirmdlg.exec();
00670 if (confirmation != QMessageBox::Yes) {
00671
00672 return;
00673 }
00674
00675 bool r = QFile::remove(klf_plugins[k].fpath);
00676
00677 if ( r ) {
00678 QMessageBox::information(this, tr("Remove Plugin"),
00679 tr("<p style=\"-qt-block-indent: 0; text-indent: 0px;\">Please note the following:<br />\n"
00680 "<ul><li>You need to restart KLatexFormula for changes to take effect\n"
00681 "<li>If this plugin was privided in an add-on, you need to remove the corresponding "
00682 "add-on too or the plugin will be automatically re-installed."
00683 "</p>"));
00684
00685 delete selectedItem;
00686 } else {
00687 qWarning("Failed to remove plugin '%s'", qPrintable(klf_plugins[k].fpath));
00688 QMessageBox::critical(this, tr("Error"), tr("Failed to remove Plugin."));
00689 }
00690
00691 refreshAddOnList();
00692 refreshAddOnSelected();
00693 }
00694
00695 void KLFSettings::removePlugin(const QString& fname)
00696 {
00697 int k;
00698 klfDbg("removing plugin "<<fname<<" from plugins. Dumping plugin list: ");
00699 for (k = 0; k < klf_plugins.size(); ++k) {
00700 klfDbg(" --> plugin: fname="<<klf_plugins[k].fname) ;
00701 }
00702
00703 for (k = 0; k < klf_plugins.size() && klf_plugins[k].fname != fname; ++k)
00704 ;
00705 if (k < 0 || k >= klf_plugins.size()) {
00706 qWarning("KLFSettings::removePlugin: internal error: didn't find plugin name %s", qPrintable(fname));
00707 return;
00708 }
00709
00710 bool r = QFile::remove(klf_plugins[k].fpath);
00711
00712 if ( r ) {
00713
00714 QTreeWidgetItemIterator it(u->lstPlugins);
00715 while (*it) {
00716 if ( (*it)->data(0, KLFSETTINGS_ROLE_PLUGINDEX).toInt() == k ) {
00717
00718 delete (*it);
00719 break;
00720 }
00721 ++it;
00722 }
00723 } else {
00724 qWarning("Failed to remove plugin '%s'", qPrintable(klf_plugins[k].fpath));
00725 QMessageBox::critical(this, tr("Error"), tr("Failed to remove Plugin %1.").arg(klf_plugins[k].title));
00726 }
00727 }
00728
00729
00730 bool KLFSettings::setDefaultFor(const QString& progname, const QString& guessedprog, bool required,
00731 KLFPathChooser *destination)
00732 {
00733 QString progpath = guessedprog;
00734 if (progpath.isEmpty()) {
00735 if (QFileInfo(destination->path()).isExecutable()) {
00736
00737 return true;
00738 }
00739 if ( ! required )
00740 return false;
00741 QMessageBox msgbox(QMessageBox::Critical, tr("Error"), tr("Could not find %1 executable !")
00742 .arg(progname), QMessageBox::Ok);
00743 msgbox.setInformativeText(tr("Please check your installation and specify the path"
00744 " to %1 executable manually if it is not installed"
00745 " in $PATH.").arg(progname));
00746 msgbox.setDefaultButton(QMessageBox::Ok);
00747 msgbox.setEscapeButton(QMessageBox::Ok);
00748 msgbox.exec();
00749 return false;
00750 }
00751
00752 destination->setPath(progpath);
00753 return true;
00754 }
00755
00756 void KLFSettings::setDefaultPaths()
00757 {
00758 KLFBackend::klfSettings defaultsettings;
00759 KLFBackend::detectSettings(&defaultsettings);
00760 if ( ! QFileInfo(u->pathTempDir->path()).isDir() )
00761 u->pathTempDir->setPath(QDir::toNativeSeparators(defaultsettings.tempdir));
00762 setDefaultFor("latex", defaultsettings.latexexec, true, u->pathLatex);
00763 setDefaultFor("dvips", defaultsettings.dvipsexec, true, u->pathDvips);
00764 setDefaultFor("gs", defaultsettings.gsexec, true, u->pathGs);
00765 bool r = setDefaultFor("epstopdf", defaultsettings.epstopdfexec, false, u->pathEpstopdf);
00766 u->chkEpstopdf->setChecked(r);
00767 }
00768
00769
00770 void KLFSettings::refreshAddOnList()
00771 {
00772 u->lstAddOns->clear();
00773 u->lstAddOns->setColumnWidth(0, 160);
00774
00775
00776 int k;
00777 for (k = 0; k < klf_addons.size(); ++k) {
00778 QTreeWidgetItem *item = new QTreeWidgetItem(u->lstAddOns);
00779 item->setData(0, KLFSETTINGS_ROLE_ADDONINDEX, QVariant((int)k));
00780
00781 item->setText(0, klf_addons[k].title());
00782 item->setText(1, klf_addons[k].description());
00783
00784
00785
00786 if (klf_addons[k].isfresh()) {
00787 item->setBackground(0, QColor(200, 255, 200));
00788 item->setBackground(1, QColor(200, 255, 200));
00789 }
00790
00791
00792
00793
00794 }
00795 }
00796
00797 void KLFSettings::refreshAddOnSelected()
00798 {
00799 QList<QTreeWidgetItem*> sel = u->lstAddOns->selectedItems();
00800 if (sel.size() != 1) {
00801 u->lblAddOnInfo->setText("");
00802 u->btnRemoveAddOn->setEnabled(false);
00803 return;
00804 }
00805 int k = sel[0]->data(0, KLFSETTINGS_ROLE_ADDONINDEX).toInt();
00806 if (k < 0 || k >= klf_addons.size()) {
00807 u->lblAddOnInfo->setText("");
00808 u->btnRemoveAddOn->setEnabled(false);
00809 return;
00810 }
00811
00812
00813 u->btnRemoveAddOn->setEnabled(klf_addons[k].islocal());
00814
00815 int smallpointsize = QFontInfo(font()).pointSize() - 1;
00816 u->lblAddOnInfo->setText(tr("<p style=\"-qt-block-indent: 0; text-indent: 0px; margin-bottom: 0px\">\n"
00817 "<tt>Name:</tt> <span style=\"font-weight:600;\">%1</span><br />\n"
00818 "<tt>Author:</tt> <span style=\"font-weight:600;\">%2</span><br />\n"
00819 "<tt>Description:</tt></p>\n"
00820 "<p style=\"font-weight: 600; margin-top: 2px; margin-left: 25px;"
00821 " margin-bottom: 0px;\">%3</p>\n"
00822 "<p style=\"-qt-block-indent: 0; text-indent: 0px; margin-top: 2px;\">\n"
00823 "<tt>File Name:</tt> <span style=\"font-size: %5pt;\">%4</span><br />\n"
00824 "<tt>File Location:</tt> <span style=\"font-size: %5pt;\">%6</span><br />\n"
00825 "<tt><i>%7</i></tt>").arg(Qt::escape(klf_addons[k].title()))
00826 .arg(Qt::escape(klf_addons[k].author())).arg(Qt::escape(klf_addons[k].description()))
00827 .arg(Qt::escape(klf_addons[k].fname()))
00828 .arg(smallpointsize)
00829 .arg(Qt::escape(QDir::toNativeSeparators(QFileInfo(klf_addons[k].dir())
00830 .canonicalFilePath()) + QDir::separator()))
00831 .arg( klf_addons[k].islocal() ?
00832 tr("Add-On installed locally") :
00833 tr("Add-On installed globally on system") )
00834 );
00835
00836 }
00837
00838
00839 void KLFSettings::importAddOn()
00840 {
00841 QStringList efnames =
00842 QFileDialog::getOpenFileNames(this, tr("Please select add-on file(s) to import"),
00843 QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation),
00844 "Qt Resource Files (*.rcc)");
00845 int i;
00846 for (i = 0; i < efnames.size(); ++i) {
00847 importAddOn(efnames[i], false);
00848 }
00849
00850 if (i > 0) {
00851 QMessageBox::information(this, tr("Import"), tr("Please restart KLatexFormula for changes to take effect."));
00852 }
00853 }
00854
00855 void KLFSettings::importAddOn(const QString& fileName, bool suggestRestart)
00856 {
00857 KLF_DEBUG_BLOCK(KLF_FUNC_NAME) ;
00858 klfDbg("fileName="<<fileName<<", suggestRestart="<<suggestRestart) ;
00859
00860 QFileInfo fi(fileName);
00861 if (!fi.exists() || !fi.isReadable()) {
00862 QMessageBox::critical(this, tr("Error"), tr("File %1 cannot be accessed.").arg(fileName));
00863 return;
00864 }
00865 QString destination = klfconfig.homeConfigDirRCCResources+"/";
00866 QString destfpath = destination + QFileInfo(fileName).fileName();
00867 if ( QFile::exists(destfpath) ) {
00868 QMessageBox::critical(this, tr("Error"),
00869 tr("An Add-On with the same file name has already been imported."));
00870 return;
00871 }
00872 bool r = QFile::copy(fileName, destfpath);
00873 if ( !r ) {
00874 QMessageBox::critical(this, tr("Error"), tr("Import of add-on file %1 failed.").arg(fileName));
00875 return;
00876 }
00877
00878
00879 KLFAddOnInfo addoninfo(destfpath, true);
00880 if (!addoninfo.klfminversion().isEmpty() &&
00881 klfVersionCompareLessThan(KLF_VERSION_STRING, addoninfo.klfminversion())) {
00882
00883 QMessageBox::critical(this, tr("Error"),
00884 tr("This add-on requires a more recent version of KLatexFormula.\n"
00885 "Required version: %1\n"
00886 "This version: %2").arg(addoninfo.klfminversion(), KLF_VERSION_STRING));
00887 return;
00888 }
00889
00890
00891 int k;
00892 QStringList trlist = addoninfo.translations();
00893 KLFI18nFile *detectedI18nFile = NULL;
00894 for (k = 0; k < trlist.size(); ++k) {
00895 KLFI18nFile i18nfile(addoninfo.rccmountroot()+"/i18n/"+trlist[k]);
00896 if ( u->cbxLocale->findData(i18nfile.locale) == -1 ) {
00897 klfDbg("found translation: "<<i18nfile.locale) ;
00898 klf_add_avail_translation(i18nfile);
00899 if (detectedI18nFile == NULL)
00900 detectedI18nFile = new KLFI18nFile(i18nfile);
00901 }
00902 }
00903 if (detectedI18nFile != NULL) {
00904 klfDbg("translation(s) found. first one found was: "<<detectedI18nFile->locale) ;
00905
00906 populateLocaleCombo();
00907
00908 for (k = 0; k < klf_avail_translations.size(); ++k) {
00909 if (klf_avail_translations[k].localename == detectedI18nFile->locale)
00910 break;
00911 }
00912 int cbxindex = u->cbxLocale->findData(detectedI18nFile->locale);
00913 if (k >= 0 && k < klf_avail_translations.size() && cbxindex >= 0) {
00914 if (QMessageBox::question(this, tr("Change Langugage"), tr("Change application language to <b>%1</b>?")
00915 .arg(klf_avail_translations[k].translatedname),
00916 QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes)
00917 == QMessageBox::Yes) {
00918 u->cbxLocale->setCurrentIndex(cbxindex);
00919 apply();
00920
00921 suggestRestart = false;
00922 }
00923 }
00924 delete detectedI18nFile;
00925 detectedI18nFile = NULL;
00926 }
00927 klf_addons.append(addoninfo);
00928 refreshAddOnList();
00929
00930 if (suggestRestart) {
00931 QMessageBox::information(this, tr("Import"), tr("Please restart KLatexFormula for changes to take effect."));
00932 }
00933 }
00934
00935 void KLFSettings::removeAddOn()
00936 {
00937 QList<QTreeWidgetItem*> sel = u->lstAddOns->selectedItems();
00938 if (sel.size() != 1) {
00939 qWarning("Expected single add-on selection for removal !");
00940 return;
00941 }
00942
00943 int k = sel[0]->data(0, KLFSETTINGS_ROLE_ADDONINDEX).toInt();
00944 if (k < 0 || k >= klf_addons.size()) {
00945
00946 return;
00947 }
00948
00949 QMessageBox confirmdlg(this);
00950 confirmdlg.setIcon(QMessageBox::Warning);
00951 confirmdlg.setWindowTitle(tr("Remove Add-On?"));
00952 confirmdlg.setText(tr("<qt>Are you sure you want to remove Add-On <i>%1</i>?</qt>")
00953 .arg(klf_addons[k].title()));
00954 QStringList ourplugins = klf_addons[k].localPluginList();
00955 QString msg;
00956 if (ourplugins.size()) {
00957 msg = tr("The Add-On File %1 will be removed from disk, along with plugin(s) %2.")
00958 .arg(klf_addons[k].fpath(), ourplugins.join(", "));
00959 } else {
00960 msg = tr("The Add-On File %1 will be removed from disk.").arg(klf_addons[k].fpath());
00961 }
00962 confirmdlg.setDetailedText(msg);
00963 confirmdlg.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
00964 confirmdlg.setEscapeButton(QMessageBox::Cancel);
00965 confirmdlg.setDefaultButton(QMessageBox::Cancel);
00966
00967 int confirmation = confirmdlg.exec();
00968 if (confirmation != QMessageBox::Yes) {
00969
00970 return;
00971 }
00972
00973 bool r = QFile::remove(klf_addons[k].fpath());
00974
00975 int j;
00976 if ( r ) {
00977 QMessageBox::information(this, tr("Remove Add-On"),
00978 tr("Please restart KLatexFormula for changes to take effect."));
00979 } else {
00980 qWarning("Failed to remove add-on '%s'", qPrintable(klf_addons[k].fpath()));
00981 QMessageBox::critical(this, tr("Error"), tr("Failed to remove Add-On."));
00982 return;
00983 }
00984
00985
00986 QStringList lplugins = klf_addons[k].localPluginList();
00987 for (j = 0; j < lplugins.size(); ++j)
00988 removePlugin(lplugins[j]);
00989
00990 klf_addons.removeAt(k);
00991
00992 refreshAddOnList();
00993 refreshAddOnSelected();
00994 }
00995
00996 void KLFSettings::slotChangeFontPresetSender()
00997 {
00998 QAction *a = qobject_cast<QAction*>(sender());
00999 if (a == 0)
01000 return;
01001 const QVariantMap vmap = a->data().toMap();
01002 klfDbg("Set font from action with data "<<vmap) ;
01003 QString btnkey = vmap["Button"].toString();
01004 KLF_ASSERT_CONDITION(pFontButtons.contains(btnkey), "Unknown button "<<btnkey<<" !", return ) ;
01005 QFont f = vmap["Font"].value<QFont>();
01006 slotChangeFont(pFontButtons[btnkey], f);
01007 if (vmap.contains("isSystemDefaultAppFont") && vmap["isSystemDefaultAppFont"].toBool()) {
01008 klfDbg("Set default application font.") ;
01009 pUserSetDefaultAppFont = true;
01010 }
01011 }
01012 void KLFSettings::slotChangeFontSender()
01013 {
01014 QPushButton *w = qobject_cast<QPushButton*>(sender());
01015 if ( w == 0 )
01016 return;
01017 QFont fnt = QFontDialog::getFont(0, w->property("selectedFont").value<QFont>(), this);
01018 slotChangeFont(w, fnt);
01019 }
01020 void KLFSettings::slotChangeFont(QPushButton *w, const QFont& fnt)
01021 {
01022 if ( w == 0 )
01023 return;
01024 w->setFont(fnt);
01025 w->setProperty("selectedFont", QVariant(fnt));
01026 if (w == u->btnAppFont)
01027 pUserSetDefaultAppFont = false;
01028 }
01029
01030 void KLFSettings::apply()
01031 {
01032 int k;
01033
01034
01035
01036 KLFBackend::klfSettings s = _mainwin->currentSettings();
01037
01038 s.tempdir = QDir::fromNativeSeparators(u->pathTempDir->path());
01039 s.latexexec = u->pathLatex->path();
01040 s.dvipsexec = u->pathDvips->path();
01041 s.gsexec = u->pathGs->path();
01042 s.epstopdfexec = QString();
01043 if (u->chkEpstopdf->isChecked()) {
01044 s.epstopdfexec = u->pathEpstopdf->path();
01045 }
01046
01047
01048 klf_detect_execenv(&s);
01049
01050 s.lborderoffset = u->spnLBorderOffset->value();
01051 s.tborderoffset = u->spnTBorderOffset->value();
01052 s.rborderoffset = u->spnRBorderOffset->value();
01053 s.bborderoffset = u->spnBBorderOffset->value();
01054 s.outlineFonts = u->chkOutlineFonts->isChecked();
01055
01056 _mainwin->applySettings(s);
01057
01058 if (u->chkSHEnable->isChecked())
01059 klfconfig.SyntaxHighlighter.configFlags |= KLFLatexSyntaxHighlighter::Enabled;
01060 else
01061 klfconfig.SyntaxHighlighter.configFlags &= ~KLFLatexSyntaxHighlighter::Enabled;
01062 if (u->chkSHHighlightParensOnly->isChecked())
01063 klfconfig.SyntaxHighlighter.configFlags |= KLFLatexSyntaxHighlighter::HighlightParensOnly;
01064 else
01065 klfconfig.SyntaxHighlighter.configFlags &= ~KLFLatexSyntaxHighlighter::HighlightParensOnly;
01066 if (u->chkSHHighlightLonelyParen->isChecked())
01067 klfconfig.SyntaxHighlighter.configFlags |= KLFLatexSyntaxHighlighter::HighlightLonelyParen;
01068 else
01069 klfconfig.SyntaxHighlighter.configFlags &= ~KLFLatexSyntaxHighlighter::HighlightLonelyParen;
01070
01071 for (k = 0; k < _textformats.size(); ++k) {
01072 QColor c = _textformats[k].fg->color();
01073 if (c.isValid())
01074 _textformats[k].fmt->setForeground(c);
01075 else
01076 _textformats[k].fmt->clearForeground();
01077 c = _textformats[k].bg->color();
01078 if (c.isValid())
01079 _textformats[k].fmt->setBackground(c);
01080 else
01081 _textformats[k].fmt->clearBackground();
01082 Qt::CheckState b = _textformats[k].chkB->checkState();
01083 if (b == Qt::PartiallyChecked)
01084 _textformats[k].fmt->clearProperty(QTextFormat::FontWeight);
01085 else if (b == Qt::Checked)
01086 _textformats[k].fmt->setFontWeight(QFont::Bold);
01087 else
01088 _textformats[k].fmt->setFontWeight(QFont::Normal);
01089 Qt::CheckState it = _textformats[k].chkI->checkState();
01090 if (it == Qt::PartiallyChecked)
01091 _textformats[k].fmt->clearProperty(QTextFormat::FontItalic);
01092 else
01093 _textformats[k].fmt->setFontItalic( it == Qt::Checked );
01094 }
01095
01096
01097 QString localename = u->cbxLocale->itemData(u->cbxLocale->currentIndex()).toString();
01098 klfDbg("New locale name: "<<localename);
01099 bool localechanged = false;
01100 if (klfconfig.UI.locale != localename) {
01101 if ((!klfconfig.UI.locale.isEmpty() && klfconfig.UI.locale != "C" && klfconfig.UI.locale != "en_US") ||
01102 (!localename.isEmpty() && localename != "C" && localename != "en_US"))
01103 localechanged = true;
01104 }
01105 klfconfig.UI.locale = localename;
01106 QLocale::setDefault(klfconfig.UI.locale);
01107 _mainwin->setApplicationLocale(localename);
01108 if (localechanged) {
01109 QMessageBox::information(this, tr("Language changed"),
01110 tr("You may need to restart KLatexFormula for your new language "
01111 "settings to fully take effect."));
01112 }
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123 QFont curAppFont = klfconfig.UI.applicationFont;
01124 QFont newAppFont = u->btnAppFont->property("selectedFont").value<QFont>();
01125 if (curAppFont != newAppFont || pUserSetDefaultAppFont != klfconfig.UI.useSystemAppFont) {
01126 klfconfig.UI.useSystemAppFont = pUserSetDefaultAppFont;
01127 klfconfig.UI.applicationFont = newAppFont;
01128 if (klfconfig.UI.useSystemAppFont) {
01129 qApp->setFont(klfconfig.defaultStdFont);
01130 qApp->setFont(QFont());
01131 } else {
01132 qApp->setFont(klfconfig.UI.applicationFont);
01133 }
01134
01135 qApp->setStyleSheet(qApp->styleSheet());
01136 _mainwin->refreshAllWindowStyleSheets();
01137 }
01138 klfconfig.UI.latexEditFont = u->btnEditorFont->property("selectedFont").value<QFont>();
01139 _mainwin->setTxtLatexFont(klfconfig.UI.latexEditFont);
01140 klfconfig.UI.preambleEditFont = u->btnPreambleFont->property("selectedFont").value<QFont>();
01141 _mainwin->setTxtPreambleFont(klfconfig.UI.preambleEditFont);
01142
01143 klfconfig.UI.labelOutputFixedSize = QSize(u->spnPreviewWidth->value(), u->spnPreviewHeight->value());
01144 klfconfig.UI.enableRealTimePreview = u->chkEnableRealTimePreview->isChecked();
01145
01146 klfconfig.UI.previewTooltipMaxSize = QSize(u->spnToolTipMaxWidth->value(), u->spnToolTipMaxHeight->value());
01147 klfconfig.UI.enableToolTipPreview = u->chkEnableToolTipPreview->isChecked();
01148
01149 klfconfig.UI.showHintPopups = u->chkShowHintPopups->isChecked();
01150 klfconfig.UI.clearLatexOnly = u->chkClearLatexOnly->isChecked();
01151 klfconfig.UI.glowEffect = u->chkGlowEffect->isChecked();
01152
01153 klfconfig.UI.copyExportProfile =
01154 u->cbxCopyExportProfile->itemData(u->cbxCopyExportProfile->currentIndex()).toString();
01155 klfconfig.UI.dragExportProfile =
01156 u->cbxDragExportProfile->itemData(u->cbxDragExportProfile->currentIndex()).toString();
01157
01158 klfconfig.UI.menuExportProfileAffectsDrag = u->chkMenuExportProfileAffectsDrag->isChecked();
01159 klfconfig.UI.menuExportProfileAffectsCopy = u->chkMenuExportProfileAffectsCopy->isChecked();
01160
01161 klfconfig.LibraryBrowser.restoreURLs = u->chkLibRestoreURLs->isChecked();
01162 klfconfig.LibraryBrowser.confirmClose = u->chkLibConfirmClose->isChecked();
01163 klfconfig.LibraryBrowser.historyTagCopyToArchive = u->chkLibHistoryTagCopyToArchive->isChecked();
01164
01165 klfconfig.LibraryBrowser.iconViewFlow = u->cbxLibIconViewFlow->selectedValue();
01166
01167
01168 bool warnneedrestart = false;
01169 QTreeWidgetItemIterator it(u->lstPlugins);
01170 while (*it) {
01171 int j = (*it)->data(0, KLFSETTINGS_ROLE_PLUGINDEX).toInt();
01172 QString name = (*it)->data(0, KLFSETTINGS_ROLE_PLUGNAME).toString();
01173 bool loadenable = ( (*it)->checkState(0) == Qt::Checked ) ;
01174 if (loadenable != klfconfig.Plugins.pluginConfig[name]["__loadenabled"])
01175 warnneedrestart = true;
01176 klfconfig.Plugins.pluginConfig[name]["__loadenabled"] = loadenable;
01177
01178 if (klf_plugins[j].instance != NULL) {
01179 KLFPluginConfigAccess pconfa = klfconfig.getPluginConfigAccess(name);
01180 klf_plugins[j].instance->saveToConfig(mPluginConfigWidgets[name], &pconfa);
01181 }
01182
01183 ++it;
01184 }
01185 if (warnneedrestart) {
01186 QMessageBox::information(this, tr("Restart KLatexFormula"),
01187 tr("You need to restart KLatexFormula for your changes to take effect."));
01188 }
01189
01190 _mainwin->refreshShowCorrectClearButton();
01191 _mainwin->saveSettings();
01192
01193
01194 _mainwin->refreshWindowSizes();
01195
01196
01197
01198 reset();
01199 }
01200
01201 void KLFSettings::accept()
01202 {
01203
01204 apply();
01205
01206 QDialog::accept();
01207 }
01208
01209 void KLFSettings::help()
01210 {
01211 QWhatsThis::enterWhatsThisMode();
01212 }
01213
01214
01215
01216