From a6d0cb84cf26fa453f63a8b68e5a85b98afab578 Mon Sep 17 00:00:00 2001 From: tastytea Date: Tue, 25 Feb 2020 03:22:13 +0100 Subject: [PATCH] Add menu bar and about dialog. --- gui/qml/mainwindow.qml | 70 ++++++++++++++++++++++++++++++++++++-- gui/src/main.cpp | 10 +++++- gui/src/qmlbridge.cpp | 32 +++++++++++++++++ gui/src/qmlbridge.hpp | 22 ++++++++++++ lib/include/fedipotato.hpp | 38 +++++++++++++++++++++ lib/src/fedipotato.cpp | 6 ++++ 6 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 gui/src/qmlbridge.cpp create mode 100644 gui/src/qmlbridge.hpp diff --git a/gui/qml/mainwindow.qml b/gui/qml/mainwindow.qml index 57848b7..68fe2ee 100644 --- a/gui/qml/mainwindow.qml +++ b/gui/qml/mainwindow.qml @@ -1,6 +1,6 @@ import QtQuick 2.10 -import QtQuick.Controls 2.10 -import QtQuick.Layouts 1.10 +import QtQuick.Controls 2.3 +import QtQuick.Layouts 1.3 ApplicationWindow { @@ -9,4 +9,70 @@ ApplicationWindow visible: true width: 400 height: 500 + + menuBar: MenuBar + { + Menu + { + title: "&FediPotato" + MenuItem + { + id: menu_exit + text: qsTr("Exit") + onTriggered: Qt.quit(); + + Shortcut + { + sequence: "Ctrl+Q" + context: Qt.ApplicationShortcut + onActivated: menu_exit.clicked(); + } + } + } + + Menu + { + title: qsTr("&Help") + MenuItem + { + text: qsTr("Website") + onTriggered: Qt.openUrlExternally("http://fedipotato.org/") + } + MenuItem + { + text: qsTr("About FediPotato") + onTriggered: dialog_about.open() + } + } + } + + Dialog + { + id: dialog_about + title: qsTr("About FediPotato") + " " + QMLBridge.get_version() + standardButtons: Dialog.Close + + ColumnLayout + { + width: parent.width + + Label + { + text: qsTr("Client for Fediverse servers.") + } + + Label + { + Layout.fillWidth: true + wrapMode: Text.WordWrap + onLinkActivated: Qt.openUrlExternally(link) + text: qsTr("License AGPLv3: " + + "GNU Affero GPL version 3.
" + + "This program comes with ABSOLUTELY NO WARRANTY. " + + "This is free software, and you are welcome to " + + "redistribute it under certain conditions.") + } + } + } } diff --git a/gui/src/main.cpp b/gui/src/main.cpp index 984c111..9a8ce63 100644 --- a/gui/src/main.cpp +++ b/gui/src/main.cpp @@ -14,15 +14,23 @@ * along with this program. If not, see . */ +#include "qmlbridge.hpp" + #include #include +#include + +using namespace FediPotato; int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - QQmlApplicationEngine engine; + QMLBridge qmlbridge; + QQmlApplicationEngine engine; + // Make qmlbridge callable as QMLBridge in QML files. + engine.rootContext()->setContextProperty("QMLBridge", &qmlbridge); engine.load(QUrl(QStringLiteral("qrc:/qml/mainwindow.qml"))); return QGuiApplication::exec(); diff --git a/gui/src/qmlbridge.cpp b/gui/src/qmlbridge.cpp new file mode 100644 index 0000000..102fb83 --- /dev/null +++ b/gui/src/qmlbridge.cpp @@ -0,0 +1,32 @@ +/* This file is part of FediPotato. + * Copyright © 2020 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, version 3. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "qmlbridge.hpp" +#include "fedipotato.hpp" + +namespace FediPotato +{ + +QMLBridge::QMLBridge(QObject *parent) + : QObject(parent) +{} + +QString QMLBridge::get_version() +{ + return FediPotato::get_version().data(); +} + +} // namespace FediPotato diff --git a/gui/src/qmlbridge.hpp b/gui/src/qmlbridge.hpp new file mode 100644 index 0000000..377ca5b --- /dev/null +++ b/gui/src/qmlbridge.hpp @@ -0,0 +1,22 @@ +#ifndef FEDIPOTATO_GUI_QMLBRIDGE_HPP +#define FEDIPOTATO_GUI_QMLBRIDGE_HPP + +#include +#include + +namespace FediPotato +{ + +class QMLBridge : public QObject +{ + Q_OBJECT + +public: + explicit QMLBridge(QObject *parent = nullptr); + + Q_INVOKABLE static QString get_version(); +}; + +} // namespace FediPotato + +#endif // FEDIPOTATO_GUI_QMLBRIDGE_HPP diff --git a/lib/include/fedipotato.hpp b/lib/include/fedipotato.hpp index 9e9c5d7..506cbc9 100644 --- a/lib/include/fedipotato.hpp +++ b/lib/include/fedipotato.hpp @@ -17,9 +17,47 @@ #ifndef FEDIPOTATO_HPP #define FEDIPOTATO_HPP +#include + +/*! + * @brief High-level interface to fediverse accounts and their data. + * + * @since 0.1.0 + */ namespace FediPotato { +using std::string_view; + +class FediPotato +{ +public: + //! Default constructor + FediPotato() = default; + + //! Copy constructor + FediPotato(const FediPotato &other) = default; + + //! Move constructor + FediPotato(FediPotato &&other) noexcept = default; + + //! Destructor + virtual ~FediPotato() noexcept = default; + + //! Copy assignment operator + FediPotato& operator=(const FediPotato &other) = default; + + //! Move assignment operator + FediPotato& operator=(FediPotato &&other) noexcept = default; + + /*! + * @brief Return the version. + * + * @since 0.1.0 + */ + static string_view get_version(); +}; + } // namespace FediPotato #endif // FEDIPOTATO_HPP diff --git a/lib/src/fedipotato.cpp b/lib/src/fedipotato.cpp index 0e1af7b..ea10f6c 100644 --- a/lib/src/fedipotato.cpp +++ b/lib/src/fedipotato.cpp @@ -15,8 +15,14 @@ */ #include "fedipotato.hpp" +#include "version.hpp" namespace FediPotato { +string_view FediPotato::get_version() +{ + return version; +} + } // namespace FediPotato