2016-10-26 16:43:13 +00:00
|
|
|
/*
|
2018-01-03 10:23:14 +00:00
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-10-26 16:43:13 +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-26 16:43:13 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-05-02 09:08:08 +00:00
|
|
|
#include "base/timer.h"
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
namespace style {
|
|
|
|
struct Tooltip;
|
2017-05-17 09:40:03 +00:00
|
|
|
struct ImportantTooltip;
|
2016-12-23 13:21:01 +00:00
|
|
|
} // namespace style
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
|
|
|
class AbstractTooltipShower {
|
|
|
|
public:
|
|
|
|
virtual QString tooltipText() const = 0;
|
|
|
|
virtual QPoint tooltipPos() const = 0;
|
2017-04-29 18:41:41 +00:00
|
|
|
virtual bool tooltipWindowActive() const;
|
2016-12-23 13:21:01 +00:00
|
|
|
virtual const style::Tooltip *tooltipSt() const;
|
2016-10-26 16:43:13 +00:00
|
|
|
virtual ~AbstractTooltipShower();
|
2017-04-29 18:41:41 +00:00
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Tooltip : public TWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void Show(int32 delay, const AbstractTooltipShower *shower);
|
|
|
|
static void Hide();
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
private slots:
|
2016-10-26 16:43:13 +00:00
|
|
|
void onWndActiveChanged();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void hideEvent(QHideEvent *e) override;
|
|
|
|
|
|
|
|
bool eventFilter(QObject *o, QEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2017-05-02 09:08:08 +00:00
|
|
|
void performShow();
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
Tooltip();
|
|
|
|
~Tooltip();
|
|
|
|
|
|
|
|
void popup(const QPoint &p, const QString &text, const style::Tooltip *st);
|
|
|
|
|
|
|
|
friend class AbstractTooltipShower;
|
|
|
|
const AbstractTooltipShower *_shower = nullptr;
|
2017-05-02 09:08:08 +00:00
|
|
|
base::Timer _showTimer;
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
Text _text;
|
|
|
|
QPoint _point;
|
|
|
|
|
|
|
|
const style::Tooltip *_st = nullptr;
|
|
|
|
|
2017-05-02 09:08:08 +00:00
|
|
|
base::Timer _hideByLeaveTimer;
|
|
|
|
bool _isEventFilter = false;
|
2016-12-23 13:21:01 +00:00
|
|
|
bool _useTransparency = true;
|
2016-10-26 16:43:13 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-05-17 09:40:03 +00:00
|
|
|
class ImportantTooltip : public TWidget {
|
|
|
|
public:
|
|
|
|
ImportantTooltip(QWidget *parent, object_ptr<TWidget> content, const style::ImportantTooltip &st);
|
|
|
|
|
2017-05-24 12:20:50 +00:00
|
|
|
void pointAt(QRect area, RectParts preferSide = RectPart::Top | RectPart::Left);
|
2017-05-17 09:40:03 +00:00
|
|
|
|
|
|
|
void toggleAnimated(bool visible);
|
|
|
|
void toggleFast(bool visible);
|
2019-02-19 06:57:53 +00:00
|
|
|
void hideAfter(crl::time timeout);
|
2017-05-17 09:40:03 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setHiddenCallback(Fn<void()> callback) {
|
2017-05-17 09:40:03 +00:00
|
|
|
_hiddenCallback = std::move(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent *e);
|
|
|
|
void paintEvent(QPaintEvent *e);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void animationCallback();
|
|
|
|
QRect countInner() const;
|
|
|
|
void setArea(QRect area);
|
2017-05-24 12:20:50 +00:00
|
|
|
void countApproachSide(RectParts preferSide);
|
2017-05-17 09:40:03 +00:00
|
|
|
void updateGeometry();
|
|
|
|
void checkAnimationFinish();
|
|
|
|
void refreshAnimationCache();
|
|
|
|
|
|
|
|
base::Timer _hideTimer;
|
|
|
|
const style::ImportantTooltip &_st;
|
|
|
|
object_ptr<TWidget> _content;
|
|
|
|
QRect _area;
|
2017-05-24 12:20:50 +00:00
|
|
|
RectParts _side = RectPart::Top | RectPart::Left;
|
2017-05-17 09:40:03 +00:00
|
|
|
QPixmap _arrow;
|
|
|
|
|
|
|
|
Animation _visibleAnimation;
|
|
|
|
bool _visible = false;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _hiddenCallback;
|
2017-05-17 09:40:03 +00:00
|
|
|
bool _useTransparency = true;
|
|
|
|
QPixmap _cache;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
} // namespace Ui
|