• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

  • interfaces
  • 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
22using namespace KTextEditor;
23
24class 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
37Attribute::Attribute()
38 : d(new AttributePrivate())
39{
40}
41
42Attribute::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
51Attribute::~Attribute()
52{
53 delete d;
54}
55
56Attribute& 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
73Attribute::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
81void Attribute::setDynamicAttribute( ActivationType type, Attribute::Ptr attribute )
82{
83 if (type < 0 || type > ActivateCaretIn)
84 return;
85
86 d->dynamicAttributes[type] = attribute;
87}
88
89QBrush Attribute::outline( ) const
90{
91 if (hasProperty(Outline))
92 return qVariantValue<QBrush>(property(Outline));
93
94 return QBrush();
95}
96
97void Attribute::setOutline( const QBrush & brush )
98{
99 setProperty(Outline, brush);
100}
101
102QBrush Attribute::selectedForeground( ) const
103{
104 if (hasProperty(SelectedForeground))
105 return qVariantValue<QBrush>(property(SelectedForeground));
106
107 return QBrush();
108}
109
110void Attribute::setSelectedForeground( const QBrush & foreground )
111{
112 setProperty(SelectedForeground, foreground);
113}
114
115bool Attribute::backgroundFillWhitespace( ) const
116{
117 if (hasProperty(BackgroundFillWhitespace))
118 return boolProperty(BackgroundFillWhitespace);
119
120 return true;
121}
122
123void Attribute::setBackgroundFillWhitespace( bool fillWhitespace )
124{
125 setProperty(BackgroundFillWhitespace, fillWhitespace);
126}
127
128QBrush Attribute::selectedBackground( ) const
129{
130 if (hasProperty(SelectedBackground))
131 return qVariantValue<QBrush>(properties()[SelectedBackground]);
132
133 return QBrush();
134}
135
136void Attribute::setSelectedBackground( const QBrush & brush )
137{
138 setProperty(SelectedBackground, brush);
139}
140
141void 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
151bool Attribute::fontBold( ) const
152{
153 return fontWeight() == QFont::Bold;
154}
155
156void Attribute::setFontBold( bool bold )
157{
158 setFontWeight(bold ? QFont::Bold : 0);
159}
160
161void Attribute::clearAssociatedActions( )
162{
163 d->associatedActions.clear();
164}
165
166bool Attribute::hasAnyProperty( ) const
167{
168 return properties().count();
169}
170
171const QList< KAction * > & Attribute::associatedActions( ) const
172{
173 return d->associatedActions;
174}
175
176Attribute::Effects KTextEditor::Attribute::effects( ) const
177{
178 if (hasProperty(AttributeDynamicEffect))
179 return Effects(intProperty(AttributeDynamicEffect));
180
181 return EffectNone;
182}
183
184void KTextEditor::Attribute::setEffects( Effects effects )
185{
186 setProperty(AttributeDynamicEffect, QVariant(effects));
187}
188
189Attribute & 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;
attribute.h
KSharedPtr< Attribute >
KTextEditor::Attribute
A class which provides customized text decorations.
Definition: attribute.h:61
KTextEditor::Attribute::ActivationType
ActivationType
Several automatic activation mechanisms exist for associated attributes.
Definition: attribute.h:262
KTextEditor::Attribute::ActivateCaretIn
@ ActivateCaretIn
Activate attribute on caret in.
Definition: attribute.h:266
KTextEditor::Attribute::effects
Effects effects() const
Definition: attribute.cpp:176
KTextEditor::Attribute::setBackgroundFillWhitespace
void setBackgroundFillWhitespace(bool fillWhitespace)
Set whether background color is drawn over whitespace.
Definition: attribute.cpp:123
KTextEditor::Attribute::~Attribute
virtual ~Attribute()
Virtual destructor.
Definition: attribute.cpp:51
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::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
KTextEditor::Attribute::setEffects
void setEffects(Effects effects)
Definition: attribute.cpp:184
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::selectedBackground
QBrush selectedBackground() const
Get the brush used to draw the background of selected text, if any.
Definition: attribute.cpp:128
KTextEditor::Attribute::fontBold
bool fontBold() const
Find out if the font weight is set to QFont::Bold.
Definition: attribute.cpp:151
KTextEditor::Attribute::operator=
Attribute & operator=(const Attribute &a)
Replacement assignment operator.
Definition: attribute.cpp:189
KTextEditor::Attribute::associatedActions
const QList< KAction * > & associatedActions() const
Returns a list of currently associated KActions.
Definition: attribute.cpp:171
KTextEditor::Attribute::clear
void clear()
Clear all set properties.
Definition: attribute.cpp:141
KTextEditor::Attribute::operator+=
Attribute & operator+=(const Attribute &a)
Addition assignment operator.
Definition: attribute.cpp:56
KTextEditor::Attribute::setFontBold
void setFontBold(bool bold=true)
Set the font weight to QFont::Bold.
Definition: attribute.cpp:156
KTextEditor::Attribute::SelectedBackground
@ SelectedBackground
Changes the brush used to paint the background when it is selected.
Definition: attribute.h:101
KTextEditor::Attribute::Outline
@ Outline
Draws an outline around the text.
Definition: attribute.h:97
KTextEditor::Attribute::SelectedForeground
@ SelectedForeground
Changes the brush used to paint the text when it is selected.
Definition: attribute.h:99
KTextEditor::Attribute::BackgroundFillWhitespace
@ BackgroundFillWhitespace
Determines whether background color is drawn over whitespace. Defaults to true.
Definition: attribute.h:103
KTextEditor::Attribute::setOutline
void setOutline(const QBrush &brush)
Set a brush to be used to draw an outline around text.
Definition: attribute.cpp:97
KTextEditor::Attribute::Attribute
Attribute()
Default constructor.
Definition: attribute.cpp:37
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
KTextEditor::Attribute::Ptr
KSharedPtr< Attribute > Ptr
Definition: attribute.h:65
KTextEditor::Attribute::setSelectedForeground
void setSelectedForeground(const QBrush &foreground)
Set a brush to be used to draw selected text.
Definition: attribute.cpp:110
KTextEditor::Attribute::clearAssociatedActions
void clearAssociatedActions()
Clears all associations between KActions and this attribute.
Definition: attribute.cpp:161
KTextEditor::Attribute::backgroundFillWhitespace
bool backgroundFillWhitespace() const
Determine whether background color is drawn over whitespace.
Definition: attribute.cpp:115
KTextEditor::Attribute::outline
QBrush outline() const
Get the brush used to draw an outline around text, if any.
Definition: attribute.cpp:89
KTextEditor::Attribute::hasAnyProperty
bool hasAnyProperty() const
Determine if any properties are set.
Definition: attribute.cpp:166
QList
QTextCharFormat
properties
KGuiItem properties()
KTextEditor
Namespace for the KDE Text Editor Interfaces.
Definition: annotationinterface.h:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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