• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

  • kde-4.14
  • applications
  • kate
  • ktexteditor
attribute.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  * Copyright (C) 2003-2005 Hamish Rodda <rodda@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 #include "attribute.h"
21 
22 using namespace KTextEditor;
23 
24 class KTextEditor::AttributePrivate
25 {
26  public:
27  AttributePrivate()
28  {
29  dynamicAttributes.append(Attribute::Ptr());
30  dynamicAttributes.append(Attribute::Ptr());
31  }
32 
33  QList<KAction*> associatedActions;
34  QList<Attribute::Ptr> dynamicAttributes;
35 };
36 
37 Attribute::Attribute()
38  : d(new AttributePrivate())
39 {
40 }
41 
42 Attribute::Attribute( const Attribute & a )
43  : QTextCharFormat(a)
44  , QSharedData()
45  , d(new AttributePrivate())
46 {
47  d->associatedActions = a.d->associatedActions;
48  d->dynamicAttributes = a.d->dynamicAttributes;
49 }
50 
51 Attribute::~Attribute()
52 {
53  delete d;
54 }
55 
56 Attribute& Attribute::operator+=(const Attribute& a)
57 {
58  merge(a);
59 
60  d->associatedActions += a.associatedActions();
61 
62  for (int i = 0; i < a.d->dynamicAttributes.count(); ++i)
63  if (i < d->dynamicAttributes.count()) {
64  if (a.d->dynamicAttributes[i])
65  d->dynamicAttributes[i] = a.d->dynamicAttributes[i];
66  } else {
67  d->dynamicAttributes.append(a.d->dynamicAttributes[i]);
68  }
69 
70  return *this;
71 }
72 
73 Attribute::Ptr Attribute::dynamicAttribute(ActivationType type) const
74 {
75  if (type < 0 || type >= d->dynamicAttributes.count())
76  return Ptr();
77 
78  return d->dynamicAttributes[type];
79 }
80 
81 void Attribute::setDynamicAttribute( ActivationType type, Attribute::Ptr attribute )
82 {
83  if (type < 0 || type > ActivateCaretIn)
84  return;
85 
86  d->dynamicAttributes[type] = attribute;
87 }
88 
89 QBrush Attribute::outline( ) const
90 {
91  if (hasProperty(Outline))
92  return qVariantValue<QBrush>(property(Outline));
93 
94  return QBrush();
95 }
96 
97 void Attribute::setOutline( const QBrush & brush )
98 {
99  setProperty(Outline, brush);
100 }
101 
102 QBrush Attribute::selectedForeground( ) const
103 {
104  if (hasProperty(SelectedForeground))
105  return qVariantValue<QBrush>(property(SelectedForeground));
106 
107  return QBrush();
108 }
109 
110 void Attribute::setSelectedForeground( const QBrush & foreground )
111 {
112  setProperty(SelectedForeground, foreground);
113 }
114 
115 bool Attribute::backgroundFillWhitespace( ) const
116 {
117  if (hasProperty(BackgroundFillWhitespace))
118  return boolProperty(BackgroundFillWhitespace);
119 
120  return true;
121 }
122 
123 void Attribute::setBackgroundFillWhitespace( bool fillWhitespace )
124 {
125  setProperty(BackgroundFillWhitespace, fillWhitespace);
126 }
127 
128 QBrush Attribute::selectedBackground( ) const
129 {
130  if (hasProperty(SelectedBackground))
131  return qVariantValue<QBrush>(properties()[SelectedBackground]);
132 
133  return QBrush();
134 }
135 
136 void Attribute::setSelectedBackground( const QBrush & brush )
137 {
138  setProperty(SelectedBackground, brush);
139 }
140 
141 void Attribute::clear( )
142 {
143  QTextCharFormat::operator=(QTextCharFormat());
144 
145  d->associatedActions.clear();
146  d->dynamicAttributes.clear();
147  d->dynamicAttributes.append(Ptr());
148  d->dynamicAttributes.append(Ptr());
149 }
150 
151 bool Attribute::fontBold( ) const
152 {
153  return fontWeight() == QFont::Bold;
154 }
155 
156 void Attribute::setFontBold( bool bold )
157 {
158  setFontWeight(bold ? QFont::Bold : 0);
159 }
160 
161 void Attribute::clearAssociatedActions( )
162 {
163  d->associatedActions.clear();
164 }
165 
166 bool Attribute::hasAnyProperty( ) const
167 {
168  return properties().count();
169 }
170 
171 const QList< KAction * > & Attribute::associatedActions( ) const
172 {
173  return d->associatedActions;
174 }
175 
176 Attribute::Effects KTextEditor::Attribute::effects( ) const
177 {
178  if (hasProperty(AttributeDynamicEffect))
179  return Effects(intProperty(AttributeDynamicEffect));
180 
181  return EffectNone;
182 }
183 
184 void KTextEditor::Attribute::setEffects( Effects effects )
185 {
186  setProperty(AttributeDynamicEffect, QVariant(effects));
187 }
188 
189 Attribute & KTextEditor::Attribute::operator =( const Attribute & a )
190 {
191  QTextCharFormat::operator=(a);
192  Q_ASSERT(static_cast<QTextCharFormat>(*this) == a);
193 
194  d->associatedActions = a.d->associatedActions;
195  d->dynamicAttributes = a.d->dynamicAttributes;
196 
197  return *this;
198 }
199 
200 // kate: space-indent on; indent-width 2; replace-tabs on;
QTextFormat::setProperty
void setProperty(int propertyId, const QVariant &value)
KTextEditor::Attribute
A class which provides customized text decorations.
Definition: attribute.h:58
QTextCharFormat::fontWeight
int fontWeight() const
KTextEditor::Attribute::setBackgroundFillWhitespace
void setBackgroundFillWhitespace(bool fillWhitespace)
Set whether background color is drawn over whitespace.
Definition: attribute.cpp:123
KTextEditor::Attribute::associatedActions
const QList< KAction * > & associatedActions() const
Returns a list of currently associated KActions.
Definition: attribute.cpp:171
KTextEditor::Attribute::effects
Effects effects() const
Definition: attribute.cpp:176
KTextEditor::Attribute::selectedForeground
QBrush selectedForeground() const
Get the brush used to draw text when it is selected, if any.
Definition: attribute.cpp:102
KTextEditor::Attribute::outline
QBrush outline() const
Get the brush used to draw an outline around text, if any.
Definition: attribute.cpp:89
QBrush
KTextEditor::Attribute::setOutline
void setOutline(const QBrush &brush)
Set a brush to be used to draw an outline around text.
Definition: attribute.cpp:97
QTextFormat::merge
void merge(const QTextFormat &other)
KTextEditor::Attribute::setSelectedForeground
void setSelectedForeground(const QBrush &foreground)
Set a brush to be used to draw selected text.
Definition: attribute.cpp:110
KTextEditor::Attribute::BackgroundFillWhitespace
Determines whether background color is drawn over whitespace. Defaults to true.
Definition: attribute.h:99
KTextEditor::Attribute::fontBold
bool fontBold() const
Find out if the font weight is set to QFont::Bold.
Definition: attribute.cpp:151
QTextFormat::operator=
QTextFormat & operator=(const QTextFormat &other)
QTextFormat::hasProperty
bool hasProperty(int propertyId) const
KTextEditor::Attribute::hasAnyProperty
bool hasAnyProperty() const
Determine if any properties are set.
Definition: attribute.cpp:166
QSharedData
QTextCharFormat::QTextCharFormat
QTextCharFormat()
KTextEditor::Attribute::~Attribute
virtual ~Attribute()
Virtual destructor.
Definition: attribute.cpp:51
attribute.h
KTextEditor::Attribute::backgroundFillWhitespace
bool backgroundFillWhitespace() const
Determine whether background color is drawn over whitespace.
Definition: attribute.cpp:115
KTextEditor::Attribute::Ptr
KSharedPtr< Attribute > Ptr
Definition: attribute.h:61
QTextFormat::properties
QMap< int, QVariant > properties() const
KTextEditor::Attribute::operator=
Attribute & operator=(const Attribute &a)
Replacement assignment operator.
Definition: attribute.cpp:189
KTextEditor::Attribute::setSelectedBackground
void setSelectedBackground(const QBrush &brush)
Set a brush to be used to draw the background of selected text, if any.
Definition: attribute.cpp:136
KTextEditor::Attribute::setFontBold
void setFontBold(bool bold=true)
Set the font weight to QFont::Bold.
Definition: attribute.cpp:156
QList< KAction * >
KTextEditor::Attribute::ActivateCaretIn
Activate attribute on caret in.
Definition: attribute.h:262
KTextEditor::Attribute::SelectedBackground
Changes the brush used to paint the background when it is selected.
Definition: attribute.h:97
KTextEditor::Attribute::Attribute
Attribute()
Default constructor.
Definition: attribute.cpp:37
QTextCharFormat
KTextEditor::Attribute::selectedBackground
QBrush selectedBackground() const
Get the brush used to draw the background of selected text, if any.
Definition: attribute.cpp:128
QTextCharFormat::setFontWeight
void setFontWeight(int weight)
QTextFormat::boolProperty
bool boolProperty(int propertyId) const
KTextEditor::Attribute::clearAssociatedActions
void clearAssociatedActions()
Clears all associations between KActions and this attribute.
Definition: attribute.cpp:161
KTextEditor::Attribute::Outline
Draws an outline around the text.
Definition: attribute.h:93
KTextEditor::Attribute::setDynamicAttribute
void setDynamicAttribute(ActivationType type, Attribute::Ptr attribute)
Set the attribute to use when the event referred to by type occurs.
Definition: attribute.cpp:81
QTextFormat::property
QVariant property(int propertyId) const
KTextEditor::Attribute::operator+=
Attribute & operator+=(const Attribute &a)
Addition assignment operator.
Definition: attribute.cpp:56
KTextEditor::Attribute::ActivationType
ActivationType
Several automatic activation mechanisms exist for associated attributes.
Definition: attribute.h:258
KTextEditor::Attribute::setEffects
void setEffects(Effects effects)
Definition: attribute.cpp:184
KTextEditor::Attribute::clear
void clear()
Clear all set properties.
Definition: attribute.cpp:141
KTextEditor::Attribute::SelectedForeground
Changes the brush used to paint the text when it is selected.
Definition: attribute.h:95
QTextFormat::type
int type() const
QVariant
KTextEditor::Attribute::dynamicAttribute
Attribute::Ptr dynamicAttribute(ActivationType type) const
Return the attribute to use when the event referred to by type occurs.
Definition: attribute.cpp:73
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:47 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KTextEditor

Skip menu "KTextEditor"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal