summaryrefslogtreecommitdiffstats
path: root/kate/part/kateattribute.h
blob: a54279b24b6f23f55661a3d408d8d7e1317d1b7f (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
/* This file is part of the KDE libraries
   Copyright (C) 2003 Hamish Rodda <rodda@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef __KATE_ATTRIBUTE_H__
#define __KATE_ATTRIBUTE_H__

#include "katefont.h"

#include <tqcolor.h>

/**
 * The Attribute class incorporates all text decorations supported by Kate.
 *
 * TODO: store the actual font as well.
 * TODO: update changed mechanism - use separate bitfield
 */
class KateAttribute
{
public:
  enum items {
    Weight = 0x1,
    Bold = 0x2,
    Italic = 0x4,
    Underline = 0x8,
    StrikeOut = 0x10,
    Outline = 0x20,
    TextColor = 0x40,
    SelectedTextColor = 0x80,
    BGColor = 0x100,
    SelectedBGColor = 0x200,
    Overline = 0x400
  };

  KateAttribute();
  virtual ~KateAttribute();

  TQFont font(const TQFont& ref);

  inline int width(KateFontStruct& fs, const TQString& text, int col, int tabWidth) const
  { return fs.width(text, col, bold(), italic(), tabWidth); };

  // Non-preferred function when you have a string and you want one char's width!!
  inline int width(KateFontStruct& fs, const TQChar& c, int tabWidth) const
  { return fs.width(c, bold(), italic(), tabWidth); };

  inline bool itemSet(int item) const
  { return item & m_itemsSet; };

  inline bool isSomethingSet() const
  { return m_itemsSet; };

  inline int itemsSet() const
  { return m_itemsSet; };

  inline void clearAttribute(int item)
  { m_itemsSet &= (~item); }

  inline int weight() const
  { return m_weight; };

  void setWeight(int weight);

  inline bool bold() const
  { return weight() >= TQFont::Bold; };
  
  void setBold(bool enable = true);

  inline bool italic() const
  { return m_italic; };
  
  void setItalic(bool enable = true);

  inline bool overline() const
  { return m_overline; };
  
  void setOverline(bool enable = true);

  inline bool underline() const
  { return m_underline; };
  
  void setUnderline(bool enable = true);

  inline bool strikeOut() const
  { return m_strikeout; };

  void setStrikeOut(bool enable = true);

  inline const TQColor& outline() const
  { return m_outline; };
  
  void setOutline(const TQColor& color);

  inline const TQColor& textColor() const
  { return m_textColor; };
  
  void setTextColor(const TQColor& color);

  inline const TQColor& selectedTextColor() const
  { return m_selectedTextColor; };

  void setSelectedTextColor(const TQColor& color);

  inline const TQColor& bgColor() const
  { return m_bgColor; };
  
  void setBGColor(const TQColor& color);

  inline const TQColor& selectedBGColor() const
  { return m_selectedBGColor; };
  
  void setSelectedBGColor(const TQColor& color);

  KateAttribute& operator+=(const KateAttribute& a);

  friend bool operator ==(const KateAttribute& h1, const KateAttribute& h2);
  friend bool operator !=(const KateAttribute& h1, const KateAttribute& h2);

  virtual void changed() { m_changed = true; };
  bool isChanged() { bool ret = m_changed; m_changed = false; return ret; };

  void clear();

private:
  int m_weight;
  bool m_italic, m_underline, m_overline,m_strikeout, m_changed;
  TQColor m_outline, m_textColor, m_selectedTextColor, m_bgColor, m_selectedBGColor;
  int m_itemsSet;
};

#endif

// kate: space-indent on; indent-width 2; replace-tabs on;