• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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

KTextEditor

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal