X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiRef.cpp;h=5d46a471c710bb980c0c062085c8f3a480d405b5;hb=b91e2b99986c0f957ba27eeba74b5ae0460d73bc;hp=f8e75449180b45b72384cf1e70825639acadcfca;hpb=ff3690a5fdec36dd24740525696a846be4696ebf;p=lyx.git diff --git a/src/frontends/qt4/GuiRef.cpp b/src/frontends/qt4/GuiRef.cpp index f8e7544918..5d46a471c7 100644 --- a/src/frontends/qt4/GuiRef.cpp +++ b/src/frontends/qt4/GuiRef.cpp @@ -18,6 +18,8 @@ #include "Buffer.h" #include "BufferParams.h" #include "BufferList.h" +#include "BufferView.h" +#include "Cursor.h" #include "FuncRequest.h" #include "qt_helpers.h" @@ -59,6 +61,13 @@ GuiRef::GuiRef(GuiView & lv) filter_->setAutoHideButton(FancyLineEdit::Right, true); filter_->setPlaceholderText(qt_("All available labels")); 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_); @@ -67,13 +76,12 @@ GuiRef::GuiRef(GuiView & lv) sortingCO->addItem(qt_("Alphabetically (Case-Insensitive)"), "nocase"); sortingCO->addItem(qt_("Alphabetically (Case-Sensitive)"), "case"); + buttonBox->button(QDialogButtonBox::Reset)->setText(qt_("&Update")); + buttonBox->button(QDialogButtonBox::Reset)->setToolTip(qt_("Update the label list")); + refsTW->setColumnCount(1); refsTW->header()->setVisible(false); - connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); - connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); - connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - connect(closePB, SIGNAL(clicked()), this, SLOT(resetDialog())); connect(this, SIGNAL(rejected()), this, SLOT(dialogRejected())); connect(typeCO, SIGNAL(activated(int)), @@ -102,8 +110,6 @@ GuiRef::GuiRef(GuiView & lv) this, SLOT(groupToggled())); connect(gotoPB, SIGNAL(clicked()), this, SLOT(gotoClicked())); - connect(updatePB, SIGNAL(clicked()), - this, SLOT(updateClicked())); connect(bufferCO, SIGNAL(activated(int)), this, SLOT(updateClicked())); connect(pluralCB, SIGNAL(clicked()), @@ -116,13 +122,15 @@ GuiRef::GuiRef(GuiView & lv) enableBoxes(); bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy); - 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().addReadOnly(typeCO); restored_buffer_ = -1; active_buffer_ = -1; + + setFocusProxy(filter_); } @@ -137,14 +145,14 @@ void GuiRef::enableView(bool enable) void GuiRef::enableBoxes() { - bool const isFormatted = + bool const isFormatted = (InsetRef::getName(typeCO->currentIndex()) == "formatted"); - bool const isLabelOnly = + 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 && usingRefStyle); + capsCB->setEnabled(isFormatted && usingRefStyle); + noprefixCB->setEnabled(isLabelOnly); } @@ -161,7 +169,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(); @@ -252,6 +260,28 @@ void GuiRef::groupToggled() } +void GuiRef::on_buttonBox_clicked(QAbstractButton * button) +{ + switch (buttonBox->standardButton(button)) { + case QDialogButtonBox::Ok: + slotOK(); + break; + case QDialogButtonBox::Apply: + slotApply(); + break; + case QDialogButtonBox::Cancel: + slotClose(); + resetDialog(); + break; + case QDialogButtonBox::Reset: + updateClicked(); + break; + default: + break; + } +} + + void GuiRef::updateClicked() { updateRefs(); @@ -284,10 +314,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_(""), "ref"); + typeCO->addItem(qt_("()"), "eqref"); + typeCO->addItem(qt_(""), "pageref"); + typeCO->addItem(qt_("on page "), "vpageref"); + typeCO->addItem(qt_(" on page "), "vref"); + typeCO->addItem(qt_("Textual reference"), "nameref"); + if (bufferview()->cursor().inTexted()) { + typeCO->addItem(qt_("Formatted reference"), "formatted"); + typeCO->addItem(qt_("Label only"), "labelonly"); + } else + typeCO->addItem(qt_("Formatted reference"), "prettyref"); referenceED->setText(toqstr(params_["reference"])); nameED->setText(toqstr(params_["name"])); @@ -296,10 +342,15 @@ 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); @@ -341,14 +392,14 @@ 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() ? + params_["plural"] = pluralCB->isChecked() ? from_ascii("true") : from_ascii("false"); - params_["caps"] = capsCB->isChecked() ? + params_["caps"] = capsCB->isChecked() ? from_ascii("true") : from_ascii("false"); - params_["noprefix"] = noprefixCB->isChecked() ? + params_["noprefix"] = noprefixCB->isChecked() ? from_ascii("true") : from_ascii("false"); restored_buffer_ = bufferCO->currentIndex(); } @@ -459,8 +510,8 @@ void GuiRef::redoRefs() QString const cat = refsCategories.at(i); QTreeWidgetItem * item = new QTreeWidgetItem(refsTW); item->setText(0, cat); - for (int i = 0; i < refsStrings.size(); ++i) { - QString const ref = refsStrings.at(i); + for (int j = 0; j < refsStrings.size(); ++j) { + QString const ref = refsStrings.at(j); if ((ref.startsWith(cat + QString(":"))) || (cat == qt_("") && (!ref.mid(1).contains(":") || ref.left(1).contains(":")))) { @@ -532,8 +583,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(); } @@ -579,9 +628,9 @@ void GuiRef::resetFilter() } -bool GuiRef::initialiseParams(std::string const & data) +bool GuiRef::initialiseParams(std::string const & sdata) { - InsetCommand::string2params(data, params_); + InsetCommand::string2params(sdata, params_); return true; }