SILICON
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2025. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <QApplication>
19#include <QCommandLineParser>
20#include <QCoreApplication>
21#include <QEvent>
22#include <QEventLoop>
23#include <QFont>
24#include <QFontDatabase>
25#include <QIcon>
26#include <QLabel>
27#include <QMainWindow>
28
29#ifdef SILICON_HAS_FONTCONFIG
30 #include <fontconfig/fontconfig.h>
31#endif
32
33#include <iostream>
34
36#include <logging/logger.hpp>
37
39#include <ui/shell/icons.hpp>
42
43using namespace SILICON::logging;
44using namespace SILICON::ui;
45
46#if defined(__linux__) && defined(SILICON_HAS_SANITIZERS)
47extern "C" const char* __lsan_default_suppressions()
48{
49 // Qt's Wayland platform plugin can leave proxies behind while it shuts down.
50 // They are allocated and owned by Qt/libwayland, outside SILICON's control.
51 return "leak:wl_display_read_events\n"
52 "leak:QtWaylandClient::QWaylandDisplay::createSurface\n";
53}
54#endif
55
56int siliconMain(int argc, char** argv)
57{
59 Logger::addConsoleSink(std::clog);
61
62 int exitCode = 0;
63
64 {
65 QApplication app(argc, argv);
66 QApplication::setApplicationName("SILICON");
67 QApplication::setApplicationVersion(SILICON_VERSION);
68
69 // LOAD THE FONTS
70 QFontDatabase::addApplicationFont(":/fonts/Chango.ttf");
71 QFontDatabase::addApplicationFont(":/fonts/Quicksand.ttf");
72 QFontDatabase::addApplicationFont(":/fonts/NovaMono.ttf");
73
74 // Installing a style resets Qt's class-specific fonts. Assign them afterwards.
75 QApplication::setStyle(new SiliconStyle);
76
77 QFont regular("Quicksand");
78 regular.setPixelSize(14);
79 QApplication::setFont(regular);
80
81 QFont bold = regular;
82 bold.setWeight(QFont::Bold);
83 QApplication::setFont(bold, "QPushButton");
84
85 QFont monospace("NovaMono");
86 monospace.setPixelSize(14);
87 monospace.setFixedPitch(true);
88 QApplication::setFont(monospace, "QPlainTextEdit");
89
90 QApplication::setWindowIcon(Icon("silicon"));
91
92 // Command Line Parser
93 QCommandLineParser parser;
94 parser.setApplicationDescription("SILICON: Simulation of Interconnected Logical\
95 Inputs, Circuits, and Output Nodes");
96 parser.addHelpOption();
97 parser.addVersionOption();
98 parser.process(app);
99
100#ifdef __MINGW32__
101 QFont font = QApplication::font();
102 font.setHintingPreference(QFont::PreferNoHinting);
103 QApplication::setFont(font);
104#endif
105
106 // Register all components explicitly
109
111 registerAllGUIComponents(guiFactory);
112
113 {
114 SiliconWindow mainWindow{};
115 mainWindow.resize(QGuiApplication::primaryScreen()->size() * 0.6);
116 mainWindow.show();
117
119
120 Logger uiLog("ui");
121 uiLog.info("SILICON UI started");
122
123 exitCode = QApplication::exec();
124 mainWindow.close();
125 }
126
127 QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
128 QCoreApplication::processEvents(QEventLoop::AllEvents);
129 QFontDatabase::removeAllApplicationFonts();
130 }
131
132#ifdef SILICON_HAS_FONTCONFIG
133 FcFini();
134#endif
135
137 return exitCode;
138}
139
140int main(int argc, char** argv)
141{
142 return siliconMain(argc, argv);
143}
static ComponentRegistry & instance()
static void initialize()
Definition logger.cpp:180
static void setMinimumLevel(LogLevel level)
Definition logger.cpp:231
static void shutdown()
Definition logger.cpp:187
static void addConsoleSink(std::ostream &stream)
Definition logger.cpp:208
Factory for creating graphical circuit components.
static GUIComponentFactory & instance()
Gets the global singleton factory instance.
Main window for the SILICON graphical circuit editor.
int siliconMain(int argc, char **argv)
Definition main.cpp:56
int main(int argc, char **argv)
Definition main.cpp:140
void registerAllComponents(ComponentRegistry &registry)
const SILICON::logging::Logger uiLog("ui")
void registerAllGUIComponents(GUIComponentFactory &factory)