Commit 0ca9208a authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

cleanup: improve code handling timeline preview selection

parent 8d3f4583
......@@ -5,11 +5,13 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "encodingprofilesdialog.h"
#include "core.h"
#include "kdenlivesettings.h"
#include "profiles/profilemodel.hpp"
#include "profiles/profilerepository.hpp"
#include "klocalizedstring.h"
#include <KMessageWidget>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QStandardItemModel>
......@@ -185,13 +187,13 @@ void EncodingProfilesDialog::slotEditProfile()
}
EncodingProfilesChooser::EncodingProfilesChooser(QWidget *parent, EncodingProfilesManager::ProfileType type, bool showAutoItem, const QString &configName,
const QString &selectByValue)
bool native)
: QWidget(parent)
, m_type(type)
, m_showAutoItem(showAutoItem)
{
QVBoxLayout *grid = new QVBoxLayout(this);
grid->setContentsMargins(0, 0, 0, 0);
QVBoxLayout *verticalLayout = new QVBoxLayout(this);
verticalLayout->setContentsMargins(0, 0, 0, 0);
m_profilesCombo = new QComboBox(this);
if (!configName.isEmpty()) {
m_profilesCombo->setObjectName(QStringLiteral("kcfg_%1").arg(configName));
......@@ -213,25 +215,25 @@ EncodingProfilesChooser::EncodingProfilesChooser(QWidget *parent, EncodingProfil
hor->addWidget(m_profilesCombo);
hor->addWidget(buttonConfigure);
hor->addWidget(buttonInfo);
grid->addLayout(hor);
grid->addWidget(m_info);
// Message widget
m_messageWidget = new KMessageWidget(this);
m_messageWidget->setWordWrap(true);
m_messageWidget->setCloseButtonVisible(true);
verticalLayout->addLayout(hor);
verticalLayout->addWidget(m_info);
verticalLayout->addWidget(m_messageWidget);
m_info->setVisible(false);
m_messageWidget->hide();
connect(buttonConfigure, &QAbstractButton::clicked, this, &EncodingProfilesChooser::slotManageEncodingProfile);
connect(buttonInfo, &QAbstractButton::clicked, m_info, &QWidget::setVisible);
connect(m_profilesCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &EncodingProfilesChooser::slotUpdateProfile);
loadEncodingProfiles();
if (!configName.isEmpty()) {
KConfigGroup resourceConfig(KSharedConfig::openConfig(), "project");
int ix = resourceConfig.readEntry(configName).toInt();
m_profilesCombo->setCurrentIndex(ix);
slotUpdateProfile(ix);
} else if (!selectByValue.isEmpty()) {
int ix = m_profilesCombo->findData(selectByValue);
if (ix == -1) {
m_profilesCombo->addItem(i18n("Current Settings"), selectByValue);
ix = m_profilesCombo->findData(selectByValue);
}
if (ix > -1) {
if (native) {
loadEncodingProfiles();
if (!configName.isEmpty()) {
KConfigGroup resourceConfig(KSharedConfig::openConfig(), "project");
int ix = resourceConfig.readEntry(configName).toInt();
m_profilesCombo->setCurrentIndex(ix);
slotUpdateProfile(ix);
}
......@@ -245,11 +247,12 @@ void EncodingProfilesChooser::slotManageEncodingProfile()
dia->exec();
delete dia;
loadEncodingProfiles();
filterPreviewProfiles(pCore->getCurrentProfilePath());
}
void EncodingProfilesChooser::loadEncodingProfiles()
{
m_profilesCombo->blockSignals(true);
QSignalBlocker bk(m_profilesCombo);
QString currentItem = m_profilesCombo->currentText();
m_profilesCombo->clear();
if (m_showAutoItem) {
......@@ -267,20 +270,106 @@ void EncodingProfilesChooser::loadEncodingProfiles()
while (i.hasNext()) {
i.next();
if (!i.key().isEmpty()) {
if (m_type == EncodingProfilesManager::TimelinePreview) {
// We filter out incompatible profiles
if (i.value().contains(QLatin1String("nvenc"))) {
if (KdenliveSettings::nvencEnabled()) {
m_profilesCombo->addItem(QIcon::fromTheme(QStringLiteral("speedometer")), i.key(), i.value());
}
continue;
m_profilesCombo->addItem(i.key(), i.value());
}
}
if (!currentItem.isEmpty()) {
int ix = m_profilesCombo->findText(currentItem);
m_profilesCombo->setCurrentIndex(ix);
slotUpdateProfile(ix);
}
}
QString EncodingProfilesChooser::currentExtension()
{
QString profilestr = m_profilesCombo->currentData().toString();
if (profilestr.isEmpty()) {
return {};
}
return profilestr.section(QLatin1Char(';'), 1, 1);
}
QString EncodingProfilesChooser::currentParams()
{
QString profilestr = m_profilesCombo->currentData().toString();
if (profilestr.isEmpty()) {
return {};
}
return profilestr.section(QLatin1Char(';'), 0, 0);
}
void EncodingProfilesChooser::slotUpdateProfile(int ix)
{
m_info->clear();
QString profilestr = m_profilesCombo->itemData(ix).toString();
if (!profilestr.isEmpty()) {
m_info->setPlainText(profilestr.section(QLatin1Char(';'), 0, 0));
}
}
void EncodingProfilesChooser::hideMessage()
{
m_messageWidget->hide();
}
void EncodingProfilesChooser::filterPreviewProfiles(const QString & /*profile*/) {}
EncodingTimelinePreviewProfilesChooser::EncodingTimelinePreviewProfilesChooser(QWidget *parent, bool showAutoItem, const QString &defaultValue,
bool selectFromConfig)
: EncodingProfilesChooser(parent, EncodingProfilesManager::TimelinePreview, showAutoItem, QString(), false)
{
loadEncodingProfiles();
if (selectFromConfig) {
KConfigGroup resourceConfig(KSharedConfig::openConfig(), "project");
int ix = resourceConfig.readEntry(defaultValue).toInt();
m_profilesCombo->setCurrentIndex(ix);
slotUpdateProfile(ix);
} else if (!defaultValue.isEmpty()) {
int ix = m_profilesCombo->findData(defaultValue);
if (ix == -1) {
m_profilesCombo->addItem(i18n("Current Settings"), defaultValue);
ix = m_profilesCombo->findData(defaultValue);
}
if (ix > -1) {
m_profilesCombo->setCurrentIndex(ix);
slotUpdateProfile(ix);
}
}
connect(m_profilesCombo, &KComboBox::currentIndexChanged, m_messageWidget, &KMessageWidget::hide);
}
void EncodingTimelinePreviewProfilesChooser::loadEncodingProfiles()
{
QSignalBlocker bk(m_profilesCombo);
QString currentItem = m_profilesCombo->currentText();
m_profilesCombo->clear();
if (m_showAutoItem) {
if (KdenliveSettings::nvencEnabled() || KdenliveSettings::vaapiEnabled()) {
m_profilesCombo->addItem(QIcon::fromTheme(QStringLiteral("speedometer")), i18n("Automatic"));
} else {
m_profilesCombo->addItem(i18n("Automatic"));
}
}
KConfig conf(QStringLiteral("encodingprofiles.rc"), KConfig::CascadeConfig, QStandardPaths::AppDataLocation);
KConfigGroup group(&conf, EncodingProfilesManager::configGroupName(m_type));
QMap<QString, QString> values = group.entryMap();
QMapIterator<QString, QString> i(values);
while (i.hasNext()) {
i.next();
if (!i.key().isEmpty()) {
// We filter out incompatible profiles
if (i.value().contains(QLatin1String("nvenc"))) {
if (KdenliveSettings::nvencEnabled()) {
m_profilesCombo->addItem(QIcon::fromTheme(QStringLiteral("speedometer")), i.key(), i.value());
}
if (i.value().contains(QLatin1String("vaapi"))) {
if (KdenliveSettings::vaapiEnabled()) {
m_profilesCombo->addItem(QIcon::fromTheme(QStringLiteral("speedometer")), i.key(), i.value());
}
continue;
continue;
}
if (i.value().contains(QLatin1String("vaapi"))) {
if (KdenliveSettings::vaapiEnabled()) {
m_profilesCombo->addItem(QIcon::fromTheme(QStringLiteral("speedometer")), i.key(), i.value());
}
continue;
}
m_profilesCombo->addItem(i.key(), i.value());
}
......@@ -290,10 +379,9 @@ void EncodingProfilesChooser::loadEncodingProfiles()
m_profilesCombo->setCurrentIndex(ix);
slotUpdateProfile(ix);
}
m_profilesCombo->blockSignals(false);
}
void EncodingProfilesChooser::filterPreviewProfiles(const QString &profile)
void EncodingTimelinePreviewProfilesChooser::filterPreviewProfiles(const QString &profile)
{
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(m_profilesCombo->model());
Q_ASSERT(model != nullptr);
......@@ -326,36 +414,10 @@ void EncodingProfilesChooser::filterPreviewProfiles(const QString &profile)
for (int i = 0; i < max; i++) {
if (m_profilesCombo->itemData(i).isNull()) {
m_profilesCombo->setCurrentIndex(i);
emit incompatibleProfile();
m_messageWidget->setText(i18n("Selected Timeline preview profile is not compatible with the project framerate,\nreverting to Automatic."));
m_messageWidget->animatedShow();
break;
}
}
}
}
QString EncodingProfilesChooser::currentExtension()
{
QString profilestr = m_profilesCombo->currentData().toString();
if (profilestr.isEmpty()) {
return {};
}
return profilestr.section(QLatin1Char(';'), 1, 1);
}
QString EncodingProfilesChooser::currentParams()
{
QString profilestr = m_profilesCombo->currentData().toString();
if (profilestr.isEmpty()) {
return {};
}
return profilestr.section(QLatin1Char(';'), 0, 0);
}
void EncodingProfilesChooser::slotUpdateProfile(int ix)
{
m_info->clear();
QString profilestr = m_profilesCombo->itemData(ix).toString();
if (!profilestr.isEmpty()) {
m_info->setPlainText(profilestr.section(QLatin1Char(';'), 0, 0));
}
}
......@@ -11,6 +11,8 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include "definitions.h"
#include "ui_manageencodingprofile_ui.h"
class KMessageWidget;
class EncodingProfilesManager
{
......@@ -52,25 +54,39 @@ class EncodingProfilesChooser : public QWidget
public:
EncodingProfilesChooser(QWidget *parent, EncodingProfilesManager::ProfileType, bool showAutoItem = false, const QString &configname = {},
const QString &selectByValue = {});
bool native = true);
QString currentExtension();
QString currentParams();
void hideMessage();
/** @brief Only enable preview profiles with matching framerate */
void filterPreviewProfiles(const QString &profile);
virtual void filterPreviewProfiles(const QString & /*profile*/);
public slots:
void slotUpdateProfile(int ix);
private:
protected:
QComboBox *m_profilesCombo;
QPlainTextEdit *m_info;
EncodingProfilesManager::ProfileType m_type;
bool m_showAutoItem;
KMessageWidget *m_messageWidget;
private:
QPlainTextEdit *m_info;
private slots:
void slotManageEncodingProfile();
void loadEncodingProfiles();
virtual void loadEncodingProfiles();
};
signals:
void incompatibleProfile();
class EncodingTimelinePreviewProfilesChooser : public EncodingProfilesChooser
{
Q_OBJECT
public:
EncodingTimelinePreviewProfilesChooser(QWidget *parent, bool showAutoItem = false, const QString &defaultValue = {}, bool selectFromConfig = false);
/** @brief Only enable preview profiles with matching framerate */
void filterPreviewProfiles(const QString &profile) override;
private slots:
void loadEncodingProfiles() override;
};
......@@ -260,15 +260,13 @@ void KdenliveSettingsDialog::initProjectPage()
{
QWidget *p8 = new QWidget;
m_configProject.setupUi(p8);
m_configProject.profileWarning->hide();
// Timeline preview
m_tlPreviewProfiles = new EncodingProfilesChooser(p8, EncodingProfilesManager::TimelinePreview, true, QStringLiteral("preview_profile"));
m_tlPreviewProfiles = new EncodingTimelinePreviewProfilesChooser(p8, true, QStringLiteral("preview_profile"), true);
m_configProject.preview_profile_box->addWidget(m_tlPreviewProfiles);
auto *vbox = new QVBoxLayout;
m_pw = new ProfileWidget(this);
vbox->addWidget(m_pw);
connect(m_pw, &ProfileWidget::profileChanged, this, [this]() { m_tlPreviewProfiles->filterPreviewProfiles(m_pw->selectedProfile()); });
connect(m_tlPreviewProfiles, &EncodingProfilesChooser::incompatibleProfile, m_configProject.profileWarning, &KMessageWidget::animatedShow);
m_configProject.profile_box->setLayout(vbox);
m_configProject.profile_box->setTitle(i18n("Select the Default Profile (preset)"));
// Select profile
......@@ -1016,7 +1014,7 @@ void KdenliveSettingsDialog::updateSettings()
QString device = m_configShuttle.shuttledevicelist->itemData(m_configShuttle.shuttledevicelist->currentIndex()).toString();
if (device != KdenliveSettings::shuttledevice()) KdenliveSettings::setShuttledevice(device);
}*/
m_tlPreviewProfiles->hideMessage();
if (m_configProject.projecturl->url().toLocalFile() != KdenliveSettings::defaultprojectfolder()) {
KdenliveSettings::setDefaultprojectfolder(m_configProject.projecturl->url().toLocalFile());
if (!KdenliveSettings::sameprojectfolder()) {
......
......@@ -132,7 +132,7 @@ private:
SpeechToText *m_stt;
QMap<QString, QString> m_mappable_actions;
QVector<QComboBox *> m_shuttle_buttons;
EncodingProfilesChooser *m_tlPreviewProfiles;
EncodingTimelinePreviewProfilesChooser *m_tlPreviewProfiles;
EncodingProfilesChooser *m_proxyProfiles;
EncodingProfilesChooser *m_decklinkProfiles;
EncodingProfilesChooser *m_v4lProfiles;
......
......@@ -61,7 +61,6 @@ ProjectSettings::ProjectSettings(KdenliveDoc *doc, QMap<QString, QString> metada
{
setupUi(this);
tabWidget->setTabBarAutoHide(true);
previewWarning->hide();
auto *vbox = new QVBoxLayout;
vbox->setContentsMargins(0, 0, 0, 0);
m_pw = new ProfileWidget(this);
......@@ -172,10 +171,9 @@ ProjectSettings::ProjectSettings(KdenliveDoc *doc, QMap<QString, QString> metada
if (!m_previewparams.isEmpty() || !m_previewextension.isEmpty()) {
currentProfileParams = QString("%1;%2").arg(m_previewparams, m_previewextension);
}
m_tlPreviewProfiles = new EncodingProfilesChooser(this, EncodingProfilesManager::TimelinePreview, true, QStringLiteral(), currentProfileParams);
m_tlPreviewProfiles = new EncodingTimelinePreviewProfilesChooser(this, true, currentProfileParams);
preview_profile_box->addWidget(m_tlPreviewProfiles);
connect(m_pw, &ProfileWidget::profileChanged, this, [this]() { m_tlPreviewProfiles->filterPreviewProfiles(m_pw->selectedProfile()); });
connect(m_tlPreviewProfiles, &EncodingProfilesChooser::incompatibleProfile, previewWarning, &KMessageWidget::animatedShow);
m_tlPreviewProfiles->filterPreviewProfiles(currentProf);
loadProxyProfiles();
loadExternalProxyProfiles();
......
......@@ -93,7 +93,7 @@ private:
QString m_previewparams;
QString m_previewextension;
QString m_initialExternalProxyProfile;
EncodingProfilesChooser *m_tlPreviewProfiles;
EncodingTimelinePreviewProfilesChooser *m_tlPreviewProfiles;
/** @brief Fill the proxy profiles combobox. */
// void loadPreviewProfiles();
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>579</width>
<height>269</height>
<height>194</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
......@@ -17,19 +17,27 @@
<property name="topMargin">
<number>0</number>
</property>
<item row="1" column="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Audio tracks</string>
</property>
</widget>
<item row="2" column="0" colspan="6">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="kcfg_customprojectfolder">
<property name="text">
<string>Custom project folder:</string>
</property>
</widget>
</item>
<item>
<widget class="KUrlRequester" name="projecturl">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="kcfg_audiotracks"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="kcfg_videotracks"/>
</item>
<item row="3" column="0" colspan="6">
<widget class="QCheckBox" name="kcfg_sameprojectfolder">
<property name="text">
......@@ -37,30 +45,10 @@
</property>
</widget>
</item>
<item row="8" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<item row="1" column="4">
<widget class="QLabel" name="label">
<property name="text">
<string>Video tracks</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="7">
<widget class="QGroupBox" name="profile_box">
<property name="flat">
<bool>true</bool>
<string>Audio channels:</string>
</property>
</widget>
</item>
......@@ -89,6 +77,23 @@
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="kcfg_videotracks"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Video tracks</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="7">
<widget class="QGroupBox" name="profile_box">
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="0" colspan="6">
<layout class="QHBoxLayout" name="preview_profile_box">
<item>
......@@ -106,39 +111,23 @@
</item>
</layout>
</item>
<item row="1" column="4">
<widget class="QLabel" name="label">
<property name="text">
<string>Audio channels:</string>
<item row="7" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="2" column="0" colspan="6">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="kcfg_customprojectfolder">
<property name="text">
<string>Custom project folder:</string>
</property>
</widget>
</item>
<item>
<widget class="KUrlRequester" name="projecturl">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="0" colspan="6">
<widget class="KMessageWidget" name="profileWarning">
<item row="1" column="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Selected Timeline preview profile is not compatible with the project framerate,
reverting to Automatic.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
<string>Audio tracks</string>
</property>
</widget>
</item>
......@@ -151,11 +140,6 @@ reverting to Automatic.</string>
<header>kurlrequester.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KMessageWidget</class>
<extends>QFrame</extends>
<header>kmessagewidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>kcfg_videotracks</tabstop>
......
......@@ -37,53 +37,6 @@
<string>Settings</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>229</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="4">
<widget class="QGroupBox" name="profile_box">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="0" colspan="4">
<widget class="KMessageWidget" name="previewWarning">
<property name="text">
<string>Selected Timeline preview profile is not compatible with the project framerate,
reverting to Automatic.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="closeButtonVisible">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Project folder to store proxy clips, thumbnails, previews</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
......@@ -140,10 +93,23 @@ reverting to Automatic.</string>
</item>
</layout>
</item>
<item row="5" column="2">
<widget class="QCheckBox" name="audio_thumbs">