summaryrefslogtreecommitdiffstats
path: root/examples/uitools/textfinder
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /examples/uitools/textfinder
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'examples/uitools/textfinder')
-rw-r--r--examples/uitools/textfinder/forms/input.txt9
-rw-r--r--examples/uitools/textfinder/forms/textfinder.ui89
-rw-r--r--examples/uitools/textfinder/main.cpp55
-rw-r--r--examples/uitools/textfinder/textfinder.cpp155
-rw-r--r--examples/uitools/textfinder/textfinder.h74
-rw-r--r--examples/uitools/textfinder/textfinder.pro12
-rw-r--r--examples/uitools/textfinder/textfinder.qrc6
7 files changed, 400 insertions, 0 deletions
diff --git a/examples/uitools/textfinder/forms/input.txt b/examples/uitools/textfinder/forms/input.txt
new file mode 100644
index 0000000000..29dfe5d6c6
--- /dev/null
+++ b/examples/uitools/textfinder/forms/input.txt
@@ -0,0 +1,9 @@
+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/examples/uitools/textfinder/forms/textfinder.ui b/examples/uitools/textfinder/forms/textfinder.ui
new file mode 100644
index 0000000000..af05192dbd
--- /dev/null
+++ b/examples/uitools/textfinder/forms/textfinder.ui
@@ -0,0 +1,89 @@
+<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" >
+ <property name="margin" >
+ <number>9</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <item>
+ <layout class="QGridLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <property name="spacing" >
+ <number>6</number>
+ </property>
+ <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>&amp;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>&amp;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" >
+ <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>
diff --git a/examples/uitools/textfinder/main.cpp b/examples/uitools/textfinder/main.cpp
new file mode 100644
index 0000000000..2fe9b715d1
--- /dev/null
+++ b/examples/uitools/textfinder/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include "textfinder.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(textfinder);
+ QApplication app(argc, argv);
+
+ TextFinder *textFinder = new TextFinder;
+ textFinder->show();
+
+ return app.exec();
+}
+//! [0]
diff --git a/examples/uitools/textfinder/textfinder.cpp b/examples/uitools/textfinder/textfinder.cpp
new file mode 100644
index 0000000000..0a69d5e2dd
--- /dev/null
+++ b/examples/uitools/textfinder/textfinder.cpp
@@ -0,0 +1,155 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtUiTools>
+#include <QtGui>
+#include "textfinder.h"
+
+//! [0]
+TextFinder::TextFinder(QWidget *parent)
+ : QWidget(parent)
+{
+ QWidget *formWidget = loadUiFile();
+
+//! [1]
+ ui_findButton = findChild<QPushButton*>("findButton");
+ ui_textEdit = findChild<QTextEdit*>("textEdit");
+ ui_lineEdit = findChild<QLineEdit*>("lineEdit");
+//! [0] //! [1]
+
+//! [2]
+ QMetaObject::connectSlotsByName(this);
+//! [2]
+
+//! [3a]
+ loadTextFile();
+//! [3a]
+
+//! [3b]
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addWidget(formWidget);
+ setLayout(layout);
+//! [3b]
+
+//! [3c]
+ setWindowTitle(tr("Text Finder"));
+ isFirstTime = true;
+}
+//! [3c]
+
+//! [4]
+QWidget* TextFinder::loadUiFile()
+{
+ QUiLoader loader;
+
+ QFile file(":/forms/textfinder.ui");
+ file.open(QFile::ReadOnly);
+
+ QWidget *formWidget = loader.load(&file, this);
+ file.close();
+
+ return formWidget;
+}
+//! [4]
+
+//! [5]
+void TextFinder::loadTextFile()
+{
+ QFile inputFile(":/forms/input.txt");
+ inputFile.open(QIODevice::ReadOnly);
+ QTextStream in(&inputFile);
+ QString line = in.readAll();
+ inputFile.close();
+
+ ui_textEdit->append(line);
+ ui_textEdit->setUndoRedoEnabled(false);
+ ui_textEdit->setUndoRedoEnabled(true);
+}
+//! [5]
+
+//! [6] //! [7]
+void TextFinder::on_findButton_clicked()
+{
+ QString searchString = ui_lineEdit->text();
+ QTextDocument *document = ui_textEdit->document();
+
+ bool found = false;
+
+ if (isFirstTime == false)
+ document->undo();
+
+ if (searchString.isEmpty()) {
+ QMessageBox::information(this, tr("Empty Search Field"),
+ "The search field is empty. Please enter a word and click Find.");
+ } else {
+
+ QTextCursor highlightCursor(document);
+ QTextCursor cursor(document);
+
+ cursor.beginEditBlock();
+//! [6]
+
+ QTextCharFormat plainFormat(highlightCursor.charFormat());
+ QTextCharFormat colorFormat = plainFormat;
+ colorFormat.setForeground(Qt::red);
+
+ while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
+ highlightCursor = document->find(searchString, highlightCursor, QTextDocument::FindWholeWords);
+
+ if (!highlightCursor.isNull()) {
+ found = true;
+ highlightCursor.movePosition(QTextCursor::WordRight,
+ QTextCursor::KeepAnchor);
+ highlightCursor.mergeCharFormat(colorFormat);
+ }
+ }
+
+//! [8]
+ cursor.endEditBlock();
+//! [7] //! [9]
+ isFirstTime = false;
+
+ if (found == false) {
+ QMessageBox::information(this, tr("Word Not Found"),
+ "Sorry, the word cannot be found.");
+ }
+ }
+}
+//! [8] //! [9]
diff --git a/examples/uitools/textfinder/textfinder.h b/examples/uitools/textfinder/textfinder.h
new file mode 100644
index 0000000000..c3cd030cb2
--- /dev/null
+++ b/examples/uitools/textfinder/textfinder.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TEXTFINDER_H
+#define TEXTFINDER_H
+
+#include <QWidget>
+
+QT_BEGIN_NAMESPACE
+class QPushButton;
+class QTextEdit;
+class QLineEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class TextFinder : public QWidget
+{
+ Q_OBJECT
+
+public:
+ TextFinder(QWidget *parent = 0);
+
+private slots:
+ void on_findButton_clicked();
+
+private:
+ QWidget* loadUiFile();
+ void loadTextFile();
+
+ QPushButton *ui_findButton;
+ QTextEdit *ui_textEdit;
+ QLineEdit *ui_lineEdit;
+ bool isFirstTime;
+};
+//! [0]
+
+#endif
diff --git a/examples/uitools/textfinder/textfinder.pro b/examples/uitools/textfinder/textfinder.pro
new file mode 100644
index 0000000000..6ec523b37b
--- /dev/null
+++ b/examples/uitools/textfinder/textfinder.pro
@@ -0,0 +1,12 @@
+CONFIG += uitools
+HEADERS = textfinder.h
+RESOURCES = textfinder.qrc
+SOURCES = textfinder.cpp main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/uitools/textfinder
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro forms
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/uitools/textfinder
+INSTALLS += target sources
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
diff --git a/examples/uitools/textfinder/textfinder.qrc b/examples/uitools/textfinder/textfinder.qrc
new file mode 100644
index 0000000000..a4cea8a77d
--- /dev/null
+++ b/examples/uitools/textfinder/textfinder.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>forms/textfinder.ui</file>
+ <file>forms/input.txt</file>
+</qresource>
+</RCC> \ No newline at end of file