Kate
expandingdelegate.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries and the Kate part. 00002 * 00003 * Copyright (C) 2006 Hamish Rodda <rodda@kde.org> 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 #ifndef ExpandingDelegate_H 00022 #define ExpandingDelegate_H 00023 00024 #include <QtGui/QItemDelegate> 00025 #include <QItemDelegate> 00026 #include <QtGui/QTextLine> 00027 #include <QModelIndex> 00028 #include <QPoint> 00029 00030 class KateRenderer; 00031 class KateCompletionWidget; 00032 class KateDocument; 00033 class KateTextLine; 00034 class ExpandingWidgetModel; 00035 class QVariant; 00036 class QStyleOptionViewItem; 00037 00042 class ExpandingDelegate : public QItemDelegate 00043 { 00044 Q_OBJECT 00045 00046 public: 00047 explicit ExpandingDelegate(ExpandingWidgetModel* model, QObject* parent = 0L); 00048 00049 00050 // Overridden to create highlighting for current index 00051 virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; 00052 00053 // Returns the basic size-hint as reported by QItemDelegate 00054 QSize basicSizeHint( const QModelIndex& index ) const; 00055 00056 ExpandingWidgetModel* model() const; 00057 protected: 00058 //Called right before paint to allow last-minute changes to the style 00059 virtual void adjustStyle( const QModelIndex& index, QStyleOptionViewItem & option ) const; 00060 virtual void drawDisplay ( QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect, const QString & text ) const; 00061 virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const; 00062 virtual bool editorEvent ( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ); 00063 virtual void drawBackground ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; 00064 virtual void drawDecoration(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QPixmap& pixmap) const; 00065 //option can be changed 00066 virtual QList<QTextLayout::FormatRange> createHighlighting(const QModelIndex& index, QStyleOptionViewItem& option) const; 00067 00068 void adjustRect(QRect& rect) const; 00069 00073 QList<QTextLayout::FormatRange> highlightingFromVariantList(const QList<QVariant>& customHighlights) const; 00074 00075 //Called when an item was expanded/unexpanded and the height changed 00076 virtual void heightChanged() const; 00077 00078 //Initializes the style options from the index 00079 void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const; 00080 00081 mutable int m_currentColumnStart; //Text-offset for custom highlighting, will be applied to m_cachedHighlights(Only highlights starting after this will be used). Shoult be zero of the highlighting is not taken from kate. 00082 mutable QList<int> m_currentColumnStarts; 00083 mutable QList<QTextLayout::FormatRange> m_cachedHighlights; 00084 00085 mutable Qt::Alignment m_cachedAlignment; 00086 mutable QColor m_backgroundColor; 00087 mutable QModelIndex m_currentIndex; 00088 private: 00089 00090 ExpandingWidgetModel* m_model; 00091 }; 00092 00093 #endif
KDE 4.6 API Reference