BitInspectorPanel.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "pch.h"
  2. #include "BitInspectorPanel.h"
  3. #include <QScrollArea>
  4. #include <QPushButton>
  5. #include <QVBoxLayout>
  6. #include <QHBoxLayout>
  7. #include <QSettings>
  8. #include <QApplication>
  9. #include <QDesktopWidget>
  10. BitInspectorPanel::BitInspectorPanel(QWidget *parent)
  11. : QWidget(parent), inspector(new BitInspector(this))
  12. {
  13. QScrollArea* scrollArea = new QScrollArea(this);
  14. scrollArea->setWidget(inspector);
  15. scrollArea->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
  16. scrollArea->setWidgetResizable(true);
  17. QVBoxLayout* layout = new QVBoxLayout(this);
  18. layout->setContentsMargins(0, 0, 0, 0);
  19. layout->setSpacing(0);
  20. topPanel = new QHBoxLayout();
  21. topPanel->setContentsMargins(0, 0, 0, 0);
  22. topPanel->setSpacing(0);
  23. topPanel->addWidget(new QLabel("Iteration"));
  24. topPanel->addSpacing(2);
  25. topPanel->addWidget(new QLabel("Number"));
  26. topPanel->addSpacing(2);
  27. topPanel->addWidget(new QLabel("ObjectiveFunction"));
  28. topPanel->addSpacing(2);
  29. topPanel->addWidget(new QLabel("Binary"));
  30. topPanel->addStretch();
  31. runNameLabel = new QLabel("");
  32. topPanel->addWidget(runNameLabel);
  33. layout->addLayout(topPanel);
  34. layout->addWidget(scrollArea);
  35. popupWidget->setInformation("<h3><u>Inspector</u></h3> Shows all solution of a repetition. Each solution gets displayed in a row.<br><br><b>Iteration:</b> Show the iteration in which the solution is generated.<br><b>Number:</b> Shows which individual in the population is represented.<br><b>Objective Function:</b> Objective Function: Describes how optimal the solution is. Depending on the problem, a low or high value is desired.<br><b>Binary:</b> Shows the bitstring of the solution. White rectangle represents the bit is <i>false<i> and black <i>true<i>.");
  36. informationButton->setMinimumSize(20, 20);
  37. informationButton->setMaximumSize(20, 20);
  38. informationButton->setIcon(QIcon(":/metavis/Resources/information_icon.svg"));
  39. informationButton->setHoveredIcon(QIcon(":/metavis/Resources/information_icon_hovered.svg"));
  40. informationButton->setAttribute(Qt::WA_TranslucentBackground);
  41. informationButton->setStyleSheet(informationButton->styleSheet() + "border: none;");
  42. informationButton->setToolTip("Information");
  43. connect(informationButton, &QPushButton::released, this, &BitInspectorPanel::showInformation);
  44. topPanel->addWidget(informationButton);
  45. }
  46. BitInspectorPanel::~BitInspectorPanel()
  47. {
  48. }
  49. void BitInspectorPanel::setRunName(std::string& string)
  50. {
  51. runNameLabel->setText("\"" + QString::fromStdString(string) + "\"");
  52. }
  53. void BitInspectorPanel::removeRun()
  54. {
  55. inspector->clear();
  56. runNameLabel->setText("");
  57. }
  58. void BitInspectorPanel::showInformation()
  59. {
  60. QPoint position = QCursor::pos();
  61. popupWidget->width();
  62. QRect screen = QApplication::desktop()->screenGeometry();
  63. if (position.x() + popupWidget->width() > screen.width()) {
  64. popupWidget->move(screen.width() - popupWidget->width(), position.y());
  65. }
  66. else {
  67. popupWidget->move(position.x(), position.y());
  68. }
  69. popupWidget->show();
  70. }