Skip to content

Commit db78351

Browse files
committed
Changed the donation reminder to be non-modal
I've coded this nice non-modal popup for asking whether to enable crash reporting, so might as well use it for asking for donations as well.
1 parent a74b908 commit db78351

15 files changed

+237
-230
lines changed

.LICENSE-HEADER

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* %FILENAME%
3-
* Copyright 2019, Your Name <your.name@domain>
3+
* Copyright 2021, Your Name <your.name@domain>
44
*
55
* This file is part of Tiled.
66
*

src/tiled/donationdialog.cpp

-89
This file was deleted.

src/tiled/donationdialog.ui

-72
This file was deleted.

src/tiled/donationpopup.cpp

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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"
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* donationdialog.h
3-
* Copyright 2015-2019, Thorbjørn Lindeijer <[email protected]>
2+
* donationpopup.h
3+
* Copyright 2015-2021, Thorbjørn Lindeijer <[email protected]>
44
*
55
* This file is part of Tiled.
66
*
@@ -20,28 +20,21 @@
2020

2121
#pragma once
2222

23-
#include <QDialog>
24-
25-
namespace Ui {
26-
class DonationDialog;
27-
}
23+
#include "popupwidget.h"
2824

2925
namespace Tiled {
3026

31-
class DonationDialog : public QDialog
27+
class DonationPopup : public PopupWidget
3228
{
3329
Q_OBJECT
3430

3531
public:
36-
explicit DonationDialog(QWidget *parent = nullptr);
37-
~DonationDialog();
32+
explicit DonationPopup(QWidget *parent = nullptr);
3833

3934
private:
4035
void openDonationPage();
4136
void sayThanks();
4237
void maybeLater(QAction *action);
43-
44-
Ui::DonationDialog *ui;
4538
};
4639

4740
} // namespace Tiled

src/tiled/filechangedwarning.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FileChangedWarning : public QWidget
3232
Q_OBJECT
3333

3434
public:
35-
FileChangedWarning(QWidget *parent = nullptr);
35+
explicit FileChangedWarning(QWidget *parent = nullptr);
3636

3737
signals:
3838
void reload();

0 commit comments

Comments
 (0)