Added "About" & "About Qt" dialogs.

This commit is contained in:
2025-11-04 21:21:28 +01:00
parent c8825bfe14
commit 7dd9d3d95b
3 changed files with 63 additions and 25 deletions

View File

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

View File

@ -4,6 +4,7 @@
#include <QCloseEvent>
#include <QMessageBox>
#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("<b>%1 v%2</b> is a template for Qt applications."
"<br><br><a href=\"https://working-copy.org/\">Working-Copy_Collective website</a>"
"<br><br><a href=\"mailto:support@working-copy.org\">Mail to support</a>"
"<br><br>It uses the <a href=\"https://qt.io\">Qt Framework</a>.")
.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, ...)
}

View File

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