Page MenuHomePhorge

No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None
diff --git a/krita-lager/00-krita-brush-option-deps.png b/krita-lager/00-krita-brush-option-deps.png
new file mode 100644
index 0000000..4676eb9
Binary files /dev/null and b/krita-lager/00-krita-brush-option-deps.png differ
diff --git a/krita-lager/01-krita-brush-hud.png b/krita-lager/01-krita-brush-hud.png
new file mode 100644
index 0000000..fb9c73b
Binary files /dev/null and b/krita-lager/01-krita-brush-hud.png differ
diff --git a/krita-lager/02-old-design.png b/krita-lager/02-old-design.png
new file mode 100644
index 0000000..cae3f77
Binary files /dev/null and b/krita-lager/02-old-design.png differ
diff --git a/krita-lager/03-new-design.png b/krita-lager/03-new-design.png
new file mode 100644
index 0000000..5620c8a
Binary files /dev/null and b/krita-lager/03-new-design.png differ
diff --git a/krita-lager/lager-in-krita.md b/krita-lager/lager-in-krita.md
new file mode 100644
index 0000000..6118803
--- /dev/null
+++ b/krita-lager/lager-in-krita.md
@@ -0,0 +1,57 @@
+# Lager in Krita
+
+In Krita we don't use all the advanced features of Lager. We don't even use functional approach in its pure form. Instead we user Lager and its cursors to split "business logic" of Krita brush option from the GUI.
+
+## Problem statement
+
+* in Krita we have brush engines with very complicated bursh settings
+* these brush settings may depend one on another
+* we need to separate the "business logic" of these options from the GUI
+
+For example, "Brush Mode" option depends on:
+
+* whether the brush file has alpha channel or black-and-white
+ * all the modes are avaialble for brushes having the alpha-channel
+ * black-and-white brushes can work only in "Alpha Mask" mode
+* whether the brush engine uses new or old colorsmudge algorithm (selected on a different options page)
+* "Neutral Point", "Brightness" and "Contrast" options are available only for the last three modes in the list
+
+![krita-brush-option-deps screenshot](/krita-lager/00-krita-brush-option-deps.png)
+
+In other words, the number of modes available depends on the traits of the brush selected and on a checkbox from a completely different page of the options.
+
+
+## Traditional approach
+
+![old design diagram](/krita-lager/02-old-design.png)
+
+* originally, all this logic was implemented using standard signal-slot connections between QWidget objects
+* it worked really badly, caused infinite loops signal-slot connections
+* it finally broke when we decided to implement "Brush HUD" feature: a separate widget that provides quick access to some of the brush settings for the user.
+
+![krita-brush-HUD screenshot](/krita-lager/01-krita-brush-hud.png)
+
+
+
+## New approach with Lager
+
+ ![new design diagram](/krita-lager/03-new-design.png)
+
+ * now we have a serializable "data-model". Such data-models are just PODs that represent one-to-one how the user settings are saved on disk.
+ * then on top of this data-model we build "GUI-model".
+ * "GUI model" models all dependencies between different user settings (i.e. business-logic).
+ * we can easily pass `lager::cursor<>` from one settings page to another
+ * it has several benefits against normal Qt signals:
+ * connections are unidirectional, cycles are not possible, because the connection doesn't let the update pass through if the value is not changed (remember that we use PODs, so checks are easy)
+ * cursor-based connections have automatic cold-initialization, which is always forgotten in Qt's signals.
+
+## Conclusion
+
+ * if you have complex GUI that has dependencies between elements, use Lager to model these dependencies
+ * it will also help to transition to QML smoothly
+
+## Code examples
+
+You can find code examples in the article from the official Krita documentation:
+
+https://docs.krita.org/en/untranslatable_pages/brush_editor_gui_with_lager.html
\ No newline at end of file

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 25, 8:32 PM (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39515
Default Alt Text
(3 KB)

Event Timeline