started timeruler object

This commit is contained in:
itsmattkc
2019-07-24 01:53:24 -07:00
parent 2e41f6d8f0
commit 501110c328
10 changed files with 186 additions and 15 deletions
+2
View File
@@ -22,5 +22,7 @@ set(OLIVE_SOURCES
common/rational.h
common/rational.cpp
common/qobjectlistcast.h
common/qtversionabstraction.h
common/qtversionabstraction.cpp
PARENT_SCOPE
)
+9
View File
@@ -0,0 +1,9 @@
#include "qtversionabstraction.h"
int QFontMetricsWidth(const QFontMetrics* fm, const QString& s) {
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
return fm->width(s);
#else
return fm->horizontalAdvance(s);
#endif
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef QTVERSIONABSTRACTION_H
#define QTVERSIONABSTRACTION_H
#include <QFontMetrics>
int QFontMetricsWidth(const QFontMetrics* fm, const QString& s);
#endif // QTVERSIONABSTRACTION_H
+15
View File
@@ -20,9 +20,24 @@
#include "timeline.h"
#include <QVBoxLayout>
#include "widget/timeruler/timeruler.h"
TimelinePanel::TimelinePanel(QWidget *parent) :
PanelWidget(parent)
{
// FIXME: Test code
QWidget* main = new QWidget(this);
setWidget(main);
QVBoxLayout* layout = new QVBoxLayout(main);
TimeRuler* tr = new TimeRuler(true, this);
layout->addWidget(tr);
layout->addStretch();
// End test code
Retranslate();
}
+1
View File
@@ -24,6 +24,7 @@ add_subdirectory(playbackcontrols)
add_subdirectory(projectexplorer)
add_subdirectory(projecttoolbar)
add_subdirectory(taskview)
add_subdirectory(timeruler)
add_subdirectory(toolbar)
add_subdirectory(viewer)
+3 -10
View File
@@ -26,6 +26,7 @@
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include "common/qtversionabstraction.h"
#include "core.h"
#include "nodeview.h"
#include "nodeviewundo.h"
@@ -52,11 +53,7 @@ NodeViewItem::NodeViewItem(QGraphicsItem *parent) :
//
// Not particularly great way of using text scaling to set the width (DPI-awareness, etc.)
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int widget_width = font_metrics.width("HHHHHHHHHHHHHHHH");
#else
int widget_width = font_metrics.horizontalAdvance("HHHHHHHHHHHHHHHH");
#endif
int widget_width = QFontMetricsWidth(&font_metrics, "HHHHHHHHHHHHHHHH");
// Set border width
node_border_width_ = font_metrics.height() / 12;
@@ -207,11 +204,7 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
QPointF text_pt = GetParameterTextPoint(i);
if (param->type() == NodeParam::kOutput) {
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
text_pt -= QPointF(font_metrics.width(param->name()), 0);
#else
text_pt -= QPointF(font_metrics.horizontalAdvance(param->name()), 0);
#endif
text_pt -= QPointF(QFontMetricsWidth(&font_metrics, param->name()), 0);
}
painter->drawText(text_pt, param->name());
@@ -22,6 +22,8 @@
#include <QPainter>
#include "common/qtversionabstraction.h"
ProjectExplorerIconViewItemDelegate::ProjectExplorerIconViewItemDelegate(QObject *parent) :
QStyledItemDelegate (parent)
{
@@ -62,11 +64,7 @@ void ProjectExplorerIconViewItemDelegate::paint(QPainter *painter, const QStyleO
QString duration_str = index.data(Qt::UserRole).toString();
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
int timecode_width = fm.width(duration_str);
#else
int timecode_width = fm.horizontalAdvance(duration_str);
#endif
int timecode_width = QFontMetricsWidth(&fm, duration_str);
int max_name_width = option.rect.width();
+22
View File
@@ -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
)
+84
View File
@@ -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;
}
}
}
+39
View File
@@ -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