From 33978c0b1b0f137faec3ba96b0d053baa8af51f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20St=C3=B6hr?= Date: Wed, 31 Mar 2010 00:46:50 +0000 Subject: [PATCH] fileformat change: - support to change the greyed-out note font color (fixes #3865) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33962 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 4 ++ lib/layouts/stdinsets.inc | 3 ++ lib/lyx2lyx/lyx_2_0.py | 44 +++++++++++++++++++- src/Buffer.cpp | 3 +- src/BufferParams.cpp | 10 +++++ src/BufferParams.h | 2 + src/Color.cpp | 1 + src/ColorCode.h | 2 + src/LaTeXFeatures.cpp | 19 ++++++--- src/frontends/qt4/GuiDocument.cpp | 35 ++++++++++++++++ src/frontends/qt4/GuiDocument.h | 2 + src/frontends/qt4/GuiPrefs.cpp | 5 ++- src/frontends/qt4/ui/FontUi.ui | 69 ++++++++++++++++++++++++++++++- 13 files changed, 188 insertions(+), 11 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index c20bd894f4..169617a166 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,10 @@ LyX file-format changes ----------------------- +2010-03-31 Uwe Stöhr + * Format incremented to 382: support to change the font color + for greyed-out notes + 2010-03-28: Vincent van Ravesteijn * Format incremented to 381: support for new parameters for \xymatrix: \xymatrix@!0, \xymatrix!R and \xymatrix!C. diff --git a/lib/layouts/stdinsets.inc b/lib/layouts/stdinsets.inc index 5b005ae797..852eccbe21 100644 --- a/lib/layouts/stdinsets.inc +++ b/lib/layouts/stdinsets.inc @@ -160,6 +160,9 @@ InsetLayout Note:Greyedout LatexType environment LatexName lyxgreyedout BgColor greyedoutbg + Font + Color greyedouttext + EndFont LabelFont Color greyedout Size Small diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index 3392fec98f..d1f4620538 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -1338,6 +1338,44 @@ def revert_equalspacing_xymatrix(document): if has_equal_spacing and not has_preamble: add_to_preamble(document, ['\\usepackage[all]{xy}']) + +def revert_notefontcolor(document): + " Reverts greyed-out note font color to preamble code " + i = 0 + colorcode = "" + while True: + i = find_token(document.header, "\\notefontcolor", i) + if i == -1: + return + colorcode = get_value(document.header, '\\notefontcolor', 0) + del document.header[i] + # 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 increment 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' + '% for greyed-out notes\n' + + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n' + + '\\definecolor{note_fontcolor}{rgb}{' + + str(redout) + ', ' + str(greenout) + + ', ' + str(blueout) + '}\n' + + '\\renewenvironment{lyxgreyedout}\n' + + ' {\\textcolor{note_fontcolor}\\bgroup}{\\egroup}\n') + + ## # Conversion hub # @@ -1378,10 +1416,12 @@ convert = [[346, []], [378, []], [379, [convert_math_output]], [380, []], - [381, []] + [381, []], + [382, []] ] -revert = [[380, [revert_equalspacing_xymatrix]], +revert = [[381, [revert_notefontcolor]], + [380, [revert_equalspacing_xymatrix]], [379, [revert_inset_preview]], [378, [revert_math_output]], [377, []], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 1a47fdf5bd..6e8c480a48 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 = 381; // vfr: new parameters for xymatrix +int const LYX_FORMAT = 382; // uwestoehr: support to change font color for greyed-out notes typedef map DepClean; typedef map > RefCache; @@ -668,6 +668,7 @@ int Buffer::readHeader(Lexer & lex) params().pdfoptions().clear(); params().indiceslist().clear(); params().backgroundcolor = lyx::rgbFromHexName("#ffffff"); + params().notefontcolor = lyx::rgbFromHexName("#cccccc"); for (int i = 0; i < 4; ++i) { params().user_defined_bullet(i) = ITEMIZE_DEFAULTS[i]; diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 04d035481f..bd43f2819f 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -369,6 +369,8 @@ BufferParams::BufferParams() suppress_date = false; // white is equal to no background color backgroundcolor = lyx::rgbFromHexName("#ffffff"); + // light gray is the default font color for greyed-out notes + notefontcolor = lyx::rgbFromHexName("#cccccc"); compressed = lyxrc.save_compressed; for (int iter = 0; iter < 4; ++iter) { user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter]; @@ -721,6 +723,12 @@ string BufferParams::readToken(Lexer & lex, string const & token, } else if (token == "\\backgroundcolor") { lex.eatLine(); backgroundcolor = lyx::rgbFromHexName(lex.getString()); + } else if (token == "\\notefontcolor") { + lex.eatLine(); + string color = lex.getString(); + notefontcolor = lyx::rgbFromHexName(color); + // set the font color within LyX + lcolor.setColor(Color_greyedouttext, color); } else if (token == "\\paperwidth") { lex >> paperwidth; } else if (token == "\\paperheight") { @@ -913,6 +921,8 @@ void BufferParams::writeFile(ostream & os) const << '\n'; if (backgroundcolor != lyx::rgbFromHexName("#ffffff")) os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n'; + if (notefontcolor != lyx::rgbFromHexName("#cccccc")) + os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n'; BranchList::const_iterator it = branchlist().begin(); BranchList::const_iterator end = branchlist().end(); diff --git a/src/BufferParams.h b/src/BufferParams.h index c1992aac59..561a4f51a1 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -288,6 +288,8 @@ public: std::string pagestyle; /// RGBColor backgroundcolor; + /// + RGBColor notefontcolor; /// \param index should lie in the range 0 <= \c index <= 3. Bullet & temp_bullet(size_type index); Bullet const & temp_bullet(size_type index) const; diff --git a/src/Color.cpp b/src/Color.cpp index f2b5965e18..e11311ad8e 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -181,6 +181,7 @@ ColorSet::ColorSet() { Color_commentlabel, N_("comment label"), "comment", "magenta", "comment" }, { Color_commentbg, N_("comment background"), "commentbg", "linen", "commentbg" }, { Color_greyedoutlabel, N_("greyedout inset label"), "greyedout", "#ff0080", "greyedout" }, + { Color_greyedouttext, N_("greyedout inset text"), "greyedouttext", grey80, "greyedouttext" }, { Color_greyedoutbg, N_("greyedout inset background"), "greyedoutbg", "linen", "greyedoutbg" }, { Color_phantomtext, N_("phantom inset text"), "phantomtext", "#7f7f7f", "phantomtext" }, { Color_shadedbg, N_("shaded box"), "shaded", "#ff0000", "shaded" }, diff --git a/src/ColorCode.h b/src/ColorCode.h index 4b1b78cab2..4286ae54ec 100644 --- a/src/ColorCode.h +++ b/src/ColorCode.h @@ -65,6 +65,8 @@ enum ColorCode Color_commentbg, /// Label color for greyedout insets Color_greyedoutlabel, + /// Color for greyedout inset text + Color_greyedouttext, /// Background color of greyedout inset Color_greyedoutbg, /// Background color of shaded box diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 35fbe1933a..8f78e02d1a 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -160,7 +160,7 @@ static docstring const tabularnewline_def = from_ascii( static docstring const lyxgreyedout_def = from_ascii( "%% The greyedout annotation environment\n" - "\\newenvironment{lyxgreyedout}{\\textcolor[gray]{0.8}\\bgroup}{\\egroup}\n"); + "\\newenvironment{lyxgreyedout}{\\textcolor{note_fontcolor}\\bgroup}{\\egroup}\n"); // We want to omit the file extension for includegraphics, but this does not // work when the filename contains other dots. @@ -580,16 +580,23 @@ string const LaTeXFeatures::getColorOptions() const if (mustProvide("pdfcolmk")) colors << "\\usepackage{pdfcolmk}\n"; + // the following 3 color commands must be set after color + // is loaded and before pdfpages, therefore add the command + // here define the set color if (mustProvide("pagecolor")) { - // the \pagecolor command must be set after color is loaded and - // before pdfpages, therefore add the command here - // define the set color colors << "\\definecolor{page_backgroundcolor}{rgb}{"; colors << outputLaTeXColor(params_.backgroundcolor) << "}\n"; // set the page color colors << "\\pagecolor{page_backgroundcolor}\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) + } + return colors.str(); } @@ -885,7 +892,9 @@ docstring const LaTeXFeatures::getMacros() const if (mustProvide("NeedTabularnewline")) macros << tabularnewline_def; - // greyedout environment (note inset) + // greyed-out environment (note inset) + // the color is specified in the routine + // getColorOptions() to avoid LaTeX-package clashes if (mustProvide("lyxgreyedout")) macros << lyxgreyedout_def; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index dac72fe2ae..37198db827 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -178,6 +178,7 @@ vector > pagestyles; namespace lyx { RGBColor set_backgroundcolor; +RGBColor set_notefontcolor; namespace { // used when sorting the textclass list. @@ -682,6 +683,10 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(change_adaptor())); connect(fontModule->fontOsfCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(fontModule->noteFontColorPB, SIGNAL(clicked()), + this, SLOT(changeNoteFontColor())); + connect(fontModule->delNoteFontColorTB, SIGNAL(clicked()), + this, SLOT(deleteNoteFontColor())); updateFontlist(); @@ -1349,6 +1354,32 @@ void GuiDocument::deleteBackgroundColor() } +void GuiDocument::changeNoteFontColor() +{ + QColor const & newColor = QColorDialog::getColor( + rgb2qcolor(set_notefontcolor), asQWidget()); + if (!newColor.isValid()) + return; + // set the button color + fontModule->noteFontColorPB->setStyleSheet( + colorButtonStyleSheet(newColor)); + // save color + set_notefontcolor = rgbFromHexName(fromqstr(newColor.name())); + changed(); +} + + +void GuiDocument::deleteNoteFontColor() +{ + // set the button color back to light gray + fontModule->noteFontColorPB->setStyleSheet( + colorButtonStyleSheet(QColor(204, 204, 204, 255))); + // save light gray as the set color + set_notefontcolor = rgbFromHexName("#cccccc"); + changed(); +} + + void GuiDocument::xetexChanged(bool xetex) { updateFontlist(); @@ -2210,6 +2241,7 @@ void GuiDocument::applyView() bp_.orientation = ORIENTATION_PORTRAIT; bp_.backgroundcolor = set_backgroundcolor; + bp_.notefontcolor = set_notefontcolor; // margins bp_.use_geometry = !marginsModule->marginCB->isChecked() @@ -2591,6 +2623,9 @@ void GuiDocument::paramsToDialog() fontModule->fontOsfCB->setChecked(bp_.fontsOSF); fontModule->scaleSansSB->setValue(bp_.fontsSansScale); fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale); + fontModule->noteFontColorPB->setStyleSheet( + colorButtonStyleSheet(rgb2qcolor(bp_.notefontcolor))); + set_notefontcolor = bp_.notefontcolor; int nn = findToken(GuiDocument::fontfamilies, bp_.fontsDefaultFamily); if (nn >= 0) diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 537dce2749..64ce15aaa9 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -111,6 +111,8 @@ private Q_SLOTS: void modulesChanged(); void changeBackgroundColor(); void deleteBackgroundColor(); + void changeNoteFontColor(); + void deleteNoteFontColor(); void xetexChanged(bool); void branchesRename(docstring const &, docstring const &); private: diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index f2a40b2641..56b0beba3c 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1005,7 +1005,8 @@ PrefColors::PrefColors(GuiPreferences * form) || lc == Color_magenta || lc == Color_yellow || lc == Color_inherit - || lc == Color_ignore) continue; + || lc == Color_ignore + || lc == Color_greyedouttext) continue; lcolors_.push_back(lc); } @@ -1013,7 +1014,7 @@ PrefColors::PrefColors(GuiPreferences * form) vector::const_iterator cit = lcolors_.begin(); vector::const_iterator const end = lcolors_.end(); for (; cit != end; ++cit) { - (void) new QListWidgetItem(QIcon(icon), + (void) new QListWidgetItem(QIcon(icon), toqstr(lcolor.getGUIName(*cit)), lyxObjectsLW); } curcolors_.resize(lcolors_.size()); diff --git a/src/frontends/qt4/ui/FontUi.ui b/src/frontends/qt4/ui/FontUi.ui index e5066f952e..7ac625dbbf 100644 --- a/src/frontends/qt4/ui/FontUi.ui +++ b/src/frontends/qt4/ui/FontUi.ui @@ -201,7 +201,74 @@ - + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Font color for</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">greyed-out notes:</span></p></body></html> + + + + + + + + + + 16777215 + 16777215 + + + + Click to change the color + + + &Change... + + + + + + + + 23 + 23 + + + + Revert the color to the default + + + R&eset + + + Qt::ToolButtonTextOnly + + + Qt::LeftArrow + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + Qt::Vertical