From: Kevin Krammer Date: Mon, 5 Nov 2012 20:00:52 +0000 (+0100) Subject: Add text-editor example application X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=0c79e3adc6ae66a2f7d9271a2ce051221b3c213b;p=web%2Fkonrad%2FDeclarativeWidgets.git Add text-editor example application --- diff --git a/examples/examples.pro b/examples/examples.pro index 9b6825e..defb139 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,5 +1,7 @@ TEMPLATE = subdirs +SUBDIRS += text-editor + OTHER_FILES += \ animation.qml \ browser.qml \ diff --git a/examples/text-editor/main.cpp b/examples/text-editor/main.cpp new file mode 100644 index 0000000..bb72b1e --- /dev/null +++ b/examples/text-editor/main.cpp @@ -0,0 +1,44 @@ +/* + Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Kevin Krammer, krake@kdab.com + Author: Tobias Koenig, tokoe@kdab.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "declarativewidgetsdocument.h" + +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + const QUrl documentUrl = QUrl("qrc:///main.qml"); + + DeclarativeWidgetsDocument document(documentUrl); + QObject::connect(document.engine(), SIGNAL(quit()), &app, SLOT(quit())); + + QWidget *widget = document.create(); + if (!widget) + qFatal("Failed to create widget from document"); + + widget->show(); + + return app.exec(); +} diff --git a/examples/text-editor/main.qml b/examples/text-editor/main.qml new file mode 100644 index 0000000..c31671c --- /dev/null +++ b/examples/text-editor/main.qml @@ -0,0 +1,144 @@ +import QtGui 1.0 + +MainWindow { + id: mainWindow + + windowTitle: textEdit.modified ? qsTr("Declarative Widget Editor *modified*") : qsTr("Declarative Widget Editor") + + size: Qt.size(800, 600) + + MenuBar { + Menu { + title: qsTr("File") + + Action { + id: newAction + text: qsTr("New") + } + + Action { + text: qsTr("Save") + } + + Separator {} + + Action { + text: qsTr("Print") + } + + Separator {} + + Action { + text: qsTr("Close") + onTriggered: mainWindow.close() + } + } + + Menu { + title: qsTr("Edit") + + Action { + text: qsTr("Undo") + onTriggered: textEdit.undo() + } + + Action { + text: qsTr("Redo") + onTriggered: textEdit.redo() + } + + Separator {} + + Action { + id: cutAction + text: qsTr("Cut") + onTriggered: textEdit.cut() + } + + Action { + id: copyAction + text: qsTr("Copy") + onTriggered: textEdit.copy() + } + + Action { + id: pasteAction + text: qsTr("Paste") + onTriggered: textEdit.paste() + } + + Separator {} + + Action { + text: qsTr("Select All") + onTriggered: textEdit.selectAll() + } + } + + Menu { + title: qsTr("View") + + Action { + text: qsTr("Enlarge Font") + onTriggered: textEdit.zoomIn() + } + + Action { + text: qsTr("Shrink Font") + onTriggered: textEdit.zoomOut() + } + } + + Menu { + title: qsTr("Help") + + Action { + text: qsTr("About") + onTriggered: MessageBox.about(qsTr("About Declarative Widgets Editor Example"), + qsTr("This is an example of a simple text editor written in QML using DeclarativeWidgets")) + } + + Action { + text: qsTr("About Qt") + onTriggered: MessageBox.aboutQt(qsTr("About Qt")) + } + } + } + + ToolBar { + ActionItem { + action: newAction + } + + Separator {} + + Label { + text: "Zoom" + } + } + + TextEdit { + id: textEdit + + contextMenuPolicy: Qt.ActionsContextMenu + + ActionItem { + action: cutAction + } + + ActionItem { + action: copyAction + } + + ActionItem { + action: pasteAction + } + } + + StatusBar { + Label { + StatusBar.stretch: 2 + text: "Pos:" + } + } +} diff --git a/examples/text-editor/text-editor.pro b/examples/text-editor/text-editor.pro new file mode 100644 index 0000000..d960ab0 --- /dev/null +++ b/examples/text-editor/text-editor.pro @@ -0,0 +1,18 @@ +TEMPLATE = app + +DEPENDPATH += . +INCLUDEPATH += . ../../lib + +LIBS += -L ../../lib -ldeclarativewidgets + +QT += declarative + +# Input +SOURCES += \ + main.cpp + +RESOURCES += \ + text-editor.qrc + +OTHER_FILES += \ + main.qml diff --git a/examples/text-editor/text-editor.qrc b/examples/text-editor/text-editor.qrc new file mode 100644 index 0000000..5f6483a --- /dev/null +++ b/examples/text-editor/text-editor.qrc @@ -0,0 +1,5 @@ + + + main.qml + +