1
/*********************************************************************************
3
* Copyright (C) 2005, 2009 by Albert Astals Cid <aacid@kde.org> *
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. *
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. *
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/>. *
21
*********************************************************************************/
23
#ifndef KFONTMETRICS_H
24
#define KFONTMETRICS_H
26
#include <QGraphicsTextItem>
28
#include "kdeui_export.h"
36
/** Modifiers for the adaptFontSize function */
37
enum AdaptFontSizeOption {
38
NoFlags = 0x01 /** No modifier */,
39
DoNotAllowWordWrap = 0x02 /** Do not use word wrapping */
41
Q_DECLARE_FLAGS(AdaptFontSizeOptions, AdaptFontSizeOption)
43
/** Helper function that calculates the biggest font size (in points) used
44
drawing a centered text using word wrapping.
45
@param text The QGraphicsTextItem you want to draw
46
@param width The available width for drawing
47
@param height The available height for drawing
48
@param maxFontSize The maximum font size (in points) to consider
49
@param minFontSize The minimum font size (in points) to consider
50
@param flags The modifiers for how the text is painted
51
@param precision The maximum unused space (in pixels) in any axys
52
@return The calculated biggest font size (in points) that draws the text
53
in the given dimensions. Cannot return smaller than minFontSize neither
54
bigger than maxFontSize. Can return -1 on error.
57
qreal KDEUI_EXPORT adaptFontSize(QGraphicsTextItem* text,
60
qreal maxFontSize = 28.0,
61
qreal minFontSize = 1.0,
62
qreal precision = 1.0);
64
/** Convenience function for adaptFontSize that accepts a QSizeF instead two qreals
67
qreal KDEUI_EXPORT adaptFontSize(QGraphicsTextItem* text,
68
const QSizeF &availableSize,
69
qreal maxFontSize = 28.0,
70
qreal minFontSize = 1.0,
71
qreal precision = 1.0);
74
Q_DECLARE_OPERATORS_FOR_FLAGS(KFontUtils::AdaptFontSizeOptions)