1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the assistant application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
30
#include "finddialog.h"
31
#include "mainwindow.h"
32
#include "tabbedbrowser.h"
33
#include "helpwindow.h"
35
#include <qtextbrowser.h>
36
#include <qtextcursor.h>
37
#include <qstatusbar.h>
38
#include <qlineedit.h>
39
#include <qdatetime.h>
40
#include <qgridlayout.h>
43
FindDialog::FindDialog(MainWindow *parent)
46
contentsWidget = new QWidget(this);
47
ui.setupUi(contentsWidget);
49
QVBoxLayout *l = new QVBoxLayout(this);
52
l->addWidget(contentsWidget);
58
sb = new QStatusBar(this);
61
sb->showMessage(tr("Enter the text you are looking for."));
63
connect(ui.findButton, SIGNAL(clicked()), this, SLOT(findButtonClicked()));
64
connect(ui.closeButton, SIGNAL(clicked()), this, SLOT(reject()));
67
FindDialog::~FindDialog()
71
void FindDialog::findButtonClicked()
73
doFind(ui.radioForward->isChecked());
76
void FindDialog::doFind(bool forward)
78
QTextBrowser *browser = static_cast<QTextBrowser*>(mainWindow()->browsers()->currentBrowser());
81
if (ui.comboFind->currentText() != findExpr || lastBrowser != browser)
83
findExpr = ui.comboFind->currentText();
85
QTextDocument::FindFlags flags = 0;
87
if (ui.checkCase->isChecked())
88
flags |= QTextDocument::FindCaseSensitively;
90
if (ui.checkWords->isChecked())
91
flags |= QTextDocument::FindWholeWords;
93
QTextCursor c = browser->textCursor();
94
if (!c.hasSelection()) {
96
c.movePosition(QTextCursor::Start);
98
c.movePosition(QTextCursor::End);
100
browser->setTextCursor(c);
103
QTextDocument::FindFlags options;
104
if (forward == false)
105
flags |= QTextDocument::FindBackward;
107
QTextCursor found = browser->document()->find(findExpr, c, flags);
108
if (found.isNull()) {
111
statusMessage(tr("Search reached end of the document"));
113
statusMessage(tr("Search reached start of the document"));
115
statusMessage(tr( "Text not found" ));
118
browser->setTextCursor(found);
120
onceFound |= !found.isNull();
121
lastBrowser = browser;
124
bool FindDialog::hasFindExpression() const
126
return !findExpr.isEmpty();
129
void FindDialog::statusMessage(const QString &message)
132
sb->showMessage(message);
134
static_cast<MainWindow*>(parent())->statusBar()->showMessage(message, 2000);
137
MainWindow *FindDialog::mainWindow() const
139
return static_cast<MainWindow*>(parentWidget());
142
void FindDialog::reset()
144
ui.comboFind->setFocus();
145
ui.comboFind->lineEdit()->setSelection(
146
0, ui.comboFind->lineEdit()->text().length());