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