-
Notifications
You must be signed in to change notification settings - Fork 0
/
styleeditordialog.cpp
60 lines (50 loc) · 1.35 KB
/
styleeditordialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "styleeditordialog.h"
#include "ui_styleeditordialog.h"
#include <QFile>
#include <QMessageBox>
#include <QApplication>
StyleEditorDialog::StyleEditorDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::StyleEditorDialog)
{
ui->setupUi(this);
loadStyle();
}
StyleEditorDialog::~StyleEditorDialog()
{
delete ui;
}
void StyleEditorDialog::on_btnSave_clicked()
{
QFile file("stylesheet-dev.css");
if (!file.open(QFile::WriteOnly)) {
QMessageBox::critical(this, "Save Error", file.errorString());
return;
}
file.write(ui->txtStyle->toPlainText().toLatin1());
file.close();
}
void StyleEditorDialog::on_btnRevert_clicked()
{
if (QMessageBox::warning(this, "Confirm", "Are you sure?", QMessageBox::Yes| QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
return;
loadStyle();
}
void StyleEditorDialog::on_txtStyle_textChanged()
{
applyStyle();
}
void StyleEditorDialog::loadStyle () {
QFile file("stylesheet-dev.css");
if (!file.open(QFile::ReadOnly)) {
QMessageBox::critical(this, "Load Error", file.errorString());
return;
}
QByteArray data = file.readAll();
file.close();
ui->txtStyle->setPlainText(QString::fromLatin1(data));
applyStyle();
}
void StyleEditorDialog::applyStyle () {
qApp->setStyleSheet(ui->txtStyle->toPlainText());
}