Vincent van Ravesteijn schrieb:
Why do you want 127 correspond to 0.5 ? This looks like an irreversible
adjustment of the color. 0 -> 0, 1 -> 2/256 ?
Because in the LaTeX world you define e.g. light yellow as 1, 1, 0.5 and not as "1, 1, 0.4980392".
When you look in the default color settings one can see that the values are often 63, 127, 191 etc.
The error of 1/256 is acceptable small.
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.
Because I want to give out 127 as 0.5. For this more code is needed therefore I put it in a routine
and when rewriting the text style dialog I planned to use this routine as well.
+// 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 ?
This routine and the idea to set the color this way is taken from the source code of the Qt
designer. What is wrong with a QLatin1String?
> There is whitespace in stead of tabs at the beginning of these lines
Fixed.
+ pageLayoutModule->backgroundTB->setStyleSheet(
+ colorButtonStyleSheet(QColor(rgb2qcolor(bp_.backgroundcolor))));
double conversion to QColor ?
Fixed.
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.
I first tried to do this, but I failed to get the color from the stylesheet.
How do you do this with?:
QString const & style = pageLayoutModule->backgroundTB->styleSheet();
bp_.backgroundcolor = rgbFromHexName(fromqstr(style.split(":")[1]));
Where do you get the info about the style color? A style can have several ":" so how do get the
color info from a style like this?:
"border: 2px solid black; border-radius: 2px; background: yellow"
There is no defined order in the string and I couldn't find in the Qt docs if the term "background"
is unique and always followed by a color name that can be transformed to a hex code. I also haven't
found code where the color was read out tis way. Therefore I used the safe way.
thanks and regards
Uwe