Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/vcs/widgets/vcsannotationitemdelegate.h
- This file was added.
1 | /* This file is part of KDevelop | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Copyright 2017-2018 Friedrich W. H. Kossebau <kossebau@kde.org> | ||||
4 | * | ||||
5 | * This program is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU General Public License | ||||
7 | * as published by the Free Software Foundation; either version 2 | ||||
8 | * of the License, or (at your option) any later version. | ||||
9 | * | ||||
10 | * This program 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 | ||||
13 | * GNU General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU General Public License | ||||
16 | * along with this program; if not, write to the Free Software | ||||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||||
18 | * 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #ifndef KDEVPLATFORM_VCSANNITATIONITEMDELEGATE_H | ||||
22 | #define KDEVPLATFORM_VCSANNITATIONITEMDELEGATE_H | ||||
23 | | ||||
24 | #include <KTextEditor/AbstractAnnotationItemDelegate> | ||||
25 | | ||||
26 | #include <vcsrevision.h> | ||||
27 | #include <QHash> | ||||
28 | #include <QBrush> | ||||
29 | #include <QPointer> | ||||
30 | | ||||
31 | namespace KDevelop | ||||
32 | { | ||||
33 | class ActiveToolTip; | ||||
34 | class VcsAnnotationLine; | ||||
35 | | ||||
36 | class VcsAnnotationItemDelegate : public KTextEditor::AbstractAnnotationItemDelegate | ||||
37 | { | ||||
38 | Q_OBJECT | ||||
39 | | ||||
40 | public: | ||||
41 | VcsAnnotationItemDelegate(KTextEditor::View* view, KTextEditor::AnnotationModel* model, QObject* parent); | ||||
42 | ~VcsAnnotationItemDelegate() override; | ||||
43 | | ||||
44 | public: // AbstractAnnotationItemDelegate APO | ||||
45 | void paint(QPainter* painter, const KTextEditor::StyleOptionAnnotationItem& option, | ||||
46 | KTextEditor::AnnotationModel* model, int line) const override; | ||||
47 | QSize sizeHint(const KTextEditor::StyleOptionAnnotationItem& option, | ||||
48 | KTextEditor::AnnotationModel* model, int line) const override; | ||||
49 | bool helpEvent(QHelpEvent* event, KTextEditor::View* view, | ||||
50 | const KTextEditor::StyleOptionAnnotationItem& option, | ||||
51 | KTextEditor::AnnotationModel *model, int line) override; | ||||
52 | void hideTooltip(KTextEditor::View *view) override; | ||||
53 | | ||||
54 | private: | ||||
55 | void renderBackground(QPainter* painter, | ||||
56 | const KTextEditor::StyleOptionAnnotationItem& option, | ||||
57 | const VcsAnnotationLine& annotationLine) const; | ||||
58 | void renderMessageAndAge(QPainter* painter, | ||||
59 | const KTextEditor::StyleOptionAnnotationItem& option, | ||||
60 | const QRect& messageRect, const QString& messageText, | ||||
61 | const QRect& ageRect, const QString& ageText) const; | ||||
62 | void renderAuthor(QPainter* painter, | ||||
63 | const KTextEditor::StyleOptionAnnotationItem& option, | ||||
64 | const QRect& authorRect, const QString& authorText) const; | ||||
65 | void renderHighlight(QPainter* painter, | ||||
66 | const KTextEditor::StyleOptionAnnotationItem& option) const; | ||||
67 | void doMessageLineLayout(const KTextEditor::StyleOptionAnnotationItem& option, | ||||
68 | QRect* messageRect, QRect* ageRect) const; | ||||
69 | void doAuthorLineLayout(const KTextEditor::StyleOptionAnnotationItem& option, | ||||
70 | QRect* authorRect) const; | ||||
71 | | ||||
72 | protected: // QObject API | ||||
73 | bool eventFilter(QObject* object, QEvent* event) override; | ||||
74 | | ||||
75 | private Q_SLOTS: | ||||
76 | void resetBackgrounds(); | ||||
77 | | ||||
78 | private: | ||||
79 | int widthHintFromViewWidth(int viewWidth) const; | ||||
80 | | ||||
81 | private: | ||||
82 | KTextEditor::AnnotationModel* const m_model; | ||||
83 | | ||||
84 | QPointer<ActiveToolTip> m_tooltip; | ||||
85 | QString m_tooltippedAnnotationGroupId; | ||||
86 | | ||||
87 | mutable QHash<VcsRevision, QBrush> m_backgrounds; | ||||
88 | | ||||
89 | mutable int m_lastCharBasedWidthHint = 0; | ||||
90 | mutable int m_lastViewBasedWidthHint = 0; | ||||
91 | }; | ||||
92 | | ||||
93 | } | ||||
94 | | ||||
95 | #endif |