ScreenTools.qml 2.54 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 10 11

import QGroundControl.ScreenToolsController 1.0

Item {
    signal repaintRequested

12
    readonly property real defaultFontPixelSize:    _textMeasure.fontHeight * ScreenToolsController.defaultFontPixelSizeRatio
Don Gagne's avatar
Don Gagne committed
13
    readonly property real defaultFontPixelHeight:  defaultFontPixelSize
14
    readonly property real defaultFontPixelWidth:   _textMeasure.fontWidth
Don Gagne's avatar
Don Gagne committed
15
    readonly property real smallFontPixelSize:      defaultFontPixelSize * ScreenToolsController.smallFontPixelSizeRatio
16 17
    readonly property real smallFontPixelHeight:    smallFontPixelSize
    readonly property real smallFontPixelWidth:     defaultFontPixelWidth * ScreenToolsController.smallFontPixelSizeRatio
18

dogmaphobic's avatar
dogmaphobic committed
19 20 21 22 23
    // To proportionally scale fonts

    readonly property real  _defaultFontHeight: 16
    readonly property real  fontHRatio:         isTinyScreen ? (_textMeasure.contentHeight / _defaultFontHeight) * 0.75 : (_textMeasure.contentHeight / _defaultFontHeight)
    readonly property real  realFontHeight:     _textMeasure.contentHeight
dogmaphobic's avatar
dogmaphobic committed
24
    readonly property real  realFontWidth :     _textMeasure.contentWidth
dogmaphobic's avatar
dogmaphobic committed
25

26 27
    // On OSX ElCapitan with Qt 5.4.0 any font pixel size above 19 shows garbage test. No idea why at this point.
    // Will remove Math.min when problem is figure out.
Don Gagne's avatar
Don Gagne committed
28 29
    readonly property real mediumFontPixelSize:     Math.min(defaultFontPixelSize * ScreenToolsController.mediumFontPixelSizeRatio, ScreenToolsController.isMobile ? 10000 : 19)
    readonly property real largeFontPixelSize:      Math.min(defaultFontPixelSize * ScreenToolsController.largeFontPixelSizeRatio, ScreenToolsController.isMobile ? 10000 : 19)
Don Gagne's avatar
Don Gagne committed
30 31 32 33

    property bool isAndroid:        ScreenToolsController.isAndroid
    property bool isiOS:            ScreenToolsController.isiOS
    property bool isMobile:         ScreenToolsController.isMobile
34
    property bool isDebug:          ScreenToolsController.isDebug
35 36
    property bool isTinyScreen:     (Screen.width  / Screen.pixelDensity) < 120 // 120mm
    property bool isShortScreen:    ScreenToolsController.isMobile && ((Screen.height / Screen.width) < 0.6) // Nexus 7 for example
Don Gagne's avatar
Don Gagne committed
37 38 39 40 41 42 43 44 45 46

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

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

    Text {
47 48
        id:     _textMeasure
        text:   "X"
dogmaphobic's avatar
dogmaphobic committed
49
        property real fontWidth:    contentWidth  * (ScreenToolsController.testHighDPI ? 2 : 1)
50
        property real fontHeight:   contentHeight * (ScreenToolsController.testHighDPI ? 2 : 1)
Don Gagne's avatar
Don Gagne committed
51 52
    }
}