From 6e024134ce331b8f32a5d97b807fdf211c64f316 Mon Sep 17 00:00:00 2001 From: Kevin Krammer Date: Thu, 8 Nov 2012 20:26:31 +0100 Subject: [PATCH] Add icon support --- examples/text-editor/editor.cpp | 10 +++++++++ examples/text-editor/editor.h | 4 +++ examples/text-editor/editor.png | Bin 0 -> 1635 bytes examples/text-editor/main.qml | 37 +++++++++++++++++++++++++++++++-- examples/text-editor/text-editor.pro | 6 ++-- examples/text-editor/text-editor.qrc | 1 + 6 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 examples/text-editor/editor.png 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 0000000000000000000000000000000000000000..6644160655b09c32b048971d77fe911ef5d21ee3 GIT binary patch literal 1635 zcmV-p2AuhcP)i|UK~#90rI&wf6XzMnKj*vi-T8d>`OZ$77U9qcL>eeR)Cg9s z)nIHT(29(v3q(+j!jK?CYK5{NOk)rPTBWT*%K}>enO3Q-|0<@XXh;zfDHUi#DkBvM z>7Yp!Kw&Yl_~DSW$-6%sdofO82OjB>Wxwz1&-eL0clX{4j}f1K^0C;nXOAdisx(bL zTEyeW#K^sb7`fX&od^j~01Yqz--Lwm!5K#^787fKyaF*c3c&Aw`3nGX=+L2w6$yZO z^XBDbcXv14-QAoxaY6#{JPN$7c5UA8dz*GJ!HGif?7A8CAQp>>y7lW|>^sERXxahs z9b$A8A<}6$tA9H8@J8=JN^Q4w``^WcRU!3zo~1Q$YZwf8nPZaFpe2Y}zv_U|W(h6Bhm zfeSGPLcsXvU*Bn|yr-)jI~=9* znT2#-?jSLk;$CWmufG|jazPCqkA$koSf)sXpJ97lw?E9)9JQJOlJ18r$xR*-bVX`da^Xa&DfUpxJ6g2Uh zI)hSv1rNiJowOqZ%N*HK=1V=A0EGi;rxJw zOKQ<|4Le{_5^*VwxVVmu-)Hdi32=C5FPP{=Mbyc{doKNr3zu%N^7%Pa!oU7zkgBEY zQDhlIQwdro5!c2E1+gqYnkunn_aAfMFvSZ=OY>^6X=_s!zHY;>IMWuRr>i{=o)}Eg z(bZ4Y(mK4Vg6Y!<1ueo(04Es0@*C)0g*SG;O*|gY<4w97Rz#f{!52PPkD_=meFkC2 zrX(C9917qwyr{B=pS^i7uktAcv^1|4HLt&4H2m4>4JfjVX&Qvx5Tzw9t{uSgX(+P9 z>$~<(37=FzMbw!Vezo^@8oX>Xi{{|~Wo-Ze002ovPDHLkV1nZw3s?XE literal 0 HcmV?d00001 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 -- 1.7.2.5