]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiRef.cpp
Use QFontMetrics information for underlines (and friends) width and position
[lyx.git] / src / frontends / qt4 / GuiRef.cpp
index c79dcb913949198997d81c9a408fc7d5ef6ae716..1150d586b20efd01204755a944abd551d4f4c3f6 100644 (file)
@@ -61,9 +61,9 @@ GuiRef::GuiRef(GuiView & lv)
                this, SLOT(changed_adaptor()));
        connect(referenceED, SIGNAL(textChanged(QString)),
                this, SLOT(changed_adaptor()));
-       connect(findLE, SIGNAL(textEdited(QString)), 
+       connect(findLE, SIGNAL(textEdited(QString)),
                this, SLOT(filterLabels()));
-       connect(csFindCB, SIGNAL(clicked()), 
+       connect(csFindCB, SIGNAL(clicked()),
                this, SLOT(filterLabels()));
        connect(nameED, SIGNAL(textChanged(QString)),
                this, SLOT(changed_adaptor()));
@@ -162,6 +162,11 @@ void GuiRef::refSelected(QTreeWidgetItem * sel)
        if (isBufferReadonly())
                return;
 
+       if (sel->childCount()) {
+               sel->setExpanded(false);
+               return;
+       }
+
 /*     int const cur_item = refsTW->currentRow();
        bool const cur_item_selected = cur_item >= 0 ?
                refsLB->isSelected(cur_item) : false;*/
@@ -246,7 +251,7 @@ void GuiRef::updateContents()
 
        // insert buffer list
        bufferCO->clear();
-       FileNameList const & buffers = theBufferList().fileNames();
+       FileNameList const buffers(theBufferList().fileNames());
        for (FileNameList::const_iterator it = buffers.begin();
             it != buffers.end(); ++it) {
                bufferCO->addItem(toqstr(makeDisplayPath(it->absFileName())));
@@ -350,19 +355,29 @@ void GuiRef::redoRefs()
        QStringList refsStrings;
        QStringList refsCategories;
        vector<docstring>::const_iterator iter;
+       bool noprefix = false;
        for (iter = refs_.begin(); iter != refs_.end(); ++iter) {
                QString const lab = toqstr(*iter);
                refsStrings.append(lab);
-               if (groupCB->isChecked() && lab.contains(":")) {
-                       QString const pref = lab.split(':')[0];
-                       if (!pref.isEmpty() && !refsCategories.contains(pref))
-                                 refsCategories.append(pref);
+               if (groupCB->isChecked()) {
+                       if (lab.contains(":")) {
+                               QString const pref = lab.split(':')[0];
+                               if (!refsCategories.contains(pref)) {
+                                       if (!pref.isEmpty())
+                                               refsCategories.append(pref);
+                                       else
+                                               noprefix = true;
+                               }
+                       }
+                       else
+                               noprefix = true;
                }
        }
        // sort categories case-intensively
        qSort(refsCategories.begin(), refsCategories.end(),
              caseInsensitiveLessThan /*defined above*/);
-       refsCategories.insert(0, qt_("<No prefix>"));
+       if (noprefix)
+               refsCategories.insert(0, qt_("<No prefix>"));
 
        if (sortCB->isEnabled() && sortCB->isChecked()) {
                if(caseSensitiveCB->isEnabled() && caseSensitiveCB->isChecked())
@@ -371,7 +386,7 @@ void GuiRef::redoRefs()
                        qSort(refsStrings.begin(), refsStrings.end(),
                              caseInsensitiveLessThan /*defined above*/);
        }
-       
+
        if (groupCB->isChecked()) {
                QList<QTreeWidgetItem *> refsCats;
                for (int i = 0; i < refsCategories.size(); ++i) {
@@ -382,11 +397,11 @@ void GuiRef::redoRefs()
                                QString const ref = refsStrings.at(i);
                                if ((ref.startsWith(cat + QString(":")))
                                    || (cat == qt_("<No prefix>")
-                                       && !ref.contains(":"))) {
-                                       QTreeWidgetItem * child =
-                                               new QTreeWidgetItem(item);
-                                       child->setText(0, ref);
-                                       item->addChild(child);
+                                      && (!ref.mid(1).contains(":") || ref.left(1).contains(":")))) {
+                                               QTreeWidgetItem * child =
+                                                       new QTreeWidgetItem(item);
+                                               child->setText(0, ref);
+                                               item->addChild(child);
                                }
                        }
                        refsCats.append(item);
@@ -413,7 +428,7 @@ void GuiRef::redoRefs()
                QTreeWidgetItemIterator it(refsTW);
                while (*it) {
                        if ((*it)->text(0) == textToFind) {
-                               refsTW->setCurrentItem(*it);
+                               refsTW->setCurrentItem(*it);
                                refsTW->setItemSelected(*it, !newInset);
                                //Make sure selected item is visible
                                refsTW->scrollToItem(*it);
@@ -440,13 +455,15 @@ void GuiRef::updateRefs()
        refs_.clear();
        int const the_buffer = bufferCO->currentIndex();
        if (the_buffer != -1) {
-               FileName const & name = theBufferList().fileNames()[the_buffer];
+               FileNameList const names(theBufferList().fileNames());
+               FileName const & name = names[the_buffer];
                Buffer const * buf = theBufferList().getBuffer(name);
                buf->getLabelList(refs_);
        }
        sortCB->setEnabled(!refs_.empty());
        caseSensitiveCB->setEnabled(sortCB->isEnabled() && sortCB->isChecked());
        refsTW->setEnabled(!refs_.empty());
+       groupCB->setEnabled(!refs_.empty());
        // refsTW should only be the focus proxy when it is enabled
        setFocusProxy(refs_.empty() ? 0 : refsTW);
        gotoPB->setEnabled(!refs_.empty());