]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiRef.cpp
Do not show master's errors if compiling child
[lyx.git] / src / frontends / qt4 / GuiRef.cpp
index ecfe598c4cc64f8551339a1079a598dce15fed7f..c07ce5ce87037c894a3f1813d9187cf2670001b2 100644 (file)
 #include "GuiApplication.h"
 
 #include "Buffer.h"
+#include "BufferParams.h"
 #include "BufferList.h"
+#include "BufferView.h"
+#include "Cursor.h"
 #include "FuncRequest.h"
 
 #include "qt_helpers.h"
@@ -52,16 +55,19 @@ GuiRef::GuiRef(GuiView & lv)
 
        // The filter bar
        filter_ = new FancyLineEdit(this);
-#if QT_VERSION >= 0x040600
        filter_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png"));
        filter_->setButtonVisible(FancyLineEdit::Right, true);
        filter_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text"));
        filter_->setAutoHideButton(FancyLineEdit::Right, true);
-#endif
-#if QT_VERSION >= 0x040700
        filter_->setPlaceholderText(qt_("All available labels"));
-#endif
        filter_->setToolTip(qt_("Enter string to filter the list of available labels"));
+#if (QT_VERSION < 0x050000)
+       connect(filter_, SIGNAL(downPressed()),
+               refsTW, SLOT(setFocus()));
+#else
+       connect(filter_, &FancyLineEdit::downPressed,
+               refsTW, [=](){ focusAndHighlight(refsTW); });
+#endif
 
        filterBarL->addWidget(filter_, 0);
        findKeysLA->setBuddy(filter_);
@@ -87,6 +93,8 @@ GuiRef::GuiRef(GuiView & lv)
                this, SLOT(changed_adaptor()));
        connect(filter_, SIGNAL(textEdited(QString)),
                this, SLOT(filterLabels()));
+       connect(filter_, SIGNAL(rightButtonClicked()),
+               this, SLOT(resetFilter()));
        connect(csFindCB, SIGNAL(clicked()),
                this, SLOT(filterLabels()));
        connect(nameED, SIGNAL(textChanged(QString)),
@@ -107,6 +115,14 @@ GuiRef::GuiRef(GuiView & lv)
                this, SLOT(updateClicked()));
        connect(bufferCO, SIGNAL(activated(int)),
                this, SLOT(updateClicked()));
+       connect(pluralCB, SIGNAL(clicked()),
+               this, SLOT(changed_adaptor()));
+       connect(capsCB, SIGNAL(clicked()),
+               this, SLOT(changed_adaptor()));
+       connect(noprefixCB, SIGNAL(clicked()),
+               this, SLOT(changed_adaptor()));
+
+       enableBoxes();
 
        bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
        bc().setOK(okPB);
@@ -116,6 +132,8 @@ GuiRef::GuiRef(GuiView & lv)
 
        restored_buffer_ = -1;
        active_buffer_ = -1;
+
+       setFocusProxy(filter_);
 }
 
 
@@ -128,9 +146,23 @@ void GuiRef::enableView(bool enable)
 }
 
 
+void GuiRef::enableBoxes()
+{
+       bool const isFormatted =
+           (InsetRef::getName(typeCO->currentIndex()) == "formatted");
+       bool const isLabelOnly =
+           (InsetRef::getName(typeCO->currentIndex()) == "labelonly");
+       bool const usingRefStyle = buffer().params().use_refstyle;
+       pluralCB->setEnabled(isFormatted && usingRefStyle);
+       capsCB->setEnabled(isFormatted && usingRefStyle);
+       noprefixCB->setEnabled(isLabelOnly);
+}
+
+
 void GuiRef::changed_adaptor()
 {
        changed();
+       enableBoxes();
 }
 
 
@@ -140,7 +172,7 @@ void GuiRef::gotoClicked()
        // to which we are going (or from which we are returning) is
        // restored in the dialog. It's a bit of a hack, but it works,
        // and no-one seems to have any better idea.
-       bool const toggled = 
+       bool const toggled =
                last_reference_.isEmpty() || last_reference_.isNull();
        if (toggled)
                last_reference_ = referenceED->text();
@@ -263,10 +295,26 @@ void GuiRef::closeEvent(QCloseEvent * e)
 
 void GuiRef::updateContents()
 {
-       int orig_type = typeCO->currentIndex();
+       QString const orig_type =
+               typeCO->itemData(typeCO->currentIndex()).toString();
 
        referenceED->clear();
        nameED->clear();
+       typeCO->clear();
+
+       // FIXME Bring InsetMathRef on par with InsetRef
+       // (see #9798)
+       typeCO->addItem(qt_("<reference>"), "ref");
+       typeCO->addItem(qt_("(<reference>)"), "eqref");
+       typeCO->addItem(qt_("<page>"), "pageref");
+       typeCO->addItem(qt_("on page <page>"), "vpageref");
+       typeCO->addItem(qt_("<reference> on page <page>"), "vref");
+       if (bufferview()->cursor().inTexted()) {
+               typeCO->addItem(qt_("Formatted reference"), "formatted");
+               typeCO->addItem(qt_("Textual reference"), "nameref");
+               typeCO->addItem(qt_("Label only"), "labelonly");
+       } else
+               typeCO->addItem(qt_("Formatted reference"), "prettyref");
 
        referenceED->setText(toqstr(params_["reference"]));
        nameED->setText(toqstr(params_["name"]));
@@ -275,14 +323,23 @@ void GuiRef::updateContents()
 
        // restore type settings for new insets
        bool const new_inset = params_["reference"].empty();
-       if (new_inset)
-               typeCO->setCurrentIndex(orig_type);
+       if (new_inset) {
+               int index = typeCO->findData(orig_type);
+               if (index == -1)
+                       index = 0;
+               typeCO->setCurrentIndex(index);
+       }
        else
-               typeCO->setCurrentIndex(InsetRef::getType(params_.getCmdName()));
+               typeCO->setCurrentIndex(
+                       typeCO->findData(toqstr(params_.getCmdName())));
        typeCO->setEnabled(typeAllowed() && !isBufferReadonly());
        if (!typeAllowed())
                typeCO->setCurrentIndex(0);
 
+       pluralCB->setChecked(params_["plural"] == "true");
+       capsCB->setChecked(params_["caps"] == "true");
+       noprefixCB->setChecked(params_["noprefix"] == "true");
+
        // insert buffer list
        bufferCO->clear();
        FileNameList const buffers(theBufferList().fileNames());
@@ -305,6 +362,7 @@ void GuiRef::updateContents()
        active_buffer_ = thebuffer;
 
        updateRefs();
+       enableBoxes();
        // Activate OK/Apply buttons if the users inserts a new ref
        // and we have a valid pre-setting.
        bc().setValid(isValid() && new_inset);
@@ -315,10 +373,15 @@ void GuiRef::applyView()
 {
        last_reference_ = referenceED->text();
 
-       params_.setCmdName(InsetRef::getName(typeCO->currentIndex()));
+       params_.setCmdName(fromqstr(typeCO->itemData(typeCO->currentIndex()).toString()));
        params_["reference"] = qstring_to_ucs4(last_reference_);
        params_["name"] = qstring_to_ucs4(nameED->text());
-
+       params_["plural"] = pluralCB->isChecked() ?
+             from_ascii("true") : from_ascii("false");
+       params_["caps"] = capsCB->isChecked() ?
+             from_ascii("true") : from_ascii("false");
+       params_["noprefix"] = noprefixCB->isChecked() ?
+             from_ascii("true") : from_ascii("false");
        restored_buffer_ = bufferCO->currentIndex();
 }
 
@@ -501,8 +564,6 @@ void GuiRef::updateRefs()
        sortingCO->setEnabled(!refs_.empty());
        refsTW->setEnabled(!refs_.empty());
        groupCB->setEnabled(!refs_.empty());
-       // refsTW should only be the focus proxy when it is enabled
-       setFocusProxy(refs_.empty() ? 0 : refsTW);
        redoRefs();
 }
 
@@ -541,6 +602,13 @@ void GuiRef::filterLabels()
 }
 
 
+void GuiRef::resetFilter()
+{
+       filter_->setText(QString());
+       filterLabels();
+}
+
+
 bool GuiRef::initialiseParams(std::string const & data)
 {
        InsetCommand::string2params(data, params_);