Group.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /******************************************************************************
  2. Copyright (C) 2023 by Dennis Sädtler <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <Idian/Group.hpp>
  15. #include "../OBSIdianWidget.hpp"
  16. #include <Idian/moc_Group.cpp>
  17. using idian::Group;
  18. Group::Group(QWidget *parent) : QFrame(parent), OBSIdianUtils(this)
  19. {
  20. layout = new QVBoxLayout(this);
  21. layout->setSpacing(0);
  22. layout->setContentsMargins(0, 0, 0, 0);
  23. headerContainer = new QWidget();
  24. headerLayout = new QHBoxLayout();
  25. headerLayout->setSpacing(0);
  26. headerLayout->setContentsMargins(0, 0, 0, 0);
  27. headerContainer->setLayout(headerLayout);
  28. OBSIdianUtils::addClass(headerContainer, "header");
  29. labelContainer = new QWidget();
  30. labelLayout = new QVBoxLayout();
  31. labelLayout->setSpacing(0);
  32. labelLayout->setContentsMargins(0, 0, 0, 0);
  33. labelContainer->setLayout(labelLayout);
  34. labelContainer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
  35. controlContainer = new QWidget();
  36. controlLayout = new QVBoxLayout();
  37. controlLayout->setSpacing(0);
  38. controlLayout->setContentsMargins(0, 0, 0, 0);
  39. controlContainer->setLayout(controlLayout);
  40. headerLayout->addWidget(labelContainer);
  41. headerLayout->addWidget(controlContainer);
  42. contentsContainer = new QWidget();
  43. contentsLayout = new QVBoxLayout();
  44. contentsLayout->setSpacing(0);
  45. contentsLayout->setContentsMargins(0, 0, 0, 0);
  46. contentsContainer->setLayout(contentsLayout);
  47. OBSIdianUtils::addClass(contentsContainer, "contents");
  48. layout->addWidget(headerContainer);
  49. layout->addWidget(contentsContainer);
  50. propertyList = new PropertiesList(this);
  51. setLayout(layout);
  52. contentsLayout->addWidget(propertyList);
  53. nameLabel = new QLabel();
  54. OBSIdianUtils::addClass(nameLabel, "title");
  55. nameLabel->setVisible(false);
  56. labelLayout->addWidget(nameLabel);
  57. descriptionLabel = new QLabel();
  58. OBSIdianUtils::addClass(descriptionLabel, "description");
  59. descriptionLabel->setVisible(false);
  60. labelLayout->addWidget(descriptionLabel);
  61. }
  62. void Group::addRow(GenericRow *row) const
  63. {
  64. propertyList->addRow(row);
  65. }
  66. void Group::setTitle(QString name)
  67. {
  68. nameLabel->setText(name);
  69. setAccessibleName(name);
  70. showTitle(true);
  71. }
  72. void Group::setDescription(QString desc)
  73. {
  74. descriptionLabel->setText(desc);
  75. setAccessibleDescription(desc);
  76. showDescription(true);
  77. }
  78. void Group::showTitle(bool visible)
  79. {
  80. nameLabel->setVisible(visible);
  81. }
  82. void Group::showDescription(bool visible)
  83. {
  84. descriptionLabel->setVisible(visible);
  85. }
  86. void Group::setCheckable(bool check)
  87. {
  88. checkable = check;
  89. if (checkable && !toggleSwitch) {
  90. toggleSwitch = new ToggleSwitch(true);
  91. controlLayout->addWidget(toggleSwitch);
  92. connect(toggleSwitch, &ToggleSwitch::toggled, this,
  93. [=](bool checked) { propertyList->setEnabled(checked); });
  94. }
  95. if (!checkable && toggleSwitch) {
  96. controlLayout->removeWidget(toggleSwitch);
  97. toggleSwitch->deleteLater();
  98. }
  99. }