Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Sizing] add simple sizing class
  • Loading branch information
neochapay committed Apr 7, 2017
1 parent 156318c commit 42a25f7
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rpm/qtquickcontrols-nemo.spec
@@ -1,6 +1,6 @@
Name: qt5-qtquickcontrols-nemo
Summary: Nemomobile Qt Quick Controls
Version: 5.1.3
Version: 5.2.0
Release: nemo1
Group: Qt/Qt
License: LGPLv2.1 with exception or GPLv3
Expand Down
6 changes: 4 additions & 2 deletions src/controls/controls.pro
Expand Up @@ -34,7 +34,8 @@ HEADERS += \
qquickfilteringmousearea.h \
nemoimageprovider.h \
themedaemon/mlocalthemedaemonclient.h \
themedaemon/mabstractthemedaemonclient.h
themedaemon/mabstractthemedaemonclient.h \
sizing.h

SOURCES += \
qquicknemocontrolsextensionplugin.cpp \
Expand All @@ -44,7 +45,8 @@ SOURCES += \
qquickfilteringmousearea.cpp \
nemoimageprovider.cpp \
themedaemon/mlocalthemedaemonclient.cpp \
themedaemon/mabstractthemedaemonclient.cpp
themedaemon/mabstractthemedaemonclient.cpp \
sizing.cpp

target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH

Expand Down
7 changes: 7 additions & 0 deletions src/controls/qquicknemocontrolsextensionplugin.cpp
Expand Up @@ -25,6 +25,7 @@
#include "nemopage.h"
#include "qquickfilteringmousearea.h"
#include "nemoimageprovider.h"
#include "sizing.h"

QQuickNemoControlsExtensionPlugin::QQuickNemoControlsExtensionPlugin(QObject *parent) :
QQmlExtensionPlugin(parent)
Expand All @@ -48,7 +49,13 @@ void QQuickNemoControlsExtensionPlugin::registerTypes(const char *uri)

void QQuickNemoControlsExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
Sizing *sizing = new Sizing();

QQmlExtensionPlugin::initializeEngine(engine,uri);
QQmlContext* context = engine->rootContext();

context->setContextProperty("mm",sizing->getScaleFactor());

engine->addImageProvider(QLatin1String("theme"), new NemoImageProvider);
}

45 changes: 45 additions & 0 deletions src/controls/sizing.cpp
@@ -0,0 +1,45 @@
#include "sizing.h"

#include <QScreen>
#include <QDebug>
#include <QGuiApplication>

Sizing::Sizing(QObject *parent) : QObject(parent)
{
m_valid = false;
m_scale_factor = 10;

m_p_height = qgetenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT").toInt();
m_p_width = qgetenv("QT_QPA_EGLFS_PHYSICAL_WIDTH").toInt();

QScreen *screen = QGuiApplication::primaryScreen();

m_height = screen->size().height();
m_width = screen->size().width();

if(m_p_height > 0 && m_p_width >0){
m_valid = true;
scaleFactor();
}else{
if(m_p_height == 0){
qWarning("QT_QPA_EGLFS_PHYSICAL_HEIGHT is not set!");
}

if(m_p_width == 0){
qWarning("QT_QPA_EGLFS_PHYSICAL_WIDTH is not set!");
}

qWarning("Device sizing don`t work");
}
}

void Sizing::scaleFactor()
{
if(m_p_width != 0){
m_scale_factor = m_width/m_p_width;
}

qDebug() << "Scale factor is " << m_scale_factor;
}


27 changes: 27 additions & 0 deletions src/controls/sizing.h
@@ -0,0 +1,27 @@
#ifndef SIZING_H
#define SIZING_H

#include <QObject>

class Sizing : public QObject
{
Q_OBJECT
public:
explicit Sizing(QObject *parent = 0);
bool isValid(){return m_valid;}
int getScaleFactor(){return m_scale_factor;}

private:
bool m_valid;

int m_p_width;
int m_p_height;
int m_width;
int m_height;

int m_scale_factor;

void scaleFactor();
};

#endif // SIZING_H

0 comments on commit 42a25f7

Please sign in to comment.