KTextEditor

expandingdelegate.h
1 /*
2  SPDX-FileCopyrightText: 2006 Hamish Rodda <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef ExpandingDelegate_H
8 #define ExpandingDelegate_H
9 
10 #include <QItemDelegate>
11 #include <QModelIndex>
12 #include <QTextLayout>
13 
15 class QVariant;
17 
23 {
24  Q_OBJECT
25 
26 public:
27  explicit ExpandingDelegate(ExpandingWidgetModel *model, QObject *parent = nullptr);
28 
29  // Overridden to create highlighting for current index
30  void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
31 
32  // Returns the basic size-hint as reported by QItemDelegate
33  QSize basicSizeHint(const QModelIndex &index) const;
34 
35  ExpandingWidgetModel *model() const;
36 
37 protected:
38  // Called right before paint to allow last-minute changes to the style
39  virtual void adjustStyle(const QModelIndex &index, QStyleOptionViewItem &option) const;
40  void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const override;
41  QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
42  bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override;
43  virtual void drawBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
44  void drawDecoration(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QPixmap &pixmap) const override;
45  // option can be changed
46  virtual QVector<QTextLayout::FormatRange> createHighlighting(const QModelIndex &index, QStyleOptionViewItem &option) const;
47 
48  void adjustRect(QRect &rect) const;
49 
54 
55  // Called when an item was expanded/unexpanded and the height changed
56  virtual void heightChanged() const;
57 
58  // Initializes the style options from the index
59  void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const;
60 
61  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.
62  mutable QList<int> m_currentColumnStarts;
63  mutable QVector<QTextLayout::FormatRange> m_cachedHighlights;
64 
65  mutable Qt::Alignment m_cachedAlignment;
66  mutable QColor m_backgroundColor;
67  mutable QModelIndex m_currentIndex;
68 
69 private:
70  ExpandingWidgetModel *m_model;
71 };
72 
73 #endif
void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const override
typedef Alignment
virtual bool event(QEvent *e)
QVector< QTextLayout::FormatRange > highlightingFromVariantList(const QList< QVariant > &customHighlights) const
Creates a list of FormatRanges as should be returned by createHighlighting from a list of QVariants a...
Q_OBJECTQ_OBJECT
This is a delegate that cares, together with ExpandingWidgetModel, about embedded widgets in tree-vie...
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
QObject * parent() const const
Cares about expanding/un-expanding items in a tree-view together with ExpandingDelegate.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 14 2020 22:57:22 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.