textfinder.cpp 2.06 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6 7 8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
9
** Commercial Usage
10
**
11 12 13 14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18 19 20 21 22 23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25 26
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
con's avatar
con committed
27
**
28
**************************************************************************/
29 30 31

#include "textfinder.h"

32
//! [1]
con's avatar
con committed
33 34
#include <QtCore/QFile>
#include <QtCore/QTextStream>
35
//! [1]
36
#include <QtGui/QMessageBox>
con's avatar
con committed
37

38
//! [3]
hjk's avatar
hjk committed
39 40
TextFinder::TextFinder(QWidget *parent)
    : QWidget(parent), ui(new Ui::TextFinder)
con's avatar
con committed
41
{
hjk's avatar
hjk committed
42
    ui->setupUi(this);
con's avatar
con committed
43 44
    loadTextFile();
}
45
//! [3]
con's avatar
con committed
46 47 48

TextFinder::~TextFinder()
{
hjk's avatar
hjk committed
49
    delete ui;
con's avatar
con committed
50 51
}

52
//! [0]
con's avatar
con committed
53 54 55 56 57 58 59 60 61
void TextFinder::loadTextFile()
{
    QFile inputFile(":/input.txt");
    inputFile.open(QIODevice::ReadOnly);

    QTextStream in(&inputFile);
    QString line = in.readAll();
    inputFile.close();

hjk's avatar
hjk committed
62 63
    ui->textEdit->setPlainText(line);
    QTextCursor cursor = ui->textEdit->textCursor();
con's avatar
con committed
64 65
    cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
}
66
//! [0]
con's avatar
con committed
67

68
//! [2]
con's avatar
con committed
69 70
void TextFinder::on_findButton_clicked()
{
hjk's avatar
hjk committed
71 72
    QString searchString = ui->lineEdit->text();
    ui->textEdit->find(searchString, QTextDocument::FindWholeWords);
con's avatar
con committed
73
}
74
//! [2]