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 | |
14 | class QPainter; |
15 | class QSizeF; |
16 | class QString; |
17 | |
18 | /*! |
19 | * \namespace KFontUtils |
20 | * \inmodule KGuiAddons |
21 | * \brief Provides utility functions for font data. |
22 | */ |
23 | namespace KFontUtils |
24 | { |
25 | /*! |
26 | * Modifiers for the adaptFontSize function |
27 | * |
28 | * \value NoFlags No modifier |
29 | * \value DoNotAllowWordWrap Do not use word wrapping |
30 | * |
31 | */ |
32 | enum AdaptFontSizeOption { |
33 | NoFlags = 0x01, |
34 | DoNotAllowWordWrap = 0x02, |
35 | }; |
36 | |
37 | Q_DECLARE_FLAGS(AdaptFontSizeOptions, AdaptFontSizeOption) |
38 | Q_DECLARE_OPERATORS_FOR_FLAGS(AdaptFontSizeOptions) |
39 | |
40 | /*! Helper function that calculates the biggest font size (in points) used |
41 | drawing a centered text using word wrapping. |
42 | |
43 | \a painter The painter where the text will be painted. The font set |
44 | in the painter is used for the calculation. Note the |
45 | painter font size is modified by this call |
46 | |
47 | \a text The text you want to draw |
48 | |
49 | \a width The available width for drawing |
50 | |
51 | \a height The available height for drawing |
52 | |
53 | \a maxFontSize The maximum font size (in points) to consider |
54 | |
55 | \a minFontSize The minimum font size (in points) to consider |
56 | |
57 | \a flags The modifiers for how the text is painted |
58 | |
59 | Returns the calculated biggest font size (in points) that draws the text |
60 | in the given dimensions. Can return smaller than minFontSize, |
61 | that means the text doesn't fit in the given rectangle. Can |
62 | return -1 on error |
63 | \since 4.7 |
64 | */ |
65 | qreal KGUIADDONS_EXPORT adaptFontSize(QPainter &painter, |
66 | const QString &text, |
67 | qreal width, |
68 | qreal height, |
69 | qreal maxFontSize = 28.0, |
70 | qreal minFontSize = 1.0, |
71 | AdaptFontSizeOptions flags = NoFlags); |
72 | |
73 | /*! Convenience function for adaptFontSize that accepts a QSizeF instead two qreals |
74 | \since 4.7 |
75 | */ |
76 | qreal KGUIADDONS_EXPORT adaptFontSize(QPainter &painter, |
77 | const QString &text, |
78 | const QSizeF &availableSize, |
79 | qreal maxFontSize = 28.0, |
80 | qreal minFontSize = 1.0, |
81 | AdaptFontSizeOptions flags = NoFlags); |
82 | } |
83 | |
84 | #endif |
85 | |