| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | /*
 | 
					
						
							|  |  |  | This file is part of Telegram Desktop, | 
					
						
							| 
									
										
										
										
											2014-12-01 13:47:38 +03:00
										 |  |  | the official desktop version of Telegram messaging app, see https://telegram.org
 | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04: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. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-03 16:16:42 +03:00
										 |  |  | In addition, as a special exception, the copyright holders give permission | 
					
						
							|  |  |  | to link the code of portions of this program with the OpenSSL library. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
 | 
					
						
							| 
									
										
										
										
											2016-02-08 13:56:18 +03:00
										 |  |  | Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
 | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | */ | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QtWidgets/QTextEdit>
 | 
					
						
							| 
									
										
										
										
											2016-04-07 22:05:28 +04:00
										 |  |  | #include "ui/style.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | #include "animation.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-29 00:20:04 +03:00
										 |  |  | class UserData; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | static UserData * const LookingUpInlineBot = SharedMemoryLocation<UserData, 0>(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-08 15:33:37 +03:00
										 |  |  | class FlatTextarea : public QTextEdit { | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 	Q_OBJECT | 
					
						
							| 
									
										
										
										
											2015-09-16 16:04:08 +03:00
										 |  |  | 	T_WIDGET | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	FlatTextarea(QWidget *parent, const style::flatTextarea &st, const QString &ph = QString(), const QString &val = QString()); | 
					
						
							| 
									
										
										
										
											2015-04-04 23:01:34 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 16:03:03 +03:00
										 |  |  | 	bool viewportEvent(QEvent *e) override; | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 	void touchEvent(QTouchEvent *e); | 
					
						
							| 
									
										
										
										
											2016-04-14 16:03:03 +03:00
										 |  |  | 	void paintEvent(QPaintEvent *e) override; | 
					
						
							|  |  |  | 	void focusInEvent(QFocusEvent *e) override; | 
					
						
							|  |  |  | 	void focusOutEvent(QFocusEvent *e) override; | 
					
						
							|  |  |  | 	void keyPressEvent(QKeyEvent *e) override; | 
					
						
							|  |  |  | 	void resizeEvent(QResizeEvent *e) override; | 
					
						
							|  |  |  | 	void mousePressEvent(QMouseEvent *e) override; | 
					
						
							|  |  |  | 	void dropEvent(QDropEvent *e) override; | 
					
						
							|  |  |  | 	void contextMenuEvent(QContextMenuEvent *e) override; | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-17 00:15:13 +03:00
										 |  |  | 	void setMaxLength(int32 maxLength); | 
					
						
							| 
									
										
										
										
											2015-09-16 16:04:08 +03:00
										 |  |  | 	void setMinHeight(int32 minHeight); | 
					
						
							|  |  |  | 	void setMaxHeight(int32 maxHeight); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-06 22:49:23 +03:00
										 |  |  | 	const QString &getLastText() const { | 
					
						
							|  |  |  | 		return _oldtext; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-12-31 23:27:21 +08:00
										 |  |  | 	void setPlaceholder(const QString &ph, int32 afterSymbols = 0); | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 	void updatePlaceholder(); | 
					
						
							| 
									
										
										
										
											2015-12-31 23:27:21 +08:00
										 |  |  | 	void finishPlaceholder(); | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QRect getTextRect() const; | 
					
						
							| 
									
										
										
										
											2014-10-25 19:40:20 +04:00
										 |  |  | 	int32 fakeMargin() const; | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-08 15:33:37 +03:00
										 |  |  | 	void step_appearance(float64 ms, bool timer); | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 16:03:03 +03:00
										 |  |  | 	QSize sizeHint() const override; | 
					
						
							|  |  |  | 	QSize minimumSizeHint() const override; | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 17:55:24 +03:00
										 |  |  | 	EmojiPtr getSingleEmoji() const; | 
					
						
							| 
									
										
										
										
											2016-01-02 09:28:11 +08:00
										 |  |  | 	QString getMentionHashtagBotCommandPart(bool &start) const; | 
					
						
							| 
									
										
										
										
											2016-04-09 15:02:50 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Get the current inline bot and request string for it.
 | 
					
						
							|  |  |  | 	// The *outInlineBot can be filled by LookingUpInlineBot shared ptr.
 | 
					
						
							|  |  |  | 	// In that case the caller should lookup the bot by *outInlineBotUsername.
 | 
					
						
							|  |  |  | 	QString getInlineBotQuery(UserData **outInlineBot, QString *outInlineBotUsername) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 17:55:24 +03:00
										 |  |  | 	void removeSingleEmoji(); | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 	bool hasText() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-18 15:40:43 +03:00
										 |  |  | 	bool isUndoAvailable() const; | 
					
						
							|  |  |  | 	bool isRedoAvailable() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-07 01:15:29 +03:00
										 |  |  | 	void parseLinks(); | 
					
						
							|  |  |  | 	QStringList linksList() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 16:03:03 +03:00
										 |  |  | 	void insertFromMimeData(const QMimeData *source) override; | 
					
						
							| 
									
										
										
										
											2015-04-07 01:15:29 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 16:03:03 +03:00
										 |  |  | 	QMimeData *createMimeDataFromSelection() const override; | 
					
						
							| 
									
										
										
										
											2016-04-09 15:02:50 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	enum class SubmitSettings { | 
					
						
							|  |  |  | 		None, | 
					
						
							|  |  |  | 		Enter, | 
					
						
							|  |  |  | 		CtrlEnter, | 
					
						
							|  |  |  | 		Both, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	void setSubmitSettings(SubmitSettings settings); | 
					
						
							| 
									
										
										
										
											2015-08-18 19:10:01 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 08:58:43 +08:00
										 |  |  | 	void setTextFast(const QString &text, bool clearUndoHistory = true); | 
					
						
							| 
									
										
										
										
											2015-10-17 16:52:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | public slots: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void onTouchTimer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void onDocumentContentsChange(int position, int charsRemoved, int charsAdded); | 
					
						
							|  |  |  | 	void onDocumentContentsChanged(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-18 15:40:43 +03:00
										 |  |  | 	void onUndoAvailable(bool avail); | 
					
						
							|  |  |  | 	void onRedoAvailable(bool avail); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-15 20:19:24 +03:00
										 |  |  | 	void onMentionHashtagOrBotCommandInsert(QString str); | 
					
						
							| 
									
										
										
										
											2015-03-19 12:18:19 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | signals: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-16 16:04:08 +03:00
										 |  |  | 	void resized(); | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 	void changed(); | 
					
						
							| 
									
										
										
										
											2014-10-17 16:57:14 +04:00
										 |  |  | 	void submitted(bool ctrlShiftEnter); | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 	void cancelled(); | 
					
						
							|  |  |  | 	void tabbed(); | 
					
						
							| 
									
										
										
										
											2015-04-07 01:15:29 +03:00
										 |  |  | 	void spacedReturnedPasted(); | 
					
						
							|  |  |  | 	void linksChanged(); | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-06 22:49:23 +03:00
										 |  |  | 	QString getText(int32 start = 0, int32 end = -1) const; | 
					
						
							|  |  |  | 	virtual void correctValue(const QString &was, QString &now); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 	void insertEmoji(EmojiPtr emoji, QTextCursor c); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-14 16:03:03 +03:00
										 |  |  | 	QVariant loadResource(int type, const QUrl &name) override; | 
					
						
							| 
									
										
										
										
											2015-08-18 19:10:01 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-16 16:04:08 +03:00
										 |  |  | 	void checkContentHeight(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 17:55:24 +03:00
										 |  |  | 	void getSingleEmojiFragment(QString &text, QTextFragment &fragment) const; | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 	void processDocumentContentsChange(int position, int charsAdded); | 
					
						
							| 
									
										
										
										
											2015-09-16 16:04:08 +03:00
										 |  |  | 	bool heightAutoupdated(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-09 15:02:50 +04:00
										 |  |  | 	int _minHeight = -1; // < 0 - no autosize
 | 
					
						
							|  |  |  | 	int _maxHeight = -1; | 
					
						
							|  |  |  | 	int _maxLength = -1; | 
					
						
							|  |  |  | 	SubmitSettings _submitSettings = SubmitSettings::Enter; | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QString _ph, _phelided, _oldtext; | 
					
						
							| 
									
										
										
										
											2016-04-09 15:02:50 +04:00
										 |  |  | 	int _phAfter = 0; | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 	bool _phVisible; | 
					
						
							|  |  |  | 	anim::ivalue a_phLeft; | 
					
						
							|  |  |  | 	anim::fvalue a_phAlpha; | 
					
						
							|  |  |  | 	anim::cvalue a_phColor; | 
					
						
							| 
									
										
										
										
											2015-12-08 15:33:37 +03:00
										 |  |  | 	Animation _a_appearance; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 	style::flatTextarea _st; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-09 15:02:50 +04:00
										 |  |  | 	bool _undoAvailable = false; | 
					
						
							|  |  |  | 	bool _redoAvailable = false; | 
					
						
							|  |  |  | 	bool _inDrop = false; | 
					
						
							|  |  |  | 	bool _inHeightCheck = false; | 
					
						
							| 
									
										
										
										
											2014-11-18 15:40:43 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-09 15:02:50 +04:00
										 |  |  | 	int _fakeMargin = 0; | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QTimer _touchTimer; | 
					
						
							| 
									
										
										
										
											2016-04-09 15:02:50 +04:00
										 |  |  | 	bool _touchPress = false; | 
					
						
							|  |  |  | 	bool _touchRightButton = false; | 
					
						
							|  |  |  | 	bool _touchMove = false; | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | 	QPoint _touchStart; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-09 15:02:50 +04:00
										 |  |  | 	bool _correcting = false; | 
					
						
							| 
									
										
										
										
											2015-04-07 01:15:29 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	typedef QPair<int, int> LinkRange; | 
					
						
							|  |  |  | 	typedef QList<LinkRange> LinkRanges; | 
					
						
							|  |  |  | 	LinkRanges _links; | 
					
						
							| 
									
										
										
										
											2014-05-30 12:53:19 +04:00
										 |  |  | }; |