1 /* This file is part of the KDE project
2 * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "KoFindStrategy.h"
21
22 #include <kfind.h>
23 #include <kfinddialog.h>
24 #include <kmessagebox.h>
25 #include <klocalizedstring.h>
26
27 #include "FindDirection_p.h"
28
29 class NonClosingFindDialog : public KFindDialog
30 {
31 Q_OBJECT
32 public:
NonClosingFindDialog(QWidget * parent)33 NonClosingFindDialog(QWidget *parent)
34 : KFindDialog(parent) {}
35
accept()36 void accept() override {}
37 };
38
KoFindStrategy(QWidget * parent)39 KoFindStrategy::KoFindStrategy(QWidget *parent)
40 : m_dialog(new NonClosingFindDialog(parent))
41 , m_matches(0)
42 {
43 m_dialog->setOptions(KFind::FromCursor);
44 }
45
~KoFindStrategy()46 KoFindStrategy::~KoFindStrategy()
47 {
48 if (m_dialog->parent() == 0)
49 delete m_dialog;
50 }
51
dialog() const52 KFindDialog *KoFindStrategy::dialog() const
53 {
54 return m_dialog;
55 }
56
reset()57 void KoFindStrategy::reset()
58 {
59 m_matches = 0;
60 }
61
displayFinalDialog()62 void KoFindStrategy::displayFinalDialog()
63 {
64 KMessageBox::information(m_dialog, m_matches ? i18np("Found 1 match", "Found %1 matches", m_matches) : i18n("Found no match"));
65 reset();
66 }
67
foundMatch(QTextCursor & cursor,FindDirection * findDirection)68 bool KoFindStrategy::foundMatch(QTextCursor &cursor, FindDirection *findDirection)
69 {
70 ++m_matches;
71 findDirection->select(cursor);
72 return false;
73 }
74 #include "KoFindStrategy.moc"
75