2016-10-02 09:30:28 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-10-02 09:30:28 +00:00
|
|
|
*/
|
2016-10-02 13:54:27 +00:00
|
|
|
#include "window/notifications_manager_default.h"
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
#include "platform/platform_notifications_manager.h"
|
2021-01-10 03:52:18 +00:00
|
|
|
#include "platform/platform_specific.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "ui/platform/ui_platform_utility.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "ui/text/text_options.h"
|
2019-08-28 18:20:49 +00:00
|
|
|
#include "ui/emoji_config.h"
|
|
|
|
#include "ui/empty_userpic.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2016-10-02 09:30:28 +00:00
|
|
|
#include "dialogs/dialogs_layout.h"
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2021-02-25 15:12:51 +00:00
|
|
|
#include "window/window_controller.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "storage/file_download.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-07-01 08:03:34 +00:00
|
|
|
#include "main/main_account.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/history_item.h"
|
2020-10-29 19:56:13 +00:00
|
|
|
#include "base/platform/base_platform_last_input.h"
|
2019-09-26 10:55:35 +00:00
|
|
|
#include "base/call_delayed.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
|
|
|
#include "app.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
|
|
|
#include "styles/style_layers.h"
|
|
|
|
#include "styles/style_window.h"
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2021-02-25 15:12:51 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
#include <QtGui/QScreen>
|
2019-09-04 07:19:15 +00:00
|
|
|
|
2016-10-02 09:30:28 +00:00
|
|
|
namespace Window {
|
|
|
|
namespace Notifications {
|
2016-10-02 13:54:27 +00:00
|
|
|
namespace Default {
|
|
|
|
namespace {
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
int notificationMaxHeight() {
|
|
|
|
return st::notifyMinHeight + st::notifyReplyArea.heightMax + st::notifyBorderWidth;
|
|
|
|
}
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
QPoint notificationStartPosition() {
|
2020-06-18 18:04:16 +00:00
|
|
|
const auto corner = Core::App().settings().notificationsCorner();
|
2021-02-25 15:12:51 +00:00
|
|
|
const auto window = Core::App().activeWindow();
|
|
|
|
const auto r = window
|
|
|
|
? window->widget()->desktopRect()
|
|
|
|
: QGuiApplication::primaryScreen()->availableGeometry();
|
2020-06-18 18:04:16 +00:00
|
|
|
const auto isLeft = Core::Settings::IsLeftCorner(corner);
|
|
|
|
const auto isTop = Core::Settings::IsTopCorner(corner);
|
|
|
|
const auto x = (isLeft == rtl()) ? (r.x() + r.width() - st::notifyWidth - st::notifyDeltaX) : (r.x() + st::notifyDeltaX);
|
|
|
|
const auto y = isTop ? r.y() : (r.y() + r.height());
|
2016-10-06 16:41:09 +00:00
|
|
|
return QPoint(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal::Widget::Direction notificationShiftDirection() {
|
2020-06-18 18:04:16 +00:00
|
|
|
auto isTop = Core::Settings::IsTopCorner(Core::App().settings().notificationsCorner());
|
2016-10-06 16:41:09 +00:00
|
|
|
return isTop ? internal::Widget::Direction::Down : internal::Widget::Direction::Up;
|
|
|
|
}
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
} // namespace
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
std::unique_ptr<Manager> Create(System *system) {
|
|
|
|
return std::make_unique<Manager>(system);
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 11:26:43 +00:00
|
|
|
Manager::Manager(System *system)
|
|
|
|
: Notifications::Manager(system)
|
|
|
|
, _inputCheckTimer([=] { checkLastInput(); }) {
|
2021-05-25 13:51:59 +00:00
|
|
|
system->settingsChanged(
|
|
|
|
) | rpl::start_with_next([=](ChangeType change) {
|
2016-10-06 16:41:09 +00:00
|
|
|
settingsChanged(change);
|
2021-05-25 13:51:59 +00:00
|
|
|
}, system->lifetime());
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
Manager::QueuedNotification::QueuedNotification(
|
2019-08-28 14:24:12 +00:00
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
int forwardedCount)
|
2018-01-11 19:33:26 +00:00
|
|
|
: history(item->history())
|
|
|
|
, peer(history->peer)
|
2019-08-28 14:24:12 +00:00
|
|
|
, author(item->notificationHeader())
|
2018-01-11 19:33:26 +00:00
|
|
|
, item((forwardedCount < 2) ? item.get() : nullptr)
|
2019-08-28 14:24:12 +00:00
|
|
|
, forwardedCount(forwardedCount)
|
2019-08-28 18:20:49 +00:00
|
|
|
, fromScheduled((item->out() || peer->isSelf()) && item->isFromScheduled()) {
|
2018-01-11 19:33:26 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
QPixmap Manager::hiddenUserpicPlaceholder() const {
|
|
|
|
if (_hiddenUserpicPlaceholder.isNull()) {
|
2019-01-21 13:42:21 +00:00
|
|
|
_hiddenUserpicPlaceholder = App::pixmapFromImageInPlace(Core::App().logoNoMargin().scaled(st::notifyPhotoSize, st::notifyPhotoSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
2017-05-12 15:27:19 +00:00
|
|
|
_hiddenUserpicPlaceholder.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
|
|
|
return _hiddenUserpicPlaceholder;
|
|
|
|
}
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
bool Manager::hasReplyingNotification() const {
|
2017-03-04 19:36:59 +00:00
|
|
|
for_const (auto ¬ification, _notifications) {
|
2016-10-06 16:41:09 +00:00
|
|
|
if (notification->isReplying()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
void Manager::settingsChanged(ChangeType change) {
|
|
|
|
if (change == ChangeType::Corner) {
|
2016-10-06 16:41:09 +00:00
|
|
|
auto startPosition = notificationStartPosition();
|
|
|
|
auto shiftDirection = notificationShiftDirection();
|
2017-03-04 19:36:59 +00:00
|
|
|
for_const (auto ¬ification, _notifications) {
|
2016-10-06 16:41:09 +00:00
|
|
|
notification->updatePosition(startPosition, shiftDirection);
|
|
|
|
}
|
|
|
|
if (_hideAll) {
|
|
|
|
_hideAll->updatePosition(startPosition, shiftDirection);
|
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
} else if (change == ChangeType::MaxCount) {
|
2020-06-18 18:04:16 +00:00
|
|
|
int allow = Core::App().settings().notificationsCount();
|
2016-10-06 16:41:09 +00:00
|
|
|
for (int i = _notifications.size(); i != 0;) {
|
2017-03-04 19:36:59 +00:00
|
|
|
auto ¬ification = _notifications[--i];
|
2016-10-06 16:41:09 +00:00
|
|
|
if (notification->isUnlinked()) continue;
|
|
|
|
if (--allow < 0) {
|
|
|
|
notification->unlinkHistory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (allow > 0) {
|
|
|
|
for (int i = 0; i != allow; ++i) {
|
|
|
|
showNextFromQueue();
|
|
|
|
}
|
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
} else if (change == ChangeType::DemoIsShown) {
|
2016-10-06 16:41:09 +00:00
|
|
|
auto demoIsShown = Global::NotificationsDemoIsShown();
|
|
|
|
_demoMasterOpacity.start([this] { demoMasterOpacityCallback(); }, demoIsShown ? 1. : 0., demoIsShown ? 0. : 1., st::notifyFastAnim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::demoMasterOpacityCallback() {
|
2017-03-04 19:36:59 +00:00
|
|
|
for_const (auto ¬ification, _notifications) {
|
2016-10-06 16:41:09 +00:00
|
|
|
notification->updateOpacity();
|
|
|
|
}
|
|
|
|
if (_hideAll) {
|
|
|
|
_hideAll->updateOpacity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 Manager::demoMasterOpacity() const {
|
2019-04-02 09:13:30 +00:00
|
|
|
return _demoMasterOpacity.value(Global::NotificationsDemoIsShown() ? 0. : 1.);
|
2016-10-06 16:41:09 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Manager::checkLastInput() {
|
2016-10-06 16:41:09 +00:00
|
|
|
auto replying = hasReplyingNotification();
|
2016-10-05 16:56:27 +00:00
|
|
|
auto waiting = false;
|
2017-03-04 19:36:59 +00:00
|
|
|
for_const (auto ¬ification, _notifications) {
|
2016-10-06 16:41:09 +00:00
|
|
|
if (!notification->checkLastInput(replying)) {
|
2016-10-05 16:56:27 +00:00
|
|
|
waiting = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (waiting) {
|
2019-01-18 11:26:43 +00:00
|
|
|
_inputCheckTimer.callOnce(300);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::startAllHiding() {
|
2016-10-06 16:41:09 +00:00
|
|
|
if (!hasReplyingNotification()) {
|
2016-10-05 16:56:27 +00:00
|
|
|
int notHidingCount = 0;
|
2017-03-04 19:36:59 +00:00
|
|
|
for_const (auto ¬ification, _notifications) {
|
2016-10-05 16:56:27 +00:00
|
|
|
if (notification->isShowing()) {
|
|
|
|
++notHidingCount;
|
|
|
|
} else {
|
|
|
|
notification->startHiding();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
notHidingCount += _queuedNotifications.size();
|
|
|
|
if (_hideAll && notHidingCount < 2) {
|
|
|
|
_hideAll->startHiding();
|
|
|
|
}
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::stopAllHiding() {
|
2017-03-04 19:36:59 +00:00
|
|
|
for_const (auto ¬ification, _notifications) {
|
2016-10-05 16:56:27 +00:00
|
|
|
notification->stopHiding();
|
|
|
|
}
|
|
|
|
if (_hideAll) {
|
|
|
|
_hideAll->stopHiding();
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::showNextFromQueue() {
|
2017-08-13 16:16:48 +00:00
|
|
|
auto guard = gsl::finally([this] {
|
2017-03-04 19:36:59 +00:00
|
|
|
if (_positionsOutdated) {
|
|
|
|
moveWidgets();
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
});
|
|
|
|
if (_queuedNotifications.empty()) {
|
|
|
|
return;
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
2020-06-18 18:04:16 +00:00
|
|
|
int count = Core::App().settings().notificationsCount();
|
2020-06-30 15:33:22 +00:00
|
|
|
for (const auto ¬ification : _notifications) {
|
2017-03-04 19:36:59 +00:00
|
|
|
if (notification->isUnlinked()) continue;
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
if (count <= 0) {
|
|
|
|
return;
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
|
|
|
|
auto startPosition = notificationStartPosition();
|
|
|
|
auto startShift = 0;
|
|
|
|
auto shiftDirection = notificationShiftDirection();
|
|
|
|
do {
|
|
|
|
auto queued = _queuedNotifications.front();
|
|
|
|
_queuedNotifications.pop_front();
|
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
subscribeToSession(&queued.history->session());
|
|
|
|
_notifications.push_back(std::make_unique<Notification>(
|
2017-03-04 19:36:59 +00:00
|
|
|
this,
|
|
|
|
queued.history,
|
|
|
|
queued.peer,
|
|
|
|
queued.author,
|
|
|
|
queued.item,
|
|
|
|
queued.forwardedCount,
|
2019-08-28 14:24:12 +00:00
|
|
|
queued.fromScheduled,
|
|
|
|
startPosition,
|
|
|
|
startShift,
|
2020-06-19 12:59:31 +00:00
|
|
|
shiftDirection));
|
2017-03-04 19:36:59 +00:00
|
|
|
--count;
|
|
|
|
} while (count > 0 && !_queuedNotifications.empty());
|
|
|
|
|
|
|
|
_positionsOutdated = true;
|
|
|
|
checkLastInput();
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
void Manager::subscribeToSession(not_null<Main::Session*> session) {
|
|
|
|
auto i = _subscriptions.find(session);
|
|
|
|
if (i == _subscriptions.end()) {
|
2020-07-01 08:03:34 +00:00
|
|
|
i = _subscriptions.emplace(session).first;
|
|
|
|
session->account().sessionChanges(
|
|
|
|
) | rpl::start_with_next([=] {
|
2020-06-19 12:59:31 +00:00
|
|
|
_subscriptions.remove(session);
|
2020-07-01 08:03:34 +00:00
|
|
|
}, i->second.lifetime);
|
|
|
|
} else if (i->second.subscription) {
|
2020-06-19 12:59:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-07-01 08:03:34 +00:00
|
|
|
session->downloaderTaskFinished(
|
|
|
|
) | rpl::start_with_next([=] {
|
2020-06-19 12:59:31 +00:00
|
|
|
auto found = false;
|
|
|
|
for (const auto ¬ification : _notifications) {
|
|
|
|
if (const auto history = notification->maybeHistory()) {
|
|
|
|
if (&history->session() == session) {
|
|
|
|
notification->updatePeerPhoto();
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2020-07-01 08:03:34 +00:00
|
|
|
_subscriptions[session].subscription.destroy();
|
2020-06-19 12:59:31 +00:00
|
|
|
}
|
2020-07-01 08:03:34 +00:00
|
|
|
}, i->second.subscription);
|
2020-06-19 12:59:31 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Manager::moveWidgets() {
|
2016-10-06 16:41:09 +00:00
|
|
|
auto shift = st::notifyDeltaY;
|
|
|
|
int lastShift = 0, lastShiftCurrent = 0, count = 0;
|
2016-10-05 16:56:27 +00:00
|
|
|
for (int i = _notifications.size(); i != 0;) {
|
2017-03-04 19:36:59 +00:00
|
|
|
auto ¬ification = _notifications[--i];
|
2016-10-05 16:56:27 +00:00
|
|
|
if (notification->isUnlinked()) continue;
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
notification->changeShift(shift);
|
|
|
|
shift += notification->height() + st::notifyDeltaY;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
lastShiftCurrent = notification->currentShift();
|
|
|
|
lastShift = shift;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
if (count > 1 || !_queuedNotifications.empty()) {
|
2016-11-15 11:56:49 +00:00
|
|
|
auto deltaY = st::notifyHideAllHeight + st::notifyDeltaY;
|
2016-10-05 16:56:27 +00:00
|
|
|
if (!_hideAll) {
|
2017-03-04 19:36:59 +00:00
|
|
|
_hideAll = std::make_unique<HideAllButton>(this, notificationStartPosition(), lastShiftCurrent, notificationShiftDirection());
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
2016-10-06 16:41:09 +00:00
|
|
|
_hideAll->changeShift(lastShift);
|
2016-10-05 16:56:27 +00:00
|
|
|
_hideAll->stopHiding();
|
|
|
|
} else if (_hideAll) {
|
|
|
|
_hideAll->startHidingFast();
|
|
|
|
}
|
|
|
|
}
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Manager::changeNotificationHeight(Notification *notification, int newHeight) {
|
|
|
|
auto deltaHeight = newHeight - notification->height();
|
|
|
|
if (!deltaHeight) return;
|
2016-10-02 13:54:27 +00:00
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
notification->addToHeight(deltaHeight);
|
2017-03-04 19:36:59 +00:00
|
|
|
auto it = std::find_if(_notifications.cbegin(), _notifications.cend(), [notification](auto &item) {
|
|
|
|
return (item.get() == notification);
|
|
|
|
});
|
|
|
|
if (it != _notifications.cend()) {
|
|
|
|
for (auto i = _notifications.cbegin(); i != it; ++i) {
|
|
|
|
auto ¬ification = *i;
|
2016-10-05 16:56:27 +00:00
|
|
|
if (notification->isUnlinked()) continue;
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
notification->addToShift(deltaHeight);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_hideAll) {
|
2016-10-06 16:41:09 +00:00
|
|
|
_hideAll->addToShift(deltaHeight);
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Manager::unlinkFromShown(Notification *remove) {
|
2016-10-02 13:54:27 +00:00
|
|
|
if (remove) {
|
2016-10-05 16:56:27 +00:00
|
|
|
if (remove->unlinkHistory()) {
|
|
|
|
_positionsOutdated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
showNextFromQueue();
|
|
|
|
}
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
void Manager::removeWidget(internal::Widget *remove) {
|
|
|
|
if (remove == _hideAll.get()) {
|
|
|
|
_hideAll.reset();
|
|
|
|
} else if (remove) {
|
2019-04-01 17:44:54 +00:00
|
|
|
const auto it = ranges::find(
|
|
|
|
_notifications,
|
|
|
|
remove,
|
|
|
|
&std::unique_ptr<Notification>::get);
|
|
|
|
if (it != end(_notifications)) {
|
2017-03-04 19:36:59 +00:00
|
|
|
_notifications.erase(it);
|
2016-10-05 16:56:27 +00:00
|
|
|
_positionsOutdated = true;
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
showNextFromQueue();
|
|
|
|
}
|
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
void Manager::doShowNotification(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
int forwardedCount) {
|
2019-04-01 17:44:54 +00:00
|
|
|
_queuedNotifications.emplace_back(item, forwardedCount);
|
2016-10-02 13:54:27 +00:00
|
|
|
showNextFromQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::doClearAll() {
|
|
|
|
_queuedNotifications.clear();
|
2019-04-01 17:44:54 +00:00
|
|
|
for (const auto ¬ification : _notifications) {
|
2016-10-05 16:56:27 +00:00
|
|
|
notification->unlinkHistory();
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
2016-10-05 16:56:27 +00:00
|
|
|
showNextFromQueue();
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
void Manager::doClearAllFast() {
|
|
|
|
_queuedNotifications.clear();
|
2017-03-04 19:36:59 +00:00
|
|
|
base::take(_notifications);
|
|
|
|
base::take(_hideAll);
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2019-08-30 14:06:21 +00:00
|
|
|
void Manager::doClearFromHistory(not_null<History*> history) {
|
2016-10-02 13:54:27 +00:00
|
|
|
for (auto i = _queuedNotifications.begin(); i != _queuedNotifications.cend();) {
|
|
|
|
if (i->history == history) {
|
|
|
|
i = _queuedNotifications.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2020-06-19 12:59:31 +00:00
|
|
|
for (const auto ¬ification : _notifications) {
|
2016-10-05 16:56:27 +00:00
|
|
|
if (notification->unlinkHistory(history)) {
|
|
|
|
_positionsOutdated = true;
|
|
|
|
}
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
showNextFromQueue();
|
|
|
|
}
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
void Manager::doClearFromSession(not_null<Main::Session*> session) {
|
|
|
|
for (auto i = _queuedNotifications.begin(); i != _queuedNotifications.cend();) {
|
|
|
|
if (&i->history->session() == session) {
|
|
|
|
i = _queuedNotifications.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto ¬ification : _notifications) {
|
|
|
|
if (notification->unlinkSession(session)) {
|
|
|
|
_positionsOutdated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
showNextFromQueue();
|
|
|
|
}
|
|
|
|
|
2019-08-30 14:06:21 +00:00
|
|
|
void Manager::doClearFromItem(not_null<HistoryItem*> item) {
|
|
|
|
_queuedNotifications.erase(std::remove_if(_queuedNotifications.begin(), _queuedNotifications.end(), [&](auto &queued) {
|
2017-03-04 19:36:59 +00:00
|
|
|
return (queued.item == item);
|
|
|
|
}), _queuedNotifications.cend());
|
|
|
|
|
2017-03-08 20:51:40 +00:00
|
|
|
auto showNext = false;
|
2017-03-04 19:36:59 +00:00
|
|
|
for_const (auto ¬ification, _notifications) {
|
2017-03-08 20:51:40 +00:00
|
|
|
if (notification->unlinkItem(item)) {
|
|
|
|
showNext = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showNext) {
|
|
|
|
// This call invalidates _notifications iterators.
|
|
|
|
showNextFromQueue();
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-28 07:20:39 +00:00
|
|
|
bool Manager::doSkipAudio() const {
|
|
|
|
return Platform::Notifications::SkipAudioForCustom();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Manager::doSkipToast() const {
|
|
|
|
return Platform::Notifications::SkipToastForCustom();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Manager::doSkipFlashBounce() const {
|
|
|
|
return Platform::Notifications::SkipFlashBounceForCustom();
|
|
|
|
}
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
void Manager::doUpdateAll() {
|
2017-03-04 19:36:59 +00:00
|
|
|
for_const (auto ¬ification, _notifications) {
|
2016-10-05 16:56:27 +00:00
|
|
|
notification->updateNotifyDisplay();
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Manager::~Manager() {
|
|
|
|
clearAllFast();
|
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
namespace internal {
|
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
Widget::Widget(
|
|
|
|
not_null<Manager*> manager,
|
|
|
|
QPoint startPosition,
|
|
|
|
int shift,
|
|
|
|
Direction shiftDirection)
|
2021-04-02 11:29:47 +00:00
|
|
|
: _manager(manager)
|
2016-10-06 16:41:09 +00:00
|
|
|
, _startPosition(startPosition)
|
|
|
|
, _direction(shiftDirection)
|
2019-04-01 17:44:54 +00:00
|
|
|
, _shift(shift)
|
|
|
|
, _shiftAnimation([=](crl::time now) {
|
|
|
|
return shiftAnimationCallback(now);
|
|
|
|
}) {
|
2016-10-05 16:56:27 +00:00
|
|
|
setWindowOpacity(0.);
|
|
|
|
|
2018-07-19 14:27:09 +00:00
|
|
|
setWindowFlags(Qt::WindowFlags(Qt::FramelessWindowHint)
|
|
|
|
| Qt::WindowStaysOnTopHint
|
2018-08-04 10:54:08 +00:00
|
|
|
| Qt::BypassWindowManagerHint
|
2018-07-19 14:27:09 +00:00
|
|
|
| Qt::NoDropShadowWindowHint
|
|
|
|
| Qt::Tool);
|
2016-10-05 16:56:27 +00:00
|
|
|
setAttribute(Qt::WA_MacAlwaysShowToolWindow);
|
2017-05-02 07:25:20 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
Ui::Platform::InitOnTopPanel(this);
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
_a_opacity.start([this] { opacityAnimationCallback(); }, 0., 1., st::notifyFastAnim);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 13:24:19 +00:00
|
|
|
void Widget::destroyDelayed() {
|
|
|
|
hide();
|
|
|
|
if (_deleted) return;
|
|
|
|
_deleted = true;
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
// Ubuntu has a lag if a fully transparent widget is destroyed immediately.
|
2019-09-26 10:55:35 +00:00
|
|
|
base::call_delayed(1000, this, [this] {
|
2017-03-04 19:36:59 +00:00
|
|
|
manager()->removeWidget(this);
|
|
|
|
});
|
2016-10-07 13:24:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
void Widget::opacityAnimationCallback() {
|
2016-10-06 16:41:09 +00:00
|
|
|
updateOpacity();
|
2016-10-05 16:56:27 +00:00
|
|
|
update();
|
2016-12-07 13:32:25 +00:00
|
|
|
if (!_a_opacity.animating() && _hiding) {
|
|
|
|
destroyDelayed();
|
|
|
|
}
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
bool Widget::shiftAnimationCallback(crl::time now) {
|
2018-09-20 16:39:59 +00:00
|
|
|
if (anim::Disabled()) {
|
2019-04-01 17:44:54 +00:00
|
|
|
now += st::notifyFastAnim;
|
2018-09-20 16:39:59 +00:00
|
|
|
}
|
2019-04-01 17:44:54 +00:00
|
|
|
const auto dt = (now - _shiftAnimation.started())
|
|
|
|
/ float64(st::notifyFastAnim);
|
|
|
|
if (dt >= 1.) {
|
|
|
|
_shift.finish();
|
2016-10-05 16:56:27 +00:00
|
|
|
} else {
|
2019-04-01 17:44:54 +00:00
|
|
|
_shift.update(dt, anim::linear);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
2016-10-06 16:41:09 +00:00
|
|
|
moveByShift();
|
2019-04-01 17:44:54 +00:00
|
|
|
return (dt < 1.);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::hideSlow() {
|
2018-09-21 18:14:48 +00:00
|
|
|
if (anim::Disabled()) {
|
|
|
|
_hiding = true;
|
2019-09-26 10:55:35 +00:00
|
|
|
base::call_delayed(
|
2019-03-27 12:11:38 +00:00
|
|
|
st::notifySlowHide,
|
|
|
|
this,
|
|
|
|
[=, guard = _hidingDelayed.make_guard()] {
|
|
|
|
if (guard && _hiding) {
|
|
|
|
hideFast();
|
|
|
|
}
|
|
|
|
});
|
2018-09-21 18:14:48 +00:00
|
|
|
} else {
|
|
|
|
hideAnimated(st::notifySlowHide, anim::easeInCirc);
|
|
|
|
}
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::hideFast() {
|
2016-10-06 16:41:09 +00:00
|
|
|
hideAnimated(st::notifyFastAnim, anim::linear);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::hideStop() {
|
|
|
|
if (_hiding) {
|
|
|
|
_hiding = false;
|
2018-09-21 18:14:48 +00:00
|
|
|
_hidingDelayed = {};
|
2016-12-07 13:32:25 +00:00
|
|
|
_a_opacity.start([this] { opacityAnimationCallback(); }, 0., 1., st::notifyFastAnim);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 12:54:07 +00:00
|
|
|
void Widget::hideAnimated(float64 duration, const anim::transition &func) {
|
2016-10-05 16:56:27 +00:00
|
|
|
_hiding = true;
|
2016-12-07 13:32:25 +00:00
|
|
|
_a_opacity.start([this] { opacityAnimationCallback(); }, 1., 0., duration, func);
|
2016-10-06 16:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updateOpacity() {
|
2019-04-02 09:13:30 +00:00
|
|
|
setWindowOpacity(_a_opacity.value(_hiding ? 0. : 1.) * _manager->demoMasterOpacity());
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
void Widget::changeShift(int top) {
|
2019-04-01 17:44:54 +00:00
|
|
|
_shift.start(top);
|
|
|
|
_shiftAnimation.start();
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
void Widget::updatePosition(QPoint startPosition, Direction shiftDirection) {
|
|
|
|
_startPosition = startPosition;
|
|
|
|
_direction = shiftDirection;
|
|
|
|
moveByShift();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::addToHeight(int add) {
|
|
|
|
auto newHeight = height() + add;
|
|
|
|
auto newPosition = computePosition(newHeight);
|
|
|
|
updateGeometry(newPosition.x(), newPosition.y(), width(), newHeight);
|
2019-09-16 11:14:06 +00:00
|
|
|
Ui::Platform::UpdateOverlayed(this);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updateGeometry(int x, int y, int width, int height) {
|
|
|
|
setGeometry(x, y, width, height);
|
2020-05-14 18:38:44 +00:00
|
|
|
setMinimumSize(QSize(width, height));
|
|
|
|
setMaximumSize(QSize(width, height));
|
2016-10-05 16:56:27 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
void Widget::addToShift(int add) {
|
2019-04-01 17:44:54 +00:00
|
|
|
_shift.add(add);
|
2016-10-06 16:41:09 +00:00
|
|
|
moveByShift();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::moveByShift() {
|
|
|
|
move(computePosition(height()));
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Widget::computePosition(int height) const {
|
2019-04-01 17:44:54 +00:00
|
|
|
auto realShift = qRound(_shift.current());
|
2016-10-06 16:41:09 +00:00
|
|
|
if (_direction == Direction::Up) {
|
|
|
|
realShift = -realShift - height;
|
|
|
|
}
|
|
|
|
return QPoint(_startPosition.x(), _startPosition.y() + realShift);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Background::Background(QWidget *parent) : TWidget(parent) {
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Background::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(rect(), st::notificationBg);
|
2016-10-05 16:56:27 +00:00
|
|
|
p.fillRect(0, 0, st::notifyBorderWidth, height(), st::notifyBorder);
|
|
|
|
p.fillRect(width() - st::notifyBorderWidth, 0, st::notifyBorderWidth, height(), st::notifyBorder);
|
|
|
|
p.fillRect(st::notifyBorderWidth, height() - st::notifyBorderWidth, width() - 2 * st::notifyBorderWidth, st::notifyBorderWidth, st::notifyBorder);
|
|
|
|
}
|
|
|
|
|
2019-01-18 11:26:43 +00:00
|
|
|
Notification::Notification(
|
2019-08-28 14:24:12 +00:00
|
|
|
not_null<Manager*> manager,
|
|
|
|
not_null<History*> history,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const QString &author,
|
|
|
|
HistoryItem *item,
|
2019-01-18 11:26:43 +00:00
|
|
|
int forwardedCount,
|
2019-08-28 14:24:12 +00:00
|
|
|
bool fromScheduled,
|
2019-01-18 11:26:43 +00:00
|
|
|
QPoint startPosition,
|
|
|
|
int shift,
|
|
|
|
Direction shiftDirection)
|
|
|
|
: Widget(manager, startPosition, shift, shiftDirection)
|
2020-05-28 14:32:10 +00:00
|
|
|
, _peer(peer)
|
2019-03-10 13:40:44 +00:00
|
|
|
, _started(crl::now())
|
2016-10-02 13:54:27 +00:00
|
|
|
, _history(history)
|
2020-05-28 14:32:10 +00:00
|
|
|
, _userpicView(_peer->createUserpicView())
|
2016-10-02 13:54:27 +00:00
|
|
|
, _author(author)
|
2019-08-28 14:24:12 +00:00
|
|
|
, _item(item)
|
2016-10-02 13:54:27 +00:00
|
|
|
, _forwardedCount(forwardedCount)
|
2019-08-28 14:24:12 +00:00
|
|
|
, _fromScheduled(fromScheduled)
|
2016-10-02 13:54:27 +00:00
|
|
|
, _close(this, st::notifyClose)
|
2019-06-18 16:53:27 +00:00
|
|
|
, _reply(this, tr::lng_notification_reply(), st::defaultBoxButton) {
|
2020-09-30 09:11:44 +00:00
|
|
|
Lang::Updated(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
refreshLang();
|
|
|
|
}, lifetime());
|
2017-05-30 15:21:05 +00:00
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
auto position = computePosition(st::notifyMinHeight);
|
|
|
|
updateGeometry(position.x(), position.y(), st::notifyWidth, st::notifyMinHeight);
|
2016-10-04 18:18:08 +00:00
|
|
|
|
2020-05-30 18:20:19 +00:00
|
|
|
_userpicLoaded = !_userpicView || (_userpicView->image() != nullptr);
|
2016-10-02 09:30:28 +00:00
|
|
|
updateNotifyDisplay();
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
_hideTimer.setSingleShot(true);
|
2018-05-31 12:20:28 +00:00
|
|
|
connect(&_hideTimer, &QTimer::timeout, [=] { startHiding(); });
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-04 18:18:08 +00:00
|
|
|
_close->setClickedCallback([this] {
|
2016-10-05 16:56:27 +00:00
|
|
|
unlinkHistoryInManager();
|
2016-10-02 09:30:28 +00:00
|
|
|
});
|
2016-10-04 18:18:08 +00:00
|
|
|
_close->setAcceptBoth(true);
|
|
|
|
_close->moveToRight(st::notifyClosePos.x(), st::notifyClosePos.y());
|
|
|
|
_close->show();
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-04 18:18:08 +00:00
|
|
|
_reply->setClickedCallback([this] {
|
|
|
|
showReplyField();
|
|
|
|
});
|
|
|
|
_replyPadding = st::notifyMinHeight - st::notifyPhotoPos.y() - st::notifyPhotoSize;
|
2017-05-30 15:21:05 +00:00
|
|
|
updateReplyGeometry();
|
2016-10-04 18:18:08 +00:00
|
|
|
_reply->hide();
|
|
|
|
|
|
|
|
prepareActionsCache();
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-12-31 13:34:41 +00:00
|
|
|
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) {
|
|
|
|
if (data.paletteChanged()) {
|
|
|
|
updateNotifyDisplay();
|
|
|
|
if (!_buttonsCache.isNull()) {
|
|
|
|
prepareActionsCache();
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
if (_background) {
|
|
|
|
_background->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-02 09:30:28 +00:00
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
void Notification::updateReplyGeometry() {
|
|
|
|
_reply->moveToRight(_replyPadding, height() - _reply->height() - _replyPadding);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notification::refreshLang() {
|
|
|
|
InvokeQueued(this, [this] { updateReplyGeometry(); });
|
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::prepareActionsCache() {
|
2017-12-26 12:41:48 +00:00
|
|
|
auto replyCache = Ui::GrabWidget(_reply);
|
2016-10-04 18:18:08 +00:00
|
|
|
auto fadeWidth = st::notifyFadeRight.width();
|
|
|
|
auto actionsTop = st::notifyTextTop + st::msgNameFont->height;
|
2017-07-03 10:51:38 +00:00
|
|
|
auto replyRight = _replyPadding - st::notifyBorderWidth;
|
|
|
|
auto actionsCacheWidth = _reply->width() + replyRight + fadeWidth;
|
|
|
|
auto actionsCacheHeight = height() - actionsTop - st::notifyBorderWidth;
|
|
|
|
auto actionsCacheImg = QImage(QSize(actionsCacheWidth, actionsCacheHeight) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
2016-10-07 13:14:02 +00:00
|
|
|
actionsCacheImg.setDevicePixelRatio(cRetinaFactor());
|
2016-10-31 12:29:26 +00:00
|
|
|
actionsCacheImg.fill(Qt::transparent);
|
2016-10-04 18:18:08 +00:00
|
|
|
{
|
|
|
|
Painter p(&actionsCacheImg);
|
2019-09-13 12:22:54 +00:00
|
|
|
st::notifyFadeRight.fill(p, style::rtlrect(0, 0, fadeWidth, actionsCacheHeight, actionsCacheWidth));
|
|
|
|
p.fillRect(style::rtlrect(fadeWidth, 0, actionsCacheWidth - fadeWidth, actionsCacheHeight, actionsCacheWidth), st::notificationBg);
|
2017-07-03 10:51:38 +00:00
|
|
|
p.drawPixmapRight(replyRight, _reply->y() - actionsTop, actionsCacheWidth, replyCache);
|
2016-10-04 18:18:08 +00:00
|
|
|
}
|
2017-02-21 13:45:56 +00:00
|
|
|
_buttonsCache = App::pixmapFromImageInPlace(std::move(actionsCacheImg));
|
2016-10-04 18:18:08 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
bool Notification::checkLastInput(bool hasReplyingNotifications) {
|
2016-10-05 16:56:27 +00:00
|
|
|
if (!_waitingForInput) return true;
|
|
|
|
|
2020-10-29 19:56:13 +00:00
|
|
|
const auto waitForUserInput = base::Platform::LastUserInputTimeSupported()
|
2019-03-14 17:59:10 +00:00
|
|
|
? (Core::App().lastNonIdleTime() <= _started)
|
|
|
|
: false;
|
|
|
|
if (!waitForUserInput) {
|
2016-10-05 16:56:27 +00:00
|
|
|
_waitingForInput = false;
|
2016-10-06 16:41:09 +00:00
|
|
|
if (!hasReplyingNotifications) {
|
2016-10-05 16:56:27 +00:00
|
|
|
_hideTimer.start(st::notifyWaitLongHide);
|
|
|
|
}
|
|
|
|
return true;
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
2016-10-05 16:56:27 +00:00
|
|
|
return false;
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void Notification::replyResized() {
|
2016-10-05 16:56:27 +00:00
|
|
|
changeHeight(st::notifyMinHeight + _replyArea->height() + st::notifyBorderWidth);
|
2016-10-04 18:18:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
void Notification::replyCancel() {
|
2016-10-05 16:56:27 +00:00
|
|
|
unlinkHistoryInManager();
|
2016-10-04 18:18:08 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::updateGeometry(int x, int y, int width, int height) {
|
|
|
|
if (height > st::notifyMinHeight) {
|
|
|
|
if (!_background) {
|
2016-12-13 17:07:56 +00:00
|
|
|
_background.create(this);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
_background->setGeometry(0, st::notifyMinHeight, width, height - st::notifyMinHeight);
|
|
|
|
} else if (_background) {
|
|
|
|
_background.destroy();
|
|
|
|
}
|
|
|
|
Widget::updateGeometry(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notification::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
p.setClipRect(e->rect());
|
|
|
|
p.drawPixmap(0, 0, _cache);
|
|
|
|
|
|
|
|
auto buttonsLeft = st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft;
|
|
|
|
auto buttonsTop = st::notifyTextTop + st::msgNameFont->height;
|
2019-04-02 09:13:30 +00:00
|
|
|
if (a_actionsOpacity.animating()) {
|
|
|
|
p.setOpacity(a_actionsOpacity.value(1.));
|
2017-07-03 10:51:38 +00:00
|
|
|
p.drawPixmapRight(st::notifyBorderWidth, buttonsTop, width(), _buttonsCache);
|
2016-10-05 16:56:27 +00:00
|
|
|
} else if (_actionsVisible) {
|
2017-07-03 10:51:38 +00:00
|
|
|
p.drawPixmapRight(st::notifyBorderWidth, buttonsTop, width(), _buttonsCache);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::actionsOpacityCallback() {
|
|
|
|
update();
|
|
|
|
if (!a_actionsOpacity.animating() && _actionsVisible) {
|
|
|
|
_reply->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notification::updateNotifyDisplay() {
|
2020-05-28 14:32:10 +00:00
|
|
|
if (!_history || (!_item && _forwardedCount < 2)) return;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2021-04-27 09:51:52 +00:00
|
|
|
const auto options = manager()->getNotificationOptions(_item);
|
2016-10-08 08:38:53 +00:00
|
|
|
_hideReplyButton = options.hideReplyButton;
|
|
|
|
|
2016-10-04 18:18:08 +00:00
|
|
|
int32 w = width(), h = height();
|
2016-10-02 09:30:28 +00:00
|
|
|
QImage img(w * cIntRetinaFactor(), h * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
2018-10-15 19:42:10 +00:00
|
|
|
img.setDevicePixelRatio(cRetinaFactor());
|
2016-10-31 12:29:26 +00:00
|
|
|
img.fill(st::notificationBg->c);
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
Painter p(&img);
|
2016-10-07 17:02:13 +00:00
|
|
|
p.fillRect(0, 0, w - st::notifyBorderWidth, st::notifyBorderWidth, st::notifyBorder);
|
|
|
|
p.fillRect(w - st::notifyBorderWidth, 0, st::notifyBorderWidth, h - st::notifyBorderWidth, st::notifyBorder);
|
|
|
|
p.fillRect(st::notifyBorderWidth, h - st::notifyBorderWidth, w - st::notifyBorderWidth, st::notifyBorderWidth, st::notifyBorder);
|
|
|
|
p.fillRect(0, st::notifyBorderWidth, st::notifyBorderWidth, h - st::notifyBorderWidth, st::notifyBorder);
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-08 08:38:53 +00:00
|
|
|
if (!options.hideNameAndPhoto) {
|
2019-08-28 18:20:49 +00:00
|
|
|
if (_fromScheduled && _history->peer->isSelf()) {
|
|
|
|
Ui::EmptyUserpic::PaintSavedMessages(p, st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), width(), st::notifyPhotoSize);
|
2019-09-27 16:36:19 +00:00
|
|
|
_userpicLoaded = true;
|
2020-09-11 16:22:14 +00:00
|
|
|
} else if (_history->peer->isRepliesChat()) {
|
|
|
|
Ui::EmptyUserpic::PaintRepliesMessages(p, st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), width(), st::notifyPhotoSize);
|
|
|
|
_userpicLoaded = true;
|
2019-08-28 18:20:49 +00:00
|
|
|
} else {
|
2020-05-28 14:32:10 +00:00
|
|
|
_userpicView = _history->peer->createUserpicView();
|
2019-08-28 18:20:49 +00:00
|
|
|
_history->peer->loadUserpic();
|
2020-05-28 14:32:10 +00:00
|
|
|
_history->peer->paintUserpicLeft(p, _userpicView, st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), width(), st::notifyPhotoSize);
|
2019-08-28 18:20:49 +00:00
|
|
|
}
|
2016-10-02 09:30:28 +00:00
|
|
|
} else {
|
2017-05-12 15:27:19 +00:00
|
|
|
p.drawPixmap(st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), manager()->hiddenUserpicPlaceholder());
|
2019-09-27 16:36:19 +00:00
|
|
|
_userpicLoaded = true;
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32 itemWidth = w - st::notifyPhotoPos.x() - st::notifyPhotoSize - st::notifyTextLeft - st::notifyClosePos.x() - st::notifyClose.width;
|
|
|
|
|
|
|
|
QRect rectForName(st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft, st::notifyTextTop, itemWidth, st::msgNameFont->height);
|
2019-08-28 18:20:49 +00:00
|
|
|
const auto reminder = _fromScheduled && _history->peer->isSelf();
|
2016-10-08 08:38:53 +00:00
|
|
|
if (!options.hideNameAndPhoto) {
|
2019-08-28 18:20:49 +00:00
|
|
|
if (_fromScheduled) {
|
|
|
|
static const auto emoji = Ui::Emoji::Find(QString::fromUtf8("\xF0\x9F\x93\x85"));
|
|
|
|
const auto size = Ui::Emoji::GetSizeNormal() / cIntRetinaFactor();
|
|
|
|
const auto top = rectForName.top() + (st::msgNameFont->height - size) / 2;
|
|
|
|
Ui::Emoji::Draw(p, emoji, Ui::Emoji::GetSizeNormal(), rectForName.left(), top);
|
|
|
|
rectForName.setLeft(rectForName.left() + size + st::msgNameFont->spacew);
|
|
|
|
}
|
2018-02-22 13:50:56 +00:00
|
|
|
if (const auto chatTypeIcon = Dialogs::Layout::ChatTypeIcon(_history->peer, false, false)) {
|
2016-10-02 09:30:28 +00:00
|
|
|
chatTypeIcon->paint(p, rectForName.topLeft(), w);
|
|
|
|
rectForName.setLeft(rectForName.left() + st::dialogsChatTypeSkip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 08:38:53 +00:00
|
|
|
if (!options.hideMessageText) {
|
2019-08-28 14:24:12 +00:00
|
|
|
auto itemTextCache = Ui::Text::String(itemWidth);
|
|
|
|
auto r = QRect(
|
|
|
|
st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft,
|
|
|
|
st::notifyItemTop + st::msgNameFont->height,
|
|
|
|
itemWidth,
|
|
|
|
2 * st::dialogsTextFont->height);
|
|
|
|
p.setTextPalette(st::dialogsTextPalette);
|
|
|
|
p.setPen(st::dialogsTextFg);
|
|
|
|
p.setFont(st::dialogsTextFont);
|
|
|
|
const auto text = _item
|
2019-08-28 18:20:49 +00:00
|
|
|
? _item->inDialogsText(reminder
|
|
|
|
? HistoryItem::DrawInDialog::WithoutSender
|
|
|
|
: HistoryItem::DrawInDialog::Normal)
|
2019-08-28 14:24:12 +00:00
|
|
|
: ((!_author.isEmpty()
|
|
|
|
? textcmdLink(1, _author)
|
|
|
|
: QString())
|
|
|
|
+ (_forwardedCount > 1
|
|
|
|
? ('\n' + tr::lng_forward_messages(
|
|
|
|
tr::now,
|
|
|
|
lt_count,
|
|
|
|
_forwardedCount))
|
|
|
|
: QString()));
|
|
|
|
const auto Options = TextParseOptions{
|
|
|
|
TextParseRichText
|
|
|
|
| (_forwardedCount > 1 ? TextParseMultiline : 0),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
Qt::LayoutDirectionAuto,
|
|
|
|
};
|
2019-08-28 18:20:49 +00:00
|
|
|
itemTextCache.setText(st::dialogsTextStyle, text, Options);
|
2019-08-28 14:24:12 +00:00
|
|
|
itemTextCache.drawElided(
|
|
|
|
p,
|
|
|
|
r.left(),
|
|
|
|
r.top(),
|
|
|
|
r.width(),
|
|
|
|
r.height() / st::dialogsTextFont->height);
|
|
|
|
p.restoreTextPalette();
|
2016-10-02 09:30:28 +00:00
|
|
|
} else {
|
2016-10-02 13:54:27 +00:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2016-10-02 09:30:28 +00:00
|
|
|
p.setPen(st::dialogsTextFgService);
|
2019-08-28 14:24:12 +00:00
|
|
|
p.drawText(
|
|
|
|
st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft,
|
|
|
|
st::notifyItemTop + st::msgNameFont->height + st::dialogsTextFont->ascent,
|
|
|
|
st::dialogsTextFont->elided(
|
|
|
|
tr::lng_notification_preview(tr::now),
|
|
|
|
itemWidth));
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p.setPen(st::dialogsNameFg);
|
2020-06-19 13:34:43 +00:00
|
|
|
Ui::Text::String titleText;
|
|
|
|
const auto title = options.hideNameAndPhoto
|
|
|
|
? qsl("Telegram Desktop")
|
|
|
|
: reminder
|
|
|
|
? tr::lng_notification_reminder(tr::now)
|
|
|
|
: _history->peer->nameText().toString();
|
|
|
|
const auto fullTitle = manager()->addTargetAccountName(
|
|
|
|
title,
|
|
|
|
&_history->session());
|
|
|
|
titleText.setText(st::msgNameStyle, fullTitle, Ui::NameTextOptions());
|
|
|
|
titleText.drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
_cache = App::pixmapFromImageInPlace(std::move(img));
|
2016-10-07 17:02:13 +00:00
|
|
|
if (!canReply()) {
|
|
|
|
toggleActionButtons(false);
|
|
|
|
}
|
2016-10-02 09:30:28 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::updatePeerPhoto() {
|
2020-05-28 14:32:10 +00:00
|
|
|
if (_userpicLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_userpicView = _peer->createUserpicView();
|
|
|
|
if (_userpicView && !_userpicView->image()) {
|
2016-10-05 16:56:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
_userpicLoaded = true;
|
|
|
|
|
|
|
|
auto img = _cache.toImage();
|
|
|
|
{
|
|
|
|
Painter p(&img);
|
2020-05-28 14:32:10 +00:00
|
|
|
_peer->paintUserpicLeft(
|
|
|
|
p,
|
|
|
|
_userpicView,
|
|
|
|
st::notifyPhotoPos.x(),
|
|
|
|
st::notifyPhotoPos.y(),
|
|
|
|
width(),
|
|
|
|
st::notifyPhotoSize);
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
2017-02-21 13:45:56 +00:00
|
|
|
_cache = App::pixmapFromImageInPlace(std::move(img));
|
2020-05-28 14:32:10 +00:00
|
|
|
_userpicView = nullptr;
|
2016-10-07 17:02:13 +00:00
|
|
|
update();
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 20:51:40 +00:00
|
|
|
bool Notification::unlinkItem(HistoryItem *deleted) {
|
|
|
|
auto unlink = (_item && _item == deleted);
|
|
|
|
if (unlink) {
|
2016-10-02 13:54:27 +00:00
|
|
|
_item = nullptr;
|
2017-03-08 20:51:40 +00:00
|
|
|
unlinkHistory();
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
2017-03-08 20:51:40 +00:00
|
|
|
return unlink;
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 17:02:13 +00:00
|
|
|
bool Notification::canReply() const {
|
2018-06-03 13:30:40 +00:00
|
|
|
return !_hideReplyButton
|
|
|
|
&& (_item != nullptr)
|
2020-06-19 12:59:31 +00:00
|
|
|
&& !Core::App().passcodeLocked()
|
2020-06-18 18:04:16 +00:00
|
|
|
&& (Core::App().settings().notifyView() <= dbinvShowPreview);
|
2016-10-07 17:02:13 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::unlinkHistoryInManager() {
|
2017-03-04 19:36:59 +00:00
|
|
|
manager()->unlinkFromShown(this);
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::toggleActionButtons(bool visible) {
|
2016-10-04 18:18:08 +00:00
|
|
|
if (_actionsVisible != visible) {
|
|
|
|
_actionsVisible = visible;
|
|
|
|
a_actionsOpacity.start([this] { actionsOpacityCallback(); }, _actionsVisible ? 0. : 1., _actionsVisible ? 1. : 0., st::notifyActionsDuration);
|
2016-12-07 13:32:25 +00:00
|
|
|
_reply->clearState();
|
2016-10-05 16:56:27 +00:00
|
|
|
_reply->hide();
|
2016-10-04 18:18:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::showReplyField() {
|
2019-09-27 15:53:44 +00:00
|
|
|
if (!_item) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-07 07:25:19 +00:00
|
|
|
raise();
|
2016-10-19 13:31:18 +00:00
|
|
|
activateWindow();
|
|
|
|
|
|
|
|
if (_replyArea) {
|
|
|
|
_replyArea->setFocus();
|
|
|
|
return;
|
|
|
|
}
|
2016-10-05 16:56:27 +00:00
|
|
|
stopHiding();
|
|
|
|
|
2016-11-15 11:56:49 +00:00
|
|
|
_background.create(this);
|
2016-10-05 16:56:27 +00:00
|
|
|
_background->setGeometry(0, st::notifyMinHeight, width(), st::notifySendReply.height + st::notifyBorderWidth);
|
|
|
|
_background->show();
|
2016-10-04 18:18:08 +00:00
|
|
|
|
2018-05-20 17:42:30 +00:00
|
|
|
_replyArea.create(
|
|
|
|
this,
|
|
|
|
st::notifyReplyArea,
|
|
|
|
Ui::InputField::Mode::MultiLine,
|
2019-06-18 14:07:45 +00:00
|
|
|
tr::lng_message_ph());
|
2016-10-04 18:18:08 +00:00
|
|
|
_replyArea->resize(width() - st::notifySendReply.width - 2 * st::notifyBorderWidth, st::notifySendReply.height);
|
|
|
|
_replyArea->moveToLeft(st::notifyBorderWidth, st::notifyMinHeight);
|
|
|
|
_replyArea->show();
|
|
|
|
_replyArea->setFocus();
|
|
|
|
_replyArea->setMaxLength(MaxMessageSize);
|
2020-02-10 12:19:32 +00:00
|
|
|
_replyArea->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
|
2018-05-20 17:42:30 +00:00
|
|
|
_replyArea->setInstantReplaces(Ui::InstantReplaces::Default());
|
2019-08-02 10:40:35 +00:00
|
|
|
_replyArea->setInstantReplacesEnabled(
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().replaceEmojiValue());
|
2018-05-25 17:47:29 +00:00
|
|
|
_replyArea->setMarkdownReplacesEnabled(rpl::single(true));
|
2016-10-19 13:31:18 +00:00
|
|
|
|
|
|
|
// Catch mouse press event to activate the window.
|
2017-02-23 10:59:19 +00:00
|
|
|
QCoreApplication::instance()->installEventFilter(this);
|
2018-05-31 12:20:28 +00:00
|
|
|
connect(_replyArea, &Ui::InputField::resized, [=] { replyResized(); });
|
|
|
|
connect(_replyArea, &Ui::InputField::submitted, [=] { sendReply(); });
|
|
|
|
connect(_replyArea, &Ui::InputField::cancelled, [=] { replyCancel(); });
|
2016-10-04 18:18:08 +00:00
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
_replySend.create(this, st::notifySendReply);
|
2016-10-04 18:18:08 +00:00
|
|
|
_replySend->moveToRight(st::notifyBorderWidth, st::notifyMinHeight);
|
|
|
|
_replySend->show();
|
|
|
|
_replySend->setClickedCallback([this] { sendReply(); });
|
|
|
|
|
|
|
|
toggleActionButtons(false);
|
|
|
|
|
2018-05-31 12:20:28 +00:00
|
|
|
replyResized();
|
2016-10-04 18:18:08 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::sendReply() {
|
2016-10-04 18:18:08 +00:00
|
|
|
if (!_history) return;
|
|
|
|
|
2018-05-24 13:03:21 +00:00
|
|
|
manager()->notificationReplied(
|
2020-06-19 12:59:31 +00:00
|
|
|
myId(),
|
2018-05-31 18:28:37 +00:00
|
|
|
_replyArea->getTextWithAppliedMarkdown());
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
manager()->startAllHiding();
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
Notifications::Manager::NotificationId Notification::myId() const {
|
|
|
|
if (!_history) {
|
|
|
|
return {};
|
|
|
|
}
|
2020-06-24 09:05:56 +00:00
|
|
|
return { .full = {
|
|
|
|
.sessionId = _history->session().uniqueId(),
|
|
|
|
.peerId = _history->peer->id
|
|
|
|
}, .msgId = _item ? _item->id : ShowAtUnreadMsgId };
|
2020-06-19 12:59:31 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::changeHeight(int newHeight) {
|
2017-03-04 19:36:59 +00:00
|
|
|
manager()->changeNotificationHeight(this, newHeight);
|
2016-10-04 18:18:08 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
bool Notification::unlinkHistory(History *history) {
|
2019-08-28 14:24:12 +00:00
|
|
|
const auto unlink = _history && (history == _history || !history);
|
2016-10-05 16:56:27 +00:00
|
|
|
if (unlink) {
|
|
|
|
hideFast();
|
2016-10-02 13:54:27 +00:00
|
|
|
_history = nullptr;
|
|
|
|
_item = nullptr;
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
2016-10-05 16:56:27 +00:00
|
|
|
return unlink;
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 12:59:31 +00:00
|
|
|
bool Notification::unlinkSession(not_null<Main::Session*> session) {
|
|
|
|
const auto unlink = _history && (&_history->session() == session);
|
|
|
|
if (unlink) {
|
|
|
|
hideFast();
|
|
|
|
_history = nullptr;
|
|
|
|
_item = nullptr;
|
|
|
|
}
|
|
|
|
return unlink;
|
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void Notification::enterEventHook(QEvent *e) {
|
2016-10-02 13:54:27 +00:00
|
|
|
if (!_history) return;
|
2017-03-04 19:36:59 +00:00
|
|
|
manager()->stopAllHiding();
|
2016-10-07 17:02:13 +00:00
|
|
|
if (!_replyArea && canReply()) {
|
2016-10-04 18:18:08 +00:00
|
|
|
toggleActionButtons(true);
|
|
|
|
}
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void Notification::leaveEventHook(QEvent *e) {
|
2016-10-02 13:54:27 +00:00
|
|
|
if (!_history) return;
|
2017-03-04 19:36:59 +00:00
|
|
|
manager()->startAllHiding();
|
2016-10-04 18:18:08 +00:00
|
|
|
toggleActionButtons(false);
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::startHiding() {
|
|
|
|
if (!_history) return;
|
|
|
|
hideSlow();
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::mousePressEvent(QMouseEvent *e) {
|
2016-10-02 13:54:27 +00:00
|
|
|
if (!_history) return;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
if (e->button() == Qt::RightButton) {
|
2016-10-05 16:56:27 +00:00
|
|
|
unlinkHistoryInManager();
|
2016-10-02 09:30:28 +00:00
|
|
|
} else {
|
|
|
|
e->ignore();
|
2020-06-19 12:59:31 +00:00
|
|
|
manager()->notificationActivated(myId());
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-19 13:31:18 +00:00
|
|
|
bool Notification::eventFilter(QObject *o, QEvent *e) {
|
|
|
|
if (e->type() == QEvent::MouseButtonPress) {
|
|
|
|
if (auto receiver = qobject_cast<QWidget*>(o)) {
|
|
|
|
if (isAncestorOf(receiver)) {
|
2021-06-07 07:25:19 +00:00
|
|
|
raise();
|
2016-10-19 13:31:18 +00:00
|
|
|
activateWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void Notification::stopHiding() {
|
|
|
|
if (!_history) return;
|
|
|
|
_hideTimer.stop();
|
|
|
|
Widget::hideStop();
|
|
|
|
}
|
2016-10-04 18:18:08 +00:00
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
HideAllButton::HideAllButton(
|
|
|
|
not_null<Manager*> manager,
|
|
|
|
QPoint startPosition,
|
|
|
|
int shift,
|
|
|
|
Direction shiftDirection)
|
|
|
|
: Widget(manager, startPosition, shift, shiftDirection) {
|
2016-10-05 16:56:27 +00:00
|
|
|
setCursor(style::cur_pointer);
|
|
|
|
|
2016-11-15 11:56:49 +00:00
|
|
|
auto position = computePosition(st::notifyHideAllHeight);
|
|
|
|
updateGeometry(position.x(), position.y(), st::notifyWidth, st::notifyHideAllHeight);
|
2016-10-05 16:56:27 +00:00
|
|
|
hide();
|
|
|
|
createWinId();
|
|
|
|
|
2016-12-31 13:34:41 +00:00
|
|
|
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &data) {
|
|
|
|
if (data.paletteChanged()) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
show();
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void HideAllButton::startHiding() {
|
|
|
|
hideSlow();
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void HideAllButton::startHidingFast() {
|
|
|
|
hideFast();
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void HideAllButton::stopHiding() {
|
|
|
|
hideStop();
|
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void HideAllButton::enterEventHook(QEvent *e) {
|
2016-10-05 16:56:27 +00:00
|
|
|
_mouseOver = true;
|
2016-10-04 18:18:08 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void HideAllButton::leaveEventHook(QEvent *e) {
|
2016-10-05 16:56:27 +00:00
|
|
|
_mouseOver = false;
|
2016-10-02 09:30:28 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void HideAllButton::mousePressEvent(QMouseEvent *e) {
|
|
|
|
_mouseDown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HideAllButton::mouseReleaseEvent(QMouseEvent *e) {
|
2016-10-07 16:45:45 +00:00
|
|
|
auto mouseDown = base::take(_mouseDown);
|
2016-10-05 16:56:27 +00:00
|
|
|
if (mouseDown && _mouseOver) {
|
2017-03-04 19:36:59 +00:00
|
|
|
manager()->clearAll();
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void HideAllButton::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
p.setClipRect(e->rect());
|
|
|
|
|
2016-11-15 11:56:49 +00:00
|
|
|
p.fillRect(rect(), _mouseOver ? st::lightButtonBgOver : st::lightButtonBg);
|
2016-10-05 16:56:27 +00:00
|
|
|
p.fillRect(0, 0, width(), st::notifyBorderWidth, st::notifyBorder);
|
|
|
|
p.fillRect(0, height() - st::notifyBorderWidth, width(), st::notifyBorderWidth, st::notifyBorder);
|
|
|
|
p.fillRect(0, st::notifyBorderWidth, st::notifyBorderWidth, height() - 2 * st::notifyBorderWidth, st::notifyBorder);
|
|
|
|
p.fillRect(width() - st::notifyBorderWidth, st::notifyBorderWidth, st::notifyBorderWidth, height() - 2 * st::notifyBorderWidth, st::notifyBorder);
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
p.setFont(st::defaultLinkButton.font);
|
2017-06-14 09:25:09 +00:00
|
|
|
p.setPen(_mouseOver ? st::lightButtonFgOver : st::lightButtonFg);
|
2019-06-19 15:09:03 +00:00
|
|
|
p.drawText(rect(), tr::lng_notification_hide_all(tr::now), style::al_center);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
2016-10-02 13:54:27 +00:00
|
|
|
} // namespace Default
|
2016-10-02 09:30:28 +00:00
|
|
|
} // namespace Notifications
|
|
|
|
} // namespace Window
|