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
This commit is contained in:
Uwe Stöhr 2010-04-08 00:14:08 +00:00
parent f9fa189e02
commit 84a2af2edb
10 changed files with 180 additions and 35 deletions

View File

@ -7,6 +7,10 @@ The good example would be 2010-01-10 entry.
-----------------------
2010-04-08 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 385: support to change the background color
for shaded boxes: new buffer parameter \boxbgcolor
2010-04-03 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 384: support to specify a document-wide
font color: new buffer parameter \fontcolor

View File

@ -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]],

View File

@ -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<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > 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];

View File

@ -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();

View File

@ -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;

View File

@ -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";

View File

@ -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();

View File

@ -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:

View File

@ -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);
}

View File

@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>406</width>
<height>275</height>
<height>322</height>
</rect>
</property>
<property name="contextMenuPolicy">
@ -18,13 +18,7 @@
<property name="toolTip">
<string/>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>11</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGroupBox" name="fontcolorGB">
<property name="title">
@ -193,17 +187,11 @@
<property name="flat">
<bool>true</bool>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>11</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="backgroundColorLA">
<property name="text">
<string>Background color:</string>
<string>Page:</string>
</property>
<property name="buddy">
<cstring>backgroundPB</cstring>
@ -271,6 +259,77 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="boxBackgroundColorLA">
<property name="text">
<string>Shaded boxes:</string>
</property>
<property name="buddy">
<cstring>backgroundPB</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="_2">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>11</number>
</property>
<item>
<widget class="QPushButton" name="boxBackgroundPB">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Click to change the color</string>
</property>
<property name="text">
<string>&amp;Change...</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="delBoxBackgroundTB">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="toolTip">
<string>Revert the color to the default</string>
</property>
<property name="text">
<string>R&amp;eset</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>