forked from nemomobile/qtquickcontrols-nemo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Sizing] add simple sizing class
- Loading branch information
Showing
5 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
|
|
||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |