KGuiAddons

kfontutils.h
1/*
2 SPDX-FileCopyrightText: 2005, 2009 Albert Astals Cid <aacid@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#ifndef KFONTUTILS_H
8#define KFONTUTILS_H
9
10#include <kguiaddons_export.h>
11
12#include <qglobal.h>
13
14class QPainter;
15class QSizeF;
16class QString;
17
18/**
19 * @namespace KFontUtils
20 * Provides utility functions for font data.
21 */
22namespace KFontUtils
23{
24/**
25 * Modifiers for the adaptFontSize function
26 * @see AdaptFontSizeOptions
27 */
29 NoFlags = 0x01, ///< No modifier
30 DoNotAllowWordWrap = 0x02, ///< Do not use word wrapping
31};
32/**
33 * Stores a combination of #AdaptFontSizeOption values.
34 */
36Q_DECLARE_OPERATORS_FOR_FLAGS(AdaptFontSizeOptions)
37
38/** Helper function that calculates the biggest font size (in points) used
39 drawing a centered text using word wrapping.
40 @param painter The painter where the text will be painted. The font set
41 in the painter is used for the calculation. Note the
42 painter font size is modified by this call
43 @param text The text you want to draw
44 @param width The available width for drawing
45 @param height The available height for drawing
46 @param maxFontSize The maximum font size (in points) to consider
47 @param minFontSize The minimum font size (in points) to consider
48 @param flags The modifiers for how the text is painted
49 @return The calculated biggest font size (in points) that draws the text
50 in the given dimensions. Can return smaller than minFontSize,
51 that means the text doesn't fit in the given rectangle. Can
52 return -1 on error
53 @since 4.7
54*/
55qreal KGUIADDONS_EXPORT adaptFontSize(QPainter &painter,
56 const QString &text,
57 qreal width,
58 qreal height,
59 qreal maxFontSize = 28.0,
60 qreal minFontSize = 1.0,
62
63/** Convenience function for adaptFontSize that accepts a QSizeF instead two qreals
64 @since 4.7
65*/
66qreal KGUIADDONS_EXPORT adaptFontSize(QPainter &painter,
67 const QString &text,
68 const QSizeF &availableSize,
69 qreal maxFontSize = 28.0,
70 qreal minFontSize = 1.0,
72}
73
74#endif
Provides utility functions for font data.
qreal KGUIADDONS_EXPORT adaptFontSize(QPainter &painter, const QString &text, qreal width, qreal height, qreal maxFontSize=28.0, qreal minFontSize=1.0, AdaptFontSizeOptions flags=NoFlags)
Helper function that calculates the biggest font size (in points) used drawing a centered text using ...
AdaptFontSizeOption
Modifiers for the adaptFontSize function.
Definition kfontutils.h:28
@ NoFlags
No modifier.
Definition kfontutils.h:29
@ DoNotAllowWordWrap
Do not use word wrapping.
Definition kfontutils.h:30
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.