File indexing completed on 2024-05-19 04:40:07
0001 /* 0002 SPDX-FileCopyrightText: 2017-2018 Friedrich W. H. Kossebau <kossebau@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KDEVPLATFORM_VCSANNOTATIONITEMDELEGATE_H 0008 #define KDEVPLATFORM_VCSANNOTATIONITEMDELEGATE_H 0009 0010 // KDev 0011 #include <vcsrevision.h> 0012 // KF 0013 #include <KTextEditor/AbstractAnnotationItemDelegate> 0014 // Qt 0015 #include <QHash> 0016 #include <QBrush> 0017 0018 namespace KDevelop 0019 { 0020 class VcsAnnotationLine; 0021 0022 class VcsAnnotationItemDelegate : public KTextEditor::AbstractAnnotationItemDelegate 0023 { 0024 Q_OBJECT 0025 0026 public: 0027 VcsAnnotationItemDelegate(KTextEditor::View* view, KTextEditor::AnnotationModel* model, QObject* parent); 0028 ~VcsAnnotationItemDelegate() override; 0029 0030 public: // AbstractAnnotationItemDelegate APO 0031 void paint(QPainter* painter, const KTextEditor::StyleOptionAnnotationItem& option, 0032 KTextEditor::AnnotationModel* model, int line) const override; 0033 QSize sizeHint(const KTextEditor::StyleOptionAnnotationItem& option, 0034 KTextEditor::AnnotationModel* model, int line) const override; 0035 bool helpEvent(QHelpEvent* event, KTextEditor::View* view, 0036 const KTextEditor::StyleOptionAnnotationItem& option, 0037 KTextEditor::AnnotationModel *model, int line) override; 0038 void hideTooltip(KTextEditor::View *view) override; 0039 0040 private: 0041 void renderBackground(QPainter* painter, 0042 const KTextEditor::StyleOptionAnnotationItem& option, 0043 const VcsAnnotationLine& annotationLine) const; 0044 void renderMessageAndAge(QPainter* painter, 0045 const KTextEditor::StyleOptionAnnotationItem& option, 0046 const QRect& messageRect, const QString& messageText, 0047 const QRect& ageRect, const QString& ageText) const; 0048 void renderAuthor(QPainter* painter, 0049 const KTextEditor::StyleOptionAnnotationItem& option, 0050 const QRect& authorRect, const QString& authorText) const; 0051 void renderHighlight(QPainter* painter, 0052 const KTextEditor::StyleOptionAnnotationItem& option) const; 0053 void doMessageLineLayout(const KTextEditor::StyleOptionAnnotationItem& option, 0054 QRect* messageRect, QRect* ageRect) const; 0055 void doAuthorLineLayout(const KTextEditor::StyleOptionAnnotationItem& option, 0056 QRect* authorRect) const; 0057 0058 protected: // QObject API 0059 bool eventFilter(QObject* object, QEvent* event) override; 0060 0061 private Q_SLOTS: 0062 void resetBackgrounds(); 0063 0064 private: 0065 int widthHintFromViewWidth(int viewWidth) const; 0066 0067 private: 0068 KTextEditor::AnnotationModel* const m_model; 0069 0070 // TODO: make this configurable 0071 const int m_maxWidthViewPercent = 25; 0072 0073 mutable QHash<VcsRevision, QBrush> m_backgrounds; 0074 0075 mutable int m_lastCharBasedWidthHint = 0; 0076 mutable int m_lastViewBasedWidthHint = 0; 0077 }; 0078 0079 } 0080 0081 #endif