Skip to content

Commit

Permalink
Changed the donation reminder to be non-modal
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bjorn committed May 27, 2021
1 parent a74b908 commit db78351
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 230 deletions.
2 changes: 1 addition & 1 deletion .LICENSE-HEADER
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* %FILENAME%
* Copyright 2019, Your Name <your.name@domain>
* Copyright 2021, Your Name <your.name@domain>
*
* This file is part of Tiled.
*
Expand Down
89 changes: 0 additions & 89 deletions src/tiled/donationdialog.cpp

This file was deleted.

72 changes: 0 additions & 72 deletions src/tiled/donationdialog.ui

This file was deleted.

91 changes: 91 additions & 0 deletions src/tiled/donationpopup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* donationpopup.cpp
* Copyright 2015-2021, Thorbjørn Lindeijer <[email protected]>
*
* This file is part of Tiled.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "donationpopup.h"

#include "preferences.h"
#include "utils.h"

#include <QCoreApplication>
#include <QDesktopServices>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QUrl>

using namespace Tiled;

DonationPopup::DonationPopup(QWidget *parent)
: PopupWidget(parent)
{
auto label = new QLabel(QCoreApplication::translate("DonationDialog", "Please consider supporting Tiled development with a small monthly donation."));

auto visitDonatePage = new QPushButton(QCoreApplication::translate("DonationDialog", "&Donate ↗"));
auto alreadyDonating = new QPushButton(QCoreApplication::translate("DonationDialog", "I'm a &supporter!"));
auto maybeLaterButton = new QPushButton(QCoreApplication::translate("DonationDialog", "&Maybe later"));

const QDate today(QDate::currentDate());
auto laterMenu = new QMenu(this);
laterMenu->addAction(QCoreApplication::translate("Tiled::DonationDialog", "Remind me next week"))->setData(today.addDays(7));
laterMenu->addAction(QCoreApplication::translate("Tiled::DonationDialog", "Remind me next month"))->setData(today.addMonths(1));
laterMenu->addAction(QCoreApplication::translate("Tiled::DonationDialog", "Don't remind me"))->setData(QDate());
maybeLaterButton->setMenu(laterMenu);

auto layout = new QHBoxLayout;
layout->addWidget(label);
layout->addSpacing(Utils::dpiScaled(10));
layout->addWidget(visitDonatePage);
layout->addWidget(alreadyDonating);
layout->addWidget(maybeLaterButton);
const auto margin = Utils::dpiScaled(5);
layout->setContentsMargins(margin * 2, margin, margin, margin);
setLayout(layout);

connect(visitDonatePage, &QPushButton::clicked, this, &DonationPopup::openDonationPage);
connect(alreadyDonating, &QPushButton::clicked, this, &DonationPopup::sayThanks);
connect(laterMenu, &QMenu::triggered, this, &DonationPopup::maybeLater);
}

void DonationPopup::openDonationPage()
{
QDesktopServices::openUrl(QUrl(QLatin1String("https://www.mapeditor.org/donate")));
}

void DonationPopup::sayThanks()
{
Preferences::instance()->setPatron(true);

QMessageBox(QMessageBox::NoIcon, QCoreApplication::translate("Tiled::DonationDialog", "Thanks!"),
QCoreApplication::translate("Tiled::DonationDialog", "Thanks a lot for your support! With your help Tiled will keep getting better."),
QMessageBox::Close, this).exec();

close();
}

void DonationPopup::maybeLater(QAction *action)
{
const QDate date = action->data().toDate();
Preferences::instance()->setDonationReminder(date);
close();
}

#include "moc_donationpopup.cpp"
17 changes: 5 additions & 12 deletions src/tiled/donationdialog.h → src/tiled/donationpopup.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* donationdialog.h
* Copyright 2015-2019, Thorbjørn Lindeijer <[email protected]>
* donationpopup.h
* Copyright 2015-2021, Thorbjørn Lindeijer <[email protected]>
*
* This file is part of Tiled.
*
Expand All @@ -20,28 +20,21 @@

#pragma once

#include <QDialog>

namespace Ui {
class DonationDialog;
}
#include "popupwidget.h"

namespace Tiled {

class DonationDialog : public QDialog
class DonationPopup : public PopupWidget
{
Q_OBJECT

public:
explicit DonationDialog(QWidget *parent = nullptr);
~DonationDialog();
explicit DonationPopup(QWidget *parent = nullptr);

private:
void openDonationPage();
void sayThanks();
void maybeLater(QAction *action);

Ui::DonationDialog *ui;
};

} // namespace Tiled
2 changes: 1 addition & 1 deletion src/tiled/filechangedwarning.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FileChangedWarning : public QWidget
Q_OBJECT

public:
FileChangedWarning(QWidget *parent = nullptr);
explicit FileChangedWarning(QWidget *parent = nullptr);

signals:
void reload();
Expand Down
Loading

0 comments on commit db78351

Please sign in to comment.