#include "uisettings.h"
#include "util.h"
+QHash<QString, UiStyle::FormatType> UiStyle::_formatCodes;
+
UiStyle::UiStyle() {
// register FormatList if that hasn't happened yet
// FIXME I don't think this actually avoids double registration... then again... does it hurt?
return (_metricsCache[key] = new QFontMetricsF(format(ftype, label).font()));
}
-UiStyle::FormatType UiStyle::formatType(Message::Type msgType) const {
+UiStyle::FormatType UiStyle::formatType(Message::Type msgType) {
switch(msgType) {
case Message::Plain:
return PlainMsg;
return ErrorMsg;
}
-UiStyle::FormatType UiStyle::formatType(const QString & code) const {
+UiStyle::FormatType UiStyle::formatType(const QString & code) {
if(_formatCodes.contains(code)) return _formatCodes.value(code);
return Invalid;
}
-QString UiStyle::formatCode(FormatType ftype) const {
+QString UiStyle::formatCode(FormatType ftype) {
return _formatCodes.key(ftype);
}
return result;
}
-QString UiStyle::mircToInternal(const QString &mirc_) const {
+QString UiStyle::mircToInternal(const QString &mirc_) {
QString mirc = mirc_;
mirc.replace('%', "%%"); // escape % just to be sure
mirc.replace('\x02', "%B");
{
}
-void UiStyle::StyledMessage::style(UiStyle *style) const {
+void UiStyle::StyledMessage::style() const {
QString user = userFromMask(sender());
QString host = hostFromMask(sender());
QString nick = nickFromMask(sender());
- QString txt = style->mircToInternal(contents());
+ QString txt = UiStyle::mircToInternal(contents());
QString bufferName = bufferInfo().bufferName();
bufferName.replace('%', "%%"); // well, you _can_ have a % in a buffername apparently... -_-
default:
t = tr("[%1]").arg(txt);
}
- _contents = style->styleString(t, style->formatType(type()));
+ _contents = UiStyle::styleString(t, UiStyle::formatType(type()));
+}
+
+const QString &UiStyle::StyledMessage::plainContents() const {
+ if(_contents.plainText.isNull())
+ style();
+
+ return _contents.plainText;
+}
+
+const UiStyle::FormatList &UiStyle::StyledMessage::contentsFormatList() const {
+ if(_contents.plainText.isNull())
+ style();
+
+ return _contents.formatList;
}
QString UiStyle::StyledMessage::decoratedTimestamp() const {
class StyledMessage;
- StyledString styleString(const QString &string, quint32 baseFormat = None);
- QString mircToInternal(const QString &) const;
-
- FormatType formatType(Message::Type msgType) const;
+ static FormatType formatType(Message::Type msgType);
+ static StyledString styleString(const QString &string, quint32 baseFormat = None);
+ static QString mircToInternal(const QString &);
QTextCharFormat format(quint32 formatType, quint32 messageLabel = 0);
QFontMetricsF *fontMetrics(quint32 formatType, quint32 messageLabel = 0);
void setCachedFormat(const QTextCharFormat &format, quint32 formatType, quint32 messageLabel = 0);
void mergeSubElementFormat(QTextCharFormat &format, quint32 formatType, quint32 messageLabel = 0);
- FormatType formatType(const QString &code) const;
- QString formatCode(FormatType) const;
+ static FormatType formatType(const QString &code);
+ static QString formatCode(FormatType);
private:
QFont _defaultFont;
QHash<quint64, QTextCharFormat> _formatCache;
QHash<quint64, QFontMetricsF *> _metricsCache;
- QHash<QString, FormatType> _formatCodes;
+ static QHash<QString, FormatType> _formatCodes;
};
class UiStyle::StyledMessage : public Message {
public:
explicit StyledMessage(const Message &message);
- //! Styling is only needed for calls to plainContents() and contentsFormatList()
- // StyledMessage can't style lazily by itself, as it doesn't know the used style
- bool inline needsStyling() const { return _contents.plainText.isNull(); }
- void style(UiStyle *style) const;
-
-
QString decoratedTimestamp() const;
QString plainSender() const; //!< Nickname (no decorations) for Plain and Notice, empty else
QString decoratedSender() const;
- inline const QString &plainContents() const { return _contents.plainText; }
+ const QString &plainContents() const;
inline FormatType timestampFormat() const { return UiStyle::Timestamp; }
FormatType senderFormat() const;
- inline const FormatList &contentsFormatList() const { return _contents.formatList; }
+ const FormatList &contentsFormatList() const;
+protected:
+ //! Styling is only needed for calls to plainContents() and contentsFormatList()
+ void style() const;
+
private:
mutable StyledString _contents;