exportformatcombobox: categorize formats where possible
This commit is contained in:
@@ -20,75 +20,120 @@
|
|||||||
|
|
||||||
#include "exportformatcombobox.h"
|
#include "exportformatcombobox.h"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
#include "ui/icons/icons.h"
|
||||||
|
|
||||||
namespace olive {
|
namespace olive {
|
||||||
|
|
||||||
ExportFormatComboBox::ExportFormatComboBox(Mode mode, QWidget *parent) :
|
ExportFormatComboBox::ExportFormatComboBox(Mode mode, QWidget *parent) :
|
||||||
QComboBox(parent)
|
QComboBox(parent)
|
||||||
{
|
{
|
||||||
|
custom_menu_ = new Menu(this);
|
||||||
|
|
||||||
// Populate combobox formats
|
// Populate combobox formats
|
||||||
for (int i=0; i<ExportFormat::kFormatCount; i++) {
|
switch (mode) {
|
||||||
ExportFormat::Format f = static_cast<ExportFormat::Format>(i);
|
case kShowAllFormats:
|
||||||
|
custom_menu_->addAction(CreateHeader(icon::Video, tr("Video")));
|
||||||
|
PopulateType(Track::kVideo);
|
||||||
|
custom_menu_->addSeparator();
|
||||||
|
|
||||||
switch (mode) {
|
custom_menu_->addAction(CreateHeader(icon::Audio, tr("Audio")));
|
||||||
case kShowAllFormats:
|
PopulateType(Track::kAudio);
|
||||||
break;
|
custom_menu_->addSeparator();
|
||||||
case kShowAudioOnly:
|
|
||||||
if (!ExportFormat::GetVideoCodecs(f).isEmpty()
|
|
||||||
|| !ExportFormat::GetSubtitleCodecs(f).isEmpty()
|
|
||||||
|| ExportFormat::GetAudioCodecs(f).isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case kShowVideoOnly:
|
|
||||||
if (ExportFormat::GetVideoCodecs(f).isEmpty()
|
|
||||||
|| !ExportFormat::GetSubtitleCodecs(f).isEmpty()
|
|
||||||
|| !ExportFormat::GetAudioCodecs(f).isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case kShowSubtitlesOnly:
|
|
||||||
if (!ExportFormat::GetVideoCodecs(f).isEmpty()
|
|
||||||
|| ExportFormat::GetSubtitleCodecs(f).isEmpty()
|
|
||||||
|| !ExportFormat::GetAudioCodecs(f).isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString format_name = ExportFormat::GetName(f);
|
custom_menu_->addAction(CreateHeader(icon::Subtitles, tr("Subtitle")));
|
||||||
|
PopulateType(Track::kSubtitle);
|
||||||
bool inserted = false;
|
break;
|
||||||
|
case kShowAudioOnly:
|
||||||
// Sort formats alphabetically
|
PopulateType(Track::kAudio);
|
||||||
for (int j=0; j<count(); j++) {
|
break;
|
||||||
if (itemText(j) > format_name) {
|
case kShowVideoOnly:
|
||||||
insertItem(j, format_name, i);
|
PopulateType(Track::kVideo);
|
||||||
inserted = true;
|
break;
|
||||||
break;
|
case kShowSubtitlesOnly:
|
||||||
}
|
PopulateType(Track::kSubtitle);
|
||||||
}
|
break;
|
||||||
|
|
||||||
if (!inserted) {
|
|
||||||
addItem(format_name, i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(this, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &ExportFormatComboBox::HandleIndexChange);
|
connect(custom_menu_, &Menu::triggered, this, &ExportFormatComboBox::HandleIndexChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportFormatComboBox::showPopup()
|
||||||
|
{
|
||||||
|
custom_menu_->setMinimumWidth(this->width());
|
||||||
|
custom_menu_->exec(mapToGlobal(QPoint(0, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportFormatComboBox::SetFormat(ExportFormat::Format fmt)
|
void ExportFormatComboBox::SetFormat(ExportFormat::Format fmt)
|
||||||
{
|
{
|
||||||
for (int i=0; i<count(); i++) {
|
current_ = fmt;
|
||||||
if (itemData(i).toInt() == fmt) {
|
clear();
|
||||||
setCurrentIndex(i);
|
addItem(ExportFormat::GetName(current_));
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
void ExportFormatComboBox::HandleIndexChange(QAction *a)
|
||||||
|
{
|
||||||
|
ExportFormat::Format f = static_cast<ExportFormat::Format>(a->data().toInt());
|
||||||
|
SetFormat(f);
|
||||||
|
emit FormatChanged(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportFormatComboBox::PopulateType(Track::Type type)
|
||||||
|
{
|
||||||
|
for (int i=0; i<ExportFormat::kFormatCount; i++) {
|
||||||
|
ExportFormat::Format f = static_cast<ExportFormat::Format>(i);
|
||||||
|
|
||||||
|
if (type == Track::kVideo
|
||||||
|
&& !ExportFormat::GetVideoCodecs(f).isEmpty()) {
|
||||||
|
// Do nothing
|
||||||
|
} else if (type == Track::kAudio
|
||||||
|
&& ExportFormat::GetVideoCodecs(f).isEmpty()
|
||||||
|
&& !ExportFormat::GetAudioCodecs(f).isEmpty()) {
|
||||||
|
// Do nothing
|
||||||
|
} else if (type == Track::kSubtitle
|
||||||
|
&& ExportFormat::GetVideoCodecs(f).isEmpty()
|
||||||
|
&& ExportFormat::GetAudioCodecs(f).isEmpty()
|
||||||
|
&& !ExportFormat::GetSubtitleCodecs(f).isEmpty()) {
|
||||||
|
// Do nothing
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString format_name = ExportFormat::GetName(f);
|
||||||
|
|
||||||
|
QAction *a = custom_menu_->addAction(format_name);
|
||||||
|
a->setData(i);
|
||||||
|
a->setIconVisibleInMenu(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportFormatComboBox::HandleIndexChange(int index)
|
QWidgetAction *ExportFormatComboBox::CreateHeader(const QIcon &icon, const QString &title)
|
||||||
{
|
{
|
||||||
emit FormatChanged(static_cast<ExportFormat::Format>(itemData(index).toInt()));
|
QWidgetAction *a = new QWidgetAction(this);
|
||||||
|
|
||||||
|
QWidget *w = new QWidget();
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout(w);
|
||||||
|
|
||||||
|
QLabel *icon_lbl = new QLabel();
|
||||||
|
|
||||||
|
QLabel *text_lbl = new QLabel(title);
|
||||||
|
text_lbl->setAlignment(Qt::AlignCenter);
|
||||||
|
QFont f = text_lbl->font();
|
||||||
|
f.setWeight(QFont::Bold);
|
||||||
|
text_lbl->setFont(f);
|
||||||
|
|
||||||
|
icon_lbl->setPixmap(icon.pixmap(text_lbl->sizeHint()));
|
||||||
|
|
||||||
|
layout->addStretch();
|
||||||
|
layout->addWidget(icon_lbl);
|
||||||
|
layout->addWidget(text_lbl);
|
||||||
|
layout->addStretch();
|
||||||
|
|
||||||
|
a->setDefaultWidget(w);
|
||||||
|
a->setEnabled(false);
|
||||||
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,11 @@
|
|||||||
#define EXPORTFORMATCOMBOBOX_H
|
#define EXPORTFORMATCOMBOBOX_H
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
#include <QWidgetAction>
|
||||||
|
|
||||||
#include "codec/exportformat.h"
|
#include "codec/exportformat.h"
|
||||||
|
#include "node/output/track/track.h"
|
||||||
|
#include "widget/menu/menu.h"
|
||||||
|
|
||||||
namespace olive {
|
namespace olive {
|
||||||
|
|
||||||
@@ -45,9 +48,11 @@ public:
|
|||||||
|
|
||||||
ExportFormat::Format GetFormat() const
|
ExportFormat::Format GetFormat() const
|
||||||
{
|
{
|
||||||
return static_cast<ExportFormat::Format>(currentData().toInt());
|
return current_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void showPopup();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void FormatChanged(ExportFormat::Format fmt);
|
void FormatChanged(ExportFormat::Format fmt);
|
||||||
|
|
||||||
@@ -55,7 +60,16 @@ public slots:
|
|||||||
void SetFormat(ExportFormat::Format fmt);
|
void SetFormat(ExportFormat::Format fmt);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void HandleIndexChange(int index);
|
void HandleIndexChange(QAction *a);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void PopulateType(Track::Type type);
|
||||||
|
|
||||||
|
QWidgetAction *CreateHeader(const QIcon &icon, const QString &title);
|
||||||
|
|
||||||
|
Menu *custom_menu_;
|
||||||
|
|
||||||
|
ExportFormat::Format current_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user