change: change code style to Linux style except indent.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -27,144 +27,153 @@
|
||||
#include "widget/menu/menu.h"
|
||||
#include "widget/timebased/timebasedviewselectionmanager.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class SeekableWidget : public TimeBasedView
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class SeekableWidget : public TimeBasedView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SeekableWidget(QWidget *parent = nullptr);
|
||||
SeekableWidget(QWidget *parent = nullptr);
|
||||
|
||||
int GetScroll() const
|
||||
{
|
||||
return horizontalScrollBar()->value();
|
||||
}
|
||||
int GetScroll() const
|
||||
{
|
||||
return horizontalScrollBar()->value();
|
||||
}
|
||||
|
||||
TimelineMarkerList *GetMarkers() const { return markers_; }
|
||||
TimelineWorkArea *GetWorkArea() const { return workarea_; }
|
||||
TimelineMarkerList *GetMarkers() const
|
||||
{
|
||||
return markers_;
|
||||
}
|
||||
TimelineWorkArea *GetWorkArea() const
|
||||
{
|
||||
return workarea_;
|
||||
}
|
||||
|
||||
void SetMarkers(TimelineMarkerList *markers);
|
||||
void SetWorkArea(TimelineWorkArea *workarea);
|
||||
void SetMarkers(TimelineMarkerList *markers);
|
||||
void SetWorkArea(TimelineWorkArea *workarea);
|
||||
|
||||
virtual bool IsDraggingPlayhead() const override
|
||||
{
|
||||
return dragging_;
|
||||
}
|
||||
virtual bool IsDraggingPlayhead() const override
|
||||
{
|
||||
return dragging_;
|
||||
}
|
||||
|
||||
bool IsMarkerEditingEnabled() const { return marker_editing_enabled_; }
|
||||
void SetMarkerEditingEnabled(bool e) { marker_editing_enabled_ = e; }
|
||||
bool IsMarkerEditingEnabled() const
|
||||
{
|
||||
return marker_editing_enabled_;
|
||||
}
|
||||
void SetMarkerEditingEnabled(bool e)
|
||||
{
|
||||
marker_editing_enabled_ = e;
|
||||
}
|
||||
|
||||
void DeleteSelected();
|
||||
void DeleteSelected();
|
||||
|
||||
bool CopySelected(bool cut);
|
||||
bool CopySelected(bool cut);
|
||||
|
||||
bool PasteMarkers();
|
||||
bool PasteMarkers();
|
||||
|
||||
void DeselectAllMarkers();
|
||||
void DeselectAllMarkers();
|
||||
|
||||
void SeekToScenePoint(qreal scene);
|
||||
void SeekToScenePoint(qreal scene);
|
||||
|
||||
bool HasItemsSelected() const
|
||||
{
|
||||
return !selection_manager_.GetSelectedObjects().empty();
|
||||
}
|
||||
bool HasItemsSelected() const
|
||||
{
|
||||
return !selection_manager_.GetSelectedObjects().empty();
|
||||
}
|
||||
|
||||
const std::vector<TimelineMarker*> &GetSelectedMarkers() const
|
||||
{
|
||||
return selection_manager_.GetSelectedObjects();
|
||||
}
|
||||
const std::vector<TimelineMarker *> &GetSelectedMarkers() const
|
||||
{
|
||||
return selection_manager_.GetSelectedObjects();
|
||||
}
|
||||
|
||||
virtual void SelectionManagerSelectEvent(void *obj) override;
|
||||
virtual void SelectionManagerDeselectEvent(void *obj) override;
|
||||
virtual void SelectionManagerSelectEvent(void *obj) override;
|
||||
virtual void SelectionManagerDeselectEvent(void *obj) override;
|
||||
|
||||
virtual void CatchUpScrollEvent() override;
|
||||
virtual void CatchUpScrollEvent() override;
|
||||
|
||||
public slots:
|
||||
void SetScroll(int i)
|
||||
{
|
||||
horizontalScrollBar()->setValue(i);
|
||||
}
|
||||
void SetScroll(int i)
|
||||
{
|
||||
horizontalScrollBar()->setValue(i);
|
||||
}
|
||||
|
||||
virtual void TimebaseChangedEvent(const rational &) override;
|
||||
virtual void TimebaseChangedEvent(const rational &) override;
|
||||
|
||||
signals:
|
||||
void DragMoved(int x, int y);
|
||||
void DragMoved(int x, int y);
|
||||
|
||||
void DragReleased();
|
||||
void DragReleased();
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
virtual void focusOutEvent(QFocusEvent *event) override;
|
||||
virtual void focusOutEvent(QFocusEvent *event) override;
|
||||
|
||||
void DrawMarkers(QPainter *p, int marker_bottom = 0);
|
||||
void DrawWorkArea(QPainter *p);
|
||||
void DrawMarkers(QPainter *p, int marker_bottom = 0);
|
||||
void DrawWorkArea(QPainter *p);
|
||||
|
||||
void DrawPlayhead(QPainter* p, int x, int y);
|
||||
void DrawPlayhead(QPainter *p, int x, int y);
|
||||
|
||||
inline const int& text_height() const {
|
||||
return text_height_;
|
||||
}
|
||||
inline const int &text_height() const
|
||||
{
|
||||
return text_height_;
|
||||
}
|
||||
|
||||
inline const int& playhead_width() const {
|
||||
return playhead_width_;
|
||||
}
|
||||
inline const int &playhead_width() const
|
||||
{
|
||||
return playhead_width_;
|
||||
}
|
||||
|
||||
int GetLeftLimit() const;
|
||||
int GetRightLimit() const;
|
||||
int GetLeftLimit() const;
|
||||
int GetRightLimit() const;
|
||||
|
||||
protected slots:
|
||||
virtual bool ShowContextMenu(const QPoint &p);
|
||||
virtual bool ShowContextMenu(const QPoint &p);
|
||||
|
||||
private:
|
||||
enum ResizeMode {
|
||||
kResizeNone,
|
||||
kResizeIn,
|
||||
kResizeOut
|
||||
};
|
||||
enum ResizeMode { kResizeNone, kResizeIn, kResizeOut };
|
||||
|
||||
bool FindResizeHandle(QMouseEvent *event);
|
||||
bool FindResizeHandle(QMouseEvent *event);
|
||||
|
||||
void ClearResizeHandle();
|
||||
void ClearResizeHandle();
|
||||
|
||||
void DragResizeHandle(const QPointF &scene_pos);
|
||||
void DragResizeHandle(const QPointF &scene_pos);
|
||||
|
||||
void CommitResizeHandle();
|
||||
void CommitResizeHandle();
|
||||
|
||||
TimelineMarkerList* markers_;
|
||||
TimelineWorkArea* workarea_;
|
||||
TimelineMarkerList *markers_;
|
||||
TimelineWorkArea *workarea_;
|
||||
|
||||
int text_height_;
|
||||
int text_height_;
|
||||
|
||||
int playhead_width_;
|
||||
int playhead_width_;
|
||||
|
||||
bool dragging_;
|
||||
bool dragging_;
|
||||
|
||||
bool ignore_next_focus_out_;
|
||||
bool ignore_next_focus_out_;
|
||||
|
||||
TimeBasedViewSelectionManager<TimelineMarker> selection_manager_;
|
||||
TimeBasedViewSelectionManager<TimelineMarker> selection_manager_;
|
||||
|
||||
QObject *resize_item_;
|
||||
ResizeMode resize_mode_;
|
||||
TimeRange resize_item_range_;
|
||||
QPointF resize_start_;
|
||||
uint32_t resize_snap_mask_;
|
||||
QObject *resize_item_;
|
||||
ResizeMode resize_mode_;
|
||||
TimeRange resize_item_range_;
|
||||
QPointF resize_start_;
|
||||
uint32_t resize_snap_mask_;
|
||||
|
||||
int marker_top_;
|
||||
int marker_bottom_;
|
||||
int marker_top_;
|
||||
int marker_bottom_;
|
||||
|
||||
bool marker_editing_enabled_;
|
||||
bool marker_editing_enabled_;
|
||||
|
||||
QPolygon last_playhead_shape_;
|
||||
QPolygon last_playhead_shape_;
|
||||
|
||||
private slots:
|
||||
void SetMarkerColor(int c);
|
||||
|
||||
void ShowMarkerProperties();
|
||||
void SetMarkerColor(int c);
|
||||
|
||||
void ShowMarkerProperties();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+232
-213
@@ -29,297 +29,316 @@
|
||||
#include "widget/menu/menu.h"
|
||||
#include "widget/menu/menushared.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super SeekableWidget
|
||||
|
||||
TimeRuler::TimeRuler(bool text_visible, bool cache_status_visible, QWidget* parent) :
|
||||
super(parent),
|
||||
text_visible_(text_visible),
|
||||
centered_text_(true),
|
||||
show_cache_status_(cache_status_visible),
|
||||
playback_cache_(nullptr)
|
||||
TimeRuler::TimeRuler(bool text_visible, bool cache_status_visible,
|
||||
QWidget *parent)
|
||||
: super(parent)
|
||||
, text_visible_(text_visible)
|
||||
, centered_text_(true)
|
||||
, show_cache_status_(cache_status_visible)
|
||||
, playback_cache_(nullptr)
|
||||
{
|
||||
QFontMetrics fm = fontMetrics();
|
||||
QFontMetrics fm = fontMetrics();
|
||||
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
|
||||
// Text height is used to calculate widget height
|
||||
// Text height is used to calculate widget height
|
||||
|
||||
// Get the "minimum" space allowed between two line markers on the ruler (in screen pixels)
|
||||
// Mediocre but reliable way of scaling UI objects by font/DPI size
|
||||
minimum_gap_between_lines_ = QtUtils::QFontMetricsWidth(fm, "H");
|
||||
// Get the "minimum" space allowed between two line markers on the ruler (in screen pixels)
|
||||
// Mediocre but reliable way of scaling UI objects by font/DPI size
|
||||
minimum_gap_between_lines_ = QtUtils::QFontMetricsWidth(fm, "H");
|
||||
|
||||
// Text visibility affects height, so we set that here
|
||||
UpdateHeight();
|
||||
// Text visibility affects height, so we set that here
|
||||
UpdateHeight();
|
||||
|
||||
// Force update if the default timecode display mode changes
|
||||
connect(Core::instance(), &Core::TimecodeDisplayChanged, this, static_cast<void (TimeRuler::*)()>(&TimeRuler::update));
|
||||
// Force update if the default timecode display mode changes
|
||||
connect(Core::instance(), &Core::TimecodeDisplayChanged, this,
|
||||
static_cast<void (TimeRuler::*)()>(&TimeRuler::update));
|
||||
|
||||
// Connect context menu
|
||||
connect(this, &TimeRuler::customContextMenuRequested, this, &TimeRuler::ShowContextMenu);
|
||||
// Connect context menu
|
||||
connect(this, &TimeRuler::customContextMenuRequested, this,
|
||||
&TimeRuler::ShowContextMenu);
|
||||
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
//horizontalScrollBar()->setVisible(false);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setBackgroundRole(QPalette::Window);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
//horizontalScrollBar()->setVisible(false);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setBackgroundRole(QPalette::Window);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
|
||||
// NOTE: One day it might be preferable to use AlignBottom because the lines are anchored to
|
||||
// the bottom of the widget. However, for now this makes sense since we just ported this
|
||||
// from a QWidget's paintEvent.
|
||||
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
// NOTE: One day it might be preferable to use AlignBottom because the lines are anchored to
|
||||
// the bottom of the widget. However, for now this makes sense since we just ported this
|
||||
// from a QWidget's paintEvent.
|
||||
setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||
}
|
||||
|
||||
void TimeRuler::SetPlaybackCache(PlaybackCache *cache)
|
||||
{
|
||||
if (!show_cache_status_) {
|
||||
return;
|
||||
}
|
||||
if (!show_cache_status_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (playback_cache_) {
|
||||
disconnect(playback_cache_, &PlaybackCache::Invalidated, viewport(), static_cast<void(QWidget::*)()>(&QWidget::update));
|
||||
disconnect(playback_cache_, &PlaybackCache::Validated, viewport(), static_cast<void(QWidget::*)()>(&QWidget::update));
|
||||
}
|
||||
if (playback_cache_) {
|
||||
disconnect(playback_cache_, &PlaybackCache::Invalidated, viewport(),
|
||||
static_cast<void (QWidget::*)()>(&QWidget::update));
|
||||
disconnect(playback_cache_, &PlaybackCache::Validated, viewport(),
|
||||
static_cast<void (QWidget::*)()>(&QWidget::update));
|
||||
}
|
||||
|
||||
playback_cache_ = cache;
|
||||
playback_cache_ = cache;
|
||||
|
||||
if (playback_cache_) {
|
||||
connect(playback_cache_, &PlaybackCache::Invalidated, viewport(), static_cast<void(QWidget::*)()>(&QWidget::update));
|
||||
connect(playback_cache_, &PlaybackCache::Validated, viewport(), static_cast<void(QWidget::*)()>(&QWidget::update));
|
||||
}
|
||||
if (playback_cache_) {
|
||||
connect(playback_cache_, &PlaybackCache::Invalidated, viewport(),
|
||||
static_cast<void (QWidget::*)()>(&QWidget::update));
|
||||
connect(playback_cache_, &PlaybackCache::Validated, viewport(),
|
||||
static_cast<void (QWidget::*)()>(&QWidget::update));
|
||||
}
|
||||
|
||||
update();
|
||||
update();
|
||||
}
|
||||
|
||||
void TimeRuler::drawForeground(QPainter *p, const QRectF &rect)
|
||||
{
|
||||
// Nothing to paint if the timebase is invalid
|
||||
if (timebase().isNull()) {
|
||||
return;
|
||||
}
|
||||
// Nothing to paint if the timebase is invalid
|
||||
if (timebase().isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Draw timeline points if connected
|
||||
int marker_height = TimelineMarker::GetMarkerHeight(p->fontMetrics());
|
||||
DrawWorkArea(p);
|
||||
DrawMarkers(p, marker_height);
|
||||
// Draw timeline points if connected
|
||||
int marker_height = TimelineMarker::GetMarkerHeight(p->fontMetrics());
|
||||
DrawWorkArea(p);
|
||||
DrawMarkers(p, marker_height);
|
||||
|
||||
double width_of_frame = timebase_dbl() * GetScale();
|
||||
double width_of_second = 0;
|
||||
do {
|
||||
width_of_second += timebase_dbl();
|
||||
} while (width_of_second < 1.0);
|
||||
width_of_second *= GetScale();
|
||||
double width_of_minute = width_of_second * 60;
|
||||
double width_of_hour = width_of_minute * 60;
|
||||
double width_of_day = width_of_hour * 24;
|
||||
double width_of_frame = timebase_dbl() * GetScale();
|
||||
double width_of_second = 0;
|
||||
do {
|
||||
width_of_second += timebase_dbl();
|
||||
} while (width_of_second < 1.0);
|
||||
width_of_second *= GetScale();
|
||||
double width_of_minute = width_of_second * 60;
|
||||
double width_of_hour = width_of_minute * 60;
|
||||
double width_of_day = width_of_hour * 24;
|
||||
|
||||
double long_interval, short_interval;
|
||||
int long_rate = 0;
|
||||
double long_interval, short_interval;
|
||||
int long_rate = 0;
|
||||
|
||||
// Used for comparison, even if one unit can technically fit, we have to fit at least two for it to matter
|
||||
int doubled_gap = minimum_gap_between_lines_ * 2;
|
||||
// Used for comparison, even if one unit can technically fit, we have to fit at least two for it to matter
|
||||
int doubled_gap = minimum_gap_between_lines_ * 2;
|
||||
|
||||
if (width_of_day < doubled_gap) {
|
||||
long_interval = -1;
|
||||
short_interval = width_of_day;
|
||||
} else if (width_of_hour < doubled_gap) {
|
||||
long_interval = width_of_day;
|
||||
long_rate = 24;
|
||||
short_interval = width_of_hour;
|
||||
} else if (width_of_minute < doubled_gap) {
|
||||
long_interval = width_of_hour;
|
||||
long_rate = 60;
|
||||
short_interval = width_of_minute;
|
||||
} else if (width_of_second < doubled_gap) {
|
||||
long_interval = width_of_minute;
|
||||
long_rate = 60;
|
||||
short_interval = width_of_second;
|
||||
} else if (width_of_frame < doubled_gap) {
|
||||
long_interval = width_of_second;
|
||||
long_rate = qRound(timebase_flipped_dbl_);
|
||||
short_interval = width_of_frame;
|
||||
} else {
|
||||
// FIXME: Implement this...
|
||||
long_interval = width_of_second;
|
||||
short_interval = width_of_frame;
|
||||
}
|
||||
if (width_of_day < doubled_gap) {
|
||||
long_interval = -1;
|
||||
short_interval = width_of_day;
|
||||
} else if (width_of_hour < doubled_gap) {
|
||||
long_interval = width_of_day;
|
||||
long_rate = 24;
|
||||
short_interval = width_of_hour;
|
||||
} else if (width_of_minute < doubled_gap) {
|
||||
long_interval = width_of_hour;
|
||||
long_rate = 60;
|
||||
short_interval = width_of_minute;
|
||||
} else if (width_of_second < doubled_gap) {
|
||||
long_interval = width_of_minute;
|
||||
long_rate = 60;
|
||||
short_interval = width_of_second;
|
||||
} else if (width_of_frame < doubled_gap) {
|
||||
long_interval = width_of_second;
|
||||
long_rate = qRound(timebase_flipped_dbl_);
|
||||
short_interval = width_of_frame;
|
||||
} else {
|
||||
// FIXME: Implement this...
|
||||
long_interval = width_of_second;
|
||||
short_interval = width_of_frame;
|
||||
}
|
||||
|
||||
if (short_interval < minimum_gap_between_lines_) {
|
||||
if (long_interval <= 0) {
|
||||
do {
|
||||
short_interval *= 2;
|
||||
} while (short_interval < minimum_gap_between_lines_);
|
||||
} else {
|
||||
int div;
|
||||
if (short_interval < minimum_gap_between_lines_) {
|
||||
if (long_interval <= 0) {
|
||||
do {
|
||||
short_interval *= 2;
|
||||
} while (short_interval < minimum_gap_between_lines_);
|
||||
} else {
|
||||
int div;
|
||||
|
||||
short_interval = long_interval;
|
||||
short_interval = long_interval;
|
||||
|
||||
for (div=long_rate;div>0;div--) {
|
||||
if (long_rate%div == 0) {
|
||||
// This division produces a whole number
|
||||
double test_frame_width = long_interval / static_cast<double>(div);
|
||||
for (div = long_rate; div > 0; div--) {
|
||||
if (long_rate % div == 0) {
|
||||
// This division produces a whole number
|
||||
double test_frame_width =
|
||||
long_interval / static_cast<double>(div);
|
||||
|
||||
if (test_frame_width >= minimum_gap_between_lines_) {
|
||||
short_interval = test_frame_width;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (test_frame_width >= minimum_gap_between_lines_) {
|
||||
short_interval = test_frame_width;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set line color to main text color
|
||||
p->setBrush(Qt::NoBrush);
|
||||
p->setPen(palette().text().color());
|
||||
// Set line color to main text color
|
||||
p->setBrush(Qt::NoBrush);
|
||||
p->setPen(palette().text().color());
|
||||
|
||||
// Calculate line dimensions
|
||||
QFontMetrics fm = p->fontMetrics();
|
||||
int line_bottom = height();
|
||||
// Calculate line dimensions
|
||||
QFontMetrics fm = p->fontMetrics();
|
||||
int line_bottom = height();
|
||||
|
||||
if (show_cache_status_) {
|
||||
line_bottom -= PlaybackCache::GetCacheIndicatorHeight();
|
||||
}
|
||||
if (show_cache_status_) {
|
||||
line_bottom -= PlaybackCache::GetCacheIndicatorHeight();
|
||||
}
|
||||
|
||||
int long_height = fm.height();
|
||||
int short_height = long_height/2;
|
||||
int long_y = line_bottom - long_height;
|
||||
int short_y = line_bottom - short_height;
|
||||
int long_height = fm.height();
|
||||
int short_height = long_height / 2;
|
||||
int long_y = line_bottom - long_height;
|
||||
int short_y = line_bottom - short_height;
|
||||
|
||||
// Draw long lines
|
||||
int last_long_unit = -1;
|
||||
int last_short_unit = -1;
|
||||
int last_text_draw = INT_MIN;
|
||||
// Draw long lines
|
||||
int last_long_unit = -1;
|
||||
int last_short_unit = -1;
|
||||
int last_text_draw = INT_MIN;
|
||||
|
||||
// FIXME: Hardcoded number
|
||||
const int kAverageTextWidth = 200;
|
||||
// FIXME: Hardcoded number
|
||||
const int kAverageTextWidth = 200;
|
||||
|
||||
for (int i=GetScroll()-kAverageTextWidth;i<GetScroll()+width()+kAverageTextWidth;i++) {
|
||||
double screen_pt = static_cast<double>(i);
|
||||
for (int i = GetScroll() - kAverageTextWidth;
|
||||
i < GetScroll() + width() + kAverageTextWidth; i++) {
|
||||
double screen_pt = static_cast<double>(i);
|
||||
|
||||
if (long_interval > -1) {
|
||||
int this_long_unit = std::floor(screen_pt/long_interval);
|
||||
if (this_long_unit != last_long_unit) {
|
||||
int line_y = long_y;
|
||||
if (long_interval > -1) {
|
||||
int this_long_unit = std::floor(screen_pt / long_interval);
|
||||
if (this_long_unit != last_long_unit) {
|
||||
int line_y = long_y;
|
||||
|
||||
if (text_visible_) {
|
||||
QRect text_rect;
|
||||
Qt::Alignment text_align;
|
||||
QString timecode_str = QString::fromStdString(Timecode::time_to_timecode(SceneToTime(i), timebase(), Core::instance()->GetTimecodeDisplay()));
|
||||
int timecode_width = QtUtils::QFontMetricsWidth(fm, timecode_str);
|
||||
int timecode_left;
|
||||
if (text_visible_) {
|
||||
QRect text_rect;
|
||||
Qt::Alignment text_align;
|
||||
QString timecode_str =
|
||||
QString::fromStdString(Timecode::time_to_timecode(
|
||||
SceneToTime(i), timebase(),
|
||||
Core::instance()->GetTimecodeDisplay()));
|
||||
int timecode_width =
|
||||
QtUtils::QFontMetricsWidth(fm, timecode_str);
|
||||
int timecode_left;
|
||||
|
||||
if (centered_text_) {
|
||||
text_rect = QRect(i - kAverageTextWidth/2, marker_height, kAverageTextWidth, fm.height());
|
||||
text_align = Qt::AlignCenter;
|
||||
timecode_left = i - timecode_width/2;
|
||||
} else {
|
||||
text_rect = QRect(i, marker_height, kAverageTextWidth, fm.height());
|
||||
text_align = Qt::AlignLeft | Qt::AlignVCenter;
|
||||
timecode_left = i;
|
||||
if (centered_text_) {
|
||||
text_rect = QRect(i - kAverageTextWidth / 2,
|
||||
marker_height, kAverageTextWidth,
|
||||
fm.height());
|
||||
text_align = Qt::AlignCenter;
|
||||
timecode_left = i - timecode_width / 2;
|
||||
} else {
|
||||
text_rect = QRect(i, marker_height, kAverageTextWidth,
|
||||
fm.height());
|
||||
text_align = Qt::AlignLeft | Qt::AlignVCenter;
|
||||
timecode_left = i;
|
||||
|
||||
// Add gap to left between line and text
|
||||
timecode_str.prepend(' ');
|
||||
}
|
||||
// Add gap to left between line and text
|
||||
timecode_str.prepend(' ');
|
||||
}
|
||||
|
||||
if (timecode_left > last_text_draw) {
|
||||
p->drawText(text_rect,
|
||||
static_cast<int>(text_align),
|
||||
timecode_str);
|
||||
if (timecode_left > last_text_draw) {
|
||||
p->drawText(text_rect, static_cast<int>(text_align),
|
||||
timecode_str);
|
||||
|
||||
last_text_draw = timecode_left + timecode_width;
|
||||
last_text_draw = timecode_left + timecode_width;
|
||||
|
||||
if (!centered_text_) {
|
||||
line_y = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!centered_text_) {
|
||||
line_y = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p->drawLine(i, line_y, i, line_bottom);
|
||||
last_long_unit = this_long_unit;
|
||||
}
|
||||
}
|
||||
p->drawLine(i, line_y, i, line_bottom);
|
||||
last_long_unit = this_long_unit;
|
||||
}
|
||||
}
|
||||
|
||||
if (short_interval > -1) {
|
||||
int this_short_unit = std::floor(screen_pt/short_interval);
|
||||
if (this_short_unit != last_short_unit) {
|
||||
p->drawLine(i, short_y, i, line_bottom);
|
||||
last_short_unit = this_short_unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (short_interval > -1) {
|
||||
int this_short_unit = std::floor(screen_pt / short_interval);
|
||||
if (this_short_unit != last_short_unit) {
|
||||
p->drawLine(i, short_y, i, line_bottom);
|
||||
last_short_unit = this_short_unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If cache status is enabled
|
||||
if (show_cache_status_ && playback_cache_ && playback_cache_->HasValidatedRanges()) {
|
||||
// FIXME: Hardcoded to get video length, if we ever need audio length, this will have to change
|
||||
int h = PlaybackCache::GetCacheIndicatorHeight();
|
||||
QRect cache_rect(0, height() - h, width(), h);
|
||||
// If cache status is enabled
|
||||
if (show_cache_status_ && playback_cache_ &&
|
||||
playback_cache_->HasValidatedRanges()) {
|
||||
// FIXME: Hardcoded to get video length, if we ever need audio length, this will have to change
|
||||
int h = PlaybackCache::GetCacheIndicatorHeight();
|
||||
QRect cache_rect(0, height() - h, width(), h);
|
||||
|
||||
if (ViewerOutput *viewer = dynamic_cast<ViewerOutput*>(playback_cache_->parent())) {
|
||||
int right = TimeToScene(viewer->GetVideoLength());
|
||||
cache_rect.setWidth(std::max(0, right));
|
||||
}
|
||||
if (ViewerOutput *viewer =
|
||||
dynamic_cast<ViewerOutput *>(playback_cache_->parent())) {
|
||||
int right = TimeToScene(viewer->GetVideoLength());
|
||||
cache_rect.setWidth(std::max(0, right));
|
||||
}
|
||||
|
||||
if (cache_rect.width() > 0) {
|
||||
playback_cache_->Draw(p, SceneToTime(GetScroll()), GetScale(), cache_rect);
|
||||
}
|
||||
}
|
||||
if (cache_rect.width() > 0) {
|
||||
playback_cache_->Draw(p, SceneToTime(GetScroll()), GetScale(),
|
||||
cache_rect);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the playhead if it's on screen at the moment
|
||||
int playhead_pos = TimeToScene(GetViewerNode()->GetPlayhead());
|
||||
p->setPen(Qt::NoPen);
|
||||
p->setBrush(PLAYHEAD_COLOR);
|
||||
DrawPlayhead(p, playhead_pos, line_bottom);
|
||||
// Draw the playhead if it's on screen at the moment
|
||||
int playhead_pos = TimeToScene(GetViewerNode()->GetPlayhead());
|
||||
p->setPen(Qt::NoPen);
|
||||
p->setBrush(PLAYHEAD_COLOR);
|
||||
DrawPlayhead(p, playhead_pos, line_bottom);
|
||||
}
|
||||
|
||||
void TimeRuler::TimebaseChangedEvent(const rational &tb)
|
||||
{
|
||||
super::TimebaseChangedEvent(tb);
|
||||
super::TimebaseChangedEvent(tb);
|
||||
|
||||
timebase_flipped_dbl_ = tb.flipped().toDouble();
|
||||
timebase_flipped_dbl_ = tb.flipped().toDouble();
|
||||
|
||||
update();
|
||||
update();
|
||||
}
|
||||
|
||||
int TimeRuler::CacheStatusHeight() const
|
||||
{
|
||||
return fontMetrics().height() / 4;
|
||||
return fontMetrics().height() / 4;
|
||||
}
|
||||
|
||||
bool TimeRuler::ShowContextMenu(const QPoint &p)
|
||||
{
|
||||
if (super::ShowContextMenu(p)) {
|
||||
return true;
|
||||
} else {
|
||||
Menu m(this);
|
||||
if (super::ShowContextMenu(p)) {
|
||||
return true;
|
||||
} else {
|
||||
Menu m(this);
|
||||
|
||||
MenuShared::instance()->AddItemsForTimeRulerMenu(&m);
|
||||
MenuShared::instance()->AboutToShowTimeRulerActions(timebase());
|
||||
MenuShared::instance()->AddItemsForTimeRulerMenu(&m);
|
||||
MenuShared::instance()->AboutToShowTimeRulerActions(timebase());
|
||||
|
||||
m.exec(mapToGlobal(p));
|
||||
m.exec(mapToGlobal(p));
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void TimeRuler::UpdateHeight()
|
||||
{
|
||||
int height = text_height();
|
||||
int height = text_height();
|
||||
|
||||
// Add text height
|
||||
if (text_visible_) {
|
||||
height += text_height();
|
||||
}
|
||||
// Add text height
|
||||
if (text_visible_) {
|
||||
height += text_height();
|
||||
}
|
||||
|
||||
// Add cache status height
|
||||
if (show_cache_status_) {
|
||||
height += PlaybackCache::GetCacheIndicatorHeight();
|
||||
}
|
||||
// Add cache status height
|
||||
if (show_cache_status_) {
|
||||
height += PlaybackCache::GetCacheIndicatorHeight();
|
||||
}
|
||||
|
||||
// Add marker height
|
||||
height += TimelineMarker::GetMarkerHeight(fontMetrics());
|
||||
// Add marker height
|
||||
height += TimelineMarker::GetMarkerHeight(fontMetrics());
|
||||
|
||||
setFixedHeight(height);
|
||||
setFixedHeight(height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,43 +27,43 @@
|
||||
#include "seekablewidget.h"
|
||||
#include "render/playbackcache.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
class TimeRuler : public SeekableWidget
|
||||
namespace olive
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class TimeRuler : public SeekableWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TimeRuler(bool text_visible = true, bool cache_status_visible = false, QWidget* parent = nullptr);
|
||||
TimeRuler(bool text_visible = true, bool cache_status_visible = false,
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
void SetCenteredText(bool c);
|
||||
void SetCenteredText(bool c);
|
||||
|
||||
void SetPlaybackCache(PlaybackCache* cache);
|
||||
void SetPlaybackCache(PlaybackCache *cache);
|
||||
|
||||
protected:
|
||||
virtual void drawForeground(QPainter *painter, const QRectF &rect) override;
|
||||
virtual void drawForeground(QPainter *painter, const QRectF &rect) override;
|
||||
|
||||
virtual void TimebaseChangedEvent(const rational& tb) override;
|
||||
virtual void TimebaseChangedEvent(const rational &tb) override;
|
||||
|
||||
protected slots:
|
||||
virtual bool ShowContextMenu(const QPoint &p) override;
|
||||
virtual bool ShowContextMenu(const QPoint &p) override;
|
||||
|
||||
private:
|
||||
void UpdateHeight();
|
||||
void UpdateHeight();
|
||||
|
||||
int CacheStatusHeight() const;
|
||||
int CacheStatusHeight() const;
|
||||
|
||||
int minimum_gap_between_lines_;
|
||||
int minimum_gap_between_lines_;
|
||||
|
||||
bool text_visible_;
|
||||
bool text_visible_;
|
||||
|
||||
bool centered_text_;
|
||||
bool centered_text_;
|
||||
|
||||
double timebase_flipped_dbl_;
|
||||
double timebase_flipped_dbl_;
|
||||
|
||||
bool show_cache_status_;
|
||||
|
||||
PlaybackCache* playback_cache_;
|
||||
bool show_cache_status_;
|
||||
|
||||
PlaybackCache *playback_cache_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user