]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
QDialogButtonBox for the remaining dialogs.
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 36f9fa4c06457b4510e8d2edddc314384bde458b..d60385b041dd98d5bda834874fb4264347b5851a 100644 (file)
 #include "insets/InsetListingsParams.h"
 
 #include "support/debug.h"
+#include "support/docstream.h"
 #include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
 #include "support/lstrings.h"
+#include "support/TempFile.h"
 
 #include "frontends/alert.h"
 
 #include <QAbstractItemModel>
-#include <QHeaderView>
+#include <QButtonGroup>
 #include <QColor>
 #include <QColorDialog>
 #include <QCloseEvent>
 #include <QFontDatabase>
+#include <QHeaderView>
 #include <QScrollBar>
 #include <QTextBoundaryFinder>
 #include <QTextCursor>
@@ -469,6 +472,34 @@ PreambleModule::PreambleModule(QWidget * parent)
        preambleTE->setWordWrapMode(QTextOption::NoWrap);
        setFocusProxy(preambleTE);
        connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
+       connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
+       connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
+       connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
+       connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
+       checkFindButton();
+       // https://stackoverflow.com/questions/13027091/how-to-override-tab-width-in-qt
+       const int tabStop = 4;
+       QFontMetrics metrics(preambleTE->currentFont());
+       preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
+}
+
+
+void PreambleModule::checkFindButton()
+{
+       findButtonPB->setEnabled(!findLE->text().isEmpty());
+}
+
+
+void PreambleModule::findText()
+{
+       bool const found = preambleTE->find(findLE->text());
+       if (!found) {
+               // wrap
+               QTextCursor qtcur = preambleTE->textCursor();
+               qtcur.movePosition(QTextCursor::Start);
+               preambleTE->setTextCursor(qtcur);
+               preambleTE->find(findLE->text());
+       }
 }
 
 
@@ -518,6 +549,36 @@ void PreambleModule::closeEvent(QCloseEvent * e)
 }
 
 
+void PreambleModule::editExternal() {
+       if (!current_id_)
+               return;
+
+       if (tempfile_) {
+               preambleTE->setReadOnly(false);
+               FileName const tempfilename = tempfile_->name();
+               docstring const s = tempfilename.fileContents("UTF-8");
+               preambleTE->document()->setPlainText(toqstr(s));
+               tempfile_.reset();
+               editPB->setText(qt_("Edit"));
+               changed();
+               return;
+       }
+
+       string const format =
+               current_id_->params().documentClass().outputFormat();
+       string const ext = theFormats().extension(format);
+       tempfile_.reset(new TempFile("preamble_editXXXXXX." + ext));
+       FileName const tempfilename = tempfile_->name();
+       string const name = tempfilename.toFilesystemEncoding();
+       ofdocstream os(name.c_str());
+       os << qstring_to_ucs4(preambleTE->document()->toPlainText());
+       os.close();
+       preambleTE->setReadOnly(true);
+       theFormats().edit(*current_id_, tempfilename, format);
+       editPB->setText(qt_("End Edit"));
+       changed();
+}
+
 /////////////////////////////////////////////////////////////////////
 //
 // LocalLayout
@@ -528,9 +589,12 @@ void PreambleModule::closeEvent(QCloseEvent * e)
 LocalLayout::LocalLayout(QWidget * parent)
        : UiWidget<Ui::LocalLayoutUi>(parent), current_id_(0), validated_(false)
 {
+       locallayoutTE->setFont(guiApp->typewriterSystemFont());
+       locallayoutTE->setWordWrapMode(QTextOption::NoWrap);
        connect(locallayoutTE, SIGNAL(textChanged()), this, SLOT(textChanged()));
        connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
        connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
+       connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
 }
 
 
@@ -655,6 +719,38 @@ void LocalLayout::validatePressed() {
 }
 
 
+void LocalLayout::editExternal() {
+       if (!current_id_)
+               return;
+
+       if (tempfile_) {
+               locallayoutTE->setReadOnly(false);
+               FileName const tempfilename = tempfile_->name();
+               docstring const s = tempfilename.fileContents("UTF-8");
+               locallayoutTE->document()->setPlainText(toqstr(s));
+               tempfile_.reset();
+               editPB->setText(qt_("Edit"));
+               changed();
+               return;
+       }
+
+       string const format =
+               current_id_->params().documentClass().outputFormat();
+       string const ext = theFormats().extension(format);
+       tempfile_.reset(new TempFile("preamble_editXXXXXX." + ext));
+       FileName const tempfilename = tempfile_->name();
+       string const name = tempfilename.toFilesystemEncoding();
+       ofdocstream os(name.c_str());
+       os << qstring_to_ucs4(locallayoutTE->document()->toPlainText());
+       os.close();
+       locallayoutTE->setReadOnly(true);
+       theFormats().edit(*current_id_, tempfilename, format);
+       editPB->setText(qt_("End Edit"));
+       validatePB->setEnabled(false);
+       hideConvert();
+       changed();
+}
+
 /////////////////////////////////////////////////////////////////////
 //
 // DocumentDialog
@@ -669,20 +765,18 @@ GuiDocument::GuiDocument(GuiView & lv)
 {
        setupUi(this);
 
-       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
-       connect(restorePB, SIGNAL(clicked()), this, SLOT(slotRestore()));
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
 
        connect(savePB, SIGNAL(clicked()), this, SLOT(saveDefaultClicked()));
        connect(defaultPB, SIGNAL(clicked()), this, SLOT(useDefaultsClicked()));
 
        // Manage the restore, ok, apply, restore and cancel/close buttons
        bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
-       bc().setOK(okPB);
-       bc().setApply(applyPB);
-       bc().setCancel(closePB);
-       bc().setRestore(restorePB);
+       bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
+       bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
+       bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
+       bc().setRestore(buttonBox->button(QDialogButtonBox::Reset));
 
 
        // text layout
@@ -811,6 +905,62 @@ GuiDocument::GuiDocument(GuiView & lv)
        connect(outputModule->saveTransientPropertiesCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
 
+
+       // language & quote
+       // this must preceed font, since fonts depend on this
+       langModule = new UiWidget<Ui::LanguageUi>(this);
+       connect(langModule->languageCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->languageCO, SIGNAL(activated(int)),
+               this, SLOT(languageChanged(int)));
+       connect(langModule->defaultencodingRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(langModule->otherencodingRB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(langModule->encodingCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->languagePackageCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
+               this, SLOT(change_adaptor()));
+       connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
+               this, SLOT(languagePackageChanged(int)));
+       connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+
+       langModule->languagePackageLE->setValidator(new NoNewLineValidator(
+               langModule->languagePackageLE));
+
+       QAbstractItemModel * language_model = guiApp->languageModel();
+       // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
+       language_model->sort(0);
+       langModule->languageCO->setModel(language_model);
+       langModule->languageCO->setModelColumn(0);
+
+       // Always put the default encoding in the first position.
+       langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
+       QStringList encodinglist;
+       for (auto const & encvar : encodings) {
+               if (!encvar.unsafe() && !encvar.guiName().empty())
+                       encodinglist.append(qt_(encvar.guiName()));
+       }
+       encodinglist.sort();
+       langModule->encodingCO->addItems(encodinglist);
+
+       langModule->languagePackageCO->addItem(
+               qt_("Default"), toqstr("default"));
+       langModule->languagePackageCO->addItem(
+               qt_("Automatic"), toqstr("auto"));
+       langModule->languagePackageCO->addItem(
+               qt_("Always Babel"), toqstr("babel"));
+       langModule->languagePackageCO->addItem(
+               qt_("Custom"), toqstr("custom"));
+       langModule->languagePackageCO->addItem(
+               qt_("None[[language package]]"), toqstr("none"));
+
+
        // fonts
        fontModule = new FontModule(this);
        connect(fontModule->osFontsCB, SIGNAL(clicked()),
@@ -874,9 +1024,9 @@ GuiDocument::GuiDocument(GuiView & lv)
        fontModule->fontsizeCO->addItem(qt_("11"));
        fontModule->fontsizeCO->addItem(qt_("12"));
 
-       fontModule->fontencCO->addItem(qt_("Default"), QString("global"));
+       fontModule->fontencCO->addItem(qt_("Automatic"), QString("auto"));
+       fontModule->fontencCO->addItem(qt_("Class Default"), QString("default"));
        fontModule->fontencCO->addItem(qt_("Custom"), QString("custom"));
-       fontModule->fontencCO->addItem(qt_("None (no fontenc)"), QString("default"));
 
        for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
                fontModule->fontsDefaultCO->addItem(
@@ -1041,62 +1191,6 @@ GuiDocument::GuiDocument(GuiView & lv)
                marginsModule->columnsepL);
 
 
-       // language & quote
-       langModule = new UiWidget<Ui::LanguageUi>(this);
-       connect(langModule->languageCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->languageCO, SIGNAL(activated(int)),
-               this, SLOT(languageChanged(int)));
-       connect(langModule->defaultencodingRB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(langModule->otherencodingRB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(langModule->encodingCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->quoteStyleCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->languagePackageCO, SIGNAL(activated(int)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->languagePackageLE, SIGNAL(textChanged(QString)),
-               this, SLOT(change_adaptor()));
-       connect(langModule->languagePackageCO, SIGNAL(currentIndexChanged(int)),
-               this, SLOT(languagePackageChanged(int)));
-       connect(langModule->dynamicQuotesCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-
-       langModule->languagePackageLE->setValidator(new NoNewLineValidator(
-               langModule->languagePackageLE));
-
-       QAbstractItemModel * language_model = guiApp->languageModel();
-       // FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
-       language_model->sort(0);
-       langModule->languageCO->setModel(language_model);
-       langModule->languageCO->setModelColumn(0);
-
-       // Always put the default encoding in the first position.
-       langModule->encodingCO->addItem(qt_("Language Default (no inputenc)"));
-       QStringList encodinglist;
-       Encodings::const_iterator it = encodings.begin();
-       Encodings::const_iterator const end = encodings.end();
-       for (auto const & encvar : encodings) {
-               if (!encvar.unsafe() && !encvar.guiName().empty())
-                       encodinglist.append(qt_(encvar.guiName()));
-       }
-       encodinglist.sort();
-       langModule->encodingCO->addItems(encodinglist);
-
-       langModule->languagePackageCO->addItem(
-               qt_("Default"), toqstr("default"));
-       langModule->languagePackageCO->addItem(
-               qt_("Automatic"), toqstr("auto"));
-       langModule->languagePackageCO->addItem(
-               qt_("Always Babel"), toqstr("babel"));
-       langModule->languagePackageCO->addItem(
-               qt_("Custom"), toqstr("custom"));
-       langModule->languagePackageCO->addItem(
-               qt_("None[[language package]]"), toqstr("none"));
-
-
        // color
        colorModule = new UiWidget<Ui::ColorUi>(this);
        connect(colorModule->fontColorPB, SIGNAL(clicked()),
@@ -1157,10 +1251,14 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(updateResetDefaultBiblio()));
        connect(biblioModule->biblatexBbxCO, SIGNAL(activated(int)),
                this, SLOT(biblioChanged()));
+       connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
+               this, SLOT(biblioChanged()));
        connect(biblioModule->biblatexBbxCO, SIGNAL(editTextChanged(QString)),
                this, SLOT(updateResetDefaultBiblio()));
        connect(biblioModule->biblatexCbxCO, SIGNAL(activated(int)),
                this, SLOT(biblioChanged()));
+       connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
+               this, SLOT(biblioChanged()));
        connect(biblioModule->biblatexCbxCO, SIGNAL(editTextChanged(QString)),
                this, SLOT(updateResetDefaultBiblio()));
        connect(biblioModule->rescanBibliosPB, SIGNAL(clicked()),
@@ -1210,7 +1308,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        headers << qt_("Package") << qt_("Load automatically")
                << qt_("Load always") << qt_("Do not load");
        mathsModule->packagesTW->setHorizontalHeaderLabels(headers);
-       setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::ResizeToContents);
+       setSectionResizeMode(mathsModule->packagesTW->horizontalHeader(), QHeaderView::Stretch);
        map<string, string> const & packages = BufferParams::auto_packages();
        mathsModule->packagesTW->setRowCount(packages.size());
        int packnum = 0;
@@ -1243,15 +1341,34 @@ GuiDocument::GuiDocument(GuiView & lv)
                autoRB->setToolTip(autoTooltip);
                alwaysRB->setToolTip(alwaysTooltip);
                neverRB->setToolTip(neverTooltip);
+
+               // Pack the buttons in a layout in order to get proper alignment
+               QWidget * autoRBWidget = new QWidget();
+               QHBoxLayout * autoRBLayout = new QHBoxLayout(autoRBWidget);
+               autoRBLayout->addWidget(autoRB);
+               autoRBLayout->setAlignment(Qt::AlignCenter);
+               autoRBLayout->setContentsMargins(0, 0, 0, 0);
+               autoRBWidget->setLayout(autoRBLayout);
+
+               QWidget * alwaysRBWidget = new QWidget();
+               QHBoxLayout * alwaysRBLayout = new QHBoxLayout(alwaysRBWidget);
+               alwaysRBLayout->addWidget(alwaysRB);
+               alwaysRBLayout->setAlignment(Qt::AlignCenter);
+               alwaysRBLayout->setContentsMargins(0, 0, 0, 0);
+               alwaysRBWidget->setLayout(alwaysRBLayout);
+
+               QWidget * neverRBWidget = new QWidget();
+               QHBoxLayout * neverRBLayout = new QHBoxLayout(neverRBWidget);
+               neverRBLayout->addWidget(neverRB);
+               neverRBLayout->setAlignment(Qt::AlignCenter);
+               neverRBLayout->setContentsMargins(0, 0, 0, 0);
+               neverRBWidget->setLayout(neverRBLayout);
+
                QTableWidgetItem * pack = new QTableWidgetItem(toqstr(package));
                mathsModule->packagesTW->setItem(packnum, 0, pack);
-               mathsModule->packagesTW->setCellWidget(packnum, 1, autoRB);
-               mathsModule->packagesTW->setCellWidget(packnum, 2, alwaysRB);
-               mathsModule->packagesTW->setCellWidget(packnum, 3, neverRB);
-               //center the radio buttons
-               autoRB->setStyleSheet("margin-left:50%; margin-right:50%;");
-               alwaysRB->setStyleSheet("margin-left:50%; margin-right:50%;");
-               neverRB->setStyleSheet("margin-left:50%; margin-right:50%;");
+               mathsModule->packagesTW->setCellWidget(packnum, 1, autoRBWidget);
+               mathsModule->packagesTW->setCellWidget(packnum, 2, alwaysRBWidget);
+               mathsModule->packagesTW->setCellWidget(packnum, 3, neverRBWidget);
 
                connect(autoRB, SIGNAL(clicked()),
                        this, SLOT(change_adaptor()));
@@ -1503,7 +1620,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        docPS->addPanel(indicesModule, N_("Indexes"));
        docPS->addPanel(pdfSupportModule, N_("PDF Properties"));
        docPS->addPanel(mathsModule, N_("Math Options"));
-       docPS->addPanel(floatModule, N_("Float Placement"));
+       docPS->addPanel(floatModule, N_("Float Settings"));
        docPS->addPanel(listingsModule, N_("Listings[[inset]]"));
        docPS->addPanel(bulletsModule, N_("Bullets"));
        docPS->addPanel(branchesModule, N_("Branches"));
@@ -1573,6 +1690,28 @@ void GuiDocument::slotOK()
 }
 
 
+void GuiDocument::slotButtonBox(QAbstractButton * button)
+{
+       switch (buttonBox->standardButton(button)) {
+       case QDialogButtonBox::Ok:
+               slotOK();
+               break;
+       case QDialogButtonBox::Apply:
+               slotApply();
+               break;
+       case QDialogButtonBox::Cancel:
+               slotClose();
+               break;
+       case QDialogButtonBox::Reset:
+       case QDialogButtonBox::RestoreDefaults:
+               slotRestore();
+               break;
+       default:
+               break;
+       }
+}
+
+
 void GuiDocument::includeonlyClicked(QTreeWidgetItem * item, int)
 {
        if (item == 0)
@@ -2100,8 +2239,13 @@ bool GuiDocument::ot1() const
 {
        QString const fontenc =
                fontModule->fontencCO->itemData(fontModule->fontencCO->currentIndex()).toString();
+       int const i = langModule->languageCO->currentIndex();
+       if (i == -1)
+               return false;
+       QString const langname = langModule->languageCO->itemData(i).toString();
+       Language const * newlang = lyx::languages.getLanguage(fromqstr(langname));
        return (fontenc == "default"
-               || (fontenc == "global" && (lyxrc.fontenc == "default" || lyxrc.fontenc == "OT1"))
+               || (fontenc == "auto" && newlang->fontenc(buffer().params()) == "OT1")
                || (fontenc == "custom" && fontModule->fontencLE->text() == "OT1"));
 }
 
@@ -2397,7 +2541,7 @@ void GuiDocument::classChanged()
                return;
        string const classname = fromqstr(latexModule->classCO->getData(idx));
 
-       if (applyPB->isEnabled()) {
+       if (buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
                int const ret = Alert::prompt(_("Unapplied changes"),
                                _("Some changes in the dialog were not yet applied.\n"
                                "If you do not apply now, they will be lost after this action."),
@@ -2443,6 +2587,28 @@ void GuiDocument::biblioChanged()
 }
 
 
+void GuiDocument::checkPossibleCiteEngines()
+{
+       // Check if the class provides a specific engine,
+       // and if so, enforce this.
+       string force_engine;
+       if (documentClass().provides("natbib")
+           || documentClass().provides("natbib-internal"))
+               force_engine = "natbib";
+       else if (documentClass().provides("jurabib"))
+               force_engine = "jurabib";
+       else if (documentClass().provides("biblatex"))
+               force_engine = "biblatex";
+       else if (documentClass().provides("biblatex-natbib"))
+               force_engine = "biblatex-natbib";
+
+       if (!force_engine.empty())
+               biblioModule->citeEngineCO->setCurrentIndex(
+                       biblioModule->citeEngineCO->findData(toqstr(force_engine)));
+       biblioModule->citeEngineCO->setEnabled(force_engine.empty());
+}
+
+
 void GuiDocument::rescanBibFiles()
 {
        if (isBiblatex())
@@ -2677,7 +2843,8 @@ void GuiDocument::modulesChanged()
 {
        modulesToParams(bp_);
 
-       if (applyPB->isEnabled() && (nonModuleChanged_ || shellescapeChanged_)) {
+       if (buttonBox->button(QDialogButtonBox::Apply)->isEnabled()
+           && (nonModuleChanged_ || shellescapeChanged_)) {
                int const ret = Alert::prompt(_("Unapplied changes"),
                                _("Some changes in the dialog were not yet applied.\n"
                                "If you do not apply now, they will be lost after this action."),
@@ -2976,17 +3143,19 @@ void GuiDocument::applyView()
                if (!item)
                        continue;
                int row = mathsModule->packagesTW->row(item);
-               QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1);
+
+               QRadioButton * rb =
+                       (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
                if (rb->isChecked()) {
                        bp_.use_package(it->first, BufferParams::package_auto);
                        continue;
                }
-               rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2);
+               rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
                if (rb->isChecked()) {
                        bp_.use_package(it->first, BufferParams::package_on);
                        continue;
                }
-               rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3);
+               rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
                if (rb->isChecked())
                        bp_.use_package(it->first, BufferParams::package_off);
        }
@@ -3134,8 +3303,9 @@ void GuiDocument::applyView()
        bp_.maintain_unincluded_children =
                masterChildModule->maintainAuxCB->isChecked();
 
-       // Float Placement
-       bp_.float_placement = floatModule->get();
+       // Float Settings
+       bp_.float_placement = floatModule->getPlacement();
+       bp_.float_alignment = floatModule->getAlignment();
 
        // Listings
        // text should have passed validation
@@ -3316,7 +3486,7 @@ void GuiDocument::paramsToDialog()
        latexModule->refstyleCB->setChecked(bp_.use_refstyle);
 
        // biblio
-       string const cite_engine = bp_.citeEngine().list().front();
+       string const cite_engine = bp_.citeEngine();
 
        biblioModule->citeEngineCO->setCurrentIndex(
                biblioModule->citeEngineCO->findData(toqstr(cite_engine)));
@@ -3324,6 +3494,8 @@ void GuiDocument::paramsToDialog()
        updateEngineType(documentClass().opt_enginetype(),
                bp_.citeEngineType());
 
+       checkPossibleCiteEngines();
+
        biblioModule->citeStyleCO->setCurrentIndex(
                biblioModule->citeStyleCO->findData(bp_.citeEngineType()));
 
@@ -3519,17 +3691,20 @@ void GuiDocument::paramsToDialog()
                int row = mathsModule->packagesTW->row(item);
                switch (bp_.use_package(it->first)) {
                        case BufferParams::package_off: {
-                               QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3);
+                               QRadioButton * rb =
+                                       (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 3)->layout()->itemAt(0)->widget();
                                rb->setChecked(true);
                                break;
                        }
                        case BufferParams::package_on: {
-                               QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2);
+                               QRadioButton * rb =
+                                       (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 2)->layout()->itemAt(0)->widget();
                                rb->setChecked(true);
                                break;
                        }
                        case BufferParams::package_auto: {
-                               QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1);
+                               QRadioButton * rb =
+                                       (QRadioButton*)mathsModule->packagesTW->cellWidget(row, 1)->layout()->itemAt(0)->widget();
                                rb->setChecked(true);
                                break;
                        }
@@ -3660,7 +3835,8 @@ void GuiDocument::paramsToDialog()
                bp_.maintain_unincluded_children);
 
        // Float Settings
-       floatModule->set(bp_.float_placement);
+       floatModule->setPlacement(bp_.float_placement);
+       floatModule->setAlignment(bp_.float_alignment);
 
        // ListingsSettings
        // break listings_params to multiple lines
@@ -3757,12 +3933,13 @@ void GuiDocument::paramsToDialog()
        if (nn >= 0)
                fontModule->fontsDefaultCO->setCurrentIndex(nn);
 
-       if (bp_.fontenc == "global" || bp_.fontenc == "default") {
+       if (bp_.fontenc == "auto" || bp_.fontenc == "default") {
                fontModule->fontencCO->setCurrentIndex(
                        fontModule->fontencCO->findData(toqstr(bp_.fontenc)));
                fontModule->fontencLE->setEnabled(false);
        } else {
-               fontModule->fontencCO->setCurrentIndex(1);
+               fontModule->fontencCO->setCurrentIndex(
+                                       fontModule->fontencCO->findData("custom"));
                fontModule->fontencLE->setText(toqstr(bp_.fontenc));
        }
 
@@ -3981,6 +4158,12 @@ bool GuiDocument::isBiblatex() const
                biblioModule->citeEngineCO->itemData(
                                biblioModule->citeEngineCO->currentIndex()).toString();
 
+       // this can happen if the cite engine is unknown, which can happen
+       // if one is using a file that came from someone else, etc. in that
+       // case, we crash if we proceed.
+       if (engine.isEmpty())
+           return false;
+
        return theCiteEnginesList[fromqstr(engine)]->getCiteFramework() == "biblatex";
 }
 
@@ -4132,7 +4315,7 @@ void GuiDocument::updateContents()
 
 void GuiDocument::useClassDefaults()
 {
-       if (applyPB->isEnabled()) {
+       if (buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
                int const ret = Alert::prompt(_("Unapplied changes"),
                                _("Some changes in the dialog were not yet applied.\n"
                                  "If you do not apply now, they will be lost after this action."),
@@ -4166,6 +4349,8 @@ bool GuiDocument::isValid()
        return
                validateListingsParameters().isEmpty() &&
                localLayout->isValid() &&
+               !localLayout->editing() &&
+               !preambleModule->editing() &&
                (
                        // if we're asking for skips between paragraphs
                        !textLayoutModule->skipRB->isChecked() ||
@@ -4533,7 +4718,8 @@ void GuiDocument::allPackagesNot()
 void GuiDocument::allPackages(int col)
 {
        for (int row = 0; row < mathsModule->packagesTW->rowCount(); ++row) {
-               QRadioButton * rb = (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col);
+               QRadioButton * rb =
+                       (QRadioButton*)mathsModule->packagesTW->cellWidget(row, col)->layout()->itemAt(0)->widget();
                rb->setChecked(true);
        }
 }