-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
676 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
#include "audioencodermodel.hpp" | ||
|
||
class AudioEncoderModel::AudioEncoderModelPrivate | ||
{ | ||
public: | ||
explicit AudioEncoderModelPrivate(AudioEncoderModel *q) | ||
: q_ptr(q) | ||
{ | ||
auto metaEnums = QMetaEnum::fromType<Property>(); | ||
for (int i = 0; i < metaEnums.keyCount(); i++) { | ||
headers.append(metaEnums.key(i)); | ||
} | ||
} | ||
|
||
AudioEncoderModel *q_ptr; | ||
|
||
Ffmpeg::EncodeContexts encodeContexts; | ||
QStringList headers; | ||
}; | ||
|
||
AudioEncoderModel::AudioEncoderModel(QObject *parent) | ||
: QAbstractTableModel{parent} | ||
, d_ptr(new AudioEncoderModelPrivate(this)) | ||
{} | ||
|
||
AudioEncoderModel::~AudioEncoderModel() = default; | ||
|
||
auto AudioEncoderModel::rowCount(const QModelIndex &parent) const -> int | ||
{ | ||
Q_UNUSED(parent); | ||
return d_ptr->encodeContexts.size(); | ||
} | ||
|
||
auto AudioEncoderModel::columnCount(const QModelIndex &parent) const -> int | ||
{ | ||
Q_UNUSED(parent); | ||
return d_ptr->headers.size(); | ||
} | ||
|
||
auto AudioEncoderModel::data(const QModelIndex &index, int role) const -> QVariant | ||
{ | ||
if (!index.isValid()) { | ||
return {}; | ||
} | ||
|
||
auto row = index.row(); | ||
auto col = index.column(); | ||
|
||
const auto &data = d_ptr->encodeContexts.at(row); | ||
switch (role) { | ||
case Qt::TextAlignmentRole: return Qt::AlignCenter; | ||
case Qt::WhatsThisRole: | ||
case Qt::ToolTipRole: | ||
case Qt::DisplayRole: | ||
case Qt::EditRole: { //双击为空需添加 | ||
switch (col) { | ||
case Property::ID: return row; | ||
case Property::Encoder: return data.codecInfo().displayName; | ||
case Property::ChannelLayout: return data.chLayout().channelName; | ||
case Property::Bitrate: return data.bitrate; | ||
case Property::Crf: return data.crf; | ||
case Property::Profile: { | ||
auto profile = data.profile(); | ||
if (profile.profile >= 0) { | ||
return profile.name; | ||
} | ||
return {}; | ||
} | ||
default: break; | ||
} | ||
break; | ||
case Qt::UserRole: return QVariant::fromValue(data); | ||
} | ||
default: break; | ||
} | ||
return {}; | ||
} | ||
|
||
auto AudioEncoderModel::setData(const QModelIndex &index, const QVariant &value, int role) -> bool | ||
{ | ||
if (!index.isValid()) { | ||
return false; | ||
} | ||
|
||
auto row = index.row(); | ||
auto col = index.column(); | ||
|
||
auto &data = d_ptr->encodeContexts[row]; | ||
switch (role) { | ||
case Qt::EditRole: { | ||
switch (col) { | ||
case Property::Encoder: { | ||
auto codec = value.value<Ffmpeg::CodecInfo>(); | ||
if (data.codecInfo() != codec) { | ||
data.setEncoderName(codec.name); | ||
emit dataChanged(index, index); | ||
} | ||
} break; | ||
case Property::ChannelLayout: { | ||
auto channel = static_cast<AVChannel>(value.toLongLong()); | ||
if (data.chLayout().channel != channel) { | ||
data.setChannel(channel); | ||
emit dataChanged(index, index); | ||
} | ||
} break; | ||
case Property::Bitrate: | ||
data.maxBitrate = data.minBitrate = data.bitrate = value.toInt(); | ||
break; | ||
case Property::Crf: data.crf = value.toInt(); | ||
case Property::Profile: { | ||
auto profile = value.toInt(); | ||
if (data.profile().profile != profile) { | ||
data.setProfile(profile); | ||
emit dataChanged(index, index); | ||
} | ||
} break; | ||
default: break; | ||
} | ||
} break; | ||
default: break; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
auto AudioEncoderModel::flags(const QModelIndex &index) const -> Qt::ItemFlags | ||
{ | ||
if (!index.isValid()) { | ||
return {}; | ||
} | ||
auto flags = QAbstractTableModel::flags(index); | ||
if (index.column() != Property::ID) { | ||
flags |= Qt::ItemIsEditable; | ||
} | ||
return flags; | ||
} | ||
|
||
auto AudioEncoderModel::headerData(int section, Qt::Orientation orientation, int role) const | ||
-> QVariant | ||
{ | ||
if (section < 0 || section >= d_ptr->headers.size() || orientation != Qt::Horizontal) { | ||
return {}; | ||
} | ||
switch (role) { | ||
case Qt::TextAlignmentRole: return Qt::AlignCenter; | ||
case Qt::WhatsThisRole: | ||
case Qt::ToolTipRole: | ||
case Qt::DisplayRole: return d_ptr->headers.at(section); | ||
default: break; | ||
} | ||
return {}; | ||
} | ||
|
||
void AudioEncoderModel::setDatas(const Ffmpeg::EncodeContexts &encodeContexts) | ||
{ | ||
beginResetModel(); | ||
d_ptr->encodeContexts = encodeContexts; | ||
endResetModel(); | ||
} | ||
|
||
Ffmpeg::EncodeContexts AudioEncoderModel::datas() const | ||
{ | ||
return d_ptr->encodeContexts; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef AUDIOENCODERMODEL_HPP | ||
#define AUDIOENCODERMODEL_HPP | ||
|
||
#include <ffmpeg/encodecontext.hpp> | ||
|
||
#include <QAbstractTableModel> | ||
|
||
class AudioEncoderModel : public QAbstractTableModel | ||
{ | ||
Q_OBJECT | ||
public: | ||
enum Property { ID, Encoder, ChannelLayout, Bitrate, Crf, Profile }; | ||
Q_ENUM(Property); | ||
|
||
explicit AudioEncoderModel(QObject *parent = nullptr); | ||
~AudioEncoderModel() override; | ||
|
||
[[nodiscard]] auto rowCount(const QModelIndex &parent = QModelIndex()) const -> int override; | ||
[[nodiscard]] auto columnCount(const QModelIndex &parent = QModelIndex()) const -> int override; | ||
|
||
[[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
auto setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) | ||
-> bool override; | ||
|
||
[[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override; | ||
|
||
[[nodiscard]] QVariant headerData(int section, | ||
Qt::Orientation orientation, | ||
int role = Qt::DisplayRole) const override; | ||
|
||
void setDatas(const Ffmpeg::EncodeContexts &encodeContexts); | ||
Ffmpeg::EncodeContexts datas() const; | ||
|
||
private: | ||
class AudioEncoderModelPrivate; | ||
QScopedPointer<AudioEncoderModelPrivate> d_ptr; | ||
}; | ||
|
||
#endif // AUDIOENCODERMODEL_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "audioencodertableview.hpp" | ||
#include "audioencodermodel.hpp" | ||
#include "styleditemdelegate.hpp" | ||
|
||
#include <QHeaderView> | ||
|
||
class AudioEncoderTableView::AudioEncoderTableViewPrivate | ||
{ | ||
public: | ||
explicit AudioEncoderTableViewPrivate(AudioEncoderTableView *q) | ||
: q_ptr(q) | ||
{ | ||
model = new AudioEncoderModel(q_ptr); | ||
} | ||
|
||
AudioEncoderTableView *q_ptr; | ||
|
||
AudioEncoderModel *model; | ||
}; | ||
|
||
AudioEncoderTableView::AudioEncoderTableView(QWidget *parent) | ||
: QTableView{parent} | ||
, d_ptr(new AudioEncoderTableViewPrivate(this)) | ||
{ | ||
setupUI(); | ||
} | ||
|
||
AudioEncoderTableView::~AudioEncoderTableView() {} | ||
|
||
void AudioEncoderTableView::setDatas(const Ffmpeg::EncodeContexts &encodeContexts) | ||
{ | ||
d_ptr->model->setDatas(encodeContexts); | ||
} | ||
|
||
Ffmpeg::EncodeContexts AudioEncoderTableView::datas() const | ||
{ | ||
return d_ptr->model->datas(); | ||
} | ||
|
||
void AudioEncoderTableView::setupUI() | ||
{ | ||
setModel(d_ptr->model); | ||
|
||
setShowGrid(true); | ||
setWordWrap(false); | ||
setAlternatingRowColors(true); | ||
verticalHeader()->setVisible(false); | ||
verticalHeader()->setDefaultSectionSize(35); | ||
horizontalHeader()->setStretchLastSection(true); | ||
horizontalHeader()->setDefaultSectionSize(120); | ||
horizontalHeader()->setMinimumSectionSize(60); | ||
horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); | ||
horizontalHeader()->setSectionResizeMode(AudioEncoderModel::Property::Encoder, | ||
QHeaderView::Stretch); | ||
setIconSize(QSize(20, 20)); | ||
|
||
setItemDelegateForColumn(AudioEncoderModel::Property::Encoder, new AudioEncoderDelegate(this)); | ||
setItemDelegateForColumn(AudioEncoderModel::Property::ChannelLayout, | ||
new ChannelLayoutDelegate(this)); | ||
setItemDelegateForColumn(AudioEncoderModel::Property::Profile, new ProfileDelegate(this)); | ||
|
||
setColumnWidth(AudioEncoderModel::Property::ID, 50); | ||
setColumnWidth(AudioEncoderModel::Property::ChannelLayout, 100); | ||
setColumnWidth(AudioEncoderModel::Property::Bitrate, 100); | ||
setColumnWidth(AudioEncoderModel::Property::Crf, 50); | ||
setColumnWidth(AudioEncoderModel::Property::Profile, 100); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef AUDIOENCODERTABLEVIEW_HPP | ||
#define AUDIOENCODERTABLEVIEW_HPP | ||
|
||
#include <ffmpeg/encodecontext.hpp> | ||
|
||
#include <QTableView> | ||
|
||
class AudioEncoderTableView : public QTableView | ||
{ | ||
public: | ||
explicit AudioEncoderTableView(QWidget *parent = nullptr); | ||
~AudioEncoderTableView() override; | ||
|
||
void setDatas(const Ffmpeg::EncodeContexts &encodeContexts); | ||
Ffmpeg::EncodeContexts datas() const; | ||
|
||
private: | ||
void setupUI(); | ||
|
||
class AudioEncoderTableViewPrivate; | ||
QScopedPointer<AudioEncoderTableViewPrivate> d_ptr; | ||
}; | ||
|
||
#endif // AUDIOENCODERTABLEVIEW_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.