* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
-#ifndef UISTYLE_H
-#define UISTYLE_H
+#ifndef UISTYLE_H_
+#define UISTYLE_H_
#include <QDataStream>
#include <QFontMetricsF>
RenameMsg = 0x00000009,
ModeMsg = 0x0000000a,
ActionMsg = 0x0000000b,
- HighlightMsg = 0x0000000f,
-
- // Note: mergedFormat() assumes that 0x10 - 0x80 are *only* used within the message contents,
- // e.g. not together with any of 0x0100-0x2000!
- // If we happen to find a use case for that, we can see if/how to implement that though.
// Standard Formats
Bold = 0x00000010,
ModeFlags = 0x00002000,
// URL is special, we want that to take precedence over the rest...
- Url = 0x00100000,
+ Url = 0x00080000,
// mIRC Colors - we assume those to be present only in plain contents
FgCol00 = 0x00400000,
SenderColSelf = 0xff000200
};
+ enum MessageLabel {
+ Highlight = 0x00000001
+ };
+
struct StyledString {
QString plainText;
FormatList formatList; // starting pos, ftypes
StyledString styleString(const QString &);
QString mircToInternal(const QString &) const;
- void setFormat(FormatType, QTextCharFormat, Settings::Mode mode/* = Settings::Custom*/);
- void setSenderAutoColor(bool state);
- QTextCharFormat format(FormatType, Settings::Mode mode = Settings::Custom) const;
- QTextCharFormat mergedFormat(quint32 formatType);
- QFontMetricsF *fontMetrics(quint32 formatType);
+ void setFormat(FormatType, QTextCharFormat, Settings::Mode mode/* = Settings::Custom*/); // FIXME go away
+ void setSenderAutoColor(bool state); // FIXME go away
+ QTextCharFormat format(FormatType, Settings::Mode mode = Settings::Custom) const; // FIXME go away
+
+ QTextCharFormat cachedFormat(quint64 key) const;
+ QTextCharFormat cachedFormat(quint32 formatType, quint32 messageLabel = 0) const;
+ void setCachedFormat(const QTextCharFormat &format, quint32 formatType, quint32 messageLabel = 0);
+
+ QTextCharFormat mergedFormat(quint32 formatType, quint32 messageLabel = 0);
+ QFontMetricsF *fontMetrics(quint32 formatType, quint32 messageLabel = 0);
FormatType formatType(const QString &code) const;
QString formatCode(FormatType) const;
protected:
void loadStyleSheet();
+ //! Determines the format set to be used for the given hostmask
+ //int formatSetIndex(const QString &hostmask) const;
+ //int formatSetIndexForSelf() const;
+
+ void mergeSubElementFormat(QTextCharFormat &format, quint32 formatType, quint32 messageLabel = 0);
+
bool _senderAutoColor;
private:
QTextCharFormat _defaultPlainFormat;
QHash<FormatType, QTextCharFormat> _defaultFormats;
QHash<FormatType, QTextCharFormat> _customFormats;
- QHash<quint32, QTextCharFormat> _cachedFormats;
- QHash<quint32, QFontMetricsF *> _cachedFontMetrics;
+ QHash<quint64, QTextCharFormat> _formatCache;
+ QHash<quint64, QFontMetricsF *> _metricsCache;
QHash<QString, FormatType> _formatCodes;
QString _settingsKey;
mutable StyledString _contents;
};
-class UiStyle::QssParser {
-public:
- enum Column {
- Any,
- Timestamp,
- Sender,
- Contents
- };
-
- struct ChatLineFormat {
- QVector<QTextCharFormat> senderColors;
- QVector<QTextCharFormat> mircColors;
- QHash<FormatType, QTextCharFormat> formats;
-
- };
-
- QssParser();
-
- void loadStyleSheet(const QString &sheet);
-
- inline QPalette palette() const { return _palette; }
- ChatLineFormat basicFormat() const;
- QHash<FormatType, ChatLineFormat> specialFormats() const;
-
-protected:
- typedef QList<qreal> ColorTuple;
-
- void parseChatLineData(const QString &decl, const QString &contents);
- void parsePaletteData(const QString &decl, const QString &contents);
-
- QTextCharFormat parseFormat(const QString &qss);
- bool parsePalette(QPalette &, const QString &qss);
-
- // Parse basic data types
- QBrush parseBrushValue(const QString &str);
- QColor parseColorValue(const QString &str);
- QFont parseFont(const QString &str);
-
- // Parse subelements
- ColorTuple parseColorTuple(const QString &str);
- QGradientStops parseGradientStops(const QString &str);
-
- QHash<QString, QPalette::ColorRole> _paletteColorRoles;
-
-private:
- QPalette _palette;
- ChatLineFormat _basicFormat;
- QHash<FormatType, ChatLineFormat> _specialFormats;
-};
-
QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList);
QDataStream &operator>>(QDataStream &in, UiStyle::FormatList &formatList);