1 /* === S Y N F I G ========================================================= */
2 /*!	\file dialogs/dialog_template.cpp
3 **	\brief Dialog design list and panel template Implemetation
4 **
5 **	$Id$
6 **
7 **	\legal
8 **	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **	Copyright (c) 2016 Jerome Blanchi
10 **
11 **	This package is free software; you can redistribute it and/or
12 **	modify it under the terms of the GNU General Public License as
13 **	published by the Free Software Foundation; either version 2 of
14 **	the License, or (at your option) any later version.
15 **
16 **	This package is distributed in the hope that it will be useful,
17 **	but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **	General Public License for more details.
20 **	\endlegal
21 */
22 /* ========================================================================= */
23 
24 /* === H E A D E R S ======================================================= */
25 
26 #ifdef USING_PCH
27 #	include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #	include <config.h>
31 #endif
32 
33 #include "dialog_template.h"
34 
35 #include <gtkmm/eventbox.h>
36 
37 #include <gui/localization.h>
38 
39 #endif
40 
41 /* === U S I N G =========================================================== */
42 using namespace synfig;
43 using namespace std;
44 using namespace studio;
45 
46 /* === M A C R O S ========================================================= */
47 // TODO Group All HARDCODED user interface information somewhere "global"
48 // TODO All UI info from .rc
49 #define DIALOG_TEMPLATE_UI_INIT_GRID(grid) 					\
50 		grid->set_orientation(Gtk::ORIENTATION_HORIZONTAL);		\
51 		grid->set_row_spacing(6);								\
52 		grid->set_column_spacing(12);							\
53 		grid->set_border_width(8);								\
54 		grid->set_column_homogeneous(false);
55 
56 /* === G L O B A L S ======================================================= */
57 
58 /* === P R O C E D U R E S ================================================= */
59 
60 /* === M E T H O D S ======================================================= */
Dialog_Template(Gtk::Window & parent,synfig::String dialog_title)61 Dialog_Template::Dialog_Template(Gtk::Window& parent, synfig::String dialog_title):
62 	Dialog(dialog_title.c_str(),parent,true),
63 	page_index(0)
64 {
65 		// Setup the buttons
66 	Gtk::Button *restore_button(manage(new class Gtk::Button(_("Restore Defaults"))));
67 	restore_button->show();
68 	add_action_widget(*restore_button,1);
69 	restore_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Template::on_restore_pressed));
70 
71 	Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-cancel"))));
72 	cancel_button->show();
73 	add_action_widget(*cancel_button,0);
74 	cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Template::hide));
75 
76 	Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
77 	ok_button->show();
78 	add_action_widget(*ok_button,2);
79 	ok_button->signal_clicked().connect(sigc::mem_fun(*this, &Dialog_Template::on_ok_pressed));
80 
81 
82 	//! TODO Make global this design to being used else where in other dialogs
83 	//! TODO UI design information to .rc
84 	// Style for title and section
85 	Pango::AttrInt attr = Pango::Attribute::create_attr_weight(Pango::WEIGHT_BOLD);
86 	//! Nota section_attrlist also use for BOLDING " X " string in document page
87 	section_attrlist.insert(attr);
88 	title_attrlist.insert(attr);
89 	Pango::AttrInt pango_size(Pango::Attribute::create_attr_size(Pango::SCALE*26));
90 	title_attrlist.change(pango_size);
91 	// create negative foreground/background attributes
92 	Gdk::RGBA colorcontext(get_style_context()->get_color());
93 	Gdk::RGBA bgcolorcontext(get_style_context()->get_background_color());
94 	Pango::AttrColor bgcolor = Pango::Attribute::create_attr_background(colorcontext.get_red_u(),
95 			colorcontext.get_green_u(),
96 			colorcontext.get_blue_u()
97 			);
98 	title_attrlist.change(bgcolor);
99 	Pango::AttrColor color = Pango::Attribute::create_attr_foreground(bgcolorcontext.get_red_u(),
100 			bgcolorcontext.get_green_u(),
101 			bgcolorcontext.get_blue_u()
102 			);
103 	title_attrlist.change(color);
104 
105 	// Notebook
106 	notebook=manage(new class Gtk::Notebook());
107 	// Main preferences notebook
108 	notebook->set_show_tabs (false);
109 	notebook->set_show_border (false);
110 
111 	{
112 		// WARNING FIXED ORDER : the page added to notebook same has treeview (see create_xxxx_page() upper)
113 		categories_reftreemodel = Gtk::TreeStore::create(categories);
114 		categories_treeview.set_model(categories_reftreemodel);
115 
116 		categories_treeview.set_headers_visible(false);
117 		categories_treeview.append_column(_("Category"), categories.category_name);
118 
119 		categories_treeview.get_selection()->signal_changed().connect(
120 				sigc::mem_fun(*this, &Dialog_Template::on_treeviewselection_changed));
121 
122 		categories_scrolledwindow.add(categories_treeview);
123 		categories_scrolledwindow.set_size_request(-1, 80);
124 		categories_scrolledwindow.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
125 	}
126 
127 	main_grid.attach(categories_scrolledwindow, 0, 0, 1 ,1);
128 	notebook->show_all();
129 
130 	main_grid.attach(*notebook, 1, 0, 1, 1);
131 	main_grid.set_border_width(6);
132 
133 	//! TODO create a warning zone to push message on rare events (like no brush path, zero fps ...)
134 	//! this warning zone could also hold normal message like : "x change to come"  (and a link to "Changes summary" page)
135 
136 	get_vbox()->pack_start(main_grid);
137 	get_vbox()->set_border_width(12);
138 
139 	show_all_children();
140 }
141 
~Dialog_Template()142 Dialog_Template::~Dialog_Template()
143 {
144 }
145 
146 
147 void
on_ok_pressed()148 Dialog_Template::on_ok_pressed()
149 {
150 	on_apply_pressed();
151 	hide();
152 }
153 
154 void
on_treeviewselection_changed()155 Dialog_Template::on_treeviewselection_changed()
156 {
157 	if(const Gtk::TreeModel::iterator iter = categories_treeview.get_selection()->get_selected())
158 	{
159 		notebook->set_current_page((int) ((*iter)[categories.category_id]));
160 	}
161 }
162 
163 void
attach_label(Gtk::Grid * grid,synfig::String str,guint row)164 Dialog_Template::attach_label(Gtk::Grid *grid, synfig::String str, guint row)
165 {
166 	Gtk::Label* label(manage(new Gtk::Label((str + ":").c_str())));
167 	label->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
168 	label->set_margin_start(10);
169 	grid->attach(*label, 0, row, 1, 1);
170 }
171 
172 void
attach_label_section(Gtk::Grid * grid,synfig::String str,guint row)173 Dialog_Template::attach_label_section(Gtk::Grid *grid, synfig::String str, guint row)
174 {
175 	Gtk::Label* label(manage(new Gtk::Label(str)));
176 	label->set_attributes(section_attrlist);
177 	label->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
178 	grid->attach(*label, 0, row, 1, 1);
179 }
180 
181 void
attach_label_title(Gtk::Grid * grid,synfig::String str)182 Dialog_Template::attach_label_title(Gtk::Grid *grid, synfig::String str)
183 {
184 	Gtk::Label* label(manage(new Gtk::Label(str)));
185 	label->set_attributes(title_attrlist);
186 	label->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
187 	label->set_margin_start(20);
188 	Gtk::EventBox* box(manage(new Gtk::EventBox()));
189 	box->add(*label);
190 	box->override_background_color(get_style_context()->get_color());
191 	grid->attach(*box, 0, 0, 1, 1);
192 }
193 
194 Gtk::Label*
attach_label(Gtk::Grid * grid,synfig::String str,guint row,guint col,bool endstring)195 Dialog_Template::attach_label(Gtk::Grid *grid, synfig::String str, guint row, guint col, bool endstring)
196 {
197 	str = endstring?str+":":str;
198 	Gtk::Label* label(manage(new Gtk::Label(str)));
199 	label->set_alignment(Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
200 	grid->attach(*label, col, row, 1, 1);
201 	return label;
202 }
203 
204 Dialog_Template::PageInfo
add_page(synfig::String page_title)205 Dialog_Template::add_page(synfig::String page_title)
206 {
207 	Dialog_Template::PageInfo pageinfo;
208 
209 	pageinfo.grid=manage(new Gtk::Grid());
210 	Gtk::Grid *page_grid=manage(new Gtk::Grid());
211 	DIALOG_TEMPLATE_UI_INIT_GRID(pageinfo.grid);
212 	notebook->append_page(*page_grid,page_title);
213 	attach_label_title(page_grid,page_title);
214 	page_grid->attach(*(pageinfo.grid), 0,1,1,1);
215 
216 	pageinfo.row = *(categories_reftreemodel->append());
217 	pageinfo.row[categories.category_id] = page_index++;
218 	pageinfo.row[categories.category_name] = page_title;
219 
220 	return pageinfo;
221 }
222 
223 Dialog_Template::PageInfo
add_child_page(synfig::String page_title,Gtk::TreeRow parentrow)224 Dialog_Template::add_child_page(synfig::String page_title, Gtk::TreeRow parentrow)
225 {
226 	Dialog_Template::PageInfo pageinfo;
227 
228 	pageinfo.grid=manage(new Gtk::Grid());
229 	Gtk::Grid *page_grid=manage(new Gtk::Grid());
230 	DIALOG_TEMPLATE_UI_INIT_GRID(pageinfo.grid);
231 	notebook->append_page(*page_grid,page_title);
232 	attach_label_title(page_grid,page_title);
233 	page_grid->attach(*(pageinfo.grid), 0,1,1,1);
234 
235 	pageinfo.row = *(categories_reftreemodel->append(parentrow.children()));
236 	pageinfo.row[categories.category_id] = page_index++;
237 	pageinfo.row[categories.category_name] = page_title;
238 
239 	categories_treeview.expand_all();
240 
241 	return pageinfo;
242 }
243