From 4011260d37111c480a9be7bdbb1213263ccb410c Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 28 Dec 2021 06:30:51 +0100 Subject: [PATCH] WIP Qt6 bits --- meson.build | 29 +--- src/BlurhashProvider.h | 4 +- src/Cache.cpp | 2 +- src/ChatPage.cpp | 19 ++- src/CompletionProxyModel.cpp | 4 +- src/JdenticonProvider.h | 6 +- src/LoginPage.cpp | 3 +- src/MatrixClient.cpp | 4 +- src/MxcImageProvider.cpp | 6 +- src/MxcImageProvider.h | 4 +- src/RegisterPage.cpp | 4 +- src/TrayIcon.cpp | 2 +- src/TrayIcon.h | 2 +- src/UserSettingsPage.cpp | 3 +- src/Utils.cpp | 6 +- src/WelcomePage.cpp | 2 +- src/dialogs/CreateRoom.cpp | 5 +- src/dialogs/FallbackAuth.cpp | 6 +- src/dialogs/ImageOverlay.cpp | 1 - src/dialogs/Logout.cpp | 6 +- src/dialogs/PreviewUploadOverlay.cpp | 8 +- src/dialogs/ReCaptcha.cpp | 6 +- src/main.cpp | 1 - src/timeline/DelegateChooser.cpp | 4 +- src/timeline/DelegateChooser.h | 4 +- src/timeline/InputBar.cpp | 2 +- src/timeline/InputBar.h | 2 +- src/timeline/TimelineModel.cpp | 9 +- src/ui/FlatButton.cpp | 215 --------------------------- src/ui/FlatButton.h | 67 --------- src/ui/FloatingButton.cpp | 1 + src/ui/MxcAnimatedImage.h | 2 +- src/ui/OverlayWidget.cpp | 2 +- src/ui/RaisedButton.cpp | 59 -------- src/ui/RaisedButton.h | 7 - src/ui/SnackBar.cpp | 2 +- src/ui/TextField.cpp | 151 ------------------- src/ui/TextField.h | 45 ------ src/ui/UserProfile.h | 2 +- src/voip/CallManager.h | 2 +- 40 files changed, 72 insertions(+), 637 deletions(-) diff --git a/meson.build b/meson.build index 5b6ef257..75546c50 100644 --- a/meson.build +++ b/meson.build @@ -9,7 +9,7 @@ project( compiler = meson.get_compiler('cpp') -qt5 = import('qt5') +qt5 = import('qt6') qt5_modules = ['Core', 'Gui', 'Qml', 'Quick', 'QuickWidgets', 'Widgets', 'Multimedia', 'Svg'] if target_machine.system() == 'windows' #qt5_modules += 'WinMain' @@ -19,7 +19,7 @@ else qt5_modules += 'DBus' endif -qt5_dep = dependency('qt5', modules: qt5_modules, include_type: 'system') +qt5_dep = dependency('qt6', modules: qt5_modules, include_type: 'system') inc = include_directories('src', 'includes', 'third_party/cpp-httplib-0.5.12') @@ -61,28 +61,9 @@ if not lmdbxx_dep.found() endif deps += lmdbxx_dep -qtkeychain_dep = dependency('Qt5Keychain', required: get_option('wrap_mode') == 'nofallback') -if (not qtkeychain_dep.found() - or get_option('wrap_mode') == 'forcefallback' - or 'QtKeychain' in get_option('force_fallback_for')) - cmake = import('cmake') - qtkeychain_options = cmake.subproject_options() - qtkeychain_options.add_cmake_defines({ - 'BUILD_SHARED_LIBS': false, - }) - if target_machine.system() != 'windows' - qtkeychain_options.add_cmake_defines({ - 'CMAKE_C_FLAGS': '-fPIC', - }) - endif - qtkeychain_options.set_override_option('werror', 'false') - qtkeychain_options.set_override_option('warning_level', '0') - qtkeychain_proj = cmake.subproject('QtKeychain', options: qtkeychain_options) - qtkeychain_dep = qtkeychain_proj.dependency('qt5keychain') - - if target_machine.system() == 'linux' or target_machine.system() == 'freebsd' or target_machine.system() == 'netbsd' or target_machine.system() == 'openbsd' or target_machine.system() == 'dragonfly' - deps += dependency('libsecret-1', default_options: ['manpage=false', 'vapi=false', 'gtk_doc=false', 'introspection=false',], include_type: 'system') # 'bash_completion=disabled']) - endif +qtkeychain_dep = dependency('Qt6Keychain', required: get_option('wrap_mode') == 'nofallback') +if (not qtkeychain_dep.found()) + qtkeychain_dep = dependency('qtkeychain') endif deps += qtkeychain_dep diff --git a/src/BlurhashProvider.h b/src/BlurhashProvider.h index 7f6f31c9..9934c7f4 100644 --- a/src/BlurhashProvider.h +++ b/src/BlurhashProvider.h @@ -63,9 +63,7 @@ public: QImage m_image; }; -class BlurhashProvider - : public QObject - , public QQuickAsyncImageProvider +class BlurhashProvider : public QQuickAsyncImageProvider { Q_OBJECT public slots: diff --git a/src/Cache.cpp b/src/Cache.cpp index dd26157c..39b21799 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -3833,7 +3833,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; } diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 86e2141f..a66ed028 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -62,7 +62,6 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) topLayout_ = new QHBoxLayout(this); topLayout_->setSpacing(0); - topLayout_->setMargin(0); view_manager_ = new TimelineViewManager(callManager_, this); @@ -1231,18 +1230,18 @@ ChatPage::startChat(QString userid) } static QString -mxidFromSegments(QStringRef sigil, QStringRef mxid) +mxidFromSegments(QStringView sigil, QStringView mxid) { if (mxid.isEmpty()) return ""; auto mxid_ = QUrl::fromPercentEncoding(mxid.toUtf8()); - if (sigil == "u") { + if (sigil == QAnyStringView("u")) { return "@" + mxid_; - } else if (sigil == "roomid") { + } else if (sigil == QAnyStringView("roomid")) { return "!" + mxid_; - } else if (sigil == "r") { + } else if (sigil == QAnyStringView("r")) { return "#" + mxid_; //} else if (sigil == "group") { // return "+" + mxid_; @@ -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] == QAnyStringView("e")) { if (segments[3].isEmpty()) return false; else @@ -1335,7 +1334,7 @@ ChatPage::handleMatrixUri(QString uri) } } - if (sigil1 == "u") { + if (sigil1 == QAnyStringView("u")) { if (action.isEmpty()) { auto t = view_manager_->rooms()->currentRoom(); if (t && cache::isRoomMember(mxid1.toStdString(), t->roomId().toStdString())) { @@ -1347,7 +1346,7 @@ ChatPage::handleMatrixUri(QString uri) this->startChat(mxid1); } return true; - } else if (sigil1 == "roomid") { + } else if (sigil1 == QAnyStringView("roomid")) { auto joined_rooms = cache::joinedRooms(); auto targetRoomId = mxid1.toStdString(); @@ -1365,7 +1364,7 @@ ChatPage::handleMatrixUri(QString uri) return true; } return false; - } else if (sigil1 == "r") { + } else if (sigil1 == QAnyStringView("r")) { auto joined_rooms = cache::joinedRooms(); auto targetRoomAlias = mxid1.toStdString(); diff --git a/src/CompletionProxyModel.cpp b/src/CompletionProxyModel.cpp index 454f54b7..bb0a05c6 100644 --- a/src/CompletionProxyModel.cpp +++ b/src/CompletionProxyModel.cpp @@ -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); } diff --git a/src/JdenticonProvider.h b/src/JdenticonProvider.h index c355eae7..78e107ae 100644 --- a/src/JdenticonProvider.h +++ b/src/JdenticonProvider.h @@ -52,9 +52,7 @@ public: QImage m_pixmap; }; -class JdenticonProvider - : public QObject - , public QQuickAsyncImageProvider +class JdenticonProvider : public QQuickAsyncImageProvider { Q_OBJECT @@ -72,7 +70,7 @@ public slots: auto queryStart = id.lastIndexOf('?'); if (queryStart != -1) { id_ = id.left(queryStart); - auto query = id.midRef(queryStart + 1); + auto query = id.mid(queryStart + 1); auto queryBits = query.split('&'); for (auto b : queryBits) { diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index 656ee2d9..00a5b964 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -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); } diff --git a/src/MatrixClient.cpp b/src/MatrixClient.cpp index 35277a69..38329f88 100644 --- a/src/MatrixClient.cpp +++ b/src/MatrixClient.cpp @@ -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) Q_DECLARE_METATYPE(std::vector) @@ -54,7 +54,7 @@ init() qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); - qRegisterMetaType(); + // qRegisterMetaType(); qRegisterMetaType>(); qRegisterMetaType>(); qRegisterMetaType>("std::map"); diff --git a/src/MxcImageProvider.cpp b/src/MxcImageProvider.cpp index 4834c2fc..4e1e41a0 100644 --- a/src/MxcImageProvider.cpp +++ b/src/MxcImageProvider.cpp @@ -31,13 +31,13 @@ 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 == QAnyStringView("scale")) { crop = false; - } else if (b.startsWith("radius=")) { + } else if (b.startsWith(QLatin1String("radius="))) { radius = b.mid(7).toDouble(); } } diff --git a/src/MxcImageProvider.h b/src/MxcImageProvider.h index 89c3d9aa..dbf492bc 100644 --- a/src/MxcImageProvider.h +++ b/src/MxcImageProvider.h @@ -70,9 +70,7 @@ public: QImage m_image; }; -class MxcImageProvider - : public QObject - , public QQuickAsyncImageProvider +class MxcImageProvider : public QQuickAsyncImageProvider { Q_OBJECT public slots: diff --git a/src/RegisterPage.cpp b/src/RegisterPage.cpp index 062a04ab..646ef103 100644 --- a/src/RegisterPage.cpp +++ b/src/RegisterPage.cpp @@ -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); } diff --git a/src/TrayIcon.cpp b/src/TrayIcon.cpp index 98a1d242..19ec5b7f 100644 --- a/src/TrayIcon.cpp +++ b/src/TrayIcon.cpp @@ -69,7 +69,7 @@ MsgCountComposedIcon::clone() const } QList -MsgCountComposedIcon::availableSizes(QIcon::Mode mode, QIcon::State state) const +MsgCountComposedIcon::availableSizes(QIcon::Mode mode, QIcon::State state) { Q_UNUSED(mode); Q_UNUSED(state); diff --git a/src/TrayIcon.h b/src/TrayIcon.h index 1ce7fb0b..55bb14b1 100644 --- a/src/TrayIcon.h +++ b/src/TrayIcon.h @@ -20,7 +20,7 @@ public: void paint(QPainter *p, const QRect &rect, QIcon::Mode mode, QIcon::State state) override; QIconEngine *clone() const override; - QList availableSizes(QIcon::Mode mode, QIcon::State state) const override; + QList availableSizes(QIcon::Mode mode, QIcon::State state) override; QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override; int msgCount = 0; diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index d4455d58..9b659fc0 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -771,7 +771,6 @@ UserSettingsPage::UserSettingsPage(QSharedPointer 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); } diff --git a/src/Utils.cpp b/src/Utils.cpp index aebb1bc6..1cfda279 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -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())) { diff --git a/src/WelcomePage.cpp b/src/WelcomePage.cpp index c7168789..e29d6576 100644 --- a/src/WelcomePage.cpp +++ b/src/WelcomePage.cpp @@ -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); } diff --git a/src/dialogs/CreateRoom.cpp b/src/dialogs/CreateRoom.cpp index 30dbf83d..153d36c0 100644 --- a/src/dialogs/CreateRoom.cpp +++ b/src/dialogs/CreateRoom.cpp @@ -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); diff --git a/src/dialogs/FallbackAuth.cpp b/src/dialogs/FallbackAuth.cpp index 2b8dfed9..0d8be237 100644 --- a/src/dialogs/FallbackAuth.cpp +++ b/src/dialogs/FallbackAuth.cpp @@ -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); diff --git a/src/dialogs/ImageOverlay.cpp b/src/dialogs/ImageOverlay.cpp index 551e0041..8890814d 100644 --- a/src/dialogs/ImageOverlay.cpp +++ b/src/dialogs/ImageOverlay.cpp @@ -4,7 +4,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include -#include #include #include #include diff --git a/src/dialogs/Logout.cpp b/src/dialogs/Logout.cpp index d10e4cdf..45cef6a5 100644 --- a/src/dialogs/Logout.cpp +++ b/src/dialogs/Logout.cpp @@ -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); diff --git a/src/dialogs/PreviewUploadOverlay.cpp b/src/dialogs/PreviewUploadOverlay.cpp index 2e95bd91..338f0635 100644 --- a/src/dialogs/PreviewUploadOverlay.cpp +++ b/src/dialogs/PreviewUploadOverlay.cpp @@ -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); } -} \ No newline at end of file +} diff --git a/src/dialogs/ReCaptcha.cpp b/src/dialogs/ReCaptcha.cpp index 0ae46bba..982c17b6 100644 --- a/src/dialogs/ReCaptcha.cpp +++ b/src/dialogs/ReCaptcha.cpp @@ -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); diff --git a/src/main.cpp b/src/main.cpp index 2508b729..2b6478cf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/src/timeline/DelegateChooser.cpp b/src/timeline/DelegateChooser.cpp index 682077ae..36a11376 100644 --- a/src/timeline/DelegateChooser.cpp +++ b/src/timeline/DelegateChooser.cpp @@ -76,13 +76,13 @@ DelegateChooser::appendChoice(QQmlListProperty *p, DelegateChoic dc->choices_.append(c); } -int +qsizetype DelegateChooser::choiceCount(QQmlListProperty *p) { return static_cast(p->object)->choices_.count(); } DelegateChoice * -DelegateChooser::choice(QQmlListProperty *p, int index) +DelegateChooser::choice(QQmlListProperty *p, qsizetype index) { return static_cast(p->object)->choices_.at(index); } diff --git a/src/timeline/DelegateChooser.h b/src/timeline/DelegateChooser.h index 3e4b16d7..fc6016b9 100644 --- a/src/timeline/DelegateChooser.h +++ b/src/timeline/DelegateChooser.h @@ -84,7 +84,7 @@ private: DelegateIncubator incubator{*this}; static void appendChoice(QQmlListProperty *, DelegateChoice *); - static int choiceCount(QQmlListProperty *); - static DelegateChoice *choice(QQmlListProperty *, int index); + static qsizetype choiceCount(QQmlListProperty *); + static DelegateChoice *choice(QQmlListProperty *, qsizetype index); static void clearChoices(QQmlListProperty *); }; diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 191160ea..597899b7 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -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; diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index 65593244..c63a8618 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include @@ -15,7 +16,6 @@ class TimelineModel; class CombinedImagePackModel; class QMimeData; class QDropEvent; -class QStringList; enum class MarkdownOverride { diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index b9941dfa..31112080 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -616,7 +616,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; @@ -1002,7 +1002,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 = @@ -1730,8 +1730,7 @@ TimelineModel::formatTypingUsers(const std::vector &users, QColor bg) if (startIndex - index != 0) coloredUsername += - prefix + - uncoloredUsername.midRef(index, startIndex > 0 ? startIndex - index : -1) + + prefix + uncoloredUsername.mid(index, startIndex > 0 ? startIndex - index : -1) + ""; auto endIndex = uncoloredUsername.indexOf("", startIndex); @@ -1739,7 +1738,7 @@ TimelineModel::formatTypingUsers(const std::vector &users, QColor bg) endIndex += sizeof("") - 1; if (endIndex - startIndex != 0) - coloredUsername += uncoloredUsername.midRef(startIndex, endIndex - startIndex); + coloredUsername += uncoloredUsername.mid(startIndex, endIndex - startIndex); index = endIndex; } while (index > 0 && index < uncoloredUsername.size()); diff --git a/src/ui/FlatButton.cpp b/src/ui/FlatButton.cpp index c80a88dc..3a510503 100644 --- a/src/ui/FlatButton.cpp +++ b/src/ui/FlatButton.cpp @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -#include #include #include #include @@ -10,7 +9,6 @@ #include #include #include -#include #include "FlatButton.h" #include "Ripple.h" @@ -37,7 +35,6 @@ void FlatButton::init() { ripple_overlay_ = new RippleOverlay(this); - state_machine_ = new FlatButtonStateMachine(this); role_ = ui::Role::Default; ripple_style_ = ui::RippleStyle::PositionedRipple; icon_placement_ = ui::ButtonIconPlacement::LeftIcon; @@ -59,9 +56,6 @@ FlatButton::init() ripple_overlay_->setClipPath(path); ripple_overlay_->setClipping(true); - - state_machine_->setupProperties(); - state_machine_->startAnimations(); } FlatButton::FlatButton(QWidget *parent, ui::ButtonPreset preset) @@ -106,7 +100,6 @@ void FlatButton::setRole(ui::Role role) { role_ = role; - state_machine_->setupProperties(); } ui::Role @@ -290,7 +283,6 @@ void FlatButton::setBackgroundMode(Qt::BGMode mode) { bg_mode_ = mode; - state_machine_->setupProperties(); } Qt::BGMode @@ -303,7 +295,6 @@ void FlatButton::setBaseOpacity(qreal opacity) { base_opacity_ = opacity; - state_machine_->setupProperties(); } qreal @@ -315,9 +306,6 @@ FlatButton::baseOpacity() const void FlatButton::setCheckable(bool value) { - state_machine_->updateCheckedStatus(); - state_machine_->setCheckedOverlayProgress(0); - QPushButton::setCheckable(value); } @@ -361,7 +349,6 @@ FlatButton::sizeHint() const void FlatButton::checkStateSet() { - state_machine_->updateCheckedStatus(); QPushButton::checkStateSet(); } @@ -402,7 +389,6 @@ void FlatButton::mouseReleaseEvent(QMouseEvent *event) { QPushButton::mouseReleaseEvent(event); - state_machine_->updateCheckedStatus(); } void @@ -441,9 +427,6 @@ FlatButton::paintEvent(QPaintEvent *event) void FlatButton::paintBackground(QPainter *painter) { - const qreal overlayOpacity = state_machine_->overlayOpacity(); - const qreal checkedProgress = state_machine_->checkedOverlayProgress(); - if (Qt::OpaqueMode == bg_mode_) { QBrush brush; brush.setStyle(Qt::SolidPattern); @@ -468,27 +451,6 @@ FlatButton::paintBackground(QPainter *painter) return; } - if ((ui::OverlayStyle::NoOverlay != overlay_style_) && (overlayOpacity > 0)) { - if (ui::OverlayStyle::TintedOverlay == overlay_style_) { - brush.setColor(overlayColor()); - } else { - brush.setColor(Qt::gray); - } - - painter->setOpacity(overlayOpacity); - painter->setBrush(brush); - painter->drawRect(rect()); - } - - if (isCheckable() && checkedProgress > 0) { - const qreal q = Qt::TransparentMode == bg_mode_ ? 0.45 : 0.7; - brush.setColor(foregroundColor()); - painter->setOpacity(q * checkedProgress); - painter->setBrush(brush); - QRect r(rect()); - r.setHeight(static_cast(r.height()) * checkedProgress); - painter->drawRect(r); - } } #define COLOR_INTERPOLATE(CH) (1 - progress) * source.CH() + progress *dest.CH() @@ -498,20 +460,6 @@ FlatButton::paintForeground(QPainter *painter) { if (isEnabled()) { painter->setPen(foregroundColor()); - const qreal progress = state_machine_->checkedOverlayProgress(); - - if (isCheckable() && progress > 0) { - QColor source = foregroundColor(); - QColor dest = Qt::TransparentMode == bg_mode_ ? Qt::white : backgroundColor(); - if (qFuzzyCompare(1, progress)) { - painter->setPen(dest); - } else { - painter->setPen(QColor(COLOR_INTERPOLATE(red), - COLOR_INTERPOLATE(green), - COLOR_INTERPOLATE(blue), - COLOR_INTERPOLATE(alpha))); - } - } } else { painter->setPen(disabledForegroundColor()); } @@ -555,166 +503,3 @@ FlatButton::updateClipPath() ripple_overlay_->setClipPath(path); } -FlatButtonStateMachine::FlatButtonStateMachine(FlatButton *parent) - : QStateMachine(parent) - , button_(parent) - , top_level_state_(new QState(QState::ParallelStates)) - , config_state_(new QState(top_level_state_)) - , checkable_state_(new QState(top_level_state_)) - , checked_state_(new QState(checkable_state_)) - , unchecked_state_(new QState(checkable_state_)) - , neutral_state_(new QState(config_state_)) - , neutral_focused_state_(new QState(config_state_)) - , hovered_state_(new QState(config_state_)) - , hovered_focused_state_(new QState(config_state_)) - , pressed_state_(new QState(config_state_)) - , overlay_opacity_(0) - , checked_overlay_progress_(parent->isChecked() ? 1 : 0) - , was_checked_(false) -{ - Q_ASSERT(parent); - - parent->installEventFilter(this); - - config_state_->setInitialState(neutral_state_); - addState(top_level_state_); - setInitialState(top_level_state_); - - checkable_state_->setInitialState(parent->isChecked() ? checked_state_ : unchecked_state_); - QSignalTransition *transition; - QPropertyAnimation *animation; - - transition = new QSignalTransition(this, SIGNAL(buttonChecked())); - transition->setTargetState(checked_state_); - unchecked_state_->addTransition(transition); - - animation = new QPropertyAnimation(this, "checkedOverlayProgress", this); - animation->setDuration(200); - transition->addAnimation(animation); - - transition = new QSignalTransition(this, SIGNAL(buttonUnchecked())); - transition->setTargetState(unchecked_state_); - checked_state_->addTransition(transition); - - animation = new QPropertyAnimation(this, "checkedOverlayProgress", this); - animation->setDuration(200); - transition->addAnimation(animation); - - addTransition(button_, QEvent::FocusIn, neutral_state_, neutral_focused_state_); - addTransition(button_, QEvent::FocusOut, neutral_focused_state_, neutral_state_); - addTransition(button_, QEvent::Enter, neutral_state_, hovered_state_); - addTransition(button_, QEvent::Leave, hovered_state_, neutral_state_); - addTransition(button_, QEvent::Enter, neutral_focused_state_, hovered_focused_state_); - addTransition(button_, QEvent::Leave, hovered_focused_state_, neutral_focused_state_); - addTransition(button_, QEvent::FocusIn, hovered_state_, hovered_focused_state_); - addTransition(button_, QEvent::FocusOut, hovered_focused_state_, hovered_state_); - addTransition(this, SIGNAL(buttonPressed()), hovered_state_, pressed_state_); - addTransition(button_, QEvent::Leave, pressed_state_, neutral_focused_state_); - addTransition(button_, QEvent::FocusOut, pressed_state_, hovered_state_); -} - -void -FlatButtonStateMachine::setOverlayOpacity(qreal opacity) -{ - overlay_opacity_ = opacity; - button_->update(); -} - -void -FlatButtonStateMachine::setCheckedOverlayProgress(qreal opacity) -{ - checked_overlay_progress_ = opacity; - button_->update(); -} - -void -FlatButtonStateMachine::startAnimations() -{ - start(); -} - -void -FlatButtonStateMachine::setupProperties() -{ - QColor overlayColor; - - if (Qt::TransparentMode == button_->backgroundMode()) { - overlayColor = button_->backgroundColor(); - } else { - overlayColor = button_->foregroundColor(); - } - - const qreal baseOpacity = button_->baseOpacity(); - - neutral_state_->assignProperty(this, "overlayOpacity", 0); - neutral_focused_state_->assignProperty(this, "overlayOpacity", 0); - hovered_state_->assignProperty(this, "overlayOpacity", baseOpacity); - hovered_focused_state_->assignProperty(this, "overlayOpacity", baseOpacity); - pressed_state_->assignProperty(this, "overlayOpacity", baseOpacity); - checked_state_->assignProperty(this, "checkedOverlayProgress", 1); - unchecked_state_->assignProperty(this, "checkedOverlayProgress", 0); - - button_->update(); -} - -void -FlatButtonStateMachine::updateCheckedStatus() -{ - const bool checked = button_->isChecked(); - if (was_checked_ != checked) { - was_checked_ = checked; - if (checked) { - emit buttonChecked(); - } else { - emit buttonUnchecked(); - } - } -} - -bool -FlatButtonStateMachine::eventFilter(QObject *watched, QEvent *event) -{ - if (QEvent::FocusIn == event->type()) { - QFocusEvent *focusEvent = static_cast(event); - if (focusEvent && Qt::MouseFocusReason == focusEvent->reason()) { - emit buttonPressed(); - return true; - } - } - - return QStateMachine::eventFilter(watched, event); -} - -void -FlatButtonStateMachine::addTransition(QObject *object, - const char *signal, - QState *fromState, - QState *toState) -{ - addTransition(new QSignalTransition(object, signal), fromState, toState); -} - -void -FlatButtonStateMachine::addTransition(QObject *object, - QEvent::Type eventType, - QState *fromState, - QState *toState) -{ - addTransition(new QEventTransition(object, eventType), fromState, toState); -} - -void -FlatButtonStateMachine::addTransition(QAbstractTransition *transition, - QState *fromState, - QState *toState) -{ - transition->setTargetState(toState); - - QPropertyAnimation *animation; - - animation = new QPropertyAnimation(this, "overlayOpacity", this); - animation->setDuration(150); - transition->addAnimation(animation); - - fromState->addTransition(transition); -} diff --git a/src/ui/FlatButton.h b/src/ui/FlatButton.h index 3f2c3f05..79ab4010 100644 --- a/src/ui/FlatButton.h +++ b/src/ui/FlatButton.h @@ -5,77 +5,11 @@ #pragma once #include -#include #include "Theme.h" class RippleOverlay; -class FlatButton; -class FlatButtonStateMachine : public QStateMachine -{ - Q_OBJECT - - Q_PROPERTY(qreal overlayOpacity WRITE setOverlayOpacity READ overlayOpacity) - Q_PROPERTY( - qreal checkedOverlayProgress WRITE setCheckedOverlayProgress READ checkedOverlayProgress) - -public: - explicit FlatButtonStateMachine(FlatButton *parent); - - void setOverlayOpacity(qreal opacity); - void setCheckedOverlayProgress(qreal opacity); - - inline qreal overlayOpacity() const; - inline qreal checkedOverlayProgress() const; - - void startAnimations(); - void setupProperties(); - void updateCheckedStatus(); - -signals: - void buttonPressed(); - void buttonChecked(); - void buttonUnchecked(); - -protected: - bool eventFilter(QObject *watched, QEvent *event) override; - -private: - void addTransition(QObject *object, const char *signal, QState *fromState, QState *toState); - void addTransition(QObject *object, QEvent::Type eventType, QState *fromState, QState *toState); - void addTransition(QAbstractTransition *transition, QState *fromState, QState *toState); - - FlatButton *const button_; - - QState *const top_level_state_; - QState *const config_state_; - QState *const checkable_state_; - QState *const checked_state_; - QState *const unchecked_state_; - QState *const neutral_state_; - QState *const neutral_focused_state_; - QState *const hovered_state_; - QState *const hovered_focused_state_; - QState *const pressed_state_; - - qreal overlay_opacity_; - qreal checked_overlay_progress_; - - bool was_checked_; -}; - -inline qreal -FlatButtonStateMachine::overlayOpacity() const -{ - return overlay_opacity_; -} - -inline qreal -FlatButtonStateMachine::checkedOverlayProgress() const -{ - return checked_overlay_progress_; -} class FlatButton : public QPushButton { @@ -158,7 +92,6 @@ protected: private: RippleOverlay *ripple_overlay_; - FlatButtonStateMachine *state_machine_; ui::Role role_; ui::RippleStyle ripple_style_; diff --git a/src/ui/FloatingButton.cpp b/src/ui/FloatingButton.cpp index 3f88e313..5dc777d2 100644 --- a/src/ui/FloatingButton.cpp +++ b/src/ui/FloatingButton.cpp @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: GPL-3.0-or-later +#include #include #include diff --git a/src/ui/MxcAnimatedImage.h b/src/ui/MxcAnimatedImage.h index c3ca24d1..0b678ab6 100644 --- a/src/ui/MxcAnimatedImage.h +++ b/src/ui/MxcAnimatedImage.h @@ -9,7 +9,7 @@ #include #include -class TimelineModel; +#include "timeline/TimelineModel.h" // This is an AnimatedImage, that can draw encrypted images class MxcAnimatedImage : public QQuickItem diff --git a/src/ui/OverlayWidget.cpp b/src/ui/OverlayWidget.cpp index 4e338753..f47c035c 100644 --- a/src/ui/OverlayWidget.cpp +++ b/src/ui/OverlayWidget.cpp @@ -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); } diff --git a/src/ui/RaisedButton.cpp b/src/ui/RaisedButton.cpp index 42afdd37..88383eef 100644 --- a/src/ui/RaisedButton.cpp +++ b/src/ui/RaisedButton.cpp @@ -2,63 +2,14 @@ // // SPDX-License-Identifier: GPL-3.0-or-later -#include -#include - #include "RaisedButton.h" void RaisedButton::init() { - shadow_state_machine_ = new QStateMachine(this); - normal_state_ = new QState; - pressed_state_ = new QState; - effect_ = new QGraphicsDropShadowEffect; - - effect_->setBlurRadius(7); - effect_->setOffset(QPointF(0, 2)); - effect_->setColor(QColor(0, 0, 0, 75)); - setBackgroundMode(Qt::OpaqueMode); setMinimumHeight(42); - setGraphicsEffect(effect_); setBaseOpacity(0.3); - - shadow_state_machine_->addState(normal_state_); - shadow_state_machine_->addState(pressed_state_); - - normal_state_->assignProperty(effect_, "offset", QPointF(0, 2)); - normal_state_->assignProperty(effect_, "blurRadius", 7); - - pressed_state_->assignProperty(effect_, "offset", QPointF(0, 5)); - pressed_state_->assignProperty(effect_, "blurRadius", 29); - - QAbstractTransition *transition; - - transition = new QEventTransition(this, QEvent::MouseButtonPress); - transition->setTargetState(pressed_state_); - normal_state_->addTransition(transition); - - transition = new QEventTransition(this, QEvent::MouseButtonDblClick); - transition->setTargetState(pressed_state_); - normal_state_->addTransition(transition); - - transition = new QEventTransition(this, QEvent::MouseButtonRelease); - transition->setTargetState(normal_state_); - pressed_state_->addTransition(transition); - - QPropertyAnimation *animation; - - animation = new QPropertyAnimation(effect_, "offset", this); - animation->setDuration(100); - shadow_state_machine_->addDefaultAnimation(animation); - - animation = new QPropertyAnimation(effect_, "blurRadius", this); - animation->setDuration(100); - shadow_state_machine_->addDefaultAnimation(animation); - - shadow_state_machine_->setInitialState(normal_state_); - shadow_state_machine_->start(); } RaisedButton::RaisedButton(QWidget *parent) @@ -77,15 +28,5 @@ RaisedButton::RaisedButton(const QString &text, QWidget *parent) bool RaisedButton::event(QEvent *event) { - if (QEvent::EnabledChange == event->type()) { - if (isEnabled()) { - shadow_state_machine_->start(); - effect_->setEnabled(true); - } else { - shadow_state_machine_->stop(); - effect_->setEnabled(false); - } - } - return FlatButton::event(event); } diff --git a/src/ui/RaisedButton.h b/src/ui/RaisedButton.h index a93fa000..03221ce3 100644 --- a/src/ui/RaisedButton.h +++ b/src/ui/RaisedButton.h @@ -5,8 +5,6 @@ #pragma once #include -#include -#include #include "FlatButton.h" @@ -23,9 +21,4 @@ protected: private: void init(); - - QStateMachine *shadow_state_machine_; - QState *normal_state_; - QState *pressed_state_; - QGraphicsDropShadowEffect *effect_; }; diff --git a/src/ui/SnackBar.cpp b/src/ui/SnackBar.cpp index 90187154..077cb9de 100644 --- a/src/ui/SnackBar.cpp +++ b/src/ui/SnackBar.cpp @@ -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; diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp index 8f1a6aa5..e5be67dd 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp @@ -5,7 +5,6 @@ #include "TextField.h" #include -#include #include #include #include @@ -20,7 +19,6 @@ TextField::TextField(QWidget *parent) QPalette pal; - state_machine_ = new TextFieldStateMachine(this); label_ = nullptr; label_font_size_ = 15; show_label_ = false; @@ -32,7 +30,6 @@ TextField::TextField(QWidget *parent) setMouseTracking(true); setTextMargins(0, 4, 0, 6); - state_machine_->start(); QCoreApplication::processEvents(); } @@ -59,7 +56,6 @@ TextField::setShowLabel(bool value) if (!label_ && value) { label_ = new TextFieldLabel(this); - state_machine_->setLabel(label_); } if (value) { @@ -211,7 +207,6 @@ TextField::paintEvent(QPaintEvent *event) QPainter painter(this); if (text().isEmpty()) { - painter.setOpacity(1 - state_machine_->progress()); painter.fillRect(rect(), backgroundColor()); } @@ -228,150 +223,4 @@ TextField::paintEvent(QPaintEvent *event) QBrush brush; brush.setStyle(Qt::SolidPattern); brush.setColor(inkColor()); - - const qreal progress = state_machine_->progress(); - - if (progress > 0) { - painter.setPen(Qt::NoPen); - painter.setBrush(brush); - const int w = (1 - progress) * static_cast(wd / 2); - painter.drawRect(w + 2.5, height() - 2, wd - 2 * w, 2); - } -} - -TextFieldStateMachine::TextFieldStateMachine(TextField *parent) - : QStateMachine(parent) - , text_field_(parent) -{ - normal_state_ = new QState; - focused_state_ = new QState; - - label_ = nullptr; - offset_anim_ = nullptr; - color_anim_ = nullptr; - progress_ = 0.0; - - addState(normal_state_); - addState(focused_state_); - - setInitialState(normal_state_); - - QEventTransition *transition; - QPropertyAnimation *animation; - - transition = new QEventTransition(parent, QEvent::FocusIn); - transition->setTargetState(focused_state_); - normal_state_->addTransition(transition); - - animation = new QPropertyAnimation(this, "progress", this); - animation->setEasingCurve(QEasingCurve::InCubic); - animation->setDuration(310); - transition->addAnimation(animation); - - transition = new QEventTransition(parent, QEvent::FocusOut); - transition->setTargetState(normal_state_); - focused_state_->addTransition(transition); - - animation = new QPropertyAnimation(this, "progress", this); - animation->setEasingCurve(QEasingCurve::OutCubic); - animation->setDuration(310); - transition->addAnimation(animation); - - normal_state_->assignProperty(this, "progress", 0); - focused_state_->assignProperty(this, "progress", 1); - - setupProperties(); - - connect(text_field_, SIGNAL(textChanged(QString)), this, SLOT(setupProperties())); -} - -void -TextFieldStateMachine::setLabel(TextFieldLabel *label) -{ - if (label_) { - delete label_; - } - - if (offset_anim_) { - removeDefaultAnimation(offset_anim_); - delete offset_anim_; - } - - if (color_anim_) { - removeDefaultAnimation(color_anim_); - delete color_anim_; - } - - label_ = label; - - if (label_) { - offset_anim_ = new QPropertyAnimation(label_, "offset", this); - offset_anim_->setDuration(210); - offset_anim_->setEasingCurve(QEasingCurve::OutCubic); - addDefaultAnimation(offset_anim_); - - color_anim_ = new QPropertyAnimation(label_, "color", this); - color_anim_->setDuration(210); - addDefaultAnimation(color_anim_); - } - - setupProperties(); -} - -void -TextFieldStateMachine::setupProperties() -{ - if (label_) { - const int m = text_field_->textMargins().top(); - - if (text_field_->text().isEmpty()) { - normal_state_->assignProperty(label_, "offset", QPointF(0, 26)); - } else { - normal_state_->assignProperty(label_, "offset", QPointF(0, 0 - m)); - } - - focused_state_->assignProperty(label_, "offset", QPointF(0, 0 - m)); - focused_state_->assignProperty(label_, "color", text_field_->inkColor()); - normal_state_->assignProperty(label_, "color", text_field_->labelColor()); - - if (0 != label_->offset().y() && !text_field_->text().isEmpty()) { - label_->setOffset(QPointF(0, 0 - m)); - } else if (!text_field_->hasFocus() && label_->offset().y() <= 0 && - text_field_->text().isEmpty()) { - label_->setOffset(QPointF(0, 26)); - } - } - - text_field_->update(); -} - -TextFieldLabel::TextFieldLabel(TextField *parent) - : QWidget(parent) - , text_field_(parent) -{ - x_ = 0; - y_ = 26; - scale_ = 1; - color_ = parent->labelColor(); - - QFont font; - font.setWeight(60); - font.setLetterSpacing(QFont::PercentageSpacing, 102); - setFont(font); -} - -void -TextFieldLabel::paintEvent(QPaintEvent *) -{ - if (!text_field_->hasLabel()) - return; - - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - painter.scale(scale_, scale_); - painter.setPen(color_); - painter.setOpacity(1); - - QPointF pos(2 + x_, height() - 36 + y_); - painter.drawText(pos.x(), pos.y(), text_field_->label()); } diff --git a/src/ui/TextField.h b/src/ui/TextField.h index 47257019..fb7d0b1a 100644 --- a/src/ui/TextField.h +++ b/src/ui/TextField.h @@ -9,12 +9,10 @@ #include #include #include -#include #include class TextField; class TextFieldLabel; -class TextFieldStateMachine; class TextField : public QLineEdit { @@ -60,7 +58,6 @@ private: QColor underline_color_; QString label_text_; TextFieldLabel *label_; - TextFieldStateMachine *state_machine_; bool show_label_; QRegularExpression regexp_; bool is_valid_; @@ -136,45 +133,3 @@ TextFieldLabel::color() const return color_; } -class TextFieldStateMachine : public QStateMachine -{ - Q_OBJECT - - Q_PROPERTY(qreal progress WRITE setProgress READ progress) - -public: - TextFieldStateMachine(TextField *parent); - - inline void setProgress(qreal progress); - void setLabel(TextFieldLabel *label); - - inline qreal progress() const; - -public slots: - void setupProperties(); - -private: - QPropertyAnimation *color_anim_; - QPropertyAnimation *offset_anim_; - - QState *focused_state_; - QState *normal_state_; - - TextField *text_field_; - TextFieldLabel *label_; - - qreal progress_; -}; - -inline void -TextFieldStateMachine::setProgress(qreal progress) -{ - progress_ = progress; - text_field_->update(); -} - -inline qreal -TextFieldStateMachine::progress() const -{ - return progress_; -} diff --git a/src/ui/UserProfile.h b/src/ui/UserProfile.h index cd2f4740..c1d7a79c 100644 --- a/src/ui/UserProfile.h +++ b/src/ui/UserProfile.h @@ -12,6 +12,7 @@ #include #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 diff --git a/src/voip/CallManager.h b/src/voip/CallManager.h index 22f31814..a9c522cf 100644 --- a/src/voip/CallManager.h +++ b/src/voip/CallManager.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "CallDevices.h" @@ -21,7 +22,6 @@ namespace mtx::responses { struct TurnServer; } -class QStringList; class QUrl; class CallManager : public QObject