Making Quassel slowly ready for its first release...
[quassel.git] / src / uisupport / uistyle.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
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 <QTextCharFormat>
25 #include <QTextLayout>
26 #include <QUrl>
27
28 #include "message.h"
29
30 class UiStyle {
31
32   public:
33     UiStyle();
34     virtual ~UiStyle();
35
36     /** This enumerates the possible formats a text element may have. */
37     enum FormatType {
38       None, Bold, Italic, Underline, Reverse,                                        // Standard formats
39       PlainMsg, NoticeMsg, ServerMsg, ErrorMsg, JoinMsg, PartMsg, QuitMsg, KickMsg,  // Internal message formats
40       RenameMsg, ModeMsg, ActionMsg,                                                 // ...cnt'd
41       Timestamp, Sender, Nick, Hostmask, ChannelName, ModeFlags, Url,                // individual elements
42       FgCol00, FgCol01, FgCol02, FgCol03, FgCol04, FgCol05, FgCol06, FgCol07,        // Color codes
43       FgCol08, FgCol09, FgCol10, FgCol11, FgCol12, FgCol13, FgCol14, FgCol15,
44       BgCol00, BgCol01, BgCol02, BgCol03, BgCol04, BgCol05, BgCol06, BgCol07,
45       BgCol08, BgCol09, BgCol10, BgCol11, BgCol12, BgCol13, BgCol14, BgCol15,
46       NumFormatTypes, Invalid   // Do not add anything after this
47     };
48
49     struct UrlInfo {
50       int start, end;
51       QUrl url;
52     };
53
54     struct StyledText {
55       QString text;
56       QList<QTextLayout::FormatRange> formats;
57       QList<UrlInfo> urls;
58     };
59
60     StyledText styleString(QString);
61
62     void setFormat(FormatType, QTextCharFormat);
63     QTextCharFormat format(FormatType) const;
64
65     FormatType formatType(const QString &code) const;
66     QString formatCode(FormatType) const;
67
68   protected:
69
70
71   private:
72     QTextCharFormat mergedFormat(QList<FormatType>);
73
74     QVector<QTextCharFormat> _formats;
75     QHash<QString, FormatType> _formatCodes;
76
77 };
78
79 #endif