LogStatePage.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // *****************************************************************************
  2. // 版权所有(C)2023~2099 上海骄成超声波技术有限公司
  3. // 保留所有权利
  4. // *****************************************************************************
  5. // 作者 : 杨坚
  6. // 版本 : 1.0
  7. // 功能说明:
  8. // 侧边栏日志状态
  9. // *****************************************************************************
  10. #include "LogStatePage.h"
  11. #include "QGraphicsEffect"
  12. LogStateSidebar::LogStateSidebar(QWidget* parent /*= nullptr*/) : QWidget(parent)
  13. {
  14. setGraphicsEffect(new QGraphicsDropShadowEffect(this));
  15. setFixedWidth(200);
  16. setStyleSheet("background-color: #333; color: white;");
  17. //setStyleSheet("background-color: rgba(51, 51, 51, 220);");
  18. // 创建动画
  19. m_pAnimation = new QPropertyAnimation(this, "pos");
  20. m_pAnimation->setDuration(300);
  21. m_pAnimation->setEasingCurve(QEasingCurve::InOutQuad);
  22. // 添加一些内容
  23. auto layout = new QVBoxLayout(this);
  24. layout->addWidget(new QPushButton("Option 1", this));
  25. layout->addWidget(new QPushButton("Option 2", this));
  26. layout->addWidget(new QPushButton("Option 3", this));
  27. layout->addStretch();
  28. }
  29. void LogStateSidebar::ShowSidebar()
  30. {
  31. m_pAnimation->stop();
  32. m_pAnimation->setStartValue(QPoint(-width(), y()));
  33. m_pAnimation->setEndValue(QPoint(0, y()));
  34. show();
  35. m_pAnimation->start();
  36. m_expanded = true;
  37. }
  38. void LogStateSidebar::HideSidebar()
  39. {
  40. m_pAnimation->stop();
  41. m_pAnimation->setStartValue(QPoint(x(), y()));
  42. m_pAnimation->setEndValue(QPoint(-width(), y()));
  43. connect(m_pAnimation, &QPropertyAnimation::finished, this, [this]() {
  44. // hide(); // 完成了不要隐藏
  45. m_expanded = false;
  46. });
  47. m_pAnimation->start();
  48. }
  49. bool LogStateSidebar::isExpanded()
  50. {
  51. return x() >= 0;
  52. }