1 /*
2 * donationpopup.cpp
3 * Copyright 2015-2021, 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
21 #include "donationpopup.h"
22
23 #include "preferences.h"
24 #include "utils.h"
25
26 #include <QCoreApplication>
27 #include <QDesktopServices>
28 #include <QHBoxLayout>
29 #include <QLabel>
30 #include <QMenu>
31 #include <QMessageBox>
32 #include <QPushButton>
33 #include <QUrl>
34
35 using namespace Tiled;
36
DonationPopup(QWidget * parent)37 DonationPopup::DonationPopup(QWidget *parent)
38 : PopupWidget(parent)
39 {
40 setTint(Qt::green);
41
42 auto label = new QLabel(QCoreApplication::translate("DonationDialog", "Please consider supporting Tiled development with a small monthly donation."));
43
44 auto visitDonatePage = new QPushButton(QCoreApplication::translate("DonationDialog", "&Donate ↗"));
45 auto alreadyDonating = new QPushButton(QCoreApplication::translate("DonationDialog", "I'm a &supporter!"));
46 auto maybeLaterButton = new QPushButton(QCoreApplication::translate("DonationDialog", "&Maybe later"));
47
48 const QDate today(QDate::currentDate());
49 auto laterMenu = new QMenu(this);
50 laterMenu->addAction(QCoreApplication::translate("Tiled::DonationDialog", "Remind me next week"))->setData(today.addDays(7));
51 laterMenu->addAction(QCoreApplication::translate("Tiled::DonationDialog", "Remind me next month"))->setData(today.addMonths(1));
52 laterMenu->addAction(QCoreApplication::translate("Tiled::DonationDialog", "Don't remind me"))->setData(QDate());
53 maybeLaterButton->setMenu(laterMenu);
54
55 auto layout = new QHBoxLayout;
56 layout->addWidget(label);
57 layout->addSpacing(Utils::dpiScaled(10));
58 layout->addWidget(visitDonatePage);
59 layout->addWidget(alreadyDonating);
60 layout->addWidget(maybeLaterButton);
61 const auto margin = Utils::dpiScaled(5);
62 layout->setContentsMargins(margin * 2, margin, margin, margin);
63 setLayout(layout);
64
65 connect(visitDonatePage, &QPushButton::clicked, this, &DonationPopup::openDonationPage);
66 connect(alreadyDonating, &QPushButton::clicked, this, &DonationPopup::sayThanks);
67 connect(laterMenu, &QMenu::triggered, this, &DonationPopup::maybeLater);
68 }
69
openDonationPage()70 void DonationPopup::openDonationPage()
71 {
72 QDesktopServices::openUrl(QUrl(QLatin1String("https://www.mapeditor.org/donate")));
73 }
74
sayThanks()75 void DonationPopup::sayThanks()
76 {
77 Preferences::instance()->setPatron(true);
78
79 QMessageBox(QMessageBox::NoIcon, QCoreApplication::translate("Tiled::DonationDialog", "Thanks!"),
80 QCoreApplication::translate("Tiled::DonationDialog", "Thanks a lot for your support! With your help Tiled will keep getting better."),
81 QMessageBox::Close, this).exec();
82
83 close();
84 }
85
maybeLater(QAction * action)86 void DonationPopup::maybeLater(QAction *action)
87 {
88 const QDate date = action->data().toDate();
89 Preferences::instance()->setDonationReminder(date);
90 close();
91 }
92
93 #include "moc_donationpopup.cpp"
94