1 /* === S Y N F I G ========================================================= */
2 /*! \file canvasproperties.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "canvasproperties.h"
33 #include <gtkmm/frame.h>
34 #include <gtkmm/table.h>
35 #include <gtkmm/label.h>
36 #include <gtkmm/alignment.h>
37 #include <synfigapp/canvasinterface.h>
38 #include "metadatatreestore.h"
39 #include <gtkmm/treeview.h>
40 #include <gtkmm/scrolledwindow.h>
47 /* === U S I N G =========================================================== */
51 using namespace synfig;
52 using namespace studio;
54 /* === M A C R O S ========================================================= */
56 /* === G L O B A L S ======================================================= */
58 /* === P R O C E D U R E S ================================================= */
60 /* === M E T H O D S ======================================================= */
62 CanvasProperties::CanvasProperties(Gtk::Window& parent,etl::handle<synfigapp::CanvasInterface> canvas_interface):
63 Gtk::Dialog(_("Canvas Properties"),parent,false,true),
64 canvas_interface_(canvas_interface)
66 widget_rend_desc.show();
67 widget_rend_desc.signal_changed().connect(sigc::mem_fun(*this,&studio::CanvasProperties::on_rend_desc_changed));
69 Gtk::Alignment *dialogPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
70 dialogPadding->set_padding(12, 12, 12, 12);
71 get_vbox()->pack_start(*dialogPadding, false, false, 0);
73 Gtk::VBox *dialogBox = manage(new Gtk::VBox(false, 12));
74 dialogPadding->add(*dialogBox);
76 Gtk::Frame *info_frame=manage(new Gtk::Frame(_("Canvas Info")));
77 info_frame->set_shadow_type(Gtk::SHADOW_NONE);
78 ((Gtk::Label *) info_frame->get_label_widget())->set_markup(_("<b>Canvas Info</b>"));
79 dialogBox->pack_start(*info_frame, false, false, 0);
81 Gtk::Alignment *infoPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
82 infoPadding->set_padding(6, 0, 24, 0);
83 info_frame->add(*infoPadding);
85 Gtk::Table *info_table=manage(new Gtk::Table(2,2,false));
86 info_table->set_row_spacings(6);
87 info_table->set_col_spacings(12);
88 infoPadding->add(*info_table);
90 // The root canvas doesn't have an ID, so don't
91 // display it if this is a root canvas.
92 if(!canvas_interface_->get_canvas()->is_root())
94 Gtk::Label *idLabel = manage(new Gtk::Label(_("_ID"), true));
95 idLabel->set_alignment(0, 0.5);
96 idLabel->set_mnemonic_widget(entry_id);
97 info_table->attach(*idLabel, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
98 info_table->attach(entry_id, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
100 Gtk::Label *nameLabel = manage(new Gtk::Label(_("_Name"), true));
101 nameLabel->set_alignment(0, 0.5);
102 nameLabel->set_mnemonic_widget(entry_name);
103 Gtk::Label *descriptionLabel = manage(new Gtk::Label(_("_Description"), true));
104 descriptionLabel->set_alignment(0, 0.5);
105 descriptionLabel->set_mnemonic_widget(entry_description);
106 info_table->attach(*nameLabel, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
107 info_table->attach(*descriptionLabel, 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
108 info_table->attach(entry_name, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
109 info_table->attach(entry_description, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
111 dialogBox->pack_start(widget_rend_desc, false, false, 0);
113 canvas_interface_->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&studio::CanvasProperties::refresh));
115 Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
117 add_action_widget(*ok_button,2);
118 ok_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_ok_pressed));
120 Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
121 apply_button->show();
122 add_action_widget(*apply_button,1);
123 apply_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_apply_pressed));
125 Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
126 cancel_button->show();
127 add_action_widget(*cancel_button,0);
128 cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_cancel_pressed));
130 //set_default_response(1);
132 get_vbox()->show_all();
139 CanvasProperties::create_meta_data_view()
141 MetaDataTreeStore::Model model;
142 meta_data_tree_view=(manage(new class Gtk::TreeView()));
144 meta_data_tree_view->append_column(_("Key"),model.key);
145 meta_data_tree_view->append_column_editable(_("Data"),model.data);
146 meta_data_tree_view->set_model(MetaDataTreeStore::create(canvas_interface_));
147 meta_data_tree_view->set_rules_hint();
148 meta_data_tree_view->show();
150 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
151 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
152 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
153 scrolledwindow->add(*meta_data_tree_view);
154 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
155 scrolledwindow->show();
159 Gtk::Table *table=manage(new Gtk::Table());
160 table->attach(*scrolledwindow, 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
162 Gtk::Button* button_add(manage(new Gtk::Button(Gtk::StockID("gtk-add"))));
164 button_add->signal_clicked().connect(sigc::mem_fun(*this,&CanvasProperties::on_button_meta_data_add));
165 table->attach(*button_add, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
167 Gtk::Button* button_delete(manage(new Gtk::Button(Gtk::StockID("gtk-delete"))));
168 button_delete->show();
169 button_delete->signal_clicked().connect(sigc::mem_fun(*this,&CanvasProperties::on_button_meta_data_delete));
170 table->attach(*button_delete, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
177 CanvasProperties::on_button_meta_data_add()
180 if(App::dialog_entry(_("New MetaData Entry"), _("Please enter the name of the key"),key) && !key.empty())
182 canvas_interface_->set_meta_data(key," ");
188 CanvasProperties::on_button_meta_data_delete()
193 CanvasProperties::update_title()
195 set_title(_("Properties")+String(" - ")+canvas_interface_->get_canvas()->get_name());
199 CanvasProperties::refresh()
201 widget_rend_desc.set_rend_desc(canvas_interface_->get_canvas()->rend_desc());
202 entry_id.set_text(canvas_interface_->get_canvas()->get_id());
203 entry_name.set_text(canvas_interface_->get_canvas()->get_name());
204 entry_description.set_text(canvas_interface_->get_canvas()->get_description());
206 dirty_rend_desc=false;
211 CanvasProperties::~CanvasProperties()
216 CanvasProperties::on_rend_desc_changed()
218 dirty_rend_desc=true;
222 CanvasProperties::on_apply_pressed()
224 if(entry_id.get_text()!=canvas_interface_->get_canvas()->get_id())
225 canvas_interface_->set_id(entry_id.get_text());
226 if(entry_name.get_text()!=canvas_interface_->get_canvas()->get_name())
227 canvas_interface_->set_name(entry_name.get_text());
228 if(entry_description.get_text()!=canvas_interface_->get_canvas()->get_description())
229 canvas_interface_->set_description(entry_description.get_text());
230 if(dirty_rend_desc) // do this last, because it causes the dialog to be refreshed with currently set values
231 canvas_interface_->set_rend_desc(widget_rend_desc.get_rend_desc());
233 dirty_rend_desc=false;
237 CanvasProperties::on_ok_pressed()
244 CanvasProperties::on_cancel_pressed()