~ubuntu-branches/ubuntu/raring/quassel/raring-proposed

« back to all changes in this revision

Viewing changes to src/uisupport/uistyle.h

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-08-27 16:13:38 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20080827161338-wwscdevtkwm9lq93
Tags: upstream-0.3.0
ImportĀ upstreamĀ versionĀ 0.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#ifndef _UISTYLE_H_
22
22
#define _UISTYLE_H_
23
23
 
 
24
#include <QDataStream>
 
25
#include <QFontMetricsF>
24
26
#include <QTextCharFormat>
25
27
#include <QTextLayout>
26
28
#include <QUrl>
29
31
#include "settings.h"
30
32
 
31
33
class UiStyle {
 
34
  Q_DECLARE_TR_FUNCTIONS (UiStyle);
32
35
 
33
36
  public:
34
37
    UiStyle(const QString &settingsKey);
35
38
    virtual ~UiStyle();
36
39
 
37
 
    /** This enumerates the possible formats a text element may have. */
 
40
    typedef QList<QPair<quint16, quint32> > FormatList;
 
41
 
 
42
    //! This enumerates the possible formats a text element may have. */
 
43
    /** These formats are ordered on increasing importance, in cases where a given property is specified
 
44
     *  by multiple active formats.
 
45
     *  \NOTE: Do not change/add values here without also adapting the relevant
 
46
     *         methods in this class (in particular mergedFormat())!
 
47
     *         Also, we _do_ rely on certain properties of these values in styleString() and friends!
 
48
     */
38
49
    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
 
50
      None            = 0x00000000,
 
51
      Invalid         = 0x11111111,
 
52
      // Message Formats (mutually exclusive!)
 
53
      PlainMsg        = 0x00000001,
 
54
      NoticeMsg       = 0x00000002,
 
55
      ServerMsg       = 0x00000003,
 
56
      ErrorMsg        = 0x00000004,
 
57
      JoinMsg         = 0x00000005,
 
58
      PartMsg         = 0x00000006,
 
59
      QuitMsg         = 0x00000007,
 
60
      KickMsg         = 0x00000008,
 
61
      RenameMsg       = 0x00000009,
 
62
      ModeMsg         = 0x0000000a,
 
63
      ActionMsg       = 0x0000000b,
 
64
      // Standard Formats
 
65
      Bold            = 0x00000010,
 
66
      Italic          = 0x00000020,
 
67
      Underline       = 0x00000040,
 
68
      Reverse         = 0x00000080,
 
69
      // Individual parts of a message
 
70
      Timestamp       = 0x00000100,
 
71
      Sender          = 0x00000200,
 
72
      Nick            = 0x00000400,
 
73
      Hostmask        = 0x00000800,
 
74
      ChannelName     = 0x00001000,
 
75
      ModeFlags       = 0x00002000,
 
76
      // URL is special, we want that to take precedence over the rest...
 
77
      Url             = 0x00100000,
 
78
      // Colors
 
79
      FgCol00         = 0x00400000,
 
80
      FgCol01         = 0x01400000,
 
81
      FgCol02         = 0x02400000,
 
82
      FgCol03         = 0x03400000,
 
83
      FgCol04         = 0x04400000,
 
84
      FgCol05         = 0x05400000,
 
85
      FgCol06         = 0x06400000,
 
86
      FgCol07         = 0x07400000,
 
87
      FgCol08         = 0x08400000,
 
88
      FgCol09         = 0x09400000,
 
89
      FgCol10         = 0x0a400000,
 
90
      FgCol11         = 0x0b400000,
 
91
      FgCol12         = 0x0c400000,
 
92
      FgCol13         = 0x0d400000,
 
93
      FgCol14         = 0x0e400000,
 
94
      FgCol15         = 0x0f400000,
 
95
 
 
96
      BgCol00         = 0x00800000,
 
97
      BgCol01         = 0x10800000,
 
98
      BgCol02         = 0x20800000,
 
99
      BgCol03         = 0x30800000,
 
100
      BgCol04         = 0x40800000,
 
101
      BgCol05         = 0x50800000,
 
102
      BgCol06         = 0x60800000,
 
103
      BgCol07         = 0x70800000,
 
104
      BgCol08         = 0x80800000,
 
105
      BgCol09         = 0x90800000,
 
106
      BgCol10         = 0xa0800000,
 
107
      BgCol11         = 0xb0800000,
 
108
      BgCol12         = 0xc0800000,
 
109
      BgCol13         = 0xd0800000,
 
110
      BgCol14         = 0xe0800000,
 
111
      BgCol15         = 0xf0800000
 
112
 
48
113
    };
49
114
 
50
115
    struct UrlInfo {
52
117
      QUrl url;
53
118
    };
54
119
 
55
 
    struct StyledText {
56
 
      QString text;
57
 
      QList<QTextLayout::FormatRange> formats;
58
 
      QList<UrlInfo> urls;
59
 
    };
60
 
 
61
 
    StyledText styleString(const QString &);
 
120
    struct StyledString {
 
121
      QString plainText;
 
122
      FormatList formatList;  // starting pos, ftypes
 
123
    };
 
124
 
 
125
    struct StyledMessage {
 
126
      StyledString timestamp;
 
127
      StyledString sender;
 
128
      StyledString contents;
 
129
    };
 
130
 
 
131
    StyledString styleString(const QString &);
 
132
    StyledMessage styleMessage(const Message &);
 
133
    QString mircToInternal(const QString &) const;
62
134
 
63
135
    void setFormat(FormatType, QTextCharFormat, Settings::Mode mode/* = Settings::Custom*/);
64
136
    QTextCharFormat format(FormatType, Settings::Mode mode = Settings::Custom) const;
 
137
    QTextCharFormat mergedFormat(quint32 formatType);
 
138
    QFontMetricsF *fontMetrics(quint32 formatType);
65
139
 
66
140
    FormatType formatType(const QString &code) const;
67
141
    QString formatCode(FormatType) const;
68
142
 
 
143
    inline QFont defaultFont() const { return _defaultFont; }
 
144
 
 
145
    QList<QTextLayout::FormatRange> toTextLayoutList(const FormatList &, int textLength);
 
146
 
69
147
  protected:
70
148
 
71
149
 
72
150
  private:
73
 
    QTextCharFormat mergedFormat(QList<FormatType>);
74
151
 
75
 
    QVector<QTextCharFormat> _defaultFormats;
76
 
    QVector<QTextCharFormat> _customFormats;
 
152
    QFont _defaultFont;
 
153
    QTextCharFormat _defaultPlainFormat;
 
154
    QHash<FormatType, QTextCharFormat> _defaultFormats;
 
155
    QHash<FormatType, QTextCharFormat> _customFormats;
 
156
    QHash<quint32, QTextCharFormat> _cachedFormats;
 
157
    QHash<quint32, QFontMetricsF *> _cachedFontMetrics;
77
158
    QHash<QString, FormatType> _formatCodes;
78
159
 
79
160
    QString _settingsKey;
80
 
 
81
161
};
82
162
 
 
163
QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList);
 
164
QDataStream &operator>>(QDataStream &in, UiStyle::FormatList &formatList);
 
165
 
 
166
Q_DECLARE_METATYPE(UiStyle::FormatList);
 
167
 
83
168
#endif