SILICON
Loading...
Searching...
No Matches
uiUtils.cpp
Go to the documentation of this file.
1#include "uiUtils.hpp"
2
3#include <string_view>
4
5#include <QAction>
6
8#include <ui/shell/icons.hpp>
9
10namespace SILICON::ui {
11
13{
14 switch (mode) {
15 case InteractionMode::NORMAL_MODE: return QStringLiteral("NORMAL");
16 case InteractionMode::COMPONENT_PLACING_MODE:
17 return QStringLiteral("COMPONENT PLACING");
18 case InteractionMode::WIRE_CREATION_MODE: return QStringLiteral("WIRE CREATION");
19 case InteractionMode::PAN_MODE: return QStringLiteral("PAN");
20 case InteractionMode::SIMULATION_MODE: return QStringLiteral("SIMULATION");
21 }
22
23 throw std::logic_error("Unhandled InteractionMode in interactionModeName");
24}
25
27{
28 std::string_view iconName;
29 switch (SILICON::project::categoryOf(type)) {
30 case SILICON::project::DocumentCategory::Diagram: iconName = "circuit-board"; break;
31 case SILICON::project::DocumentCategory::Code: iconName = "code"; break;
32 case SILICON::project::DocumentCategory::Architecture: iconName = "cpu"; break;
33 case SILICON::project::DocumentCategory::Binary: iconName = "file"; break;
34 }
35 return Icon(QString::fromUtf8(iconName.data(), static_cast<qsizetype>(iconName.size())));
36}
37
38QAction* makeAction(QObject* parent, const QIcon& icon, const QString& text,
39 const QString& statusTip)
40{
41 auto* action = new QAction(icon, text, parent);
42 if (!statusTip.isEmpty())
43 action->setStatusTip(statusTip);
44 return action;
45}
46
47QAction* makeAction(QObject* parent, const QString& text, const QString& statusTip)
48{
49 auto* action = new QAction(text, parent);
50 if (!statusTip.isEmpty())
51 action->setStatusTip(statusTip);
52 return action;
53}
54
55} // namespace SILICON::ui
constexpr DocumentCategory categoryOf(const DocumentType type)
QAction * makeAction(QObject *parent, const QIcon &icon, const QString &text, const QString &statusTip)
Definition uiUtils.cpp:38
QIcon categoryIcon(const SILICON::project::DocumentType type)
Definition uiUtils.cpp:26
QString interactionModeName(const InteractionMode mode)
Definition uiUtils.cpp:12
DiagramScene::InteractionMode InteractionMode
Alias for DiagramScene::InteractionMode.