ScreenTools.qml 3.1 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2
pragma Singleton

dogmaphobic's avatar
dogmaphobic committed
3
import QtQuick 2.4
Don Gagne's avatar
Don Gagne committed
4
import QtQuick.Controls 1.2
dogmaphobic's avatar
dogmaphobic committed
5
import QtQuick.Window 2.2
Don Gagne's avatar
Don Gagne committed
6 7 8 9

import QGroundControl.ScreenToolsController 1.0

Item {
10 11
    id: _screenTools

Don Gagne's avatar
Don Gagne committed
12 13
    signal repaintRequested

14
    property real availableHeight:          0
15

dogmaphobic's avatar
dogmaphobic committed
16 17 18 19 20 21 22
    //-- These are computed at runtime
    property real defaultFontPointSize:     10
    property real defaultFontPixelHeight:   10
    property real defaultFontPixelWidth:    10
    property real smallFontPointSize:       10
    property real mediumFontPointSize:      10
    property real largeFontPointSize:       10
dogmaphobic's avatar
dogmaphobic committed
23

24 25 26
    readonly property real smallFontPointRatio:      0.75
    readonly property real mediumFontPointRatio:     1.25
    readonly property real largeFontPointRatio:      1.5
dogmaphobic's avatar
dogmaphobic committed
27

Don Gagne's avatar
Don Gagne committed
28 29 30
    property bool isAndroid:        ScreenToolsController.isAndroid
    property bool isiOS:            ScreenToolsController.isiOS
    property bool isMobile:         ScreenToolsController.isMobile
31
    property bool isDebug:          ScreenToolsController.isDebug
32
    property bool isTinyScreen:     (Screen.width / Screen.pixelDensity) < 120 // 120mm
33
    property bool isShortScreen:    ScreenToolsController.isMobile && ((Screen.height / Screen.width) < 0.6) // Nexus 7 for example
Don Gagne's avatar
Don Gagne committed
34

35 36 37
    readonly property string normalFontFamily:      "opensans"
    readonly property string demiboldFontFamily:    "opensans-demibold"

Don Gagne's avatar
Don Gagne committed
38 39 40 41 42 43 44 45
    function mouseX() {
        return ScreenToolsController.mouseX()
    }

    function mouseY() {
        return ScreenToolsController.mouseY()
    }

46 47 48 49 50 51
    Text {
        id:     _defaultFont
        text:   "X"
        property real fontHeight: contentHeight
    }

Don Gagne's avatar
Don Gagne committed
52
    Text {
53 54
        id:     _textMeasure
        text:   "X"
55
        font.family:    normalFontFamily
56 57 58 59 60 61 62 63 64 65 66 67 68
        font.pointSize: {
            if(ScreenToolsController.isMobile) {
                // Small Devices
                if((Screen.width / Screen.pixelDensity) < 120) {
                    return 11;
                // iOS
                } else if(ScreenToolsController.isiOS) {
                    return 13;
                // Android
                } else {
                    return 14;
                }
            } else {
dogmaphobic's avatar
dogmaphobic committed
69 70
                //-- Mac OS
                if(ScreenToolsController.isMacOS)
71
                    return _defaultFont.font.pointSize - 1
dogmaphobic's avatar
dogmaphobic committed
72 73 74
                //-- Linux
                if(ScreenToolsController.isLinux)
                    return _defaultFont.font.pointSize - 3.25
75 76
                else
                    return _defaultFont.font.pointSize
77
            }
78 79 80 81 82 83 84 85 86 87
        }
        property real   fontWidth:    contentWidth
        property real   fontHeight:   contentHeight
        Component.onCompleted: {
            defaultFontPointSize    = _textMeasure.font.pointSize
            defaultFontPixelHeight  = _textMeasure.fontHeight
            defaultFontPixelWidth   = _textMeasure.fontWidth
            smallFontPointSize      = defaultFontPointSize  * _screenTools.smallFontPointRatio
            mediumFontPointSize     = defaultFontPointSize  * _screenTools.mediumFontPointRatio
            largeFontPointSize      = defaultFontPointSize  * _screenTools.largeFontPointRatio
88
        }
Don Gagne's avatar
Don Gagne committed
89 90
    }
}