node: merge various metadata functions into one
This commit is contained in:
@@ -64,7 +64,7 @@ FootageRelinkDialog::FootageRelinkDialog(const QVector<Footage *> &footage, QWid
|
||||
connect(item_browse_btn, &QPushButton::clicked, this, &FootageRelinkDialog::BrowseForFootage);
|
||||
item_actions_layout->addWidget(item_browse_btn);
|
||||
|
||||
item->setIcon(0, f->icon());
|
||||
item->setIcon(0, f->data(Node::ICON).value<QIcon>());
|
||||
item->setText(0, f->GetLabel());
|
||||
item->setText(1, f->filename());
|
||||
|
||||
@@ -89,7 +89,7 @@ void FootageRelinkDialog::UpdateFootageItem(int index)
|
||||
{
|
||||
Footage* f = footage_.at(index);
|
||||
QTreeWidgetItem* item = table_->topLevelItem(index);
|
||||
item->setIcon(0, f->icon());
|
||||
item->setIcon(0, f->data(Node::ICON).value<QIcon>());
|
||||
item->setText(1, f->filename());
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -103,10 +103,14 @@ void Node::Retranslate()
|
||||
SetInputName(kEnabledInput, tr("Enabled"));
|
||||
}
|
||||
|
||||
QIcon Node::icon() const
|
||||
QVariant Node::data(const DataType &d) const
|
||||
{
|
||||
// Just a meaningless default icon to be used where necessary
|
||||
return icon::New;
|
||||
if (d == ICON) {
|
||||
// Just a meaningless default icon to be used where necessary
|
||||
return icon::New;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool Node::SetNodePositionInContext(Node *node, const QPointF &pos)
|
||||
|
||||
+9
-7
@@ -194,14 +194,16 @@ public:
|
||||
*/
|
||||
virtual void Retranslate();
|
||||
|
||||
virtual QIcon icon() const;
|
||||
enum DataType
|
||||
{
|
||||
ICON,
|
||||
DURATION,
|
||||
CREATED_TIME,
|
||||
MODIFIED_TIME,
|
||||
FREQUENCY_RATE
|
||||
};
|
||||
|
||||
virtual QString duration() const {return QString();}
|
||||
|
||||
virtual qint64 creation_time() const {return 0;}
|
||||
virtual qint64 mod_time() const {return 0;}
|
||||
|
||||
virtual QString rate() const {return QString();}
|
||||
virtual QVariant data(const DataType &d) const;
|
||||
|
||||
const QVector<QString>& inputs() const
|
||||
{
|
||||
|
||||
@@ -87,56 +87,61 @@ QString ViewerOutput::Description() const
|
||||
return tr("Interface between a Viewer panel and the node system.");
|
||||
}
|
||||
|
||||
QString ViewerOutput::duration() const
|
||||
QVariant ViewerOutput::data(const DataType &d) const
|
||||
{
|
||||
rational using_timebase;
|
||||
Timecode::Display using_display = Core::instance()->GetTimecodeDisplay();
|
||||
switch (d) {
|
||||
case DURATION:
|
||||
{
|
||||
rational using_timebase;
|
||||
Timecode::Display using_display = Core::instance()->GetTimecodeDisplay();
|
||||
|
||||
// Get first enabled streams
|
||||
VideoParams video = GetFirstEnabledVideoStream();
|
||||
AudioParams audio = GetFirstEnabledAudioStream();
|
||||
SubtitleParams sub = GetFirstEnabledSubtitleStream();
|
||||
// Get first enabled streams
|
||||
VideoParams video = GetFirstEnabledVideoStream();
|
||||
AudioParams audio = GetFirstEnabledAudioStream();
|
||||
SubtitleParams sub = GetFirstEnabledSubtitleStream();
|
||||
|
||||
if (video.is_valid() && video.video_type() != VideoParams::kVideoTypeStill) {
|
||||
// Prioritize video
|
||||
using_timebase = video.frame_rate_as_time_base();
|
||||
} else if (audio.is_valid()) {
|
||||
// Use audio as a backup
|
||||
// If we're showing in a timecode, we prefer showing audio in seconds instead
|
||||
if (using_display == Timecode::kTimecodeDropFrame
|
||||
|| using_display == Timecode::kTimecodeNonDropFrame) {
|
||||
using_display = Timecode::kTimecodeSeconds;
|
||||
if (video.is_valid() && video.video_type() != VideoParams::kVideoTypeStill) {
|
||||
// Prioritize video
|
||||
using_timebase = video.frame_rate_as_time_base();
|
||||
} else if (audio.is_valid()) {
|
||||
// Use audio as a backup
|
||||
// If we're showing in a timecode, we prefer showing audio in seconds instead
|
||||
if (using_display == Timecode::kTimecodeDropFrame
|
||||
|| using_display == Timecode::kTimecodeNonDropFrame) {
|
||||
using_display = Timecode::kTimecodeSeconds;
|
||||
}
|
||||
|
||||
using_timebase = audio.sample_rate_as_time_base();
|
||||
} else if (sub.is_valid()) {
|
||||
using_timebase = OLIVE_CONFIG("DefaultSequenceFrameRate").value<rational>();
|
||||
}
|
||||
|
||||
using_timebase = audio.sample_rate_as_time_base();
|
||||
} else if (sub.is_valid()) {
|
||||
using_timebase = OLIVE_CONFIG("DefaultSequenceFrameRate").value<rational>();
|
||||
if (!using_timebase.isNull()) {
|
||||
// Return time transformed to timecode
|
||||
return QString::fromStdString(Timecode::time_to_timecode(GetLength(), using_timebase, using_display));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FREQUENCY_RATE:
|
||||
{
|
||||
VideoParams video_stream;
|
||||
|
||||
if (HasEnabledVideoStreams()
|
||||
&& (video_stream = GetFirstEnabledVideoStream()).video_type() != VideoParams::kVideoTypeStill) {
|
||||
// This is a video editor, prioritize video streams
|
||||
return tr("%1 FPS").arg(video_stream.frame_rate().toDouble());
|
||||
} else if (HasEnabledAudioStreams()) {
|
||||
// No video streams, return audio
|
||||
AudioParams audio_stream = GetFirstEnabledAudioStream();
|
||||
return tr("%1 Hz").arg(audio_stream.sample_rate());
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (using_timebase.isNull()) {
|
||||
// No timebase, return null
|
||||
return QString();
|
||||
} else {
|
||||
// Return time transformed to timecode
|
||||
return QString::fromStdString(Timecode::time_to_timecode(GetLength(), using_timebase, using_display));
|
||||
}
|
||||
}
|
||||
|
||||
QString ViewerOutput::rate() const
|
||||
{
|
||||
VideoParams video_stream;
|
||||
|
||||
if (HasEnabledVideoStreams()
|
||||
&& (video_stream = GetFirstEnabledVideoStream()).video_type() != VideoParams::kVideoTypeStill) {
|
||||
// This is a video editor, prioritize video streams
|
||||
return tr("%1 FPS").arg(video_stream.frame_rate().toDouble());
|
||||
} else if (HasEnabledAudioStreams()) {
|
||||
// No video streams, return audio
|
||||
AudioParams audio_stream = GetFirstEnabledAudioStream();
|
||||
return tr("%1 Hz").arg(audio_stream.sample_rate());
|
||||
}
|
||||
|
||||
return QString();
|
||||
return super::data(d);
|
||||
}
|
||||
|
||||
bool ViewerOutput::HasEnabledVideoStreams() const
|
||||
|
||||
@@ -53,8 +53,7 @@ public:
|
||||
virtual QVector<CategoryID> Category() const override;
|
||||
virtual QString Description() const override;
|
||||
|
||||
virtual QString duration() const override;
|
||||
virtual QString rate() const override;
|
||||
virtual QVariant data(const DataType &d) const override;
|
||||
|
||||
void set_default_parameters();
|
||||
|
||||
|
||||
@@ -37,9 +37,13 @@ Folder::Folder()
|
||||
AddInput(kChildInput, NodeValue::kNone, InputFlags(kInputFlagArray | kInputFlagNotKeyframable));
|
||||
}
|
||||
|
||||
QIcon Folder::icon() const
|
||||
QVariant Folder::data(const DataType &d) const
|
||||
{
|
||||
return icon::Folder;
|
||||
if (d == ICON) {
|
||||
return icon::Folder;
|
||||
}
|
||||
|
||||
return super::data(d);
|
||||
}
|
||||
|
||||
void Folder::Retranslate()
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
return tr("Organize several items into a single collection.");
|
||||
}
|
||||
|
||||
virtual QIcon icon() const override;
|
||||
virtual QVariant data(const DataType &d) const override;
|
||||
|
||||
virtual void Retranslate() override;
|
||||
|
||||
|
||||
@@ -203,26 +203,6 @@ const QString &Footage::decoder() const
|
||||
return decoder_;
|
||||
}
|
||||
|
||||
QIcon Footage::icon() const
|
||||
{
|
||||
if (valid_ && GetTotalStreamCount()) {
|
||||
// Prioritize video > audio > image
|
||||
VideoParams s = GetFirstEnabledVideoStream();
|
||||
|
||||
if (s.is_valid() && s.video_type() != VideoParams::kVideoTypeStill) {
|
||||
return icon::Video;
|
||||
} else if (HasEnabledAudioStreams()) {
|
||||
return icon::Audio;
|
||||
} else if (s.is_valid() && s.video_type() == VideoParams::kVideoTypeStill) {
|
||||
return icon::Image;
|
||||
} else if (HasEnabledSubtitleStreams()) {
|
||||
return icon::Subtitles;
|
||||
}
|
||||
}
|
||||
|
||||
return icon::Error;
|
||||
}
|
||||
|
||||
QString Footage::DescribeVideoStream(const VideoParams ¶ms)
|
||||
{
|
||||
if (params.video_type() == VideoParams::kVideoTypeStill) {
|
||||
@@ -375,26 +355,51 @@ void Footage::LoadFinishedEvent()
|
||||
}
|
||||
}
|
||||
|
||||
qint64 Footage::creation_time() const
|
||||
QVariant Footage::data(const DataType &d) const
|
||||
{
|
||||
QFileInfo info(filename());
|
||||
switch (d) {
|
||||
case CREATED_TIME:
|
||||
{
|
||||
QFileInfo info(filename());
|
||||
|
||||
if (info.exists()) {
|
||||
return QtUtils::GetCreationDate(info).toSecsSinceEpoch();
|
||||
if (info.exists()) {
|
||||
return QtUtils::GetCreationDate(info).toSecsSinceEpoch();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MODIFIED_TIME:
|
||||
{
|
||||
QFileInfo info(filename());
|
||||
|
||||
if (info.exists()) {
|
||||
return info.lastModified().toSecsSinceEpoch();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ICON:
|
||||
{
|
||||
if (valid_ && GetTotalStreamCount()) {
|
||||
// Prioritize video > audio > image
|
||||
VideoParams s = GetFirstEnabledVideoStream();
|
||||
|
||||
if (s.is_valid() && s.video_type() != VideoParams::kVideoTypeStill) {
|
||||
return icon::Video;
|
||||
} else if (HasEnabledAudioStreams()) {
|
||||
return icon::Audio;
|
||||
} else if (s.is_valid() && s.video_type() == VideoParams::kVideoTypeStill) {
|
||||
return icon::Image;
|
||||
} else if (HasEnabledSubtitleStreams()) {
|
||||
return icon::Subtitles;
|
||||
}
|
||||
}
|
||||
|
||||
return icon::Error;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
qint64 Footage::mod_time() const
|
||||
{
|
||||
QFileInfo info(filename());
|
||||
|
||||
if (info.exists()) {
|
||||
return info.lastModified().toSecsSinceEpoch();
|
||||
}
|
||||
|
||||
return 0;
|
||||
return super::data(d);
|
||||
}
|
||||
|
||||
void Footage::UpdateTooltip()
|
||||
|
||||
@@ -153,8 +153,6 @@ public:
|
||||
*/
|
||||
const QString& decoder() const;
|
||||
|
||||
virtual QIcon icon() const override;
|
||||
|
||||
virtual bool IsItem() const override
|
||||
{
|
||||
return true;
|
||||
@@ -176,8 +174,7 @@ public:
|
||||
|
||||
virtual void LoadFinishedEvent() override;
|
||||
|
||||
virtual qint64 creation_time() const override;
|
||||
virtual qint64 mod_time() const override;
|
||||
virtual QVariant data(const DataType &d) const override;
|
||||
|
||||
virtual int GetTotalStreamCount() const override { return total_stream_count_; }
|
||||
|
||||
|
||||
@@ -71,9 +71,13 @@ void Sequence::add_default_nodes(MultiUndoCommand* command)
|
||||
}
|
||||
}
|
||||
|
||||
QIcon Sequence::icon() const
|
||||
QVariant Sequence::data(const DataType &d) const
|
||||
{
|
||||
return icon::Sequence;
|
||||
if (d == ICON) {
|
||||
return icon::Sequence;
|
||||
}
|
||||
|
||||
return super::data(d);
|
||||
}
|
||||
|
||||
QVector<Track *> Sequence::GetUnlockedTracks() const
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
|
||||
void add_default_nodes(MultiUndoCommand *command = nullptr);
|
||||
|
||||
virtual QIcon icon() const override;
|
||||
virtual QVariant data(const DataType &d) const override;
|
||||
|
||||
const QVector<Track *> &GetTracks() const
|
||||
{
|
||||
|
||||
@@ -140,13 +140,13 @@ QVariant ProjectViewModel::data(const QModelIndex &index, int role) const
|
||||
case kName:
|
||||
return internal_item->GetLabel();
|
||||
case kDuration:
|
||||
return internal_item->duration();
|
||||
return internal_item->data(Node::DURATION);
|
||||
case kRate:
|
||||
return internal_item->rate();
|
||||
return internal_item->data(Node::FREQUENCY_RATE);
|
||||
case kLastModified:
|
||||
case kCreatedTime:
|
||||
{
|
||||
qint64 using_time = (column_type == kLastModified) ? internal_item->mod_time() : internal_item->creation_time();
|
||||
qint64 using_time = (column_type == kLastModified) ? internal_item->data(Node::MODIFIED_TIME).toLongLong() : internal_item->data(Node::CREATED_TIME).toLongLong();
|
||||
|
||||
if (using_time == 0) {
|
||||
// 0 is the null value, return nothing
|
||||
@@ -178,7 +178,7 @@ QVariant ProjectViewModel::data(const QModelIndex &index, int role) const
|
||||
case Qt::DecorationRole:
|
||||
// If this is the first column, return the Item's icon
|
||||
if (column_type == kName) {
|
||||
return internal_item->icon();
|
||||
return internal_item->data(Node::ICON);
|
||||
}
|
||||
break;
|
||||
case Qt::ToolTipRole:
|
||||
|
||||
Reference in New Issue
Block a user