add a clear action to the window

This commit is contained in:
Fries 2023-06-25 23:41:53 -07:00
parent a806a2fcfc
commit 53b81f78c0
5 changed files with 40 additions and 3 deletions

View file

@ -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)

View file

@ -1,4 +1,9 @@
#include "MainWindow.hh"
#include <KLocalizedString>
#include <QAction>
#include <KActionCollection>
#include <KStandardAction>
#include <QApplication>
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");
}

View file

@ -10,6 +10,7 @@ public:
private:
KTextEdit* textArea;
void setupActions();
};
#endif

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<gui name="TextEditor" version="1" xmlns="https://www.kde.org/standards/kxmlgui/1.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.kde.org/standards/kxmlgui/1.0/kxmlgui.xsd">
<MenuBar>
<Menu name="file">
<Action name="clear" />
</Menu>
</MenuBar>
<ToolBar name="mainToolBar">
<text>Main Toolbar</text>
<Action name="clear" />
</ToolBar>
</gui>

View file

@ -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