diff --git a/src/controls/AboutPage.qml b/src/controls/AboutPage.qml index d84f689c..3db43d9f 100644 --- a/src/controls/AboutPage.qml +++ b/src/controls/AboutPage.qml @@ -1,234 +1,234 @@ /* * 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: qsTr("About") Component { id: licencePage ScrollablePage { property alias text: content.text QQC2.TextArea { id: content readOnly: true } } } Component { id: personDelegate RowLayout { height: implicitHeight + (Units.smallSpacing * 2) spacing: Units.smallSpacing * 2 Icon { width: Units.iconSizes.smallMedium height: width source: "user" } QQC2.Label { text: modelData.emailAddress ? qsTr("%1 <%2>").arg(modelData.name).arg(modelData.emailAddress) : modelData.name } } } FormLayout { id: form GridLayout { columns: 2 Layout.fillWidth: true Icon { Layout.rowSpan: 2 Layout.preferredHeight: Units.iconSizes.huge Layout.preferredWidth: height Layout.maximumWidth: page.width / 3; Layout.rightMargin: Units.largeSpacing - source: page.aboutData.programLogo || page.aboutData.programIconName || page.aboutData.componentName + source: Settings.applicationWindowIcon || page.aboutData.programLogo || page.aboutData.programIconName || page.aboutData.componentName } Heading { Layout.fillWidth: true text: page.aboutData.displayName + " " + page.aboutData.version } Heading { Layout.fillWidth: true level: 2 wrapMode: Text.WordWrap text: page.aboutData.shortDescription } } Separator { Layout.fillWidth: true } Heading { FormData.isSection: true text: qsTr("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 } Component { id: licenseLinkButton RowLayout { Layout.leftMargin: Units.smallSpacing QQC2.Label { text: qsTr("License:") } LinkButton { text: modelData.name onClicked: applicationWindow().pageStack.push(licencePage, { text: modelData.text, title: modelData.name } ) } } } Component { id: licenseTextItem RowLayout { Layout.leftMargin: Units.smallSpacing QQC2.Label { text: qsTr("License: %1").arg(modelData.name) } } } Repeater { model: aboutData.licenses delegate: applicationWindow().pageStack ? licenseLinkButton : licenseTextItem } Heading { FormData.isSection: visible text: qsTr("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 FormData.isSection: visible text: qsTr("Authors") visible: aboutData.authors.length > 0 } Repeater { model: aboutData.authors delegate: personDelegate } Heading { height: visible ? implicitHeight : 0 FormData.isSection: visible text: qsTr("Credits") visible: repCredits.count > 0 } Repeater { id: repCredits model: aboutData.credits delegate: personDelegate } Heading { height: visible ? implicitHeight : 0 FormData.isSection: visible text: qsTr("Translators") visible: repTranslators.count > 0 } Repeater { id: repTranslators model: aboutData.translators delegate: personDelegate } } } diff --git a/src/settings.cpp b/src/settings.cpp index b9f79a6d..52ac71cf 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,160 +1,170 @@ /* * Copyright 2016 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * 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 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. */ #include "settings.h" #include #include #include #include #include +#include #include "libkirigami/tabletmodewatcher.h" #ifndef KIRIGAMI_BUILD_TYPE_STATIC #include "../kirigami_version.h" #endif class SettingsSingleton { public: Settings self; }; Q_GLOBAL_STATIC(SettingsSingleton, privateSettingsSelf) Settings::Settings(QObject *parent) : QObject(parent) { m_tabletModeAvailable = Kirigami::TabletModeWatcher::self()->isTabletModeAvailable(); connect(Kirigami::TabletModeWatcher::self(), &Kirigami::TabletModeWatcher::tabletModeAvailableChanged, this, [this](bool tabletModeAvailable) { setTabletModeAvailable(tabletModeAvailable); }); m_tabletMode = Kirigami::TabletModeWatcher::self()->isTabletMode(); connect(Kirigami::TabletModeWatcher::self(), &Kirigami::TabletModeWatcher::tabletModeChanged, this, [this](bool tabletMode) { setTabletMode(tabletMode); }); #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) m_mobile = true; #else //Mostly for debug purposes and for platforms which are always mobile, //such as Plasma Mobile if (qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MOBILE")) { m_mobile = QByteArrayList{"1", "true"}.contains(qgetenv("QT_QUICK_CONTROLS_MOBILE")); } else { m_mobile = false; } #endif const QString configPath = QStandardPaths::locate(QStandardPaths::ConfigLocation, QStringLiteral("kdeglobals")); if (QFile::exists(configPath)) { QSettings globals(configPath, QSettings::IniFormat); globals.beginGroup(QStringLiteral("KDE")); m_scrollLines = qMax(1, globals.value(QStringLiteral("WheelScrollLines"), 3).toInt()); } else { m_scrollLines = 3; } } Settings::~Settings() { } Settings *Settings::self() { return &privateSettingsSelf()->self; } void Settings::setTabletModeAvailable(bool mobileAvailable) { if (mobileAvailable == m_tabletModeAvailable) { return; } m_tabletModeAvailable = mobileAvailable; emit tabletModeAvailableChanged(); } bool Settings::isTabletModeAvailable() const { return m_tabletModeAvailable; } void Settings::setIsMobile(bool mobile) { if (mobile == m_mobile) { return; } m_mobile = mobile; emit isMobileChanged(); } bool Settings::isMobile() const { return m_mobile; } void Settings::setTabletMode(bool tablet) { if (tablet == m_tabletMode) { return; } m_tabletMode = tablet; emit tabletModeChanged(); } bool Settings::tabletMode() const { return m_tabletMode; } QString Settings::style() const { return m_style; } void Settings::setStyle(const QString &style) { m_style = style; } int Settings::mouseWheelScrollLines() const { return m_scrollLines; } QStringList Settings::information() const { return { #ifndef KIRIGAMI_BUILD_TYPE_STATIC tr("KDE Frameworks %1").arg(QStringLiteral(KIRIGAMI2_VERSION_STRING)), #endif tr("The %1 windowing system").arg(QGuiApplication::platformName()), tr("Qt %2 (built against %3)").arg(QString::fromLocal8Bit(qVersion()), QStringLiteral(QT_VERSION_STR)) }; } + +QVariant Settings::applicationWindowIcon() const +{ + const QIcon& windowIcon = qApp->windowIcon(); + if (windowIcon.isNull()) { + return QVariant(); + } + return windowIcon; +} diff --git a/src/settings.h b/src/settings.h index 75ebbf79..9613be8a 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,109 +1,120 @@ /* * Copyright 2016 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * 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 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. */ #ifndef SETTINGS_H #define SETTINGS_H #include +#include /** * This class contains global kirigami settings about the current device setup * It is exposed to QML as the singleton "Settings" */ class Settings : public QObject { Q_OBJECT /** * True if the system can dynamically enter in tablet mode * (or the device is actually a tablet). * such as transformable laptops that support keyboard detachment */ Q_PROPERTY(bool tabletModeAvailable READ isTabletModeAvailable NOTIFY tabletModeAvailableChanged) /** * True if we are running on a small mobile device such as a mobile phone * This is used when we want to do specific adaptations to our UI for * small screen form factors, such as having bigger touch areas. */ Q_PROPERTY(bool isMobile READ isMobile NOTIFY isMobileChanged) /** * True if the device we are running on is behaving like a tablet: * Note that this doesn't mean exactly a tablet form factor, but * that the preferred input mode for the device is the touch screen * and that pointer and keyboard are either secondary or not available. */ Q_PROPERTY(bool tabletMode READ tabletMode NOTIFY tabletModeChanged) /** * name of the QtQuickControls2 style we are using, * for instance org.kde.desktop, Plasma, Material, Universal etc */ Q_PROPERTY(QString style READ style CONSTANT) //TODO: make this adapt without file watchers? /** * How many lines of text the mouse wheel should scroll */ 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) + + /** + * @returns application window icon, basically \QApplication::windowIcon() + * + * @since 5.62 + * @since org.kde.kirigami 2.10 + */ + Q_PROPERTY(QVariant applicationWindowIcon READ applicationWindowIcon CONSTANT) public: Settings(QObject *parent = nullptr); ~Settings(); void setTabletModeAvailable(bool mobile); bool isTabletModeAvailable() const; void setIsMobile(bool mobile); bool isMobile() const; void setTabletMode(bool tablet); bool tabletMode() const; QString style() const; void setStyle(const QString &style); int mouseWheelScrollLines() const; QStringList information() const; + + QVariant applicationWindowIcon() const; static Settings *self(); Q_SIGNALS: void tabletModeAvailableChanged(); void tabletModeChanged(); void isMobileChanged(); private: QString m_style; int m_scrollLines = 0; bool m_tabletModeAvailable : 1; bool m_mobile : 1; bool m_tabletMode : 1; }; #endif