-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
redasmsettings.cpp
83 lines (62 loc) · 2.76 KB
/
redasmsettings.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
#include "redasmsettings.h"
#include <QStandardPaths>
#include <QFontDatabase>
#include <QApplication>
#include <QDir>
#define CURRENT_WINDOW_GEOMETRY "window_geometry_2"
#define CURRENT_WINDOW_STATE "window_state_2"
QByteArray REDasmSettings::m_defaultstate;
REDasmSettings::REDasmSettings(QObject *parent): QSettings(QDir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)).absoluteFilePath("redasm.conf"), QSettings::IniFormat, parent) { }
bool REDasmSettings::restoreState(QMainWindow *mainwindow)
{
m_defaultstate = mainwindow->saveState(); // Keep default state
if(this->contains(CURRENT_WINDOW_GEOMETRY))
mainwindow->restoreGeometry(this->value(CURRENT_WINDOW_GEOMETRY).toByteArray());
if(this->contains(CURRENT_WINDOW_STATE))
{
mainwindow->restoreState(this->value(CURRENT_WINDOW_STATE).toByteArray());
return true;
}
return false;
}
void REDasmSettings::defaultState(QMainWindow *mainwindow) { mainwindow->restoreState(m_defaultstate); }
void REDasmSettings::saveState(const QMainWindow *mainwindow)
{
this->setValue(CURRENT_WINDOW_GEOMETRY, mainwindow->saveGeometry());
this->setValue(CURRENT_WINDOW_STATE, mainwindow->saveState());
}
void REDasmSettings::clearRecentFiles() { this->setValue("recent_files", QStringList()); }
QStringList REDasmSettings::recentFiles() const { return this->value("recent_files").toStringList(); }
void REDasmSettings::updateRecentFiles(const QString &s)
{
QStringList recents = this->recentFiles();
recents.removeAll(s); // Remove duplicates
recents.prepend(s);
while(recents.length() > MAX_RECENT_FILES)
recents.removeLast();
this->setValue("recent_files", recents);
}
QString REDasmSettings::currentTheme() const { return this->value("selected_theme", "light").toString(); }
QFont REDasmSettings::currentFont() const { return this->value("selected_font", QFontDatabase::systemFont(QFontDatabase::FixedFont)).value<QFont>(); }
int REDasmSettings::currentFontSize() const
{
int size = qApp->font().pixelSize();
if(size == -1)
size = QFontMetrics{qApp->font()}.height();
return this->value("selected_font_size", size).toInt();
}
void REDasmSettings::changeTheme(const QString& theme) { this->setValue("selected_theme", theme.toLower()); }
void REDasmSettings::changeFont(const QFont &font) { this->setValue("selected_font", font); }
void REDasmSettings::changeFontSize(int size) { this->setValue("selected_font_size", size); }
QFont REDasmSettings::font()
{
REDasmSettings settings;
QFont f = settings.currentFont();
if(f.styleHint() == QFont::Monospace)
{
f.setFamily("Monospace"); // Force Monospaced font
f.setStyleHint(QFont::TypeWriter);
}
f.setPointSize(settings.currentFontSize());
return f;
}