diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index b587a444c..cb764c410 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "data/data_types.h" +#include "ui/rect_part.h" enum class ImageRoundRadius; class MainWindow; diff --git a/Telegram/SourceFiles/base/algorithm.h b/Telegram/SourceFiles/base/algorithm.h index a971e9704..edcf7684f 100644 --- a/Telegram/SourceFiles/base/algorithm.h +++ b/Telegram/SourceFiles/base/algorithm.h @@ -32,6 +32,17 @@ inline bool contains(const Container &container, const T &value) { return std::find(std::begin(container), end, value) != end; } +template +inline constexpr D up_cast(T object) { + using DV = std::decay_t; + using TV = std::decay_t; + if constexpr (std::is_base_of_v) { + return object; + } else { + return nullptr; + } +} + // We need a custom comparator for set>::find to work with pointers. // thanks to http://stackoverflow.com/questions/18939882/raw-pointer-lookup-for-sets-of-unique-ptrs template diff --git a/Telegram/SourceFiles/base/invoke_queued.h b/Telegram/SourceFiles/base/invoke_queued.h index e7a91b1b9..a94efe527 100644 --- a/Telegram/SourceFiles/base/invoke_queued.h +++ b/Telegram/SourceFiles/base/invoke_queued.h @@ -40,3 +40,23 @@ inline void InvokeQueued(const QObject *context, Lambda &&lambda) { const_cast(context), new base::InvokeQueuedEvent(std::forward(lambda))); } + +class SingleQueuedInvokation : public QObject { +public: + SingleQueuedInvokation(Fn callback) : _callback(callback) { + } + void call() { + if (_pending.testAndSetAcquire(0, 1)) { + InvokeQueued(this, [this] { + if (_pending.testAndSetRelease(1, 0)) { + _callback(); + } + }); + } + } + +private: + Fn _callback; + QAtomicInt _pending = { 0 }; + +}; diff --git a/Telegram/SourceFiles/base/object_ptr.h b/Telegram/SourceFiles/base/object_ptr.h new file mode 100644 index 000000000..92479f4db --- /dev/null +++ b/Telegram/SourceFiles/base/object_ptr.h @@ -0,0 +1,119 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +// Smart pointer for QObject*, has move semantics, destroys object if it doesn't have a parent. +template +class object_ptr { +public: + object_ptr(std::nullptr_t) noexcept { + } + + // No default constructor, but constructors with at least + // one argument are simply make functions. + template + explicit object_ptr(Parent &&parent, Args&&... args) + : _object(new Object(std::forward(parent), std::forward(args)...)) { + } + static object_ptr fromRaw(Object *value) noexcept { + object_ptr result = { nullptr }; + result._object = value; + return result; + } + Object *release() noexcept { + return static_cast(base::take(_object).data()); + } + + object_ptr(const object_ptr &other) = delete; + object_ptr &operator=(const object_ptr &other) = delete; + object_ptr(object_ptr &&other) noexcept : _object(base::take(other._object)) { + } + object_ptr &operator=(object_ptr &&other) noexcept { + auto temp = std::move(other); + destroy(); + std::swap(_object, temp._object); + return *this; + } + + template < + typename OtherObject, + typename = std::enable_if_t< + std::is_base_of_v>> + object_ptr(object_ptr &&other) noexcept + : _object(base::take(other._object)) { + } + + template < + typename OtherObject, + typename = std::enable_if_t< + std::is_base_of_v>> + object_ptr &operator=(object_ptr &&other) noexcept { + _object = base::take(other._object); + return *this; + } + + object_ptr &operator=(std::nullptr_t) noexcept { + _object = nullptr; + return *this; + } + + // So we can pass this pointer to methods like connect(). + Object *data() const noexcept { + return static_cast(_object.data()); + } + operator Object*() const noexcept { + return data(); + } + + explicit operator bool() const noexcept { + return _object != nullptr; + } + + Object *operator->() const noexcept { + return data(); + } + Object &operator*() const noexcept { + return *data(); + } + + // Use that instead "= new Object(parent, ...)" + template + Object *create(Parent &&parent, Args&&... args) { + destroy(); + _object = new Object( + std::forward(parent), + std::forward(args)...); + return data(); + } + void destroy() noexcept { + delete base::take(_object); + } + void destroyDelayed() { + if (_object) { + if (auto widget = base::up_cast(data())) { + widget->hide(); + } + base::take(_object)->deleteLater(); + } + } + + ~object_ptr() noexcept { + if (auto pointer = _object) { + if (!pointer->parent()) { + destroy(); + } + } + } + +private: + template + friend class object_ptr; + + QPointer _object; + +}; diff --git a/Telegram/SourceFiles/boxes/abstract_box.h b/Telegram/SourceFiles/boxes/abstract_box.h index 5e2a436a9..64930ccc7 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.h +++ b/Telegram/SourceFiles/boxes/abstract_box.h @@ -225,7 +225,8 @@ protected: template object_ptr takeInnerWidget() { - return static_object_cast(doTakeInnerWidget()); + return object_ptr::fromRaw( + static_cast(doTakeInnerWidget().release())); } void setInnerVisible(bool scrollAreaVisible); diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 0a47c0469..b7ddecd53 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/special_buttons.h" #include "ui/text_options.h" #include "ui/unread_badge.h" +#include "ui/ui_utility.h" #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_user.h" @@ -579,7 +580,7 @@ void GroupInfoBox::createGroup( }).fail([=](const RPCError &error) { _creationRequestId = 0; if (error.type() == qstr("NO_CHAT_TITLE")) { - auto weak = make_weak(this); + auto weak = Ui::MakeWeak(this); selectUsersBox->closeBox(); if (weak) { _title->showError(); @@ -618,7 +619,7 @@ void GroupInfoBox::submit() { if (_type != Type::Group) { createChannel(title, description); } else { - auto initBox = [title, weak = make_weak(this)]( + auto initBox = [title, weak = Ui::MakeWeak(this)]( not_null box) { auto create = [box, title, weak] { if (weak) { @@ -1362,7 +1363,7 @@ void RevokePublicLinkBox::Inner::updateSelected() { PeerData *selected = nullptr; auto top = _rowsTop; for (const auto &row : _rows) { - auto revokeLink = rtlrect(width() - st::contactsPadding.right() - st::contactsCheckPosition.x() - _revokeWidth, top + st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, _revokeWidth, st::normalFont->height, width()); + auto revokeLink = style::rtlrect(width() - st::contactsPadding.right() - st::contactsCheckPosition.x() - _revokeWidth, top + st::contactsPadding.top() + (st::contactsPhotoSize - st::normalFont->height) / 2, _revokeWidth, st::normalFont->height, width()); if (revokeLink.contains(point)) { selected = row.peer; break; diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index b7b1142f1..cec8274bb 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "ui/effects/round_checkbox.h" #include "ui/image/image.h" +#include "ui/ui_utility.h" #include "main/main_session.h" #include "apiwrap.h" #include "mtproto/sender.h" @@ -154,7 +155,7 @@ void BackgroundBox::prepare() { void BackgroundBox::removePaper(const Data::WallPaper &paper) { const auto box = std::make_shared>(); const auto session = _session; - const auto remove = [=, weak = make_weak(this)]{ + const auto remove = [=, weak = Ui::MakeWeak(this)]{ if (*box) { (*box)->closeBox(); } diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index df4dbbbfb..908efa695 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/toast/toast.h" #include "ui/image/image.h" #include "ui/widgets/checkbox.h" +#include "ui/ui_utility.h" #include "history/history.h" #include "history/history_message.h" #include "history/view/history_view_message.h" diff --git a/Telegram/SourceFiles/boxes/calendar_box.cpp b/Telegram/SourceFiles/boxes/calendar_box.cpp index 0c772a5ee..25bbbfe79 100644 --- a/Telegram/SourceFiles/boxes/calendar_box.cpp +++ b/Telegram/SourceFiles/boxes/calendar_box.cpp @@ -8,10 +8,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/calendar_box.h" #include "ui/widgets/buttons.h" -#include "styles/style_boxes.h" -#include "styles/style_dialogs.h" #include "lang/lang_keys.h" #include "ui/effects/ripple_animation.h" +#include "ui/ui_utility.h" +#include "styles/style_boxes.h" +#include "styles/style_dialogs.h" namespace { @@ -258,7 +259,7 @@ void CalendarBox::Inner::monthChanged(QDate month) { _ripples.clear(); resizeToCurrent(); update(); - sendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton); + Ui::SendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton); } void CalendarBox::Inner::resizeToCurrent() { diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index e67261d50..0af50feed 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -309,7 +309,7 @@ void ChangePhoneBox::EnterCode::submit() { const auto session = _session; const auto code = _code->getDigitsOnly(); - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); _requestId = MTP::send(MTPaccount_ChangePhone( MTP_string(_phone), MTP_string(_hash), diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index b260db701..7aa97edcd 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -415,7 +415,7 @@ void ProxyRow::paintCheck(Painter &p) { pen.setCapStyle(Qt::RoundCap); p.setPen(pen); p.setBrush(_st->bg); - const auto rect = rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(_st->thickness / 2., _st->thickness / 2., _st->thickness / 2., _st->thickness / 2.)), outerWidth); + const auto rect = style::rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(_st->thickness / 2., _st->thickness / 2., _st->thickness / 2., _st->thickness / 2.)), outerWidth); if (_progress && loading.shown > 0 && anim::Disabled()) { anim::DrawStaticLoading( p, @@ -434,7 +434,7 @@ void ProxyRow::paintCheck(Painter &p) { p.setBrush(anim::brush(_st->untoggledFg, _st->toggledFg, toggled * set)); auto skip0 = _st->diameter / 2., skip1 = _st->skip / 10., checkSkip = skip0 * (1. - toggled) + skip1 * toggled; - p.drawEllipse(rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(checkSkip, checkSkip, checkSkip, checkSkip)), outerWidth)); + p.drawEllipse(style::rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(checkSkip, checkSkip, checkSkip, checkSkip)), outerWidth)); } } diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 8c0435dc7..5d23f0351 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -812,10 +812,10 @@ void EditCaptionBox::paintEvent(QPaintEvent *e) { // App::roundRect(p, x, y, w, h, st::msgInBg, MessageInCorners, &st::msgInShadow); if (_thumbw) { - QRect rthumb(rtlrect(x + 0, y + 0, st::msgFileThumbSize, st::msgFileThumbSize, width())); + QRect rthumb(style::rtlrect(x + 0, y + 0, st::msgFileThumbSize, st::msgFileThumbSize, width())); p.drawPixmap(rthumb.topLeft(), _thumb); } else { - const QRect inner(rtlrect(x + 0, y + 0, st::msgFileSize, st::msgFileSize, width())); + const QRect inner(style::rtlrect(x + 0, y + 0, st::msgFileSize, st::msgFileSize, width())); p.setPen(Qt::NoPen); p.setBrush(st::msgFileInBg); diff --git a/Telegram/SourceFiles/boxes/edit_color_box.cpp b/Telegram/SourceFiles/boxes/edit_color_box.cpp index 6efe374c8..fae3a3574 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_color_box.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "ui/widgets/shadow.h" #include "ui/widgets/input_fields.h" +#include "ui/ui_utility.h" #include "platform/platform_info.h" #include "app.h" #include "styles/style_boxes.h" @@ -874,7 +875,7 @@ void EditColorBox::fieldSubmitted() { } void EditColorBox::saveColor() { - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); _cancelCallback = nullptr; if (_saveCallback) { _saveCallback(_new.toRgb()); diff --git a/Telegram/SourceFiles/boxes/passcode_box.cpp b/Telegram/SourceFiles/boxes/passcode_box.cpp index a60d3ad16..1391df364 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.cpp +++ b/Telegram/SourceFiles/boxes/passcode_box.cpp @@ -269,7 +269,7 @@ void PasscodeBox::setPasswordDone(const QByteArray &newPasswordBytes) { } _setRequest = 0; _newPasswordSet.fire_copy(newPasswordBytes); - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); const auto text = _reenterPasscode->isHidden() ? tr::lng_cloud_password_removed(tr::now) : _oldPasscode->isHidden() @@ -368,7 +368,7 @@ void PasscodeBox::validateEmail( } else if (error.type() == qstr("CODE_INVALID")) { errors->fire(tr::lng_signin_wrong_code(tr::now)); } else if (error.type() == qstr("EMAIL_HASH_EXPIRED")) { - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); _clearUnconfirmedPassword.fire({}); if (weak) { auto box = Box( @@ -409,7 +409,7 @@ void PasscodeBox::validateEmail( box->boxClosing( ) | rpl::filter([=] { return !*set; - }) | start_with_next([=, weak = make_weak(this)] { + }) | start_with_next([=, weak = Ui::MakeWeak(this)] { if (weak) { weak->_clearUnconfirmedPassword.fire({}); } @@ -512,7 +512,7 @@ void PasscodeBox::save(bool force) { } } else { closeReplacedBy(); - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); cSetPasscodeBadTries(0); Local::setPasscode(pwd.toUtf8()); _session->localPasscodeChanged(); diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index f7b2f375e..4835bf039 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -507,14 +507,14 @@ void PeerListRow::paintDisabledCheckUserpic( auto userpicDiameter = st::contactsPhotoCheckbox.imageRadius * 2; auto userpicLeft = x + userpicShift; auto userpicTop = y + userpicShift; - auto userpicEllipse = rtlrect(x, y, userpicDiameter, userpicDiameter, outerWidth); + auto userpicEllipse = style::rtlrect(x, y, userpicDiameter, userpicDiameter, outerWidth); auto userpicBorderPen = st::contactsPhotoDisabledCheckFg->p; userpicBorderPen.setWidth(st::contactsPhotoCheckbox.selectWidth); auto iconDiameter = st::contactsPhotoCheckbox.check.size; auto iconLeft = x + userpicDiameter + st::contactsPhotoCheckbox.selectWidth - iconDiameter; auto iconTop = y + userpicDiameter + st::contactsPhotoCheckbox.selectWidth - iconDiameter; - auto iconEllipse = rtlrect(iconLeft, iconTop, iconDiameter, iconDiameter, outerWidth); + auto iconEllipse = style::rtlrect(iconLeft, iconTop, iconDiameter, iconDiameter, outerWidth); auto iconBorderPen = st::contactsPhotoCheckbox.check.border->p; iconBorderPen.setWidth(st::contactsPhotoCheckbox.selectWidth); diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp index 3b0a37489..bad2a093e 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/confirm_box.h" #include "observer_peer.h" #include "ui/widgets/checkbox.h" +#include "ui/ui_utility.h" #include "main/main_session.h" #include "data/data_session.h" #include "data/data_channel.h" diff --git a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp index 8a14dbf8e..5d2ce7e03 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp @@ -202,7 +202,7 @@ void Controller::initNameFields( return; } SendRequest( - make_weak(_box), + Ui::MakeWeak(_box), _user, _sharePhone && _sharePhone->checked(), firstValue, diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index bd7df538e..ff10e04ba 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -57,7 +57,7 @@ void SetCloudPassword(not_null box, not_null user) { user->session().api().passwordState( ) | rpl::start_with_next([=] { using namespace Settings; - const auto weak = make_weak(box); + const auto weak = Ui::MakeWeak(box); if (CheckEditCloudPassword(&user->session())) { box->getDelegate()->show( EditCloudPasswordBox(&user->session())); @@ -580,7 +580,7 @@ void EditAdminBox::sendTransferRequestFrom( if (_transferRequestId) { return; } - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); const auto user = this->user(); const auto api = &channel->session().api(); _transferRequestId = api->request(MTPchannels_EditCreator( @@ -626,7 +626,7 @@ void EditAdminBox::sendTransferRequestFrom( || (type == qstr("PASSWORD_TOO_FRESH_XXX")) || (type == qstr("SESSION_TOO_FRESH_XXX")); }(); - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); getDelegate()->show(Box(problem)); if (box) { box->closeBox(); diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 411dde9e4..17d408d34 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "base/unixtime.h" #include "ui/widgets/popup_menu.h" +#include "ui/ui_utility.h" #include "window/window_session_controller.h" #include "history/history.h" #include "facades.h" diff --git a/Telegram/SourceFiles/boxes/photo_crop_box.cpp b/Telegram/SourceFiles/boxes/photo_crop_box.cpp index 99699865c..81b5347fa 100644 --- a/Telegram/SourceFiles/boxes/photo_crop_box.cpp +++ b/Telegram/SourceFiles/boxes/photo_crop_box.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "ui/widgets/buttons.h" +#include "ui/ui_utility.h" #include "app.h" #include "styles/style_boxes.h" @@ -260,7 +261,7 @@ void PhotoCropBox::sendPhoto() { tosend = cropped.copy(); } - auto weak = make_weak(this); + auto weak = Ui::MakeWeak(this); _readyImages.fire(std::move(tosend)); if (weak) { closeBox(); diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 9fe13e3ef..f4b3b1a4b 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -900,7 +900,7 @@ void SingleFilePreview::paintEvent(QPaintEvent *e) { App::roundRect(p, x, y, w, h, st::msgOutBg, MessageOutCorners, &st::msgOutShadow); if (_fileThumb.isNull()) { - QRect inner(rtlrect(x + st::msgFilePadding.left(), y + st::msgFilePadding.top(), st::msgFileSize, st::msgFileSize, width())); + QRect inner(style::rtlrect(x + st::msgFilePadding.left(), y + st::msgFilePadding.top(), st::msgFileSize, st::msgFileSize, width())); p.setPen(Qt::NoPen); p.setBrush(st::msgFileOutBg); @@ -916,7 +916,7 @@ void SingleFilePreview::paintEvent(QPaintEvent *e) { : st::historyFileOutDocument; icon.paintInCenter(p, inner); } else { - QRect rthumb(rtlrect(x + st::msgFileThumbPadding.left(), y + st::msgFileThumbPadding.top(), st::msgFileThumbSize, st::msgFileThumbSize, width())); + QRect rthumb(style::rtlrect(x + st::msgFileThumbPadding.left(), y + st::msgFileThumbPadding.top(), st::msgFileThumbSize, st::msgFileThumbSize, width())); p.drawPixmap(rthumb.topLeft(), _fileThumb); } p.setFont(st::semiboldFont); @@ -1464,7 +1464,7 @@ void SendFilesBox::setupShadows( bottomShadow->move( geometry.x(), geometry.y() + geometry.height() - st::lineWidth); - }, [t = make_weak(topShadow), b = make_weak(bottomShadow)] { + }, [t = Ui::MakeWeak(topShadow), b = Ui::MakeWeak(bottomShadow)] { Ui::DestroyChild(t.data()); Ui::DestroyChild(b.data()); }, topShadow->lifetime()); diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 0b5115d16..20b4ac99f 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -643,7 +643,7 @@ void ShareBox::Inner::repaintChatAtIndex(int index) { auto row = index / _columnCount; auto column = index % _columnCount; - update(rtlrect(_rowsLeft + qFloor(column * _rowWidthReal), row * _rowHeight, _rowWidth, _rowHeight, width())); + update(style::rtlrect(_rowsLeft + qFloor(column * _rowWidthReal), row * _rowHeight, _rowWidth, _rowHeight, width())); } ShareBox::Inner::Chat *ShareBox::Inner::getChatAtIndex(int index) { diff --git a/Telegram/SourceFiles/boxes/single_choice_box.cpp b/Telegram/SourceFiles/boxes/single_choice_box.cpp index 8844a1780..f617a5fca 100644 --- a/Telegram/SourceFiles/boxes/single_choice_box.cpp +++ b/Telegram/SourceFiles/boxes/single_choice_box.cpp @@ -54,7 +54,7 @@ void SingleChoiceBox::prepare() { st::boxOptionListSkip)); } group->setChangedCallback([=](int value) { - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); _callback(value); if (weak) { closeBox(); diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index ce25b4279..a44cca08c 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -879,7 +879,7 @@ void StickersBox::Inner::paintRow(Painter &p, not_null set, int index) { { PainterHighQualityEnabler hq(p); - p.drawEllipse(rtlrect(namex + set->titleWidth + st::stickersFeaturedUnreadSkip, namey + st::stickersFeaturedUnreadTop, st::stickersFeaturedUnreadSize, st::stickersFeaturedUnreadSize, width())); + p.drawEllipse(style::rtlrect(namex + set->titleWidth + st::stickersFeaturedUnreadSkip, namey + st::stickersFeaturedUnreadTop, st::stickersFeaturedUnreadSize, st::stickersFeaturedUnreadSize, width())); } } diff --git a/Telegram/SourceFiles/calls/calls_box_controller.cpp b/Telegram/SourceFiles/calls/calls_box_controller.cpp index cda6825c8..937c34a74 100644 --- a/Telegram/SourceFiles/calls/calls_box_controller.cpp +++ b/Telegram/SourceFiles/calls/calls_box_controller.cpp @@ -158,7 +158,7 @@ void BoxController::Row::paintAction( _actionRipple.reset(); } } - st::callReDial.icon.paintInCenter(p, rtlrect(x, y, size.width(), size.height(), outerWidth)); + st::callReDial.icon.paintInCenter(p, style::rtlrect(x, y, size.width(), size.height(), outerWidth)); } void BoxController::Row::refreshStatus() { diff --git a/Telegram/SourceFiles/calls/calls_top_bar.h b/Telegram/SourceFiles/calls/calls_top_bar.h index e98a5363c..4cd250c6a 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.h +++ b/Telegram/SourceFiles/calls/calls_top_bar.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/weak_ptr.h" #include "base/timer.h" +#include "base/object_ptr.h" #include "ui/rp_widget.h" namespace Ui { diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index 69e94913a..03589d0b0 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" #include "ui/emoji_config.h" +#include "ui/ui_utility.h" #include "lang/lang_keys.h" #include "emoji_suggestions_data.h" #include "emoji_suggestions_helper.h" diff --git a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp index efda1fd4a..09fd1dc95 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp @@ -294,7 +294,7 @@ void Loader::setImplementation( void Loader::unpack(const QString &path) { const auto folder = internal::SetDataPath(_id); - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); crl::async([=] { if (UnpackSet(path, folder)) { QFile(path).remove(); @@ -401,7 +401,7 @@ void Row::paintRadio(Painter &p) { pen.setCapStyle(Qt::RoundCap); p.setPen(pen); p.setBrush(_st->bg); - const auto rect = rtlrect(QRectF( + const auto rect = style::rtlrect(QRectF( left, top, _st->diameter, @@ -432,7 +432,7 @@ void Row::paintRadio(Painter &p) { const auto skip0 = _st->diameter / 2.; const auto skip1 = _st->skip / 10.; const auto checkSkip = skip0 * (1. - toggled) + skip1 * toggled; - p.drawEllipse(rtlrect(QRectF( + p.drawEllipse(style::rtlrect(QRectF( left, top, _st->diameter, diff --git a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp index b6787e4c3..d2b763a4f 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_suggestions_widget.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/inner_dropdown.h" #include "ui/widgets/input_fields.h" #include "ui/emoji_config.h" +#include "ui/ui_utility.h" #include "platform/platform_specific.h" #include "core/application.h" #include "core/event_filter.h" diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 8039fa235..0e012190d 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lottie/lottie_single_player.h" #include "ui/widgets/scroll_area.h" #include "ui/image/image.h" +#include "ui/ui_utility.h" #include "main/main_session.h" #include "chat_helpers/stickers.h" #include "base/unixtime.h" diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h index c0880c5d2..67b151c35 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/animations.h" #include "ui/rp_widget.h" #include "base/timer.h" +#include "base/object_ptr.h" #include "chat_helpers/stickers.h" namespace Ui { diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index f5410896f..3b835790c 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" #include "ui/wrap/vertical_layout.h" #include "ui/widgets/popup_menu.h" +#include "ui/ui_utility.h" #include "data/data_session.h" #include "data/data_user.h" #include "core/event_filter.h" @@ -153,7 +154,7 @@ void EditLinkBox::prepare() { url->showError(); return; } - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); _callback(linkText, linkUrl); if (weak) { closeBox(); @@ -354,7 +355,7 @@ Fn DefaultEditLinkCallback( not_null session, not_null field) { - const auto weak = make_weak(field); + const auto weak = Ui::MakeWeak(field); return [=]( EditLinkSelection selection, QString text, diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 756918d1c..f88aebbac 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -465,13 +465,13 @@ void StickersListWidget::Footer::paintLeftRightFading(Painter &p) const { auto o_left = snap(_iconsX.current() / st::stickerIconLeft.width(), 0., 1.); if (o_left > 0) { p.setOpacity(o_left); - st::stickerIconLeft.fill(p, rtlrect(_iconsLeft, _iconsTop, st::stickerIconLeft.width(), st::emojiFooterHeight, width())); + st::stickerIconLeft.fill(p, style::rtlrect(_iconsLeft, _iconsTop, st::stickerIconLeft.width(), st::emojiFooterHeight, width())); p.setOpacity(1.); } auto o_right = snap((_iconsMax - _iconsX.current()) / st::stickerIconRight.width(), 0., 1.); if (o_right > 0) { p.setOpacity(o_right); - st::stickerIconRight.fill(p, rtlrect(width() - _iconsRight - st::stickerIconRight.width(), _iconsTop, st::stickerIconRight.width(), st::emojiFooterHeight, width())); + st::stickerIconRight.fill(p, style::rtlrect(width() - _iconsRight - st::stickerIconRight.width(), _iconsTop, st::stickerIconRight.width(), st::emojiFooterHeight, width())); p.setOpacity(1.); } } @@ -1396,7 +1396,7 @@ void StickersListWidget::paintStickers(Painter &p, QRect clip) { { PainterHighQualityEnabler hq(p); - p.drawEllipse(rtlrect(st::emojiPanHeaderLeft - st::buttonRadius + titleWidth + st::stickersFeaturedUnreadSkip, info.top + st::stickersTrendingHeaderTop + st::stickersFeaturedUnreadTop, st::stickersFeaturedUnreadSize, st::stickersFeaturedUnreadSize, width())); + p.drawEllipse(style::rtlrect(st::emojiPanHeaderLeft - st::buttonRadius + titleWidth + st::stickersFeaturedUnreadSkip, info.top + st::stickersTrendingHeaderTop + st::stickersFeaturedUnreadTop, st::stickersFeaturedUnreadSize, st::stickersFeaturedUnreadSize, width())); } } diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp index f057aef66..a655905d0 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/shadow.h" #include "ui/image/image_prepare.h" +#include "ui/ui_utility.h" #include "chat_helpers/tabbed_selector.h" #include "window/window_session_controller.h" #include "mainwindow.h" diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h index bc6782865..0ffdc29c2 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_panel.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_panel.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/animations.h" #include "ui/rp_widget.h" #include "base/timer.h" +#include "base/object_ptr.h" namespace Window { class SessionController; diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index 2d29dae6f..8924145b4 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/panel_animation.h" #include "mtproto/sender.h" #include "main/main_session.h" +#include "base/object_ptr.h" namespace InlineBots { class Result; diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 5f7d8164b..2d14bb639 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -736,7 +736,7 @@ void Application::registerLeaveSubscription(QWidget *widget) { #ifdef Q_OS_MAC if (const auto topLevel = widget->window()) { if (topLevel == _window->widget()) { - auto weak = make_weak(widget); + auto weak = Ui::MakeWeak(widget); auto subscription = _window->widget()->leaveEvents( ) | rpl::start_with_next([weak] { if (const auto window = weak.data()) { @@ -862,3 +862,11 @@ Application &App() { } } // namespace Core + +namespace Ui { + +void PostponeCall(FnMut &&callable) { + Core::App().postponeCall(std::move(callable)); +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/core/qt_signal_producer.h b/Telegram/SourceFiles/core/qt_signal_producer.h index fa78b1e0e..e9655ac72 100644 --- a/Telegram/SourceFiles/core/qt_signal_producer.h +++ b/Telegram/SourceFiles/core/qt_signal_producer.h @@ -47,7 +47,7 @@ auto QtSignalProducer(Object *object, Signal signal) { NoArgument, rpl::empty_value, std::remove_const_t>>; - const auto guarded = make_weak(object); + const auto guarded = QPointer(object); return rpl::make_producer([=](auto consumer) { if (!guarded) { return rpl::lifetime(); @@ -59,7 +59,7 @@ auto QtSignalProducer(Object *object, Signal signal) { signal, listener, std::forward(handler)); - const auto weak = make_weak(listener); + const auto weak = QPointer(listener); return rpl::lifetime([=] { if (weak) { delete weak; diff --git a/Telegram/SourceFiles/core/sandbox.cpp b/Telegram/SourceFiles/core/sandbox.cpp index 16e14254c..fd40494a6 100644 --- a/Telegram/SourceFiles/core/sandbox.cpp +++ b/Telegram/SourceFiles/core/sandbox.cpp @@ -513,7 +513,7 @@ bool Sandbox::notify(QObject *receiver, QEvent *e) { const auto wrap = createEventNestingLevel(); if (e->type() == QEvent::UpdateRequest) { - const auto weak = make_weak(receiver); + const auto weak = QPointer(receiver); _widgetUpdateRequests.fire({}); if (!weak) { return true; diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index 39db59375..2484ceb91 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -25,17 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace base { -template -inline constexpr D up_cast(T object) { - using DV = std::decay_t; - using TV = std::decay_t; - if constexpr (std::is_base_of_v) { - return object; - } else { - return nullptr; - } -} - template using set_of_unique_ptr = std::set, base::pointer_comparator>; diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index e7ccf5201..8d6a4697b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/popup_menu.h" #include "ui/text_options.h" +#include "ui/ui_utility.h" #include "data/data_drafts.h" #include "data/data_folder.h" #include "data/data_session.h" diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index 08f044dae..b5b29a017 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/animations.h" #include "ui/rp_widget.h" #include "base/flags.h" +#include "base/object_ptr.h" namespace Main { class Session; diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp index 2c8c1eef1..f5b2103bf 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp @@ -252,7 +252,7 @@ void PanelController::showCriticalError(const QString &text) { void PanelController::showError(const QString &text) { auto box = Box(text); - const auto weak = make_weak(box.data()); + const auto weak = Ui::MakeWeak(box.data()); const auto hidden = _panel->isHidden(); _panel->showBox( std::move(box), diff --git a/Telegram/SourceFiles/export/view/export_view_progress.cpp b/Telegram/SourceFiles/export/view/export_view_progress.cpp index ff028cd27..785b3b48b 100644 --- a/Telegram/SourceFiles/export/view/export_view_progress.cpp +++ b/Telegram/SourceFiles/export/view/export_view_progress.cpp @@ -141,7 +141,7 @@ void ProgressWidget::Row::toggleInstance(Instance &instance, bool shown) { if (instance.hiding != shown) { return; } - const auto label = make_weak(instance.label->entity()); + const auto label = Ui::MakeWeak(instance.label->entity()); instance.opacity.start( [=] { instanceOpacityCallback(label); }, shown ? 0. : 1., @@ -156,7 +156,7 @@ void ProgressWidget::Row::instanceOpacityCallback( QPointer label) { update(); const auto i = ranges::find(_old, label, [](const Instance &instance) { - return make_weak(instance.label->entity()); + return Ui::MakeWeak(instance.label->entity()); }); if (i != end(_old) && i->hiding && !i->opacity.animating()) { crl::on_main(this, [=] { @@ -167,7 +167,7 @@ void ProgressWidget::Row::instanceOpacityCallback( void ProgressWidget::Row::removeOldInstance(QPointer label) { const auto i = ranges::find(_old, label, [](const Instance &instance) { - return make_weak(instance.label->entity()); + return Ui::MakeWeak(instance.label->entity()); }); if (i != end(_old)) { _old.erase(i); diff --git a/Telegram/SourceFiles/export/view/export_view_progress.h b/Telegram/SourceFiles/export/view/export_view_progress.h index e792a2165..f370c34c3 100644 --- a/Telegram/SourceFiles/export/view/export_view_progress.h +++ b/Telegram/SourceFiles/export/view/export_view_progress.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rp_widget.h" #include "export/view/export_view_content.h" +#include "base/object_ptr.h" namespace Ui { class VerticalLayout; diff --git a/Telegram/SourceFiles/export/view/export_view_settings.cpp b/Telegram/SourceFiles/export/view/export_view_settings.cpp index 1a6e4fd32..e964877d7 100644 --- a/Telegram/SourceFiles/export/view/export_view_settings.cpp +++ b/Telegram/SourceFiles/export/view/export_view_settings.cpp @@ -397,7 +397,7 @@ void SettingsWidget::editDateLimit( callback, finalize, st::exportCalendarSizes); - *shared = make_weak(box.data()); + *shared = Ui::MakeWeak(box.data()); _showBoxCallback(std::move(box)); } diff --git a/Telegram/SourceFiles/export/view/export_view_settings.h b/Telegram/SourceFiles/export/view/export_view_settings.h index d7a22c81b..68fae7695 100644 --- a/Telegram/SourceFiles/export/view/export_view_settings.h +++ b/Telegram/SourceFiles/export/view/export_view_settings.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "export/export_settings.h" #include "ui/rp_widget.h" +#include "base/object_ptr.h" class BoxContent; diff --git a/Telegram/SourceFiles/export/view/export_view_top_bar.h b/Telegram/SourceFiles/export/view/export_view_top_bar.h index c27a52d20..24e015f68 100644 --- a/Telegram/SourceFiles/export/view/export_view_top_bar.h +++ b/Telegram/SourceFiles/export/view/export_view_top_bar.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "base/object_ptr.h" namespace Ui { class FlatLabel; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp index e7eb554f3..2e5ad7f76 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/shadow.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" +#include "ui/ui_utility.h" #include "mainwidget.h" #include "mainwindow.h" #include "apiwrap.h" diff --git a/Telegram/SourceFiles/history/history_drag_area.cpp b/Telegram/SourceFiles/history/history_drag_area.cpp index b978f0213..9b9b4069f 100644 --- a/Telegram/SourceFiles/history/history_drag_area.cpp +++ b/Telegram/SourceFiles/history/history_drag_area.cpp @@ -7,8 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "history/history_drag_area.h" -#include "styles/style_chat_helpers.h" -#include "styles/style_boxes.h" #include "boxes/confirm_box.h" #include "boxes/sticker_set_box.h" #include "inline_bots/inline_bot_result.h" @@ -17,11 +15,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_widget.h" #include "storage/localstorage.h" #include "lang/lang_keys.h" +#include "ui/widgets/shadow.h" +#include "ui/ui_utility.h" #include "mainwindow.h" #include "apiwrap.h" #include "mainwidget.h" #include "app.h" -#include "ui/widgets/shadow.h" +#include "styles/style_chat_helpers.h" +#include "styles/style_boxes.h" DragArea::DragArea(QWidget *parent) : TWidget(parent) { setMouseTracking(true); diff --git a/Telegram/SourceFiles/history/history_drag_area.h b/Telegram/SourceFiles/history/history_drag_area.h index b5c16ff29..17554c781 100644 --- a/Telegram/SourceFiles/history/history_drag_area.h +++ b/Telegram/SourceFiles/history/history_drag_area.h @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "ui/twidget.h" +#include "ui/rp_widget.h" #include "ui/effects/animations.h" class DragArea : public TWidget { diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index ca0580d03..202e3eb71 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/image/image.h" #include "ui/toast/toast.h" #include "ui/text_options.h" +#include "ui/ui_utility.h" #include "window/window_session_controller.h" #include "window/window_peer_menu.h" #include "boxes/confirm_box.h" @@ -932,7 +933,7 @@ void HistoryInner::touchEvent(QTouchEvent *e) { case QEvent::TouchEnd: { if (!_touchInProgress) return; _touchInProgress = false; - auto weak = make_weak(this); + auto weak = Ui::MakeWeak(this); if (_touchSelect) { mouseActionFinish(_touchPos, Qt::RightButton); QContextMenuEvent contextMenu(QContextMenuEvent::Mouse, mapFromGlobal(_touchPos), _touchPos); diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 5c65ce1c3..aa18732b3 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -308,7 +308,7 @@ void HistoryMessageReply::paint( if (flags & PaintFlag::InBubble) { bar = (flags & PaintFlag::Selected) ? (outbg ? st::msgOutReplyBarSelColor : st::msgInReplyBarSelColor) : (outbg ? st::msgOutReplyBarColor : st::msgInReplyBarColor); } - QRect rbar(rtlrect(x + st::msgReplyBarPos.x(), y + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.width(), st::msgReplyBarSize.height(), w + 2 * x)); + QRect rbar(style::rtlrect(x + st::msgReplyBarPos.x(), y + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.width(), st::msgReplyBarSize.height(), w + 2 * x)); p.fillRect(rbar, bar); if (w > st::msgReplyBarSkip) { @@ -321,7 +321,7 @@ void HistoryMessageReply::paint( if (hasPreview) { if (const auto image = replyToMsg->media()->replyPreview()) { - auto to = rtlrect(x + st::msgReplyBarSkip, y + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.height(), st::msgReplyBarSize.height(), w + 2 * x); + auto to = style::rtlrect(x + st::msgReplyBarSkip, y + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.height(), st::msgReplyBarSize.height(), w + 2 * x); auto previewWidth = image->width() / cIntRetinaFactor(); auto previewHeight = image->height() / cIntRetinaFactor(); auto preview = image->pixSingle(replyToMsg->fullId(), previewWidth, previewHeight, to.width(), to.height(), ImageRoundRadius::Small, RectPart::AllCorners, selected ? &st::msgStickerOverlay : nullptr); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index b03472746..254af33ea 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6308,7 +6308,7 @@ void HistoryWidget::forwardSelected() { if (!_list) { return; } - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); Window::ShowForwardMessagesBox(controller(), getSelectedItems(), [=] { if (const auto strong = weak.data()) { strong->clearSelected(); @@ -6323,7 +6323,7 @@ void HistoryWidget::confirmDeleteSelected() { if (items.empty()) { return; } - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); const auto box = Ui::show(Box( &session(), std::move(items))); diff --git a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp index b85d551bd..f6dc27d8b 100644 --- a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/input_fields.h" #include "ui/special_buttons.h" +#include "ui/ui_utility.h" #include "lang/lang_keys.h" #include "core/event_filter.h" #include "core/qt_signal_producer.h" diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 8636b26c5..8d857d8bb 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "ui/image/image.h" #include "ui/toast/toast.h" +#include "ui/ui_utility.h" #include "chat_helpers/message_field.h" #include "boxes/confirm_box.h" #include "boxes/sticker_set_box.h" @@ -239,7 +240,7 @@ bool AddForwardSelectedAction( } menu->addAction(tr::lng_context_forward_selected(tr::now), [=] { - const auto weak = make_weak(list); + const auto weak = Ui::MakeWeak(list); const auto callback = [=] { if (const auto strong = weak.data()) { strong->cancelSelection(); @@ -324,7 +325,7 @@ bool AddSendNowSelectedAction( const auto history = *histories.begin(); menu->addAction(tr::lng_context_send_now_selected(tr::now), [=] { - const auto weak = make_weak(list); + const auto weak = Ui::MakeWeak(list); const auto callback = [=] { request.navigation->showBackFromStack(); }; @@ -398,7 +399,7 @@ bool AddDeleteSelectedAction( } menu->addAction(tr::lng_context_delete_selected(tr::now), [=] { - const auto weak = make_weak(list); + const auto weak = Ui::MakeWeak(list); auto items = ExtractIdsList(request.selectedItems); const auto box = Ui::show(Box( &request.navigation->session(), diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index ae3a5f951..8365366d9 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1447,7 +1447,7 @@ void Message::drawRightAction( p.setBrush(st::msgServiceBg); { PainterHighQualityEnabler hq(p); - p.drawEllipse(rtlrect( + p.drawEllipse(style::rtlrect( left, top, st::historyFastShareSize, diff --git a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp index cb28ae824..20b6dd9e5 100644 --- a/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp +++ b/Telegram/SourceFiles/history/view/history_view_schedule_box.cpp @@ -263,7 +263,7 @@ TimeInput::TimeInput(QWidget *parent, const QString &value) GetMinute(value)) , _value(valueCurrent()) { const auto focused = [=](const object_ptr &field) { - return [this, pointer = make_weak(field.data())]{ + return [this, pointer = Ui::MakeWeak(field.data())]{ _borderAnimationStart = pointer->borderAnimationStart() + pointer->x() - _hour->x(); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 48801ef75..9e51ada7e 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/shadow.h" #include "ui/toast/toast.h" #include "ui/special_buttons.h" +#include "ui/ui_utility.h" #include "api/api_common.h" #include "api/api_sending.h" #include "apiwrap.h" @@ -943,7 +944,7 @@ void ScheduledWidget::confirmDeleteSelected() { if (items.empty()) { return; } - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); const auto box = Ui::show(Box( &_history->session(), std::move(items))); diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index c6f4e5209..92af82f9b 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -20,11 +20,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "lang/lang_keys.h" #include "core/shortcuts.h" -#include "ui/special_buttons.h" -#include "ui/unread_badge.h" #include "ui/widgets/buttons.h" #include "ui/widgets/dropdown_menu.h" #include "ui/effects/radial_animation.h" +#include "ui/special_buttons.h" +#include "ui/unread_badge.h" +#include "ui/ui_utility.h" #include "window/window_session_controller.h" #include "window/window_peer_menu.h" #include "calls/calls_instance.h" @@ -198,23 +199,23 @@ void TopBarWidget::showMenu() { return; } _menu.create(parentWidget()); - _menu->setHiddenCallback([weak = make_weak(this), menu = _menu.data()]{ + _menu->setHiddenCallback([weak = Ui::MakeWeak(this), menu = _menu.data()]{ menu->deleteLater(); if (weak && weak->_menu == menu) { weak->_menu = nullptr; weak->_menuToggle->setForceRippled(false); } - }); + }); _menu->setShowStartCallback(crl::guard(this, [this, menu = _menu.data()]{ if (_menu == menu) { _menuToggle->setForceRippled(true); } - })); + })); _menu->setHideStartCallback(crl::guard(this, [this, menu = _menu.data()]{ if (_menu == menu) { _menuToggle->setForceRippled(false); } - })); + })); _menuToggle->installEventFilter(_menu); const auto addAction = [&]( const QString & text, diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index 02873bde3..b3ca0b051 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rp_widget.h" #include "ui/effects/animations.h" #include "base/timer.h" +#include "base/object_ptr.h" #include "dialogs/dialogs_key.h" namespace Main { diff --git a/Telegram/SourceFiles/history/view/media/history_view_contact.cpp b/Telegram/SourceFiles/history/view/media/history_view_contact.cpp index 42db87d77..7b6cf07f6 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_contact.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_contact.cpp @@ -163,7 +163,7 @@ void Contact::draw(Painter &p, const QRect &r, TextSelection selection, crl::tim statustop = st::msgFileThumbStatusTop - topMinus; linktop = st::msgFileThumbLinkTop - topMinus; - QRect rthumb(rtlrect(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top() - topMinus, st::msgFileThumbSize, st::msgFileThumbSize, paintw)); + QRect rthumb(style::rtlrect(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top() - topMinus, st::msgFileThumbSize, st::msgFileThumbSize, paintw)); if (_contact) { _contact->paintUserpic(p, rthumb.x(), rthumb.y(), st::msgFileThumbSize); } else { @@ -208,7 +208,7 @@ TextState Contact::textState(QPoint point, StateRequest request) const { if (_userId) { nameleft = st::msgFileThumbPadding.left() + st::msgFileThumbSize + st::msgFileThumbPadding.right(); linktop = st::msgFileThumbLinkTop - topMinus; - if (rtlrect(nameleft, linktop, _linkw, st::semiboldFont->height, width()).contains(point)) { + if (style::rtlrect(nameleft, linktop, _linkw, st::semiboldFont->height, width()).contains(point)) { result.link = _linkl; return result; } diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 07f54119c..9343d66c8 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -238,7 +238,7 @@ void Document::draw(Painter &p, const QRect &r, TextSelection selection, crl::ti auto inWebPage = (_parent->media() != this); auto roundRadius = inWebPage ? ImageRoundRadius::Small : ImageRoundRadius::Large; - QRect rthumb(rtlrect(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top() - topMinus, st::msgFileThumbSize, st::msgFileThumbSize, width())); + QRect rthumb(style::rtlrect(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top() - topMinus, st::msgFileThumbSize, st::msgFileThumbSize, width())); QPixmap thumb; if (const auto normal = _data->thumbnail()) { if (normal->loaded()) { @@ -307,7 +307,7 @@ void Document::draw(Painter &p, const QRect &r, TextSelection selection, crl::ti statustop = st::msgFileStatusTop - topMinus; bottom = st::msgFilePadding.top() + st::msgFileSize + st::msgFilePadding.bottom() - topMinus; - QRect inner(rtlrect(st::msgFilePadding.left(), st::msgFilePadding.top() - topMinus, st::msgFileSize, st::msgFileSize, width())); + QRect inner(style::rtlrect(st::msgFilePadding.left(), st::msgFilePadding.top() - topMinus, st::msgFileSize, st::msgFileSize, width())); p.setPen(Qt::NoPen); if (selected) { p.setBrush(outbg ? st::msgFileOutBgSelected : st::msgFileInBgSelected); @@ -447,7 +447,7 @@ void Document::draw(Painter &p, const QRect &r, TextSelection selection, crl::ti { PainterHighQualityEnabler hq(p); - p.drawEllipse(rtlrect(nameleft + w + st::mediaUnreadSkip, statustop + st::mediaUnreadTop, st::mediaUnreadSize, st::mediaUnreadSize, width())); + p.drawEllipse(style::rtlrect(nameleft + w + st::mediaUnreadSkip, statustop + st::mediaUnreadTop, st::mediaUnreadSize, st::mediaUnreadSize, width())); } } } @@ -473,7 +473,7 @@ void Document::drawCornerDownload(Painter &p, bool selected) const { auto topMinus = isBubbleTop() ? 0 : st::msgFileTopMinus; const auto shift = st::historyAudioDownloadShift; const auto size = st::historyAudioDownloadSize; - const auto inner = rtlrect(st::msgFilePadding.left() + shift, st::msgFilePadding.top() - topMinus + shift, size, size, width()); + const auto inner = style::rtlrect(st::msgFilePadding.left() + shift, st::msgFilePadding.top() - topMinus + shift, size, size, width()); auto pen = (selected ? (outbg ? st::msgOutBgSelected : st::msgInBgSelected) : (outbg ? st::msgOutBg : st::msgInBg))->p; @@ -512,7 +512,7 @@ TextState Document::cornerDownloadTextState( auto topMinus = isBubbleTop() ? 0 : st::msgFileTopMinus; const auto shift = st::historyAudioDownloadShift; const auto size = st::historyAudioDownloadSize; - const auto inner = rtlrect(st::msgFilePadding.left() + shift, st::msgFilePadding.top() - topMinus + shift, size, size, width()); + const auto inner = style::rtlrect(st::msgFilePadding.left() + shift, st::msgFilePadding.top() - topMinus + shift, size, size, width()); if (inner.contains(point)) { result.link = _data->loading() ? _cancell : _savel; } @@ -540,14 +540,14 @@ TextState Document::textState(QPoint point, StateRequest request) const { linktop = st::msgFileThumbLinkTop - topMinus; bottom = st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom() - topMinus; - QRect rthumb(rtlrect(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top() - topMinus, st::msgFileThumbSize, st::msgFileThumbSize, width())); + QRect rthumb(style::rtlrect(st::msgFileThumbPadding.left(), st::msgFileThumbPadding.top() - topMinus, st::msgFileThumbSize, st::msgFileThumbSize, width())); if ((_data->loading() || _data->uploading()) && rthumb.contains(point)) { result.link = _cancell; return result; } if (_data->status != FileUploadFailed) { - if (rtlrect(nameleft, linktop, thumbed->_linkw, st::semiboldFont->height, width()).contains(point)) { + if (style::rtlrect(nameleft, linktop, thumbed->_linkw, st::semiboldFont->height, width()).contains(point)) { result.link = (_data->loading() || _data->uploading()) ? thumbed->_linkcancell : _data->loaded() @@ -565,7 +565,7 @@ TextState Document::textState(QPoint point, StateRequest request) const { if (const auto state = cornerDownloadTextState(point, request); state.link) { return state; } - QRect inner(rtlrect(st::msgFilePadding.left(), st::msgFilePadding.top() - topMinus, st::msgFileSize, st::msgFileSize, width())); + QRect inner(style::rtlrect(st::msgFilePadding.left(), st::msgFilePadding.top() - topMinus, st::msgFileSize, st::msgFileSize, width())); if ((_data->loading() || _data->uploading()) && inner.contains(point) && !downloadInCorner()) { result.link = _cancell; return result; diff --git a/Telegram/SourceFiles/history/view/media/history_view_game.cpp b/Telegram/SourceFiles/history/view/media/history_view_game.cpp index faa30fadc..1adde94d2 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_game.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_game.cpp @@ -213,7 +213,7 @@ void Game::draw(Painter &p, const QRect &r, TextSelection selection, crl::time m bshift += bottomInfoPadding(); } - QRect bar(rtlrect(st::msgPadding.left(), tshift, st::webPageBar, height() - tshift - bshift, width())); + QRect bar(style::rtlrect(st::msgPadding.left(), tshift, st::webPageBar, height() - tshift - bshift, width())); p.fillRect(bar, barfg); auto lineHeight = unitedLineHeight(); @@ -255,7 +255,7 @@ void Game::draw(Painter &p, const QRect &r, TextSelection selection, crl::time m auto gameX = pixwidth - st::msgDateImgDelta - gameW; auto gameY = pixheight - st::msgDateImgDelta - gameH; - App::roundRect(p, rtlrect(gameX, gameY, gameW, gameH, pixwidth), selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners); + App::roundRect(p, style::rtlrect(gameX, gameY, gameW, gameH, pixwidth), selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners); p.setFont(st::msgDateFont); p.setPen(st::msgDateImgFg); diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 2f9d0f9ef..f9913e836 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -292,7 +292,7 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms } if (rtl()) usex = width() - usex - usew; - QRect rthumb(rtlrect(usex + paintx, painty, usew, painth, width())); + QRect rthumb(style::rtlrect(usex + paintx, painty, usew, painth, width())); auto roundRadius = isRound ? ImageRoundRadius::Ellipse : inWebPage ? ImageRoundRadius::Small : ImageRoundRadius::Large; auto roundCorners = (isRound || inWebPage) ? RectPart::AllCorners : ((isBubbleTop() ? (RectPart::TopLeft | RectPart::TopRight) : RectPart::None) @@ -417,14 +417,14 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms auto statusY = painty + st::msgDateImgDelta + st::msgDateImgPadding.y(); auto statusW = st::normalFont->width(_statusText) + 2 * st::msgDateImgPadding.x(); auto statusH = st::normalFont->height + 2 * st::msgDateImgPadding.y(); - App::roundRect(p, rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, width()), selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners); + App::roundRect(p, style::rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, width()), selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners); p.setFont(st::normalFont); p.setPen(st::msgDateImgFg); p.drawTextLeft(statusX, statusY, width(), _statusText, statusW - 2 * st::msgDateImgPadding.x()); } } if (displayMute) { - auto muteRect = rtlrect(rthumb.x() + (rthumb.width() - st::historyVideoMessageMuteSize) / 2, rthumb.y() + st::msgDateImgDelta, st::historyVideoMessageMuteSize, st::historyVideoMessageMuteSize, width()); + auto muteRect = style::rtlrect(rthumb.x() + (rthumb.width() - st::historyVideoMessageMuteSize) / 2, rthumb.y() + st::msgDateImgDelta, st::historyVideoMessageMuteSize, st::historyVideoMessageMuteSize, width()); p.setPen(Qt::NoPen); p.setBrush(selected ? st::msgDateImgBgSelected : st::msgDateImgBg); PainterHighQualityEnabler hq(p); @@ -441,7 +441,7 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms if (mediaUnread) { statusW += st::mediaUnreadSkip + st::mediaUnreadSize; } - App::roundRect(p, rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, width()), selected ? st::msgServiceBgSelected : st::msgServiceBg, selected ? StickerSelectedCorners : StickerCorners); + App::roundRect(p, style::rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, width()), selected ? st::msgServiceBgSelected : st::msgServiceBg, selected ? StickerSelectedCorners : StickerCorners); p.setFont(st::normalFont); p.setPen(st::msgServiceFg); p.drawTextLeft(statusX, statusY, width(), _statusText, statusW - 2 * st::msgDateImgPadding.x()); @@ -451,7 +451,7 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms { PainterHighQualityEnabler hq(p); - p.drawEllipse(rtlrect(statusX - st::msgDateImgPadding.x() + statusW - st::msgDateImgPadding.x() - st::mediaUnreadSize, statusY + st::mediaUnreadTop, st::mediaUnreadSize, st::mediaUnreadSize, width())); + p.drawEllipse(style::rtlrect(statusX - st::msgDateImgPadding.x() + statusW - st::msgDateImgPadding.x() - st::mediaUnreadSize, statusY + st::mediaUnreadTop, st::mediaUnreadSize, st::mediaUnreadSize, width())); } } if (via || reply || forwarded) { diff --git a/Telegram/SourceFiles/history/view/media/history_view_invoice.cpp b/Telegram/SourceFiles/history/view/media/history_view_invoice.cpp index ab427878a..0b0ea2437 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_invoice.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_invoice.cpp @@ -259,7 +259,7 @@ void Invoice::draw(Painter &p, const QRect &r, TextSelection selection, crl::tim auto statusX = st::msgDateImgDelta; auto statusY = st::msgDateImgDelta; - App::roundRect(p, rtlrect(statusX, statusY, statusW, statusH, pixwidth), selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners); + App::roundRect(p, style::rtlrect(statusX, statusY, statusW, statusH, pixwidth), selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners); p.setFont(st::msgDateFont); p.setPen(st::msgDateImgFg); diff --git a/Telegram/SourceFiles/history/view/media/history_view_media.h b/Telegram/SourceFiles/history/view/media/history_view_media.h index e502bbe24..29a260113 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media.h +++ b/Telegram/SourceFiles/history/view/media/history_view_media.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "history/view/history_view_object.h" +#include "ui/rect_part.h" class History; struct HistoryMessageEdited; diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index 97971606e..e96f81098 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -164,7 +164,7 @@ void Photo::draw(Painter &p, const QRect &r, TextSelection selection, crl::time } const auto radial = isRadialAnimation(); - auto rthumb = rtlrect(paintx, painty, paintw, painth, width()); + auto rthumb = style::rtlrect(paintx, painty, paintw, painth, width()); if (_serviceWidth > 0) { const auto pix = [&] { if (loaded) { @@ -187,7 +187,7 @@ void Photo::draw(Painter &p, const QRect &r, TextSelection selection, crl::time if (isBubbleBottom()) { painth -= st::msgPadding.bottom(); } - rthumb = rtlrect(paintx, painty, paintw, painth, width()); + rthumb = style::rtlrect(paintx, painty, paintw, painth, width()); } } else { App::roundShadow(p, 0, 0, paintw, painth, selected ? st::msgInShadowSelected : st::msgInShadow, selected ? InSelectedShadowCorners : InShadowCorners); diff --git a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp index aed5508fe..95ff8ddfb 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_theme_document.cpp @@ -118,7 +118,7 @@ void ThemeDocument::draw(Painter &p, const QRect &r, TextSelection selection, cr } const auto radial = isRadialAnimation(); - auto rthumb = rtlrect(paintx, painty, paintw, painth, width()); + auto rthumb = style::rtlrect(paintx, painty, paintw, painth, width()); auto roundRadius = ImageRoundRadius::Small; auto roundCorners = RectPart::AllCorners; validateThumbnail(); @@ -131,7 +131,7 @@ void ThemeDocument::draw(Painter &p, const QRect &r, TextSelection selection, cr auto statusY = painty + st::msgDateImgDelta + st::msgDateImgPadding.y(); auto statusW = st::normalFont->width(_statusText) + 2 * st::msgDateImgPadding.x(); auto statusH = st::normalFont->height + 2 * st::msgDateImgPadding.y(); - App::roundRect(p, rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, width()), selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners); + App::roundRect(p, style::rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, width()), selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners); p.setFont(st::normalFont); p.setPen(st::msgDateImgFg); p.drawTextLeft(statusX, statusY, width(), _statusText, statusW - 2 * st::msgDateImgPadding.x()); diff --git a/Telegram/SourceFiles/history/view/media/history_view_video.cpp b/Telegram/SourceFiles/history/view/media/history_view_video.cpp index c1119fc46..12ef0cb56 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_video.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_video.cpp @@ -184,7 +184,7 @@ void Video::draw(Painter &p, const QRect &r, TextSelection selection, crl::time auto roundRadius = inWebPage ? ImageRoundRadius::Small : ImageRoundRadius::Large; auto roundCorners = inWebPage ? RectPart::AllCorners : ((isBubbleTop() ? (RectPart::TopLeft | RectPart::TopRight) : RectPart::None) | ((isBubbleBottom() && _caption.isEmpty()) ? (RectPart::BottomLeft | RectPart::BottomRight) : RectPart::None)); - QRect rthumb(rtlrect(paintx, painty, paintw, painth, width())); + QRect rthumb(style::rtlrect(paintx, painty, paintw, painth, width())); const auto good = _data->goodThumbnail(); if (good && good->loaded()) { @@ -278,7 +278,7 @@ void Video::drawCornerStatus(Painter &p, bool selected) const { const auto statusH = cornerDownload ? (st::historyVideoDownloadSize + 2 * padding.y()) : (st::normalFont->height + 2 * padding.y()); const auto statusX = st::msgDateImgDelta + padding.x(); const auto statusY = st::msgDateImgDelta + padding.y(); - const auto around = rtlrect(statusX - padding.x(), statusY - padding.y(), statusW, statusH, width()); + const auto around = style::rtlrect(statusX - padding.x(), statusY - padding.y(), statusW, statusH, width()); const auto statusTextTop = statusY + (cornerDownload ? (((statusH - 2 * st::normalFont->height) / 3) - padding.y()) : 0); App::roundRect(p, around, selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners); p.setFont(st::normalFont); diff --git a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp index 06e19b7a0..6a096c283 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_web_page.cpp @@ -434,7 +434,7 @@ void WebPage::draw(Painter &p, const QRect &r, TextSelection selection, crl::tim bshift += bottomInfoPadding(); } - QRect bar(rtlrect(st::msgPadding.left(), tshift, st::webPageBar, height() - tshift - bshift, width())); + QRect bar(style::rtlrect(st::msgPadding.left(), tshift, st::webPageBar, height() - tshift - bshift, width())); p.fillRect(bar, barfg); auto lineHeight = unitedLineHeight(); @@ -462,7 +462,7 @@ void WebPage::draw(Painter &p, const QRect &r, TextSelection selection, crl::tim } p.drawPixmapLeft(padding.left() + paintw - pw, tshift, width(), pix); if (selected) { - App::roundRect(p, rtlrect(padding.left() + paintw - pw, tshift, pw, _pixh, width()), p.textPalette().selectOverlay, SelectedOverlaySmallCorners); + App::roundRect(p, style::rtlrect(padding.left() + paintw - pw, tshift, pw, _pixh, width()), p.textPalette().selectOverlay, SelectedOverlaySmallCorners); } paintw -= pw + st::webPagePhotoDelta; } @@ -573,7 +573,7 @@ TextState WebPage::textState(QPoint point, StateRequest request) const { auto inThumb = false; if (asArticle()) { auto pw = qMax(_pixw, lineHeight); - if (rtlrect(padding.left() + paintw - pw, 0, pw, _pixh, width()).contains(point)) { + if (style::rtlrect(padding.left() + paintw - pw, 0, pw, _pixh, width()).contains(point)) { inThumb = true; } paintw -= pw + st::webPagePhotoDelta; diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp index be6b791fa..c74a78f1b 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_controller.h" #include "ui/search_field_controller.h" #include "ui/widgets/scroll_area.h" +#include "ui/ui_utility.h" #include "data/data_user.h" #include "data/data_session.h" #include "main/main_session.h" diff --git a/Telegram/SourceFiles/info/info_memento.cpp b/Telegram/SourceFiles/info/info_memento.cpp index 4e81e1053..e20f7b471 100644 --- a/Telegram/SourceFiles/info/info_memento.cpp +++ b/Telegram/SourceFiles/info/info_memento.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_section_widget.h" #include "info/info_layer_widget.h" #include "info/info_controller.h" +#include "ui/ui_utility.h" #include "boxes/peer_list_box.h" #include "data/data_channel.h" #include "data/data_chat.h" diff --git a/Telegram/SourceFiles/info/info_memento.h b/Telegram/SourceFiles/info/info_memento.h index 49c527640..73ec0da59 100644 --- a/Telegram/SourceFiles/info/info_memento.h +++ b/Telegram/SourceFiles/info/info_memento.h @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_wrap_widget.h" #include "dialogs/dialogs_key.h" #include "window/section_memento.h" +#include "base/object_ptr.h" namespace Storage { enum class SharedMediaType : signed char; diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index c25106ed1..2955b54c3 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -52,7 +52,7 @@ void TopBar::registerUpdateControlCallback( QObject *guard, Callback &&callback) { _updateControlCallbacks[guard] =[ - weak = make_weak(guard), + weak = Ui::MakeWeak(guard), callback = std::forward(callback) ](anim::type animated) { if (!weak) { @@ -532,7 +532,7 @@ void TopBar::performForward() { Window::ShowForwardMessagesBox( _navigation, std::move(items), - [weak = make_weak(this)] { + [weak = Ui::MakeWeak(this)] { if (weak) { weak->_cancelSelectionClicks.fire({}); } @@ -547,7 +547,7 @@ void TopBar::performDelete() { const auto box = Ui::show(Box( &_navigation->session(), std::move(items))); - box->setDeleteConfirmedCallback([weak = make_weak(this)] { + box->setDeleteConfirmedCallback([weak = Ui::MakeWeak(this)] { if (weak) { weak->_cancelSelectionClicks.fire({}); } diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index f677dc281..4ef14a780 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -1036,7 +1036,7 @@ object_ptr WrapWidget::createTopBarSurrogate( Assert(_topBar != nullptr); auto result = object_ptr(parent); - result->addClickHandler([weak = make_weak(this)]{ + result->addClickHandler([weak = Ui::MakeWeak(this)]{ if (weak) { weak->_controller->showBackFromStack(); } diff --git a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp index f8fe93706..8a42ab263 100644 --- a/Telegram/SourceFiles/info/media/info_media_list_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_list_widget.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_peer_menu.h" #include "storage/file_download.h" #include "ui/widgets/popup_menu.h" +#include "ui/ui_utility.h" #include "lang/lang_keys.h" #include "main/main_session.h" #include "mainwidget.h" @@ -1396,7 +1397,7 @@ void ListWidget::forwardItem(UniversalMsgId universalId) { } void ListWidget::forwardItems(MessageIdsList &&items) { - auto callback = [weak = make_weak(this)] { + auto callback = [weak = Ui::MakeWeak(this)] { if (const auto strong = weak.data()) { strong->clearSelected(); } @@ -1409,7 +1410,7 @@ void ListWidget::forwardItems(MessageIdsList &&items) { void ListWidget::deleteSelected() { if (const auto box = deleteItems(collectSelectedIds())) { - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); box->setDeleteConfirmedCallback([=]{ if (const auto strong = weak.data()) { strong->clearSelected(); @@ -1439,7 +1440,7 @@ DeleteMessagesBox *ListWidget::deleteItems(MessageIdsList &&items) { void ListWidget::setActionBoxWeak(QPointer box) { if ((_actionBoxWeak = box)) { _actionBoxWeakLifetime = _actionBoxWeak->alive( - ) | rpl::start_with_done([weak = make_weak(this)]{ + ) | rpl::start_with_done([weak = Ui::MakeWeak(this)]{ if (weak) { weak->_checkForHide.fire({}); } diff --git a/Telegram/SourceFiles/info/media/info_media_widget.cpp b/Telegram/SourceFiles/info/media/info_media_widget.cpp index dad143584..ab405f56e 100644 --- a/Telegram/SourceFiles/info/media/info_media_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_widget.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_controller.h" #include "ui/widgets/scroll_area.h" #include "ui/search_field_controller.h" +#include "ui/ui_utility.h" #include "styles/style_info.h" namespace Info { diff --git a/Telegram/SourceFiles/info/members/info_members_widget.cpp b/Telegram/SourceFiles/info/members/info_members_widget.cpp index d51928c74..5e8f4e0c6 100644 --- a/Telegram/SourceFiles/info/members/info_members_widget.cpp +++ b/Telegram/SourceFiles/info/members/info_members_widget.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_members.h" #include "info/info_controller.h" #include "ui/widgets/scroll_area.h" +#include "ui/ui_utility.h" #include "styles/style_info.h" namespace Info { diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.h b/Telegram/SourceFiles/info/profile/info_profile_actions.h index 3f4607113..f36b8a9d1 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.h +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "base/object_ptr.h" + namespace Ui { class RpWidget; } // namespace Ui diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp index bc7b0ca96..0f3aa8934 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp @@ -75,7 +75,7 @@ void SectionToggle::paint( int top, int outerWidth) { auto sqrt2 = sqrt(2.); - auto vLeft = rtlpoint(left + _st.skip, 0, outerWidth).x() + 0.; + auto vLeft = style::rtlpoint(left + _st.skip, 0, outerWidth).x() + 0.; auto vTop = top + _st.skip + 0.; auto vWidth = _st.size - 2 * _st.skip; auto vHeight = _st.size - 2 * _st.skip; diff --git a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.h b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.h index 99e24809c..938e7712a 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.h +++ b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.h @@ -7,8 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include #include "ui/rp_widget.h" +#include "base/object_ptr.h" + +#include namespace Window { class SessionController; diff --git a/Telegram/SourceFiles/info/profile/info_profile_text.h b/Telegram/SourceFiles/info/profile/info_profile_text.h index 3a9942603..813abd872 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_text.h +++ b/Telegram/SourceFiles/info/profile/info_profile_text.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "base/object_ptr.h" + #include namespace style { diff --git a/Telegram/SourceFiles/info/profile/info_profile_widget.cpp b/Telegram/SourceFiles/info/profile/info_profile_widget.cpp index c6069e2e0..f2d7546ea 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_widget.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_widget.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_inner_widget.h" #include "info/profile/info_profile_members.h" #include "ui/widgets/scroll_area.h" +#include "ui/ui_utility.h" #include "info/info_controller.h" namespace Info { diff --git a/Telegram/SourceFiles/info/settings/info_settings_widget.cpp b/Telegram/SourceFiles/info/settings/info_settings_widget.cpp index 89a09479c..5b7b8818a 100644 --- a/Telegram/SourceFiles/info/settings/info_settings_widget.cpp +++ b/Telegram/SourceFiles/info/settings/info_settings_widget.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_memento.h" #include "info/info_controller.h" #include "settings/settings_common.h" +#include "ui/ui_utility.h" namespace Info { namespace Settings { diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp index cba573812..cacf33239 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.cpp @@ -218,7 +218,7 @@ TextState Gif::getState( QPoint point, StateRequest request) const { if (QRect(0, 0, _width, st::inlineMediaHeight).contains(point)) { - if (_delete && rtlpoint(point, _width).x() >= _width - st::stickerPanDeleteIconBg.width() && point.y() < st::stickerPanDeleteIconBg.height()) { + if (_delete && style::rtlpoint(point, _width).x() >= _width - st::stickerPanDeleteIconBg.width() && point.y() < st::stickerPanDeleteIconBg.height()) { return { nullptr, _delete }; } else { return { nullptr, _send }; @@ -668,12 +668,12 @@ void Video::paint(Painter &p, const QRect &clip, const PaintContext *context) co if (withThumb) { prepareThumbnail({ st::inlineThumbSize, st::inlineThumbSize }); if (_thumb.isNull()) { - p.fillRect(rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width), st::overviewPhotoBg); + p.fillRect(style::rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width), st::overviewPhotoBg); } else { p.drawPixmapLeft(0, st::inlineRowMargin, _width, _thumb); } } else { - p.fillRect(rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width), st::overviewVideoBg); + p.fillRect(style::rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width), st::overviewVideoBg); } if (!_duration.isEmpty()) { @@ -695,7 +695,7 @@ void Video::paint(Painter &p, const QRect &clip, const PaintContext *context) co _description.drawLeftElided(p, left, st::inlineRowMargin + titleHeight, _width - left, _width, descriptionLines); if (!context->lastRow) { - p.fillRect(rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg); + p.fillRect(style::rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg); } } @@ -791,7 +791,7 @@ void File::paint(Painter &p, const QRect &clip, const PaintContext *context) con const auto showPause = updateStatusText(); const auto radial = isRadialAnimation(); - auto inner = rtlrect(0, st::inlineRowMargin, st::msgFileSize, st::msgFileSize, _width); + auto inner = style::rtlrect(0, st::inlineRowMargin, st::msgFileSize, st::msgFileSize, _width); p.setPen(Qt::NoPen); if (isThumbAnimation()) { auto over = _animation->a_thumbOver.value(1.); @@ -849,7 +849,7 @@ void File::paint(Painter &p, const QRect &clip, const PaintContext *context) con } if (!context->lastRow) { - p.fillRect(rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg); + p.fillRect(style::rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg); } } @@ -994,7 +994,7 @@ void Contact::paint(Painter &p, const QRect &clip, const PaintContext *context) left = st::msgFileSize + st::inlineThumbSkip; prepareThumbnail(st::msgFileSize, st::msgFileSize); - QRect rthumb(rtlrect(0, st::inlineRowMargin, st::msgFileSize, st::msgFileSize, _width)); + QRect rthumb(style::rtlrect(0, st::inlineRowMargin, st::msgFileSize, st::msgFileSize, _width)); p.drawPixmapLeft(rthumb.topLeft(), _width, _thumb); int titleTop = st::inlineRowMargin + st::inlineRowFileNameTop; @@ -1007,7 +1007,7 @@ void Contact::paint(Painter &p, const QRect &clip, const PaintContext *context) _description.drawLeftElided(p, left, descriptionTop, _width - left, _width); if (!context->lastRow) { - p.fillRect(rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg); + p.fillRect(style::rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg); } } @@ -1107,7 +1107,7 @@ void Article::paint(Painter &p, const QRect &clip, const PaintContext *context) if (_withThumb) { left = st::inlineThumbSize + st::inlineThumbSkip; prepareThumbnail(st::inlineThumbSize, st::inlineThumbSize); - QRect rthumb(rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width)); + QRect rthumb(style::rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width)); if (_thumb.isNull()) { const auto thumb = getResultThumb(); if (!thumb && !_thumbLetter.isEmpty()) { @@ -1147,7 +1147,7 @@ void Article::paint(Painter &p, const QRect &clip, const PaintContext *context) } if (!context->lastRow) { - p.fillRect(rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg); + p.fillRect(style::rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg); } } @@ -1164,7 +1164,7 @@ TextState Article::getState( auto titleHeight = qMin(_title.countHeight(_width - left), st::semiboldFont->height * 2); auto descriptionLines = 2; auto descriptionHeight = qMin(_description.countHeight(_width - left), st::normalFont->height * descriptionLines); - if (rtlrect(left, st::inlineRowMargin + titleHeight + descriptionHeight, _urlWidth, st::normalFont->height, _width).contains(point)) { + if (style::rtlrect(left, st::inlineRowMargin + titleHeight + descriptionHeight, _urlWidth, st::normalFont->height, _width).contains(point)) { return { nullptr, _url }; } } @@ -1268,7 +1268,7 @@ void Game::paint(Painter &p, const QRect &clip, const PaintContext *context) con int32 left = st::emojiPanHeaderLeft - st::inlineResultsLeft; left = st::inlineThumbSize + st::inlineThumbSkip; - auto rthumb = rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width); + auto rthumb = style::rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width); // Gif thumb auto thumbDisplayed = false, radial = false; @@ -1335,7 +1335,7 @@ void Game::paint(Painter &p, const QRect &clip, const PaintContext *context) con _description.drawLeftElided(p, left, st::inlineRowMargin + titleHeight, _width - left, _width, descriptionLines); if (!context->lastRow) { - p.fillRect(rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg); + p.fillRect(style::rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg); } } diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index 4d3d4d3f7..b5ff89353 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -254,7 +254,7 @@ void Widget::historyMove(Direction direction) { } void Widget::hideAndDestroy(object_ptr> widget) { - const auto weak = make_weak(widget.data()); + const auto weak = Ui::MakeWeak(widget.data()); widget->hide(anim::type::normal); widget->shownValue( ) | rpl::start_with_next([=](bool shown) { @@ -447,7 +447,7 @@ void Widget::showTerms(Fn callback) { if (getData()->termsLock.text.text.isEmpty()) { return; } - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); const auto box = Ui::show(callback ? Box( getData()->termsLock, diff --git a/Telegram/SourceFiles/main/main_settings.h b/Telegram/SourceFiles/main/main_settings.h index 3ba716653..541995f74 100644 --- a/Telegram/SourceFiles/main/main_settings.h +++ b/Telegram/SourceFiles/main/main_settings.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "data/data_auto_download.h" +#include "ui/rect_part.h" enum class SendFilesWay; diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index d3e5acb53..190637730 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" #include "ui/emoji_config.h" +#include "ui/ui_utility.h" #include "lang/lang_cloud_manager.h" #include "lang/lang_instance.h" #include "lang/lang_keys.h" diff --git a/Telegram/SourceFiles/media/player/media_player_float.h b/Telegram/SourceFiles/media/player/media_player_float.h index 3b9758800..d71dddfda 100644 --- a/Telegram/SourceFiles/media/player/media_player_float.h +++ b/Telegram/SourceFiles/media/player/media_player_float.h @@ -8,7 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/rect_part.h" #include "ui/effects/animations.h" +#include "base/object_ptr.h" namespace Window { class SessionController; diff --git a/Telegram/SourceFiles/media/player/media_player_panel.cpp b/Telegram/SourceFiles/media/player/media_player_panel.cpp index 1ee47fa82..5eb81aa4c 100644 --- a/Telegram/SourceFiles/media/player/media_player_panel.cpp +++ b/Telegram/SourceFiles/media/player/media_player_panel.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_chat.h" #include "ui/widgets/shadow.h" #include "ui/widgets/scroll_area.h" +#include "ui/ui_utility.h" #include "mainwindow.h" #include "main/main_session.h" #include "app.h" diff --git a/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp b/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp index d2f9c7d41..ebe93958d 100644 --- a/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp +++ b/Telegram/SourceFiles/media/player/media_player_volume_controller.cpp @@ -11,12 +11,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" #include "ui/widgets/continuous_sliders.h" -#include "styles/style_media_player.h" -#include "styles/style_widgets.h" +#include "ui/ui_utility.h" +#include "base/object_ptr.h" #include "mainwindow.h" #include "main/main_session.h" #include "facades.h" #include "app.h" +#include "styles/style_media_player.h" +#include "styles/style_widgets.h" namespace Media { namespace Player { diff --git a/Telegram/SourceFiles/media/player/media_player_volume_controller.h b/Telegram/SourceFiles/media/player/media_player_volume_controller.h index f9e0101ef..d94e69898 100644 --- a/Telegram/SourceFiles/media/player/media_player_volume_controller.h +++ b/Telegram/SourceFiles/media/player/media_player_volume_controller.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/animations.h" #include "ui/rp_widget.h" +#include "base/object_ptr.h" #include diff --git a/Telegram/SourceFiles/media/player/media_player_widget.h b/Telegram/SourceFiles/media/player/media_player_widget.h index 88c1e8324..1b01a518c 100644 --- a/Telegram/SourceFiles/media/player/media_player_widget.h +++ b/Telegram/SourceFiles/media/player/media_player_widget.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "base/object_ptr.h" class AudioMsgId; diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_common.h b/Telegram/SourceFiles/media/streaming/media_streaming_common.h index 71263faeb..fcc748075 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_common.h +++ b/Telegram/SourceFiles/media/streaming/media_streaming_common.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/rect_part.h" + enum class ImageRoundRadius; namespace Media { diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 1c99a9065..82638a84a 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/text_utilities.h" #include "ui/toast/toast.h" #include "ui/text_options.h" +#include "ui/ui_utility.h" #include "boxes/confirm_box.h" #include "media/audio/media_audio.h" #include "media/view/media_view_playback_controls.h" @@ -351,11 +352,11 @@ void OverlayWidget::moveToScreen(bool force) { auto navSkip = 2 * st::mediaviewControlMargin + st::mediaviewControlSize; _closeNav = myrtlrect(width() - st::mediaviewControlMargin - st::mediaviewControlSize, st::mediaviewControlMargin, st::mediaviewControlSize, st::mediaviewControlSize); - _closeNavIcon = centerrect(_closeNav, st::mediaviewClose); + _closeNavIcon = style::centerrect(_closeNav, st::mediaviewClose); _leftNav = myrtlrect(st::mediaviewControlMargin, navSkip, st::mediaviewControlSize, height() - 2 * navSkip); - _leftNavIcon = centerrect(_leftNav, st::mediaviewLeft); + _leftNavIcon = style::centerrect(_leftNav, st::mediaviewLeft); _rightNav = myrtlrect(width() - st::mediaviewControlMargin - st::mediaviewControlSize, navSkip, st::mediaviewControlSize, height() - 2 * navSkip); - _rightNavIcon = centerrect(_rightNav, st::mediaviewRight); + _rightNavIcon = style::centerrect(_rightNav, st::mediaviewRight); _saveMsg.moveTo((width() - _saveMsg.width()) / 2, (height() - _saveMsg.height()) / 2); _photoRadialRect = QRect(QPoint((width() - st::radialSize.width()) / 2, (height() - st::radialSize.height()) / 2), st::radialSize); @@ -558,9 +559,9 @@ void OverlayWidget::updateControls() { && _doc->filepath(DocumentData::FilePathResolve::Checked).isEmpty() && !_doc->loading()); _saveNav = myrtlrect(width() - st::mediaviewIconSize.width() * 2, height() - st::mediaviewIconSize.height(), st::mediaviewIconSize.width(), st::mediaviewIconSize.height()); - _saveNavIcon = centerrect(_saveNav, st::mediaviewSave); + _saveNavIcon = style::centerrect(_saveNav, st::mediaviewSave); _moreNav = myrtlrect(width() - st::mediaviewIconSize.width(), height() - st::mediaviewIconSize.height(), st::mediaviewIconSize.width(), st::mediaviewIconSize.height()); - _moreNavIcon = centerrect(_moreNav, st::mediaviewMore); + _moreNavIcon = style::centerrect(_moreNav, st::mediaviewMore); const auto dNow = QDateTime::currentDateTime(); const auto d = [&] { @@ -2256,7 +2257,7 @@ void OverlayWidget::initThemePreview() { const auto path = _doc->location().name(); const auto id = _themePreviewId = rand_value(); - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); crl::async([=, data = std::move(current)]() mutable { auto preview = GeneratePreview( bytes, @@ -3588,7 +3589,7 @@ void OverlayWidget::touchEvent(QTouchEvent *e) { case QEvent::TouchEnd: { if (!_touchPress) return; - auto weak = make_weak(this); + auto weak = Ui::MakeWeak(this); if (!_touchMove) { Qt::MouseButton btn(_touchRightButton ? Qt::RightButton : Qt::LeftButton); auto mapped = mapFromGlobal(_touchStart); diff --git a/Telegram/SourceFiles/media/view/media_view_playback_controls.h b/Telegram/SourceFiles/media/view/media_view_playback_controls.h index 0a2e11104..4e91c157c 100644 --- a/Telegram/SourceFiles/media/view/media_view_playback_controls.h +++ b/Telegram/SourceFiles/media/view/media_view_playback_controls.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "base/object_ptr.h" namespace Ui { class LabelSimple; diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 89c202d64..cf08a6048 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -645,7 +645,7 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const const auto statustop = _st.songStatusTop; const auto namewidth = _width - nameleft - nameright; - const auto inner = rtlrect( + const auto inner = style::rtlrect( _st.songPadding.left(), _st.songPadding.top(), _st.songThumbSize, @@ -710,12 +710,12 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const icon->paintInCenter(p, inner); } - if (clip.intersects(rtlrect(nameleft, nametop, namewidth, st::semiboldFont->height, _width))) { + if (clip.intersects(style::rtlrect(nameleft, nametop, namewidth, st::semiboldFont->height, _width))) { p.setPen(st::historyFileNameInFg); _name.drawLeftElided(p, nameleft, nametop, namewidth, _width); } - if (clip.intersects(rtlrect(nameleft, statustop, namewidth, st::normalFont->height, _width))) { + if (clip.intersects(style::rtlrect(nameleft, statustop, namewidth, st::normalFont->height, _width))) { p.setFont(st::normalFont); p.setPen(selected ? st::mediaInFgSelected : st::mediaInFg); int32 unreadx = nameleft; @@ -735,7 +735,7 @@ void Voice::paint(Painter &p, const QRect &clip, TextSelection selection, const { PainterHighQualityEnabler hq(p); - p.drawEllipse(rtlrect(unreadx + st::mediaUnreadSkip, statustop + st::mediaUnreadTop, st::mediaUnreadSize, st::mediaUnreadSize, _width)); + p.drawEllipse(style::rtlrect(unreadx + st::mediaUnreadSkip, statustop + st::mediaUnreadTop, st::mediaUnreadSize, st::mediaUnreadSize, _width)); } } } @@ -760,7 +760,7 @@ TextState Voice::getState( const auto nametop = _st.songNameTop; const auto statustop = _st.songStatusTop; - const auto inner = rtlrect( + const auto inner = style::rtlrect( _st.songPadding.left(), _st.songPadding.top(), _st.songThumbSize, @@ -776,7 +776,7 @@ TextState Voice::getState( } auto result = TextState(parent()); const auto statusmaxwidth = _width - nameleft - nameright; - const auto statusrect = rtlrect( + const auto statusrect = style::rtlrect( nameleft, statustop, statusmaxwidth, @@ -794,7 +794,7 @@ TextState Voice::getState( const auto namewidth = std::min( _width - nameleft - nameright, _name.maxWidth()); - const auto namerect = rtlrect( + const auto namerect = style::rtlrect( nameleft, nametop, namewidth, @@ -954,7 +954,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con nametop = _st.songNameTop; statustop = _st.songStatusTop; - auto inner = rtlrect(_st.songPadding.left(), _st.songPadding.top(), _st.songThumbSize, _st.songThumbSize, _width); + auto inner = style::rtlrect(_st.songPadding.left(), _st.songPadding.top(), _st.songThumbSize, _st.songThumbSize, _width); if (clip.intersects(inner)) { p.setPen(Qt::NoPen); if (selected) { @@ -995,12 +995,12 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con statustop = st::linksBorder + _st.fileStatusTop; datetop = st::linksBorder + _st.fileDateTop; - QRect border(rtlrect(nameleft, 0, _width - nameleft, st::linksBorder, _width)); + QRect border(style::rtlrect(nameleft, 0, _width - nameleft, st::linksBorder, _width)); if (!context->isAfterDate && clip.intersects(border)) { p.fillRect(clip.intersected(border), st::linksBorderFg); } - QRect rthumb(rtlrect(0, st::linksBorder + _st.filePadding.top(), _st.fileThumbSize, _st.fileThumbSize, _width)); + QRect rthumb(style::rtlrect(0, st::linksBorder + _st.filePadding.top(), _st.fileThumbSize, _st.fileThumbSize, _width)); if (clip.intersects(rthumb)) { if (wthumb) { const auto thumbLoaded = _data->thumbnail()->loaded(); @@ -1069,17 +1069,17 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con const auto availwidth = _width - nameleft - nameright; const auto namewidth = std::min(availwidth, _name.maxWidth()); - if (clip.intersects(rtlrect(nameleft, nametop, namewidth, st::semiboldFont->height, _width))) { + if (clip.intersects(style::rtlrect(nameleft, nametop, namewidth, st::semiboldFont->height, _width))) { p.setPen(st::historyFileNameInFg); _name.drawLeftElided(p, nameleft, nametop, namewidth, _width); } - if (clip.intersects(rtlrect(nameleft, statustop, availwidth, st::normalFont->height, _width))) { + if (clip.intersects(style::rtlrect(nameleft, statustop, availwidth, st::normalFont->height, _width))) { p.setFont(st::normalFont); p.setPen((isSong && selected) ? st::mediaInFgSelected : st::mediaInFg); p.drawTextLeft(nameleft, statustop, _width, _status.text()); } - if (datetop >= 0 && clip.intersects(rtlrect(nameleft, datetop, _datew, st::normalFont->height, _width))) { + if (datetop >= 0 && clip.intersects(style::rtlrect(nameleft, datetop, _datew, st::normalFont->height, _width))) { p.setFont(ClickHandler::showAsActive(_msgl) ? st::normalFont->underline() : st::normalFont); p.setPen(st::mediaInFg); p.drawTextLeft(nameleft, datetop, _width, _date, _datew); @@ -1105,7 +1105,7 @@ void Document::drawCornerDownload(Painter &p, bool selected, const PaintContext } const auto size = st::overviewSmallCheck.size; const auto shift = _st.songThumbSize + st::overviewCheckSkip - size; - const auto inner = rtlrect(_st.songPadding.left() + shift, _st.songPadding.top() + shift, size, size, _width); + const auto inner = style::rtlrect(_st.songPadding.left() + shift, _st.songPadding.top() + shift, size, size, _width); auto pen = st::windowBg->p; pen.setWidth(st::lineWidth); p.setPen(pen); @@ -1143,7 +1143,7 @@ TextState Document::cornerDownloadTextState( } const auto size = st::overviewSmallCheck.size; const auto shift = _st.songThumbSize + st::overviewCheckSkip - size; - const auto inner = rtlrect(_st.songPadding.left() + shift, _st.songPadding.top() + shift, size, size, _width); + const auto inner = style::rtlrect(_st.songPadding.left() + shift, _st.songPadding.top() + shift, size, size, _width); if (inner.contains(point)) { result.link = _data->loading() ? _cancell : _savel; } @@ -1170,7 +1170,7 @@ TextState Document::getState( return state; } - const auto inner = rtlrect( + const auto inner = style::rtlrect( _st.songPadding.left(), _st.songPadding.top(), _st.songThumbSize, @@ -1185,7 +1185,7 @@ TextState Document::getState( : _savel; return { parent(), link }; } - const auto namerect = rtlrect( + const auto namerect = style::rtlrect( nameleft, nametop, namewidth, @@ -1204,7 +1204,7 @@ TextState Document::getState( const auto statustop = st::linksBorder + _st.fileStatusTop; const auto datetop = st::linksBorder + _st.fileDateTop; - const auto rthumb = rtlrect( + const auto rthumb = style::rtlrect( 0, st::linksBorder + _st.filePadding.top(), _st.fileThumbSize, @@ -1221,7 +1221,7 @@ TextState Document::getState( } if (_data->status != FileUploadFailed) { - auto daterect = rtlrect( + auto daterect = style::rtlrect( nameleft, datetop, _datew, @@ -1232,7 +1232,7 @@ TextState Document::getState( } } if (!_data->loading() && !_data->isNull()) { - auto leftofnamerect = rtlrect( + auto leftofnamerect = style::rtlrect( 0, st::linksBorder, nameleft, @@ -1241,7 +1241,7 @@ TextState Document::getState( if (loaded && leftofnamerect.contains(point)) { return { parent(), _namel }; } - const auto namerect = rtlrect( + const auto namerect = style::rtlrect( nameleft, nametop, namewidth, @@ -1492,7 +1492,7 @@ void Link::paint(Painter &p, const QRect &clip, TextSelection selection, const P const auto pixLeft = 0; const auto pixTop = st::linksMargin.top() + st::linksBorder; - if (clip.intersects(rtlrect(0, pixTop, st::linksPhotoSize, st::linksPhotoSize, _width))) { + if (clip.intersects(style::rtlrect(0, pixTop, st::linksPhotoSize, st::linksPhotoSize, _width))) { if (_page && _page->photo) { QPixmap pix; if (_page->photo->thumbnail()->loaded()) { @@ -1515,7 +1515,7 @@ void Link::paint(Painter &p, const QRect &clip, TextSelection selection, const P ? 0 : (_letter[0].unicode() % 4); const auto fill = [&](style::color color, RoundCorners corners) { - auto pixRect = rtlrect( + auto pixRect = style::rtlrect( pixLeft, pixTop, st::linksPhotoSize, @@ -1533,7 +1533,7 @@ void Link::paint(Painter &p, const QRect &clip, TextSelection selection, const P if (!_letter.isEmpty()) { p.setFont(st::linksLetterFont); p.setPen(st::linksLetterFg); - p.drawText(rtlrect(pixLeft, pixTop, st::linksPhotoSize, st::linksPhotoSize, _width), _letter, style::al_center); + p.drawText(style::rtlrect(pixLeft, pixTop, st::linksPhotoSize, st::linksPhotoSize, _width), _letter, style::al_center); } } } @@ -1550,7 +1550,7 @@ void Link::paint(Painter &p, const QRect &clip, TextSelection selection, const P p.setPen(st::linksTextFg); p.setFont(st::semiboldFont); if (!_title.isEmpty()) { - if (clip.intersects(rtlrect(left, top, qMin(w, _titlew), st::semiboldFont->height, _width))) { + if (clip.intersects(style::rtlrect(left, top, qMin(w, _titlew), st::semiboldFont->height, _width))) { p.drawTextLeft(left, top, _width, (w < _titlew) ? st::semiboldFont->elided(_title, w) : _title); } top += st::semiboldFont->height; @@ -1558,7 +1558,7 @@ void Link::paint(Painter &p, const QRect &clip, TextSelection selection, const P p.setFont(st::msgFont); if (!_text.isEmpty()) { int32 h = qMin(st::normalFont->height * 3, _text.countHeight(w)); - if (clip.intersects(rtlrect(left, top, w, h, _width))) { + if (clip.intersects(style::rtlrect(left, top, w, h, _width))) { _text.drawLeftElided(p, left, top, w, _width, 3); } top += h; @@ -1566,14 +1566,14 @@ void Link::paint(Painter &p, const QRect &clip, TextSelection selection, const P p.setPen(st::windowActiveTextFg); for (const auto &link : _links) { - if (clip.intersects(rtlrect(left, top, qMin(w, link.width), st::normalFont->height, _width))) { + if (clip.intersects(style::rtlrect(left, top, qMin(w, link.width), st::normalFont->height, _width))) { p.setFont(ClickHandler::showAsActive(link.lnk) ? st::normalFont->underline() : st::normalFont); p.drawTextLeft(left, top, _width, (w < link.width) ? st::normalFont->elided(link.text, w) : link.text); } top += st::normalFont->height; } - QRect border(rtlrect(left, 0, w, st::linksBorder, _width)); + QRect border(style::rtlrect(left, 0, w, st::linksBorder, _width)); if (!context->isAfterDate && clip.intersects(border)) { p.fillRect(clip.intersected(border), st::linksBorderFg); } @@ -1589,7 +1589,7 @@ TextState Link::getState( QPoint point, StateRequest request) const { int32 left = st::linksPhotoSize + st::linksPhotoPadding, top = st::linksMargin.top() + st::linksBorder, w = _width - left; - if (rtlrect(0, top, st::linksPhotoSize, st::linksPhotoSize, _width).contains(point)) { + if (style::rtlrect(0, top, st::linksPhotoSize, st::linksPhotoSize, _width).contains(point)) { return { parent(), _photol }; } @@ -1597,7 +1597,7 @@ TextState Link::getState( top += (st::linksPhotoSize - st::semiboldFont->height - st::normalFont->height) / 2; } if (!_title.isEmpty()) { - if (rtlrect(left, top, qMin(w, _titlew), st::semiboldFont->height, _width).contains(point)) { + if (style::rtlrect(left, top, qMin(w, _titlew), st::semiboldFont->height, _width).contains(point)) { return { parent(), _photol }; } top += st::webPageTitleFont->height; @@ -1606,7 +1606,7 @@ TextState Link::getState( top += qMin(st::normalFont->height * 3, _text.countHeight(w)); } for (const auto &link : _links) { - if (rtlrect(left, top, qMin(w, link.width), st::normalFont->height, _width).contains(point)) { + if (style::rtlrect(left, top, qMin(w, link.width), st::normalFont->height, _width).contains(point)) { return { parent(), ClickHandlerPtr(link.lnk) }; } top += st::normalFont->height; diff --git a/Telegram/SourceFiles/passport/passport_form_view_controller.h b/Telegram/SourceFiles/passport/passport_form_view_controller.h index 85efd5d3c..795fb84f1 100644 --- a/Telegram/SourceFiles/passport/passport_form_view_controller.h +++ b/Telegram/SourceFiles/passport/passport_form_view_controller.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "passport/passport_form_controller.h" +#include "base/object_ptr.h" namespace Passport { diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.cpp b/Telegram/SourceFiles/passport/passport_panel_controller.cpp index 11d29c3e8..051c876b1 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_controller.cpp @@ -1223,7 +1223,7 @@ void PanelController::startScopeEdit( std::move(scans), std::move(translations), PrepareSpecialFiles(*_editDocument)); - const auto weak = make_weak(result.data()); + const auto weak = Ui::MakeWeak(result.data()); _panelHasUnsavedChanges = [=] { return weak ? weak->hasUnsavedChanges() : false; }; @@ -1241,7 +1241,7 @@ void PanelController::startScopeEdit( _editValue->nativeNames), _editValue->error, _editValue->data.parsedInEdit); - const auto weak = make_weak(result.data()); + const auto weak = Ui::MakeWeak(result.data()); _panelHasUnsavedChanges = [=] { return weak ? weak->hasUnsavedChanges() : false; }; diff --git a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp index cad3555a3..658595612 100644 --- a/Telegram/SourceFiles/passport/passport_panel_details_row.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_details_row.cpp @@ -552,7 +552,7 @@ DateRow::DateRow( GetYear(value)) , _value(valueCurrent()) { const auto focused = [=](const object_ptr &field) { - return [this, pointer = make_weak(field.data())]{ + return [this, pointer = Ui::MakeWeak(field.data())]{ _borderAnimationStart = pointer->borderAnimationStart() + pointer->x() - _day->x(); diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_contact.h b/Telegram/SourceFiles/passport/passport_panel_edit_contact.h index cf657463a..cd58420b2 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_contact.h +++ b/Telegram/SourceFiles/passport/passport_panel_edit_contact.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "base/object_ptr.h" class BoxContent; diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.h b/Telegram/SourceFiles/passport/passport_panel_edit_document.h index 22ef459fd..fcf9aa287 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.h +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "base/object_ptr.h" class BoxContent; diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_scans.h b/Telegram/SourceFiles/passport/passport_panel_edit_scans.h index fc8fee23b..b529db963 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_scans.h +++ b/Telegram/SourceFiles/passport/passport_panel_edit_scans.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rp_widget.h" #include "ui/effects/animations.h" +#include "base/object_ptr.h" class BoxContentDivider; diff --git a/Telegram/SourceFiles/passport/passport_panel_form.h b/Telegram/SourceFiles/passport/passport_panel_form.h index f13caf38a..a7fdd9f96 100644 --- a/Telegram/SourceFiles/passport/passport_panel_form.h +++ b/Telegram/SourceFiles/passport/passport_panel_form.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "base/object_ptr.h" class BoxContentDivider; diff --git a/Telegram/SourceFiles/passport/passport_panel_password.h b/Telegram/SourceFiles/passport/passport_panel_password.h index 1de899762..63df347c6 100644 --- a/Telegram/SourceFiles/passport/passport_panel_password.h +++ b/Telegram/SourceFiles/passport/passport_panel_password.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "base/object_ptr.h" namespace Ui { class PasswordInput; diff --git a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm index cdf6bc5b9..0569a15bf 100644 --- a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm +++ b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm @@ -812,7 +812,7 @@ void AppendEmojiPacks(std::vector &to) { if (const auto inputField = qobject_cast( QApplication::focusWidget())) { Ui::InsertEmojiAtCursor(inputField->textCursor(), emoji); - Ui::Emoji::AddRecent(emoji); + AddRecentEmoji(emoji); return true; } } @@ -1065,7 +1065,7 @@ void AppendEmojiPacks(std::vector &to) { }, _lifetime); rpl::merge( - Ui::Emoji::UpdatedRecent(), + UpdatedRecentEmoji(), Ui::Emoji::Updated() ) | rpl::start_with_next([=] { [self updatePickerPopover:ScrubberItemType::Emoji]; diff --git a/Telegram/SourceFiles/platform/platform_window_title.h b/Telegram/SourceFiles/platform/platform_window_title.h index 7aed20b63..6aea66396 100644 --- a/Telegram/SourceFiles/platform/platform_window_title.h +++ b/Telegram/SourceFiles/platform/platform_window_title.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_title.h" #include "window/themes/window_theme_preview.h" +#include "base/object_ptr.h" namespace Platform { diff --git a/Telegram/SourceFiles/platform/win/specific_win.cpp b/Telegram/SourceFiles/platform/win/specific_win.cpp index 68f7bcb85..83b31d693 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.cpp +++ b/Telegram/SourceFiles/platform/win/specific_win.cpp @@ -572,7 +572,7 @@ void psSendToMenu(bool send, bool silent) { _manageAppLnk(send, silent, CSIDL_SENDTO, L"-sendpath", L"Telegram send to link.\nYou can disable send to menu item in Telegram settings."); } -void psUpdateOverlayed(TWidget *widget) { +void psUpdateOverlayed(QWidget *widget) { bool wm = widget->testAttribute(Qt::WA_Mapped), wv = widget->testAttribute(Qt::WA_WState_Visible); if (!wm) widget->setAttribute(Qt::WA_Mapped, true); if (!wv) widget->setAttribute(Qt::WA_WState_Visible, true); diff --git a/Telegram/SourceFiles/platform/win/specific_win.h b/Telegram/SourceFiles/platform/win/specific_win.h index 5f6995fd5..cf2ab893f 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.h +++ b/Telegram/SourceFiles/platform/win/specific_win.h @@ -82,7 +82,7 @@ int psFixPrevious(); void psNewVersion(); -void psUpdateOverlayed(TWidget *widget); +void psUpdateOverlayed(QWidget *widget); inline QByteArray psDownloadPathBookmark(const QString &path) { return QByteArray(); } diff --git a/Telegram/SourceFiles/platform/win/window_title_win.h b/Telegram/SourceFiles/platform/win/window_title_win.h index ab1d5c2f5..19e0a1246 100644 --- a/Telegram/SourceFiles/platform/win/window_title_win.h +++ b/Telegram/SourceFiles/platform/win/window_title_win.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "platform/platform_window_title.h" +#include "base/object_ptr.h" namespace Ui { class IconButton; diff --git a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp index f18cc724a..a0545df1d 100644 --- a/Telegram/SourceFiles/profile/profile_block_peer_list.cpp +++ b/Telegram/SourceFiles/profile/profile_block_peer_list.cpp @@ -122,7 +122,7 @@ void PeerListWidget::paintItem(Painter &p, int x, int y, Item *item, bool select } void PeerListWidget::paintItemRect(Painter &p, int x, int y, int w, int h) const { - p.fillRect(rtlrect(x, y, w, h, width()), _st.button.textBgOver); + p.fillRect(style::rtlrect(x, y, w, h, width()), _st.button.textBgOver); } void PeerListWidget::mouseMoveEvent(QMouseEvent *e) { diff --git a/Telegram/SourceFiles/profile/profile_cover_drop_area.cpp b/Telegram/SourceFiles/profile/profile_cover_drop_area.cpp index d1513eda8..9e42f7e34 100644 --- a/Telegram/SourceFiles/profile/profile_cover_drop_area.cpp +++ b/Telegram/SourceFiles/profile/profile_cover_drop_area.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "profile/profile_cover_drop_area.h" +#include "ui/ui_utility.h" #include "styles/style_profile.h" namespace Profile { diff --git a/Telegram/SourceFiles/profile/profile_cover_drop_area.h b/Telegram/SourceFiles/profile/profile_cover_drop_area.h index c757c510e..156d53ade 100644 --- a/Telegram/SourceFiles/profile/profile_cover_drop_area.h +++ b/Telegram/SourceFiles/profile/profile_cover_drop_area.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/effects/animations.h" +#include "ui/rp_widget.h" namespace Profile { diff --git a/Telegram/SourceFiles/settings/settings_common.h b/Telegram/SourceFiles/settings/settings_common.h index 89dee31d9..1e0d57dea 100644 --- a/Telegram/SourceFiles/settings/settings_common.h +++ b/Telegram/SourceFiles/settings/settings_common.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "base/object_ptr.h" namespace Main { class Session; diff --git a/Telegram/SourceFiles/settings/settings_notifications.cpp b/Telegram/SourceFiles/settings/settings_notifications.cpp index aa56bfaf9..ea7c4a8fc 100644 --- a/Telegram/SourceFiles/settings/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/settings_notifications.cpp @@ -226,24 +226,24 @@ void NotificationsCount::prepareNotificationSampleSmall() { auto padding = height / 8; auto userpicSize = height - 2 * padding; p.setBrush(st::notificationSampleUserpicFg); - p.drawEllipse(rtlrect(padding, padding, userpicSize, userpicSize, width)); + p.drawEllipse(style::rtlrect(padding, padding, userpicSize, userpicSize, width)); auto rowLeft = height; auto rowHeight = padding; auto nameTop = (height - 5 * padding) / 2; auto nameWidth = height; p.setBrush(st::notificationSampleNameFg); - p.drawRoundedRect(rtlrect(rowLeft, nameTop, nameWidth, rowHeight, width), rowHeight / 2, rowHeight / 2); + p.drawRoundedRect(style::rtlrect(rowLeft, nameTop, nameWidth, rowHeight, width), rowHeight / 2, rowHeight / 2); auto rowWidth = (width - rowLeft - 3 * padding); auto rowTop = nameTop + rowHeight + padding; p.setBrush(st::notificationSampleTextFg); - p.drawRoundedRect(rtlrect(rowLeft, rowTop, rowWidth, rowHeight, width), rowHeight / 2, rowHeight / 2); + p.drawRoundedRect(style::rtlrect(rowLeft, rowTop, rowWidth, rowHeight, width), rowHeight / 2, rowHeight / 2); rowTop += rowHeight + padding; - p.drawRoundedRect(rtlrect(rowLeft, rowTop, rowWidth, rowHeight, width), rowHeight / 2, rowHeight / 2); + p.drawRoundedRect(style::rtlrect(rowLeft, rowTop, rowWidth, rowHeight, width), rowHeight / 2, rowHeight / 2); auto closeLeft = width - 2 * padding; - p.fillRect(rtlrect(closeLeft, padding, padding, padding, width), st::notificationSampleCloseFg); + p.fillRect(style::rtlrect(closeLeft, padding, padding, padding, width), st::notificationSampleCloseFg); } _notificationSampleSmall = App::pixmapFromImageInPlace(std::move(sampleImage)); _notificationSampleSmall.setDevicePixelRatio(cRetinaFactor()); @@ -281,7 +281,7 @@ void NotificationsCount::prepareNotificationSampleLarge() { int itemWidth = w - st::notifyPhotoPos.x() - st::notifyPhotoSize - st::notifyTextLeft - st::notifyClosePos.x() - st::notifyClose.width; - auto rectForName = rtlrect(st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft, st::notifyTextTop, itemWidth, st::msgNameFont->height, w); + auto rectForName = style::rtlrect(st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft, st::notifyTextTop, itemWidth, st::msgNameFont->height, w); auto notifyText = st::dialogsTextFont->elided(tr::lng_notification_sample(tr::now), itemWidth); p.setFont(st::dialogsTextFont); @@ -318,10 +318,10 @@ void NotificationsCount::mouseMoveEvent(QMouseEvent *e) { auto screenRect = getScreenRect(); auto cornerWidth = screenRect.width() / 3; auto cornerHeight = screenRect.height() / 3; - auto topLeft = rtlrect(screenRect.x(), screenRect.y(), cornerWidth, cornerHeight, width()); - auto topRight = rtlrect(screenRect.x() + screenRect.width() - cornerWidth, screenRect.y(), cornerWidth, cornerHeight, width()); - auto bottomRight = rtlrect(screenRect.x() + screenRect.width() - cornerWidth, screenRect.y() + screenRect.height() - cornerHeight, cornerWidth, cornerHeight, width()); - auto bottomLeft = rtlrect(screenRect.x(), screenRect.y() + screenRect.height() - cornerHeight, cornerWidth, cornerHeight, width()); + auto topLeft = style::rtlrect(screenRect.x(), screenRect.y(), cornerWidth, cornerHeight, width()); + auto topRight = style::rtlrect(screenRect.x() + screenRect.width() - cornerWidth, screenRect.y(), cornerWidth, cornerHeight, width()); + auto bottomRight = style::rtlrect(screenRect.x() + screenRect.width() - cornerWidth, screenRect.y() + screenRect.height() - cornerHeight, cornerWidth, cornerHeight, width()); + auto bottomLeft = style::rtlrect(screenRect.x(), screenRect.y() + screenRect.height() - cornerHeight, cornerWidth, cornerHeight, width()); if (topLeft.contains(e->pos())) { setOverCorner(Notify::ScreenCorner::TopLeft); } else if (topRight.contains(e->pos())) { diff --git a/Telegram/SourceFiles/stdafx.h b/Telegram/SourceFiles/stdafx.h index f687fa9a5..2f93879cf 100644 --- a/Telegram/SourceFiles/stdafx.h +++ b/Telegram/SourceFiles/stdafx.h @@ -126,7 +126,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/palette.h" #include "styles/style_basic.h" -#include "ui/twidget.h" #include "ui/image/image_location.h" #include "ui/text/text.h" diff --git a/Telegram/SourceFiles/storage/file_download.cpp b/Telegram/SourceFiles/storage/file_download.cpp index caf550dff..ffac1874e 100644 --- a/Telegram/SourceFiles/storage/file_download.cpp +++ b/Telegram/SourceFiles/storage/file_download.cpp @@ -449,7 +449,7 @@ bool FileLoader::tryLoadLocal() { return true; } - const auto weak = make_weak(this); + const auto weak = QPointer(this); if (_toCache == LoadToCacheAsWell) { loadLocal(cacheKey()); emit progress(this); @@ -485,7 +485,7 @@ void FileLoader::cancel(bool fail) { const auto queue = _queue; const auto sessionGuard = &session(); - const auto weak = make_weak(this); + const auto weak = QPointer(this); if (fail) { emit failed(this, started); } else { @@ -989,7 +989,7 @@ void mtpFileLoader::getCdnFileHashesDone( } } if (someMoreChecked) { - const auto weak = make_weak(this); + const auto weak = QPointer(this); notifyAboutProgress(); if (weak) { requestMoreCdnFileHashes(); diff --git a/Telegram/SourceFiles/support/support_autocomplete.cpp b/Telegram/SourceFiles/support/support_autocomplete.cpp index 22f295a87..2e4e166d0 100644 --- a/Telegram/SourceFiles/support/support_autocomplete.cpp +++ b/Telegram/SourceFiles/support/support_autocomplete.cpp @@ -539,7 +539,7 @@ void ConfirmContactBox::prepare() { _contact->initDimensions(); _submit = [=, original = std::move(_submit)](Qt::KeyboardModifiers m) { - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); original(m); if (weak) { closeBox(); diff --git a/Telegram/SourceFiles/ui/abstract_button.cpp b/Telegram/SourceFiles/ui/abstract_button.cpp index e4a2fcf50..165b1a9ea 100644 --- a/Telegram/SourceFiles/ui/abstract_button.cpp +++ b/Telegram/SourceFiles/ui/abstract_button.cpp @@ -7,9 +7,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/abstract_button.h" +#include "core/application.h" +#include "ui/ui_utility.h" + #include #include -#include "core/application.h" namespace Ui { @@ -69,7 +71,7 @@ void AbstractButton::mouseReleaseEvent(QMouseEvent *e) { const auto was = _state; _state &= ~State(StateFlag::Down); - auto weak = make_weak(this); + auto weak = MakeWeak(this); onStateChanged(was, StateChangeSource::ByPress); if (!weak) { return; diff --git a/Telegram/SourceFiles/ui/effects/animation_value.h b/Telegram/SourceFiles/ui/effects/animation_value.h index 78d74ea5c..93eaf9b08 100644 --- a/Telegram/SourceFiles/ui/effects/animation_value.h +++ b/Telegram/SourceFiles/ui/effects/animation_value.h @@ -251,7 +251,7 @@ TG_FORCE_INLINE Shifted non_premultiplied(QColor color) { } TG_FORCE_INLINE QColor color(QColor a, QColor b, float64 b_ratio) { - auto bOpacity = snap(interpolate(0, 255, b_ratio), 0, 255) + 1; + auto bOpacity = std::clamp(interpolate(0, 255, b_ratio), 0, 255) + 1; auto aOpacity = (256 - bOpacity); auto components = (non_premultiplied(a) * aOpacity + non_premultiplied(b) * bOpacity); return { diff --git a/Telegram/SourceFiles/ui/effects/animations.cpp b/Telegram/SourceFiles/ui/effects/animations.cpp index 690f31eb5..c493aadfc 100644 --- a/Telegram/SourceFiles/ui/effects/animations.cpp +++ b/Telegram/SourceFiles/ui/effects/animations.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/effects/animations.h" +#include "ui/ui_utility.h" #include "core/application.h" namespace Ui { diff --git a/Telegram/SourceFiles/ui/effects/cross_animation.cpp b/Telegram/SourceFiles/ui/effects/cross_animation.cpp index 962e7bc0b..07c6a3693 100644 --- a/Telegram/SourceFiles/ui/effects/cross_animation.cpp +++ b/Telegram/SourceFiles/ui/effects/cross_animation.cpp @@ -118,7 +118,7 @@ void CrossAnimation::paint( auto sqrt2 = sqrt(2.); auto deleteScale = shown + st.minScale * (1. - shown); auto deleteSkip = (deleteScale * st.skip) + (1. - deleteScale) * (st.size / 2); - auto deleteLeft = rtlpoint(x + deleteSkip, 0, outerWidth).x() + 0.; + auto deleteLeft = style::rtlpoint(x + deleteSkip, 0, outerWidth).x() + 0.; auto deleteTop = y + deleteSkip + 0.; auto deleteWidth = st.size - 2 * deleteSkip; auto deleteHeight = st.size - 2 * deleteSkip; diff --git a/Telegram/SourceFiles/ui/effects/fade_animation.cpp b/Telegram/SourceFiles/ui/effects/fade_animation.cpp index 2ec5caca8..5c7febd09 100644 --- a/Telegram/SourceFiles/ui/effects/fade_animation.cpp +++ b/Telegram/SourceFiles/ui/effects/fade_animation.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/effects/fade_animation.h" +#include "ui/ui_utility.h" #include "app.h" namespace Ui { diff --git a/Telegram/SourceFiles/ui/effects/panel_animation.cpp b/Telegram/SourceFiles/ui/effects/panel_animation.cpp index b9432c973..4d3109735 100644 --- a/Telegram/SourceFiles/ui/effects/panel_animation.cpp +++ b/Telegram/SourceFiles/ui/effects/panel_animation.cpp @@ -493,7 +493,7 @@ void PanelAnimation::paintFrame(QPainter &p, int x, int y, int outerWidth, float // frameInts += _frameIntsPerLineAdded; //} - p.drawImage(rtlpoint(x + (outerLeft / cIntRetinaFactor()), y + (outerTop / cIntRetinaFactor()), outerWidth), _frame, QRect(outerLeft, outerTop, outerRight - outerLeft, outerBottom - outerTop)); + p.drawImage(style::rtlpoint(x + (outerLeft / cIntRetinaFactor()), y + (outerTop / cIntRetinaFactor()), outerWidth), _frame, QRect(outerLeft, outerTop, outerRight - outerLeft, outerBottom - outerTop)); } } // namespace Ui diff --git a/Telegram/SourceFiles/ui/effects/radial_animation.cpp b/Telegram/SourceFiles/ui/effects/radial_animation.cpp index 813aad5b6..ca0e2729e 100644 --- a/Telegram/SourceFiles/ui/effects/radial_animation.cpp +++ b/Telegram/SourceFiles/ui/effects/radial_animation.cpp @@ -147,7 +147,7 @@ void InfiniteRadialAnimation::draw( auto o = p.opacity(); p.setOpacity(o * state.shown); - const auto rect = rtlrect( + const auto rect = style::rtlrect( position.x(), position.y(), size.width(), diff --git a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp index 239bd407f..fb2b5f6d7 100644 --- a/Telegram/SourceFiles/ui/effects/round_checkbox.cpp +++ b/Telegram/SourceFiles/ui/effects/round_checkbox.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/themes/window_theme.h" #include "ui/rp_widget.h" +#include "ui/ui_utility.h" #include "app.h" #include @@ -427,7 +428,7 @@ void RoundImageCheckbox::paint(Painter &p, int x, int y, int outerWidth) { auto pen = _st.selectFg->p; pen.setWidth(_st.selectWidth); p.setPen(pen); - p.drawEllipse(rtlrect(x, y, _st.imageRadius * 2, _st.imageRadius * 2, outerWidth)); + p.drawEllipse(style::rtlrect(x, y, _st.imageRadius * 2, _st.imageRadius * 2, outerWidth)); p.setOpacity(1.); } diff --git a/Telegram/SourceFiles/ui/grouped_layout.h b/Telegram/SourceFiles/ui/grouped_layout.h index 0f66a7958..58a8f4ab5 100644 --- a/Telegram/SourceFiles/ui/grouped_layout.h +++ b/Telegram/SourceFiles/ui/grouped_layout.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/rect_part.h" + namespace Ui { struct GroupMediaLayout { diff --git a/Telegram/SourceFiles/ui/image/image_prepare.h b/Telegram/SourceFiles/ui/image/image_prepare.h index b9f96a560..b8af5715b 100644 --- a/Telegram/SourceFiles/ui/image/image_prepare.h +++ b/Telegram/SourceFiles/ui/image/image_prepare.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "base/flags.h" +#include "ui/rect_part.h" namespace Storage { namespace Cache { diff --git a/Telegram/SourceFiles/ui/rect_part.h b/Telegram/SourceFiles/ui/rect_part.h new file mode 100644 index 000000000..37fe1425e --- /dev/null +++ b/Telegram/SourceFiles/ui/rect_part.h @@ -0,0 +1,59 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "base/flags.h" + +enum class RectPart { + None = 0, + + TopLeft = (1 << 0), + Top = (1 << 1), + TopRight = (1 << 2), + Left = (1 << 3), + Center = (1 << 4), + Right = (1 << 5), + BottomLeft = (1 << 6), + Bottom = (1 << 7), + BottomRight = (1 << 8), + + FullTop = TopLeft | Top | TopRight, + NoTopBottom = Left | Center | Right, + FullBottom = BottomLeft | Bottom | BottomRight, + NoTop = NoTopBottom | FullBottom, + NoBottom = FullTop | NoTopBottom, + + FullLeft = TopLeft | Left | BottomLeft, + NoLeftRight = Top | Center | Bottom, + FullRight = TopRight | Right | BottomRight, + NoLeft = NoLeftRight | FullRight, + NoRight = FullLeft | NoLeftRight, + + AllCorners = TopLeft | TopRight | BottomLeft | BottomRight, + AllSides = Top | Bottom | Left | Right, + + Full = FullTop | NoTop, +}; +using RectParts = base::flags; +inline constexpr auto is_flag_type(RectPart) { return true; }; + +inline bool IsTopCorner(RectPart corner) { + return (corner == RectPart::TopLeft) || (corner == RectPart::TopRight); +} + +inline bool IsBottomCorner(RectPart corner) { + return (corner == RectPart::BottomLeft) || (corner == RectPart::BottomRight); +} + +inline bool IsLeftCorner(RectPart corner) { + return (corner == RectPart::TopLeft) || (corner == RectPart::BottomLeft); +} + +inline bool IsRightCorner(RectPart corner) { + return (corner == RectPart::TopRight) || (corner == RectPart::BottomRight); +} diff --git a/Telegram/SourceFiles/ui/rp_widget.h b/Telegram/SourceFiles/ui/rp_widget.h index 0f1c9f091..6109e4baf 100644 --- a/Telegram/SourceFiles/ui/rp_widget.h +++ b/Telegram/SourceFiles/ui/rp_widget.h @@ -7,93 +7,241 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "base/unique_qptr.h" +#include "ui/style/style_core_direction.h" +#include "ui/ui_utility.h" + #include #include #include -#include "base/unique_qptr.h" -namespace Ui { -namespace details { +class TWidget; -struct ForwardTag { -}; - -struct InPlaceTag { -}; - -template -class AttachmentOwner : public QObject { +template +class TWidgetHelper : public Base { public: - template - AttachmentOwner(QObject *parent, const ForwardTag&, OtherValue &&value) - : QObject(parent) - , _value(std::forward(value)) { + using Base::Base; + + virtual QMargins getMargins() const { + return QMargins(); } - template - AttachmentOwner(QObject *parent, const InPlaceTag&, Args &&...args) - : QObject(parent) - , _value(std::forward(args)...) { + bool inFocusChain() const { + return Ui::InFocusChain(this); } - not_null value() { - return &_value; + void hideChildren() { + for (auto child : Base::children()) { + if (child->isWidgetType()) { + static_cast(child)->hide(); + } + } + } + void showChildren() { + for (auto child : Base::children()) { + if (child->isWidgetType()) { + static_cast(child)->show(); + } + } + } + + void moveToLeft(int x, int y, int outerw = 0) { + auto margins = getMargins(); + x -= margins.left(); + y -= margins.top(); + Base::move(rtl() ? ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - Base::width()) : x, y); + } + void moveToRight(int x, int y, int outerw = 0) { + auto margins = getMargins(); + x -= margins.right(); + y -= margins.top(); + Base::move(rtl() ? x : ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - Base::width()), y); + } + void setGeometryToLeft(int x, int y, int w, int h, int outerw = 0) { + auto margins = getMargins(); + x -= margins.left(); + y -= margins.top(); + w -= margins.left() - margins.right(); + h -= margins.top() - margins.bottom(); + Base::setGeometry(rtl() ? ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - w) : x, y, w, h); + } + void setGeometryToRight(int x, int y, int w, int h, int outerw = 0) { + auto margins = getMargins(); + x -= margins.right(); + y -= margins.top(); + w -= margins.left() - margins.right(); + h -= margins.top() - margins.bottom(); + Base::setGeometry(rtl() ? x : ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - w), y, w, h); + } + QPoint myrtlpoint(int x, int y) const { + return style::rtlpoint(x, y, Base::width()); + } + QPoint myrtlpoint(const QPoint point) const { + return style::rtlpoint(point, Base::width()); + } + QRect myrtlrect(int x, int y, int w, int h) const { + return style::rtlrect(x, y, w, h, Base::width()); + } + QRect myrtlrect(const QRect &rect) const { + return style::rtlrect(rect, Base::width()); + } + void rtlupdate(const QRect &rect) { + Base::update(myrtlrect(rect)); + } + void rtlupdate(int x, int y, int w, int h) { + Base::update(myrtlrect(x, y, w, h)); + } + + QPoint mapFromGlobal(const QPoint &point) const { + return Base::mapFromGlobal(point); + } + QPoint mapToGlobal(const QPoint &point) const { + return Base::mapToGlobal(point); + } + QRect mapFromGlobal(const QRect &rect) const { + return QRect(mapFromGlobal(rect.topLeft()), rect.size()); + } + QRect mapToGlobal(const QRect &rect) const { + return QRect(mapToGlobal(rect.topLeft()), rect.size()); + } + +protected: + void enterEvent(QEvent *e) final override { + if (auto parent = tparent()) { + parent->leaveToChildEvent(e, this); + } + return enterEventHook(e); + } + virtual void enterEventHook(QEvent *e) { + return Base::enterEvent(e); + } + + void leaveEvent(QEvent *e) final override { + if (auto parent = tparent()) { + parent->enterFromChildEvent(e, this); + } + return leaveEventHook(e); + } + virtual void leaveEventHook(QEvent *e) { + return Base::leaveEvent(e); + } + + // e - from enterEvent() of child TWidget + virtual void leaveToChildEvent(QEvent *e, QWidget *child) { + } + + // e - from leaveEvent() of child TWidget + virtual void enterFromChildEvent(QEvent *e, QWidget *child) { } private: - Value _value; + TWidget *tparent() { + return qobject_cast(Base::parentWidget()); + } + const TWidget *tparent() const { + return qobject_cast(Base::parentWidget()); + } + + template + friend class TWidgetHelper; }; -} // namespace details +class TWidget : public TWidgetHelper { + // The Q_OBJECT meta info is used for qobject_cast! + Q_OBJECT + +public: + TWidget(QWidget *parent = nullptr) : TWidgetHelper(parent) { + } + + // Get the size of the widget as it should be. + // Negative return value means no default width. + virtual int naturalWidth() const { + return -1; + } + + // Count new height for width=newWidth and resize to it. + void resizeToWidth(int newWidth) { + auto margins = getMargins(); + auto fullWidth = margins.left() + newWidth + margins.right(); + auto fullHeight = margins.top() + resizeGetHeight(newWidth) + margins.bottom(); + auto newSize = QSize(fullWidth, fullHeight); + if (newSize != size()) { + resize(newSize); + update(); + } + } + + // Resize to minimum of natural width and available width. + void resizeToNaturalWidth(int newWidth) { + auto maxWidth = naturalWidth(); + resizeToWidth((maxWidth >= 0) ? qMin(newWidth, maxWidth) : newWidth); + } + + QRect rectNoMargins() const { + return rect().marginsRemoved(getMargins()); + } + + int widthNoMargins() const { + return rectNoMargins().width(); + } + + int heightNoMargins() const { + return rectNoMargins().height(); + } + + int bottomNoMargins() const { + auto rectWithoutMargins = rectNoMargins(); + return y() + rectWithoutMargins.y() + rectWithoutMargins.height(); + } + + QSize sizeNoMargins() const { + return rectNoMargins().size(); + } + + // Updates the area that is visible inside the scroll container. + void setVisibleTopBottom(int visibleTop, int visibleBottom) { + auto max = height(); + visibleTopBottomUpdated( + snap(visibleTop, 0, max), + snap(visibleBottom, 0, max)); + } + +signals: + // Child widget is responsible for emitting this signal. + void heightUpdated(); + +protected: + void setChildVisibleTopBottom( + TWidget *child, + int visibleTop, + int visibleBottom) { + if (child) { + auto top = child->y(); + child->setVisibleTopBottom( + visibleTop - top, + visibleBottom - top); + } + } + + // Resizes content and counts natural widget height for the desired width. + virtual int resizeGetHeight(int newWidth) { + return heightNoMargins(); + } + + virtual void visibleTopBottomUpdated( + int visibleTop, + int visibleBottom) { + } + +}; + +namespace Ui { class RpWidget; -template -inline base::unique_qptr CreateObject(Args &&...args) { - return base::make_unique_q( - nullptr, - std::forward(args)...); -} - -template -inline Value *CreateChild( - Parent *parent, - Args &&...args) { - Expects(parent != nullptr); - - if constexpr (std::is_base_of_v) { - return new Value(parent, std::forward(args)...); - } else { - return CreateChild>( - parent, - details::InPlaceTag{}, - std::forward(args)...)->value(); - } -} - -inline void DestroyChild(QWidget *child) { - delete child; -} - -template -inline auto Connect(Args &&...args) { - return QObject::connect(std::forward(args)...); -} - -void ResizeFitChild( - not_null parent, - not_null child); - -template -inline not_null*> AttachAsChild( - not_null parent, - Value &&value) { - return CreateChild>>( - parent.get(), - details::ForwardTag{}, - std::forward(value))->value(); -} +void ResizeFitChild(not_null parent, not_null child); template using RpWidgetParent = std::conditional_t< diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index 425ac9263..17f0c7fb5 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/radial_animation.h" #include "ui/image/image_prepare.h" #include "ui/empty_userpic.h" +#include "ui/ui_utility.h" #include "data/data_photo.h" #include "data/data_session.h" #include "data/data_folder.h" diff --git a/Telegram/SourceFiles/ui/style/style_core.h b/Telegram/SourceFiles/ui/style/style_core.h index 90b8ae686..506376f27 100644 --- a/Telegram/SourceFiles/ui/style/style_core.h +++ b/Telegram/SourceFiles/ui/style/style_core.h @@ -9,13 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/style/style_core_scale.h" #include "ui/style/style_core_types.h" - -inline QRect centerrect(const QRect &inRect, const QRect &rect) { - return QRect(inRect.x() + (inRect.width() - rect.width()) / 2, inRect.y() + (inRect.height() - rect.height()) / 2, rect.width(), rect.height()); -} -inline QRect centerrect(const QRect &inRect, const style::icon &icon) { - return centerrect(inRect, QRect(0, 0, icon.width(), icon.height())); -} +#include "ui/style/style_core_direction.h" namespace style { namespace internal { @@ -40,9 +34,6 @@ void EnsureContrast(ColorData &over, const ColorData &under); } // namespace internal -[[nodiscard]] bool RightToLeft(); -void SetRightToLeft(bool rtl); - void startManager(int scale); void stopManager(); diff --git a/Telegram/SourceFiles/ui/style/style_core_direction.h b/Telegram/SourceFiles/ui/style/style_core_direction.h new file mode 100644 index 000000000..2cf6620ff --- /dev/null +++ b/Telegram/SourceFiles/ui/style/style_core_direction.h @@ -0,0 +1,60 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "ui/style/style_core_types.h" + +#include +#include + +namespace style { + +[[nodiscard]] bool RightToLeft(); +void SetRightToLeft(bool rtl); + +inline QRect centerrect(const QRect &inRect, const QRect &rect) { + return QRect( + inRect.x() + (inRect.width() - rect.width()) / 2, + inRect.y() + (inRect.height() - rect.height()) / 2, + rect.width(), + rect.height()); +} + +inline QRect centerrect(const QRect &inRect, const style::icon &icon) { + return centerrect(inRect, QRect(0, 0, icon.width(), icon.height())); +} + +inline QPoint rtlpoint(int x, int y, int outerw) { + return QPoint(RightToLeft() ? (outerw - x) : x, y); +} + +inline QPoint rtlpoint(const QPoint &p, int outerw) { + return RightToLeft() ? QPoint(outerw - p.x(), p.y()) : p; +} + +inline QPointF rtlpoint(const QPointF &p, int outerw) { + return RightToLeft() ? QPointF(outerw - p.x(), p.y()) : p; +} + +inline QRect rtlrect(int x, int y, int w, int h, int outerw) { + return QRect(RightToLeft() ? (outerw - x - w) : x, y, w, h); +} + +inline QRect rtlrect(const QRect &r, int outerw) { + return RightToLeft() + ? QRect(outerw - r.x() - r.width(), r.y(), r.width(), r.height()) + : r; +} + +inline QRectF rtlrect(const QRectF &r, int outerw) { + return RightToLeft() + ? QRectF(outerw - r.x() - r.width(), r.y(), r.width(), r.height()) + : r; +} + +} // namespace style diff --git a/Telegram/SourceFiles/ui/style/style_core_font.cpp b/Telegram/SourceFiles/ui/style/style_core_font.cpp index 84c50c38c..e3c1c51f2 100644 --- a/Telegram/SourceFiles/ui/style/style_core_font.cpp +++ b/Telegram/SourceFiles/ui/style/style_core_font.cpp @@ -78,7 +78,7 @@ QString OpenSansSemiboldOverride; } // namespace -void Start() { +void StartFonts() { if (Started) { return; } diff --git a/Telegram/SourceFiles/ui/text/text.cpp b/Telegram/SourceFiles/ui/text/text.cpp index 9a1dc5ae1..cc58fc4b2 100644 --- a/Telegram/SourceFiles/ui/text/text.cpp +++ b/Telegram/SourceFiles/ui/text/text.cpp @@ -3099,10 +3099,18 @@ StateResult String::getState(QPoint point, int width, StateRequest request) cons return Renderer(nullptr, this).getState(point, width, request); } +StateResult String::getStateLeft(QPoint point, int width, int outerw, StateRequest request) const { + return getState(style::rtlpoint(point, outerw), width, request); +} + StateResult String::getStateElided(QPoint point, int width, StateRequestElided request) const { return Renderer(nullptr, this).getStateElided(point, width, request); } +StateResult String::getStateElidedLeft(QPoint point, int width, int outerw, StateRequestElided request) const { + return getStateElided(style::rtlpoint(point, outerw), width, request); +} + TextSelection String::adjustSelection(TextSelection selection, TextSelectType selectType) const { uint16 from = selection.from, to = selection.to; if (from < _text.size() && from <= to) { diff --git a/Telegram/SourceFiles/ui/text/text.h b/Telegram/SourceFiles/ui/text/text.h index 0df838338..53e9dd0dd 100644 --- a/Telegram/SourceFiles/ui/text/text.h +++ b/Telegram/SourceFiles/ui/text/text.h @@ -152,13 +152,9 @@ public: } StateResult getState(QPoint point, int width, StateRequest request = StateRequest()) const; - StateResult getStateLeft(QPoint point, int width, int outerw, StateRequest request = StateRequest()) const { - return getState(rtlpoint(point, outerw), width, request); - } + StateResult getStateLeft(QPoint point, int width, int outerw, StateRequest request = StateRequest()) const; StateResult getStateElided(QPoint point, int width, StateRequestElided request = StateRequestElided()) const; - StateResult getStateElidedLeft(QPoint point, int width, int outerw, StateRequestElided request = StateRequestElided()) const { - return getStateElided(rtlpoint(point, outerw), width, request); - } + StateResult getStateElidedLeft(QPoint point, int width, int outerw, StateRequestElided request = StateRequestElided()) const; [[nodiscard]] TextSelection adjustSelection(TextSelection selection, TextSelectType selectType) const; bool isFullSelection(TextSelection selection) const { diff --git a/Telegram/SourceFiles/ui/toast/toast_widget.h b/Telegram/SourceFiles/ui/toast/toast_widget.h index 9879ab780..d4c16619c 100644 --- a/Telegram/SourceFiles/ui/toast/toast_widget.h +++ b/Telegram/SourceFiles/ui/toast/toast_widget.h @@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/toast/toast.h" -#include "ui/twidget.h" +#include "ui/rp_widget.h" #include "ui/text/text.h" namespace Ui { diff --git a/Telegram/SourceFiles/ui/twidget.h b/Telegram/SourceFiles/ui/twidget.h deleted file mode 100644 index fbf11c4d6..000000000 --- a/Telegram/SourceFiles/ui/twidget.h +++ /dev/null @@ -1,540 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -#include "base/flags.h" - -class TWidget; - -template -class object_ptr; - -inline QPoint rtlpoint(int x, int y, int outerw) { - return QPoint(rtl() ? (outerw - x) : x, y); -} -inline QPoint rtlpoint(const QPoint &p, int outerw) { - return rtl() ? QPoint(outerw - p.x(), p.y()) : p; -} -inline QPointF rtlpoint(const QPointF &p, int outerw) { - return rtl() ? QPointF(outerw - p.x(), p.y()) : p; -} -inline QRect rtlrect(int x, int y, int w, int h, int outerw) { - return QRect(rtl() ? (outerw - x - w) : x, y, w, h); -} -inline QRect rtlrect(const QRect &r, int outerw) { - return rtl() ? QRect(outerw - r.x() - r.width(), r.y(), r.width(), r.height()) : r; -} -inline QRectF rtlrect(const QRectF &r, int outerw) { - return rtl() ? QRectF(outerw - r.x() - r.width(), r.y(), r.width(), r.height()) : r; -} - -namespace Ui { - -inline bool InFocusChain(not_null widget) { - if (auto top = widget->window()) { - if (auto focused = top->focusWidget()) { - return !widget->isHidden() - && (focused == widget - || widget->isAncestorOf(focused)); - } - } - return false; -} - -template -inline ChildWidget *AttachParentChild( - not_null parent, - const object_ptr &child) { - if (auto raw = child.data()) { - raw->setParent(parent); - raw->show(); - return raw; - } - return nullptr; -} - -void SendPendingMoveResizeEvents(not_null target); - -QPixmap GrabWidget( - not_null target, - QRect rect = QRect(), - QColor bg = QColor(255, 255, 255, 0)); -QImage GrabWidgetToImage( - not_null target, - QRect rect = QRect(), - QColor bg = QColor(255, 255, 255, 0)); - -void RenderWidget( - QPainter &painter, - not_null source, - const QPoint &targetOffset = QPoint(), - const QRegion &sourceRegion = QRegion(), - QWidget::RenderFlags renderFlags - = QWidget::DrawChildren | QWidget::IgnoreMask); - - -void ForceFullRepaint(not_null widget); - -void PostponeCall(FnMut &&callable); - -template < - typename Guard, - typename Callable, - typename GuardTraits = crl::guard_traits>, - typename = std::enable_if_t< - sizeof(GuardTraits) != crl::details::dependent_zero>> -inline void PostponeCall(Guard &&object, Callable &&callable) { - return PostponeCall(crl::guard( - std::forward(object), - std::forward(callable))); -} - -} // namespace Ui - -enum class RectPart { - None = 0, - - TopLeft = (1 << 0), - Top = (1 << 1), - TopRight = (1 << 2), - Left = (1 << 3), - Center = (1 << 4), - Right = (1 << 5), - BottomLeft = (1 << 6), - Bottom = (1 << 7), - BottomRight = (1 << 8), - - FullTop = TopLeft | Top | TopRight, - NoTopBottom = Left | Center | Right, - FullBottom = BottomLeft | Bottom | BottomRight, - NoTop = NoTopBottom | FullBottom, - NoBottom = FullTop | NoTopBottom, - - FullLeft = TopLeft | Left | BottomLeft, - NoLeftRight = Top | Center | Bottom, - FullRight = TopRight | Right | BottomRight, - NoLeft = NoLeftRight | FullRight, - NoRight = FullLeft | NoLeftRight, - - AllCorners = TopLeft | TopRight | BottomLeft | BottomRight, - AllSides = Top | Bottom | Left | Right, - - Full = FullTop | NoTop, -}; -using RectParts = base::flags; -inline constexpr auto is_flag_type(RectPart) { return true; }; - -inline bool IsTopCorner(RectPart corner) { - return (corner == RectPart::TopLeft) || (corner == RectPart::TopRight); -} - -inline bool IsBottomCorner(RectPart corner) { - return (corner == RectPart::BottomLeft) || (corner == RectPart::BottomRight); -} - -inline bool IsLeftCorner(RectPart corner) { - return (corner == RectPart::TopLeft) || (corner == RectPart::BottomLeft); -} - -inline bool IsRightCorner(RectPart corner) { - return (corner == RectPart::TopRight) || (corner == RectPart::BottomRight); -} - -template -class TWidgetHelper : public Base { -public: - using Base::Base; - - virtual QMargins getMargins() const { - return QMargins(); - } - - bool inFocusChain() const { - return Ui::InFocusChain(this); - } - - void hideChildren() { - for (auto child : Base::children()) { - if (child->isWidgetType()) { - static_cast(child)->hide(); - } - } - } - void showChildren() { - for (auto child : Base::children()) { - if (child->isWidgetType()) { - static_cast(child)->show(); - } - } - } - - void moveToLeft(int x, int y, int outerw = 0) { - auto margins = getMargins(); - x -= margins.left(); - y -= margins.top(); - Base::move(rtl() ? ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - Base::width()) : x, y); - } - void moveToRight(int x, int y, int outerw = 0) { - auto margins = getMargins(); - x -= margins.right(); - y -= margins.top(); - Base::move(rtl() ? x : ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - Base::width()), y); - } - void setGeometryToLeft(int x, int y, int w, int h, int outerw = 0) { - auto margins = getMargins(); - x -= margins.left(); - y -= margins.top(); - w -= margins.left() - margins.right(); - h -= margins.top() - margins.bottom(); - Base::setGeometry(rtl() ? ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - w) : x, y, w, h); - } - void setGeometryToRight(int x, int y, int w, int h, int outerw = 0) { - auto margins = getMargins(); - x -= margins.right(); - y -= margins.top(); - w -= margins.left() - margins.right(); - h -= margins.top() - margins.bottom(); - Base::setGeometry(rtl() ? x : ((outerw > 0 ? outerw : Base::parentWidget()->width()) - x - w), y, w, h); - } - QPoint myrtlpoint(int x, int y) const { - return rtlpoint(x, y, Base::width()); - } - QPoint myrtlpoint(const QPoint point) const { - return rtlpoint(point, Base::width()); - } - QRect myrtlrect(int x, int y, int w, int h) const { - return rtlrect(x, y, w, h, Base::width()); - } - QRect myrtlrect(const QRect &rect) const { - return rtlrect(rect, Base::width()); - } - void rtlupdate(const QRect &rect) { - Base::update(myrtlrect(rect)); - } - void rtlupdate(int x, int y, int w, int h) { - Base::update(myrtlrect(x, y, w, h)); - } - - QPoint mapFromGlobal(const QPoint &point) const { - return Base::mapFromGlobal(point); - } - QPoint mapToGlobal(const QPoint &point) const { - return Base::mapToGlobal(point); - } - QRect mapFromGlobal(const QRect &rect) const { - return QRect(mapFromGlobal(rect.topLeft()), rect.size()); - } - QRect mapToGlobal(const QRect &rect) const { - return QRect(mapToGlobal(rect.topLeft()), rect.size()); - } - -protected: - void enterEvent(QEvent *e) final override { - if (auto parent = tparent()) { - parent->leaveToChildEvent(e, this); - } - return enterEventHook(e); - } - virtual void enterEventHook(QEvent *e) { - return Base::enterEvent(e); - } - - void leaveEvent(QEvent *e) final override { - if (auto parent = tparent()) { - parent->enterFromChildEvent(e, this); - } - return leaveEventHook(e); - } - virtual void leaveEventHook(QEvent *e) { - return Base::leaveEvent(e); - } - - // e - from enterEvent() of child TWidget - virtual void leaveToChildEvent(QEvent *e, QWidget *child) { - } - - // e - from leaveEvent() of child TWidget - virtual void enterFromChildEvent(QEvent *e, QWidget *child) { - } - -private: - TWidget *tparent() { - return qobject_cast(Base::parentWidget()); - } - const TWidget *tparent() const { - return qobject_cast(Base::parentWidget()); - } - - template - friend class TWidgetHelper; - -}; - -class TWidget : public TWidgetHelper { - // The Q_OBJECT meta info is used for qobject_cast! - Q_OBJECT - -public: - TWidget(QWidget *parent = nullptr) : TWidgetHelper(parent) { - } - - // Get the size of the widget as it should be. - // Negative return value means no default width. - virtual int naturalWidth() const { - return -1; - } - - // Count new height for width=newWidth and resize to it. - void resizeToWidth(int newWidth) { - auto margins = getMargins(); - auto fullWidth = margins.left() + newWidth + margins.right(); - auto fullHeight = margins.top() + resizeGetHeight(newWidth) + margins.bottom(); - auto newSize = QSize(fullWidth, fullHeight); - if (newSize != size()) { - resize(newSize); - update(); - } - } - - // Resize to minimum of natural width and available width. - void resizeToNaturalWidth(int newWidth) { - auto maxWidth = naturalWidth(); - resizeToWidth((maxWidth >= 0) ? qMin(newWidth, maxWidth) : newWidth); - } - - QRect rectNoMargins() const { - return rect().marginsRemoved(getMargins()); - } - - int widthNoMargins() const { - return rectNoMargins().width(); - } - - int heightNoMargins() const { - return rectNoMargins().height(); - } - - int bottomNoMargins() const { - auto rectWithoutMargins = rectNoMargins(); - return y() + rectWithoutMargins.y() + rectWithoutMargins.height(); - } - - QSize sizeNoMargins() const { - return rectNoMargins().size(); - } - - // Updates the area that is visible inside the scroll container. - void setVisibleTopBottom(int visibleTop, int visibleBottom) { - auto max = height(); - visibleTopBottomUpdated( - snap(visibleTop, 0, max), - snap(visibleBottom, 0, max)); - } - -signals: - // Child widget is responsible for emitting this signal. - void heightUpdated(); - -protected: - void setChildVisibleTopBottom( - TWidget *child, - int visibleTop, - int visibleBottom) { - if (child) { - auto top = child->y(); - child->setVisibleTopBottom( - visibleTop - top, - visibleBottom - top); - } - } - - // Resizes content and counts natural widget height for the desired width. - virtual int resizeGetHeight(int newWidth) { - return heightNoMargins(); - } - - virtual void visibleTopBottomUpdated( - int visibleTop, - int visibleBottom) { - } - -}; - -template -QPointer make_weak(Widget *object) { - return QPointer(object); -} - -template -QPointer make_weak(const Widget *object) { - return QPointer(object); -} - -template -QPointer make_weak(not_null object) { - return QPointer(object.get()); -} - -template -QPointer make_weak(not_null object) { - return QPointer(object.get()); -} - -class SingleQueuedInvokation : public QObject { -public: - SingleQueuedInvokation(Fn callback) : _callback(callback) { - } - void call() { - if (_pending.testAndSetAcquire(0, 1)) { - InvokeQueued(this, [this] { - if (_pending.testAndSetRelease(1, 0)) { - _callback(); - } - }); - } - } - -private: - Fn _callback; - QAtomicInt _pending = { 0 }; - -}; - -// Smart pointer for QObject*, has move semantics, destroys object if it doesn't have a parent. -template -class object_ptr { -public: - object_ptr(std::nullptr_t) noexcept { - } - - // No default constructor, but constructors with at least - // one argument are simply make functions. - template - explicit object_ptr(Parent &&parent, Args&&... args) - : _object(new Object(std::forward(parent), std::forward(args)...)) { - } - static object_ptr fromRaw(Object *value) noexcept { - object_ptr result = { nullptr }; - result._object = value; - return result; - } - - object_ptr(const object_ptr &other) = delete; - object_ptr &operator=(const object_ptr &other) = delete; - object_ptr(object_ptr &&other) noexcept : _object(base::take(other._object)) { - } - object_ptr &operator=(object_ptr &&other) noexcept { - auto temp = std::move(other); - destroy(); - std::swap(_object, temp._object); - return *this; - } - - template < - typename OtherObject, - typename = std::enable_if_t< - std::is_base_of_v>> - object_ptr(object_ptr &&other) noexcept - : _object(base::take(other._object)) { - } - - template < - typename OtherObject, - typename = std::enable_if_t< - std::is_base_of_v>> - object_ptr &operator=(object_ptr &&other) noexcept { - _object = base::take(other._object); - return *this; - } - - object_ptr &operator=(std::nullptr_t) noexcept { - _object = nullptr; - return *this; - } - - // So we can pass this pointer to methods like connect(). - Object *data() const noexcept { - return static_cast(_object.data()); - } - operator Object*() const noexcept { - return data(); - } - - explicit operator bool() const noexcept { - return _object != nullptr; - } - - Object *operator->() const noexcept { - return data(); - } - Object &operator*() const noexcept { - return *data(); - } - - // Use that instead "= new Object(parent, ...)" - template - Object *create(Parent &&parent, Args&&... args) { - destroy(); - _object = new Object( - std::forward(parent), - std::forward(args)...); - return data(); - } - void destroy() noexcept { - delete base::take(_object); - } - void destroyDelayed() { - if (_object) { - if (auto widget = base::up_cast(data())) { - widget->hide(); - } - base::take(_object)->deleteLater(); - } - } - - ~object_ptr() noexcept { - if (auto pointer = _object) { - if (!pointer->parent()) { - destroy(); - } - } - } - - template - friend object_ptr static_object_cast( - object_ptr source); - -private: - template - friend class object_ptr; - - QPointer _object; - -}; - -template -inline object_ptr static_object_cast( - object_ptr source) { - auto result = object_ptr(nullptr); - result._object = static_cast( - base::take(source._object).data()); - return std::move(result); -} - -void sendSynteticMouseEvent( - QWidget *widget, - QEvent::Type type, - Qt::MouseButton button, - const QPoint &globalPoint); - -inline void sendSynteticMouseEvent( - QWidget *widget, - QEvent::Type type, - Qt::MouseButton button) { - return sendSynteticMouseEvent(widget, type, button, QCursor::pos()); -} diff --git a/Telegram/SourceFiles/ui/twidget.cpp b/Telegram/SourceFiles/ui/ui_utility.cpp similarity index 90% rename from Telegram/SourceFiles/ui/twidget.cpp rename to Telegram/SourceFiles/ui/ui_utility.cpp index 2884845b9..5947332da 100644 --- a/Telegram/SourceFiles/ui/twidget.cpp +++ b/Telegram/SourceFiles/ui/ui_utility.cpp @@ -5,11 +5,7 @@ the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ -#include "twidget.h" - -#include "mainwindow.h" -#include "core/application.h" -#include "platform/platform_info.h" +#include "ui/ui_utility.h" #include #include @@ -31,8 +27,10 @@ void CreateWidgetStateRecursive(not_null target) { if (!target->isWindow()) { CreateWidgetStateRecursive(target->parentWidget()); WidgetCreator::Create(target); - } else if (!Platform::IsMac() || Platform::IsMac10_7OrGreater()) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + } else { WidgetCreator::Create(target); +#endif // Qt >= 5.6 } } } @@ -150,15 +148,9 @@ void ForceFullRepaint(not_null widget) { refresher->show(); } -void PostponeCall(FnMut &&callable) { - Core::App().postponeCall(std::move(callable)); -} - -} // namespace Ui - -void sendSynteticMouseEvent(QWidget *widget, QEvent::Type type, Qt::MouseButton button, const QPoint &globalPoint) { - if (auto windowHandle = widget->window()->windowHandle()) { - auto localPoint = windowHandle->mapFromGlobal(globalPoint); +void SendSynteticMouseEvent(QWidget *widget, QEvent::Type type, Qt::MouseButton button, const QPoint &globalPoint) { + if (const auto windowHandle = widget->window()->windowHandle()) { + const auto localPoint = windowHandle->mapFromGlobal(globalPoint); QMouseEvent ev(type , localPoint , localPoint @@ -174,3 +166,5 @@ void sendSynteticMouseEvent(QWidget *widget, QEvent::Type type, Qt::MouseButton QGuiApplication::sendEvent(windowHandle, &ev); } } + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/ui_utility.h b/Telegram/SourceFiles/ui/ui_utility.h new file mode 100644 index 000000000..c1c613de3 --- /dev/null +++ b/Telegram/SourceFiles/ui/ui_utility.h @@ -0,0 +1,185 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +#include "base/unique_qptr.h" + +template +class object_ptr; + +namespace Ui { +namespace details { + +struct ForwardTag { +}; + +struct InPlaceTag { +}; + +template +class AttachmentOwner : public QObject { +public: + template + AttachmentOwner(QObject *parent, const ForwardTag&, OtherValue &&value) + : QObject(parent) + , _value(std::forward(value)) { + } + + template + AttachmentOwner(QObject *parent, const InPlaceTag&, Args &&...args) + : QObject(parent) + , _value(std::forward(args)...) { + } + + not_null value() { + return &_value; + } + +private: + Value _value; + +}; + +} // namespace details + +template +inline base::unique_qptr CreateObject(Args &&...args) { + return base::make_unique_q( + nullptr, + std::forward(args)...); +} + +template +inline Value *CreateChild( + Parent *parent, + Args &&...args) { + Expects(parent != nullptr); + + if constexpr (std::is_base_of_v) { + return new Value(parent, std::forward(args)...); + } else { + return CreateChild>( + parent, + details::InPlaceTag{}, + std::forward(args)...)->value(); + } +} + +inline void DestroyChild(QWidget *child) { + delete child; +} + +template +inline auto Connect(Args &&...args) { + return QObject::connect(std::forward(args)...); +} + +template +inline not_null*> AttachAsChild( + not_null parent, + Value &&value) { + return CreateChild>>( + parent.get(), + details::ForwardTag{}, + std::forward(value))->value(); +} + +[[nodiscard]] inline bool InFocusChain(not_null widget) { + if (const auto top = widget->window()) { + if (auto focused = top->focusWidget()) { + return !widget->isHidden() + && (focused == widget + || widget->isAncestorOf(focused)); + } + } + return false; +} + +template +inline ChildWidget *AttachParentChild( + not_null parent, + const object_ptr &child) { + if (const auto raw = child.data()) { + raw->setParent(parent); + raw->show(); + return raw; + } + return nullptr; +} + +void SendPendingMoveResizeEvents(not_null target); + +[[nodiscard]] QPixmap GrabWidget( + not_null target, + QRect rect = QRect(), + QColor bg = QColor(255, 255, 255, 0)); + +[[nodiscard]] QImage GrabWidgetToImage( + not_null target, + QRect rect = QRect(), + QColor bg = QColor(255, 255, 255, 0)); + +void RenderWidget( + QPainter &painter, + not_null source, + const QPoint &targetOffset = QPoint(), + const QRegion &sourceRegion = QRegion(), + QWidget::RenderFlags renderFlags + = QWidget::DrawChildren | QWidget::IgnoreMask); + +void ForceFullRepaint(not_null widget); + +// Must be implemented outside lib_ui. +void PostponeCall(FnMut &&callable); + +template < + typename Guard, + typename Callable, + typename GuardTraits = crl::guard_traits>, + typename = std::enable_if_t< + sizeof(GuardTraits) != crl::details::dependent_zero>> +inline void PostponeCall(Guard && object, Callable && callable) { + return PostponeCall(crl::guard( + std::forward(object), + std::forward(callable))); +} + +void SendSynteticMouseEvent( + QWidget *widget, + QEvent::Type type, + Qt::MouseButton button, + const QPoint &globalPoint); + +inline void SendSynteticMouseEvent( + QWidget *widget, + QEvent::Type type, + Qt::MouseButton button) { + return SendSynteticMouseEvent(widget, type, button, QCursor::pos()); +} + +template +QPointer MakeWeak(Widget *object) { + return QPointer(object); +} + +template +QPointer MakeWeak(const Widget *object) { + return QPointer(object); +} + +template +QPointer MakeWeak(not_null object) { + return QPointer(object.get()); +} + +template +QPointer MakeWeak(not_null object) { + return QPointer(object.get()); +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/widgets/buttons.cpp b/Telegram/SourceFiles/ui/widgets/buttons.cpp index df9a252b6..440651159 100644 --- a/Telegram/SourceFiles/ui/widgets/buttons.cpp +++ b/Telegram/SourceFiles/ui/widgets/buttons.cpp @@ -398,7 +398,7 @@ void RoundButton::paintEvent(QPaintEvent *e) { QImage RoundButton::prepareRippleMask() const { auto innerWidth = contentWidth(); - auto rounded = rtlrect(rect().marginsRemoved(_st.padding), width()); + auto rounded = style::rtlrect(rect().marginsRemoved(_st.padding), width()); if (_fullWidthOverride < 0) { rounded = QRect(0, rounded.top(), innerWidth - _fullWidthOverride, rounded.height()); } diff --git a/Telegram/SourceFiles/ui/widgets/checkbox.cpp b/Telegram/SourceFiles/ui/widgets/checkbox.cpp index b6521fd8e..e53ed4bf6 100644 --- a/Telegram/SourceFiles/ui/widgets/checkbox.cpp +++ b/Telegram/SourceFiles/ui/widgets/checkbox.cpp @@ -105,8 +105,8 @@ void ToggleView::paint(Painter &p, int left, int top, int outerWidth) { auto innerDiameter = _st->diameter - 2 * _st->shift; auto innerRadius = float64(innerDiameter) / 2.; auto toggleLeft = left + anim::interpolate(0, fullWidth - _st->diameter, toggled); - auto bgRect = rtlrect(left + _st->shift, top + _st->shift, fullWidth - 2 * _st->shift, innerDiameter, outerWidth); - auto fgRect = rtlrect(toggleLeft, top, _st->diameter, _st->diameter, outerWidth); + auto bgRect = style::rtlrect(left + _st->shift, top + _st->shift, fullWidth - 2 * _st->shift, innerDiameter, outerWidth); + auto fgRect = style::rtlrect(toggleLeft, top, _st->diameter, _st->diameter, outerWidth); auto fgBrush = anim::brush(_st->untoggledFg, _st->toggledFg, toggled); p.setPen(Qt::NoPen); @@ -157,7 +157,7 @@ void ToggleView::paintXV(Painter &p, int left, int top, int outerWidth, float64 { xLeft + (xSize / 2.) - stroke, xTop + (xSize / 2.) }, }; for (auto &point : pathX) { - point = rtlpoint(point, outerWidth); + point = style::rtlpoint(point, outerWidth); } if (toggled > 0) { // X->V. @@ -180,7 +180,7 @@ void ToggleView::paintXV(Painter &p, int left, int top, int outerWidth, float64 { vLeft + vSize - 2 * stroke, vTop + xSize - stroke }, }; for (auto &point : pathV) { - point = rtlpoint(point, outerWidth); + point = style::rtlpoint(point, outerWidth); } p.fillPath(anim::interpolate(pathX, pathV, toggled), brush); } else { @@ -262,7 +262,7 @@ void CheckView::paint(Painter &p, int left, int top, int outerWidth) { { PainterHighQualityEnabler hq(p); - p.drawRoundedRect(rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(_st->thickness / 2., _st->thickness / 2., _st->thickness / 2., _st->thickness / 2.)), outerWidth), st::buttonRadius - (_st->thickness / 2.), st::buttonRadius - (_st->thickness / 2.)); + p.drawRoundedRect(style::rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(_st->thickness / 2., _st->thickness / 2., _st->thickness / 2., _st->thickness / 2.)), outerWidth), st::buttonRadius - (_st->thickness / 2.), st::buttonRadius - (_st->thickness / 2.)); } if (toggled > 0) { @@ -320,7 +320,7 @@ void RadioView::paint(Painter &p, int left, int top, int outerWidth) { p.setBrush(_st->bg); //int32 skip = qCeil(_st->thickness / 2.); //p.drawEllipse(_checkRect.marginsRemoved(QMargins(skip, skip, skip, skip))); - p.drawEllipse(rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(_st->thickness / 2., _st->thickness / 2., _st->thickness / 2., _st->thickness / 2.)), outerWidth)); + p.drawEllipse(style::rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(_st->thickness / 2., _st->thickness / 2., _st->thickness / 2., _st->thickness / 2.)), outerWidth)); if (toggled > 0) { p.setPen(Qt::NoPen); @@ -333,7 +333,7 @@ void RadioView::paint(Painter &p, int left, int top, int outerWidth) { : anim::brush(_st->untoggledFg, _st->toggledFg, toggled))); auto skip0 = _st->diameter / 2., skip1 = _st->skip / 10., checkSkip = skip0 * (1. - toggled) + skip1 * toggled; - p.drawEllipse(rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(checkSkip, checkSkip, checkSkip, checkSkip)), outerWidth)); + p.drawEllipse(style::rtlrect(QRectF(left, top, _st->diameter, _st->diameter).marginsRemoved(QMarginsF(checkSkip, checkSkip, checkSkip, checkSkip)), outerWidth)); //int32 fskip = qFloor(checkSkip), cskip = qCeil(checkSkip); //if (2 * fskip < _checkRect.width()) { // if (fskip != cskip) { diff --git a/Telegram/SourceFiles/ui/widgets/inner_dropdown.cpp b/Telegram/SourceFiles/ui/widgets/inner_dropdown.cpp index e9d2d8035..5848d6e9f 100644 --- a/Telegram/SourceFiles/ui/widgets/inner_dropdown.cpp +++ b/Telegram/SourceFiles/ui/widgets/inner_dropdown.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/shadow.h" #include "ui/effects/panel_animation.h" #include "ui/image/image_prepare.h" +#include "ui/ui_utility.h" #include "app.h" namespace { diff --git a/Telegram/SourceFiles/ui/widgets/inner_dropdown.h b/Telegram/SourceFiles/ui/widgets/inner_dropdown.h index a081b5a58..e57d29d21 100644 --- a/Telegram/SourceFiles/ui/widgets/inner_dropdown.h +++ b/Telegram/SourceFiles/ui/widgets/inner_dropdown.h @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rp_widget.h" #include "ui/effects/animations.h" #include "ui/effects/panel_animation.h" +#include "base/object_ptr.h" #include diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index 9522abad1..f0d168535 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/popup_menu.h" #include "ui/countryinput.h" #include "ui/emoji_config.h" +#include "ui/ui_utility.h" #include "chat_helpers/emoji_suggestions_helper.h" #include "chat_helpers/message_field.h" // ConvertTextTagsToEntities #include "platform/platform_info.h" @@ -1044,7 +1045,7 @@ void FlatInput::touchEvent(QTouchEvent *e) { case QEvent::TouchEnd: { if (!_touchPress) return; - auto weak = make_weak(this); + auto weak = MakeWeak(this); if (!_touchMove && window()) { Qt::MouseButton btn(_touchRightButton ? Qt::RightButton : Qt::LeftButton); QPoint mapped(mapFromGlobal(_touchStart)), winMapped(window()->mapFromGlobal(_touchStart)); @@ -1645,7 +1646,7 @@ void InputField::handleTouchEvent(QTouchEvent *e) { case QEvent::TouchEnd: { if (!_touchPress) return; - auto weak = make_weak(this); + auto weak = MakeWeak(this); if (!_touchMove && window()) { Qt::MouseButton btn(_touchRightButton ? Qt::RightButton : Qt::LeftButton); QPoint mapped(mapFromGlobal(_touchStart)), winMapped(window()->mapFromGlobal(_touchStart)); @@ -2315,7 +2316,7 @@ void InputField::handleContentsChanged() { if (tagsChanged || (_lastTextWithTags.text != currentText)) { _lastTextWithTags.text = currentText; - const auto weak = make_weak(this); + const auto weak = MakeWeak(this); emit changed(); if (!weak) { return; @@ -3697,7 +3698,7 @@ void MaskedInputField::touchEvent(QTouchEvent *e) { case QEvent::TouchEnd: { if (!_touchPress) return; - auto weak = make_weak(this); + auto weak = MakeWeak(this); if (!_touchMove && window()) { Qt::MouseButton btn(_touchRightButton ? Qt::RightButton : Qt::LeftButton); QPoint mapped(mapFromGlobal(_touchStart)), winMapped(window()->mapFromGlobal(_touchStart)); diff --git a/Telegram/SourceFiles/ui/widgets/labels.cpp b/Telegram/SourceFiles/ui/widgets/labels.cpp index 691c318e3..5b0dd8de8 100644 --- a/Telegram/SourceFiles/ui/widgets/labels.cpp +++ b/Telegram/SourceFiles/ui/widgets/labels.cpp @@ -536,7 +536,7 @@ void FlatLabel::touchEvent(QTouchEvent *e) { case QEvent::TouchEnd: { if (!_touchInProgress) return; _touchInProgress = false; - auto weak = make_weak(this); + auto weak = MakeWeak(this); if (_touchSelect) { dragActionFinish(_touchPos, Qt::RightButton); QContextMenuEvent contextMenu(QContextMenuEvent::Mouse, mapFromGlobal(_touchPos), _touchPos); diff --git a/Telegram/SourceFiles/ui/widgets/menu.h b/Telegram/SourceFiles/ui/widgets/menu.h index a91f3ac00..aa845547f 100644 --- a/Telegram/SourceFiles/ui/widgets/menu.h +++ b/Telegram/SourceFiles/ui/widgets/menu.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/rp_widget.h" #include "styles/style_widgets.h" #include diff --git a/Telegram/SourceFiles/ui/widgets/multi_select.cpp b/Telegram/SourceFiles/ui/widgets/multi_select.cpp index 4b6b23a6b..17ceb2f7c 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.cpp +++ b/Telegram/SourceFiles/ui/widgets/multi_select.cpp @@ -72,7 +72,7 @@ void MultiSelect::Item::paintOnce(Painter &p, int x, int y, int outerWidth) { } auto radius = _st.height / 2; - auto inner = rtlrect(x + radius, y, _width - radius, _st.height, outerWidth); + auto inner = style::rtlrect(x + radius, y, _width - radius, _st.height, outerWidth); auto clipEnabled = p.hasClipping(); auto clip = clipEnabled ? p.clipRegion() : QRegion(); @@ -82,7 +82,7 @@ void MultiSelect::Item::paintOnce(Painter &p, int x, int y, int outerWidth) { p.setBrush(_active ? _st.textActiveBg : _st.textBg); { PainterHighQualityEnabler hq(p); - p.drawRoundedRect(rtlrect(x, y, _width, _st.height, outerWidth), radius, radius); + p.drawRoundedRect(style::rtlrect(x, y, _width, _st.height, outerWidth), radius, radius); } if (clipEnabled) { @@ -112,7 +112,7 @@ void MultiSelect::Item::paintDeleteButton(Painter &p, int x, int y, int outerWid p.setBrush(_color); { PainterHighQualityEnabler hq(p); - p.drawEllipse(rtlrect(x, y, _st.height, _st.height, outerWidth)); + p.drawEllipse(style::rtlrect(x, y, _st.height, _st.height, outerWidth)); } CrossAnimation::paint(p, _st.deleteCross, _st.deleteFg, x, y, outerWidth, overOpacity); @@ -129,7 +129,7 @@ bool MultiSelect::Item::paintCached(Painter &p, int x, int y, int outerWidth) { auto width = opacity * _cache.width() / _cache.devicePixelRatio(); p.setOpacity(opacity); - p.drawPixmap(rtlrect(x + (_width - width) / 2., y + (_st.height - height) / 2., width, height, outerWidth), _cache); + p.drawPixmap(style::rtlrect(x + (_width - width) / 2., y + (_st.height - height) / 2., width, height, outerWidth), _cache); p.setOpacity(1.); return true; } diff --git a/Telegram/SourceFiles/ui/widgets/multi_select.h b/Telegram/SourceFiles/ui/widgets/multi_select.h index a907553b6..679a4c8f4 100644 --- a/Telegram/SourceFiles/ui/widgets/multi_select.h +++ b/Telegram/SourceFiles/ui/widgets/multi_select.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_widgets.h" #include "ui/rp_widget.h" #include "ui/effects/animations.h" +#include "base/object_ptr.h" namespace Ui { diff --git a/Telegram/SourceFiles/ui/widgets/popup_menu.cpp b/Telegram/SourceFiles/ui/widgets/popup_menu.cpp index 8476c583d..ea7d15175 100644 --- a/Telegram/SourceFiles/ui/widgets/popup_menu.cpp +++ b/Telegram/SourceFiles/ui/widgets/popup_menu.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/shadow.h" #include "ui/image/image_prepare.h" +#include "ui/ui_utility.h" #include "platform/platform_info.h" #include "platform/platform_specific.h" #include "mainwindow.h" diff --git a/Telegram/SourceFiles/ui/widgets/popup_menu.h b/Telegram/SourceFiles/ui/widgets/popup_menu.h index add2722ea..a9f727a7d 100644 --- a/Telegram/SourceFiles/ui/widgets/popup_menu.h +++ b/Telegram/SourceFiles/ui/widgets/popup_menu.h @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/menu.h" #include "ui/effects/animations.h" #include "ui/effects/panel_animation.h" +#include "base/object_ptr.h" namespace Ui { diff --git a/Telegram/SourceFiles/ui/widgets/scroll_area.cpp b/Telegram/SourceFiles/ui/widgets/scroll_area.cpp index beb5814bf..3dcbe270e 100644 --- a/Telegram/SourceFiles/ui/widgets/scroll_area.cpp +++ b/Telegram/SourceFiles/ui/widgets/scroll_area.cpp @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/widgets/scroll_area.h" +#include "ui/ui_utility.h" + #include #include #include @@ -342,7 +344,7 @@ void ScrollArea::onScrolled() { if (em) { emit scrolled(); if (!_movingByScrollBar) { - sendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton); + SendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton); } } } @@ -518,7 +520,7 @@ void ScrollArea::touchEvent(QTouchEvent *e) { case QEvent::TouchEnd: { if (!_touchPress) return; _touchPress = false; - auto weak = make_weak(this); + auto weak = MakeWeak(this); if (_touchScroll) { if (_touchScrollState == TouchScrollState::Manual) { _touchScrollState = TouchScrollState::Auto; @@ -537,9 +539,9 @@ void ScrollArea::touchEvent(QTouchEvent *e) { } else if (window()) { // one short tap -- like left mouse click, one long tap -- like right mouse click Qt::MouseButton btn(_touchRightButton ? Qt::RightButton : Qt::LeftButton); - if (weak) sendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton, _touchStart); - if (weak) sendSynteticMouseEvent(this, QEvent::MouseButtonPress, btn, _touchStart); - if (weak) sendSynteticMouseEvent(this, QEvent::MouseButtonRelease, btn, _touchStart); + if (weak) SendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton, _touchStart); + if (weak) SendSynteticMouseEvent(this, QEvent::MouseButtonPress, btn, _touchStart); + if (weak) SendSynteticMouseEvent(this, QEvent::MouseButtonRelease, btn, _touchStart); if (weak && _touchRightButton) { auto windowHandle = window()->windowHandle(); diff --git a/Telegram/SourceFiles/ui/widgets/scroll_area.h b/Telegram/SourceFiles/ui/widgets/scroll_area.h index f4a33cfda..e82875d40 100644 --- a/Telegram/SourceFiles/ui/widgets/scroll_area.h +++ b/Telegram/SourceFiles/ui/widgets/scroll_area.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rp_widget.h" #include "ui/effects/animations.h" +#include "base/object_ptr.h" #include "styles/style_widgets.h" #include @@ -133,7 +134,8 @@ public: } template object_ptr takeWidget() { - return static_object_cast(doTakeWidget()); + return object_ptr::fromRaw( + static_cast(doTakeWidget().release())); } void rangeChanged(int oldMax, int newMax, bool vertical); diff --git a/Telegram/SourceFiles/ui/widgets/shadow.cpp b/Telegram/SourceFiles/ui/widgets/shadow.cpp index b9d908dd0..2f1ed2682 100644 --- a/Telegram/SourceFiles/ui/widgets/shadow.cpp +++ b/Telegram/SourceFiles/ui/widgets/shadow.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/widgets/shadow.h" +#include "ui/ui_utility.h" #include "styles/style_widgets.h" namespace Ui { @@ -38,7 +39,7 @@ void Shadow::paint(Painter &p, const QRect &box, int outerWidth, const style::Sh to -= st.bottomLeft.height() - st.extend.bottom(); } if (to > from && !st.left.empty()) { - st.left.fill(p, rtlrect(box.x() - st.extend.left(), from, st.left.width(), to - from, outerWidth)); + st.left.fill(p, style::rtlrect(box.x() - st.extend.left(), from, st.left.width(), to - from, outerWidth)); } } if (right) { @@ -53,7 +54,7 @@ void Shadow::paint(Painter &p, const QRect &box, int outerWidth, const style::Sh to -= st.bottomRight.height() - st.extend.bottom(); } if (to > from && !st.right.empty()) { - st.right.fill(p, rtlrect(box.x() + box.width() + st.extend.right() - st.right.width(), from, st.right.width(), to - from, outerWidth)); + st.right.fill(p, style::rtlrect(box.x() + box.width() + st.extend.right() - st.right.width(), from, st.right.width(), to - from, outerWidth)); } } if (top && !st.top.empty()) { @@ -62,7 +63,7 @@ void Shadow::paint(Painter &p, const QRect &box, int outerWidth, const style::Sh if (left && !st.topLeft.empty()) from += st.topLeft.width() - st.extend.left(); if (right && !st.topRight.empty()) to -= st.topRight.width() - st.extend.right(); if (to > from) { - st.top.fill(p, rtlrect(from, box.y() - st.extend.top(), to - from, st.top.height(), outerWidth)); + st.top.fill(p, style::rtlrect(from, box.y() - st.extend.top(), to - from, st.top.height(), outerWidth)); } } if (bottom && !st.bottom.empty()) { @@ -71,7 +72,7 @@ void Shadow::paint(Painter &p, const QRect &box, int outerWidth, const style::Sh if (left && !st.bottomLeft.empty()) from += st.bottomLeft.width() - st.extend.left(); if (right && !st.bottomRight.empty()) to -= st.bottomRight.width() - st.extend.right(); if (to > from) { - st.bottom.fill(p, rtlrect(from, box.y() + box.height() + st.extend.bottom() - st.bottom.height(), to - from, st.bottom.height(), outerWidth)); + st.bottom.fill(p, style::rtlrect(from, box.y() + box.height() + st.extend.bottom() - st.bottom.height(), to - from, st.bottom.height(), outerWidth)); } } } diff --git a/Telegram/SourceFiles/ui/widgets/shadow.h b/Telegram/SourceFiles/ui/widgets/shadow.h index d5a59c779..a33c97075 100644 --- a/Telegram/SourceFiles/ui/widgets/shadow.h +++ b/Telegram/SourceFiles/ui/widgets/shadow.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/rect_part.h" namespace style { struct Shadow; diff --git a/Telegram/SourceFiles/ui/widgets/tooltip.cpp b/Telegram/SourceFiles/ui/widgets/tooltip.cpp index ac6353e63..c12a48181 100644 --- a/Telegram/SourceFiles/ui/widgets/tooltip.cpp +++ b/Telegram/SourceFiles/ui/widgets/tooltip.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "platform/platform_specific.h" #include "core/qt_signal_producer.h" +#include "ui/ui_utility.h" #include "app.h" #include "styles/style_widgets.h" diff --git a/Telegram/SourceFiles/ui/widgets/tooltip.h b/Telegram/SourceFiles/ui/widgets/tooltip.h index 286d4cf49..6bc0e02e2 100644 --- a/Telegram/SourceFiles/ui/widgets/tooltip.h +++ b/Telegram/SourceFiles/ui/widgets/tooltip.h @@ -8,8 +8,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "base/timer.h" +#include "base/object_ptr.h" #include "ui/effects/animations.h" #include "ui/rp_widget.h" +#include "ui/rect_part.h" namespace style { struct Tooltip; diff --git a/Telegram/SourceFiles/ui/wrap/slide_wrap.cpp b/Telegram/SourceFiles/ui/wrap/slide_wrap.cpp index 93e834662..bfc979e55 100644 --- a/Telegram/SourceFiles/ui/wrap/slide_wrap.cpp +++ b/Telegram/SourceFiles/ui/wrap/slide_wrap.cpp @@ -107,7 +107,7 @@ void SlideWrap::animationStep() { } auto shouldBeHidden = !_toggled && !_animation.animating(); if (shouldBeHidden != isHidden()) { - const auto guard = make_weak(this); + const auto guard = MakeWeak(this); setVisible(!shouldBeHidden); if (shouldBeHidden && guard) { SendPendingMoveResizeEvents(this); diff --git a/Telegram/SourceFiles/ui/wrap/vertical_layout.cpp b/Telegram/SourceFiles/ui/wrap/vertical_layout.cpp index bda6e224b..2f946d46c 100644 --- a/Telegram/SourceFiles/ui/wrap/vertical_layout.cpp +++ b/Telegram/SourceFiles/ui/wrap/vertical_layout.cpp @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/wrap/vertical_layout.h" +#include "ui/ui_utility.h" + namespace Ui { QMargins VerticalLayout::getMargins() const { diff --git a/Telegram/SourceFiles/ui/wrap/vertical_layout.h b/Telegram/SourceFiles/ui/wrap/vertical_layout.h index 10376e0ac..bdc247793 100644 --- a/Telegram/SourceFiles/ui/wrap/vertical_layout.h +++ b/Telegram/SourceFiles/ui/wrap/vertical_layout.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "base/object_ptr.h" namespace Ui { diff --git a/Telegram/SourceFiles/ui/wrap/wrap.h b/Telegram/SourceFiles/ui/wrap/wrap.h index cb18d6929..d578c40a4 100644 --- a/Telegram/SourceFiles/ui/wrap/wrap.h +++ b/Telegram/SourceFiles/ui/wrap/wrap.h @@ -8,6 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/rp_widget.h" +#include "ui/ui_utility.h" +#include "base/object_ptr.h" namespace Ui { diff --git a/Telegram/SourceFiles/window/layer_widget.cpp b/Telegram/SourceFiles/window/layer_widget.cpp index f8c38d042..4e68a2634 100644 --- a/Telegram/SourceFiles/window/layer_widget.cpp +++ b/Telegram/SourceFiles/window/layer_widget.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" #include "ui/widgets/shadow.h" +#include "ui/ui_utility.h" #include "window/window_main_menu.h" #include "app.h" #include "styles/style_boxes.h" @@ -294,7 +295,7 @@ void LayerStackWidget::BackgroundWidget::paintEvent(QPaintEvent *e) { p.setOpacity(1.); auto shownWidth = mainMenuRight + st::boxRoundShadow.extend.right(); auto sourceWidth = shownWidth * cIntRetinaFactor(); - auto sourceRect = rtlrect(_mainMenuCache.width() - sourceWidth, 0, sourceWidth, _mainMenuCache.height(), _mainMenuCache.width()); + auto sourceRect = style::rtlrect(_mainMenuCache.width() - sourceWidth, 0, sourceWidth, _mainMenuCache.height(), _mainMenuCache.width()); p.drawPixmapLeft(0, 0, shownWidth, height(), width(), _mainMenuCache, sourceRect); } } @@ -442,7 +443,7 @@ void LayerStackWidget::setCacheImages() { } void LayerStackWidget::closeLayer(not_null layer) { - const auto weak = make_weak(layer.get()); + const auto weak = Ui::MakeWeak(layer.get()); if (weak->inFocusChain()) { setFocus(); } @@ -542,7 +543,7 @@ void LayerStackWidget::startAnimation( } else { setupNewWidgets(); setCacheImages(); - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); clearOldWidgets(); if (weak) { prepareForAnimation(); @@ -552,7 +553,7 @@ void LayerStackWidget::startAnimation( } void LayerStackWidget::resizeEvent(QResizeEvent *e) { - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); _background->setGeometry(rect()); if (!weak) { return; @@ -769,7 +770,7 @@ void LayerStackWidget::clearLayers() { } void LayerStackWidget::clearClosingLayers() { - const auto weak = make_weak(this); + const auto weak = Ui::MakeWeak(this); while (!_closingLayers.empty()) { const auto index = _closingLayers.size() - 1; const auto layer = _closingLayers.back().get(); @@ -822,7 +823,7 @@ void LayerStackWidget::fixOrder() { } void LayerStackWidget::sendFakeMouseEvent() { - sendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton); + SendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton); } LayerStackWidget::~LayerStackWidget() { diff --git a/Telegram/SourceFiles/window/layer_widget.h b/Telegram/SourceFiles/window/layer_widget.h index e7adbf213..5ffa1fcc2 100644 --- a/Telegram/SourceFiles/window/layer_widget.h +++ b/Telegram/SourceFiles/window/layer_widget.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rp_widget.h" #include "ui/effects/animations.h" +#include "base/object_ptr.h" #include "data/data_file_origin.h" namespace Lottie { diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 73b243d29..0a4ef73d3 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "data/data_session.h" #include "main/main_session.h" +#include "ui/ui_utility.h" #include "apiwrap.h" #include "mainwindow.h" #include "facades.h" diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index e079de8c6..e908d0c10 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_title.h" #include "ui/rp_widget.h" #include "base/timer.h" +#include "base/object_ptr.h" #include diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 16253b9e5..f5f63c00b 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text_options.h" #include "ui/emoji_config.h" #include "ui/empty_userpic.h" +#include "ui/ui_utility.h" #include "dialogs/dialogs_layout.h" #include "window/themes/window_theme.h" #include "styles/style_dialogs.h" @@ -602,8 +603,8 @@ void Notification::prepareActionsCache() { actionsCacheImg.fill(Qt::transparent); { Painter p(&actionsCacheImg); - st::notifyFadeRight.fill(p, rtlrect(0, 0, fadeWidth, actionsCacheHeight, actionsCacheWidth)); - p.fillRect(rtlrect(fadeWidth, 0, actionsCacheWidth - fadeWidth, actionsCacheHeight, actionsCacheWidth), st::notificationBg); + st::notifyFadeRight.fill(p, style::rtlrect(0, 0, fadeWidth, actionsCacheHeight, actionsCacheWidth)); + p.fillRect(style::rtlrect(fadeWidth, 0, actionsCacheWidth - fadeWidth, actionsCacheHeight, actionsCacheWidth), st::notificationBg); p.drawPixmapRight(replyRight, _reply->y() - actionsTop, actionsCacheWidth, replyCache); } _buttonsCache = App::pixmapFromImageInPlace(std::move(actionsCacheImg)); diff --git a/Telegram/SourceFiles/window/notifications_manager_default.h b/Telegram/SourceFiles/window/notifications_manager_default.h index 4129eab1e..43179b691 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.h +++ b/Telegram/SourceFiles/window/notifications_manager_default.h @@ -9,8 +9,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/notifications_manager.h" #include "ui/effects/animations.h" +#include "ui/rp_widget.h" #include "base/timer.h" #include "base/binary_guard.h" +#include "base/object_ptr.h" #include diff --git a/Telegram/SourceFiles/window/section_widget.cpp b/Telegram/SourceFiles/window/section_widget.cpp index 199eacb4d..aa298db0c 100644 --- a/Telegram/SourceFiles/window/section_widget.cpp +++ b/Telegram/SourceFiles/window/section_widget.cpp @@ -7,13 +7,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "window/section_widget.h" -#include #include "mainwidget.h" +#include "ui/ui_utility.h" #include "window/section_memento.h" #include "window/window_slide_animation.h" #include "window/themes/window_theme.h" #include "window/window_session_controller.h" +#include + namespace Window { Main::Session &AbstractSectionWidget::session() const { @@ -32,7 +34,7 @@ void SectionWidget::setGeometryWithTopMoved( _topDelta = topDelta; bool willBeResized = (size() != newGeometry.size()); if (geometry() != newGeometry) { - auto weak = make_weak(this); + auto weak = Ui::MakeWeak(this); setGeometry(newGeometry); if (!weak) { return; @@ -77,6 +79,11 @@ void SectionWidget::showFast() { showFinished(); } +QPixmap SectionWidget::grabForShowAnimation( + const SectionSlideParams ¶ms) { + return Ui::GrabWidget(this); +} + void SectionWidget::PaintBackground(not_null widget, QRect clip) { Painter p(widget); diff --git a/Telegram/SourceFiles/window/section_widget.h b/Telegram/SourceFiles/window/section_widget.h index ecb747f35..5962ef8ba 100644 --- a/Telegram/SourceFiles/window/section_widget.h +++ b/Telegram/SourceFiles/window/section_widget.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/rp_widget.h" #include "dialogs/dialogs_key.h" +#include "base/object_ptr.h" namespace Main { class Session; @@ -106,9 +107,7 @@ public: // This can be used to grab with or without top bar shadow. // This will be protected when animation preparation will be done inside. - virtual QPixmap grabForShowAnimation(const SectionSlideParams ¶ms) { - return Ui::GrabWidget(this); - } + virtual QPixmap grabForShowAnimation(const SectionSlideParams ¶ms); // Attempt to show the required section inside the existing one. // For example if this section already shows exactly the required diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp index b1272bcd6..4fbf73e89 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/multi_select.h" #include "ui/widgets/dropdown_menu.h" #include "ui/toast/toast.h" +#include "ui/ui_utility.h" #include "base/parse_helper.h" #include "base/zlib_help.h" #include "core/file_utilities.h" @@ -698,7 +699,7 @@ void Editor::showMenu() { return; } _menu.create(this); - _menu->setHiddenCallback([weak = make_weak(this), menu = _menu.data()]{ + _menu->setHiddenCallback([weak = Ui::MakeWeak(this), menu = _menu.data()]{ menu->deleteLater(); if (weak && weak->_menu == menu) { weak->_menu = nullptr; diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor.h b/Telegram/SourceFiles/window/themes/window_theme_editor.h index 8a246af08..9a3c36352 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.h +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.h @@ -8,6 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "data/data_cloud_themes.h" +#include "ui/rp_widget.h" +#include "base/object_ptr.h" namespace Ui { class FlatButton; diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_block.h b/Telegram/SourceFiles/window/themes/window_theme_editor_block.h index aef178dcc..05d93593e 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_block.h +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_block.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/rp_widget.h" + class EditColorBox; namespace Window { diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp index 6ed1c91d2..27b62369f 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp @@ -746,7 +746,7 @@ void Generator::paintBubble(const Bubble &bubble) { auto h = st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom(); auto bar = (bubble.outbg ? st::msgOutReplyBarColor[_palette] : st::msgInReplyBarColor[_palette]); - auto rbar = rtlrect(trect.x() + st::msgReplyBarPos.x(), trect.y() + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.width(), st::msgReplyBarSize.height(), _rect.width()); + auto rbar = style::rtlrect(trect.x() + st::msgReplyBarPos.x(), trect.y() + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.width(), st::msgReplyBarSize.height(), _rect.width()); _p->fillRect(rbar, bar); _p->setPen(bubble.outbg ? st::msgOutServiceFg[_palette] : st::msgInServiceFg[_palette]); @@ -770,7 +770,7 @@ void Generator::paintBubble(const Bubble &bubble) { auto statustop = y + st::msgFileStatusTop; auto bottom = y + st::msgFilePadding.top() + st::msgFileSize + st::msgFilePadding.bottom(); - auto inner = rtlrect(x + st::msgFilePadding.left(), y + st::msgFilePadding.top(), st::msgFileSize, st::msgFileSize, _rect.width()); + auto inner = style::rtlrect(x + st::msgFilePadding.left(), y + st::msgFilePadding.top(), st::msgFileSize, st::msgFileSize, _rect.width()); _p->setPen(Qt::NoPen); _p->setBrush(bubble.outbg ? st::msgFileOutBg[_palette] : st::msgFileInBg[_palette]); diff --git a/Telegram/SourceFiles/window/themes/window_theme_warning.cpp b/Telegram/SourceFiles/window/themes/window_theme_warning.cpp index 3b98bfafe..84a4649e8 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_warning.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_warning.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_boxes.h" #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" +#include "ui/ui_utility.h" #include "window/themes/window_theme.h" #include "lang/lang_keys.h" #include "app.h" diff --git a/Telegram/SourceFiles/window/themes/window_theme_warning.h b/Telegram/SourceFiles/window/themes/window_theme_warning.h index b72466d9b..ec35c3496 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_warning.h +++ b/Telegram/SourceFiles/window/themes/window_theme_warning.h @@ -8,7 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "base/timer.h" +#include "base/object_ptr.h" #include "ui/effects/animations.h" +#include "ui/rp_widget.h" namespace Ui { class RoundButton; diff --git a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp index d697c1066..c3abbecef 100644 --- a/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp +++ b/Telegram/SourceFiles/window/themes/window_themes_cloud_list.cpp @@ -265,9 +265,9 @@ void CloudListCheck::paintWithColors( p.setPen(Qt::NoPen); p.setBrush(_colors->received); - p.drawRoundedRect(rtlrect(received, outerWidth), radius, radius); + p.drawRoundedRect(style::rtlrect(received, outerWidth), radius, radius); p.setBrush(_colors->sent); - p.drawRoundedRect(rtlrect(sent, outerWidth), radius, radius); + p.drawRoundedRect(style::rtlrect(sent, outerWidth), radius, radius); const auto skip = st::settingsThemeRadioBottom / 2; diff --git a/Telegram/SourceFiles/window/window_connecting_widget.cpp b/Telegram/SourceFiles/window/window_connecting_widget.cpp index 3273b6b69..c15bc2b55 100644 --- a/Telegram/SourceFiles/window/window_connecting_widget.cpp +++ b/Telegram/SourceFiles/window/window_connecting_widget.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/effects/radial_animation.h" +#include "ui/ui_utility.h" #include "window/themes/window_theme.h" #include "boxes/connection_box.h" #include "lang/lang_keys.h" diff --git a/Telegram/SourceFiles/window/window_main_menu.h b/Telegram/SourceFiles/window/window_main_menu.h index 081a92270..44f43dcbf 100644 --- a/Telegram/SourceFiles/window/window_main_menu.h +++ b/Telegram/SourceFiles/window/window_main_menu.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "base/timer.h" +#include "base/object_ptr.h" #include "ui/rp_widget.h" namespace Ui { diff --git a/Telegram/SourceFiles/window/window_outdated_bar.h b/Telegram/SourceFiles/window/window_outdated_bar.h index 1a3bfd9dc..5f4d37379 100644 --- a/Telegram/SourceFiles/window/window_outdated_bar.h +++ b/Telegram/SourceFiles/window/window_outdated_bar.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "base/object_ptr.h" + namespace Ui { class RpWidget; } // namespace Ui diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index f19ffc6e6..41790c8e7 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include "base/flags.h" #include "base/observer.h" +#include "base/object_ptr.h" #include "dialogs/dialogs_key.h" #include "ui/effects/animation_value.h" diff --git a/Telegram/SourceFiles/window/window_title.h b/Telegram/SourceFiles/window/window_title.h index cbd9dfbc5..50260a354 100644 --- a/Telegram/SourceFiles/window/window_title.h +++ b/Telegram/SourceFiles/window/window_title.h @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "ui/rp_widget.h" + namespace Window { enum class HitTestResult { diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index 0656dc677..d2cb486d6 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -68,6 +68,7 @@ 'qt.gypi', 'qt_moc.gypi', 'qt_rcc.gypi', + 'codegen_styles_rule.gypi', 'codegen_rules.gypi', 'pch.gypi', ], diff --git a/Telegram/gyp/codegen_rules.gypi b/Telegram/gyp/codegen_rules.gypi index d1c92900b..9cad3ee41 100644 --- a/Telegram/gyp/codegen_rules.gypi +++ b/Telegram/gyp/codegen_rules.gypi @@ -5,9 +5,6 @@ # https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL { - 'includes': [ - 'codegen_styles_rule.gypi', - ], 'actions': [{ 'action_name': 'update_dependent_qrc', 'inputs': [ diff --git a/Telegram/gyp/codegen_rules_ui.gypi b/Telegram/gyp/codegen_rules_ui.gypi index 63cd679cd..63a7c9e94 100644 --- a/Telegram/gyp/codegen_rules_ui.gypi +++ b/Telegram/gyp/codegen_rules_ui.gypi @@ -5,9 +5,6 @@ # https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL { - 'includes': [ - 'codegen_styles_rule.gypi', - ], 'actions': [{ 'action_name': 'codegen_palette', 'inputs': [ diff --git a/Telegram/gyp/lib_base.gyp b/Telegram/gyp/lib_base.gyp index 82d42d4ae..30a3289ee 100644 --- a/Telegram/gyp/lib_base.gyp +++ b/Telegram/gyp/lib_base.gyp @@ -60,6 +60,7 @@ '<(src_loc)/base/invoke_queued.h', '<(src_loc)/base/last_used_cache.h', '<(src_loc)/base/match_method.h', + '<(src_loc)/base/object_ptr.h', '<(src_loc)/base/observer.cpp', '<(src_loc)/base/observer.h', '<(src_loc)/base/ordered_set.h', diff --git a/Telegram/gyp/lib_ui.gyp b/Telegram/gyp/lib_ui.gyp index ef95ddb2d..375b86cb8 100644 --- a/Telegram/gyp/lib_ui.gyp +++ b/Telegram/gyp/lib_ui.gyp @@ -16,6 +16,7 @@ 'common.gypi', 'qt.gypi', 'qt_moc.gypi', + 'codegen_styles_rule.gypi', 'codegen_rules_ui.gypi', 'pch.gypi', ], diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index 04ac54519..f025fc642 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -766,16 +766,6 @@ <(src_loc)/ui/image/image_prepare.h <(src_loc)/ui/image/image_source.cpp <(src_loc)/ui/image/image_source.h -<(src_loc)/ui/style/style_core.cpp -<(src_loc)/ui/style/style_core.h -<(src_loc)/ui/style/style_core_color.cpp -<(src_loc)/ui/style/style_core_color.h -<(src_loc)/ui/style/style_core_font.cpp -<(src_loc)/ui/style/style_core_font.h -<(src_loc)/ui/style/style_core_icon.cpp -<(src_loc)/ui/style/style_core_icon.h -<(src_loc)/ui/style/style_core_types.cpp -<(src_loc)/ui/style/style_core_types.h <(src_loc)/ui/text/text.cpp <(src_loc)/ui/text/text.h <(src_loc)/ui/text/text_block.cpp @@ -852,8 +842,8 @@ <(src_loc)/ui/special_buttons.h <(src_loc)/ui/text_options.cpp <(src_loc)/ui/text_options.h -<(src_loc)/ui/twidget.cpp -<(src_loc)/ui/twidget.h +<(src_loc)/ui/ui_utility.cpp +<(src_loc)/ui/ui_utility.h <(src_loc)/ui/unread_badge.cpp <(src_loc)/ui/unread_badge.h <(src_loc)/window/layer_widget.cpp