fixed #571
This commit is contained in:
+85
-4
@@ -76,17 +76,71 @@ void MainWindow::setup_layout(bool reset) {
|
|||||||
QFile panel_config(get_config_dir().filePath("layout"));
|
QFile panel_config(get_config_dir().filePath("layout"));
|
||||||
if (panel_config.exists() && panel_config.open(QFile::ReadOnly)) {
|
if (panel_config.exists() && panel_config.open(QFile::ReadOnly)) {
|
||||||
|
|
||||||
// default to resetting unless we find the tag in the XML file
|
// default to resetting unless we find layout data in the XML file
|
||||||
reset = true;
|
reset = true;
|
||||||
|
|
||||||
// read XML layout file
|
// read XML layout file
|
||||||
QXmlStreamReader stream(&panel_config);
|
QXmlStreamReader stream(&panel_config);
|
||||||
|
|
||||||
|
// loop through XML for all data
|
||||||
while (!stream.atEnd()) {
|
while (!stream.atEnd()) {
|
||||||
stream.readNextStartElement();
|
stream.readNext();
|
||||||
if (stream.name() == "panels") {
|
|
||||||
restoreState(QByteArray::fromBase64(stream.readElementText().toUtf8()), 0);
|
if (stream.name() == "panels" && stream.isStartElement()) {
|
||||||
|
|
||||||
|
// element contains MainWindow layout data to restore
|
||||||
|
stream.readNext();
|
||||||
|
restoreState(QByteArray::fromBase64(stream.text().toUtf8()), 0);
|
||||||
reset = false;
|
reset = false;
|
||||||
|
|
||||||
|
} else if (stream.name() == "panel" && stream.isStartElement()) {
|
||||||
|
|
||||||
|
// element contains layout data specific to a panel, we'll find the panel and load it
|
||||||
|
|
||||||
|
// get panel name from XML attribute
|
||||||
|
QString panel_name;
|
||||||
|
const QXmlStreamAttributes& attributes = stream.attributes();
|
||||||
|
for (int i=0;i<attributes.size();i++) {
|
||||||
|
const QXmlStreamAttribute& attr = attributes.at(i);
|
||||||
|
if (attr.name() == "name") {
|
||||||
|
panel_name = attr.value().toString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (panel_name.isEmpty()) {
|
||||||
|
qWarning() << "Layout file specified data for a panel but didn't specify a name. Layout wasn't loaded.";
|
||||||
|
} else {
|
||||||
|
// loop through panels for a panel with the same name
|
||||||
|
|
||||||
|
bool found_panel = false;
|
||||||
|
|
||||||
|
for (int i=0;i<olive::panels.size();i++) {
|
||||||
|
|
||||||
|
Panel* panel = olive::panels.at(i);
|
||||||
|
if (panel->objectName() == panel_name) {
|
||||||
|
|
||||||
|
// found the panel, so we can load its state
|
||||||
|
stream.readNext();
|
||||||
|
panel->LoadLayoutState(QByteArray::fromBase64(stream.text().toUtf8()));
|
||||||
|
|
||||||
|
// we found it, no more need to loop through panels
|
||||||
|
found_panel = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found_panel) {
|
||||||
|
qWarning() << "Panel specified in layout data doesn't exist. Layout wasn't loaded.";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
panel_config.close();
|
panel_config.close();
|
||||||
@@ -904,10 +958,37 @@ void MainWindow::closeEvent(QCloseEvent *e) {
|
|||||||
QFile panel_config(get_config_dir().filePath("layout"));
|
QFile panel_config(get_config_dir().filePath("layout"));
|
||||||
if (panel_config.open(QFile::WriteOnly)) {
|
if (panel_config.open(QFile::WriteOnly)) {
|
||||||
QXmlStreamWriter stream(&panel_config);
|
QXmlStreamWriter stream(&panel_config);
|
||||||
|
stream.setAutoFormatting(true);
|
||||||
stream.writeStartDocument();
|
stream.writeStartDocument();
|
||||||
|
|
||||||
|
stream.writeStartElement("layout");
|
||||||
|
|
||||||
stream.writeTextElement("panels", saveState(0).toBase64());
|
stream.writeTextElement("panels", saveState(0).toBase64());
|
||||||
|
|
||||||
|
// if the panels have any specific layout data to save, save it now
|
||||||
|
for (int i=0;i<olive::panels.size();i++) {
|
||||||
|
QByteArray layout_data = olive::panels.at(i)->SaveLayoutState();
|
||||||
|
|
||||||
|
if (!layout_data.isEmpty()) {
|
||||||
|
|
||||||
|
// layout data is matched with the panel's objectName(), which we can't do if the panel has no name
|
||||||
|
const QString& panel_name = olive::panels.at(i)->objectName();
|
||||||
|
if (panel_name.isEmpty()) {
|
||||||
|
qWarning() << "Panel" << i << "had layout state data but no objectName(). Layout was not saved.";
|
||||||
|
} else {
|
||||||
|
stream.writeStartElement("panel");
|
||||||
|
|
||||||
|
stream.writeAttribute("name", panel_name);
|
||||||
|
|
||||||
|
stream.writeCharacters(layout_data.toBase64());
|
||||||
|
|
||||||
|
stream.writeEndElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.writeEndElement(); // layout
|
||||||
|
|
||||||
stream.writeEndDocument();
|
stream.writeEndDocument();
|
||||||
panel_config.close();
|
panel_config.close();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QSplitter>
|
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
@@ -321,7 +320,7 @@ void EffectControls::setup_ui() {
|
|||||||
hlayout->setSpacing(0);
|
hlayout->setSpacing(0);
|
||||||
hlayout->setMargin(0);
|
hlayout->setMargin(0);
|
||||||
|
|
||||||
QSplitter* splitter = new QSplitter();
|
splitter = new QSplitter();
|
||||||
splitter->setOrientation(Qt::Horizontal);
|
splitter->setOrientation(Qt::Horizontal);
|
||||||
splitter->setChildrenCollapsible(false);
|
splitter->setChildrenCollapsible(false);
|
||||||
|
|
||||||
@@ -507,6 +506,16 @@ void EffectControls::Retranslate() {
|
|||||||
UpdateTitle();
|
UpdateTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EffectControls::LoadLayoutState(const QByteArray &data)
|
||||||
|
{
|
||||||
|
splitter->restoreState(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray EffectControls::SaveLayoutState()
|
||||||
|
{
|
||||||
|
return splitter->saveState();
|
||||||
|
}
|
||||||
|
|
||||||
void EffectControls::update_scrollbar() {
|
void EffectControls::update_scrollbar() {
|
||||||
verticalScrollBar->setMaximum(qMax(0, effects_area->height() - keyframeView->height() - headers->height()));
|
verticalScrollBar->setMaximum(qMax(0, effects_area->height() - keyframeView->height() - headers->height()));
|
||||||
verticalScrollBar->setPageStep(verticalScrollBar->height());
|
verticalScrollBar->setPageStep(verticalScrollBar->height());
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
#include <QSplitter>
|
||||||
|
|
||||||
#include "project/projectelements.h"
|
#include "project/projectelements.h"
|
||||||
#include "ui/timelineheader.h"
|
#include "ui/timelineheader.h"
|
||||||
@@ -78,6 +79,9 @@ public:
|
|||||||
void add_effect_paste_action(QMenu* menu);
|
void add_effect_paste_action(QMenu* menu);
|
||||||
|
|
||||||
virtual void Retranslate() override;
|
virtual void Retranslate() override;
|
||||||
|
|
||||||
|
virtual void LoadLayoutState(const QByteArray& data) override;
|
||||||
|
virtual QByteArray SaveLayoutState() override;
|
||||||
public slots:
|
public slots:
|
||||||
void cut();
|
void cut();
|
||||||
void copy(bool del = false);
|
void copy(bool del = false);
|
||||||
@@ -112,6 +116,7 @@ private:
|
|||||||
QString panel_name;
|
QString panel_name;
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
|
QSplitter* splitter;
|
||||||
QPushButton* btnAddVideoEffect;
|
QPushButton* btnAddVideoEffect;
|
||||||
QLabel* lblVideoEffects;
|
QLabel* lblVideoEffects;
|
||||||
QPushButton* btnAddVideoTransition;
|
QPushButton* btnAddVideoTransition;
|
||||||
|
|||||||
+1
-1
@@ -1185,7 +1185,7 @@ void Project::save_project(bool autorecovery) {
|
|||||||
sequence_id = 1;
|
sequence_id = 1;
|
||||||
|
|
||||||
QFile file(autorecovery ? autorecovery_filename : olive::ActiveProjectFilename);
|
QFile file(autorecovery ? autorecovery_filename : olive::ActiveProjectFilename);
|
||||||
if (!file.open(QIODevice::WriteOnly/* | QIODevice::Text*/)) {
|
if (!file.open(QIODevice::WriteOnly)) {
|
||||||
qCritical() << "Could not open file";
|
qCritical() << "Could not open file";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,13 @@ Panel::~Panel()
|
|||||||
olive::panels.removeAll(this);
|
olive::panels.removeAll(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Panel::LoadLayoutState(const QByteArray &) {}
|
||||||
|
|
||||||
|
QByteArray Panel::SaveLayoutState()
|
||||||
|
{
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
void Panel::changeEvent(QEvent *e)
|
void Panel::changeEvent(QEvent *e)
|
||||||
{
|
{
|
||||||
if (e->type() == QEvent::LanguageChange) {
|
if (e->type() == QEvent::LanguageChange) {
|
||||||
|
|||||||
@@ -28,7 +28,11 @@ class Panel : public QDockWidget {
|
|||||||
public:
|
public:
|
||||||
Panel(QWidget* parent = nullptr);
|
Panel(QWidget* parent = nullptr);
|
||||||
virtual ~Panel() override;
|
virtual ~Panel() override;
|
||||||
|
|
||||||
virtual void Retranslate() = 0;
|
virtual void Retranslate() = 0;
|
||||||
|
|
||||||
|
virtual void LoadLayoutState(const QByteArray& data);
|
||||||
|
virtual QByteArray SaveLayoutState();
|
||||||
protected:
|
protected:
|
||||||
virtual void changeEvent(QEvent* e) override;
|
virtual void changeEvent(QEvent* e) override;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user