uwesto...@lyx.org schreef:
+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;
+}
+
Why do you want 127 correspond to 0.5 ? This looks like an irreversible
adjustment of the color. 0 -> 0, 1 -> 2/256 ?
Modified: lyx-devel/trunk/src/LaTeXFeatures.cpp
==============================================================================
--- lyx-devel/trunk/src/LaTeXFeatures.cpp Sat Apr 11 23:17:58 2009
(r29219)
+++ lyx-devel/trunk/src/LaTeXFeatures.cpp Sat Apr 11 23:40:11 2009
(r29220)
@@ -545,6 +545,16 @@
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();
}
Why don't you just use the same as is done for the other colors:
colors << "\\definecolor{page_backgroundcolor}{rgb}{"
<< c.r / 255.0 << ',' << c.g / 255.0 << ',' << c.b / 255.0
<< "}\n";
Then the outputLatexColor() function is unneeded.
+// a style sheet for buttons
+// this is for example used for the background color setting button
+static inline QString colorButtonStyleSheet(const QColor &bgColor)
Why static inline ?
const QColor &bgColor -> QColor const & bgColor.
+{
+ if (bgColor.isValid()) {
+ QString rc = QLatin1String("background:");
+ rc += bgColor.name();
+ return rc;
+ }
+ return QLatin1String("");
+}
+
+
Why QLatin1Strings ?
There are all spaces in stead of tabs.
using namespace std;
using namespace lyx::support;
@@ -157,6 +173,8 @@
namespace lyx {
+RGBColor set_backgroundcolor;
+
namespace {
// used when sorting the textclass list.
class less_textclass_avail_desc
@@ -661,6 +679,10 @@
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()));
There is whitespace in stead of tabs at the beginning of these lines
pageLayoutModule->pagestyleCO->addItem(qt_("Default"));
pageLayoutModule->pagestyleCO->addItem(qt_("empty"));
@@ -1165,6 +1187,31 @@
marginsModule->columnsepUnit->setEnabled(enableColSep);
}
+void GuiDocument::changeBackgroundColor()
+{
+ const QColor newColor = QColorDialog::getColor(
+ rgb2qcolor(set_backgroundcolor), qApp->focusWidget());
QColor const & ?
+ if (!newColor.isValid())
+ return;
+ // set the button color
+ pageLayoutModule->backgroundTB->setStyleSheet(
+ colorButtonStyleSheet(newColor));
+ // save white as the set color
wrong comment.
+ 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 @@
else
bp_.orientation = ORIENTATION_PORTRAIT;
+ bp_.backgroundcolor = set_backgroundcolor;
+
// margins
bp_.use_geometry = !marginsModule->marginCB->isChecked()
|| geom_papersize;
@@ -2267,10 +2316,12 @@
pageLayoutModule->facingPagesCB->setChecked(
bp_.sides == TwoSides);
+ pageLayoutModule->backgroundTB->setStyleSheet(
+ colorButtonStyleSheet(QColor(rgb2qcolor(bp_.backgroundcolor))));
double conversion to QColor ?
+ set_backgroundcolor = bp_.backgroundcolor;
lengthToWidgets(pageLayoutModule->paperwidthLE,
All other document settings (AFAICS) derive their value from the
GUI-component. You can do the same here without the global variable. See
attached patch.
Vincent
Index: src/frontends/qt4/GuiDocument.cpp
===================================================================
--- src/frontends/qt4/GuiDocument.cpp (revision 29220)
+++ src/frontends/qt4/GuiDocument.cpp (working copy)
@@ -173,8 +173,6 @@
namespace lyx {
-RGBColor set_backgroundcolor;
-
namespace {
// used when sorting the textclass list.
class less_textclass_avail_desc
@@ -1189,15 +1187,17 @@
void GuiDocument::changeBackgroundColor()
{
- const QColor newColor = QColorDialog::getColor(
- rgb2qcolor(set_backgroundcolor), qApp->focusWidget());
+ QString const & style = pageLayoutModule->backgroundTB->styleSheet();
+ QColor const & col = QColor(style.split(":")[1]);
+
+ QColor const & newColor = QColorDialog::getColor(col,
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();
}
@@ -1207,8 +1207,6 @@
// 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();
}
@@ -1975,7 +1973,8 @@
else
bp_.orientation = ORIENTATION_PORTRAIT;
- bp_.backgroundcolor = set_backgroundcolor;
+ QString const & style = pageLayoutModule->backgroundTB->styleSheet();
+ bp_.backgroundcolor = rgbFromHexName(fromqstr(style.split(":")[1]));
// margins
bp_.use_geometry = !marginsModule->marginCB->isChecked()
@@ -2318,7 +2317,6 @@
pageLayoutModule->backgroundTB->setStyleSheet(
colorButtonStyleSheet(QColor(rgb2qcolor(bp_.backgroundcolor))));
- set_backgroundcolor = bp_.backgroundcolor;
lengthToWidgets(pageLayoutModule->paperwidthLE,
pageLayoutModule->paperwidthUnitCO, bp_.paperwidth,
defaultUnit);