diff --git a/app/config/config.cpp b/app/config/config.cpp index 0d22fc54e..b294f5909 100644 --- a/app/config/config.cpp +++ b/app/config/config.cpp @@ -75,6 +75,7 @@ void Config::SetDefaults() config_map_["Autoscroll"] = AutoScroll::kPage; config_map_["DefaultViewerDivider"] = 2; config_map_["AutoSelectDivider"] = false; + config_map_["SetNameWithMarker"] = false; config_map_["DropWithoutSequenceBehavior"] = TimelineWidget::kDWSAsk; config_map_["DiskCachePath"] = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); diff --git a/app/panel/timebased/timebased.cpp b/app/panel/timebased/timebased.cpp index d74b1cd61..e0e93e7a7 100644 --- a/app/panel/timebased/timebased.cpp +++ b/app/panel/timebased/timebased.cpp @@ -159,3 +159,8 @@ void TimeBasedPanel::ClearInOut() { GetTimeBasedWidget()->ClearInOutPoints(); } + +void TimeBasedPanel::SetMarker() +{ + GetTimeBasedWidget()->SetMarker(); +} diff --git a/app/panel/timebased/timebased.h b/app/panel/timebased/timebased.h index 555821539..db4c7f9c5 100644 --- a/app/panel/timebased/timebased.h +++ b/app/panel/timebased/timebased.h @@ -54,6 +54,8 @@ public: virtual void ClearInOut() override; + virtual void SetMarker() override; + public slots: void SetTimebase(const rational& timebase); diff --git a/app/widget/panel/panel.h b/app/widget/panel/panel.h index d81df1be8..0ea111e45 100644 --- a/app/widget/panel/panel.h +++ b/app/widget/panel/panel.h @@ -128,6 +128,8 @@ public: virtual void ClearInOut(){} + virtual void SetMarker(){} + protected: /** * @brief paintEvent diff --git a/app/widget/timebased/timebased.cpp b/app/widget/timebased/timebased.cpp index ded2687ec..816ba0f20 100644 --- a/app/widget/timebased/timebased.cpp +++ b/app/widget/timebased/timebased.cpp @@ -1,8 +1,10 @@ #include "timebased.h" +#include #include #include "common/timecodefunctions.h" +#include "config/config.h" #include "core.h" #include "project/item/sequence/sequence.h" #include "widget/timelinewidget/undo/undo.h" @@ -366,3 +368,23 @@ void TimeBasedWidget::ClearInOutPoints() Core::instance()->undo_stack()->push(new WorkareaSetEnabledCommand(points_, false)); } + +void TimeBasedWidget::SetMarker() +{ + if (!points_) { + return; + } + + bool ok; + QString marker_name; + + if (Config::Current()["SetNameWithMarker"].toBool()) { + marker_name = QInputDialog::getText(this, tr("Set Marker"), tr("Marker name:"), QLineEdit::Normal, QString(), &ok); + } else { + ok = true; + } + + if (ok) { + points_->markers()->AddMarker(TimeRange(GetTime(), GetTime()), marker_name); + } +} diff --git a/app/widget/timebased/timebased.h b/app/widget/timebased/timebased.h index 24ea72299..6a58ba12b 100644 --- a/app/widget/timebased/timebased.h +++ b/app/widget/timebased/timebased.h @@ -59,6 +59,8 @@ public slots: void ClearInOutPoints(); + void SetMarker(); + TimeRuler* ruler() const; protected slots: diff --git a/app/widget/timeruler/timeruler.cpp b/app/widget/timeruler/timeruler.cpp index 25df8bdfe..6cc411854 100644 --- a/app/widget/timeruler/timeruler.cpp +++ b/app/widget/timeruler/timeruler.cpp @@ -93,6 +93,8 @@ void TimeRuler::paintEvent(QPaintEvent *) // Draw timeline points if connected if (timeline_points()) { + + // Draw in/out workarea if (timeline_points()->workarea()->enabled()) { int workarea_left = qMax(0, TimeToScreen(timeline_points()->workarea()->in())); int workarea_right; @@ -105,6 +107,51 @@ void TimeRuler::paintEvent(QPaintEvent *) p.fillRect(workarea_left, 0, workarea_right - workarea_left, height(), palette().highlight()); } + + // Draw markers + if (!timeline_points()->markers()->list().isEmpty()) { + int marker_bottom = height() - text_height_; + + if (show_cache_status_) { + marker_bottom -= cache_status_height_; + } + + if (text_visible_) { + marker_bottom -= cache_status_height_; + } + + int marker_top = marker_bottom - text_height_; + + // FIXME: Hardcoded marker colors + p.setPen(Qt::black); + p.setBrush(Qt::green); + + foreach (TimelineMarker* marker, timeline_points()->markers()->list()) { + int marker_left = TimeToScreen(marker->time().in()); + int marker_right = TimeToScreen(marker->time().out()); + + if (marker_left >= width() || marker_right < 0) { + continue; + } + + if (marker->time().length() == 0) { + // Single point in time marker + DrawPlayhead(&p, marker_left, marker_bottom); + } else { + // Marker range + int rect_left = qMax(0, marker_left); + int rect_right = qMin(width(), marker_right); + + QRect marker_rect(rect_left, marker_top, rect_right - rect_left, marker_bottom - marker_top); + + p.drawRect(marker_rect); + + if (!marker->name().isEmpty()) { + p.drawText(marker_rect, marker->name()); + } + } + } + } } double width_of_frame = timebase_dbl() * GetScale(); @@ -320,13 +367,18 @@ void TimeRuler::UpdateHeight() { int height = text_height_; + // Add text height if (text_visible_) { height += text_height_; } + // Add cache status height if (show_cache_status_) { height += cache_status_height_; } + // Add marker height + height += text_height_; + setFixedHeight(height); } diff --git a/app/window/mainwindow/mainmenu.cpp b/app/window/mainwindow/mainmenu.cpp index 429a63282..95c4eba68 100644 --- a/app/window/mainwindow/mainmenu.cpp +++ b/app/window/mainwindow/mainmenu.cpp @@ -87,7 +87,7 @@ MainMenu::MainMenu(QMainWindow *parent) : edit_delete_inout_item_ = edit_menu_->AddItem("deleteinout", nullptr, nullptr, ";"); edit_ripple_delete_inout_item_ = edit_menu_->AddItem("rippledeleteinout", nullptr, nullptr, "'"); edit_menu_->addSeparator(); - edit_set_marker_item_ = edit_menu_->AddItem("marker", nullptr, nullptr, "M"); + edit_set_marker_item_ = edit_menu_->AddItem("marker", this, SLOT(SetMarkerTriggered()), "M"); // // VIEW MENU @@ -507,6 +507,11 @@ void MainMenu::GoToNextCutTriggered() PanelManager::instance()->CurrentlyFocused()->GoToNextCut(); } +void MainMenu::SetMarkerTriggered() +{ + PanelManager::instance()->CurrentlyFocused()->SetMarker(); +} + void MainMenu::Retranslate() { // MenuShared is not a QWidget and therefore does not receive a LanguageEvent, we use MainMenu's to update it diff --git a/app/window/mainwindow/mainmenu.h b/app/window/mainwindow/mainmenu.h index 81476ab2d..2f4eea741 100644 --- a/app/window/mainwindow/mainmenu.h +++ b/app/window/mainwindow/mainmenu.h @@ -140,6 +140,8 @@ private slots: void GoToPrevCutTriggered(); void GoToNextCutTriggered(); + void SetMarkerTriggered(); + private: /** * @brief Set strings based on the current application language.