4 * Copyright (C) 2009 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcdisplayinfo.h"
25 #include "editlength.h"
28 #include "edlsession.h"
30 #include "localsession.h"
32 #include "mwindowgui.h"
37 EditLengthThread::EditLengthThread(MWindow *mwindow)
40 this->mwindow = mwindow;
43 EditLengthThread::~EditLengthThread()
48 void EditLengthThread::start(Edit *edit)
55 double start = mwindow->edl->local_session->get_selectionstart();
56 double end = mwindow->edl->local_session->get_selectionend();
58 // get the default length from the first edit selected
63 for(track = mwindow->edl->tracks->first;
69 int64_t start_units = track->to_units(start, 0);
70 int64_t end_units = track->to_units(end, 0);
72 for(edit = track->edits->first;
76 if(edit->startproject >= start_units &&
77 edit->startproject < end_units)
81 track->from_units(edit->length);
89 BC_DialogThread::start();
92 BC_Window* EditLengthThread::new_gui()
94 BC_DisplayInfo display_info;
95 int x = display_info.get_abs_cursor_x() - 150;
96 int y = display_info.get_abs_cursor_y() - 50;
97 EditLengthDialog *gui = new EditLengthDialog(mwindow,
101 gui->create_objects();
105 void EditLengthThread::handle_close_event(int result)
111 // mwindow->set_edit_length(edit, length);
115 mwindow->set_edit_length(length);
128 EditLengthDialog::EditLengthDialog(MWindow *mwindow,
129 EditLengthThread *thread,
132 : BC_Window(_(PROGRAM_NAME ": Edit length"),
143 this->mwindow = mwindow;
144 this->thread = thread;
147 EditLengthDialog::~EditLengthDialog()
152 void EditLengthDialog::create_objects()
154 lock_window("EditLengthDialog::create_objects");
155 add_subwindow(new BC_Title(10, 10, _("Seconds:")));
156 text = new EditLengthText(mwindow, this, 100, 10);
157 text->create_objects();
158 add_subwindow(new BC_OKButton(this));
159 add_subwindow(new BC_CancelButton(this));
164 int EditLengthDialog::close_event()
175 EditLengthText::EditLengthText(MWindow *mwindow,
176 EditLengthDialog *gui,
179 : BC_TumbleTextBox(gui,
180 (float)gui->thread->length,
187 this->mwindow = mwindow;
191 int EditLengthText::handle_event()
193 double result = atof(get_text());
194 if(fabs(result - gui->thread->length) > 0.000001)
196 gui->thread->length = result;