aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/dialogs/cssdebugdialog.cpp
blob: 6e4513869fa2ebf10bc4c2bae368f9dc80d2c3df (plain) (blame)
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
#include "cssdebugdialog.h"
#include "ui_cssdebugdialog.h"
#include "mainwindow.h"
#include "themetuner.h"
#include "uiconfig.h"
#include <QApplication>
#include <QPushButton>

CssDebugDialog::CssDebugDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CssDebugDialog)
{
    ui->setupUi(this);
    connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));

    appliedCss = CFG_UI.General.CustomCss.get();
    if (appliedCss.isEmpty())
        appliedCss = MAINWINDOW->styleSheet();

    ui->cssEdit->setPlainText(appliedCss);
    updateState();

    connect(ui->cssEdit, SIGNAL(textChanged()), this, SLOT(updateState()));
}

CssDebugDialog::~CssDebugDialog()
{
    delete ui;
}

void CssDebugDialog::buttonClicked(QAbstractButton* button)
{
    if (ui->buttonBox->standardButton(button) == QDialogButtonBox::RestoreDefaults)
    {
        ui->cssEdit->setPlainText(THEME_TUNER->getDefaultCss());
    }
    else if (ui->buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole)
    {
        appliedCss = ui->cssEdit->toPlainText();
        CFG_UI.General.CustomCss.set(appliedCss);
        MAINWINDOW->setStyleSheet(appliedCss);
    }

    updateState();
}

void CssDebugDialog::updateState()
{
    ui->buttonBox->button(QDialogButtonBox::Apply)->setEnabled(ui->cssEdit->toPlainText() != appliedCss);
}

void CssDebugDialog::closeEvent(QCloseEvent*)
{
    deleteLater();
}