From 84a2af2edb4bea7224b392a645623c4b10b3db47 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20St=C3=B6hr?= Date: Thu, 8 Apr 2010 00:14:08 +0000 Subject: [PATCH] fileformat change: support to specify the background color of shaded boxes - new buffer parameter \boxbgcolor (I'm still working on the remaining issue #6626 as this affect not only this feature.) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34083 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 4 ++ lib/lyx2lyx/lyx_2_0.py | 41 +++++++++++++- src/Buffer.cpp | 3 +- src/BufferParams.cpp | 10 ++++ src/BufferParams.h | 2 + src/LaTeXFeatures.cpp | 23 +++----- src/frontends/qt4/GuiDocument.cpp | 36 ++++++++++++ src/frontends/qt4/GuiDocument.h | 2 + src/frontends/qt4/GuiPrefs.cpp | 3 +- src/frontends/qt4/ui/ColorUi.ui | 91 +++++++++++++++++++++++++------ 10 files changed, 180 insertions(+), 35 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index ee67835fb1..49b2cbf7a6 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -7,6 +7,10 @@ The good example would be 2010-01-10 entry. ----------------------- +2010-04-08 Uwe Stöhr + * Format incremented to 385: support to change the background color + for shaded boxes: new buffer parameter \boxbgcolor + 2010-04-03 Uwe Stöhr * Format incremented to 384: support to specify a document-wide font color: new buffer parameter \fontcolor diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index b446a5569c..d7f00c8e80 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -1431,6 +1431,41 @@ def revert_fontcolor(document): + '\\color{document_fontcolor}\n') +def revert_shadedboxcolor(document): + " Reverts shaded box color to preamble code " + i = 0 + colorcode = "" + while True: + i = find_token(document.header, "\\boxbgcolor", i) + if i == -1: + return + colorcode = get_value(document.header, '\\boxbgcolor', 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 color\n' + '% of boxes with shaded background\n' + + '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n' + + '\\definecolor{shadecolor}{rgb}{' + + str(redout) + ', ' + str(greenout) + + ', ' + str(blueout) + '}\n') + + ## # Conversion hub # @@ -1474,10 +1509,12 @@ convert = [[346, []], [381, []], [382, []], [383, []], - [384, []] + [384, []], + [385, []] ] -revert = [[383, [revert_fontcolor]], +revert = [[384, [revert_shadedboxcolor]], + [383, [revert_fontcolor]], [382, [revert_turkmen]], [381, [revert_notefontcolor]], [380, [revert_equalspacing_xymatrix]], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 4a278219e7..cc7eae04f4 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 = 384; // uwestoehr: support for document-wide font color +int const LYX_FORMAT = 385; // uwestoehr: support to change the shaded box color typedef map DepClean; typedef map > RefCache; @@ -672,6 +672,7 @@ int Buffer::readHeader(Lexer & lex) params().fontcolor = lyx::rgbFromHexName("#000000"); params().isfontcolor = false; params().notefontcolor = lyx::rgbFromHexName("#cccccc"); + params().boxbgcolor = lyx::rgbFromHexName("#ff0000"); 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 8f6d7fc535..dcb9fa6579 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -375,6 +375,7 @@ BufferParams::BufferParams() isfontcolor = false; // light gray is the default font color for greyed-out notes notefontcolor = lyx::rgbFromHexName("#cccccc"); + boxbgcolor = lyx::rgbFromHexName("#ff0000"); compressed = lyxrc.save_compressed; for (int iter = 0; iter < 4; ++iter) { user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter]; @@ -739,6 +740,13 @@ string BufferParams::readToken(Lexer & lex, string const & token, // set the font color within LyX // FIXME: the color is correctly set but later overwritten by the default lcolor.setColor(Color_greyedouttext, color); + } else if (token == "\\boxbgcolor") { + lex.eatLine(); + string color = lex.getString(); + boxbgcolor = lyx::rgbFromHexName(color); + // set the font color within LyX + // FIXME: the color is correctly set but later overwritten by the default + lcolor.setColor(Color_shadedbg, color); } else if (token == "\\paperwidth") { lex >> paperwidth; } else if (token == "\\paperheight") { @@ -935,6 +943,8 @@ void BufferParams::writeFile(ostream & os) const os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n'; if (notefontcolor != lyx::rgbFromHexName("#cccccc")) os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n'; + if (boxbgcolor != lyx::rgbFromHexName("#ff0000")) + os << "\\boxbgcolor " << lyx::X11hexname(boxbgcolor) << '\n'; BranchList::const_iterator it = branchlist().begin(); BranchList::const_iterator end = branchlist().end(); diff --git a/src/BufferParams.h b/src/BufferParams.h index 8ad2e06419..1e8174d12c 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -293,6 +293,8 @@ public: bool isfontcolor; /// RGBColor notefontcolor; + /// + RGBColor boxbgcolor; /// \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/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index f4a8456630..615901f893 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -604,6 +604,13 @@ string const LaTeXFeatures::getColorOptions() const // the lyxgreyedout environment (see lyxgreyedout_def) } + // color for shaded boxes + if (isRequired("framed") && mustProvide("color")) { + colors << "\\definecolor{shadecolor}{rgb}{"; + colors << outputLaTeXColor(params_.boxbgcolor) << "}\n"; + // this color is automatically used by the LaTeX-package "framed" + } + return colors.str(); } @@ -693,21 +700,7 @@ string const LaTeXFeatures::getPackages() const << params_.graphicsDriver << "]{graphicx}\n"; } - // shadecolor for shaded - if (isRequired("framed") && mustProvide("color")) { - RGBColor c = rgbFromHexName(lcolor.getX11Name(Color_shadedbg)); - //255.0 to force conversion to double - //NOTE As Jürgen Spitzmüller pointed out, an alternative would be - //to use the xcolor package instead, and then we can do - // \define{shadcolor}{RGB}... - //and not do any conversion. We'd then need to require xcolor - //in InsetNote::validate(). - int const stmSize = packages.precision(2); - packages << "\\definecolor{shadecolor}{rgb}{" - << c.r / 255.0 << ',' << c.g / 255.0 << ',' << c.b / 255.0 << "}\n"; - packages.precision(stmSize); - } - + // lyxskak.sty --- newer chess support based on skak.sty if (mustProvide("chess")) packages << "\\usepackage[ps,mover]{lyxskak}\n"; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 9678dfc38d..77923128da 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -182,6 +182,7 @@ bool is_backgroundcolor; RGBColor set_fontcolor; bool is_fontcolor; RGBColor set_notefontcolor; +RGBColor set_boxbgcolor; namespace { // used when sorting the textclass list. @@ -889,6 +890,10 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(changeBackgroundColor())); connect(colorModule->delBackgroundTB, SIGNAL(clicked()), this, SLOT(deleteBackgroundColor())); + connect(colorModule->boxBackgroundPB, SIGNAL(clicked()), + this, SLOT(changeBoxBackgroundColor())); + connect(colorModule->delBoxBackgroundTB, SIGNAL(clicked()), + this, SLOT(deleteBoxBackgroundColor())); // numbering @@ -1440,6 +1445,32 @@ void GuiDocument::deleteNoteFontColor() } +void GuiDocument::changeBoxBackgroundColor() +{ + QColor const & newColor = QColorDialog::getColor( + rgb2qcolor(set_boxbgcolor), asQWidget()); + if (!newColor.isValid()) + return; + // set the button color + colorModule->boxBackgroundPB->setStyleSheet( + colorButtonStyleSheet(newColor)); + // save color + set_boxbgcolor = rgbFromHexName(fromqstr(newColor.name())); + changed(); +} + + +void GuiDocument::deleteBoxBackgroundColor() +{ + // set the button color back to red + colorModule->boxBackgroundPB->setStyleSheet( + colorButtonStyleSheet(QColor(Qt::red))); + // save red as the set color + set_boxbgcolor = rgbFromHexName("#ff0000"); + changed(); +} + + void GuiDocument::xetexChanged(bool xetex) { updateFontlist(); @@ -2051,6 +2082,7 @@ void GuiDocument::applyView() bp_.fontcolor = set_fontcolor; bp_.isfontcolor = is_fontcolor; bp_.notefontcolor = set_notefontcolor; + bp_.boxbgcolor = set_boxbgcolor; // numbering if (bp_.documentClass().hasTocLevels()) { @@ -2453,6 +2485,10 @@ void GuiDocument::paramsToDialog() set_backgroundcolor = bp_.backgroundcolor; is_backgroundcolor = bp_.isbackgroundcolor; + colorModule->boxBackgroundPB->setStyleSheet( + colorButtonStyleSheet(rgb2qcolor(bp_.boxbgcolor))); + set_boxbgcolor = bp_.boxbgcolor; + // numbering int const min_toclevel = documentClass().min_toclevel(); int const max_toclevel = documentClass().max_toclevel(); diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 410b6b77bf..d5b70c4afe 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -113,6 +113,8 @@ private Q_SLOTS: void deleteFontColor(); void changeNoteFontColor(); void deleteNoteFontColor(); + void changeBoxBackgroundColor(); + void deleteBoxBackgroundColor(); 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 56b0beba3c..57047f419d 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1006,7 +1006,8 @@ PrefColors::PrefColors(GuiPreferences * form) || lc == Color_yellow || lc == Color_inherit || lc == Color_ignore - || lc == Color_greyedouttext) continue; + || lc == Color_greyedouttext + || lc == Color_shadedbg) continue; lcolors_.push_back(lc); } diff --git a/src/frontends/qt4/ui/ColorUi.ui b/src/frontends/qt4/ui/ColorUi.ui index 85c0a7b1e4..349af578d8 100644 --- a/src/frontends/qt4/ui/ColorUi.ui +++ b/src/frontends/qt4/ui/ColorUi.ui @@ -6,7 +6,7 @@ 0 0 406 - 275 + 322 @@ -18,13 +18,7 @@ - - - 11 - - - 6 - + @@ -193,17 +187,11 @@ true - - - 11 - - - 6 - + - Background color: + Page: backgroundPB @@ -271,6 +259,77 @@ + + + + Shaded boxes: + + + backgroundPB + + + + + + + 6 + + + 11 + + + + + + 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 + + + + + + -- 2.39.2