started timeruler object
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
widget/timeruler/timeruler.h
|
||||
widget/timeruler/timeruler.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "timeruler.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
#include "common/qtversionabstraction.h"
|
||||
|
||||
TimeRuler::TimeRuler(bool text_visible, QWidget* parent) :
|
||||
QWidget(parent),
|
||||
scroll_(0),
|
||||
scale_(1.0)
|
||||
{
|
||||
// Text height is used to calculate widget height
|
||||
text_height_ = fontMetrics().height();
|
||||
|
||||
// FIXME: Fairly mediocre, but reliable way of scaling UI objects by font/DPI size
|
||||
QFontMetrics fm = fontMetrics();
|
||||
width_of_second_ = QFontMetricsWidth(&fm, "HHHHHHHHHHHHHHHH");
|
||||
minimum_gap_between_lines_ = QFontMetricsWidth(&fm, "HH");
|
||||
|
||||
SetTextVisible(text_visible);
|
||||
}
|
||||
|
||||
void TimeRuler::SetTextVisible(bool e)
|
||||
{
|
||||
text_visible_ = e;
|
||||
|
||||
if (text_visible_) {
|
||||
setMinimumHeight(text_height_ * 2);
|
||||
} else {
|
||||
setMinimumHeight(text_height_);
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void TimeRuler::SetScale(double d)
|
||||
{
|
||||
scale_ = d;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void TimeRuler::SetTimebase(const rational &r)
|
||||
{
|
||||
time_base_ = r;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void TimeRuler::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
|
||||
QPainter p(this);
|
||||
|
||||
// FIXME: Make this CSS configurable
|
||||
p.setPen(Qt::white);
|
||||
|
||||
// Calculate where the ruler lines should be
|
||||
int ruler_second_line_top = 0;
|
||||
int ruler_second_line_bottom = height();
|
||||
|
||||
//int ruler_frame_line_top = (text_visible_) ? text_height_ : 0;
|
||||
//int ruler_frame_line_bottom = height();
|
||||
|
||||
// Get scaled width of a second
|
||||
double scaled_width = width_of_second_ * scale_;
|
||||
|
||||
// Draw a line for each second
|
||||
int last_draw = -1;
|
||||
for (double i=0;i<width();i+=scaled_width) {
|
||||
|
||||
// Ensure a reasonable gap has been left between the last line drawn and the line we're about to draw
|
||||
int line_x = qRound(i);
|
||||
if (last_draw < 0 || line_x - last_draw > minimum_gap_between_lines_) {
|
||||
|
||||
p.drawLine(line_x, ruler_second_line_top, line_x, ruler_second_line_bottom);
|
||||
|
||||
p.drawText(line_x, p.fontMetrics().ascent(), QString::number(line_x));
|
||||
|
||||
last_draw = line_x;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef TIMERULER_H
|
||||
#define TIMERULER_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "common/rational.h"
|
||||
|
||||
class TimeRuler : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TimeRuler(bool text_visible = true, QWidget* parent = nullptr);
|
||||
|
||||
void SetTextVisible(bool e);
|
||||
|
||||
void SetScale(double d);
|
||||
|
||||
void SetTimebase(const rational& r);
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent* e) override;
|
||||
|
||||
private:
|
||||
int text_height_;
|
||||
|
||||
int width_of_second_;
|
||||
|
||||
int minimum_gap_between_lines_;
|
||||
|
||||
int scroll_;
|
||||
|
||||
bool text_visible_;
|
||||
|
||||
double scale_;
|
||||
|
||||
rational time_base_;
|
||||
};
|
||||
|
||||
#endif // TIMERULER_H
|
||||
Reference in New Issue
Block a user