2014-05-30 08:53: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-05-30 08:53: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
|
2014-12-01 10:47:38 +00:00
|
|
|
Copyright (c) 2014 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QtWidgets/QTextEdit>
|
|
|
|
#include "style.h"
|
|
|
|
#include "animation.h"
|
|
|
|
|
|
|
|
class FlatTextarea : public QTextEdit, public Animated {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
FlatTextarea(QWidget *parent, const style::flatTextarea &st, const QString &ph = QString(), const QString &val = QString());
|
2015-04-04 20:01:34 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
bool viewportEvent(QEvent *e);
|
|
|
|
void touchEvent(QTouchEvent *e);
|
|
|
|
void paintEvent(QPaintEvent *e);
|
|
|
|
void focusInEvent(QFocusEvent *e);
|
|
|
|
void focusOutEvent(QFocusEvent *e);
|
|
|
|
void keyPressEvent(QKeyEvent *e);
|
|
|
|
void resizeEvent(QResizeEvent *e);
|
|
|
|
void mousePressEvent(QMouseEvent *e);
|
|
|
|
|
2015-05-29 18:52:43 +00:00
|
|
|
const QString &getLastText() const;
|
2014-05-30 08:53:19 +00:00
|
|
|
void updatePlaceholder();
|
|
|
|
|
|
|
|
QRect getTextRect() const;
|
2014-10-25 15:40:20 +00:00
|
|
|
int32 fakeMargin() const;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
bool animStep(float64 ms);
|
|
|
|
|
|
|
|
QSize sizeHint() const;
|
|
|
|
QSize minimumSizeHint() const;
|
|
|
|
|
2015-01-02 14:55:24 +00:00
|
|
|
EmojiPtr getSingleEmoji() const;
|
2015-03-24 10:00:27 +00:00
|
|
|
void getMentionHashtagStart(QString &start) const;
|
2015-01-02 14:55:24 +00:00
|
|
|
void removeSingleEmoji();
|
2014-05-30 08:53:19 +00:00
|
|
|
QString getText(int32 start = 0, int32 end = -1) const;
|
|
|
|
bool hasText() const;
|
|
|
|
|
2014-11-18 12:40:43 +00:00
|
|
|
bool isUndoAvailable() const;
|
|
|
|
bool isRedoAvailable() const;
|
|
|
|
|
2015-04-06 22:15:29 +00:00
|
|
|
void parseLinks();
|
|
|
|
QStringList linksList() const;
|
|
|
|
|
|
|
|
void insertFromMimeData(const QMimeData *source);
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
public slots:
|
|
|
|
|
|
|
|
void onTouchTimer();
|
|
|
|
|
|
|
|
void onDocumentContentsChange(int position, int charsRemoved, int charsAdded);
|
|
|
|
void onDocumentContentsChanged();
|
|
|
|
|
2014-11-18 12:40:43 +00:00
|
|
|
void onUndoAvailable(bool avail);
|
|
|
|
void onRedoAvailable(bool avail);
|
|
|
|
|
2015-03-24 10:00:27 +00:00
|
|
|
void onMentionOrHashtagInsert(QString mentionOrHashtag);
|
2015-03-19 09:18:19 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
void changed();
|
2014-10-17 12:57:14 +00:00
|
|
|
void submitted(bool ctrlShiftEnter);
|
2014-05-30 08:53:19 +00:00
|
|
|
void cancelled();
|
|
|
|
void tabbed();
|
2015-04-06 22:15:29 +00:00
|
|
|
void spacedReturnedPasted();
|
|
|
|
void linksChanged();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void insertEmoji(EmojiPtr emoji, QTextCursor c);
|
2015-05-29 18:52:43 +00:00
|
|
|
TWidget *tparent() {
|
|
|
|
return qobject_cast<TWidget*>(parentWidget());
|
|
|
|
}
|
|
|
|
const TWidget *tparent() const {
|
|
|
|
return qobject_cast<const TWidget*>(parentWidget());
|
|
|
|
}
|
|
|
|
void enterEvent(QEvent *e) {
|
|
|
|
TWidget *p(tparent());
|
|
|
|
if (p) p->leaveToChildEvent(e);
|
|
|
|
return QTextEdit::enterEvent(e);
|
|
|
|
}
|
|
|
|
void leaveEvent(QEvent *e) {
|
|
|
|
TWidget *p(tparent());
|
|
|
|
if (p) p->enterFromChildEvent(e);
|
|
|
|
return QTextEdit::leaveEvent(e);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2015-01-02 14:55:24 +00:00
|
|
|
void getSingleEmojiFragment(QString &text, QTextFragment &fragment) const;
|
2014-05-30 08:53:19 +00:00
|
|
|
void processDocumentContentsChange(int position, int charsAdded);
|
|
|
|
|
|
|
|
QMimeData *createMimeDataFromSelection() const;
|
|
|
|
|
|
|
|
QString _ph, _phelided, _oldtext;
|
|
|
|
bool _phVisible;
|
|
|
|
anim::ivalue a_phLeft;
|
|
|
|
anim::fvalue a_phAlpha;
|
|
|
|
anim::cvalue a_phColor;
|
|
|
|
style::flatTextarea _st;
|
|
|
|
|
2014-11-18 12:40:43 +00:00
|
|
|
bool _undoAvailable, _redoAvailable;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 _fakeMargin;
|
|
|
|
|
|
|
|
QTimer _touchTimer;
|
|
|
|
bool _touchPress, _touchRightButton, _touchMove;
|
|
|
|
QPoint _touchStart;
|
|
|
|
|
|
|
|
bool _replacingEmojis;
|
|
|
|
typedef QPair<int, int> Insertion;
|
|
|
|
typedef QList<Insertion> Insertions;
|
|
|
|
Insertions _insertions;
|
2015-04-06 22:15:29 +00:00
|
|
|
|
|
|
|
typedef QPair<int, int> LinkRange;
|
|
|
|
typedef QList<LinkRange> LinkRanges;
|
|
|
|
LinkRanges _links;
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|