add a clear action to the window
This commit is contained in:
parent
a806a2fcfc
commit
53b81f78c0
5 changed files with 40 additions and 3 deletions
|
@ -11,3 +11,6 @@ target_link_libraries(TextEditor
|
||||||
KF5::XmlGui
|
KF5::XmlGui
|
||||||
KF5::TextWidgets
|
KF5::TextWidgets
|
||||||
)
|
)
|
||||||
|
|
||||||
|
install(TARGETS TextEditor ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
|
||||||
|
install(FILES TextEditorUI.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/TextEditor)
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
#include "MainWindow.hh"
|
#include "MainWindow.hh"
|
||||||
|
#include <KLocalizedString>
|
||||||
|
#include <QAction>
|
||||||
|
#include <KActionCollection>
|
||||||
|
#include <KStandardAction>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget* parent)
|
MainWindow::MainWindow(QWidget* parent)
|
||||||
: KXmlGuiWindow(parent)
|
: KXmlGuiWindow(parent)
|
||||||
|
@ -8,5 +13,19 @@ MainWindow::MainWindow(QWidget* parent)
|
||||||
// set the central widget to be the TextArea
|
// set the central widget to be the TextArea
|
||||||
setCentralWidget(textArea);
|
setCentralWidget(textArea);
|
||||||
// setup the GUI
|
// 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");
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KTextEdit* textArea;
|
KTextEdit* textArea;
|
||||||
|
void setupActions();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
14
src/TextEditor/TextEditorUI.rc
Normal file
14
src/TextEditor/TextEditorUI.rc
Normal 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>
|
|
@ -7,11 +7,11 @@
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
KLocalizedString::setApplicationDomain("MainWindow");
|
KLocalizedString::setApplicationDomain("TextEditor");
|
||||||
|
|
||||||
KAboutData aboutData(
|
KAboutData aboutData(
|
||||||
// Internal Name
|
// Internal Name
|
||||||
QStringLiteral("MainWindow"),
|
QStringLiteral("TextEditor"),
|
||||||
// Name
|
// Name
|
||||||
i18n("Text Editor"),
|
i18n("Text Editor"),
|
||||||
// Version Number
|
// Version Number
|
||||||
|
|
Loading…
Reference in a new issue