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 
11 namespace armarx
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 
67  std::stringstream timeoutStr;
68  timeoutStr << desc.timeout;
69  timeout->setText(QString::fromStdString(timeoutStr.str()));
70  }
71 
72 } // namespace armarx
armarx::skills::SkillDescription::description
std::string description
Definition: SkillDescription.h:21
armarx::skills::SkillDescription::timeout
armarx::core::time::Duration timeout
Definition: SkillDescription.h:23
armarx::skills::SkillID::skillName
std::string skillName
Definition: SkillID.h:60
armarx::skills::SkillDescription
Definition: SkillDescription.h:18
markdown::Document
Definition: markdown.h:24
markdown.h
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition: SkillDescription.h:20
SkillDescriptionWidget.h
armarx::SkillDescriptionWidget::SkillDescriptionWidget
SkillDescriptionWidget(QWidget *parent=nullptr)
Definition: SkillDescriptionWidget.cpp:25
armarx::SkillDescriptionWidget::setSkillDescription
void setSkillDescription(const skills::SkillDescription &desc)
Definition: SkillDescriptionWidget.cpp:62
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28