about.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* about.cpp - about dialog
  2. * Copyright (C) 2017-2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <fmt/format.h>
  18. #include <QFile>
  19. #include <QVideoWidget>
  20. #include <QMediaPlayer>
  21. #include <QMediaPlaylist>
  22. #include <version.h>
  23. #include <util/strings.h>
  24. #include "about.h"
  25. #include "ui_about.h"
  26. namespace rainynite::studio {
  27. AboutDialog::AboutDialog(QWidget* parent) :
  28. QDialog(parent),
  29. ui(make_unique<Ui::AboutDialog>()),
  30. player(make_unique<QMediaPlayer>())
  31. {
  32. ui->setupUi(this);
  33. auto about_formatted = fmt::format(
  34. util::str(ui->about_label->text()),
  35. RAINYNITE_STUDIO_VERSION,
  36. RAINYNITE_STUDIO_CODENAME
  37. );
  38. ui->about_label->setText(util::str(about_formatted));
  39. QFile license(":/text/COPYING.gpl3");
  40. if (license.open(QIODevice::ReadOnly)) {
  41. ui->license_text->setText(license.readAll());
  42. license.close();
  43. }
  44. QFile third_party(":/text/third-party.txt");
  45. if (third_party.open(QIODevice::ReadOnly)) {
  46. ui->third_party_text->setText(third_party.readAll());
  47. third_party.close();
  48. }
  49. ui->image->installEventFilter(this);
  50. connect(ui->close_button, SIGNAL(clicked()), this, SLOT(accept()));
  51. }
  52. AboutDialog::~AboutDialog() = default;
  53. bool AboutDialog::eventFilter(QObject* /*target*/, QEvent* event) {
  54. if (event->type() == QEvent::MouseButtonPress) {
  55. play_video();
  56. return true;
  57. }
  58. return false;
  59. }
  60. void AboutDialog::play_video() {
  61. auto video = new QVideoWidget();
  62. delete ui->image_container->replaceWidget(ui->image, video);
  63. delete ui->image;
  64. player->setVideoOutput(video);
  65. auto list = new QMediaPlaylist();
  66. list->addMedia(QUrl{"qrc:/video/imperfect_wave.webm"});
  67. list->setPlaybackMode(QMediaPlaylist::Loop);
  68. player->setPlaylist(list);
  69. player->play();
  70. }
  71. } // namespace rainynite::studio