SkillDashboardConfigWindow.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * \package ArmarXGui::gui-plugins::OperatorViewWidgetController
19 * \author Leonie Leven
20 * \date 2024
21 * \copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
27#include <RobotAPI/gui-plugins/ui_SkillDashboardConfig.h>
28
29#include <QHBoxLayout>
30#include <QLabel>
31#include <QPushButton>
32#include <QStylePlugin>
33#include <QtWidgets>
34#include <QDesktopServices>
35#include <QUrl>
36
37namespace armarx
38{
39
40
42 QDialog(parent), ui(new Ui::SkillDashboardConfig)
43 {
44 ui->setupUi(this);
45 this->setWindowTitle("Configure Skill");
46 connect(ui->dialogButtons, &QDialogButtonBox::accepted, this, &QDialog::accept);
47 connect(ui->dialogButtons, &QDialogButtonBox::rejected, this, &QDialog::reject);
48 connect(ui->linkButton, &QPushButton::clicked, this, &SkillDashboardConfigWindow::openNerdFontSearch);
49 connect(ui->buttonName,
50 &QLineEdit::textChanged,
51 this,
52 &SkillDashboardConfigWindow::onShortcutNameChanged);
53 }
54
55 void
56 SkillDashboardConfigWindow::onShortcutNameChanged()
57 {
59 }
60
61 QString
63 {
64 return ui->buttonName->text();
65 }
66
67 QString
69 {
70 return ui->iconName->text();
71 }
72
73 void
74 SkillDashboardConfigWindow::openNerdFontSearch()
75 {
76 QDesktopServices::openUrl(QUrl("https://www.nerdfonts.com/cheat-sheet"));
77 return;
78 }
79
80 QString
82 {
83 return ui->skillName->text();
84 }
85
86 QString
88 {
89 return ui->skillArgs->toPlainText();
90 }
91
92 void
94 {
95 ui->buttonName->setText(QString::fromStdString(name));
96 }
97
98 void
100 {
101 ui->skillName->setText(QString::fromStdString(id));
102 }
103
104 void
105 SkillDashboardConfigWindow::setIconName(const std::string& iconName)
106 {
107 ui->iconName->setText(QString::fromStdString(iconName));
108 }
109
110 void
112 {
113 ui->skillArgs->setPlainText(QString::fromStdString(config));
114 }
115
116 void
118 {
119 ui->infoText->setText(QString::fromStdString(info));
120 ui->infoText->setStyleSheet("color: red;");
121 }
122
127
128 MessageWidget::MessageWidget(bool withShowAll, QWidget* parent) : QWidget(parent)
129 {
130 this->hboxLayout = new QHBoxLayout(this);
131 this->hboxLayout->setContentsMargins(6, 2, 6, 2);
132 this->hboxLayout->setSpacing(4);
133
134 this->label = new QLabel(this);
135 this->label->setWordWrap(true);
136 this->label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
137 this->label->setStyleSheet("color: red;");
138 this->hboxLayout->addWidget(label);
139
140
141 if (withShowAll)
142 {
143 this->closeButton = new QPushButton("✕", this);
144 this->closeButton->setFixedSize(18, 18);
145 this->closeButton->setStyleSheet(R"(
146 QPushButton {
147 border: none;
148 font-weight: bold;
149 color: #444;
150 }
151 QPushButton:hover {
152 color: black;
153 }
154 )");
155
156 this->showAllButton = new QPushButton(this);
157 this->showAllButton->setFixedSize(20, 20);
158
159 this->showAllButton->setIcon(
160 parentWidget()->style()->standardIcon(QStyle::SP_ToolBarVerticalExtensionButton));
161 this->hboxLayout->addWidget(showAllButton);
162 connect(
163 showAllButton, &QPushButton::clicked, this, &MessageWidget::showAllButtonClicked);
164 this->hboxLayout->addWidget(closeButton);
165 connect(closeButton, &QPushButton::clicked, this, &MessageWidget::closeButtonClicked);
166 }
167
168 this->hide();
169 }
170
171 void
172 MessageWidget::closeButtonClicked()
173 {
174 this->messages.pop();
175 if (this->messages.empty())
176 {
177 this->hide();
178 }
179 else
180 {
181 this->label->setText(messages.top());
182 }
183 }
184
185 void
186 MessageWidget::showAllButtonClicked()
187 {
188 QLayout* mainLayout = nullptr;
189 if (parentWidget())
190 mainLayout = parentWidget()->layout();
191
192 if (!mainLayout)
193 return;
194 if (not this->closeAllButton)
195 {
196 QPushButton* closeAll = new QPushButton("Close all", parentWidget());
197 connect(closeAll, &QPushButton::clicked, this, &MessageWidget::closeAllButtonClicked);
198 mainLayout->addWidget(closeAll);
199 this->closeAllButton = true;
200 }
201
202 while (!messages.empty())
203 {
204 const QString& text = messages.top();
205 MessageWidget* w = new MessageWidget(false, parentWidget());
206 w->newErrorMessage(text);
207 mainLayout->addWidget(w);
208 allMessageWidgets.push_back(w);
209 messages.pop();
210 }
211
212 this->hide();
213 }
214
215 void
216 MessageWidget::closeAllButtonClicked()
217 {
218 QLayout* mainLayout = nullptr;
219 if (parentWidget())
220 mainLayout = parentWidget()->layout();
221
222 if (!mainLayout)
223 return;
224
225 for (MessageWidget* w : allMessageWidgets)
226 {
227 mainLayout->removeWidget(w);
228 w->hide();
229 w->deleteLater();
230 }
231 allMessageWidgets.clear();
232
233 QPushButton* button = qobject_cast<QPushButton*>(sender());
234 if (button)
235 {
236 mainLayout->removeWidget(button);
237 button->hide();
238 button->deleteLater();
239 }
240 this->closeAllButton = false;
241 }
242
243 void
245 {
246 this->messages.push(text);
247 this->label->setText(text);
248 if (not QWidget::isVisible())
249 {
250 this->show();
251 }
252 }
253
254
255} // namespace armarx
void newErrorMessage(const QString &text)
MessageWidget(bool withShowAll, QWidget *parent=nullptr)
void setIconName(const std::string &iconName)
void setShortcutName(const std::string &name)
void setSkillConfig(const std::string &config)
ArmarX Headers.
This file offers overloads of toIce() and fromIce() functions for STL container types.