1/*********************************************************************************
2 * *
3 * Copyright (C) 2005, 2009 by Albert Astals Cid <aacid@kde.org> *
4 * *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Lesser General Public *
7 * License as published by the Free Software Foundation; either *
8 * version 2.1 of the License, or (at your option) version 3, or any *
9 * later version accepted by the membership of KDE e.V. (or its *
10 * successor approved by the membership of KDE e.V.), which shall *
11 * act as a proxy defined in Section 6 of version 3 of the license. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>. *
20 * *
21 *********************************************************************************/
22
23#ifndef KFONTMETRICS_H
24#define KFONTMETRICS_H
25
26#include "kdeui_export.h"
27
28class QPainter;
29class QSizeF;
30class QString;
31
32namespace KFontUtils
33{
34 /** Modifiers for the adaptFontSize function */
35 enum AdaptFontSizeOption {
36 NoFlags = 0x01 /** No modifier */,
37 DoNotAllowWordWrap = 0x02 /** Do not use word wrapping */
38 };
39 Q_DECLARE_FLAGS(AdaptFontSizeOptions, AdaptFontSizeOption)
40
41 /** Helper function that calculates the biggest font size (in points) used
42 drawing a centered text using word wrapping.
43 @param 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 @param text The text you want to draw
47 @param width The available width for drawing
48 @param height The available height for drawing
49 @param maxFontSize The maximum font size (in points) to consider
50 @param minFontSize The minimum font size (in points) to consider
51 @param flags The modifiers for how the text is painted
52 @return The calculated biggest font size (in points) that draws the text
53 in the given dimensions. Can return smaller than minFontSize,
54 that means the text doesn't fit in the given rectangle. Can
55 return -1 on error
56 @since KDE 4.7
57 */
58 qreal KDEUI_EXPORT adaptFontSize(QPainter &painter,
59 const QString &text,
60 qreal width,
61 qreal height,
62 qreal maxFontSize = 28.0,
63 qreal minFontSize = 1.0,
64 AdaptFontSizeOptions flags = NoFlags);
65
66 /** Convenience function for adaptFontSize that accepts a QSizeF instead two qreals
67 @since KDE 4.7
68 */
69 qreal KDEUI_EXPORT adaptFontSize(QPainter &painter,
70 const QString &text,
71 const QSizeF &availableSize,
72 qreal maxFontSize = 28.0,
73 qreal minFontSize = 1.0,
74 AdaptFontSizeOptions flags = NoFlags);
75}
76
77Q_DECLARE_OPERATORS_FOR_FLAGS(KFontUtils::AdaptFontSizeOptions)
78
79#endif
80
81