1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
/* This file is part of the KDE libraries and the Kate part.
*
* Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
* Copyright (C) 2007 David Nolden <david.nolden.kdevelop@art-master.de>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KDEVPLATFORM_PLUGIN_EXPANDINGDELEGATE_H
#define KDEVPLATFORM_PLUGIN_EXPANDINGDELEGATE_H
#include <QItemDelegate>
#include <QTextLayout>
#include <QModelIndex>
class KateRenderer;
class KateCompletionWidget;
class KateDocument;
class KateTextLine;
class ExpandingWidgetModel;
class QVariant;
class QStyleOptionViewItem;
/**
* This is a delegate that cares, together with ExpandingWidgetModel, about embedded widgets in tree-view.
* */
class ExpandingDelegate
: public QItemDelegate
{
Q_OBJECT
public:
explicit ExpandingDelegate(ExpandingWidgetModel* model, QObject* parent = nullptr);
// Overridden to create highlighting for current index
void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
// Returns the basic size-hint as reported by QItemDelegate
QSize basicSizeHint(const QModelIndex& index) const;
ExpandingWidgetModel* model() const;
protected:
//Called right before paint to allow last-minute changes to the style
virtual void adjustStyle(const QModelIndex& index, QStyleOptionViewItem& option) const;
void drawDisplay (QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QString& text) const override;
QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const override;
bool editorEvent (QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
virtual void drawBackground (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
void drawDecoration(QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, const QPixmap& pixmap) const override;
//option can be changed
virtual QVector<QTextLayout::FormatRange> createHighlighting(const QModelIndex& index, QStyleOptionViewItem& option) const;
void adjustRect(QRect& rect) const;
/**
* Creates a list of FormatRanges as should be returned by createHighlighting from a list of QVariants as described in the kde header ktexteditor/codecompletionmodel.h
* */
QVector<QTextLayout::FormatRange> highlightingFromVariantList(const QList<QVariant>& customHighlights) const;
//Called when an item was expanded/unexpanded and the height changed
virtual void heightChanged() const;
//Initializes the style options from the index
void initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const;
mutable int m_currentColumnStart; //Text-offset for custom highlighting, will be applied to m_cachedHighlights(Only highlights starting after this will be used). Should be zero of the highlighting is not taken from kate.
mutable QList<int> m_currentColumnStarts;
mutable QVector<QTextLayout::FormatRange> m_cachedHighlights;
mutable Qt::Alignment m_cachedAlignment;
mutable QColor m_backgroundColor;
mutable QModelIndex m_currentIndex;
private:
ExpandingWidgetModel* m_model;
};
#endif // KDEVPLATFORM_PLUGIN_EXPANDINGDELEGATE_H
|