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 <QHBoxLayout>
28#include <QLabel>
29#include <QPushButton>
30#include <QStylePlugin>
31#include <QtWidgets>
32#include <QDesktopServices>
33#include <QUrl>
34
35namespace armarx
36{
37
38
40 QDialog(parent), ui(new Ui::SkillDashboardConfig)
41 {
42 ui->setupUi(this);
43 this->setWindowTitle("Configure Skill");
44 connect(ui->dialogButtons, &QDialogButtonBox::accepted, this, &QDialog::accept);
45 connect(ui->dialogButtons, &QDialogButtonBox::rejected, this, &QDialog::reject);
46 connect(ui->linkButton, &QPushButton::clicked, this, &SkillDashboardConfigWindow::openNerdFontSearch);
47 connect(ui->buttonName,
48 &QLineEdit::textChanged,
49 this,
50 &SkillDashboardConfigWindow::onShortcutNameChanged);
51 }
52
53 void
54 SkillDashboardConfigWindow::onShortcutNameChanged()
55 {
57 }
58
59 QString
61 {
62 return ui->buttonName->text();
63 }
64
65 QString
67 {
68 return ui->iconName->text();
69 }
70
71 void
72 SkillDashboardConfigWindow::openNerdFontSearch()
73 {
74 QDesktopServices::openUrl(QUrl("https://www.nerdfonts.com/cheat-sheet"));
75 return;
76 }
77
78 QString
80 {
81 return ui->skillName->text();
82 }
83
84 QString
86 {
87 return ui->skillArgs->toPlainText();
88 }
89
90 void
92 {
93 ui->buttonName->setText(QString::fromStdString(name));
94 }
95
96 void
98 {
99 ui->skillName->setText(QString::fromStdString(id));
100 }
101
102 void
103 SkillDashboardConfigWindow::setIconName(const std::string& iconName)
104 {
105 ui->iconName->setText(QString::fromStdString(iconName));
106 }
107
108 void
110 {
111 ui->skillArgs->setPlainText(QString::fromStdString(config));
112 }
113
114 void
116 {
117 ui->infoText->setText(QString::fromStdString(info));
118 ui->infoText->setStyleSheet("color: red;");
119 }
120
125
126 MessageWidget::MessageWidget(bool withShowAll, QWidget* parent) : QWidget(parent)
127 {
128 this->hboxLayout = new QHBoxLayout(this);
129 this->hboxLayout->setContentsMargins(6, 2, 6, 2);
130 this->hboxLayout->setSpacing(4);
131
132 this->label = new QLabel(this);
133 this->label->setWordWrap(true);
134 this->label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
135 this->label->setStyleSheet("color: red;");
136 this->hboxLayout->addWidget(label);
137
138
139 if (withShowAll)
140 {
141 this->closeButton = new QPushButton("✕", this);
142 this->closeButton->setFixedSize(18, 18);
143 this->closeButton->setStyleSheet(R"(
144 QPushButton {
145 border: none;
146 font-weight: bold;
147 color: #444;
148 }
149 QPushButton:hover {
150 color: black;
151 }
152 )");
153
154 this->showAllButton = new QPushButton(this);
155 this->showAllButton->setFixedSize(20, 20);
156
157 this->showAllButton->setIcon(
158 parentWidget()->style()->standardIcon(QStyle::SP_ToolBarVerticalExtensionButton));
159 this->hboxLayout->addWidget(showAllButton);
160 connect(
161 showAllButton, &QPushButton::clicked, this, &MessageWidget::showAllButtonClicked);
162 this->hboxLayout->addWidget(closeButton);
163 connect(closeButton, &QPushButton::clicked, this, &MessageWidget::closeButtonClicked);
164 }
165
166 this->hide();
167 }
168
169 void
170 MessageWidget::closeButtonClicked()
171 {
172 this->messages.pop();
173 if (this->messages.empty())
174 {
175 this->hide();
176 }
177 else
178 {
179 this->label->setText(messages.top());
180 }
181 }
182
183 void
184 MessageWidget::showAllButtonClicked()
185 {
186 QLayout* mainLayout = nullptr;
187 if (parentWidget())
188 mainLayout = parentWidget()->layout();
189
190 if (!mainLayout)
191 return;
192 if (not this->closeAllButton)
193 {
194 QPushButton* closeAll = new QPushButton("Close all", parentWidget());
195 connect(closeAll, &QPushButton::clicked, this, &MessageWidget::closeAllButtonClicked);
196 mainLayout->addWidget(closeAll);
197 this->closeAllButton = true;
198 }
199
200 while (!messages.empty())
201 {
202 const QString& text = messages.top();
203 MessageWidget* w = new MessageWidget(false, parentWidget());
204 w->newErrorMessage(text);
205 mainLayout->addWidget(w);
206 allMessageWidgets.push_back(w);
207 messages.pop();
208 }
209
210 this->hide();
211 }
212
213 void
214 MessageWidget::closeAllButtonClicked()
215 {
216 QLayout* mainLayout = nullptr;
217 if (parentWidget())
218 mainLayout = parentWidget()->layout();
219
220 if (!mainLayout)
221 return;
222
223 for (MessageWidget* w : allMessageWidgets)
224 {
225 mainLayout->removeWidget(w);
226 w->hide();
227 w->deleteLater();
228 }
229 allMessageWidgets.clear();
230
231 QPushButton* button = qobject_cast<QPushButton*>(sender());
232 if (button)
233 {
234 mainLayout->removeWidget(button);
235 button->hide();
236 button->deleteLater();
237 }
238 this->closeAllButton = false;
239 }
240
241 void
243 {
244 this->messages.push(text);
245 this->label->setText(text);
246 if (not QWidget::isVisible())
247 {
248 this->show();
249 }
250 }
251
252
253} // 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.