KD Chart 2  [rev.2.7]
KDTextDocument.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #include "KDTextDocument.h"
24 #include <QRect>
25 #include <QAbstractTextDocumentLayout>
26 #include <QtDebug>
27 #include <QTextBlock>
28 
29 #include <KDABLibFakes>
30 
31 // This is an internal class that mimicks some of the behavior of a
32 // QLabel with rich text assigned, this is mostly a workaround around
33 // QTextDocumentLayout not being a public class.
34 
36  : QTextDocument( p ),
37  mHintValid( false ),
38  mSizeHint(),
39  mMinimumSizeHint()
40 {
41 
42 }
43 
44 KDTextDocument::KDTextDocument( const QString & text, QObject * p )
45  : QTextDocument( text, p ),
46  mHintValid( false ),
47  mSizeHint(),
48  mMinimumSizeHint()
49 {
50 
51 }
52 
54 
55 
57 {
58  if ( !mHintValid )
59  (void)minimumSizeHint();
60  return mSizeHint;
61 }
62 
64 {
65  /*
66  QTextCursor cursor( this );
67  if ( ! cursor.atEnd() )
68  cursor.movePosition( QTextCursor::NextBlock );
69  qDebug() << "KDTextDocument::minimumSizeHint() found:" << cursor.block().text();
70  QSizeF s( documentLayout()->blockBoundingRect( cursor.block() ).size() );
71  qDebug() << "KDTextDocument::minimumSizeHint() found rect" << documentLayout()->blockBoundingRect( cursor.block());
72  return QSize( static_cast<int>(s.width()),
73  static_cast<int>(s.height()) );
74  */
75 
76  if ( mHintValid )
77  return mMinimumSizeHint;
78 
79  mHintValid = true;
80  mSizeHint = sizeForWidth( -1 );
81  QSize sz(-1, -1);
82 
83  // PENDING(kalle) Cache
84  sz.rwidth() = sizeForWidth( 0 ).width();
85  sz.rheight() = sizeForWidth( 32000 ).height();
86  if ( mSizeHint.height() < sz.height())
87  sz.rheight() = mSizeHint.height();
88 
89  mMinimumSizeHint = sz;
90  return sz;
91 }
92 
93 
94 QSize KDTextDocument::sizeForWidth(int w)
95 {
96  Q_UNUSED( w );
97 
98  setPageSize(QSize(0, 100000));
99 
100  return documentLayout()->documentSize().toSize();
101 }
~KDTextDocument() override
QSize minimumSizeHint()
Class only listed here to document inheritance of some KDChart classes.
Class only listed here to document inheritance of some KDChart classes.
KDTextDocument(QObject *parent=0)

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/