KD Chart API Documentation  3.1
KDTextDocument.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** This file is part of the KD Chart library.
4 **
5 ** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: MIT
8 **
9 ****************************************************************************/
10 
11 #include "KDTextDocument.h"
12 #include <QAbstractTextDocumentLayout>
13 #include <QRect>
14 #include <QTextBlock>
15 #include <QtDebug>
16 
17 #include <KDABLibFakes>
18 
19 // This is an internal class that mimics some of the behavior of a
20 // QLabel with rich text assigned, this is mostly a workaround around
21 // QTextDocumentLayout not being a public class.
22 
24  : QTextDocument(p)
25  , mSizeHint()
26  , mMinimumSizeHint()
27 {
28 }
29 
30 KDTextDocument::KDTextDocument(const QString &text, QObject *p)
31  : QTextDocument(text, p)
32  , mHintValid(false)
33  , mSizeHint()
34  , mMinimumSizeHint()
35 {
36 }
37 
39 {
40 }
41 
43 {
44  if (!mHintValid)
45  ( void )minimumSizeHint();
46  return mSizeHint;
47 }
48 
50 {
51  /*
52  QTextCursor cursor( this );
53  if ( ! cursor.atEnd() )
54  cursor.movePosition( QTextCursor::NextBlock );
55  qDebug() << "KDTextDocument::minimumSizeHint() found:" << cursor.block().text();
56  QSizeF s( documentLayout()->blockBoundingRect( cursor.block() ).size() );
57  qDebug() << "KDTextDocument::minimumSizeHint() found rect" << documentLayout()->blockBoundingRect( cursor.block());
58  return QSize( static_cast<int>(s.width()),
59  static_cast<int>(s.height()) );
60  */
61 
62  if (mHintValid)
63  return mMinimumSizeHint;
64 
65  mHintValid = true;
66  mSizeHint = sizeForWidth(-1);
67  QSize sz(-1, -1);
68 
69  // PENDING(kalle) Cache
70  sz.rwidth() = sizeForWidth(0).width();
71  sz.rheight() = sizeForWidth(32000).height();
72  if (mSizeHint.height() < sz.height())
73  sz.rheight() = mSizeHint.height();
74 
75  mMinimumSizeHint = sz;
76  return sz;
77 }
78 
79 QSize KDTextDocument::sizeForWidth(int w)
80 {
81  Q_UNUSED(w);
82 
83  setPageSize(QSize(0, 100000));
84 
85  return documentLayout()->documentSize().toSize();
86 }
KDTextDocument(QObject *parent=nullptr)
~KDTextDocument() override
QSize minimumSizeHint()

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated by doxygen 1.9.1