mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-02 16:44:16 +02:00
Remember the sheet background colour between runs
Picking a sheet (folio) background colour in the diagram editor was lost on every restart. Diagram::background_color is a static initialised to white and PaletteGraphicsView's s_custom_bg a static bool, and neither was ever written anywhere -- Diagram::toXml() carries no colour attribute either -- so closing and reopening a project always came back on the default and the choice had to be made again. Store it in QSettings under diagrameditor/sheet_background_* as a pair of values rather than one: the colour, and whether it was picked explicitly. Both halves are needed. "#ffffff, follow the system" and "#ffffff, always white" are the same colour and two behaviours -- the first is what the views invert on a dark palette -- so keeping only the colour would silently turn one into the other on the next start, which is the reported problem one step removed. The colour is written as HexRgb on purpose. The SVG export gives Diagram::background_color an alpha of 0 to render a transparent background and never puts it back, and that transient value must not be persisted as a permanently transparent sheet. Applied from main() after the headless export and scripting branch -- those return before reaching it and must keep rendering on plain white, the rule ProjectPrintWindow already enforces for printing -- and before QETApp is constructed, since that constructor already loads the projects given on the command line. The GUI export dialog is left alone: it renders through drawBackground(), so what you see is what you export, as it already was within a session. Saved at the moment the colour is applied rather than at shutdown, so neither the print window's temporary white nor the SVG export's alpha can reach it. The button's constructor now mirrors the stored state instead of always claiming "system colour", and the "recently used" list is stored alongside it. Covered by tst_sheetbackgroundsetting, which pins the custom flag and the dropped alpha -- the two rules a single stored colour would lose.
This commit is contained in:
@@ -152,4 +152,67 @@ namespace QetSettings
|
||||
QSettings settings;
|
||||
settings.setValue("scripting/enabled", enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief setSheetBackground
|
||||
* Store the sheet background last picked in the diagram editor, so the
|
||||
* next start opens on it for every project, old or new. @sa sheetBackground
|
||||
* @param background
|
||||
*/
|
||||
void setSheetBackground(const SheetBackground &background)
|
||||
{
|
||||
QSettings settings;
|
||||
//HexRgb, not HexArgb, on purpose: Diagram::background_color is
|
||||
//temporarily given an alpha of 0 by the SVG export to make the
|
||||
//background transparent, and that transient value must never end
|
||||
//up here as a stored transparent sheet.
|
||||
settings.setValue(QStringLiteral("diagrameditor/sheet_background_color"),
|
||||
background.color.name(QColor::HexRgb));
|
||||
settings.setValue(QStringLiteral("diagrameditor/sheet_background_custom"),
|
||||
background.custom);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief sheetBackground
|
||||
* @return the sheet background stored by setSheetBackground(), or the
|
||||
* built-in default (white, following the system) when there is none.
|
||||
* @sa setSheetBackground
|
||||
*/
|
||||
SheetBackground sheetBackground()
|
||||
{
|
||||
QSettings settings;
|
||||
SheetBackground background;
|
||||
background.custom = settings.value(
|
||||
QStringLiteral("diagrameditor/sheet_background_custom"),
|
||||
false).toBool();
|
||||
const QColor stored(settings.value(
|
||||
QStringLiteral("diagrameditor/sheet_background_color"),
|
||||
QStringLiteral("#ffffff")).toString());
|
||||
background.color = stored.isValid() ? stored : QColor(Qt::white);
|
||||
return background;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief sheetBackgroundRecentColors
|
||||
* @return the "recently used" sheet background colours, most recent
|
||||
* first. Empty until the user has picked a non-preset colour.
|
||||
* @sa setSheetBackgroundRecentColors
|
||||
*/
|
||||
QStringList sheetBackgroundRecentColors()
|
||||
{
|
||||
QSettings settings;
|
||||
return settings.value(QStringLiteral("diagrameditor/sheet_background_recent")).toStringList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief setSheetBackgroundRecentColors
|
||||
* Store the "recently used" sheet background colours, most recent first.
|
||||
* @sa sheetBackgroundRecentColors
|
||||
* @param colors
|
||||
*/
|
||||
void setSheetBackgroundRecentColors(const QStringList &colors)
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue(QStringLiteral("diagrameditor/sheet_background_recent"), colors);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user