Commit 0657eb50 authored by Shashwat Dixit's avatar Shashwat Dixit Committed by Johnny Jazeix
Browse files

REVIEW: 127471, BUG: 357950, settings, store wdith/height of GCompris and restore it at start up

parent ff91f214
......@@ -28,6 +28,9 @@
#include <QGuiApplication>
#include <QScreen>
#include <QLocale>
#include <QApplication>
#include <QRect>
#include <QDesktopWidget>
#include <QSettings>
#include <QStandardPaths>
......@@ -45,6 +48,8 @@ static const QString INTERNAL_GROUP_KEY = "Internal";
static const QString FAVORITE_GROUP_KEY = "Favorite";
static const QString FULLSCREEN_KEY = "fullscreen";
static const QString PREVIOUS_HEIGHT_KEY = "previousHeight";
static const QString PREVIOUS_WIDTH_KEY = "previousWidth";
static const QString SHOW_LOCKED_ACTIVITIES_KEY = "showLockedActivities";
static const QString ENABLE_AUDIO_VOICES_KEY = "enableAudioVoices";
static const QString ENABLE_AUDIO_EFFECTS_KEY = "enableAudioEffects";
......@@ -84,13 +89,17 @@ ApplicationSettings::ApplicationSettings(QObject *parent): QObject(parent),
m_config(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) +
"/gcompris/" + GCOMPRIS_APPLICATION_NAME + ".conf", QSettings::IniFormat)
{
const QRect &screenSize = QApplication::desktop()->screenGeometry();
// initialize from settings file or default
// general group
m_config.beginGroup(GENERAL_GROUP_KEY);
m_isAudioEffectsEnabled = m_config.value(ENABLE_AUDIO_EFFECTS_KEY, true).toBool();
m_isFullscreen = m_config.value(FULLSCREEN_KEY, true).toBool();
m_isAudioVoicesEnabled = m_config.value(ENABLE_AUDIO_VOICES_KEY, true).toBool();
m_previousHeight = m_config.value(PREVIOUS_HEIGHT_KEY, screenSize.height()).toUInt();
m_previousWidth = m_config.value(PREVIOUS_WIDTH_KEY, screenSize.width()).toUInt();
m_isAudioVoicesEnabled = m_config.value(ENABLE_AUDIO_VOICES_KEY, true).toBool();
m_isVirtualKeyboard = m_config.value(VIRTUALKEYBOARD_KEY,
ApplicationInfo::getInstance()->isMobile()).toBool();
m_locale = m_config.value(LOCALE_KEY, GC_DEFAULT_LOCALE).toString();
......@@ -156,6 +165,8 @@ ApplicationSettings::ApplicationSettings(QObject *parent): QObject(parent),
connect(this, &ApplicationSettings::audioVoicesEnabledChanged, this, &ApplicationSettings::notifyAudioVoicesEnabledChanged);
connect(this, &ApplicationSettings::audioEffectsEnabledChanged, this, &ApplicationSettings::notifyAudioEffectsEnabledChanged);
connect(this, &ApplicationSettings::fullscreenChanged, this, &ApplicationSettings::notifyFullscreenChanged);
connect(this, &ApplicationSettings::previousHeightChanged, this, &ApplicationSettings::notifyPreviousHeightChanged);
connect(this, &ApplicationSettings::previousWidthChanged, this, &ApplicationSettings::notifyPreviousWidthChanged);
connect(this, &ApplicationSettings::localeChanged, this, &ApplicationSettings::notifyLocaleChanged);
connect(this, &ApplicationSettings::fontChanged, this, &ApplicationSettings::notifyFontChanged);
connect(this, &ApplicationSettings::virtualKeyboardChanged, this, &ApplicationSettings::notifyVirtualKeyboardChanged);
......@@ -183,6 +194,8 @@ ApplicationSettings::~ApplicationSettings()
m_config.setValue(FONT_KEY, m_font);
m_config.setValue(IS_CURRENT_FONT_EMBEDDED, m_isEmbeddedFont);
m_config.setValue(FULLSCREEN_KEY, m_isFullscreen);
m_config.setValue(PREVIOUS_HEIGHT_KEY, m_previousHeight);
m_config.setValue(PREVIOUS_WIDTH_KEY, m_previousWidth);
m_config.setValue(VIRTUALKEYBOARD_KEY, m_isVirtualKeyboard);
m_config.setValue(ENABLE_AUTOMATIC_DOWNLOADS, m_isAutomaticDownloadsEnabled);
m_config.setValue(FILTER_LEVEL_MIN, m_filterLevelMin);
......@@ -269,6 +282,18 @@ void ApplicationSettings::notifyFullscreenChanged()
qDebug() << "fullscreen set to: " << m_isFullscreen;
}
void ApplicationSettings::notifyPreviousHeightChanged()
{
updateValueInConfig(GENERAL_GROUP_KEY, PREVIOUS_HEIGHT_KEY, m_previousHeight);
qDebug() << "previous height set to: " << m_previousHeight;
}
void ApplicationSettings::notifyPreviousWidthChanged()
{
updateValueInConfig(GENERAL_GROUP_KEY, PREVIOUS_WIDTH_KEY, m_previousWidth);
qDebug() << "previous width set to: " << m_previousWidth;
}
void ApplicationSettings::notifyVirtualKeyboardChanged()
{
updateValueInConfig(GENERAL_GROUP_KEY, VIRTUALKEYBOARD_KEY, m_isVirtualKeyboard);
......
......@@ -86,6 +86,16 @@ class ApplicationSettings : public QObject
*/
Q_PROPERTY(bool isFullscreen READ isFullscreen WRITE setFullscreen NOTIFY fullscreenChanged)
/**
* Window Height on Application's Startup
*/
Q_PROPERTY(quint32 previousHeight READ previousHeight WRITE setPreviousHeight NOTIFY previousHeightChanged)
/**
* Window Width on Application's Startup
*/
Q_PROPERTY(quint32 previousWidth READ previousWidth WRITE setPreviousWidth NOTIFY previousWidthChanged)
/**
* Whether on-screen keyboard should be enabled per default in activities
* that use it.
......@@ -276,6 +286,22 @@ public:
}
}
qint32 previousHeight() const { return m_previousHeight; }
void setPreviousHeight(qint32 height) {
if(m_previousHeight != height) {
m_previousHeight = height;
emit previousHeightChanged();
}
}
qint32 previousWidth() const { return m_previousWidth; }
void setPreviousWidth(qint32 width) {
if(m_previousWidth != width) {
m_previousWidth = width;
emit previousWidthChanged();
}
}
bool isVirtualKeyboard() const { return m_isVirtualKeyboard; }
void setVirtualKeyboard(const bool newMode) {
m_isVirtualKeyboard = newMode;
......@@ -427,6 +453,8 @@ protected slots:
Q_INVOKABLE void notifyAudioVoicesEnabledChanged();
Q_INVOKABLE void notifyAudioEffectsEnabledChanged();
Q_INVOKABLE void notifyFullscreenChanged();
Q_INVOKABLE void notifyPreviousHeightChanged();
Q_INVOKABLE void notifyPreviousWidthChanged();
Q_INVOKABLE void notifyVirtualKeyboardChanged();
Q_INVOKABLE void notifyLocaleChanged();
Q_INVOKABLE void notifyFontChanged();
......@@ -493,6 +521,8 @@ signals:
void audioVoicesEnabledChanged();
void audioEffectsEnabledChanged();
void fullscreenChanged();
void previousHeightChanged();
void previousWidthChanged();
void virtualKeyboardChanged();
void localeChanged();
void fontChanged();
......@@ -528,6 +558,8 @@ private:
bool m_isAudioVoicesEnabled;
bool m_isAudioEffectsEnabled;
bool m_isFullscreen;
quint32 m_previousHeight;
quint32 m_previousWidth;
bool m_isVirtualKeyboard;
bool m_isAutomaticDownloadsEnabled;
bool m_isEmbeddedFont;
......
......@@ -212,7 +212,8 @@ function quit(parent)
if (aboutToQuit) // don't execute concurrently
return;
aboutToQuit = true;
GCompris.ApplicationSettings.previousHeight = parent.height;
GCompris.ApplicationSettings.previousWidth = parent.width;
GCompris.ApplicationInfo.abandonAudioFocus()
if (GCompris.DownloadManager.downloadIsRunning()) {
......
......@@ -19,7 +19,7 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <QtDebug>
#include <QGuiApplication>
#include <QApplication>
#include <QQuickWindow>
#include <QQmlApplicationEngine>
#include <QStandardPaths>
......@@ -108,7 +108,7 @@ int main(int argc, char *argv[])
// Disable it because we already support HDPI display natively
qunsetenv("QT_DEVICE_PIXEL_RATIO");
QGuiApplication app(argc, argv);
QApplication app(argc, argv);
app.setOrganizationName("KDE");
app.setApplicationName(GCOMPRIS_APPLICATION_NAME);
app.setOrganizationDomain("kde.org");
......
......@@ -44,8 +44,8 @@ import "qrc:/gcompris/src/core/core.js" as Core
Window {
id: main
// Start in window mode at full screen size
width: Screen.width
height: Screen.height
width: ApplicationSettings.previousWidth
height: ApplicationSettings.previousHeight
minimumWidth: 400 * ApplicationInfo.ratio
minimumHeight: 400 * ApplicationInfo.ratio
title: "GCompris"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment