SettingCardGroup.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "SettingCardGroup.h"
  2. #include "Layout/ExpandLayout.h"
  3. #include "Common/StyleSheet.h"
  4. SettingCardGroup::SettingCardGroup(const QString &title, QWidget *parent) : QWidget(parent)
  5. {
  6. m_titleLabel = new QLabel(title, this);
  7. vBoxLayout = new QVBoxLayout(this);
  8. cardLayout = new ExpandLayout();
  9. vBoxLayout->setContentsMargins(0, 0, 0, 0);
  10. vBoxLayout->setAlignment(Qt::AlignTop);
  11. vBoxLayout->setSpacing(0);
  12. cardLayout->setContentsMargins(0, 0, 0, 0);
  13. cardLayout->setSpacing(2);
  14. vBoxLayout->addWidget(m_titleLabel);
  15. vBoxLayout->addSpacing(12);
  16. vBoxLayout->addLayout(cardLayout, 1);
  17. FluentStyleSheet::apply("SETTING_CARD_GROUP", this);
  18. m_titleLabel->adjustSize();
  19. }
  20. void SettingCardGroup::addSettingCard(QWidget *card)
  21. {
  22. card->setParent(this);
  23. cardLayout->addWidget(card);
  24. adjustSize();
  25. }
  26. void SettingCardGroup::addSettingCards(const QList<QWidget *> &cards)
  27. {
  28. for (auto c : cards) {
  29. addSettingCard(c);
  30. }
  31. }
  32. void SettingCardGroup::adjustSize()
  33. {
  34. int h = cardLayout->heightForWidth(this->width()) + 46;
  35. this->resize(this->width(), h);
  36. }