diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index d4b7e8a92..ea914d90f 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -2710,7 +2710,7 @@ namespace { } } if (h > 2 * cornerHeight) { - if ((parts & RectPart::NoTopBottom) == qFlags(RectPart::NoTopBottom)) { + if ((parts & RectPart::NoTopBottom) == RectPart::NoTopBottom) { p.fillRect(x, y + cornerHeight, w, h - 2 * cornerHeight, bg); } else { if (parts & RectPart::Left) { diff --git a/Telegram/SourceFiles/base/qthelp_regex.h b/Telegram/SourceFiles/base/qthelp_regex.h index 582b52786..657094cd9 100644 --- a/Telegram/SourceFiles/base/qthelp_regex.h +++ b/Telegram/SourceFiles/base/qthelp_regex.h @@ -20,6 +20,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once +#include "base/flags.h" + namespace qthelp { class RegularExpressionMatch { @@ -65,8 +67,8 @@ enum class RegExOption { DontAutomaticallyOptimize = QRegularExpression::DontAutomaticallyOptimizeOption, #endif // OS_MAC_OLD }; -using RegExOptions = QFlags; -Q_DECLARE_OPERATORS_FOR_FLAGS(RegExOptions); +using RegExOptions = base::flags; +inline constexpr auto is_flag_type(RegExOption) { return true; }; inline RegularExpressionMatch regex_match(const QString &string, const QString &subject, RegExOptions options = 0) { auto qtOptions = QRegularExpression::PatternOptions(static_cast(options)); diff --git a/Telegram/SourceFiles/boxes/abstract_box.cpp b/Telegram/SourceFiles/boxes/abstract_box.cpp index fc56e37c7..91dd88f7c 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.cpp +++ b/Telegram/SourceFiles/boxes/abstract_box.cpp @@ -242,7 +242,8 @@ void AbstractBox::paintEvent(QPaintEvent *e) { auto paintTopRounded = clip.intersects(QRect(0, 0, width(), st::boxRadius)); auto paintBottomRounded = clip.intersects(QRect(0, height() - st::boxRadius, width(), st::boxRadius)); if (paintTopRounded || paintBottomRounded) { - auto parts = qFlags(RectPart::None); + auto parts = RectPart::None | 0; + parts |= RectPart::None; if (paintTopRounded) parts |= RectPart::FullTop; if (paintBottomRounded) parts |= RectPart::FullBottom; App::roundRect(p, rect(), st::boxBg, BoxCorners, nullptr, parts); diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 364d15f56..6f1068da2 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -757,7 +757,7 @@ void EditCaptionBox::onSave(bool ctrlShiftEnter) { return; } - auto flags = qFlags(MTPmessages_EditMessage::Flag::f_message); + auto flags = MTPmessages_EditMessage::Flag::f_message | 0; if (_previewCancelled) { flags |= MTPmessages_EditMessage::Flag::f_no_webpage; } diff --git a/Telegram/SourceFiles/chat_helpers/stickers.cpp b/Telegram/SourceFiles/chat_helpers/stickers.cpp index 2610ec283..2342103c2 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers.cpp @@ -242,7 +242,7 @@ void SetIsFaved(not_null document, base::optionalstickers.indexOf(document); if (index == 0) { @@ -436,7 +436,7 @@ void SpecialSetReceived(uint64 setId, const QString &setTitle, const QVectortitle = setTitle; } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index a856a076c..bab357f2c 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -1312,7 +1312,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) { if (canEdit) { auto hidden = Auth().data().isGroupStickersSectionHidden(_megagroupSet->id); if (isShownHere(hidden)) { - _mySets.push_back(Set(Stickers::MegagroupSetId, qFlags(MTPDstickerSet_ClientFlag::f_special), lang(lng_group_stickers), 0)); + _mySets.push_back(Set(Stickers::MegagroupSetId, MTPDstickerSet_ClientFlag::f_special | 0, lang(lng_group_stickers), 0)); } } return; @@ -1338,7 +1338,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) { if (isInstalled && !canEdit) { removeHiddenForGroup(); } else if (isShownHere(hidden)) { - _mySets.push_back(Set(Stickers::MegagroupSetId, qFlags(MTPDstickerSet_ClientFlag::f_special), lang(lng_group_stickers), it->stickers.size() + 1, it->stickers)); + _mySets.push_back(Set(Stickers::MegagroupSetId, MTPDstickerSet_ClientFlag::f_special | 0, lang(lng_group_stickers), it->stickers.size() + 1, it->stickers)); } return; } diff --git a/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py b/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py index a05e42dda..2e1a684ae 100644 --- a/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py +++ b/Telegram/SourceFiles/codegen/scheme/codegen_scheme.py @@ -322,8 +322,8 @@ with open(input_file) as f: funcsText += '\n'; funcsText += '\t\tMAX_FIELD = (1 << ' + str(maxbit) + '),\n'; funcsText += '\t};\n'; - funcsText += '\tusing Flags = QFlags;\n'; - funcsText += '\tfriend inline Flags operator~(Flag v) { return QFlag(~static_cast(v)); }\n'; + funcsText += '\tusing Flags = base::flags;\n'; + funcsText += '\tfriend inline constexpr auto is_flag_type(Flag) { return true; };\n'; funcsText += '\n'; if (len(conditions)): for paramName in conditionsList: @@ -415,8 +415,6 @@ with open(input_file) as f: methods += methodBodies; funcsText += '};\n'; # class ending - if (len(conditionsList)): - funcsText += 'Q_DECLARE_OPERATORS_FOR_FLAGS(MTP' + name + '::Flags)\n\n'; if (isTemplate != ''): funcsText += 'template \n'; funcsText += 'using MTP' + Name + ' = MTPBoxed>;\n'; @@ -605,8 +603,8 @@ for restype in typesList: dataText += '\n'; dataText += '\t\tMAX_FIELD = (1 << ' + str(maxbit) + '),\n'; dataText += '\t};\n'; - dataText += '\tusing Flags = QFlags;\n'; - dataText += '\tfriend inline Flags operator~(Flag v) { return QFlag(~static_cast(v)); }\n'; + dataText += '\tusing Flags = base::flags;\n'; + dataText += '\tfriend inline constexpr auto is_flag_type(Flag) { return true; };\n'; dataText += '\n'; if (len(conditions)): for paramName in conditionsList: @@ -699,8 +697,6 @@ for restype in typesList: else: # single creator creatorProxyText += '\t\treturn MTP' + restype + '();\n'; creatorProxyText += '\t}\n'; - if (len(conditionsList)): - flagDeclarations += 'Q_DECLARE_OPERATORS_FOR_FLAGS(MTPD' + name + '::Flags)\n'; creatorsDeclarations += 'MTP' + restype + ' MTP_' + name + '(' + ', '.join(creatorParams) + ');\n'; creatorsBodies += 'MTP' + restype + ' MTP_' + name + '(' + ', '.join(creatorParams) + ') {\n'; creatorsBodies += '\treturn MTP::internal::TypeCreator::new_' + name + '(' + ', '.join(creatorParamsList) + ');\n'; @@ -852,7 +848,7 @@ for childName in parentFlagsList: error else: parentFlagsCheck[parentName][flag] = parentFlagsCheck[childName][flag]; - flagOperators += 'inline ' + parentName + '::Flags mtpCastFlags(' + childName + '::Flags flags) { return ' + parentName + '::Flags(QFlag(flags)); }\n'; + flagOperators += 'inline ' + parentName + '::Flags mtpCastFlags(' + childName + '::Flags flags) { return static_cast<' + parentName + '::Flag>(flags.value()); }\n'; flagOperators += 'inline ' + parentName + '::Flags mtpCastFlags(MTPflags<' + childName + '::Flags> flags) { return mtpCastFlags(flags.v); }\n'; # manual types added here @@ -935,6 +931,7 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org\n\ #pragma once\n\ \n\ #include "mtproto/core_types.h"\n\ +#include "base/flags.h"\n\ \n\ // Creator current layer and proxy class declaration\n\ namespace MTP {\n\ diff --git a/Telegram/SourceFiles/core/basic_types.h b/Telegram/SourceFiles/core/basic_types.h index fa4f93f8f..e6cdbfa48 100644 --- a/Telegram/SourceFiles/core/basic_types.h +++ b/Telegram/SourceFiles/core/basic_types.h @@ -63,27 +63,3 @@ using float64 = double; #define qsl(s) QStringLiteral(s) #define qstr(s) QLatin1String(s, sizeof(s) - 1) - -// For QFlags<> declared in private section of a class we need to declare -// operators from Q_DECLARE_OPERATORS_FOR_FLAGS as friend functions. -#ifndef OS_MAC_OLD - -#define Q_DECLARE_FRIEND_INCOMPATIBLE_FLAGS(Flags) \ -friend Q_DECL_CONSTEXPR QIncompatibleFlag operator|(Flags::enum_type f1, int f2) Q_DECL_NOTHROW; - -#define Q_DECLARE_FRIEND_OPERATORS_FOR_FLAGS(Flags) \ -friend Q_DECL_CONSTEXPR QFlags operator|(Flags::enum_type f1, Flags::enum_type f2) Q_DECL_NOTHROW; \ -friend Q_DECL_CONSTEXPR QFlags operator|(Flags::enum_type f1, QFlags f2) Q_DECL_NOTHROW; \ -Q_DECLARE_FRIEND_INCOMPATIBLE_FLAGS(Flags) - -#else // OS_MAC_OLD - -#define Q_DECLARE_FRIEND_INCOMPATIBLE_FLAGS(Flags) \ -friend Q_DECL_CONSTEXPR QIncompatibleFlag operator|(Flags::enum_type f1, int f2); - -#define Q_DECLARE_FRIEND_OPERATORS_FOR_FLAGS(Flags) \ -friend Q_DECL_CONSTEXPR QFlags operator|(Flags::enum_type f1, Flags::enum_type f2); \ -friend Q_DECL_CONSTEXPR QFlags operator|(Flags::enum_type f1, QFlags f2); \ -Q_DECLARE_FRIEND_INCOMPATIBLE_FLAGS(Flags) - -#endif // OS_MAC_OLD diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index d0a5f6297..fc35bd1b5 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "core/basic_types.h" +#include "base/flags.h" // Define specializations for QByteArray for Qt 5.3.2, because // QByteArray in Qt 5.3.2 doesn't declare "pointer" subtype. @@ -178,11 +179,6 @@ reversion_wrapper reversed(Container &&container) { // while "for_const (T *p, v)" won't and "for_const (T *&p, v)" won't compile #define for_const(range_declaration, range_expression) for (range_declaration : std::as_const(range_expression)) -template -inline constexpr QFlags qFlags(Enum v) { - return QFlags(v); -} - template inline void InvokeQueued(QObject *context, Lambda &&lambda) { QObject proxy; @@ -581,8 +577,8 @@ enum ShowLayerOption { AnimatedShowLayer = 0x00, ForceFastShowLayer = 0x04, }; -using ShowLayerOptions = QFlags; -Q_DECLARE_OPERATORS_FOR_FLAGS(ShowLayerOptions); +using ShowLayerOptions = base::flags; +inline constexpr auto is_flag_type(ShowLayerOption) { return true; }; static int32 FullArcLength = 360 * 16; static int32 QuarterArcLength = (FullArcLength / 4); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h index 962a1e890..654eaef09 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.h @@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "dialogs/dialogs_widget.h" +#include "base/flags.h" namespace Dialogs { class Row; @@ -180,8 +181,9 @@ private: MessageSearch = 0x08, All = 0x0F, }; - using UpdateRowSections = QFlags; - Q_DECLARE_FRIEND_OPERATORS_FOR_FLAGS(UpdateRowSections); + using UpdateRowSections = base::flags; + friend inline constexpr auto is_flag_type(UpdateRowSection) { return true; }; + void updateDialogRow(PeerData *peer, MsgId msgId, QRect updateRect, UpdateRowSections sections = UpdateRowSection::All); int dialogsOffset() const; @@ -293,5 +295,3 @@ private: base::lambda _loadMoreCallback; }; - -Q_DECLARE_OPERATORS_FOR_FLAGS(DialogsInner::UpdateRowSections); diff --git a/Telegram/SourceFiles/history/history.h b/Telegram/SourceFiles/history/history.h index 6295562c0..24db52f0d 100644 --- a/Telegram/SourceFiles/history/history.h +++ b/Telegram/SourceFiles/history/history.h @@ -27,6 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "base/timer.h" #include "base/variant.h" #include "base/flat_set.h" +#include "base/flags.h" void HistoryInit(); @@ -548,17 +549,10 @@ private: f_has_pending_resized_items = (1 << 0), f_pending_resize = (1 << 1), }; - using Flags = QFlags; - Q_DECL_CONSTEXPR friend inline QFlags operator|(Flags::enum_type f1, Flags::enum_type f2) noexcept { - return QFlags(f1) | f2; - } - Q_DECL_CONSTEXPR friend inline QFlags operator|(Flags::enum_type f1, QFlags f2) noexcept { - return f2 | f1; - } - Q_DECL_CONSTEXPR friend inline QFlags operator~(Flags::enum_type f) noexcept { - return ~QFlags(f); - } - Flags _flags = { 0 }; + using Flags = base::flags; + friend inline constexpr auto is_flag_type(Flag) { return true; }; + + Flags _flags = 0; bool _mute = false; int _unreadCount = 0; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 6b345ce0d..b7f3c744c 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -557,6 +557,8 @@ HistoryMessageLogEntryOriginal &HistoryMessageLogEntryOriginal::operator=(Histor HistoryMessageLogEntryOriginal::~HistoryMessageLogEntryOriginal() = default; +HistoryMediaPtr::HistoryMediaPtr() = default; + HistoryMediaPtr::HistoryMediaPtr(std::unique_ptr pointer) : _pointer(std::move(pointer)) { if (_pointer) { _pointer->attachToParent(); diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 8d9bc3464..6bfffb72d 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "base/runtime_composer.h" +#include "base/flags.h" namespace Ui { class RippleAnimation; @@ -170,11 +171,12 @@ struct HistoryMessageReply : public RuntimeComponent { void resize(int width) const; void itemRemoved(HistoryMessage *holder, HistoryItem *removed); - enum PaintFlag { - PaintInBubble = 0x01, - PaintSelected = 0x02, + enum class PaintFlag { + InBubble = 0x01, + Selected = 0x02, }; - using PaintFlags = QFlags; + using PaintFlags = base::flags; + friend inline constexpr auto is_flag_type(PaintFlag) { return true; }; void paint(Painter &p, const HistoryItem *holder, int x, int y, int w, PaintFlags flags) const; MsgId replyToId() const { @@ -196,7 +198,6 @@ struct HistoryMessageReply : public RuntimeComponent { std::unique_ptr _replyToVia; int toWidth = 0; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(HistoryMessageReply::PaintFlags); class ReplyKeyboard; struct HistoryMessageReplyMarkup : public RuntimeComponent { @@ -433,7 +434,7 @@ struct HistoryMessageLogEntryOriginal : public RuntimeComponent other); @@ -604,7 +605,7 @@ public: // optimization: don't create markup component for the case // MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag - return qFlags(MTPDreplyKeyboardMarkup_ClientFlag::f_zero); + return MTPDreplyKeyboardMarkup_ClientFlag::f_zero | 0; } bool hasSwitchInlineButton() const { return _flags & MTPDmessage_ClientFlag::f_has_switch_inline_button; diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp index b0ca60408..0a350680e 100644 --- a/Telegram/SourceFiles/history/history_media_types.cpp +++ b/Telegram/SourceFiles/history/history_media_types.cpp @@ -2200,7 +2200,7 @@ void HistoryGif::draw(Painter &p, const QRect &r, TextSelection selection, TimeM if (reply) { HistoryMessageReply::PaintFlags flags = 0; if (selected) { - flags |= HistoryMessageReply::PaintSelected; + flags |= HistoryMessageReply::PaintFlag::Selected; } reply->paint(p, _parent, rectx, recty, rectw, flags); } @@ -2756,7 +2756,7 @@ void HistorySticker::draw(Painter &p, const QRect &r, TextSelection selection, T if (reply) { HistoryMessageReply::PaintFlags flags = 0; if (selected) { - flags |= HistoryMessageReply::PaintSelected; + flags |= HistoryMessageReply::PaintFlag::Selected; } reply->paint(p, _parent, rectx, recty, rectw, flags); } diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 3cfec00f7..ca4f9289c 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -486,11 +486,11 @@ void HistoryMessageReply::itemRemoved(HistoryMessage *holder, HistoryItem *remov } void HistoryMessageReply::paint(Painter &p, const HistoryItem *holder, int x, int y, int w, PaintFlags flags) const { - bool selected = (flags & PaintSelected), outbg = holder->hasOutLayout(); + bool selected = (flags & PaintFlag::Selected), outbg = holder->hasOutLayout(); style::color bar = st::msgImgReplyBarColor; - if (flags & PaintInBubble) { - bar = (flags & PaintSelected) ? (outbg ? st::msgOutReplyBarSelColor : st::msgInReplyBarSelColor) : (outbg ? st::msgOutReplyBarColor : st::msgInReplyBarColor); + 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)); p.fillRect(rbar, bar); @@ -514,7 +514,7 @@ void HistoryMessageReply::paint(Painter &p, const HistoryItem *holder, int x, in } } if (w > st::msgReplyBarSkip + previewSkip) { - if (flags & PaintInBubble) { + if (flags & PaintFlag::InBubble) { p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg)); } else { p.setPen(st::msgImgReplyBarColor); @@ -526,7 +526,7 @@ void HistoryMessageReply::paint(Painter &p, const HistoryItem *holder, int x, in } auto replyToAsMsg = replyToMsg->toHistoryMessage(); - if (!(flags & PaintInBubble)) { + if (!(flags & PaintFlag::InBubble)) { } else if ((replyToAsMsg && replyToAsMsg->emptyText()) || replyToMsg->serviceMsg()) { p.setPen(outbg ? (selected ? st::msgOutDateFgSelected : st::msgOutDateFg) : (selected ? st::msgInDateFgSelected : st::msgInDateFg)); } else { @@ -537,7 +537,7 @@ void HistoryMessageReply::paint(Painter &p, const HistoryItem *holder, int x, in } else { p.setFont(st::msgDateFont); auto &date = outbg ? (selected ? st::msgOutDateFgSelected : st::msgOutDateFg) : (selected ? st::msgInDateFgSelected : st::msgInDateFg); - p.setPen((flags & PaintInBubble) ? date : st::msgDateImgFg); + p.setPen((flags & PaintFlag::InBubble) ? date : st::msgDateImgFg); p.drawTextLeft(x + st::msgReplyBarSkip, y + st::msgReplyPadding.top() + (st::msgReplyBarSize.height() - st::msgDateFont->height) / 2, w + 2 * x, st::msgDateFont->elided(lang(replyToMsgId ? lng_profile_loading : lng_deleted_message), w - st::msgReplyBarSkip)); } } @@ -1783,9 +1783,9 @@ void HistoryMessage::paintReplyInfo(Painter &p, QRect &trect, bool selected) con if (auto reply = Get()) { int32 h = st::msgReplyPadding.top() + st::msgReplyBarSize.height() + st::msgReplyPadding.bottom(); - HistoryMessageReply::PaintFlags flags = HistoryMessageReply::PaintInBubble; + auto flags = HistoryMessageReply::PaintFlag::InBubble | 0; if (selected) { - flags |= HistoryMessageReply::PaintSelected; + flags |= HistoryMessageReply::PaintFlag::Selected; } reply->paint(p, this, trect.x(), trect.y(), trect.width(), flags); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index f16395e8a..c95dea1e0 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1214,7 +1214,7 @@ void HistoryWidget::onTextChange() { updateStickersByEmoji(); if (_peer && (!_peer->isChannel() || _peer->isMegagroup())) { - if (!_inlineBot && !_editMsgId && (_textUpdateEvents.testFlag(TextUpdateEvent::SendTyping))) { + if (!_inlineBot && !_editMsgId && (_textUpdateEvents & TextUpdateEvent::SendTyping)) { updateSendAction(_history, SendAction::Type::Typing); } } @@ -1229,14 +1229,14 @@ void HistoryWidget::onTextChange() { } _saveCloudDraftTimer.stop(); - if (!_peer || !(_textUpdateEvents.testFlag(TextUpdateEvent::SaveDraft))) return; + if (!_peer || !(_textUpdateEvents & TextUpdateEvent::SaveDraft)) return; _saveDraftText = true; onDraftSave(true); } void HistoryWidget::onDraftSaveDelayed() { - if (!_peer || !(_textUpdateEvents.testFlag(TextUpdateEvent::SaveDraft))) return; + if (!_peer || !(_textUpdateEvents & TextUpdateEvent::SaveDraft)) return; if (!_field->textCursor().anchor() && !_field->textCursor().position() && !_field->verticalScrollBar()->value()) { if (!Local::hasDraftCursors(_peer->id)) { return; @@ -2798,7 +2798,7 @@ void HistoryWidget::saveEditMsg() { return; } - auto sendFlags = qFlags(MTPmessages_EditMessage::Flag::f_message); + auto sendFlags = MTPmessages_EditMessage::Flag::f_message | 0; if (webPageId == CancelledWebPageId) { sendFlags |= MTPmessages_EditMessage::Flag::f_no_webpage; } @@ -4488,14 +4488,14 @@ void HistoryWidget::sendFileConfirmed(const FileLoadResultPtr &file) { auto messageFromId = channelPost ? 0 : Auth().userId(); auto messagePostAuthor = channelPost ? (Auth().user()->firstName + ' ' + Auth().user()->lastName) : QString(); if (file->type == SendMediaType::Photo) { - auto photoFlags = qFlags(MTPDmessageMediaPhoto::Flag::f_photo); + auto photoFlags = MTPDmessageMediaPhoto::Flag::f_photo | 0; if (!file->caption.isEmpty()) { photoFlags |= MTPDmessageMediaPhoto::Flag::f_caption; } auto photo = MTP_messageMediaPhoto(MTP_flags(photoFlags), file->photo, MTP_string(file->caption), MTPint()); h->addNewMessage(MTP_message(MTP_flags(flags), MTP_int(newId.msg), MTP_int(messageFromId), peerToMTP(file->to.peer), MTPnullFwdHeader, MTPint(), MTP_int(file->to.replyTo), MTP_int(unixtime()), MTP_string(""), photo, MTPnullMarkup, MTPnullEntities, MTP_int(1), MTPint(), MTP_string(messagePostAuthor)), NewMessageUnread); } else if (file->type == SendMediaType::File) { - auto documentFlags = qFlags(MTPDmessageMediaDocument::Flag::f_document); + auto documentFlags = MTPDmessageMediaDocument::Flag::f_document | 0; if (!file->caption.isEmpty()) { documentFlags |= MTPDmessageMediaDocument::Flag::f_caption; } @@ -4505,7 +4505,7 @@ void HistoryWidget::sendFileConfirmed(const FileLoadResultPtr &file) { if (!h->peer->isChannel()) { flags |= MTPDmessage::Flag::f_media_unread; } - auto documentFlags = qFlags(MTPDmessageMediaDocument::Flag::f_document); + auto documentFlags = MTPDmessageMediaDocument::Flag::f_document | 0; if (!file->caption.isEmpty()) { documentFlags |= MTPDmessageMediaDocument::Flag::f_caption; } @@ -5340,7 +5340,7 @@ void HistoryWidget::onInlineResultSend(InlineBots::Result *result, UserData *bot bool out = !_peer->isSelf(), unread = !_peer->isSelf(); auto flags = NewMessageFlags(_peer) | MTPDmessage::Flag::f_media; // unread, out - auto sendFlags = qFlags(MTPmessages_SendInlineBotResult::Flag::f_clear_draft); + auto sendFlags = MTPmessages_SendInlineBotResult::Flag::f_clear_draft | 0; if (replyToId()) { flags |= MTPDmessage::Flag::f_reply_to_msg_id; sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_reply_to_msg_id; diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index c97a49a7f..5744abfb2 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -27,6 +27,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "window/section_widget.h" #include "core/single_timer.h" #include "ui/widgets/input_fields.h" +#include "base/flags.h" namespace InlineBots { namespace Layout { @@ -693,8 +694,8 @@ private: SaveDraft = 0x01, SendTyping = 0x02, }; - using TextUpdateEvents = QFlags; - Q_DECLARE_FRIEND_OPERATORS_FOR_FLAGS(TextUpdateEvents); + using TextUpdateEvents = base::flags; + friend inline constexpr auto is_flag_type(TextUpdateEvent) { return true; }; void writeDrafts(Data::Draft **localDraft, Data::Draft **editDraft); void writeDrafts(History *history); @@ -833,7 +834,7 @@ private: bool _nonEmptySelection = false; TaskQueue _fileLoader; - TextUpdateEvents _textUpdateEvents = (TextUpdateEvent::SaveDraft | TextUpdateEvent::SendTyping); + TextUpdateEvents _textUpdateEvents = (TextUpdateEvents() | TextUpdateEvent::SaveDraft | TextUpdateEvent::SendTyping); int64 _serviceImageCacheSize = 0; QString _confirmSource; @@ -866,5 +867,3 @@ private: bool _inGrab = false; }; - -Q_DECLARE_OPERATORS_FOR_FLAGS(HistoryWidget::TextUpdateEvents) diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h index 464a66d5e..a1c4ecb66 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h +++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_internal.h @@ -20,6 +20,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once +#include "base/flags.h" #include "inline_bots/inline_bot_layout_item.h" #include "ui/effects/radial_animation.h" #include "ui/text/text.h" @@ -84,11 +85,9 @@ private: Over = 0x01, DeleteOver = 0x02, }; - using StateFlags = QFlags; + using StateFlags = base::flags; + friend inline constexpr auto is_flag_type(StateFlag) { return true; }; StateFlags _state; - friend inline StateFlags operator~(StateFlag flag) { - return ~StateFlags(flag); - } Media::Clip::ReaderPointer _gif; ClickHandlerPtr _delete; diff --git a/Telegram/SourceFiles/logs.cpp b/Telegram/SourceFiles/logs.cpp index 1d6bb3159..d916756c8 100644 --- a/Telegram/SourceFiles/logs.cpp +++ b/Telegram/SourceFiles/logs.cpp @@ -158,7 +158,7 @@ private: } } - QFlags mode = QIODevice::WriteOnly | QIODevice::Text; + auto mode = QIODevice::WriteOnly | QIODevice::Text; if (type == LogDataMain) { // we can call LOG() in LogDataMain reopen - mutex not locked if (postfix.isEmpty()) { // instance checked, need to move to log.txt Assert(!files[type]->fileName().isEmpty()); // one of log_startXX.txt should've been opened already diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index d1f7a1f87..8c83cd394 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -3903,7 +3903,7 @@ void MainWidget::getChannelDifference(ChannelData *channel, ChannelDifferenceReq channel->ptsSetRequesting(true); auto filter = MTP_channelMessagesFilterEmpty(); - auto flags = qFlags(MTPupdates_GetChannelDifference::Flag::f_force); + auto flags = MTPupdates_GetChannelDifference::Flag::f_force | 0; if (from != ChannelDifferenceRequest::PtsGapOrShortPoll) { if (!channel->ptsWaitingForSkipped()) { flags = 0; // No force flag when requesting for short poll. @@ -4283,7 +4283,7 @@ void MainWidget::incrementSticker(DocumentData *sticker) { auto it = sets.find(Stickers::CloudRecentSetId); if (it == sets.cend()) { if (it == sets.cend()) { - it = sets.insert(Stickers::CloudRecentSetId, Stickers::Set(Stickers::CloudRecentSetId, 0, lang(lng_recent_stickers), QString(), 0, 0, qFlags(MTPDstickerSet_ClientFlag::f_special))); + it = sets.insert(Stickers::CloudRecentSetId, Stickers::Set(Stickers::CloudRecentSetId, 0, lang(lng_recent_stickers), QString(), 0, 0, MTPDstickerSet_ClientFlag::f_special | 0)); } else { it->title = lang(lng_recent_stickers); } diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 0f0b4e7b7..0798d184d 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -360,7 +360,7 @@ void MainWindow::destroyLayerDelayed() { void MainWindow::ui_hideSettingsAndLayer(ShowLayerOptions options) { if (_layerBg) { _layerBg->hideAll(); - if (options.testFlag(ForceFastShowLayer)) { + if (options & ForceFastShowLayer) { destroyLayerDelayed(); } } @@ -399,8 +399,8 @@ PasscodeWidget *MainWindow::passcodeWidget() { void MainWindow::ui_showBox(object_ptr box, ShowLayerOptions options) { if (box) { ensureLayerCreated(); - if (options.testFlag(KeepOtherLayers)) { - if (options.testFlag(ShowAfterOtherLayers)) { + if (options & KeepOtherLayers) { + if (options & ShowAfterOtherLayers) { _layerBg->prependBox(std::move(box)); } else { _layerBg->appendBox(std::move(box)); @@ -408,13 +408,13 @@ void MainWindow::ui_showBox(object_ptr box, ShowLayerOptions options } else { _layerBg->showBox(std::move(box)); } - if (options.testFlag(ForceFastShowLayer)) { + if (options & ForceFastShowLayer) { _layerBg->finishAnimation(); } } else { if (_layerBg) { _layerBg->hideTopLayer(); - if (options.testFlag(ForceFastShowLayer) && !_layerBg->layerShown()) { + if ((options & ForceFastShowLayer) && !_layerBg->layerShown()) { destroyLayerDelayed(); } } diff --git a/Telegram/SourceFiles/mtproto/core_types.h b/Telegram/SourceFiles/mtproto/core_types.h index caa886004..59b81db12 100644 --- a/Telegram/SourceFiles/mtproto/core_types.h +++ b/Telegram/SourceFiles/mtproto/core_types.h @@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "core/basic_types.h" +#include "base/flags.h" namespace MTP { @@ -353,7 +354,7 @@ struct ZeroFlagsHelper { template class MTPflags { public: - Flags v = Flags(0); + Flags v = 0; static_assert(sizeof(Flags) == sizeof(int32), "MTPflags are allowed only wrapping int32 flag types!"); MTPflags() = default; @@ -380,21 +381,21 @@ private: } template - friend MTPflags> MTP_flags(QFlags v); + friend MTPflags> MTP_flags(base::flags v); template - friend MTPflags> MTP_flags(T v); + friend MTPflags> MTP_flags(T v); }; template -inline MTPflags> MTP_flags(QFlags v) { - return MTPflags>(v); +inline MTPflags> MTP_flags(base::flags v) { + return MTPflags>(v); } template ::value>> -inline MTPflags> MTP_flags(T v) { - return MTPflags>(v); +inline MTPflags> MTP_flags(T v) { + return MTPflags>(v); } inline internal::ZeroFlagsHelper MTP_flags(void(internal::ZeroFlagsHelper::*)()) { diff --git a/Telegram/SourceFiles/mtproto/dc_options.cpp b/Telegram/SourceFiles/mtproto/dc_options.cpp index 61f37159f..149ee5a6e 100644 --- a/Telegram/SourceFiles/mtproto/dc_options.cpp +++ b/Telegram/SourceFiles/mtproto/dc_options.cpp @@ -406,15 +406,15 @@ DcOptions::Variants DcOptions::lookup(DcId dcId, DcType type) const { switch (protocol) { case Variants::Tcp: return { // Regular TCP IPv4 - throughProxy ? (MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_static) : qFlags(MTPDdcOption::Flag::f_tcpo_only), - throughProxy ? qFlags(MTPDdcOption::Flag::f_static) : MTPDdcOption::Flags(0), - qFlags(MTPDdcOption::Flag::f_tcpo_only), - MTPDdcOption::Flags(0) + throughProxy ? (MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_tcpo_only | 0), + throughProxy ? (MTPDdcOption::Flag::f_static | 0) : MTPDdcOption::Flags(0), + (MTPDdcOption::Flag::f_tcpo_only | 0), + 0 }; case Variants::Http: return { // Regular HTTP IPv4 - throughProxy ? qFlags(MTPDdcOption::Flag::f_static) : MTPDdcOption::Flags(0), - MTPDdcOption::Flags(0), + throughProxy ? (MTPDdcOption::Flag::f_static | 0) : MTPDdcOption::Flags(0), + 0, }; } } break; @@ -423,14 +423,14 @@ DcOptions::Variants DcOptions::lookup(DcId dcId, DcType type) const { case Variants::Tcp: return { // Regular TCP IPv6 throughProxy ? (MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_ipv6), - throughProxy ? (MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : qFlags(MTPDdcOption::Flag::f_ipv6), + throughProxy ? (MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_ipv6 | 0), (MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_ipv6), - qFlags(MTPDdcOption::Flag::f_ipv6), + (MTPDdcOption::Flag::f_ipv6 | 0), }; case Variants::Http: return { // Regular HTTP IPv6 - throughProxy ? (MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : qFlags(MTPDdcOption::Flag::f_ipv6), - qFlags(MTPDdcOption::Flag::f_ipv6), + throughProxy ? (MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_ipv6 | 0), + (MTPDdcOption::Flag::f_ipv6 | 0), }; } } break; @@ -443,20 +443,20 @@ DcOptions::Variants DcOptions::lookup(DcId dcId, DcType type) const { case Variants::Tcp: return { // Media download TCP IPv4 throughProxy ? (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_tcpo_only), - throughProxy ? (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_static) : qFlags(MTPDdcOption::Flag::f_tcpo_only), - qFlags(MTPDdcOption::Flag::f_media_only), - throughProxy ? qFlags(MTPDdcOption::Flag::f_static) : MTPDdcOption::Flags(0), + throughProxy ? (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_tcpo_only | 0), + (MTPDdcOption::Flag::f_media_only | 0), + throughProxy ? (MTPDdcOption::Flag::f_static | 0) : MTPDdcOption::Flags(0), (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_tcpo_only), - throughProxy ? (MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_static) : qFlags(MTPDdcOption::Flag::f_tcpo_only), - throughProxy ? qFlags(MTPDdcOption::Flag::f_tcpo_only) : qFlags(MTPDdcOption::Flag::f_media_only), - MTPDdcOption::Flags(0), + throughProxy ? (MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_tcpo_only | 0), + throughProxy ? (MTPDdcOption::Flag::f_tcpo_only | 0) : (MTPDdcOption::Flag::f_media_only | 0), + 0, }; case Variants::Http: return { // Media download HTTP IPv4 - throughProxy ? (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_static) : qFlags(MTPDdcOption::Flag::f_media_only), - qFlags(MTPDdcOption::Flag::f_media_only), - throughProxy ? qFlags(MTPDdcOption::Flag::f_static) : MTPDdcOption::Flags(0), - MTPDdcOption::Flags(0), + throughProxy ? (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_media_only | 0), + (MTPDdcOption::Flag::f_media_only | 0), + throughProxy ? (MTPDdcOption::Flag::f_static | 0) : MTPDdcOption::Flags(0), + 0, }; } } break; @@ -467,18 +467,18 @@ DcOptions::Variants DcOptions::lookup(DcId dcId, DcType type) const { throughProxy ? (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_ipv6), throughProxy ? (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_ipv6), (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_ipv6), - throughProxy ? (MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : qFlags(MTPDdcOption::Flag::f_ipv6), + throughProxy ? (MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_ipv6 | 0), (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_ipv6), throughProxy ? (MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_ipv6), throughProxy ? (MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_ipv6) : (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_ipv6), - qFlags(MTPDdcOption::Flag::f_ipv6) + (MTPDdcOption::Flag::f_ipv6 | 0) }; case Variants::Http: return { // Media download HTTP IPv6 throughProxy ? (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_ipv6), (MTPDdcOption::Flag::f_media_only | MTPDdcOption::Flag::f_ipv6), - throughProxy ? (MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : qFlags(MTPDdcOption::Flag::f_ipv6), - qFlags(MTPDdcOption::Flag::f_ipv6), + throughProxy ? (MTPDdcOption::Flag::f_ipv6 | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_ipv6 | 0), + (MTPDdcOption::Flag::f_ipv6 | 0), }; } } break; @@ -491,14 +491,14 @@ DcOptions::Variants DcOptions::lookup(DcId dcId, DcType type) const { case Variants::Tcp: return { // CDN TCP IPv4 throughProxy ? (MTPDdcOption::Flag::f_cdn | MTPDdcOption::Flag::f_tcpo_only | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_cdn | MTPDdcOption::Flag::f_tcpo_only), - throughProxy ? (MTPDdcOption::Flag::f_cdn | MTPDdcOption::Flag::f_static) : qFlags(MTPDdcOption::Flag::f_cdn), + throughProxy ? (MTPDdcOption::Flag::f_cdn | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_cdn | 0), (MTPDdcOption::Flag::f_cdn | MTPDdcOption::Flag::f_tcpo_only), - qFlags(MTPDdcOption::Flag::f_cdn), + (MTPDdcOption::Flag::f_cdn | 0), }; case Variants::Http: return { // CDN HTTP IPv4 - throughProxy ? (MTPDdcOption::Flag::f_cdn | MTPDdcOption::Flag::f_static) : qFlags(MTPDdcOption::Flag::f_cdn), - qFlags(MTPDdcOption::Flag::f_cdn), + throughProxy ? (MTPDdcOption::Flag::f_cdn | MTPDdcOption::Flag::f_static) : (MTPDdcOption::Flag::f_cdn | 0), + (MTPDdcOption::Flag::f_cdn | 0), }; } } break; diff --git a/Telegram/SourceFiles/mtproto/type_utils.h b/Telegram/SourceFiles/mtproto/type_utils.h index 974e72bc3..b843ba618 100644 --- a/Telegram/SourceFiles/mtproto/type_utils.h +++ b/Telegram/SourceFiles/mtproto/type_utils.h @@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "scheme.h" +#include "base/flags.h" inline MTPbool MTP_bool(bool v) { return v ? MTP_boolTrue() : MTP_boolFalse(); @@ -36,18 +37,14 @@ inline bool mtpIsFalse(const MTPBool &v) { // we must validate that MTProto scheme flags don't intersect with client side flags // and define common bit operators which allow use Type_ClientFlag together with Type::Flag #define DEFINE_MTP_CLIENT_FLAGS(Type) \ -static_assert(static_cast(Type::Flag::MAX_FIELD) < static_cast(Type##_ClientFlag::MIN_FIELD), \ +static_assert(Type::Flags(Type::Flag::MAX_FIELD) < static_cast(Type##_ClientFlag::MIN_FIELD), \ "MTProto flags conflict with client side flags!"); \ -inline Type::Flags qFlags(Type##_ClientFlag v) { return Type::Flags(static_cast(v)); } \ -inline Type::Flags operator&(Type::Flags i, Type##_ClientFlag v) { return i & qFlags(v); } \ -inline Type::Flags operator&(Type##_ClientFlag i, Type##_ClientFlag v) { return qFlags(i) & v; } \ -inline Type::Flags &operator&=(Type::Flags &i, Type##_ClientFlag v) { return i &= qFlags(v); } \ -inline Type::Flags operator|(Type::Flags i, Type##_ClientFlag v) { return i | qFlags(v); } \ -inline Type::Flags operator|(Type::Flag i, Type##_ClientFlag v) { return i | qFlags(v); } \ -inline Type::Flags operator|(Type##_ClientFlag i, Type##_ClientFlag v) { return qFlags(i) | v; } \ -inline Type::Flags operator|(Type##_ClientFlag i, Type::Flag v) { return qFlags(i) | v; } \ -inline Type::Flags &operator|=(Type::Flags &i, Type##_ClientFlag v) { return i |= qFlags(v); } \ -inline Type::Flags operator~(Type##_ClientFlag v) { return ~qFlags(v); } +namespace base {\ + template<>\ + struct extended_flags {\ + using type = Type::Flag;\ + };\ +} // we use the same flags field for some additional client side flags enum class MTPDmessage_ClientFlag : int32 { diff --git a/Telegram/SourceFiles/observer_peer.h b/Telegram/SourceFiles/observer_peer.h index 19b4ce05c..4a72a48e0 100644 --- a/Telegram/SourceFiles/observer_peer.h +++ b/Telegram/SourceFiles/observer_peer.h @@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "base/observer.h" +#include "base/flags.h" namespace Notify { @@ -74,7 +75,9 @@ struct PeerUpdate { ChannelStickersChanged = 0x00040000U, ChannelPinnedChanged = 0x00080000U, }; - using Flags = QFlags; + using Flags = base::flags; + friend inline constexpr auto is_flag_type(Flag) { return true; } + Flags flags = 0; // NameChanged data @@ -85,7 +88,6 @@ struct PeerUpdate { int32 mediaTypesMask = 0; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(PeerUpdate::Flags); void peerUpdatedDelayed(const PeerUpdate &update); inline void peerUpdatedDelayed(PeerData *peer, PeerUpdate::Flags events) { diff --git a/Telegram/SourceFiles/platform/win/main_window_win.h b/Telegram/SourceFiles/platform/win/main_window_win.h index b080e20a6..510c41cde 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.h +++ b/Telegram/SourceFiles/platform/win/main_window_win.h @@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "platform/platform_main_window.h" +#include "base/flags.h" #include namespace Ui { @@ -60,7 +61,8 @@ public: Hidden = 0x08, Activate = 0x10, }; - using ShadowsChanges = QFlags; + using ShadowsChanges = base::flags; + friend inline constexpr auto is_flag_type(ShadowsChange) { return true; }; bool shadowsWorking() const { return _shadowsWorking; @@ -127,6 +129,4 @@ private: }; -Q_DECLARE_OPERATORS_FOR_FLAGS(MainWindow::ShadowsChanges); - } // namespace Platform diff --git a/Telegram/SourceFiles/settings/settings_layer.cpp b/Telegram/SourceFiles/settings/settings_layer.cpp index 180449c97..46b2b4635 100644 --- a/Telegram/SourceFiles/settings/settings_layer.cpp +++ b/Telegram/SourceFiles/settings/settings_layer.cpp @@ -89,7 +89,7 @@ void Layer::paintEvent(QPaintEvent *e) { auto paintTopRounded = clip.intersects(QRect(0, 0, width(), st::boxRadius)); auto paintBottomRounded = clip.intersects(QRect(0, height() - st::boxRadius, width(), st::boxRadius)); if (paintTopRounded || paintBottomRounded) { - auto parts = qFlags(RectPart::None); + auto parts = RectPart::None | 0; if (paintTopRounded) parts |= RectPart::FullTop; if (paintBottomRounded) parts |= RectPart::FullBottom; App::roundRect(p, rect(), st::boxBg, BoxCorners, nullptr, parts); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 95fe06e6c..4ec093408 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -36,6 +36,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "apiwrap.h" #include "auth_session.h" #include "window/window_controller.h" +#include "base/flags.h" #include @@ -78,8 +79,8 @@ enum class FileOption { User = 0x01, Safe = 0x02, }; -using FileOptions = QFlags; -Q_DECLARE_OPERATORS_FOR_FLAGS(FileOptions); +using FileOptions = base::flags; +inline constexpr auto is_flag_type(FileOption) { return true; }; bool keyAlreadyUsed(QString &name, FileOptions options = FileOption::User | FileOption::Safe) { name += '0'; @@ -3312,7 +3313,7 @@ void _readStickerSets(FileKey &stickersKey, Stickers::Order *outOrder = nullptr, return; } - bool readingInstalled = (readingFlags == qFlags(MTPDstickerSet::Flag::f_installed)); + bool readingInstalled = (readingFlags == MTPDstickerSet::Flag::f_installed); auto &sets = Global::RefStickerSets(); if (outOrder) outOrder->clear(); @@ -3329,16 +3330,19 @@ void _readStickerSets(FileKey &stickersKey, Stickers::Order *outOrder = nullptr, qint32 scnt = 0; stickers.stream >> setId >> setAccess >> setTitle >> setShortName >> scnt; - qint32 setHash = 0, setFlags = 0; + qint32 setHash = 0; + MTPDstickerSet::Flags setFlags = 0; if (stickers.version > 8033) { - stickers.stream >> setHash >> setFlags; - if (setFlags & qFlags(MTPDstickerSet_ClientFlag::f_not_loaded__old)) { - setFlags &= ~qFlags(MTPDstickerSet_ClientFlag::f_not_loaded__old); - setFlags |= qFlags(MTPDstickerSet_ClientFlag::f_not_loaded); + qint32 setFlagsValue = 0; + stickers.stream >> setHash >> setFlagsValue; + setFlags = MTPDstickerSet::Flags{ setFlagsValue }; + if (setFlags & MTPDstickerSet_ClientFlag::f_not_loaded__old) { + setFlags &= ~MTPDstickerSet_ClientFlag::f_not_loaded__old; + setFlags |= MTPDstickerSet_ClientFlag::f_not_loaded; } } if (readingInstalled && stickers.version < 9061) { - setFlags |= qFlags(MTPDstickerSet::Flag::f_installed); + setFlags |= MTPDstickerSet::Flag::f_installed; } if (setId == Stickers::DefaultSetId) { @@ -3349,13 +3353,13 @@ void _readStickerSets(FileKey &stickersKey, Stickers::Order *outOrder = nullptr, } } else if (setId == Stickers::CustomSetId) { setTitle = qsl("Custom stickers"); - setFlags |= qFlags(MTPDstickerSet_ClientFlag::f_special); + setFlags |= MTPDstickerSet_ClientFlag::f_special; } else if (setId == Stickers::CloudRecentSetId) { setTitle = lang(lng_recent_stickers); - setFlags |= qFlags(MTPDstickerSet_ClientFlag::f_special); + setFlags |= MTPDstickerSet_ClientFlag::f_special; } else if (setId == Stickers::FavedSetId) { setTitle = lang(lng_faved_stickers); - setFlags |= qFlags(MTPDstickerSet_ClientFlag::f_special); + setFlags |= MTPDstickerSet_ClientFlag::f_special; } else if (setId) { if (readingInstalled && outOrder && stickers.version < 9061) { outOrder->push_back(setId); @@ -3604,11 +3608,11 @@ void readInstalledStickers() { } Global::RefStickerSets().clear(); - _readStickerSets(_installedStickersKey, &Global::RefStickerSetsOrder(), qFlags(MTPDstickerSet::Flag::f_installed)); + _readStickerSets(_installedStickersKey, &Global::RefStickerSetsOrder(), MTPDstickerSet::Flag::f_installed); } void readFeaturedStickers() { - _readStickerSets(_featuredStickersKey, &Global::RefFeaturedStickerSetsOrder(), qFlags(MTPDstickerSet_ClientFlag::f_featured)); + _readStickerSets(_featuredStickersKey, &Global::RefFeaturedStickerSetsOrder(), MTPDstickerSet::Flags() | MTPDstickerSet_ClientFlag::f_featured); auto &sets = Global::StickerSets(); int unreadCount = 0; diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index e12bb504b..c9ee2856e 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -478,7 +478,7 @@ public: uint64 access = 0; - MTPDuser::Flags flags = { 0 }; + MTPDuser::Flags flags = 0; bool isVerified() const { return flags & MTPDuser::Flag::f_verified; } @@ -831,8 +831,8 @@ public: int32 date = 0; int version = 0; - MTPDchannel::Flags flags = { 0 }; - MTPDchannelFull::Flags flagsFull = { 0 }; + MTPDchannel::Flags flags = 0; + MTPDchannelFull::Flags flagsFull = 0; std::unique_ptr mgInfo; bool lastParticipantsCountOutdated() const { if (!mgInfo || !(mgInfo->lastParticipantsStatus & MegagroupInfo::LastParticipantsCountOutdated)) { diff --git a/Telegram/SourceFiles/ui/abstract_button.h b/Telegram/SourceFiles/ui/abstract_button.h index 657280b43..e8a21379f 100644 --- a/Telegram/SourceFiles/ui/abstract_button.h +++ b/Telegram/SourceFiles/ui/abstract_button.h @@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #pragma once #include "ui/twidget.h" +#include "base/flags.h" namespace Ui { @@ -80,8 +81,7 @@ protected: Down = 0x02, Disabled = 0x04, }; - using State = QFlags; - Q_DECLARE_FRIEND_OPERATORS_FOR_FLAGS(State); + using State = base::flags; State state() const { return _state; @@ -111,6 +111,4 @@ private: }; -Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractButton::State); - } // namespace Ui diff --git a/Telegram/SourceFiles/ui/images.cpp b/Telegram/SourceFiles/ui/images.cpp index 73d4a975a..a0e892f69 100644 --- a/Telegram/SourceFiles/ui/images.cpp +++ b/Telegram/SourceFiles/ui/images.cpp @@ -295,16 +295,16 @@ QImage prepareOpaque(QImage image) { QImage prepare(QImage img, int w, int h, Images::Options options, int outerw, int outerh, const style::color *colored) { Assert(!img.isNull()); - if (options.testFlag(Images::Option::Blurred)) { + if (options & Images::Option::Blurred) { img = prepareBlur(std::move(img)); Assert(!img.isNull()); } if (w <= 0 || (w == img.width() && (h <= 0 || h == img.height()))) { } else if (h <= 0) { - img = img.scaledToWidth(w, options.testFlag(Images::Option::Smooth) ? Qt::SmoothTransformation : Qt::FastTransformation); + img = img.scaledToWidth(w, (options & Images::Option::Smooth) ? Qt::SmoothTransformation : Qt::FastTransformation); Assert(!img.isNull()); } else { - img = img.scaled(w, h, Qt::IgnoreAspectRatio, options.testFlag(Images::Option::Smooth) ? Qt::SmoothTransformation : Qt::FastTransformation); + img = img.scaled(w, h, Qt::IgnoreAspectRatio, (options & Images::Option::Smooth) ? Qt::SmoothTransformation : Qt::FastTransformation); Assert(!img.isNull()); } if (outerw > 0 && outerh > 0) { @@ -329,22 +329,22 @@ QImage prepare(QImage img, int w, int h, Images::Options options, int outerw, in } } auto corners = [](Images::Options options) { - return (options.testFlag(Images::Option::RoundedTopLeft) ? ImageRoundCorner::TopLeft : ImageRoundCorner::None) - | (options.testFlag(Images::Option::RoundedTopRight) ? ImageRoundCorner::TopRight : ImageRoundCorner::None) - | (options.testFlag(Images::Option::RoundedBottomLeft) ? ImageRoundCorner::BottomLeft : ImageRoundCorner::None) - | (options.testFlag(Images::Option::RoundedBottomRight) ? ImageRoundCorner::BottomRight : ImageRoundCorner::None); + return ((options & Images::Option::RoundedTopLeft) ? ImageRoundCorner::TopLeft : ImageRoundCorner::None) + | ((options & Images::Option::RoundedTopRight) ? ImageRoundCorner::TopRight : ImageRoundCorner::None) + | ((options & Images::Option::RoundedBottomLeft) ? ImageRoundCorner::BottomLeft : ImageRoundCorner::None) + | ((options & Images::Option::RoundedBottomRight) ? ImageRoundCorner::BottomRight : ImageRoundCorner::None); }; - if (options.testFlag(Images::Option::Circled)) { + if (options & Images::Option::Circled) { prepareCircle(img); Assert(!img.isNull()); - } else if (options.testFlag(Images::Option::RoundedLarge)) { + } else if (options & Images::Option::RoundedLarge) { prepareRound(img, ImageRoundRadius::Large, corners(options)); Assert(!img.isNull()); - } else if (options.testFlag(Images::Option::RoundedSmall)) { + } else if (options & Images::Option::RoundedSmall) { prepareRound(img, ImageRoundRadius::Small, corners(options)); Assert(!img.isNull()); } - if (options.testFlag(Images::Option::Colored)) { + if (options & Images::Option::Colored) { Assert(colored != nullptr); img = prepareColored(*colored, std::move(img)); } @@ -729,19 +729,19 @@ QPixmap Image::pixNoCache(int w, int h, Images::Options options, int outerw, int } auto corners = [](Images::Options options) { - return (options.testFlag(Images::Option::RoundedTopLeft) ? ImageRoundCorner::TopLeft : ImageRoundCorner::None) - | (options.testFlag(Images::Option::RoundedTopRight) ? ImageRoundCorner::TopRight : ImageRoundCorner::None) - | (options.testFlag(Images::Option::RoundedBottomLeft) ? ImageRoundCorner::BottomLeft : ImageRoundCorner::None) - | (options.testFlag(Images::Option::RoundedBottomRight) ? ImageRoundCorner::BottomRight : ImageRoundCorner::None); + return ((options & Images::Option::RoundedTopLeft) ? ImageRoundCorner::TopLeft : ImageRoundCorner::None) + | ((options & Images::Option::RoundedTopRight) ? ImageRoundCorner::TopRight : ImageRoundCorner::None) + | ((options & Images::Option::RoundedBottomLeft) ? ImageRoundCorner::BottomLeft : ImageRoundCorner::None) + | ((options & Images::Option::RoundedBottomRight) ? ImageRoundCorner::BottomRight : ImageRoundCorner::None); }; - if (options.testFlag(Images::Option::Circled)) { + if (options & Images::Option::Circled) { Images::prepareCircle(result); - } else if (options.testFlag(Images::Option::RoundedLarge)) { + } else if (options & Images::Option::RoundedLarge) { Images::prepareRound(result, ImageRoundRadius::Large, corners(options)); - } else if (options.testFlag(Images::Option::RoundedSmall)) { + } else if (options & Images::Option::RoundedSmall) { Images::prepareRound(result, ImageRoundRadius::Small, corners(options)); } - if (options.testFlag(Images::Option::Colored)) { + if (options & Images::Option::Colored) { Assert(colored != nullptr); result = Images::prepareColored(*colored, std::move(result)); } diff --git a/Telegram/SourceFiles/ui/images.h b/Telegram/SourceFiles/ui/images.h index f9c5809f0..8ae456dbe 100644 --- a/Telegram/SourceFiles/ui/images.h +++ b/Telegram/SourceFiles/ui/images.h @@ -20,6 +20,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once +#include "base/flags.h" + class FileLoader; class mtpFileLoader; @@ -47,8 +49,8 @@ enum class ImageRoundCorner { BottomRight = 0x08, All = 0x0f, }; -using ImageRoundCorners = QFlags; -Q_DECLARE_OPERATORS_FOR_FLAGS(ImageRoundCorners); +using ImageRoundCorners = base::flags; +inline constexpr auto is_flag_type(ImageRoundCorner) { return true; }; inline uint32 packInt(int32 a) { return (a < 0) ? uint32(int64(a) + 0x100000000LL) : uint32(a); @@ -199,8 +201,8 @@ enum class Option { Colored = 0x200, TransparentBackground = 0x400, }; -using Options = QFlags