KTextEditor
attribute.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 * Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Library General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "attribute.h" 00021 00022 using namespace KTextEditor; 00023 00024 class KTextEditor::AttributePrivate 00025 { 00026 public: 00027 AttributePrivate() 00028 { 00029 dynamicAttributes.append(Attribute::Ptr()); 00030 dynamicAttributes.append(Attribute::Ptr()); 00031 } 00032 00033 QList<KAction*> associatedActions; 00034 QList<Attribute::Ptr> dynamicAttributes; 00035 }; 00036 00037 Attribute::Attribute() 00038 : d(new AttributePrivate()) 00039 { 00040 } 00041 00042 Attribute::Attribute( const Attribute & a ) 00043 : QTextCharFormat(a) 00044 , QSharedData() 00045 , d(new AttributePrivate()) 00046 { 00047 d->associatedActions = a.d->associatedActions; 00048 d->dynamicAttributes = a.d->dynamicAttributes; 00049 } 00050 00051 Attribute::~Attribute() 00052 { 00053 delete d; 00054 } 00055 00056 Attribute& Attribute::operator+=(const Attribute& a) 00057 { 00058 merge(a); 00059 00060 d->associatedActions += a.associatedActions(); 00061 00062 for (int i = 0; i < a.d->dynamicAttributes.count(); ++i) 00063 if (i < d->dynamicAttributes.count()) { 00064 if (a.d->dynamicAttributes[i]) 00065 d->dynamicAttributes[i] = a.d->dynamicAttributes[i]; 00066 } else { 00067 d->dynamicAttributes.append(a.d->dynamicAttributes[i]); 00068 } 00069 00070 return *this; 00071 } 00072 00073 Attribute::Ptr Attribute::dynamicAttribute(ActivationType type) const 00074 { 00075 if (type < 0 || type >= d->dynamicAttributes.count()) 00076 return Ptr(); 00077 00078 return d->dynamicAttributes[type]; 00079 } 00080 00081 void Attribute::setDynamicAttribute( ActivationType type, Attribute::Ptr attribute ) 00082 { 00083 if (type < 0 || type > ActivateCaretIn) 00084 return; 00085 00086 d->dynamicAttributes[type] = attribute; 00087 } 00088 00089 QBrush Attribute::outline( ) const 00090 { 00091 if (hasProperty(Outline)) 00092 return qVariantValue<QBrush>(property(Outline)); 00093 00094 return QBrush(); 00095 } 00096 00097 void Attribute::setOutline( const QBrush & brush ) 00098 { 00099 setProperty(Outline, brush); 00100 } 00101 00102 QBrush Attribute::selectedForeground( ) const 00103 { 00104 if (hasProperty(SelectedForeground)) 00105 return qVariantValue<QBrush>(property(SelectedForeground)); 00106 00107 return QBrush(); 00108 } 00109 00110 void Attribute::setSelectedForeground( const QBrush & foreground ) 00111 { 00112 setProperty(SelectedForeground, foreground); 00113 } 00114 00115 bool Attribute::backgroundFillWhitespace( ) const 00116 { 00117 if (hasProperty(BackgroundFillWhitespace)) 00118 return boolProperty(BackgroundFillWhitespace); 00119 00120 return true; 00121 } 00122 00123 void Attribute::setBackgroundFillWhitespace( bool fillWhitespace ) 00124 { 00125 setProperty(BackgroundFillWhitespace, fillWhitespace); 00126 } 00127 00128 QBrush Attribute::selectedBackground( ) const 00129 { 00130 if (hasProperty(SelectedBackground)) 00131 return qVariantValue<QBrush>(properties()[SelectedBackground]); 00132 00133 return QBrush(); 00134 } 00135 00136 void Attribute::setSelectedBackground( const QBrush & brush ) 00137 { 00138 setProperty(SelectedBackground, brush); 00139 } 00140 00141 void Attribute::clear( ) 00142 { 00143 QTextCharFormat::operator=(QTextCharFormat()); 00144 00145 d->associatedActions.clear(); 00146 d->dynamicAttributes.clear(); 00147 d->dynamicAttributes.append(Ptr()); 00148 d->dynamicAttributes.append(Ptr()); 00149 } 00150 00151 bool Attribute::fontBold( ) const 00152 { 00153 return fontWeight() == QFont::Bold; 00154 } 00155 00156 void Attribute::setFontBold( bool bold ) 00157 { 00158 setFontWeight(bold ? QFont::Bold : 0); 00159 } 00160 00161 void Attribute::clearAssociatedActions( ) 00162 { 00163 d->associatedActions.clear(); 00164 } 00165 00166 bool Attribute::hasAnyProperty( ) const 00167 { 00168 return properties().count(); 00169 } 00170 00171 const QList< KAction * > & Attribute::associatedActions( ) const 00172 { 00173 return d->associatedActions; 00174 } 00175 00176 Attribute::Effects KTextEditor::Attribute::effects( ) const 00177 { 00178 if (hasProperty(AttributeDynamicEffect)) 00179 return Effects(intProperty(AttributeDynamicEffect)); 00180 00181 return EffectNone; 00182 } 00183 00184 void KTextEditor::Attribute::setEffects( Effects effects ) 00185 { 00186 setProperty(AttributeDynamicEffect, QVariant(effects)); 00187 } 00188 00189 Attribute & KTextEditor::Attribute::operator =( const Attribute & a ) 00190 { 00191 QTextCharFormat::operator=(a); 00192 Q_ASSERT(static_cast<QTextCharFormat>(*this) == a); 00193 00194 d->associatedActions = a.d->associatedActions; 00195 d->dynamicAttributes = a.d->dynamicAttributes; 00196 00197 return *this; 00198 } 00199 00200 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference