Improve layouts management, allow reordering, add reset button to restore the default layouts.

Related to #407
parent 71333c83
......@@ -22,6 +22,7 @@ install(FILES
timeline_vthumbs.png
kdenliveeffectscategory.rc
kdenlivetranscodingrc
kdenlivedefaultlayouts.rc
DESTINATION ${DATA_INSTALL_DIR}/kdenlive)
install(FILES kdenlive.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR})
......
[Order]
1=Logging
2=Editing
3=Audio
4=Effects
5=Color Correction
[Layouts]
Logging=AAAA/wAAAAD9AAAAAQAAAAIAAAUAAAABVfwBAAAADfsAAAAYAG4AbwB0AGUAcwBfAHcAaQBkAGcAZQB0AAAAAAD/////AAAAZwEAAAP7AAAADgBsAGkAYgByAGEAcgB5AAAAAAD/////AAAAZwEAAAP7AAAAFABzAGMAcgBlAGUAbgBnAHIAYQBiAAAAAAD/////AAAAYAEAAAP7AAAAGgBhAHUAZABpAG8AcwBwAGUAYwB0AHIAdQBtAAAAAAD/////AAAAZgEAAAP8AAAAAAAAAUEAAACLAP////oAAAAAAQAAAAP7AAAAFgBwAHIAbwBqAGUAYwB0AF8AYgBpAG4BAAAAAP////8AAABbAQAAA/sAAAAYAGUAZgBmAGUAYwB0AF8AcwB0AGEAYwBrAQAAAAD/////AAAAVwEAAAP7AAAAHgBjAGwAaQBwAF8AcAByAG8AcABlAHIAdABpAGUAcwAAAAAA/////wAAAGABAAAD/AAAAUIAAADQAAAAiwD////6AAAAAQEAAAAC+wAAAB4AdAByAGEAbgBzAGkAdABpAG8AbgBfAGwAaQBzAHQBAAAAAP////8AAAAEAQAAA/sAAAAWAGUAZgBmAGUAYwB0AF8AbABpAHMAdAEAAAAA/////wAAAAQBAAAD/AAAAhMAAAGJAAABRAD////6AAAAAQEAAAAC+wAAABgAYwBsAGkAcABfAG0AbwBuAGkAdABvAHIBAAAAAP////8AAAFEAQAAA/sAAAAeAHAAcgBvAGoAZQBjAHQAXwBtAG8AbgBpAHQAbwByAQAAAAD/////AAABRAEAAAP7AAAAGAB1AG4AZ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AAA/////wAAAKgBAAAD+wAAABQAcgBnAGIAXwBwAGEAcgBhAGQAZQAAAAAA/////wAAAKQBAAAD+wAAABIAaABpAHMAdABvAGcAcgBhAG0AAAAAAP////8AAAFKAQAAAwAAA/wAAAFFAAAABAAAAAQAAAAIAAAACPwAAAABAAAAAgAAAAIAAAAWAG0AYQBpAG4AVABvAG8AbABCAGEAcgEAAAAA/////wAAAAAAAAAAAAAAGABlAHgAdAByAGEAVABvAG8AbABCAGEAcgEAAAIp/////wAAAAAAAAAA
......@@ -29,30 +29,6 @@ LayoutManagement::LayoutManagement(QObject *parent)
// Prepare layout actions
KActionCategory *layoutActions = new KActionCategory(i18n("Layouts"), pCore->window()->actionCollection());
m_loadLayout = new KSelectAction(i18n("Load Layout"), pCore->window()->actionCollection());
KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kdenlive-layoutsrc"));
KConfigGroup layouts(config, "Layouts");
QStringList names = layouts.keyList();
if (names.isEmpty()) {
//initialize default Layouts
names = QStringList({i18n("Logging"), i18n("Editing"), i18n("Audio"), i18n("Effects"), i18n("Color Correction")});
QList <QByteArray> layoutData = {"AAAA/wAAAAD9AAAAAQAAAAIAAAUAAAABVfwBAAAADfsAAAAYAG4AbwB0AGUAcwBfAHcAaQBkAGcAZQB0AAAAAAD/////AAAAZwEAAAP7AAAADgBsAGkAYgByAGEAcgB5AAAAAAD/////AAAAZwEAAAP7AAAAFABzAGMAcgBlAGUAbgBnAHIAYQBiAAAAAAD/////AAAAYAEAAAP7AAAAGgBhAHUAZABpAG8AcwBwAGUAYwB0AHIAdQBtAAAAAAD/////AAAAZgEAAAP8AAAAAAAAAUEAAACLAP////oAAAAAAQAAAAP7AAAAFgBwAHIAbwBqAGUAYwB0AF8AYgBpAG4BAAAAAP////8AAABbAQAAA/sAAAAYAGUAZgBmAGUAYwB0AF8AcwB0AGEAYwBrAQAAAAD/////AAAAVwEAAAP7AAAAHgBjAGwAaQBwAF8AcAByAG8AcABlAHIAdABpAGUAcw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AAAAP////8AAABgAQAAA/sAAAAaAGEAdQBkAGkAbwBzAHAAZQBjAHQAcgB1AG0AAAAAAP////8AAABmAQAAA/wAAAAAAAABQQAAAGAA////+gAAAAABAAAAAvsAAAAYAGUAZgBmAGUAYwB0AF8AcwB0AGEAYwBrAQAAAAD/////AAAAYAEAAAP7AAAAHgBjAGwAaQBwAF8AcAByAG8AcABlAHIAdABpAGUAcwAAAAAA/////wAAAGABAAAD/AAAAUIAAADQAAAAiwD////6AAAAAQEAAAAC+wAAAB4AdAByAGEAbgBzAGkAdABpAG8AbgBfAGwAaQBzAHQBAAAAAP////8AAAAEAQAAA/sAAAAWAGUAZgBmAGUAYwB0AF8AbABpAHMAdAEAAAAA/////wAAAAQBAAAD/AAAAhMAAAGJAAABRAD////6AAAAAQEAAAAC+wAAABgAYwBsAGkAcABfAG0AbwBuAGkAdABvAHIBAAAAAP////8AAAFEAQAAA/sAAAAeAHAAcgBvAGoAZQBjAHQAXwBtAG8AbgBpAHQAbwByAQAAAAD/////AAABRAEAAAP7AAAAGAB1AG4AZABvAF8AaABpAHMAdABvAHIAeQAAAAAA/////wAAAGABAAAD+wAAAAoAbQBpAHgAZQByAQAAA50AAAFjAAABJAEAAAP7AAAAFgB2AGUAYwB0AG8AcgBzAGMAbwBwAGUAAAAAAP////8AAAEyAQAAA/sAAAAQAHcAYQB2AGUAZgBvAHIAbQAAAAAA/////wAAAKgBAAAD+wAAABQAcgBnAGIAXwBwAGEAcgBhAGQAZQAAAAAA/////wAAAKQBAAAD+wAAABIAaABpAHMAdABvAGcAcgBhAG0AAAAAAP////8AAAFKAQAAAwAAA/wAAAFFAAAABAAAAAQAAAAIAAAACPwAAAABAAAAAgAAAAIAAAAWAG0AYQBpAG4AVABvAG8AbABCAGEAcgEAAAAA/////wAAAAAAAAAAAAAAGABlAHgAdAByAGEAVABvAG8AbABCAGEAcgEAAAIp/////wAAAAAAAAAA"};
int i = 0;
for (const QString &layoutName : names) {
if (i > 1) {
i = 0;
}
layouts.writeEntry(layoutName, layoutData.at(i));
i++;
}
}
int i = 1;
for (const QString &layoutName : names) {
QAction *load = new QAction(QIcon(), i18n("Layout %1: %2", i, layoutName), this);
load->setData(layoutName);
layoutActions->addAction("load_layout" + QString::number(i), load);
m_loadLayout->addAction(load);
i++;
}
// Required to enable user to add the load layout action to toolbar
layoutActions->addAction(QStringLiteral("load_layouts"), m_loadLayout);
connect(m_loadLayout, static_cast<void (KSelectAction::*)(QAction *)>(&KSelectAction::triggered), this, &LayoutManagement::slotLoadLayout);
......@@ -72,7 +48,15 @@ void LayoutManagement::initializeLayouts()
if (m_loadLayout == nullptr) {
return;
}
KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kdenlive-layoutsrc"));
// Load default base layouts
KConfig defaultConfig(QStringLiteral("kdenlivedefaultlayouts.rc"), KConfig::CascadeConfig, QStandardPaths::AppDataLocation);
KConfigGroup defaultOrder(&defaultConfig, "Order");
KConfigGroup defaultLayout(&defaultConfig, "Layouts");
QStringList defaultLayouts;
// Load User defined layouts
KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kdenlive-layoutsrc"), KConfig::NoCascade);
KConfigGroup layoutGroup(config, "Layouts");
// If we don't have any layout saved, check in main config file
if (!layoutGroup.exists()) {
......@@ -84,10 +68,37 @@ void LayoutManagement::initializeLayouts()
}
}
m_loadLayout->clear();
if (!layoutGroup.exists()) {
return;
KConfigGroup layoutOrder(config, "Order");
QStringList entries;
if (!layoutOrder.exists()) {
// This is an old or newly created config file, import defaults
defaultLayouts = defaultOrder.entryMap().values();
entries = layoutGroup.keyList();
} else {
// User sorted list
entries = layoutOrder.entryMap().values();
}
// Add default layouts to user config in they don't exist
bool addedDefault = false;
for (const QString &lay : defaultLayouts)
{
if (!entries.contains(lay)) {
entries.insert(defaultLayouts.indexOf(lay), lay);
layoutGroup.writeEntry(lay, defaultLayout.readEntry(lay));
addedDefault = true;
}
}
if (addedDefault) {
// Write updated order
layoutOrder.deleteGroup();
int j = 1;
for (const QString &entry : entries) {
layoutOrder.writeEntry(QString::number(j), entry);
j++;
}
}
QStringList entries = layoutGroup.keyList();
KActionCategory *layoutActions = new KActionCategory(i18n("Layouts"), pCore->window()->actionCollection());
int i = 1;
for (const QString &layoutName : entries) {
......@@ -109,9 +120,12 @@ void LayoutManagement::slotLoadLayout(QAction *action)
if (layoutId.isEmpty()) {
return;
}
KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kdenlive-layoutsrc"));
KConfigGroup layouts(config, "Layouts");
if (!layouts.hasKey(layoutId)) {
// Error, layout not found
return;
}
QByteArray state = QByteArray::fromBase64(layouts.readEntry(layoutId).toLatin1());
bool timelineVisible = true;
if (state.startsWith("NO-TL")) {
......@@ -143,49 +157,123 @@ void LayoutManagement::slotManageLayouts()
{
KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kdenlive-layoutsrc"));
KConfigGroup layouts(config, "Layouts");
QStringList names = layouts.keyList();
bool nameChanged = false;
KConfigGroup order(config, "Order");
QStringList names = order.entryMap().values();
QDialog d(pCore->window());
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
auto *l = new QVBoxLayout;
d.setLayout(l);
l->addWidget(new QLabel(i18n("Current Layouts"), &d));
QListWidget list(&d);
list.setAlternatingRowColors(true);
l->addWidget(&list);
// Delete button
QToolButton tb(&d);
tb.setIcon(QIcon::fromTheme(QStringLiteral("edit-delete")));
tb.setAutoRaise(true);
connect(&tb, &QToolButton::clicked, [&layouts, &list, &nameChanged]() {
connect(&tb, &QToolButton::clicked, [this, &layouts, &list]() {
if (list.currentItem()) {
layouts.deleteEntry(list.currentItem()->data(Qt::UserRole).toString());
delete list.currentItem();
nameChanged = true;
}
});
tb.setToolTip(i18n("Delete Layout"));
l->addWidget(&tb);
auto *l2 = new QHBoxLayout;
l->addLayout(l2);
l2->addWidget(&tb);
// Up button
QToolButton tb2(&d);
tb2.setIcon(QIcon::fromTheme(QStringLiteral("go-up")));
tb2.setAutoRaise(true);
connect(&tb2, &QToolButton::clicked, [&list]() {
if (list.currentItem() && list.currentRow() > 0) {
int updatedRow = list.currentRow() - 1;
QListWidgetItem *item = list.takeItem(list.currentRow());
list.insertItem(updatedRow, item);
list.setCurrentRow(updatedRow);
}
});
l2->addWidget(&tb2);
// Down button
QToolButton tb3(&d);
tb3.setIcon(QIcon::fromTheme(QStringLiteral("go-down")));
tb3.setAutoRaise(true);
connect(&tb3, &QToolButton::clicked, [&list]() {
if (list.currentItem() && list.currentRow() < list.count() - 1) {
int updatedRow = list.currentRow() + 1;
QListWidgetItem *item = list.takeItem(list.currentRow());
list.insertItem(updatedRow, item);
list.setCurrentRow(updatedRow);
}
});
l2->addWidget(&tb3);
// Reset button
QToolButton tb4(&d);
tb4.setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
tb4.setAutoRaise(true);
tb4.setToolTip(i18n("Reset"));
connect(&tb4, &QToolButton::clicked, [&list, &layouts]() {
// Load default base layouts
KConfig defaultConfig(QStringLiteral("kdenlivedefaultlayouts.rc"), KConfig::CascadeConfig, QStandardPaths::AppDataLocation);
KConfigGroup defaultOrder(&defaultConfig, "Order");
KConfigGroup defaultLayout(&defaultConfig, "Layouts");
QStringList defaultLayoutNames = defaultOrder.entryMap().values();
// Get list of current layouts
QStringList currentNames;
for (int i = 0; i < list.count(); i++) {
currentNames << list.item(i)->data(Qt::UserRole).toString();
}
int pos = 0;
for (const QString &name : defaultLayoutNames) {
if (!currentNames.contains(name)) {
// Insert default layout
QListWidgetItem *item = new QListWidgetItem(name);
item->setData(Qt::UserRole, name);
item->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
list.insertItem(pos, item);
// Write layout data
layouts.writeEntry(name, defaultLayout.readEntry(name));
pos++;
}
}
});
l2->addWidget(&tb4);
connect(&list, &QListWidget::currentRowChanged, [&list, &tb2, &tb3] (int row) {
tb2.setEnabled(row > 0);
tb3.setEnabled(row < list.count() - 1);
});
l2->addStretch();
// Add layouts to list
for (const QString &name : names) {
QListWidgetItem *item = new QListWidgetItem(name, &list);
item->setData(Qt::UserRole, name);
item->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
}
list.setCurrentRow(0);
l->addWidget(buttonBox);
d.connect(buttonBox, &QDialogButtonBox::rejected, &d, &QDialog::reject);
d.connect(buttonBox, &QDialogButtonBox::accepted, &d, &QDialog::accept);
if (d.exec() != QDialog::Accepted) {
return;
}
// Reset order
order.deleteGroup();
// Update order and new names
for (int i = 0; i < list.count(); i++) {
QListWidgetItem *item = list.item(i);
order.writeEntry(QString::number(i + 1), item->data(Qt::UserRole).toString());
if (item->text() != item->data(Qt::UserRole).toString() && !item->text().isEmpty()) {
nameChanged = true;
layouts.writeEntry(item->text(), layouts.readEntry(item->data(Qt::UserRole).toString()));
layouts.deleteEntry(item->data(Qt::UserRole).toString());
}
}
if (nameChanged) {
initializeLayouts();
}
config->reparseConfiguration();
initializeLayouts();
}
void LayoutManagement::slotOnGUISetupDone()
......
......@@ -36,7 +36,6 @@ private slots:
private:
/** @brief Populates the "load layout" menu. */
void initializeLayouts();
KSelectAction *m_loadLayout;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment