Browse Source

Find text in XML

Kandrashin Denis 13 years ago
parent
commit
8d1b13c4e5
8 changed files with 111 additions and 23 deletions
  1. 12 0
      source/fb2code.cpp
  2. 3 0
      source/fb2code.hpp
  3. 55 8
      source/fb2dlgs.cpp
  4. 32 11
      source/fb2dlgs.hpp
  5. 3 0
      source/fb2find.ui
  6. 3 1
      source/fb2main.cpp
  7. 2 2
      source/fb2view.cpp
  8. 1 1
      source/fb2view.hpp

+ 12 - 0
source/fb2code.cpp

@@ -1,4 +1,5 @@
 #include "fb2code.hpp"
+#include "fb2dlgs.hpp"
 
 #ifdef FB2_USE_SCINTILLA
 
@@ -531,6 +532,17 @@ void Fb2CodeEdit::lineNumberAreaPaintEvent(QPaintEvent *event)
     }
 }
 
+bool Fb2CodeEdit::findText(const QString &exp, QTextDocument::FindFlags options)
+{
+    return QPlainTextEdit::find(exp, options);
+}
+
+void Fb2CodeEdit::find()
+{
+    Fb2CodeFindDlg dlg(*this);
+    dlg.exec();
+}
+
 void Fb2CodeEdit::zoomIn()
 {
     qreal ratio = zoomRatio * 1.1;

+ 3 - 0
source/fb2code.hpp

@@ -126,7 +126,10 @@ public:
 
     void zoomTo ( int size ) {}
 
+    bool findText(const QString &exp, QTextDocument::FindFlags options = 0);
+
 public slots:
+    void find();
     void zoomIn();
     void zoomOut();
     void zoomReset();

+ 55 - 8
source/fb2dlgs.cpp

@@ -1,32 +1,79 @@
 #include "fb2dlgs.hpp"
+#include "fb2code.hpp"
 #include "fb2view.hpp"
 #include "fb2utils.h"
 #include "ui_fb2find.h"
 #include "ui_fb2note.h"
 
 //---------------------------------------------------------------------------
-//  Fb2FindDlg
+//  Fb2CodeFindDlg
 //---------------------------------------------------------------------------
 
-Fb2FindDlg::Fb2FindDlg(QWidget *parent) :
-    QDialog(parent),
-    ui(new Ui::Fb2Find)
+Fb2CodeFindDlg::Fb2CodeFindDlg(Fb2CodeEdit &edit)
+    : QDialog(&edit)
+    , ui(new Ui::Fb2Find)
+    , m_edit(edit)
 {
     ui->setupUi(this);
+    ui->checkHigh->setText(tr("Complete words"));
+    connect(ui->btnFind, SIGNAL(clicked()), this, SLOT(find()));
 }
 
-Fb2FindDlg::~Fb2FindDlg()
+Fb2CodeFindDlg::~Fb2CodeFindDlg()
 {
     delete ui;
 }
 
+void Fb2CodeFindDlg::find()
+{
+    QString text = ui->editText->text();
+    if (text.isEmpty()) return;
+    QTextDocument::FindFlags options = 0;
+    if (ui->radioUp->isChecked()) options |= QTextDocument::FindBackward;
+    if (ui->checkCase->isChecked()) options |= QTextDocument::FindCaseSensitively;
+    if (ui->checkHigh->isChecked()) options |= QTextDocument::FindWholeWords;
+
+    m_edit.findText(text, options);
+}
+
+//---------------------------------------------------------------------------
+//  Fb2TextFindDlg
+//---------------------------------------------------------------------------
+
+Fb2TextFindDlg::Fb2TextFindDlg(Fb2WebView &edit)
+    : QDialog(&edit)
+    , ui(new Ui::Fb2Find)
+    , m_edit(edit)
+{
+    ui->setupUi(this);
+    connect(ui->btnFind, SIGNAL(clicked()), this, SLOT(find()));
+}
+
+Fb2TextFindDlg::~Fb2TextFindDlg()
+{
+    m_edit.findText(QString(), QWebPage::HighlightAllOccurrences);
+    delete ui;
+}
+
+void Fb2TextFindDlg::find()
+{
+    QString text = ui->editText->text();
+    if (text.isEmpty()) return;
+    QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
+    if (ui->radioUp->isChecked()) options |= QWebPage::FindBackward;
+    if (ui->checkCase->isChecked()) options |= QWebPage::FindCaseSensitively;
+    if (ui->checkHigh->isChecked()) options |= QWebPage::HighlightAllOccurrences;
+
+    m_edit.findText(text, options);
+}
+
 //---------------------------------------------------------------------------
 //  Fb2NoteDlg
 //---------------------------------------------------------------------------
 
-Fb2NoteDlg::Fb2NoteDlg(Fb2WebView &view, QWidget *parent) :
-    QDialog(parent),
-    ui(new Ui::Fb2Note)
+Fb2NoteDlg::Fb2NoteDlg(Fb2WebView &view)
+    : QDialog(&view)
+    , ui(new Ui::Fb2Note)
 {
     ui->setupUi(this);
     ui->m_key->addItem(tr("<create new>"));

+ 32 - 11
source/fb2dlgs.hpp

@@ -3,35 +3,56 @@
 
 #include <QDialog>
 
+class Fb2CodeEdit;
 class Fb2WebView;
 
 namespace Ui {
-class Fb2Note;
 class Fb2Find;
+class Fb2Note;
 }
 
-class Fb2NoteDlg : public QDialog
+class Fb2CodeFindDlg : public QDialog
 {
     Q_OBJECT
-    
+
 public:
-    explicit Fb2NoteDlg(Fb2WebView &view, QWidget *parent = 0);
-    virtual ~Fb2NoteDlg();
-    
+    explicit Fb2CodeFindDlg(Fb2CodeEdit &edit);
+    virtual ~Fb2CodeFindDlg();
+
+private slots:
+    void find();
+
 private:
-    Ui::Fb2Note *ui;
+    Ui::Fb2Find * ui;
+    Fb2CodeEdit & m_edit;
 };
 
-class Fb2FindDlg : public QDialog
+class Fb2TextFindDlg : public QDialog
 {
     Q_OBJECT
 
 public:
-    explicit Fb2FindDlg(QWidget *parent = 0);
-    virtual ~Fb2FindDlg();
+    explicit Fb2TextFindDlg(Fb2WebView &edit);
+    virtual ~Fb2TextFindDlg();
+
+private slots:
+    void find();
+
+private:
+    Ui::Fb2Find * ui;
+    Fb2WebView & m_edit;
+};
+
+class Fb2NoteDlg : public QDialog
+{
+    Q_OBJECT
+    
+public:
+    explicit Fb2NoteDlg(Fb2WebView &view);
+    virtual ~Fb2NoteDlg();
 
 private:
-    Ui::Fb2Find *ui;
+    Ui::Fb2Note * ui;
 };
 
 #endif // FB2DLGS_H

+ 3 - 0
source/fb2find.ui

@@ -101,6 +101,9 @@
         <property name="text">
          <string>&amp;Down</string>
         </property>
+        <property name="checked">
+         <bool>true</bool>
+        </property>
        </widget>
       </item>
      </layout>

+ 3 - 1
source/fb2main.cpp

@@ -634,6 +634,8 @@ void Fb2MainWindow::viewCode()
     connect(actionCopy, SIGNAL(triggered()), codeEdit, SLOT(copy()));
     connect(actionPaste, SIGNAL(triggered()), codeEdit, SLOT(paste()));
 
+    connect(actionFind, SIGNAL(triggered()), codeEdit, SLOT(find()));
+
     connect(actionZoomIn, SIGNAL(triggered()), codeEdit, SLOT(zoomIn()));
     connect(actionZoomOut, SIGNAL(triggered()), codeEdit, SLOT(zoomOut()));
     connect(actionZoomReset, SIGNAL(triggered()), codeEdit, SLOT(zoomReset()));
@@ -666,7 +668,7 @@ void Fb2MainWindow::viewText()
     connect(actionCopy, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Copy), SIGNAL(triggered()));
     connect(actionPaste, SIGNAL(triggered()), textEdit->pageAction(QWebPage::Paste), SIGNAL(triggered()));
 
-    connect(actionFind, SIGNAL(triggered()), textEdit, SLOT(findText()));
+    connect(actionFind, SIGNAL(triggered()), textEdit, SLOT(find()));
 
     connect(actionTextBold, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleBold), SIGNAL(triggered()));
     connect(actionTextItalic, SIGNAL(triggered()), textEdit->pageAction(QWebPage::ToggleItalic), SIGNAL(triggered()));

+ 2 - 2
source/fb2view.cpp

@@ -272,9 +272,9 @@ bool Fb2WebView::SupChecked()
     return pageAction(QWebPage::ToggleSuperscript)->isChecked();
 }
 
-void Fb2WebView::findText()
+void Fb2WebView::find()
 {
-    Fb2FindDlg dlg(this);
+    Fb2TextFindDlg dlg(*this);
     dlg.exec();
 }
 

+ 1 - 1
source/fb2view.hpp

@@ -91,7 +91,6 @@ public slots:
     void data(QString name, QByteArray data);
     void html(QString name, QString html);
     void linkHovered(const QString &link, const QString &title, const QString &textContent);
-    void findText();
     void showInspector();
     void insertImage();
     void insertNote();
@@ -99,6 +98,7 @@ public slots:
     void zoomIn();
     void zoomOut();
     void zoomReset();
+    void find();
 
 private slots:
     void fixContents();