-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy patheditbandsdialog.cpp
More file actions
124 lines (104 loc) · 3.37 KB
/
Copy patheditbandsdialog.cpp
File metadata and controls
124 lines (104 loc) · 3.37 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "editbandsdialog.h"
#include "ui_editbandsdialog.h"
#include <QAbstractButton>
#include <QFile>
#include "settings.h"
#include "style.h"
extern int g_showMessageBox(QWidget* parent, QMessageBox::Icon icon,
QString title, QString text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
EditBandsDialog::EditBandsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::EditBandsDialog)
{
ui->setupUi(this);
QString style;
style = Style::dialog();
style += "QDialogButtonBox QPushButton {background-color: rgb(26, 45, 98);color: white;}";
setStyleSheet(style);
QFont font = ui->textEdit->font();
font.setPointSize(12);
ui->textEdit->setFont(font);
connect(ui->buttonBox, &QDialogButtonBox::clicked, [=](QAbstractButton* _button){
QPushButton* button = qobject_cast<QPushButton*>(_button);
if(button == ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)) {
loadDefaults();
} else if(button == ui->buttonBox->button(QDialogButtonBox::Save)) {
save();
QDialog::accept();
} else if(button == ui->buttonBox->button(QDialogButtonBox::Cancel)) {
QDialog::reject();
}
});
load();
}
EditBandsDialog::~EditBandsDialog()
{
delete ui;
}
void EditBandsDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
bool EditBandsDialog::loadDefaults()
{
QString ituPath = Settings::programDataPath("itu-regions-defaults.txt");
QFile file(ituPath);
bool res = file.open(QFile::ReadOnly);
if(!res) {
qDebug() << "load defaults" << file.errorString() << ituPath;
g_showMessageBox(this, QMessageBox::Information, "loadDefaults", file.errorString() + ituPath);
return false;
}
m_filePath = ituPath;
ui->textEdit->clear();
QTextStream stream(&file);
ui->textEdit->setText(stream.readAll());
file.close();
return true;
}
bool EditBandsDialog::load()
{
QString ituPath = Settings::programDataPath("itu-regions.txt");
QFile file(ituPath);
if (!file.exists()) {
file.setFileName(Settings::programDataPath("itu-regions-defaults.txt"));
}
bool res = file.open(QFile::ReadOnly);
if(!res) {
qDebug() << "load" << file.errorString() << ituPath;
g_showMessageBox(this, QMessageBox::Information, "load", file.errorString() + ituPath);
return false;
}
m_filePath = ituPath;
ui->textEdit->clear();
QTextStream stream(&file);
ui->textEdit->setText(stream.readAll());
file.close();
return true;
}
bool EditBandsDialog::save()
{
QString ituPath = Settings::programDataPath("itu-regions.txt");
QFile file(ituPath);
bool res = file.open(QFile::Truncate|QFile::WriteOnly|QFile::Text);
if(!res) {
qDebug() << "save" << file.errorString() << ituPath;
g_showMessageBox(this, QMessageBox::Information, "EditBandsDialog::save", file.errorString() + ituPath);
return false;
}
QTextStream stream(&file);
stream << ui->textEdit->toPlainText();
file.flush();
file.close();
m_changed = true;
return true;
}