From: Kevin Krammer Date: Thu, 8 Nov 2012 19:26:31 +0000 (+0100) Subject: Add icon support X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=6e024134ce331b8f32a5d97b807fdf211c64f316;p=konrad%2FDeclarativeWidgets.git Add icon support --- diff --git a/examples/text-editor/editor.cpp b/examples/text-editor/editor.cpp index 9307d62..c98f0c2 100644 --- a/examples/text-editor/editor.cpp +++ b/examples/text-editor/editor.cpp @@ -34,6 +34,16 @@ QString Editor::fileName() const return m_fileName; } +QIcon Editor::iconFromFile(const QString &fileName) const +{ + return QIcon(fileName); +} + +QIcon Editor::iconFromTheme(const QString &iconName) const +{ + return QIcon::fromTheme(iconName); +} + void Editor::newDocument() { m_fileName = QString(); diff --git a/examples/text-editor/editor.h b/examples/text-editor/editor.h index 7342608..a2cbad0 100644 --- a/examples/text-editor/editor.h +++ b/examples/text-editor/editor.h @@ -1,6 +1,7 @@ #ifndef EDITOR_H #define EDITOR_H +#include #include class QTextDocument; @@ -20,6 +21,9 @@ class Editor : public QObject void setFileName(const QString &fileName); QString fileName() const; + Q_INVOKABLE QIcon iconFromFile(const QString &fileName) const; + Q_INVOKABLE QIcon iconFromTheme(const QString &iconName) const; + Q_SIGNALS: void fileNameChanged(const QString &fileName); void requestSaveFileName(); diff --git a/examples/text-editor/editor.png b/examples/text-editor/editor.png new file mode 100644 index 0000000..6644160 Binary files /dev/null and b/examples/text-editor/editor.png differ diff --git a/examples/text-editor/main.qml b/examples/text-editor/main.qml index 4560a2b..4588bda 100644 --- a/examples/text-editor/main.qml +++ b/examples/text-editor/main.qml @@ -5,6 +5,7 @@ MainWindow { id: mainWindow windowTitle: textEdit.modified ? qsTr("Declarative Widget Editor *modified*") : qsTr("Declarative Widget Editor") + windowIcon: _editor.iconFromFile(":/editor.png") size: Qt.size(800, 600) @@ -15,11 +16,14 @@ MainWindow { Action { id: newAction text: qsTr("New") + icon: _editor.iconFromTheme("document-new"); onTriggered: _editor.newDocument() } Action { + id: openAction text: qsTr("Open") + icon: _editor.iconFromTheme("document-open") onTriggered: { FileDialog.nameFilters = [ qsTr("Plain text files (*.txt)"), qsTr("All files (*.*)") ] var fileName = FileDialog.getOpenFileName() @@ -29,7 +33,9 @@ MainWindow { } Action { + id: saveAction text: qsTr("Save") + icon: _editor.iconFromTheme("document-save") onTriggered: _editor.save() } @@ -37,12 +43,14 @@ MainWindow { Action { text: qsTr("Print") + icon: _editor.iconFromTheme("document-print") } Separator {} Action { text: qsTr("Close") + icon: _editor.iconFromTheme("application-exit") onTriggered: mainWindow.close() } } @@ -51,12 +59,16 @@ MainWindow { title: qsTr("Edit") Action { + id: undoAction text: qsTr("Undo") + icon: _editor.iconFromTheme("edit-undo") onTriggered: textEdit.undo() } Action { + id: redoAction text: qsTr("Redo") + icon: _editor.iconFromTheme("edit-redo") onTriggered: textEdit.redo() } @@ -65,18 +77,21 @@ MainWindow { Action { id: cutAction text: qsTr("Cut") + icon: _editor.iconFromTheme("edit-cut") onTriggered: textEdit.cut() } Action { id: copyAction text: qsTr("Copy") + icon: _editor.iconFromTheme("edit-copy") onTriggered: textEdit.copy() } Action { id: pasteAction text: qsTr("Paste") + icon: _editor.iconFromTheme("edit-paste") onTriggered: textEdit.paste() } @@ -84,6 +99,7 @@ MainWindow { Action { text: qsTr("Select All") + icon: _editor.iconFromTheme("edit-select-all") onTriggered: textEdit.selectAll() } } @@ -93,11 +109,13 @@ MainWindow { Action { text: qsTr("Enlarge Font") + icon: _editor.iconFromTheme("zoom-in") onTriggered: textEdit.zoomIn() } Action { text: qsTr("Shrink Font") + icon: _editor.iconFromTheme("zoom-out") onTriggered: textEdit.zoomOut() } } @@ -107,6 +125,7 @@ MainWindow { Action { text: qsTr("About") + icon: mainWindow.windowIcon onTriggered: MessageBox.about(qsTr("About Declarative Widgets Editor Example"), qsTr("This is an example of a simple text editor written in QML using DeclarativeWidgets")) } @@ -123,10 +142,22 @@ MainWindow { action: newAction } - Separator {} + ActionItem { + action: openAction + } - Label { - text: "Zoom" + ActionItem { + action: saveAction + } + } + + ToolBar { + ActionItem { + action: undoAction + } + + ActionItem { + action: redoAction } } diff --git a/examples/text-editor/text-editor.pro b/examples/text-editor/text-editor.pro index 7a9e6f3..c410879 100644 --- a/examples/text-editor/text-editor.pro +++ b/examples/text-editor/text-editor.pro @@ -12,11 +12,11 @@ SOURCES += \ main.cpp \ editor.cpp +HEADERS += \ + editor.h + RESOURCES += \ text-editor.qrc OTHER_FILES += \ main.qml - -HEADERS += \ - editor.h diff --git a/examples/text-editor/text-editor.qrc b/examples/text-editor/text-editor.qrc index 5f6483a..93e81a1 100644 --- a/examples/text-editor/text-editor.qrc +++ b/examples/text-editor/text-editor.qrc @@ -1,5 +1,6 @@ main.qml + editor.png