about.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #include "about.h"
  2. void About::readConfig() {
  3. QString homePath = QDir::homePath();
  4. QString configPath = homePath + "/.config/plainDE/config.json";
  5. QFile configReader(configPath);
  6. configReader.open(QIODevice::ReadOnly | QIODevice::Text);
  7. QString data = configReader.readAll();
  8. configReader.close();
  9. mConfig = QJsonDocument::fromJson(data.toUtf8()).object();
  10. }
  11. void About::setAppearance() {
  12. // Stylesheet
  13. QString stylesheetPath = "/usr/share/plainDE/styles/" + mConfig["theme"].toString();
  14. QFile stylesheetReader(stylesheetPath);
  15. stylesheetReader.open(QIODevice::Text | QIODevice::ReadOnly);
  16. QString stylesheet = stylesheetReader.readAll();
  17. stylesheetReader.close();
  18. this->setStyleSheet(stylesheet);
  19. // Font
  20. mFontFamily = mConfig["fontFamily"].toString();
  21. this->setFont(mFontFamily);
  22. }
  23. void About::setUI() {
  24. this->setWindowTitle("plainAbout");
  25. this->setObjectName("about");
  26. QVBoxLayout* layout = new QVBoxLayout(this);
  27. QHBoxLayout* upperLayout = new QHBoxLayout();
  28. QVBoxLayout* appInfoLayout = new QVBoxLayout();
  29. mComponentLabel = new QLabel("plainDE");
  30. mComponentLabel->setFont(QFont(mFontFamily, 25));
  31. appInfoLayout->addWidget(mComponentLabel);
  32. mVersionLabel = new QLabel("Version");
  33. mVersionLabel->setFont(QFont(mFontFamily, 12));
  34. appInfoLayout->addWidget(mVersionLabel);
  35. appInfoLayout->addSpacerItem(new QSpacerItem(0, 0,
  36. QSizePolicy::Ignored,
  37. QSizePolicy::MinimumExpanding));
  38. upperLayout->addLayout(appInfoLayout);
  39. QLabel* logoLabel = new QLabel();
  40. logoLabel->setMaximumSize(120, 120);
  41. logoLabel->setScaledContents(true);
  42. logoLabel->setPixmap(QPixmap("/usr/share/plainDE/menuIcon.png"));
  43. upperLayout->addWidget(logoLabel);
  44. layout->addLayout(upperLayout);
  45. QTextEdit* additionalInfoTextEdit = new QTextEdit();
  46. additionalInfoTextEdit->setFont(QFont(mFontFamily, 11));
  47. additionalInfoTextEdit->setHtml("plainDE was brought to you by <b>thm-unix</b>.<br>"
  48. "Found bug/want to help us/have an idea? Leave feedback via GitHub Issues.<br><br>"
  49. "<a style=\"color:#378edf;\" href=\"https://plainDE.github.io/\">https://plainDE.github.io/</a><br>"
  50. "<a style=\"color:#378edf;\" href=\"https://github.com/plainDE/\">https://github.com/plainDE/</a><br>"
  51. "<a style=\"color:#378edf;\" href=\"https://github.com/thm-unix/\">https://github.com/thm-unix/</a><br><br>"
  52. "<a style=\"color:#378edf;\" href=\"https://www.gnu.org/licenses/gpl-3.0.html\">Learn more about GNU General Public License v3...</a><br>"
  53. "2022-2024");
  54. additionalInfoTextEdit->setReadOnly(true);
  55. layout->addWidget(additionalInfoTextEdit);
  56. QHBoxLayout* buttonsLayout = new QHBoxLayout();
  57. buttonsLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
  58. QPushButton* okButton = new QPushButton("OK");
  59. okButton->setFont(QFont(mFontFamily));
  60. buttonsLayout->addWidget(okButton);
  61. layout->addLayout(buttonsLayout);
  62. connect(okButton, &QPushButton::clicked, this, []() {
  63. exit(0);
  64. });
  65. }
  66. void About::setReleaseData() {
  67. QFile releaseFile("/usr/share/plainDE/release_data");
  68. releaseFile.open(QIODevice::Text | QIODevice::ReadOnly);
  69. QString releaseData = releaseFile.readAll();
  70. releaseFile.close();
  71. mVersionLabel->setText(releaseData);
  72. }
  73. void About::setComponent() {
  74. if (mArguments.contains("--plainPanel")) {
  75. mComponentLabel->setText("plainPanel");
  76. }
  77. else if (mArguments.contains("--plainControlCenter")) {
  78. mComponentLabel->setText("plainControlCenter");
  79. }
  80. }
  81. void About::setWindowGeometry() {
  82. QScreen* primaryScreen = qApp->primaryScreen();
  83. QRect screenGeometry = primaryScreen->geometry();
  84. int width = 550, height = 360;
  85. int x = (screenGeometry.width() - width) / 2, y = (screenGeometry.height() - height) / 2;
  86. if (mArguments.contains("-x")) {
  87. int xIndex = mArguments.indexOf("-x") + 1;
  88. x = mArguments.at(xIndex).toInt();
  89. }
  90. if (mArguments.contains("-y")) {
  91. int yIndex = mArguments.indexOf("-y") + 1;
  92. y = mArguments.at(yIndex).toInt();
  93. }
  94. this->setGeometry(x, y, width, height);
  95. }
  96. void About::setTransparency() {
  97. QScreen* screen = this->screen();
  98. QRect widgetGeometry = this->geometry();
  99. QPixmap pixmap = screen->grabWindow(0,
  100. widgetGeometry.x(),
  101. widgetGeometry.y(),
  102. widgetGeometry.width(),
  103. widgetGeometry.height());
  104. QGraphicsBlurEffect* blurEffect = new QGraphicsBlurEffect();
  105. blurEffect->setBlurRadius(15);
  106. blurEffect->setBlurHints(QGraphicsBlurEffect::QualityHint);
  107. QGraphicsScene* scene = new QGraphicsScene();
  108. QGraphicsPixmapItem item;
  109. item.setPixmap(pixmap);
  110. item.setGraphicsEffect(blurEffect);
  111. scene->addItem(&item);
  112. QImage res(QSize(widgetGeometry.width(), widgetGeometry.height()), QImage::Format_ARGB32);
  113. res.fill(Qt::transparent);
  114. QPainter ptr(&res);
  115. scene->render(&ptr, QRectF(), QRectF(0, 0, widgetGeometry.width(), widgetGeometry.height()));
  116. QPalette palette;
  117. palette.setBrush(this->backgroundRole(),
  118. QBrush(QPixmap::fromImage(res)));
  119. this->setPalette(palette);
  120. }
  121. About::About(QWidget* parent) : QWidget(parent) {
  122. mArguments = QCoreApplication::arguments();
  123. readConfig();
  124. setAppearance();
  125. setUI();
  126. setReleaseData();
  127. setComponent();
  128. setWindowGeometry();
  129. if (mConfig["theme"].toString().contains("transparent")) {
  130. setTransparency();
  131. }
  132. }
  133. About::~About() {
  134. }