change: change code style to Linux style except indent.

This commit is contained in:
Mike Solar
2025-08-03 03:09:40 +08:00
parent 65ab76edc8
commit 74f73ab3be
789 changed files with 77113 additions and 68888 deletions
+221 -194
View File
@@ -28,376 +28,403 @@
#include "core.h"
#include "ui/colorcoding.h"
namespace olive {
TimelineMarker::TimelineMarker(QObject *parent) :
color_(OLIVE_CONFIG("MarkerColor").toInt())
namespace olive
{
setParent(parent);
TimelineMarker::TimelineMarker(QObject *parent)
: color_(OLIVE_CONFIG("MarkerColor").toInt())
{
setParent(parent);
}
TimelineMarker::TimelineMarker(int color, const TimeRange &time, const QString &name, QObject *parent) :
time_(time),
name_(name),
color_(color)
TimelineMarker::TimelineMarker(int color, const TimeRange &time,
const QString &name, QObject *parent)
: time_(time)
, name_(name)
, color_(color)
{
setParent(parent);
setParent(parent);
}
void TimelineMarker::set_time(const TimeRange &time)
{
time_ = time;
emit TimeChanged(time_);
time_ = time;
emit TimeChanged(time_);
}
void TimelineMarker::set_time(const rational &time)
{
set_time(TimeRange(time, time + time_.length()));
set_time(TimeRange(time, time + time_.length()));
}
bool TimelineMarker::has_sibling_at_time(const rational &t) const
{
TimelineMarker *m = static_cast<TimelineMarkerList*>(parent())->GetMarkerAtTime(t);
return m && m != this;
TimelineMarker *m =
static_cast<TimelineMarkerList *>(parent())->GetMarkerAtTime(t);
return m && m != this;
}
void TimelineMarker::set_name(const QString &name)
{
name_ = name;
emit NameChanged(name_);
name_ = name;
emit NameChanged(name_);
}
void TimelineMarker::set_color(int c)
{
color_ = c;
emit ColorChanged(color_);
color_ = c;
emit ColorChanged(color_);
}
int TimelineMarker::GetMarkerHeight(const QFontMetrics &fm)
{
return fm.height();
return fm.height();
}
QRect TimelineMarker::Draw(QPainter *p, const QPoint &pt, int max_right, double scale, bool selected)
QRect TimelineMarker::Draw(QPainter *p, const QPoint &pt, int max_right,
double scale, bool selected)
{
QFontMetrics fm = p->fontMetrics();
QFontMetrics fm = p->fontMetrics();
int marker_height = GetMarkerHeight(fm);
int marker_width = QtUtils::QFontMetricsWidth(fm, QStringLiteral("H"));
int marker_height = GetMarkerHeight(fm);
int marker_width = QtUtils::QFontMetricsWidth(fm, QStringLiteral("H"));
int half_width = marker_width / 2;
int half_width = marker_width / 2;
QColor c = QtUtils::toQColor(ColorCoding::GetColor(color()));
if (selected) {
p->setPen(Qt::white);
p->setBrush(c.lighter());
} else {
p->setPen(Qt::black);
p->setBrush(c);
}
QColor c = QtUtils::toQColor(ColorCoding::GetColor(color()));
if (selected) {
p->setPen(Qt::white);
p->setBrush(c.lighter());
} else {
p->setPen(Qt::black);
p->setBrush(c);
}
int top = pt.y() - marker_height;
int top = pt.y() - marker_height;
QTextOption op(Qt::AlignLeft | Qt::AlignVCenter);
op.setWrapMode(QTextOption::NoWrap);
QTextOption op(Qt::AlignLeft | Qt::AlignVCenter);
op.setWrapMode(QTextOption::NoWrap);
if (time_.out() != time_.in()) {
QRect marker_rect(pt.x(), top, time_.length().toDouble() * scale, marker_height);
if (time_.out() != time_.in()) {
QRect marker_rect(pt.x(), top, time_.length().toDouble() * scale,
marker_height);
p->drawRect(marker_rect);
p->drawRect(marker_rect);
if (!name_.isEmpty()) {
p->setPen(ColorCoding::GetUISelectorColor(ColorCoding::GetColor(color_)));
p->drawText(marker_rect.adjusted(marker_width/4, 0, 0, 0), name_, op);
}
if (!name_.isEmpty()) {
p->setPen(
ColorCoding::GetUISelectorColor(ColorCoding::GetColor(color_)));
p->drawText(marker_rect.adjusted(marker_width / 4, 0, 0, 0), name_,
op);
}
return marker_rect;
} else {
int half_marker_height = marker_height / 3;
int left = pt.x() - half_width;
int right = pt.x() + half_width;
int center_y = pt.y() - half_marker_height;
return marker_rect;
} else {
int half_marker_height = marker_height / 3;
int left = pt.x() - half_width;
int right = pt.x() + half_width;
int center_y = pt.y() - half_marker_height;
QPoint points[] = {
pt,
QPoint(left, center_y),
QPoint(left, top),
QPoint(right, top),
QPoint(right, center_y),
pt,
};
QPoint points[] = {
pt,
QPoint(left, center_y),
QPoint(left, top),
QPoint(right, top),
QPoint(right, center_y),
pt,
};
p->setRenderHint(QPainter::Antialiasing);
p->drawPolygon(points, 6);
p->setRenderHint(QPainter::Antialiasing);
p->drawPolygon(points, 6);
if (!name_.isEmpty() && max_right != -1) {
QRect text_rect(right, top, max_right - right, marker_height);
if (!name_.isEmpty() && max_right != -1) {
QRect text_rect(right, top, max_right - right, marker_height);
int padding = QtUtils::QFontMetricsWidth(p->fontMetrics(), QStringLiteral(" "));
text_rect.adjust(padding, 0, - padding - half_width, 0);
int padding = QtUtils::QFontMetricsWidth(p->fontMetrics(),
QStringLiteral(" "));
text_rect.adjust(padding, 0, -padding - half_width, 0);
p->setPen(qApp->palette().text().color());
p->drawText(text_rect, name_, op);
}
p->setPen(qApp->palette().text().color());
p->drawText(text_rect, name_, op);
}
return QRect(left, top, marker_width, marker_height);
}
return QRect(left, top, marker_width, marker_height);
}
}
bool TimelineMarker::load(QXmlStreamReader *reader)
{
rational in, out;
rational in, out;
XMLAttributeLoop(reader, attr) {
if (attr.name() == QStringLiteral("name")) {
this->set_name(attr.value().toString());
} else if (attr.name() == QStringLiteral("in")) {
in = rational::fromString(attr.value().toString().toStdString());
} else if (attr.name() == QStringLiteral("out")) {
out = rational::fromString(attr.value().toString().toStdString());
} else if (attr.name() == QStringLiteral("color")) {
this->set_color(attr.value().toInt());
}
}
XMLAttributeLoop(reader, attr)
{
if (attr.name() == QStringLiteral("name")) {
this->set_name(attr.value().toString());
} else if (attr.name() == QStringLiteral("in")) {
in = rational::fromString(attr.value().toString().toStdString());
} else if (attr.name() == QStringLiteral("out")) {
out = rational::fromString(attr.value().toString().toStdString());
} else if (attr.name() == QStringLiteral("color")) {
this->set_color(attr.value().toInt());
}
}
this->set_time(TimeRange(in, out));
this->set_time(TimeRange(in, out));
// This element has no inner text, so just skip it
reader->skipCurrentElement();
// This element has no inner text, so just skip it
reader->skipCurrentElement();
return true;
return true;
}
void TimelineMarker::save(QXmlStreamWriter *writer) const
{
writer->writeAttribute(QStringLiteral("name"), this->name());
writer->writeAttribute(QStringLiteral("in"), QString::fromStdString(this->time().in().toString()));
writer->writeAttribute(QStringLiteral("out"), QString::fromStdString(this->time().out().toString()));
writer->writeAttribute(QStringLiteral("color"), QString::number(this->color()));
writer->writeAttribute(QStringLiteral("name"), this->name());
writer->writeAttribute(
QStringLiteral("in"),
QString::fromStdString(this->time().in().toString()));
writer->writeAttribute(
QStringLiteral("out"),
QString::fromStdString(this->time().out().toString()));
writer->writeAttribute(QStringLiteral("color"),
QString::number(this->color()));
}
bool TimelineMarkerList::load(QXmlStreamReader *reader)
{
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("marker")) {
TimelineMarker *marker = new TimelineMarker(this);
if (!marker->load(reader)) {
return false;
}
} else {
reader->skipCurrentElement();
}
}
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("marker")) {
TimelineMarker *marker = new TimelineMarker(this);
if (!marker->load(reader)) {
return false;
}
} else {
reader->skipCurrentElement();
}
}
return true;
return true;
}
void TimelineMarkerList::save(QXmlStreamWriter *writer) const
{
for (auto it=this->cbegin(); it!=this->cend(); it++) {
TimelineMarker* marker = *it;
for (auto it = this->cbegin(); it != this->cend(); it++) {
TimelineMarker *marker = *it;
writer->writeStartElement(QStringLiteral("marker"));
writer->writeStartElement(QStringLiteral("marker"));
marker->save(writer);
marker->save(writer);
writer->writeEndElement(); // marker
}
writer->writeEndElement(); // marker
}
}
void TimelineMarkerList::childEvent(QChildEvent *e)
{
QObject::childEvent(e);
QObject::childEvent(e);
if (TimelineMarker *marker = dynamic_cast<TimelineMarker *>(e->child())) {
if (e->type() == QChildEvent::ChildAdded) {
if (TimelineMarker *marker = dynamic_cast<TimelineMarker *>(e->child())) {
if (e->type() == QChildEvent::ChildAdded) {
connect(marker, &TimelineMarker::TimeChanged, this,
&TimelineMarkerList::HandleMarkerTimeChange);
connect(marker, &TimelineMarker::TimeChanged, this,
&TimelineMarkerList::HandleMarkerModification);
connect(marker, &TimelineMarker::NameChanged, this,
&TimelineMarkerList::HandleMarkerModification);
connect(marker, &TimelineMarker::ColorChanged, this,
&TimelineMarkerList::HandleMarkerModification);
connect(marker, &TimelineMarker::TimeChanged, this, &TimelineMarkerList::HandleMarkerTimeChange);
connect(marker, &TimelineMarker::TimeChanged, this, &TimelineMarkerList::HandleMarkerModification);
connect(marker, &TimelineMarker::NameChanged, this, &TimelineMarkerList::HandleMarkerModification);
connect(marker, &TimelineMarker::ColorChanged, this, &TimelineMarkerList::HandleMarkerModification);
InsertIntoList(marker);
InsertIntoList(marker);
emit MarkerAdded(marker);
emit MarkerAdded(marker);
} else if (e->type() == QChildEvent::ChildRemoved) {
RemoveFromList(marker);
} else if (e->type() == QChildEvent::ChildRemoved) {
disconnect(marker, &TimelineMarker::TimeChanged, this,
&TimelineMarkerList::HandleMarkerTimeChange);
disconnect(marker, &TimelineMarker::TimeChanged, this,
&TimelineMarkerList::HandleMarkerModification);
disconnect(marker, &TimelineMarker::NameChanged, this,
&TimelineMarkerList::HandleMarkerModification);
disconnect(marker, &TimelineMarker::ColorChanged, this,
&TimelineMarkerList::HandleMarkerModification);
RemoveFromList(marker);
disconnect(marker, &TimelineMarker::TimeChanged, this, &TimelineMarkerList::HandleMarkerTimeChange);
disconnect(marker, &TimelineMarker::TimeChanged, this, &TimelineMarkerList::HandleMarkerModification);
disconnect(marker, &TimelineMarker::NameChanged, this, &TimelineMarkerList::HandleMarkerModification);
disconnect(marker, &TimelineMarker::ColorChanged, this, &TimelineMarkerList::HandleMarkerModification);
emit MarkerRemoved(marker);
}
}
emit MarkerRemoved(marker);
}
}
}
void TimelineMarkerList::InsertIntoList(TimelineMarker *marker)
{
// Insertion sort by time to allow some loop optimizations
bool found = false;
for (auto it=markers_.begin(); it!=markers_.end(); it++) {
TimelineMarker *m = *it;
// Insertion sort by time to allow some loop optimizations
bool found = false;
for (auto it = markers_.begin(); it != markers_.end(); it++) {
TimelineMarker *m = *it;
Q_ASSERT(m->time().in() != marker->time().in());
Q_ASSERT(m->time().in() != marker->time().in());
if (m->time().in() > marker->time().in()) {
markers_.insert(it, marker);
found = true;
break;
}
}
if (m->time().in() > marker->time().in()) {
markers_.insert(it, marker);
found = true;
break;
}
}
if (!found) {
markers_.push_back(marker);
}
if (!found) {
markers_.push_back(marker);
}
}
bool TimelineMarkerList::RemoveFromList(TimelineMarker *marker)
{
auto it = std::find(markers_.begin(), markers_.end(), marker);
auto it = std::find(markers_.begin(), markers_.end(), marker);
if (it != markers_.end()) {
markers_.erase(it);
return true;
}
if (it != markers_.end()) {
markers_.erase(it);
return true;
}
return false;
return false;
}
void TimelineMarkerList::HandleMarkerModification()
{
emit MarkerModified(static_cast<TimelineMarker*>(sender()));
emit MarkerModified(static_cast<TimelineMarker *>(sender()));
}
void TimelineMarkerList::HandleMarkerTimeChange()
{
TimelineMarker *m = static_cast<TimelineMarker*>(sender());
TimelineMarker *m = static_cast<TimelineMarker *>(sender());
auto it = std::find(markers_.begin(), markers_.end(), m);
auto it = std::find(markers_.begin(), markers_.end(), m);
if (it != markers_.end()) {
markers_.erase(it);
InsertIntoList(m);
}
if (it != markers_.end()) {
markers_.erase(it);
InsertIntoList(m);
}
}
MarkerAddCommand::MarkerAddCommand(TimelineMarkerList *marker_list, const TimeRange &range, const QString &name, int color) :
MarkerAddCommand(marker_list, new TimelineMarker(color, range, name, &memory_manager_))
MarkerAddCommand::MarkerAddCommand(TimelineMarkerList *marker_list,
const TimeRange &range, const QString &name,
int color)
: MarkerAddCommand(marker_list,
new TimelineMarker(color, range, name, &memory_manager_))
{
}
MarkerAddCommand::MarkerAddCommand(TimelineMarkerList *marker_list, TimelineMarker *marker) :
marker_list_(marker_list),
added_marker_(marker)
MarkerAddCommand::MarkerAddCommand(TimelineMarkerList *marker_list,
TimelineMarker *marker)
: marker_list_(marker_list)
, added_marker_(marker)
{
added_marker_->setParent(&memory_manager_);
added_marker_->setParent(&memory_manager_);
}
Project* MarkerAddCommand::GetRelevantProject() const
Project *MarkerAddCommand::GetRelevantProject() const
{
return Project::GetProjectFromObject(marker_list_);
return Project::GetProjectFromObject(marker_list_);
}
void MarkerAddCommand::redo()
{
added_marker_->setParent(marker_list_);
added_marker_->setParent(marker_list_);
}
void MarkerAddCommand::undo()
{
added_marker_->setParent(&memory_manager_);
added_marker_->setParent(&memory_manager_);
}
MarkerRemoveCommand::MarkerRemoveCommand(TimelineMarker *marker) :
marker_(marker)
MarkerRemoveCommand::MarkerRemoveCommand(TimelineMarker *marker)
: marker_(marker)
{
}
Project* MarkerRemoveCommand::GetRelevantProject() const
Project *MarkerRemoveCommand::GetRelevantProject() const
{
return Project::GetProjectFromObject(marker_);
return Project::GetProjectFromObject(marker_);
}
void MarkerRemoveCommand::redo()
{
marker_list_ = marker_->parent();
marker_->setParent(&memory_manager_);
marker_list_ = marker_->parent();
marker_->setParent(&memory_manager_);
}
void MarkerRemoveCommand::undo()
{
marker_->setParent(marker_list_);
marker_->setParent(marker_list_);
}
MarkerChangeColorCommand::MarkerChangeColorCommand(TimelineMarker *marker, int new_color) :
marker_(marker),
new_color_(new_color)
MarkerChangeColorCommand::MarkerChangeColorCommand(TimelineMarker *marker,
int new_color)
: marker_(marker)
, new_color_(new_color)
{
}
Project* MarkerChangeColorCommand::GetRelevantProject() const
Project *MarkerChangeColorCommand::GetRelevantProject() const
{
return Project::GetProjectFromObject(marker_);
return Project::GetProjectFromObject(marker_);
}
void MarkerChangeColorCommand::redo()
{
old_color_ = marker_->color();
marker_->set_color(new_color_);
old_color_ = marker_->color();
marker_->set_color(new_color_);
}
void MarkerChangeColorCommand::undo()
{
marker_->set_color(old_color_);
marker_->set_color(old_color_);
}
MarkerChangeNameCommand::MarkerChangeNameCommand(TimelineMarker *marker, QString new_name) :
marker_(marker),
new_name_(new_name)
MarkerChangeNameCommand::MarkerChangeNameCommand(TimelineMarker *marker,
QString new_name)
: marker_(marker)
, new_name_(new_name)
{
}
Project* MarkerChangeNameCommand::GetRelevantProject() const
Project *MarkerChangeNameCommand::GetRelevantProject() const
{
return Project::GetProjectFromObject(marker_);
return Project::GetProjectFromObject(marker_);
}
void MarkerChangeNameCommand::redo()
{
old_name_ = marker_->name();
marker_->set_name(new_name_);
old_name_ = marker_->name();
marker_->set_name(new_name_);
}
void MarkerChangeNameCommand::undo()
{
marker_->set_name(old_name_);
marker_->set_name(old_name_);
}
MarkerChangeTimeCommand::MarkerChangeTimeCommand(TimelineMarker* marker, const TimeRange &time, const TimeRange &old_time) :
marker_(marker),
old_time_(old_time),
new_time_(time)
MarkerChangeTimeCommand::MarkerChangeTimeCommand(TimelineMarker *marker,
const TimeRange &time,
const TimeRange &old_time)
: marker_(marker)
, old_time_(old_time)
, new_time_(time)
{
}
Project* MarkerChangeTimeCommand::GetRelevantProject() const
Project *MarkerChangeTimeCommand::GetRelevantProject() const
{
return Project::GetProjectFromObject(marker_);
return Project::GetProjectFromObject(marker_);
}
void MarkerChangeTimeCommand::redo()
{
marker_->set_time(new_time_);
marker_->set_time(new_time_);
}
void MarkerChangeTimeCommand::undo()
{
marker_->set_time(old_time_);
marker_->set_time(old_time_);
}
}