support for \pagecolor, fileformat change

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29220 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2009-04-11 21:40:11 +00:00
parent 0e8f00dbe1
commit 4d30bc7579
11 changed files with 408 additions and 217 deletions

View File

@ -1,6 +1,9 @@
LyX file-format changes
-----------------------
2009-04-11 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 351: support to set a page background color.
2009-04-06 Jürgen Spitzmüller <spitz@lyx.org>
* Format incremented to 350: new param \default_output_format.

View File

@ -18,7 +18,7 @@
""" Convert files to the file format generated by lyx 2.0"""
import re
import re, string
from parser_tools import find_token, find_end_of, find_tokens, get_value, get_value_string
@ -296,6 +296,41 @@ def revert_outputformat(document):
del document.header[i]
def revert_backgroundcolor(document):
" Reverts backgrund color to preamble code "
i = 0
colorcode = ""
while True:
i = find_token(document.header, "\\backgroundcolor", i)
if i == -1:
return
colorcode = get_value(document.header, '\\backgroundcolor', 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 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 background color\n'
+ '\\@ifundefined{definecolor}{\\usepackage{color}}{}\n'
+ '\\definecolor{page_backgroundcolor}{rgb}{'
+ str(redout) + ', ' + str(greenout)
+ ', ' + str(blueout) + '}\n'
+ '\\pagecolor{page_backgroundcolor}\n')
##
# Conversion hub
#
@ -305,10 +340,12 @@ convert = [[346, []],
[347, []],
[348, []],
[349, []],
[350, []]
[350, []],
[351, []]
]
revert = [[349, [revert_outputformat]],
revert = [[350, [revert_backgroundcolor]],
[349, [revert_outputformat]],
[348, [revert_xetex]],
[347, [revert_phantom, revert_hphantom, revert_vphantom]],
[346, [revert_tabularvalign]],

View File

@ -124,7 +124,7 @@ namespace {
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
int const LYX_FORMAT = 350; // jspitzm: default output format
int const LYX_FORMAT = 351; // uwestoehr: support for page background color
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -356,6 +356,8 @@ BufferParams::BufferParams()
columns = 1;
listings_params = string();
pagestyle = "default";
// white is equal to no background color
backgroundcolor = lyx::rgbFromHexName("#ffffff");
compressed = false;
for (int iter = 0; iter < 4; ++iter) {
user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
@ -600,7 +602,6 @@ string BufferParams::readToken(Lexer & lex, string const & token,
color = lcolor.getX11Name(Color_background);
// FIXME UNICODE
lcolor.setColor(to_utf8(branch), color);
}
}
} else if (token == "\\author") {
@ -613,6 +614,9 @@ string BufferParams::readToken(Lexer & lex, string const & token,
string orient;
lex >> orient;
orientation = paperorientationtranslator().find(orient);
} else if (token == "\\backgroundcolor") {
lex.eatLine();
backgroundcolor = lyx::rgbFromHexName(lex.getString());
} else if (token == "\\paperwidth") {
lex >> paperwidth;
} else if (token == "\\paperheight") {
@ -778,6 +782,7 @@ void BufferParams::writeFile(ostream & os) const
<< "\n\\cite_engine " << citeenginetranslator().find(cite_engine_)
<< "\n\\use_bibtopic " << convert<string>(use_bibtopic)
<< "\n\\paperorientation " << string_orientation[orientation]
<< "\n\\backgroundcolor " << lyx::X11hexname(backgroundcolor)
<< '\n';
BranchList::const_iterator it = branchlist().begin();
@ -1264,6 +1269,15 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
texrow.newline();
}
// only output when the background color is not white
if (backgroundcolor != lyx::rgbFromHexName("#ffffff")) {
// only require color here, the background color will be defined
// in LaTeXFeatures.cpp to avoid interferences with the LaTeX
// package pdfpages
features.require("color");
features.require("pagecolor");
}
// Only if class has a ToC hierarchy
if (tclass.hasTocLevels()) {
if (secnumdepth != tclass.secnumdepth()) {

View File

@ -254,6 +254,8 @@ public:
PageSides sides;
///
std::string pagestyle;
///
RGBColor backgroundcolor;
/// \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

@ -19,6 +19,7 @@
#include "Color.h"
#include "ColorSet.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/gettext.h"
#include "support/lstrings.h"
@ -84,6 +85,28 @@ RGBColor rgbFromHexName(string const & x11hexname)
return c;
}
string const outputLaTeXColor(RGBColor const & color)
{
// this routine returns a LaTeX readable color string in the form
// "red, green, blue" where the colors are a number in the range 0-1
int red = color.r;
int green = color.g;
int blue = color.b;
// the color values are given in the range of 0-255, so to get
// an output of "0.5" for the value 127 we need to do the following
if (red != 0)
++red;
if (green != 0)
++green;
if (blue != 0)
++blue;
string output;
output = convert<string>(float(red) / 256) + ", "
+ convert<string>(float(green) / 256) + ", "
+ convert<string>(float(blue) / 256);
return output;
}
Color::Color(ColorCode base_color) : baseColor(base_color),
mergeColor(Color_ignore)

View File

@ -61,6 +61,7 @@ std::ostream & operator<<(std::ostream & os, Color color);
std::string const X11hexname(RGBColor const & col);
RGBColor rgbFromHexName(std::string const & x11hexname);
std::string const outputLaTeXColor(RGBColor const & color);
} // namespace lyx

View File

@ -545,6 +545,16 @@ string const LaTeXFeatures::getColorOptions() const
if (mustProvide("pdfcolmk"))
colors << "\\usepackage{pdfcolmk}\n";
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";
}
return colors.str();
}

View File

@ -28,6 +28,7 @@
#include "BufferParams.h"
#include "BufferView.h"
#include "Color.h"
#include "ColorCache.h"
#include "Encoding.h"
#include "FloatPlacement.h"
#include "Format.h"
@ -54,6 +55,8 @@
#include "frontends/alert.h"
#include <QAbstractItemModel>
#include <QColor>
#include <QColorDialog>
#include <QCloseEvent>
#include <QFontDatabase>
#include <QScrollBar>
@ -67,6 +70,19 @@
#endif
// a style sheet for buttons
// this is for example used for the background color setting button
static inline QString colorButtonStyleSheet(const QColor &bgColor)
{
if (bgColor.isValid()) {
QString rc = QLatin1String("background:");
rc += bgColor.name();
return rc;
}
return QLatin1String("");
}
using namespace std;
using namespace lyx::support;
@ -157,6 +173,8 @@ vector<pair<string, QString> > pagestyles;
namespace lyx {
RGBColor set_backgroundcolor;
namespace {
// used when sorting the textclass list.
class less_textclass_avail_desc
@ -661,6 +679,10 @@ GuiDocument::GuiDocument(GuiView & lv)
this, SLOT(change_adaptor()));
connect(pageLayoutModule->pagestyleCO, SIGNAL(activated(int)),
this, SLOT(change_adaptor()));
connect(pageLayoutModule->backgroundTB, SIGNAL(clicked()),
this, SLOT(changeBackgroundColor()));
connect(pageLayoutModule->delbackgroundTB, SIGNAL(clicked()),
this, SLOT(deleteBackgroundColor()));
pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
@ -1165,6 +1187,31 @@ void GuiDocument::setCustomMargins(bool custom)
marginsModule->columnsepUnit->setEnabled(enableColSep);
}
void GuiDocument::changeBackgroundColor()
{
const QColor newColor = QColorDialog::getColor(
rgb2qcolor(set_backgroundcolor), qApp->focusWidget());
if (!newColor.isValid())
return;
// set the button color
pageLayoutModule->backgroundTB->setStyleSheet(
colorButtonStyleSheet(newColor));
// save white as the set color
set_backgroundcolor = rgbFromHexName(fromqstr(newColor.name()));
changed();
}
void GuiDocument::deleteBackgroundColor()
{
// set the button color back to white
pageLayoutModule->backgroundTB->setStyleSheet(
colorButtonStyleSheet(QColor(Qt::white)));
// save white as the set color
set_backgroundcolor = rgbFromHexName("#ffffff");
changed();
}
void GuiDocument::xetexChanged(bool xetex)
{
@ -1928,6 +1975,8 @@ void GuiDocument::applyView()
else
bp_.orientation = ORIENTATION_PORTRAIT;
bp_.backgroundcolor = set_backgroundcolor;
// margins
bp_.use_geometry = !marginsModule->marginCB->isChecked()
|| geom_papersize;
@ -2267,10 +2316,12 @@ void GuiDocument::paramsToDialog()
pageLayoutModule->facingPagesCB->setChecked(
bp_.sides == TwoSides);
pageLayoutModule->backgroundTB->setStyleSheet(
colorButtonStyleSheet(QColor(rgb2qcolor(bp_.backgroundcolor))));
set_backgroundcolor = bp_.backgroundcolor;
lengthToWidgets(pageLayoutModule->paperwidthLE,
pageLayoutModule->paperwidthUnitCO, bp_.paperwidth, defaultUnit);
lengthToWidgets(pageLayoutModule->paperheightLE,
pageLayoutModule->paperheightUnitCO, bp_.paperheight, defaultUnit);

View File

@ -100,6 +100,8 @@ private Q_SLOTS:
void classChanged();
void updateModuleInfo();
void modulesChanged();
void changeBackgroundColor();
void deleteBackgroundColor();
void xetexChanged(bool);
private:
/// validate listings parameters and return an error message, if any

View File

@ -1,245 +1,277 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PageLayoutUi</class>
<widget class="QWidget" name="PageLayoutUi" >
<property name="geometry" >
<widget class="QWidget" name="PageLayoutUi">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>287</width>
<height>264</height>
<width>373</width>
<height>377</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string/>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<layout class="QGridLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing" >
<property name="spacing">
<number>6</number>
</property>
<item row="6" column="0" colspan="4" >
<layout class="QHBoxLayout" >
<property name="margin" >
<item row="0" column="1" colspan="13">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<string>Page Layout</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape" >
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" colspan="4" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<widget class="QLabel" name="label_2">
<property name="text">
<string>Paper Format</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_2" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<widget class="QFrame" name="frame_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape" >
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow" >
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1" colspan="2" >
<widget class="QComboBox" name="papersizeCO" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Choose a particular paper size, or set your own with "Custom"</string>
</property>
<property name="maxVisibleItems" >
<number>20</number>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2" >
<widget class="QComboBox" name="pagestyleCO" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Style used for the page header and footer</string>
</property>
</widget>
</item>
<item row="7" column="0" >
<widget class="QLabel" name="pagestyleL" >
<property name="text" >
<string>Headings &amp;style:</string>
</property>
<property name="buddy" >
<cstring>pagestyleCO</cstring>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2" >
<widget class="QRadioButton" name="landscapeRB" >
<property name="text" >
<string>&amp;Landscape</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2" >
<widget class="QRadioButton" name="portraitRB" >
<property name="text" >
<string>&amp;Portrait</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="2" >
<widget class="LengthCombo" name="paperwidthUnitCO" />
</item>
<item row="2" column="2" >
<widget class="LengthCombo" name="paperheightUnitCO" />
</item>
<item row="3" column="1" >
<widget class="QLineEdit" name="paperwidthLE" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QLineEdit" name="paperheightLE" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="papersizeL" >
<property name="text" >
<item row="1" column="1">
<widget class="QLabel" name="papersizeL">
<property name="text">
<string>&amp;Format:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>papersizeCO</cstring>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="paperheightL" >
<property name="enabled" >
<item row="1" column="5" colspan="8">
<widget class="QComboBox" name="papersizeCO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Choose a particular paper size, or set your own with &quot;Custom&quot;</string>
</property>
<property name="maxVisibleItems">
<number>20</number>
</property>
</widget>
</item>
<item row="1" column="13">
<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>
<item row="2" column="1">
<widget class="QLabel" name="paperheightL">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text" >
<property name="text">
<string>&amp;Height:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>paperheightLE</cstring>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="paperwidthL" >
<property name="enabled" >
<item row="2" column="5">
<widget class="QLineEdit" name="paperheightLE">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text" >
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="12">
<widget class="LengthCombo" name="paperheightUnitCO"/>
</item>
<item row="3" column="1">
<widget class="QLabel" name="paperwidthL">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Width:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>paperwidthLE</cstring>
</property>
</widget>
</item>
<item row="4" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<item row="3" column="5">
<widget class="QLineEdit" name="paperwidthLE">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="12">
<widget class="LengthCombo" name="paperwidthUnitCO"/>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>&amp;Orientation:</string>
</property>
<property name="buddy" >
<property name="buddy">
<cstring>portraitRB</cstring>
</property>
</widget>
</item>
<item row="9" column="1" >
<item row="4" column="5" colspan="8">
<widget class="QRadioButton" name="portraitRB">
<property name="text">
<string>&amp;Portrait</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="5" colspan="8">
<widget class="QRadioButton" name="landscapeRB">
<property name="text">
<string>&amp;Landscape</string>
</property>
</widget>
</item>
<item row="6" column="1" colspan="13">
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Page Layout</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="1" colspan="2">
<widget class="QLabel" name="pagestyleL">
<property name="text">
<string>Headings &amp;style:</string>
</property>
<property name="buddy">
<cstring>pagestyleCO</cstring>
</property>
</widget>
</item>
<item row="7" column="5" colspan="8">
<widget class="QComboBox" name="pagestyleCO">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Style used for the page header and footer</string>
</property>
</widget>
</item>
<item row="7" column="13">
<spacer>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="8" column="1" colspan="12">
<widget class="QCheckBox" name="facingPagesCB">
<property name="toolTip">
<string>Lay out the page for double-sided printing</string>
</property>
<property name="text">
<string>&amp;Two-sided document</string>
</property>
</widget>
</item>
<item row="9" column="1" colspan="3">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Background Color:</string>
</property>
</widget>
</item>
<item row="10" column="5">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>51</width>
<height>131</height>
@ -247,22 +279,49 @@
</property>
</spacer>
</item>
<item row="8" column="0" colspan="3" >
<widget class="QCheckBox" name="facingPagesCB" >
<property name="toolTip" >
<string>Lay out the page for double-sided printing</string>
<item row="9" column="5" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QToolButton" name="backgroundTB">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>&amp;Two-sided document</string>
<property name="minimumSize">
<size>
<width>33</width>
<height>23</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="7" column="3" >
<spacer>
<property name="orientation" >
<item>
<widget class="QToolButton" name="delbackgroundTB">
<property name="minimumSize">
<size>
<width>23</width>
<height>23</height>
</size>
</property>
<property name="text">
<string>...</string>
</property>
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
@ -270,18 +329,7 @@
</property>
</spacer>
</item>
<item row="1" column="3" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</layout>
</item>
</layout>
</widget>
@ -304,7 +352,7 @@
<tabstop>facingPagesCB</tabstop>
</tabstops>
<includes>
<include location="local" >qt_i18n.h</include>
<include location="local">qt_i18n.h</include>
</includes>
<resources/>
<connections/>