tdesktop/Telegram/SourceFiles/ui/popupmenu.h

163 lines
3.5 KiB
C
Raw Normal View History

/*
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.
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
*/
#pragma once
#include "ui/text/text.h"
class PopupMenu : public TWidget {
Q_OBJECT
public:
PopupMenu(const style::PopupMenu &st = st::defaultPopupMenu);
PopupMenu(QMenu *menu, const style::PopupMenu &st = st::defaultPopupMenu);
QAction *addAction(const QString &text, const QObject *receiver, const char* member);
QAction *addAction(QAction *a);
QAction *addSeparator();
void resetActions();
typedef QVector<QAction*> Actions;
Actions &actions();
void deleteOnHide(bool del);
void popup(const QPoint &p);
void hideMenu(bool fast = false);
~PopupMenu();
2015-10-23 16:15:24 +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);
void hideEvent(QHideEvent *e);
2015-10-23 16:15:24 +00:00
public slots:
2015-10-23 16:15:24 +00:00
void actionChanged();
private:
2015-10-23 16:15:24 +00:00
void updateSelected();
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
void init();
2015-10-23 16:15:24 +00:00
void hideFinish();
enum PressSource {
PressSourceMouse,
PressSourceKeyboard,
};
2015-10-23 16:15:24 +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);
int32 itemY(int32 index);
2015-10-23 16:15:24 +00:00
void updateSelectedItem();
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;
typedef QVector<PopupMenu*> PopupMenus;
QMenu *_menu;
2015-10-23 16:15:24 +00:00
Actions _actions;
PopupMenus _menus;
PopupMenu *_parent;
QStringList _texts, _shortcutTexts;
2015-10-23 16:15:24 +00:00
int32 _itemHeight, _separatorHeight;
2015-10-23 16:15:24 +00:00
QRect _inner;
style::margins _padding;
QPoint _mouse;
bool _mouseSelection;
BoxShadow _shadow;
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
};
class AbstractTooltipShower {
public:
virtual QString tooltipText() const = 0;
virtual QPoint tooltipPos() const = 0;
virtual const style::Tooltip *tooltipSt() const {
return &st::defaultTooltip;
}
virtual ~AbstractTooltipShower();
};
class PopupTooltip : public TWidget {
Q_OBJECT
public:
bool eventFilter(QObject *o, QEvent *e);
static void Show(int32 delay, const AbstractTooltipShower *shower);
static void Hide();
~PopupTooltip();
public slots:
void onShow();
void onWndActiveChanged();
void onHideByLeave();
protected:
void paintEvent(QPaintEvent *e);
void hideEvent(QHideEvent *e);
private:
PopupTooltip();
void popup(const QPoint &p, const QString &text, const style::Tooltip *st);
friend class AbstractTooltipShower;
const AbstractTooltipShower *_shower;
QTimer _showTimer;
Text _text;
QPoint _point;
const style::Tooltip *_st;
QTimer _hideByLeaveTimer;
};