@@ -12,9 +12,11 @@ use rnote_compose::SplitOrder;
12
12
use rnote_compose:: penevent:: ShortcutKey ;
13
13
use rnote_engine:: engine:: StrokeContent ;
14
14
use rnote_engine:: ext:: GraphenePointExt ;
15
+ use rnote_engine:: pens:: PenStyle ;
15
16
use rnote_engine:: strokes:: resize:: { ImageSizeOption , Resize } ;
16
17
use rnote_engine:: { Camera , Engine } ;
17
18
use std:: path:: PathBuf ;
19
+ use std:: str:: FromStr ;
18
20
use std:: time:: Instant ;
19
21
use tracing:: { debug, error} ;
20
22
@@ -160,6 +162,13 @@ impl RnAppWindow {
160
162
let action_visual_debug = gio:: PropertyAction :: new ( "visual-debug" , self , "visual-debug" ) ;
161
163
self . add_action ( & action_visual_debug) ;
162
164
165
+ let action_pen_style = gio:: SimpleAction :: new_stateful (
166
+ "pen-style" ,
167
+ Some ( & String :: static_variant_type ( ) ) ,
168
+ & String :: from ( "brush" ) . to_variant ( ) ,
169
+ ) ;
170
+ self . add_action ( & action_pen_style) ;
171
+
163
172
// Open settings
164
173
action_open_settings. connect_activate ( clone ! (
165
174
#[ weak( rename_to = appwindow) ]
@@ -295,6 +304,35 @@ impl RnAppWindow {
295
304
}
296
305
) ) ;
297
306
307
+ // Pen style
308
+ action_pen_style. connect_activate ( clone ! (
309
+ #[ weak( rename_to=appwindow) ]
310
+ self ,
311
+ move |action, target| {
312
+ let pen_style_str = target. unwrap( ) . str ( ) . unwrap( ) ;
313
+
314
+ let pen_style = match PenStyle :: from_str( pen_style_str) {
315
+ Ok ( s) => s,
316
+ Err ( e) => {
317
+ error!( "Activated pen-style action with invalid target, Err: {e:}" ) ;
318
+ return ;
319
+ }
320
+ } ;
321
+
322
+ let Some ( canvas) = appwindow. active_tab_canvas( ) else {
323
+ return ;
324
+ } ;
325
+ // don't change the style if the current style with override is already the same
326
+ // (e.g. when switched to from the pen button, not by clicking the pen page)
327
+ if pen_style != canvas. engine_ref( ) . current_pen_style_w_override( ) {
328
+ let mut widget_flags = canvas. engine_mut( ) . change_pen_style( pen_style) ;
329
+ widget_flags |= canvas. engine_mut( ) . change_pen_style_override( None ) ;
330
+ appwindow. handle_widget_flags( widget_flags, & canvas) ;
331
+ }
332
+ action. set_state( & pen_style_str. to_variant( ) ) ;
333
+ }
334
+ ) ) ;
335
+
298
336
// Tab actions
299
337
action_active_tab_move_left. connect_activate ( clone ! (
300
338
#[ weak( rename_to=appwindow) ]
0 commit comments