-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
112 lines (92 loc) · 2.62 KB
/
Copy pathmain.cpp
File metadata and controls
112 lines (92 loc) · 2.62 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
#include "MainWindow.h"
#include "SyntaxManager.h"
#include <QApplication>
#include <QMainWindow>
#include <QIcon>
#include <QPixmap>
#include <QPainter>
#include <QBitmap>
#include <QFont>
#include <QFontDatabase>
#include <QFile>
// Function to create a round icon
QIcon createRoundIcon(const QString &iconPath)
{
QPixmap pixmap(iconPath);
if (pixmap.isNull())
{
qWarning() << "Failed to load icon:" << iconPath;
return QIcon();
}
QPixmap roundPixmap(pixmap.size());
roundPixmap.fill(Qt::transparent);
QPainter painter(&roundPixmap);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setBrush(QBrush(pixmap));
painter.setPen(Qt::NoPen);
painter.drawEllipse(0, 0, pixmap.width(), pixmap.height());
return QIcon(roundPixmap);
}
QFont setFont()
{
SyntaxManager::initializeUserSyntaxConfig();
QStringList preferreFontFamilies = {"Monaco", "Menlo", "Consolas", "Courier New", "Monospace"};
QStringList availableFamilies = QFontDatabase::families();
QString chosenFamily;
for(QString family: preferreFontFamilies)
{
if (availableFamilies.contains(family))
{
chosenFamily = family;
break;
}
}
if (chosenFamily.isEmpty())
{
chosenFamily = QFontDatabase::systemFont(QFontDatabase::FixedFont).family();
}
QFont font;
font.setFamily(chosenFamily);
font.setFixedPitch(true);
font.setPointSize(13);
return font;
}
QPalette setPalette()
{
QPalette palette;
palette.setColor(QPalette::Base, QColor("#1e1e1e"));
palette.setColor(QPalette::Text, QColor("#d4d4d4"));
return palette;
}
QString getStyleConfig()
{
QFile styleFile(":/resources/themes/dark.qss");
if (styleFile.open(QFile::ReadOnly))
{
return QString::fromUtf8(styleFile.readAll());
}
return QString{};
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QIcon windowIcon = createRoundIcon(":/resources/app_icon.png");
QFont font = setFont();
QPalette palette = setPalette();
QString theme = getStyleConfig();
if (!theme.isEmpty())
{
app.setStyleSheet(theme);
}
app.setPalette(palette);
app.setFont(font);
app.setWindowIcon(windowIcon);
app.setStyle("Fusion");
app.setApplicationVersion(QStringLiteral("0.2.0"));
app.setOrganizationName(QStringLiteral("Chris Dedman"));
app.setApplicationName(QStringLiteral("CodeAstra"));
app.setApplicationDisplayName(QStringLiteral("CodeAstra"));
QScopedPointer<MainWindow> window(new MainWindow);
window->show();
return app.exec();
}