ScreenTools.qml 2.58 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 13
    property real availableHeight: 0

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

dogmaphobic's avatar
dogmaphobic committed
21 22 23 24 25
    // 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
26
    readonly property real  realFontWidth :     _textMeasure.contentWidth
dogmaphobic's avatar
dogmaphobic committed
27

28 29
    // 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
30 31
    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
32 33 34 35

    property bool isAndroid:        ScreenToolsController.isAndroid
    property bool isiOS:            ScreenToolsController.isiOS
    property bool isMobile:         ScreenToolsController.isMobile
36
    property bool isDebug:          ScreenToolsController.isDebug
37 38
    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
39 40 41 42 43 44 45 46 47 48

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

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

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