blib/lib/Video/DVDRip/GUI/Filters.pm untested

filter: Statementstmt 0.0% 0 / 292 Branchbran 0.0% 0 / 62 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 0.0% 0 / 42 Podpod 0.0% 0 / 37 totaltotal 0.0% 0 / 491 CC 32 SCAR 27.6
CC
32
Cov
0%
preview_selection
56.0
build_filter_settings_form
56.0
build_selected_filters_box
20.0
CRAP 15.9
1 # $Id: Filters.pm 2187 2006-08-16 19:34:38Z joern $
2  
3 #-----------------------------------------------------------------------
4 # Copyright (C) 2001-2006 Jörn Reder <joern AT zyn.de>.
5 # All Rights Reserved. See file COPYRIGHT for details.
6 #
7 # This module is part of Video::DVDRip, which is free software; you can
8 # redistribute it and/or modify it under the same terms as Perl itself.
9 #-----------------------------------------------------------------------
10  
11 package Video::DVDRip::GUI::Filters;
12 use Locale::TextDomain qw (video.dvdrip);
13  
14 use base qw(Video::DVDRip::GUI::Base);
15  
16 use strict;
17 use Carp;
18  
19 my $filters_ff;
20  
21 sub selected_avail_filter_name { shift->{selected_avail_filter_name} }
22 sub selected_used_filter_instance_id { shift->{selected_used_filter_instance_id} }
23  
24 sub set_selected_avail_filter_name { shift->{selected_avail_filter_name} = $_[1] }
25 sub set_selected_used_filter_instance_id { shift->{selected_used_filter_instance_id} = $_[1] }
26  
27 sub current_filter { shift->{current_filter} }
28 sub current_filter_settings { shift->{current_filter_settings} }
29  
30 sub set_current_filter { shift->{current_filter} = $_[1] }
31 sub set_current_filter_settings { shift->{current_filter_settings} = $_[1] }
32  
33 sub in_update { shift->{in_update} }
34 sub last_filter_built { shift->{last_filter_built} }
35  
36 sub set_in_update { shift->{in_update} = $_[1] }
37 sub set_last_filter_built { shift->{last_filter_built} = $_[1] }
38  
39 sub selected_avail_filter {
40 my $self = shift;
41 my $name_row = $self->selected_avail_filter_name;
42 return undef if !$name_row || !$name_row->[0];
43 return Video::DVDRip::FilterList->get_filter(
44 filter_name => $name_row->[0],
45 );
46 }
47  
48 sub selected_used_filter_instance {
49 my $self = shift;
50 my ($no_filter_lookup) = @_;
51 my $id_row = $self->selected_used_filter_instance_id;
52 return undef if !$id_row || !$id_row->[0] ||
53 $id_row->[0] eq 'pre' || $id_row->[0] eq 'post';
54 my $filter_settings =
55 $self->get_context->get_object("filter_settings");
56 return $filter_settings->get_filter_instance(id => $id_row->[0]);
57 }
58  
59 sub open_window {
60 my $self = shift;
61  
62 return if $filters_ff;
63  
64 $self->build;
65  
66 1;
67 }
68  
69 sub build {
70 my $self = shift;
71  
72 my $context = $self->get_context;
73  
74 $filters_ff = Gtk2::Ex::FormFactory->new(
75 context => $context,
76 sync => 1,
77 content => [
78 Gtk2::Ex::FormFactory::Window->new(
79 title => __ "dvd::rip - Filters & Preview",
80 customize_hook => sub {
81 my ($gtk_window) = @_;
82 $_[0]->parent->set(
83 default_width => 680,
84 default_height => 500,
85 );
86 1;
87 },
88 closed_hook => sub {
89 $filters_ff->close if $filters_ff;
90 $filters_ff = undef;
91 $context->set_object(filter_window => undef);
92 1;
93 },
94 content => [
95 Gtk2::Ex::FormFactory::Table->new(
96 expand => 1,
97 layout => q{
98 +>----------------------------------------+
99 | Available filters Selected filters |
100 | |
101 +-----------------------------------------+
102 ^ Filter info Filter Settings |
103 | |
104 +->------------------+--------------------+
105 | Prev. settings | Preview control |
106 +--------------------+--------------------+
107 },
108 content => [
109 Gtk2::Ex::FormFactory::HBox->new (
110 height => 220,
111 content => [
112 $self->build_available_filters_box,
113 $self->build_selected_filters_box,
114 ],
115 properties => {
116 homogeneous => 1,
117 },
118 ),
119 Gtk2::Ex::FormFactory::HBox->new (
120 expand => 1,
121 content => [
122 $self->build_filter_info_box,
123 $self->build_filter_settings_box,
124 ],
125 properties => {
126 homogeneous => 1,
127 },
128 ),
129 $self->build_preview_settings_box,
130 $self->build_preview_control_box,
131 ],
132 ),
133 ],
134 ),
135  
136 ],
137 );
138  
139 $filters_ff->build;
140 $filters_ff->update;
141 $filters_ff->show;
142  
143 $context->set_object(filter_window => $self);
144  
145 1;
146 }
147  
148 sub build_available_filters_box {
149 my $self = shift;
150  
151 Gtk2::SimpleList->add_column_type(
152 'avail_filter_row',
153 type => "Glib::Scalar",
154 renderer => "Gtk2::CellRendererText",
155 attr => sub {
156 my ($treecol, $cell, $model, $iter, $col_num) = @_;
157 my $locked = $model->get($iter, 2);
158 $cell->set ( text => $model->get($iter, $col_num) );
159 $cell->set ( foreground => $locked ? "grey" : "black");
160 1;
161 },
162 );
163  
164 return Gtk2::Ex::FormFactory::HBox->new (
165 title => __"Available filters",
166 expand => 1,
167 content => [
168 Gtk2::Ex::FormFactory::List->new (
169 name => "avail_filters",
170 attr => "avail_filter_list.filters",
171 attr_select => "filter_window.selected_avail_filter_name",
172 attr_select_column => 0,
173 columns => [ __"Name", __"Description", "locked" ],
174 visible => [ 1, 1, 0 ],
175 types => [ "avail_filter_row", "avail_filter_row", "int" ],
176 scrollbars => [ "automatic", "automatic" ],
177 expand => 1,
178 tip => __"Double click a row to activate a filter. "
179 . "Greyed out filters are not available anymore, "
180 . "because they are activated already.",
181 signal_connect => {
182 row_activated => sub {
183 my ($sl, $path, $column) = @_;
184 my $row_ref = $sl->get_row_data_from_path($path);
185 return if $row_ref->[2]; # locked, can't be added again
186 $self->activate_selected_avail_filter;
187 1;
188 },
189 },
190 changed_hook => sub { $self->unselect_used_filters },
191 changed_hook_after => sub {
192 $self->get_context->set_object (
193 "current_filter_settings",
194 undef,
195 );
196 $self->build_filter_settings_form;
197 $self->get_context->set_object (
198 "current_filter_settings",
199 $self->current_filter_settings,
200 );
201 },
202 ),
203 ],
204 );
205 }
206  
207 sub build_selected_filters_box {
208 my $self = shift;
209  
210 return Gtk2::Ex::FormFactory::HBox->new (
211 title => __"Used filters",
212 expand => 1,
213 content => [
214 Gtk2::Ex::FormFactory::List->new (
215 name => "used_filters",
216 attr => "filter_settings.filters",
217 attr_select => "filter_window.selected_used_filter_instance_id",
218 attr_select_column => 0,
219 columns => [ "id", __"Name", __"Description" ],
220 visible => [ 0, 1, 1, ],
221 scrollbars => [ "always", "always" ],
222 expand => 1,
223 tip => __"Double click a row to remove a filter, "
224 . "reorder by drag and drop",
225 signal_connect => {
226 row_activated => sub {
227 $self->deactivate_selected_avail_filter;
228 1;
229 },
230 },
231 customize_hook => sub {
232 my ($gtk_simple_list, $list) = @_;
233 $gtk_simple_list->set_reorderable(1);
234 $gtk_simple_list->get_model->signal_connect ("row-changed", sub {
235 my ($model, $path, $iter) = @_;
236 return 1 if $list->get_in_update;
237 if ( $self->preview_is_open ) {
238 $self->message_window (
239 ff => $filters_ff,
240 message => __"You can't change the filter "
241 . "order\nwhile the preview window is open."
242 );
243 return 1;
244 }
245 my $id = $gtk_simple_list->get_row_data_from_path($path)->[0];
246 $path->next;
247 my $before_row = $gtk_simple_list->get_row_data_from_path($path);
248 my $before_id = $before_row ? $before_row->[0] : undef;
249 $self->reorder_filter($id, $before_id);
250 1;
251 });
252 },
253 changed_hook => sub { $self->unselect_avail_filters },
254 changed_hook_after => sub {
255 $self->get_context->set_object (
256 "current_filter_settings",
257 undef,
258 );
259 $self->build_filter_settings_form;
260 $self->get_context->set_object (
261 "current_filter_settings",
262 $self->current_filter_settings,
263 );
264 },
265 ),
266 ],
267 );
268 }
269  
270 sub build_filter_info_box {
271 my $self = shift;
272
273 return Gtk2::Ex::FormFactory::VBox->new (
274 title => __"Filter information",
275 object => "current_filter",
276 expand => 1,
277 content => [
278 Gtk2::Ex::FormFactory::Form->new (
279 expand => 1,
280 label_top_align => 1,
281 scrollbars => [ "always", "always" ],
282 content => [
283 Gtk2::Ex::FormFactory::Label->new (
284 label => "<i>".__("Filter name")."</i> ",
285 label_markup => 1,
286 attr => "current_filter.filter_name",
287 ),
288 Gtk2::Ex::FormFactory::Label->new (
289 label => "<i>".__("Description")."</i> ",
290 label_markup => 1,
291 attr => "current_filter.desc",
292 ),
293 Gtk2::Ex::FormFactory::Label->new (
294 label => "<i>".__("Version")."</i> ",
295 label_markup => 1,
296 attr => "current_filter.version",
297 ),
298 Gtk2::Ex::FormFactory::Label->new (
299 label => "<i>".__("Author(s)")."</i> ",
300 label_markup => 1,
301 attr => "current_filter.author",
302 ),
303 Gtk2::Ex::FormFactory::Label->new (
304 label => "<i>".__("A/V type")."</i> ",
305 label_markup => 1,
306 attr => "current_filter.av_type",
307 ),
308 Gtk2::Ex::FormFactory::Label->new (
309 label => "<i>".__("Colorspace")."</i> ",
310 label_markup => 1,
311 attr => "current_filter.colorspace_type",
312 ),
313 Gtk2::Ex::FormFactory::Label->new (
314 label => "<i>".__("PRE/POST")."</i> ",
315 label_markup => 1,
316 attr => "current_filter.pre_post_type",
317 ),
318 Gtk2::Ex::FormFactory::Label->new (
319 label => "<i>".__("Multiple")."</i> ",
320 label_markup => 1,
321 attr => "current_filter.multiple_type",
322 ),
323 ],
324 properties => {
325 row_spacing => 5,
326 border_width => 5,
327 },
328 )
329 ]
330 );
331 }
332  
333 sub build_filter_settings_box {
334 my $self = shift;
335
336 return Gtk2::Ex::FormFactory::VBox->new (
337 name => "filter_settings_vbox",
338 title => __"Filter settings",
339 object => "current_filter_settings",
340 expand => 1,
341 );
342 }
343  
344  
345 sub build_preview_settings_box {
346 my $self = shift;
347  
348 return Gtk2::Ex::FormFactory::HBox->new (
349 title => __"Preview settings",
350 expand => 1,
351 content => [
352 Gtk2::Ex::FormFactory::Combo->new (
353 attr => "title.tc_preview_buffer_frames",
354 tip => __("Frames buffered in the preview window ".
355 "and thus are available for scrubbing"),
356 presets => [ 20, 50, 100, 150, 200],
357 width => 80,
358 expand => 0,
359 ),
360 Gtk2::Ex::FormFactory::Entry->new (
361 attr => "title.tc_preview_start_frame",
362 tip => __"Preview should start at this frame",
363 width => 40,
364 expand => 1,
365 ),
366 Gtk2::Ex::FormFactory::Label->new (
367 label => " - ",
368 ),
369 Gtk2::Ex::FormFactory::Entry->new (
370 attr => "title.tc_preview_end_frame",
371 tip => __"Preview should start stop this frame",
372 width => 40,
373 expand => 1,
374 ),
375 ],
376 );
377 }
378  
379 sub build_preview_control_box {
380 my $self = shift;
381  
382 my $active_when_preview_open = sub {
383 $self->get_context_object("preview_window") ? 1 : 0;
384 };
385 my $active_when_preview_closed = sub {
386 $self->get_context_object("preview_window") ? 0 : 1;
387 };
388 my $active_when_preview_paused = sub {
389 my $preview = $self->get_context_object("preview_window");
390 return $preview && $preview->paused;
391 };
392 my $inactive_when_preview_paused = sub {
393 my $preview = $self->get_context_object("preview_window");
394 return $preview && !$preview->paused;
395 };
396  
397 return Gtk2::Ex::FormFactory::HBox->new (
398 title => __"Preview control",
399 expand => 1,
400 content => [
401 Gtk2::Ex::FormFactory::Button->new (
402 stock => "gtk-media-play",
403 label => "",
404 tip => __"Open preview window and play",
405 active_cond => $active_when_preview_closed,
406 active_depends => [ "preview_window" ],
407 clicked_hook => sub { $self->preview_play },
408 ),
409 Gtk2::Ex::FormFactory::Button->new (
410 stock => "gtk-apply",
411 label => "",
412 tip => __"Apply filter chain",
413 active_cond => $inactive_when_preview_paused,
414 active_depends => [ "preview_window" ],
415 clicked_hook => sub { $self->preview_apply },
416 ),
417 Gtk2::Ex::FormFactory::Button->new (
418 stock => "gtk-remove",
419 label => "",
420 tip => __"Decrease preview speed",
421 active_cond => $inactive_when_preview_paused,
422 active_depends => [ "preview_window" ],
423 clicked_hook => sub { $self->preview_command("slower") },
424 ),
425 Gtk2::Ex::FormFactory::Button->new (
426 stock => "gtk-add",
427 label => "",
428 tip => __"Increase preview speed",
429 active_cond => $inactive_when_preview_paused,
430 active_depends => [ "preview_window" ],
431 clicked_hook => sub { $self->preview_command("faster") },
432 ),
433 Gtk2::Ex::FormFactory::ToggleButton->new (
434 attr => "preview_window.paused",
435 stock => "gtk-media-pause",
436 true_label => "",
437 false_label => "",
438 tip => __"Pause/Resume",
439 active_cond => $active_when_preview_open,
440 active_depends => [ "preview_window" ],
441 changed_hook => sub { $self->preview_pause },
442 ),
443 Gtk2::Ex::FormFactory::Button->new (
444 stock => "gtk-media-rewind",
445 with_repeat => 1,
446 label => "",
447 tip => __"Step backward one frame",
448 active_cond => $active_when_preview_paused,
449 active_depends => [ "preview_window" ],
450 clicked_hook => sub { $self->preview_command("slowbw") },
451 ),
452 Gtk2::Ex::FormFactory::Button->new (
453 stock => "gtk-media-forward",
454 with_repeat => 1,
455 label => "",
456 tip => __"Step forward one frame",
457 active_cond => $active_when_preview_paused,
458 active_depends => [ "preview_window" ],
459 clicked_hook => sub { $self->preview_command("slowfw") },
460 ),
461 Gtk2::Ex::FormFactory::Button->new (
462 stock => "gtk-goto-first",
463 with_repeat => 1,
464 label => "",
465 tip => __"Step backward several frames",
466 active_cond => $active_when_preview_paused,
467 active_depends => [ "preview_window" ],
468 clicked_hook => sub { $self->preview_command("fastbw") },
469 ),
470 Gtk2::Ex::FormFactory::Button->new (
471 stock => "gtk-goto-last",
472 with_repeat => 1,
473 label => "",
474 tip => __"Step forward several frames",
475 active_cond => $active_when_preview_paused,
476 active_depends => [ "preview_window" ],
477 clicked_hook => sub { $self->preview_command("fastfw") },
478 ),
479 Gtk2::Ex::FormFactory::Button->new (
480 stock => "gtk-media-stop",
481 label => "",
482 tip => __"Stop playing and close preview window",
483 active_cond => $active_when_preview_open,
484 active_depends => [ "preview_window" ],
485 clicked_hook => sub { $self->preview_stop },
486 ),
487 ],
488 );
489 }
490  
491 sub get_transcode_remote {
492 my $self = shift;
493
494 return $self->get_context_object("preview_window")
495 ->transcode_remote
496 }
497  
498 sub preview_is_open {
499 my $self = shift;
500 return $self->get_context_object("preview_window") ? 1 : 0;
501 }
502  
503 sub preview_command {
504 my $self = shift;
505 my ($command) = @_;
506 $self->get_transcode_remote->preview( command => $command );
507 1;
508 }
509  
510 sub preview_play {
511 my $self = shift;
512  
513 require Video::DVDRip::GUI::Preview;
514  
515 my $preview = Video::DVDRip::GUI::Preview->new (
516 context => $self->get_context,
517 closed_cb => sub {
518 $self->preview_stop
519 },
520 selection_cb => sub { $self->preview_selection ( @_ ) },
521 eof_cb => sub {
522 my ($ok) = @_;
523 $self->preview_stop;
524 $ok == 1 && Glib::Timeout->add (1000, sub {
525 $self->preview_play;
526 return 0;
527 });
528 },
529 );
530  
531 $self->get_context->set_object ( "preview_window" => $preview );
532  
533 $preview->open;
534  
535 1;
536 }
537  
538 sub preview_stop {
539 my $self = shift;
540
541 my $preview = $self->get_context_object("preview_window");
542 $self->get_context->set_object ( "preview_window" => 0 );
543
544 $preview->stop;
545
546 1;
547 }
548  
549 sub preview_pause {
550 my $self = shift;
551  
552 my $context = $self->get_context;
553
554 $context->get_object("preview_window")->pause;
555 $context->update_object_widgets("preview_window");
556  
557 1;
558 }
559  
560 sub preview_apply {
561 my $self = shift;
562  
563 my $context = $self->get_context;
564
565 $context->get_object("preview_window")->apply_filter_settings;
566  
567 1;
568 }
569  
570 sub preview_selection {
571 my $self = shift;
572 my %par = @_;
573 my ($x1, $y1, $x2, $y2) =
574 @par{'x1','y1','x2','y2'};
575  
576 my $context = $self->get_context;
577 my $title = $context->get_object("title");
578 my $filter_setting = $context->get_object("current_filter_settings");
579
580 return unless $filter_setting;
581
582 my $filter = $filter_setting->get_filter;
583  
584 my $selection_cb = $filter->get_selection_cb;
585 return 1 if not $selection_cb;
586  
587 ($x1, $x2) = ($x2, $x1) if $x1 > $x2;
588 ($y1, $y2) = ($y2, $y1) if $y1 > $y2;
589  
590 if ( $filter_setting->queue eq 'pre' ) {
591 # transform back values => undo resizing & clipping
592  
593 # undo 2nd clip
594 $x1 += $title->tc_clip2_left;
595 $y1 += $title->tc_clip2_top;
596 $x2 += $title->tc_clip2_left;
597 $y2 += $title->tc_clip2_top;
598  
599 # undo resize
600 my $width_factor = $title->tc_zoom_width /
601 ( $title->width - $title->tc_clip1_left
602 - $title->tc_clip1_right );
603 my $height_factor = $title->tc_zoom_height/
604 ( $title->height - $title->tc_clip1_top
605 - $title->tc_clip1_bottom );
606 $x1 = int ($x1 / $width_factor );
607 $x2 = int ($x2 / $width_factor );
608 $y1 = int ($y1 / $height_factor );
609 $y2 = int ($y2 / $height_factor );
610  
611 # undo 1st clip
612 $x1 += $title->tc_clip1_left;
613 $y1 += $title->tc_clip1_top;
614 $x2 += $title->tc_clip1_left;
615 $y2 += $title->tc_clip1_top;
616 }
617  
618 if ( $title->tc_use_yuv_internal ) {
619 foreach my $x ( $x1, $x2, $y1, $y2 ) {
620 $x = int($x/2)*2;
621 }
622 }
623  
624 &$selection_cb (
625 filter_setting => $filter_setting,
626 x1 => $x1,
627 y1 => $y1,
628 x2 => $x2,
629 y2 => $y2,
630 );
631  
632 $context->update_object_widgets("current_filter_settings");
633  
634 $self->preview_apply;
635  
636 1;
637 }
638  
639 sub activate_selected_avail_filter {
640 my $self = shift;
641  
642 my $filter_list =
643 $self->get_context->get_object("avail_filter_list");
644  
645 my $filter_settings =
646 $self->get_context->get_object("filter_settings");
647  
648 my $filter_name =
649 $self->selected_avail_filter_name->[0];
650  
651 my $instance = $filter_settings->add_filter (
652 filter_name => $filter_name,
653 );
654  
655 my $preview = $self->get_context_object("preview_window");
656  
657 $preview && $preview->transcode_remote->config_filter (
658 filter => $instance->filter_name,
659 options => $instance->get_config_string,
660 );
661  
662 $self->get_context->update_object_attr_widgets(
663 "filter_settings", "filters"
664 );
665  
666 $self->get_context->update_object_attr_widgets(
667 "avail_filter_list", "filters"
668 );
669  
670 my $list = $filters_ff->get_widget("used_filters");
671 $list->select_row_by_attr($instance->id);
672  
673 1;
674 }
675  
676 sub deactivate_selected_avail_filter {
677 my $self = shift;
678  
679 my $filter_settings =
680 $self->get_context->get_object("filter_settings");
681  
682 my $id = $self->selected_used_filter_instance_id->[0];
683  
684 return 1 if $id =~ /^(?:pre|post)$/;
685  
686 my $instance = $filter_settings->del_filter ( id => $id );
687 my $preview = $self->get_context_object("preview_window");
688  
689 $preview && $preview->transcode_remote->disable_filter (
690 filter => $instance->filter_name
691 );
692  
693 $self->get_context->update_object_attr_widgets(
694 "filter_settings", "filters"
695 );
696  
697 $self->get_context->update_object_attr_widgets(
698 "avail_filter_list", "filters"
699 );
700  
701 my $list = $filters_ff->get_widget("avail_filters");
702 $list->select_row_by_attr($instance->filter_name);
703  
704 1;
705 }
706  
707 sub reorder_filter {
708 my $self = shift;
709 my ($id, $before_id) = @_;
710
711 return if $id == $before_id;
712
713 my $filter_settings =
714 $self->get_context->get_object("filter_settings");
715  
716 my $success = $filter_settings->move_instance (
717 id => $id,
718 before_id => $before_id,
719 );
720
721 if ( !$success ) {
722 $self->get_context->update_object_attr_widgets(
723 "filter_settings", "filters"
724 );
725 }
726
727 1;
728 }
729  
730 sub unselect_used_filters {
731 my $self = shift;
732  
733 return if $self->in_update;
734  
735 $self->set_in_update(1);
736 my $list = $filters_ff->get_widget("used_filters");
737 $list->get_gtk_widget->get_selection->unselect_all;
738 $self->set_in_update(0);
739  
740 1;
741 }
742  
743 sub unselect_avail_filters {
744 my $self = shift;
745  
746 return if $self->in_update;
747  
748 $self->set_in_update(1);
749 my $list = $filters_ff->get_widget("avail_filters");
750 $list->get_gtk_widget->get_selection->unselect_all;
751 $self->set_in_update(0);
752  
753 1;
754 }
755  
756 sub build_filter_settings_form {
757 my $self = shift;
758  
759 my $instance = $self->current_filter_settings;
760 my $filter = $instance ? $instance->get_filter : undef;
761  
762 return if $self->last_filter_built eq $filter;
763  
764 $self->set_last_filter_built($filter);
765  
766 my $vbox = $filters_ff->get_widget("filter_settings_vbox");
767 my $old_widget = $vbox->get_content->[0];
768  
769 $old_widget && $vbox->remove_child_widget($old_widget);
770  
771 return if !$instance;
772  
773 my @content = (
774 Gtk2::Ex::FormFactory::YesNo->new (
775 attr => "current_filter_settings.enabled",
776 label => __"Filter",
777 true_label => __"Enable",
778 false_label => __"Disable",
779 tip => __"Enable or disable filter temporarily",
780 ),
781 );
782  
783 my %used_options;
784 foreach my $option ( @{$filter->options} ) {
785 next if $option->option_name eq 'pre';
786 next if $used_options{$option->option_name};
787 $used_options{$option->option_name} = 1;
788
789 my @option_widgets;
790 for ( my $idx=0; $idx < @{$option->fields}; ++$idx ) {
791 my $widget = $self->build_option_field($option, $idx);
792 if ( $widget->get_width && @{$option->fields} == 1 ) {
793 $widget->set_width($widget->get_width+50);
794 }
795 push @option_widgets, $widget;
796 }
797 push @content, Gtk2::Ex::FormFactory::HBox->new (
798 label => $option->get_wrapped_desc,
799 content => \@option_widgets,
800 );
801 }
802  
803 my $form = Gtk2::Ex::FormFactory::Form->new (
804 content => \@content,
805 expand => 1,
806 scrollbars => [ "always", "always" ],
807 properties => {
808 row_spacing => 5,
809 border_width => 5,
810 },
811 active_cond => sub { $self->selected_used_filter_instance },
812 active_depends => "current_filter_settings",
813 );
814  
815 $vbox->add_child_widget($form);
816  
817 1;
818 }
819  
820 sub build_option_field {
821 my $self = shift;
822 my ($option, $idx) = @_;
823
824 my $field = $option->fields->[$idx];
825 my $option_name = $option->option_name;
826 my $attr = "current_filter_settings.filter_option_".$option_name."_$idx";
827  
828 if ( $field->checkbox || $field->switch ) {
829 return Gtk2::Ex::FormFactory::CheckButton->new (
830 attr => $attr,
831 detach_label => 1,
832 tip => $field->get_range_text,
833 );
834 }
835  
836 if ( $field->combo ) {
837 my @presets = ( $field->range_from .. $field->range_to );
838 return Gtk2::Ex::FormFactory::Combo->new (
839 attr => $attr,
840 width => 60,
841 presets => \@presets,
842 tip => $field->get_range_text,
843 );
844 }
845  
846 return Gtk2::Ex::FormFactory::Entry->new (
847 attr => $attr,
848 width => 50,
849 tip => $field->get_range_text,
850 );
851 }
852  
853 1;
854