|
| 1 | +/* === S Y N F I G ========================================================= */ |
| 2 | +/*! \file Dialog_Guide.cpp |
| 3 | +** \brief Dialog for editing guides. |
| 4 | +** |
| 5 | +** \legal |
| 6 | +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley |
| 7 | +** |
| 8 | +** This file is part of Synfig. |
| 9 | +** |
| 10 | +** Synfig is free software: you can redistribute it and/or modify |
| 11 | +** it under the terms of the GNU General Public License as published by |
| 12 | +** the Free Software Foundation, either version 2 of the License, or |
| 13 | +** (at your option) any later version. |
| 14 | +** |
| 15 | +** Synfig 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 |
| 18 | +** GNU General Public License for more details. |
| 19 | +** |
| 20 | +** You should have received a copy of the GNU General Public License |
| 21 | +** along with Synfig. If not, see <https://www.gnu.org/licenses/>. |
| 22 | +** \endlegal |
| 23 | +*/ |
| 24 | +/* ========================================================================= */ |
| 25 | + |
| 26 | +/* === H E A D E R S ======================================================= */ |
| 27 | + |
| 28 | +#ifdef USING_PCH |
| 29 | +# include "pch.h" |
| 30 | +#else |
| 31 | +#ifdef HAVE_CONFIG_H |
| 32 | +# include <config.h> |
| 33 | +#endif |
| 34 | + |
| 35 | +#include <gui/dialogs/dialog_guide.h> |
| 36 | + |
| 37 | +#include <gui/localization.h> |
| 38 | + |
| 39 | +#include <gtkmm/box.h> |
| 40 | +#include <gtkmm/frame.h> |
| 41 | +#include <gtkmm/grid.h> |
| 42 | + |
| 43 | +#include <gui/workarea.h> |
| 44 | +#include <gui/duckmatic.h> |
| 45 | +#include <gui/app.h> |
| 46 | + |
| 47 | +#endif |
| 48 | + |
| 49 | +using namespace synfig; |
| 50 | +using namespace studio; |
| 51 | + |
| 52 | +/* === M A C R O S ========================================================= */ |
| 53 | + |
| 54 | +/* === G L O B A L S ======================================================= */ |
| 55 | +/* === P R O C E D U R E S ================================================= */ |
| 56 | + |
| 57 | +/* === M E T H O D S ======================================================= */ |
| 58 | + |
| 59 | +Dialog_Guide::Dialog_Guide(Gtk::Window& parent, etl::handle<synfig::Canvas> canvas, WorkArea* work_area): |
| 60 | + Dialog(_("Guide Editor"),parent), |
| 61 | + canvas(canvas), |
| 62 | + current_work_area(work_area), |
| 63 | + angle_adjustment(Gtk::Adjustment::create(0,-2000000000,2000000000,1,1,0)), |
| 64 | + degrees(true) |
| 65 | +{ |
| 66 | + this->set_resizable(false); |
| 67 | + assert(canvas); |
| 68 | + |
| 69 | + //Box start |
| 70 | + Gtk::Box *guide_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL)); |
| 71 | + |
| 72 | + angle_widget=manage(new Gtk::SpinButton(angle_adjustment,15,2)); |
| 73 | + angle_widget->show(); |
| 74 | + |
| 75 | + Gtk::Frame* angleFrame = manage(new Gtk::Frame(_("Rotate Guide"))); |
| 76 | + angleFrame->set_shadow_type(Gtk::SHADOW_NONE); |
| 77 | + (static_cast<Gtk::Label*>(angleFrame->get_label_widget()))->set_markup(_("<b>Rotate Guide</b>")); |
| 78 | + angleFrame->set_margin_bottom(5); |
| 79 | + angleFrame->set_margin_top(5); |
| 80 | + |
| 81 | + |
| 82 | + auto guideGrid = manage(new Gtk::Grid()); |
| 83 | + guideGrid->get_style_context()->add_class("dialog-secondary-content"); |
| 84 | + guideGrid->set_row_spacing(6); |
| 85 | + guideGrid->set_column_spacing(8); |
| 86 | + |
| 87 | + angle_type_picker.append("Degree", _("Degree")); |
| 88 | + angle_type_picker.append("Radian", _("Radian")); |
| 89 | + angle_type_picker.set_active(0); |
| 90 | + angle_type_picker.signal_changed().connect(sigc::mem_fun(*this, &Dialog_Guide::set_angle_type)); |
| 91 | + |
| 92 | + Gtk::Label* rotationAngleLabel = manage(new Gtk::Label(_("_Rotation Angle"), true)); |
| 93 | + rotationAngleLabel->set_halign(Gtk::ALIGN_CENTER); |
| 94 | + rotationAngleLabel->set_mnemonic_widget(*angle_widget); |
| 95 | + guideGrid->attach(*rotationAngleLabel, 0, 0, 1, 1); |
| 96 | + guideGrid->attach(*angle_widget , 1, 0, 1, 1); |
| 97 | + guideGrid->attach(angle_type_picker , 2, 0, 1, 1); |
| 98 | + |
| 99 | + guide_box->add(*angleFrame); |
| 100 | + guide_box->add(*guideGrid); |
| 101 | + guide_box->set_margin_bottom(5); |
| 102 | + |
| 103 | + //Box end |
| 104 | + get_content_area()->pack_start(*guide_box); |
| 105 | + |
| 106 | + Gtk::Button *apply_button(manage(new Gtk::Button(_("_Apply"), true))); |
| 107 | + apply_button->show(); |
| 108 | + add_action_widget(*apply_button, Gtk::RESPONSE_APPLY); |
| 109 | + apply_button->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &Dialog_Guide::on_ok_or_apply_pressed), false)); |
| 110 | + |
| 111 | + Gtk::Button *ok_button(manage(new Gtk::Button(_("_OK"), true))); |
| 112 | + ok_button->show(); |
| 113 | + add_action_widget(*ok_button, Gtk::RESPONSE_OK); |
| 114 | + ok_button->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &Dialog_Guide::on_ok_or_apply_pressed), true)); |
| 115 | + |
| 116 | + guide_box->show_all(); |
| 117 | +} |
| 118 | + |
| 119 | +Dialog_Guide::~Dialog_Guide() |
| 120 | +{ |
| 121 | +} |
| 122 | + |
| 123 | +void |
| 124 | +Dialog_Guide::set_current_guide(GuideList::iterator current_guide) |
| 125 | +{ |
| 126 | + curr_guide = current_guide; |
| 127 | + init_widget_values(); |
| 128 | +} |
| 129 | + |
| 130 | + |
| 131 | +void |
| 132 | +Dialog_Guide::on_ok_or_apply_pressed(bool ok) |
| 133 | +{ |
| 134 | + if (degrees && synfig::Angle::deg(curr_guide->angle).get() != angle_widget->get_value()) { |
| 135 | + curr_guide->angle = synfig::Angle::deg(angle_widget->get_value()); |
| 136 | + } else if (!degrees && curr_guide->angle.get() != angle_widget->get_value()) { |
| 137 | + curr_guide->angle = synfig::Angle::rad(angle_widget->get_value()); |
| 138 | + } |
| 139 | + |
| 140 | + if (ok) |
| 141 | + hide(); |
| 142 | + else |
| 143 | + current_work_area->get_drawing_area()->queue_draw(); |
| 144 | +} |
| 145 | + |
| 146 | +void |
| 147 | +Dialog_Guide::set_angle_type() |
| 148 | +{ |
| 149 | + Glib::ustring text = angle_type_picker.get_active_text(); |
| 150 | + if (text == "Degree") |
| 151 | + degrees=true; |
| 152 | + else if (text == "Radian") |
| 153 | + degrees=false; |
| 154 | +} |
| 155 | + |
| 156 | +void |
| 157 | +Dialog_Guide::init_widget_values() |
| 158 | +{ |
| 159 | + if(degrees) |
| 160 | + angle_widget->set_value(synfig::Angle::deg(curr_guide->angle).get()); |
| 161 | + else |
| 162 | + angle_widget->set_value(curr_guide->angle.get()); |
| 163 | +} |
0 commit comments