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"
|
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"
|
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"
|
2016-10-02 09:30:28 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-10-04 18:18:08 +00:00
|
|
|
#include "styles/style_window.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "storage/file_download.h"
|
|
|
|
#include "auth_session.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"
|
2017-05-12 15:27:19 +00:00
|
|
|
#include "platform/platform_specific.h"
|
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() {
|
|
|
|
auto r = psDesktopRect();
|
|
|
|
auto isLeft = Notify::IsLeftCorner(Global::NotificationsCorner());
|
|
|
|
auto isTop = Notify::IsTopCorner(Global::NotificationsCorner());
|
|
|
|
auto x = (isLeft == rtl()) ? (r.x() + r.width() - st::notifyWidth - st::notifyDeltaX) : (r.x() + st::notifyDeltaX);
|
|
|
|
auto y = isTop ? r.y() : (r.y() + r.height());
|
|
|
|
return QPoint(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal::Widget::Direction notificationShiftDirection() {
|
|
|
|
auto isTop = Notify::IsTopCorner(Global::NotificationsCorner());
|
|
|
|
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(); }) {
|
2017-03-15 16:24:06 +00:00
|
|
|
subscribe(system->authSession()->downloader().taskFinished(), [this] {
|
2017-03-04 19:36:59 +00:00
|
|
|
for_const (auto ¬ification, _notifications) {
|
2016-10-05 16:56:27 +00:00
|
|
|
notification->updatePeerPhoto();
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
});
|
2017-03-04 19:36:59 +00:00
|
|
|
subscribe(system->settingsChanged(), [this](ChangeType change) {
|
2016-10-06 16:41:09 +00:00
|
|
|
settingsChanged(change);
|
|
|
|
});
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
Manager::QueuedNotification::QueuedNotification(
|
|
|
|
not_null<HistoryItem*> item
|
|
|
|
, int forwardedCount)
|
|
|
|
: history(item->history())
|
|
|
|
, peer(history->peer)
|
2018-01-13 12:45:11 +00:00
|
|
|
, author((!peer->isUser() && !item->isPost()) ? item->author().get() : nullptr)
|
2018-01-11 19:33:26 +00:00
|
|
|
, item((forwardedCount < 2) ? item.get() : nullptr)
|
|
|
|
, forwardedCount(forwardedCount) {
|
|
|
|
}
|
|
|
|
|
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) {
|
2016-10-06 16:41:09 +00:00
|
|
|
int allow = Global::NotificationsCount();
|
|
|
|
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 {
|
|
|
|
return _demoMasterOpacity.current(Global::NotificationsDemoIsShown() ? 0. : 1.);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
int count = Global::NotificationsCount();
|
|
|
|
for_const (auto ¬ification, _notifications) {
|
|
|
|
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();
|
|
|
|
|
|
|
|
auto notification = std::make_unique<Notification>(
|
|
|
|
this,
|
|
|
|
queued.history,
|
|
|
|
queued.peer,
|
|
|
|
queued.author,
|
|
|
|
queued.item,
|
|
|
|
queued.forwardedCount,
|
|
|
|
startPosition, startShift, shiftDirection);
|
|
|
|
_notifications.push_back(std::move(notification));
|
|
|
|
--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
|
|
|
|
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) {
|
|
|
|
auto it = std::find_if(_notifications.cbegin(), _notifications.cend(), [remove](auto &item) {
|
|
|
|
return item.get() == remove;
|
|
|
|
});
|
|
|
|
if (it != _notifications.cend()) {
|
|
|
|
_notifications.erase(it);
|
2016-10-05 16:56:27 +00:00
|
|
|
_positionsOutdated = true;
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
showNextFromQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::doShowNotification(HistoryItem *item, int forwardedCount) {
|
|
|
|
_queuedNotifications.push_back(QueuedNotification(item, forwardedCount));
|
|
|
|
showNextFromQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::doClearAll() {
|
|
|
|
_queuedNotifications.clear();
|
2017-03-04 19:36:59 +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
|
|
|
}
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
void Manager::doClearFromHistory(History *history) {
|
|
|
|
for (auto i = _queuedNotifications.begin(); i != _queuedNotifications.cend();) {
|
|
|
|
if (i->history == history) {
|
|
|
|
i = _queuedNotifications.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
2017-03-04 19:36:59 +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
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
void Manager::doClearFromItem(HistoryItem *item) {
|
2017-03-04 19:36:59 +00:00
|
|
|
_queuedNotifications.erase(std::remove_if(_queuedNotifications.begin(), _queuedNotifications.end(), [item](auto &queued) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
Widget::Widget(Manager *manager, QPoint startPosition, int shift, Direction shiftDirection) : TWidget(nullptr)
|
|
|
|
, _manager(manager)
|
2016-10-06 16:41:09 +00:00
|
|
|
, _startPosition(startPosition)
|
|
|
|
, _direction(shiftDirection)
|
|
|
|
, a_shift(shift)
|
|
|
|
, _a_shift(animation(this, &Widget::step_shift)) {
|
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);
|
|
|
|
|
|
|
|
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.
|
|
|
|
App::CallDelayed(1000, this, [this] {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
void Widget::step_shift(float64 ms, bool timer) {
|
2018-09-20 16:39:59 +00:00
|
|
|
if (anim::Disabled()) {
|
|
|
|
ms += st::notifyFastAnim;
|
|
|
|
}
|
2016-10-05 16:56:27 +00:00
|
|
|
float64 dt = ms / float64(st::notifyFastAnim);
|
|
|
|
if (dt >= 1) {
|
2016-10-06 16:41:09 +00:00
|
|
|
a_shift.finish();
|
2016-10-05 16:56:27 +00:00
|
|
|
} else {
|
2016-10-06 16:41:09 +00:00
|
|
|
a_shift.update(dt, anim::linear);
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
2016-10-06 16:41:09 +00:00
|
|
|
moveByShift();
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::hideSlow() {
|
2018-09-21 18:14:48 +00:00
|
|
|
if (anim::Disabled()) {
|
|
|
|
_hiding = true;
|
|
|
|
auto [left, right] = base::make_binary_guard();
|
|
|
|
_hidingDelayed = std::move(left);
|
|
|
|
App::CallDelayed(st::notifySlowHide, this, [=, guard = std::move(right)] {
|
2019-01-17 08:18:23 +00:00
|
|
|
if (guard && _hiding) {
|
2018-09-21 18:14:48 +00:00
|
|
|
hideFast();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} 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() {
|
2017-03-04 19:36:59 +00:00
|
|
|
setWindowOpacity(_a_opacity.current(_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) {
|
|
|
|
a_shift.start(top);
|
|
|
|
_a_shift.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);
|
2016-11-04 11:14:47 +00:00
|
|
|
psUpdateOverlayed(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);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
void Widget::addToShift(int add) {
|
|
|
|
a_shift.add(add);
|
|
|
|
moveByShift();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::moveByShift() {
|
|
|
|
move(computePosition(height()));
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Widget::computePosition(int height) const {
|
2016-12-05 11:01:08 +00:00
|
|
|
auto realShift = qRound(a_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(
|
|
|
|
Manager *manager,
|
|
|
|
History *history,
|
|
|
|
PeerData *peer,
|
|
|
|
PeerData *author,
|
|
|
|
HistoryItem *msg,
|
|
|
|
int forwardedCount,
|
|
|
|
QPoint startPosition,
|
|
|
|
int shift,
|
|
|
|
Direction shiftDirection)
|
|
|
|
: Widget(manager, startPosition, shift, shiftDirection)
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
, _started(GetTickCount())
|
|
|
|
#endif // Q_OS_WIN
|
2016-10-02 13:54:27 +00:00
|
|
|
, _history(history)
|
|
|
|
, _peer(peer)
|
|
|
|
, _author(author)
|
|
|
|
, _item(msg)
|
|
|
|
, _forwardedCount(forwardedCount)
|
|
|
|
, _close(this, st::notifyClose)
|
2017-05-30 15:21:05 +00:00
|
|
|
, _reply(this, langFactory(lng_notification_reply), st::defaultBoxButton) {
|
|
|
|
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
|
|
|
|
|
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
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
_userpicLoaded = _peer ? _peer->userpicLoaded() : true;
|
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);
|
|
|
|
st::notifyFadeRight.fill(p, rtlrect(0, 0, fadeWidth, actionsCacheHeight, actionsCacheWidth));
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(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;
|
|
|
|
|
|
|
|
auto wasUserInput = true; // TODO
|
2017-02-28 10:51:00 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2016-10-02 09:30:28 +00:00
|
|
|
LASTINPUTINFO lii;
|
|
|
|
lii.cbSize = sizeof(LASTINPUTINFO);
|
|
|
|
BOOL res = GetLastInputInfo(&lii);
|
2016-10-05 16:56:27 +00:00
|
|
|
wasUserInput = (!res || lii.dwTime >= _started);
|
2017-02-28 10:51:00 +00:00
|
|
|
#endif // Q_OS_WIN
|
2016-10-05 16:56:27 +00:00
|
|
|
if (wasUserInput) {
|
|
|
|
_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;
|
|
|
|
if (a_actionsOpacity.animating(getms())) {
|
|
|
|
p.setOpacity(a_actionsOpacity.current());
|
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() {
|
2016-10-02 13:54:27 +00:00
|
|
|
if (!_history || !_peer || (!_item && _forwardedCount < 2)) return;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-08 08:38:53 +00:00
|
|
|
auto options = Manager::getNotificationOptions(_item);
|
|
|
|
_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) {
|
2016-10-02 13:54:27 +00:00
|
|
|
_history->peer->loadUserpic(true, true);
|
2016-12-29 09:03:51 +00:00
|
|
|
_history->peer->paintUserpicLeft(p, st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), width(), st::notifyPhotoSize);
|
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());
|
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);
|
2016-10-08 08:38:53 +00:00
|
|
|
if (!options.hideNameAndPhoto) {
|
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) {
|
2016-10-02 09:30:28 +00:00
|
|
|
const HistoryItem *textCachedFor = 0;
|
|
|
|
Text itemTextCache(itemWidth);
|
|
|
|
QRect r(st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft, st::notifyItemTop + st::msgNameFont->height, itemWidth, 2 * st::dialogsTextFont->height);
|
2016-10-02 13:54:27 +00:00
|
|
|
if (_item) {
|
2016-11-05 08:36:24 +00:00
|
|
|
auto active = false, selected = false;
|
2017-09-05 17:21:56 +00:00
|
|
|
_item->drawInDialog(
|
|
|
|
p,
|
|
|
|
r,
|
|
|
|
active,
|
|
|
|
selected,
|
|
|
|
HistoryItem::DrawInDialog::Normal,
|
|
|
|
textCachedFor,
|
|
|
|
itemTextCache);
|
2016-10-02 13:54:27 +00:00
|
|
|
} else if (_forwardedCount > 1) {
|
2016-10-02 09:30:28 +00:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2016-10-02 13:54:27 +00:00
|
|
|
if (_author) {
|
2016-12-23 13:21:01 +00:00
|
|
|
itemTextCache.setText(st::dialogsTextStyle, _author->name);
|
2016-10-02 09:30:28 +00:00
|
|
|
p.setPen(st::dialogsTextFgService);
|
2018-03-14 23:40:35 +00:00
|
|
|
itemTextCache.drawElided(p, r.left(), r.top(), r.width());
|
2016-10-02 09:30:28 +00:00
|
|
|
r.setTop(r.top() + st::dialogsTextFont->height);
|
|
|
|
}
|
|
|
|
p.setPen(st::dialogsTextFg);
|
2016-10-02 13:54:27 +00:00
|
|
|
p.drawText(r.left(), r.top() + st::dialogsTextFont->ascent, lng_forward_messages(lt_count, _forwardedCount));
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
static QString notifyText = st::dialogsTextFont->elided(lang(lng_notification_preview), itemWidth);
|
2016-10-02 13:54:27 +00:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2016-10-02 09:30:28 +00:00
|
|
|
p.setPen(st::dialogsTextFgService);
|
|
|
|
p.drawText(st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft, st::notifyItemTop + st::msgNameFont->height + st::dialogsTextFont->ascent, notifyText);
|
|
|
|
}
|
|
|
|
|
|
|
|
p.setPen(st::dialogsNameFg);
|
2016-10-08 08:38:53 +00:00
|
|
|
if (!options.hideNameAndPhoto) {
|
2016-10-02 13:54:27 +00:00
|
|
|
_history->peer->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
|
2016-10-02 09:30:28 +00:00
|
|
|
} else {
|
2016-10-02 13:54:27 +00:00
|
|
|
p.setFont(st::msgNameFont);
|
2016-10-02 09:30:28 +00:00
|
|
|
static QString notifyTitle = st::msgNameFont->elided(qsl("Telegram Desktop"), rectForName.width());
|
|
|
|
p.drawText(rectForName.left(), rectForName.top() + st::msgNameFont->ascent, notifyTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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() {
|
|
|
|
if (_userpicLoaded || !_peer || !_peer->userpicLoaded()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_userpicLoaded = true;
|
|
|
|
|
|
|
|
auto img = _cache.toImage();
|
|
|
|
{
|
|
|
|
Painter p(&img);
|
2016-12-29 09:03:51 +00:00
|
|
|
_peer->paintUserpicLeft(p, 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));
|
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)
|
2019-01-21 13:42:21 +00:00
|
|
|
&& !Core::App().locked()
|
2018-06-03 13:30:40 +00:00
|
|
|
&& (Global::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() {
|
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,
|
|
|
|
langFactory(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);
|
2018-05-21 21:31:46 +00:00
|
|
|
_replyArea->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
|
2018-05-20 17:42:30 +00:00
|
|
|
_replyArea->setInstantReplaces(Ui::InstantReplaces::Default());
|
2018-05-24 13:03:21 +00:00
|
|
|
_replyArea->setInstantReplacesEnabled(Global::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;
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
auto peerId = _history->peer->id;
|
|
|
|
auto msgId = _item ? _item->id : ShowAtUnreadMsgId;
|
2018-05-24 13:03:21 +00:00
|
|
|
manager()->notificationReplied(
|
|
|
|
peerId,
|
|
|
|
msgId,
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
auto unlink = _history && (history == _history || !history);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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();
|
2017-03-04 19:36:59 +00:00
|
|
|
auto peerId = _history->peer->id;
|
|
|
|
auto msgId = _item ? _item->id : ShowAtUnreadMsgId;
|
|
|
|
manager()->notificationActivated(peerId, msgId);
|
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)) {
|
|
|
|
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
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
HideAllButton::HideAllButton(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);
|
2016-10-05 16:56:27 +00:00
|
|
|
p.drawText(rect(), lang(lng_notification_hide_all), style::al_center);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
2016-10-02 13:54:27 +00:00
|
|
|
} // namespace Default
|
2016-10-02 09:30:28 +00:00
|
|
|
} // namespace Notifications
|
|
|
|
} // namespace Window
|