Marble

FpsLayer.cpp
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2006-2009 Torsten Rahn <[email protected]>
4 // SPDX-FileCopyrightText: 2011, 2012 Bernhard Beschow <[email protected]>
5 //
6 
7 
8 #include "FpsLayer.h"
9 
10 #include <QPoint>
11 #include <QElapsedTimer>
12 #include <QFont>
13 #include <QPainter>
14 
15 namespace Marble
16 {
17 
18 FpsLayer::FpsLayer( QElapsedTimer *time )
19  : m_time( time )
20 {
21 }
22 
23 void FpsLayer::paint( QPainter *painter ) const
24 {
25  const qreal fps = 1000.0 / (qreal)( m_time->elapsed() );
26  const QString fpsString = QString("Speed: %1 fps").arg(fps, 5, 'f', 1, QLatin1Char(' '));
27 
28  const QPoint fpsLabelPos( 10, 20 );
29 
30  painter->setFont( QFont( QStringLiteral( "Sans Serif" ), 10 ) );
31 
32  painter->setPen( Qt::black );
33  painter->setBrush( Qt::black );
34  painter->drawText( fpsLabelPos, fpsString );
35 
36  painter->setPen( Qt::white );
37  painter->setBrush( Qt::white );
38  painter->drawText( fpsLabelPos.x() - 1, fpsLabelPos.y() - 1, fpsString );
39 }
40 
41 }
void setPen(const QColor &color)
void drawText(const QPointF &position, const QString &text)
Binds a QML item to a specific geodetic location in screen coordinates.
void setBrush(const QBrush &brush)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
void setFont(const QFont &font)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Oct 2 2023 03:52:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.