kate Library API Documentation

kateattribute.cpp

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2003 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., 59 Temple Place - Suite 330,
00016    Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #include "kateattribute.h"
00020 
00021 KateAttribute::KateAttribute()
00022   : m_weight(QFont::Normal)
00023   , m_italic(false)
00024   , m_underline(false)
00025   , m_strikeout(false)
00026   , m_itemsSet(0)
00027 {
00028 }
00029 
00030 KateAttribute::~KateAttribute()
00031 {
00032 }
00033 
00034 void KateAttribute::clear()
00035 {
00036   m_itemsSet=0;
00037 }
00038 
00039 KateAttribute& KateAttribute::operator+=(const KateAttribute& a)
00040 {
00041   if (a.itemSet(Weight))
00042     setWeight(a.weight());
00043 
00044   if (a.itemSet(Italic))
00045     setItalic(a.italic());
00046 
00047   if (a.itemSet(Underline))
00048     setUnderline(a.underline());
00049 
00050   if (a.itemSet(StrikeOut))
00051     setStrikeOut(a.strikeOut());
00052 
00053   if (a.itemSet(Outline))
00054     setOutline(a.outline());
00055 
00056   if (a.itemSet(TextColor))
00057     setTextColor(a.textColor());
00058 
00059   if (a.itemSet(SelectedTextColor))
00060     setSelectedTextColor(a.selectedTextColor());
00061 
00062   if (a.itemSet(BGColor))
00063     setBGColor(a.bgColor());
00064 
00065   if (a.itemSet(SelectedBGColor))
00066     setSelectedBGColor(a.selectedBGColor());
00067 
00068   return *this;
00069 }
00070 
00071 QFont KateAttribute::font(const QFont& ref)
00072 {
00073   QFont ret = ref;
00074 
00075   if (itemSet(Weight))
00076     ret.setWeight(weight());
00077   if (itemSet(Italic))
00078     ret.setItalic(italic());
00079   if (itemSet(Underline))
00080     ret.setUnderline(underline());
00081   if (itemSet(StrikeOut))
00082     ret.setStrikeOut(strikeOut());
00083 
00084   return ret;
00085 }
00086 
00087 void KateAttribute::setWeight(int weight)
00088 {
00089   if (!(m_itemsSet & Weight) || m_weight != weight)
00090   {
00091     m_itemsSet |= Weight;
00092 
00093     m_weight = weight;
00094 
00095     changed();
00096   }
00097 }
00098 
00099 void KateAttribute::setBold(bool enable)
00100 {
00101   setWeight(enable ? QFont::Bold : QFont::Normal);
00102 }
00103 
00104 void KateAttribute::setItalic(bool enable)
00105 {
00106   if (!(m_itemsSet & Italic) || m_italic != enable)
00107   {
00108     m_itemsSet |= Italic;
00109 
00110     m_italic = enable;
00111 
00112     changed();
00113   }
00114 }
00115 
00116 void KateAttribute::setUnderline(bool enable)
00117 {
00118   if (!(m_itemsSet & Underline) || m_underline != enable)
00119   {
00120     m_itemsSet |= Underline;
00121 
00122     m_underline = enable;
00123 
00124     changed();
00125   }
00126 }
00127 
00128 void KateAttribute::setStrikeOut(bool enable)
00129 {
00130   if (!(m_itemsSet & StrikeOut) || m_strikeout != enable)
00131   {
00132     m_itemsSet |= StrikeOut;
00133 
00134     m_strikeout = enable;
00135 
00136     changed();
00137   }
00138 }
00139 
00140 void KateAttribute::setOutline(const QColor& color)
00141 {
00142   if (!(m_itemsSet & Outline) || m_outline != color)
00143   {
00144     m_itemsSet |= Outline;
00145 
00146     m_outline = color;
00147 
00148     changed();
00149   }
00150 }
00151 
00152 void KateAttribute::setTextColor(const QColor& color)
00153 {
00154   if (!(m_itemsSet & TextColor) || m_textColor != color)
00155   {
00156     m_itemsSet |= TextColor;
00157 
00158     m_textColor = color;
00159 
00160     changed();
00161   }
00162 }
00163 
00164 void KateAttribute::setSelectedTextColor(const QColor& color)
00165 {
00166   if (!(m_itemsSet & SelectedTextColor) || m_selectedTextColor != color)
00167   {
00168     m_itemsSet |= SelectedTextColor;
00169 
00170     m_selectedTextColor = color;
00171 
00172     changed();
00173   }
00174 }
00175 
00176 void KateAttribute::setBGColor(const QColor& color)
00177 {
00178   if (!(m_itemsSet & BGColor) || m_bgColor != color)
00179   {
00180     m_itemsSet |= BGColor;
00181 
00182     m_bgColor = color;
00183 
00184     changed();
00185   }
00186 }
00187 
00188 void KateAttribute::setSelectedBGColor(const QColor& color)
00189 {
00190   if (!(m_itemsSet & SelectedBGColor) || m_selectedBGColor != color)
00191   {
00192     m_itemsSet |= SelectedBGColor;
00193 
00194     m_selectedBGColor = color;
00195 
00196     changed();
00197   }
00198 }
00199 
00200 bool operator ==(const KateAttribute& h1, const KateAttribute& h2)
00201 {
00202   if (h1.m_itemsSet != h2.m_itemsSet)
00203     return false;
00204 
00205   if (h1.itemSet(KateAttribute::Weight))
00206     if (h1.m_weight != h2.m_weight)
00207       return false;
00208 
00209   if (h1.itemSet(KateAttribute::Italic))
00210     if (h1.m_italic != h2.m_italic)
00211       return false;
00212 
00213   if (h1.itemSet(KateAttribute::Underline))
00214     if (h1.m_underline != h2.m_underline)
00215       return false;
00216 
00217   if (h1.itemSet(KateAttribute::StrikeOut))
00218     if (h1.m_strikeout != h2.m_strikeout)
00219       return false;
00220 
00221   if (h1.itemSet(KateAttribute::Outline))
00222     if (h1.m_outline != h2.m_outline)
00223       return false;
00224 
00225   if (h1.itemSet(KateAttribute::TextColor))
00226     if (h1.m_textColor != h2.m_textColor)
00227       return false;
00228 
00229   if (h1.itemSet(KateAttribute::SelectedTextColor))
00230     if (h1.m_selectedTextColor != h2.m_selectedTextColor)
00231       return false;
00232 
00233   if (h1.itemSet(KateAttribute::BGColor))
00234     if (h1.m_bgColor != h2.m_bgColor)
00235       return false;
00236 
00237   if (h1.itemSet(KateAttribute::SelectedBGColor))
00238     if (h1.m_selectedBGColor != h2.m_selectedBGColor)
00239       return false;
00240 
00241   return true;
00242 }
00243 
00244 bool operator !=(const KateAttribute& h1, const KateAttribute& h2)
00245 {
00246   return !(h1 == h2);
00247 }
00248 
00249 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE Logo
This file is part of the documentation for kate Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jan 22 16:52:50 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003