Kate
expandingtree.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries and the Kate part. 00002 * 00003 * Copyright (C) 2007 David Nolden <david.nolden.kdevelop@art-master.de> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "expandingtree.h" 00022 00023 #include <QTextLayout> 00024 #include <QTextDocument> 00025 #include <QAbstractTextDocumentLayout> 00026 #include <QPainter> 00027 #include <kdebug.h> 00028 #include "expandingwidgetmodel.h" 00029 00030 ExpandingTree::ExpandingTree(QWidget* parent) : QTreeView(parent) { 00031 m_drawText.documentLayout()->setPaintDevice(this); 00032 setUniformRowHeights(false); 00033 } 00034 00035 void ExpandingTree::drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { 00036 QTreeView::drawRow( painter, option, index ); 00037 00038 const ExpandingWidgetModel* eModel = qobject_cast<const ExpandingWidgetModel*>(model()); 00039 if( eModel && eModel->isPartiallyExpanded( index ) ) 00040 { 00041 QRect rect = eModel->partialExpandRect( index ); 00042 if( rect.isValid() ) 00043 { 00044 painter->fillRect(rect,QBrush(0xffffffff)); 00045 00046 QAbstractTextDocumentLayout::PaintContext ctx; 00047 // since arbitrary HTML can be shown use a black on white color scheme here 00048 ctx.palette = QPalette( Qt::black, Qt::white ); 00049 ctx.clip = QRectF(0,0,rect.width(),rect.height());; 00050 painter->setViewTransformEnabled(true); 00051 painter->translate(rect.left(), rect.top()); 00052 00053 m_drawText.setHtml( eModel->partialExpandText( index ) ); 00054 m_drawText.setPageSize(QSizeF(rect.width(), rect.height())); 00055 m_drawText.documentLayout()->draw( painter, ctx ); 00056 00057 painter->translate(-rect.left(), -rect.top()); 00058 } 00059 } 00060 } 00061 00062 int ExpandingTree::sizeHintForColumn ( int column ) const { 00063 return columnWidth( column ); 00064 }
KDE 4.6 API Reference