X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fuistyle.h;h=3bb1a45bf0feec7a45b6155caee44aca25f962a2;hp=59841dc776cd004d3790ff86dfa5c5f48939d807;hb=f824db0e31b54969e0b7fa0b5405b1e9173d482c;hpb=e017aca90eb3444df68fb365a5d50b05881b1c5c diff --git a/src/uisupport/uistyle.h b/src/uisupport/uistyle.h index 59841dc7..3bb1a45b 100644 --- a/src/uisupport/uistyle.h +++ b/src/uisupport/uistyle.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -21,10 +21,8 @@ #ifndef _UISTYLE_H_ #define _UISTYLE_H_ -#ifndef SPUTDEV -# include "old-uistyle.h" -#else - +#include +#include #include #include #include @@ -33,11 +31,14 @@ #include "settings.h" class UiStyle { + Q_DECLARE_TR_FUNCTIONS(UiStyle) public: UiStyle(const QString &settingsKey); virtual ~UiStyle(); + typedef QList > FormatList; + //! This enumerates the possible formats a text element may have. */ /** These formats are ordered on increasing importance, in cases where a given property is specified * by multiple active formats. @@ -117,31 +118,71 @@ class UiStyle { }; struct StyledString { - QString text; - QList > formats; // starting pos, ftypes + QString plainText; + FormatList formatList; // starting pos, ftypes }; + class StyledMessage; + StyledString styleString(const QString &); + StyledMessage styleMessage(const Message &); + QString mircToInternal(const QString &) const; void setFormat(FormatType, QTextCharFormat, Settings::Mode mode/* = Settings::Custom*/); QTextCharFormat format(FormatType, Settings::Mode mode = Settings::Custom) const; QTextCharFormat mergedFormat(quint32 formatType); + QFontMetricsF *fontMetrics(quint32 formatType); FormatType formatType(const QString &code) const; QString formatCode(FormatType) const; + inline QFont defaultFont() const { return _defaultFont; } + + QList toTextLayoutList(const FormatList &, int textLength); + protected: private: + + QFont _defaultFont; QTextCharFormat _defaultPlainFormat; QHash _defaultFormats; QHash _customFormats; QHash _cachedFormats; + QHash _cachedFontMetrics; QHash _formatCodes; QString _settingsKey; }; -#endif // SPUTDEV +class UiStyle::StyledMessage { + + public: + explicit StyledMessage(const Message &, UiStyle *style); + + QDateTime timestamp() const; + QString decoratedTimestamp() const; + QString sender() const; //!< Nickname (no decorations) for Plain and Notice, empty else + QString decoratedSender() const; + QString contents() const; + + FormatType timestampFormat() const; + FormatType senderFormat() const; + FormatList contentsFormatList() const; + + inline Message::Type type() const { return _msgType; } + + private: + StyledString _contents; + QDateTime _timestamp; + QString _sender; + Message::Type _msgType; +}; + +QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList); +QDataStream &operator>>(QDataStream &in, UiStyle::FormatList &formatList); + +Q_DECLARE_METATYPE(UiStyle::FormatList) + #endif