From 53b81f78c0362847ade6ebd9c02e1ccde5b152ab Mon Sep 17 00:00:00 2001 From: Fries Date: Sun, 25 Jun 2023 23:41:53 -0700 Subject: [PATCH] add a clear action to the window --- src/TextEditor/CMakeLists.txt | 3 +++ src/TextEditor/MainWindow.cc | 21 ++++++++++++++++++++- src/TextEditor/MainWindow.hh | 1 + src/TextEditor/TextEditorUI.rc | 14 ++++++++++++++ src/TextEditor/main.cc | 4 ++-- 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/TextEditor/TextEditorUI.rc diff --git a/src/TextEditor/CMakeLists.txt b/src/TextEditor/CMakeLists.txt index dd9aa9d..cdd9e98 100644 --- a/src/TextEditor/CMakeLists.txt +++ b/src/TextEditor/CMakeLists.txt @@ -11,3 +11,6 @@ target_link_libraries(TextEditor KF5::XmlGui KF5::TextWidgets ) + +install(TARGETS TextEditor ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) +install(FILES TextEditorUI.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/TextEditor) diff --git a/src/TextEditor/MainWindow.cc b/src/TextEditor/MainWindow.cc index 1cc5a4f..89b12cc 100644 --- a/src/TextEditor/MainWindow.cc +++ b/src/TextEditor/MainWindow.cc @@ -1,4 +1,9 @@ #include "MainWindow.hh" +#include +#include +#include +#include +#include MainWindow::MainWindow(QWidget* parent) : KXmlGuiWindow(parent) @@ -8,5 +13,19 @@ MainWindow::MainWindow(QWidget* parent) // set the central widget to be the TextArea setCentralWidget(textArea); // setup the GUI - setupGUI(); + setupActions(); +} + +void MainWindow::setupActions() +{ + QAction* clearAction = new QAction(this); + clearAction->setText(i18n("&Clear")); + clearAction->setIcon(QIcon::fromTheme("document-new")); + actionCollection()->addAction("clear", clearAction); + actionCollection()->setDefaultShortcut(clearAction, Qt::CTRL + Qt::Key_W); + connect(clearAction, &QAction::triggered, textArea, &KTextEdit::clear); + + KStandardAction::quit(qApp, &QCoreApplication::quit, actionCollection()); + + setupGUI(Default, "TextEditorUI.rc"); } diff --git a/src/TextEditor/MainWindow.hh b/src/TextEditor/MainWindow.hh index 60f8b92..d41414e 100644 --- a/src/TextEditor/MainWindow.hh +++ b/src/TextEditor/MainWindow.hh @@ -10,6 +10,7 @@ public: private: KTextEdit* textArea; + void setupActions(); }; #endif diff --git a/src/TextEditor/TextEditorUI.rc b/src/TextEditor/TextEditorUI.rc new file mode 100644 index 0000000..0a4837f --- /dev/null +++ b/src/TextEditor/TextEditorUI.rc @@ -0,0 +1,14 @@ + + + + + + + + + Main Toolbar + + + diff --git a/src/TextEditor/main.cc b/src/TextEditor/main.cc index d8af0ce..0604d10 100644 --- a/src/TextEditor/main.cc +++ b/src/TextEditor/main.cc @@ -7,11 +7,11 @@ int main(int argc, char* argv[]) { QApplication app(argc, argv); - KLocalizedString::setApplicationDomain("MainWindow"); + KLocalizedString::setApplicationDomain("TextEditor"); KAboutData aboutData( // Internal Name - QStringLiteral("MainWindow"), + QStringLiteral("TextEditor"), // Name i18n("Text Editor"), // Version Number