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
@@ -23,60 +23,62 @@
#include <olive/core/core.h>
#include <QComboBox>
extern "C"{
extern "C" {
#include <libavformat/avformat.h>
}
#include "ui/humanstrings.h"
namespace olive {
namespace olive
{
using namespace core;
class ChannelLayoutComboBox : public QComboBox
{
Q_OBJECT
class ChannelLayoutComboBox : public QComboBox {
Q_OBJECT
public:
ChannelLayoutComboBox(QWidget* parent = nullptr) :
QComboBox(parent)
{
foreach (const uint64_t& ch_layout, AudioParams::kSupportedChannelLayouts) {
this->addItem(HumanStrings::ChannelLayoutToString(ch_layout),
QVariant::fromValue(ch_layout));
}
}
[[nodiscard]] AVChannelLayout GetChannelLayout() const
{
AVChannelLayout audio_channel_layout_;
av_channel_layout_from_mask(&audio_channel_layout_, this->currentData().toULongLong());
return audio_channel_layout_;
}
void SetChannelLayout(uint64_t ch)
{
for (int i=0; i<this->count(); i++) {
if (this->itemData(i).toULongLong() == ch) {
this->setCurrentIndex(i);
break;
}
}
}
void SetChannelLayout(AVChannelLayout &ch)
{
for (int i=0; i<this->count(); i++) {
if (this->itemData(i).toULongLong() == ch.u.mask) {
this->setCurrentIndex(i);
break;
}
}
}
void SetChannelLayout(AVChannelLayout &&ch)
{
for (int i=0; i<this->count(); i++) {
if (this->itemData(i).toULongLong() == ch.u.mask) {
this->setCurrentIndex(i);
break;
}
}
}
ChannelLayoutComboBox(QWidget *parent = nullptr)
: QComboBox(parent)
{
foreach (const uint64_t &ch_layout,
AudioParams::kSupportedChannelLayouts) {
this->addItem(HumanStrings::ChannelLayoutToString(ch_layout),
QVariant::fromValue(ch_layout));
}
}
[[nodiscard]] AVChannelLayout GetChannelLayout() const
{
AVChannelLayout audio_channel_layout_;
av_channel_layout_from_mask(&audio_channel_layout_,
this->currentData().toULongLong());
return audio_channel_layout_;
}
void SetChannelLayout(uint64_t ch)
{
for (int i = 0; i < this->count(); i++) {
if (this->itemData(i).toULongLong() == ch) {
this->setCurrentIndex(i);
break;
}
}
}
void SetChannelLayout(AVChannelLayout &ch)
{
for (int i = 0; i < this->count(); i++) {
if (this->itemData(i).toULongLong() == ch.u.mask) {
this->setCurrentIndex(i);
break;
}
}
}
void SetChannelLayout(AVChannelLayout &&ch)
{
for (int i = 0; i < this->count(); i++) {
if (this->itemData(i).toULongLong() == ch.u.mask) {
this->setCurrentIndex(i);
break;
}
}
}
public slots:
private:
};
+128 -122
View File
@@ -29,164 +29,170 @@
#include "render/videoparams.h"
namespace olive {
class FrameRateComboBox : public QWidget
namespace olive
{
Q_OBJECT
class FrameRateComboBox : public QWidget {
Q_OBJECT
public:
FrameRateComboBox(QWidget* parent = nullptr) :
QWidget(parent)
{
inner_ = new QComboBox();
FrameRateComboBox(QWidget *parent = nullptr)
: QWidget(parent)
{
inner_ = new QComboBox();
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(inner_);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(inner_);
RepopulateList();
RepopulateList();
old_index_ = 0;
old_index_ = 0;
connect(inner_, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &FrameRateComboBox::IndexChanged);
}
connect(inner_,
static_cast<void (QComboBox::*)(int)>(
&QComboBox::currentIndexChanged),
this, &FrameRateComboBox::IndexChanged);
}
rational GetFrameRate() const
{
if (inner_->currentIndex() == inner_->count() - 1) {
return custom_rate_;
} else {
return inner_->currentData().value<rational>();
}
}
rational GetFrameRate() const
{
if (inner_->currentIndex() == inner_->count() - 1) {
return custom_rate_;
} else {
return inner_->currentData().value<rational>();
}
}
void SetFrameRate(const rational& r)
{
int standard_rates = inner_->count() - 1;
for (int i=0; i<standard_rates; i++) {
if (inner_->itemData(i).value<rational>() == r) {
// Set standard frame rate
old_index_ = i;
SetInnerIndexWithoutSignal(i);
return;
}
}
void SetFrameRate(const rational &r)
{
int standard_rates = inner_->count() - 1;
for (int i = 0; i < standard_rates; i++) {
if (inner_->itemData(i).value<rational>() == r) {
// Set standard frame rate
old_index_ = i;
SetInnerIndexWithoutSignal(i);
return;
}
}
// If we're here, set a custom rate
custom_rate_ = r;
old_index_ = inner_->count()-1;
SetInnerIndexWithoutSignal(old_index_);
RepopulateList();
}
// If we're here, set a custom rate
custom_rate_ = r;
old_index_ = inner_->count() - 1;
SetInnerIndexWithoutSignal(old_index_);
RepopulateList();
}
signals:
void FrameRateChanged(const rational& frame_rate);
void FrameRateChanged(const rational &frame_rate);
protected:
virtual void changeEvent(QEvent* event) override
{
QWidget::changeEvent(event);
virtual void changeEvent(QEvent *event) override
{
QWidget::changeEvent(event);
if (event->type() == QEvent::LanguageChange) {
RepopulateList();
}
}
if (event->type() == QEvent::LanguageChange) {
RepopulateList();
}
}
private slots:
void IndexChanged(int index)
{
if (index == inner_->count() - 1) {
// Custom
QString s;
bool ok;
void IndexChanged(int index)
{
if (index == inner_->count() - 1) {
// Custom
QString s;
bool ok;
if (!custom_rate_.isNull()) {
s = QString::number(custom_rate_.toDouble());
}
if (!custom_rate_.isNull()) {
s = QString::number(custom_rate_.toDouble());
}
while (true) {
s = QInputDialog::getText(this, tr("Custom Frame Rate"), tr("Enter custom frame rate:"),
QLineEdit::Normal, s, &ok);
while (true) {
s = QInputDialog::getText(this, tr("Custom Frame Rate"),
tr("Enter custom frame rate:"),
QLineEdit::Normal, s, &ok);
if (ok) {
rational r;
if (ok) {
rational r;
// Try converting to double, assuming most users will input frame rates this way
double d = s.toDouble(&ok);
// Try converting to double, assuming most users will input frame rates this way
double d = s.toDouble(&ok);
if (ok) {
// Try converting from double
r = rational::fromDouble(d, &ok);
} else {
// Try converting to rational in case someone formatted that way
r = rational::fromString(s.toStdString(), &ok);
}
if (ok) {
// Try converting from double
r = rational::fromDouble(d, &ok);
} else {
// Try converting to rational in case someone formatted that way
r = rational::fromString(s.toStdString(), &ok);
}
if (ok) {
if (ok) {
custom_rate_ = r;
emit FrameRateChanged(r);
old_index_ = index;
RepopulateList();
break;
custom_rate_ = r;
emit FrameRateChanged(r);
old_index_ = index;
RepopulateList();
break;
} else {
// Show message and continue loop
QMessageBox::critical(
this, tr("Invalid Input"),
tr("Failed to convert \"%1\" to a frame rate.")
.arg(s));
}
} else {
// Show message and continue loop
QMessageBox::critical(this, tr("Invalid Input"), tr("Failed to convert \"%1\" to a frame rate.").arg(s));
}
} else {
// User cancelled, revert to original value
SetInnerIndexWithoutSignal(old_index_);
break;
}
}
} else {
old_index_ = index;
emit FrameRateChanged(GetFrameRate());
}
}
} else {
// User cancelled, revert to original value
SetInnerIndexWithoutSignal(old_index_);
break;
}
}
} else {
old_index_ = index;
emit FrameRateChanged(GetFrameRate());
}
}
private:
void RepopulateList()
{
int temp_index = inner_->currentIndex();
void RepopulateList()
{
int temp_index = inner_->currentIndex();
inner_->blockSignals(true);
inner_->blockSignals(true);
inner_->clear();
inner_->clear();
foreach (const rational& fr, VideoParams::kSupportedFrameRates) {
inner_->addItem(VideoParams::FrameRateToString(fr), QVariant::fromValue(fr));
}
foreach (const rational &fr, VideoParams::kSupportedFrameRates) {
inner_->addItem(VideoParams::FrameRateToString(fr),
QVariant::fromValue(fr));
}
if (custom_rate_.isNull()) {
inner_->addItem(tr("Custom..."));
} else {
inner_->addItem(tr("Custom (%1)").arg(VideoParams::FrameRateToString(custom_rate_)));
}
if (custom_rate_.isNull()) {
inner_->addItem(tr("Custom..."));
} else {
inner_->addItem(
tr("Custom (%1)")
.arg(VideoParams::FrameRateToString(custom_rate_)));
}
inner_->setCurrentIndex(temp_index);
inner_->setCurrentIndex(temp_index);
inner_->blockSignals(false);
}
inner_->blockSignals(false);
}
void SetInnerIndexWithoutSignal(int index)
{
inner_->blockSignals(true);
inner_->setCurrentIndex(index);
inner_->blockSignals(false);
}
void SetInnerIndexWithoutSignal(int index)
{
inner_->blockSignals(true);
inner_->setCurrentIndex(index);
inner_->blockSignals(false);
}
QComboBox* inner_;
QComboBox *inner_;
rational custom_rate_;
int old_index_;
rational custom_rate_;
int old_index_;
};
}
+20 -21
View File
@@ -25,31 +25,30 @@
#include "render/videoparams.h"
namespace olive {
class InterlacedComboBox : public QComboBox
namespace olive
{
Q_OBJECT
class InterlacedComboBox : public QComboBox {
Q_OBJECT
public:
InterlacedComboBox(QWidget* parent = nullptr) :
QComboBox(parent)
{
// These must match the Interlacing enum in VideoParams
this->addItem(tr("None (Progressive)"));
this->addItem(tr("Top-Field First"));
this->addItem(tr("Bottom-Field First"));
}
InterlacedComboBox(QWidget *parent = nullptr)
: QComboBox(parent)
{
// These must match the Interlacing enum in VideoParams
this->addItem(tr("None (Progressive)"));
this->addItem(tr("Top-Field First"));
this->addItem(tr("Bottom-Field First"));
}
VideoParams::Interlacing GetInterlaceMode() const
{
return static_cast<VideoParams::Interlacing>(this->currentIndex());
}
void SetInterlaceMode(VideoParams::Interlacing mode)
{
this->setCurrentIndex(mode);
}
VideoParams::Interlacing GetInterlaceMode() const
{
return static_cast<VideoParams::Interlacing>(this->currentIndex());
}
void SetInterlaceMode(VideoParams::Interlacing mode)
{
this->setCurrentIndex(mode);
}
};
}
@@ -26,100 +26,97 @@
#include "common/ratiodialog.h"
#include "render/videoparams.h"
namespace olive {
class PixelAspectRatioComboBox : public QComboBox
namespace olive
{
Q_OBJECT
class PixelAspectRatioComboBox : public QComboBox {
Q_OBJECT
public:
PixelAspectRatioComboBox(QWidget* parent = nullptr) :
QComboBox(parent),
dont_prompt_custom_par_(false)
{
QStringList par_names = VideoParams::GetStandardPixelAspectRatioNames();
for (int i=0; i<VideoParams::kStandardPixelAspects.size(); i++) {
const rational& ratio = VideoParams::kStandardPixelAspects.at(i);
PixelAspectRatioComboBox(QWidget *parent = nullptr)
: QComboBox(parent)
, dont_prompt_custom_par_(false)
{
QStringList par_names = VideoParams::GetStandardPixelAspectRatioNames();
for (int i = 0; i < VideoParams::kStandardPixelAspects.size(); i++) {
const rational &ratio = VideoParams::kStandardPixelAspects.at(i);
this->addItem(par_names.at(i),
QVariant::fromValue(ratio));
}
this->addItem(par_names.at(i), QVariant::fromValue(ratio));
}
// Always add custom item last, much of the logic relies on this. Set this to the current AR so
// that if none of the above are ==, it will eventually select this item
this->addItem(QString());
UpdateCustomItem(rational());
// Always add custom item last, much of the logic relies on this. Set this to the current AR so
// that if none of the above are ==, it will eventually select this item
this->addItem(QString());
UpdateCustomItem(rational());
// Pick up index signal to query for custom aspect ratio if requested
connect(this, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &PixelAspectRatioComboBox::IndexChanged);
}
// Pick up index signal to query for custom aspect ratio if requested
connect(this,
static_cast<void (QComboBox::*)(int)>(
&QComboBox::currentIndexChanged),
this, &PixelAspectRatioComboBox::IndexChanged);
}
rational GetPixelAspectRatio() const
{
return this->currentData().value<rational>();
}
rational GetPixelAspectRatio() const
{
return this->currentData().value<rational>();
}
void SetPixelAspectRatio(const rational& r)
{
// Determine which index to select on startup
for (int i=0; i<this->count(); i++) {
if (this->itemData(i).value<rational>() == r) {
this->setCurrentIndex(i);
return;
}
}
void SetPixelAspectRatio(const rational &r)
{
// Determine which index to select on startup
for (int i = 0; i < this->count(); i++) {
if (this->itemData(i).value<rational>() == r) {
this->setCurrentIndex(i);
return;
}
}
// Must not have found the ratio, so it must be custom
UpdateCustomItem(r);
dont_prompt_custom_par_ = true;
this->setCurrentIndex(this->count() - 1);
dont_prompt_custom_par_ = false;
}
// Must not have found the ratio, so it must be custom
UpdateCustomItem(r);
dont_prompt_custom_par_ = true;
this->setCurrentIndex(this->count() - 1);
dont_prompt_custom_par_ = false;
}
private slots:
void IndexChanged(int index)
{
if (dont_prompt_custom_par_) {
return;
}
void IndexChanged(int index)
{
if (dont_prompt_custom_par_) {
return;
}
// Detect if custom was selected, in which case query what the new AR should be
if (index == this->count() - 1) {
// Query for custom pixel aspect ratio
bool ok;
// Detect if custom was selected, in which case query what the new AR should be
if (index == this->count() - 1) {
// Query for custom pixel aspect ratio
bool ok;
double custom_ratio = GetFloatRatioFromUser(this,
tr("Set Custom Pixel Aspect Ratio"),
&ok);
double custom_ratio = GetFloatRatioFromUser(
this, tr("Set Custom Pixel Aspect Ratio"), &ok);
if (ok) {
UpdateCustomItem(rational::fromDouble(custom_ratio));
}
}
}
if (ok) {
UpdateCustomItem(rational::fromDouble(custom_ratio));
}
}
}
private:
void UpdateCustomItem(const rational &ratio)
{
const int custom_index = this->count() - 1;
void UpdateCustomItem(const rational &ratio)
{
const int custom_index = this->count() - 1;
if (ratio.isNull()) {
this->setItemText(custom_index,
tr("Custom..."));
if (ratio.isNull()) {
this->setItemText(custom_index, tr("Custom..."));
// Use 1:1 to prevent any real chance of the PAR being set to 0
this->setItemData(custom_index,
QVariant::fromValue(rational(1)));
} else {
this->setItemText(custom_index,
VideoParams::FormatPixelAspectRatioString(tr("Custom (%1)"), ratio));
this->setItemData(custom_index,
QVariant::fromValue(ratio));
}
}
bool dont_prompt_custom_par_;
// Use 1:1 to prevent any real chance of the PAR being set to 0
this->setItemData(custom_index, QVariant::fromValue(rational(1)));
} else {
this->setItemText(custom_index,
VideoParams::FormatPixelAspectRatioString(
tr("Custom (%1)"), ratio));
this->setItemData(custom_index, QVariant::fromValue(ratio));
}
}
bool dont_prompt_custom_par_;
};
}
+29 -29
View File
@@ -25,40 +25,40 @@
#include "render/videoparams.h"
namespace olive {
class PixelFormatComboBox : public QComboBox
namespace olive
{
Q_OBJECT
class PixelFormatComboBox : public QComboBox {
Q_OBJECT
public:
PixelFormatComboBox(bool float_only, QWidget* parent = nullptr) :
QComboBox(parent)
{
// Set up preview formats
for (int i=0;i<PixelFormat::COUNT;i++) {
PixelFormat pix_fmt = static_cast<PixelFormat::Format>(i);
PixelFormatComboBox(bool float_only, QWidget *parent = nullptr)
: QComboBox(parent)
{
// Set up preview formats
for (int i = 0; i < PixelFormat::COUNT; i++) {
PixelFormat pix_fmt = static_cast<PixelFormat::Format>(i);
if (!float_only || pix_fmt.is_float()) {
this->addItem(VideoParams::GetFormatName(pix_fmt), static_cast<PixelFormat::Format>(pix_fmt));
}
}
}
if (!float_only || pix_fmt.is_float()) {
this->addItem(VideoParams::GetFormatName(pix_fmt),
static_cast<PixelFormat::Format>(pix_fmt));
}
}
}
PixelFormat GetPixelFormat() const
{
return static_cast<PixelFormat::Format>(this->currentData().toInt());
}
void SetPixelFormat(PixelFormat fmt)
{
for (int i=0; i<this->count(); i++) {
if (this->itemData(i).toInt() == fmt) {
this->setCurrentIndex(i);
break;
}
}
}
PixelFormat GetPixelFormat() const
{
return static_cast<PixelFormat::Format>(this->currentData().toInt());
}
void SetPixelFormat(PixelFormat fmt)
{
for (int i = 0; i < this->count(); i++) {
if (this->itemData(i).toInt() == fmt) {
this->setCurrentIndex(i);
break;
}
}
}
};
}
@@ -26,81 +26,85 @@
#include "ui/humanstrings.h"
namespace olive {
namespace olive
{
using namespace core;
class SampleFormatComboBox : public QComboBox
{
Q_OBJECT
class SampleFormatComboBox : public QComboBox {
Q_OBJECT
public:
SampleFormatComboBox(QWidget* parent = nullptr) :
QComboBox(parent),
attempt_to_restore_format_(true)
{
}
SampleFormatComboBox(QWidget *parent = nullptr)
: QComboBox(parent)
, attempt_to_restore_format_(true)
{
}
void SetAttemptToRestoreFormat(bool e) { attempt_to_restore_format_ = e; }
void SetAttemptToRestoreFormat(bool e)
{
attempt_to_restore_format_ = e;
}
void SetAvailableFormats(const std::vector<SampleFormat> &formats)
{
SampleFormat tmp = SampleFormat::INVALID;
void SetAvailableFormats(const std::vector<SampleFormat> &formats)
{
SampleFormat tmp = SampleFormat::INVALID;
if (attempt_to_restore_format_) {
tmp = GetSampleFormat();
}
if (attempt_to_restore_format_) {
tmp = GetSampleFormat();
}
clear();
foreach (const SampleFormat &of, formats) {
AddFormatItem(of);
}
clear();
foreach (const SampleFormat &of, formats) {
AddFormatItem(of);
}
if (attempt_to_restore_format_) {
SetSampleFormat(tmp);
}
}
if (attempt_to_restore_format_) {
SetSampleFormat(tmp);
}
}
void SetPackedFormats()
{
SampleFormat tmp = SampleFormat::INVALID;
void SetPackedFormats()
{
SampleFormat tmp = SampleFormat::INVALID;
if (attempt_to_restore_format_) {
tmp = GetSampleFormat();
}
if (attempt_to_restore_format_) {
tmp = GetSampleFormat();
}
clear();
for (int i=SampleFormat::PACKED_START; i<SampleFormat::PACKED_END; i++) {
AddFormatItem(static_cast<SampleFormat::Format>(i));
}
clear();
for (int i = SampleFormat::PACKED_START; i < SampleFormat::PACKED_END;
i++) {
AddFormatItem(static_cast<SampleFormat::Format>(i));
}
if (attempt_to_restore_format_) {
SetSampleFormat(tmp);
}
}
if (attempt_to_restore_format_) {
SetSampleFormat(tmp);
}
}
SampleFormat GetSampleFormat() const
{
return static_cast<SampleFormat::Format>(this->currentData().toInt());
}
SampleFormat GetSampleFormat() const
{
return static_cast<SampleFormat::Format>(this->currentData().toInt());
}
void SetSampleFormat(SampleFormat fmt)
{
for (int i=0; i<this->count(); i++) {
if (this->itemData(i).toInt() == fmt) {
this->setCurrentIndex(i);
break;
}
}
}
void SetSampleFormat(SampleFormat fmt)
{
for (int i = 0; i < this->count(); i++) {
if (this->itemData(i).toInt() == fmt) {
this->setCurrentIndex(i);
break;
}
}
}
private:
void AddFormatItem(SampleFormat f)
{
this->addItem(HumanStrings::FormatToString(f), static_cast<SampleFormat::Format>(f));
}
bool attempt_to_restore_format_;
void AddFormatItem(SampleFormat f)
{
this->addItem(HumanStrings::FormatToString(f),
static_cast<SampleFormat::Format>(f));
}
bool attempt_to_restore_format_;
};
}
+24 -25
View File
@@ -26,37 +26,36 @@
#include "ui/humanstrings.h"
namespace olive {
namespace olive
{
using namespace core;
class SampleRateComboBox : public QComboBox
{
Q_OBJECT
class SampleRateComboBox : public QComboBox {
Q_OBJECT
public:
SampleRateComboBox(QWidget* parent = nullptr) :
QComboBox(parent)
{
foreach (int sr, AudioParams::kSupportedSampleRates) {
this->addItem(HumanStrings::SampleRateToString(sr), sr);
}
}
SampleRateComboBox(QWidget *parent = nullptr)
: QComboBox(parent)
{
foreach (int sr, AudioParams::kSupportedSampleRates) {
this->addItem(HumanStrings::SampleRateToString(sr), sr);
}
}
int GetSampleRate() const
{
return this->currentData().toInt();
}
void SetSampleRate(int rate)
{
for (int i=0; i<this->count(); i++) {
if (this->itemData(i).toInt() == rate) {
this->setCurrentIndex(i);
break;
}
}
}
int GetSampleRate() const
{
return this->currentData().toInt();
}
void SetSampleRate(int rate)
{
for (int i = 0; i < this->count(); i++) {
if (this->itemData(i).toInt() == rate) {
this->setCurrentIndex(i);
break;
}
}
}
};
}
@@ -25,35 +25,34 @@
#include "render/videoparams.h"
namespace olive {
class VideoDividerComboBox : public QComboBox
namespace olive
{
Q_OBJECT
class VideoDividerComboBox : public QComboBox {
Q_OBJECT
public:
VideoDividerComboBox(QWidget* parent = nullptr) :
QComboBox(parent)
{
foreach (int d, VideoParams::kSupportedDividers) {
this->addItem(VideoParams::GetNameForDivider(d), d);
}
}
VideoDividerComboBox(QWidget *parent = nullptr)
: QComboBox(parent)
{
foreach (int d, VideoParams::kSupportedDividers) {
this->addItem(VideoParams::GetNameForDivider(d), d);
}
}
int GetDivider() const
{
return this->currentData().toInt();
}
void SetDivider(int d)
{
for (int i=0; i<this->count(); i++) {
if (this->itemData(i).toInt() == d) {
this->setCurrentIndex(i);
break;
}
}
}
int GetDivider() const
{
return this->currentData().toInt();
}
void SetDivider(int d)
{
for (int i = 0; i < this->count(); i++) {
if (this->itemData(i).toInt() == d) {
this->setCurrentIndex(i);
break;
}
}
}
};
}