FlatTextarea::FlatTextarea(QWidget *parent, const style::flatTextarea &st, const QString &pholder, const QString &v) : QTextEdit(parent), _minHeight(-1), _maxHeight(-1), _maxLength(-1), _ctrlEnterSubmit(true), _oldtext(v), _phVisible(!v.length()), a_phLeft(_phVisible ? 0 : st.phShift), a_phAlpha(_phVisible ? 1 : 0), a_phColor(st.phColor->c), _st(st), _undoAvailable(false), _redoAvailable(false), _inDrop(false), _inHeightCheck(false), _fakeMargin(0), _touchPress(false), _touchRightButton(false), _touchMove(false), _correcting(false) { setAcceptRichText(false); resize(_st.width, _st.font->height); setFont(_st.font->f); setAlignment(_st.align); setPlaceholder(pholder); QPalette p(palette()); p.setColor(QPalette::Text, _st.textColor->c); setPalette(p); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setFrameStyle(QFrame::NoFrame | QFrame::Plain); viewport()->setAutoFillBackground(false); setContentsMargins(0, 0, 0, 0); switch (cScale()) { case dbisOneAndQuarter: _fakeMargin = 1; break; case dbisOneAndHalf: _fakeMargin = 2; break; case dbisTwo: _fakeMargin = 4; break; } setStyleSheet(qsl("QTextEdit { margin: %1px; }").arg(_fakeMargin)); viewport()->setAttribute(Qt::WA_AcceptTouchEvents); _touchTimer.setSingleShot(true); connect(&_touchTimer, SIGNAL(timeout()), this, SLOT(onTouchTimer())); connect(document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(onDocumentContentsChange(int, int, int))); connect(document(), SIGNAL(contentsChanged()), this, SLOT(onDocumentContentsChanged())); connect(this, SIGNAL(undoAvailable(bool)), this, SLOT(onUndoAvailable(bool))); connect(this, SIGNAL(redoAvailable(bool)), this, SLOT(onRedoAvailable(bool))); if (App::wnd()) connect(this, SIGNAL(selectionChanged()), App::wnd(), SLOT(updateGlobalMenu())); if (!v.isEmpty()) { setPlainText(v); } }
InputField::InputField(QWidget *parent, const style::InputField &st, const QString &ph, const QString &val) : TWidget(parent), _inner(this, val), _oldtext(val), _keyEvent(0), _undoAvailable(false), _redoAvailable(false), _fakeMargin(0), _customUpDown(false), _placeholderFull(ph), _placeholderVisible(val.isEmpty()), a_placeholderLeft(_placeholderVisible ? 0 : st.placeholderShift), a_placeholderOpacity(_placeholderVisible ? 1 : 0), a_placeholderFg(st.placeholderFg->c), _placeholderFgAnim(animFunc(this, &InputField::placeholderFgStep)), _placeholderShiftAnim(animFunc(this, &InputField::placeholderShiftStep)), a_borderOpacityActive(0), a_borderFg(st.borderFg->c), _borderAnim(animFunc(this, &InputField::borderStep)), _focused(false), _error(false), _st(&st), _touchPress(false), _touchRightButton(false), _touchMove(false), _replacingEmojis(false) { _inner.setAcceptRichText(false); resize(_st->width, _st->height); _inner.setWordWrapMode(QTextOption::NoWrap); _inner.setLineWrapMode(QTextEdit::NoWrap); _inner.setFont(_st->font->f); _inner.setAlignment(cRtl() ? Qt::AlignRight : Qt::AlignLeft); _placeholder = _st->font->m.elidedText(_placeholderFull, Qt::ElideRight, width() - _st->textMargins.left() - _st->textMargins.right() - _st->placeholderMargins.left() - _st->placeholderMargins.right() - 1); QPalette p(palette()); p.setColor(QPalette::Text, _st->textFg->c); setPalette(p); _inner.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); _inner.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); _inner.setFrameStyle(QFrame::NoFrame | QFrame::Plain); _inner.viewport()->setAutoFillBackground(false); _inner.setContentsMargins(0, 0, 0, 0); _inner.document()->setDocumentMargin(0); setAttribute(Qt::WA_AcceptTouchEvents); _inner.viewport()->setAttribute(Qt::WA_AcceptTouchEvents); _touchTimer.setSingleShot(true); connect(&_touchTimer, SIGNAL(timeout()), this, SLOT(onTouchTimer())); connect(_inner.document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(onDocumentContentsChange(int, int, int))); connect(_inner.document(), SIGNAL(contentsChanged()), this, SLOT(onDocumentContentsChanged())); connect(&_inner, SIGNAL(undoAvailable(bool)), this, SLOT(onUndoAvailable(bool))); connect(&_inner, SIGNAL(redoAvailable(bool)), this, SLOT(onRedoAvailable(bool))); if (App::wnd()) connect(&_inner, SIGNAL(selectionChanged()), App::wnd(), SLOT(updateGlobalMenu())); }