This commit is contained in:
itsmattkc
2019-03-01 11:56:32 -08:00
parent 64bad4de4e
commit cabd2f9ca9
6 changed files with 113 additions and 7 deletions
+85 -4
View File
@@ -76,17 +76,71 @@ void MainWindow::setup_layout(bool reset) {
QFile panel_config(get_config_dir().filePath("layout"));
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;
// read XML layout file
QXmlStreamReader stream(&panel_config);
// loop through XML for all data
while (!stream.atEnd()) {
stream.readNextStartElement();
if (stream.name() == "panels") {
restoreState(QByteArray::fromBase64(stream.readElementText().toUtf8()), 0);
stream.readNext();
if (stream.name() == "panels" && stream.isStartElement()) {
// element contains MainWindow layout data to restore
stream.readNext();
restoreState(QByteArray::fromBase64(stream.text().toUtf8()), 0);
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();
@@ -904,10 +958,37 @@ void MainWindow::closeEvent(QCloseEvent *e) {
QFile panel_config(get_config_dir().filePath("layout"));
if (panel_config.open(QFile::WriteOnly)) {
QXmlStreamWriter stream(&panel_config);
stream.setAutoFormatting(true);
stream.writeStartDocument();
stream.writeStartElement("layout");
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();
panel_config.close();
} else {
+11 -2
View File
@@ -24,7 +24,6 @@
#include <QVBoxLayout>
#include <QResizeEvent>
#include <QScrollBar>
#include <QSplitter>
#include <QScrollArea>
#include <QPushButton>
#include <QSpacerItem>
@@ -321,7 +320,7 @@ void EffectControls::setup_ui() {
hlayout->setSpacing(0);
hlayout->setMargin(0);
QSplitter* splitter = new QSplitter();
splitter = new QSplitter();
splitter->setOrientation(Qt::Horizontal);
splitter->setChildrenCollapsible(false);
@@ -507,6 +506,16 @@ void EffectControls::Retranslate() {
UpdateTitle();
}
void EffectControls::LoadLayoutState(const QByteArray &data)
{
splitter->restoreState(data);
}
QByteArray EffectControls::SaveLayoutState()
{
return splitter->saveState();
}
void EffectControls::update_scrollbar() {
verticalScrollBar->setMaximum(qMax(0, effects_area->height() - keyframeView->height() - headers->height()));
verticalScrollBar->setPageStep(verticalScrollBar->height());
+5
View File
@@ -29,6 +29,7 @@
#include <QLabel>
#include <QScrollBar>
#include <QHBoxLayout>
#include <QSplitter>
#include "project/projectelements.h"
#include "ui/timelineheader.h"
@@ -78,6 +79,9 @@ public:
void add_effect_paste_action(QMenu* menu);
virtual void Retranslate() override;
virtual void LoadLayoutState(const QByteArray& data) override;
virtual QByteArray SaveLayoutState() override;
public slots:
void cut();
void copy(bool del = false);
@@ -112,6 +116,7 @@ private:
QString panel_name;
int mode;
QSplitter* splitter;
QPushButton* btnAddVideoEffect;
QLabel* lblVideoEffects;
QPushButton* btnAddVideoTransition;
+1 -1
View File
@@ -1185,7 +1185,7 @@ void Project::save_project(bool autorecovery) {
sequence_id = 1;
QFile file(autorecovery ? autorecovery_filename : olive::ActiveProjectFilename);
if (!file.open(QIODevice::WriteOnly/* | QIODevice::Text*/)) {
if (!file.open(QIODevice::WriteOnly)) {
qCritical() << "Could not open file";
return;
}
+7
View File
@@ -37,6 +37,13 @@ Panel::~Panel()
olive::panels.removeAll(this);
}
void Panel::LoadLayoutState(const QByteArray &) {}
QByteArray Panel::SaveLayoutState()
{
return QByteArray();
}
void Panel::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
+4
View File
@@ -28,7 +28,11 @@ class Panel : public QDockWidget {
public:
Panel(QWidget* parent = nullptr);
virtual ~Panel() override;
virtual void Retranslate() = 0;
virtual void LoadLayoutState(const QByteArray& data);
virtual QByteArray SaveLayoutState();
protected:
virtual void changeEvent(QEvent* e) override;
};