css files can be loaded from file

This commit is contained in:
itsmattkc
2019-01-12 02:03:53 +11:00
parent b1bb4b7808
commit 215606772c
6 changed files with 61 additions and 11 deletions
+30 -5
View File
@@ -1,6 +1,7 @@
#include "preferencesdialog.h"
#include "io/config.h"
#include "mainwindow.h"
#include <QMenuBar>
#include <QAction>
@@ -108,6 +109,13 @@ void PreferencesDialog::setup_kbd_shortcuts(QMenuBar* menubar) {
}
void PreferencesDialog::save() {
if (!custom_css_fn->text().isEmpty() && !QFileInfo::exists(custom_css_fn->text())) {
QMessageBox::critical(this, "Invalid CSS File", "CSS file '" + custom_css_fn->text() + "' does not exist.");
return;
}
config.css_path = custom_css_fn->text();
mainWindow->load_css_from_file(config.css_path);
config.recording_mode = recordingComboBox->currentIndex() + 1;
config.img_seq_formats = imgSeqFormatEdit->text();
config.fast_seeking = fastSeekButton->isChecked();
@@ -230,7 +238,14 @@ void PreferencesDialog::save_shortcut_file() {
} else {
QMessageBox::critical(this, "Error saving shortcuts", "Failed to open file for writing");
}
}
}
}
void PreferencesDialog::browse_css_file() {
QString fn = QFileDialog::getOpenFileName(this, "Browse for CSS file");
if (!fn.isEmpty()) {
custom_css_fn->setText(fn);
}
}
void PreferencesDialog::setup_ui() {
@@ -240,19 +255,29 @@ void PreferencesDialog::setup_ui() {
QTabWidget* general_tab = new QTabWidget();
QGridLayout* general_layout = new QGridLayout(general_tab);
general_layout->addWidget(new QLabel("Image sequence formats:"), 0, 0, 1, 1);
general_layout->addWidget(new QLabel("Custom CSS:"), 0, 0, 1, 1);
custom_css_fn = new QLineEdit(general_tab);
custom_css_fn->setText(config.css_path);
general_layout->addWidget(custom_css_fn, 0, 1, 1, 1);
QPushButton* custom_css_browse = new QPushButton("Browse", general_tab);
connect(custom_css_browse, SIGNAL(clicked(bool)), this, SLOT(browse_css_file()));
general_layout->addWidget(custom_css_browse, 0, 2, 1, 1);
general_layout->addWidget(new QLabel("Image sequence formats:"), 1, 0, 1, 1);
imgSeqFormatEdit = new QLineEdit(general_tab);
general_layout->addWidget(imgSeqFormatEdit, 0, 1, 1, 1);
general_layout->addWidget(imgSeqFormatEdit, 1, 1, 1, 2);
general_layout->addWidget(new QLabel("Audio Recording:"), 1, 0, 1, 1);
general_layout->addWidget(new QLabel("Audio Recording:"), 2, 0, 1, 1);
recordingComboBox = new QComboBox(general_tab);
recordingComboBox->addItem("Mono");
recordingComboBox->addItem("Stereo");
general_layout->addWidget(recordingComboBox, 1, 1, 1, 1);
general_layout->addWidget(recordingComboBox, 2, 1, 1, 2);
tabWidget->addTab(general_tab, "General");
QWidget* behavior_tab = new QWidget();
+2
View File
@@ -42,11 +42,13 @@ private slots:
bool refine_shortcut_list(const QString &, QTreeWidgetItem* parent = NULL);
void load_shortcut_file();
void save_shortcut_file();
void browse_css_file();
private:
void setup_ui();
void setup_kbd_shortcut_worker(QMenu* menu, QTreeWidgetItem* parent);
QLineEdit* custom_css_fn;
QLineEdit* imgSeqFormatEdit;
QComboBox* recordingComboBox;
QRadioButton* accurateSeekButton;
+7 -3
View File
@@ -46,7 +46,7 @@ Config::Config()
upcoming_queue_type(FRAME_QUEUE_TYPE_SECONDS),
loop(true),
pause_at_out_point(true),
seek_also_selects(false)
seek_also_selects(false)
{}
void Config::load(QString path) {
@@ -162,7 +162,10 @@ void Config::load(QString path) {
} else if (stream.name() == "SeekAlsoSelects") {
stream.readNext();
seek_also_selects = (stream.text() == "1");
}
} else if (stream.name() == "CSSPath") {
stream.readNext();
css_path = stream.text().toString();
}
}
}
if (stream.hasError()) {
@@ -220,7 +223,8 @@ void Config::save(QString path) {
stream.writeTextElement("UpcomingFrameQueueType", QString::number(upcoming_queue_type));
stream.writeTextElement("Loop", QString::number(loop));
stream.writeTextElement("PauseAtOutPoint", QString::number(pause_at_out_point));
stream.writeTextElement("SeekAlsoSelects", QString::number(seek_also_selects));
stream.writeTextElement("SeekAlsoSelects", QString::number(seek_also_selects));
stream.writeTextElement("CSSPath", css_path);
stream.writeEndElement(); // configuration
stream.writeEndDocument(); // doc
+1
View File
@@ -61,6 +61,7 @@ struct Config {
bool loop;
bool pause_at_out_point;
bool seek_also_selects;
QString css_path;
void load(QString path);
void save(QString path);
+19 -3
View File
@@ -53,6 +53,7 @@
MainWindow* mainWindow;
#define DEFAULT_CSS "QPushButton::checked { background: rgb(25, 25, 25); }"
#define OLIVE_FILE_FILTER "Olive Project (*.ove)"
QTimer autorecovery_timer;
@@ -106,7 +107,7 @@ MainWindow::MainWindow(QWidget *parent, const QString &an) :
// set up style?
qApp->setStyle(QStyleFactory::create("Fusion"));
setStyleSheet("QPushButton::checked { background: rgb(25, 25, 25); }");
setStyleSheet(DEFAULT_CSS);
QPalette darkPalette;
darkPalette.setColor(QPalette::Window, QColor(53,53,53));
@@ -197,7 +198,11 @@ MainWindow::MainWindow(QWidget *parent, const QString &an) :
config_fn = config_path + "/config.xml";
if (QFileInfo::exists(config_fn)) {
config.load(config_fn);
}
if (!config.css_path.isEmpty()) {
load_css_from_file(config.css_path);
}
}
}
alloc_panels(this);
@@ -330,7 +335,18 @@ void MainWindow::save_shortcuts(const QString& fn) {
shortcut_file_io.close();
} else {
qCritical() << "Failed to save shortcut file";
}
}
}
void MainWindow::load_css_from_file(const QString &fn) {
QFile css_file(fn);
if (css_file.exists() && css_file.open(QFile::ReadOnly)) {
setStyleSheet(css_file.readAll());
css_file.close();
} else {
// set default stylesheet
setStyleSheet(DEFAULT_CSS);
}
}
void MainWindow::show_about() {
+2
View File
@@ -23,6 +23,8 @@ public:
void load_shortcuts(const QString &fn, bool first = false);
void save_shortcuts(const QString &fn);
void load_css_from_file(const QString& fn);
public slots:
void undo();
void redo();