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