*
* \author John Levon
*
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "support/lstrings.h"
-#include "Lsstream.h"
+#include "support/tostr.h"
+#include "support/std_sstream.h"
#include <iomanip>
#include "ControlPrefs.h"
#include "ui/QPrefDisplayModule.h"
#include "ui/QPrefPathsModule.h"
#include "ui/QPrefSpellcheckerModule.h"
-#include "ui/QPrefConvertersModule.h"
-#include "ui/QPrefFileformatsModule.h"
#include "ui/QPrefLanguageModule.h"
#include "ui/QPrefPrinterModule.h"
#include "ui/QPrefUIModule.h"
+#include "ui/QPrefIdentityModule.h"
+#include "lyx_gui.h"
#include "QPrefs.h"
#include "Qt2BC.h"
-#include "lyxrc.h"
+#include "lyxfont.h"
#include "frnt_lang.h"
#include "helper_funcs.h"
#include "qt_helpers.h"
-#include "debug.h"
+#include "lcolorcache.h"
#include <boost/tuple/tuple.hpp>
#include <qlineedit.h>
#include <qspinbox.h>
#include <qcombobox.h>
-#include <qlistbox.h>
#include <qlabel.h>
#include "qcoloritem.h"
+using namespace lyx::support;
+
using std::vector;
using std::pair;
using std::ostringstream;
using std::setw;
using std::endl;
+
typedef Qt2CB<ControlPrefs, Qt2DB<QPrefsDialog> > base_class;
QPrefs::QPrefs()
- : base_class(qt_("LyX: Preferences"))
+ : base_class(_("LyX: Preferences"))
{
}
{
dialog_.reset(new QPrefsDialog(this));
- bc().setOK(dialog_->savePB);
- bc().setApply(dialog_->applyPB);
- bc().setCancel(dialog_->closePB);
- bc().setRestore(dialog_->restorePB);
+ bcview().setOK(dialog_->savePB);
+ bcview().setApply(dialog_->applyPB);
+ bcview().setCancel(dialog_->closePB);
+ bcview().setRestore(dialog_->restorePB);
QPrefLanguageModule * langmod(dialog_->languageModule);
for (; lit != lend; ++lit) {
langmod->defaultLanguageCO->insertItem(toqstr(lit->first));
}
+
+ QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
+ spellmod->spellCommandCO->insertItem(qt_("ispell"));
+ spellmod->spellCommandCO->insertItem(qt_("aspell"));
+ spellmod->spellCommandCO->insertItem(qt_("hspell"));
+#ifdef USE_PSPELL
+ spellmod->spellCommandCO->insertItem(qt_("pspell (library)"));
+#else
+#ifdef USE_ASPELL
+ spellmod->spellCommandCO->insertItem(qt_("aspell (library)"));
+#endif
+#endif
}
rc.auto_reset_options = latexmod->latexAutoresetCB->isChecked();
rc.view_dvi_paper_option = fromqstr(latexmod->latexDviPaperED->text());
rc.default_papersize =
- static_cast<BufferParams::PAPER_SIZE>(latexmod->latexPaperSizeCO->currentItem());
-
+ static_cast<PAPER_SIZE>(latexmod->latexPaperSizeCO->currentItem());
QPrefDisplayModule * displaymod(dialog_->displayModule);
rc.preview = displaymod->previewCB->isChecked();
- grfx::DisplayType dtype(grfx::ColorDisplay);
+ lyx::graphics::DisplayType dtype(lyx::graphics::ColorDisplay);
switch (displaymod->displayGraphicsCO->currentItem()) {
- case 3: dtype = grfx::NoDisplay; break;
- case 2: dtype = grfx::ColorDisplay; break;
- case 1: dtype = grfx::GrayscaleDisplay; break;
- case 0: dtype = grfx::MonochromeDisplay; break;
+ case 3: dtype = lyx::graphics::NoDisplay; break;
+ case 2: dtype = lyx::graphics::ColorDisplay; break;
+ case 1: dtype = lyx::graphics::GrayscaleDisplay; break;
+ case 0: dtype = lyx::graphics::MonochromeDisplay; break;
}
rc.display_graphics = dtype;
#endif
#if 0
if (old_value != rc.display_graphics) {
- grfx::GCache & gc = grfx::GCache::get();
+ lyx::graphics::GCache & gc = lyx::graphics::GCache::get();
gc.changeDisplay();
}
#endif
QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
- if (spellmod->spellCommandCO->currentItem() == 0)
- rc.isp_command = "ispell";
- else
- rc.isp_command = "aspell";
+ switch (spellmod->spellCommandCO->currentItem()) {
+ case 0:
+ case 1:
+ case 2:
+ rc.use_spell_lib = false;
+ rc.isp_command = fromqstr(spellmod->spellCommandCO->currentText());
+ break;
+ case 3:
+ rc.use_spell_lib = true;
+ break;
+ }
// FIXME: remove isp_use_alt_lang
rc.isp_alt_lang = fromqstr(spellmod->altLanguageED->text());
rc.print_reverse_flag = fromqstr(printmod->printerReverseED->text());
rc.print_to_printer = fromqstr(printmod->printerToPrinterED->text());
rc.print_file_extension = fromqstr(printmod->printerExtensionED->text());
- rc.print_file_extension = fromqstr(printmod->printerSpoolCommandED->text());
+ rc.print_spool_command = fromqstr(printmod->printerSpoolCommandED->text());
rc.print_paper_flag = fromqstr(printmod->printerPaperTypeED->text());
rc.print_evenpage_flag = fromqstr(printmod->printerEvenED->text());
rc.print_oddpage_flag = fromqstr(printmod->printerOddED->text());
rc.print_paper_dimension_flag = fromqstr(printmod->printerPaperSizeED->text());
+ QPrefIdentityModule * idmod(dialog_->identityModule);
+ rc.user_name = fromqstr(idmod->nameED->text());
+ rc.user_email = fromqstr(idmod->emailED->text());
+
QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
LyXRC const oldrc(rc);
QListBoxItem * ib(colmod->lyxObjectsLB->item(i));
QColorItem * ci(static_cast<QColorItem*>(ib));
- ostringstream ostr;
-
- ostr << '#' << std::setbase(16) << setfill('0')
- << setw(2) << ci->color().red()
- << setw(2) << ci->color().green()
- << setw(2) << ci->color().blue();
+ LColor::color const col(dialog_->colors_[i]);
+ QColor const & qcol(lcolorcache.get(col));
- string newhex(STRCONV(ostr.str()));
+ // FIXME: dubious, but it's what xforms does
+ if (qcol != ci->color()) {
+ ostringstream ostr;
- LColor::color col(dialog_->colors_[i]);
+ ostr << '#' << std::setbase(16) << setfill('0')
+ << setw(2) << ci->color().red()
+ << setw(2) << ci->color().green()
+ << setw(2) << ci->color().blue();
- // FIXME: dubious, but it's what xforms does
- if (lcolor.getX11Name(col) != newhex) {
+ string newhex(STRCONV(ostr.str()));
controller().setColor(col, newhex);
}
}
return std::distance(vec.begin(), it);
}
-void setComboxFont(QComboBox * cb, string const & family,
- string const & foundry, QFont::StyleHint hint)
+void setComboxFont(QComboBox * cb, string const & family, string const & foundry)
{
string const name = makeFontName(family, foundry);
for (int i = 0; i < cb->count(); ++i) {
}
}
- // Try matching without foundary name
+ // Try matching without foundry name
// We count in reverse in order to prefer the Xft foundry
for (int i = cb->count() - 1; i >= 0; --i) {
}
}
- // Try the hint
- QFont font;
- font.setStyleHint(hint);
- QFontInfo fi(font);
+ // family alone can contain e.g. "Helvetica [Adobe]"
+ pair<string, string> tmpfam = parseFontName(family);
+ // We count in reverse in order to prefer the Xft foundry
for (int i = cb->count() - 1; i >= 0; --i) {
- if (cb->text(i) == fi.family()) {
+ pair<string, string> tmp = parseFontName(fromqstr(cb->text(i)));
+ if (compare_no_case(tmp.first, tmpfam.first) == 0) {
+ cb->setCurrentItem(i);
+ return;
+ }
+ }
+
+ // Bleh, default fonts, and the names couldn't be found. Hack
+ // for bug 1063. Qt makes baby Jesus cry.
+
+ QFont font;
+
+ if (family == lyx_gui::roman_font_name()) {
+ font.setStyleHint(QFont::Serif);
+ font.setFamily(lyx_gui::roman_font_name().c_str());
+ } else if (family == lyx_gui::sans_font_name()) {
+ font.setStyleHint(QFont::SansSerif);
+ font.setFamily(lyx_gui::sans_font_name().c_str());
+ } else if (family == lyx_gui::typewriter_font_name()) {
+ font.setStyleHint(QFont::TypeWriter);
+ font.setFamily(lyx_gui::typewriter_font_name().c_str());
+ } else {
+ lyxerr << "FAILED to find the default font !"
+ << foundry << ", " << family << endl;
+ return;
+ }
+
+ QFontInfo info(font);
+ lyxerr << "Apparent font is " << info.family() << endl;
+
+ for (int i = 0; i < cb->count(); ++i) {
+ lyxerr << "Looking at " << fromqstr(cb->text(i)) << endl;
+ if (compare_no_case(cb->text(i).latin1(), info.family().latin1()) == 0) {
cb->setCurrentItem(i);
return;
}
}
-}
+ lyxerr << "FAILED to find the font !"
+ << foundry << ", " << family << endl;
}
+} // end namespace anon
+
+
void QPrefs::update_contents()
{
LyXRC const & rc(controller().rc());
uimod->lastfilesSB->setValue(rc.num_lastfiles);
+ QPrefIdentityModule * idmod(dialog_->identityModule);
+ idmod->nameED->setText(toqstr(rc.user_name));
+ idmod->emailED->setText(toqstr(rc.user_email));
+
+
QPrefKeyboardModule * keymod(dialog_->keyboardModule);
// FIXME: can derive CB from the two EDs
int item = 2;
switch (rc.display_graphics) {
- case grfx::NoDisplay: item = 3; break;
- case grfx::ColorDisplay: item = 2; break;
- case grfx::GrayscaleDisplay: item = 1; break;
- case grfx::MonochromeDisplay: item = 0; break;
+ case lyx::graphics::NoDisplay: item = 3; break;
+ case lyx::graphics::ColorDisplay: item = 2; break;
+ case lyx::graphics::GrayscaleDisplay: item = 1; break;
+ case lyx::graphics::MonochromeDisplay: item = 0; break;
default: break;
}
displaymod->displayGraphicsCO->setCurrentItem(item);
QPrefSpellcheckerModule * spellmod(dialog_->spellcheckerModule);
- item = (rc.isp_command == "ispell") ? 0 : 1;
- spellmod->spellCommandCO->setCurrentItem(item);
+ spellmod->spellCommandCO->setCurrentItem(0);
+
+ if (rc.isp_command == "ispell") {
+ spellmod->spellCommandCO->setCurrentItem(0);
+ } else if (rc.isp_command == "aspell") {
+ spellmod->spellCommandCO->setCurrentItem(1);
+ } else if (rc.isp_command == "hspell") {
+ spellmod->spellCommandCO->setCurrentItem(2);
+ }
+
+ if (rc.use_spell_lib) {
+#if defined(USE_ASPELL) || defined(USE_PSPELL)
+ spellmod->spellCommandCO->setCurrentItem(3);
+#endif
+ }
+
// FIXME: remove isp_use_alt_lang
spellmod->altLanguageED->setText(toqstr(rc.isp_alt_lang));
// FIXME: remove isp_use_esc_chars
printmod->printerReverseED->setText(toqstr(rc.print_reverse_flag));
printmod->printerToPrinterED->setText(toqstr(rc.print_to_printer));
printmod->printerExtensionED->setText(toqstr(rc.print_file_extension));
- printmod->printerSpoolCommandED->setText(toqstr(rc.print_file_extension));
+ printmod->printerSpoolCommandED->setText(toqstr(rc.print_spool_command));
printmod->printerPaperTypeED->setText(toqstr(rc.print_paper_flag));
printmod->printerEvenED->setText(toqstr(rc.print_evenpage_flag));
printmod->printerOddED->setText(toqstr(rc.print_oddpage_flag));
QPrefScreenFontsModule * fontmod(dialog_->screenfontsModule);
setComboxFont(fontmod->screenRomanCO, rc.roman_font_name,
- rc.roman_font_foundry, QFont::Serif);
+ rc.roman_font_foundry);
setComboxFont(fontmod->screenSansCO, rc.sans_font_name,
- rc.sans_font_foundry, QFont::SansSerif);
+ rc.sans_font_foundry);
setComboxFont(fontmod->screenTypewriterCO, rc.typewriter_font_name,
- rc.typewriter_font_foundry, QFont::TypeWriter);
+ rc.typewriter_font_foundry);
dialog_->select_roman(fontmod->screenRomanCO->currentText());
dialog_->select_sans(fontmod->screenSansCO->currentText());