1
/* This file is part of the KDE libraries
2
* Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
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.
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.
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.
20
#include "attribute.h"
22
using namespace KTextEditor;
24
class KTextEditor::AttributePrivate
29
dynamicAttributes.append(Attribute::Ptr());
30
dynamicAttributes.append(Attribute::Ptr());
33
QList<KAction*> associatedActions;
34
QList<Attribute::Ptr> dynamicAttributes;
37
Attribute::Attribute()
38
: d(new AttributePrivate())
42
Attribute::Attribute( const Attribute & a )
45
, d(new AttributePrivate())
47
d->associatedActions = a.d->associatedActions;
48
d->dynamicAttributes = a.d->dynamicAttributes;
51
Attribute::~Attribute()
56
Attribute& Attribute::operator+=(const Attribute& a)
60
d->associatedActions += a.associatedActions();
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];
67
d->dynamicAttributes.append(a.d->dynamicAttributes[i]);
73
Attribute::Ptr Attribute::dynamicAttribute(ActivationType type) const
75
if (type < 0 || type >= d->dynamicAttributes.count())
78
return d->dynamicAttributes[type];
81
void Attribute::setDynamicAttribute( ActivationType type, Attribute::Ptr attribute )
83
if (type < 0 || type > ActivateCaretIn)
86
d->dynamicAttributes[type] = attribute;
89
QBrush Attribute::outline( ) const
91
if (hasProperty(Outline))
92
return qVariantValue<QBrush>(property(Outline));
97
void Attribute::setOutline( const QBrush & brush )
99
setProperty(Outline, brush);
102
QBrush Attribute::selectedForeground( ) const
104
if (hasProperty(SelectedForeground))
105
return qVariantValue<QBrush>(property(SelectedForeground));
110
void Attribute::setSelectedForeground( const QBrush & foreground )
112
setProperty(SelectedForeground, foreground);
115
bool Attribute::backgroundFillWhitespace( ) const
117
if (hasProperty(BackgroundFillWhitespace))
118
return boolProperty(BackgroundFillWhitespace);
123
void Attribute::setBackgroundFillWhitespace( bool fillWhitespace )
125
setProperty(BackgroundFillWhitespace, fillWhitespace);
128
QBrush Attribute::selectedBackground( ) const
130
if (hasProperty(SelectedBackground))
131
return qVariantValue<QBrush>(properties()[SelectedBackground]);
136
void Attribute::setSelectedBackground( const QBrush & brush )
138
setProperty(SelectedBackground, brush);
141
void Attribute::clear( )
143
QTextCharFormat::operator=(QTextCharFormat());
145
d->associatedActions.clear();
146
d->dynamicAttributes.clear();
147
d->dynamicAttributes.append(Ptr());
148
d->dynamicAttributes.append(Ptr());
151
bool Attribute::fontBold( ) const
153
return fontWeight() == QFont::Bold;
156
void Attribute::setFontBold( bool bold )
158
setFontWeight(bold ? QFont::Bold : 0);
161
void Attribute::clearAssociatedActions( )
163
d->associatedActions.clear();
166
bool Attribute::hasAnyProperty( ) const
168
return properties().count();
171
const QList< KAction * > & Attribute::associatedActions( ) const
173
return d->associatedActions;
176
Attribute::Effects KTextEditor::Attribute::effects( ) const
178
if (hasProperty(AttributeDynamicEffect))
179
return Effects(intProperty(AttributeDynamicEffect));
184
void KTextEditor::Attribute::setEffects( Effects effects )
186
setProperty(AttributeDynamicEffect, QVariant(effects));
189
Attribute & KTextEditor::Attribute::operator =( const Attribute & a )
191
QTextCharFormat::operator=(a);
192
Q_ASSERT(static_cast<QTextCharFormat>(*this) == a);
194
d->associatedActions = a.d->associatedActions;
195
d->dynamicAttributes = a.d->dynamicAttributes;
200
// kate: space-indent on; indent-width 2; replace-tabs on;