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