KDTextDocument.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2011 Klaralvdalens Datakonsult AB.  All rights reserved.
00003 **
00004 ** This file is part of the KD Chart library.
00005 **
00006 ** Licensees holding valid commercial KD Chart licenses may use this file in
00007 ** accordance with the KD Chart Commercial License Agreement provided with
00008 ** the Software.
00009 **
00010 **
00011 ** This file may be distributed and/or modified under the terms of the
00012 ** GNU General Public License version 2 and version 3 as published by the
00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** Contact info@kdab.com if any conditions of this licensing are not
00019 ** clear to you.
00020 **
00021 **********************************************************************/
00022 
00023 #include "KDTextDocument.h"
00024 #include <QRect>
00025 #include <QAbstractTextDocumentLayout>
00026 #include <QtDebug>
00027 #include <QTextBlock>
00028 
00029 #include <KDABLibFakes>
00030 
00031 // This is an internal class that mimicks some of the behavior of a
00032 // QLabel with rich text assigned, this is mostly a workaround around
00033 // QTextDocumentLayout not being a public class.
00034 
00035 KDTextDocument::KDTextDocument( QObject * p )
00036     : QTextDocument( p ),
00037       mHintValid( false ),
00038       mSizeHint(),
00039       mMinimumSizeHint()
00040 {
00041 
00042 }
00043 
00044 KDTextDocument::KDTextDocument( const QString & text, QObject * p )
00045     : QTextDocument( text, p ),
00046       mHintValid( false ),
00047       mSizeHint(),
00048       mMinimumSizeHint()
00049 {
00050 
00051 }
00052 
00053 KDTextDocument::~KDTextDocument() {}
00054 
00055 
00056 QSize KDTextDocument::sizeHint()
00057 {
00058     if( !mHintValid )
00059         (void)minimumSizeHint();
00060     return mSizeHint;
00061 }
00062 
00063 QSize KDTextDocument::minimumSizeHint()
00064 {
00065     /*
00066     QTextCursor cursor( this );
00067     if( ! cursor.atEnd() )
00068         cursor.movePosition( QTextCursor::NextBlock );
00069     qDebug() << "KDTextDocument::minimumSizeHint() found:" << cursor.block().text();
00070     QSizeF s( documentLayout()->blockBoundingRect( cursor.block() ).size() );
00071     qDebug() << "KDTextDocument::minimumSizeHint() found rect" << documentLayout()->blockBoundingRect( cursor.block());
00072     return QSize( static_cast<int>(s.width()),
00073                   static_cast<int>(s.height()) );
00074     */
00075 
00076     if( mHintValid )
00077         return mMinimumSizeHint;
00078 
00079     mHintValid = true;
00080     mSizeHint = sizeForWidth( -1 );
00081     QSize sz(-1, -1);
00082 
00083     // PENDING(kalle) Cache
00084     sz.rwidth() = sizeForWidth( 0 ).width();
00085     sz.rheight() = sizeForWidth( 32000 ).height();
00086     if( mSizeHint.height() < sz.height())
00087         sz.rheight() = mSizeHint.height();
00088 
00089     mMinimumSizeHint = sz;
00090     return sz;
00091 }
00092 
00093 
00094 QSize KDTextDocument::sizeForWidth(int w)
00095 {
00096     Q_UNUSED( w );
00097 
00098     setPageSize(QSize(0, 100000));
00099 
00100     return documentLayout()->documentSize().toSize();
00101 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/