From 7dd9d3d95bb14136b3961aa74b5bfa032f730de5 Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Tue, 4 Nov 2025 21:21:28 +0100 Subject: [PATCH] Added "About" & "About Qt" dialogs. --- CMakeLists.txt | 2 ++ mainwindow.cpp | 79 +++++++++++++++++++++++++++++++++++--------------- mainwindow.h | 7 ++++- 3 files changed, 63 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6d92e2..0bec82c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,8 @@ endif() qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) endif() +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + target_link_libraries(${TARGET_APP} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) target_include_directories(${TARGET_APP} PRIVATE ${CORE_LIB_DIR}/) diff --git a/mainwindow.cpp b/mainwindow.cpp index 5cca1e3..18517ce 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -4,6 +4,7 @@ #include #include +#include "../../ApplicationConfig.h" #include "data/settingshandler.h" #include "genericcore.h" @@ -29,6 +30,9 @@ MainWindow::MainWindow(QWidget* parent) setWindowIcon(QIcon(iconString)); #endif + createActions(); + createHelpMenu(); + /// TODO restore window geometry and state (& save it in closeEvent) const QVariantMap settings = SettingsHandler::getSettings("GUI"); restoreGeometry(settings.value("geometry").toByteArray()); @@ -45,30 +49,6 @@ MainWindow::~MainWindow() { delete m_core; } -void MainWindow::on_pushButton_clicked() { - const QString prefix("Backend provided by: "); - ui->label->setText(prefix + m_core->toString()); -} - -void MainWindow::showStatusMessage(const QString text) { - qInfo() << text; - ui->statusbar->showMessage(text); -} - -void MainWindow::on_actionCheck_for_update_triggered() { - showStatusMessage("Checking for update..."); - const bool updateAvailable = m_core->isApplicationUpdateAvailable(); - if (updateAvailable) { - const QString text = isWindowModified() ? updateTextDirty : updateTextClean; - const QMessageBox::StandardButton clickedButton = QMessageBox::question( - this, tr("Update available."), text, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); - if (clickedButton == QMessageBox::Yes) { - m_core->triggerApplicationUpdate(); - close(); - } - } -} - void MainWindow::closeEvent(QCloseEvent* event) { if (isWindowModified()) { QMessageBox msgBox; @@ -106,3 +86,54 @@ void MainWindow::closeEvent(QCloseEvent* event) { "GUI"); } } + +void MainWindow::onAboutClicked() { + const QString applicationName = APPLICATION_NAME; + const QString titlePrefix = tr("About "); + const QString aboutText = + tr(QString("%1 v%2 is a template for Qt applications." + "

Working-Copy_Collective website" + "

Mail to support" + "

It uses the Qt Framework.") + .arg(applicationName) + .arg(APPLICATION_VERSION) + .toLatin1()); + QMessageBox::about(this, titlePrefix + applicationName, aboutText); +} + +void MainWindow::showStatusMessage(const QString text) { + qInfo() << text; + ui->statusbar->showMessage(text); +} + +void MainWindow::on_actionCheck_for_update_triggered() { + showStatusMessage("Checking for update..."); + const bool updateAvailable = m_core->isApplicationUpdateAvailable(); + if (updateAvailable) { + const QString text = isWindowModified() ? updateTextDirty : updateTextClean; + const QMessageBox::StandardButton clickedButton = QMessageBox::question( + this, tr("Update available."), text, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + if (clickedButton == QMessageBox::Yes) { + m_core->triggerApplicationUpdate(); + close(); + } + } +} + +void MainWindow::on_pushButton_clicked() { + const QString prefix("Backend provided by: "); + ui->label->setText(prefix + m_core->toString()); +} + +void MainWindow::createHelpMenu() { + QMenu* helpMenu = menuBar()->addMenu(tr("&Help")); + QAction* aboutAct = helpMenu->addAction(tr("&About"), this, &MainWindow::onAboutClicked); + aboutAct->setStatusTip(tr("Show the application's About box")); + + QAction* aboutQtAct = helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); + aboutQtAct->setStatusTip(tr("Show the Qt library's About box")); +} + +void MainWindow::createActions() { + // TODO add generic menu actions (file/new, edit/cut, ...) +} diff --git a/mainwindow.h b/mainwindow.h index 7ebac8f..69efbbd 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -27,14 +27,19 @@ class MainWindow : public QMainWindow { void closeEvent(QCloseEvent* event) override; private slots: + void onAboutClicked(); void showStatusMessage(const QString text); + void on_actionCheck_for_update_triggered(); void on_pushButton_clicked(); - void on_actionCheck_for_update_triggered(); private: Ui::MainWindow* ui; GenericCore* m_core; + + /// Setup functions + void createActions(); + void createHelpMenu(); }; #endif // MAINWINDOW_H