YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
jointItemTree.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
7#include "jointItemTree.h"
8#include "ui_jointItemTree.h"
9
10JointItemTree::JointItemTree(int index, QWidget *parent) :
11 QWidget(parent),
12 m_ui(new Ui::jointItemTree),
13 m_index(index)
14{
15 m_ui->setupUi(this);
16 setAttribute(Qt::WA_StyledBackground, true);
17
18 this->setContextMenuPolicy(Qt::CustomContextMenu);
19
20 connect(this, SIGNAL(customContextMenuRequested(QPoint)),
21 this, SLOT(onShowContextMenu(QPoint)));
22
23 m_rightClickMenuTitle = new QAction(this);
24 m_rightClickMenuTitle->setEnabled(false);
25 m_rightClickMenu.addAction(m_rightClickMenuTitle);
26 m_rightClickMenu.addSeparator();
27
28 m_idleAction = new QAction("Idle joint", this);
29 connect(m_idleAction, SIGNAL(triggered()), this, SLOT(onIdleClicked()));
30 m_rightClickMenu.addAction(m_idleAction);
31
32 m_runAction = new QAction("Run joint", this);
33 connect(m_runAction, SIGNAL(triggered()), this, SLOT(onRunClicked()));
34 m_rightClickMenu.addAction(m_runAction);
35
36 m_pidAction = new QAction("Show joint PID", this);
37 connect(m_pidAction, SIGNAL(triggered()), this, SLOT(onPIDClicked()));
38 m_rightClickMenu.addAction(m_pidAction);
39
40 m_homeAction = new QAction("Home joint", this);
41 connect(m_homeAction, SIGNAL(triggered()), this, SLOT(onHomeClicked()));
42 m_rightClickMenu.addAction(m_homeAction);
43}
44
46{
47 delete m_ui;
48}
49
50void JointItemTree::setJointName(const QString &name)
51{
52 m_ui->jointName->setText(name);
53}
54
56{
57 return m_ui->jointName->text();
58}
59
61{
62
63 if (!m_modeSet || mode != m_mode)
64 {
65 const int text_r = 35;
66 const int text_g = 38;
67 const int text_b = 41;
68 setColor(QColor(text_r, text_g, text_b), JointItem::GetModeColor(mode));
69
70 switch (mode) {
73 {
74 m_homeAction->setEnabled(true);
75 m_runAction->setEnabled(true);
76 m_idleAction->setEnabled(true);
77 m_pidAction->setEnabled(true);
78 break;
79 }
80 case JointItem::Idle:
84 case JointItem::Pwm:
86 {
87 m_homeAction->setEnabled(false);
88 m_runAction->setEnabled(true);
89 m_idleAction->setEnabled(true);
90 m_pidAction->setEnabled(true);
91 break;
92 }
93
95 m_homeAction->setEnabled(false);
96 m_runAction->setEnabled(false);
97 m_idleAction->setEnabled(true);
98 m_pidAction->setEnabled(true);
99 break;
100 }
105 default:
106 {
107 m_homeAction->setEnabled(false);
108 m_runAction->setEnabled(false);
109 m_idleAction->setEnabled(false);
110 m_pidAction->setEnabled(false);
111 break;
112 }
113 }
114
115 m_ui->jointMode->setText(JointItem::GetModeString(mode));
116 m_modeSet = true;
117 m_mode = mode;
118 }
119}
120
122{
123 return m_mode;
124}
125
126void JointItemTree::setColor(const QColor &color, const QColor &background)
127{
128 setAutoFillBackground(true);
129 QString stileSheet = QString("color: rgb(%1, %2, %3); background-color: rgb(%4, %5, %6)")
130 .arg(color.red()).arg(color.green()).arg(color.blue())
131 .arg(background.red()).arg(background.green()).arg(background.blue());
132 setStyleSheet(stileSheet);
133}
134
136{
137 emit sig_jointClicked(m_index);
138}
139
141{
142 QSize size = QWidget::sizeHint();
143 if (m_desiredWidth > 0)
144 {
145 size.setWidth(m_desiredWidth);
146 }
147 if (m_desiredHeight > 0)
148 {
149 size.setHeight(m_desiredHeight);
150 }
151
152 return size;
153}
154
156{
157 m_desiredWidth = w;
158 m_desiredHeight = h;
159}
160
162{
163 m_rightClickMenuTitle->setText(m_ui->jointName->text() + " menu");
164 m_rightClickMenu.exec(mapToGlobal(pos));
165}
166
168{
169 emit sig_homeClicked(m_index);
170}
171
173{
174 emit sig_runClicked(m_index);
175}
176
178{
179 emit sig_idleClicked(m_index);
180}
181
183{
184 emit sig_PIDClicked(m_index);
185}
int SIGNAL(int pid, int signum)
void sig_runClicked(int index)
void setJointMode(const JointItem::JointState &mode)
void sig_homeClicked(int index)
void setJointName(const QString &name)
void sig_jointClicked(int index)
void setDesiredSize(int w, int h)
~JointItemTree() override
JointItemTree(int index, QWidget *parent=nullptr)
void sig_idleClicked(int index)
void mouseDoubleClickEvent(QMouseEvent *) override
QSize sizeHint() const override
JointItem::JointState jointMode() const
QString jointName() const
void sig_PIDClicked(int index)
void onShowContextMenu(QPoint pos)
static QColor GetModeColor(JointState mode)
Definition jointitem.cpp:57
static QString GetModeString(JointState mode)
@ PositionDirect
Definition jointitem.h:33
@ Disconnected
Definition jointitem.h:34
@ Calibrating
Definition jointitem.h:34
@ NotConfigured
Definition jointitem.h:34
Definition aboutdlg.h:11