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 | // KDev | ||||
25 | #include <vcsrevision.h> | ||||
26 | // KF | ||||
27 | #include <KTextEditor/AbstractAnnotationItemDelegate> | ||||
28 | // Qt | ||||
29 | #include <QHash> | ||||
30 | #include <QBrush> | ||||
31 | #include <QPointer> | ||||
32 | | ||||
33 | namespace KDevelop | ||||
34 | { | ||||
35 | class ActiveToolTip; | ||||
36 | class VcsAnnotationLine; | ||||
37 | | ||||
38 | class VcsAnnotationItemDelegate : public KTextEditor::AbstractAnnotationItemDelegate | ||||
39 | { | ||||
40 | Q_OBJECT | ||||
41 | | ||||
42 | public: | ||||
43 | VcsAnnotationItemDelegate(KTextEditor::View* view, KTextEditor::AnnotationModel* model, QObject* parent); | ||||
44 | ~VcsAnnotationItemDelegate() override; | ||||
45 | | ||||
46 | public: // AbstractAnnotationItemDelegate APO | ||||
47 | void paint(QPainter* painter, const KTextEditor::StyleOptionAnnotationItem& option, | ||||
48 | KTextEditor::AnnotationModel* model, int line) const override; | ||||
49 | QSize sizeHint(const KTextEditor::StyleOptionAnnotationItem& option, | ||||
50 | KTextEditor::AnnotationModel* model, int line) const override; | ||||
51 | bool helpEvent(QHelpEvent* event, KTextEditor::View* view, | ||||
52 | const KTextEditor::StyleOptionAnnotationItem& option, | ||||
53 | KTextEditor::AnnotationModel *model, int line) override; | ||||
54 | void hideTooltip(KTextEditor::View *view) override; | ||||
55 | | ||||
56 | private: | ||||
57 | void renderBackground(QPainter* painter, | ||||
58 | const KTextEditor::StyleOptionAnnotationItem& option, | ||||
59 | const VcsAnnotationLine& annotationLine) const; | ||||
60 | void renderMessageAndAge(QPainter* painter, | ||||
61 | const KTextEditor::StyleOptionAnnotationItem& option, | ||||
62 | const QRect& messageRect, const QString& messageText, | ||||
63 | const QRect& ageRect, const QString& ageText) const; | ||||
64 | void renderAuthor(QPainter* painter, | ||||
65 | const KTextEditor::StyleOptionAnnotationItem& option, | ||||
66 | const QRect& authorRect, const QString& authorText) const; | ||||
67 | void renderHighlight(QPainter* painter, | ||||
68 | const KTextEditor::StyleOptionAnnotationItem& option) const; | ||||
69 | void doMessageLineLayout(const KTextEditor::StyleOptionAnnotationItem& option, | ||||
70 | QRect* messageRect, QRect* ageRect) const; | ||||
71 | void doAuthorLineLayout(const KTextEditor::StyleOptionAnnotationItem& option, | ||||
72 | QRect* authorRect) const; | ||||
73 | | ||||
74 | protected: // QObject API | ||||
75 | bool eventFilter(QObject* object, QEvent* event) override; | ||||
76 | | ||||
77 | private Q_SLOTS: | ||||
78 | void resetBackgrounds(); | ||||
79 | | ||||
80 | private: | ||||
81 | int widthHintFromViewWidth(int viewWidth) const; | ||||
82 | | ||||
83 | private: | ||||
84 | KTextEditor::AnnotationModel* const m_model; | ||||
85 | | ||||
86 | // TODO: make this configurable | ||||
87 | const int m_maxWidthViewPercent = 25; | ||||
88 | | ||||
89 | QPointer<ActiveToolTip> m_tooltip; | ||||
90 | QString m_tooltippedAnnotationGroupId; | ||||
91 | | ||||
92 | mutable QHash<VcsRevision, QBrush> m_backgrounds; | ||||
93 | | ||||
94 | mutable int m_lastCharBasedWidthHint = 0; | ||||
95 | mutable int m_lastViewBasedWidthHint = 0; | ||||
96 | }; | ||||
97 | | ||||
98 | } | ||||
99 | | ||||
100 | #endif |