~ubuntu-branches/ubuntu/vivid/kate/vivid-updates

« back to all changes in this revision

Viewing changes to ktexteditor/attribute.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;