timebasedwidget/timeruler: reimplemented creating and displaying markers

This commit is contained in:
itsmattkc
2020-03-14 23:03:27 +11:00
parent a56484d3e6
commit 1c4411a4ad
9 changed files with 94 additions and 1 deletions
+1
View File
@@ -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);
+5
View File
@@ -159,3 +159,8 @@ void TimeBasedPanel::ClearInOut()
{
GetTimeBasedWidget()->ClearInOutPoints();
}
void TimeBasedPanel::SetMarker()
{
GetTimeBasedWidget()->SetMarker();
}
+2
View File
@@ -54,6 +54,8 @@ public:
virtual void ClearInOut() override;
virtual void SetMarker() override;
public slots:
void SetTimebase(const rational& timebase);
+2
View File
@@ -128,6 +128,8 @@ public:
virtual void ClearInOut(){}
virtual void SetMarker(){}
protected:
/**
* @brief paintEvent
+22
View File
@@ -1,8 +1,10 @@
#include "timebased.h"
#include <QInputDialog>
#include <QUndoCommand>
#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);
}
}
+2
View File
@@ -59,6 +59,8 @@ public slots:
void ClearInOutPoints();
void SetMarker();
TimeRuler* ruler() const;
protected slots:
+52
View File
@@ -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);
}
+6 -1
View File
@@ -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
+2
View File
@@ -140,6 +140,8 @@ private slots:
void GoToPrevCutTriggered();
void GoToNextCutTriggered();
void SetMarkerTriggered();
private:
/**
* @brief Set strings based on the current application language.