1 // This file is part of Desktop App Toolkit,
2 // a set of libraries for developing nice desktop applications.
3 //
4 // For license and copyright information please follow this link:
5 // https://github.com/desktop-app/legal/blob/master/LEGAL
6 //
7 #pragma once
8 
9 #include <memory>
10 #include <map>
11 #include <functional>
12 #include <QtCore/QString>
13 #include <QtCore/QSet>
14 #include <QtCore/QMap>
15 #include "codegen/common/cpp_file.h"
16 #include "codegen/style/structure_types.h"
17 
18 namespace codegen {
19 namespace style {
20 namespace structure {
21 class Module;
22 } // namespace structure
23 
24 class Generator {
25 public:
26 	Generator(const structure::Module &module, const QString &destBasePath, const common::ProjectInfo &project, bool isPalette);
27 	Generator(const Generator &other) = delete;
28 	Generator &operator=(const Generator &other) = delete;
29 
30 	bool writeHeader();
31 	bool writeSource();
32 
33 private:
34 	QString typeToString(structure::Type type) const;
35 	QString typeToDefaultValue(structure::Type type) const;
36 	QString valueAssignmentCode(structure::Value value) const;
37 
38 	bool writeHeaderRequiredIncludes();
39 	bool writeHeaderStyleNamespace();
40 	bool writeStructsForwardDeclarations();
41 	bool writeStructsDefinitions();
42 	bool writePaletteDefinition();
43 	bool writeRefsDeclarations();
44 
45 	bool writeIncludesInSource();
46 	bool writeVariableDefinitions();
47 	bool writeRefsDefinition();
48 	bool writeSetPaletteColor();
49 	bool writeVariableInit();
50 	bool writePxValuesInit();
51 	bool writeFontFamiliesInit();
52 	bool writeIconValues();
53 	bool writeIconsInit();
54 
55 	bool collectUniqueValues();
56 
57 	const structure::Module &module_;
58 	QString basePath_, baseName_;
59 	const common::ProjectInfo &project_;
60 	std::unique_ptr<common::CppFile> source_, header_;
61 	bool isPalette_ = false;
62 
63 	QMap<int, bool> pxValues_;
64 	QMap<std::string, int> fontFamilies_;
65 	QMap<QString, int> iconMasks_; // icon file -> index
66 	std::map<QString, int, std::greater<QString>> paletteIndices_;
67 
68 };
69 
70 } // namespace style
71 } // namespace codegen
72