OriginalWnd.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "OriginalWnd.h"
  2. #include "ui_OriginalWnd.h"
  3. #include "OriginalWnd/Demo001_1.h"
  4. #include "OriginalWnd/Demo001_2.h"
  5. #include "OriginalWnd/Demo001_3.h"
  6. #include "OriginalWnd/treeviewmanager.h"
  7. #include <QDebug>
  8. #include <QJsonDocument>
  9. #include <QFile>
  10. #include <QFileDialog>
  11. #include <QDateTime>
  12. #include <QTimer>
  13. #include <QSettings>
  14. OriginalWnd::OriginalWnd(QWidget *parent)
  15. : QMainWindow(parent)
  16. , ui(new Ui::OriginalWnd)
  17. {
  18. ui->setupUi(this);
  19. // 初始化 TreeViewManager
  20. treeViewManager = new TreeViewManager(this, ui->widget_2);
  21. if (!treeViewManager) {
  22. qWarning() << "TreeViewManager 初始化失败";
  23. return;
  24. }
  25. qDebug() << "UI 初始化完成";
  26. initForm();
  27. }
  28. OriginalWnd::~OriginalWnd()
  29. {
  30. delete ui;
  31. }
  32. QWidget* OriginalWnd::getWidgetLeft() const
  33. {
  34. return ui->widget;
  35. }
  36. void OriginalWnd::initForm()
  37. {
  38. QTimer *timer = new QTimer(this);
  39. connect(timer, &QTimer::timeout, this, &OriginalWnd::updateTime);
  40. timer->start(100);
  41. ui->toolButton->setIcon(QIcon(":/images/light/stop.png"));
  42. ui->toolButton_2->setIcon(QIcon(":/images/light/start.png"));
  43. ui->toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
  44. ui->toolButton_2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
  45. ui->label_userlogo->setPixmap(QPixmap(":/images/light/user.png").scaled(20, 20, Qt::KeepAspectRatio));
  46. QSettings settings("OrganizationName__", "ApplicationName__");
  47. int lastSavedIndex = settings.value("lastIndex", 1).toInt();
  48. if (lastSavedIndex == 1) {
  49. Demo001_1 *demo001_1 = new Demo001_1;
  50. ui->switchShowPageUI->addWidget(demo001_1);
  51. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_1));
  52. }
  53. if (lastSavedIndex == 2) {
  54. Demo001_2 *demo001_2 = new Demo001_2;
  55. ui->switchShowPageUI->addWidget(demo001_2);
  56. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_2));
  57. }
  58. if (lastSavedIndex == 3) {
  59. Demo001_3 *demo001_3 = new Demo001_3;
  60. ui->switchShowPageUI->addWidget(demo001_3);
  61. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_3));
  62. }
  63. }
  64. void OriginalWnd::updateTime() {
  65. QDateTime currentDateTime = QDateTime::currentDateTime();
  66. QString timeStr = currentDateTime.toString("yyyy-MM-dd HH:mm:ss");
  67. ui->label_time->setText(timeStr);
  68. QSettings settings("YourCompany_2", "YourAppName_2");
  69. QString userName = settings.value("userName", "???").toString();
  70. ui->label_username->setText(userName);
  71. }
  72. void OriginalWnd::on_ChartButton_clicked()
  73. {
  74. Demo001_1 *demo001_1 = new Demo001_1;
  75. ui->switchShowPageUI->addWidget(demo001_1);
  76. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_1));
  77. QSettings settings("OrganizationName__", "ApplicationName__");
  78. settings.setValue("lastIndex", 1);
  79. }
  80. void OriginalWnd::on_DoubleImageButton_clicked()
  81. {
  82. Demo001_2 *demo001_2 = new Demo001_2;
  83. ui->switchShowPageUI->addWidget(demo001_2);
  84. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_2));
  85. QSettings settings("OrganizationName__", "ApplicationName__");
  86. settings.setValue("lastIndex", 2);
  87. }
  88. void OriginalWnd::on_SingleImageButton_clicked()
  89. {
  90. Demo001_3 *demo001_3 = new Demo001_3;
  91. ui->switchShowPageUI->addWidget(demo001_3);
  92. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_3));
  93. QSettings settings("OrganizationName__", "ApplicationName__");
  94. settings.setValue("lastIndex", 3);
  95. }