first version of richtext support for input widget - needs a lot of refactoring
authorDirk Rettschlag <dirk.rettschlag@gmail.com>
Tue, 9 Feb 2010 11:46:57 +0000 (12:46 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 14 Feb 2010 20:00:25 +0000 (21:00 +0100)
icons/oxygen_kde.qrc
icons/oxygen_kde/22x22/actions/format-fill-color.png [new file with mode: 0644]
icons/oxygen_kde/22x22/actions/format-text-bold.png [new file with mode: 0644]
icons/oxygen_kde/22x22/actions/format-text-color.png [new file with mode: 0644]
icons/oxygen_kde/22x22/actions/format-text-italic.png [new file with mode: 0644]
icons/oxygen_kde/22x22/actions/format-text-underline.png [new file with mode: 0644]
src/qtui/inputwidget.cpp
src/qtui/inputwidget.h
src/qtui/ui/inputwidget.ui
src/uisupport/multilineedit.cpp
src/uisupport/multilineedit.h

index efa3ee5..51eb97a 100644 (file)
     <file alias="oxygen/22x22/actions/edit-clear-locationbar-rtl.png">oxygen_kde/22x22/actions/edit-clear-locationbar-rtl.png</file>
     <file alias="oxygen/22x22/actions/list-add-user.png">oxygen_kde/22x22/actions/list-add-user.png</file>
     <file alias="oxygen/22x22/actions/dialog-close.png">oxygen_kde/22x22/actions/dialog-close.png</file>
+    <file alias="oxygen/22x22/actions/format-fill-color.png">oxygen_kde/22x22/actions/format-fill-color.png</file>
+    <file alias="oxygen/22x22/actions/format-text-bold.png">oxygen_kde/22x22/actions/format-text-bold.png</file>
+    <file alias="oxygen/22x22/actions/format-text-color.png">oxygen_kde/22x22/actions/format-text-color.png</file>
+    <file alias="oxygen/22x22/actions/format-text-italic.png">oxygen_kde/22x22/actions/format-text-italic.png</file>
+    <file alias="oxygen/22x22/actions/format-text-underline.png">oxygen_kde/22x22/actions/format-text-underline.png</file>
     <file alias="oxygen/16x16/apps/quassel.png">oxygen_kde/16x16/apps/quassel.png</file>
     <file alias="oxygen/16x16/status/security-low.png">oxygen_kde/16x16/status/security-low.png</file>
     <file alias="oxygen/16x16/status/user-away.png">oxygen_kde/16x16/status/user-away.png</file>
diff --git a/icons/oxygen_kde/22x22/actions/format-fill-color.png b/icons/oxygen_kde/22x22/actions/format-fill-color.png
new file mode 100644 (file)
index 0000000..e31f00e
Binary files /dev/null and b/icons/oxygen_kde/22x22/actions/format-fill-color.png differ
diff --git a/icons/oxygen_kde/22x22/actions/format-text-bold.png b/icons/oxygen_kde/22x22/actions/format-text-bold.png
new file mode 100644 (file)
index 0000000..a5535e3
Binary files /dev/null and b/icons/oxygen_kde/22x22/actions/format-text-bold.png differ
diff --git a/icons/oxygen_kde/22x22/actions/format-text-color.png b/icons/oxygen_kde/22x22/actions/format-text-color.png
new file mode 100644 (file)
index 0000000..98f6173
Binary files /dev/null and b/icons/oxygen_kde/22x22/actions/format-text-color.png differ
diff --git a/icons/oxygen_kde/22x22/actions/format-text-italic.png b/icons/oxygen_kde/22x22/actions/format-text-italic.png
new file mode 100644 (file)
index 0000000..a50211f
Binary files /dev/null and b/icons/oxygen_kde/22x22/actions/format-text-italic.png differ
diff --git a/icons/oxygen_kde/22x22/actions/format-text-underline.png b/icons/oxygen_kde/22x22/actions/format-text-underline.png
new file mode 100644 (file)
index 0000000..e511395
Binary files /dev/null and b/icons/oxygen_kde/22x22/actions/format-text-underline.png differ
index be18830..1652393 100644 (file)
@@ -31,6 +31,7 @@
 #include "qtui.h"
 #include "qtuisettings.h"
 #include "tabcompleter.h"
+#include <QPainter>
 
 InputWidget::InputWidget(QWidget *parent)
   : AbstractItemView(parent),
@@ -41,6 +42,10 @@ InputWidget::InputWidget(QWidget *parent)
 
   layout()->setAlignment(ui.ownNick, Qt::AlignBottom);
   layout()->setAlignment(ui.inputEdit, Qt::AlignBottom);
+  layout()->setAlignment(ui.showStyleButton, Qt::AlignBottom);
+  layout()->setAlignment(ui.styleFrame, Qt::AlignBottom);
+
+  ui.styleFrame->setVisible(false);
 
   setFocusProxy(ui.inputEdit);
   ui.ownNick->setFocusProxy(ui.inputEdit);
@@ -55,6 +60,35 @@ InputWidget::InputWidget(QWidget *parent)
   ui.inputEdit->setMode(MultiLineEdit::MultiLine);
   ui.inputEdit->setPasteProtectionEnabled(true);
 
+  ui.boldButton->setIcon(SmallIcon("format-text-bold"));
+  ui.italicButton->setIcon(SmallIcon("format-text-italic"));
+  ui.underlineButton->setIcon(SmallIcon("format-text-underline"));
+  ui.textcolorButton->setIcon(SmallIcon("format-text-color"));
+  ui.highlightcolorButton->setIcon(SmallIcon("format-fill-color"));
+
+  _colorMenu = new QMenu();
+  _colorFillMenu = new QMenu();
+
+  QStringList names;
+  names << tr("White") << tr("Black") << tr("Dark blue") << tr("Dark green") << tr("Red") << tr("Dark red") << tr("Dark magenta")  << tr("Orange")
+  << tr("Yellow") << tr("Green") << tr("Dark cyan") << tr("Cyan") << tr("Blue") << tr("Magenta") << tr("Dark gray") << tr("Light gray");
+
+  QPixmap pix(16, 16);
+  for (int i = 0; i < inputLine()->mircColorMap().count(); i++) {
+    pix.fill(inputLine()->mircColorMap().values()[i]);
+    _colorMenu->addAction(pix, names[i])->setData(inputLine()->mircColorMap().keys()[i]);
+    _colorFillMenu->addAction(pix, names[i])->setData(inputLine()->mircColorMap().keys()[i]);
+  }
+
+  pix.fill(Qt::transparent);
+  _colorMenu->addAction(pix, tr("Clear Color"))->setData("");
+  _colorFillMenu->addAction(pix, tr("Clear Color"))->setData("");
+
+  ui.textcolorButton->setMenu(_colorMenu);
+  connect(_colorMenu, SIGNAL(triggered(QAction*)), this, SLOT(colorChoosen(QAction*)));
+  ui.highlightcolorButton->setMenu(_colorFillMenu);
+  connect(_colorFillMenu, SIGNAL(triggered(QAction*)), this, SLOT(colorHighlightChoosen(QAction*)));
+
   new TabCompleter(ui.inputEdit);
 
   UiStyleSettings fs("Fonts");
@@ -89,33 +123,6 @@ InputWidget::InputWidget(QWidget *parent)
   activateInputline->setText(tr("Focus Input Line"));
   activateInputline->setShortcut(tr("Ctrl+L"));
 
-  actionTextBold = coll->add<Action>("TextBold");
-  QFont bold;
-  bold.setBold(true);
-  actionTextBold->setFont(bold);
-  actionTextBold->setText(tr("Bold"));
-  actionTextBold->setShortcut(tr("Ctrl+B"));
-  actionTextBold->setCheckable(true);
-  connect(actionTextBold, SIGNAL(triggered()), SLOT(textBold()));
-
-  actionTextUnderline = coll->add<Action>("TextUnderline");
-  QFont underline;
-  underline.setUnderline(true);
-  actionTextUnderline->setFont(underline);
-  actionTextUnderline->setText(tr("Underline"));
-  actionTextUnderline->setShortcut(tr("Ctrl+U"));
-  actionTextUnderline->setCheckable(true);
-  connect(actionTextUnderline, SIGNAL(triggered()), SLOT(textUnderline()));
-
-  actionTextItalic = coll->add<Action>("TextItalic");
-  QFont italic;
-  italic.setItalic(true);
-  actionTextItalic->setFont(italic);
-  actionTextItalic->setText(tr("Italic"));
-  actionTextItalic->setShortcut(tr("Ctrl+I"));
-  actionTextItalic->setCheckable(true);
-  connect(actionTextItalic, SIGNAL(triggered()), SLOT(textItalic()));
-
   connect(inputLine(), SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(currentCharFormatChanged(QTextCharFormat)));
 }
 
@@ -353,12 +360,17 @@ void InputWidget::changeNick(const QString &newNick) const {
 
 void InputWidget::on_inputEdit_textEntered(const QString &text) const {
   Client::userInput(currentBufferInfo(), text);
-  actionTextBold->setChecked(false);
-  actionTextUnderline->setChecked(false);
-  actionTextItalic->setChecked(false);
-  inputLine()->setFontWeight(QFont::Normal);
-  inputLine()->setFontUnderline(false);
-  inputLine()->setFontItalic(false);
+  ui.boldButton->setChecked(false);
+  ui.underlineButton->setChecked(false);
+  ui.italicButton->setChecked(false);
+
+  QTextCharFormat fmt;
+  fmt.setFontWeight(QFont::Normal);
+  fmt.setFontUnderline(false);
+  fmt.setFontItalic(false);
+  fmt.clearForeground();
+  fmt.clearBackground();
+  inputLine()->setCurrentCharFormat(fmt);
 }
 
 void InputWidget::mergeFormatOnWordOrSelection(const QTextCharFormat &format) {
@@ -369,47 +381,131 @@ void InputWidget::mergeFormatOnWordOrSelection(const QTextCharFormat &format) {
   inputLine()->mergeCurrentCharFormat(format);
 }
 
+void InputWidget::setFormatOnWordOrSelection(const QTextCharFormat &format) {
+  QTextCursor cursor = inputLine()->textCursor();
+  if (!cursor.hasSelection())
+    cursor.select(QTextCursor::WordUnderCursor);
+  cursor.setCharFormat(format);
+  inputLine()->setCurrentCharFormat(format);
+}
+
+QTextCharFormat InputWidget::getFormatOfWordOrSelection() {
+  QTextCursor cursor = inputLine()->textCursor();
+  return cursor.charFormat();
+}
+
 void InputWidget::currentCharFormatChanged(const QTextCharFormat &format) {
   fontChanged(format.font());
-  colorChanged(format.foreground().color(), format.background().color());
+  if (format.foreground().isOpaque())
+    colorChanged(format.foreground().color());
+  else
+    colorChanged(Qt::transparent);
+  if (format.background().isOpaque())
+    colorHighlightChanged(format.background().color());
+  else
+    colorHighlightChanged(Qt::transparent);
 }
 
-void InputWidget::textBold()
-{
-  if (inputLine()->hasFocus()) {
-    QTextCharFormat fmt;
-    fmt.setFontWeight(actionTextBold->isChecked() ? QFont::Bold : QFont::Normal);
-    mergeFormatOnWordOrSelection(fmt);
-  }
+void InputWidget::on_boldButton_toggled(bool checked) {
+  QTextCharFormat fmt;
+  fmt.setFontWeight(checked ? QFont::Bold : QFont::Normal);
+  mergeFormatOnWordOrSelection(fmt);
 }
 
-void InputWidget::textUnderline()
+void InputWidget::on_underlineButton_toggled(bool checked) {
+  QTextCharFormat fmt;
+  fmt.setFontUnderline(checked);
+  mergeFormatOnWordOrSelection(fmt);
+}
+
+void InputWidget::on_italicButton_toggled(bool checked) {
+  QTextCharFormat fmt;
+  fmt.setFontItalic(checked);
+  mergeFormatOnWordOrSelection(fmt);
+}
+
+void InputWidget::fontChanged(const QFont &f)
 {
-  if (inputLine()->hasFocus()) {
-    QTextCharFormat fmt;
-    fmt.setFontUnderline(actionTextUnderline->isChecked());
+  ui.boldButton->setChecked(f.bold());
+  ui.italicButton->setChecked(f.italic());
+  ui.underlineButton->setChecked(f.underline());
+}
+
+void InputWidget::colorChoosen(QAction * action) {
+  QTextCharFormat fmt;
+  QColor color;
+  if (qVariantValue<QString>(action->data()) == "") {
+    color = Qt::transparent;
+    fmt = getFormatOfWordOrSelection();
+    fmt.clearForeground();
+    setFormatOnWordOrSelection(fmt);
+  }
+  else {
+    color = QColor(inputLine()->rgbColorFromMirc(qVariantValue<QString>(action->data())));
+    fmt.setForeground(color);
     mergeFormatOnWordOrSelection(fmt);
   }
+  ui.textcolorButton->setDefaultAction(action);
+  ui.textcolorButton->setIcon(createColorToolButtonIcon(SmallIcon("format-text-color"), color));
 }
 
-void InputWidget::textItalic()
-{
-  if (inputLine()->hasFocus()) {
-    QTextCharFormat fmt;
-    fmt.setFontItalic(actionTextItalic->isChecked());
+void InputWidget::colorHighlightChoosen(QAction * action) {
+  QTextCharFormat fmt;
+  QColor color;
+  if (qVariantValue<QString>(action->data()) == "") {
+    color = Qt::transparent;
+    fmt = getFormatOfWordOrSelection();
+    fmt.clearBackground();
+    setFormatOnWordOrSelection(fmt);
+  }
+  else {
+    color = QColor(inputLine()->rgbColorFromMirc(qVariantValue<QString>(action->data())));
+    fmt.setBackground(color);
     mergeFormatOnWordOrSelection(fmt);
   }
+  ui.highlightcolorButton->setDefaultAction(action);
+  ui.highlightcolorButton->setIcon(createColorToolButtonIcon(SmallIcon("format-fill-color"), color));
 }
 
-void InputWidget::fontChanged(const QFont &f)
-{
-  actionTextBold->setChecked(f.bold());
-  actionTextItalic->setChecked(f.italic());
-  actionTextUnderline->setChecked(f.underline());
+void InputWidget::colorChanged(const QColor &fg) {
+  if (fg == Qt::transparent)
+    ui.textcolorButton->setDefaultAction(_colorMenu->actions().last());
+  else
+    ui.textcolorButton->setDefaultAction(_colorMenu->actions().value(inputLine()->mircColorFromRGB(fg.name()).toInt()));
+
+  ui.textcolorButton->setIcon(createColorToolButtonIcon(SmallIcon("format-text-color"), fg));
+}
+
+void InputWidget::colorHighlightChanged(const QColor &bg) {
+  if (bg == Qt::transparent)
+    ui.highlightcolorButton->setDefaultAction(_colorFillMenu->actions().last());
+  else
+    ui.highlightcolorButton->setDefaultAction(_colorFillMenu->actions().value(inputLine()->mircColorFromRGB(bg.name()).toInt()));
+
+  ui.highlightcolorButton->setIcon(createColorToolButtonIcon(SmallIcon("format-fill-color"), bg));
+}
+
+void InputWidget::on_showStyleButton_toggled(bool checked) {
+  ui.styleFrame->setVisible(checked);
+  if (checked) {
+    ui.showStyleButton->setArrowType(Qt::LeftArrow);
+  }
+  else {
+    ui.showStyleButton->setArrowType(Qt::RightArrow);
+  }
 }
 
-void InputWidget::colorChanged(const QColor &fg, const QColor &bg) {
-  //TODO update colorpicker
+QIcon InputWidget::createColorToolButtonIcon(const QIcon &icon, QColor color) {
+  QPixmap pixmap(16, 16);
+  pixmap.fill(Qt::transparent);
+  QPainter painter(&pixmap);
+  QPixmap image = icon.pixmap(16,16);
+  QRect target(0, 0, 16, 14);
+  QRect source(0, 0, 16, 14);
+  painter.fillRect(QRect(0, 14, 16, 16), color);
+  painter.drawPixmap(target, image, source);
+
+  return QIcon(pixmap);
 }
 
 // MOUSE WHEEL FILTER
index b185567..da014c3 100644 (file)
@@ -72,26 +72,27 @@ private slots:
   BufferInfo currentBufferInfo() const;
 
   void currentCharFormatChanged(const QTextCharFormat &format);
-  void textBold();
-  void textUnderline();
-  void textItalic();
+  void on_showStyleButton_toggled(bool checked);
+  void on_boldButton_toggled(bool checked);
+  void on_italicButton_toggled(bool checked);
+  void on_underlineButton_toggled(bool checked);
+  void colorChoosen(QAction * action);
+  void colorHighlightChoosen(QAction * action);
 
 private:
   Ui::InputWidget ui;
 
   NetworkId _networkId;
   IdentityId _identityId;
-
-  Action *actionTextBold,
-  *actionTextUnderline,
-  *actionTextItalic,
-  *actionTextFgColor,
-  *actionTextBgColor;
+  QMenu *_colorMenu, *_colorFillMenu;
 
   void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
   void fontChanged(const QFont &f);
-  void colorChanged(const QColor &fg, const QColor &bg);
-
+  void colorChanged(const QColor &fg);
+  void colorHighlightChanged(const QColor &bg);
+  QIcon createColorToolButtonIcon(const QIcon &icon, QColor color);
+  QTextCharFormat getFormatOfWordOrSelection();
+  void setFormatOnWordOrSelection(const QTextCharFormat &format);
 };
 
 
index 7ed5d57..4ecdc25 100644 (file)
     <verstretch>0</verstretch>
    </sizepolicy>
   </property>
+  <property name="minimumSize">
+   <size>
+    <width>192</width>
+    <height>0</height>
+   </size>
+  </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
     <number>0</number>
    </property>
    <item>
-    <widget class="QComboBox" name="ownNick"/>
+    <widget class="QComboBox" name="ownNick">
+     <property name="frame">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QToolButton" name="showStyleButton">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+     <property name="checkable">
+      <bool>true</bool>
+     </property>
+     <property name="arrowType">
+      <enum>Qt::RightArrow</enum>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QFrame" name="styleFrame">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="minimumSize">
+      <size>
+       <width>161</width>
+       <height>24</height>
+      </size>
+     </property>
+     <property name="lineWidth">
+      <number>0</number>
+     </property>
+     <widget class="QToolButton" name="textcolorButton">
+      <property name="geometry">
+       <rect>
+        <x>81</x>
+        <y>0</y>
+        <width>40</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="text">
+       <string/>
+      </property>
+      <property name="popupMode">
+       <enum>QToolButton::MenuButtonPopup</enum>
+      </property>
+      <property name="arrowType">
+       <enum>Qt::NoArrow</enum>
+      </property>
+     </widget>
+     <widget class="QToolButton" name="boldButton">
+      <property name="enabled">
+       <bool>true</bool>
+      </property>
+      <property name="geometry">
+       <rect>
+        <x>0</x>
+        <y>0</y>
+        <width>27</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="text">
+       <string/>
+      </property>
+      <property name="iconSize">
+       <size>
+        <width>16</width>
+        <height>16</height>
+       </size>
+      </property>
+      <property name="checkable">
+       <bool>true</bool>
+      </property>
+      <property name="checked">
+       <bool>false</bool>
+      </property>
+     </widget>
+     <widget class="QToolButton" name="underlineButton">
+      <property name="enabled">
+       <bool>true</bool>
+      </property>
+      <property name="geometry">
+       <rect>
+        <x>54</x>
+        <y>0</y>
+        <width>27</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="text">
+       <string/>
+      </property>
+      <property name="iconSize">
+       <size>
+        <width>16</width>
+        <height>16</height>
+       </size>
+      </property>
+      <property name="checkable">
+       <bool>true</bool>
+      </property>
+      <property name="checked">
+       <bool>false</bool>
+      </property>
+     </widget>
+     <widget class="QToolButton" name="highlightcolorButton">
+      <property name="geometry">
+       <rect>
+        <x>121</x>
+        <y>0</y>
+        <width>40</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="text">
+       <string/>
+      </property>
+      <property name="popupMode">
+       <enum>QToolButton::MenuButtonPopup</enum>
+      </property>
+     </widget>
+     <widget class="QToolButton" name="italicButton">
+      <property name="enabled">
+       <bool>true</bool>
+      </property>
+      <property name="geometry">
+       <rect>
+        <x>27</x>
+        <y>0</y>
+        <width>27</width>
+        <height>24</height>
+       </rect>
+      </property>
+      <property name="sizePolicy">
+       <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <property name="text">
+       <string/>
+      </property>
+      <property name="iconSize">
+       <size>
+        <width>16</width>
+        <height>16</height>
+       </size>
+      </property>
+      <property name="checkable">
+       <bool>true</bool>
+      </property>
+      <property name="checked">
+       <bool>false</bool>
+      </property>
+     </widget>
+    </widget>
    </item>
    <item>
     <widget class="MultiLineEdit" name="inputEdit">
index c80c2fc..7b26e7e 100644 (file)
@@ -60,22 +60,22 @@ MultiLineEdit::MultiLineEdit(QWidget *parent)
 
   connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged()));
 
-  mircColorMap["00"] = "#ffffff";
-  mircColorMap["01"] = "#000000";
-  mircColorMap["02"] = "#000080";
-  mircColorMap["03"] = "#008000";
-  mircColorMap["04"] = "#ff0000";
-  mircColorMap["05"] = "#800000";
-  mircColorMap["06"] = "#800080";
-  mircColorMap["07"] = "#ffa500";
-  mircColorMap["08"] = "#ffff00";
-  mircColorMap["09"] = "#00ff00";
-  mircColorMap["10"] = "#008080";
-  mircColorMap["11"] = "#00ffff";
-  mircColorMap["12"] = "#4169e1";
-  mircColorMap["13"] = "#ff00ff";
-  mircColorMap["14"] = "#808080";
-  mircColorMap["15"] = "#c0c0c0";
+  _mircColorMap["00"] = "#ffffff";
+  _mircColorMap["01"] = "#000000";
+  _mircColorMap["02"] = "#000080";
+  _mircColorMap["03"] = "#008000";
+  _mircColorMap["04"] = "#ff0000";
+  _mircColorMap["05"] = "#800000";
+  _mircColorMap["06"] = "#800080";
+  _mircColorMap["07"] = "#ffa500";
+  _mircColorMap["08"] = "#ffff00";
+  _mircColorMap["09"] = "#00ff00";
+  _mircColorMap["10"] = "#008080";
+  _mircColorMap["11"] = "#00ffff";
+  _mircColorMap["12"] = "#4169e1";
+  _mircColorMap["13"] = "#ff00ff";
+  _mircColorMap["14"] = "#808080";
+  _mircColorMap["15"] = "#c0c0c0";
 
 }
 
@@ -359,10 +359,10 @@ QString MultiLineEdit::convertHtmlToMircCodes(const QString &text) {
           QString color = regexColors.cap(2);
 
           if (colorType == "color")
-            mircFgColor = mircColorMap.key(color);
+            mircFgColor = _mircColorMap.key(color);
 
           if (colorType == "background-color")
-            mircBgColor = mircColorMap.key(color);
+            mircBgColor = _mircColorMap.key(color);
 
           posColors += regexColors.matchedLength();
         }
@@ -372,7 +372,7 @@ QString MultiLineEdit::convertHtmlToMircCodes(const QString &text) {
         // we need a fg color to be able to use a bg color
         if (mircFgColor.isEmpty()) {
           //FIXME try to use the current forecolor
-          mircFgColor = mircColorMap.key(textColor().name());
+          mircFgColor = _mircColorMap.key(textColor().name());
           if (mircFgColor.isEmpty())
             mircFgColor = "01"; //use black if the current foreground color can't be converted
         }
@@ -450,12 +450,12 @@ QString MultiLineEdit::convertMircCodesToHtml(const QString &text) {
           bg = words[i].mid(pos+4,2);
 
         style.append(" color:");
-        style.append(mircColorMap[fg]);
+        style.append(_mircColorMap[fg]);
         style.append(";");
 
         if (!bg.isEmpty()) {
           style.append(" background-color:");
-          style.append(mircColorMap[bg]);
+          style.append(_mircColorMap[bg]);
           style.append(";");
           len = 6;
         }
index da44304..999487a 100644 (file)
@@ -66,6 +66,10 @@ public:
   virtual QSize sizeHint() const;
   virtual QSize minimumSizeHint() const;
 
+  inline QString mircColorFromRGB(QString rgbColor) const { return _mircColorMap.key(rgbColor); }
+  inline QString rgbColorFromMirc(QString mircColor) const { return _mircColorMap[mircColor]; }
+  inline QMap<QString, QString>  mircColorMap() const { return _mircColorMap; }
+
 public slots:
   void setMode(Mode mode);
   void setMinHeight(int numLines);
@@ -112,7 +116,7 @@ private:
   QSize _sizeHint;
   qreal _lastDocumentHeight;
 
-  QHash<QString, QString> mircColorMap;
+  QMap<QString, QString> _mircColorMap;
 
   void reset();
   void showHistoryEntry();