ScreenTools.qml 1.93 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 18

    // 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
19 20
    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
21 22 23 24

    property bool isAndroid:        ScreenToolsController.isAndroid
    property bool isiOS:            ScreenToolsController.isiOS
    property bool isMobile:         ScreenToolsController.isMobile
25
    property bool isDebug:          ScreenToolsController.isDebug
dogmaphobic's avatar
dogmaphobic committed
26
    property bool isTinyScreen:     (Screen.width / Screen.pixelDensity) < 120 // 120mm
Don Gagne's avatar
Don Gagne committed
27 28 29 30 31 32 33 34 35 36

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

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

    Text {
37 38 39
        id:     _textMeasure
        text:   "X"

dogmaphobic's avatar
dogmaphobic committed
40
        property real fontWidth:    contentWidth  * (ScreenToolsController.testHighDPI ? 2 : 1)
41
        property real fontHeight:   contentHeight * (ScreenToolsController.testHighDPI ? 2 : 1)
Don Gagne's avatar
Don Gagne committed
42 43 44 45 46 47 48
    }

    Connections {
        target: ScreenToolsController
        onRepaintRequested: repaintRequested()
    }
}