add a meow action to the TextEditor program

This commit is contained in:
Fries 2023-06-26 19:49:48 -07:00
parent b020fe9c7f
commit e64edc5c5a
3 changed files with 26 additions and 2 deletions

View file

@ -24,16 +24,33 @@ MainWindow::MainWindow(QWidget* parent)
void MainWindow::setupClearAction()
{
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);
}
void MainWindow::setupMeowAction()
{
QAction* meowAction = new QAction(this);
meowAction->setText(i18n("&Meow"));
meowAction->setIcon(QIcon::fromTheme("network-wireless-signal-excellent"));
actionCollection()->addAction("meow", meowAction);
actionCollection()->setDefaultShortcut(meowAction, Qt::CTRL + Qt::Key_M);
connect(meowAction, &QAction::triggered, this, &MainWindow::meow);
}
void MainWindow::setupActions()
{
setupClearAction();
setupMeowAction();
KStandardAction::quit(qApp, &QCoreApplication::quit, actionCollection());
KStandardAction::open(this, &MainWindow::openFile, actionCollection());
@ -109,3 +126,7 @@ void MainWindow::downloadFinished(KJob* job)
textArea->setPlainText(QTextStream(storedJob->data(), QIODevice::ReadOnly).readAll());
}
}
void MainWindow::meow() {
KMessageBox::information(this, "Meow", "Meow");
}

View file

@ -14,15 +14,17 @@ private:
void setupActions();
void saveFileToDisk(const QString& outputFileName);
void setupClearAction();
void setupMeowAction();
private Q_SLOTS:
void newFile();
void openFile();
void saveFile();
void saveFileAs();
void downloadFinished(KJob *job);
void meow();
private:
KTextEdit* textArea;
QString fileName;

View file

@ -8,11 +8,12 @@
</Menu>
<Menu>
<text>Another Meownu</text>
<Action name="clear" />
<Action name="meow" />
</Menu>
</MenuBar>
<ToolBar name="mainToolBar">
<text>Main Toolbar</text>
<Action name="clear" />
<Action name="meow" />
</ToolBar>
</gui>