baseactionsheet.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "sheets/baseactionsheet.h"
  2. #include "base/application.h"
  3. #include "base/utils.h"
  4. #include "widgets/gradientwidget.h"
  5. #include "widgets/elidedlabel.h"
  6. #include <QBoxLayout>
  7. #include <QPainter>
  8. #include <QPaintEvent>
  9. #include <QPushButton>
  10. #ifdef Q_OS_LINUX
  11. #include <QFontDatabase>
  12. #endif
  13. BaseActionSheet::BaseActionSheet(QWidget *parent) : BaseSheet(parent)
  14. {
  15. background = new GradientWidget(this);
  16. background->resize(size());
  17. label = new ElidedLabel(this);
  18. #if defined(Q_OS_WIN)
  19. label->setFont(QFont("Segoe UI", 14));
  20. #elif defined(Q_OS_MACOS)
  21. label->setFont(QFont(".SF NS Text", 18));
  22. #elif defined(Q_OS_LINUX)
  23. QFont font = QFontDatabase::systemFont(QFontDatabase::TitleFont);
  24. font.setPointSize(14);
  25. label->setFont(font);
  26. #endif
  27. label->setAlignment(Qt::AlignCenter);
  28. label->setStyleSheet("margin-bottom: 6px;");
  29. layout = new QVBoxLayout(this);
  30. layout->setMargin(64);
  31. layout->setSpacing(6);
  32. layout->addStretch();
  33. layout->addWidget(label);
  34. layout->addStretch();
  35. }
  36. void BaseActionSheet::setHeading(const QString &title)
  37. {
  38. label->setText(title);
  39. }
  40. void BaseActionSheet::addWidget(QWidget *widget)
  41. {
  42. layout->insertWidget(layout->count() - 1, widget);
  43. }
  44. QPushButton *BaseActionSheet::addButton(const QString &title)
  45. {
  46. QPushButton *button = new QPushButton(this);
  47. button->setText(title);
  48. button->setMinimumHeight(Utils::scale(34));
  49. if (!Utils::isDarkTheme()) {
  50. const QString btnStyle(
  51. "QPushButton { background: rgb(225, 240, 190); border: none; padding: 0 20px } "
  52. "QPushButton:hover { background: rgb(215, 230, 180); }"
  53. "QPushButton:pressed { background: rgb(205, 220, 170); }"
  54. );
  55. button->setStyleSheet(btnStyle);
  56. }
  57. addWidget(button);
  58. return button;
  59. }
  60. void BaseActionSheet::resizeEvent(QResizeEvent *event)
  61. {
  62. background->resize(event->size());
  63. }