1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_time.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include <gtkmm/entry.h>
34 #include <gtkmm/button.h>
35 #include "widget_time.h"
42 /* === U S I N G =========================================================== */
45 //using namespace etl;
46 using namespace synfig;
47 using namespace studio;
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 /* === P R O C E D U R E S ================================================= */
55 /* === M E T H O D S ======================================================= */
57 Widget_Time::Widget_Time():
61 signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Time::refresh_value));
62 signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Time::refresh_text));
65 Widget_Time::~Widget_Time()
70 Widget_Time::refresh_text()
72 set_text(time_.get_string(fps_,App::get_time_format()));
77 Widget_Time::set_value(const synfig::Time &data)
84 Widget_Time::get_value() const
90 Widget_Time::set_fps(float x)
97 Widget_Time::refresh_value()
101 Time newtime(get_text(),fps_);
102 if(abs(newtime-time_)>=0.001)
106 signal_value_changed()();
111 throw string("Caught unknown exception");
116 Widget_Time::on_event(GdkEvent* event)
118 const Time scroll_amount(0.25);
123 if(event->scroll.direction==GDK_SCROLL_DOWN || event->scroll.direction==GDK_SCROLL_LEFT)
125 time_-=scroll_amount;
127 signal_value_changed()();
129 else if(event->scroll.direction==GDK_SCROLL_UP || event->scroll.direction==GDK_SCROLL_RIGHT)
131 time_+=scroll_amount;
133 signal_value_changed()();
137 case GDK_BUTTON_PRESS:
138 case GDK_2BUTTON_PRESS:
139 case GDK_3BUTTON_PRESS:
147 return Gtk::Entry::on_event(event);
151 Widget_Time::on_focus_out_event(GdkEventFocus* event)
155 return Gtk::Entry::on_focus_out_event(event);
159 Widget_Time::on_focus_in_event(GdkEventFocus* event)
161 // if defined, show the full time format "0h 0m 5s 0f" when the time widget gets focus
162 if (getenv("SYNFIG_SHOW_FULL_TIME_ON_FOCUS"))
163 set_text(time_.get_string(fps_,App::get_time_format()|Time::FORMAT_FULL));
165 return Gtk::Entry::on_focus_in_event(event);