SkillDescriptionWidget.cpp
Go to the documentation of this file.
2
3#include <sstream>
4
5#include <QGridLayout>
6#include <QLabel>
7#include <QTextEdit>
8
9#include <ArmarXGui/libraries/ArmarXGuiBase/widgets/cpp-markdown/markdown.h> // ToDo: Move cpp-markdown to own Axii module.
10
11namespace armarx::skills::gui
12{
13
14 static std::string
15 markdownToHtml(const std::string& markdownText, size_t spacesPerTab = 2)
16 {
17 ::markdown::Document document(spacesPerTab);
18 document.read(markdownText);
19
20 std::stringstream html;
21 document.write(html);
22 return html.str();
23 }
24
25 SkillDescriptionWidget::SkillDescriptionWidget(QWidget* parent) : QWidget{parent}
26 {
27 QGridLayout* layout = new QGridLayout;
28 setLayout(layout);
29
30 layout->setMargin(0);
31
32 int row = 0;
33 int col = 0;
34
35 layout->addWidget(new QLabel("Name:"), row, col++);
36 name = new QLabel;
37 layout->addWidget(name, row, col++);
38
39 // Add some padding.
40 layout->addWidget(new QLabel(), row, col++);
41
42 {
43 QLabel* label = new QLabel("Timeout:");
44 label->setAlignment(Qt::AlignmentFlag::AlignRight);
45 layout->addWidget(label, row, col++);
46 }
47 timeout = new QLabel;
48 timeout->setAlignment(Qt::AlignmentFlag::AlignRight);
49 layout->addWidget(timeout, row, col++);
50
51 ++row;
52 int numCols = col;
53 col = 0;
54
55 description = new QTextEdit;
56 description->setReadOnly(true);
57 layout->addWidget(description, row, col, 1, numCols);
58 ++row;
59 }
60
61 void
63 {
64 name->setText(QString::fromStdString(desc.skillId.skillName));
65 description->setHtml(QString::fromStdString(markdownToHtml(desc.description)));
66 timeout->setText(QString::fromStdString(desc.timeout.toDurationString()));
67 }
68
69} // namespace armarx::skills::gui
std::string toDurationString() const
String representation of the current duration in minimal/default format.
Definition Duration.cpp:180
std::string skillName
Definition SkillID.h:41
void setSkillDescription(const skills::SkillDescription &desc)
armarx::core::time::Duration timeout