2014-09-26 23:48:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-09-26 23:48:19 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2014-09-26 23:48:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-04-14 11:00:23 +00:00
|
|
|
#include "ui/text/text.h"
|
2016-02-07 15:38:49 +00:00
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
class PopupMenu : public TWidget {
|
2014-09-26 23:48:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
PopupMenu(const style::PopupMenu &st = st::defaultPopupMenu);
|
|
|
|
PopupMenu(QMenu *menu, const style::PopupMenu &st = st::defaultPopupMenu);
|
2014-09-29 02:47:30 +00:00
|
|
|
QAction *addAction(const QString &text, const QObject *receiver, const char* member);
|
2015-11-01 18:14:30 +00:00
|
|
|
QAction *addAction(QAction *a);
|
2016-02-26 16:49:31 +00:00
|
|
|
QAction *addSeparator();
|
2014-09-29 02:47:30 +00:00
|
|
|
void resetActions();
|
|
|
|
|
|
|
|
typedef QVector<QAction*> Actions;
|
|
|
|
Actions &actions();
|
2014-09-26 23:48:19 +00:00
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
void deleteOnHide(bool del);
|
2014-09-29 02:47:30 +00:00
|
|
|
void popup(const QPoint &p);
|
2015-11-01 18:14:30 +00:00
|
|
|
void hideMenu(bool fast = false);
|
2014-09-29 02:47:30 +00:00
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
~PopupMenu();
|
2015-10-23 16:15:24 +00:00
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
protected:
|
2015-10-23 16:15:24 +00:00
|
|
|
|
|
|
|
void resizeEvent(QResizeEvent *e);
|
|
|
|
void paintEvent(QPaintEvent *e);
|
|
|
|
void keyPressEvent(QKeyEvent *e);
|
|
|
|
void mouseMoveEvent(QMouseEvent *e);
|
|
|
|
void mousePressEvent(QMouseEvent *e);
|
|
|
|
void leaveEvent(QEvent *e);
|
|
|
|
void enterEvent(QEvent *e);
|
|
|
|
void focusOutEvent(QFocusEvent *e);
|
2015-11-02 23:30:28 +00:00
|
|
|
void hideEvent(QHideEvent *e);
|
2015-10-23 16:15:24 +00:00
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
public slots:
|
2015-10-23 16:15:24 +00:00
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
void actionChanged();
|
|
|
|
|
|
|
|
private:
|
2015-10-23 16:15:24 +00:00
|
|
|
|
|
|
|
void updateSelected();
|
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
void childHiding(PopupMenu *child);
|
2015-10-23 16:15:24 +00:00
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
void step_hide(float64 ms, bool timer);
|
2015-10-23 16:15:24 +00:00
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
void init();
|
2015-10-23 16:15:24 +00:00
|
|
|
void hideFinish();
|
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
enum PressSource {
|
|
|
|
PressSourceMouse,
|
|
|
|
PressSourceKeyboard,
|
|
|
|
};
|
2015-10-23 16:15:24 +00:00
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
void clearActions(bool force = false);
|
|
|
|
int32 processAction(QAction *a, int32 index, int32 w);
|
2015-10-23 16:15:24 +00:00
|
|
|
void setSelected(int32 selected);
|
2015-11-01 18:14:30 +00:00
|
|
|
int32 itemY(int32 index);
|
2015-10-23 16:15:24 +00:00
|
|
|
void updateSelectedItem();
|
2015-11-01 18:14:30 +00:00
|
|
|
void itemPressed(PressSource source);
|
|
|
|
void popupChildMenu(PressSource source);
|
|
|
|
void showMenu(const QPoint &p, PopupMenu *parent, PressSource source);;
|
2015-10-23 16:15:24 +00:00
|
|
|
|
|
|
|
const style::PopupMenu &_st;
|
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
typedef QVector<PopupMenu*> PopupMenus;
|
|
|
|
|
|
|
|
QMenu *_menu;
|
2015-10-23 16:15:24 +00:00
|
|
|
Actions _actions;
|
2015-11-01 18:14:30 +00:00
|
|
|
PopupMenus _menus;
|
|
|
|
PopupMenu *_parent;
|
|
|
|
QStringList _texts, _shortcutTexts;
|
2015-10-23 16:15:24 +00:00
|
|
|
|
2015-11-01 18:14:30 +00:00
|
|
|
int32 _itemHeight, _separatorHeight;
|
2015-10-23 16:15:24 +00:00
|
|
|
QRect _inner;
|
|
|
|
style::margins _padding;
|
|
|
|
|
|
|
|
QPoint _mouse;
|
|
|
|
bool _mouseSelection;
|
|
|
|
|
|
|
|
BoxShadow _shadow;
|
2015-11-01 18:14:30 +00:00
|
|
|
int32 _selected, _childMenuIndex;
|
2015-10-23 16:15:24 +00:00
|
|
|
|
|
|
|
QPixmap _cache;
|
|
|
|
anim::fvalue a_opacity;
|
|
|
|
Animation _a_hide;
|
|
|
|
|
2015-11-03 16:49:14 +00:00
|
|
|
bool _deleteOnHide, _triggering, _deleteLater;
|
2015-10-23 16:15:24 +00:00
|
|
|
|
|
|
|
};
|
2016-02-07 15:38:49 +00:00
|
|
|
|
2016-02-07 18:58:42 +00:00
|
|
|
class AbstractTooltipShower {
|
|
|
|
public:
|
|
|
|
virtual QString tooltipText() const = 0;
|
|
|
|
virtual QPoint tooltipPos() const = 0;
|
|
|
|
virtual const style::Tooltip *tooltipSt() const {
|
|
|
|
return &st::defaultTooltip;
|
|
|
|
}
|
|
|
|
virtual ~AbstractTooltipShower();
|
|
|
|
};
|
|
|
|
|
2016-02-07 15:38:49 +00:00
|
|
|
class PopupTooltip : public TWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool eventFilter(QObject *o, QEvent *e);
|
|
|
|
|
2016-02-07 18:58:42 +00:00
|
|
|
static void Show(int32 delay, const AbstractTooltipShower *shower);
|
2016-02-07 15:38:49 +00:00
|
|
|
static void Hide();
|
|
|
|
|
|
|
|
~PopupTooltip();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
2016-02-07 18:58:42 +00:00
|
|
|
void onShow();
|
2016-02-22 07:01:10 +00:00
|
|
|
void onWndActiveChanged();
|
2016-02-07 15:38:49 +00:00
|
|
|
void onHideByLeave();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent *e);
|
|
|
|
void hideEvent(QHideEvent *e);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2016-02-07 18:58:42 +00:00
|
|
|
PopupTooltip();
|
|
|
|
|
2016-02-07 15:38:49 +00:00
|
|
|
void popup(const QPoint &p, const QString &text, const style::Tooltip *st);
|
|
|
|
|
2016-02-07 18:58:42 +00:00
|
|
|
friend class AbstractTooltipShower;
|
|
|
|
const AbstractTooltipShower *_shower;
|
|
|
|
QTimer _showTimer;
|
|
|
|
|
2016-02-07 15:38:49 +00:00
|
|
|
Text _text;
|
|
|
|
QPoint _point;
|
|
|
|
|
|
|
|
const style::Tooltip *_st;
|
|
|
|
|
|
|
|
QTimer _hideByLeaveTimer;
|
|
|
|
|
|
|
|
};
|