2016-10-02 12:30:28 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
2016-10-02 16:54:27 +03:00
|
|
|
#include "window/notifications_manager_default.h"
|
2016-10-02 12:30:28 +03:00
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
#include "platform/platform_notifications_manager.h"
|
2016-10-02 12:30:28 +03:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "dialogs/dialogs_layout.h"
|
|
|
|
#include "styles/style_dialogs.h"
|
|
|
|
|
|
|
|
namespace Window {
|
|
|
|
namespace Notifications {
|
2016-10-02 16:54:27 +03:00
|
|
|
namespace Default {
|
|
|
|
namespace {
|
2016-10-02 12:30:28 +03:00
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
// 3 desktop notifies at the same time.
|
|
|
|
constexpr int kNotifyWindowsCount = 3;
|
|
|
|
|
2016-10-02 18:44:54 +03:00
|
|
|
NeverFreedPointer<Manager> ManagerInstance;
|
2016-10-02 16:54:27 +03:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void start() {
|
2016-10-02 18:44:54 +03:00
|
|
|
ManagerInstance.makeIfNull();
|
2016-10-02 16:54:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Manager *manager() {
|
2016-10-02 18:44:54 +03:00
|
|
|
return ManagerInstance.data();
|
2016-10-02 16:54:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void finish() {
|
2016-10-02 18:44:54 +03:00
|
|
|
ManagerInstance.clear();
|
2016-10-02 16:54:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Manager::Manager() {
|
|
|
|
subscribe(FileDownload::ImageLoaded(), [this] {
|
|
|
|
for_const (auto widget, _widgets) {
|
|
|
|
widget->updatePeerPhoto();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::startAllHiding() {
|
|
|
|
for_const (auto widget, _widgets) {
|
|
|
|
widget->startHiding();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::stopAllHiding() {
|
|
|
|
for_const (auto widget, _widgets) {
|
|
|
|
widget->stopHiding();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::showNextFromQueue() {
|
|
|
|
if (_queuedNotifications.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = kNotifyWindowsCount;
|
|
|
|
for_const (auto widget, _widgets) {
|
|
|
|
if (widget->index() < 0) continue;
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
if (count <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto r = psDesktopRect();
|
|
|
|
auto x = r.x() + r.width() - st::notifyWidth - st::notifyDeltaX;
|
|
|
|
auto y = r.y() + r.height() - st::notifyHeight - st::notifyDeltaY;
|
|
|
|
do {
|
|
|
|
auto queued = _queuedNotifications.front();
|
|
|
|
_queuedNotifications.pop_front();
|
|
|
|
|
|
|
|
auto widget = std_::make_unique<Widget>(queued.history, queued.peer, queued.author, queued.item, queued.forwardedCount, x, y);
|
|
|
|
Platform::Notifications::defaultNotificationShown(widget.get());
|
|
|
|
_widgets.push_back(widget.release());
|
|
|
|
--count;
|
|
|
|
} while (count > 0 && !_queuedNotifications.isEmpty());
|
|
|
|
|
|
|
|
auto shown = kNotifyWindowsCount - count;
|
|
|
|
for_const (auto widget, _widgets) {
|
|
|
|
if (widget->index() < 0) continue;
|
|
|
|
--shown;
|
|
|
|
widget->moveTo(x, y - shown * (st::notifyHeight + st::notifyDeltaY));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::removeFromShown(Widget *remove) {
|
|
|
|
if (remove) {
|
|
|
|
auto index = _widgets.indexOf(remove);
|
|
|
|
if (index >= 0) {
|
|
|
|
_widgets.removeAt(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
showNextFromQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::doShowNotification(HistoryItem *item, int forwardedCount) {
|
|
|
|
_queuedNotifications.push_back(QueuedNotification(item, forwardedCount));
|
|
|
|
showNextFromQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::doClearAll() {
|
|
|
|
_queuedNotifications.clear();
|
|
|
|
for_const (auto widget, _widgets) {
|
|
|
|
widget->unlinkHistory();
|
|
|
|
}
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
void Manager::doClearAllFast() {
|
|
|
|
_queuedNotifications.clear();
|
|
|
|
|
|
|
|
auto widgets = createAndSwap(_widgets);
|
|
|
|
for_const (auto widget, widgets) {
|
|
|
|
widget->deleteLater();
|
|
|
|
}
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
void Manager::doClearFromHistory(History *history) {
|
|
|
|
for (auto i = _queuedNotifications.begin(); i != _queuedNotifications.cend();) {
|
|
|
|
if (i->history == history) {
|
|
|
|
i = _queuedNotifications.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for_const (auto widget, _widgets) {
|
|
|
|
widget->unlinkHistory(history);
|
|
|
|
}
|
|
|
|
showNextFromQueue();
|
|
|
|
}
|
2016-10-02 12:30:28 +03:00
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
void Manager::doClearFromItem(HistoryItem *item) {
|
|
|
|
for_const (auto widget, _widgets) {
|
|
|
|
widget->itemRemoved(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::doUpdateAll() {
|
|
|
|
for_const (auto widget, _widgets) {
|
|
|
|
widget->updateNotifyDisplay();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Manager::~Manager() {
|
|
|
|
clearAllFast();
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget::Widget(History *history, PeerData *peer, PeerData *author, HistoryItem *msg, int forwardedCount, int x, int y) : TWidget(nullptr)
|
|
|
|
, _history(history)
|
|
|
|
, _peer(peer)
|
|
|
|
, _author(author)
|
|
|
|
, _item(msg)
|
|
|
|
, _forwardedCount(forwardedCount)
|
2016-10-02 12:30:28 +03:00
|
|
|
#if defined Q_OS_WIN && !defined Q_OS_WINRT
|
2016-10-02 16:54:27 +03:00
|
|
|
, _started(GetTickCount())
|
2016-10-02 12:30:28 +03:00
|
|
|
#endif // Q_OS_WIN && !Q_OS_WINRT
|
2016-10-02 16:54:27 +03:00
|
|
|
, _close(this, st::notifyClose)
|
|
|
|
, _alphaDuration(st::notifyFastAnim)
|
|
|
|
, _posDuration(st::notifyFastAnim)
|
2016-10-02 12:30:28 +03:00
|
|
|
, a_opacity(0)
|
|
|
|
, a_func(anim::linear)
|
|
|
|
, a_y(y + st::notifyHeight + st::notifyDeltaY)
|
|
|
|
, _a_appearance(animation(this, &Widget::step_appearance)) {
|
|
|
|
updateNotifyDisplay();
|
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
_hideTimer.setSingleShot(true);
|
|
|
|
connect(&_hideTimer, SIGNAL(timeout()), this, SLOT(hideByTimer()));
|
2016-10-02 12:30:28 +03:00
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
_inputTimer.setSingleShot(true);
|
|
|
|
connect(&_inputTimer, SIGNAL(timeout()), this, SLOT(checkLastInput()));
|
2016-10-02 12:30:28 +03:00
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
_close.setClickedCallback([this] {
|
2016-10-02 12:30:28 +03:00
|
|
|
unlinkHistoryAndNotify();
|
|
|
|
});
|
2016-10-02 16:54:27 +03:00
|
|
|
_close.setAcceptBoth(true);
|
|
|
|
_close.move(st::notifyWidth - st::notifyClose.width - st::notifyClosePos.x(), st::notifyClosePos.y());
|
|
|
|
_close.show();
|
2016-10-02 12:30:28 +03:00
|
|
|
|
|
|
|
a_y.start(y);
|
|
|
|
setGeometry(x, a_y.current(), st::notifyWidth, st::notifyHeight);
|
|
|
|
|
|
|
|
a_opacity.start(1);
|
|
|
|
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
|
|
|
|
setAttribute(Qt::WA_MacAlwaysShowToolWindow);
|
|
|
|
|
|
|
|
show();
|
|
|
|
|
|
|
|
setWindowOpacity(a_opacity.current());
|
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
_alphaDuration = _posDuration = st::notifyFastAnim;
|
2016-10-02 12:30:28 +03:00
|
|
|
_a_appearance.start();
|
|
|
|
|
|
|
|
checkLastInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::checkLastInput() {
|
|
|
|
#if defined Q_OS_WIN && !defined Q_OS_WINRT
|
|
|
|
LASTINPUTINFO lii;
|
|
|
|
lii.cbSize = sizeof(LASTINPUTINFO);
|
|
|
|
BOOL res = GetLastInputInfo(&lii);
|
2016-10-02 16:54:27 +03:00
|
|
|
if (!res || lii.dwTime >= _started) {
|
|
|
|
_hideTimer.start(st::notifyWaitLongHide);
|
2016-10-02 12:30:28 +03:00
|
|
|
} else {
|
2016-10-02 16:54:27 +03:00
|
|
|
_inputTimer.start(300);
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
#else // Q_OS_WIN && !Q_OS_WINRT
|
|
|
|
// TODO
|
|
|
|
if (true) {
|
2016-10-02 16:54:27 +03:00
|
|
|
_hideTimer.start(st::notifyWaitLongHide);
|
2016-10-02 12:30:28 +03:00
|
|
|
} else {
|
2016-10-02 16:54:27 +03:00
|
|
|
_inputTimer.start(300);
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
#endif // else for Q_OS_WIN && !Q_OS_WINRT
|
|
|
|
}
|
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
void Widget::moveTo(int x, int y, int index) {
|
2016-10-02 12:30:28 +03:00
|
|
|
if (index >= 0) {
|
|
|
|
_index = index;
|
|
|
|
}
|
|
|
|
move(x, a_y.current());
|
|
|
|
a_y.start(y);
|
|
|
|
a_opacity.restart();
|
2016-10-02 16:54:27 +03:00
|
|
|
_posDuration = st::notifyFastAnim;
|
2016-10-02 12:30:28 +03:00
|
|
|
_a_appearance.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updateNotifyDisplay() {
|
2016-10-02 16:54:27 +03:00
|
|
|
if (!_history || !_peer || (!_item && _forwardedCount < 2)) return;
|
2016-10-02 12:30:28 +03:00
|
|
|
|
|
|
|
int32 w = st::notifyWidth, h = st::notifyHeight;
|
|
|
|
QImage img(w * cIntRetinaFactor(), h * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
if (cRetina()) img.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
img.fill(st::notifyBG->c);
|
|
|
|
|
|
|
|
{
|
|
|
|
Painter p(&img);
|
|
|
|
p.fillRect(0, 0, w - st::notifyBorderWidth, st::notifyBorderWidth, st::notifyBorder->b);
|
|
|
|
p.fillRect(w - st::notifyBorderWidth, 0, st::notifyBorderWidth, h - st::notifyBorderWidth, st::notifyBorder->b);
|
|
|
|
p.fillRect(st::notifyBorderWidth, h - st::notifyBorderWidth, w - st::notifyBorderWidth, st::notifyBorderWidth, st::notifyBorder->b);
|
|
|
|
p.fillRect(0, st::notifyBorderWidth, st::notifyBorderWidth, h - st::notifyBorderWidth, st::notifyBorder->b);
|
|
|
|
|
|
|
|
if (!App::passcoded() && Global::NotifyView() <= dbinvShowName) {
|
2016-10-02 16:54:27 +03:00
|
|
|
_history->peer->loadUserpic(true, true);
|
|
|
|
_history->peer->paintUserpicLeft(p, st::notifyPhotoSize, st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), width());
|
2016-10-02 12:30:28 +03:00
|
|
|
} else {
|
|
|
|
static QPixmap icon = App::pixmapFromImageInPlace(App::wnd()->iconLarge().scaled(st::notifyPhotoSize, st::notifyPhotoSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
|
|
|
p.drawPixmap(st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (!App::passcoded() && Global::NotifyView() <= dbinvShowName) {
|
2016-10-02 16:54:27 +03:00
|
|
|
if (auto chatTypeIcon = Dialogs::Layout::ChatTypeIcon(_history->peer, false)) {
|
2016-10-02 12:30:28 +03:00
|
|
|
chatTypeIcon->paint(p, rectForName.topLeft(), w);
|
|
|
|
rectForName.setLeft(rectForName.left() + st::dialogsChatTypeSkip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!App::passcoded() && Global::NotifyView() <= dbinvShowPreview) {
|
|
|
|
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 16:54:27 +03:00
|
|
|
if (_item) {
|
2016-10-02 12:30:28 +03:00
|
|
|
bool active = false;
|
2016-10-02 16:54:27 +03:00
|
|
|
_item->drawInDialog(p, r, active, textCachedFor, itemTextCache);
|
|
|
|
} else if (_forwardedCount > 1) {
|
2016-10-02 12:30:28 +03:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2016-10-02 16:54:27 +03:00
|
|
|
if (_author) {
|
|
|
|
itemTextCache.setText(st::dialogsTextFont, _author->name);
|
2016-10-02 12:30:28 +03:00
|
|
|
p.setPen(st::dialogsTextFgService);
|
|
|
|
itemTextCache.drawElided(p, r.left(), r.top(), r.width(), st::dialogsTextFont->height);
|
|
|
|
r.setTop(r.top() + st::dialogsTextFont->height);
|
|
|
|
}
|
|
|
|
p.setPen(st::dialogsTextFg);
|
2016-10-02 16:54:27 +03:00
|
|
|
p.drawText(r.left(), r.top() + st::dialogsTextFont->ascent, lng_forward_messages(lt_count, _forwardedCount));
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
static QString notifyText = st::dialogsTextFont->elided(lang(lng_notification_preview), itemWidth);
|
2016-10-02 16:54:27 +03:00
|
|
|
p.setFont(st::dialogsTextFont);
|
2016-10-02 12:30:28 +03: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);
|
|
|
|
if (!App::passcoded() && Global::NotifyView() <= dbinvShowName) {
|
2016-10-02 16:54:27 +03:00
|
|
|
_history->peer->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
|
2016-10-02 12:30:28 +03:00
|
|
|
} else {
|
2016-10-02 16:54:27 +03:00
|
|
|
p.setFont(st::msgNameFont);
|
2016-10-02 12:30:28 +03:00
|
|
|
static QString notifyTitle = st::msgNameFont->elided(qsl("Telegram Desktop"), rectForName.width());
|
|
|
|
p.drawText(rectForName.left(), rectForName.top() + st::msgNameFont->ascent, notifyTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
_cache = App::pixmapFromImageInPlace(std_::move(img));
|
2016-10-02 12:30:28 +03:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updatePeerPhoto() {
|
|
|
|
if (!peerPhoto->isNull() && peerPhoto->loaded()) {
|
2016-10-02 16:54:27 +03:00
|
|
|
auto img = _cache.toImage();
|
2016-10-02 12:30:28 +03:00
|
|
|
{
|
2016-10-02 16:54:27 +03:00
|
|
|
Painter p(&img);
|
2016-10-02 12:30:28 +03:00
|
|
|
p.drawPixmap(st::notifyPhotoPos.x(), st::notifyPhotoPos.y(), peerPhoto->pix(st::notifyPhotoSize));
|
|
|
|
}
|
|
|
|
peerPhoto = ImagePtr();
|
2016-10-02 16:54:27 +03:00
|
|
|
_cache = App::pixmapFromImageInPlace(std_::move(img));
|
2016-10-02 12:30:28 +03:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
void Widget::itemRemoved(HistoryItem *deleted) {
|
|
|
|
if (_item && _item == deleted) {
|
|
|
|
_item = nullptr;
|
2016-10-02 12:30:28 +03:00
|
|
|
unlinkHistoryAndNotify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::unlinkHistoryAndNotify() {
|
|
|
|
unlinkHistory();
|
2016-10-02 18:44:54 +03:00
|
|
|
if (auto manager = ManagerInstance.data()) {
|
2016-10-02 16:54:27 +03:00
|
|
|
manager->showNextFromQueue();
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
void Widget::unlinkHistory(History *history) {
|
|
|
|
if (!history || history == _history) {
|
2016-10-02 12:30:28 +03:00
|
|
|
animHide(st::notifyFastAnim, anim::linear);
|
2016-10-02 16:54:27 +03:00
|
|
|
_history = nullptr;
|
|
|
|
_item = nullptr;
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::enterEvent(QEvent *e) {
|
2016-10-02 16:54:27 +03:00
|
|
|
if (!_history) return;
|
2016-10-02 18:44:54 +03:00
|
|
|
if (auto manager = ManagerInstance.data()) {
|
2016-10-02 16:54:27 +03:00
|
|
|
manager->stopAllHiding();
|
|
|
|
}
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::leaveEvent(QEvent *e) {
|
2016-10-02 16:54:27 +03:00
|
|
|
if (!_history) return;
|
2016-10-02 18:44:54 +03:00
|
|
|
if (auto manager = ManagerInstance.data()) {
|
2016-10-02 16:54:27 +03:00
|
|
|
manager->startAllHiding();
|
|
|
|
}
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::startHiding() {
|
2016-10-02 16:54:27 +03:00
|
|
|
_hideTimer.start(st::notifyWaitShortHide);
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::mousePressEvent(QMouseEvent *e) {
|
2016-10-02 16:54:27 +03:00
|
|
|
if (!_history) return;
|
2016-10-02 12:30:28 +03:00
|
|
|
|
|
|
|
if (e->button() == Qt::RightButton) {
|
|
|
|
unlinkHistoryAndNotify();
|
|
|
|
} else {
|
|
|
|
e->ignore();
|
2016-10-02 19:32:46 +03:00
|
|
|
if (auto manager = ManagerInstance.data()) {
|
|
|
|
auto peerId = _history->peer->id;
|
|
|
|
auto msgId = _item ? _item->id : ShowAtUnreadMsgId;
|
|
|
|
manager->notificationActivated(peerId, msgId);
|
|
|
|
}
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::paintEvent(QPaintEvent *e) {
|
|
|
|
QPainter p(this);
|
2016-10-02 16:54:27 +03:00
|
|
|
p.drawPixmap(0, 0, _cache);
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::animHide(float64 duration, anim::transition func) {
|
2016-10-02 16:54:27 +03:00
|
|
|
if (!_history) return;
|
|
|
|
_alphaDuration = duration;
|
2016-10-02 12:30:28 +03:00
|
|
|
a_func = func;
|
|
|
|
a_opacity.start(0);
|
|
|
|
a_y.restart();
|
2016-10-02 16:54:27 +03:00
|
|
|
_hiding = true;
|
2016-10-02 12:30:28 +03:00
|
|
|
_a_appearance.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::stopHiding() {
|
2016-10-02 16:54:27 +03:00
|
|
|
if (!_history) return;
|
|
|
|
_alphaDuration = st::notifyFastAnim;
|
2016-10-02 12:30:28 +03:00
|
|
|
a_func = anim::linear;
|
|
|
|
a_opacity.start(1);
|
|
|
|
a_y.restart();
|
2016-10-02 16:54:27 +03:00
|
|
|
_hiding = false;
|
|
|
|
_hideTimer.stop();
|
2016-10-02 12:30:28 +03:00
|
|
|
_a_appearance.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::hideByTimer() {
|
2016-10-02 16:54:27 +03:00
|
|
|
if (!_history) return;
|
2016-10-02 12:30:28 +03:00
|
|
|
animHide(st::notifySlowHide, st::notifySlowHideFunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::step_appearance(float64 ms, bool timer) {
|
2016-10-02 16:54:27 +03:00
|
|
|
float64 dtAlpha = ms / _alphaDuration, dtPos = ms / _posDuration;
|
2016-10-02 12:30:28 +03:00
|
|
|
if (dtAlpha >= 1) {
|
|
|
|
a_opacity.finish();
|
2016-10-02 16:54:27 +03:00
|
|
|
if (_hiding) {
|
2016-10-02 12:30:28 +03:00
|
|
|
_a_appearance.stop();
|
|
|
|
deleteLater();
|
|
|
|
} else if (dtPos >= 1) {
|
|
|
|
_a_appearance.stop();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
a_opacity.update(dtAlpha, a_func);
|
|
|
|
}
|
|
|
|
setWindowOpacity(a_opacity.current());
|
|
|
|
if (dtPos >= 1) {
|
|
|
|
a_y.finish();
|
|
|
|
} else {
|
|
|
|
a_y.update(dtPos, anim::linear);
|
|
|
|
}
|
|
|
|
move(x(), a_y.current());
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget::~Widget() {
|
2016-10-02 18:44:54 +03:00
|
|
|
if (auto manager = ManagerInstance.data()) {
|
2016-10-02 16:54:27 +03:00
|
|
|
manager->removeFromShown(this);
|
|
|
|
}
|
2016-10-02 12:30:28 +03:00
|
|
|
}
|
|
|
|
|
2016-10-02 16:54:27 +03:00
|
|
|
} // namespace Default
|
2016-10-02 12:30:28 +03:00
|
|
|
} // namespace Notifications
|
|
|
|
} // namespace Window
|