Removing SPUTDEV, obsolete code and #ifdefs from sources
[quassel.git] / src / uisupport / uistyle.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _UISTYLE_H_
22 #define _UISTYLE_H_
23
24 #include <QDataStream>
25 #include <QTextCharFormat>
26 #include <QTextLayout>
27 #include <QUrl>
28
29 #include "message.h"
30 #include "settings.h"
31
32 class UiStyle {
33   Q_DECLARE_TR_FUNCTIONS (UiStyle);
34
35   public:
36     UiStyle(const QString &settingsKey);
37     virtual ~UiStyle();
38
39     typedef QList<QPair<int, quint32> > FormatList;
40
41     //! This enumerates the possible formats a text element may have. */
42     /** These formats are ordered on increasing importance, in cases where a given property is specified
43      *  by multiple active formats.
44      *  \NOTE: Do not change/add values here without also adapting the relevant
45      *         methods in this class (in particular mergedFormat())!
46      *         Also, we _do_ rely on certain properties of these values in styleString() and friends!
47      */
48     enum FormatType {
49       None            = 0x00000000,
50       Invalid         = 0x11111111,
51       // Message Formats (mutually exclusive!)
52       PlainMsg        = 0x00000001,
53       NoticeMsg       = 0x00000002,
54       ServerMsg       = 0x00000003,
55       ErrorMsg        = 0x00000004,
56       JoinMsg         = 0x00000005,
57       PartMsg         = 0x00000006,
58       QuitMsg         = 0x00000007,
59       KickMsg         = 0x00000008,
60       RenameMsg       = 0x00000009,
61       ModeMsg         = 0x0000000a,
62       ActionMsg       = 0x0000000b,
63       // Standard Formats
64       Bold            = 0x00000010,
65       Italic          = 0x00000020,
66       Underline       = 0x00000040,
67       Reverse         = 0x00000080,
68       // Individual parts of a message
69       Timestamp       = 0x00000100,
70       Sender          = 0x00000200,
71       Nick            = 0x00000400,
72       Hostmask        = 0x00000800,
73       ChannelName     = 0x00001000,
74       ModeFlags       = 0x00002000,
75       // URL is special, we want that to take precedence over the rest...
76       Url             = 0x00100000,
77       // Colors
78       FgCol00         = 0x00400000,
79       FgCol01         = 0x01400000,
80       FgCol02         = 0x02400000,
81       FgCol03         = 0x03400000,
82       FgCol04         = 0x04400000,
83       FgCol05         = 0x05400000,
84       FgCol06         = 0x06400000,
85       FgCol07         = 0x07400000,
86       FgCol08         = 0x08400000,
87       FgCol09         = 0x09400000,
88       FgCol10         = 0x0a400000,
89       FgCol11         = 0x0b400000,
90       FgCol12         = 0x0c400000,
91       FgCol13         = 0x0d400000,
92       FgCol14         = 0x0e400000,
93       FgCol15         = 0x0f400000,
94
95       BgCol00         = 0x00800000,
96       BgCol01         = 0x10800000,
97       BgCol02         = 0x20800000,
98       BgCol03         = 0x30800000,
99       BgCol04         = 0x40800000,
100       BgCol05         = 0x50800000,
101       BgCol06         = 0x60800000,
102       BgCol07         = 0x70800000,
103       BgCol08         = 0x80800000,
104       BgCol09         = 0x90800000,
105       BgCol10         = 0xa0800000,
106       BgCol11         = 0xb0800000,
107       BgCol12         = 0xc0800000,
108       BgCol13         = 0xd0800000,
109       BgCol14         = 0xe0800000,
110       BgCol15         = 0xf0800000
111
112     };
113
114     struct UrlInfo {
115       int start, end;
116       QUrl url;
117     };
118
119     struct StyledString {
120       QString plainText;
121       FormatList formatList;  // starting pos, ftypes
122     };
123
124     struct StyledMessage {
125       StyledString timestamp;
126       StyledString sender;
127       StyledString contents;
128     };
129
130     StyledString styleString(const QString &);
131     StyledMessage styleMessage(const Message &);
132
133     void setFormat(FormatType, QTextCharFormat, Settings::Mode mode/* = Settings::Custom*/);
134     QTextCharFormat format(FormatType, Settings::Mode mode = Settings::Custom) const;
135     QTextCharFormat mergedFormat(quint32 formatType);
136
137     FormatType formatType(const QString &code) const;
138     QString formatCode(FormatType) const;
139
140   protected:
141
142
143   private:
144     QString mircToInternal(const QString &);
145
146     QTextCharFormat _defaultPlainFormat;
147     QHash<FormatType, QTextCharFormat> _defaultFormats;
148     QHash<FormatType, QTextCharFormat> _customFormats;
149     QHash<quint32, QTextCharFormat> _cachedFormats;
150     QHash<QString, FormatType> _formatCodes;
151
152     QString _settingsKey;
153 };
154
155 QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList);
156 QDataStream &operator>>(QDataStream &in, UiStyle::FormatList &formatList);
157
158 Q_DECLARE_METATYPE(UiStyle::FormatList);
159
160 #endif