Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible ruler description #888

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from

Conversation

letsfindaway
Copy link
Collaborator

@letsfindaway letsfindaway commented Feb 11, 2024

This PR replaces the fixed background rulings (blank, lined, crossed, Seyes) by a mechanism that allows flexible ruler descriptions, where additional background rulings can simply be added by providing an additional description file. In the resources/etc/background directory, there is already a set of 12 different rulings (plus one for the blank page).

The idea is to have an XML description for the rulings. There is an XML Schema file, which describes the format both formally and with user readable comments. Basically a background ruling is described as a set of line groups. Each line group has a defined angle and one or several lines in a specified distance. Line groups may repeat infinitely. The color and opacity of lines can be specified, but also the default colors defined in the preferences can be used. Additional settings allow to limit lines to the right and the left and to add a border on one or both sides.

For the user, the background palette changes as follows:

  • It now displays a set of 6 different background rulings.
  • The selection of light or dark background color is now a switch.
  • In the preferences, the user may select which of the available rulings are presented in the palette and in which order by simply dragging them to the desired position.

Background rulings are stored in the document SVG files. To provide some interoperability with existing documents, the current flags for "lined", "crossed" and "intermediateLines" are interpreted, when no ruling description is provided. These flags are also written when rulings are used, which to some extend mimic the "old" patterns.

See Flexible background patterns for a deeper description of the user experience and pattern design.

This PR is still a draft, as I want to collect more input about usability. The code may also need more testing.

@letsfindaway letsfindaway requested a review from kaamui February 11, 2024 17:33
@letsfindaway
Copy link
Collaborator Author

letsfindaway commented Feb 12, 2024

TODOs

Here's a list of TODOs for this PR:

  • Move background button templates to resources.
  • Store unknown background pattern locally.
  • Allow to delete local background patterns by dragging them to a trash icon displayed at the end of the list in the preferences dialog.
  • Double check code style.
  • Double check possible nullptr references.
  • Add copyright header to new classes.
  • Write a Wiki page with user instructions and a guide to create own background patterns.

@letsfindaway letsfindaway force-pushed the feat-flexible-ruler-description branch from e0cf458 to f4e7e32 Compare February 13, 2024 07:58
@letsfindaway letsfindaway force-pushed the feat-flexible-ruler-description branch 2 times, most recently from cf7d6a7 to 06e0d42 Compare February 25, 2024 17:11
@sebojolais
Copy link
Contributor

Just a comment:
The Seyes background feature introduced in 1.7.0 was more a trick than a feature.
With this PR, it will be a real feature. So I think this PR is welcome.
+1

@letsfindaway letsfindaway marked this pull request as ready for review February 26, 2024 07:03
@letsfindaway
Copy link
Collaborator Author

Now I think the PR is good enough to remove draft status. Thanks @sebojolais for valuable input!

@letsfindaway letsfindaway mentioned this pull request Feb 27, 2024
@sebojolais
Copy link
Contributor

Another good point of this PR: it is not a local feature, it will benefit for every users.

@letsfindaway letsfindaway mentioned this pull request Jun 15, 2024
@ch-westphal
Copy link

Very useful feature! Another interesting option would be to have a specific logo in the corner of the page.

@letsfindaway letsfindaway force-pushed the feat-flexible-ruler-description branch 2 times, most recently from 0434504 to 623fc18 Compare August 23, 2024 15:39
@letsfindaway letsfindaway force-pushed the feat-flexible-ruler-description branch 2 times, most recently from 2fade4f to 505eefc Compare September 5, 2024 13:59
@letsfindaway letsfindaway force-pushed the feat-flexible-ruler-description branch from 505eefc to fd241f2 Compare September 13, 2024 12:42
@letsfindaway
Copy link
Collaborator Author

letsfindaway commented Sep 13, 2024

This PR is now updated to deal with the snap-to-grid feature. We can now snap to a flexible background definition as follows:

  • If a background only contains lines, then we snap to the closest line.
  • If a background has any grid pattern, then we snap to all intersection points of the grid.
  • Border definitions are not used for snapping.
  • If a crossed background has a margin, then we do not snap when objects are on that margin. However we do snap to the lines of a lines background even on the margin. (I considered to harmonize that, but then found it useful to still "keep the line" even on the margin)
  • The blank background is defined to have an invisible 10mm grid, so that it behaves as before.

@kaamui
Copy link
Member

kaamui commented Sep 13, 2024

I remember some features requests that asked for the ability to have a dark green background to mimic some old school blackboards where the slate used was of this color. Do you think it would be possible to add this as a parameter, where one must give the background color, and the expected behavior (behave as a dark background, or behave as a light background) ?

@letsfindaway
Copy link
Collaborator Author

I remember some features requests that asked for the ability to have a dark green background to mimic some old school blackboards where the slate used was of this color. Do you think it would be possible to add this as a parameter, where one must give the background color, and the expected behavior (behave as a dark background, or behave as a light background) ?

The background color is still drawn here:

if (darkBackground)
{
painter->fillRect (rect, QBrush (QColor (Qt::black)));
}
else
{
painter->fillRect (rect, QBrush (QColor (Qt::white)));
}

So the flexible ruler description does not affect that in any way. As long as you replace black and white by configurable colors there, it will work. And of course, the dark background should really be dark and the light background should be light, so that the foreground color substitution works.

This means, that the feature of a configurable background color is completely independent of the rulings!

@kaamui
Copy link
Member

kaamui commented Sep 13, 2024

Good point, it's not mandatory to attach this to the ruler descriptions.

@letsfindaway
Copy link
Collaborator Author

letsfindaway commented Sep 13, 2024

Good point, it's not mandatory to attach this to the ruler descriptions.

Yes, exactly. The ruler descriptions only describe the lines, not the color behind. They currently just assume that there are exactly two possible background colors, light and dark. And for those they offer the option to define a line color. But also this is only an option. If you omit that, then the line color defined in the preferences is used.

The color definition in the ruling description is more meant for things like the red lines in Seyes or similar. Or just to modify the alpha value of the default line color, as I do it for the 1mm grid, where 10mm, 5mm and 1mm lines have different alpha, but still the same (default) color.

letsfindaway and others added 4 commits February 12, 2025 14:51
- add UBBackgroundRulings to read/write/keep a ruling description
- add UBBackgroundManager to manage UBBackgroundRulings
- add XML schema for ruling descriptions
- add initial set of rulings
- provide compatibility with legacy background flags
- save and load rulings in document pages
- add a widget to the "Grid" preferences page
- display all available background rulings
- allow to reorder rulings by DnD
- first six background rulings will be in background palette
- persist preferred rulings
- save patterns when loading a document
- allow to delete user provided patterns in preferences
- move background button templates to resources
- add copyright header
- improve code style for new classes
- add missing classes to gui.pri
sebojolais and others added 9 commits February 12, 2025 14:51
- remove the extra template subdirectory from the path
- use stretch element to limit length of lines
- positive values extend outside of page border
- negative values restrict to inside page border
- keep option to draw border lines
- fix algorithm so that it works for any line group angle
- stretch now also works for single lines (spacing = 0)
- add stack element to limit stacking of line groups
- positive values extend outside of page border
- negative values restrict to inside page border
- update XML schema accordingly
- update rules accordingly
- the topmost line group was not painted in some cases
- re-introduce a decrement lost in previous rework
- fixed regression
- initialization of the black scene caused unintentional
  switch to dark background during startup
- ruled with border
- crossed with border
- move the snap function from UBGraphicsScene to UBBackgroundRuling
- calculate snap points based on ruling description
- factor out common code with background drawing
@letsfindaway letsfindaway force-pushed the feat-flexible-ruler-description branch from 72ec947 to 5a63e0d Compare February 12, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants