Marble

FpsLayer.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2006-2009 Torsten Rahn <tackat@kde.org>
4// SPDX-FileCopyrightText: 2011, 2012 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
5//
6
7#include "FpsLayer.h"
8
9#include <QElapsedTimer>
10#include <QFont>
11#include <QPainter>
12#include <QPoint>
13
14namespace Marble
15{
16
17FpsLayer::FpsLayer(QElapsedTimer *time)
18 : m_time(time)
19{
20}
21
22void FpsLayer::paint(QPainter *painter) const
23{
24 const qreal fps = 1000.0 / (qreal)(m_time->elapsed());
25 const QString fpsString = QStringLiteral("Speed: %1 fps").arg(fps, 5, 'f', 1, QLatin1Char(' '));
26
27 const QPoint fpsLabelPos(10, 20);
28
29 painter->setFont(QFont(QStringLiteral("Sans Serif"), 10));
30
31 painter->setPen(Qt::black);
32 painter->setBrush(Qt::black);
33 painter->drawText(fpsLabelPos, fpsString);
34
35 painter->setPen(Qt::white);
36 painter->setBrush(Qt::white);
37 painter->drawText(fpsLabelPos.x() - 1, fpsLabelPos.y() - 1, fpsString);
38}
39
40}
Binds a QML item to a specific geodetic location in screen coordinates.
void drawText(const QPoint &position, const QString &text)
void setBrush(Qt::BrushStyle style)
void setFont(const QFont &font)
void setPen(Qt::PenStyle style)
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.