KTextEditor

attribute.cpp
1/*
2 SPDX-FileCopyrightText: 2003-2005 Hamish Rodda <rodda@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "attribute.h"
8#include "kateextendedattribute.h"
9
10#include <KSyntaxHighlighting/Theme>
11
12#include <QDebug>
13#include <QMetaEnum>
14
15using namespace KTextEditor;
16
17class KTextEditor::AttributePrivate
18{
19public:
20 AttributePrivate()
21 {
22 dynamicAttributes.append(Attribute::Ptr());
23 dynamicAttributes.append(Attribute::Ptr());
24 }
25
26 QList<Attribute::Ptr> dynamicAttributes;
27};
28
30 : d(new AttributePrivate())
31{
32}
33
35 : d(new AttributePrivate())
36{
38 setDefaultStyle(style);
39}
40
43 , QSharedData()
44 , d(new AttributePrivate())
45{
46 d->dynamicAttributes = a.d->dynamicAttributes;
47}
48
50{
51 delete d;
52}
53
55{
56 merge(a);
57
58 for (int i = 0; i < a.d->dynamicAttributes.count(); ++i) {
59 if (i < d->dynamicAttributes.count()) {
60 if (a.d->dynamicAttributes[i]) {
61 d->dynamicAttributes[i] = a.d->dynamicAttributes[i];
62 }
63 } else {
64 d->dynamicAttributes.append(a.d->dynamicAttributes[i]);
65 }
66 }
67
68 return *this;
69}
70
72{
73 if (type < 0 || type >= d->dynamicAttributes.count()) {
74 return Ptr();
75 }
76
77 return d->dynamicAttributes[type];
78}
79
81{
83 return;
84 }
85
86 d->dynamicAttributes[type] = std::move(attribute);
87}
88
90{
91 return stringProperty(AttributeName);
92}
93
94void Attribute::setName(const QString &name)
95{
96 setProperty(AttributeName, name);
97}
98
100{
101 return static_cast<KSyntaxHighlighting::Theme::TextStyle>(intProperty(AttributeDefaultStyleIndex));
102}
103
105{
106 setProperty(AttributeDefaultStyleIndex, QVariant(static_cast<int>(style)));
107}
108
110{
111 return boolProperty(Spellchecking);
112}
113
114void Attribute::setSkipSpellChecking(bool skipspellchecking)
115{
116 setProperty(Spellchecking, QVariant(skipspellchecking));
117}
118
120{
121 if (hasProperty(Outline)) {
122 return property(Outline).value<QBrush>();
123 }
124
125 return QBrush();
126}
127
129{
130 setProperty(Outline, brush);
131}
132
134{
135 if (hasProperty(SelectedForeground)) {
136 return property(SelectedForeground).value<QBrush>();
137 }
138
139 return QBrush();
140}
141
143{
144 setProperty(SelectedForeground, foreground);
145}
146
148{
149 if (hasProperty(BackgroundFillWhitespace)) {
150 return boolProperty(BackgroundFillWhitespace);
151 }
152
153 return true;
154}
155
157{
158 setProperty(BackgroundFillWhitespace, fillWhitespace);
159}
160
162{
163 if (hasProperty(SelectedBackground)) {
164 return property(SelectedBackground).value<QBrush>();
165 }
166
167 return QBrush();
168}
169
171{
172 setProperty(SelectedBackground, brush);
173}
174
176{
178
179 d->dynamicAttributes.clear();
180 d->dynamicAttributes.append(Ptr());
181 d->dynamicAttributes.append(Ptr());
182}
183
185{
186 return fontWeight() == QFont::Bold;
187}
188
190{
191 if (bold) {
193 } else {
195 }
196}
197
199{
200 return !properties().isEmpty();
201}
202
204{
206 Q_ASSERT(static_cast<QTextCharFormat>(*this) == a);
207
208 d->dynamicAttributes = a.d->dynamicAttributes;
209
210 return *this;
211}
A class which provides customized text decorations.
Definition attribute.h:51
QExplicitlySharedDataPointer< Attribute > Ptr
Shared data pointer for Attribute.
Definition attribute.h:56
ActivationType
Several automatic activation mechanisms exist for associated attributes.
Definition attribute.h:244
@ ActivateCaretIn
Activate attribute on caret in.
Definition attribute.h:248
void setName(const QString &name)
Set attribute name.
Definition attribute.cpp:94
void setBackgroundFillWhitespace(bool fillWhitespace)
Set whether background color is drawn over whitespace.
virtual ~Attribute()
Virtual destructor.
Definition attribute.cpp:49
void setSelectedBackground(const QBrush &brush)
Set a brush to be used to draw the background of selected text, if any.
void setDefaultStyle(KSyntaxHighlighting::Theme::TextStyle style)
Set default style of this attribute.
void setDynamicAttribute(ActivationType type, Attribute::Ptr attribute)
Set the attribute to use when the event referred to by type occurs.
Definition attribute.cpp:80
void setSkipSpellChecking(bool skipspellchecking)
Set if we should spellchecking be skipped?
QBrush selectedForeground() const
Get the brush used to draw text when it is selected, if any.
QBrush selectedBackground() const
Get the brush used to draw the background of selected text, if any.
bool fontBold() const
Find out if the font weight is set to QFont::Bold.
Attribute & operator=(const Attribute &a)
Replacement assignment operator.
void clear()
Clear all set properties.
Attribute & operator+=(const Attribute &a)
Addition assignment operator.
Definition attribute.cpp:54
KSyntaxHighlighting::Theme::TextStyle defaultStyle() const
Default style of this attribute.
Definition attribute.cpp:99
QString name() const
Attribute name.
Definition attribute.cpp:89
void setFontBold(bool bold=true)
Set the font weight to QFont::Bold.
void setOutline(const QBrush &brush)
Set a brush to be used to draw an outline around text.
Attribute()
Default constructor.
Definition attribute.cpp:29
bool skipSpellChecking() const
Should spellchecking be skipped?
Attribute::Ptr dynamicAttribute(ActivationType type) const
Return the attribute to use when the event referred to by type occurs.
Definition attribute.cpp:71
void setSelectedForeground(const QBrush &foreground)
Set a brush to be used to draw selected text.
bool backgroundFillWhitespace() const
Determine whether background color is drawn over whitespace.
QBrush outline() const
Get the brush used to draw an outline around text, if any.
bool hasAnyProperty() const
Determine if any properties are set.
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
int fontWeight() const const
void setFontWeight(int weight)
bool boolProperty(int propertyId) const const
void clearProperty(int propertyId)
QBrush foreground() const const
bool hasProperty(int propertyId) const const
int intProperty(int propertyId) const const
void merge(const QTextFormat &other)
QTextFormat & operator=(const QTextFormat &other)
QMap< int, QVariant > properties() const const
QVariant property(int propertyId) const const
void setProperty(int propertyId, const QList< QTextLength > &value)
QString stringProperty(int propertyId) const const
int type() const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.