PageRenderTime 33ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tiled/donationdialog.cpp

http://github.com/bjorn/tiled
C++ | 87 lines | 52 code | 16 blank | 19 comment | 0 complexity | 84dad98b3ad694482ddf84716f8fba61 MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0, LGPL-2.1, AGPL-1.0
  1. /*
  2. * donationdialog.cpp
  3. * Copyright 2015-2019, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
  4. *
  5. * This file is part of Tiled.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "donationdialog.h"
  21. #include "ui_donationdialog.h"
  22. #include "preferences.h"
  23. #include "utils.h"
  24. #include <QDesktopServices>
  25. #include <QMessageBox>
  26. #include <QUrl>
  27. #include <QMenu>
  28. using namespace Tiled;
  29. DonationDialog::DonationDialog(QWidget *parent) :
  30. QDialog(parent),
  31. ui(new Ui::DonationDialog)
  32. {
  33. #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
  34. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  35. #endif
  36. ui->setupUi(this);
  37. resize(Utils::dpiScaled(size()));
  38. const QDate today(QDate::currentDate());
  39. auto laterMenu = new QMenu(this);
  40. laterMenu->addAction(tr("Remind me next week"))->setData(today.addDays(7));
  41. laterMenu->addAction(tr("Remind me next month"))->setData(today.addMonths(1));
  42. laterMenu->addAction(tr("Don't remind me"))->setData(QDate());
  43. ui->maybeLaterButton->setMenu(laterMenu);
  44. connect(ui->visitDonatePage, &QPushButton::clicked, this, &DonationDialog::openDonationPage);
  45. connect(ui->alreadyDonating, &QPushButton::clicked, this, &DonationDialog::sayThanks);
  46. connect(laterMenu, &QMenu::triggered, this, &DonationDialog::maybeLater);
  47. }
  48. DonationDialog::~DonationDialog()
  49. {
  50. delete ui;
  51. }
  52. void DonationDialog::openDonationPage()
  53. {
  54. QDesktopServices::openUrl(QUrl(QLatin1String("https://www.mapeditor.org/donate")));
  55. }
  56. void DonationDialog::sayThanks()
  57. {
  58. Preferences *prefs = Preferences::instance();
  59. prefs->setPatron(true);
  60. QMessageBox box(QMessageBox::NoIcon, tr("Thanks!"),
  61. tr("Thanks a lot for your support! With your help Tiled will keep getting better."),
  62. QMessageBox::Close, this);
  63. box.exec();
  64. close();
  65. }
  66. void DonationDialog::maybeLater(QAction *action)
  67. {
  68. const QDate date = action->data().toDate();
  69. Preferences::instance()->setDonationDialogReminder(date);
  70. close();
  71. }