Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store window size #3

Merged
merged 2 commits into from Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions libglacierapp.pro
@@ -1,3 +1,6 @@
TEMPLATE=subdirs
SUBDIRS += src examples
examples.depends = src

DISTFILES += \
rpm/libglacierapp.spec
3 changes: 2 additions & 1 deletion rpm/libglacierapp.spec
Expand Up @@ -5,13 +5,14 @@

Name: libglacierapp
Summary: Glacier Application library
Version: 0.3
Version: 0.4.0
Release: 1
Group: System/Libraries
License: LGPL
URL: https://github.com/nemomobile-ux/libglacierapp
Source0: %{name}-%{version}.tar.bz2

BuildRequires: pkgconfig(mlite5)
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5Quick)
Expand Down
42 changes: 42 additions & 0 deletions src/glacierapp.cpp
Expand Up @@ -33,6 +33,12 @@
#include <MDeclarativeCache>
#endif

#ifdef HAS_MLITE5
#include <MGConfItem>
#else
#include <QSettings>
#endif

QGuiApplication *GlacierApp::app(int &argc, char **argv)
{
setenv("QT_QUICK_CONTROLS_STYLE", "Nemo", 1);
Expand All @@ -50,6 +56,8 @@ QGuiApplication *GlacierApp::app(int &argc, char **argv)
myappTranslator.load(QStringLiteral("/usr/share/%1/translations/%1_%2.qm").arg(app->applicationName()).arg(QLocale::system().name()));
app->installTranslator(&myappTranslator);

connect(app,&QGuiApplication::aboutToQuit, saveWindowSize);

return app;
}

Expand Down Expand Up @@ -81,13 +89,28 @@ QQuickWindow *GlacierApp::showWindow()
qCritical() << "Top object is not Window!";
return nullptr;
}

if(QCoreApplication::arguments().contains("--prestart") || QCoreApplication::arguments().contains("-p"))
{
qDebug() << "Application run in shadow mode";
}
else{
if (QCoreApplication::arguments().contains("--window") || QCoreApplication::arguments().contains("-w"))
{
/*Load last params of window*/
#ifdef HAS_MLITE5
window->setX((MGConfItem(QStringLiteral("/nemo/apps/%1/size/x").arg(qApp->applicationName()))).value(0).toInt());
window->setY((MGConfItem(QStringLiteral("/nemo/apps/%1/size/y").arg(qApp->applicationName()))).value(0).toInt());
window->setWidth((MGConfItem(QStringLiteral("/nemo/apps/%1/size/w").arg(qApp->applicationName()))).value(480).toInt());
window->setHeight((MGConfItem(QStringLiteral("/nemo/apps/%1/size/h").arg(qApp->applicationName()))).value(480).toInt());
#else
QSettings settings;
window->setX(settings.value("size/x",0).toInt());
window->setY(settings.value("size/y",0).toInt());
window->setWidth(settings.value("size/w",480).toInt());
window->setHeight(settings.value("size/h",640).toInt());

#endif
window->show();
}
else
Expand All @@ -97,3 +120,22 @@ QQuickWindow *GlacierApp::showWindow()
}
return window;
}

void GlacierApp::saveWindowSize()
{
QQmlApplicationEngine* engine = GlacierApp::engine(qApp);
QObject *topLevel = engine->rootObjects().first();
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
#ifdef HAS_MLITE5
MGConfItem(QStringLiteral("/nemo/apps/%1/size/x").arg(qApp->applicationName())).set(window->x());
MGConfItem(QStringLiteral("/nemo/apps/%1/size/y").arg(qApp->applicationName())).set(window->y());
MGConfItem(QStringLiteral("/nemo/apps/%1/size/w").arg(qApp->applicationName())).set(window->width());
MGConfItem(QStringLiteral("/nemo/apps/%1/size/h").arg(qApp->applicationName())).set(window->height());
#else
QSettings settings;
settings.setValue("size/x",window->x());
settings.setValue("size/y",window->y());
settings.setValue("size/w",window->width());
settings.setValue("size/h",window->height());
#endif
}
2 changes: 2 additions & 0 deletions src/glacierapp.h
Expand Up @@ -33,6 +33,8 @@ class GlacierApp : public QObject
static QQmlApplicationEngine* engine(QObject *parent = nullptr);
static QQuickWindow* showWindow();

private:
static void saveWindowSize();
};

#endif // GLACIERAPP_H
13 changes: 9 additions & 4 deletions src/src.pro
Expand Up @@ -13,7 +13,15 @@ packagesExist(qdeclarative5-boostable) {
warning("qdeclarative-boostable not available; startup times will be slower")
}

VERSION = 0.1.0
packagesExist(mlite5) {
message("Building with mlite5 support")
PKGCONFIG += mlite5
DEFINES += HAS_MLITE5
} else {
warning("mlite5 not available;")
}

VERSION = 0.4.0

# Input
SOURCES += \
Expand Down Expand Up @@ -42,6 +50,3 @@ QMAKE_EXTRA_TARGETS += pkgconfig
QMAKE_CLEAN += $${pkgconfig.files}

INSTALLS += target public_headers

DISTFILES += \
../rpm/libglacierapp.spec