]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCharacter.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiCharacter.cpp
index e506b98dbbc7f723149e582d3cf06626d00d267f..59b7ca3f0e50074d3d79fd11b3452fcec5c91947 100644 (file)
@@ -34,7 +34,9 @@
 #include "support/lstrings.h"
 
 #include <QAbstractItemModel>
+#include <QPushButton>
 #include <QComboBox>
+#include <QMenu>
 #include <QModelIndex>
 #include <QSettings>
 #include <QVariant>
@@ -60,20 +62,20 @@ static QList<ShapePair> shapeData()
 static QList<SizePair> sizeData()
 {
        QList<SizePair> sizes;
-       sizes << SizePair(qt_("No change"), FONT_SIZE_IGNORE);
-       sizes << SizePair(qt_("Default"), FONT_SIZE_INHERIT);
-       sizes << SizePair(qt_("Tiny"), FONT_SIZE_TINY);
-       sizes << SizePair(qt_("Smallest"), FONT_SIZE_SCRIPT);
-       sizes << SizePair(qt_("Smaller"), FONT_SIZE_FOOTNOTE);
-       sizes << SizePair(qt_("Small"), FONT_SIZE_SMALL);
-       sizes << SizePair(qt_("Normal"), FONT_SIZE_NORMAL);
-       sizes << SizePair(qt_("Large"), FONT_SIZE_LARGE);
-       sizes << SizePair(qt_("Larger"), FONT_SIZE_LARGER);
-       sizes << SizePair(qt_("Largest"), FONT_SIZE_LARGEST);
-       sizes << SizePair(qt_("Huge"), FONT_SIZE_HUGE);
-       sizes << SizePair(qt_("Huger"), FONT_SIZE_HUGER);
-       sizes << SizePair(qt_("Increase"), FONT_SIZE_INCREASE);
-       sizes << SizePair(qt_("Decrease"), FONT_SIZE_DECREASE);
+       sizes << SizePair(qt_("No change"), IGNORE_SIZE);
+       sizes << SizePair(qt_("Default"), INHERIT_SIZE);
+       sizes << SizePair(qt_("Tiny"), TINY_SIZE);
+       sizes << SizePair(qt_("Smallest"), SCRIPT_SIZE);
+       sizes << SizePair(qt_("Smaller"), FOOTNOTE_SIZE);
+       sizes << SizePair(qt_("Small"), SMALL_SIZE);
+       sizes << SizePair(qt_("Normal"), NORMAL_SIZE);
+       sizes << SizePair(qt_("Large"), LARGE_SIZE);
+       sizes << SizePair(qt_("Larger"), LARGER_SIZE);
+       sizes << SizePair(qt_("Largest"), LARGEST_SIZE);
+       sizes << SizePair(qt_("Huge"), HUGE_SIZE);
+       sizes << SizePair(qt_("Huger"), HUGER_SIZE);
+       sizes << SizePair(qt_("Increase"), INCREASE_SIZE);
+       sizes << SizePair(qt_("Decrease"), DECREASE_SIZE);
        return sizes;
 }
 
@@ -211,9 +213,11 @@ GuiCharacter::GuiCharacter(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()));
+       // fix height to minimum
+       setFixedHeight(sizeHint().height());
+
+       connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
+               this, SLOT(slotButtonBox(QAbstractButton *)));
        connect(autoapplyCB, SIGNAL(stateChanged(int)), this,
                SLOT(slotAutoApply()));
 
@@ -249,9 +253,10 @@ GuiCharacter::GuiCharacter(GuiView & lv)
        fillCombo(langCO, language);
 
        bc().setPolicy(ButtonPolicy::OkApplyCancelAutoReadOnlyPolicy);
-       bc().setOK(okPB);
-       bc().setApply(applyPB);
-       bc().setCancel(closePB);
+       bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
+       bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
+       bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
+       bc().setRestore(buttonBox->button(QDialogButtonBox::Reset));
        bc().setAutoApply(autoapplyCB);
        bc().addReadOnly(familyCO);
        bc().addReadOnly(seriesCO);
@@ -266,6 +271,18 @@ GuiCharacter::GuiCharacter(GuiView & lv)
        bc().addReadOnly(colorCO);
        bc().addReadOnly(autoapplyCB);
 
+       // Add button menu to restore button to reset
+       // all widgets to "Defaults" or "No Change"
+       resetdefault_ = new QAction(qt_("Reset All To &Default"), this);
+       resetnochange_ = new QAction(qt_("Reset All To No Chan&ge"), this);
+       QMenu * resetmenu = new QMenu();
+       resetmenu->addAction(resetdefault_);
+       resetmenu->addAction(resetnochange_);
+       buttonBox->button(QDialogButtonBox::RestoreDefaults)->setMenu(resetmenu);
+       buttonBox->button(QDialogButtonBox::RestoreDefaults)->setText(qt_("&Reset All Fields"));
+       connect(resetdefault_, SIGNAL(triggered()), this, SLOT(resetToDefault()));
+       connect(resetnochange_, SIGNAL(triggered()), this, SLOT(resetToNoChange()));
+
 #ifdef Q_OS_MAC
        // On Mac it's common to have tool windows which are always in the
        // foreground and are hidden when the main window is not focused.
@@ -308,19 +325,21 @@ void GuiCharacter::on_nospellcheckCB_clicked()
 }
 
 
-
-void GuiCharacter::change_adaptor()
+void GuiCharacter::resetToDefault()
 {
-       changed();
+       Font font(inherit_font);
+       font.setLanguage(reset_language);
+       paramsToDialog(font);
+       change_adaptor();
+}
 
-       if (!autoapplyCB->isChecked())
-               return;
 
-       // to be really good here, we should set the combos to the values of
-       // the current text, and make it appear as "no change" if the values
-       // stay the same between applys. Might be difficult though wrt to a
-       // moved cursor - jbl
-       slotApply();
+void GuiCharacter::resetToNoChange()
+{
+       Font font(ignore_font);
+       font.setLanguage(ignore_language);
+       paramsToDialog(font);
+       change_adaptor();
 }
 
 
@@ -335,7 +354,7 @@ static int findPos2nd(QList<P> const & vec, B const & val)
 
 
 namespace{
-FontState getBar(FontInfo const & fi)
+FontDeco getBar(FontInfo const & fi)
 {
        if (fi.underbar() == FONT_ON)
                return UNDERBAR;
@@ -349,11 +368,14 @@ FontState getBar(FontInfo const & fi)
        if (fi.underbar() == FONT_IGNORE)
                return IGNORE;
 
+       if (fi.underbar() == FONT_INHERIT)
+               return INHERIT;
+
        return NONE;
 }
 
 
-FontState getStrike(FontInfo const & fi)
+FontDeco getStrike(FontInfo const & fi)
 {
        if (fi.strikeout() == FONT_ON)
                return STRIKEOUT;
@@ -364,6 +386,9 @@ FontState getStrike(FontInfo const & fi)
        if (fi.strikeout() == FONT_IGNORE)
                return IGNORE;
 
+       if (fi.strikeout() == FONT_INHERIT)
+               return INHERIT;
+
        return NONE;
 }
 
@@ -371,12 +396,12 @@ FontState getStrike(FontInfo const & fi)
 Qt::CheckState getMarkupState(lyx::FontState fs)
 {
        switch (fs) {
+       case FONT_INHERIT:
        case FONT_OFF:
                return Qt::Unchecked;
        case FONT_ON:
                return Qt::Checked;
        case FONT_TOGGLE:
-       case FONT_INHERIT:
        case FONT_IGNORE:
        default:
                return Qt::PartiallyChecked;
@@ -399,10 +424,65 @@ lyx::FontState setMarkupState(Qt::CheckState cs)
 } // end namespace anon
 
 
+void GuiCharacter::change_adaptor()
+{
+       changed();
+
+       checkRestoreDefaults();
+
+       if (!autoapplyCB->isChecked())
+               return;
+
+       // to be really good here, we should set the combos to the values of
+       // the current text, and make it appear as "no change" if the values
+       // stay the same between applys. Might be difficult though wrt to a
+       // moved cursor - jbl
+       slotApply();
+}
+
+
+void GuiCharacter::checkRestoreDefaults()
+{
+       if (familyCO->currentIndex() == -1 || seriesCO->currentIndex() == -1
+           || shapeCO->currentIndex() == -1 || sizeCO->currentIndex() == -1
+           || ulineCO->currentIndex() == -1 || strikeCO->currentIndex() == -1
+           || colorCO->currentIndex() == -1 || langCO->currentIndex() == -1)
+               // dialog not yet built
+               return;
+
+       // (De)Activate Restore Defaults menu items
+       resetdefault_->setEnabled(
+               family[familyCO->currentIndex()].second != INHERIT_FAMILY
+               || series[seriesCO->currentIndex()].second != INHERIT_SERIES
+               || shape[shapeCO->currentIndex()].second != INHERIT_SHAPE
+               || size[sizeCO->currentIndex()].second != INHERIT_SIZE
+               || setMarkupState(emphCB->checkState()) != FONT_OFF
+               || setMarkupState(nounCB->checkState()) != FONT_OFF
+               || setMarkupState(nospellcheckCB->checkState()) != FONT_OFF
+               || bar[ulineCO->currentIndex()].second != INHERIT
+               || strike[strikeCO->currentIndex()].second != INHERIT
+               || lcolor.getFromLyXName(fromqstr(colorCO->itemData(colorCO->currentIndex()).toString())) != Color_inherit
+               || languages.getLanguage(fromqstr(language[langCO->currentIndex()].second)) != reset_language);
+
+       resetnochange_->setEnabled(
+               family[familyCO->currentIndex()].second != IGNORE_FAMILY
+               || series[seriesCO->currentIndex()].second != IGNORE_SERIES
+               || shape[shapeCO->currentIndex()].second != IGNORE_SHAPE
+               || size[sizeCO->currentIndex()].second != IGNORE_SIZE
+               || setMarkupState(emphCB->checkState()) != FONT_IGNORE
+               || setMarkupState(nounCB->checkState()) != FONT_IGNORE
+               || setMarkupState(nospellcheckCB->checkState()) != FONT_IGNORE
+               || bar[ulineCO->currentIndex()].second != IGNORE
+               || strike[strikeCO->currentIndex()].second != IGNORE
+               || lcolor.getFromLyXName(fromqstr(colorCO->itemData(colorCO->currentIndex()).toString())) != Color_ignore
+               || languages.getLanguage(fromqstr(language[langCO->currentIndex()].second)) != ignore_language);
+}
+
+
 void GuiCharacter::updateContents()
 {
        if (bufferview()->cursor().selection()) {
-               Font font = bufferview()->cursor().real_current_font;
+               Font font = bufferview()->cursor().current_font;
                FontInfo fi = font.fontInfo();
                BufferParams const & bp = buffer().masterParams();
 
@@ -416,7 +496,7 @@ void GuiCharacter::updateContents()
                        }
                        Paragraph const & par = dit.paragraph();
                        pos_type const pos = dit.pos();
-                       Font tmp = par.getFont(bp, pos, font);
+                       Font tmp = par.getFontSettings(bp, pos);
                        if (font.language() != tmp.language())
                                font.setLanguage(ignore_language);
                        if (fi.family() != tmp.fontInfo().family())
@@ -426,7 +506,7 @@ void GuiCharacter::updateContents()
                        if (fi.shape() != tmp.fontInfo().shape())
                                font.fontInfo().setShape(IGNORE_SHAPE);
                        if (fi.size() != tmp.fontInfo().size())
-                               font.fontInfo().setSize(FONT_SIZE_IGNORE);
+                               font.fontInfo().setSize(IGNORE_SIZE);
                        if (fi.emph() != tmp.fontInfo().emph())
                                font.fontInfo().setEmph(FONT_IGNORE);
                        if (fi.noun() != tmp.fontInfo().noun())
@@ -446,13 +526,19 @@ void GuiCharacter::updateContents()
                }
                font_ = font;
        } else
-               font_ = bufferview()->cursor().real_current_font;
+               font_ = bufferview()->cursor().current_font;
+
+       // If we use the buffer language, display "Default"
+       if (font_.language() == buffer().params().language)
+               font_.setLanguage(reset_language);
 
        paramsToDialog(font_);
+
+       checkRestoreDefaults();
 }
 
 
-void GuiCharacter::setBar(FontInfo & fi, FontState val)
+void GuiCharacter::setBar(FontInfo & fi, FontDeco val)
 {
        switch (val) {
        case IGNORE:
@@ -490,7 +576,7 @@ void GuiCharacter::setBar(FontInfo & fi, FontState val)
 }
 
 
-void GuiCharacter::setStrike(FontInfo & fi, FontState val)
+void GuiCharacter::setStrike(FontInfo & fi, FontDeco val)
 {
        switch (val) {
        case IGNORE:
@@ -576,7 +662,7 @@ bool GuiCharacter::initialiseParams(string const &)
        if (fi.family()    != IGNORE_FAMILY
            || fi.series() != IGNORE_SERIES
            || fi.shape()  != IGNORE_SHAPE
-           || fi.size()   != FONT_SIZE_IGNORE
+           || fi.size()   != IGNORE_SIZE
            || getBar(fi)  != IGNORE
            || fi.color()  != Color_ignore
            || font_.language() != ignore_language)