mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Branch: Implement separate static colors in dark mode
Set colors now apply to the active mode only. Matching reversed colors are produced for the other mode if no color is assigned yet. File format change.
This commit is contained in:
parent
81c19502c1
commit
7b762ee950
@ -7,6 +7,10 @@ changes happened in particular if possible. A good example would be
|
||||
|
||||
-----------------------
|
||||
|
||||
2021-01-19 Jürgen Spitzmüller <spitz@lyx.org>
|
||||
* Format incremented to 604: Branch colors now take two values:
|
||||
\color lightmode darkmode
|
||||
|
||||
2021-01-18 Jürgen Spitzmüller <spitz@lyx.org>
|
||||
* Format incremented to 603: New InsetGraphics param darkModeSensitive
|
||||
This advises LyX to revert colors in dark mode.
|
||||
|
@ -4086,6 +4086,26 @@ def revert_darkmode_graphics(document):
|
||||
i += 1
|
||||
|
||||
|
||||
def revert_branch_darkcols(document):
|
||||
" Revert dark branch colors "
|
||||
|
||||
i = 0
|
||||
while True:
|
||||
i = find_token(document.header, "\\branch", i)
|
||||
if i == -1:
|
||||
break
|
||||
j = find_token(document.header, "\\end_branch", i)
|
||||
if j == -1:
|
||||
document.warning("Malformed LyX document. Can't find end of branch definition!")
|
||||
break
|
||||
k = find_token(document.header, "\\color", i, j)
|
||||
if k != -1:
|
||||
m = re.search('\\\\color (\S+) (\S+)', document.header[k])
|
||||
if m:
|
||||
document.header[k] = "\\color " + m.group(1)
|
||||
i += 1
|
||||
|
||||
|
||||
##
|
||||
# Conversion hub
|
||||
#
|
||||
@ -4150,10 +4170,12 @@ convert = [
|
||||
[600, []],
|
||||
[601, [convert_math_refs]],
|
||||
[602, [convert_branch_colors]],
|
||||
[603, []]
|
||||
[603, []],
|
||||
[604, []]
|
||||
]
|
||||
|
||||
revert = [[602, [revert_darkmode_graphics]],
|
||||
revert = [[603, [revert_branch_darkcols]],
|
||||
[602, [revert_darkmode_graphics]],
|
||||
[601, [revert_branch_colors]],
|
||||
[600, []],
|
||||
[599, [revert_math_refs]],
|
||||
|
@ -29,7 +29,8 @@ namespace lyx {
|
||||
Branch::Branch()
|
||||
: selected_(false), filenameSuffix_(false)
|
||||
{
|
||||
color_ = "background";
|
||||
lmcolor_ = "background";
|
||||
dmcolor_ = "background";
|
||||
}
|
||||
|
||||
|
||||
@ -74,23 +75,57 @@ void Branch::setFileNameSuffix(bool b)
|
||||
|
||||
string const & Branch::color() const
|
||||
{
|
||||
return color_;
|
||||
return (theApp() && theApp()->isInDarkMode())
|
||||
? dmcolor_ : lmcolor_;
|
||||
}
|
||||
|
||||
|
||||
void Branch::setColor(string const & str)
|
||||
string const & Branch::lightModeColor() const
|
||||
{
|
||||
color_ = str;
|
||||
return lmcolor_;
|
||||
}
|
||||
|
||||
|
||||
string const & Branch::darkModeColor() const
|
||||
{
|
||||
return dmcolor_;
|
||||
}
|
||||
|
||||
|
||||
void Branch::setColor(string const & col)
|
||||
{
|
||||
if (theApp() && theApp()->isInDarkMode())
|
||||
setColors(string(), col);
|
||||
else
|
||||
setColors(col);
|
||||
}
|
||||
|
||||
|
||||
void Branch::setColors(string const & lmcol, string const & dmcol)
|
||||
{
|
||||
if (lmcol.empty() && lmcolor_ == "background" && support::prefixIs(dmcol, "#"))
|
||||
lmcolor_ = X11hexname(inverseRGBColor(rgbFromHexName(dmcol)));
|
||||
else if (!lmcol.empty())
|
||||
lmcolor_ = lmcol;
|
||||
if (dmcol.empty() && dmcolor_ == "background" && support::prefixIs(lmcol, "#"))
|
||||
dmcolor_ = X11hexname(inverseRGBColor(rgbFromHexName(lmcol)));
|
||||
else if (!dmcol.empty())
|
||||
dmcolor_ = dmcol;
|
||||
|
||||
// Update the Color table
|
||||
string color = str;
|
||||
bool darkmode = theApp() ? theApp()->isInDarkMode() : false;
|
||||
if (color == "none")
|
||||
color = lcolor.getX11HexName(Color_background, darkmode);
|
||||
else if (color.size() != 7 || color[0] != '#')
|
||||
color = lcolor.getX11HexName(lcolor.getFromLyXName(color), darkmode);
|
||||
string lmcolor = lmcolor_;
|
||||
string dmcolor = dmcolor_;
|
||||
if (lmcolor == "none")
|
||||
lmcolor = lcolor.getX11HexName(Color_background);
|
||||
else if (lmcolor.size() != 7 || lmcolor[0] != '#')
|
||||
lmcolor = lcolor.getX11HexName(lcolor.getFromLyXName(lmcolor));
|
||||
if (dmcolor == "none")
|
||||
lmcolor = lcolor.getX11HexName(Color_background, true);
|
||||
else if (dmcolor.size() != 7 || dmcolor[0] != '#')
|
||||
dmcolor = lcolor.getX11HexName(lcolor.getFromLyXName(dmcolor), true);
|
||||
|
||||
// FIXME UNICODE
|
||||
lcolor.setColor(to_utf8(branch_), color);
|
||||
lcolor.setColor(to_utf8(branch_), lmcolor, dmcolor);
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,13 +62,21 @@ public:
|
||||
void setFileNameSuffix(bool);
|
||||
///
|
||||
std::string const & color() const;
|
||||
///
|
||||
std::string const & lightModeColor() const;
|
||||
///
|
||||
std::string const & darkModeColor() const;
|
||||
/**
|
||||
* Set color from a hexcolor string "#rrggbb" or a lyx color name.
|
||||
* Set background color from a hexcolor string "#rrggbb" or a lyx color name.
|
||||
* Use Color:background if the string is no valid color.
|
||||
* This ensures compatibility with LyX 1.4.0 that had the symbolic
|
||||
* color "none" that was displayed as Color:background.
|
||||
* This sets the dark color if in dark mode, else the light color.
|
||||
*/
|
||||
void setColor(std::string const &);
|
||||
void setColor(std::string const & color);
|
||||
/// Set dark and light background colors
|
||||
void setColors(std::string const & color,
|
||||
std::string const & dmcolor = std::string());
|
||||
|
||||
private:
|
||||
///
|
||||
@ -77,8 +85,10 @@ private:
|
||||
bool selected_;
|
||||
///
|
||||
bool filenameSuffix_;
|
||||
///
|
||||
std::string color_;
|
||||
/// light mode background color
|
||||
std::string lmcolor_;
|
||||
/// dark mode background color
|
||||
std::string dmcolor_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -990,9 +990,13 @@ string BufferParams::readToken(Lexer & lex, string const & token,
|
||||
}
|
||||
if (tok == "\\color") {
|
||||
lex.eatLine();
|
||||
string color = lex.getString();
|
||||
vector<string> const colors = getVectorFromString(lex.getString(), " ");
|
||||
string const lmcolor = colors.front();
|
||||
string dmcolor;
|
||||
if (colors.size() > 1)
|
||||
dmcolor = colors.back();
|
||||
if (branch_ptr)
|
||||
branch_ptr->setColor(color);
|
||||
branch_ptr->setColors(lmcolor, dmcolor);
|
||||
}
|
||||
}
|
||||
} else if (token == "\\index") {
|
||||
@ -1382,7 +1386,7 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
|
||||
os << "\\branch " << to_utf8(br.branch())
|
||||
<< "\n\\selected " << br.isSelected()
|
||||
<< "\n\\filename_suffix " << br.hasFileNameSuffix()
|
||||
<< "\n\\color " << br.color()
|
||||
<< "\n\\color " << br.lightModeColor() << " " << br.darkModeColor()
|
||||
<< "\n\\end_branch"
|
||||
<< "\n";
|
||||
}
|
||||
|
@ -153,6 +153,16 @@ RGBColor const RGBColorFromLaTeX(string const & color)
|
||||
}
|
||||
|
||||
|
||||
RGBColor const inverseRGBColor(RGBColor color)
|
||||
{
|
||||
color.r = 255 - color.r;
|
||||
color.g = 255 - color.g;
|
||||
color.b = 255 - color.b;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
Color::Color(ColorCode base_color) : baseColor(base_color),
|
||||
mergeColor(Color_ignore)
|
||||
{}
|
||||
|
@ -64,6 +64,8 @@ RGBColor rgbFromHexName(std::string const & x11hexname);
|
||||
std::string const outputLaTeXColor(RGBColor const & color);
|
||||
/// Inverse of outputLaTeXColor
|
||||
RGBColor const RGBColorFromLaTeX(std::string const & color);
|
||||
/// Inverted color
|
||||
RGBColor const inverseRGBColor(RGBColor color);
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
|
||||
|
||||
// Do not remove the comment below, so we get merge conflict in
|
||||
// independent branches. Instead add your own.
|
||||
#define LYX_FORMAT_LYX 603 // spitz: InsetGraphicsParam darkModeSensitive
|
||||
#define LYX_FORMAT_TEX2LYX 603
|
||||
#define LYX_FORMAT_LYX 604 // spitz: separate dark branch color
|
||||
#define LYX_FORMAT_TEX2LYX 604
|
||||
|
||||
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
|
||||
#ifndef _MSC_VER
|
||||
|
Loading…
Reference in New Issue
Block a user