-
Notifications
You must be signed in to change notification settings - Fork 3
/
editconfig.cpp
93 lines (80 loc) · 2.38 KB
/
editconfig.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
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
#include "editconfig.h"
#include "ui_editconfig.h"
#include "preferences.h"
EditConfig::EditConfig(const QString &path) :
QDialog(),
m_ui(new Ui::EditConfig),
path (path)
{
m_ui->setupUi(this);
this->setWindowFlags(Qt::WindowCloseButtonHint);
}
void EditConfig::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
void EditConfig::showEvent(QShowEvent *e) {
m_ui->memConfigPath->setPlainText(this->path.replace("\\", "/"));
// Content holen und setzen
m_ui->memConfigContent->setPlainText(this->getContent());
// Dialog öffnen
// Mittig ausrichten
int winW = this->width();
int winH = this->height();
int left (0);
if (Preferences::instance()->isVisible()) {
// Wenn das Hauptfenster offen ist mittig über diesem plazieren
left = Preferences::instance()->geometry().x();
left = left + (Preferences::instance()->geometry().width() - winW) / 2;
} else {
// Desktop auswerten
left = qApp->desktop()->width();
// Die Breite bei virtuellen Desktops vierteln
if (left > 2000 && qApp->desktop()->isVirtualDesktop()) {
left /= 4;
}
}
// Nun die neuen setzen
this->setGeometry(left, (qApp->desktop()->height() / 2) - (winH / 2), winW, winH);
// Öffnen
e->accept();
this->setWindowState(Qt::WindowActive);
}
void EditConfig::on_cmdSave_clicked()
{
// Speichern
QFile saveFile (this->path);
if (!saveFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
return;
}
QTextStream out(&saveFile);
out << m_ui->memConfigContent->toPlainText();
saveFile.close();
// Reload File
m_ui->memConfigContent->setPlainText(this->getContent());
this->close();
}
void EditConfig::on_cmdClose_clicked()
{
this->close();
}
QString EditConfig::getContent() {
QString fileContent ("");
QFile cf (this->path);
if (!cf.open(QIODevice::ReadOnly | QIODevice::Text))
return QLatin1String("");
QTextStream in(&cf);
while (!in.atEnd()) {
QString line = in.readLine();
fileContent += line + QLatin1String("\n");
}
cf.close();
return fileContent;
}