From 4e2cd3065796d99cce1c1c77cbd30a52c37bce60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Fri, 2 Apr 2010 23:39:36 +0000 Subject: [PATCH] fileformat change: support to specify a document-wide font color - new buffer parameter \fontcolor - the default color is internally black because we have to set a color - the font color is only used when the user explicitly specified a color git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34042 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 6 ++- lib/lyx2lyx/lyx_2_0.py | 44 ++++++++++++++++++- src/Buffer.cpp | 4 +- src/BufferParams.cpp | 18 ++++++++ src/BufferParams.h | 4 ++ src/LaTeXFeatures.cpp | 9 +++- src/frontends/qt4/GuiDocument.cpp | 46 ++++++++++++++++++++ src/frontends/qt4/GuiDocument.h | 2 + src/frontends/qt4/ui/ColorUi.ui | 70 ++++++++++++++++++++++++++++++- 9 files changed, 197 insertions(+), 6 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 31237f7828..ee67835fb1 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -7,12 +7,16 @@ The good example would be 2010-01-10 entry. ----------------------- +2010-04-03 Uwe Stöhr + * Format incremented to 384: support to specify a document-wide + font color: new buffer parameter \fontcolor + 2010-03-31 Uwe Stöhr * Format incremented to 383: support for Turkmen 2010-03-31 Uwe Stöhr * Format incremented to 382: support to change the font color - for greyed-out notes: new parameter \notefontcolor + for greyed-out notes: new buffer parameter \notefontcolor 2010-03-28: Vincent van Ravesteijn * Format incremented to 381: support for new parameters diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 39f118874b..b446a5569c 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -1393,6 +1393,44 @@ def revert_turkmen(document): j = j + 1 +def revert_fontcolor(document): + " Reverts font color to preamble code " + i = 0 + colorcode = "" + while True: + i = find_token(document.header, "\\fontcolor", i) + if i == -1: + return + colorcode = get_value(document.header, '\\fontcolor', 0) + del document.header[i] + # don't clutter the preamble if backgroundcolor is not set + if colorcode == "#000000": + continue + # the color code is in the form #rrggbb where every character denotes a hex number + # convert the string to an int + red = string.atoi(colorcode[1:3],16) + # we want the output "0.5" for the value "127" therefore add here + if red != 0: + red = red + 1 + redout = float(red) / 256 + green = string.atoi(colorcode[3:5],16) + if green != 0: + green = green + 1 + greenout = float(green) / 256 + blue = string.atoi(colorcode[5:7],16) + if blue != 0: + blue = blue + 1 + blueout = float(blue) / 256 + # write the preamble + insert_to_preamble(0, document, + '% Commands inserted by lyx2lyx to set the font color\n' + + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n' + + '\\definecolor{document_fontcolor}{rgb}{' + + str(redout) + ', ' + str(greenout) + + ', ' + str(blueout) + '}\n' + + '\\color{document_fontcolor}\n') + + ## # Conversion hub # @@ -1435,10 +1473,12 @@ convert = [[346, []], [380, []], [381, []], [382, []], - [383, []] + [383, []], + [384, []] ] -revert = [[382, [revert_turkmen]], +revert = [[383, [revert_fontcolor]], + [382, [revert_turkmen]], [381, [revert_notefontcolor]], [380, [revert_equalspacing_xymatrix]], [379, [revert_inset_preview]], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 646cd7616a..f5f11e6991 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -126,7 +126,7 @@ namespace { // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -int const LYX_FORMAT = 383; // uwestoehr: support for Turkmen +int const LYX_FORMAT = 384; // uwestoehr: support for document-wide font color typedef map DepClean; typedef map > RefCache; @@ -668,6 +668,8 @@ int Buffer::readHeader(Lexer & lex) params().pdfoptions().clear(); params().indiceslist().clear(); params().backgroundcolor = lyx::rgbFromHexName("#ffffff"); + params().fontcolor = lyx::rgbFromHexName("#000000"); + params().isfontcolor = false; params().notefontcolor = lyx::rgbFromHexName("#cccccc"); for (int i = 0; i < 4; ++i) { diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 480ab941c2..0bdee62716 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -369,6 +369,9 @@ BufferParams::BufferParams() suppress_date = false; // white is equal to no background color backgroundcolor = lyx::rgbFromHexName("#ffffff"); + // no color is the default (black) + fontcolor = lyx::rgbFromHexName("#000000"); + isfontcolor = false; // light gray is the default font color for greyed-out notes notefontcolor = lyx::rgbFromHexName("#cccccc"); compressed = lyxrc.save_compressed; @@ -723,6 +726,10 @@ string BufferParams::readToken(Lexer & lex, string const & token, } else if (token == "\\backgroundcolor") { lex.eatLine(); backgroundcolor = lyx::rgbFromHexName(lex.getString()); + } else if (token == "\\fontcolor") { + lex.eatLine(); + fontcolor = lyx::rgbFromHexName(lex.getString()); + isfontcolor = true; } else if (token == "\\notefontcolor") { lex.eatLine(); string color = lex.getString(); @@ -921,6 +928,8 @@ void BufferParams::writeFile(ostream & os) const << '\n'; if (backgroundcolor != lyx::rgbFromHexName("#ffffff")) os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n'; + if (isfontcolor == true) + os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n'; if (notefontcolor != lyx::rgbFromHexName("#cccccc")) os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n'; @@ -1454,6 +1463,15 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, features.require("pagecolor"); } + // only output when the font color is not black + if (isfontcolor == true) { + // only require color here, the font color will be defined + // in LaTeXFeatures.cpp to avoid interferences with the LaTeX + // package pdfpages + features.require("color"); + features.require("fontcolor"); + } + // Only if class has a ToC hierarchy if (tclass.hasTocLevels()) { if (secnumdepth != tclass.secnumdepth()) { diff --git a/src/BufferParams.h b/src/BufferParams.h index cfea374e1b..cd5e96afd6 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -286,6 +286,10 @@ public: /// RGBColor backgroundcolor; /// + RGBColor fontcolor; + /// + bool isfontcolor; + /// RGBColor notefontcolor; /// \param index should lie in the range 0 <= \c index <= 3. Bullet & temp_bullet(size_type index); diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 8f78e02d1a..f4a8456630 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -590,11 +590,18 @@ string const LaTeXFeatures::getColorOptions() const colors << "\\pagecolor{page_backgroundcolor}\n"; } + if (mustProvide("fontcolor")) { + colors << "\\definecolor{document_fontcolor}{rgb}{"; + colors << outputLaTeXColor(params_.fontcolor) << "}\n"; + // set the color + colors << "\\color{document_fontcolor}\n"; + } + if (mustProvide("lyxgreyedout")) { colors << "\\definecolor{note_fontcolor}{rgb}{"; colors << outputLaTeXColor(params_.notefontcolor) << "}\n"; // the color will be set together with the definition of - // the lyxgreyedout environment (lyxgreyedout_def) + // the lyxgreyedout environment (see lyxgreyedout_def) } return colors.str(); diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 40f2027636..035c131983 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -178,6 +178,8 @@ vector > pagestyles; namespace lyx { RGBColor set_backgroundcolor; +RGBColor set_fontcolor; +bool is_fontcolor; RGBColor set_notefontcolor; namespace { @@ -874,6 +876,10 @@ GuiDocument::GuiDocument(GuiView & lv) // color colorModule = new UiWidget; + connect(colorModule->fontColorPB, SIGNAL(clicked()), + this, SLOT(changeFontColor())); + connect(colorModule->delFontColorTB, SIGNAL(clicked()), + this, SLOT(deleteFontColor())); connect(colorModule->noteFontColorPB, SIGNAL(clicked()), this, SLOT(changeNoteFontColor())); connect(colorModule->delNoteFontColorTB, SIGNAL(clicked()), @@ -1373,6 +1379,36 @@ void GuiDocument::deleteBackgroundColor() } +void GuiDocument::changeFontColor() +{ + QColor const & newColor = QColorDialog::getColor( + rgb2qcolor(set_fontcolor), asQWidget()); + if (!newColor.isValid()) + return; + // set the button color and text + colorModule->fontColorPB->setStyleSheet( + colorButtonStyleSheet(newColor)); + colorModule->fontColorPB->setText(toqstr("Change...")); + // save color + set_fontcolor = rgbFromHexName(fromqstr(newColor.name())); + is_fontcolor = true; + changed(); +} + + +void GuiDocument::deleteFontColor() +{ + // set the button color back to default by setting an epmty StyleSheet + colorModule->fontColorPB->setStyleSheet(QLatin1String("")); + // change button text + colorModule->fontColorPB->setText(toqstr("Default...")); + // save default color (black) + set_fontcolor = rgbFromHexName("#000000"); + is_fontcolor = false; + changed(); +} + + void GuiDocument::changeNoteFontColor() { QColor const & newColor = QColorDialog::getColor( @@ -2006,6 +2042,8 @@ void GuiDocument::applyView() //color bp_.backgroundcolor = set_backgroundcolor; + bp_.fontcolor = set_fontcolor; + bp_.isfontcolor = is_fontcolor; bp_.notefontcolor = set_notefontcolor; // numbering @@ -2391,9 +2429,17 @@ void GuiDocument::paramsToDialog() langModule->otherencodingRB->setChecked(!default_enc); //color + if (bp_.isfontcolor) { + colorModule->fontColorPB->setStyleSheet( + colorButtonStyleSheet(rgb2qcolor(bp_.fontcolor))); + } + set_fontcolor = bp_.fontcolor; + is_fontcolor = bp_.isfontcolor; + colorModule->noteFontColorPB->setStyleSheet( colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor))); set_notefontcolor = bp_.notefontcolor; + colorModule->backgroundPB->setStyleSheet( colorButtonStyleSheet(rgb2qcolor(bp_.backgroundcolor))); set_backgroundcolor = bp_.backgroundcolor; diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index a24eeccbe9..410b6b77bf 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -109,6 +109,8 @@ private Q_SLOTS: void modulesChanged(); void changeBackgroundColor(); void deleteBackgroundColor(); + void changeFontColor(); + void deleteFontColor(); void changeNoteFontColor(); void deleteNoteFontColor(); void xetexChanged(bool); diff --git a/src/frontends/qt4/ui/ColorUi.ui b/src/frontends/qt4/ui/ColorUi.ui index 2c3554955e..17208af729 100644 --- a/src/frontends/qt4/ui/ColorUi.ui +++ b/src/frontends/qt4/ui/ColorUi.ui @@ -29,14 +29,82 @@ + + + Font color: + + + fontColorPB + + + + + + + + + + 16777215 + 16777215 + + + + Click to change the color + + + Default... + + + + + + + + 23 + 23 + + + + Revert the color to the default + + + R&eset + + + Qt::ToolButtonTextOnly + + + Qt::LeftArrow + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + Font color for greyed-out notes: + + fontColorPB + - + -- 2.39.2