Commit 5f11bb1e authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Update layout management: add 5 default layouts, allow renaming/deleting.

Related to #407
parent e8cc6d25
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="kdenlive" version="187" translationDomain="kdenlive">
<kpartgui name="kdenlive" version="188" translationDomain="kdenlive">
<MenuBar>
<Menu name="file" >
<Action name="file_save"/>
......@@ -231,14 +231,10 @@
<Menu name="view" noMerge="1" ><text>View</text>
<Action name="fullscreen" />
<Separator />
<Menu name="layout_save_as" ><text>Save Layout As</text>
<Action name="save_layout1" />
<Action name="save_layout2" />
<Action name="save_layout3" />
<Action name="save_layout4" />
</Menu>
<Action name="load_layouts" />
<Menu name="dockareaoriantation" ><text>Dock Area Orientation</text>
<Action name="load_layouts" />
<Action name="save_layout" />
<Action name="manage_layout" />
<Menu name="dockareaoriantation" ><text>Dock Area Orientation</text>
<Action name="vertical_dockareaorientation" />
<Action name="horizontal_dockareaorientation" />
</Menu>
......
......@@ -14,6 +14,9 @@ the Free Software Foundation, either version 3 of the License, or
#include "mainwindow.h"
#include <QInputDialog>
#include <QMenu>
#include <QDialog>
#include <QDialogButtonBox>
#include <QListWidget>
#include <KConfigGroup>
#include <KSharedConfig>
......@@ -26,26 +29,47 @@ 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());
for (int i = 1; i < 5; ++i) {
QAction *load = new QAction(QIcon(), i18n("Layout %1", i), this);
load->setData('_' + QString::number(i));
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 <QByteAr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/////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);
QAction *save = new QAction(QIcon(), i18n("Save As Layout %1", i), this);
save->setData('_' + QString::number(i));
layoutActions->addAction("save_layout" + QString::number(i), save);
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);
QAction *saveLayout = new QAction(i18n("Save Layout"), pCore->window()->actionCollection());
layoutActions->addAction(QStringLiteral("save_layout"), saveLayout);
connect(saveLayout, &QAction::triggered, this, &LayoutManagement::slotSaveLayout);
QAction *manageLayout = new QAction(i18n("Manage Layouts"), pCore->window()->actionCollection());
layoutActions->addAction(QStringLiteral("manage_layout"), manageLayout);
connect(manageLayout, &QAction::triggered, this, &LayoutManagement::slotManageLayouts);
connect(pCore->window(), &MainWindow::GUISetupDone, this, &LayoutManagement::slotOnGUISetupDone);
}
void LayoutManagement::initializeLayouts()
{
QMenu *saveLayout = static_cast<QMenu *>(pCore->window()->factory()->container(QStringLiteral("layout_save_as"), pCore->window()));
if (m_loadLayout == nullptr || saveLayout == nullptr) {
if (m_loadLayout == nullptr) {
return;
}
KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kdenlive-layoutsrc"));
......@@ -63,30 +87,15 @@ void LayoutManagement::initializeLayouts()
return;
}
QStringList entries = layoutGroup.keyList();
QList<QAction *> loadActions = m_loadLayout->actions();
QList<QAction *> saveActions = saveLayout->actions();
for (int i = 1; i < 5; ++i) {
// Rename the layouts actions
for (const QString &key : entries) {
if (key.endsWith(QStringLiteral("_%1").arg(i))) {
// Found previously saved layout
QString layoutName = key.section(QLatin1Char('_'), 0, -2);
for (int j = 0; j < loadActions.count(); ++j) {
if (loadActions.at(j)->data().toString().endsWith('_' + QString::number(i))) {
loadActions[j]->setText(layoutName);
loadActions[j]->setData(key);
break;
}
}
for (int j = 0; j < saveActions.count(); ++j) {
if (saveActions.at(j)->data().toString().endsWith('_' + QString::number(i))) {
saveActions[j]->setText(i18n("Save as %1", layoutName));
saveActions[j]->setData(key);
break;
}
}
}
}
m_loadLayout->clear();
KActionCategory *layoutActions = new KActionCategory(i18n("Layouts"), pCore->window()->actionCollection());
int i = 1;
for (const QString &layoutName : entries) {
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++;
}
}
......@@ -113,35 +122,73 @@ void LayoutManagement::slotLoadLayout(QAction *action)
pCore->window()->restoreState(state);
}
void LayoutManagement::slotSaveLayout(QAction *action)
void LayoutManagement::slotSaveLayout()
{
QString originallayoutName = action->data().toString();
int layoutId = originallayoutName.section(QLatin1Char('_'), -1).toInt();
QString layoutName = QInputDialog::getText(pCore->window(), i18n("Save Layout"), i18n("Layout name:"), QLineEdit::Normal,
originallayoutName.section(QLatin1Char('_'), 0, -2));
QString layoutName = QInputDialog::getText(pCore->window(), i18n("Save Layout"), i18n("Layout name:"), QLineEdit::Normal);
if (layoutName.isEmpty()) {
return;
}
KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kdenlive-layoutsrc"));
KConfigGroup layouts(config, "Layouts");
layouts.deleteEntry(originallayoutName);
QByteArray st = pCore->window()->saveState();
if (!pCore->window()->timelineVisible()) {
st.prepend("NO-TL");
}
layoutName.append('_' + QString::number(layoutId));
layouts.writeEntry(layoutName, st.toBase64());
initializeLayouts();
}
void LayoutManagement::slotOnGUISetupDone()
void LayoutManagement::slotManageLayouts()
{
QMenu *saveLayout = static_cast<QMenu *>(pCore->window()->factory()->container(QStringLiteral("layout_save_as"), pCore->window()));
if (saveLayout) {
connect(saveLayout, &QMenu::triggered, this, &LayoutManagement::slotSaveLayout);
KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kdenlive-layoutsrc"));
KConfigGroup layouts(config, "Layouts");
QStringList names = layouts.keyList();
bool nameChanged = false;
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);
l->addWidget(&list);
QToolButton tb(&d);
tb.setIcon(QIcon::fromTheme(QStringLiteral("edit-delete")));
tb.setAutoRaise(true);
connect(&tb, &QToolButton::clicked, [&layouts, &list, &nameChanged]() {
if (list.currentItem()) {
layouts.deleteEntry(list.currentItem()->data(Qt::UserRole).toString());
delete list.currentItem();
nameChanged = true;
}
});
tb.setToolTip(i18n("Delete Layout"));
l->addWidget(&tb);
for (const QString &name : names) {
QListWidgetItem *item = new QListWidgetItem(name, &list);
item->setData(Qt::UserRole, name);
item->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
}
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;
}
for (int i = 0; i < list.count(); i++) {
QListWidgetItem *item = list.item(i);
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();
}
}
void LayoutManagement::slotOnGUISetupDone()
{
initializeLayouts();
}
......@@ -26,9 +26,11 @@ public:
private slots:
/** @brief Saves the widget layout. */
void slotSaveLayout(QAction *action);
void slotSaveLayout();
/** @brief Loads a saved widget layout. */
void slotLoadLayout(QAction *action);
/** @brief Manage layout. */
void slotManageLayouts();
void slotOnGUISetupDone();
private:
......
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