Files
oak-editor/app/widget/timelinewidget/trackview/trackviewitem.cpp
T
Mike-Solar bb40b4923e style: unify identifier naming per updated conventions
Automated with clang-tidy readability-identifier-naming (config added to
.clang-tidy) plus scripted passes, per the updated rules now documented
in CONTRIBUTING.md:

- types (class/struct/enum/alias/template params): PascalCase
- functions, variables, members: snake_case (incl. rational -> Rational)
- private/protected members: trailing underscore; static member
  variables likewise (instance_, available_themes_)
- constants and enum values: snake_case (kLinear -> k_linear,
  F32P -> f32p); ALL_CAPS reserved for macros
- macros: OAK_ prefix (OLIVE_ADD_TEST/OLIVE_ASSERT/OLIVE_CONFIG ->
  OAK_ADD_TEST/OAK_ASSERT/OAK_CONFIG, GL_PREAMBLE -> OAK_GL_PREAMBLE,
  include guards -> OAK_*)
- file names: all lowercase (Current/Plugin/OliveHost/OliveClip/
  OlivePluginInstance -> current/plugin/olivehost/oliveclip/
  oliveplugininstance)
- getters share the member name sans underscore, setters set_foo()
- Qt and third-party (OpenFX) virtual overrides and framework callbacks
  keep their original names (exempt in .clang-tidy)

Manual follow-ups required where automation could not reach:
- string-based QMetaObject/SIGNAL/SLOT references updated to renamed
  methods (AddTask, CreatedFile, DeleteSpecificFile, moveSelectionUp, ...)
- macro bodies referencing renamed methods (OLIVE_CONFIG,
  NODE_DEFAULT_DESTRUCTOR, MANAGEDDISPLAYWIDGET_*)
- self-shadowing locals renamed where signals/methods became same-named
  (size_changed, worker_count, selected_items, import param, filters)
- third_party OFX member/namespace usages restored (OFX::Host::*,
  _created, _clipPrefsDirty, createInstance, clearPersistentMessage)
- STL protocol aliases restored (const_iterator) with .clang-tidy
  ignore rules; qHash overloads restored

Full build and test suite pass: ctest 4/4, ~1960 gtest cases green.
2026-07-19 16:10:54 +08:00

210 lines
5.8 KiB
C++

/***
Olive - Non-Linear Video Editor
Copyright (C) 2022 Olive Team
Modifications Copyright (C) 2025 mikesolar
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/>.
***/
#include "trackviewitem.h"
#include <QDebug>
#include <QHBoxLayout>
#include <QMessageBox>
#include <QMouseEvent>
#include <QPainter>
#include <QtMath>
#include "core.h"
#include "timeline/timelineundogeneral.h"
#include "ui/icons/icons.h"
#include "widget/menu/menu.h"
namespace olive
{
TrackViewItem::TrackViewItem(Track *track, QWidget *parent)
: QWidget(parent)
, track_(track)
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
stack_ = new QStackedWidget();
layout->addWidget(stack_);
label_ = new ClickableLabel();
connect(label_, &ClickableLabel::mouse_double_clicked, this,
&TrackViewItem::label_clicked);
connect(track_, &Track::label_changed, this, &TrackViewItem::update_label);
connect(track_, &Track::index_changed, this, &TrackViewItem::update_label);
update_label();
stack_->addWidget(label_);
line_edit_ = new FocusableLineEdit();
connect(line_edit_, &FocusableLineEdit::confirmed, this,
&TrackViewItem::line_edit_confirmed);
connect(line_edit_, &FocusableLineEdit::cancelled, this,
&TrackViewItem::line_edit_cancelled);
stack_->addWidget(line_edit_);
mute_button_ = create_msl_button(Qt::red);
mute_button_->setChecked(track->is_muted());
update_mute_button(track->is_muted());
connect(mute_button_, &QPushButton::toggled, track_, &Track::set_muted);
connect(mute_button_, &QPushButton::toggled, this,
&TrackViewItem::update_mute_button);
layout->addWidget(mute_button_);
/*solo_button_ = CreateMSLButton(tr("S"), Qt::yellow);
layout->addWidget(solo_button_);*/
lock_button_ = create_msl_button(Qt::gray);
lock_button_->setChecked(track->is_locked());
update_lock_button(track->is_locked());
connect(lock_button_, &QPushButton::toggled, track_, &Track::set_locked);
connect(lock_button_, &QPushButton::toggled, this,
&TrackViewItem::update_lock_button);
layout->addWidget(lock_button_);
setMinimumHeight(mute_button_->height());
setContextMenuPolicy(Qt::CustomContextMenu);
connect(track, &Track::muted_changed, mute_button_,
&QPushButton::setChecked);
connect(this, &QWidget::customContextMenuRequested, this,
&TrackViewItem::show_context_menu);
}
QPushButton *TrackViewItem::create_msl_button(const QColor &checked_color) const
{
QPushButton *button = new QPushButton();
button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
button->setCheckable(true);
button->setStyleSheet(
QStringLiteral("QPushButton::checked { background: %1; }")
.arg(checked_color.name()));
int size = button->sizeHint().height();
size = qRound(size * 0.75);
button->setFixedSize(size, size);
return button;
}
void TrackViewItem::label_clicked()
{
stack_->setCurrentWidget(line_edit_);
line_edit_->setFocus();
line_edit_->selectAll();
}
void TrackViewItem::line_edit_confirmed()
{
line_edit_->blockSignals(true);
track_->set_label(line_edit_->text());
update_label();
stack_->setCurrentWidget(label_);
line_edit_->blockSignals(false);
}
void TrackViewItem::line_edit_cancelled()
{
line_edit_->blockSignals(true);
stack_->setCurrentWidget(label_);
line_edit_->blockSignals(false);
}
void TrackViewItem::update_label()
{
label_->setText(track_->get_label_or_name());
}
void TrackViewItem::show_context_menu(const QPoint &p)
{
Menu m(this);
QAction *delete_action = m.addAction(tr("&Delete"));
connect(delete_action, &QAction::triggered, this,
&TrackViewItem::delete_track, Qt::QueuedConnection);
m.addSeparator();
QAction *delete_unused_action = m.addAction(tr("Delete All &Empty"));
connect(delete_unused_action, &QAction::triggered, this,
&TrackViewItem::delete_all_empty_tracks, Qt::QueuedConnection);
m.exec(mapToGlobal(p));
}
void TrackViewItem::delete_track()
{
emit about_to_delete_track(track_);
Core::instance()->undo_stack()->push(
new TimelineRemoveTrackCommand(track_),
tr("Deleted Track \"%1\"").arg(track_->get_label_or_name()));
}
void TrackViewItem::delete_all_empty_tracks()
{
Sequence *sequence = track_->sequence();
QVector<Track *> tracks_to_remove;
QStringList track_names_to_remove;
foreach (Track *t, sequence->get_tracks()) {
if (t->blocks().isEmpty()) {
tracks_to_remove.append(t);
track_names_to_remove.append(t->get_label_or_name());
}
}
if (tracks_to_remove.isEmpty()) {
QMessageBox::information(this, tr("Delete All Empty"),
tr("No tracks are currently empty"));
} else {
if (QMessageBox::question(
this, tr("Delete All Empty"),
tr("This will delete the following tracks:\n\n%1\n\nDo you wish to continue?")
.arg(track_names_to_remove.join('\n')),
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
MultiUndoCommand *command = new MultiUndoCommand();
foreach (Track *track, tracks_to_remove) {
command->add_child(new TimelineRemoveTrackCommand(track));
}
Core::instance()->undo_stack()->push(
command, tr("Deleted All Empty Tracks"));
}
}
}
void TrackViewItem::update_mute_button(bool e)
{
mute_button_->setIcon(e ? icon::eye_closed : icon::eye_opened);
}
void TrackViewItem::update_lock_button(bool e)
{
lock_button_->setIcon(e ? icon::lock_closed : icon::lock_opened);
}
}