File indexing completed on 2024-06-23 04:19:02
0001 0002 /* 0003 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org> 0004 All rights reserved. 0005 0006 Redistribution and use in source and binary forms, with or without 0007 modification, are permitted provided that the following conditions 0008 are met: 0009 0010 1. Redistributions of source code must retain the above copyright 0011 notice, this list of conditions and the following disclaimer. 0012 2. Redistributions in binary form must reproduce the above copyright 0013 notice, this list of conditions and the following disclaimer in the 0014 documentation and/or other materials provided with the distribution. 0015 0016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0017 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0018 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0019 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0020 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0021 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0022 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0023 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0025 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0026 */ 0027 0028 0029 #include "layers/selections/text/kpTextStyle.h" 0030 0031 #include <QDataStream> 0032 #include <QFont> 0033 #include <QFontMetrics> 0034 0035 0036 kpTextStyle::kpTextStyle () 0037 : m_fontSize (0), 0038 m_isBold (false), m_isItalic (false), 0039 m_isUnderline (false), m_isStrikeThru (false), 0040 m_isBackgroundOpaque (true) 0041 { 0042 } 0043 0044 kpTextStyle::kpTextStyle (const QString &fontFamily, 0045 int fontSize, 0046 bool isBold, bool isItalic, 0047 bool isUnderline, bool isStrikeThru, 0048 const kpColor &fcolor, const kpColor &bcolor, 0049 bool isBackgroundOpaque) 0050 : m_fontFamily (fontFamily), 0051 m_fontSize (fontSize), 0052 m_isBold (isBold), m_isItalic (isItalic), 0053 m_isUnderline (isUnderline), m_isStrikeThru (isStrikeThru), 0054 m_foregroundColor (fcolor), m_backgroundColor (bcolor), 0055 m_isBackgroundOpaque (isBackgroundOpaque) 0056 { 0057 } 0058 0059 kpTextStyle::~kpTextStyle () = default; 0060 0061 0062 // friend 0063 QDataStream &operator<< (QDataStream &stream, const kpTextStyle &textStyle) 0064 { 0065 stream << textStyle.m_fontFamily; 0066 stream << textStyle.m_fontSize; 0067 0068 stream << int (textStyle.m_isBold) << int (textStyle.m_isItalic) 0069 << int (textStyle.m_isUnderline) << int (textStyle.m_isStrikeThru); 0070 0071 stream << textStyle.m_foregroundColor << textStyle.m_backgroundColor; 0072 0073 stream << int (textStyle.m_isBackgroundOpaque); 0074 0075 return stream; 0076 } 0077 0078 // friend 0079 QDataStream &operator>> (QDataStream &stream, kpTextStyle &textStyle) 0080 { 0081 stream >> textStyle.m_fontFamily; 0082 stream >> textStyle.m_fontSize; 0083 0084 int a, b, c, d; 0085 stream >> a >> b >> c >> d; 0086 textStyle.m_isBold = a; 0087 textStyle.m_isItalic = b; 0088 textStyle.m_isUnderline = c; 0089 textStyle.m_isStrikeThru = d; 0090 0091 stream >> textStyle.m_foregroundColor >> textStyle.m_backgroundColor; 0092 0093 int e; 0094 stream >> e; 0095 textStyle.m_isBackgroundOpaque = e; 0096 0097 return stream; 0098 } 0099 0100 // public 0101 bool kpTextStyle::operator== (const kpTextStyle &rhs) const 0102 { 0103 return (m_fontFamily == rhs.m_fontFamily && 0104 m_fontSize == rhs.m_fontSize && 0105 m_isBold == rhs.m_isBold && 0106 m_isItalic == rhs.m_isItalic && 0107 m_isUnderline == rhs.m_isUnderline && 0108 m_isStrikeThru == rhs.m_isStrikeThru && 0109 m_foregroundColor == rhs.m_foregroundColor && 0110 m_backgroundColor == rhs.m_backgroundColor && 0111 m_isBackgroundOpaque == rhs.m_isBackgroundOpaque); 0112 } 0113 0114 // public 0115 bool kpTextStyle::operator!= (const kpTextStyle &rhs) const 0116 { 0117 return !(*this == rhs); 0118 } 0119 0120 0121 // public 0122 QString kpTextStyle::fontFamily () const 0123 { 0124 return m_fontFamily; 0125 } 0126 0127 // public 0128 void kpTextStyle::setFontFamily (const QString &f) 0129 { 0130 m_fontFamily = f; 0131 } 0132 0133 0134 // public 0135 int kpTextStyle::fontSize () const 0136 { 0137 return m_fontSize; 0138 } 0139 0140 // public 0141 void kpTextStyle::setFontSize (int s) 0142 { 0143 m_fontSize = s; 0144 } 0145 0146 0147 // public 0148 bool kpTextStyle::isBold () const 0149 { 0150 return m_isBold; 0151 } 0152 0153 // public 0154 void kpTextStyle::setBold (bool yes) 0155 { 0156 m_isBold = yes; 0157 } 0158 0159 0160 // public 0161 bool kpTextStyle::isItalic () const 0162 { 0163 return m_isItalic; 0164 } 0165 0166 // public 0167 void kpTextStyle::setItalic (bool yes) 0168 { 0169 m_isItalic = yes; 0170 } 0171 0172 0173 // public 0174 bool kpTextStyle::isUnderline () const 0175 { 0176 return m_isUnderline; 0177 } 0178 0179 // public 0180 void kpTextStyle::setUnderline (bool yes) 0181 { 0182 m_isUnderline = yes; 0183 } 0184 0185 0186 // public 0187 bool kpTextStyle::isStrikeThru () const 0188 { 0189 return m_isStrikeThru; 0190 } 0191 0192 // public 0193 void kpTextStyle::setStrikeThru (bool yes) 0194 { 0195 m_isStrikeThru = yes; 0196 } 0197 0198 0199 // public 0200 kpColor kpTextStyle::foregroundColor () const 0201 { 0202 return m_foregroundColor; 0203 } 0204 0205 // public 0206 void kpTextStyle::setForegroundColor (const kpColor &fcolor) 0207 { 0208 m_foregroundColor = fcolor; 0209 } 0210 0211 0212 // public 0213 kpColor kpTextStyle::backgroundColor () const 0214 { 0215 return m_backgroundColor; 0216 } 0217 0218 // public 0219 void kpTextStyle::setBackgroundColor (const kpColor &bcolor) 0220 { 0221 m_backgroundColor = bcolor; 0222 } 0223 0224 0225 // public 0226 bool kpTextStyle::isBackgroundOpaque () const 0227 { 0228 return m_isBackgroundOpaque; 0229 } 0230 0231 // public 0232 void kpTextStyle::setBackgroundOpaque (bool yes) 0233 { 0234 m_isBackgroundOpaque = yes; 0235 } 0236 0237 0238 // public 0239 bool kpTextStyle::isBackgroundTransparent () const 0240 { 0241 return !m_isBackgroundOpaque; 0242 } 0243 0244 // public 0245 void kpTextStyle::setBackgroundTransparent (bool yes) 0246 { 0247 m_isBackgroundOpaque = !yes; 0248 } 0249 0250 0251 // public 0252 QFont kpTextStyle::font () const 0253 { 0254 QFont fnt (m_fontFamily, m_fontSize); 0255 fnt.setBold (m_isBold); 0256 fnt.setItalic (m_isItalic); 0257 fnt.setUnderline (m_isUnderline); 0258 fnt.setStrikeOut (m_isStrikeThru); 0259 0260 return fnt; 0261 } 0262 0263 // public 0264 QFontMetrics kpTextStyle::fontMetrics () const 0265 { 0266 return QFontMetrics (font ()); 0267 }