X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fuistyle.cpp;h=5f46331f735b06ed128f92b411296238716b483e;hp=8c3afaab4dc470a0d37a3882668c27e0db272a48;hb=ff6a8ed14fad421991b7c9998582b9f5df6912dc;hpb=068a9f975337b4d0b08a438a2abd10ddf94e259d diff --git a/src/uisupport/uistyle.cpp b/src/uisupport/uistyle.cpp index 8c3afaab..5f46331f 100644 --- a/src/uisupport/uistyle.cpp +++ b/src/uisupport/uistyle.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by the Quassel IRC Team * + * Copyright (C) 2005-08 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * (at your option) version 3. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -19,14 +19,21 @@ ***************************************************************************/ #include "uistyle.h" +#include "uistylesettings.h" -UiStyle::UiStyle() { +UiStyle::UiStyle(const QString &settingsKey) : _settingsKey(settingsKey) { // Default format QTextCharFormat def; def.setForeground(QBrush("#000000")); - def.setFont(QFont("Verdana",9)); - - _formats = QVector(NumFormatTypes, def); + def.setFont(QFont("Mono",12)); + _defaultFormats = QVector(NumFormatTypes, def); + _customFormats = QVector(NumFormatTypes, QTextFormat().toCharFormat()); + + // Load saved custom formats + UiStyleSettings s(_settingsKey); + foreach(FormatType type, s.availableFormats()) { + _customFormats[type] = s.customFormat(type); + } // Initialize color codes according to mIRC "standard" QStringList colors; @@ -68,19 +75,19 @@ UiStyle::UiStyle() { _formatCodes[QString("%Dcf%1").arg(idx)] = (FormatType)(FgCol00 + i); _formatCodes[QString("%Dcb%1").arg(idx)] = (FormatType)(BgCol00 + i); QTextCharFormat fgf, bgf; - fgf.setForeground(QBrush(QColor(colors[i]))); _formats[FgCol00 + i] = fgf; - bgf.setBackground(QBrush(QColor(colors[i]))); _formats[BgCol00 + i] = bgf; + fgf.setForeground(QBrush(QColor(colors[i]))); setFormat((FormatType)(FgCol00 + i), fgf, Settings::Default); + bgf.setBackground(QBrush(QColor(colors[i]))); setFormat((FormatType)(BgCol00 + i), bgf, Settings::Default); } // Set a few more standard formats QTextCharFormat bold; bold.setFontWeight(QFont::Bold); - setFormat(Bold, bold); + setFormat(Bold, bold, Settings::Default); QTextCharFormat italic; italic.setFontItalic(true); - setFormat(Italic, italic); + setFormat(Italic, italic, Settings::Default); QTextCharFormat underline; underline.setFontUnderline(true); - setFormat(Underline, underline); + setFormat(Underline, underline, Settings::Default); // All other formats should be defined in derived classes. } @@ -89,12 +96,24 @@ UiStyle::~ UiStyle() { } -void UiStyle::setFormat(FormatType ftype, QTextCharFormat fmt) { - _formats[ftype] = fmt; +void UiStyle::setFormat(FormatType ftype, QTextCharFormat fmt, Settings::Mode mode) { + if(mode == Settings::Default) { + _defaultFormats[ftype] = fmt; + } else { + UiStyleSettings s(_settingsKey); + if(fmt != _defaultFormats[ftype]) { + _customFormats[ftype] = fmt; + s.setCustomFormat(ftype, fmt); + } else { + _customFormats[ftype] = QTextFormat().toCharFormat(); + s.removeCustomFormat(ftype); + } + } } -QTextCharFormat UiStyle::format(FormatType ftype) const { - return _formats[ftype]; +QTextCharFormat UiStyle::format(FormatType ftype, Settings::Mode mode) const { + if(mode == Settings::Custom && _customFormats[ftype].isValid()) return _customFormats[ftype]; + else return _defaultFormats[ftype]; } UiStyle::FormatType UiStyle::formatType(const QString & code) const { @@ -112,6 +131,7 @@ UiStyle::StyledText UiStyle::styleString(QString s) { fmtList.append(None); QTextLayout::FormatRange curFmtRng; curFmtRng.format = format(None); + curFmtRng.start = 0; result.formats.append(curFmtRng); int pos = 0; int length; int fgCol = -1, bgCol = -1; // marks current mIRC color @@ -136,6 +156,8 @@ UiStyle::StyledText UiStyle::styleString(QString s) { length = 4; } else { int color = 10 * s[pos+4].digitValue() + s[pos+5].digitValue(); + //TODO: use 99 as transparent color (re mirc color "standard") + color &= 0x0f; int *colptr; FormatType coltype; if(s[pos+3] == 'f') { // foreground colptr = &fgCol; coltype = FgCol00; @@ -160,16 +182,20 @@ UiStyle::StyledText UiStyle::styleString(QString s) { fmtList.clear(); fmtList.append(None); curFmtRng.format = format(None); fgCol = bgCol = -1; - length = 1; + length = 2; } else if(s[pos+1] == 'R') { // reverse // TODO: implement reverse formatting - length = 1; + length = 2; } else { // all others are toggles QString code = QString("%") + s[pos+1]; if(s[pos+1] == 'D') code += s[pos+2]; FormatType ftype = formatType(code); - Q_ASSERT(ftype != Invalid); + if(ftype == Invalid) { + qWarning(qPrintable(QString("Invalid format code in string: %1").arg(s))); + continue; + } + //Q_ASSERT(ftype != Invalid); length = code.length(); if(!fmtList.contains(ftype)) { // toggle it on