2017-03-29 17:04:00 +03: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
|
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-08 18:20:12 +03:00
|
|
|
#include "chat_helpers/tabbed_selector.h"
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-04-07 21:10:49 +03:00
|
|
|
namespace Window {
|
|
|
|
class Controller;
|
|
|
|
} // namespace Window
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
namespace ChatHelpers {
|
|
|
|
|
|
|
|
constexpr auto kEmojiSectionCount = 8;
|
|
|
|
|
|
|
|
class EmojiColorPicker : public TWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
EmojiColorPicker(QWidget *parent);
|
|
|
|
|
|
|
|
void showEmoji(EmojiPtr emoji);
|
|
|
|
|
|
|
|
void clearSelection();
|
|
|
|
void handleMouseMove(QPoint globalPos);
|
|
|
|
void handleMouseRelease(QPoint globalPos);
|
2017-11-12 13:54:18 +04:00
|
|
|
void setSingleSize(QSize size);
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
void hideFast();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void showAnimated();
|
|
|
|
void hideAnimated();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void emojiSelected(EmojiPtr emoji);
|
|
|
|
void hidden();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void animationCallback();
|
2017-11-12 13:54:18 +04:00
|
|
|
void updateSize();
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
void drawVariant(Painter &p, int variant);
|
|
|
|
|
|
|
|
void updateSelected();
|
|
|
|
void setSelected(int newSelected);
|
|
|
|
|
|
|
|
bool _ignoreShow = false;
|
|
|
|
|
|
|
|
QVector<EmojiPtr> _variants;
|
|
|
|
|
|
|
|
int _selected = -1;
|
|
|
|
int _pressedSel = -1;
|
|
|
|
QPoint _lastMousePos;
|
2017-11-12 13:54:18 +04:00
|
|
|
QSize _singleSize;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
bool _hiding = false;
|
|
|
|
QPixmap _cache;
|
|
|
|
Animation _a_opacity;
|
|
|
|
|
|
|
|
QTimer _hideTimer;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-04-08 18:20:12 +03:00
|
|
|
class EmojiListWidget : public TabbedSelector::Inner {
|
2017-03-29 17:04:00 +03:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-08-17 11:31:24 +03:00
|
|
|
EmojiListWidget(QWidget *parent, not_null<Window::Controller*> controller);
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
using Section = Ui::Emoji::Section;
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void refreshRecent() override;
|
|
|
|
void clearSelection() override;
|
2017-04-08 18:20:12 +03:00
|
|
|
object_ptr<TabbedSelector::InnerFooter> createFooter() override;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
void showEmojiSection(Section section);
|
|
|
|
Section currentSection(int yOffset) const;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onShowPicker();
|
|
|
|
void onPickerHidden();
|
|
|
|
void onColorSelected(EmojiPtr emoji);
|
|
|
|
|
|
|
|
bool checkPickerHide();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void selected(EmojiPtr emoji);
|
|
|
|
void switchToStickers();
|
|
|
|
|
|
|
|
protected:
|
2017-09-13 19:57:44 +03:00
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
|
|
|
void leaveToChildEvent(QEvent *e, QWidget *child) override;
|
|
|
|
void enterFromChildEvent(QEvent *e, QWidget *child) override;
|
2017-11-05 21:07:27 +04:00
|
|
|
bool eventHook(QEvent *e) override;
|
2017-03-29 18:09:16 +03:00
|
|
|
|
2017-04-08 18:20:12 +03:00
|
|
|
TabbedSelector::InnerFooter *getFooter() const override;
|
2017-03-29 18:09:16 +03:00
|
|
|
void processHideFinished() override;
|
2017-11-12 13:54:18 +04:00
|
|
|
int countDesiredHeight(int newWidth) override;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
private:
|
2017-03-29 18:09:16 +03:00
|
|
|
class Footer;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
struct SectionInfo {
|
|
|
|
int section = 0;
|
|
|
|
int count = 0;
|
|
|
|
int top = 0;
|
|
|
|
int rowsCount = 0;
|
|
|
|
int rowsTop = 0;
|
|
|
|
int rowsBottom = 0;
|
|
|
|
};
|
2017-09-13 19:57:44 +03:00
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
template <typename Callback>
|
|
|
|
bool enumerateSections(Callback callback) const;
|
|
|
|
SectionInfo sectionInfo(int section) const;
|
|
|
|
SectionInfo sectionInfoByOffset(int yOffset) const;
|
|
|
|
|
|
|
|
void ensureLoaded(int section);
|
|
|
|
int countSectionTop(int section) const;
|
|
|
|
void updateSelected();
|
|
|
|
void setSelected(int newSelected);
|
|
|
|
|
|
|
|
void selectEmoji(EmojiPtr emoji);
|
|
|
|
|
|
|
|
QRect emojiRect(int section, int sel);
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
Footer *_footer = nullptr;
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
int _counts[kEmojiSectionCount];
|
|
|
|
QVector<EmojiPtr> _emoji[kEmojiSectionCount];
|
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
int _rowsLeft = 0;
|
2017-11-14 14:26:12 +04:00
|
|
|
int _columnCount = 1;
|
2017-11-12 13:54:18 +04:00
|
|
|
QSize _singleSize;
|
|
|
|
int _esize = 0;
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
int _selected = -1;
|
|
|
|
int _pressedSel = -1;
|
|
|
|
int _pickerSel = -1;
|
|
|
|
QPoint _lastMousePos;
|
|
|
|
|
|
|
|
object_ptr<EmojiColorPicker> _picker;
|
|
|
|
QTimer _showPickerTimer;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ChatHelpers
|