Move UnreadBadge to ui/unread_badge.

This commit is contained in:
John Preston 2017-12-17 15:04:47 +04:00
parent defec611e3
commit 656e4869e6
5 changed files with 99 additions and 42 deletions

View File

@ -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<Window::Controller*> controller)

View File

@ -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<Ui::RoundButton> _forward, _delete;
object_ptr<Ui::IconButton> _back;
object_ptr<UnreadBadge> _unreadBadge = { nullptr };
object_ptr<Ui::UnreadBadge> _unreadBadge = { nullptr };
object_ptr<Ui::UserpicButton> _info = { nullptr };
object_ptr<Ui::IconButton> _call;

View File

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

View File

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

View File

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