1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #6005

Jimi Huotari (1):
      refactor(Qt): fix build with Qt 5.15
This commit is contained in:
sudden6 2020-03-19 01:22:31 +01:00
commit 4345fafbc6
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
11 changed files with 55 additions and 1 deletions

View File

@ -34,6 +34,9 @@
#include "src/util/strongtype.h"
#include <QCoreApplication>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
#include <QRandomGenerator>
#endif
#include <QRegularExpression>
#include <QString>
#include <QStringBuilder>
@ -792,7 +795,11 @@ void Core::bootstrapDht()
}
int i = 0;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
static int j = QRandomGenerator::global()->generate() % listSize;
#else
static int j = qrand() % listSize;
#endif
// i think the more we bootstrap, the more we jitter because the more we overwrite nodes
while (i < 2) {
const DhtServer& dhtServer = bootstrapNodes[j % listSize];

View File

@ -175,7 +175,9 @@ int main(int argc, char* argv[])
qInstallMessageHandler(logMessageHandler);
// initialize random number generator
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
qsrand(time(nullptr));
#endif
std::unique_ptr<QApplication> a(new QApplication(argc, argv));
@ -207,7 +209,9 @@ int main(int argc, char* argv[])
osx::migrateProfiles();
#endif
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
qsrand(time(nullptr));
#endif
Settings& settings = Settings::getInstance();
QString locale = settings.getTranslation();
Translator::translate(locale);

View File

@ -96,7 +96,11 @@ bool toxFileIsComplete(ToxFile::FileStatus status)
std::map<ChatLogIdx, ChatLogItem>::const_iterator
firstItemAfterDate(QDate date, const std::map<ChatLogIdx, ChatLogItem>& items)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
return std::lower_bound(items.begin(), items.end(), QDateTime(date.startOfDay()),
#else
return std::lower_bound(items.begin(), items.end(), QDateTime(date),
#endif
[](const MessageDateAdaptor& a, MessageDateAdaptor const& b) {
return a.timestamp.date() < b.timestamp.date();
});

View File

@ -957,7 +957,11 @@ QList<History::DateIdx> History::getNumMessagesForFriendBeforeDateBoundaries(con
"%4;")
.arg(countMessagesForFriend)
.arg(friendPkString)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
.arg(QDateTime(from.startOfDay()).toMSecsSinceEpoch())
#else
.arg(QDateTime(from).toMSecsSinceEpoch())
#endif
.arg(limitString);
QList<DateIdx> dateIdxs;

View File

@ -161,8 +161,16 @@ void EmoticonsWidget::mousePressEvent(QMouseEvent*)
void EmoticonsWidget::wheelEvent(QWheelEvent* e)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
const bool vertical = qAbs(e->angleDelta().y()) >= qAbs(e->angleDelta().x());
const int delta = vertical ? e->angleDelta().y() : e->angleDelta().x();
if (vertical) {
if (delta < 0) {
#else
if (e->orientation() == Qt::Vertical) {
if (e->delta() < 0) {
#endif
stack.setCurrentIndex(stack.currentIndex() + 1);
} else {
stack.setCurrentIndex(stack.currentIndex() - 1);

View File

@ -104,7 +104,7 @@ QLayoutItem* FlowLayout::takeAt(int index)
Qt::Orientations FlowLayout::expandingDirections() const
{
return nullptr;
return {};
}
bool FlowLayout::hasHeightForWidth() const

View File

@ -56,7 +56,11 @@ LoadHistoryDialog::~LoadHistoryDialog()
QDateTime LoadHistoryDialog::getFromDate()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
QDateTime res(ui->fromDate->selectedDate().startOfDay());
#else
QDateTime res(ui->fromDate->selectedDate());
#endif
if (res.date().month() != ui->fromDate->monthShown()
|| res.date().year() != ui->fromDate->yearShown()) {
QDate newDate(ui->fromDate->yearShown(), ui->fromDate->monthShown(), 1);

View File

@ -37,7 +37,11 @@ SearchSettingsForm::SearchSettingsForm(QWidget *parent) :
reloadTheme();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
connect(ui->startSearchComboBox, QOverload<int, const QString &>::of(&QComboBox::currentIndexChanged),
#else
connect(ui->startSearchComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
#endif
this, &SearchSettingsForm::onStartSearchSelected);
connect(ui->registerCheckBox, &QCheckBox::clicked, this, &SearchSettingsForm::onRegisterClicked);
connect(ui->wordsOnlyRadioButton, &QCheckBox::clicked, this, &SearchSettingsForm::onWordsOnlyClicked);

View File

@ -23,6 +23,9 @@
#include <QDebug>
#include <QFile>
#include <QMessageBox>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
#include <QRandomGenerator>
#endif
#include "src/core/core.h"
#include "src/nexus.h"
@ -98,11 +101,19 @@ void PrivacyForm::showEvent(QShowEvent*)
void PrivacyForm::on_randomNosapamButton_clicked()
{
QTime time = QTime::currentTime();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
QRandomGenerator((uint)time.msec());
#else
qsrand((uint)time.msec());
#endif
uint32_t newNospam{0};
for (int i = 0; i < 4; ++i)
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
newNospam = (newNospam << 8) + (QRandomGenerator::global()->generate() % 256); // Generate byte by byte. For some reason.
#else
newNospam = (newNospam << 8) + (qrand() % 256); // Generate byte by byte. For some reason.
#endif
Core::getInstance()->setNospam(newNospam);
bodyUI->nospamLineEdit->setText(Core::getInstance()->getSelfId().getNoSpamString());

View File

@ -33,7 +33,11 @@ public:
GenericChatItemLayout(const GenericChatItemLayout& layout) = delete;
~GenericChatItemLayout();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
void addSortedWidget(GenericChatItemWidget* widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment());
#else
void addSortedWidget(GenericChatItemWidget* widget, int stretch = 0, Qt::Alignment alignment = nullptr);
#endif
int indexOfSortedWidget(GenericChatItemWidget* widget) const;
bool existsSortedWidget(GenericChatItemWidget* widget) const;
void removeSortedWidget(GenericChatItemWidget* widget);

View File

@ -26,7 +26,11 @@ class ActivateDialog : public QDialog
{
Q_OBJECT
public:
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
ActivateDialog(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
#else
ActivateDialog(QWidget* parent = nullptr, Qt::WindowFlags f = nullptr);
#endif
bool event(QEvent* event) override;
signals: