ScreenTools.cc 2.91 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
#include "ScreenTools.h"
#include "MainWindow.h"
Don Gagne's avatar
Don Gagne committed
29

30
// Pixel size, instead of a physical thing is actually a philosophical question when
31
// it comes to Qt.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
// The values below came from actually measuring the elements on the screen on these
// devices. I have yet to find a constant from Qt so these things can be properly
// computed at runtime.

#if defined(Q_OS_OSX)
double ScreenTools::_pixelFactor    = 1.0;
#elif defined(__ios__)
double ScreenTools::_pixelFactor    = 0.75;
#elif defined(Q_OS_WIN)
double ScreenTools::_pixelFactor    = 0.86;
#elif defined(__android__)
double ScreenTools::_pixelFactor    = 2.5;
#elif defined(Q_OS_LINUX)
double ScreenTools::_pixelFactor    = 1.0;
#endif

#if defined(__android__)
#define FONT_FACTOR 2
#else
#define FONT_FACTOR 1
#endif

int ScreenTools::_font8  = 8  * FONT_FACTOR;
int ScreenTools::_font9  = 9  * FONT_FACTOR;
int ScreenTools::_font10 = 10 * FONT_FACTOR;
int ScreenTools::_font11 = 11 * FONT_FACTOR;
int ScreenTools::_font12 = 12 * FONT_FACTOR;
int ScreenTools::_font13 = 13 * FONT_FACTOR;
int ScreenTools::_font14 = 14 * FONT_FACTOR;
int ScreenTools::_font15 = 15 * FONT_FACTOR;
int ScreenTools::_font16 = 16 * FONT_FACTOR;
int ScreenTools::_font17 = 17 * FONT_FACTOR;
int ScreenTools::_font18 = 18 * FONT_FACTOR;
int ScreenTools::_font19 = 19 * FONT_FACTOR;
int ScreenTools::_font20 = 20 * FONT_FACTOR;
int ScreenTools::_font21 = 21 * FONT_FACTOR;
int ScreenTools::_font22 = 22 * FONT_FACTOR;
69

70
ScreenTools::ScreenTools()
Don Gagne's avatar
Don Gagne committed
71
{
72 73 74
    MainWindow* mainWindow = MainWindow::instance();
    // Unit tests can run Qml without MainWindow
    if (mainWindow) {
75
        connect(mainWindow, &MainWindow::repaintCanvas, this, &ScreenTools::_updateCanvas);
76
    }
Don Gagne's avatar
Don Gagne committed
77
}
78

79
qreal ScreenTools::adjustPixelSize(qreal pixelSize)
80
{
81 82 83 84 85
    return adjustPixelSize_s(pixelSize);
}

qreal ScreenTools::adjustPixelSize_s(qreal pixelSize)
{
86
    return pixelSize * _pixelFactor;
87 88
}

89 90 91 92
void ScreenTools::_updateCanvas()
{
    emit repaintRequestedChanged();
}