4 * Copyright (C) 2008 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
25 #include "awindowgui.h"
28 #include "editpopup.h"
30 #include "edlsession.h"
34 #include "localsession.h"
35 #include "mainerror.h"
36 #include "mainsession.h"
38 #include "mwindowgui.h"
39 #include "plugindialog.h"
40 #include "resizetrackthread.h"
44 #include "trackcanvas.h"
48 EditPopup::EditPopup(MWindow *mwindow, MWindowGUI *gui)
49 : BC_PopupMenu(0, 0, 0, "", 0)
51 this->mwindow = mwindow;
61 EditPopup::~EditPopup()
65 void EditPopup::create_objects()
67 add_item(new EditPopupClearSelect(mwindow, this));
68 add_item(new EditPopupCopy(mwindow, this));
69 add_item(new EditPopupCut(mwindow, this));
70 add_item(new EditPopupMute(mwindow, this));
71 add_item(new EditPopupCopyPack(mwindow, this));
72 add_item(new EditPopupCutPack(mwindow, this));
73 add_item(new EditPopupMutePack(mwindow, this));
74 add_item(new EditPopupPaste(mwindow, this));
75 add_item(new EditPopupOverwrite(mwindow, this));
76 add_item(new EditPopupFindAsset(mwindow, this));
77 add_item(new EditPopupShow(mwindow, this));
78 add_item(new EditPopupUserTitle(mwindow, this));
79 add_item(new EditPopupTitleColor(mwindow, this));
82 int EditPopup::activate_menu(Track *track, Edit *edit,
83 PluginSet *pluginset, Plugin *plugin, double position)
87 this->pluginset = pluginset;
88 this->plugin = plugin;
89 this->position = position;
90 return BC_PopupMenu::activate_menu();
93 EditPopupClearSelect::EditPopupClearSelect(MWindow *mwindow, EditPopup *popup)
94 : BC_MenuItem(_("Clear Select"),_("Ctrl-Shift-A"),'A')
96 this->mwindow = mwindow;
102 int EditPopupClearSelect::handle_event()
104 mwindow->edl->tracks->clear_selected_edits();
105 popup->gui->draw_overlays(1);
109 EditPopupCopy::EditPopupCopy(MWindow *mwindow, EditPopup *popup)
110 : BC_MenuItem(_("Copy"),_("Ctrl-c"),'c')
112 this->mwindow = mwindow;
117 int EditPopupCopy::handle_event()
119 mwindow->selected_to_clipboard(0);
123 EditPopupCopyPack::EditPopupCopyPack(MWindow *mwindow, EditPopup *popup)
124 : BC_MenuItem(_("Copy pack"),_("Ctrl-Shift-C"),'C')
126 this->mwindow = mwindow;
132 int EditPopupCopyPack::handle_event()
134 mwindow->selected_to_clipboard(1);
138 EditPopupCut::EditPopupCut(MWindow *mwindow, EditPopup *popup)
139 : BC_MenuItem(_("Cut"),_("Ctrl-x"),'x')
141 this->mwindow = mwindow;
146 int EditPopupCut::handle_event()
148 mwindow->cut_selected_edits(1, 0);
152 EditPopupCutPack::EditPopupCutPack(MWindow *mwindow, EditPopup *popup)
153 : BC_MenuItem(_("Cut pack"),_("Ctrl-z"),'z')
155 this->mwindow = mwindow;
160 int EditPopupCutPack::handle_event()
162 mwindow->cut_selected_edits(1, 1);
166 EditPopupMute::EditPopupMute(MWindow *mwindow, EditPopup *popup)
167 : BC_MenuItem(_("Mute"),_("Ctrl-m"),'m')
169 this->mwindow = mwindow;
174 int EditPopupMute::handle_event()
176 mwindow->cut_selected_edits(0, 0);
180 EditPopupMutePack::EditPopupMutePack(MWindow *mwindow, EditPopup *popup)
181 : BC_MenuItem(_("Mute pack"),_("Ctrl-Shift-M"),'M')
183 this->mwindow = mwindow;
189 int EditPopupMutePack::handle_event()
191 mwindow->cut_selected_edits(0, 1);
195 EditPopupPaste::EditPopupPaste(MWindow *mwindow, EditPopup *popup)
196 : BC_MenuItem(_("Paste"),_("Ctrl-v"),'v')
198 this->mwindow = mwindow;
203 int EditPopupPaste::handle_event()
205 mwindow->paste(popup->position, popup->track, 0, 0);
206 mwindow->edl->tracks->clear_selected_edits();
207 popup->gui->draw_overlays(1);
208 if( mwindow->session->current_operation == DROP_TARGETING ) {
209 mwindow->session->current_operation = NO_OPERATION;
210 popup->gui->update_cursor();
215 EditPopupOverwrite::EditPopupOverwrite(MWindow *mwindow, EditPopup *popup)
216 : BC_MenuItem(_("Overwrite"),_("Ctrl-b"),'b')
218 this->mwindow = mwindow;
223 int EditPopupOverwrite::handle_event()
225 mwindow->paste(popup->position, popup->track, 0, -1);
226 mwindow->edl->tracks->clear_selected_edits();
227 popup->gui->draw_overlays(1);
228 if( mwindow->session->current_operation == DROP_TARGETING ) {
229 mwindow->session->current_operation = NO_OPERATION;
230 popup->gui->update_cursor();
235 EditPopupFindAsset::EditPopupFindAsset(MWindow *mwindow, EditPopup *popup)
236 : BC_MenuItem(_("Find in Resources"))
238 this->mwindow = mwindow;
242 int EditPopupFindAsset::handle_event()
244 Edit *edit = popup->edit;
246 Indexable *idxbl = (Indexable *)edit->asset;
247 if( !idxbl ) idxbl = (Indexable *)edit->nested_edl;
249 AWindowGUI *agui = mwindow->awindow->gui;
250 agui->lock_window("EditPopupFindAsset::handle_event");
251 AssetPicon *picon = 0;
252 for( int i=0, n=agui->assets.size(); i<n; ++i ) {
253 AssetPicon *ap = (AssetPicon *)agui->assets[i];
254 int found = ap->indexable && ( idxbl == ap->indexable ||
255 !strcmp(idxbl->path, ap->indexable->path) );
256 if( found && !picon ) picon = ap;
257 ap->set_selected(found);
260 int selected_folder = picon->indexable->folder_no;
261 mwindow->edl->session->awindow_folder = selected_folder;
262 for( int i=0,n=agui->folders.size(); i<n; ++i ) {
263 AssetPicon *folder_item = (AssetPicon *)agui->folders[i];
264 int selected = folder_item->foldernum == selected_folder ? 1 : 0;
265 folder_item->set_selected(selected);
268 agui->unlock_window();
269 agui->async_update_assets();
276 EditPopupUserTitle::EditPopupUserTitle(MWindow *mwindow, EditPopup *popup)
277 : BC_MenuItem(_("User title..."))
279 this->mwindow = mwindow;
281 dialog_thread = new EditUserTitleDialogThread(this);
284 EditPopupUserTitle::~EditPopupUserTitle()
286 delete dialog_thread;
289 int EditPopupUserTitle::handle_event()
292 dialog_thread->close_window();
293 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
294 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
295 dialog_thread->start(wx, wy);
300 void EditUserTitleDialogThread::start(int wx, int wy)
302 this->wx = wx; this->wy = wy;
303 BC_DialogThread::start();
306 EditUserTitleDialogThread::EditUserTitleDialogThread(EditPopupUserTitle *edit_title)
308 this->edit_title = edit_title;
311 EditUserTitleDialogThread::~EditUserTitleDialogThread()
316 BC_Window* EditUserTitleDialogThread::new_gui()
318 MWindow *mwindow = edit_title->mwindow;
319 EditPopup *popup = edit_title->popup;
320 window = new EditPopupUserTitleWindow(mwindow, popup, wx, wy);
321 window->create_objects();
325 void EditUserTitleDialogThread::handle_close_event(int result)
330 void EditUserTitleDialogThread::handle_done_event(int result)
333 MWindow *mwindow = edit_title->mwindow;
334 EditPopup *popup = edit_title->popup;
335 strcpy(popup->edit->user_title, window->title_text->get_text());
336 mwindow->gui->lock_window("EditUserTitleDialogThread::handle_done_event");
337 mwindow->gui->draw_canvas(1, 0);
338 mwindow->gui->flash_canvas(1);
339 mwindow->gui->unlock_window();
342 EditPopupUserTitleWindow::EditPopupUserTitleWindow(MWindow *mwindow,
343 EditPopup *popup, int wx, int wy)
344 : BC_Window(_(PROGRAM_NAME ": Set edit title"), wx, wy,
345 300, 130, 300, 130, 0, 0, 1)
347 this->mwindow = mwindow;
349 strcpy(new_text, !popup->edit ? "" : popup->edit->user_title);
352 EditPopupUserTitleWindow::~EditPopupUserTitleWindow()
356 void EditPopupUserTitleWindow::create_objects()
358 lock_window("EditPopupUserTitleWindow::create_objects");
359 int x = 10, y = 10, x1;
360 BC_Title *title = new BC_Title(x1=x, y, _("User title:"));
361 add_subwindow(title); x1 += title->get_w() + 10;
362 title_text = new EditPopupUserTitleText(this, mwindow, x1, y, new_text);
363 add_subwindow(title_text);
365 add_tool(new BC_OKButton(this));
366 add_tool(new BC_CancelButton(this));
375 EditPopupUserTitleText::EditPopupUserTitleText(EditPopupUserTitleWindow *window,
376 MWindow *mwindow, int x, int y, const char *text)
377 : BC_TextBox(x, y, window->get_w()-x-15, 1, text)
379 this->window = window;
380 this->mwindow = mwindow;
383 EditPopupUserTitleText::~EditPopupUserTitleText()
387 int EditPopupUserTitleText::handle_event()
389 if( get_keypress() == RETURN )
395 EditPopupTitleColor::EditPopupTitleColor(MWindow *mwindow, EditPopup *popup)
396 : BC_MenuItem(_("Bar Color..."))
398 this->mwindow = mwindow;
402 EditPopupTitleColor::~EditPopupTitleColor()
407 int EditPopupTitleColor::handle_event()
410 int color = popup->mwindow->get_title_color(popup->edit);
411 if( color < 0 ) color = popup->mwindow->theme->get_color_title_bg();
413 color_picker = new EditTitleColorPicker(popup);
414 color_picker->start_window(color, -1, 1);
419 EditTitleColorDefault::EditTitleColorDefault(
420 EditTitleColorPicker *color_picker, int x, int y)
421 : BC_GenericButton(x, y, _("default"))
423 this->color_picker = color_picker;
426 int EditTitleColorDefault::handle_event()
428 int color = color_picker->popup->mwindow->theme->get_color_title_bg();
429 color_picker->update_gui(color, -1);
433 EditTitleColorPicker::EditTitleColorPicker(EditPopup *popup)
434 : ColorPicker(0, _("Bar Color"))
439 EditTitleColorPicker::~EditTitleColorPicker()
442 void EditTitleColorPicker::create_objects(ColorWindow *gui)
444 int y = gui->get_h() - BC_CancelButton::calculate_h() - 50;
445 int x = gui->get_w() - BC_GenericButton::calculate_w(gui, _("default")) - 15;
446 gui->add_subwindow(new EditTitleColorDefault(this, x, y));
449 int EditTitleColorPicker::handle_new_color(int color, int alpha)
455 void EditTitleColorPicker::handle_done_event(int result)
458 EDL *edl = popup->mwindow->edl;
460 for( Track *track=edl->tracks->first; track; track=track->next ) {
461 if( !track->record ) continue;
462 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
463 if( !edit->is_selected ) continue;
469 edl->tracks->clear_selected_edits();
471 popup->edit->color = color;
473 MWindowGUI *mwindow_gui = popup->mwindow->gui;
474 mwindow_gui->lock_window("GWindowColorUpdate::run");
475 mwindow_gui->draw_trackmovement();
476 mwindow_gui->unlock_window();
480 EditPopupShow::EditPopupShow(MWindow *mwindow, EditPopup *popup)
481 : BC_MenuItem(_("Show edit"))
483 this->mwindow = mwindow;
485 dialog_thread = new EditShowDialogThread(this);
488 EditPopupShow::~EditPopupShow()
490 delete dialog_thread;
493 int EditPopupShow::handle_event()
496 dialog_thread->close_window();
497 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
498 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
499 dialog_thread->start(wx, wy);
504 void EditShowDialogThread::start(int wx, int wy)
506 this->wx = wx; this->wy = wy;
507 BC_DialogThread::start();
510 EditShowDialogThread::EditShowDialogThread(EditPopupShow *edit_show)
512 this->edit_show = edit_show;
515 EditShowDialogThread::~EditShowDialogThread()
520 BC_Window* EditShowDialogThread::new_gui()
522 MWindow *mwindow = edit_show->mwindow;
523 EditPopup *popup = edit_show->popup;
524 window = new EditPopupShowWindow(mwindow, popup, wx, wy);
525 window->create_objects();
529 void EditShowDialogThread::handle_close_event(int result)
534 EditPopupShowWindow::EditPopupShowWindow(MWindow *mwindow,
535 EditPopup *popup, int wx, int wy)
536 : BC_Window(_(PROGRAM_NAME ": Show edit"), wx, wy,
537 300, 220, 300, 220, 0, 0, 1)
539 this->mwindow = mwindow;
543 EditPopupShowWindow::~EditPopupShowWindow()
547 void EditPopupShowWindow::create_objects()
549 lock_window("EditPopupShowWindow::create_objects");
552 char text[BCTEXTLEN];
553 Edit *edit = popup->edit;
554 Track *track = edit->track;
555 sprintf(text, _("Track %d:"), mwindow->edl->tracks->number_of(track)+1);
556 add_subwindow(title = new BC_Title(x, y, text));
557 int x1 = x + title->get_w() + 10;
558 int tw = get_w() - x1 - 20;
559 truncate_text(text, track->title, tw);
560 add_subwindow(new BC_Title(x1, y, text));
561 y += title->get_h() + 5;
562 sprintf(text, _("Edit %d:"), track->edits->number_of(edit)+1);
563 add_subwindow(title = new BC_Title(x, y, text));
564 char edit_title[BCTEXTLEN];
565 edit->get_title(edit_title);
566 truncate_text(text, edit_title, tw);
567 add_subwindow(new BC_Title(x1, y, text));
568 y += title->get_h() + 5;
570 EDLSession *session = mwindow->edl->session;
571 int time_format = session->time_format;
572 int sample_rate = session->sample_rate;
573 double frame_rate = session->frame_rate;
574 double frames_per_foot = session->frames_per_foot;
576 double startsource = track->from_units(edit->startsource);
577 double startproject = track->from_units(edit->startproject);
578 double length = track->from_units(edit->length);
580 char text_startsource[BCSTRLEN];
581 char text_startproject[BCSTRLEN];
582 char text_length[BCSTRLEN];
583 sprintf(text, _("StartSource: %s\nStartProject: %s\nLength: %s\n"),
584 Units::totext(text_startsource, startsource,
585 time_format, sample_rate, frame_rate, frames_per_foot),
586 Units::totext(text_startproject, startproject,
587 time_format, sample_rate, frame_rate, frames_per_foot),
588 Units::totext(text_length, length,
589 time_format, sample_rate, frame_rate, frames_per_foot));
590 show_text = new EditPopupShowText(this, mwindow, x+15, y+10, text);
591 add_subwindow(show_text);
592 add_tool(new BC_OKButton(this));
600 EditPopupShowText::EditPopupShowText(EditPopupShowWindow *window,
601 MWindow *mwindow, int x, int y, const char *text)
602 : BC_TextBox(x, y, 250, 4, text)
604 this->window = window;
605 this->mwindow = mwindow;
608 EditPopupShowText::~EditPopupShowText()