diff --git a/src/qt/memoserv_win.cpp b/src/qt/memoserv_win.cpp index d55cffd..05d0dbf 100644 --- a/src/qt/memoserv_win.cpp +++ b/src/qt/memoserv_win.cpp @@ -17,9 +17,11 @@ #include "memoserv_win.hpp" #include "app_config.h" +#include "version_info_win.hpp" #include #include #include + #include class QApplication; @@ -52,6 +54,11 @@ void MemoservWin::create_menu(QApplication* app) { } QMenu* const help_menu = menuBar()->addMenu(tr("&Help")); + { + const auto version_info_act = new QAction(tr("Version &info..."), this); + help_menu->addAction(version_info_act); + connect(version_info_act, &QAction::triggered, this, &MemoservWin::show_version_info); + } { help_menu->addAction(tr("About &Qt..."), app, &QApplication::aboutQt); } @@ -61,4 +68,11 @@ void MemoservWin::open() { std::cout << "MemoservWin::open()\n"; } +void MemoservWin::show_version_info() { + std::cout << "MemoservWin::show_version_info()\n"; + VersionInfoWin vinfo(this); + vinfo.setWindowModality(Qt::WindowModality::WindowModal); + vinfo.exec(); +} + } //namespace duck diff --git a/src/qt/memoserv_win.hpp b/src/qt/memoserv_win.hpp index 4d86fd8..c616d83 100644 --- a/src/qt/memoserv_win.hpp +++ b/src/qt/memoserv_win.hpp @@ -33,6 +33,7 @@ public: private: void create_menu(QApplication*); + void show_version_info(); void open(); }; diff --git a/src/qt/meson.build b/src/qt/meson.build index 7524826..ac64678 100644 --- a/src/qt/meson.build +++ b/src/qt/meson.build @@ -2,10 +2,13 @@ cpp = meson.get_compiler('cpp') fslib_dep = cpp.find_library('stdc++fs', required: false) qt5 = import('qt5') -qt5_dep = dependency('qt5', modules: ['Core', 'Gui', 'Widgets']) +qt5_dep = dependency('qt5', modules: ['Core', 'Gui', 'Widgets'], version: '>=5.14') inc = include_directories('includes') moc_files = qt5.preprocess( - moc_headers: 'memoserv_win.hpp', + moc_headers: [ + 'memoserv_win.hpp', + 'version_info_win.hpp', + ], #ui_files: 'main_window.ui', moc_extra_arguments: ['-DMAKES_MY_MOC_HEADER_COMPILE'], include_directories: inc, @@ -25,7 +28,12 @@ config_file = configure_file( executable(app_name, 'main.cpp', 'memoserv_win.cpp', + 'version_info_win.cpp', moc_files, + config_file, + project_config_file, + gitrev_config_file, include_directories: inc, dependencies: [qt5_dep, fslib_dep], + install: true, ) diff --git a/src/qt/version_info_win.cpp b/src/qt/version_info_win.cpp new file mode 100644 index 0000000..4bf16e6 --- /dev/null +++ b/src/qt/version_info_win.cpp @@ -0,0 +1,89 @@ +/* Copyright 2020, Michele Santullo + * This file is part of memoserv. + * + * Memoserv is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Memoserv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Memoserv. If not, see . + */ + +#include "version_info_win.hpp" +#include "app_config.h" +#include "config.h" +#include "git_version.h" +#include +#include +#include +#include +#include + +namespace duck { +namespace { + const constexpr char g_gpl_text[] = + APP_SHORT_DESC "\n" + "Copyright (C) " COPYRIGHT_YEAR " Michele Santullo\n" + "\n" + "This program is free software: you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation, either version 3 of the License, or\n" + "(at your option) any later version.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU General Public License\n" + "along with this program. If not, see .\n" + ; + + void add_centered_md_label (const std::unique_ptr& lay, const QString& text) { + auto label = std::make_unique(); + label->setTextFormat(Qt::TextFormat::MarkdownText); + label->setText(text); + lay->addWidget(label.release(), 0, Qt::AlignCenter); + } +} //unnamed namespace + +VersionInfoWin::VersionInfoWin (QWidget* parent) : + QDialog(parent) +{ + this->setWindowTitle(tr("Version info") + " " + APP_NAME); + + auto main_lay = std::make_unique(); + + add_centered_md_label(main_lay, QString("**") + APP_NAME + "**"); + add_centered_md_label(main_lay, tr("is part of") + " **" + PROJECT_NAME + "** v" + project_ver()); + + if constexpr (sizeof(PROJECT_GIT_SHA1) > 1) { + add_centered_md_label(main_lay, tr("git revision") + " [" + PROJECT_GIT_SHA1 + "](" + PROJECT_REPO_URL + "/commit/" + PROJECT_GIT_SHA1 + ")"); + } + add_centered_md_label(main_lay, tr("Official source code repository is available here:")); + add_centered_md_label(main_lay, QString("[") + PROJECT_REPO_URL + "](" + PROJECT_REPO_URL + ")"); + + { + auto txt = std::make_unique(); + txt->setFrameStyle(QFrame::Panel | QFrame::Sunken); + txt->setText(g_gpl_text); + main_lay->addWidget(txt.release()); + } + + { + auto close = std::make_unique(); + close->setText(tr("&Close")); + close->setDefault(true); + connect(close.get(), &QPushButton::clicked, [this](){this->close();}); + main_lay->addWidget(close.release(), 0, Qt::AlignRight); + } + + setLayout(main_lay.release()); +} +} //namespace duck diff --git a/src/qt/version_info_win.hpp b/src/qt/version_info_win.hpp new file mode 100644 index 0000000..818b341 --- /dev/null +++ b/src/qt/version_info_win.hpp @@ -0,0 +1,29 @@ +/* Copyright 2020, Michele Santullo + * This file is part of memoserv. + * + * Memoserv is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Memoserv is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Memoserv. If not, see . + */ + +#pragma once + +#include + +namespace duck { +class VersionInfoWin : public QDialog { + Q_OBJECT +public: + explicit VersionInfoWin (QWidget* parent); +private: +}; +} //namespace duck