summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2011-03-02 17:49:28 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2011-03-02 21:17:57 -0300
commitb94f5359b08e3984c039023b337bfd248a984aee (patch)
tree0058d4ae3a40b2316089eb8ffcbe11a40a59b36b
parent97a16f10ab0d0f608a00d3b05497cc6c4a464d2b (diff)
downloadpyside-b94f5359b08e3984c039023b337bfd248a984aee.tar.gz
pyside-b94f5359b08e3984c039023b337bfd248a984aee.tar.xz
pyside-b94f5359b08e3984c039023b337bfd248a984aee.zip
Added some missing code snippets to PySide documentation.
-rw-r--r--doc/codesnippets/doc/src/snippets/audio/main.cpp55
-rw-r--r--doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc18
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp17
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp16
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp6
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp16
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp35
-rw-r--r--doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp114
-rw-r--r--doc/codesnippets/examples/declarative/cppextensions/plugins/plugins.qml52
-rw-r--r--doc/codesnippets/examples/dialogs/tabdialog/tabdialog.cpp144
-rw-r--r--doc/codesnippets/examples/uitools/textfinder/textfinder.cpp131
-rw-r--r--doc/codesnippets/webkitsnippets/webelement/main.cpp65
12 files changed, 596 insertions, 73 deletions
diff --git a/doc/codesnippets/doc/src/snippets/audio/main.cpp b/doc/codesnippets/doc/src/snippets/audio/main.cpp
new file mode 100644
index 0000000..5b3e9eb
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/audio/main.cpp
@@ -0,0 +1,55 @@
+
+class Window2 (QWidget):
+//![0]
+ @Slot(QAudio.State)
+ def stateChanged(self, newState):
+ if newState == QAudio.StopState:
+ if self.input.error() != QAudio.NoError:
+ # Error handling
+//![0]
+
+class Window (QWidget):
+ def __init__(self):
+ QWidget.__init__(self)
+ self.output = QAudioOutput()
+ self.output.stateChanged[QAudio.State].connect(self.stateChanged)
+
+ def setupFormat(self):
+//![1]
+ format = QAudioFormat()
+ format.setFrequency(44100)
+//![1]
+ format.setChannels(2)
+ format.setSampleSize(16)
+ format.setCodec("audio/pcm")
+ format.setByteOrder(QAudioFormat.LittleEndian)
+//![2]
+ format.setSampleType(QAudioFormat.SignedInt)
+
+ info = QAudioDeviceInfo(QAudioDeviceInfo.defaultOutputDevice())
+
+ if not info.isFormatSupported(format):
+ format = info.nearestFormat(format)
+//![2]
+
+//![3]
+ @Slot(QAudio.State)
+ def stateChanged(self, newState):
+ if newState == QAudio.StopState:
+ if self.output.error() != QAudio.NoError:
+ # Perform error handling
+ else:
+ # Normal stop
+//![3]
+
+ # Handle
+ elif newState == QAudio.ActiveState:
+ # Handle active state...
+
+app = QApplication(sys.argv)
+
+window = Window()
+window.show()
+sys.exit(app.exec_())
+
+
diff --git a/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc b/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc
new file mode 100644
index 0000000..6bd0bce
--- /dev/null
+++ b/doc/codesnippets/doc/src/snippets/code/doc_src_qnamespace.qdoc
@@ -0,0 +1,18 @@
+
+//! [0]
+QObject::connect: Cannot queue arguments of type 'MyType'
+//! [0]
+
+
+//! [1]
+# An important event
+ImportantEventPriority = Qt.HighEventPriority
+# A more important event
+MoreImportantEventPriority = ImportantEventPriority + 1
+# A critical event
+CriticalEventPriority = 100 * MoreImportantEventPriority
+# Not that important
+StatusEventPriority = Qt.LowEventPriority
+# These are less important than Status events
+IdleProcessingDoneEventPriority = StatusEventPriority - 1
+//! [1]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp b/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp
index 4fc5541..c2c1647 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp
@@ -145,7 +145,7 @@ def dragEnterEvent(self, event):
def itemChange(self, change, value):
if change == ItemPositionChange && scene():
# value is the new position.
- rect = scene()->sceneRect()
+ rect = scene().sceneRect()
if !rect.contains(value):
# Keep the item inside the scene rect.
value.setX(qMin(rect.right(), qMax(value.x(), rect.left())))
@@ -182,3 +182,18 @@ class CustomItem(QGraphicsItem):
return self.Type
...
//! [QGraphicsItem type]
+
+//! [18]
+class QGraphicsPathItem (QAbstractGraphicsShapeItem):
+ Type = 2
+
+ def type(self):
+ return QGraphicsPathItem.Type
+# ...
+//! [18]
+
+//! [19]
+xform = item.deviceTransform(view.viewportTransform())
+deviceRect = xform.mapRect(rect).toAlignedRect()
+view.viewport().scroll(dx, dy, deviceRect)
+//! [19]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp b/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp
index 5e8f1da..efe7be4 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_gui_image_qicon.cpp
@@ -12,15 +12,21 @@ button.setIcon(QIcon())
//! [2]
def drawIcon(self, painter, pos):
enabledStatus = QIcon.Normal
- if !isEnabled():
+ if not isEnabled():
enabledStatus = QIcon::Disabled
onOff = QIcon.On
- if !isOn():
+ if not isOn():
onOff = QIcon.Off
- pixmap = icon.pixmap(QSize(22, 22),
- enabledStatus,
- onOff)
+ pixmap = self.icon.pixmap(QSize(22, 22), enabledStatus, onOff)
painter.drawPixmap(pos, pixmap)
//! [2]
+
+//! [3]
+ undoicon = QIcon.fromTheme("edit-undo")
+//! [3]
+
+//! [4]
+ undoicon = QIcon.fromTheme("edit-undo", QIcon(":/undo.png"))
+//! [4]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp b/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp
index baa5337..b76c7d3 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_gui_image_qpixmap.cpp
@@ -10,3 +10,9 @@ static const char * const start_xpm[]={
myPixmap = QPixmap()
myPixmap.setMask(myPixmap.createHeuristicMask())
//! [1]
+
+//! [2]
+pixmap = QPixmap("background.png")
+exposed = QRegion()
+pixmap.scroll(10, 10, pixmap.rect(), exposed)
+//! [2]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp b/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp
index dca1292..c9b7d91 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_gui_painting_qpainter.cpp
@@ -193,3 +193,19 @@ image = QImage(":/images/myImage.png")
painter = QPainter(self)
painter.drawImage(target, image, source)
//! [20]
+
+//! [21]
+painter = QPainter(self)
+painter.fillRect(0, 0, 128, 128, Qt.green)
+painter.beginNativePainting()
+
+glEnable(GL_SCISSOR_TEST)
+glScissor(0, 0, 64, 64)
+
+glClearColor(1, 0, 0, 1)
+glClear(GL_COLOR_BUFFER_BIT)
+
+glDisable(GL_SCISSOR_TEST)
+
+painter.endNativePainting()
+//! [21]
diff --git a/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp b/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp
index 73b58c1..9d0ed1c 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_network_access_qnetworkaccessmanager.cpp
@@ -1,21 +1,36 @@
//! [0]
manager = QNetworkAccessManager(self)
-connect(manager, SIGNAL(finished("QNetworkReply*")),
- self, SLOT(replyFinished("QNetworkReply*")))
+manager.finished[QNetworkReply].connect(self.replyFinished)
-manager.get(QNetworkRequest(QUrl("http://qtsoftware.com")))
+manager.get(QNetworkRequest(QUrl("http://qt.nokia.com")))
//! [0]
//! [1]
-QNetworkRequest request
-request.setUrl(QUrl("http://qtsoftware.com"))
+request = QNetworkRequest()
+request.setUrl(QUrl("http://qt.nokia.com"))
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0")
reply = manager.get(request)
-connect(reply, SIGNAL("readyRead()"), self, SLOT("slotReadyRead()"))
-connect(reply, SIGNAL(error("QNetworkReply.NetworkError")),
- self, SLOT(slotError("QNetworkReply.NetworkError")))
-connect(reply, SIGNAL(sslErrors("QList<QSslError>")),
- self, SLOT(slotSslErrors("QList<QSslError>")))
+reply.readyRead.connect(self.slotReadyRead)
+reply.error[QNetworkReply.NetworkError].connect(self..slotError)
+reply.sslErrors.connect(self.slotSslErrors)
//! [1]
+
+//! [2]
+manager = QNetworkConfigurationManager()
+networkAccessManager.setConfiguration(manager.defaultConfiguration())
+//! [2]
+
+//! [3]
+networkAccessManager.setConfiguration(QNetworkConfiguration())
+//! [3]
+
+//! [4]
+networkAccessManager.setNetworkAccessible(QNetworkAccessManager.NotAccessible)
+//! [4]
+
+//! [5]
+networkAccessManager.setNetworkAccessible(QNetworkAccessManager.Accessible)
+//! [5]
+
diff --git a/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp b/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp
index c143e33..aed6526 100644
--- a/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp
+++ b/doc/codesnippets/doc/src/snippets/code/src_qtestlib_qtestcase.cpp
@@ -1,84 +1,81 @@
-void wrapInFunction()
-{
-
//! [0]
-QVERIFY(1 + 1 == 2);
+QVERIFY(1 + 1 == 2)
//! [0]
//! [1]
-QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occured.");
+QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occured.")
//! [1]
//! [2]
-QCOMPARE(QString("hello").toUpper(), QString("HELLO"));
+QCOMPARE(QString("hello").toUpper(), QString("HELLO"))
//! [2]
//! [3]
-void TestQString::toInt_data()
+void TestQString.toInt_data()
{
- QTest::addColumn<QString>("aString");
- QTest::addColumn<int>("expected");
+ QTest.addColumn<QString>("aString")
+ QTest.addColumn<int>("expected")
- QTest::newRow("positive value") << "42" << 42;
- QTest::newRow("negative value") << "-42" << -42;
- QTest::newRow("zero") << "0" << 0;
+ QTest.newRow("positive value") << "42" << 42
+ QTest.newRow("negative value") << "-42" << -42
+ QTest.newRow("zero") << "0" << 0
}
//! [3]
//! [4]
-void TestQString::toInt()
+void TestQString.toInt()
{
- QFETCH(QString, aString);
- QFETCH(int, expected);
+ QFETCH(QString, aString)
+ QFETCH(int, expected)
- QCOMPARE(aString.toInt(), expected);
+ QCOMPARE(aString.toInt(), expected)
}
//! [4]
//! [5]
if (sizeof(int) != 4)
- QFAIL("This test has not been ported to this platform yet.");
+ QFAIL("This test has not been ported to this platform yet.")
//! [5]
//! [6]
-QFETCH(QString, myString);
-QCOMPARE(QString("hello").toUpper(), myString);
+QFETCH(QString, myString)
+QCOMPARE(QString("hello").toUpper(), myString)
//! [6]
//! [7]
-QTEST(QString("hello").toUpper(), "myString");
+QTEST(QString("hello").toUpper(), "myString")
//! [7]
//! [8]
-if (!QSqlDatabase::drivers().contains("SQLITE"))
- QSKIP("This test requires the SQLITE database driver", SkipAll);
+if (!QSqlDatabase.drivers().contains("SQLITE"))
+ QSKIP("This test requires the SQLITE database driver", SkipAll)
//! [8]
//! [9]
-QEXPECT_FAIL("", "Will fix in the next release", Continue);
-QCOMPARE(i, 42);
-QCOMPARE(j, 43);
+QEXPECT_FAIL("", "Will fix in the next release", Continue)
+QCOMPARE(i, 42)
+QCOMPARE(j, 43)
//! [9]
//! [10]
-QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort);
-QCOMPARE(i, 42);
+QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort)
+QCOMPARE(i, 42)
//! [10]
//! [11]
-class TestQString: public QObject { ... };
+class TestQString: public QObject { ... }
QTEST_MAIN(TestQString)
//! [11]
@@ -94,19 +91,19 @@ QTEST_MAIN(TestQString)
//! [13]
-QTest::keyClick(myWidget, 'a');
+QTest.keyClick(myWidget, 'a')
//! [13]
//! [14]
-QTest::keyClick(myWidget, Qt::Key_Escape);
+QTest.keyClick(myWidget, Qt.Key_Escape)
-QTest::keyClick(myWidget, Qt::Key_Escape, Qt::ShiftModifier, 200);
+QTest.keyClick(myWidget, Qt.Key_Escape, Qt.ShiftModifier, 200)
//! [14]
//! [15]
-QTest::keyClicks(myWidget, "hello world");
+QTest.keyClicks(myWidget, "hello world")
//! [15]
@@ -115,74 +112,77 @@ namespace QTest {
template<>
char *toString(const MyPoint &point)
{
- QByteArray ba = "MyPoint(";
- ba += QByteArray::number(point.x()) + ", " + QByteArray::number(point.y());
- ba += ")";
- return qstrdup(ba.data());
+ QByteArray ba = "MyPoint("
+ ba += QByteArray.number(point.x()) + ", " + QByteArray.number(point.y())
+ ba += ")"
+ return qstrdup(ba.data())
}
}
//! [16]
//! [17]
-int i = 0;
+int i = 0
while (myNetworkServerNotResponding() && i++ < 50)
- QTest::qWait(250);
+ QTest.qWait(250)
//! [17]
//! [18]
-MyFirstTestObject test1;
-QTest::qExec(&test1);
+MyFirstTestObject test1
+QTest.qExec(&test1)
-MySecondTestObject test2;
-QTest::qExec(&test2);
+MySecondTestObject test2
+QTest.qExec(&test2)
//! [18]
//! [19]
-QDir dir;
+QDir dir
-QTest::ignoreMessage(QtWarningMsg, "QDir::mkdir: Empty or null file name(s)");
-dir.mkdir("");
+QTest.ignoreMessage(QtWarningMsg, "QDir.mkdir: Empty or null file name(s)")
+dir.mkdir("")
//! [19]
//! [20]
void myTestFunction_data()
{
- QTest::addColumn<QString>("aString");
- QTest::newRow("just hello") << QString("hello");
- QTest::newRow("a null string") << QString();
+ QTest.addColumn<QString>("aString")
+ QTest.newRow("just hello") << QString("hello")
+ QTest.newRow("a null string") << QString()
}
//! [20]
//! [21]
void myTestFunction_data() {
- QTest::addColumn<int>("intval");
- QTest::addColumn<QString>("str");
- QTest::addColumn<double>("dbl");
+ QTest.addColumn<int>("intval")
+ QTest.addColumn<QString>("str")
+ QTest.addColumn<double>("dbl")
- QTest::newRow("row1") << 1 << "hello" << 1.5;
+ QTest.newRow("row1") << 1 << "hello" << 1.5
}
//! [21]
//! [22]
-void MyTestClass::cleanup()
+void MyTestClass.cleanup()
{
if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) {
// clean up all database connections
- closeAllDatabases();
+ closeAllDatabases()
}
}
//! [22]
//! [23]
-QTest::qSleep(250);
+QTest.qSleep(250)
//! [23]
-}
-
+//! [24]
+widget = QWidget()
+widget.show()
+QTest.qWaitForWindowShown(widget)
+//! [24]
diff --git a/doc/codesnippets/examples/declarative/cppextensions/plugins/plugins.qml b/doc/codesnippets/examples/declarative/cppextensions/plugins/plugins.qml
new file mode 100644
index 0000000..3aa0995
--- /dev/null
+++ b/doc/codesnippets/examples/declarative/cppextensions/plugins/plugins.qml
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 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$
+**
+****************************************************************************/
+//![0]
+import com.nokia.TimeExample 1.0 // import types from the plugin
+
+Clock { // this class is defined in QML (com/nokia/TimeExample/Clock.qml)
+
+ Time { // this class is defined in C++ (plugin.cpp)
+ id: time
+ }
+
+ hours: time.hour
+ minutes: time.minute
+}
+//![0]
diff --git a/doc/codesnippets/examples/dialogs/tabdialog/tabdialog.cpp b/doc/codesnippets/examples/dialogs/tabdialog/tabdialog.cpp
new file mode 100644
index 0000000..7d7dc9f
--- /dev/null
+++ b/doc/codesnippets/examples/dialogs/tabdialog/tabdialog.cpp
@@ -0,0 +1,144 @@
+
+//! [0]
+class TabDialog (QDialog):
+ def __init__(self, fileName, parent = None):
+ QDialog.__init__(self, parent)
+ fileInfo = QFileInfo(fileName)
+
+ self.tabWidget = QTabWidget()
+ self.tabWidget.addTab(GeneralTab(fileInfo), "General")
+ self.tabWidget.addTab(PermissionsTab(fileInfo), "Permissions")
+ self.tabWidget.addTab(ApplicationsTab(fileInfo), "Applications")
+//! [0]
+
+//! [1] //! [2]
+ self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok
+//! [1] //! [3]
+ | QDialogButtonBox.Cancel)
+
+ self.buttonBox.accepted.connect(self.accept)
+ self.buttonBox.rejected.connect(self.reject)
+//! [2] //! [3]
+
+//! [4]
+ mainLayout = QVBoxLayout()
+ mainLayout.addWidget(tabWidget)
+ mainLayout.addWidget(buttonBox)
+ self.setLayout(mainLayout)
+//! [4]
+
+//! [5]
+ self.setWindowTitle("Tab Dialog")
+//! [5]
+
+//! [6]
+class GeneralTab (QWidget):
+ def __init__(self, fileInfo, parent = None):
+ QWidget.__init__(self, parent)
+ fileNameLabel = QLabel("File Name:")
+ fileNameEdit = QLineEdit(fileInfo.fileName())
+
+ pathLabel = QLabel("Path:")
+ pathValueLabel = QLabel(fileInfo.absoluteFilePath())
+ pathValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
+
+ sizeLabel = QLabel("Size:")
+ size = fileInfo.size()/1024
+ sizeValueLabel = QLabel("%d K" % size)
+ sizeValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
+
+ lastReadLabel = QLabel("Last Read:")
+ lastReadValueLabel = QLabel(fileInfo.lastRead().toString())
+ lastReadValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
+
+ lastModLabel = QLabel("Last Modified:")
+ lastModValueLabel = QLabel(fileInfo.lastModified().toString())
+ lastModValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
+
+ mainLayout = QVBoxLayout()
+ mainLayout.addWidget(fileNameLabel)
+ mainLayout.addWidget(fileNameEdit)
+ mainLayout.addWidget(pathLabel)
+ mainLayout.addWidget(pathValueLabel)
+ mainLayout.addWidget(sizeLabel)
+ mainLayout.addWidget(sizeValueLabel)
+ mainLayout.addWidget(lastReadLabel)
+ mainLayout.addWidget(lastReadValueLabel)
+ mainLayout.addWidget(lastModLabel)
+ mainLayout.addWidget(lastModValueLabel)
+ mainLayout.addStretch(1)
+ self.setLayout(mainLayout)
+//! [6]
+
+//! [7]
+class PermissionsTab (QWidget):
+ def __init__(self, fileInfo, parent = None):
+ QWidget.__init__(self, parent)
+ permissionsGroup = QGroupBox("Permissions")
+
+ readable = QCheckBox("Readable")
+ if fileInfo.isReadable():
+ readable.setChecked(True)
+
+ writable = QCheckBox("Writable")
+ if fileInfo.isWritable():
+ writable.setChecked(True)
+
+ executable = QCheckBox("Executable")
+ if fileInfo.isExecutable():
+ executable.setChecked(True)
+
+ ownerGroup = QGroupBox("Ownership")
+
+ ownerLabel = QLabel("Owner")
+ ownerValueLabel = QLabel(fileInfo.owner())
+ ownerValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
+
+ groupLabel = QLabel("Group")
+ groupValueLabel = QLabel(fileInfo.group())
+ groupValueLabel.setFrameStyle(QFrame.Panel | QFrame.Sunken)
+
+ permissionsLayout = QVBoxLayout()
+ permissionsLayout.addWidget(readable)
+ permissionsLayout.addWidget(writable)
+ permissionsLayout.addWidget(executable)
+ permissionsGroup.setLayout(permissionsLayout)
+
+ ownerLayout = QVBoxLayout()
+ ownerLayout.addWidget(ownerLabel)
+ ownerLayout.addWidget(ownerValueLabel)
+ ownerLayout.addWidget(groupLabel)
+ ownerLayout.addWidget(groupValueLabel)
+ ownerGroup.setLayout(ownerLayout)
+
+ mainLayout = QVBoxLayout()
+ mainLayout.addWidget(permissionsGroup)
+ mainLayout.addWidget(ownerGroup)
+ mainLayout.addStretch(1)
+ self.setLayout(mainLayout)
+//! [7]
+
+//! [8]
+class ApplicationsTab (QWidget):
+ def __init__(self, fileInfo, parent = None):
+ QWidget.__init__(self, parent)
+ topLabel = QLabel("Open with:")
+
+ applicationsListBox = QListWidget()
+ applications = []
+
+ for i in range(30):
+ applications.append("Application %d" %s i)
+ applicationsListBox.insertItems(0, applications)
+
+ if fileInfo.suffix().isEmpty():
+ alwaysCheckBox = QCheckBox("Always use this application to open this type of file")
+ else:
+ alwaysCheckBox = QCheckBox("Always use this application to open files with the extension '%s'" % fileInfo.suffix())
+
+ layout = QVBoxLayout()
+ layout.addWidget(topLabel)
+ layout.addWidget(applicationsListBox)
+ layout.addWidget(alwaysCheckBox)
+ self.setLayout(layout)
+//! [8]
diff --git a/doc/codesnippets/examples/uitools/textfinder/textfinder.cpp b/doc/codesnippets/examples/uitools/textfinder/textfinder.cpp
new file mode 100644
index 0000000..edbe222
--- /dev/null
+++ b/doc/codesnippets/examples/uitools/textfinder/textfinder.cpp
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 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]
+def __init__(self, parent = None):
+ QWidget.__init__(self. parent)
+ formWidget = self.loadUiFile()
+
+//! [1]
+ self.ui_findButton = qFindChild(QPushButton, self, "findButton")
+ self.ui_textEdit = qFindChild(QTextEdit, self, "textEdit")
+ self.ui_lineEdit = qFindChild(QLineEdit, self, "lineEdit")
+//! [0] //! [1]
+
+//! [2]
+ QMetaObject.connectSlotsByName(self)
+//! [2]
+
+//! [3a]
+ self.loadTextFile()
+//! [3a]
+
+//! [3b]
+ layout = QVBoxLayout()
+ layout.addWidget(formWidget)
+ self.setLayout(layout)
+//! [3b]
+
+//! [3c]
+ self.setWindowTitle("Text Finder")
+ self.isFirstTime = True
+//! [3c]
+
+//! [4]
+def loadUiFile(self):
+ loader = QUiLoader()
+ return loader.load(":/forms/textfinder.ui", self)
+//! [4]
+
+//! [5]
+def loadTextFile(self):
+ inputFile = QFile(":/forms/input.txt")
+ inputFile.open(QIODevice.ReadOnly)
+ in = QTextStream(inputFile)
+ line = in.readAll()
+ inputFile.close()
+
+ self.ui_textEdit.append(line)
+ self.ui_textEdit.setUndoRedoEnabled(False)
+ self.ui_textEdit.setUndoRedoEnabled(True)
+//! [5]
+
+//! [6] //! [7]
+@Slot()
+def on_findButton_clicked(self):
+ searchString = self.ui_lineEdit.text()
+ document = self.ui_textEdit.document()
+
+ found = False
+
+ if not self.isFirstTime:
+ document.undo()
+
+ if not searchString:
+ QMessageBox.information(self, "Empty Search Field",
+ "The search field is empty. Please enter a word and click Find.")
+ else:
+ highlightCursor = QTextCursor(document)
+ cursor = QTextCursor(document)
+ cursor.beginEditBlock()
+//! [6]
+ plainFormat = QTextCharFormat(highlightCursor.charFormat())
+ colorFormat = QTextCharFormat(plainFormat)
+ colorFormat.setForeground(Qt.red)
+
+ while not highlightCursor.isNull() and not highlightCursor.atEnd():
+ highlightCursor = document.find(searchString, highlightCursor, QTextDocument.FindWholeWords)
+
+ if not highlightCursor.isNull():
+ found = True
+ highlightCursor.movePosition(QTextCursor.WordRight, QTextCursor.KeepAnchor)
+ highlightCursor.mergeCharFormat(colorFormat)
+//! [8]
+ cursor.endEditBlock()
+//! [7] //! [9]
+ self.isFirstTime = False
+
+ if not found:
+ QMessageBox.information(self, "Word Not Found", "Sorry, the word cannot be found.");
+//! [8] //! [9]
diff --git a/doc/codesnippets/webkitsnippets/webelement/main.cpp b/doc/codesnippets/webkitsnippets/webelement/main.cpp
new file mode 100644
index 0000000..3be8a69
--- /dev/null
+++ b/doc/codesnippets/webkitsnippets/webelement/main.cpp
@@ -0,0 +1,65 @@
+
+def traverse():
+//! [Traversing with QWebElement]
+ frame.setHtml("<html><body><p>First Paragraph</p><p>Second Paragraph</p></body></html>")
+ doc = frame.documentElement()
+ body = doc.firstChild()
+ firstParagraph = body.firstChild()
+ secondParagraph = firstParagraph.nextSibling()
+//! [Traversing with QWebElement]
+
+def findButtonAndClick():
+ frame.setHtml("<form name=\"myform\" action=\"submit_form.asp\" method=\"get\">" \
+ "<input type=\"text\" name=\"myfield\">" \
+ "<input type=\"submit\" value=\"Submit\">" \
+ "</form>")
+
+//! [Calling a DOM element method]
+
+ document = frame.documentElement()
+ # Assume that the document has the following structure:
+ #
+ # <form name="myform" action="submit_form.asp" method="get">
+ # <input type="text" name="myfield">
+ # <input type="submit" value="Submit">
+ # </form>
+
+ button = document.findFirst("input[type=submit]")
+ button.evaluateJavaScript("click()")
+
+//! [Calling a DOM element method]
+
+def autocomplete1():
+ document = frame.documentElement()
+//! [autocomplete1]
+ firstTextInput = document.findFirst("input[type=text]")
+ storedText = firstTextInput.attribute("value")
+//! [autocomplete1]
+
+def autocomplete2():
+ document = frame.documentElement()
+ storedText = "text"
+
+//! [autocomplete2]
+ firstTextInput = document.findFirst("input[type=text]")
+ textInput.setAttribute("value", storedText)
+//! [autocomplete2]
+
+def findAll():
+//! [FindAll]
+ document = frame.documentElement()
+ # Assume the document has the following structure:
+ #
+ # <p class=intro>
+ # <span>Intro</span>
+ # <span>Snippets</span>
+ # </p>
+ # <p>
+ # <span>Content</span>
+ # <span>Here</span>
+ # </p>
+
+//! [FindAll intro]
+ allSpans = document.findAll("span")
+ introSpans = document.findAll("p.intro span")
+//! [FindAll intro] //! [FindAll]