Horizon
preferences.hpp
1 #pragma once
2 #include "canvas/appearance.hpp"
3 #include "nlohmann/json_fwd.hpp"
4 #include <sigc++/sigc++.h>
5 #include <string>
6 #include "imp/action_catalog.hpp"
7 
8 namespace horizon {
9 using json = nlohmann::json;
10 
11 enum class ActionID;
12 enum class ToolID;
13 enum class InToolActionID;
14 
15 class CanvasPreferences {
16 public:
17  Appearance appearance;
18  void load_from_json(const json &j);
19  void load_colors_from_json(const json &j);
20  json serialize() const;
21  json serialize_colors() const;
22 };
23 
24 class SchematicPreferences {
25 public:
26  bool show_all_junctions = false;
27  bool drag_start_net_line = true;
28  bool bend_non_ortho = true;
29 
30  void load_from_json(const json &j);
31  json serialize() const;
32 };
33 
34 class BoardPreferences {
35 public:
36  bool drag_start_track = true;
37  bool highlight_on_top = true;
38  bool show_text_in_tracks = true;
39  bool show_text_in_vias = true;
40  bool move_using_router = true;
41 
42  void load_from_json(const json &j);
43  json serialize() const;
44 };
45 
46 class KeySequencesPreferences {
47 public:
48  std::map<ActionToolID, std::map<ActionCatalogItem::Availability, std::vector<KeySequence>>> keys;
49 
50  void load_from_json(const json &j);
51  void append_from_json(const json &j);
52  json serialize() const;
53 };
54 
55 class InToolKeySequencesPreferences {
56 public:
57  std::map<InToolActionID, std::vector<KeySequence>> keys;
58 
59  void load_from_json(const json &j);
60  void append_from_json(const json &j);
61  json serialize() const;
62 };
63 
64 class ZoomPreferences {
65 public:
66  bool smooth_zoom_2d = true;
67  bool smooth_zoom_3d = false;
68  bool touchpad_pan = false;
69  float zoom_factor = 50;
70 
71  void load_from_json(const json &j);
72  json serialize() const;
73 };
74 
75 class PartInfoPreferences {
76 public:
77  bool enable = false;
78  std::string url = "https://dev-partinfo.kitspace.org/graphql";
79  std::string preferred_distributor;
80  bool ignore_moq_gt_1 = true;
81  unsigned int max_price_breaks = 3;
82  unsigned int cache_days = 5;
83  bool is_enabled() const;
84 
85  void load_from_json(const json &j);
86  json serialize() const;
87 };
88 
89 class ActionBarPreferences {
90 public:
91  bool enable = true;
92  bool remember = true;
93  bool show_in_tool = true;
94 
95  void load_from_json(const json &j);
96  json serialize() const;
97 };
98 
99 class Preferences {
100 public:
101  Preferences();
102  void set_filename(const std::string &filename);
103  void load();
104  void load_default();
105  void load_from_json(const json &j);
106  void save();
107  static std::string get_preferences_filename();
108  json serialize() const;
109 
110  CanvasPreferences canvas_non_layer;
111  CanvasPreferences canvas_layer;
112  SchematicPreferences schematic;
113  BoardPreferences board;
114  KeySequencesPreferences key_sequences;
115  ZoomPreferences zoom;
116  bool capture_output = false;
117  PartInfoPreferences partinfo;
118  ActionBarPreferences action_bar;
119  InToolKeySequencesPreferences in_tool_key_sequences;
120 
121  bool show_pull_request_tools = false;
122 
123  typedef sigc::signal<void> type_signal_changed;
124  type_signal_changed signal_changed()
125  {
126  return s_signal_changed;
127  }
128 
129 private:
130  std::string filename;
131  type_signal_changed s_signal_changed;
132 };
133 } // namespace horizon
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:166
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61