Analysis
Overview
Frame templates provide the ability a frame to be saved as template and used to create new frames. Frame elements that are included into the template are frame properties (excluding z-order) and frame content. Frame templates can be accessed via Frames in Library flap. In later revisions a template editor may be present.
Frame behavior
- Creating - A frame template can be created by dragging the frame to the Frames in Library flap. Other ways may be present too (file -> save frame as template)
- Saving - When a frame is saved as template, the changed properties of the frame are saved - the other properties are with their previous (default) value.
- Editing - When a template is edited, the changes apply to all of the frames created with this template. A warning dialog is showed. Editing global templates reflect to all books that use this template.
When a frame created from a template is edited, it's "Use Template" checkbox is unchecked. If checked again, the value defined for this property is reset.
Task requirements
You should provide templating of the following frame properties:
- position (frame bounds without z-order) (See Comments section)
- size (frame bounds without z-order)
- insets
- padding
- margins
- content
- border style
- color
- thickness?
- opacity
- shadow style
- color
- thickness
- opacity
- background style
- image
- color
- opacity
Frame HUD
- In the frame hud checkboxes "Use template" and "Lock" should be present for the following
- position
- size
- insets
- content
- border style
- shadow style
- background style
"Use template" resets the property to the template's value. This should be implemented in this task.
"Lock" prevents the property value from changing. This should be implemented in FRAME_PROPERTY_LOCKING_R0
Task result
The result of this task should be code. You should provide a prototype of frame templating.
Implementation idea
Provide templating for size, position, shadow, border and background. Provide templating for subelements if there is enough time.
Related
PAGE_TEMPLATES_R0
FRAME_CONTENT_R0
FRAME_BOUNDS_R0
FRAME_INSETS_R0
FRAME_MARGINS_R0
FRAME_PADDING_R0
FRAME_BORDERS_R0
FRAME_POSITION_R0
FRAME_SIZE_R0
FRAME_PROPERTY_LOCKING_R0
How to demo
Create frame insert feature (like text, image, etc).
Design
- Create a class TemplateField in the org.sophie2.base.model.book. This class will be used for properties that have value - calculated by the template, own value, and locked value property which will be responsible for locking the own value.
- Class Frame
- Create Frame value property template() which is the template of the Frame.
- Create FrameContent auto property content() which is the content of the frame. If the frame has its own content the content() will return the own content of the frame. Otherwise, it will return the content property of the frame template.
- Create @Own FrameContent value property ownContent() which will return the own value of the content of the frame.
- Create @Own FrameContent auto property templatedContent() which will calculate the template of the FrameContent of the Frame.
- Create TemplateField properties in the class Frame
- contentSize()
- contentBounds()
- contentLocation()
- Refactor properties border(), background(), paddingInsets(), marginInsets() of the Frame
- Class FrameContent
- Create FrameContent auto property template() which is template of the FrameContent
- Create abstract FrameContent createTemplated() method which each concrete content should override. Every concrete class should define for itself how it will create a template.
- Class BackgroungStyle
- Create abstract BackgroundStyle template() property.
- Create TemplateFields auto bgType(), bgColor(), bgImageResource(), bgOpacity(), bgGradient() properties. (Refactor the current ones.)
- Class BorderStyle - change to abstract
- Create abstract BorderStyle template() property.
- Create TemplateFields auto borderColor(), borderThickness(), borderInsets() properties.
- Class ShadowStyle - change to abstract
- Create abstract ShadowStyle template() property.
- Create TemplateFields auto position(), color(), opacity(), enabled() properties. (Refactor the current ones.)
- The unit tests are org.sophie2.base.model.book.TemplateFieldDemo and org.sophie2.base.model.book.FrameTemplatesTest
Implementation
Testing
Comments
Different behavior should be present for creating a frame by dragging it or menu (when dragged, property "position" should not be used.) Saving the z-order should be discussed as it may be useful.