HAL
selection_details_icon_provider.cpp
Go to the documentation of this file.
3 #include "gui/gui_globals.h"
8 #include <QDebug>
9 #include <QImage>
10 
11 namespace hal
12 {
13  SelectionDetailsIconProvider* SelectionDetailsIconProvider::inst = nullptr;
14 
15  SettingsItemDropdown* SelectionDetailsIconProvider::sIconSizeSetting = nullptr;
16 
17  bool SelectionDetailsIconProvider::sSettingsInitialized = initSettings();
18 
19  bool SelectionDetailsIconProvider::initSettings()
20  {
21  sIconSizeSetting = new SettingsItemDropdown(
22  "Right Corner Icon Size",
23  "selection_details/icon_size",
24  SelectionDetailsIconProvider::IconSize::BigIcon,
25  "Appearance:Selection Details",
26  "Specifies the size of the icon in the upper right corner of selection details or if the icon is omitted (NoIcon)."
27  );
29  return true;
30  }
31 
32 
34  {
35  Q_ASSERT(gNetlistRelay); // make sure it does not get called before event relay is installed
36  if (!inst) inst = new SelectionDetailsIconProvider();
37  return inst;
38  }
39 
40  SelectionDetailsIconProvider::SelectionDetailsIconProvider(QObject *parent)
41  : QObject(parent)
42  {
43  connect(MainWindow::sSettingStyle, &SettingsItemDropdown::intChanged,this,&SelectionDetailsIconProvider::loadIcons);
45  loadIcons(MainWindow::sSettingStyle->value().toInt());
46  }
47 
49  {
50  auto it = mModuleIcons.find(id);
51  if (it == mModuleIcons.end()) return;
52  delete it.value();
54  mModuleIcons[id] = new QIcon(gui_utility::getStyledSvgIcon("all->" + col.name(QColor::HexRgb), ":/icons/ne_module"));
55  }
56 
57  void SelectionDetailsIconProvider::loadIcons(int istyle)
58  {
60  QString solidColor = (theme == MainWindow::Light) ? "all->#000000" : "all->#ffffff";
61 
62  if (!mDefaultIcons.isEmpty())
63  {
64  for (auto it = mDefaultIcons.begin(); it != mDefaultIcons.end(); ++it)
65  delete it.value();
66  }
67 
68  mDefaultIcons[ModuleIcon] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/ne_module"));
69  mDefaultIcons[GateIcon] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/ne_gate"));
70  mDefaultIcons[NetIcon] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/ne_net"));
71  mDefaultIcons[ViewDir] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/view-dir"));
72  mDefaultIcons[ViewCtx] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/view-ctx"));
73 
74  if (!mGateIcons.isEmpty())
75  {
76  for (auto it = mGateIcons.begin(); it != mGateIcons.end(); ++it)
77  delete it.value();
78  }
79 
80  mGateIcons[(int)GateTypeProperty::c_buffer] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/ne_gate_buffer"));
81  mGateIcons[(int)GateTypeProperty::c_inverter] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/ne_gate_inverter"));
82  mGateIcons[(int)GateTypeProperty::c_and] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/ne_gate_and"));
83  mGateIcons[(int)GateTypeProperty::c_nand] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/ne_gate_nand"));
84  mGateIcons[(int)GateTypeProperty::c_or] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/ne_gate_or"));
85  mGateIcons[(int)GateTypeProperty::c_nor] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/ne_gate_nor"));
86  mGateIcons[(int)GateTypeProperty::c_xor] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/ne_gate_xor"));
87  mGateIcons[(int)GateTypeProperty::c_xnor] = new QIcon(gui_utility::getStyledSvgIcon(solidColor, ":/icons/ne_gate_xnor"));
88  }
89 
91  {
92  Gate* g = nullptr;
93  QColor col;
94 
95  switch (catg)
96  {
97  case GateIcon:
98  g = gNetlist->get_gate_by_id(itemId);
99  if (g)
100  {
101  std::vector<GateTypeProperty> prop = g->get_type()->get_property_list();
102  if (!prop.empty())
103  {
104  const QIcon* gateTypeIcon = mGateIcons.value((int)prop.at(0));
105  if (gateTypeIcon) return gateTypeIcon;
106  }
107  }
108  break;
109  case ModuleIcon:
110  col = gNetlistRelay->getModuleColor(itemId);
111  if (col.isValid())
112  {
113  auto it = mModuleIcons.find(itemId);
114  if (it != mModuleIcons.end())
115  return it.value();
116  QIcon* newIcon = new QIcon(gui_utility::getStyledSvgIcon("all->" + col.name(QColor::HexRgb), ":/icons/ne_module"));
117  mModuleIcons[itemId] = newIcon;
118  return newIcon;
119  }
120  break;
121  default:
122  break;
123  }
124  return mDefaultIcons.value(catg);
125  }
126 }
Definition: gate.h:58
static SettingsItemDropdown * sSettingStyle
Definition: main_window.h:302
void moduleColorChanged(u32 id) const
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
ModuleColorManager * getModuleColorManager() const
QColor getModuleColor(const u32 id)
const QIcon * getIcon(IconCategory catg, u32 itemId)
static SelectionDetailsIconProvider * instance()
static SettingsItemDropdown * sIconSizeSetting
Q_ENUM(IconSize) private Q_SLOTS void handleModuleColorChanged(u32 id)
void intChanged(int value)
QIcon getStyledSvgIcon(const QString &from_to_colors_enabled, const QString &svg_path, QString from_to_colors_disabled=QString())
Definition: graphics.cpp:60
Netlist * gNetlist
Definition: plugin_gui.cpp:80
NetlistRelay * gNetlistRelay
Definition: plugin_gui.cpp:81
quint32 u32
i32 id
bool isValid() const const
QString name() const const
T & value() const const
QHash::iterator begin()
QHash::iterator end()
QHash::iterator find(const Key &key)
bool isEmpty() const const
const T value(const Key &key) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)