1/* 2 * Copyright (c) 2019-2021 Alecaddd (https://alecaddd.com) 3 * 4 * This file is part of Akira. 5 * 6 * Akira is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 11 * Akira is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 16 * You should have received a copy of the GNU General Public License 17 * along with Akira. If not, see <https://www.gnu.org/licenses/>. 18 * 19 * Authored by: Giacomo "giacomoalbe" Alberini <giacomoalbe@gmail.com> 20 * Authored by: Alessandro "alecaddd" Castellani <castellani.ale@gmail.com> 21 * Authored by: Ivan "isneezy" Vilanculo <ivilanculo@gmail.com> 22 */ 23 24public class Akira.Layouts.Partials.FillItem : Gtk.Grid { 25 private unowned Akira.Window window; 26 private unowned Lib.Components.Fill fill; 27 28 private Gtk.Button hidden_button; 29 private Gtk.Button delete_button; 30 private Gtk.Image hidden_button_icon; 31 32 private bool hidden { 33 owned get { 34 return fill.hidden; 35 } set { 36 fill.hidden = value; 37 set_hidden_button (); 38 toggle_ui_visibility (); 39 } 40 } 41 42 public signal void fill_deleted (); 43 44 public FillItem (Akira.Window window, Lib.Components.Fill fill) { 45 this.window = window; 46 this.fill = fill; 47 48 create_ui (); 49 hidden = fill.hidden; 50 51 create_event_bindings (); 52 show_all (); 53 } 54 55 private void create_ui () { 56 margin_top = margin_bottom = 5; 57 58 var fill_chooser = new Gtk.Grid (); 59 fill_chooser.hexpand = true; 60 fill_chooser.margin_end = 5; 61 62 fill_chooser.add (new Widgets.ColorRow (window, new Models.ColorModel (fill))); 63 64 hidden_button = new Gtk.Button (); 65 hidden_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); 66 hidden_button.get_style_context ().add_class ("button-rounded"); 67 hidden_button.can_focus = false; 68 hidden_button.valign = Gtk.Align.CENTER; 69 70 delete_button = new Gtk.Button (); 71 delete_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); 72 delete_button.get_style_context ().add_class ("button-rounded"); 73 delete_button.can_focus = false; 74 delete_button.valign = Gtk.Align.CENTER; 75 delete_button.set_tooltip_text (_("Remove fill color")); 76 delete_button.add (new Gtk.Image.from_icon_name ("user-trash-symbolic", 77 Gtk.IconSize.SMALL_TOOLBAR)); 78 79 attach (fill_chooser, 0, 0, 1, 1); 80 attach (hidden_button, 1, 0, 1, 1); 81 attach (delete_button, 2, 0, 1, 1); 82 } 83 84 private void create_event_bindings () { 85 delete_button.clicked.connect (on_delete_item); 86 hidden_button.clicked.connect (toggle_visibility); 87 } 88 89 private void on_delete_item () { 90 fill.remove (); 91 fill_deleted (); 92 } 93 94 private void set_hidden_button () { 95 if (hidden_button_icon != null) { 96 hidden_button.remove (hidden_button_icon); 97 } 98 99 hidden_button_icon = new Gtk.Image.from_icon_name ( 100 "layer-%s-symbolic".printf (hidden ? "hidden" : "visible"), 101 Gtk.IconSize.SMALL_TOOLBAR); 102 103 hidden_button.add (hidden_button_icon); 104 hidden_button_icon.show_all (); 105 } 106 107 private void toggle_visibility () { 108 hidden = !hidden; 109 toggle_ui_visibility (); 110 } 111 112 private void toggle_ui_visibility () { 113 if (hidden) { 114 get_style_context ().add_class ("disabled"); 115 hidden_button.set_tooltip_text (_("Show fill color")); 116 return; 117 } 118 119 hidden_button.set_tooltip_text (_("Hide fill color")); 120 get_style_context ().remove_class ("disabled"); 121 } 122} 123