]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/GuiRef.cpp
Properly scale some icons for HiDPI (#12695)
[lyx.git] / src / frontends / qt / GuiRef.cpp
index ad4d7107a94772ae7626b1f7dec5818761a5d5b2..9b9144377a244428820f1d6b64fb57faff5572cf 100644 (file)
@@ -22,6 +22,7 @@
 #include "Cursor.h"
 #include "FancyLineEdit.h"
 #include "FuncRequest.h"
+#include "PDFOptions.h"
 
 #include "qt_helpers.h"
 
@@ -109,6 +110,8 @@ GuiRef::GuiRef(GuiView & lv)
                this, SLOT(changed_adaptor()));
        connect(noprefixCB, SIGNAL(clicked()),
                this, SLOT(changed_adaptor()));
+       connect(nolinkCB, SIGNAL(clicked()),
+               this, SLOT(changed_adaptor()));
 
        enableBoxes();
 
@@ -142,9 +145,12 @@ void GuiRef::enableBoxes()
        bool const isLabelOnly = (reftype == "labelonly");
        bool const usingRefStyle = buffer().params().use_refstyle;
        bool const intext = bufferview()->cursor().inTexted();
+       bool const hyper_on = buffer().params().pdfoptions().use_hyperref;
        pluralCB->setEnabled(intext && isFormatted && usingRefStyle);
        capsCB->setEnabled(intext && isFormatted && usingRefStyle);
        noprefixCB->setEnabled(intext && isLabelOnly);
+       // disabling of hyperlinks not supported by formatted references
+       nolinkCB->setEnabled(hyper_on && intext && !isFormatted && !isLabelOnly);
 }
 
 
@@ -338,6 +344,7 @@ void GuiRef::updateContents()
        pluralCB->setChecked(params_["plural"] == "true");
        capsCB->setChecked(params_["caps"] == "true");
        noprefixCB->setChecked(params_["noprefix"] == "true");
+       nolinkCB->setChecked(params_["nolink"] == "true");
 
        // insert buffer list
        bufferCO->clear();
@@ -380,6 +387,8 @@ void GuiRef::applyView()
              from_ascii("true") : from_ascii("false");
        params_["noprefix"] = noprefixCB->isChecked() ?
              from_ascii("true") : from_ascii("false");
+       params_["nolink"] = nolinkCB->isChecked() ?
+             from_ascii("true") : from_ascii("false");
        restored_buffer_ = bufferCO->currentIndex();
 }
 
@@ -414,6 +423,11 @@ void GuiRef::gotoRef()
        at_ref_ = !at_ref_;
 }
 
+inline bool caseInsensitiveLessThanVec(QPair<QString, QString> const & s1, QPair<QString, QString> const & s2)
+{
+       return s1.first.toLower() < s2.first.toLower();
+}
+
 inline bool caseInsensitiveLessThan(QString const & s1, QString const & s2)
 {
        return s1.toLower() < s2.toLower();
@@ -434,17 +448,17 @@ void GuiRef::redoRefs()
        // the first item inserted
        QString const oldSelection(referenceED->text());
 
-       QStringList refsNames;
-       QStringList refsAsStrings;
+       // Plain label and GUI string. This might get resorted below
+       QVector<QPair<QString, QString>> refsNames;
+       // List of categories (prefixes)
        QStringList refsCategories;
-       vector<std::pair<docstring, docstring>>::const_iterator iter;
+       // Do we have a prefix-less label at all?
        bool noprefix = false;
+       vector<std::pair<docstring, docstring>>::const_iterator iter;
        for (iter = refs_.begin(); iter != refs_.end(); ++iter) {
-               // the plain label name
+               // first: plain label name, second: gui name
                QString const lab = toqstr((*iter).first);
-               refsNames.append(lab);
-               // the label as gui string
-               refsAsStrings.append(toqstr((*iter).second));
+               refsNames.append({lab, toqstr((*iter).second)});
                if (groupCB->isChecked()) {
                        if (lab.contains(":")) {
                                QString const pref = lab.split(':')[0];
@@ -468,9 +482,10 @@ void GuiRef::redoRefs()
        QString const sort_method = sortingCO->isEnabled() ?
                                        sortingCO->itemData(sortingCO->currentIndex()).toString()
                                        : QString();
+       // Sort items if so requested.
        if (sort_method == "nocase")
                sort(refsNames.begin(), refsNames.end(),
-                         caseInsensitiveLessThan /*defined above*/);
+                         caseInsensitiveLessThanVec /*defined above*/);
        else if (sort_method == "case")
                sort(refsNames.begin(), refsNames.end());
 
@@ -481,14 +496,15 @@ void GuiRef::redoRefs()
                        QTreeWidgetItem * item = new QTreeWidgetItem(refsTW);
                        item->setText(0, cat);
                        for (int j = 0; j < refsNames.size(); ++j) {
-                               QString const & ref = refsNames.at(j);
+                               QString const ref = refsNames.at(j).first;
                                if ((ref.startsWith(cat + QString(":")))
                                    || (cat == qt_("<No prefix>")
                                       && (!ref.mid(1).contains(":") || ref.left(1).contains(":")))) {
                                                QTreeWidgetItem * child =
                                                        new QTreeWidgetItem(item);
-                                               item->setText(0, refsAsStrings.at(j));
-                                               item->setData(0, Qt::UserRole, ref);
+                                               QString const val = refsNames.at(j).second;
+                                               child->setText(0, val);
+                                               child->setData(0, Qt::UserRole, ref);
                                                item->addChild(child);
                                }
                        }
@@ -499,8 +515,9 @@ void GuiRef::redoRefs()
                QList<QTreeWidgetItem *> refsItems;
                for (int i = 0; i < refsNames.size(); ++i) {
                        QTreeWidgetItem * item = new QTreeWidgetItem(refsTW);
-                       QString const & ref = refsNames.at(i);
-                       item->setText(0, refsAsStrings.at(i));
+                       QString const ref = refsNames.at(i).first;
+                       QString const val = refsNames.at(i).second;
+                       item->setText(0, val);
                        item->setData(0, Qt::UserRole, ref);
                        refsItems.append(item);
                }