UI: Separate delegate class into header file
parent
8d3ee5708f
commit
0e2fe10595
|
@ -57,216 +57,206 @@ enum RemuxEntryRole {
|
|||
Delegate - Presents cells in the grid.
|
||||
**********************************************************/
|
||||
|
||||
class RemuxEntryPathItemDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
RemuxEntryPathItemDelegate::RemuxEntryPathItemDelegate(bool isOutput,
|
||||
const QString &defaultPath)
|
||||
: QStyledItemDelegate(),
|
||||
isOutput(isOutput),
|
||||
defaultPath(defaultPath)
|
||||
{
|
||||
}
|
||||
|
||||
RemuxEntryPathItemDelegate(bool isOutput, const QString &defaultPath)
|
||||
: QStyledItemDelegate(),
|
||||
isOutput(isOutput),
|
||||
defaultPath(defaultPath)
|
||||
{
|
||||
}
|
||||
QWidget *RemuxEntryPathItemDelegate::createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem & /* option */,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
RemuxEntryState state = index.model()
|
||||
->index(index.row(), RemuxEntryColumn::State)
|
||||
.data(RemuxEntryRole::EntryStateRole)
|
||||
.value<RemuxEntryState>();
|
||||
if (state == RemuxEntryState::Pending ||
|
||||
state == RemuxEntryState::InProgress) {
|
||||
// Never allow modification of rows that are
|
||||
// in progress.
|
||||
return Q_NULLPTR;
|
||||
} else if (isOutput && state != RemuxEntryState::Ready) {
|
||||
// Do not allow modification of output rows
|
||||
// that aren't associated with a valid input.
|
||||
return Q_NULLPTR;
|
||||
} else if (!isOutput && state == RemuxEntryState::Complete) {
|
||||
// Don't allow modification of rows that are
|
||||
// already complete.
|
||||
return Q_NULLPTR;
|
||||
} else {
|
||||
QSizePolicy buttonSizePolicy(
|
||||
QSizePolicy::Policy::Minimum,
|
||||
QSizePolicy::Policy::Expanding,
|
||||
QSizePolicy::ControlType::PushButton);
|
||||
|
||||
virtual QWidget *createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem & /* option */,
|
||||
const QModelIndex &index) const override
|
||||
{
|
||||
RemuxEntryState state = index.model()
|
||||
->index(index.row(), RemuxEntryColumn::State)
|
||||
.data(RemuxEntryRole::EntryStateRole)
|
||||
.value<RemuxEntryState>();
|
||||
if (state == RemuxEntryState::Pending ||
|
||||
state == RemuxEntryState::InProgress) {
|
||||
// Never allow modification of rows that are
|
||||
// in progress.
|
||||
return Q_NULLPTR;
|
||||
} else if (isOutput && state != RemuxEntryState::Ready) {
|
||||
// Do not allow modification of output rows
|
||||
// that aren't associated with a valid input.
|
||||
return Q_NULLPTR;
|
||||
} else if (!isOutput && state == RemuxEntryState::Complete) {
|
||||
// Don't allow modification of rows that are
|
||||
// already complete.
|
||||
return Q_NULLPTR;
|
||||
} else {
|
||||
QSizePolicy buttonSizePolicy(
|
||||
QSizePolicy::Policy::Minimum,
|
||||
QSizePolicy::Policy::Expanding,
|
||||
QSizePolicy::ControlType::PushButton);
|
||||
QWidget *container = new QWidget(parent);
|
||||
|
||||
QWidget *container = new QWidget(parent);
|
||||
auto browseCallback = [this, container]()
|
||||
{
|
||||
const_cast<RemuxEntryPathItemDelegate *>(this)
|
||||
->handleBrowse(container);
|
||||
};
|
||||
|
||||
auto browseCallback = [this, container]()
|
||||
{
|
||||
const_cast<RemuxEntryPathItemDelegate *>(this)
|
||||
->handleBrowse(container);
|
||||
};
|
||||
auto clearCallback = [this, container]()
|
||||
{
|
||||
const_cast<RemuxEntryPathItemDelegate *>(this)
|
||||
->handleClear(container);
|
||||
};
|
||||
|
||||
auto clearCallback = [this, container]()
|
||||
{
|
||||
const_cast<RemuxEntryPathItemDelegate *>(this)
|
||||
->handleClear(container);
|
||||
};
|
||||
QHBoxLayout *layout = new QHBoxLayout();
|
||||
layout->setMargin(0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout();
|
||||
layout->setMargin(0);
|
||||
layout->setSpacing(0);
|
||||
QLineEdit *text = new QLineEdit();
|
||||
text->setObjectName(QStringLiteral("text"));
|
||||
text->setSizePolicy(QSizePolicy(
|
||||
QSizePolicy::Policy::Expanding,
|
||||
QSizePolicy::Policy::Expanding,
|
||||
QSizePolicy::ControlType::LineEdit));
|
||||
layout->addWidget(text);
|
||||
|
||||
QLineEdit *text = new QLineEdit();
|
||||
text->setObjectName(QStringLiteral("text"));
|
||||
text->setSizePolicy(QSizePolicy(
|
||||
QSizePolicy::Policy::Expanding,
|
||||
QSizePolicy::Policy::Expanding,
|
||||
QSizePolicy::ControlType::LineEdit));
|
||||
layout->addWidget(text);
|
||||
QToolButton *browseButton = new QToolButton();
|
||||
browseButton->setText("...");
|
||||
browseButton->setSizePolicy(buttonSizePolicy);
|
||||
layout->addWidget(browseButton);
|
||||
|
||||
QToolButton *browseButton = new QToolButton();
|
||||
browseButton->setText("...");
|
||||
browseButton->setSizePolicy(buttonSizePolicy);
|
||||
layout->addWidget(browseButton);
|
||||
container->connect(browseButton, &QToolButton::clicked,
|
||||
browseCallback);
|
||||
|
||||
container->connect(browseButton, &QToolButton::clicked,
|
||||
browseCallback);
|
||||
// The "clear" button is not shown in output cells
|
||||
// or the insertion point's input cell.
|
||||
if (!isOutput && state != RemuxEntryState::Empty) {
|
||||
QToolButton *clearButton = new QToolButton();
|
||||
clearButton->setText("X");
|
||||
clearButton->setSizePolicy(buttonSizePolicy);
|
||||
layout->addWidget(clearButton);
|
||||
|
||||
// The "clear" button is not shown in output cells
|
||||
// or the insertion point's input cell.
|
||||
if (!isOutput && state != RemuxEntryState::Empty) {
|
||||
QToolButton *clearButton = new QToolButton();
|
||||
clearButton->setText("X");
|
||||
clearButton->setSizePolicy(buttonSizePolicy);
|
||||
layout->addWidget(clearButton);
|
||||
|
||||
container->connect(clearButton,
|
||||
&QToolButton::clicked,
|
||||
clearCallback);
|
||||
}
|
||||
|
||||
container->setLayout(layout);
|
||||
container->setFocusProxy(text);
|
||||
|
||||
return container;
|
||||
container->connect(clearButton,
|
||||
&QToolButton::clicked,
|
||||
clearCallback);
|
||||
}
|
||||
|
||||
container->setLayout(layout);
|
||||
container->setFocusProxy(text);
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void setEditorData(QWidget *editor, const QModelIndex &index)
|
||||
const override
|
||||
{
|
||||
QLineEdit *text = editor->findChild<QLineEdit *>();
|
||||
text->setText(index.data().toString());
|
||||
|
||||
editor->setProperty(PATH_LIST_PROP, QVariant());
|
||||
}
|
||||
|
||||
virtual void setModelData(QWidget *editor,
|
||||
QAbstractItemModel *model,
|
||||
const QModelIndex &index) const override
|
||||
{
|
||||
// We use the PATH_LIST_PROP property to pass a list of
|
||||
// path strings from the editor widget into the model's
|
||||
// NewPathsToProcessRole. This is only used when paths
|
||||
// are selected through the "browse" or "delete" buttons
|
||||
// in the editor. If the user enters new text in the
|
||||
// text box, we simply pass that text on to the model
|
||||
// as normal text data in the default role.
|
||||
QVariant pathListProp = editor->property(PATH_LIST_PROP);
|
||||
if (pathListProp.isValid()) {
|
||||
QStringList list = editor->property(PATH_LIST_PROP)
|
||||
.toStringList();
|
||||
if (isOutput) {
|
||||
if (list.size() > 0)
|
||||
model->setData(index, list);
|
||||
} else
|
||||
model->setData(index, list,
|
||||
RemuxEntryRole::NewPathsToProcessRole);
|
||||
} else {
|
||||
QLineEdit *lineEdit = editor->findChild<QLineEdit *>();
|
||||
model->setData(index, lineEdit->text());
|
||||
}
|
||||
}
|
||||
|
||||
virtual void paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override
|
||||
{
|
||||
RemuxEntryState state = index.model()
|
||||
->index(index.row(), RemuxEntryColumn::State)
|
||||
.data(RemuxEntryRole::EntryStateRole)
|
||||
.value<RemuxEntryState>();
|
||||
|
||||
QStyleOptionViewItem localOption = option;
|
||||
initStyleOption(&localOption, index);
|
||||
void RemuxEntryPathItemDelegate::setEditorData(QWidget *editor,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QLineEdit *text = editor->findChild<QLineEdit *>();
|
||||
text->setText(index.data().toString());
|
||||
editor->setProperty(PATH_LIST_PROP, QVariant());
|
||||
}
|
||||
|
||||
void RemuxEntryPathItemDelegate::setModelData(QWidget *editor,
|
||||
QAbstractItemModel *model,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
// We use the PATH_LIST_PROP property to pass a list of
|
||||
// path strings from the editor widget into the model's
|
||||
// NewPathsToProcessRole. This is only used when paths
|
||||
// are selected through the "browse" or "delete" buttons
|
||||
// in the editor. If the user enters new text in the
|
||||
// text box, we simply pass that text on to the model
|
||||
// as normal text data in the default role.
|
||||
QVariant pathListProp = editor->property(PATH_LIST_PROP);
|
||||
if (pathListProp.isValid()) {
|
||||
QStringList list = editor->property(PATH_LIST_PROP)
|
||||
.toStringList();
|
||||
if (isOutput) {
|
||||
if (state != Ready) {
|
||||
QColor background = localOption.palette
|
||||
.color(QPalette::ColorGroup::Disabled,
|
||||
QPalette::ColorRole::Background);
|
||||
if (list.size() > 0)
|
||||
model->setData(index, list);
|
||||
} else
|
||||
model->setData(index, list,
|
||||
RemuxEntryRole::NewPathsToProcessRole);
|
||||
} else {
|
||||
QLineEdit *lineEdit = editor->findChild<QLineEdit *>();
|
||||
model->setData(index, lineEdit->text());
|
||||
}
|
||||
}
|
||||
|
||||
localOption.backgroundBrush = QBrush(background);
|
||||
}
|
||||
void RemuxEntryPathItemDelegate::paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
RemuxEntryState state = index.model()
|
||||
->index(index.row(), RemuxEntryColumn::State)
|
||||
.data(RemuxEntryRole::EntryStateRole)
|
||||
.value<RemuxEntryState>();
|
||||
|
||||
QStyleOptionViewItem localOption = option;
|
||||
initStyleOption(&localOption, index);
|
||||
|
||||
if (isOutput) {
|
||||
if (state != Ready) {
|
||||
QColor background = localOption.palette
|
||||
.color(QPalette::ColorGroup::Disabled,
|
||||
QPalette::ColorRole::Background);
|
||||
|
||||
localOption.backgroundBrush = QBrush(background);
|
||||
}
|
||||
|
||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem,
|
||||
&localOption, painter);
|
||||
}
|
||||
|
||||
private:
|
||||
bool isOutput;
|
||||
QString defaultPath;
|
||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem,
|
||||
&localOption, painter);
|
||||
}
|
||||
|
||||
const char *PATH_LIST_PROP = "pathList";
|
||||
void RemuxEntryPathItemDelegate::handleBrowse(QWidget *container)
|
||||
{
|
||||
QString OutputPattern =
|
||||
"(*.mp4 *.flv *.mov *.mkv *.ts *.m3u8)";
|
||||
QString InputPattern =
|
||||
"(*.flv *.mov *.mkv *.ts *.m3u8)";
|
||||
|
||||
void handleBrowse(QWidget *container)
|
||||
{
|
||||
QString OutputPattern =
|
||||
"(*.mp4 *.flv *.mov *.mkv *.ts *.m3u8)";
|
||||
QString InputPattern =
|
||||
"(*.flv *.mov *.mkv *.ts *.m3u8)";
|
||||
QLineEdit *text = container->findChild<QLineEdit *>();
|
||||
|
||||
QLineEdit *text = container->findChild<QLineEdit *>();
|
||||
QString currentPath = text->text();
|
||||
if (currentPath.isEmpty())
|
||||
currentPath = defaultPath;
|
||||
|
||||
QString currentPath = text->text();
|
||||
if (currentPath.isEmpty())
|
||||
currentPath = defaultPath;
|
||||
bool isSet = false;
|
||||
if (isOutput) {
|
||||
QString newPath = QFileDialog::getSaveFileName(
|
||||
container, QTStr("Remux.SelectTarget"),
|
||||
currentPath, OutputPattern);
|
||||
|
||||
bool isSet = false;
|
||||
if (isOutput) {
|
||||
QString newPath = QFileDialog::getSaveFileName(
|
||||
container, QTStr("Remux.SelectTarget"),
|
||||
currentPath, OutputPattern);
|
||||
|
||||
if (!newPath.isEmpty()) {
|
||||
container->setProperty(PATH_LIST_PROP,
|
||||
QStringList() << newPath);
|
||||
isSet = true;
|
||||
}
|
||||
} else {
|
||||
QStringList paths = QFileDialog::getOpenFileNames(
|
||||
container,
|
||||
QTStr("Remux.SelectRecording"),
|
||||
currentPath,
|
||||
QTStr("Remux.OBSRecording")
|
||||
+ QString(" ") + InputPattern);
|
||||
|
||||
if (!paths.empty()) {
|
||||
container->setProperty(PATH_LIST_PROP, paths);
|
||||
isSet = true;
|
||||
}
|
||||
if (!newPath.isEmpty()) {
|
||||
container->setProperty(PATH_LIST_PROP,
|
||||
QStringList() << newPath);
|
||||
isSet = true;
|
||||
}
|
||||
} else {
|
||||
QStringList paths = QFileDialog::getOpenFileNames(
|
||||
container,
|
||||
QTStr("Remux.SelectRecording"),
|
||||
currentPath,
|
||||
QTStr("Remux.OBSRecording")
|
||||
+ QString(" ") + InputPattern);
|
||||
|
||||
if (isSet)
|
||||
emit commitData(container);
|
||||
if (!paths.empty()) {
|
||||
container->setProperty(PATH_LIST_PROP, paths);
|
||||
isSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
void handleClear(QWidget *container)
|
||||
{
|
||||
// An empty string list will indicate that the entry is being
|
||||
// blanked and should be deleted.
|
||||
container->setProperty(PATH_LIST_PROP, QStringList());
|
||||
|
||||
if (isSet)
|
||||
emit commitData(container);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void RemuxEntryPathItemDelegate::handleClear(QWidget *container)
|
||||
{
|
||||
// An empty string list will indicate that the entry is being
|
||||
// blanked and should be deleted.
|
||||
container->setProperty(PATH_LIST_PROP, QStringList());
|
||||
|
||||
emit commitData(container);
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************
|
||||
Model - Manages the queue's data
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QMutex>
|
||||
#include <QPointer>
|
||||
#include <QThread>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <memory>
|
||||
#include "ui_OBSRemux.h"
|
||||
|
||||
|
@ -160,3 +161,32 @@ signals:
|
|||
|
||||
friend class OBSRemux;
|
||||
};
|
||||
|
||||
class RemuxEntryPathItemDelegate : public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RemuxEntryPathItemDelegate(bool isOutput, const QString &defaultPath);
|
||||
|
||||
virtual QWidget *createEditor(QWidget *parent,
|
||||
const QStyleOptionViewItem & /* option */,
|
||||
const QModelIndex &index) const override;
|
||||
|
||||
virtual void setEditorData(QWidget *editor, const QModelIndex &index)
|
||||
const override;
|
||||
virtual void setModelData(QWidget *editor,
|
||||
QAbstractItemModel *model,
|
||||
const QModelIndex &index) const override;
|
||||
virtual void paint(QPainter *painter,
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
|
||||
private:
|
||||
bool isOutput;
|
||||
QString defaultPath;
|
||||
const char *PATH_LIST_PROP = "pathList";
|
||||
|
||||
void handleBrowse(QWidget *container);
|
||||
void handleClear(QWidget *container);
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue