Fix bug 11099.

Adds simple search/find functionality to preamble.
This commit is contained in:
Richard Heck 2018-04-01 22:18:04 -04:00
parent bcd1814746
commit 2bb9d49527
3 changed files with 59 additions and 12 deletions

View 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());
}
}

View 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();
};

View 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>
@ -9,19 +10,38 @@
<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/>