ScreenTools.qml 2.33 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

dogmaphobic's avatar
dogmaphobic committed
17 18 19 20 21
    // 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
22
    readonly property real  realFontWidth :     _textMeasure.contentWidth
dogmaphobic's avatar
dogmaphobic committed
23

24 25
    // 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
26 27
    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
28 29 30 31

    property bool isAndroid:        ScreenToolsController.isAndroid
    property bool isiOS:            ScreenToolsController.isiOS
    property bool isMobile:         ScreenToolsController.isMobile
32
    property bool isDebug:          ScreenToolsController.isDebug
dogmaphobic's avatar
dogmaphobic committed
33
    property bool isTinyScreen:     (Screen.width / Screen.pixelDensity) < 120 // 120mm
Don Gagne's avatar
Don Gagne committed
34 35 36 37 38 39 40 41 42 43

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

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

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

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