ScreenTools.h 7.5 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1
/*=====================================================================
2

Don Gagne's avatar
Don Gagne committed
3
 QGroundControl Open Source Ground Control Station
4

Don Gagne's avatar
Don Gagne committed
5
 (c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
6

Don Gagne's avatar
Don Gagne committed
7
 This file is part of the QGROUNDCONTROL project
8

Don Gagne's avatar
Don Gagne committed
9 10 11 12
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
13

Don Gagne's avatar
Don Gagne committed
14 15 16 17
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
18

Don Gagne's avatar
Don Gagne committed
19 20
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
21

Don Gagne's avatar
Don Gagne committed
22 23 24
 ======================================================================*/

/// @file
25
///     @author Gus Grubba <mavlink@grubba.com>
Don Gagne's avatar
Don Gagne committed
26

27 28
#ifndef SCREENTOOLS_H
#define SCREENTOOLS_H
Don Gagne's avatar
Don Gagne committed
29 30 31 32

#include <QObject>
#include <QCursor>

33 34 35 36 37 38 39 40
/*!
    @brief Screen helper tools for QML widgets
    To use its functions, you need to import the module with the following line:
    @code
    import QGroundControl.ScreenTools 1.0
    @endcode
*/

41 42
/// This Qml control is used to return screen parameters
class ScreenTools : public QObject
Don Gagne's avatar
Don Gagne committed
43 44 45
{
    Q_OBJECT
public:
46 47
    ScreenTools();

48 49 50 51
    Q_PROPERTY(bool     isAndroid           READ isAndroid  CONSTANT)
    Q_PROPERTY(bool     isiOS               READ isiOS      CONSTANT)
    Q_PROPERTY(bool     isMobile            READ isMobile   CONSTANT)

52
    //! Returns the global mouse X position
53
    Q_PROPERTY(int      mouseX              READ mouseX)
54
    //! Returns the global mouse Y position
55
    Q_PROPERTY(int      mouseY              READ mouseY)
56 57 58 59 60
    //! Used to trigger a \c Canvas element repaint.
    /*!
      There is a bug as of Qt 5.4 where a Canvas element defined within a QQuickWidget does not receive
      repaint events. QGC's main window will emit these signals when a \c Canvas element needs to be
      repainted.
dogmaphobic's avatar
dogmaphobic committed
61
      If you use a \c Canvas element inside some QML widget, you can use this code to handle repaint:
62 63 64 65 66 67 68 69
      @code
      import QGroundControl.ScreenTools 1.0
      ...
        Canvas {
            id: myCanvas
            height: 40
            width:  40
            Connections {
70
                target: ScreenTools
71 72 73 74 75 76 77 78 79 80 81
                onRepaintRequestedChanged: {
                    myCanvas.requestPaint();
                }
            }
            onPaint: {
                var context = getContext("2d");
                ...
            }
        }
      @endcode
     */
82

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    //! Font sizes
    Q_PROPERTY(int   font22   READ font22 CONSTANT)
    Q_PROPERTY(int   font21   READ font21 CONSTANT)
    Q_PROPERTY(int   font20   READ font20 CONSTANT)
    Q_PROPERTY(int   font19   READ font19 CONSTANT)
    Q_PROPERTY(int   font18   READ font18 CONSTANT)
    Q_PROPERTY(int   font17   READ font17 CONSTANT)
    Q_PROPERTY(int   font16   READ font16 CONSTANT)
    Q_PROPERTY(int   font15   READ font15 CONSTANT)
    Q_PROPERTY(int   font14   READ font14 CONSTANT)
    Q_PROPERTY(int   font13   READ font13 CONSTANT)
    Q_PROPERTY(int   font12   READ font12 CONSTANT)
    Q_PROPERTY(int   font11   READ font11 CONSTANT)
    Q_PROPERTY(int   font10   READ font10 CONSTANT)
    Q_PROPERTY(int   font9    READ font9  CONSTANT)
    Q_PROPERTY(int   font8    READ font8  CONSTANT)

100
    //! Returns the system wide default font point size (properly scaled)
101
    Q_PROPERTY(int   defaultFontPizelSize   READ defaultFontPizelSize   CONSTANT)
102
    //! Returns the system wide default font point size (properly scaled)
103
    Q_PROPERTY(int   mediumFontPixelSize    READ mediumFontPixelSize    CONSTANT)
104
    //! Returns the system wide default font point size (properly scaled)
105
    Q_PROPERTY(int   largeFontPixelSize     READ largeFontPixelSize     CONSTANT)
106

107 108 109 110
    Q_PROPERTY(bool     repaintRequested    READ repaintRequested       NOTIFY repaintRequestedChanged)
    //! Returns the pixel size factor
    Q_PROPERTY(double   pixelSizeFactor     READ pixelSizeFactor        CONSTANT)
    
111 112 113 114 115
    //! Utility for adjusting pixel size. Not dynamic (no signals)
    Q_INVOKABLE qreal   adjustPixelSize(qreal pixelSize);

    /// Static version of adjustPixelSize of use in C++ code
    static qreal adjustPixelSize_s(qreal pixelSize);
116

117 118 119
    int     mouseX              () { return QCursor::pos().x(); }
    int     mouseY              () { return QCursor::pos().y(); }
    bool    repaintRequested    () { return true; }
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    double  pixelSizeFactor     () { return _pixelFactor; }

    int   font22    () { return _font22; }
    int   font21    () { return _font21; }
    int   font20    () { return _font20; }
    int   font19    () { return _font19; }
    int   font18    () { return _font18; }
    int   font17    () { return _font17; }
    int   font16    () { return _font16; }
    int   font15    () { return _font15; }
    int   font14    () { return _font14; }
    int   font13    () { return _font13; }
    int   font12    () { return _font12; }
    int   font11    () { return _font11; }
    int   font10    () { return _font10; }
    int   font9     () { return _font9; }
    int   font8     () { return _font8; }

    int  defaultFontPizelSize    () { return _font12; }
    int  mediumFontPixelSize     () { return _font16; }
    int  largeFontPixelSize      () { return _font20; }

    /// Static version for use in C++ code
    static int   font22_s    () { return _font22; }
    static int   font21_s    () { return _font21; }
    static int   font20_s    () { return _font20; }
    static int   font19_s    () { return _font19; }
    static int   font18_s    () { return _font18; }
    static int   font17_s    () { return _font17; }
    static int   font16_s    () { return _font16; }
    static int   font15_s    () { return _font15; }
    static int   font14_s    () { return _font14; }
    static int   font13_s    () { return _font13; }
    static int   font12_s    () { return _font12; }
    static int   font11_s    () { return _font11; }
    static int   font10_s    () { return _font10; }
    static int   font9_s     () { return _font9; }
    static int   font8_s     () { return _font8; }

    static int  defaultFontPizelSize_s      () { return _font12; }
    static int  mediumFontPixelSize_s       () { return _font16; }
    static int  largeFontPixelSize_s        () { return _font20; }

    static double  pixelSizeFactor_s        () { return _pixelFactor; }
164

165 166 167 168
#if defined (__android__)
    bool    isAndroid           () { return true;  }
    bool    isiOS               () { return false; }
    bool    isMobile            () { return true;  }
dogmaphobic's avatar
dogmaphobic committed
169 170 171 172
#elif defined(__ios__)
    bool    isAndroid           () { return false; }
    bool    isiOS               () { return true; }
    bool    isMobile            () { return true; }
173 174 175 176 177 178
#else
    bool    isAndroid           () { return false; }
    bool    isiOS               () { return false; }
    bool    isMobile            () { return false; }
#endif

179 180 181 182 183
signals:
    void repaintRequestedChanged();

private slots:
    void _updateCanvas();
184 185

private:
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    // Font Sizes
    static int _font8;
    static int _font9;
    static int _font10;
    static int _font11;
    static int _font12;
    static int _font13;
    static int _font14;
    static int _font15;
    static int _font16;
    static int _font17;
    static int _font18;
    static int _font19;
    static int _font20;
    static int _font21;
    static int _font22;
    // UI Dimension Factors
    static double _pixelFactor;
Don Gagne's avatar
Don Gagne committed
204 205 206
};

#endif