2016-10-02 09:30:28 +00: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
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-10-02 09:30:28 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
#include "window/notifications_manager.h"
|
2016-10-05 16:56:27 +00:00
|
|
|
#include "core/single_timer.h"
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-04 18:18:08 +00:00
|
|
|
namespace Ui {
|
|
|
|
class IconButton;
|
2016-11-11 13:46:04 +00:00
|
|
|
class RoundButton;
|
2016-11-15 11:56:49 +00:00
|
|
|
class InputArea;
|
2016-10-04 18:18:08 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2016-10-02 09:30:28 +00:00
|
|
|
namespace Window {
|
|
|
|
namespace Notifications {
|
2016-10-02 13:54:27 +00:00
|
|
|
namespace Default {
|
2016-10-05 16:56:27 +00:00
|
|
|
namespace internal {
|
2016-10-06 16:41:09 +00:00
|
|
|
class Widget;
|
2016-10-05 16:56:27 +00:00
|
|
|
class Notification;
|
|
|
|
class HideAllButton;
|
|
|
|
} // namespace internal
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
class Manager;
|
2017-03-04 19:36:59 +00:00
|
|
|
std::unique_ptr<Manager> Create(System *system);
|
2016-10-02 13:54:27 +00:00
|
|
|
|
|
|
|
class Manager : public Notifications::Manager, private base::Subscriber {
|
2016-10-02 09:30:28 +00:00
|
|
|
public:
|
2017-03-04 19:36:59 +00:00
|
|
|
Manager(System *system);
|
2016-10-02 13:54:27 +00:00
|
|
|
|
|
|
|
template <typename Method>
|
2016-10-05 16:56:27 +00:00
|
|
|
void enumerateNotifications(Method method) {
|
2017-03-04 19:36:59 +00:00
|
|
|
for_const (auto ¬ification, _notifications) {
|
2016-10-05 16:56:27 +00:00
|
|
|
method(notification);
|
2016-10-02 13:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~Manager();
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
private:
|
2016-10-07 13:14:02 +00:00
|
|
|
friend class internal::Notification;
|
|
|
|
friend class internal::HideAllButton;
|
|
|
|
friend class internal::Widget;
|
2016-10-05 16:56:27 +00:00
|
|
|
using Notification = internal::Notification;
|
|
|
|
using HideAllButton = internal::HideAllButton;
|
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
QPixmap hiddenUserpicPlaceholder() const;
|
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
void doUpdateAll() override;
|
|
|
|
void doShowNotification(HistoryItem *item, int forwardedCount) override;
|
|
|
|
void doClearAll() override;
|
|
|
|
void doClearAllFast() override;
|
|
|
|
void doClearFromHistory(History *history) override;
|
|
|
|
void doClearFromItem(HistoryItem *item) override;
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void showNextFromQueue();
|
|
|
|
void unlinkFromShown(Notification *remove);
|
|
|
|
void startAllHiding();
|
|
|
|
void stopAllHiding();
|
|
|
|
void checkLastInput();
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
void removeWidget(internal::Widget *remove);
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
float64 demoMasterOpacity() const;
|
|
|
|
void demoMasterOpacityCallback();
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void moveWidgets();
|
|
|
|
void changeNotificationHeight(Notification *widget, int newHeight);
|
2017-03-04 19:36:59 +00:00
|
|
|
void settingsChanged(ChangeType change);
|
2016-10-06 16:41:09 +00:00
|
|
|
|
|
|
|
bool hasReplyingNotification() const;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
std::vector<std::unique_ptr<Notification>> _notifications;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
std::unique_ptr<HideAllButton> _hideAll;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
bool _positionsOutdated = false;
|
|
|
|
SingleTimer _inputCheckTimer;
|
2016-10-02 13:54:27 +00:00
|
|
|
|
|
|
|
struct QueuedNotification {
|
|
|
|
QueuedNotification(HistoryItem *item, int forwardedCount)
|
|
|
|
: history(item->history())
|
|
|
|
, peer(history->peer)
|
|
|
|
, author((item->hasFromName() && !item->isPost()) ? item->author() : nullptr)
|
|
|
|
, item((forwardedCount > 1) ? nullptr : item)
|
|
|
|
, forwardedCount(forwardedCount) {
|
|
|
|
}
|
|
|
|
|
|
|
|
History *history;
|
|
|
|
PeerData *peer;
|
|
|
|
PeerData *author;
|
|
|
|
HistoryItem *item;
|
|
|
|
int forwardedCount;
|
|
|
|
};
|
2017-03-04 19:36:59 +00:00
|
|
|
std::deque<QueuedNotification> _queuedNotifications;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _demoMasterOpacity;
|
2016-10-06 16:41:09 +00:00
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
mutable QPixmap _hiddenUserpicPlaceholder;
|
|
|
|
|
2016-10-02 09:30:28 +00:00
|
|
|
};
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
namespace internal {
|
|
|
|
|
2016-12-31 13:34:41 +00:00
|
|
|
class Widget : public TWidget, protected base::Subscriber {
|
2016-10-05 16:56:27 +00:00
|
|
|
public:
|
2016-10-06 16:41:09 +00:00
|
|
|
enum class Direction {
|
|
|
|
Up,
|
|
|
|
Down,
|
|
|
|
};
|
2017-03-04 19:36:59 +00:00
|
|
|
Widget(Manager *manager, QPoint startPosition, int shift, Direction shiftDirection);
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
bool isShowing() const {
|
2016-10-06 16:41:09 +00:00
|
|
|
return _a_opacity.animating() && !_hiding;
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
void updateOpacity();
|
|
|
|
void changeShift(int top);
|
|
|
|
int currentShift() const {
|
|
|
|
return a_shift.current();
|
|
|
|
}
|
|
|
|
void updatePosition(QPoint startPosition, Direction shiftDirection);
|
|
|
|
void addToHeight(int add);
|
|
|
|
void addToShift(int add);
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void hideSlow();
|
|
|
|
void hideFast();
|
|
|
|
void hideStop();
|
2016-10-06 16:41:09 +00:00
|
|
|
QPoint computePosition(int height) const;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
virtual void updateGeometry(int x, int y, int width, int height);
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
protected:
|
|
|
|
Manager *manager() const {
|
|
|
|
return _manager;
|
|
|
|
}
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
private:
|
2016-12-07 13:32:25 +00:00
|
|
|
void opacityAnimationCallback();
|
2016-10-07 13:24:19 +00:00
|
|
|
void destroyDelayed();
|
2016-10-06 16:41:09 +00:00
|
|
|
void moveByShift();
|
2016-11-20 12:54:07 +00:00
|
|
|
void hideAnimated(float64 duration, const anim::transition &func);
|
2016-10-06 16:41:09 +00:00
|
|
|
void step_shift(float64 ms, bool timer);
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
Manager *_manager = nullptr;
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
bool _hiding = false;
|
2016-10-07 13:24:19 +00:00
|
|
|
bool _deleted = false;
|
2016-10-06 16:41:09 +00:00
|
|
|
Animation _a_opacity;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
QPoint _startPosition;
|
|
|
|
Direction _direction;
|
2016-12-05 11:01:08 +00:00
|
|
|
anim::value a_shift;
|
2016-12-07 13:32:25 +00:00
|
|
|
BasicAnimation _a_shift;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Background : public TWidget {
|
|
|
|
public:
|
|
|
|
Background(QWidget *parent);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Notification : public Widget {
|
2016-10-02 09:30:28 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-03-04 19:36:59 +00:00
|
|
|
Notification(Manager *manager, History *history, PeerData *peer, PeerData *author, HistoryItem *item, int forwardedCount, QPoint startPosition, int shift, Direction shiftDirection);
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
void startHiding();
|
|
|
|
void stopHiding();
|
|
|
|
|
|
|
|
void updateNotifyDisplay();
|
|
|
|
void updatePeerPhoto();
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
bool isUnlinked() const {
|
2016-10-04 18:18:08 +00:00
|
|
|
return !_history;
|
2016-10-02 09:30:28 +00:00
|
|
|
}
|
2016-10-05 16:56:27 +00:00
|
|
|
bool isReplying() const {
|
2016-12-13 17:07:56 +00:00
|
|
|
return _replyArea && !isUnlinked();
|
2016-10-05 16:56:27 +00:00
|
|
|
}
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
// Called only by Manager.
|
2017-03-08 20:51:40 +00:00
|
|
|
bool unlinkItem(HistoryItem *del);
|
2016-10-05 16:56:27 +00:00
|
|
|
bool unlinkHistory(History *history = nullptr);
|
2016-10-06 16:41:09 +00:00
|
|
|
bool checkLastInput(bool hasReplyingNotifications);
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
protected:
|
2017-02-11 11:24:37 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-10-02 09:30:28 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2016-10-05 16:56:27 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
2016-10-19 13:31:18 +00:00
|
|
|
bool eventFilter(QObject *o, QEvent *e) override;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
private slots:
|
2016-10-05 16:56:27 +00:00
|
|
|
void onHideByTimer();
|
2016-10-04 18:18:08 +00:00
|
|
|
void onReplyResize();
|
|
|
|
void onReplySubmit(bool ctrlShiftEnter);
|
|
|
|
void onReplyCancel();
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-30 15:21:05 +00:00
|
|
|
void refreshLang();
|
|
|
|
void updateReplyGeometry();
|
2016-10-07 17:02:13 +00:00
|
|
|
bool canReply() const;
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
void unlinkHistoryInManager();
|
2016-10-04 18:18:08 +00:00
|
|
|
void toggleActionButtons(bool visible);
|
|
|
|
void prepareActionsCache();
|
|
|
|
void showReplyField();
|
|
|
|
void sendReply();
|
2016-10-05 16:56:27 +00:00
|
|
|
void changeHeight(int newHeight);
|
|
|
|
void updateGeometry(int x, int y, int width, int height) override;
|
|
|
|
void actionsOpacityCallback();
|
|
|
|
|
|
|
|
QPixmap _cache;
|
|
|
|
|
2016-10-08 08:38:53 +00:00
|
|
|
bool _hideReplyButton = false;
|
2016-10-05 16:56:27 +00:00
|
|
|
bool _actionsVisible = false;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation a_actionsOpacity;
|
2016-10-05 16:56:27 +00:00
|
|
|
QPixmap _buttonsCache;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2017-02-28 10:51:00 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2016-12-01 19:20:33 +00:00
|
|
|
TimeMs _started;
|
2017-02-28 10:51:00 +00:00
|
|
|
#endif // Q_OS_WIN
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-02 13:54:27 +00:00
|
|
|
History *_history;
|
|
|
|
PeerData *_peer;
|
|
|
|
PeerData *_author;
|
|
|
|
HistoryItem *_item;
|
|
|
|
int _forwardedCount;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::IconButton> _close;
|
|
|
|
object_ptr<Ui::RoundButton> _reply;
|
|
|
|
object_ptr<Background> _background = { nullptr };
|
|
|
|
object_ptr<Ui::InputArea> _replyArea = { nullptr };
|
|
|
|
object_ptr<Ui::IconButton> _replySend = { nullptr };
|
2016-10-05 16:56:27 +00:00
|
|
|
bool _waitingForInput = true;
|
2016-10-04 18:18:08 +00:00
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
QTimer _hideTimer;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
2016-10-04 18:18:08 +00:00
|
|
|
int _replyPadding = 0;
|
|
|
|
|
2016-10-05 16:56:27 +00:00
|
|
|
bool _userpicLoaded = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class HideAllButton : public Widget {
|
|
|
|
public:
|
2017-03-04 19:36:59 +00:00
|
|
|
HideAllButton(Manager *manager, QPoint startPosition, int shift, Direction shiftDirection);
|
2016-10-05 16:56:27 +00:00
|
|
|
|
|
|
|
void startHiding();
|
|
|
|
void startHidingFast();
|
|
|
|
void stopHiding();
|
|
|
|
|
|
|
|
protected:
|
2017-02-11 11:24:37 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-10-05 16:56:27 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool _mouseOver = false;
|
|
|
|
bool _mouseDown = false;
|
2016-10-02 09:30:28 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
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
|