mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(Qt): fix build with Qt 5.15
This fixes compile-time warnings about deprecated functions when
building with Qt 5.15.
(cherry picked from commit 6d51971c6f
)
This commit is contained in:
parent
465d826068
commit
d9c3279c40
|
@ -34,6 +34,9 @@
|
||||||
#include "src/util/strongtype.h"
|
#include "src/util/strongtype.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
#endif
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
|
@ -467,7 +470,11 @@ void Core::bootstrapDht()
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
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;
|
static int j = qrand() % listSize;
|
||||||
|
#endif
|
||||||
// i think the more we bootstrap, the more we jitter because the more we overwrite nodes
|
// i think the more we bootstrap, the more we jitter because the more we overwrite nodes
|
||||||
while (i < 2) {
|
while (i < 2) {
|
||||||
const DhtServer& dhtServer = bootstrapNodes[j % listSize];
|
const DhtServer& dhtServer = bootstrapNodes[j % listSize];
|
||||||
|
|
|
@ -175,7 +175,9 @@ int main(int argc, char* argv[])
|
||||||
qInstallMessageHandler(logMessageHandler);
|
qInstallMessageHandler(logMessageHandler);
|
||||||
|
|
||||||
// initialize random number generator
|
// initialize random number generator
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||||
qsrand(time(nullptr));
|
qsrand(time(nullptr));
|
||||||
|
#endif
|
||||||
|
|
||||||
std::unique_ptr<QApplication> a(new QApplication(argc, argv));
|
std::unique_ptr<QApplication> a(new QApplication(argc, argv));
|
||||||
|
|
||||||
|
@ -207,7 +209,9 @@ int main(int argc, char* argv[])
|
||||||
osx::migrateProfiles();
|
osx::migrateProfiles();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||||
qsrand(time(nullptr));
|
qsrand(time(nullptr));
|
||||||
|
#endif
|
||||||
Settings& settings = Settings::getInstance();
|
Settings& settings = Settings::getInstance();
|
||||||
QString locale = settings.getTranslation();
|
QString locale = settings.getTranslation();
|
||||||
Translator::translate(locale);
|
Translator::translate(locale);
|
||||||
|
|
|
@ -96,7 +96,11 @@ bool toxFileIsComplete(ToxFile::FileStatus status)
|
||||||
std::map<ChatLogIdx, ChatLogItem>::const_iterator
|
std::map<ChatLogIdx, ChatLogItem>::const_iterator
|
||||||
firstItemAfterDate(QDate date, const std::map<ChatLogIdx, ChatLogItem>& items)
|
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),
|
return std::lower_bound(items.begin(), items.end(), QDateTime(date),
|
||||||
|
#endif
|
||||||
[](const MessageDateAdaptor& a, MessageDateAdaptor const& b) {
|
[](const MessageDateAdaptor& a, MessageDateAdaptor const& b) {
|
||||||
return a.timestamp.date() < b.timestamp.date();
|
return a.timestamp.date() < b.timestamp.date();
|
||||||
});
|
});
|
||||||
|
|
|
@ -957,7 +957,11 @@ QList<History::DateIdx> History::getNumMessagesForFriendBeforeDateBoundaries(con
|
||||||
"%4;")
|
"%4;")
|
||||||
.arg(countMessagesForFriend)
|
.arg(countMessagesForFriend)
|
||||||
.arg(friendPkString)
|
.arg(friendPkString)
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
|
.arg(QDateTime(from.startOfDay()).toMSecsSinceEpoch())
|
||||||
|
#else
|
||||||
.arg(QDateTime(from).toMSecsSinceEpoch())
|
.arg(QDateTime(from).toMSecsSinceEpoch())
|
||||||
|
#endif
|
||||||
.arg(limitString);
|
.arg(limitString);
|
||||||
|
|
||||||
QList<DateIdx> dateIdxs;
|
QList<DateIdx> dateIdxs;
|
||||||
|
|
|
@ -161,8 +161,16 @@ void EmoticonsWidget::mousePressEvent(QMouseEvent*)
|
||||||
|
|
||||||
void EmoticonsWidget::wheelEvent(QWheelEvent* e)
|
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->orientation() == Qt::Vertical) {
|
||||||
if (e->delta() < 0) {
|
if (e->delta() < 0) {
|
||||||
|
#endif
|
||||||
stack.setCurrentIndex(stack.currentIndex() + 1);
|
stack.setCurrentIndex(stack.currentIndex() + 1);
|
||||||
} else {
|
} else {
|
||||||
stack.setCurrentIndex(stack.currentIndex() - 1);
|
stack.setCurrentIndex(stack.currentIndex() - 1);
|
||||||
|
|
|
@ -104,7 +104,7 @@ QLayoutItem* FlowLayout::takeAt(int index)
|
||||||
|
|
||||||
Qt::Orientations FlowLayout::expandingDirections() const
|
Qt::Orientations FlowLayout::expandingDirections() const
|
||||||
{
|
{
|
||||||
return nullptr;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FlowLayout::hasHeightForWidth() const
|
bool FlowLayout::hasHeightForWidth() const
|
||||||
|
|
|
@ -52,7 +52,11 @@ LoadHistoryDialog::~LoadHistoryDialog()
|
||||||
|
|
||||||
QDateTime LoadHistoryDialog::getFromDate()
|
QDateTime LoadHistoryDialog::getFromDate()
|
||||||
{
|
{
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
|
QDateTime res(ui->fromDate->selectedDate().startOfDay());
|
||||||
|
#else
|
||||||
QDateTime res(ui->fromDate->selectedDate());
|
QDateTime res(ui->fromDate->selectedDate());
|
||||||
|
#endif
|
||||||
if (res.date().month() != ui->fromDate->monthShown()
|
if (res.date().month() != ui->fromDate->monthShown()
|
||||||
|| res.date().year() != ui->fromDate->yearShown()) {
|
|| res.date().year() != ui->fromDate->yearShown()) {
|
||||||
QDate newDate(ui->fromDate->yearShown(), ui->fromDate->monthShown(), 1);
|
QDate newDate(ui->fromDate->yearShown(), ui->fromDate->monthShown(), 1);
|
||||||
|
|
|
@ -37,7 +37,11 @@ SearchSettingsForm::SearchSettingsForm(QWidget *parent) :
|
||||||
|
|
||||||
reloadTheme();
|
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),
|
connect(ui->startSearchComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
|
||||||
|
#endif
|
||||||
this, &SearchSettingsForm::onStartSearchSelected);
|
this, &SearchSettingsForm::onStartSearchSelected);
|
||||||
connect(ui->registerCheckBox, &QCheckBox::clicked, this, &SearchSettingsForm::onRegisterClicked);
|
connect(ui->registerCheckBox, &QCheckBox::clicked, this, &SearchSettingsForm::onRegisterClicked);
|
||||||
connect(ui->wordsOnlyRadioButton, &QCheckBox::clicked, this, &SearchSettingsForm::onWordsOnlyClicked);
|
connect(ui->wordsOnlyRadioButton, &QCheckBox::clicked, this, &SearchSettingsForm::onWordsOnlyClicked);
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
#include "src/nexus.h"
|
#include "src/nexus.h"
|
||||||
|
@ -98,11 +101,19 @@ void PrivacyForm::showEvent(QShowEvent*)
|
||||||
void PrivacyForm::on_randomNosapamButton_clicked()
|
void PrivacyForm::on_randomNosapamButton_clicked()
|
||||||
{
|
{
|
||||||
QTime time = QTime::currentTime();
|
QTime time = QTime::currentTime();
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
|
QRandomGenerator((uint)time.msec());
|
||||||
|
#else
|
||||||
qsrand((uint)time.msec());
|
qsrand((uint)time.msec());
|
||||||
|
#endif
|
||||||
|
|
||||||
uint32_t newNospam{0};
|
uint32_t newNospam{0};
|
||||||
for (int i = 0; i < 4; ++i)
|
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.
|
newNospam = (newNospam << 8) + (qrand() % 256); // Generate byte by byte. For some reason.
|
||||||
|
#endif
|
||||||
|
|
||||||
Core::getInstance()->setNospam(newNospam);
|
Core::getInstance()->setNospam(newNospam);
|
||||||
bodyUI->nospamLineEdit->setText(Core::getInstance()->getSelfId().getNoSpamString());
|
bodyUI->nospamLineEdit->setText(Core::getInstance()->getSelfId().getNoSpamString());
|
||||||
|
|
|
@ -33,7 +33,11 @@ public:
|
||||||
GenericChatItemLayout(const GenericChatItemLayout& layout) = delete;
|
GenericChatItemLayout(const GenericChatItemLayout& layout) = delete;
|
||||||
~GenericChatItemLayout();
|
~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);
|
void addSortedWidget(GenericChatItemWidget* widget, int stretch = 0, Qt::Alignment alignment = nullptr);
|
||||||
|
#endif
|
||||||
int indexOfSortedWidget(GenericChatItemWidget* widget) const;
|
int indexOfSortedWidget(GenericChatItemWidget* widget) const;
|
||||||
bool existsSortedWidget(GenericChatItemWidget* widget) const;
|
bool existsSortedWidget(GenericChatItemWidget* widget) const;
|
||||||
void removeSortedWidget(GenericChatItemWidget* widget);
|
void removeSortedWidget(GenericChatItemWidget* widget);
|
||||||
|
|
|
@ -26,7 +26,11 @@ class ActivateDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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);
|
ActivateDialog(QWidget* parent = nullptr, Qt::WindowFlags f = nullptr);
|
||||||
|
#endif
|
||||||
bool event(QEvent* event) override;
|
bool event(QEvent* event) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user