Dear LyXers,it annoyed me a long time that LyX does only provide the most basic colors in the character dialog and that these colors are not even displayed there. (For example I use the color "lime" quite frequently and had therefore to use TeX code.)
I thought about this and offering all possible rgb colors would be a nightmare because this will pollute the TeX output with color definitions and a strength of TeX is to provide a well-structured output. So providing only a basic set of colors makes sense. Since we support the package xcolor for a long time we could expand our color list with the standard fonts of xcolor.
This is done in the attached patch. The patch also displays the colors in the dialog. It contains also the necessary tex2lyx changes. I will of course add lyx2lyx when going on.
OK to go on? regards Uwe
src/Color.cpp | 15 +++++++++++++-- src/ColorCode.h | 28 ++++++++++++++++++++++++--- src/Font.cpp | 12 ++++++++++++ src/frontends/qt4/GuiCharacter.cpp | 39 +++++++++++++++++++++++++++++++++++--- src/frontends/qt4/GuiPrefs.cpp | 17 ++++++++++++++--- src/tex2lyx/Preamble.cpp | 10 ++++++---- src/tex2lyx/text.cpp | 12 ++++++++++++ 7 files changed, 118 insertions(+), 15 deletions(-) diff --git a/src/Color.cpp b/src/Color.cpp index 161ebba..f08c9fb 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -203,11 +203,22 @@ ColorSet::ColorSet() { Color_none, N_("none"), "none", "black", "none" }, { Color_black, N_("black"), "black", "black", "black" }, { Color_white, N_("white"), "white", "white", "white" }, - { Color_red, N_("red"), "red", "red", "red" }, - { Color_green, N_("green"), "green", "green", "green" }, { Color_blue, N_("blue"), "blue", "blue", "blue" }, + { Color_brown, N_("brown"), "brown", "brown", "brown" }, { Color_cyan, N_("cyan"), "cyan", "cyan", "cyan" }, + { Color_darkgray, N_("darkgray"), "darkgray", "darkgray", "darkgray" }, + { Color_gray, N_("gray"), "gray", "gray", "gray" }, + { Color_green, N_("green"), "green", "green", "green" }, + { Color_lightgray, N_("lightgray"), "lightgray", "lightgray", "lightgray" }, + { Color_lime, N_("lime"), "lime", "lime", "lime" }, { Color_magenta, N_("magenta"), "magenta", "magenta", "magenta" }, + { Color_olive, N_("olive"), "olive", "olive", "olive" }, + { Color_orange, N_("orange"), "orange", "orange", "orange" }, + { Color_pink, N_("pink"), "pink", "pink", "pink" }, + { Color_purple, N_("purple"), "purple", "purple", "purple" }, + { Color_red, N_("red"), "red", "red", "red" }, + { Color_teal, N_("teal"), "teal", "teal", "teal" }, + { Color_violet, N_("violet"), "violet", "violet", "violet" }, { Color_yellow, N_("yellow"), "yellow", "yellow", "yellow" }, { Color_cursor, N_("cursor"), "cursor", "black", "cursor" }, { Color_background, N_("background"), "background", "linen", "background" }, diff --git a/src/ColorCode.h b/src/ColorCode.h index 4d391c0..180e544 100644 --- a/src/ColorCode.h +++ b/src/ColorCode.h @@ -21,16 +21,38 @@ enum ColorCode { /// Color_white, /// - Color_red, + Color_blue, + /// + Color_brown, + /// + Color_cyan, + /// + Color_darkgray, + /// + Color_gray, /// Color_green, /// - Color_blue, + Color_lightgray, /// - Color_cyan, + Color_lime, /// Color_magenta, /// + Color_olive, + /// + Color_orange, + /// + Color_pink, + /// + Color_purple, + /// + Color_red, + /// + Color_teal, + /// + Color_violet, + /// Color_yellow, // Needed interface colors diff --git a/src/Font.cpp b/src/Font.cpp index 7e8b3f4..34c5c0b 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -695,6 +695,18 @@ void Font::validate(LaTeXFeatures & features) const case Color_latex: case Color_notelabel: break; + case Color_brown: + case Color_darkgray: + case Color_gray: + case Color_lightgray: + case Color_lime: + case Color_olive: + case Color_orange: + case Color_pink: + case Color_purple: + case Color_teal: + case Color_violet: + features.require("xcolor"); default: features.require("color"); LYXERR(Debug::LATEX, "Color enabled. Font: " << to_utf8(stateText(0))); diff --git a/src/frontends/qt4/GuiCharacter.cpp b/src/frontends/qt4/GuiCharacter.cpp index 0e47576..a947143 100644 --- a/src/frontends/qt4/GuiCharacter.cpp +++ b/src/frontends/qt4/GuiCharacter.cpp @@ -21,12 +21,15 @@ #include "Buffer.h" #include "BufferParams.h" #include "BufferView.h" +#include "Color.h" +#include "ColorCache.h" #include "Cursor.h" #include "FuncRequest.h" #include "Language.h" #include "Paragraph.h" #include <QAbstractItemModel> +#include <QComboBox> #include <QModelIndex> #include <QSettings> #include <QVariant> @@ -92,11 +95,22 @@ static QList<ColorPair> colorData() colors << ColorPair(qt_("No color"), Color_none); colors << ColorPair(qt_("Black"), Color_black); colors << ColorPair(qt_("White"), Color_white); - colors << ColorPair(qt_("Red"), Color_red); - colors << ColorPair(qt_("Green"), Color_green); colors << ColorPair(qt_("Blue"), Color_blue); + colors << ColorPair(qt_("Brown"), Color_brown); colors << ColorPair(qt_("Cyan"), Color_cyan); + colors << ColorPair(qt_("Darkgray"), Color_darkgray); + colors << ColorPair(qt_("Gray"), Color_gray); + colors << ColorPair(qt_("Green"), Color_green); + colors << ColorPair(qt_("Lightgray"), Color_lightgray); + colors << ColorPair(qt_("Lime"), Color_lime); colors << ColorPair(qt_("Magenta"), Color_magenta); + colors << ColorPair(qt_("Olive"), Color_olive); + colors << ColorPair(qt_("Orange"), Color_orange); + colors << ColorPair(qt_("Pink"), Color_pink); + colors << ColorPair(qt_("Purple"), Color_purple); + colors << ColorPair(qt_("Red"), Color_red); + colors << ColorPair(qt_("Teal"), Color_teal); + colors << ColorPair(qt_("Violet"), Color_violet); colors << ColorPair(qt_("Yellow"), Color_yellow); colors << ColorPair(qt_("Reset"), Color_inherit); return colors; @@ -156,6 +170,25 @@ void fillCombo(QComboBox * combo, QList<T> const & list) combo->addItem(cit->first); } +template<typename T> +void fillComboColor(QComboBox * combo, QList<T> const & list) +{ + // at first add the 2 colors "No change" and "No color" + combo->addItem(list.begin()->first); + combo->addItem((list.begin() + 1)->first); + // now add the real colors + QPixmap coloritem(32, 32); + QColor color; + typename QList<T>::const_iterator cit = list.begin() + 2; + for (; cit != list.end() - 1; ++cit) { + color = QColor(guiApp->colorCache().get(cit->second, false)); + coloritem.fill(color); + combo->addItem(QIcon(coloritem), cit->first); + } + //the last color is "Reset" + combo->addItem((list.end() - 1)->first); +} + } GuiCharacter::GuiCharacter(GuiView & lv) @@ -195,7 +228,7 @@ GuiCharacter::GuiCharacter(GuiView & lv) fillCombo(sizeCO, size); fillCombo(shapeCO, shape); fillCombo(miscCO, bar); - fillCombo(colorCO, color); + fillComboColor(colorCO, color); fillCombo(langCO, language); bc().setPolicy(ButtonPolicy::OkApplyCancelAutoReadOnlyPolicy); diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 995f8fa..7c5f236 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1121,11 +1121,22 @@ PrefColors::PrefColors(GuiPreferences * form) if (lc == Color_none || lc == Color_black || lc == Color_white - || lc == Color_red + || lc == Color_blue + || lc == Color_brown + || lc == Color_cyan + || lc == Color_darkgray + || lc == Color_gray || lc == Color_green - || lc == Color_blue - || lc == Color_cyan + || lc == Color_lightgray + || lc == Color_lime || lc == Color_magenta + || lc == Color_olive + || lc == Color_orange + || lc == Color_pink + || lc == Color_purple + || lc == Color_red + || lc == Color_teal + || lc == Color_violet || lc == Color_yellow || lc == Color_inherit || lc == Color_ignore) diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 35bb506..7da2387 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -159,11 +159,13 @@ const char * const known_if_commands[] = {"if", "ifarydshln", "ifbraket", "ifcancel", "ifcolortbl", "ifeurosym", "ifmarginnote", "ifmmode", "ifpdf", "ifsidecap", "ifupgreek", 0}; -const char * const known_basic_colors[] = {"blue", "black", "cyan", "green", -"magenta", "red", "white", "yellow", 0}; +const char * const known_basic_colors[] = {"black", "blue", "brown", "cyan", + "darkgray", "gray", "green", "lightgray", "lime", "magenta", "orange", "olive", + "pink", "purple", "red", "teal", "violet", "white", "yellow", 0}; -const char * const known_basic_color_codes[] = {"#0000ff", "#000000", "#00ffff", -"#00ff00", "#ff00ff", "#ff0000", "#ffffff", "#ffff00", 0}; +const char * const known_basic_color_codes[] = {"#000000", "#0000ff", "#964B00", "#00ffff", + "#a9a9a9", "#808080", "#00ff00", "#d3d3d3", "#bfff00", "#ff00ff", "#ff7f00", "#808000", + "#ffc0cb", "#800080", "#ff0000", "#008080", "#8F00FF", "#ffffff", "#ffff00", 0}; /// conditional commands with three arguments like \@ifundefined{}{}{} const char * const known_if_3arg_commands[] = {"@ifundefined", "IfFileExists", diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 88ec91d..14419b8 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -3155,6 +3155,18 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, context.check_layout(os); os << "\n\\color inherit\n"; preamble.registerAutomaticallyLoadedPackage("color"); + } + else if (color == "brown" || color == "darkgray" || color == "gray" + || color == "lightgray" || color == "lime" || color == "olive" + || color == "orange" || color == "pink" || color == "purple" + || color == "teal" || color == "violet") { + context.check_layout(os); + os << "\n\\color " << color << "\n"; + parse_text_snippet(p, os, FLAG_ITEM, outer, context); + context.check_layout(os); + os << "\n\\color inherit\n"; + preamble.registerAutomaticallyLoadedPackage("xcolor"); + } else // for custom defined colors output_ert_inset(os, t.asInput() + "{" + color + "}", context);
ColorTEst.lyx
Description: application/lyx