Some qt6 prep

This commit is contained in:
Nicolas Werner 2021-12-28 20:09:08 +01:00
parent 2866826356
commit 5ca98829f7
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
32 changed files with 89 additions and 66 deletions

2
.gitignore vendored
View file

@ -26,6 +26,8 @@ GPATH
*.dylib
vgcore.*
heaptrack.*
massif.*
# Qt-es

View file

@ -64,8 +64,12 @@ public:
};
class BlurhashProvider
: public QObject
, public QQuickAsyncImageProvider
:
#if QT_VERSION < 0x60000
public QObject
,
#endif
public QQuickAsyncImageProvider
{
Q_OBJECT
public slots:

View file

@ -3835,7 +3835,7 @@ Cache::displayName(const QString &room_id, const QString &user_id)
static bool
isDisplaynameSafe(const std::string &s)
{
for (QChar c : QString::fromStdString(s).toUcs4()) {
for (QChar c : QString::fromStdString(s)) {
if (c.isPrint() && !c.isSpace())
return false;
}

View file

@ -62,7 +62,6 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
topLayout_ = new QHBoxLayout(this);
topLayout_->setSpacing(0);
topLayout_->setMargin(0);
view_manager_ = new TimelineViewManager(callManager_, this);
@ -1303,7 +1302,7 @@ ChatPage::handleMatrixUri(QString uri)
auto tempPath = uri_.path(QUrl::ComponentFormattingOption::FullyEncoded);
if (tempPath.startsWith('/'))
tempPath.remove(0, 1);
auto segments = tempPath.splitRef('/');
auto segments = QStringView(tempPath).split('/');
if (segments.size() != 2 && segments.size() != 4)
return false;
@ -1314,7 +1313,7 @@ ChatPage::handleMatrixUri(QString uri)
return false;
QString mxid2;
if (segments.size() == 4 && segments[2] == "e") {
if (segments.size() == 4 && segments[2] == QStringView(u"e")) {
if (segments[3].isEmpty())
return false;
else

View file

@ -48,7 +48,7 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
.toString()
.toLower();
for (const auto &e : string1.splitRef(splitPoints)) {
for (const auto &e : QStringView(string1).split(splitPoints)) {
if (!e.isEmpty()) // NOTE(Nico): Use Qt::SkipEmptyParts in Qt 5.14
trie_.insert(e.toUcs4(), i);
}
@ -59,7 +59,7 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
.toLower();
if (!string2.isEmpty()) {
for (const auto &e : string2.splitRef(splitPoints)) {
for (const auto &e : QStringView(string2).split(splitPoints)) {
if (!e.isEmpty()) // NOTE(Nico): Use Qt::SkipEmptyParts in Qt 5.14
trie_.insert(e.toUcs4(), i);
}

View file

@ -53,8 +53,12 @@ public:
};
class JdenticonProvider
: public QObject
, public QQuickAsyncImageProvider
:
#if QT_VERSION < 0x60000
public QObject
,
#endif
public QQuickAsyncImageProvider
{
Q_OBJECT
@ -72,11 +76,11 @@ public slots:
auto queryStart = id.lastIndexOf('?');
if (queryStart != -1) {
id_ = id.left(queryStart);
auto query = id.midRef(queryStart + 1);
auto queryBits = query.split('&');
auto query = id.mid(queryStart + 1);
auto queryBits = query.splitRef('&');
for (auto b : queryBits) {
if (b.startsWith("radius=")) {
if (b.startsWith(QStringView(u"radius="))) {
radius = b.mid(7).toDouble();
}
}

View file

@ -40,7 +40,6 @@ LoginPage::LoginPage(QWidget *parent)
top_bar_layout_ = new QHBoxLayout();
top_bar_layout_->setSpacing(0);
top_bar_layout_->setMargin(0);
back_button_ = new FlatButton(this);
back_button_->setMinimumSize(QSize(30, 30));
@ -497,7 +496,7 @@ void
LoginPage::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

View file

@ -22,7 +22,7 @@ Q_DECLARE_METATYPE(mtx::responses::Sync)
Q_DECLARE_METATYPE(mtx::responses::JoinedGroups)
Q_DECLARE_METATYPE(mtx::responses::GroupProfile)
Q_DECLARE_METATYPE(nlohmann::json)
// Q_DECLARE_METATYPE(nlohmann::json)
Q_DECLARE_METATYPE(std::string)
Q_DECLARE_METATYPE(std::vector<std::string>)
Q_DECLARE_METATYPE(std::vector<QString>)
@ -54,7 +54,7 @@ init()
qRegisterMetaType<mtx::responses::JoinedGroups>();
qRegisterMetaType<mtx::responses::GroupProfile>();
qRegisterMetaType<std::string>();
qRegisterMetaType<nlohmann::json>();
// qRegisterMetaType<nlohmann::json>();
qRegisterMetaType<std::vector<std::string>>();
qRegisterMetaType<std::vector<QString>>();
qRegisterMetaType<std::map<QString, bool>>("std::map<QString, bool>");

View file

@ -32,15 +32,15 @@ MxcImageProvider::requestImageResponse(const QString &id, const QSize &requested
auto queryStart = id.lastIndexOf('?');
if (queryStart != -1) {
id_ = id.left(queryStart);
auto query = id.midRef(queryStart + 1);
auto query = QStringView(id).mid(queryStart + 1);
auto queryBits = query.split('&');
for (auto b : queryBits) {
if (b == "scale") {
if (b == QStringView(u"scale")) {
crop = false;
} else if (b.startsWith("radius=")) {
} else if (b.startsWith(QStringView(u"radius="))) {
radius = b.mid(7).toDouble();
} else if (b.startsWith("height=")) {
} else if (b.startsWith(u"height=")) {
size.setHeight(b.mid(7).toInt());
size.setWidth(0);
}
@ -109,7 +109,7 @@ MxcImageProvider::download(const QString &id,
// Protect against synapse not following the spec:
// https://github.com/matrix-org/synapse/issues/5302
&& requestedSize.height() <= 600 && requestedSize.width() <= 800) {
QString fileName = QString("%1_%2x%3_%4_radius%5")
QString fileName = QStringLiteral("%1_%2x%3_%4_radius%5")
.arg(QString::fromUtf8(id.toUtf8().toBase64(
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals)))
.arg(requestedSize.width())

View file

@ -71,8 +71,12 @@ public:
};
class MxcImageProvider
: public QObject
, public QQuickAsyncImageProvider
:
#if QT_VERSION < 0x60000
public QObject
,
#endif
public QQuickAsyncImageProvider
{
Q_OBJECT
public slots:
@ -85,7 +89,4 @@ public slots:
std::function<void(QString, QSize, QImage, QString)> then,
bool crop = true,
double radius = 0);
private:
// QThreadPool pool;
};

View file

@ -61,7 +61,6 @@ RegisterPage::RegisterPage(QWidget *parent)
logo_->setPixmap(logo.pixmap(128));
logo_layout_ = new QHBoxLayout();
logo_layout_->setMargin(0);
logo_layout_->addWidget(logo_, 0, Qt::AlignHCenter);
form_wrapper_ = new QHBoxLayout();
@ -128,7 +127,6 @@ RegisterPage::RegisterPage(QWidget *parent)
button_layout_ = new QHBoxLayout();
button_layout_->setSpacing(0);
button_layout_->setMargin(0);
error_label_ = new QLabel(this);
error_label_->setWordWrap(true);
@ -406,7 +404,7 @@ void
RegisterPage::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

View file

@ -69,7 +69,10 @@ MsgCountComposedIcon::clone() const
}
QList<QSize>
MsgCountComposedIcon::availableSizes(QIcon::Mode mode, QIcon::State state) const
MsgCountComposedIcon::availableSizes(QIcon::Mode mode, QIcon::State state)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const
#endif
{
Q_UNUSED(mode);
Q_UNUSED(state);

View file

@ -20,7 +20,11 @@ public:
void paint(QPainter *p, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
QIconEngine *clone() const override;
QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state) const override;
QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const
#endif
override;
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
int msgCount = 0;

View file

@ -771,7 +771,6 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
topBarLayout_ = new QHBoxLayout;
topBarLayout_->setSpacing(0);
topBarLayout_->setMargin(0);
topBarLayout_->addWidget(backBtn_, 1, Qt::AlignLeft | Qt::AlignVCenter);
topBarLayout_->addStretch(1);
@ -1443,7 +1442,7 @@ void
UserSettingsPage::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

View file

@ -8,7 +8,6 @@
#include <QBuffer>
#include <QComboBox>
#include <QCryptographicHash>
#include <QDesktopWidget>
#include <QGuiApplication>
#include <QImageReader>
#include <QProcessEnvironment>
@ -389,7 +388,7 @@ utils::humanReadableFingerprint(const QString &ed25519)
{
QString fingerprint;
for (int i = 0; i < ed25519.length(); i = i + 4) {
fingerprint.append(ed25519.midRef(i, 4));
fingerprint.append(QStringView(ed25519).mid(i, 4));
if (i > 0 && i % 16 == 12)
fingerprint.append('\n');
else if (i < ed25519.length())
@ -513,7 +512,8 @@ utils::markdownToHtml(const QString &text, bool rainbowify)
while ((boundaryEnd = tbf.toNextBoundary()) != -1) {
charIdx++;
// Split text to get current char
auto curChar = nodeText.midRef(boundaryStart, boundaryEnd - boundaryStart);
auto curChar =
QStringView(nodeText).mid(boundaryStart, boundaryEnd - boundaryStart);
boundaryStart = boundaryEnd;
// Don't rainbowify whitespaces
if (curChar.trimmed().isEmpty() || codepointIsEmoji(curChar.toUcs4().first())) {

View file

@ -81,7 +81,7 @@ void
WelcomePage::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

View file

@ -32,7 +32,10 @@ CreateRoom::CreateRoom(QWidget *parent)
auto layout = new QVBoxLayout(this);
layout->setSpacing(conf::modals::WIDGET_SPACING);
layout->setMargin(conf::modals::WIDGET_MARGIN);
layout->setContentsMargins(conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN);
auto buttonLayout = new QHBoxLayout();
buttonLayout->setSpacing(15);

View file

@ -25,11 +25,13 @@ FallbackAuth::FallbackAuth(const QString &authType, const QString &session, QWid
auto layout = new QVBoxLayout(this);
layout->setSpacing(conf::modals::WIDGET_SPACING);
layout->setMargin(conf::modals::WIDGET_MARGIN);
layout->setContentsMargins(conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN);
auto buttonLayout = new QHBoxLayout();
buttonLayout->setSpacing(8);
buttonLayout->setMargin(0);
openBtn_ = new QPushButton(tr("Open Fallback in Browser"), this);
cancelBtn_ = new QPushButton(tr("Cancel"), this);

View file

@ -4,7 +4,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include <QApplication>
#include <QDesktopWidget>
#include <QGuiApplication>
#include <QPainter>
#include <QScreen>

View file

@ -25,11 +25,13 @@ Logout::Logout(QWidget *parent)
auto layout = new QVBoxLayout(this);
layout->setSpacing(conf::modals::WIDGET_SPACING);
layout->setMargin(conf::modals::WIDGET_MARGIN);
layout->setContentsMargins(conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN);
auto buttonLayout = new QHBoxLayout();
buttonLayout->setSpacing(0);
buttonLayout->setMargin(0);
confirmBtn_ = new QPushButton("Logout", this);
cancelBtn_ = new QPushButton(tr("Cancel"), this);

View file

@ -33,7 +33,6 @@ PreviewUploadOverlay::PreviewUploadOverlay(QWidget *parent)
hlayout->addStretch(1);
hlayout->addWidget(&cancel_);
hlayout->addWidget(&upload_);
hlayout->setMargin(0);
auto vlayout = new QVBoxLayout{this};
vlayout->addWidget(&titleLabel_);
@ -41,7 +40,10 @@ PreviewUploadOverlay::PreviewUploadOverlay(QWidget *parent)
vlayout->addWidget(&fileName_);
vlayout->addLayout(hlayout);
vlayout->setSpacing(conf::modals::WIDGET_SPACING);
vlayout->setMargin(conf::modals::WIDGET_MARGIN);
vlayout->setContentsMargins(conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN);
upload_.setDefault(true);
connect(&upload_, &QPushButton::clicked, [this]() {
@ -217,4 +219,4 @@ PreviewUploadOverlay::keyPressEvent(QKeyEvent *event)
} else {
QWidget::keyPressEvent(event);
}
}
}

View file

@ -25,11 +25,13 @@ ReCaptcha::ReCaptcha(const QString &session, QWidget *parent)
auto layout = new QVBoxLayout(this);
layout->setSpacing(conf::modals::WIDGET_SPACING);
layout->setMargin(conf::modals::WIDGET_MARGIN);
layout->setContentsMargins(conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN);
auto buttonLayout = new QHBoxLayout();
buttonLayout->setSpacing(8);
buttonLayout->setMargin(0);
openCaptchaBtn_ = new QPushButton("Open reCAPTCHA", this);
cancelBtn_ = new QPushButton(tr("Cancel"), this);

View file

@ -8,7 +8,6 @@
#include <QApplication>
#include <QCommandLineParser>
#include <QDesktopServices>
#include <QDesktopWidget>
#include <QDir>
#include <QFile>
#include <QFontDatabase>

View file

@ -140,7 +140,7 @@ InputBar::updateAtRoom(const QString &t)
auto start = finder.position();
finder.toNextBoundary();
auto end = finder.position();
if (start > 0 && end - start >= 4 && t.midRef(start, end - start) == "room" &&
if (start > 0 && end - start >= 4 && t.mid(start, end - start) == "room" &&
t.at(start - 1) == QChar('@')) {
roomMention = true;
break;
@ -324,7 +324,7 @@ InputBar::message(const QString &msg, MarkdownOverride useMarkdown, bool rainbow
QString body;
bool firstLine = true;
for (const auto &line : related.quoted_body.split("\n")) {
for (auto line : related.quoted_body.splitRef(u'\n')) {
if (firstLine) {
firstLine = false;
body = QString("> <%1> %2\n").arg(related.quoted_user, line);
@ -707,9 +707,9 @@ InputBar::showPreview(const QMimeData &source, const QString &path, const QStrin
QSize dimensions;
QString blurhash;
auto mimeClass = mime.split("/")[0];
auto mimeClass = mime.splitRef(u'/')[0];
nhlog::ui()->debug("Mime: {}", mime.toStdString());
if (mimeClass == "image") {
if (mimeClass == u"image") {
QImage img = utils::readImage(data);
dimensions = img.size();

View file

@ -5,6 +5,7 @@
#pragma once
#include <QObject>
#include <QStringList>
#include <QTimer>
#include <deque>
@ -15,7 +16,6 @@ class TimelineModel;
class CombinedImagePackModel;
class QMimeData;
class QDropEvent;
class QStringList;
enum class MarkdownOverride
{

View file

@ -643,7 +643,7 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
// only show read receipts for messages not from us
if (acc::sender(event) != http::client()->user_id().to_string())
return qml_mtx_events::Empty;
else if (!id.isEmpty() && id[0] == "m")
else if (!id.isEmpty() && id[0] == 'm')
return qml_mtx_events::Sent;
else if (read.contains(id) || containsOthers(cache::readReceipts(id, room_id_)))
return qml_mtx_events::Read;
@ -1029,7 +1029,7 @@ TimelineModel::setCurrentIndex(int index)
if (!ChatPage::instance()->isActiveWindow())
return;
if (!currentId.startsWith("m")) {
if (!currentId.startsWith('m')) {
auto oldReadIndex =
cache::getEventIndex(roomId().toStdString(), currentReadId.toStdString());
auto nextEventIndexAndId =
@ -1759,16 +1759,16 @@ TimelineModel::formatTypingUsers(const std::vector<QString> &users, const QColor
if (startIndex - index != 0)
coloredUsername +=
prefix +
uncoloredUsername.midRef(index, startIndex > 0 ? startIndex - index : -1) +
"</font>";
prefix + uncoloredUsername.mid(index, startIndex > 0 ? startIndex - index : -1) +
QStringLiteral("</font>");
auto endIndex = uncoloredUsername.indexOf("</font>", startIndex);
if (endIndex > 0)
endIndex += sizeof("</font>") - 1;
if (endIndex - startIndex != 0)
coloredUsername += uncoloredUsername.midRef(startIndex, endIndex - startIndex);
coloredUsername +=
QStringView(uncoloredUsername).mid(startIndex, endIndex - startIndex);
index = endIndex;
} while (index > 0 && index < uncoloredUsername.size());

View file

@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include <QEvent>
#include <QPainter>
#include <QPainterPath>

View file

@ -9,7 +9,7 @@
#include <QObject>
#include <QQuickItem>
class TimelineModel;
#include "timeline/TimelineModel.h"
// This is an AnimatedImage, that can draw encrypted images
class MxcAnimatedImage : public QQuickItem

View file

@ -72,7 +72,7 @@ OverlayWidget::paintEvent(QPaintEvent *event)
Q_UNUSED(event);
QStyleOption opt;
opt.init(this);
opt.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

View file

@ -17,7 +17,7 @@ SnackBar::SnackBar(QWidget *parent)
{
QFont font;
font.setPointSizeF(font.pointSizeF() * 1.2);
font.setWeight(50);
font.setWeight(QFont::Weight::Thin);
setFont(font);
boxHeight_ = QFontMetrics(font).height() * 2;

View file

@ -12,6 +12,7 @@
#include <mtx/responses/common.hpp>
#include "CacheCryptoStructs.h"
#include "timeline/TimelineModel.h"
namespace verification {
Q_NAMESPACE
@ -28,7 +29,6 @@ Q_ENUM_NS(Status)
}
class DeviceVerificationFlow;
class TimelineModel;
class TimelineViewManager;
class DeviceInfo

View file

@ -10,6 +10,7 @@
#include <QMediaPlayer>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QTimer>
#include "CallDevices.h"
@ -21,7 +22,6 @@ namespace mtx::responses {
struct TurnServer;
}
class QStringList;
class QUrl;
class CallManager : public QObject