]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDocument.cpp
Cosmetics for r29220.
[lyx.git] / src / frontends / qt4 / GuiDocument.cpp
index 378ff9df1fb0572f79b3992c41143a92bb89ff51..f55878ebb361cbc01780c15145de78f2c8bf2bbe 100644 (file)
 #include "BufferParams.h"
 #include "BufferView.h"
 #include "Color.h"
+#include "ColorCache.h"
 #include "Encoding.h"
 #include "FloatPlacement.h"
+#include "Format.h"
 #include "FuncRequest.h"
 #include "Language.h"
 #include "LaTeXFeatures.h"
@@ -53,6 +55,8 @@
 #include "frontends/alert.h"
 
 #include <QAbstractItemModel>
+#include <QColor>
+#include <QColorDialog>
 #include <QCloseEvent>
 #include <QFontDatabase>
 #include <QScrollBar>
 #endif
 
 
+// a style sheet for buttons
+// this is for example used for the background color setting button
+static inline QString colorButtonStyleSheet(QColor const & bgColor)
+{
+       if (bgColor.isValid()) {
+               QString rc = QLatin1String("background:");
+               rc += bgColor.name();
+               return rc;
+       }
+       return QLatin1String("");
+}
+
+
 using namespace std;
 using namespace lyx::support;
 
@@ -156,6 +173,8 @@ vector<pair<string, QString> > pagestyles;
 
 namespace lyx {
 
+RGBColor set_backgroundcolor;
+
 namespace {
 // used when sorting the textclass list.
 class less_textclass_avail_desc
@@ -583,8 +602,18 @@ GuiDocument::GuiDocument(GuiView & lv)
        // initialize the length validator
        bc().addCheckedLineEdit(textLayoutModule->skipLE);
 
-       fontModule = new UiWidget<Ui::FontUi>;
+       // output
+       outputModule = new UiWidget<Ui::OutputUi>;
+
+       connect(outputModule->xetexCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
+       connect(outputModule->xetexCB, SIGNAL(toggled(bool)),
+               this, SLOT(xetexChanged(bool)));
+       connect(outputModule->defaultFormatCO, SIGNAL(activated(int)),
+               this, SLOT(change_adaptor()));
+
        // fonts
+       fontModule = new UiWidget<Ui::FontUi>;
        connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
        connect(fontModule->fontsRomanCO, SIGNAL(activated(int)),
@@ -611,10 +640,6 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(fontModule->fontOsfCB, SIGNAL(clicked()),
                this, SLOT(change_adaptor()));
-       connect(fontModule->xetexCB, SIGNAL(clicked()),
-               this, SLOT(change_adaptor()));
-       connect(fontModule->xetexCB, SIGNAL(toggled(bool)),
-               this, SLOT(xetexChanged(bool)));
 
        updateFontlist();
 
@@ -654,6 +679,10 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
                this, SLOT(change_adaptor()));
+       connect(pageLayoutModule->backgroundTB, SIGNAL(clicked()),
+               this, SLOT(changeBackgroundColor()));
+       connect(pageLayoutModule->delbackgroundTB, SIGNAL(clicked()),
+               this, SLOT(deleteBackgroundColor()));
 
        pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
        pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
@@ -982,6 +1011,7 @@ GuiDocument::GuiDocument(GuiView & lv)
        docPS->addPanel(floatModule, qt_("Float Placement"));
        docPS->addPanel(bulletsModule, qt_("Bullets"));
        docPS->addPanel(branchesModule, qt_("Branches"));
+       docPS->addPanel(outputModule, qt_("Output"));
        docPS->addPanel(preambleModule, qt_("LaTeX Preamble"));
        docPS->setCurrentPanel(qt_("Document Class"));
 // FIXME: hack to work around resizing bug in Qt >= 4.2
@@ -1157,14 +1187,60 @@ void GuiDocument::setCustomMargins(bool custom)
        marginsModule->columnsepUnit->setEnabled(enableColSep);
 }
 
+void GuiDocument::changeBackgroundColor()
+{
+       QColor const & newColor = QColorDialog::getColor(
+               rgb2qcolor(set_backgroundcolor), qApp->focusWidget());
+       if (!newColor.isValid())
+               return;
+       // set the button color
+       pageLayoutModule->backgroundTB->setStyleSheet(
+               colorButtonStyleSheet(newColor));
+       // save color
+       set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
+       changed();
+}
+
+
+void GuiDocument::deleteBackgroundColor()
+{
+       // set the button color back to white
+       pageLayoutModule->backgroundTB->setStyleSheet(
+               colorButtonStyleSheet(QColor(Qt::white)));
+       // save white as the set color
+       set_backgroundcolor = rgbFromHexName("#ffffff");
+       changed();
+}
+
 
 void GuiDocument::xetexChanged(bool xetex)
 {
        updateFontlist();
+       updateDefaultFormat();
        langModule->encodingCO->setEnabled(!xetex &&
                !langModule->defaultencodingRB->isChecked());
        langModule->defaultencodingRB->setEnabled(!xetex);
        langModule->otherencodingRB->setEnabled(!xetex);
+
+       fontModule->fontsDefaultCO->setEnabled(!xetex);
+       fontModule->fontsDefaultLA->setEnabled(!xetex);
+       fontModule->cjkFontLE->setEnabled(!xetex);
+       fontModule->cjkFontLA->setEnabled(!xetex);
+       string font;
+       if (!xetex)
+               font = tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
+       bool scaleable = providesScale(font);
+       fontModule->scaleSansSB->setEnabled(scaleable);
+       fontModule->scaleSansLA->setEnabled(scaleable);
+       if (!xetex)
+               font = tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
+       scaleable = providesScale(font);
+       fontModule->scaleTypewriterSB->setEnabled(scaleable);
+       fontModule->scaleTypewriterLA->setEnabled(scaleable);
+       if (!xetex)
+               font = tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
+       fontModule->fontScCB->setEnabled(providesSC(font));
+       fontModule->fontOsfCB->setEnabled(providesOSF(font));
 }
 
 
@@ -1193,7 +1269,7 @@ void GuiDocument::updateFontlist()
        fontModule->fontsTypewriterCO->clear();
 
        // With XeTeX, we have access to all system fonts, but not the LaTeX fonts
-       if (fontModule->xetexCB->isChecked()) {
+       if (outputModule->xetexCB->isChecked()) {
                fontModule->fontsRomanCO->addItem(qt_("Default"));
                fontModule->fontsSansCO->addItem(qt_("Default"));
                fontModule->fontsTypewriterCO->addItem(qt_("Default"));
@@ -1231,10 +1307,8 @@ void GuiDocument::updateFontlist()
 
 void GuiDocument::romanChanged(int item)
 {
-       if (fontModule->xetexCB->isChecked()) {
-               fontModule->fontScCB->setEnabled(false);
+       if (outputModule->xetexCB->isChecked())
                return;
-       }
        string const font = tex_fonts_roman[item];
        fontModule->fontScCB->setEnabled(providesSC(font));
        fontModule->fontOsfCB->setEnabled(providesOSF(font));
@@ -1243,10 +1317,8 @@ void GuiDocument::romanChanged(int item)
 
 void GuiDocument::sansChanged(int item)
 {
-       if (fontModule->xetexCB->isChecked()) {
-               fontModule->fontScCB->setEnabled(false);
+       if (outputModule->xetexCB->isChecked())
                return;
-       }
        string const font = tex_fonts_sans[item];
        bool scaleable = providesScale(font);
        fontModule->scaleSansSB->setEnabled(scaleable);
@@ -1256,10 +1328,8 @@ void GuiDocument::sansChanged(int item)
 
 void GuiDocument::ttChanged(int item)
 {
-       if (fontModule->xetexCB->isChecked()) {
-               fontModule->fontScCB->setEnabled(false);
+       if (outputModule->xetexCB->isChecked())
                return;
-       }
        string const font = tex_fonts_monospaced[item];
        bool scaleable = providesScale(font);
        fontModule->scaleTypewriterSB->setEnabled(scaleable);
@@ -1595,6 +1665,32 @@ void GuiDocument::updateNumbering()
 }
 
 
+void GuiDocument::updateDefaultFormat()
+{
+       // make a copy in order to consider unapplied changes
+       Buffer * tmpbuf = const_cast<Buffer *>(&buffer());
+       tmpbuf->params().useXetex = outputModule->xetexCB->isChecked();
+       int idx = latexModule->classCO->currentIndex();
+       if (idx >= 0) {
+               string const classname = classes_model_.getIDString(idx);
+               tmpbuf->params().setBaseClass(classname);
+               tmpbuf->params().makeDocumentClass();
+       }
+       outputModule->defaultFormatCO->blockSignals(true);
+       outputModule->defaultFormatCO->clear();
+       outputModule->defaultFormatCO->addItem(qt_("Default"),
+                               QVariant(QString("default")));
+       typedef vector<Format const *> Formats;
+       Formats formats = tmpbuf->exportableFormats(true);
+       Formats::const_iterator cit = formats.begin();
+       Formats::const_iterator end = formats.end();
+       for (; cit != end; ++cit)
+               outputModule->defaultFormatCO->addItem(qt_((*cit)->prettyname()),
+                               QVariant(toqstr((*cit)->name())));
+       outputModule->defaultFormatCO->blockSignals(false);
+}
+
+
 void GuiDocument::applyView()
 {
        // preamble
@@ -1670,7 +1766,7 @@ void GuiDocument::applyView()
 
        QString const lang = langModule->languageCO->itemData(
                langModule->languageCO->currentIndex()).toString();
-       bp_.language = lyx::languages.getLanguage(fromqstr(lang));
+       bp_.language = languages.getLanguage(fromqstr(lang));
 
        // numbering
        if (bp_.documentClass().hasTocLevels()) {
@@ -1795,10 +1891,14 @@ void GuiDocument::applyView()
 
        bp_.float_placement = floatModule->get();
 
-       // fonts
-       bool const xetex = fontModule->xetexCB->isChecked();
+       // output
+       bp_.defaultOutputFormat = fromqstr(outputModule->defaultFormatCO->itemData(
+               outputModule->defaultFormatCO->currentIndex()).toString());
+
+       bool const xetex = outputModule->xetexCB->isChecked();
        bp_.useXetex = xetex;
 
+       // fonts
        if (xetex) {
                if (fontModule->fontsRomanCO->currentIndex() == 0)
                        bp_.fontsRoman = "default";
@@ -1839,8 +1939,11 @@ void GuiDocument::applyView()
 
        bp_.fontsOSF = fontModule->fontOsfCB->isChecked();
 
-       bp_.fontsDefaultFamily = GuiDocument::fontfamilies[
-               fontModule->fontsDefaultCO->currentIndex()];
+       if (xetex)
+               bp_.fontsDefaultFamily = "default";
+       else
+               bp_.fontsDefaultFamily = GuiDocument::fontfamilies[
+                       fontModule->fontsDefaultCO->currentIndex()];
 
        if (fontModule->fontsizeCO->currentIndex() == 0)
                bp_.fontsize = "default";
@@ -1872,6 +1975,8 @@ void GuiDocument::applyView()
        else
                bp_.orientation = ORIENTATION_PORTRAIT;
 
+       bp_.backgroundcolor = set_backgroundcolor;
+
        // margins
        bp_.use_geometry = !marginsModule->marginCB->isChecked()
                || geom_papersize;
@@ -2120,12 +2225,23 @@ void GuiDocument::paramsToDialog()
 
        floatModule->set(bp_.float_placement);
 
+       // Output
+       // update combobox with formats
+       updateDefaultFormat();
+       int index = outputModule->defaultFormatCO->findData(toqstr(
+               bp_.defaultOutputFormat));
+       // set to default if format is not found 
+       if (index == -1)
+               index = 0;
+       outputModule->defaultFormatCO->setCurrentIndex(index);
+       outputModule->xetexCB->setEnabled(bp_.baseClass()->outputType() == lyx::LATEX);
+       outputModule->xetexCB->setChecked(
+               bp_.baseClass()->outputType() == lyx::LATEX && bp_.useXetex);
+
        // Fonts
        updateFontsize(documentClass().opt_fontsize(),
                        bp_.fontsize);
 
-       fontModule->xetexCB->setChecked(bp_.useXetex);
-
        if (bp_.useXetex) {
                for (int i = 0; i < fontModule->fontsRomanCO->count(); ++i) {
                        if (fontModule->fontsRomanCO->itemText(i) == toqstr(bp_.fontsRoman)) {
@@ -2200,10 +2316,12 @@ void GuiDocument::paramsToDialog()
        pageLayoutModule->facingPagesCB->setChecked(
                bp_.sides == TwoSides);
 
+       pageLayoutModule->backgroundTB->setStyleSheet(
+               colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor)));
+       set_backgroundcolor = bp_.backgroundcolor;
 
        lengthToWidgets(pageLayoutModule->paperwidthLE,
                pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, defaultUnit);
-
        lengthToWidgets(pageLayoutModule->paperheightLE,
                pageLayoutModule->paperheightUnitCO, bp_.paperheight, defaultUnit);
 
@@ -2548,6 +2666,10 @@ bool GuiDocument::isFontAvailable(string const & font) const
 
 bool GuiDocument::providesOSF(string const & font) const
 {
+       if (outputModule->xetexCB->isChecked())
+               // FIXME: we should check if the fonts really
+               // have OSF support. But how?
+               return true;
        if (font == "cmr")
                return isFontAvailable("eco");
        if (font == "palatino")
@@ -2558,6 +2680,8 @@ bool GuiDocument::providesOSF(string const & font) const
 
 bool GuiDocument::providesSC(string const & font) const
 {
+       if (outputModule->xetexCB->isChecked())
+               return false;
        if (font == "palatino")
                return isFontAvailable("mathpazo");
        if (font == "utopia")
@@ -2568,6 +2692,8 @@ bool GuiDocument::providesSC(string const & font) const
 
 bool GuiDocument::providesScale(string const & font) const
 {
+       if (outputModule->xetexCB->isChecked())
+               return true;
        return font == "helvet" || font == "luximono"
                || font == "berasans"  || font == "beramono";
 }