OriginalWnd.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. void OriginalWnd::initForm()
  33. {
  34. QTimer *timer = new QTimer(this);
  35. connect(timer, &QTimer::timeout, this, &OriginalWnd::updateTime);
  36. timer->start(100);
  37. ui->toolButton->setIcon(QIcon(":/images/light/stop.png"));
  38. ui->toolButton_2->setIcon(QIcon(":/images/light/start.png"));
  39. ui->toolButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
  40. ui->toolButton_2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
  41. ui->label_userlogo->setPixmap(QPixmap(":/images/light/user.png").scaled(20, 20, Qt::KeepAspectRatio));
  42. QSettings settings("OrganizationName__", "ApplicationName__");
  43. int lastSavedIndex = settings.value("lastIndex", 1).toInt();
  44. if (lastSavedIndex == 1) {
  45. Demo001_1 *demo001_1 = new Demo001_1;
  46. ui->switchShowPageUI->addWidget(demo001_1);
  47. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_1));
  48. }
  49. if (lastSavedIndex == 2) {
  50. Demo001_2 *demo001_2 = new Demo001_2;
  51. ui->switchShowPageUI->addWidget(demo001_2);
  52. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_2));
  53. }
  54. if (lastSavedIndex == 3) {
  55. Demo001_3 *demo001_3 = new Demo001_3;
  56. ui->switchShowPageUI->addWidget(demo001_3);
  57. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_3));
  58. }
  59. }
  60. void OriginalWnd::updateTime() {
  61. QDateTime currentDateTime = QDateTime::currentDateTime();
  62. QString timeStr = currentDateTime.toString("yyyy-MM-dd HH:mm:ss");
  63. ui->label_time->setText(timeStr);
  64. QSettings settings("YourCompany_2", "YourAppName_2");
  65. QString userName = settings.value("userName", "???").toString();
  66. ui->label_username->setText(userName);
  67. }
  68. void OriginalWnd::on_ChartButton_clicked()
  69. {
  70. Demo001_1 *demo001_1 = new Demo001_1;
  71. ui->switchShowPageUI->addWidget(demo001_1);
  72. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_1));
  73. QSettings settings("OrganizationName__", "ApplicationName__");
  74. settings.setValue("lastIndex", 1);
  75. }
  76. void OriginalWnd::on_DoubleImageButton_clicked()
  77. {
  78. Demo001_2 *demo001_2 = new Demo001_2;
  79. ui->switchShowPageUI->addWidget(demo001_2);
  80. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_2));
  81. QSettings settings("OrganizationName__", "ApplicationName__");
  82. settings.setValue("lastIndex", 2);
  83. }
  84. void OriginalWnd::on_SingleImageButton_clicked()
  85. {
  86. Demo001_3 *demo001_3 = new Demo001_3;
  87. ui->switchShowPageUI->addWidget(demo001_3);
  88. ui->switchShowPageUI->setCurrentIndex(ui->switchShowPageUI->indexOf(demo001_3));
  89. QSettings settings("OrganizationName__", "ApplicationName__");
  90. settings.setValue("lastIndex", 3);
  91. }