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

feat: Lock tool style #1119

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/rnote-engine/src/engine/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl Engine {
self.store.set_selected_keys(&all_strokes, false);

if select {
widget_flags |= self.change_pen_style(PenStyle::Selector);
widget_flags |= self.change_pen_style(PenStyle::Selector, None);
}

if adjust_document {
Expand Down Expand Up @@ -426,7 +426,7 @@ impl Engine {
let all_strokes = self.store.stroke_keys_as_rendered();
self.store.set_selected_keys(&all_strokes, false);

widget_flags |= self.change_pen_style(PenStyle::Typewriter);
widget_flags |= self.change_pen_style(PenStyle::Typewriter, None);

if let Pen::Typewriter(typewriter) = self.penholder.current_pen_mut() {
widget_flags |= typewriter.insert_text(
Expand Down Expand Up @@ -463,7 +463,7 @@ impl Engine {
// even though changing the pen style deselects too, but only when the pen is actually different.
let all_strokes = self.store.stroke_keys_as_rendered();
self.store.set_selected_keys(&all_strokes, false);
widget_flags |= self.change_pen_style(PenStyle::Selector);
widget_flags |= self.change_pen_style(PenStyle::Selector, None);

// calculate ratio
let ratio = match resize {
Expand Down
7 changes: 4 additions & 3 deletions crates/rnote-engine/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,10 @@ impl Engine {
}

/// Change the pen style.
pub fn change_pen_style(&mut self, new_style: PenStyle) -> WidgetFlags {
pub fn change_pen_style(&mut self, new_style: PenStyle, mode: Option<PenMode>) -> WidgetFlags {
self.penholder.change_style(
new_style,
mode,
&mut EngineViewMut {
tasks_tx: self.engine_tasks_tx(),
pens_config: &mut self.pens_config,
Expand Down Expand Up @@ -810,7 +811,7 @@ impl Engine {
}

pub fn select_all_strokes(&mut self) -> WidgetFlags {
let widget_flags = self.change_pen_style(PenStyle::Selector);
let widget_flags = self.change_pen_style(PenStyle::Selector, None);
self.store
.set_selected_keys(&self.store.stroke_keys_as_rendered(), true);
widget_flags
Expand All @@ -821,7 +822,7 @@ impl Engine {
}

pub fn deselect_all_strokes(&mut self) -> WidgetFlags {
let widget_flags = self.change_pen_style(PenStyle::Selector);
let widget_flags = self.change_pen_style(PenStyle::Selector, None);
self.store
.set_selected_keys(&self.store.selection_keys_as_rendered(), false);
widget_flags
Expand Down
19 changes: 13 additions & 6 deletions crates/rnote-engine/src/pens/penholder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ impl PenHolder {
self.pen_mode_state = pen_mode_state;
}

/// mutable pen mode state
pub fn pen_mode_state_mut(&mut self) -> &mut PenModeState {
&mut self.pen_mode_state
}

pub fn backlog_policy(&self) -> BacklogPolicy {
self.backlog_policy
}
Expand Down Expand Up @@ -152,9 +157,10 @@ impl PenHolder {
pub fn change_style(
&mut self,
new_style: PenStyle,
mode: Option<PenMode>,
engine_view: &mut EngineViewMut,
) -> WidgetFlags {
let widget_flags = self.change_style_int(new_style, engine_view);
let widget_flags = self.change_style_int(new_style, mode, engine_view);
// When the style is changed externally, the toggle mode / internal states are reset
self.toggle_pen_style = None;
self.prev_shortcut_key = None;
Expand Down Expand Up @@ -277,7 +283,7 @@ impl PenHolder {
}
ShortcutMode::Permanent => {
self.toggle_pen_style = None;
widget_flags |= self.change_style_int(style, engine_view);
widget_flags |= self.change_style_int(style, None, engine_view);
}
ShortcutMode::Toggle => {
if let Some(toggle_pen_style) = self.toggle_pen_style {
Expand All @@ -288,15 +294,15 @@ impl PenHolder {
.map(|k| k != shortcut_key)
.unwrap_or(true)
{
widget_flags |= self.change_style_int(style, engine_view);
widget_flags |= self.change_style_int(style, None, engine_view);
} else {
self.toggle_pen_style = None;
widget_flags |=
self.change_style_int(toggle_pen_style, engine_view);
self.change_style_int(toggle_pen_style, None, engine_view);
}
} else {
self.toggle_pen_style = Some(self.current_pen_style());
widget_flags |= self.change_style_int(style, engine_view);
widget_flags |= self.change_style_int(style, None, engine_view);
}
}
ShortcutMode::Disabled => {}
Expand Down Expand Up @@ -335,6 +341,7 @@ impl PenHolder {
fn change_style_int(
&mut self,
new_style: PenStyle,
mode: Option<PenMode>,
engine_view: &mut EngineViewMut,
) -> WidgetFlags {
let mut widget_flags = WidgetFlags::default();
Expand All @@ -344,7 +351,7 @@ impl PenHolder {
let all_strokes = engine_view.store.selection_keys_as_rendered();
engine_view.store.set_selected_keys(&all_strokes, false);

self.pen_mode_state.set_style(new_style);
self.pen_mode_state.set_style(new_style, mode);
widget_flags |= self.reinstall_pen_current_style(engine_view);
widget_flags.refresh_ui = true;
}
Expand Down
43 changes: 41 additions & 2 deletions crates/rnote-engine/src/pens/penmode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ pub struct PenModeState {
#[serde(rename = "penmode_eraser_style")]
penmode_eraser_style: PenStyle,

//lock styles
#[serde(rename = "lock_pen")]
penmode_pen_lock: bool,
#[serde(rename = "lock_eraser")]
penmode_eraser_lock: bool,

#[serde(skip)]
penmode_pen_style_override: Option<PenStyle>,
#[serde(skip)]
Expand All @@ -41,6 +47,9 @@ impl Default for PenModeState {
penmode_pen_style: PenStyle::Brush,
penmode_eraser_style: PenStyle::Eraser,

penmode_pen_lock: false,
penmode_eraser_lock: true,

penmode_pen_style_override: None,
penmode_eraser_style_override: None,
}
Expand All @@ -53,12 +62,35 @@ impl CloneConfig for PenModeState {
pen_mode: self.pen_mode,
penmode_pen_style: self.penmode_pen_style,
penmode_eraser_style: self.penmode_eraser_style,
penmode_pen_lock: self.penmode_pen_lock,
penmode_eraser_lock: self.penmode_eraser_lock,
..Default::default()
}
}
}

impl PenModeState {
pub fn get_lock(&self) -> bool {
match self.pen_mode {
PenMode::Pen => self.penmode_pen_lock,
PenMode::Eraser => self.penmode_eraser_lock,
}
}

pub fn unlock_pen(&mut self, pen_mode: PenMode) {
match pen_mode {
PenMode::Pen => self.penmode_pen_lock = false,
PenMode::Eraser => self.penmode_eraser_lock = false,
}
}

pub fn set_lock(&mut self, pen_mode: PenMode, state: bool) {
match pen_mode {
PenMode::Pen => self.penmode_pen_lock = state,
PenMode::Eraser => self.penmode_eraser_lock = state,
}
}

pub fn current_style_w_override(&self) -> PenStyle {
match self.pen_mode {
PenMode::Pen => self
Expand All @@ -82,8 +114,15 @@ impl PenModeState {
}
}

pub fn set_style(&mut self, style: PenStyle) {
match self.pen_mode {
pub fn get_style(&self, penmode: PenMode) -> PenStyle {
match penmode {
PenMode::Pen => self.penmode_pen_style,
PenMode::Eraser => self.penmode_eraser_style,
}
}

pub fn set_style(&mut self, style: PenStyle, mode: Option<PenMode>) {
match mode.unwrap_or(self.pen_mode) {
PenMode::Pen => self.penmode_pen_style = style,
PenMode::Eraser => self.penmode_eraser_style = style,
}
Expand Down
8 changes: 8 additions & 0 deletions crates/rnote-ui/data/app.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,13 @@
<default>''</default>
<summary>the engine configuration</summary>
</key>
<key name="lock-pen" type="b">
<default>false</default>
<summary>lock the pen tool</summary>
</key>
<key name="lock-eraser" type="b">
<default>true</default>
<summary>lock the eraser tool</summary>
</key>
</schema>
</schemalist>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions crates/rnote-ui/data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ rnote_ui_gresources_icons_files = files(
'icons/scalable/actions/drawing-pad-button-2-symbolic.svg',
'icons/scalable/actions/drawing-pad-button-3-symbolic.svg',
'icons/scalable/actions/drawing-pad-button-4-symbolic.svg',
'icons/scalable/actions/stylus-pen-symbolic.svg',
'icons/scalable/actions/edit-redo-symbolic.svg',
'icons/scalable/actions/edit-symbolic.svg',
'icons/scalable/actions/edit-undo-symbolic.svg',
Expand Down
2 changes: 2 additions & 0 deletions crates/rnote-ui/data/resources.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<file compressed="true" preprocess="xml-stripblanks">ui/overlays.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/penpicker.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/penshortcutrow.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/penmoderow.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/settingspanel.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/shortcuts.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/sidebar.ui</file>
Expand Down Expand Up @@ -73,6 +74,7 @@
<file compressed="true">icons/scalable/actions/drawing-pad-button-2-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/drawing-pad-button-3-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/drawing-pad-button-4-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/stylus-pen-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/edit-redo-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/edit-symbolic.svg</file>
<file compressed="true">icons/scalable/actions/edit-undo-symbolic.svg</file>
Expand Down
11 changes: 11 additions & 0 deletions crates/rnote-ui/data/ui/penmoderow.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="RnPenModeRow" parent="AdwComboRow">
<child type="suffix">
<object class="GtkSwitch" id="mode">
<property name="halign">end</property>
<property name="valign">center</property>
</object>
</child>
</template>
</interface>
2 changes: 1 addition & 1 deletion crates/rnote-ui/data/ui/penpicker.ui
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</object>
</property>
<child>
<object class="GtkBox">
<object class="GtkBox" id="toolbox">
<property name="spacing">6</property>
<property name="width-request">350</property>
<property name="homogeneous">true</property>
Expand Down
32 changes: 31 additions & 1 deletion crates/rnote-ui/data/ui/settingspanel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,36 @@ on a drawing pad</property>
</child>
</object>
</child>
<!-- Lock settings for the pen/eraser-->
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Pen/Eraser mode</property>
<child>
<object class="RnPenModeRow" id="lock_pen_mode">
<property name="title" translatable="yes">Tool for the pen action</property>
<property name="subtitle" translatable="yes">Set/lock the action for the pen</property>
<child type="prefix">
<object class="GtkImage">
<property name="icon_name">stylus-pen-symbolic</property>
<property name="icon-size">large</property>
</object>
</child>
</object>
</child>
<child>
<object class="RnPenModeRow" id="lock_eraser_mode">
<property name="title" translatable="yes">Tool for the eraser action</property>
<property name="subtitle" translatable="yes">Set/lock the action for the pen</property>
<child type="prefix">
<object class="GtkImage">
<property name="icon_name">stylus-button-eraser-symbolic</property>
<property name="icon-size">large</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
Expand Down Expand Up @@ -552,4 +582,4 @@ on a drawing pad</property>
<property name="value">120</property>
</object>
</template>
</interface>
</interface>
Loading
Loading