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::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
armarx::skills::gui::SkillDescriptionWidget::SkillDescriptionWidget
SkillDescriptionWidget(QWidget *parent=nullptr)
Definition: SkillDescriptionWidget.cpp:25
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
SkillDescriptionWidget.h
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition: SkillDescription.h:20
armarx::skills::gui
Definition: PeriodicUpdateWidget.cpp:11
armarx::skills::gui::SkillDescriptionWidget::setSkillDescription
void setSkillDescription(const skills::SkillDescription &desc)
Definition: SkillDescriptionWidget.cpp:62
armarx::core::time::Duration::toDurationString
std::string toDurationString() const
String representation of the current duration in minimal/default format.
Definition: Duration.cpp:209