TDE graphics utilities
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kptextstyle.cpp 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  13. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  14. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  15. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  17. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  18. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  19. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  21. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #include <kptextstyle.h>
  24. #include <tqdatastream.h>
  25. #include <tqfont.h>
  26. #include <tqfontmetrics.h>
  27. kpTextStyle::kpTextStyle ()
  28. : m_fontSize (0),
  29. m_isBold (false), m_isItalic (false),
  30. m_isUnderline (false), m_isStrikeThru (false),
  31. m_isBackgroundOpaque (true)
  32. {
  33. }
  34. kpTextStyle::kpTextStyle (const TQString &fontFamily,
  35. int fontSize,
  36. bool isBold, bool isItalic,
  37. bool isUnderline, bool isStrikeThru,
  38. const kpColor &fcolor, const kpColor &bcolor,
  39. bool isBackgroundOpaque)
  40. : m_fontFamily (fontFamily),
  41. m_fontSize (fontSize),
  42. m_isBold (isBold), m_isItalic (isItalic),
  43. m_isUnderline (isUnderline), m_isStrikeThru (isStrikeThru),
  44. m_foregroundColor (fcolor), m_backgroundColor (bcolor),
  45. m_isBackgroundOpaque (isBackgroundOpaque)
  46. {
  47. }
  48. kpTextStyle::~kpTextStyle ()
  49. {
  50. }
  51. // friend
  52. TQDataStream &operator<< (TQDataStream &stream, const kpTextStyle &textStyle)
  53. {
  54. stream << textStyle.m_fontFamily;
  55. stream << textStyle.m_fontSize;
  56. stream << int (textStyle.m_isBold) << int (textStyle.m_isItalic)
  57. << int (textStyle.m_isUnderline) << int (textStyle.m_isStrikeThru);
  58. stream << textStyle.m_foregroundColor << textStyle.m_backgroundColor;
  59. stream << int (textStyle.m_isBackgroundOpaque);
  60. return stream;
  61. }
  62. // friend
  63. TQDataStream &operator>> (TQDataStream &stream, kpTextStyle &textStyle)
  64. {
  65. stream >> textStyle.m_fontFamily;
  66. stream >> textStyle.m_fontSize;
  67. int a, b, c, d;
  68. stream >> a >> b >> c >> d;
  69. textStyle.m_isBold = a;
  70. textStyle.m_isItalic = b;
  71. textStyle.m_isUnderline = c;
  72. textStyle.m_isStrikeThru = d;
  73. stream >> textStyle.m_foregroundColor >> textStyle.m_backgroundColor;
  74. int e;
  75. stream >> e;
  76. textStyle.m_isBackgroundOpaque = e;
  77. return stream;
  78. }
  79. // public
  80. bool kpTextStyle::operator== (const kpTextStyle &rhs) const
  81. {
  82. return (m_fontFamily == rhs.m_fontFamily &&
  83. m_fontSize == rhs.m_fontSize &&
  84. m_isBold == rhs.m_isBold &&
  85. m_isItalic == rhs.m_isItalic &&
  86. m_isUnderline == rhs.m_isUnderline &&
  87. m_isStrikeThru == rhs.m_isStrikeThru &&
  88. m_foregroundColor == rhs.m_foregroundColor &&
  89. m_backgroundColor == rhs.m_backgroundColor &&
  90. m_isBackgroundOpaque == rhs.m_isBackgroundOpaque);
  91. }
  92. // public
  93. bool kpTextStyle::operator!= (const kpTextStyle &rhs) const
  94. {
  95. return !(*this == rhs);
  96. }
  97. // public
  98. TQString kpTextStyle::fontFamily () const
  99. {
  100. return m_fontFamily;
  101. }
  102. // public
  103. void kpTextStyle::setFontFamily (const TQString &f)
  104. {
  105. m_fontFamily = f;
  106. }
  107. // public
  108. int kpTextStyle::fontSize () const
  109. {
  110. return m_fontSize;
  111. }
  112. // public
  113. void kpTextStyle::setFontSize (int s)
  114. {
  115. m_fontSize = s;
  116. }
  117. // public
  118. bool kpTextStyle::isBold () const
  119. {
  120. return m_isBold;
  121. }
  122. // public
  123. void kpTextStyle::setBold (bool yes)
  124. {
  125. m_isBold = yes;
  126. }
  127. // public
  128. bool kpTextStyle::isItalic () const
  129. {
  130. return m_isItalic;
  131. }
  132. // public
  133. void kpTextStyle::setItalic (bool yes)
  134. {
  135. m_isItalic = yes;
  136. }
  137. // public
  138. bool kpTextStyle::isUnderline () const
  139. {
  140. return m_isUnderline;
  141. }
  142. // public
  143. void kpTextStyle::setUnderline (bool yes)
  144. {
  145. m_isUnderline = yes;
  146. }
  147. // public
  148. bool kpTextStyle::isStrikeThru () const
  149. {
  150. return m_isStrikeThru;
  151. }
  152. // public
  153. void kpTextStyle::setStrikeThru (bool yes)
  154. {
  155. m_isStrikeThru = yes;
  156. }
  157. // public
  158. kpColor kpTextStyle::foregroundColor () const
  159. {
  160. return m_foregroundColor;
  161. }
  162. // public
  163. void kpTextStyle::setForegroundColor (const kpColor &fcolor)
  164. {
  165. m_foregroundColor = fcolor;
  166. }
  167. // public
  168. kpColor kpTextStyle::backgroundColor () const
  169. {
  170. return m_backgroundColor;
  171. }
  172. // public
  173. void kpTextStyle::setBackgroundColor (const kpColor &bcolor)
  174. {
  175. m_backgroundColor = bcolor;
  176. }
  177. // public
  178. bool kpTextStyle::isBackgroundOpaque () const
  179. {
  180. return m_isBackgroundOpaque;
  181. }
  182. // public
  183. void kpTextStyle::setBackgroundOpaque (bool yes)
  184. {
  185. m_isBackgroundOpaque = yes;
  186. }
  187. // public
  188. bool kpTextStyle::isBackgroundTransparent () const
  189. {
  190. return !m_isBackgroundOpaque;
  191. }
  192. // public
  193. void kpTextStyle::setBackgroundTransparent (bool yes)
  194. {
  195. m_isBackgroundOpaque = !yes;
  196. }
  197. // public
  198. kpColor kpTextStyle::effectiveBackgroundColor () const
  199. {
  200. if (isBackgroundOpaque ())
  201. return backgroundColor ();
  202. else
  203. return kpColor::transparent;
  204. }
  205. // public
  206. TQFont kpTextStyle::font () const
  207. {
  208. TQFont fnt (m_fontFamily, m_fontSize);
  209. fnt.setBold (m_isBold);
  210. fnt.setItalic (m_isItalic);
  211. fnt.setUnderline (m_isUnderline);
  212. fnt.setStrikeOut (m_isStrikeThru);
  213. return fnt;
  214. }
  215. // public
  216. TQFontMetrics kpTextStyle::fontMetrics () const
  217. {
  218. return TQFontMetrics (font ());
  219. }