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
10 ** Copyright (c) 2008 Paul Wise
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
23 /* ========================================================================= */
25 /* === H E A D E R S ======================================================= */
34 #include <gtkmm/entry.h>
35 #include <gtkmm/button.h>
36 #include "widget_time.h"
43 /* === U S I N G =========================================================== */
46 //using namespace etl;
47 using namespace synfig;
48 using namespace studio;
50 /* === M A C R O S ========================================================= */
52 /* === G L O B A L S ======================================================= */
54 /* === P R O C E D U R E S ================================================= */
56 /* === M E T H O D S ======================================================= */
58 Widget_Time::Widget_Time():
62 signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Time::refresh_value));
63 signal_activate().connect(sigc::mem_fun(*this,&studio::Widget_Time::refresh_text));
66 Widget_Time::~Widget_Time()
71 Widget_Time::refresh_text()
73 set_text(time_.get_string(fps_,App::get_time_format()));
78 Widget_Time::set_value(const synfig::Time &data)
85 Widget_Time::get_value() const
91 Widget_Time::set_fps(float x)
98 Widget_Time::refresh_value()
102 Time newtime(get_text(),fps_);
103 if(abs(newtime-time_)>=0.001)
107 signal_value_changed()();
112 throw string("Caught unknown exception");
117 Widget_Time::on_event(GdkEvent* event)
119 const Time scroll_amount(0.25);
124 if(event->scroll.direction==GDK_SCROLL_DOWN || event->scroll.direction==GDK_SCROLL_LEFT)
126 time_-=scroll_amount;
128 signal_value_changed()();
130 else if(event->scroll.direction==GDK_SCROLL_UP || event->scroll.direction==GDK_SCROLL_RIGHT)
132 time_+=scroll_amount;
134 signal_value_changed()();
138 case GDK_BUTTON_PRESS:
139 case GDK_2BUTTON_PRESS:
140 case GDK_3BUTTON_PRESS:
148 return Gtk::Entry::on_event(event);
152 Widget_Time::on_focus_out_event(GdkEventFocus* event)
156 return Gtk::Entry::on_focus_out_event(event);
160 Widget_Time::on_focus_in_event(GdkEventFocus* event)
162 // if defined, show the full time format "0h 0m 5s 0f" when the time widget gets focus
163 if (getenv("SYNFIG_SHOW_FULL_TIME_ON_FOCUS"))
164 set_text(time_.get_string(fps_,App::get_time_format()|Time::FORMAT_FULL));
166 return Gtk::Entry::on_focus_in_event(event);