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_edits_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_edits_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 EDL *edl = mwindow->edl;
336 const char *text = window->title_text->get_text();
338 for( Track *track=edl->tracks->first; track; track=track->next ) {
339 if( !track->record ) continue;
340 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
341 if( !edit->is_selected ) continue;
342 strcpy(edit->user_title, text);
347 edl->tracks->clear_selected_edits();
348 else if( popup->edit ) {
349 strcpy(popup->edit->user_title, text);
351 mwindow->gui->lock_window("EditUserTitleDialogThread::handle_done_event");
352 mwindow->gui->draw_canvas(1, 0);
353 mwindow->gui->flash_canvas(1);
354 mwindow->gui->unlock_window();
357 EditPopupUserTitleWindow::EditPopupUserTitleWindow(MWindow *mwindow,
358 EditPopup *popup, int wx, int wy)
359 : BC_Window(_(PROGRAM_NAME ": Set edit title"), wx, wy,
360 300, 130, 300, 130, 0, 0, 1)
362 this->mwindow = mwindow;
364 strcpy(new_text, !popup->edit ? "" : popup->edit->user_title);
367 EditPopupUserTitleWindow::~EditPopupUserTitleWindow()
371 void EditPopupUserTitleWindow::create_objects()
373 lock_window("EditPopupUserTitleWindow::create_objects");
374 int x = 10, y = 10, x1;
375 BC_Title *title = new BC_Title(x1=x, y, _("User title:"));
376 add_subwindow(title); x1 += title->get_w() + 10;
377 title_text = new EditPopupUserTitleText(this, mwindow, x1, y, new_text);
378 add_subwindow(title_text);
380 add_tool(new BC_OKButton(this));
381 add_tool(new BC_CancelButton(this));
390 EditPopupUserTitleText::EditPopupUserTitleText(EditPopupUserTitleWindow *window,
391 MWindow *mwindow, int x, int y, const char *text)
392 : BC_TextBox(x, y, window->get_w()-x-15, 1, text)
394 this->window = window;
395 this->mwindow = mwindow;
398 EditPopupUserTitleText::~EditPopupUserTitleText()
402 int EditPopupUserTitleText::handle_event()
404 if( get_keypress() == RETURN )
410 EditPopupTitleColor::EditPopupTitleColor(MWindow *mwindow, EditPopup *popup)
411 : BC_MenuItem(_("Bar Color..."))
413 this->mwindow = mwindow;
417 EditPopupTitleColor::~EditPopupTitleColor()
422 int EditPopupTitleColor::handle_event()
425 int color = popup->mwindow->get_title_color(popup->edit);
426 if( !color ) color = popup->mwindow->theme->get_color_title_bg();
428 color_picker = new EditTitleColorPicker(popup, color);
429 int alpha = (~color>>24) & 0xff;
430 color_picker->start_window(color & 0xffffff, alpha, 1);
435 EditTitleColorDefault::EditTitleColorDefault(
436 EditTitleColorPicker *color_picker, int x, int y)
437 : BC_GenericButton(x, y, _("default"))
439 this->color_picker = color_picker;
442 int EditTitleColorDefault::handle_event()
444 const unsigned color = 0, alpha = 0xff;
445 color_picker->color = color | (~alpha << 24);
446 color_picker->update_gui(color, alpha);
450 EditTitleColorPicker::EditTitleColorPicker(EditPopup *popup, int color)
451 : ColorPicker(1, _("Bar Color"))
456 EditTitleColorPicker::~EditTitleColorPicker()
459 void EditTitleColorPicker::create_objects(ColorWindow *gui)
461 int y = gui->get_h() - BC_CancelButton::calculate_h() + 10;
462 int x = gui->get_w() - BC_CancelButton::calculate_w() - 10;
463 x -= BC_GenericButton::calculate_w(gui, _("default")) + 15;
464 gui->add_subwindow(new EditTitleColorDefault(this, x, y));
467 int EditTitleColorPicker::handle_new_color(int color, int alpha)
469 this->color = color | (~alpha << 24);
473 void EditTitleColorPicker::handle_done_event(int result)
476 EDL *edl = popup->mwindow->edl;
478 for( Track *track=edl->tracks->first; track; track=track->next ) {
479 if( !track->record ) continue;
480 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
481 if( !edit->is_selected ) continue;
487 edl->tracks->clear_selected_edits();
489 popup->edit->color = color;
491 MWindowGUI *mwindow_gui = popup->mwindow->gui;
492 mwindow_gui->lock_window("GWindowColorUpdate::run");
493 mwindow_gui->draw_trackmovement();
494 mwindow_gui->unlock_window();
498 EditPopupShow::EditPopupShow(MWindow *mwindow, EditPopup *popup)
499 : BC_MenuItem(_("Show edit"))
501 this->mwindow = mwindow;
503 dialog_thread = new EditShowDialogThread(this);
506 EditPopupShow::~EditPopupShow()
508 delete dialog_thread;
511 int EditPopupShow::handle_event()
514 dialog_thread->close_window();
515 int wx = mwindow->gui->get_abs_cursor_x(0) - 400 / 2;
516 int wy = mwindow->gui->get_abs_cursor_y(0) - 500 / 2;
517 dialog_thread->start(wx, wy);
522 void EditShowDialogThread::start(int wx, int wy)
524 this->wx = wx; this->wy = wy;
525 BC_DialogThread::start();
528 EditShowDialogThread::EditShowDialogThread(EditPopupShow *edit_show)
530 this->edit_show = edit_show;
533 EditShowDialogThread::~EditShowDialogThread()
538 BC_Window* EditShowDialogThread::new_gui()
540 MWindow *mwindow = edit_show->mwindow;
541 EditPopup *popup = edit_show->popup;
542 window = new EditPopupShowWindow(mwindow, popup, wx, wy);
543 window->create_objects();
547 void EditShowDialogThread::handle_close_event(int result)
552 EditPopupShowWindow::EditPopupShowWindow(MWindow *mwindow,
553 EditPopup *popup, int wx, int wy)
554 : BC_Window(_(PROGRAM_NAME ": Show edit"), wx, wy,
555 300, 220, 300, 220, 0, 0, 1)
557 this->mwindow = mwindow;
561 EditPopupShowWindow::~EditPopupShowWindow()
565 void EditPopupShowWindow::create_objects()
567 lock_window("EditPopupShowWindow::create_objects");
570 char text[BCTEXTLEN];
571 Edit *edit = popup->edit;
572 Track *track = edit->track;
573 sprintf(text, _("Track %d:"), mwindow->edl->tracks->number_of(track)+1);
574 add_subwindow(title = new BC_Title(x, y, text));
575 int x1 = x + title->get_w() + 10;
576 int tw = get_w() - x1 - 20;
577 truncate_text(text, track->title, tw);
578 add_subwindow(new BC_Title(x1, y, text));
579 y += title->get_h() + 5;
580 sprintf(text, _("Edit %d:"), track->edits->number_of(edit)+1);
581 add_subwindow(title = new BC_Title(x, y, text));
582 char edit_title[BCTEXTLEN];
583 edit->get_title(edit_title);
584 truncate_text(text, edit_title, tw);
585 add_subwindow(new BC_Title(x1, y, text));
586 y += title->get_h() + 5;
588 EDLSession *session = mwindow->edl->session;
589 int time_format = session->time_format;
590 int sample_rate = session->sample_rate;
591 double frame_rate = session->frame_rate;
592 double frames_per_foot = session->frames_per_foot;
594 double startsource = track->from_units(edit->startsource);
595 double startproject = track->from_units(edit->startproject);
596 double length = track->from_units(edit->length);
598 char text_startsource[BCSTRLEN];
599 char text_startproject[BCSTRLEN];
600 char text_length[BCSTRLEN];
601 sprintf(text, _("StartSource: %s\nStartProject: %s\nLength: %s\n"),
602 Units::totext(text_startsource, startsource,
603 time_format, sample_rate, frame_rate, frames_per_foot),
604 Units::totext(text_startproject, startproject,
605 time_format, sample_rate, frame_rate, frames_per_foot),
606 Units::totext(text_length, length,
607 time_format, sample_rate, frame_rate, frames_per_foot));
608 show_text = new EditPopupShowText(this, mwindow, x+15, y+10, text);
609 add_subwindow(show_text);
610 add_tool(new BC_OKButton(this));
618 EditPopupShowText::EditPopupShowText(EditPopupShowWindow *window,
619 MWindow *mwindow, int x, int y, const char *text)
620 : BC_TextBox(x, y, 250, 4, text)
622 this->window = window;
623 this->mwindow = mwindow;
626 EditPopupShowText::~EditPopupShowText()