Kate
expandingtree.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "expandingtree.h"
00020
00021 #include <QTextLayout>
00022 #include <QTextDocument>
00023 #include <QAbstractTextDocumentLayout>
00024 #include <QPainter>
00025 #include <kdebug.h>
00026 #include "expandingwidgetmodel.h"
00027
00028 ExpandingTree::ExpandingTree(QWidget* parent) : QTreeView(parent) {
00029 m_drawText.documentLayout()->setPaintDevice(this);
00030 setUniformRowHeights(false);
00031 }
00032
00033 void ExpandingTree::drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const {
00034 QTreeView::drawRow( painter, option, index );
00035
00036 const ExpandingWidgetModel* eModel = qobject_cast<const ExpandingWidgetModel*>(model());
00037 if( eModel && eModel->isPartiallyExpanded( index ) )
00038 {
00039 QRect rect = eModel->partialExpandRect( index );
00040 if( rect.isValid() )
00041 {
00042 painter->fillRect(rect,QBrush(0xffffffff));
00043
00044 QAbstractTextDocumentLayout::PaintContext ctx;
00045 ctx.clip = QRectF(0,0,rect.width(),rect.height());;
00046 painter->setViewTransformEnabled(true);
00047 painter->translate(rect.left(), rect.top());
00048
00049 m_drawText.setHtml( eModel->partialExpandText( index ) );
00050 m_drawText.setPageSize(QSizeF(rect.width(), rect.height()));
00051 m_drawText.documentLayout()->draw( painter, ctx );
00052
00053 painter->translate(-rect.left(), -rect.top());
00054 }
00055 }
00056 }
00057
00058 int ExpandingTree::sizeHintForColumn ( int column ) const {
00059 return columnWidth( column );
00060 }