KGuiAddons 5.109.0
kwordwrap.h
1/* This file is part of the KDE libraries
2 SPDX-FileCopyrightText: 2001 David Faure <faure@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef kwordwrap_h
8#define kwordwrap_h
9
10#include <kguiaddons_export.h>
11
12#include <QSharedDataPointer>
13#include <qnamespace.h>
14
15class QFontMetrics;
16class QRect;
17class QString;
18class QPainter;
19class KWordWrapPrivate;
20
42class KGUIADDONS_EXPORT KWordWrap
43{
44public:
49 enum {
50 FadeOut = 0x10000000,
51 Truncate = 0x20000000,
52 };
53
65 static KWordWrap formatText(QFontMetrics &fm, const QRect &r, int flags, const QString &str, int len = -1);
66
73 QRect boundingRect() const;
74
79 QString wrappedString() const; // gift for Dirk :)
80
86 QString truncatedString(bool dots = true) const;
87
100 void drawText(QPainter *painter, int x, int y, int flags = Qt::AlignLeft) const;
101
106
110 KWordWrap(const KWordWrap &other);
115
127 static void drawFadeoutText(QPainter *p, int x, int y, int maxW, const QString &t);
128
138 static void drawTruncateText(QPainter *p, int x, int y, int maxW, const QString &t);
139
140private:
141 KGUIADDONS_NO_EXPORT explicit KWordWrap(const QRect &r);
142
143 QExplicitlySharedDataPointer<KWordWrapPrivate> d;
144};
145
146#endif
Word-wrap algorithm that takes into account beautifulness ;)
Definition kwordwrap.h:43
QRect boundingRect() const
KWordWrap & operator=(const KWordWrap &other)
Assignment operator.
static void drawFadeoutText(QPainter *p, int x, int y, int maxW, const QString &t)
Draws the string t at the given coordinates, if it does not fit into maxW the text will be faded out.
static void drawTruncateText(QPainter *p, int x, int y, int maxW, const QString &t)
Draws the string t at the given coordinates, if it does not fit into maxW the text will be truncated.
KWordWrap(const KWordWrap &other)
Copy constructor.
QString truncatedString(bool dots=true) const
static KWordWrap formatText(QFontMetrics &fm, const QRect &r, int flags, const QString &str, int len=-1)
Main method for wrapping text.
~KWordWrap()
Destructor.
void drawText(QPainter *painter, int x, int y, int flags=Qt::AlignLeft) const
Draw the text that has been previously wrapped, at position x,y.
QString wrappedString() const