~ubuntu-branches/ubuntu/jaunty/quassel/jaunty

« back to all changes in this revision

Viewing changes to src/uisupport/uistyle.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2009-01-14 01:28:49 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090114012849-38celzez3y3wpai9
Tags: 0.4.0~git090113-0ubuntu1
* New upstream git snapshot
  - Use networks.ini to provide default network/channel
  - Provide presets for common IRC networks
* Add kubuntu_01_default_network_channel.patch to set Freenode, port
  8001, and #kubuntu as defaults
* Add build-dep on quilt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
 *   Copyright (C) 2005-08 by the Quassel Project                          *
 
2
 *   Copyright (C) 2005-09 by the Quassel Project                          *
3
3
 *   devel@quassel-irc.org                                                 *
4
4
 *                                                                         *
5
5
 *   This program is free software; you can redistribute it and/or modify  *
18
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
19
 ***************************************************************************/
20
20
 
21
 
#ifndef _UISTYLE_H_
22
 
#define _UISTYLE_H_
 
21
#ifndef UISTYLE_H
 
22
#define UISTYLE_H
23
23
 
24
24
#include <QDataStream>
25
25
#include <QFontMetricsF>
33
33
class UiStyle {
34
34
  Q_DECLARE_TR_FUNCTIONS(UiStyle)
35
35
 
36
 
  public:
37
 
    UiStyle(const QString &settingsKey);
38
 
    virtual ~UiStyle();
39
 
 
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
 
     */
49
 
    enum FormatType {
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
 
 
113
 
    };
114
 
 
115
 
    struct UrlInfo {
116
 
      int start, end;
117
 
      QUrl url;
118
 
    };
119
 
 
120
 
    struct StyledString {
121
 
      QString plainText;
122
 
      FormatList formatList;  // starting pos, ftypes
123
 
    };
124
 
 
125
 
    class StyledMessage;
126
 
 
127
 
    StyledString styleString(const QString &);
128
 
    StyledMessage styleMessage(const Message &);
129
 
    QString mircToInternal(const QString &) const;
130
 
 
131
 
    void setFormat(FormatType, QTextCharFormat, Settings::Mode mode/* = Settings::Custom*/);
132
 
    QTextCharFormat format(FormatType, Settings::Mode mode = Settings::Custom) const;
133
 
    QTextCharFormat mergedFormat(quint32 formatType);
134
 
    QFontMetricsF *fontMetrics(quint32 formatType);
135
 
 
136
 
    FormatType formatType(const QString &code) const;
137
 
    QString formatCode(FormatType) const;
138
 
 
139
 
    inline QFont defaultFont() const { return _defaultFont; }
140
 
 
141
 
    QList<QTextLayout::FormatRange> toTextLayoutList(const FormatList &, int textLength);
142
 
 
143
 
  protected:
144
 
 
145
 
 
146
 
  private:
147
 
 
148
 
    QFont _defaultFont;
149
 
    QTextCharFormat _defaultPlainFormat;
150
 
    QHash<FormatType, QTextCharFormat> _defaultFormats;
151
 
    QHash<FormatType, QTextCharFormat> _customFormats;
152
 
    QHash<quint32, QTextCharFormat> _cachedFormats;
153
 
    QHash<quint32, QFontMetricsF *> _cachedFontMetrics;
154
 
    QHash<QString, FormatType> _formatCodes;
155
 
 
156
 
    QString _settingsKey;
 
36
public:
 
37
  UiStyle(const QString &settingsKey);
 
38
  virtual ~UiStyle();
 
39
 
 
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
   */
 
49
  enum FormatType {
 
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
 
 
113
  };
 
114
 
 
115
  struct UrlInfo {
 
116
    int start, end;
 
117
    QUrl url;
 
118
  };
 
119
 
 
120
  struct StyledString {
 
121
    QString plainText;
 
122
    FormatList formatList;  // starting pos, ftypes
 
123
  };
 
124
 
 
125
  class StyledMessage;
 
126
 
 
127
  StyledString styleString(const QString &);
 
128
  QString mircToInternal(const QString &) const;
 
129
 
 
130
  void setFormat(FormatType, QTextCharFormat, Settings::Mode mode/* = Settings::Custom*/);
 
131
  QTextCharFormat format(FormatType, Settings::Mode mode = Settings::Custom) const;
 
132
  QTextCharFormat mergedFormat(quint32 formatType);
 
133
  QFontMetricsF *fontMetrics(quint32 formatType);
 
134
 
 
135
  FormatType formatType(const QString &code) const;
 
136
  QString formatCode(FormatType) const;
 
137
 
 
138
  inline QFont defaultFont() const { return _defaultFont; }
 
139
 
 
140
  QList<QTextLayout::FormatRange> toTextLayoutList(const FormatList &, int textLength);
 
141
 
 
142
protected:
 
143
private:
 
144
  QFont _defaultFont;
 
145
  QTextCharFormat _defaultPlainFormat;
 
146
  QHash<FormatType, QTextCharFormat> _defaultFormats;
 
147
  QHash<FormatType, QTextCharFormat> _customFormats;
 
148
  QHash<quint32, QTextCharFormat> _cachedFormats;
 
149
  QHash<quint32, QFontMetricsF *> _cachedFontMetrics;
 
150
  QHash<QString, FormatType> _formatCodes;
 
151
 
 
152
  QString _settingsKey;
157
153
};
158
154
 
159
 
class UiStyle::StyledMessage {
160
 
 
161
 
  public:
162
 
    explicit StyledMessage(const Message &, UiStyle *style);
163
 
 
164
 
    QDateTime timestamp() const;
165
 
    QString decoratedTimestamp() const;
166
 
    QString sender() const;             //!< Nickname (no decorations) for Plain and Notice, empty else
167
 
    QString decoratedSender() const;
168
 
    QString contents() const;
169
 
 
170
 
    FormatType timestampFormat() const;
171
 
    FormatType senderFormat() const;
172
 
    FormatList contentsFormatList() const;
173
 
 
174
 
    inline Message::Type type() const { return _msgType; }
175
 
 
176
 
  private:
177
 
    StyledString _contents;
178
 
    QDateTime _timestamp;
179
 
    QString _sender;
180
 
    Message::Type _msgType;
 
155
class UiStyle::StyledMessage : public Message {
 
156
public:
 
157
  explicit StyledMessage(const Message &message);
 
158
 
 
159
  //! Styling is only needed for calls to plainContents() and contentsFormatList()
 
160
  // StyledMessage can't style lazily by itself, as it doesn't know the used style
 
161
  bool inline needsStyling() const { return _contents.plainText.isNull(); }
 
162
  void style(UiStyle *style) const;
 
163
 
 
164
 
 
165
  QString decoratedTimestamp() const;
 
166
  QString plainSender() const;             //!< Nickname (no decorations) for Plain and Notice, empty else
 
167
  QString decoratedSender() const;
 
168
  inline const QString &plainContents() const { return _contents.plainText; }
 
169
 
 
170
  inline FormatType timestampFormat() const { return UiStyle::Timestamp; }
 
171
  FormatType senderFormat() const;
 
172
  inline const FormatList &contentsFormatList() const { return _contents.formatList; }
 
173
 
 
174
private:
 
175
  mutable StyledString _contents;
181
176
};
182
177
 
183
178
QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList);