MainWindow.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "MainWindow.h"
  2. #include <DateTime/DatePicker.h>
  3. #include <QFramelessWindow.h>
  4. #include <TitleBar.h>
  5. #include <Navigation/NavigationInterface.h>
  6. #include <Widgets/StackedWidget.h>
  7. #include <QDebug>
  8. StackedWidget::StackedWidget(QWidget *parent) : QFrame(parent) {
  9. m_hBoxLayout = new QHBoxLayout(this);
  10. m_view = new PopUpAniStackedWidget(this);
  11. m_hBoxLayout->setContentsMargins(0, 0, 0, 0);
  12. m_hBoxLayout->addWidget(m_view);
  13. connect(
  14. m_view, &PopUpAniStackedWidget::currentChanged, this,
  15. [this](int index) { emit currentWidgetChanged(m_view->widget(index)); });
  16. }
  17. void StackedWidget::addWidget(QWidget *widget) { m_view->addWidget(widget); }
  18. ///
  19. /// @todo widget.verticalScrollBar().setValue(0)
  20. ///
  21. void StackedWidget::setCurrentWidget(QWidget *widget, bool popOut) {
  22. if (popOut) {
  23. m_view->setCurrentWidget(widget, true, false, 200, QEasingCurve::InQuad);
  24. } else {
  25. m_view->setCurrentWidget(widget, false, true, 300);
  26. }
  27. }
  28. void StackedWidget::setCurrentIndex(int index, bool popOut) {
  29. setCurrentWidget(m_view->widget(index), popOut);
  30. }
  31. PopUpAniStackedWidget *StackedWidget::view() const { return m_view; }
  32. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
  33. initWindow();
  34. initLayout();
  35. }
  36. MainWindow::~MainWindow() {}
  37. void MainWindow::initWindow() {
  38. QWidget *w = new QWidget();
  39. m_hBoxLayout = new QHBoxLayout(w);
  40. setCentralWidget(w);
  41. m_widgetLayout = new QHBoxLayout();
  42. m_stackWidget = new StackedWidget(this);
  43. m_navigationInterface = new NavigationInterface(true, true, this);
  44. QFramelessHelper *helper = new QFramelessHelper(this);
  45. m_titleBar = new StandardTitleBar(this);
  46. m_titleBar->setGeometry(QRect(46, 0, width() - 46, m_titleBar->height()));
  47. helper->setTitleBar(m_titleBar);
  48. QIcon icon = QIcon(":/resource/logo.png");
  49. setWindowIcon(icon);
  50. m_titleBar->setIcon(icon);
  51. setWindowTitle("专家评定数据分析软件");
  52. setMinimumSize(QSize(800, 600));
  53. }
  54. void MainWindow::initLayout() {
  55. m_hBoxLayout->setSpacing(0);
  56. m_hBoxLayout->setContentsMargins(0, 0, 0, 0);
  57. m_hBoxLayout->addWidget(m_navigationInterface);
  58. m_hBoxLayout->addLayout(m_widgetLayout);
  59. m_hBoxLayout->setStretchFactor(m_widgetLayout, 1);
  60. m_widgetLayout->addWidget(m_stackWidget);
  61. m_widgetLayout->setContentsMargins(0, 32, 0, 0);
  62. }
  63. void MainWindow::resizeEvent(QResizeEvent *event) {
  64. m_navigationInterface->resize(m_navigationInterface->width(), height());
  65. m_titleBar->resize(width() - 46, m_titleBar->height());
  66. }