ScreenTools.cc 3.36 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 31 32
#include <QFont>
#include <QFontMetrics>

33
const double ScreenTools::_defaultFontPointSize = 13;
34 35
const double ScreenTools::_mediumFontPointSize = 16;
const double ScreenTools::_largeFontPointSize = 20;
36

37
ScreenTools::ScreenTools()
Don Gagne's avatar
Don Gagne committed
38
{
39 40 41 42 43 44 45 46
    MainWindow* mainWindow = MainWindow::instance();
    
    // Unit tests can run Qml without MainWindow
    if (mainWindow) {
        connect(mainWindow, &MainWindow::repaintCanvas,     this, &ScreenTools::_updateCanvas);
        connect(mainWindow, &MainWindow::pixelSizeChanged,  this, &ScreenTools::_updatePixelSize);
        connect(mainWindow, &MainWindow::fontSizeChanged,   this, &ScreenTools::_updateFontSize);
    }
Don Gagne's avatar
Don Gagne committed
47
}
48

49
qreal ScreenTools::adjustFontPointSize(qreal pointSize)
50
{
51
    return adjustFontPointSize_s(pointSize);
52 53
}

54
qreal ScreenTools::adjustFontPointSize_s(qreal pointSize)
55
{
56
    return pointSize * MainWindow::fontPointFactor();
57 58
}

59
qreal ScreenTools::adjustPixelSize(qreal pixelSize)
60
{
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    return adjustPixelSize_s(pixelSize);
}

qreal ScreenTools::adjustPixelSize_s(qreal pixelSize)
{
    return pixelSize * MainWindow::pixelSizeFactor();
}

void ScreenTools::increasePixelSize()
{
    MainWindow::instance()->setPixelSizeFactor(MainWindow::pixelSizeFactor() + 0.025);
}

void ScreenTools::decreasePixelSize()
{
    MainWindow::instance()->setPixelSizeFactor(MainWindow::pixelSizeFactor() - 0.025);
}

void ScreenTools::increaseFontSize()
{
    MainWindow::instance()->setFontSizeFactor(MainWindow::fontPointFactor() + 0.025);
}

void ScreenTools::decreaseFontSize()
{
    MainWindow::instance()->setFontSizeFactor(MainWindow::fontPointFactor() - 0.025);
87 88
}

89 90 91 92
void ScreenTools::_updateCanvas()
{
    emit repaintRequestedChanged();
}
93 94 95 96 97 98 99 100 101

void ScreenTools::_updatePixelSize()
{
    emit pixelSizeFactorChanged();
}

void ScreenTools::_updateFontSize()
{
    emit fontPointFactorChanged();
102
    emit fontSizesChanged();
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
}

double ScreenTools::fontPointFactor()
{
    return MainWindow::fontPointFactor();
}

double ScreenTools::pixelSizeFactor()
{
    return MainWindow::pixelSizeFactor();
}

double ScreenTools::defaultFontPointSize(void)
{
    return _defaultFontPointSize * MainWindow::fontPointFactor();
}
119 120 121 122 123 124 125 126 127 128

double ScreenTools::mediumFontPointSize(void)
{
    return _mediumFontPointSize * MainWindow::fontPointFactor();
}

double ScreenTools::largeFontPointSize(void)
{
    return _largeFontPointSize * MainWindow::fontPointFactor();
}