KChart

KTextDocument.cpp
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#include "KTextDocument.h"
10
11#include "KChartMath_p.h"
12
13#include <QRect>
14#include <QAbstractTextDocumentLayout>
15#include <QtDebug>
16#include <QTextBlock>
17
18// This is an internal class that mimics some of the behavior of a
19// QLabel with rich text assigned, this is mostly a workaround around
20// QTextDocumentLayout not being a public class.
21
22KTextDocument::KTextDocument( QObject * p )
23 : QTextDocument( p ),
24 mHintValid( false ),
25 mSizeHint(),
26 mMinimumSizeHint()
27{
28
29}
30
31KTextDocument::KTextDocument( const QString & text, QObject * p )
32 : QTextDocument( text, p ),
33 mHintValid( false ),
34 mSizeHint(),
35 mMinimumSizeHint()
36{
37
38}
39
40KTextDocument::~KTextDocument() {}
41
42
43QSize KTextDocument::sizeHint()
44{
45 if ( !mHintValid )
46 (void)minimumSizeHint();
47 return mSizeHint;
48}
49
50QSize KTextDocument::minimumSizeHint()
51{
52 /*
53 QTextCursor cursor( this );
54 if ( ! cursor.atEnd() )
55 cursor.movePosition( QTextCursor::NextBlock );
56 qDebug() << "KTextDocument::minimumSizeHint() found:" << cursor.block().text();
57 QSizeF s( documentLayout()->blockBoundingRect( cursor.block() ).size() );
58 qDebug() << "KTextDocument::minimumSizeHint() found rect" << documentLayout()->blockBoundingRect( cursor.block());
59 return QSize( static_cast<int>(s.width()),
60 static_cast<int>(s.height()) );
61 */
62
63 if ( mHintValid )
64 return mMinimumSizeHint;
65
66 mHintValid = true;
67 mSizeHint = sizeForWidth( -1 );
68 QSize sz(-1, -1);
69
70 // PENDING(kalle) Cache
71 sz.rwidth() = sizeForWidth( 0 ).width();
72 sz.rheight() = sizeForWidth( 32000 ).height();
73 if ( mSizeHint.height() < sz.height())
74 sz.rheight() = mSizeHint.height();
75
76 mMinimumSizeHint = sz;
77 return sz;
78}
79
80
81QSize KTextDocument::sizeForWidth(int w)
82{
83 Q_UNUSED( w );
84
85 setPageSize(QSize(0, 100000));
86
88}
virtual QSizeF documentSize() const const=0
int height() const const
int width() const const
QSize toSize() const const
QAbstractTextDocumentLayout * documentLayout() const const
void setPageSize(const QSizeF &size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.