/*** Olive - Non-Linear Video Editor Copyright (C) 2019 Olive Team This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ***/ #include "menuhelper.h" #include "oliveglobal.h" #include "ui/focusfilter.h" #include "io/config.h" #include "panels/panels.h" #include "mainwindow.h" #include #include MenuHelper olive::MenuHelper; void MenuHelper::make_new_menu(QMenu *parent) { parent->addAction(tr("&Project"), olive::Global.get(), SLOT(new_project()), QKeySequence("Ctrl+N"))->setProperty("id", "newproj"); parent->addSeparator(); parent->addAction(tr("&Sequence"), panel_project, SLOT(new_sequence()), QKeySequence("Ctrl+Shift+N"))->setProperty("id", "newseq"); parent->addAction(tr("&Folder"), panel_project, SLOT(new_folder()))->setProperty("id", "newfolder"); } void MenuHelper::make_inout_menu(QMenu *parent) { parent->addAction(tr("Set In Point"), &olive::FocusFilter, SLOT(set_in_point()), QKeySequence("I"))->setProperty("id", "setinpoint"); parent->addAction(tr("Set Out Point"), &olive::FocusFilter, SLOT(set_out_point()), QKeySequence("O"))->setProperty("id", "setoutpoint"); parent->addSeparator(); parent->addAction(tr("Reset In Point"), &olive::FocusFilter, SLOT(clear_in()))->setProperty("id", "resetin"); parent->addAction(tr("Reset Out Point"), &olive::FocusFilter, SLOT(clear_out()))->setProperty("id", "resetout"); parent->addAction(tr("Clear In/Out Point"), &olive::FocusFilter, SLOT(clear_inout()), QKeySequence("G"))->setProperty("id", "clearinout"); } void MenuHelper::make_clip_functions_menu(QMenu *parent) { parent->addAction(tr("Add Default Transition"), panel_timeline, SLOT(add_transition()), QKeySequence("Ctrl+Shift+D"))->setProperty("id", "deftransition"); parent->addAction(tr("Link/Unlink"), panel_timeline, SLOT(toggle_links()), QKeySequence("Ctrl+L"))->setProperty("id", "linkunlink"); parent->addAction(tr("Enable/Disable"), panel_timeline, SLOT(toggle_enable_on_selected_clips()), QKeySequence("Shift+E"))->setProperty("id", "enabledisable"); parent->addAction(tr("Nest"), panel_timeline, SLOT(nest()))->setProperty("id", "nest"); } void MenuHelper::make_edit_functions_menu(QMenu *parent) { parent->addAction(tr("Cu&t"), &olive::FocusFilter, SLOT(cut()), QKeySequence("Ctrl+X"))->setProperty("id", "cut"); parent->addAction(tr("Cop&y"), &olive::FocusFilter, SLOT(copy()), QKeySequence("Ctrl+C"))->setProperty("id", "copy"); parent->addAction(tr("&Paste"), olive::Global.get(), SLOT(paste()), QKeySequence("Ctrl+V"))->setProperty("id", "paste"); parent->addAction(tr("Paste Insert"), olive::Global.get(), SLOT(paste_insert()), QKeySequence("Ctrl+Shift+V"))->setProperty("id", "pasteinsert"); parent->addAction(tr("Duplicate"), &olive::FocusFilter, SLOT(duplicate()), QKeySequence("Ctrl+D"))->setProperty("id", "duplicate"); parent->addAction(tr("Delete"), &olive::FocusFilter, SLOT(delete_function()), QKeySequence("Del"))->setProperty("id", "delete"); parent->addAction(tr("Ripple Delete"), panel_timeline, SLOT(ripple_delete()), QKeySequence("Shift+Del"))->setProperty("id", "rippledelete"); parent->addAction(tr("Split"), panel_timeline, SLOT(split_at_playhead()), QKeySequence("Ctrl+K"))->setProperty("id", "split"); } void MenuHelper::set_bool_action_checked(QAction *a) { if (!a->data().isNull()) { bool* variable = reinterpret_cast(a->data().value()); a->setChecked(*variable); } } void MenuHelper::set_int_action_checked(QAction *a, const int& i) { if (!a->data().isNull()) { a->setChecked(a->data() == i); } } #include void MenuHelper::set_button_action_checked(QAction *a) { a->setChecked(reinterpret_cast(a->data().value())->isChecked()); } void MenuHelper::toggle_bool_action() { QAction* action = static_cast(sender()); bool* variable = reinterpret_cast(action->data().value()); *variable = !(*variable); update_ui(false); } void MenuHelper::set_titlesafe_from_menu() { double tsa = static_cast(sender())->data().toDouble(); if (qIsNaN(tsa)) { // disable title safe area olive::CurrentConfig.show_title_safe_area = false; } else { // using title safe area olive::CurrentConfig.show_title_safe_area = true; // are we using the default area aspect ratio, or a specific one if (qIsNull(tsa)) { // default title safe area olive::CurrentConfig.use_custom_title_safe_ratio = false; } else { // using a specific aspect ratio olive::CurrentConfig.use_custom_title_safe_ratio = true; if (tsa < 0.0) { // set a custom title safe area QString input; bool invalid = false; QRegExp arTest("[0-9.]+:[0-9.]+"); do { if (invalid) { QMessageBox::critical(olive::MainWindow, tr("Invalid aspect ratio"), tr("The aspect ratio '%1' is invalid. Please try again.").arg(input)); } input = QInputDialog::getText(olive::MainWindow, tr("Enter custom aspect ratio"), tr("Enter the aspect ratio to use for the title/action safe area (e.g. 16:9):")); invalid = !arTest.exactMatch(input) && !input.isEmpty(); } while (invalid); if (!input.isEmpty()) { QStringList inputList = input.split(':'); olive::CurrentConfig.custom_title_safe_ratio = inputList.at(0).toDouble()/inputList.at(1).toDouble(); } } else { // specified tsa is a specific custom aspect ratio olive::CurrentConfig.custom_title_safe_ratio = tsa; } } } panel_sequence_viewer->viewer_widget->update(); } void MenuHelper::set_autoscroll() { QAction* action = static_cast(sender()); olive::CurrentConfig.autoscroll = action->data().toInt(); } void MenuHelper::menu_click_button() { reinterpret_cast(static_cast(sender())->data().value())->click(); } void MenuHelper::set_timecode_view() { QAction* action = static_cast(sender()); olive::CurrentConfig.timecode_view = action->data().toInt(); update_ui(false); } void MenuHelper::open_recent_from_menu() { int index = static_cast(sender())->data().toInt(); olive::Global.get()->open_recent(index); }