Changeset View
Standalone View
src/include/ktexteditor/abstractannotationitemdelegate.h
- This file was added.
1 | /* This file is part of the KDE libraries | ||||
---|---|---|---|---|---|
2 | * Copyright 2017 Friedrich W. H. Kossebau <kossebau kde org> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Library General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This library is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * Library General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public License | ||||
15 | * along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | * Boston, MA 02110-1301, USA | ||||
18 | */ | ||||
19 | | ||||
20 | #ifndef KTEXTEDITOR_ABSTRACTANNOTATIONITEMDELEGATE_H | ||||
21 | #define KTEXTEDITOR_ABSTRACTANNOTATIONITEMDELEGATE_H | ||||
22 | | ||||
23 | #include <ktexteditor_export.h> | ||||
24 | | ||||
25 | #include <QObject> | ||||
26 | #include <QStyleOption> | ||||
27 | | ||||
28 | class QHelpEvent; | ||||
29 | class QSize; | ||||
30 | class QPoint; | ||||
31 | | ||||
32 | | ||||
33 | namespace KTextEditor | ||||
34 | { | ||||
35 | class AnnotationModel; | ||||
36 | class View; | ||||
37 | | ||||
38 | class KTEXTEDITOR_EXPORT StyleOptionAnnotationItem : public QStyleOption | ||||
39 | { | ||||
40 | public: | ||||
dhaumann: @since 5.52 :-) | |||||
41 | // TODO: not sure what SO_Default implies, but no clue how to maintain a user type registry? | ||||
42 | enum StyleOptionType { Type = SO_Default }; | ||||
43 | enum StyleOptionVersion { Version = 1 }; | ||||
44 | | ||||
45 | int wrappedLine = 0; | ||||
46 | int wrappedLineCount = 1; | ||||
47 | int visibleWrappedLineInGroup = 0; | ||||
48 | bool highlight = true; | ||||
49 | | ||||
50 | KTextEditor::View* view = nullptr; | ||||
51 | /** recommended size for icons or other symbols */ | ||||
52 | QSize decorationSize; | ||||
53 | QFontMetricsF contentFontMetrics; | ||||
I am asking myself: Is wrappedLineCount >= 1 always true? If so, can you add this as documentation? wrappedLineCount == 1 means no wrapping line? dhaumann: I am asking myself: Is wrappedLineCount >= 1 always true? If so, can you add this as… | |||||
Yes. I see now that this can be confusing and semantically strange, if wrappedLineCount == 1 means actually no wrapping here. Unsure what ould be a better way to express this. One ould use the same name and define 0 to mean that no wrapping is done. And 1 would just be a bogus value? Proposals very welcome. kossebau: Yes. I see now that this can be confusing and semantically strange, if wrappedLineCount == 1… | |||||
54 | | ||||
55 | enum AnnotationItemGroupPosition { Invalid, Beginning, Middle, End, OnlyOne }; | ||||
56 | | ||||
57 | AnnotationItemGroupPosition annotationItemGroupingPosition; | ||||
58 | // TODO: make delegate always care for background? | ||||
59 | // QBrush backgroundBrush; | ||||
60 | | ||||
61 | StyleOptionAnnotationItem() : contentFontMetrics(QFont()) {} | ||||
62 | StyleOptionAnnotationItem(const StyleOptionAnnotationItem& other) | ||||
63 | : QStyleOption(Version, Type), contentFontMetrics(QFont()) { *this = other; } | ||||
64 | | ||||
65 | protected: | ||||
66 | StyleOptionAnnotationItem(int version) : QStyleOption(version, Type), contentFontMetrics(QFont()) {} | ||||
Is this to be set by the user, and if so, is there any special meaning to a default-constructed QSize()? dhaumann: Is this to be set by the user, and if so, is there any special meaning to a default-constructed… | |||||
This parameter was inspired by QStyleOptionViewItem::decorationSize. I imagined it could be e.g. used if one ever starts to show avatar icons for commit authors in the annotations, or for other icon-based indicators which could be shown (bug fix, reviewed, etc). There is no specification on the meaning of an invalid QSize with QStyleOptionViewItem::decorationSize. I would tend to leave this here unspecified as well for now, until this gets in real use or the QStyleOptionViewItem one gets specified? kossebau: This parameter was inspired by QStyleOptionViewItem::decorationSize. I imagined it could be e.g. | |||||
67 | }; | ||||
Is the view pointer always valid when the style option is passed as argument? If so, I suggest to add this as comment to avoid unnecessary if() calls / error handling etc... dhaumann: Is the view pointer always valid when the style option is passed as argument? If so, I suggest… | |||||
68 | | ||||
69 | | ||||
70 | class KTEXTEDITOR_EXPORT AbstractAnnotationItemDelegate : public QObject | ||||
71 | { | ||||
72 | Q_OBJECT | ||||
73 | | ||||
74 | protected: | ||||
75 | explicit AbstractAnnotationItemDelegate(QObject* parent = nullptr) : QObject(parent) {} | ||||
76 | public: | ||||
77 | virtual ~AbstractAnnotationItemDelegate() {} | ||||
78 | | ||||
79 | public: | ||||
80 | virtual void paint(QPainter *painter, const KTextEditor::StyleOptionAnnotationItem &option, | ||||
81 | KTextEditor::AnnotationModel *model, int line) const = 0; | ||||
dhaumann: Is this a bitmask? The << 0, <<1, <<2 notation implies that it is. | |||||
Yes, as a line could be both begin and end of an annotation grouping (if both neighbour lines belong to different groups). Of course InGroup is mutually exclusive to GroupBegin and GroupEnd. IIRC (been some time since Nob 2017 :) ) I had used normal enum values, with another value GroupBeginAndEnd. But the resulting code using the enum was more complicated. kossebau: Yes, as a line could be both begin and end of an annotation grouping (if both neighbour lines… | |||||
82 | virtual QSize sizeHint(const KTextEditor::StyleOptionAnnotationItem &option, | ||||
83 | KTextEditor::AnnotationModel *model, int line) const = 0; | ||||
84 | virtual bool helpEvent(QHelpEvent *event, KTextEditor::View *view, | ||||
85 | KTextEditor::AnnotationModel *model, int line) = 0; | ||||
86 | virtual void contextMenuRequested(const QPoint &pos, | ||||
87 | KTextEditor::AnnotationModel *model, int line) = 0; | ||||
88 | | ||||
89 | Q_SIGNALS: | ||||
90 | void sizeHintChanged(KTextEditor::AnnotationModel *model, int line); | ||||
91 | }; | ||||
92 | | ||||
93 | } | ||||
94 | | ||||
95 | #endif | ||||
You export the class, but then the constructors are inlined. Could you please move the implementation to the cpp file? That leaves us more room to fixes by shipping an updated version of the library. dhaumann: You export the class, but then the constructors are inlined. Could you please move the… | |||||
Okay. I had looked at the other interface classes, those I looked at, even if QObject-based, are header-only, that's why it was done like this. Will change, as I remember from other projets e,g. Windows has issues with this. kossebau: Okay. I had looked at the other interface classes, those I looked at, even if QObject-based… | |||||
dhaumann: Typ: A delegate ...
And: I suggest to remove "for them". | |||||
dhaumann: Same here: Could you move the implementation to ktexteditor.cpp? | |||||
Same here: Please move the destructor to ktexteditor.cpp. You can keep = default there, but not here. dhaumann: Same here: Please move the destructor to ktexteditor.cpp. You can keep = default there, but not… | |||||
dhaumann: typo: specifying | |||||
dhaumann: inlc. -> including. No need for abbreviations |
@since 5.52 :-)