From 656e4869e6e8dd7d31c8eb68ff065fc8c596080f Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 17 Dec 2017 15:04:47 +0400 Subject: [PATCH] Move UnreadBadge to ui/unread_badge. --- .../history/history_top_bar_widget.cpp | 40 +------------- .../history/history_top_bar_widget.h | 5 +- Telegram/SourceFiles/ui/unread_badge.cpp | 52 +++++++++++++++++++ Telegram/SourceFiles/ui/unread_badge.h | 42 +++++++++++++++ Telegram/gyp/telegram_sources.txt | 2 + 5 files changed, 99 insertions(+), 42 deletions(-) create mode 100644 Telegram/SourceFiles/ui/unread_badge.cpp create mode 100644 Telegram/SourceFiles/ui/unread_badge.h diff --git a/Telegram/SourceFiles/history/history_top_bar_widget.cpp b/Telegram/SourceFiles/history/history_top_bar_widget.cpp index 13431eb2a..49c4bc8ca 100644 --- a/Telegram/SourceFiles/history/history_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/history_top_bar_widget.cpp @@ -37,9 +37,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "auth_session.h" #include "lang/lang_keys.h" #include "ui/special_buttons.h" +#include "ui/unread_badge.h" #include "ui/widgets/buttons.h" #include "ui/widgets/dropdown_menu.h" -#include "dialogs/dialogs_layout.h" #include "window/window_controller.h" #include "window/window_peer_menu.h" #include "calls/calls_instance.h" @@ -47,44 +47,6 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "observer_peer.h" #include "apiwrap.h" -class HistoryTopBarWidget::UnreadBadge : public Ui::RpWidget { -public: - using RpWidget::RpWidget; - - void setText(const QString &text, bool active) { - _text = text; - _active = active; - update(); - } - -protected: - void paintEvent(QPaintEvent *e) override; - -private: - QString _text; - bool _active = false; - -}; - -void HistoryTopBarWidget::UnreadBadge::paintEvent(QPaintEvent *e) { - if (_text.isEmpty()) { - return; - } - - Painter p(this); - - Dialogs::Layout::UnreadBadgeStyle unreadSt; - unreadSt.muted = !_active; - auto unreadRight = width(); - auto unreadTop = 0; - Dialogs::Layout::paintUnreadCount( - p, - _text, - unreadRight, - unreadTop, - unreadSt); -} - HistoryTopBarWidget::HistoryTopBarWidget( QWidget *parent, not_null controller) diff --git a/Telegram/SourceFiles/history/history_top_bar_widget.h b/Telegram/SourceFiles/history/history_top_bar_widget.h index 05da56f3a..995659708 100644 --- a/Telegram/SourceFiles/history/history_top_bar_widget.h +++ b/Telegram/SourceFiles/history/history_top_bar_widget.h @@ -28,6 +28,7 @@ class UserpicButton; class RoundButton; class IconButton; class DropdownMenu; +class UnreadBadge; } // namespace Ui namespace Window { @@ -69,8 +70,6 @@ protected: bool eventFilter(QObject *obj, QEvent *e) override; private: - class UnreadBadge; - void refreshLang(); void updateControlsGeometry(); void selectedShowCallback(); @@ -113,7 +112,7 @@ private: object_ptr _forward, _delete; object_ptr _back; - object_ptr _unreadBadge = { nullptr }; + object_ptr _unreadBadge = { nullptr }; object_ptr _info = { nullptr }; object_ptr _call; diff --git a/Telegram/SourceFiles/ui/unread_badge.cpp b/Telegram/SourceFiles/ui/unread_badge.cpp new file mode 100644 index 000000000..b9d708026 --- /dev/null +++ b/Telegram/SourceFiles/ui/unread_badge.cpp @@ -0,0 +1,52 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org +*/ +#include "ui/unread_badge.h" + +#include "dialogs/dialogs_layout.h" + +namespace Ui { + +void UnreadBadge::setText(const QString &text, bool active) { + _text = text; + _active = active; + update(); +} + +void UnreadBadge::paintEvent(QPaintEvent *e) { + if (_text.isEmpty()) { + return; + } + + Painter p(this); + + Dialogs::Layout::UnreadBadgeStyle unreadSt; + unreadSt.muted = !_active; + auto unreadRight = width(); + auto unreadTop = 0; + Dialogs::Layout::paintUnreadCount( + p, + _text, + unreadRight, + unreadTop, + unreadSt); +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/unread_badge.h b/Telegram/SourceFiles/ui/unread_badge.h new file mode 100644 index 000000000..0621e73a7 --- /dev/null +++ b/Telegram/SourceFiles/ui/unread_badge.h @@ -0,0 +1,42 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org +*/ +#pragma once + +#include "ui/rp_widget.h" + +namespace Ui { + +class UnreadBadge : public RpWidget { +public: + using RpWidget::RpWidget; + + void setText(const QString &text, bool active); + +protected: + void paintEvent(QPaintEvent *e) override; + +private: + QString _text; + bool _active = false; + +}; + +} // namespace Ui diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index f69d23cc4..f8b7f5955 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -622,6 +622,8 @@ <(src_loc)/ui/special_buttons.h <(src_loc)/ui/twidget.cpp <(src_loc)/ui/twidget.h +<(src_loc)/ui/unread_badge.cpp +<(src_loc)/ui/unread_badge.h <(src_loc)/window/layer_widget.cpp <(src_loc)/window/layer_widget.h <(src_loc)/window/main_window.cpp