diff --git a/kirigami.qrc b/kirigami.qrc --- a/kirigami.qrc +++ b/kirigami.qrc @@ -64,6 +64,9 @@ src/controls/ApplicationHeader.qml src/controls/Heading.qml src/controls/ScrollablePage.qml + src/controls/AboutPage.qml + src/controls/UrlButton.qml + src/controls/LinkButton.qml src/controls/Label.qml src/controls/BasicListItem.qml src/controls/AbstractApplicationHeader.qml diff --git a/src/controls/AboutPage.qml b/src/controls/AboutPage.qml new file mode 100644 --- /dev/null +++ b/src/controls/AboutPage.qml @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2018 Aleix Pol Gonzalez + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library/Lesser General Public License + * version 2, or (at your option) any later version, as published by the + * Free Software Foundation + * + * 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 General Public License for more details + * + * You should have received a copy of the GNU Library/Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.1 +import QtQuick.Controls 2.4 as QQC2 +import QtQuick.Layouts 1.3 +import org.kde.kirigami 2.5 + +/** + * An about page that is ready to integrate in a kirigami app + * + * Allows to have a page that will show the copyright notice of the application + * together with the contributors and some information of which platform it's + * running on. + * + * @since 5.52 + * @since org.kde.kirigami 2.6 + */ +ScrollablePage +{ + id: page + /** + * An object with the same shape of KAboutData + * + * For example: + * @code + * aboutData: { + "displayName" : "KirigamiApp", + "productName" : "kirigami/app", + "componentName" : "kirigamiapp", + "shortDescription" : "A Kirigami example", + "homepage" : "", + "bugAddress" : "submit@bugs.kde.org", + "version" : "5.14.80", + "otherText" : "", + "authors" : [ + { + "name" : "...", + "task" : "", + "emailAddress" : "somebody@kde.org", + "webAddress" : "", + "ocsUsername" : "" + } + ], + "credits" : [], + "translators" : [], + "licenses" : [ + { + "name" : "GPL v2", + "text" : "long, boring, license text", + "spdx" : "GPL-2.0" + } + ], + "copyrightStatement" : "© 2010-2018 Plasma Development Team", + "desktopFileName" : "org.kde.kirigamiapp" + } + @endcode + * + * @see KAboutData + */ + property var aboutData + + title: i18n("About") + Component { + id: licencePage + ScrollablePage { + property alias text: content.text + QQC2.TextArea { + id: content + readOnly: true + } + } + } + + Component { + id: personDelegate + AbstractCard { + Layout.fillWidth: true + contentItem: RowLayout { + Layout.preferredHeight: Units.iconSizes.medium + Icon { + Layout.fillHeight: true + Layout.alignment: Qt.AlignVCenter + Layout.minimumWidth: Units.iconSizes.medium + Layout.maximumWidth: Units.iconSizes.medium + source: "https://www.gravatar.com/avatar/" + Qt.md5(modelData.emailAddress) + "?d=404&s=" + Units.iconSizes.medium + fallback: "user" + } + QQC2.Label { + Layout.fillWidth: true + text: i18n("%1 <%2>", modelData.name, modelData.emailAddress) + } + } + } + } + + ColumnLayout { + GridLayout { + columns: 2 + Layout.fillWidth: true + Layout.preferredHeight: Units.iconSizes.huge + + Icon { + Layout.rowSpan: 2 + Layout.fillHeight: true + Layout.minimumWidth: height + Layout.rightMargin: Units.largeSpacing + source: page.aboutData.programLogo || page.aboutData.programIconName + } + Heading { + Layout.fillWidth: true + text: page.aboutData.displayName + " " + page.aboutData.version + } + Heading { + Layout.fillWidth: true + level: 2 + text: page.aboutData.shortDescription + } + } + + Separator { + Layout.fillWidth: true + } + + Heading { + text: i18n("Copyright") + } + QQC2.Label { + Layout.leftMargin: Units.gridUnit + text: aboutData.otherText + visible: text.length > 0 + } + QQC2.Label { + Layout.leftMargin: Units.gridUnit + text: aboutData.copyrightStatement + visible: text.length > 0 + } + UrlButton { + Layout.leftMargin: Units.gridUnit + url: aboutData.homepage + visible: url.length > 0 + } + + Repeater { + model: aboutData.licenses + delegate: RowLayout { + Layout.leftMargin: Units.gridUnit + QQC2.Label { text: i18n("License:" ) } + LinkButton { + text: modelData.name + onClicked: applicationWindow().pageStack.push(licencePage, { text: modelData.text, title: modelData.name } ) + } + } + } + + Heading { + text: i18n("Libraries in use") + visible: Settings.information + } + Repeater { + model: Settings.information + delegate: QQC2.Label { + Layout.leftMargin: Units.gridUnit + id: libraries + text: modelData + } + } + Heading { + Layout.fillWidth: true + text: i18n("Authors") + } + + Repeater { + model: aboutData.authors + delegate: personDelegate + } + Heading { + text: i18n("Credits") + visible: repCredits.count > 0 + } + Repeater { + id: repCredits + model: aboutData.translators + delegate: personDelegate + } + Heading { + text: i18n("Translators") + visible: repTranslators.count > 0 + } + Repeater { + id: repTranslators + model: aboutData.translators + delegate: personDelegate + } + } +} diff --git a/src/controls/LinkButton.qml b/src/controls/LinkButton.qml new file mode 100644 --- /dev/null +++ b/src/controls/LinkButton.qml @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2018 Aleix Pol Gonzalez + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library/Lesser General Public License + * version 2, or (at your option) any later version, as published by the + * Free Software Foundation + * + * 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 General Public License for more details + * + * You should have received a copy of the GNU Library/Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.2 +import org.kde.kirigami 2.0 +import QtQuick.Controls 2.1 as QQC2 + +/** + * Shows a Button that looks like a link + * + * Uses the link color settings and allows to trigger an action when clicked. + * + * Maps to the Command Link in the HIG: + * https://hig.kde.org/components/navigation/commandlink.html + * + * @since 5.52 + * @since org.kde.kirigami 2.6 + */ +QQC2.Label { + id: control + + property Action action: null + property alias acceptedButtons: area.acceptedButtons + Accessible.role: Accessible.Button + Accessible.name: text + Accessible.onPressAction: control.clicked(null) + + text: action ? action.text : "" + enabled: !action || action.enabled + onClicked: if (action) action.trigger() + + font.underline: control.enabled && area.containsMouse + color: enabled ? Theme.linkColor : Theme.textColor + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + + signal pressed(QtObject mouse) + signal clicked(QtObject mouse) + MouseArea { + id: area + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + + onClicked: control.clicked(mouse) + onPressed: control.pressed(mouse) + } +} diff --git a/src/controls/UrlButton.qml b/src/controls/UrlButton.qml new file mode 100644 --- /dev/null +++ b/src/controls/UrlButton.qml @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2018 Aleix Pol Gonzalez + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library/Lesser General Public License + * version 2, or (at your option) any later version, as published by the + * Free Software Foundation + * + * 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 General Public License for more details + * + * You should have received a copy of the GNU Library/Lesser General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.2 +import org.kde.kirigami 2.0 as Kirigami +import QtQuick.Controls 2.1 as QQC2 + +/** + * A link button that contains a URL + * + * It will open the url by default, allow to copy it if triggered with the + * secondary mouse button. + * + * @since 5.52 + * @since org.kde.kirigami 2.6 + */ +LinkButton +{ + id: button + property string url + text: url + visible: text.length > 0 + acceptedButtons: Qt.LeftButton | Qt.RightButton + + onPressed: if (mouse.button === Qt.RightButton) { + menu.popup() + } + onClicked: if (mouse.button !== Qt.RightButton) { + Qt.openUrlExternally(url) + } + + QQC2.Menu { + id: menu + QQC2.MenuItem { + text: i18n("Copy link address") + onClicked: app.copyTextToClipboard(button.url) + } + } +} diff --git a/src/kirigamiplugin.cpp b/src/kirigamiplugin.cpp --- a/src/kirigamiplugin.cpp +++ b/src/kirigamiplugin.cpp @@ -174,6 +174,11 @@ qmlRegisterType(componentUrl(QStringLiteral("ActionToolBar.qml")), uri, 2, 5, "ActionToolBar"); qmlRegisterUncreatableType(uri, 2, 5, "ScenePosition", QStringLiteral("Cannot create objects of type ScenePosition, use it as an attached property")); + //2.6 + qmlRegisterType(componentUrl(QStringLiteral("AboutPage.qml")), uri, 2, 6, "AboutPage"); + qmlRegisterType(componentUrl(QStringLiteral("LinkButton.qml")), uri, 2, 6, "LinkButton"); + qmlRegisterType(componentUrl(QStringLiteral("UrlButton.qml")), uri, 2, 6, "UrlButton"); + qmlProtectModule(uri, 2); } diff --git a/src/qmldir b/src/qmldir --- a/src/qmldir +++ b/src/qmldir @@ -43,3 +43,6 @@ ListItemDragHandle 2.5 ListItemDragHandle.qml ActionToolBar 2.5 ActionToolBar.qml BannerImage 2.5 private/BannerImage.qml +AboutPage 2.6 AboutPage.qml +UrlButton 2.6 UrlButton.qml +LinkButton 2.6 LinkButton.qml diff --git a/src/settings.h b/src/settings.h --- a/src/settings.h +++ b/src/settings.h @@ -63,6 +63,14 @@ */ Q_PROPERTY(int mouseWheelScrollLines READ mouseWheelScrollLines CONSTANT) + /** + * @returns runtime information about the libraries in use + * + * @since 5.52 + * @since org.kde.kirigami 2.6 + */ + Q_PROPERTY(QStringList information READ information CONSTANT) + public: Settings(QObject *parent = nullptr); ~Settings(); @@ -81,6 +89,8 @@ int mouseWheelScrollLines() const; + QStringList information() const; + Q_SIGNALS: void tabletModeAvailableChanged(); void tabletModeChanged(); diff --git a/src/settings.cpp b/src/settings.cpp --- a/src/settings.cpp +++ b/src/settings.cpp @@ -23,8 +23,10 @@ #include #include #include +#include #include "libkirigami/tabletmodewatcher.h" +#include "../kirigami_version.h" Settings::Settings(QObject *parent) : QObject(parent) @@ -129,5 +131,11 @@ return m_scrollLines; } -#include "moc_settings.cpp" - +QStringList Settings::information() const +{ + return { + tr("KDE Frameworks %1").arg(QStringLiteral(KIRIGAMI2_VERSION_STRING)), + tr("The %1 windowing system").arg(QGuiApplication::platformName()), + tr("Qt %2 (built against %3)").arg(QString::fromLocal8Bit(qVersion()), QStringLiteral(QT_VERSION_STR)) + }; +}