BreakType.vala 4.99 KB
Newer Older
1
/*
2
 * This file is part of GNOME Break Timer.
3
 * 
4
 * GNOME Break Timer is free software: you can redistribute it and/or modify
5 6 7 8
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
9
 * GNOME Break Timer is distributed in the hope that it will be useful,
10 11 12 13 14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
15
 * along with GNOME Break Timer.  If not, see <http://www.gnu.org/licenses/>.
16 17
 */

18
public abstract class BreakType : Object {
19
	public string id { get; private set; }
20
	public BreakStatus? status;
21 22 23 24

	public BreakInfoPanel info_panel;
	public BreakStatusPanel status_panel;
	public BreakSettingsPanel settings_panel;
25 26

	public Settings settings;
27
	
28
	public BreakType (string id, Settings settings) {
29
		this.id = id;
30
		this.settings = settings;
31
	}
32

33
	public signal void status_changed (BreakStatus? status);
34

35 36 37 38
	public virtual void initialize () {
		this.info_panel = this.get_info_panel ();
		this.status_panel = this.get_status_panel ();
		this.settings_panel = this.get_settings_panel ();
39 40
	}

41
	protected void update_status (BreakStatus? status) {
42
		this.status = status;
43
		this.status_changed (status);
44
	}
45
	
46 47 48
	protected abstract BreakInfoPanel get_info_panel ();
	protected abstract BreakStatusPanel get_status_panel ();
	protected abstract BreakSettingsPanel get_settings_panel ();
49 50 51
}

public abstract class BreakInfoPanel : Gtk.Grid {
52 53
	public BreakType break_type { public get; private set; }
	public string title { public get; private set; }
54 55 56

	private Gtk.Label heading_label;
	private Gtk.Label description_label;
57
	private Gtk.Label detail_label;
58

59 60
	public BreakInfoPanel (BreakType break_type, string title) {
		Object ();
61 62 63
		this.break_type = break_type;
		this.title = title;

64 65 66 67
		this.set_orientation (Gtk.Orientation.VERTICAL);
		this.set_hexpand (true);
		this.set_row_spacing (24);
		this.get_style_context ().add_class ("_break-info");
68

69 70 71
		this.heading_label = new Gtk.Label (null);
		this.add (this.heading_label);
		this.heading_label.get_style_context ().add_class ("_break-info-heading");
72

73 74 75 76 77
		this.description_label = new Gtk.Label (null);
		this.add (this.description_label);
		this.description_label.set_line_wrap (true);
		this.description_label.set_justify (Gtk.Justification.CENTER);
		this.description_label.set_max_width_chars (60);
78

79 80 81
		this.detail_label = new Gtk.Label (null);
		this.add (this.detail_label);

82
		this.show_all ();
83 84
	}

85 86
	protected void set_heading (string heading) {
		this.heading_label.set_label (heading);
87 88
	}

89 90
	protected void set_description (string description) {
		this.description_label.set_label (description);
91
	}
92 93 94 95

	protected void set_detail (string detail) {
		this.detail_label.set_label (detail);
	}
96 97
}

98
public abstract class BreakStatusPanel : Gtk.Grid {
99 100
	public BreakType break_type { public get; private set; }
	public bool is_enabled { get; set; default=false; }
101

102 103
	public BreakStatusPanel (BreakType break_type) {
		Object ();
104 105
		this.break_type = break_type;

106
		this.get_style_context ().add_class ("_break-status");
107 108 109
	}
}

110 111 112 113
public abstract class BreakSettingsPanel : Gtk.Grid {
	private Gtk.Grid header;
	private Gtk.Grid details;

114 115
	public BreakSettingsPanel (BreakType break_type, string title, string? description) {
		Object ();
116

117 118
		this.set_orientation (Gtk.Orientation.VERTICAL);
		this.set_row_spacing (10);
119

120 121 122
		this.header = new Gtk.Grid ();
		this.add (this.header);
		this.header.set_column_spacing (12);
123
		
124 125 126 127
		var title_grid = new Gtk.Grid ();
		this.set_header (title_grid);
		title_grid.set_orientation (Gtk.Orientation.VERTICAL);
		title_grid.set_row_spacing (4);
128
		
129 130 131 132 133 134
		var title_label = new Gtk.Label (title);
		title_grid.add (title_label);
		title_label.get_style_context ().add_class ("_settings-title");
		title_label.set_halign (Gtk.Align.FILL);
		title_label.set_hexpand (true);
		title_label.set_justify (Gtk.Justification.CENTER);
135
		
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
		// var description_label = new Gtk.Label ("<small>%s</small>".printf (description));
		// title_grid.add (description_label);
		// description_label.get_style_context ().add_class ("_settings-description");
		// description_label.set_use_markup (true);
		// description_label.set_halign (Gtk.Align.FILL);
		// description_label.set_hexpand (true);
		// description_label.set_justify (Gtk.Justification.CENTER);

		this.details = new Gtk.Grid ();
		this.add (this.details);
		this.details.set_margin_left (12);
		this.details.set_halign (Gtk.Align.CENTER);
		this.details.set_hexpand (true);

		this.show_all ();
151 152
	}

153 154
	protected void set_header (Gtk.Widget content) {
		this.header.attach (content, 0, 0, 1, 1);
155 156
	}

157 158 159 160
	protected void set_header_action (Gtk.Widget content) {
		this.header.attach (content, 1, 0, 1, 1);
		content.set_halign (Gtk.Align.END);
		content.set_valign (Gtk.Align.CENTER);
161 162
	}
	
163 164
	protected void set_details (Gtk.Widget content) {
		this.details.add (content);
165
	}
166
}