X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fuistyle.cpp;h=ec7364ee3a272f887b8164322786d3b84c87dcdf;hp=3fc53bd7332c0ca059e9de7eb13ebfe3b3a6c050;hb=16d697ab814aa594b71ac45269604aa65ed9d011;hpb=85cc2479ab9bd85b33f4d8494b1eeeb46a6a1049 diff --git a/src/uisupport/uistyle.cpp b/src/uisupport/uistyle.cpp index 3fc53bd7..ec7364ee 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,19 +19,28 @@ ***************************************************************************/ #include "uistyle.h" +#include "uistylesettings.h" -UiStyle::UiStyle() { +UiStyle::UiStyle(const QString &settingsKey) : _settingsKey(settingsKey) { // Default format QTextCharFormat def; - def.setForeground(QBrush("black")); - def.setFont(QFont("Verdana",9)); - - _formats = QVector(NumFormatTypes, def); + def.setForeground(QBrush("#000000")); + def.setFont(QFont("Courier", 10)); + _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; - colors << "white" << "black" << "navy" << "green" << "red" << "maroon" << "purple" << "orange"; - colors << "yellow" << "lime" << "teal" << "aqua" << "royalblue" << "fuchsia" << "grey" << "silver"; + //colors << "white" << "black" << "navy" << "green" << "red" << "maroon" << "purple" << "orange"; + //colors << "yellow" << "lime" << "teal" << "aqua" << "royalblue" << "fuchsia" << "grey" << "silver"; + colors << "#ffffff" << "#000000" << "#000080" << "#008000" << "#ff0000" << "#800000" << "#800080" << "#ffa500"; + colors << "#ffff00" << "#00ff00" << "#008080" << "#00ffff" << "#4169E1" << "#ff00ff" << "#808080" << "#c0c0c0"; // Now initialize the mapping between FormatCodes and FormatTypes... _formatCodes["%O"] = None; @@ -66,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. } @@ -87,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 { @@ -104,12 +125,13 @@ QString UiStyle::formatCode(FormatType ftype) const { return _formatCodes.key(ftype); } -UiStyle::StyledString UiStyle::styleString(QString s) { - StyledString result; +UiStyle::StyledText UiStyle::styleString(QString s) { + StyledText result; QList fmtList; 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 @@ -134,6 +156,8 @@ UiStyle::StyledString 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; @@ -158,16 +182,20 @@ UiStyle::StyledString 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