Replace QFlags with base::flags.

This commit is contained in:
John Preston 2017-08-31 19:28:58 +03:00
parent a1344e862a
commit df64c972d8
38 changed files with 189 additions and 210 deletions

View file

@ -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) {

View file

@ -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<RegExOption>;
Q_DECLARE_OPERATORS_FOR_FLAGS(RegExOptions);
using RegExOptions = base::flags<RegExOption>;
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<int>(options));

View file

@ -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);

View file

@ -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;
}

View file

@ -242,7 +242,7 @@ void SetIsFaved(not_null<DocumentData*> document, base::optional<std::vector<not
auto &sets = Global::RefStickerSets();
auto it = sets.find(FavedSetId);
if (it == sets.end()) {
it = sets.insert(FavedSetId, Set(FavedSetId, 0, lang(lng_faved_stickers), QString(), 0, 0, qFlags(MTPDstickerSet_ClientFlag::f_special)));
it = sets.insert(FavedSetId, Set(FavedSetId, 0, lang(lng_faved_stickers), QString(), 0, 0, MTPDstickerSet_ClientFlag::f_special | 0));
}
auto index = it->stickers.indexOf(document);
if (index == 0) {
@ -436,7 +436,7 @@ void SpecialSetReceived(uint64 setId, const QString &setTitle, const QVector<MTP
}
} else {
if (it == sets.cend()) {
it = sets.insert(setId, Set(setId, 0, setTitle, QString(), 0, 0, qFlags(MTPDstickerSet_ClientFlag::f_special)));
it = sets.insert(setId, Set(setId, 0, setTitle, QString(), 0, 0, MTPDstickerSet_ClientFlag::f_special | 0));
} else {
it->title = setTitle;
}

View file

@ -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;
}

View file

@ -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<Flag>;\n';
funcsText += '\tfriend inline Flags operator~(Flag v) { return QFlag(~static_cast<int32>(v)); }\n';
funcsText += '\tusing Flags = base::flags<Flag>;\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 <typename TQueryType>\n';
funcsText += 'using MTP' + Name + ' = MTPBoxed<MTP' + name + '<TQueryType>>;\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<Flag>;\n';
dataText += '\tfriend inline Flags operator~(Flag v) { return QFlag(~static_cast<int32>(v)); }\n';
dataText += '\tusing Flags = base::flags<Flag>;\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\

View file

@ -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<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) Q_DECL_NOTHROW; \
friend Q_DECL_CONSTEXPR QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> 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<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2); \
friend Q_DECL_CONSTEXPR QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2); \
Q_DECLARE_FRIEND_INCOMPATIBLE_FLAGS(Flags)
#endif // OS_MAC_OLD

View file

@ -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<Container> 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 <typename Enum>
inline constexpr QFlags<Enum> qFlags(Enum v) {
return QFlags<Enum>(v);
}
template <typename Lambda>
inline void InvokeQueued(QObject *context, Lambda &&lambda) {
QObject proxy;
@ -581,8 +577,8 @@ enum ShowLayerOption {
AnimatedShowLayer = 0x00,
ForceFastShowLayer = 0x04,
};
using ShowLayerOptions = QFlags<ShowLayerOption>;
Q_DECLARE_OPERATORS_FOR_FLAGS(ShowLayerOptions);
using ShowLayerOptions = base::flags<ShowLayerOption>;
inline constexpr auto is_flag_type(ShowLayerOption) { return true; };
static int32 FullArcLength = 360 * 16;
static int32 QuarterArcLength = (FullArcLength / 4);

View file

@ -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<UpdateRowSection>;
Q_DECLARE_FRIEND_OPERATORS_FOR_FLAGS(UpdateRowSections);
using UpdateRowSections = base::flags<UpdateRowSection>;
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<void()> _loadMoreCallback;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(DialogsInner::UpdateRowSections);

View file

@ -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<Flag>;
Q_DECL_CONSTEXPR friend inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) noexcept {
return QFlags<Flags::enum_type>(f1) | f2;
}
Q_DECL_CONSTEXPR friend inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept {
return f2 | f1;
}
Q_DECL_CONSTEXPR friend inline QFlags<Flags::enum_type> operator~(Flags::enum_type f) noexcept {
return ~QFlags<Flags::enum_type>(f);
}
Flags _flags = { 0 };
using Flags = base::flags<Flag>;
friend inline constexpr auto is_flag_type(Flag) { return true; };
Flags _flags = 0;
bool _mute = false;
int _unreadCount = 0;

View file

@ -557,6 +557,8 @@ HistoryMessageLogEntryOriginal &HistoryMessageLogEntryOriginal::operator=(Histor
HistoryMessageLogEntryOriginal::~HistoryMessageLogEntryOriginal() = default;
HistoryMediaPtr::HistoryMediaPtr() = default;
HistoryMediaPtr::HistoryMediaPtr(std::unique_ptr<HistoryMedia> pointer) : _pointer(std::move(pointer)) {
if (_pointer) {
_pointer->attachToParent();

View file

@ -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<HistoryMessageReply> {
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<PaintFlag>;
using PaintFlags = base::flags<PaintFlag>;
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<HistoryMessageReply> {
std::unique_ptr<HistoryMessageVia> _replyToVia;
int toWidth = 0;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(HistoryMessageReply::PaintFlags);
class ReplyKeyboard;
struct HistoryMessageReplyMarkup : public RuntimeComponent<HistoryMessageReplyMarkup> {
@ -433,7 +434,7 @@ struct HistoryMessageLogEntryOriginal : public RuntimeComponent<HistoryMessageLo
class HistoryMedia;
class HistoryMediaPtr {
public:
HistoryMediaPtr() = default;
HistoryMediaPtr();
HistoryMediaPtr(const HistoryMediaPtr &other) = delete;
HistoryMediaPtr &operator=(const HistoryMediaPtr &other) = delete;
HistoryMediaPtr(std::unique_ptr<HistoryMedia> 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;

View file

@ -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);
}

View file

@ -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<HistoryMessageReply>()) {
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);

View file

@ -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;

View file

@ -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<TextUpdateEvent>;
Q_DECLARE_FRIEND_OPERATORS_FOR_FLAGS(TextUpdateEvents);
using TextUpdateEvents = base::flags<TextUpdateEvent>;
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)

View file

@ -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<StateFlag>;
using StateFlags = base::flags<StateFlag>;
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;

View file

@ -158,7 +158,7 @@ private:
}
}
QFlags<QIODevice::OpenModeFlag> 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

View file

@ -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);
}

View file

@ -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<BoxContent> 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<BoxContent> 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();
}
}

View file

@ -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 <typename Flags>
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 <typename T>
friend MTPflags<QFlags<T>> MTP_flags(QFlags<T> v);
friend MTPflags<base::flags<T>> MTP_flags(base::flags<T> v);
template <typename T, typename>
friend MTPflags<QFlags<T>> MTP_flags(T v);
friend MTPflags<base::flags<T>> MTP_flags(T v);
};
template <typename T>
inline MTPflags<QFlags<T>> MTP_flags(QFlags<T> v) {
return MTPflags<QFlags<T>>(v);
inline MTPflags<base::flags<T>> MTP_flags(base::flags<T> v) {
return MTPflags<base::flags<T>>(v);
}
template <typename T, typename = std::enable_if_t<!std::is_same<T, int>::value>>
inline MTPflags<QFlags<T>> MTP_flags(T v) {
return MTPflags<QFlags<T>>(v);
inline MTPflags<base::flags<T>> MTP_flags(T v) {
return MTPflags<base::flags<T>>(v);
}
inline internal::ZeroFlagsHelper MTP_flags(void(internal::ZeroFlagsHelper::*)()) {

View file

@ -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;

View file

@ -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<int32>(Type::Flag::MAX_FIELD) < static_cast<int32>(Type##_ClientFlag::MIN_FIELD), \
static_assert(Type::Flags(Type::Flag::MAX_FIELD) < static_cast<Type::Flag>(Type##_ClientFlag::MIN_FIELD), \
"MTProto flags conflict with client side flags!"); \
inline Type::Flags qFlags(Type##_ClientFlag v) { return Type::Flags(static_cast<int32>(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<Type##_ClientFlag> {\
using type = Type::Flag;\
};\
}
// we use the same flags field for some additional client side flags
enum class MTPDmessage_ClientFlag : int32 {

View file

@ -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<Flag>;
using Flags = base::flags<Flag>;
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) {

View file

@ -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 <windows.h>
namespace Ui {
@ -60,7 +61,8 @@ public:
Hidden = 0x08,
Activate = 0x10,
};
using ShadowsChanges = QFlags<ShadowsChange>;
using ShadowsChanges = base::flags<ShadowsChange>;
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

View file

@ -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);

View file

@ -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 <openssl/evp.h>
@ -78,8 +79,8 @@ enum class FileOption {
User = 0x01,
Safe = 0x02,
};
using FileOptions = QFlags<FileOption>;
Q_DECLARE_OPERATORS_FOR_FLAGS(FileOptions);
using FileOptions = base::flags<FileOption>;
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;

View file

@ -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<MegagroupInfo> mgInfo;
bool lastParticipantsCountOutdated() const {
if (!mgInfo || !(mgInfo->lastParticipantsStatus & MegagroupInfo::LastParticipantsCountOutdated)) {

View file

@ -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<StateFlag>;
Q_DECLARE_FRIEND_OPERATORS_FOR_FLAGS(State);
using State = base::flags<StateFlag>;
State state() const {
return _state;
@ -111,6 +111,4 @@ private:
};
Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractButton::State);
} // namespace Ui

View file

@ -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));
}

View file

@ -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<ImageRoundCorner>;
Q_DECLARE_OPERATORS_FOR_FLAGS(ImageRoundCorners);
using ImageRoundCorners = base::flags<ImageRoundCorner>;
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<Option>;
Q_DECLARE_OPERATORS_FOR_FLAGS(Options);
using Options = base::flags<Option>;
inline constexpr auto is_flag_type(Option) { return true; };
QImage prepare(QImage img, int w, int h, Options options, int outerw, int outerh, const style::color *colored = nullptr);

View file

@ -25,6 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "core/click_handler.h"
#include "ui/text/text_entity.h"
#include "ui/emoji_config.h"
#include "base/flags.h"
static const QChar TextCommand(0x0010);
enum TextCommands {
@ -132,7 +133,8 @@ public:
LookupSymbol = 0x02,
LookupLink = 0x04,
};
using Flags = QFlags<Flag>;
using Flags = base::flags<Flag>;
friend inline constexpr auto is_flag_type(Flag) { return true; };
StateRequest() {
}

View file

@ -20,6 +20,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#pragma once
#include "base/flags.h"
namespace Fonts {
void Start();
@ -57,8 +59,8 @@ enum class RectPart {
Full = FullTop | NoTop,
};
using RectParts = QFlags<RectPart>;
Q_DECLARE_OPERATORS_FOR_FLAGS(RectParts);
using RectParts = base::flags<RectPart>;
inline constexpr auto is_flag_type(RectPart) { return true; };
inline bool IsTopCorner(RectPart corner) {
return (corner == RectPart::TopLeft) || (corner == RectPart::TopRight);

View file

@ -42,8 +42,8 @@ void Controller::enableGifPauseReason(GifPauseReason reason) {
void Controller::disableGifPauseReason(GifPauseReason reason) {
if (_gifPauseReasons & reason) {
_gifPauseReasons &= ~qFlags(reason);
if (static_cast<int>(_gifPauseReasons) < static_cast<int>(reason)) {
_gifPauseReasons &= ~reason;
if (_gifPauseReasons < reason) {
_gifPauseLevelChanged.notify();
}
}

View file

@ -20,6 +20,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#pragma once
#include "base/flags.h"
namespace Window {
enum class GifPauseReason {
@ -30,8 +32,8 @@ enum class GifPauseReason {
RoundPlaying = (1 << 3),
MediaPreview = (1 << 4),
};
using GifPauseReasons = QFlags<GifPauseReason>;
Q_DECLARE_OPERATORS_FOR_FLAGS(GifPauseReasons);
using GifPauseReasons = base::flags<GifPauseReason>;
inline constexpr bool is_flag_type(GifPauseReason) { return true; };
class MainWindow;
@ -107,7 +109,7 @@ private:
base::Observable<PeerData*> _searchInPeerChanged;
base::Observable<PeerData*> _historyPeerChanged;
GifPauseReasons _gifPauseReasons = { 0 };
GifPauseReasons _gifPauseReasons = 0;
base::Observable<void> _gifPauseLevelChanged;
base::Observable<void> _floatPlayerAreaUpdated;

View file

@ -36,6 +36,7 @@
'ProgramDataBaseFileName': '$(OutDir)\\$(ProjectName).pdb',
'DebugInformationFormat': '3', # Program Database (/Zi)
'AdditionalOptions': [
'/std:c++latest',
'/MP', # Enable multi process build.
'/EHsc', # Catch C++ exceptions only, extern C functions never throw a C++ exception.
'/WX', # Treat warnings as errors.

View file

@ -1,6 +1,7 @@
<(src_loc)/base/algorithm.h
<(src_loc)/base/assertion.h
<(src_loc)/base/build_config.h
<(src_loc)/base/flags.h
<(src_loc)/base/flat_map.h
<(src_loc)/base/flat_set.h
<(src_loc)/base/lambda.h