PropertiesList.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/PropertiesList.hpp>
  15. #include <Idian/Row.hpp>
  16. #include <QStyle>
  17. #include <Idian/moc_PropertiesList.cpp>
  18. using idian::PropertiesList;
  19. PropertiesList::PropertiesList(QWidget *parent) : QFrame(parent)
  20. {
  21. layout = new QVBoxLayout();
  22. layout->setSpacing(0);
  23. layout->setContentsMargins(0, 0, 0, 0);
  24. setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
  25. rowsList = QList<GenericRow *>();
  26. setLayout(layout);
  27. }
  28. // Note: This function takes ownership of the added widget
  29. // and it may be deleted when the properties list is destroyed
  30. // or the clear() method is called!
  31. void PropertiesList::addRow(GenericRow *row)
  32. {
  33. // Add custom spacer once more than one element exists
  34. if (layout->count() > 0)
  35. layout->addWidget(new PropertiesListSpacer(this));
  36. // Custom properties to work around :first and :last not existing.
  37. if (!first) {
  38. OBSIdianUtils::addClass(row, "first");
  39. first = row;
  40. }
  41. // Remove last property from existing last item
  42. if (last)
  43. OBSIdianUtils::removeClass(last, "last");
  44. // Most recently added item is also always last
  45. OBSIdianUtils::addClass(row, "last");
  46. last = row;
  47. row->setParent(this);
  48. rowsList.append(row);
  49. layout->addWidget(row);
  50. adjustSize();
  51. }
  52. void PropertiesList::clear()
  53. {
  54. rowsList.clear();
  55. first = nullptr;
  56. last = nullptr;
  57. QLayoutItem *item = layout->takeAt(0);
  58. while (item) {
  59. if (item->widget())
  60. item->widget()->deleteLater();
  61. delete item;
  62. item = layout->takeAt(0);
  63. }
  64. adjustSize();
  65. }