]> git.lyx.org Git - features.git/commitdiff
Fix bug 11099.
authorRichard Heck <rgheck@lyx.org>
Mon, 2 Apr 2018 02:00:41 +0000 (22:00 -0400)
committerRichard Heck <rgheck@lyx.org>
Mon, 2 Apr 2018 02:07:16 +0000 (22:07 -0400)
Adds simple search/find functionality to preamble.

src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiDocument.h
src/frontends/qt4/ui/PreambleUi.ui

index b6f1f12698b74754809485ac2609cfa2b9515465..3f2c89893563e6c91fa9549d6698b7d76723d7cd 100644 (file)
@@ -469,6 +469,29 @@ PreambleModule::PreambleModule(QWidget * parent)
        preambleTE->setWordWrapMode(QTextOption::NoWrap);
        setFocusProxy(preambleTE);
        connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
+       connect(findLE, SIGNAL(textEdited(const QString &)), this, SLOT(checkFindButton()));
+       connect(findButtonPB, SIGNAL(clicked()), this, SLOT(findText()));
+       connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
+       checkFindButton();
+}
+
+
+void PreambleModule::checkFindButton()
+{
+       findButtonPB->setEnabled(!findLE->text().isEmpty());
+}
+
+
+void PreambleModule::findText()
+{
+       bool const found = preambleTE->find(findLE->text());
+       if (!found) {
+               // wrap
+               QTextCursor qtcur = preambleTE->textCursor();
+               qtcur.movePosition(QTextCursor::Start);
+               preambleTE->setTextCursor(qtcur);
+               preambleTE->find(findLE->text());
+       }
 }
 
 
index 1fe1dc74a176fbd5c766b726767e280c237edce8..e4f32e25707e90506c69f9c4cdf267a51ce7cfbb 100644 (file)
@@ -332,10 +332,14 @@ private:
        void closeEvent(QCloseEvent *);
        void on_preambleTE_textChanged() { changed(); }
 
-private:
        typedef std::map<BufferId, std::pair<int,int> > Coords;
        Coords preamble_coords_;
        BufferId current_id_;
+
+private Q_SLOTS:
+       ///
+       void checkFindButton();
+       void findText();
 };
 
 
index b39f26173da89340e1039c4d2cd91b584b05453c..1bc1c52879ff791a3b941a58041290ccedf24724 100644 (file)
@@ -1,7 +1,8 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>PreambleUi</class>
- <widget class="QWidget" name="PreambleUi" >
-  <property name="geometry" >
+ <widget class="QWidget" name="PreambleUi">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <height>278</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string/>
   </property>
-  <layout class="QGridLayout" >
-   <property name="margin" >
+  <layout class="QGridLayout">
+   <property name="leftMargin">
     <number>11</number>
    </property>
-   <property name="spacing" >
+   <property name="topMargin">
+    <number>11</number>
+   </property>
+   <property name="rightMargin">
+    <number>11</number>
+   </property>
+   <property name="bottomMargin">
+    <number>11</number>
+   </property>
+   <property name="spacing">
     <number>6</number>
    </property>
-   <item row="0" column="0" >
-    <widget class="QTextEdit" name="preambleTE" >
-     <property name="acceptRichText" >
+   <item row="1" column="0">
+    <widget class="QLineEdit" name="findLE"/>
+   </item>
+   <item row="1" column="1">
+    <widget class="QPushButton" name="findButtonPB">
+     <property name="text">
+      <string>Find</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="0" colspan="2">
+    <widget class="QTextEdit" name="preambleTE">
+     <property name="acceptRichText">
       <bool>false</bool>
      </property>
     </widget>
@@ -29,7 +49,7 @@
   </layout>
  </widget>
  <includes>
-  <include location="local" >qt_i18n.h</include>
+  <include location="local">qt_i18n.h</include>
  </includes>
  <resources/>
  <connections/>