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 
15 public:
16  Appearance appearance;
17  void load_from_json(const json &j);
18  void load_colors_from_json(const json &j);
19  json serialize() const;
20  json serialize_colors() const;
21 };
22 
24 public:
25  bool show_all_junctions = false;
26  bool drag_start_net_line = true;
27 
28  void load_from_json(const json &j);
29  json serialize() const;
30 };
31 
33 public:
34  bool drag_start_track = true;
35  bool highlight_on_top = true;
36  bool show_text_in_tracks = true;
37 
38  void load_from_json(const json &j);
39  json serialize() const;
40 };
41 
43 public:
44  std::map<std::pair<ActionID, ToolID>, std::map<ActionCatalogItem::Availability, std::vector<KeySequence>>> keys;
45 
46  void load_from_json(const json &j);
47  void append_from_json(const json &j);
48  json serialize() const;
49 };
50 
52 public:
53  bool smooth_zoom_2d = true;
54  bool smooth_zoom_3d = false;
55  bool touchpad_pan = false;
56 
57  void load_from_json(const json &j);
58  json serialize() const;
59 };
60 
62 public:
63  bool enable = false;
64  std::string url = "https://dev-partinfo.kitspace.org/graphql";
65  std::string preferred_distributor;
66  bool ignore_moq_gt_1 = true;
67  unsigned int max_price_breaks = 3;
68  unsigned int cache_days = 5;
69  bool is_enabled() const;
70 
71  void load_from_json(const json &j);
72  json serialize() const;
73 };
74 
75 class Preferences {
76 public:
77  Preferences();
78  void set_filename(const std::string &filename);
79  void load();
80  void load_default();
81  void load_from_json(const json &j);
82  void save();
83  static std::string get_preferences_filename();
84  json serialize() const;
85 
86  CanvasPreferences canvas_non_layer;
87  CanvasPreferences canvas_layer;
88  SchematicPreferences schematic;
89  BoardPreferences board;
90  KeySequencesPreferences key_sequences;
91  ZoomPreferences zoom;
92  bool capture_output = false;
93  PartInfoPreferences partinfo;
94 
95  typedef sigc::signal<void> type_signal_changed;
96  type_signal_changed signal_changed()
97  {
98  return s_signal_changed;
99  }
100 
101 private:
102  std::string filename;
103  type_signal_changed s_signal_changed;
104 };
105 } // namespace horizon
nlohmann::json
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61
horizon::SchematicPreferences
Definition: preferences.hpp:23
horizon::Preferences
Definition: preferences.hpp:75
horizon::Appearance
Definition: appearance.hpp:7
horizon::CanvasPreferences
Definition: preferences.hpp:14
nlohmann::basic_json
a class to store JSON values
Definition: json.hpp:165
horizon::PartInfoPreferences
Definition: preferences.hpp:61
horizon::ZoomPreferences
Definition: preferences.hpp:51
horizon::BoardPreferences
Definition: preferences.hpp:32
horizon::KeySequencesPreferences
Definition: preferences.hpp:42