summaryrefslogtreecommitdiffstats
path: root/kolourpaint/kptextstyle.cpp
blob: 61f58dab9b539d515e51cc8c8bd7f4d85be33069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279

/*
   Copyright (c) 2003,2004,2005 Clarence Dang <[email protected]>
   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

   1. Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.

   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#include <kptextstyle.h>

#include <tqdatastream.h>
#include <tqfont.h>
#include <tqfontmetrics.h>


kpTextStyle::kpTextStyle ()
    : m_fontSize (0),
      m_isBold (false), m_isItalic (false),
      m_isUnderline (false), m_isStrikeThru (false),
      m_isBackgroundOpaque (true)
{
}

kpTextStyle::kpTextStyle (const TQString &fontFamily,
                          int fontSize,
                          bool isBold, bool isItalic,
                          bool isUnderline, bool isStrikeThru,
                          const kpColor &fcolor, const kpColor &bcolor,
                          bool isBackgroundOpaque)
    : m_fontFamily (fontFamily),
      m_fontSize (fontSize),
      m_isBold (isBold), m_isItalic (isItalic),
      m_isUnderline (isUnderline), m_isStrikeThru (isStrikeThru),
      m_foregroundColor (fcolor), m_backgroundColor (bcolor),
      m_isBackgroundOpaque (isBackgroundOpaque)
{
}

kpTextStyle::~kpTextStyle ()
{
}


// friend
TQDataStream &operator<< (TQDataStream &stream, const kpTextStyle &textStyle)
{
    stream << textStyle.m_fontFamily;
    stream << textStyle.m_fontSize;

    stream << int (textStyle.m_isBold) << int (textStyle.m_isItalic)
           << int (textStyle.m_isUnderline) << int (textStyle.m_isStrikeThru);

    stream << textStyle.m_foregroundColor << textStyle.m_backgroundColor;

    stream << int (textStyle.m_isBackgroundOpaque);

    return stream;
}

// friend
TQDataStream &operator>> (TQDataStream &stream, kpTextStyle &textStyle)
{
    stream >> textStyle.m_fontFamily;
    stream >> textStyle.m_fontSize;

    int a, b, c, d;
    stream >> a >> b >> c >> d;
    textStyle.m_isBold = a;
    textStyle.m_isItalic = b;
    textStyle.m_isUnderline = c;
    textStyle.m_isStrikeThru = d;

    stream >> textStyle.m_foregroundColor >> textStyle.m_backgroundColor;

    int e;
    stream >> e;
    textStyle.m_isBackgroundOpaque = e;

    return stream;
}

// public
bool kpTextStyle::operator== (const kpTextStyle &rhs) const
{
    return (m_fontFamily == rhs.m_fontFamily &&
            m_fontSize == rhs.m_fontSize &&
            m_isBold == rhs.m_isBold &&
            m_isItalic == rhs.m_isItalic &&
            m_isUnderline == rhs.m_isUnderline &&
            m_isStrikeThru == rhs.m_isStrikeThru &&
            m_foregroundColor == rhs.m_foregroundColor &&
            m_backgroundColor == rhs.m_backgroundColor &&
            m_isBackgroundOpaque == rhs.m_isBackgroundOpaque);
}

// public
bool kpTextStyle::operator!= (const kpTextStyle &rhs) const
{
    return !(*this == rhs);
}


// public
TQString kpTextStyle::fontFamily () const
{
    return m_fontFamily;
}

// public
void kpTextStyle::setFontFamily (const TQString &f)
{
    m_fontFamily = f;
}


// public
int kpTextStyle::fontSize () const
{
    return m_fontSize;
}

// public
void kpTextStyle::setFontSize (int s)
{
    m_fontSize = s;
}


// public
bool kpTextStyle::isBold () const
{
    return m_isBold;
}

// public
void kpTextStyle::setBold (bool yes)
{
    m_isBold = yes;
}


// public
bool kpTextStyle::isItalic () const
{
    return m_isItalic;
}

// public
void kpTextStyle::setItalic (bool yes)
{
    m_isItalic = yes;
}


// public
bool kpTextStyle::isUnderline () const
{
    return m_isUnderline;
}

// public
void kpTextStyle::setUnderline (bool yes)
{
    m_isUnderline = yes;
}


// public
bool kpTextStyle::isStrikeThru () const
{
    return m_isStrikeThru;
}

// public
void kpTextStyle::setStrikeThru (bool yes)
{
    m_isStrikeThru = yes;
}


// public
kpColor kpTextStyle::foregroundColor () const
{
    return m_foregroundColor;
}

// public
void kpTextStyle::setForegroundColor (const kpColor &fcolor)
{
    m_foregroundColor = fcolor;
}


// public
kpColor kpTextStyle::backgroundColor () const
{
    return m_backgroundColor;
}

// public
void kpTextStyle::setBackgroundColor (const kpColor &bcolor)
{
    m_backgroundColor = bcolor;
}


// public
bool kpTextStyle::isBackgroundOpaque () const
{
    return m_isBackgroundOpaque;
}

// public
void kpTextStyle::setBackgroundOpaque (bool yes)
{
    m_isBackgroundOpaque = yes;
}


// public
bool kpTextStyle::isBackgroundTransparent () const
{
    return !m_isBackgroundOpaque;
}

// public
void kpTextStyle::setBackgroundTransparent (bool yes)
{
    m_isBackgroundOpaque = !yes;
}


// public
kpColor kpTextStyle::effectiveBackgroundColor () const
{
    if (isBackgroundOpaque ())
        return backgroundColor ();
    else
        return kpColor::transparent;
}


// public
TQFont kpTextStyle::font () const
{
    TQFont fnt (m_fontFamily, m_fontSize);
    fnt.setBold (m_isBold);
    fnt.setItalic (m_isItalic);
    fnt.setUnderline (m_isUnderline);
    fnt.setStrikeOut (m_isStrikeThru);

    return fnt;
}

// public
TQFontMetrics kpTextStyle::fontMetrics () const
{
    return TQFontMetrics (font ());
}