Handle mouse clicks in floating player widget.

This commit is contained in:
John Preston 2017-05-23 17:40:25 +03:00
parent c58a48276f
commit 8f290451b6
2 changed files with 32 additions and 1 deletions

View File

@ -50,6 +50,30 @@ Float::Float(QWidget *parent, HistoryItem *item, base::lambda<void(bool visible)
detach(); detach();
} }
}); });
setCursor(style::cur_pointer);
}
void Float::mousePressEvent(QMouseEvent *e) {
_down = true;
}
void Float::mouseReleaseEvent(QMouseEvent *e) {
if (_down && _item) {
if (auto media = _item->getMedia()) {
media->playInline();
}
}
}
void Float::mouseDoubleClickEvent(QMouseEvent *e) {
if (_item) {
// Handle second click.
if (auto media = _item->getMedia()) {
media->playInline();
}
Ui::showPeerHistoryAtItem(_item);
}
} }
void Float::detach() { void Float::detach() {

View File

@ -42,6 +42,9 @@ public:
bool detached() const { bool detached() const {
return !_item; return !_item;
} }
void resetMouseState() {
_down = false;
}
void ui_repaintHistoryItem(const HistoryItem *item) { void ui_repaintHistoryItem(const HistoryItem *item) {
if (item == _item) { if (item == _item) {
repaintItem(); repaintItem();
@ -49,7 +52,10 @@ public:
} }
protected: protected:
void paintEvent(QPaintEvent *e); void paintEvent(QPaintEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void mouseDoubleClickEvent(QMouseEvent *e) override;
private: private:
Clip::Reader *getReader() const; Clip::Reader *getReader() const;
@ -67,6 +73,7 @@ private:
QPixmap _shadow; QPixmap _shadow;
QImage _frame; QImage _frame;
bool _down = false;
std::unique_ptr<Clip::Playback> _roundPlayback; std::unique_ptr<Clip::Playback> _roundPlayback;