change: change code style to Linux style except indent.

This commit is contained in:
Mike Solar
2025-08-03 03:09:40 +08:00
parent 65ab76edc8
commit 74f73ab3be
789 changed files with 77113 additions and 68888 deletions
+37 -30
View File
@@ -23,55 +23,62 @@
#include <QAction>
#include <QKeyEvent>
namespace olive {
namespace olive
{
#define super QKeySequenceEdit
KeySequenceEditor::KeySequenceEditor(QWidget* parent, QAction* a)
: super(parent), action(a) {
setKeySequence(action->shortcut());
KeySequenceEditor::KeySequenceEditor(QWidget *parent, QAction *a)
: super(parent)
, action(a)
{
setKeySequence(action->shortcut());
}
void KeySequenceEditor::set_action_shortcut() {
action->setShortcut(keySequence());
void KeySequenceEditor::set_action_shortcut()
{
action->setShortcut(keySequence());
}
void KeySequenceEditor::reset_to_default() {
setKeySequence(action->property("keydefault").toString());
void KeySequenceEditor::reset_to_default()
{
setKeySequence(action->property("keydefault").toString());
}
QString KeySequenceEditor::action_name() {
return action->property("id").toString();
QString KeySequenceEditor::action_name()
{
return action->property("id").toString();
}
QString KeySequenceEditor::export_shortcut() {
QKeySequence ks = keySequence();
if (ks != action->property("keydefault").value<QKeySequence>()) {
return action->property("id").toString() + "\t" + ks.toString();
}
return nullptr;
QString KeySequenceEditor::export_shortcut()
{
QKeySequence ks = keySequence();
if (ks != action->property("keydefault").value<QKeySequence>()) {
return action->property("id").toString() + "\t" + ks.toString();
}
return nullptr;
}
void KeySequenceEditor::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Backspace) {
clear();
} else if (e->key() == Qt::Key_Escape) {
e->ignore();
} else{
super::keyPressEvent(e);
}
if (e->key() == Qt::Key_Backspace) {
clear();
} else if (e->key() == Qt::Key_Escape) {
e->ignore();
} else {
super::keyPressEvent(e);
}
}
void KeySequenceEditor::keyReleaseEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_Backspace) {
// Do nothing
} else if (e->key() == Qt::Key_Escape) {
e->ignore();
} else {
super::keyReleaseEvent(e);
}
if (e->key() == Qt::Key_Backspace) {
// Do nothing
} else if (e->key() == Qt::Key_Escape) {
e->ignore();
} else {
super::keyReleaseEvent(e);
}
}
}
+17 -16
View File
@@ -25,7 +25,8 @@
#include "common/debug.h"
namespace olive {
namespace olive
{
/**
* @brief The KeySequenceEditor class
@@ -34,9 +35,9 @@ namespace olive {
* keyboard shortcuts to and from it.
*/
class KeySequenceEditor : public QKeySequenceEdit {
Q_OBJECT
Q_OBJECT
public:
/**
/**
* @brief KeySequenceEditor Constructor
*
* @param parent
@@ -47,18 +48,18 @@ public:
*
* The QAction to link to. This cannot be changed throughout the lifetime of a KeySequenceEditor.
*/
KeySequenceEditor(QWidget *parent, QAction* a);
KeySequenceEditor(QWidget *parent, QAction *a);
/**
/**
* @brief Sets the attached QAction's shortcut to the shortcut entered in this field.
*
* This is not done automatically in case the user cancels out of the Preferences dialog, in which case the
* expectation is that the changes made will not be saved. Therefore, this needs to be triggered manually when
* PreferencesDialog saves.
*/
void set_action_shortcut();
void set_action_shortcut();
/**
/**
* @brief Set this shortcut back to the QAction's default shortcut
*
* Each QAction contains the default shortcut in its `property("default")` and can be used to restore the default
@@ -68,9 +69,9 @@ public:
* the QAction into this edit field. To save it into the QAction, it's necessary to call set_action_shortcut() after
* calling this function.
*/
void reset_to_default();
void reset_to_default();
/**
/**
* @brief Return attached QAction's unique ID
*
* Each of Olive's menu actions has a unique string ID (that, unlike the text, is not translated) for matching with
@@ -81,9 +82,9 @@ public:
*
* The QAction's unique ID.
*/
QString action_name();
QString action_name();
/**
/**
* @brief Serialize this shortcut entry into a string that can be saved to a file
*
* @return
@@ -93,18 +94,18 @@ public:
* the QAction). If the entered shortcut is the same as the QAction's default shortcut, the return value is empty
* because a default shortcut does not need to be saved to a file.
*/
QString export_shortcut();
QString export_shortcut();
protected:
virtual void keyPressEvent(QKeyEvent *e) override;
virtual void keyPressEvent(QKeyEvent *e) override;
virtual void keyReleaseEvent(QKeyEvent *e) override;
virtual void keyReleaseEvent(QKeyEvent *e) override;
private:
/**
/**
* @brief Internal reference to the linked QAction
*/
QAction* action;
QAction *action;
};
}
+13 -12
View File
@@ -34,24 +34,25 @@
#include "tabs/preferenceskeyboardtab.h"
#include "window/mainwindow/mainwindow.h"
namespace olive {
PreferencesDialog::PreferencesDialog(MainWindow *main_window) :
ConfigDialogBase(main_window)
namespace olive
{
setWindowTitle(tr("Preferences"));
AddTab(new PreferencesGeneralTab(), tr("General"));
AddTab(new PreferencesAppearanceTab(), tr("Appearance"));
AddTab(new PreferencesBehaviorTab(), tr("Behavior"));
AddTab(new PreferencesDiskTab(), tr("Disk"));
AddTab(new PreferencesAudioTab(), tr("Audio"));
AddTab(new PreferencesKeyboardTab(main_window), tr("Keyboard"));
PreferencesDialog::PreferencesDialog(MainWindow *main_window)
: ConfigDialogBase(main_window)
{
setWindowTitle(tr("Preferences"));
AddTab(new PreferencesGeneralTab(), tr("General"));
AddTab(new PreferencesAppearanceTab(), tr("Appearance"));
AddTab(new PreferencesBehaviorTab(), tr("Behavior"));
AddTab(new PreferencesDiskTab(), tr("Disk"));
AddTab(new PreferencesAudioTab(), tr("Audio"));
AddTab(new PreferencesKeyboardTab(main_window), tr("Keyboard"));
}
void PreferencesDialog::AcceptEvent()
{
Config::Save();
Config::Save();
}
}
+6 -7
View File
@@ -30,7 +30,8 @@
#include "dialog/configbase/configdialogbase.h"
namespace olive {
namespace olive
{
class MainWindow;
@@ -39,16 +40,14 @@ class MainWindow;
*
* A dialog for the global application settings. Mostly an interface for Config.
*/
class PreferencesDialog : public ConfigDialogBase
{
Q_OBJECT
class PreferencesDialog : public ConfigDialogBase {
Q_OBJECT
public:
PreferencesDialog(MainWindow *main_window);
PreferencesDialog(MainWindow *main_window);
protected:
virtual void AcceptEvent() override;
virtual void AcceptEvent() override;
};
}
@@ -31,92 +31,96 @@
#include "widget/menu/menushared.h"
#include "ui/colorcoding.h"
namespace olive {
namespace olive
{
PreferencesAppearanceTab::PreferencesAppearanceTab()
{
QVBoxLayout* layout = new QVBoxLayout(this);
QVBoxLayout *layout = new QVBoxLayout(this);
QGridLayout* appearance_layout = new QGridLayout();
layout->addLayout(appearance_layout);
QGridLayout *appearance_layout = new QGridLayout();
layout->addLayout(appearance_layout);
int row = 0;
int row = 0;
// Appearance -> Theme
appearance_layout->addWidget(new QLabel(tr("Theme")), row, 0);
// Appearance -> Theme
appearance_layout->addWidget(new QLabel(tr("Theme")), row, 0);
style_combobox_ = new QComboBox();
style_combobox_ = new QComboBox();
{
const QMap<QString, QString>& themes = StyleManager::available_themes();
QMap<QString, QString>::const_iterator i;
for (i=themes.cbegin(); i!=themes.cend(); i++) {
style_combobox_->addItem(i.value(), i.key());
{
const QMap<QString, QString> &themes = StyleManager::available_themes();
QMap<QString, QString>::const_iterator i;
for (i = themes.cbegin(); i != themes.cend(); i++) {
style_combobox_->addItem(i.value(), i.key());
if (StyleManager::GetStyle() == i.key()) {
style_combobox_->setCurrentIndex(style_combobox_->count()-1);
}
}
}
if (StyleManager::GetStyle() == i.key()) {
style_combobox_->setCurrentIndex(style_combobox_->count() - 1);
}
}
}
appearance_layout->addWidget(style_combobox_, row, 1);
appearance_layout->addWidget(style_combobox_, row, 1);
row++;
row++;
{
QGroupBox* color_group = new QGroupBox();
color_group->setTitle(tr("Default Node Colors"));
{
QGroupBox *color_group = new QGroupBox();
color_group->setTitle(tr("Default Node Colors"));
QGridLayout* color_layout = new QGridLayout(color_group);
QGridLayout *color_layout = new QGridLayout(color_group);
for (int i=0; i<Node::kCategoryCount; i++) {
QString cat_name = Node::GetCategoryName(static_cast<Node::CategoryID>(i));
color_layout->addWidget(new QLabel(cat_name), i, 0);
for (int i = 0; i < Node::kCategoryCount; i++) {
QString cat_name =
Node::GetCategoryName(static_cast<Node::CategoryID>(i));
color_layout->addWidget(new QLabel(cat_name), i, 0);
ColorCodingComboBox* ccc = new ColorCodingComboBox();
ccc->SetColor(OLIVE_CONFIG_STR(QStringLiteral("CatColor%1").arg(i)).toInt());
color_layout->addWidget(ccc, i, 1);
color_btns_.append(ccc);
}
ColorCodingComboBox *ccc = new ColorCodingComboBox();
ccc->SetColor(
OLIVE_CONFIG_STR(QStringLiteral("CatColor%1").arg(i)).toInt());
color_layout->addWidget(ccc, i, 1);
color_btns_.append(ccc);
}
appearance_layout->addWidget(color_group, row, 0, 1, 2);
}
appearance_layout->addWidget(color_group, row, 0, 1, 2);
}
row++;
{
QGroupBox* marker_group = new QGroupBox();
marker_group->setTitle(tr("Miscellaneous"));
row++;
{
QGroupBox *marker_group = new QGroupBox();
marker_group->setTitle(tr("Miscellaneous"));
QGridLayout* marker_layout = new QGridLayout(marker_group);
QGridLayout *marker_layout = new QGridLayout(marker_group);
marker_layout->addWidget(new QLabel("Default Marker Color"), 0, 0);
marker_layout->addWidget(new QLabel("Default Marker Color"), 0, 0);
marker_btn_ = new ColorCodingComboBox();
marker_btn_->SetColor(OLIVE_CONFIG("MarkerColor").toInt());
marker_layout->addWidget(marker_btn_, 0, 1);
marker_btn_ = new ColorCodingComboBox();
marker_btn_->SetColor(OLIVE_CONFIG("MarkerColor").toInt());
marker_layout->addWidget(marker_btn_, 0, 1);
appearance_layout->addWidget(marker_group, row, 0, 1, 2);
}
appearance_layout->addWidget(marker_group, row, 0, 1, 2);
}
layout->addStretch();
layout->addStretch();
}
void PreferencesAppearanceTab::Accept(MultiUndoCommand *command)
{
Q_UNUSED(command)
Q_UNUSED(command)
QString style_path = style_combobox_->currentData().toString();
QString style_path = style_combobox_->currentData().toString();
if (style_path != StyleManager::GetStyle()) {
StyleManager::SetStyle(style_path);
OLIVE_CONFIG("Style") = style_path;
}
if (style_path != StyleManager::GetStyle()) {
StyleManager::SetStyle(style_path);
OLIVE_CONFIG("Style") = style_path;
}
for (int i=0; i<color_btns_.size(); i++) {
OLIVE_CONFIG_STR(QStringLiteral("CatColor%1").arg(i)) = color_btns_.at(i)->GetSelectedColor();
}
for (int i = 0; i < color_btns_.size(); i++) {
OLIVE_CONFIG_STR(QStringLiteral("CatColor%1").arg(i)) =
color_btns_.at(i)->GetSelectedColor();
}
OLIVE_CONFIG("MarkerColor") = marker_btn_->GetSelectedColor();
OLIVE_CONFIG("MarkerColor") = marker_btn_->GetSelectedColor();
}
}
@@ -29,26 +29,25 @@
#include "ui/style/style.h"
#include "widget/colorlabelmenu/colorcodingcombobox.h"
namespace olive {
class PreferencesAppearanceTab : public ConfigDialogBaseTab
namespace olive
{
Q_OBJECT
public:
PreferencesAppearanceTab();
virtual void Accept(MultiUndoCommand* command) override;
class PreferencesAppearanceTab : public ConfigDialogBaseTab {
Q_OBJECT
public:
PreferencesAppearanceTab();
virtual void Accept(MultiUndoCommand *command) override;
private:
/**
/**
* @brief UI widget for selecting the current UI style
*/
QComboBox* style_combobox_;
QComboBox *style_combobox_;
QVector<ColorCodingComboBox*> color_btns_;
ColorCodingComboBox* marker_btn_;
QVector<ColorCodingComboBox *> color_btns_;
ColorCodingComboBox *marker_btn_;
};
}
@@ -27,248 +27,291 @@
#include "audio/audiomanager.h"
#include "config/config.h"
namespace olive {
namespace olive
{
PreferencesAudioTab::PreferencesAudioTab()
{
QVBoxLayout* audio_tab_layout = new QVBoxLayout(this);
QVBoxLayout *audio_tab_layout = new QVBoxLayout(this);
{
// Backend Layout
QGridLayout* main_layout = new QGridLayout();
main_layout->setContentsMargins(0, 0, 0, 0);
{
// Backend Layout
QGridLayout *main_layout = new QGridLayout();
main_layout->setContentsMargins(0, 0, 0, 0);
int row = 0;
int row = 0;
main_layout->addWidget(new QLabel(tr("Backend:")), row, 0);
main_layout->addWidget(new QLabel(tr("Backend:")), row, 0);
audio_backend_combobox_ = new QComboBox();
connect(audio_backend_combobox_, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &PreferencesAudioTab::RefreshDevices);
main_layout->addWidget(audio_backend_combobox_, row, 1);
audio_backend_combobox_ = new QComboBox();
connect(audio_backend_combobox_,
static_cast<void (QComboBox::*)(int)>(
&QComboBox::currentIndexChanged),
this, &PreferencesAudioTab::RefreshDevices);
main_layout->addWidget(audio_backend_combobox_, row, 1);
audio_tab_layout->addLayout(main_layout);
}
audio_tab_layout->addLayout(main_layout);
}
{
QGroupBox* groupbox = new QGroupBox();
audio_tab_layout->addWidget(groupbox);
{
QGroupBox *groupbox = new QGroupBox();
audio_tab_layout->addWidget(groupbox);
QVBoxLayout* layout = new QVBoxLayout(groupbox);
QVBoxLayout *layout = new QVBoxLayout(groupbox);
int row = 0;
int row = 0;
{
// Output Group
QGroupBox* output_group = new QGroupBox();
output_group->setTitle(tr("Output"));
layout->addWidget(output_group);
{
// Output Group
QGroupBox *output_group = new QGroupBox();
output_group->setTitle(tr("Output"));
layout->addWidget(output_group);
QGridLayout* output_layout = new QGridLayout(output_group);
QGridLayout *output_layout = new QGridLayout(output_group);
output_layout->addWidget(new QLabel(tr("Device:")), row, 0);
output_layout->addWidget(new QLabel(tr("Device:")), row, 0);
audio_output_devices_ = new QComboBox();
output_layout->addWidget(audio_output_devices_, row, 1);
audio_output_devices_ = new QComboBox();
output_layout->addWidget(audio_output_devices_, row, 1);
row++;
row++;
{
int output_row = 0;
{
int output_row = 0;
QGroupBox *output_param_group = new QGroupBox(tr("Advanced"));
output_layout->addWidget(output_param_group, row, 0, 1, 2);
QGroupBox *output_param_group = new QGroupBox(tr("Advanced"));
output_layout->addWidget(output_param_group, row, 0, 1, 2);
QGridLayout *output_param_layout = new QGridLayout(output_param_group);
QGridLayout *output_param_layout =
new QGridLayout(output_param_group);
output_param_layout->addWidget(new QLabel(tr("Sample Rate:")), output_row, 0);
output_param_layout->addWidget(new QLabel(tr("Sample Rate:")),
output_row, 0);
output_rate_combo_ = new SampleRateComboBox();
output_rate_combo_->SetSampleRate(OLIVE_CONFIG("AudioOutputSampleRate").toInt());
output_param_layout->addWidget(output_rate_combo_, output_row, 1);
output_rate_combo_ = new SampleRateComboBox();
output_rate_combo_->SetSampleRate(
OLIVE_CONFIG("AudioOutputSampleRate").toInt());
output_param_layout->addWidget(output_rate_combo_, output_row,
1);
output_row++;
output_row++;
output_param_layout->addWidget(new QLabel(tr("Channel Layout:")), output_row, 0);
output_param_layout->addWidget(
new QLabel(tr("Channel Layout:")), output_row, 0);
output_ch_layout_combo_ = new ChannelLayoutComboBox();
output_ch_layout_combo_->SetChannelLayout(OLIVE_CONFIG("AudioOutputChannelLayout").toULongLong());
output_param_layout->addWidget(output_ch_layout_combo_, output_row, 1);
output_ch_layout_combo_ = new ChannelLayoutComboBox();
output_ch_layout_combo_->SetChannelLayout(
OLIVE_CONFIG("AudioOutputChannelLayout").toULongLong());
output_param_layout->addWidget(output_ch_layout_combo_,
output_row, 1);
output_row++;
output_row++;
output_param_layout->addWidget(new QLabel(tr("Sample Format:")), output_row, 0);
output_param_layout->addWidget(new QLabel(tr("Sample Format:")),
output_row, 0);
output_fmt_combo_ = new SampleFormatComboBox();
output_fmt_combo_->SetPackedFormats();
output_fmt_combo_->SetSampleFormat(SampleFormat::from_string(OLIVE_CONFIG("AudioOutputSampleFormat").toString().toStdString()));
output_param_layout->addWidget(output_fmt_combo_, output_row, 1);
}
}
output_fmt_combo_ = new SampleFormatComboBox();
output_fmt_combo_->SetPackedFormats();
output_fmt_combo_->SetSampleFormat(SampleFormat::from_string(
OLIVE_CONFIG("AudioOutputSampleFormat")
.toString()
.toStdString()));
output_param_layout->addWidget(output_fmt_combo_, output_row,
1);
}
}
row = 0;
row = 0;
{
QGroupBox* input_group = new QGroupBox();
input_group->setTitle(tr("Input"));
layout->addWidget(input_group);
{
QGroupBox *input_group = new QGroupBox();
input_group->setTitle(tr("Input"));
layout->addWidget(input_group);
QGridLayout* input_layout = new QGridLayout(input_group);
QGridLayout *input_layout = new QGridLayout(input_group);
input_layout->addWidget(new QLabel(tr("Device:")), row, 0);
input_layout->addWidget(new QLabel(tr("Device:")), row, 0);
audio_input_devices_ = new QComboBox();
input_layout->addWidget(audio_input_devices_, row, 1);
audio_input_devices_ = new QComboBox();
input_layout->addWidget(audio_input_devices_, row, 1);
row++;
row++;
QGroupBox *recording_group = new QGroupBox(tr("Recording"));
input_layout->addWidget(recording_group, row, 0, 1, 2);
QGroupBox *recording_group = new QGroupBox(tr("Recording"));
input_layout->addWidget(recording_group, row, 0, 1, 2);
QVBoxLayout *recording_layout = new QVBoxLayout(recording_group);
QVBoxLayout *recording_layout = new QVBoxLayout(recording_group);
QHBoxLayout *fmt_layout = new QHBoxLayout();
recording_layout->addLayout(fmt_layout);
QHBoxLayout *fmt_layout = new QHBoxLayout();
recording_layout->addLayout(fmt_layout);
fmt_layout->addWidget(new QLabel(tr("Format:")));
fmt_layout->addWidget(new QLabel(tr("Format:")));
record_format_combo_ = new ExportFormatComboBox(ExportFormatComboBox::kShowAudioOnly);
record_format_combo_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
record_format_combo_->SetFormat(static_cast<ExportFormat::Format>(OLIVE_CONFIG("AudioRecordingFormat").toInt()));
fmt_layout->addWidget(record_format_combo_);
record_format_combo_ =
new ExportFormatComboBox(ExportFormatComboBox::kShowAudioOnly);
record_format_combo_->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
record_format_combo_->SetFormat(static_cast<ExportFormat::Format>(
OLIVE_CONFIG("AudioRecordingFormat").toInt()));
fmt_layout->addWidget(record_format_combo_);
record_options_ = new ExportAudioTab();
record_options_->SetFormat(record_format_combo_->GetFormat());
record_options_->SetCodec(static_cast<ExportCodec::Codec>(OLIVE_CONFIG("AudioRecordingCodec").toInt()));
record_options_->sample_rate_combobox()->SetSampleRate(OLIVE_CONFIG("AudioRecordingSampleRate").toInt());
record_options_->channel_layout_combobox()->SetChannelLayout(OLIVE_CONFIG("AudioRecordingChannelLayout").toULongLong());
record_options_->bit_rate_slider()->SetValue(OLIVE_CONFIG("AudioRecordingBitRate").toInt());
record_options_->sample_format_combobox()->SetSampleFormat(SampleFormat::from_string(OLIVE_CONFIG("AudioRecordingSampleFormat").toString().toStdString()));
recording_layout->addWidget(record_options_);
record_options_ = new ExportAudioTab();
record_options_->SetFormat(record_format_combo_->GetFormat());
record_options_->SetCodec(static_cast<ExportCodec::Codec>(
OLIVE_CONFIG("AudioRecordingCodec").toInt()));
record_options_->sample_rate_combobox()->SetSampleRate(
OLIVE_CONFIG("AudioRecordingSampleRate").toInt());
record_options_->channel_layout_combobox()->SetChannelLayout(
OLIVE_CONFIG("AudioRecordingChannelLayout").toULongLong());
record_options_->bit_rate_slider()->SetValue(
OLIVE_CONFIG("AudioRecordingBitRate").toInt());
record_options_->sample_format_combobox()->SetSampleFormat(
SampleFormat::from_string(
OLIVE_CONFIG("AudioRecordingSampleFormat")
.toString()
.toStdString()));
recording_layout->addWidget(record_options_);
connect(record_format_combo_, &ExportFormatComboBox::FormatChanged, record_options_, &ExportAudioTab::SetFormat);
}
connect(record_format_combo_, &ExportFormatComboBox::FormatChanged,
record_options_, &ExportAudioTab::SetFormat);
}
QHBoxLayout* refresh_layout = new QHBoxLayout();
layout->addLayout(refresh_layout);
refresh_layout->addStretch();
QHBoxLayout *refresh_layout = new QHBoxLayout();
layout->addLayout(refresh_layout);
refresh_layout->addStretch();
refresh_devices_btn_ = new QPushButton(tr("Refresh Devices"));
refresh_layout->addWidget(refresh_devices_btn_);
refresh_devices_btn_ = new QPushButton(tr("Refresh Devices"));
refresh_layout->addWidget(refresh_devices_btn_);
connect(refresh_devices_btn_, &QPushButton::clicked, this, &PreferencesAudioTab::HardRefreshBackends);
}
connect(refresh_devices_btn_, &QPushButton::clicked, this,
&PreferencesAudioTab::HardRefreshBackends);
}
audio_tab_layout->addStretch();
audio_tab_layout->addStretch();
// Populate lists
RefreshBackends();
// Populate lists
RefreshBackends();
}
void PreferencesAudioTab::Accept(MultiUndoCommand *command)
{
Q_UNUSED(command)
Q_UNUSED(command)
// Get device indexes
PaDeviceIndex output_device = audio_output_devices_->currentData().value<PaDeviceIndex>();
PaDeviceIndex input_device = audio_input_devices_->currentData().value<PaDeviceIndex>();
// Get device indexes
PaDeviceIndex output_device =
audio_output_devices_->currentData().value<PaDeviceIndex>();
PaDeviceIndex input_device =
audio_input_devices_->currentData().value<PaDeviceIndex>();
// Get device names, which seem to be the closest thing we have to a "unique identifier" for them
OLIVE_CONFIG("AudioOutput") = audio_output_devices_->currentText();
OLIVE_CONFIG("AudioInput") = audio_input_devices_->currentText();
// Get device names, which seem to be the closest thing we have to a "unique identifier" for them
OLIVE_CONFIG("AudioOutput") = audio_output_devices_->currentText();
OLIVE_CONFIG("AudioInput") = audio_input_devices_->currentText();
// Set devices to be used from now on
AudioManager::instance()->SetOutputDevice(output_device);
AudioManager::instance()->SetInputDevice(input_device);
// Set devices to be used from now on
AudioManager::instance()->SetOutputDevice(output_device);
AudioManager::instance()->SetInputDevice(input_device);
OLIVE_CONFIG("AudioOutputSampleRate") = output_rate_combo_->GetSampleRate();
OLIVE_CONFIG("AudioOutputChannelLayout") = QVariant::fromValue(output_ch_layout_combo_->GetChannelLayout());
OLIVE_CONFIG("AudioOutputSampleFormat") = QString::fromStdString(output_fmt_combo_->GetSampleFormat().to_string());
OLIVE_CONFIG("AudioOutputSampleRate") = output_rate_combo_->GetSampleRate();
OLIVE_CONFIG("AudioOutputChannelLayout") =
QVariant::fromValue(output_ch_layout_combo_->GetChannelLayout());
OLIVE_CONFIG("AudioOutputSampleFormat") = QString::fromStdString(
output_fmt_combo_->GetSampleFormat().to_string());
OLIVE_CONFIG("AudioRecordingFormat") = record_format_combo_->GetFormat();
OLIVE_CONFIG("AudioRecordingCodec") = record_options_->GetCodec();
OLIVE_CONFIG("AudioRecordingSampleRate") = record_options_->sample_rate_combobox()->GetSampleRate();
OLIVE_CONFIG("AudioRecordingChannelLayout") = QVariant::fromValue(record_options_->channel_layout_combobox()->GetChannelLayout());
OLIVE_CONFIG("AudioRecordingBitRate") = QVariant::fromValue(record_options_->bit_rate_slider()->GetValue());
OLIVE_CONFIG("AudioRecordingSampleFormat") = QString::fromStdString(record_options_->sample_format_combobox()->GetSampleFormat().to_string());
OLIVE_CONFIG("AudioRecordingFormat") = record_format_combo_->GetFormat();
OLIVE_CONFIG("AudioRecordingCodec") = record_options_->GetCodec();
OLIVE_CONFIG("AudioRecordingSampleRate") =
record_options_->sample_rate_combobox()->GetSampleRate();
OLIVE_CONFIG("AudioRecordingChannelLayout") = QVariant::fromValue(
record_options_->channel_layout_combobox()->GetChannelLayout());
OLIVE_CONFIG("AudioRecordingBitRate") =
QVariant::fromValue(record_options_->bit_rate_slider()->GetValue());
OLIVE_CONFIG("AudioRecordingSampleFormat") =
QString::fromStdString(record_options_->sample_format_combobox()
->GetSampleFormat()
.to_string());
emit AudioManager::instance()->OutputParamsChanged();
emit AudioManager::instance() -> OutputParamsChanged();
}
void PreferencesAudioTab::RefreshBackends()
{
audio_backend_combobox_->clear();
for (PaHostApiIndex i=0, end=Pa_GetHostApiCount(); i<end; i++) {
const PaHostApiInfo *info = Pa_GetHostApiInfo(i);
audio_backend_combobox_->clear();
for (PaHostApiIndex i = 0, end = Pa_GetHostApiCount(); i < end; i++) {
const PaHostApiInfo *info = Pa_GetHostApiInfo(i);
audio_backend_combobox_->addItem(info->name);
}
audio_backend_combobox_->addItem(info->name);
}
RefreshDevices();
RefreshDevices();
AttemptToSetDevicesFromConfig();
AttemptToSetDevicesFromConfig();
}
void PreferencesAudioTab::RefreshDevices()
{
if (audio_backend_combobox_->count() == 0) {
return;
}
if (audio_backend_combobox_->count() == 0) {
return;
}
PaHostApiIndex host_index = audio_backend_combobox_->currentIndex();
const PaHostApiInfo *host = Pa_GetHostApiInfo(host_index);
PaHostApiIndex host_index = audio_backend_combobox_->currentIndex();
const PaHostApiInfo *host = Pa_GetHostApiInfo(host_index);
audio_output_devices_->clear();
audio_input_devices_->clear();
audio_output_devices_->clear();
audio_input_devices_->clear();
for (int i=0; i<host->deviceCount; i++) {
PaDeviceIndex device_index = Pa_HostApiDeviceIndexToDeviceIndex(host_index, i);
const PaDeviceInfo *device = Pa_GetDeviceInfo(device_index);
for (int i = 0; i < host->deviceCount; i++) {
PaDeviceIndex device_index =
Pa_HostApiDeviceIndexToDeviceIndex(host_index, i);
const PaDeviceInfo *device = Pa_GetDeviceInfo(device_index);
if (device->maxOutputChannels) {
audio_output_devices_->addItem(device->name, device_index);
}
if (device->maxOutputChannels) {
audio_output_devices_->addItem(device->name, device_index);
}
if (device->maxInputChannels) {
audio_input_devices_->addItem(device->name, device_index);
}
}
if (device->maxInputChannels) {
audio_input_devices_->addItem(device->name, device_index);
}
}
}
void PreferencesAudioTab::HardRefreshBackends()
{
AudioManager::instance()->HardReset();
RefreshBackends();
AudioManager::instance()->HardReset();
RefreshBackends();
}
void PreferencesAudioTab::AttemptToSetDevicesFromConfig()
{
// Load with currently active devices
PaDeviceIndex current_output_index = AudioManager::instance()->GetOutputDevice();
PaDeviceIndex current_input_index = AudioManager::instance()->GetInputDevice();
// Load with currently active devices
PaDeviceIndex current_output_index =
AudioManager::instance()->GetOutputDevice();
PaDeviceIndex current_input_index =
AudioManager::instance()->GetInputDevice();
const PaDeviceInfo *current_output = nullptr, *current_input = nullptr;
if (current_output_index != paNoDevice) {
current_output = Pa_GetDeviceInfo(current_output_index);
}
if (current_input_index != paNoDevice) {
current_input = Pa_GetDeviceInfo(current_input_index);
}
const PaDeviceInfo *current_output = nullptr, *current_input = nullptr;
if (current_output_index != paNoDevice) {
current_output = Pa_GetDeviceInfo(current_output_index);
}
if (current_input_index != paNoDevice) {
current_input = Pa_GetDeviceInfo(current_input_index);
}
if (current_output || current_input) {
PaHostApiIndex host = current_output ? current_output->hostApi : current_input->hostApi;
if (current_output || current_input) {
PaHostApiIndex host = current_output ? current_output->hostApi :
current_input->hostApi;
// Set backend accordingly
audio_backend_combobox_->setCurrentIndex(host);
// Set backend accordingly
audio_backend_combobox_->setCurrentIndex(host);
// Device comboboxes should be populated correctly now
if (current_output) {
audio_output_devices_->setCurrentText(current_output->name);
}
// Device comboboxes should be populated correctly now
if (current_output) {
audio_output_devices_->setCurrentText(current_output->name);
}
if (current_input) {
audio_input_devices_->setCurrentText(current_input->name);
}
}
if (current_input) {
audio_input_devices_->setCurrentText(current_input->name);
}
}
}
}
@@ -28,56 +28,55 @@
#include "dialog/export/exportaudiotab.h"
#include "dialog/export/exportformatcombobox.h"
namespace olive {
class PreferencesAudioTab : public ConfigDialogBaseTab
namespace olive
{
Q_OBJECT
public:
PreferencesAudioTab();
virtual void Accept(MultiUndoCommand* command) override;
class PreferencesAudioTab : public ConfigDialogBaseTab {
Q_OBJECT
public:
PreferencesAudioTab();
virtual void Accept(MultiUndoCommand *command) override;
private:
QComboBox* audio_backend_combobox_;
QComboBox *audio_backend_combobox_;
/**
/**
* @brief UI widget for selecting the output audio device
*/
QComboBox* audio_output_devices_;
QComboBox *audio_output_devices_;
/**
/**
* @brief UI widget for selecting the input audio device
*/
QComboBox* audio_input_devices_;
QComboBox *audio_input_devices_;
/**
/**
* @brief UI widget for editing the recording channels
*/
QComboBox* recording_combobox_;
QComboBox *recording_combobox_;
/**
/**
* @brief Button that triggers a refresh of the available audio devices
*/
QPushButton* refresh_devices_btn_;
QPushButton *refresh_devices_btn_;
SampleRateComboBox *output_rate_combo_;
ChannelLayoutComboBox *output_ch_layout_combo_;
SampleFormatComboBox *output_fmt_combo_;
SampleRateComboBox *output_rate_combo_;
ChannelLayoutComboBox *output_ch_layout_combo_;
SampleFormatComboBox *output_fmt_combo_;
ExportFormatComboBox *record_format_combo_;
ExportFormatComboBox *record_format_combo_;
ExportAudioTab *record_options_;
ExportAudioTab *record_options_;
private slots:
void RefreshBackends();
void RefreshBackends();
void RefreshDevices();
void RefreshDevices();
void HardRefreshBackends();
void AttemptToSetDevicesFromConfig();
void HardRefreshBackends();
void AttemptToSetDevicesFromConfig();
};
}
@@ -25,143 +25,140 @@
#include "config/config.h"
namespace olive {
namespace olive
{
PreferencesBehaviorTab::PreferencesBehaviorTab()
{
QVBoxLayout* layout = new QVBoxLayout(this);
QVBoxLayout *layout = new QVBoxLayout(this);
behavior_tree_ = new QTreeWidget();
layout->addWidget(behavior_tree_);
behavior_tree_ = new QTreeWidget();
layout->addWidget(behavior_tree_);
behavior_tree_->setHeaderLabel(tr("Behavior"));
behavior_tree_->setHeaderLabel(tr("Behavior"));
QTreeWidgetItem* general_group = AddParent(tr("General"));
AddItem(tr("Enable hover focus"),
QStringLiteral("HoverFocus"),
tr("Panels will be considered focused when the mouse cursor is over them without having to click them."),
general_group);
AddItem(tr("Enable slider ladder"),
QStringLiteral("UseSliderLadders"),
general_group);
AddItem(tr("Scrolling zooms by default"),
QStringLiteral("ScrollZooms"),
tr("By default, scrolling will move the view around, and holding Ctrl/Cmd will make it zoom instead. "
"Enabling this will switch those, scrolling will zoom by default, and holding Ctrl/Cmd will move the view instead."),
general_group);
QTreeWidgetItem *general_group = AddParent(tr("General"));
AddItem(
tr("Enable hover focus"), QStringLiteral("HoverFocus"),
tr("Panels will be considered focused when the mouse cursor is over them without having to click them."),
general_group);
AddItem(tr("Enable slider ladder"), QStringLiteral("UseSliderLadders"),
general_group);
AddItem(
tr("Scrolling zooms by default"), QStringLiteral("ScrollZooms"),
tr("By default, scrolling will move the view around, and holding Ctrl/Cmd will make it zoom instead. "
"Enabling this will switch those, scrolling will zoom by default, and holding Ctrl/Cmd will move the view instead."),
general_group);
QTreeWidgetItem* audio_group = AddParent(tr("Audio"));
AddItem(tr("Enable audio scrubbing"),
QStringLiteral("AudioScrubbing"),
audio_group);
QTreeWidgetItem *audio_group = AddParent(tr("Audio"));
AddItem(tr("Enable audio scrubbing"), QStringLiteral("AudioScrubbing"),
audio_group);
QTreeWidgetItem* timeline_group = AddParent(tr("Timeline"));
AddItem(tr("Auto-Seek to Imported Clips"),
QStringLiteral("EnableSeekToImport"),
timeline_group);
AddItem(tr("Edit Tool Also Seeks"),
QStringLiteral("EditToolAlsoSeeks"),
timeline_group);
AddItem(tr("Edit Tool Selects Links"),
QStringLiteral("EditToolSelectsLinks"),
timeline_group);
AddItem(tr("Enable Drag Files to Timeline"),
QStringLiteral("EnableDragFilesToTimeline"),
timeline_group);
AddItem(tr("Invert Timeline Scroll Axes"),
QStringLiteral("InvertTimelineScrollAxes"),
tr("Hold ALT on any UI element to switch scrolling axes"),
timeline_group);
AddItem(tr("Seek Also Selects"),
QStringLiteral("SeekAlsoSelects"),
timeline_group);
AddItem(tr("Seek to the End of Pastes"),
QStringLiteral("PasteSeeks"),
timeline_group);
AddItem(tr("Selecting Also Seeks"),
QStringLiteral("SelectAlsoSeeks"),
timeline_group);
QTreeWidgetItem *timeline_group = AddParent(tr("Timeline"));
AddItem(tr("Auto-Seek to Imported Clips"),
QStringLiteral("EnableSeekToImport"), timeline_group);
AddItem(tr("Edit Tool Also Seeks"), QStringLiteral("EditToolAlsoSeeks"),
timeline_group);
AddItem(tr("Edit Tool Selects Links"),
QStringLiteral("EditToolSelectsLinks"), timeline_group);
AddItem(tr("Enable Drag Files to Timeline"),
QStringLiteral("EnableDragFilesToTimeline"), timeline_group);
AddItem(tr("Invert Timeline Scroll Axes"),
QStringLiteral("InvertTimelineScrollAxes"),
tr("Hold ALT on any UI element to switch scrolling axes"),
timeline_group);
AddItem(tr("Seek Also Selects"), QStringLiteral("SeekAlsoSelects"),
timeline_group);
AddItem(tr("Seek to the End of Pastes"), QStringLiteral("PasteSeeks"),
timeline_group);
AddItem(tr("Selecting Also Seeks"), QStringLiteral("SelectAlsoSeeks"),
timeline_group);
QTreeWidgetItem* playback_group = AddParent(tr("Playback"));
AddItem(tr("Ask For Name When Setting Marker"),
QStringLiteral("SetNameWithMarker"),
playback_group);
AddItem(tr("Automatically rewind at the end of a sequence"),
QStringLiteral("AutoSeekToBeginning"),
playback_group);
QTreeWidgetItem *playback_group = AddParent(tr("Playback"));
AddItem(tr("Ask For Name When Setting Marker"),
QStringLiteral("SetNameWithMarker"), playback_group);
AddItem(tr("Automatically rewind at the end of a sequence"),
QStringLiteral("AutoSeekToBeginning"), playback_group);
QTreeWidgetItem* project_group = AddParent(tr("Project"));
AddItem(tr("Drop Files on Media to Replace"),
QStringLiteral("DropFileOnMediaToReplace"),
project_group);
QTreeWidgetItem *project_group = AddParent(tr("Project"));
AddItem(tr("Drop Files on Media to Replace"),
QStringLiteral("DropFileOnMediaToReplace"), project_group);
QTreeWidgetItem* node_group = AddParent(tr("Nodes"));
AddItem(tr("Add Default Effects to New Clips"),
QStringLiteral("AddDefaultEffectsToClips"),
node_group);
AddItem(tr("Auto-Scale By Default"),
QStringLiteral("AutoscaleByDefault"),
node_group);
AddItem(tr("Splitting Clips Copies Dependencies"),
QStringLiteral("SplitClipsCopyNodes"),
tr("Multiple clips can share the same nodes. Disable this to automatically share node "
"dependencies among clips when copying or splitting them."),
node_group);
QTreeWidgetItem *node_group = AddParent(tr("Nodes"));
AddItem(tr("Add Default Effects to New Clips"),
QStringLiteral("AddDefaultEffectsToClips"), node_group);
AddItem(tr("Auto-Scale By Default"), QStringLiteral("AutoscaleByDefault"),
node_group);
AddItem(
tr("Splitting Clips Copies Dependencies"),
QStringLiteral("SplitClipsCopyNodes"),
tr("Multiple clips can share the same nodes. Disable this to automatically share node "
"dependencies among clips when copying or splitting them."),
node_group);
QTreeWidgetItem* opengl_group = AddParent(tr("OpenGL"));
AddItem(tr("Use glFinish"),
QStringLiteral("UseGLFinish"),
opengl_group);
QTreeWidgetItem *opengl_group = AddParent(tr("OpenGL"));
AddItem(tr("Use glFinish"), QStringLiteral("UseGLFinish"), opengl_group);
}
void PreferencesBehaviorTab::Accept(MultiUndoCommand *command)
{
Q_UNUSED(command)
Q_UNUSED(command)
for (auto iterator=config_map_.begin();iterator!=config_map_.end();iterator++) {
OLIVE_CONFIG_STR(iterator.value()) = (iterator.key()->checkState(0) == Qt::Checked);
}
for (auto iterator = config_map_.begin(); iterator != config_map_.end();
iterator++) {
OLIVE_CONFIG_STR(iterator.value()) =
(iterator.key()->checkState(0) == Qt::Checked);
}
}
QTreeWidgetItem* PreferencesBehaviorTab::AddItem(const QString &text, const QString &config_key, const QString& tooltip, QTreeWidgetItem* parent)
QTreeWidgetItem *PreferencesBehaviorTab::AddItem(const QString &text,
const QString &config_key,
const QString &tooltip,
QTreeWidgetItem *parent)
{
QTreeWidgetItem* item = new QTreeWidgetItem({text});
item->setToolTip(0, tooltip);
item->setCheckState(0, OLIVE_CONFIG_STR(config_key).toBool() ? Qt::Checked : Qt::Unchecked);
QTreeWidgetItem *item = new QTreeWidgetItem({ text });
item->setToolTip(0, tooltip);
item->setCheckState(
0, OLIVE_CONFIG_STR(config_key).toBool() ? Qt::Checked : Qt::Unchecked);
config_map_.insert(item, config_key);
config_map_.insert(item, config_key);
if (parent) {
parent->addChild(item);
} else {
behavior_tree_->addTopLevelItem(item);
}
if (parent) {
parent->addChild(item);
} else {
behavior_tree_->addTopLevelItem(item);
}
return item;
return item;
}
QTreeWidgetItem *PreferencesBehaviorTab::AddItem(const QString &text, const QString &config_key, QTreeWidgetItem *parent)
QTreeWidgetItem *PreferencesBehaviorTab::AddItem(const QString &text,
const QString &config_key,
QTreeWidgetItem *parent)
{
return AddItem(text, config_key, QString(), parent);
return AddItem(text, config_key, QString(), parent);
}
QTreeWidgetItem *PreferencesBehaviorTab::AddParent(const QString &text, const QString &tooltip, QTreeWidgetItem *parent)
QTreeWidgetItem *PreferencesBehaviorTab::AddParent(const QString &text,
const QString &tooltip,
QTreeWidgetItem *parent)
{
QTreeWidgetItem* item = new QTreeWidgetItem({text});
item->setToolTip(0, tooltip);
QTreeWidgetItem *item = new QTreeWidgetItem({ text });
item->setToolTip(0, tooltip);
if (parent) {
parent->addChild(item);
} else {
behavior_tree_->addTopLevelItem(item);
}
if (parent) {
parent->addChild(item);
} else {
behavior_tree_->addTopLevelItem(item);
}
return item;
return item;
}
QTreeWidgetItem *PreferencesBehaviorTab::AddParent(const QString &text, QTreeWidgetItem *parent)
QTreeWidgetItem *PreferencesBehaviorTab::AddParent(const QString &text,
QTreeWidgetItem *parent)
{
return AddParent(text, QString(), parent);
return AddParent(text, QString(), parent);
}
}
@@ -25,27 +25,30 @@
#include "dialog/configbase/configdialogbase.h"
namespace olive {
class PreferencesBehaviorTab : public ConfigDialogBaseTab
namespace olive
{
Q_OBJECT
public:
PreferencesBehaviorTab();
virtual void Accept(MultiUndoCommand* command) override;
class PreferencesBehaviorTab : public ConfigDialogBaseTab {
Q_OBJECT
public:
PreferencesBehaviorTab();
virtual void Accept(MultiUndoCommand *command) override;
private:
QTreeWidgetItem *AddParent(const QString& text, const QString &tooltip, QTreeWidgetItem *parent = nullptr);
QTreeWidgetItem *AddParent(const QString& text, QTreeWidgetItem *parent = nullptr);
QTreeWidgetItem *AddParent(const QString &text, const QString &tooltip,
QTreeWidgetItem *parent = nullptr);
QTreeWidgetItem *AddParent(const QString &text,
QTreeWidgetItem *parent = nullptr);
QTreeWidgetItem *AddItem(const QString& text, const QString& config_key, const QString &tooltip, QTreeWidgetItem *parent );
QTreeWidgetItem *AddItem(const QString& text, const QString& config_key, QTreeWidgetItem *parent);
QTreeWidgetItem *AddItem(const QString &text, const QString &config_key,
const QString &tooltip, QTreeWidgetItem *parent);
QTreeWidgetItem *AddItem(const QString &text, const QString &config_key,
QTreeWidgetItem *parent);
QMap<QTreeWidgetItem*, QString> config_map_;
QTreeWidget* behavior_tree_;
QMap<QTreeWidgetItem *, QString> config_map_;
QTreeWidget *behavior_tree_;
};
}
@@ -29,94 +29,105 @@
#include "common/filefunctions.h"
namespace olive {
namespace olive
{
PreferencesDiskTab::PreferencesDiskTab()
{
// Get default disk cache folder
default_disk_cache_folder_ = DiskManager::instance()->GetDefaultCacheFolder();
// Get default disk cache folder
default_disk_cache_folder_ =
DiskManager::instance()->GetDefaultCacheFolder();
QVBoxLayout* outer_layout = new QVBoxLayout(this);
QVBoxLayout *outer_layout = new QVBoxLayout(this);
QGroupBox* disk_management_group = new QGroupBox(tr("Disk Management"));
outer_layout->addWidget(disk_management_group);
QGroupBox *disk_management_group = new QGroupBox(tr("Disk Management"));
outer_layout->addWidget(disk_management_group);
QGridLayout* disk_management_layout = new QGridLayout(disk_management_group);
QGridLayout *disk_management_layout =
new QGridLayout(disk_management_group);
int row = 0;
int row = 0;
disk_management_layout->addWidget(new QLabel(tr("Disk Cache Location:")), row, 0);
disk_management_layout->addWidget(new QLabel(tr("Disk Cache Location:")),
row, 0);
disk_cache_location_ = new PathWidget(default_disk_cache_folder_->GetPath());
disk_management_layout->addWidget(disk_cache_location_, row, 1);
disk_cache_location_ =
new PathWidget(default_disk_cache_folder_->GetPath());
disk_management_layout->addWidget(disk_cache_location_, row, 1);
row++;
row++;
QPushButton* disk_cache_settings_btn = new QPushButton(tr("Disk Cache Settings"));
connect(disk_cache_settings_btn, &QPushButton::clicked, this, [this](){
DiskManager::instance()->ShowDiskCacheSettingsDialog(disk_cache_location_->text(), this);
});
disk_management_layout->addWidget(disk_cache_settings_btn, row, 1);
QPushButton *disk_cache_settings_btn =
new QPushButton(tr("Disk Cache Settings"));
connect(disk_cache_settings_btn, &QPushButton::clicked, this, [this]() {
DiskManager::instance()->ShowDiskCacheSettingsDialog(
disk_cache_location_->text(), this);
});
disk_management_layout->addWidget(disk_cache_settings_btn, row, 1);
row++;
row++;
QGroupBox* cache_behavior = new QGroupBox(tr("Cache Behavior"));
outer_layout->addWidget(cache_behavior);
QGridLayout* cache_behavior_layout = new QGridLayout(cache_behavior);
QGroupBox *cache_behavior = new QGroupBox(tr("Cache Behavior"));
outer_layout->addWidget(cache_behavior);
QGridLayout *cache_behavior_layout = new QGridLayout(cache_behavior);
row = 0;
row = 0;
cache_behavior_layout->addWidget(new QLabel(tr("Cache Ahead:")), row, 0);
cache_behavior_layout->addWidget(new QLabel(tr("Cache Ahead:")), row, 0);
cache_ahead_slider_ = new FloatSlider();
cache_ahead_slider_->SetFormat(tr("%1 seconds"));
cache_ahead_slider_->SetMinimum(0);
cache_ahead_slider_->SetValue(OLIVE_CONFIG("DiskCacheAhead").value<rational>().toDouble());
cache_behavior_layout->addWidget(cache_ahead_slider_, row, 1);
cache_ahead_slider_ = new FloatSlider();
cache_ahead_slider_->SetFormat(tr("%1 seconds"));
cache_ahead_slider_->SetMinimum(0);
cache_ahead_slider_->SetValue(
OLIVE_CONFIG("DiskCacheAhead").value<rational>().toDouble());
cache_behavior_layout->addWidget(cache_ahead_slider_, row, 1);
cache_behavior_layout->addWidget(new QLabel(tr("Cache Behind:")), row, 2);
cache_behavior_layout->addWidget(new QLabel(tr("Cache Behind:")), row, 2);
cache_behind_slider_ = new FloatSlider();
cache_behind_slider_->SetMinimum(0);
cache_behind_slider_->SetFormat(tr("%1 seconds"));
cache_behind_slider_->SetValue(OLIVE_CONFIG("DiskCacheBehind").value<rational>().toDouble());
cache_behavior_layout->addWidget(cache_behind_slider_, row, 3);
cache_behind_slider_ = new FloatSlider();
cache_behind_slider_->SetMinimum(0);
cache_behind_slider_->SetFormat(tr("%1 seconds"));
cache_behind_slider_->SetValue(
OLIVE_CONFIG("DiskCacheBehind").value<rational>().toDouble());
cache_behavior_layout->addWidget(cache_behind_slider_, row, 3);
outer_layout->addStretch();
outer_layout->addStretch();
}
bool PreferencesDiskTab::Validate()
{
if (disk_cache_location_->text() != default_disk_cache_folder_->GetPath()) {
// Disk cache location is changing
if (disk_cache_location_->text() != default_disk_cache_folder_->GetPath()) {
// Disk cache location is changing
// Check if the user is okay with invalidating the current cache
if (!DiskManager::ShowDiskCacheChangeConfirmationDialog(this)) {
return false;
}
// Check if the user is okay with invalidating the current cache
if (!DiskManager::ShowDiskCacheChangeConfirmationDialog(this)) {
return false;
}
// Check validity of the new path
if (!FileFunctions::DirectoryIsValid(disk_cache_location_->text())) {
QMessageBox::critical(this,
tr("Disk Cache"),
tr("Failed to set disk cache location. Access was denied."));
return false;
}
}
// Check validity of the new path
if (!FileFunctions::DirectoryIsValid(disk_cache_location_->text())) {
QMessageBox::critical(
this, tr("Disk Cache"),
tr("Failed to set disk cache location. Access was denied."));
return false;
}
}
return true;
return true;
}
void PreferencesDiskTab::Accept(MultiUndoCommand *command)
{
Q_UNUSED(command)
Q_UNUSED(command)
if (disk_cache_location_->text() != default_disk_cache_folder_->GetPath()) {
default_disk_cache_folder_->SetPath(disk_cache_location_->text());
}
if (disk_cache_location_->text() != default_disk_cache_folder_->GetPath()) {
default_disk_cache_folder_->SetPath(disk_cache_location_->text());
}
OLIVE_CONFIG("DiskCacheBehind") = QVariant::fromValue(rational::fromDouble(cache_behind_slider_->GetValue()));
OLIVE_CONFIG("DiskCacheAhead") = QVariant::fromValue(rational::fromDouble(cache_ahead_slider_->GetValue()));
OLIVE_CONFIG("DiskCacheBehind") = QVariant::fromValue(
rational::fromDouble(cache_behind_slider_->GetValue()));
OLIVE_CONFIG("DiskCacheAhead") = QVariant::fromValue(
rational::fromDouble(cache_ahead_slider_->GetValue()));
}
}
@@ -30,27 +30,26 @@
#include "widget/slider/floatslider.h"
#include "widget/path/pathwidget.h"
namespace olive {
class PreferencesDiskTab : public ConfigDialogBaseTab
namespace olive
{
Q_OBJECT
class PreferencesDiskTab : public ConfigDialogBaseTab {
Q_OBJECT
public:
PreferencesDiskTab();
PreferencesDiskTab();
virtual bool Validate() override;
virtual bool Validate() override;
virtual void Accept(MultiUndoCommand* command) override;
virtual void Accept(MultiUndoCommand *command) override;
private:
PathWidget* disk_cache_location_;
PathWidget *disk_cache_location_;
FloatSlider* cache_ahead_slider_;
FloatSlider *cache_ahead_slider_;
FloatSlider* cache_behind_slider_;
DiskCacheFolder* default_disk_cache_folder_;
FloatSlider *cache_behind_slider_;
DiskCacheFolder *default_disk_cache_folder_;
};
}
@@ -30,162 +30,187 @@
#include "dialog/sequence/sequence.h"
#include "node/project/sequence/sequence.h"
namespace olive {
namespace olive
{
PreferencesGeneralTab::PreferencesGeneralTab()
{
QVBoxLayout* layout = new QVBoxLayout(this);
QVBoxLayout *layout = new QVBoxLayout(this);
{
QGroupBox* global_groupbox = new QGroupBox(tr("Locale"));
QGridLayout* global_layout = new QGridLayout(global_groupbox);
layout->addWidget(global_groupbox);
{
QGroupBox *global_groupbox = new QGroupBox(tr("Locale"));
QGridLayout *global_layout = new QGridLayout(global_groupbox);
layout->addWidget(global_groupbox);
int row = 0;
int row = 0;
// General -> Language
global_layout->addWidget(new QLabel(tr("Language:")), row, 0);
// General -> Language
global_layout->addWidget(new QLabel(tr("Language:")), row, 0);
language_combobox_ = new QComboBox();
language_combobox_ = new QComboBox();
// Add default language (en-US)
QDir language_dir(QStringLiteral(":/ts"));
QStringList languages = language_dir.entryList();
foreach (const QString& l, languages) {
AddLanguage(l);
}
// Add default language (en-US)
QDir language_dir(QStringLiteral(":/ts"));
QStringList languages = language_dir.entryList();
foreach (const QString &l, languages) {
AddLanguage(l);
}
QString current_language = OLIVE_CONFIG("Language").toString();
if (current_language.isEmpty()) {
// No configured language, use system language
current_language = QLocale::system().name();
QString current_language = OLIVE_CONFIG("Language").toString();
if (current_language.isEmpty()) {
// No configured language, use system language
current_language = QLocale::system().name();
// If we don't have a language for this, default to en_US
if (!languages.contains(current_language)) {
current_language = QStringLiteral("en_US");
}
}
language_combobox_->setCurrentIndex(languages.indexOf(current_language));
// If we don't have a language for this, default to en_US
if (!languages.contains(current_language)) {
current_language = QStringLiteral("en_US");
}
}
language_combobox_->setCurrentIndex(
languages.indexOf(current_language));
global_layout->addWidget(language_combobox_, row, 1);
}
global_layout->addWidget(language_combobox_, row, 1);
}
{
QGroupBox* timeline_groupbox = new QGroupBox(tr("Timeline"));
QGridLayout* timeline_layout = new QGridLayout(timeline_groupbox);
layout->addWidget(timeline_groupbox);
{
QGroupBox *timeline_groupbox = new QGroupBox(tr("Timeline"));
QGridLayout *timeline_layout = new QGridLayout(timeline_groupbox);
layout->addWidget(timeline_groupbox);
int row = 0;
int row = 0;
QLabel* autoscroll_lbl = new QLabel(tr("Auto-Scroll Method:"));
autoscroll_lbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
timeline_layout->addWidget(autoscroll_lbl, row, 0);
QLabel *autoscroll_lbl = new QLabel(tr("Auto-Scroll Method:"));
autoscroll_lbl->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
timeline_layout->addWidget(autoscroll_lbl, row, 0);
// ComboBox indices match enum indices
autoscroll_method_ = new QComboBox();
autoscroll_method_->addItem(tr("None"), AutoScroll::kNone);
autoscroll_method_->addItem(tr("Page Scrolling"), AutoScroll::kPage);
autoscroll_method_->addItem(tr("Smooth Scrolling"), AutoScroll::kSmooth);
autoscroll_method_->setCurrentIndex(OLIVE_CONFIG("Autoscroll").toInt());
timeline_layout->addWidget(autoscroll_method_, row, 1);
// ComboBox indices match enum indices
autoscroll_method_ = new QComboBox();
autoscroll_method_->addItem(tr("None"), AutoScroll::kNone);
autoscroll_method_->addItem(tr("Page Scrolling"), AutoScroll::kPage);
autoscroll_method_->addItem(tr("Smooth Scrolling"),
AutoScroll::kSmooth);
autoscroll_method_->setCurrentIndex(OLIVE_CONFIG("Autoscroll").toInt());
timeline_layout->addWidget(autoscroll_method_, row, 1);
row++;
row++;
timeline_layout->addWidget(new QLabel(tr("Rectified Waveforms:")), row, 0);
timeline_layout->addWidget(new QLabel(tr("Rectified Waveforms:")), row,
0);
rectified_waveforms_ = new QCheckBox();
rectified_waveforms_->setChecked(OLIVE_CONFIG("RectifiedWaveforms").toBool());
timeline_layout->addWidget(rectified_waveforms_, row, 1);
rectified_waveforms_ = new QCheckBox();
rectified_waveforms_->setChecked(
OLIVE_CONFIG("RectifiedWaveforms").toBool());
timeline_layout->addWidget(rectified_waveforms_, row, 1);
row++;
row++;
timeline_layout->addWidget(new QLabel(tr("Default Still Image Length:")), row, 0);
timeline_layout->addWidget(
new QLabel(tr("Default Still Image Length:")), row, 0);
default_still_length_ = new RationalSlider();
default_still_length_->SetMinimum(rational(100, 1000));
default_still_length_->SetTimebase(rational(100, 1000));
default_still_length_->SetFormat(tr("%1 seconds"));
default_still_length_->SetValue(OLIVE_CONFIG("DefaultStillLength").value<rational>());
timeline_layout->addWidget(default_still_length_);
}
default_still_length_ = new RationalSlider();
default_still_length_->SetMinimum(rational(100, 1000));
default_still_length_->SetTimebase(rational(100, 1000));
default_still_length_->SetFormat(tr("%1 seconds"));
default_still_length_->SetValue(
OLIVE_CONFIG("DefaultStillLength").value<rational>());
timeline_layout->addWidget(default_still_length_);
}
{
QGroupBox* autorecovery_groupbox = new QGroupBox(tr("Auto-Recovery"));
QGridLayout* autorecovery_layout = new QGridLayout(autorecovery_groupbox);
layout->addWidget(autorecovery_groupbox);
{
QGroupBox *autorecovery_groupbox = new QGroupBox(tr("Auto-Recovery"));
QGridLayout *autorecovery_layout =
new QGridLayout(autorecovery_groupbox);
layout->addWidget(autorecovery_groupbox);
int row = 0;
int row = 0;
autorecovery_layout->addWidget(new QLabel(tr("Enable Auto-Recovery:")), row, 0);
autorecovery_layout->addWidget(new QLabel(tr("Enable Auto-Recovery:")),
row, 0);
autorecovery_enabled_ = new QCheckBox();
autorecovery_enabled_->setChecked(OLIVE_CONFIG("AutorecoveryEnabled").toBool());
autorecovery_layout->addWidget(autorecovery_enabled_, row, 1);
autorecovery_enabled_ = new QCheckBox();
autorecovery_enabled_->setChecked(
OLIVE_CONFIG("AutorecoveryEnabled").toBool());
autorecovery_layout->addWidget(autorecovery_enabled_, row, 1);
row++;
row++;
autorecovery_layout->addWidget(new QLabel(tr("Auto-Recovery Interval:")), row, 0);
autorecovery_layout->addWidget(
new QLabel(tr("Auto-Recovery Interval:")), row, 0);
autorecovery_interval_ = new IntegerSlider();
autorecovery_interval_->SetMinimum(1);
autorecovery_interval_->SetMaximum(60);
autorecovery_interval_->SetFormat(QT_TRANSLATE_N_NOOP("olive::SliderBase", "%n minute(s)"), true);
autorecovery_interval_->SetValue(OLIVE_CONFIG("AutorecoveryInterval").toLongLong());
autorecovery_layout->addWidget(autorecovery_interval_, row, 1);
autorecovery_interval_ = new IntegerSlider();
autorecovery_interval_->SetMinimum(1);
autorecovery_interval_->SetMaximum(60);
autorecovery_interval_->SetFormat(
QT_TRANSLATE_N_NOOP("olive::SliderBase", "%n minute(s)"), true);
autorecovery_interval_->SetValue(
OLIVE_CONFIG("AutorecoveryInterval").toLongLong());
autorecovery_layout->addWidget(autorecovery_interval_, row, 1);
row++;
row++;
autorecovery_layout->addWidget(new QLabel(tr("Maximum Versions Per Project:")), row, 0);
autorecovery_layout->addWidget(
new QLabel(tr("Maximum Versions Per Project:")), row, 0);
autorecovery_maximum_ = new IntegerSlider();
autorecovery_maximum_->SetMinimum(1);
autorecovery_maximum_->SetMaximum(1000);
autorecovery_maximum_->SetValue(OLIVE_CONFIG("AutorecoveryMaximum").toLongLong());
autorecovery_layout->addWidget(autorecovery_maximum_, row, 1);
autorecovery_maximum_ = new IntegerSlider();
autorecovery_maximum_->SetMinimum(1);
autorecovery_maximum_->SetMaximum(1000);
autorecovery_maximum_->SetValue(
OLIVE_CONFIG("AutorecoveryMaximum").toLongLong());
autorecovery_layout->addWidget(autorecovery_maximum_, row, 1);
row++;
row++;
QPushButton* browse_autorecoveries = new QPushButton(tr("Browse Auto-Recoveries"));
connect(browse_autorecoveries, &QPushButton::clicked, Core::instance(), &Core::BrowseAutoRecoveries);
autorecovery_layout->addWidget(browse_autorecoveries, row, 1);
}
QPushButton *browse_autorecoveries =
new QPushButton(tr("Browse Auto-Recoveries"));
connect(browse_autorecoveries, &QPushButton::clicked, Core::instance(),
&Core::BrowseAutoRecoveries);
autorecovery_layout->addWidget(browse_autorecoveries, row, 1);
}
layout->addStretch();
layout->addStretch();
}
void PreferencesGeneralTab::Accept(MultiUndoCommand *command)
{
Q_UNUSED(command)
Q_UNUSED(command)
OLIVE_CONFIG("RectifiedWaveforms") = rectified_waveforms_->isChecked();
OLIVE_CONFIG("RectifiedWaveforms") = rectified_waveforms_->isChecked();
OLIVE_CONFIG("Autoscroll") = autoscroll_method_->currentData();
OLIVE_CONFIG("Autoscroll") = autoscroll_method_->currentData();
OLIVE_CONFIG("DefaultStillLength") = QVariant::fromValue(default_still_length_->GetValue());
OLIVE_CONFIG("DefaultStillLength") =
QVariant::fromValue(default_still_length_->GetValue());
QString set_language = language_combobox_->currentData().toString();
if (QLocale::system().name() == set_language) {
// Language is set to the system, assume this is effectively "auto"
set_language = QString();
}
QString set_language = language_combobox_->currentData().toString();
if (QLocale::system().name() == set_language) {
// Language is set to the system, assume this is effectively "auto"
set_language = QString();
}
// If the language has changed, set it now
if (OLIVE_CONFIG("Language").toString() != set_language) {
OLIVE_CONFIG("Language") = set_language;
Core::instance()->SetLanguage(set_language.isEmpty() ? QLocale::system().name() : set_language);
}
// If the language has changed, set it now
if (OLIVE_CONFIG("Language").toString() != set_language) {
OLIVE_CONFIG("Language") = set_language;
Core::instance()->SetLanguage(
set_language.isEmpty() ? QLocale::system().name() : set_language);
}
OLIVE_CONFIG("AutorecoveryEnabled") = autorecovery_enabled_->isChecked();
OLIVE_CONFIG("AutorecoveryInterval") = QVariant::fromValue(autorecovery_interval_->GetValue());
OLIVE_CONFIG("AutorecoveryMaximum") = QVariant::fromValue(autorecovery_maximum_->GetValue());
Core::instance()->SetAutorecoveryInterval(autorecovery_interval_->GetValue());
OLIVE_CONFIG("AutorecoveryEnabled") = autorecovery_enabled_->isChecked();
OLIVE_CONFIG("AutorecoveryInterval") =
QVariant::fromValue(autorecovery_interval_->GetValue());
OLIVE_CONFIG("AutorecoveryMaximum") =
QVariant::fromValue(autorecovery_maximum_->GetValue());
Core::instance()->SetAutorecoveryInterval(
autorecovery_interval_->GetValue());
}
void PreferencesGeneralTab::AddLanguage(const QString &locale_name)
{
language_combobox_->addItem(tr("%1 (%2)").arg(QLocale(locale_name).nativeLanguageName(),
locale_name));;
language_combobox_->setItemData(language_combobox_->count() - 1, locale_name);
language_combobox_->addItem(tr("%1 (%2)").arg(
QLocale(locale_name).nativeLanguageName(), locale_name));
;
language_combobox_->setItemData(language_combobox_->count() - 1,
locale_name);
}
}
@@ -30,33 +30,32 @@
#include "widget/slider/rationalslider.h"
#include "widget/slider/integerslider.h"
namespace olive {
class PreferencesGeneralTab : public ConfigDialogBaseTab
namespace olive
{
Q_OBJECT
public:
PreferencesGeneralTab();
virtual void Accept(MultiUndoCommand* command) override;
class PreferencesGeneralTab : public ConfigDialogBaseTab {
Q_OBJECT
public:
PreferencesGeneralTab();
virtual void Accept(MultiUndoCommand *command) override;
private:
void AddLanguage(const QString& locale_name);
void AddLanguage(const QString &locale_name);
QComboBox* language_combobox_;
QComboBox *language_combobox_;
QComboBox* autoscroll_method_;
QComboBox *autoscroll_method_;
QCheckBox* rectified_waveforms_;
QCheckBox *rectified_waveforms_;
RationalSlider* default_still_length_;
RationalSlider *default_still_length_;
QCheckBox* autorecovery_enabled_;
QCheckBox *autorecovery_enabled_;
IntegerSlider* autorecovery_interval_;
IntegerSlider* autorecovery_maximum_;
IntegerSlider *autorecovery_interval_;
IntegerSlider *autorecovery_maximum_;
};
}
@@ -29,224 +29,250 @@
#include "window/mainwindow/mainwindow.h"
namespace olive {
PreferencesKeyboardTab::PreferencesKeyboardTab(MainWindow *main_window) :
main_window_(main_window)
namespace olive
{
QVBoxLayout* shortcut_layout = new QVBoxLayout(this);
QLineEdit* key_search_line = new QLineEdit();
key_search_line->setPlaceholderText(tr("Search for action or shortcut"));
connect(key_search_line, SIGNAL(textChanged(const QString &)), this, SLOT(refine_shortcut_list(const QString &)));
PreferencesKeyboardTab::PreferencesKeyboardTab(MainWindow *main_window)
: main_window_(main_window)
{
QVBoxLayout *shortcut_layout = new QVBoxLayout(this);
shortcut_layout->addWidget(key_search_line);
QLineEdit *key_search_line = new QLineEdit();
key_search_line->setPlaceholderText(tr("Search for action or shortcut"));
connect(key_search_line, SIGNAL(textChanged(const QString &)), this,
SLOT(refine_shortcut_list(const QString &)));
keyboard_tree_ = new QTreeWidget();
QTreeWidgetItem* tree_header = keyboard_tree_->headerItem();
tree_header->setText(0, tr("Action"));
tree_header->setText(1, tr("Shortcut"));
shortcut_layout->addWidget(keyboard_tree_);
shortcut_layout->addWidget(key_search_line);
QHBoxLayout* reset_shortcut_layout = new QHBoxLayout();
keyboard_tree_ = new QTreeWidget();
QTreeWidgetItem *tree_header = keyboard_tree_->headerItem();
tree_header->setText(0, tr("Action"));
tree_header->setText(1, tr("Shortcut"));
shortcut_layout->addWidget(keyboard_tree_);
QPushButton* import_shortcut_button = new QPushButton(tr("Import"));
reset_shortcut_layout->addWidget(import_shortcut_button);
connect(import_shortcut_button, SIGNAL(clicked(bool)), this, SLOT(load_shortcut_file()));
QHBoxLayout *reset_shortcut_layout = new QHBoxLayout();
QPushButton* export_shortcut_button = new QPushButton(tr("Export"));
reset_shortcut_layout->addWidget(export_shortcut_button);
connect(export_shortcut_button, SIGNAL(clicked(bool)), this, SLOT(save_shortcut_file()));
QPushButton *import_shortcut_button = new QPushButton(tr("Import"));
reset_shortcut_layout->addWidget(import_shortcut_button);
connect(import_shortcut_button, SIGNAL(clicked(bool)), this,
SLOT(load_shortcut_file()));
reset_shortcut_layout->addStretch();
QPushButton *export_shortcut_button = new QPushButton(tr("Export"));
reset_shortcut_layout->addWidget(export_shortcut_button);
connect(export_shortcut_button, SIGNAL(clicked(bool)), this,
SLOT(save_shortcut_file()));
QPushButton* reset_selected_shortcut_button = new QPushButton(tr("Reset Selected"));
reset_shortcut_layout->addWidget(reset_selected_shortcut_button);
connect(reset_selected_shortcut_button, SIGNAL(clicked(bool)), this, SLOT(reset_default_shortcut()));
reset_shortcut_layout->addStretch();
QPushButton* reset_all_shortcut_button = new QPushButton(tr("Reset All"));
reset_shortcut_layout->addWidget(reset_all_shortcut_button);
connect(reset_all_shortcut_button, SIGNAL(clicked(bool)), this, SLOT(reset_all_shortcuts()));
QPushButton *reset_selected_shortcut_button =
new QPushButton(tr("Reset Selected"));
reset_shortcut_layout->addWidget(reset_selected_shortcut_button);
connect(reset_selected_shortcut_button, SIGNAL(clicked(bool)), this,
SLOT(reset_default_shortcut()));
shortcut_layout->addLayout(reset_shortcut_layout);
QPushButton *reset_all_shortcut_button = new QPushButton(tr("Reset All"));
reset_shortcut_layout->addWidget(reset_all_shortcut_button);
connect(reset_all_shortcut_button, SIGNAL(clicked(bool)), this,
SLOT(reset_all_shortcuts()));
setup_kbd_shortcuts(main_window_->menuBar());
shortcut_layout->addLayout(reset_shortcut_layout);
setup_kbd_shortcuts(main_window_->menuBar());
}
void PreferencesKeyboardTab::Accept(MultiUndoCommand *command)
{
Q_UNUSED(command)
Q_UNUSED(command)
// Save keyboard shortcuts
for (int i=0;i<key_shortcut_fields_.size();i++) {
key_shortcut_fields_.at(i)->set_action_shortcut();
}
// Save keyboard shortcuts
for (int i = 0; i < key_shortcut_fields_.size(); i++) {
key_shortcut_fields_.at(i)->set_action_shortcut();
}
main_window_->SaveLayout();
main_window_->SaveLayout();
}
void PreferencesKeyboardTab::setup_kbd_shortcuts(QMenuBar* menubar) {
QList<QAction*> menus = menubar->actions();
void PreferencesKeyboardTab::setup_kbd_shortcuts(QMenuBar *menubar)
{
QList<QAction *> menus = menubar->actions();
for (int i=0;i<menus.size();i++) {
QMenu* menu = menus.at(i)->menu();
for (int i = 0; i < menus.size(); i++) {
QMenu *menu = menus.at(i)->menu();
QTreeWidgetItem* item = new QTreeWidgetItem(keyboard_tree_);
item->setText(0, menu->title().replace("&", ""));
QTreeWidgetItem *item = new QTreeWidgetItem(keyboard_tree_);
item->setText(0, menu->title().replace("&", ""));
keyboard_tree_->addTopLevelItem(item);
keyboard_tree_->addTopLevelItem(item);
setup_kbd_shortcut_worker(menu, item);
}
setup_kbd_shortcut_worker(menu, item);
}
for (int i=0;i<key_shortcut_items_.size();i++) {
if (!key_shortcut_actions_.at(i)->property("id").isNull()) {
KeySequenceEditor* editor = new KeySequenceEditor(keyboard_tree_, key_shortcut_actions_.at(i));
keyboard_tree_->setItemWidget(key_shortcut_items_.at(i), 1, editor);
key_shortcut_fields_.append(editor);
}
}
for (int i = 0; i < key_shortcut_items_.size(); i++) {
if (!key_shortcut_actions_.at(i)->property("id").isNull()) {
KeySequenceEditor *editor = new KeySequenceEditor(
keyboard_tree_, key_shortcut_actions_.at(i));
keyboard_tree_->setItemWidget(key_shortcut_items_.at(i), 1, editor);
key_shortcut_fields_.append(editor);
}
}
}
void PreferencesKeyboardTab::setup_kbd_shortcut_worker(QMenu* menu, QTreeWidgetItem* parent) {
QList<QAction*> actions = menu->actions();
for (int i=0;i<actions.size();i++) {
QAction* a = actions.at(i);
void PreferencesKeyboardTab::setup_kbd_shortcut_worker(QMenu *menu,
QTreeWidgetItem *parent)
{
QList<QAction *> actions = menu->actions();
for (int i = 0; i < actions.size(); i++) {
QAction *a = actions.at(i);
if (!a->isSeparator() && a->property("keyignore").isNull()) {
QTreeWidgetItem* item = new QTreeWidgetItem(parent);
item->setText(0, a->text().replace("&", ""));
if (!a->isSeparator() && a->property("keyignore").isNull()) {
QTreeWidgetItem *item = new QTreeWidgetItem(parent);
item->setText(0, a->text().replace("&", ""));
parent->addChild(item);
parent->addChild(item);
if (a->menu() != nullptr) {
item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
setup_kbd_shortcut_worker(a->menu(), item);
} else {
key_shortcut_items_.append(item);
key_shortcut_actions_.append(a);
}
}
}
if (a->menu() != nullptr) {
item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
setup_kbd_shortcut_worker(a->menu(), item);
} else {
key_shortcut_items_.append(item);
key_shortcut_actions_.append(a);
}
}
}
}
void PreferencesKeyboardTab::reset_default_shortcut() {
QList<QTreeWidgetItem*> items = keyboard_tree_->selectedItems();
for (int i=0;i<items.size();i++) {
QTreeWidgetItem* item = keyboard_tree_->selectedItems().at(i);
static_cast<KeySequenceEditor*>(keyboard_tree_->itemWidget(item, 1))->reset_to_default();
}
void PreferencesKeyboardTab::reset_default_shortcut()
{
QList<QTreeWidgetItem *> items = keyboard_tree_->selectedItems();
for (int i = 0; i < items.size(); i++) {
QTreeWidgetItem *item = keyboard_tree_->selectedItems().at(i);
static_cast<KeySequenceEditor *>(keyboard_tree_->itemWidget(item, 1))
->reset_to_default();
}
}
void PreferencesKeyboardTab::reset_all_shortcuts() {
if (QMessageBox::question(
this,
tr("Confirm Reset All Shortcuts"),
tr("Are you sure you wish to reset all keyboard shortcuts to their defaults?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
for (int i=0;i<key_shortcut_fields_.size();i++) {
key_shortcut_fields_.at(i)->reset_to_default();
}
}
void PreferencesKeyboardTab::reset_all_shortcuts()
{
if (QMessageBox::question(
this, tr("Confirm Reset All Shortcuts"),
tr("Are you sure you wish to reset all keyboard shortcuts to their defaults?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
for (int i = 0; i < key_shortcut_fields_.size(); i++) {
key_shortcut_fields_.at(i)->reset_to_default();
}
}
}
bool PreferencesKeyboardTab::refine_shortcut_list(const QString &s, QTreeWidgetItem* parent) {
if (parent == nullptr) {
for (int i=0;i<keyboard_tree_->topLevelItemCount();i++) {
refine_shortcut_list(s, keyboard_tree_->topLevelItem(i));
}
bool PreferencesKeyboardTab::refine_shortcut_list(const QString &s,
QTreeWidgetItem *parent)
{
if (parent == nullptr) {
for (int i = 0; i < keyboard_tree_->topLevelItemCount(); i++) {
refine_shortcut_list(s, keyboard_tree_->topLevelItem(i));
}
// Return value is `all_children_are_hidden` which doesn't matter at the top level
return false;
} else {
parent->setExpanded(!s.isEmpty());
// Return value is `all_children_are_hidden` which doesn't matter at the top level
return false;
} else {
parent->setExpanded(!s.isEmpty());
bool all_children_are_hidden = !s.isEmpty();
bool all_children_are_hidden = !s.isEmpty();
for (int i=0;i<parent->childCount();i++) {
QTreeWidgetItem* item = parent->child(i);
if (item->childCount() > 0) {
if (!refine_shortcut_list(s, item)) {
all_children_are_hidden = false;
}
} else {
item->setHidden(false);
if (s.isEmpty()) {
all_children_are_hidden = false;
} else {
QString shortcut;
if (keyboard_tree_->itemWidget(item, 1) != nullptr) {
shortcut = static_cast<QKeySequenceEdit*>(keyboard_tree_->itemWidget(item, 1))->keySequence().toString();
}
if (item->text(0).contains(s, Qt::CaseInsensitive) || shortcut.contains(s, Qt::CaseInsensitive)) {
all_children_are_hidden = false;
} else {
item->setHidden(true);
}
}
}
}
for (int i = 0; i < parent->childCount(); i++) {
QTreeWidgetItem *item = parent->child(i);
if (item->childCount() > 0) {
if (!refine_shortcut_list(s, item)) {
all_children_are_hidden = false;
}
} else {
item->setHidden(false);
if (s.isEmpty()) {
all_children_are_hidden = false;
} else {
QString shortcut;
if (keyboard_tree_->itemWidget(item, 1) != nullptr) {
shortcut = static_cast<QKeySequenceEdit *>(
keyboard_tree_->itemWidget(item, 1))
->keySequence()
.toString();
}
if (item->text(0).contains(s, Qt::CaseInsensitive) ||
shortcut.contains(s, Qt::CaseInsensitive)) {
all_children_are_hidden = false;
} else {
item->setHidden(true);
}
}
}
}
if (parent->text(0).contains(s, Qt::CaseInsensitive)) all_children_are_hidden = false;
if (parent->text(0).contains(s, Qt::CaseInsensitive))
all_children_are_hidden = false;
parent->setHidden(all_children_are_hidden);
parent->setHidden(all_children_are_hidden);
return all_children_are_hidden;
}
return all_children_are_hidden;
}
}
void PreferencesKeyboardTab::load_shortcut_file() {
QString fn = QFileDialog::getOpenFileName(this, tr("Import Keyboard Shortcuts"));
if (!fn.isEmpty()) {
QFile f(fn);
if (f.exists() && f.open(QFile::ReadOnly)) {
QString ba = f.readAll();
f.close();
for (int i=0;i<key_shortcut_fields_.size();i++) {
int index = ba.indexOf(key_shortcut_fields_.at(i)->action_name());
if (index == 0 || (index > 0 && ba.at(index-1) == '\n')) {
while (index < ba.size() && ba.at(index) != '\t') index++;
QString ks;
index++;
while (index < ba.size() && ba.at(index) != '\n') {
ks.append(ba.at(index));
index++;
}
key_shortcut_fields_.at(i)->setKeySequence(ks);
} else {
key_shortcut_fields_.at(i)->reset_to_default();
}
}
} else {
QMessageBox::critical(
this,
tr("Error saving shortcuts"),
tr("Failed to open file for reading")
);
}
}
void PreferencesKeyboardTab::load_shortcut_file()
{
QString fn =
QFileDialog::getOpenFileName(this, tr("Import Keyboard Shortcuts"));
if (!fn.isEmpty()) {
QFile f(fn);
if (f.exists() && f.open(QFile::ReadOnly)) {
QString ba = f.readAll();
f.close();
for (int i = 0; i < key_shortcut_fields_.size(); i++) {
int index =
ba.indexOf(key_shortcut_fields_.at(i)->action_name());
if (index == 0 || (index > 0 && ba.at(index - 1) == '\n')) {
while (index < ba.size() && ba.at(index) != '\t')
index++;
QString ks;
index++;
while (index < ba.size() && ba.at(index) != '\n') {
ks.append(ba.at(index));
index++;
}
key_shortcut_fields_.at(i)->setKeySequence(ks);
} else {
key_shortcut_fields_.at(i)->reset_to_default();
}
}
} else {
QMessageBox::critical(this, tr("Error saving shortcuts"),
tr("Failed to open file for reading"));
}
}
}
void PreferencesKeyboardTab::save_shortcut_file() {
QString fn = QFileDialog::getSaveFileName(this, tr("Export Keyboard Shortcuts"));
if (!fn.isEmpty()) {
QFile f(fn);
if (f.open(QFile::WriteOnly)) {
bool start = true;
for (int i=0;i<key_shortcut_fields_.size();i++) {
QString s = key_shortcut_fields_.at(i)->export_shortcut();
if (!s.isEmpty()) {
if (!start) f.write("\n");
f.write(s.toUtf8());
start = false;
}
}
f.close();
QMessageBox::information(this, tr("Export Shortcuts"), tr("Shortcuts exported successfully"));
} else {
QMessageBox::critical(this, tr("Error saving shortcuts"), tr("Failed to open file for writing"));
}
}
void PreferencesKeyboardTab::save_shortcut_file()
{
QString fn =
QFileDialog::getSaveFileName(this, tr("Export Keyboard Shortcuts"));
if (!fn.isEmpty()) {
QFile f(fn);
if (f.open(QFile::WriteOnly)) {
bool start = true;
for (int i = 0; i < key_shortcut_fields_.size(); i++) {
QString s = key_shortcut_fields_.at(i)->export_shortcut();
if (!s.isEmpty()) {
if (!start)
f.write("\n");
f.write(s.toUtf8());
start = false;
}
}
f.close();
QMessageBox::information(this, tr("Export Shortcuts"),
tr("Shortcuts exported successfully"));
} else {
QMessageBox::critical(this, tr("Error saving shortcuts"),
tr("Failed to open file for writing"));
}
}
}
}
@@ -27,42 +27,42 @@
#include "dialog/configbase/configdialogbase.h"
#include "../keysequenceeditor.h"
namespace olive {
namespace olive
{
class MainWindow;
class PreferencesKeyboardTab : public ConfigDialogBaseTab
{
Q_OBJECT
class PreferencesKeyboardTab : public ConfigDialogBaseTab {
Q_OBJECT
public:
PreferencesKeyboardTab(MainWindow* main_window);
PreferencesKeyboardTab(MainWindow *main_window);
virtual void Accept(MultiUndoCommand* command) override;
virtual void Accept(MultiUndoCommand *command) override;
private slots:
/**
/**
* @brief Show a file dialog to load an external shortcut preset from file
*/
void load_shortcut_file();
void load_shortcut_file();
/**
/**
* @brief Show a file dialog to save an external shortcut preset from file
*/
void save_shortcut_file();
void save_shortcut_file();
/**
/**
* @brief Reset all selected shortcuts in keyboard_tree to their defaults
*/
void reset_default_shortcut();
void reset_default_shortcut();
/**
/**
* @brief Reset all shortcuts indiscriminately to their defaults
*
* This is safe to call directly as it'll ask the user if they wish to do so before it resets.
*/
void reset_all_shortcuts();
void reset_all_shortcuts();
/**
/**
* @brief Shows/hides shortcut entries according to a shortcut query.
*
* This function can be directly connected to QLineEdit::textChanged() for simplicity.
@@ -82,19 +82,20 @@ private slots:
* If so, TRUE is returned so the parent is shown too (even if it doesn't match the search query). If not, FALSE is
* returned so the parent is hidden.
*/
bool refine_shortcut_list(const QString &s, QTreeWidgetItem* parent = nullptr);
bool refine_shortcut_list(const QString &s,
QTreeWidgetItem *parent = nullptr);
private:
/**
/**
* @brief Populate keyboard shortcut panel with keyboard shortcuts from the menu bar
*
* @param menu
*
* A reference to the main application's menu bar. Usually MainWindow::menuBar().
*/
void setup_kbd_shortcuts(QMenuBar* menu);
void setup_kbd_shortcuts(QMenuBar *menu);
/**
/**
* @brief Internal function called by setup_kbd_shortcuts() to traverse down the menu bar's hierarchy and populate the
* shortcut panel.
*
@@ -110,33 +111,32 @@ private:
*
* The parent item to add QTreeWidgetItems to.
*/
void setup_kbd_shortcut_worker(QMenu* menu, QTreeWidgetItem* parent);
void setup_kbd_shortcut_worker(QMenu *menu, QTreeWidgetItem *parent);
/**
/**
* @brief UI widget for editing keyboard shortcuts
*/
QTreeWidget* keyboard_tree_;
QTreeWidget *keyboard_tree_;
/**
/**
* @brief List of keyboard shortcut actions that can be triggered (links with key_shortcut_items and
* key_shortcut_fields)
*/
QVector<QAction*> key_shortcut_actions_;
QVector<QAction *> key_shortcut_actions_;
/**
/**
* @brief List of keyboard shortcut items in keyboard_tree corresponding to existing actions (links with
* key_shortcut_actions and key_shortcut_fields)
*/
QVector<QTreeWidgetItem*> key_shortcut_items_;
QVector<QTreeWidgetItem *> key_shortcut_items_;
/**
/**
* @brief List of keyboard shortcut editing fields in keyboard_tree corresponding to existing actions (links with
* key_shortcut_actions and key_shortcut_fields)
*/
QVector<KeySequenceEditor*> key_shortcut_fields_;
MainWindow *main_window_;
QVector<KeySequenceEditor *> key_shortcut_fields_;
MainWindow *main_window_;
};
}