diff --git a/src/settings.cpp b/src/settings.cpp index 3490745f..7c603f57 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,84 +1,105 @@ /* * 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 "libkirigami/tabletmodewatcher.h" Settings::Settings(QObject *parent) : QObject(parent) { + m_mobileAvailable = Kirigami::TabletModeWatcher::self()->isTabletModeAvailable(); + connect(Kirigami::TabletModeWatcher::self(), &Kirigami::TabletModeWatcher::tabletModeAvailableChanged, + this, [this](bool tabletModeAvailable) { + setIsMobileAvailable(tabletModeAvailable); + }); + m_mobile = Kirigami::TabletModeWatcher::self()->isTabletMode(); connect(Kirigami::TabletModeWatcher::self(), &Kirigami::TabletModeWatcher::tabletModeChanged, this, [this](bool tabletMode) { setIsMobile(tabletMode); }); 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() { } +void Settings::setIsMobileAvailable(bool mobileAvailable) +{ + if (mobileAvailable == m_mobileAvailable) { + return; + } + + m_mobileAvailable = mobileAvailable; + emit isMobileAvailableChanged(); +} + +bool Settings::isMobileAvailable() const +{ + return m_mobileAvailable; +} + void Settings::setIsMobile(bool mobile) { if (mobile == m_mobile) { return; } m_mobile = mobile; emit isMobileChanged(); } bool Settings::isMobile() const { return m_mobile; } QString Settings::style() const { return m_style; } void Settings::setStyle(const QString &style) { m_style = style; } int Settings::mouseWheelScrollLines() const { return m_scrollLines; } #include "moc_settings.cpp" diff --git a/src/settings.h b/src/settings.h index 8143dbe2..95211990 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,54 +1,60 @@ /* * 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 class Settings : public QObject { Q_OBJECT + Q_PROPERTY(bool isMobileAvailable READ isMobileAvailable NOTIFY isMobileAvailableChanged) Q_PROPERTY(bool isMobile READ isMobile NOTIFY isMobileChanged) Q_PROPERTY(QString style READ style CONSTANT) //TODO: make this adapt without file watchers? Q_PROPERTY(int mouseWheelScrollLines READ mouseWheelScrollLines CONSTANT) public: Settings(QObject *parent=0); ~Settings(); + void setIsMobileAvailable(bool mobile); + bool isMobileAvailable() const; + void setIsMobile(bool mobile); bool isMobile() const; QString style() const; void setStyle(const QString &style); int mouseWheelScrollLines() const; Q_SIGNALS: + void isMobileAvailableChanged(); void isMobileChanged(); private: QString m_style; int m_scrollLines = 0; + bool m_mobileAvailable : 1; bool m_mobile : 1; }; #endif