~kubuntu-members/kfourinline/4.11

« back to all changes in this revision

Viewing changes to src/kfontutils.h

  • Committer: Albert Astals Cid
  • Author(s): Eneko Nieto
  • Date: 2013-07-29 21:10:55 UTC
  • Revision ID: git-v1:c14a37d405b7b61afc2ad739ff0a98f64a80f878
Make translations text fit in Quick Launch

BUGS: 169600
FIXED-IN: 4.11.0
REVIEW: 111775

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <QGraphicsTextItem>
 
27
 
 
28
#include "kdeui_export.h"
 
29
 
 
30
class QPainter;
 
31
class QSizeF;
 
32
class QString;
 
33
 
 
34
namespace KFontUtils
 
35
{
 
36
    /** Modifiers for the adaptFontSize function */
 
37
    enum AdaptFontSizeOption {
 
38
        NoFlags = 0x01 /** No modifier */,
 
39
        DoNotAllowWordWrap = 0x02  /** Do not use word wrapping */
 
40
    };
 
41
    Q_DECLARE_FLAGS(AdaptFontSizeOptions, AdaptFontSizeOption)
 
42
 
 
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.
 
55
        @since KDE 4.7
 
56
    */
 
57
    qreal KDEUI_EXPORT adaptFontSize(QGraphicsTextItem* text,
 
58
                                     qreal width,
 
59
                                     qreal height,
 
60
                                     qreal maxFontSize = 28.0,
 
61
                                     qreal minFontSize = 1.0,
 
62
                                     qreal precision = 1.0);
 
63
 
 
64
    /** Convenience function for adaptFontSize that accepts a QSizeF instead two qreals
 
65
        @since KDE 4.7
 
66
    */
 
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);
 
72
}
 
73
 
 
74
Q_DECLARE_OPERATORS_FOR_FLAGS(KFontUtils::AdaptFontSizeOptions)
 
75
 
 
76
#endif
 
77