diff options
author | con <[email protected]> | 2008-12-02 12:01:29 +0100 |
---|---|---|
committer | con <[email protected]> | 2008-12-02 12:01:29 +0100 |
commit | 05c35356abc31549c5db6eba31fb608c0365c2a0 (patch) | |
tree | be044530104267afaff13f8943889cb97f8c8bad /doc/example |
Initial import
Diffstat (limited to 'doc/example')
-rw-r--r-- | doc/example/textfinder/input.txt | 2 | ||||
-rw-r--r-- | doc/example/textfinder/main.cpp | 43 | ||||
-rw-r--r-- | doc/example/textfinder/textfinder.cpp | 75 | ||||
-rw-r--r-- | doc/example/textfinder/textfinder.h | 64 | ||||
-rw-r--r-- | doc/example/textfinder/textfinder.pro | 12 | ||||
-rw-r--r-- | doc/example/textfinder/textfinder.qrc | 5 | ||||
-rw-r--r-- | doc/example/textfinder/textfinder.ui | 78 |
7 files changed, 279 insertions, 0 deletions
diff --git a/doc/example/textfinder/input.txt b/doc/example/textfinder/input.txt new file mode 100644 index 00000000000..044545418a7 --- /dev/null +++ b/doc/example/textfinder/input.txt @@ -0,0 +1,2 @@ +These forms are processed at run-time to produce dynamically-generated user interfaces. In order to generate a form at run-time, a resource file containing a .ui file is needed. Applications that use the form handling classes need to be configured to be built against the QtUiTools module. This is done by including the following declaration in a qmake project file to ensure that the application is compiled and linked appropriately. A form loader object, provided by the QUiLoader class, is used to construct the user interface. This user interface +can be retrieved from any QIODevice; for example, a QFile object can be used to obtain a form stored in a project's resources. The QUiLoader::load() function takes the user interface description contained in the file and constructs the form widget.
\ No newline at end of file diff --git a/doc/example/textfinder/main.cpp b/doc/example/textfinder/main.cpp new file mode 100644 index 00000000000..7f8c63d951b --- /dev/null +++ b/doc/example/textfinder/main.cpp @@ -0,0 +1,43 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include <QtGui/QApplication> +#include "textfinder.h" + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(textfinder); + QApplication a(argc, argv); + TextFinder w; + w.show(); + return a.exec(); +} diff --git a/doc/example/textfinder/textfinder.cpp b/doc/example/textfinder/textfinder.cpp new file mode 100644 index 00000000000..a524f1c869a --- /dev/null +++ b/doc/example/textfinder/textfinder.cpp @@ -0,0 +1,75 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include <QtGui/QMessageBox> +#include <QtCore/QFile> +#include <QtCore/QTextStream> +#include "textfinder.h" + +TextFinder::TextFinder(QWidget *parent, Qt::WFlags flags) + : QWidget(parent, flags) +{ + ui.setupUi(this); + loadTextFile(); + isFirstTime = true; +} + +TextFinder::~TextFinder() +{ +} + +void TextFinder::loadTextFile() +{ + QFile inputFile(":/input.txt"); + inputFile.open(QIODevice::ReadOnly); + + QTextStream in(&inputFile); + QString line = in.readAll(); + inputFile.close(); + + ui.textEdit->setPlainText(line); + QTextCursor cursor = ui.textEdit->textCursor(); + cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1); +} + +void TextFinder::on_findButton_clicked() +{ + QString searchString = ui.lineEdit->text(); + QTextDocument *document = ui.textEdit->document(); + + bool found = false; + + ui.textEdit->find(searchString, QTextDocument::FindWholeWords); + QTextCursor cursor = ui.textEdit->textCursor(); + if (!cursor.isNull()) + found = true; +} diff --git a/doc/example/textfinder/textfinder.h b/doc/example/textfinder/textfinder.h new file mode 100644 index 00000000000..2563a2016ac --- /dev/null +++ b/doc/example/textfinder/textfinder.h @@ -0,0 +1,64 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information ([email protected]) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef TEXTFINDER_H +#define TEXTFINDER_H + +#include <QtGui/QWidget> +#include "ui_textfinder.h" + +class QPushButton; +class QTextEdit; +class QLineEdit; + +class TextFinder : public QWidget +{ + Q_OBJECT + +public: + TextFinder(QWidget *parent = 0, Qt::WFlags flags = 0); + ~TextFinder(); + +private slots: + void on_findButton_clicked(); + +private: + Ui::Form ui; + void loadTextFile(); + + QPushButton *ui_findButton; + QTextEdit *ui_textEdit; + QLineEdit *ui_lineEdit; + bool isFirstTime; +}; + +#endif // TEXTFINDER_H diff --git a/doc/example/textfinder/textfinder.pro b/doc/example/textfinder/textfinder.pro new file mode 100644 index 00000000000..4dd25ca402a --- /dev/null +++ b/doc/example/textfinder/textfinder.pro @@ -0,0 +1,12 @@ +TARGET = TextFinder +TEMPLATE = app + + +SOURCES += main.cpp\ + textfinder.cpp + +HEADERS += textfinder.h + +FORMS += textfinder.ui + +RESOURCES += textfinder.qrc diff --git a/doc/example/textfinder/textfinder.qrc b/doc/example/textfinder/textfinder.qrc new file mode 100644 index 00000000000..03cc512f4d6 --- /dev/null +++ b/doc/example/textfinder/textfinder.qrc @@ -0,0 +1,5 @@ + <!DOCTYPE RCC><RCC version="1.0"> + <qresource> + <file>input.txt</file> + </qresource> + </RCC>
\ No newline at end of file diff --git a/doc/example/textfinder/textfinder.ui b/doc/example/textfinder/textfinder.ui new file mode 100644 index 00000000000..1cb72c57471 --- /dev/null +++ b/doc/example/textfinder/textfinder.ui @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Form</class> + <widget class="QWidget" name="Form"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>378</width> + <height>158</height> + </rect> + </property> + <property name="windowTitle"> + <string>Find Text</string> + </property> + <layout class="QVBoxLayout"> + <item> + <layout class="QGridLayout"> + <item row="0" column="1"> + <widget class="QLineEdit" name="lineEdit"/> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="searchLabel"> + <property name="text"> + <string>&Keyword:</string> + </property> + <property name="buddy"> + <cstring>lineEdit</cstring> + </property> + </widget> + </item> + <item row="0" column="2"> + <widget class="QPushButton" name="findButton"> + <property name="text"> + <string>&Find</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QTextEdit" name="textEdit"/> + </item> + <item> + <spacer> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>16</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>lineEdit</sender> + <signal>returnPressed()</signal> + <receiver>findButton</receiver> + <slot>animateClick()</slot> + <hints> + <hint type="sourcelabel"> + <x>261</x> + <y>17</y> + </hint> + <hint type="destinationlabel"> + <x>320</x> + <y>17</y> + </hint> + </hints> + </connection> + </connections> +</ui> |