BootWidget.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #include "BootWidget.h"
  2. #include "BootGlobal.h"
  3. #include "ui_BootWidget.h"
  4. #include <QLabel>
  5. #include <QScreen>
  6. BootWidget::BootWidget(QWidget *parent)
  7. : QWidget(parent),mSplitter(NULL),mListEvtLog(NULL)
  8. {
  9. setWindowIcon(QIcon(":/res/FavIcon.ico"));
  10. setMinimumSize(1920, 1080);
  11. SetFullMode();
  12. Init();
  13. }
  14. BootWidget::~BootWidget()
  15. {
  16. }
  17. void BootWidget::SetFullMode()
  18. {
  19. setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
  20. setAttribute(Qt::WA_TranslucentBackground);
  21. /*
  22. setWindowFlags(Qt::Window | Qt::FramelessWindowHint
  23. | Qt::WindowStaysOnTopHint|Qt::Tool
  24. |Qt::X11BypassWindowManagerHint);
  25. */
  26. //setParent(nullptr);
  27. QList<QScreen *> listScreens = QGuiApplication::screens(); //多显示器
  28. QRect rect = listScreens.at(0)->geometry();
  29. const int desktopWidth = rect.width();
  30. const int desktopHeight = rect.height();
  31. setMinimumSize(desktopWidth, desktopHeight);
  32. }
  33. void BootWidget::Demo_FulfillLog()
  34. {
  35. for(int i=1; i<=20; ++i)
  36. {
  37. QString str = QString(QStringLiteral("我是第%1串字符串")).arg(i);
  38. QBaseListWidgetItem* item = new QErrorListWidgetItem(str);
  39. // 为啥子类不能直接调用父类的接口??
  40. item->AppentToWidget(mListEvtLog);
  41. }
  42. }
  43. void BootWidget::Demo_FulfillFatalMsg()
  44. {
  45. for(int i=1; i<1024; ++i)
  46. {
  47. QString str = QString(QStringLiteral("我是第%1串字符串")).arg(i);
  48. QBaseListWidgetItem* item = new QTipListWidgetItem(str);
  49. item->AppentToWidget(mListImportantTip);
  50. }
  51. }
  52. void BootWidget::Init()
  53. {
  54. QFont font;
  55. font.setFamily(QStringLiteral("微软雅黑"));
  56. //font.setPointSize(12);
  57. this->setFont(font);
  58. /*
  59. mSplitter = new QSplitter(Qt::Horizontal, this);
  60. mListEvtLog = new QListWidget(this);
  61. mListImportantTip = new QListWidget(this);
  62. auto *rightWidget = new QWidget(mSplitter);
  63. auto *layoutColumn = new QVBoxLayout(rightWidget);
  64. layoutColumn->addWidget(mListImportantTip);
  65. mSplitter->addWidget(mListEvtLog);
  66. mSplitter->addWidget(rightWidget);
  67. mSplitter->setStretchFactor(0, 80);
  68. mSplitter->setStretchFactor(1, 20);
  69. mSplitter->setAutoFillBackground(true);
  70. //mSplitter->setHandleWidth(0);
  71. QVBoxLayout *centerLayout = new QVBoxLayout(this);
  72. centerLayout->addWidget(mSplitter);
  73. this->setLayout(centerLayout);
  74. */
  75. auto *layoutCenter = new QHBoxLayout(this);
  76. auto *layoutLeft = new QVBoxLayout(this);
  77. auto *layoutRight = new QVBoxLayout(this);
  78. auto *layoutRightArea = new QVBoxLayout(this);
  79. SlimLayout(layoutCenter);
  80. SlimLayout(layoutLeft);
  81. SlimLayout(layoutRight);
  82. SlimLayout(layoutRightArea);
  83. layoutRight->addLayout(layoutRightArea);
  84. mListEvtLog = new QLeftInfoListWidget(this);
  85. layoutLeft->addWidget(mListEvtLog);
  86. Demo_FulfillLog();
  87. // LOGO
  88. mLogoLabel = new QLabel(this);
  89. QPixmap logoPixmap(GetLogoPicPath());
  90. if(false)
  91. {
  92. const int labelWidth = mLogoLabel->width();
  93. const int labelHeight = mLogoLabel->height();
  94. //logoPixmap = logoPixmap.scaled(labelWidth, labelHeight, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
  95. logoPixmap = logoPixmap.scaled(labelWidth, labelHeight, Qt::KeepAspectRatio);
  96. } else {
  97. //const int pixWidth = logoPixmap.width();
  98. //const int pixlHeight = logoPixmap.height();
  99. //mLogoLabel->resize(pixWidth, pixlHeight);
  100. }
  101. mLogoLabel->setAlignment(Qt::AlignCenter);
  102. mLogoLabel->setPixmap(logoPixmap);
  103. //mLogoLabel->setScaledContents(true);
  104. SetWidgetBackgroundColor(mLogoLabel, GetRightBackgoundColor());
  105. // TerminalInfo
  106. QLabel* terminalLabel = new QLabel(this);
  107. terminalLabel->setText("7715012020 CMB.LIB V1.2.3.4");
  108. terminalLabel->setAlignment(Qt::AlignCenter);
  109. SetWidgetBackgroundColor(terminalLabel, GetRightBackgoundColor());
  110. // Entity boot information
  111. QLabel* entityBootLabel = new QLabel(this);
  112. //equals: entityBootLabel->setText(QString::fromLocal8Bit(("11/55 个模块启动成功")));
  113. entityBootLabel->setText(QStringLiteral("11/55 个模块启动成功"));
  114. entityBootLabel->setAlignment(Qt::AlignCenter);
  115. QFont fontLabel;
  116. fontLabel.setBold(true);
  117. fontLabel.setPointSize(12);
  118. entityBootLabel->setFont(fontLabel);
  119. //entityBootLabel->setStyleSheet("font-size:40px;font-style:blod");
  120. SetWidgetBackgroundColor(entityBootLabel, GetRightBackgoundColor());
  121. // no effect.
  122. //entityBootLabel->setContentsMargins(0,1000,0,1000);
  123. entityBootLabel->setMargin(10);
  124. layoutRightArea->addWidget(mLogoLabel);
  125. layoutRightArea->addWidget(terminalLabel);
  126. layoutRightArea->addWidget(entityBootLabel);
  127. mListImportantTip = new QRightInfoListWidget(this);
  128. layoutRightArea->addWidget(mListImportantTip);
  129. /*
  130. mTextEidtFatalMsg = new QPlainTextEdit(this);
  131. mTextEidtFatalMsg->setReadOnly(true);
  132. mTextEidtFatalMsg->setMaximumBlockCount(1024);
  133. mTextEidtFatalMsg->setBackgroundVisible(false);
  134. layoutRightArea->addWidget(mTextEidtFatalMsg);
  135. */
  136. Demo_FulfillFatalMsg();
  137. layoutCenter->addLayout(layoutLeft);
  138. layoutCenter->addLayout(layoutRight);
  139. layoutCenter->setStretch(0, 80);
  140. layoutCenter->setStretch(1, 20);
  141. this->setLayout(layoutCenter);
  142. }
  143. void BootWidget::paintEvent(QPaintEvent *event)
  144. {
  145. /*
  146. QPixmap logoPixmap(GetLogoPicPath());
  147. const int pixWidth = logoPixmap.width();
  148. const int pixlHeight = logoPixmap.height();
  149. const int labelWidth = mLogoLabel->width();
  150. const int newLabelHeight = labelWidth / (pixWidth / pixlHeight);
  151. mLogoLabel->resize(labelWidth, newLabelHeight);
  152. */
  153. }