• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • completion
  • expandingtree
expandingtree.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2007 David Nolden <david.nolden.kdevelop@art-master.de>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "expandingtree.h"
22 
23 #include <QTextLayout>
24 #include <QTextDocument>
25 #include <QAbstractTextDocumentLayout>
26 #include <QPainter>
27 #include <kdebug.h>
28 #include "expandingwidgetmodel.h"
29 
30 ExpandingTree::ExpandingTree(QWidget* parent) : QTreeView(parent) {
31  m_drawText.documentLayout()->setPaintDevice(this);
32  setUniformRowHeights(false);
33 }
34 
35 void ExpandingTree::drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const {
36  QTreeView::drawRow( painter, option, index );
37 
38  const ExpandingWidgetModel* eModel = qobject_cast<const ExpandingWidgetModel*>(model());
39  if( eModel && eModel->isPartiallyExpanded( index ) )
40  {
41  QRect rect = eModel->partialExpandRect( index );
42  if( rect.isValid() )
43  {
44  painter->fillRect(rect,QBrush(0xffffffff));
45 
46  QAbstractTextDocumentLayout::PaintContext ctx;
47  // since arbitrary HTML can be shown use a black on white color scheme here
48  ctx.palette = QPalette( Qt::black, Qt::white );
49  ctx.clip = QRectF(0,0,rect.width(),rect.height());;
50  painter->setViewTransformEnabled(true);
51  painter->translate(rect.left(), rect.top());
52 
53  m_drawText.setHtml( eModel->partialExpandText( index ) );
54  m_drawText.setPageSize(QSizeF(rect.width(), rect.height()));
55  m_drawText.documentLayout()->draw( painter, ctx );
56 
57  painter->translate(-rect.left(), -rect.top());
58  }
59  }
60 }
61 
62 int ExpandingTree::sizeHintForColumn ( int column ) const {
63  return columnWidth( column );
64 }
QModelIndex
QWidget
QTextDocument::setPageSize
void setPageSize(const QSizeF &size)
QPainter::fillRect
void fillRect(const QRectF &rectangle, const QBrush &brush)
ExpandingWidgetModel::partialExpandText
QString partialExpandText(const QModelIndex &row) const
Definition: expandingwidgetmodel.cpp:244
ExpandingWidgetModel::isPartiallyExpanded
ExpansionType isPartiallyExpanded(const QModelIndex &index) const
Returns whether the given index is currently partially expanded. Does not do any other checks like ca...
Definition: expandingwidgetmodel.cpp:139
ExpandingTree::drawRow
virtual void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: expandingtree.cpp:35
QTreeView::setUniformRowHeights
void setUniformRowHeights(bool uniform)
QRect::height
int height() const
QBrush
expandingwidgetmodel.h
QRect
QTreeView::columnWidth
int columnWidth(int column) const
QRect::top
int top() const
expandingtree.h
QStyleOptionViewItem
QRect::left
int left() const
QPainter
ExpandingTree::ExpandingTree
ExpandingTree(QWidget *parent)
Definition: expandingtree.cpp:30
QTextDocument::documentLayout
QAbstractTextDocumentLayout * documentLayout() const
QAbstractTextDocumentLayout::PaintContext
QWidget::rect
QRect rect() const
ExpandingTree::sizeHintForColumn
virtual int sizeHintForColumn(int column) const
Definition: expandingtree.cpp:62
QRect::isValid
bool isValid() const
QRect::width
int width() const
QSizeF
QTreeView
QRectF
QPainter::translate
void translate(const QPointF &offset)
QTextDocument::setHtml
void setHtml(const QString &html)
QAbstractTextDocumentLayout::draw
virtual void draw(QPainter *painter, const PaintContext &context)=0
QAbstractTextDocumentLayout::setPaintDevice
void setPaintDevice(QPaintDevice *device)
QPainter::setViewTransformEnabled
void setViewTransformEnabled(bool enable)
QAbstractItemView::model
QAbstractItemModel * model() const
QPalette
QTreeView::drawRow
virtual void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
ExpandingWidgetModel
Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate.
Definition: expandingwidgetmodel.h:36
ExpandingWidgetModel::partialExpandRect
QRect partialExpandRect(const QModelIndex &row) const
Returns the rectangle for the partially expanded part of the given row.
Definition: expandingwidgetmodel.cpp:251
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal