boxes finished

This commit is contained in:
John Preston 2015-10-14 13:51:37 +02:00
parent ed707c8f0e
commit 8172b82ed4
15 changed files with 163 additions and 84 deletions

View File

@ -135,12 +135,12 @@ void AddContactBox::resizeEvent(QResizeEvent *e) {
_phone.resize(_first.width(), _last.height());
if (_invertOrder) {
_last.moveToLeft(st::boxPadding.left() + st::contactPadding.left(), st::boxTitleHeight + st::contactPadding.top());
_first.moveToLeft(_last.x(), _last.y() + _last.height() + st::contactSkip);
_phone.moveToLeft(_first.x(), _first.y() + _first.height() + st::contactPhoneSkip);
_first.moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _last.y() + _last.height() + st::contactSkip);
_phone.moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _first.y() + _first.height() + st::contactPhoneSkip);
} else {
_first.moveToLeft(st::boxPadding.left() + st::contactPadding.left(), st::boxTitleHeight + st::contactPadding.top());
_last.moveToLeft(_first.x(), _first.y() + _first.height() + st::contactSkip);
_phone.moveToLeft(_last.x(), _last.y() + _last.height() + st::contactPhoneSkip);
_last.moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _first.y() + _first.height() + st::contactSkip);
_phone.moveToLeft(st::boxPadding.left() + st::contactPadding.left(), _last.y() + _last.height() + st::contactPhoneSkip);
}
_save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height());
@ -165,7 +165,9 @@ void AddContactBox::onSubmit() {
void AddContactBox::onSave() {
if (_addRequest) return;
QString firstName = _first.getLastText().trimmed(), lastName = _last.getLastText().trimmed(), phone = _phone.getLastText().trimmed();
QString firstName = prepareSentText(_first.getLastText());
QString lastName = prepareSentText(_last.getLastText());
QString phone = _phone.getLastText().trimmed();
if (firstName.isEmpty() && lastName.isEmpty()) {
if (_invertOrder) {
_last.setFocus();
@ -318,11 +320,11 @@ void NewGroupBox::paintEvent(QPaintEvent *e) {
p.setPen(st::newGroupAboutFg->p);
QRect aboutGroup = myrtlrect(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadiobutton.textPosition.x(), _group.y() + _group.height() + st::lineWidth, _aboutGroupWidth, _aboutGroupHeight);
_aboutGroup.draw(p, aboutGroup.x(), aboutGroup.y(), aboutGroup.width());
QRect aboutGroup(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadiobutton.textPosition.x(), _group.y() + _group.height() + st::lineWidth, _aboutGroupWidth, _aboutGroupHeight);
_aboutGroup.drawLeft(p, aboutGroup.x(), aboutGroup.y(), aboutGroup.width(), width());
QRect aboutChannel = myrtlrect(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadiobutton.textPosition.x(), _channel.y() + _channel.height() + st::lineWidth, _aboutGroupWidth, _aboutGroupHeight);
_aboutChannel.draw(p, aboutChannel.x(), aboutChannel.y(), aboutChannel.width());
QRect aboutChannel(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadiobutton.textPosition.x(), _channel.y() + _channel.height() + st::lineWidth, _aboutGroupWidth, _aboutGroupHeight);
_aboutChannel.drawLeft(p, aboutChannel.x(), aboutChannel.y(), aboutChannel.width(), width());
}
void NewGroupBox::resizeEvent(QResizeEvent *e) {
@ -489,7 +491,7 @@ void GroupInfoBox::onNameSubmit() {
void GroupInfoBox::onNext() {
if (_creationRequestId) return;
QString title = _title.getLastText().trimmed();
QString title = prepareSentText(_title.getLastText());
if (title.isEmpty()) {
_title.setFocus();
_title.showError();
@ -498,7 +500,7 @@ void GroupInfoBox::onNext() {
if (_creating == CreatingGroupGroup) {
App::wnd()->replaceLayer(new ContactsBox(title, _photoBig));
} else {
_creationRequestId = MTP::send(MTPchannels_CreateChannel(MTP_int(MTPmessages_CreateChannel_flag_broadcast), MTP_string(title), MTP_string(_description.getLastText().trimmed()), MTP_vector<MTPInputUser>(0)), rpcDone(&GroupInfoBox::creationDone), rpcFail(&GroupInfoBox::creationFail));
_creationRequestId = MTP::send(MTPchannels_CreateChannel(MTP_int(MTPmessages_CreateChannel_flag_broadcast), MTP_string(title), MTP_string(prepareSentText(_description.getLastText())), MTP_vector<MTPInputUser>(0)), rpcDone(&GroupInfoBox::creationDone), rpcFail(&GroupInfoBox::creationFail));
}
}
@ -689,14 +691,14 @@ void SetupChannelBox::paintEvent(QPaintEvent *e) {
p.setPen(st::newGroupAboutFg);
QRect aboutPublic = myrtlrect(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadiobutton.textPosition.x(), _public.y() + _public.height(), _aboutPublicWidth, _aboutPublicHeight);
_aboutPublic.draw(p, aboutPublic.x(), aboutPublic.y(), aboutPublic.width());
QRect aboutPublic(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadiobutton.textPosition.x(), _public.y() + _public.height(), _aboutPublicWidth, _aboutPublicHeight);
_aboutPublic.drawLeft(p, aboutPublic.x(), aboutPublic.y(), aboutPublic.width(), width());
QRect aboutPrivate = myrtlrect(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadiobutton.textPosition.x(), _private.y() + _private.height(), _aboutPublicWidth, _aboutPublicHeight);
_aboutPrivate.draw(p, aboutPrivate.x(), aboutPrivate.y(), aboutPrivate.width());
QRect aboutPrivate(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadiobutton.textPosition.x(), _private.y() + _private.height(), _aboutPublicWidth, _aboutPublicHeight);
_aboutPrivate.drawLeft(p, aboutPrivate.x(), aboutPrivate.y(), aboutPrivate.width(), width());
//QRect aboutComments = myrtlrect(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadiobutton.textPosition.x(), _comments.y() + _comments.height(), _aboutPublicWidth, _aboutPublicHeight);
//_aboutComments.draw(p, aboutComments.x(), aboutComments.y(), aboutComments.width());
//QRect aboutComments(st::boxPadding.left() + st::newGroupPadding.left() + st::defaultRadiobutton.textPosition.x(), _comments.y() + _comments.height(), _aboutPublicWidth, _aboutPublicHeight);
//_aboutComments.drawLeft(p, aboutComments.x(), aboutComments.y(), aboutComments.width(), width());
p.setPen(st::black);
p.setFont(st::newGroupLinkFont);
@ -1078,7 +1080,7 @@ void EditNameTitleBox::resizeEvent(QResizeEvent *e) {
void EditNameTitleBox::onSave() {
if (_requestId) return;
QString first = _first.getLastText().trimmed(), last = _last.getLastText().trimmed();
QString first = prepareSentText(_first.getLastText()), last = prepareSentText(_last.getLastText());
if (first.isEmpty() && last.isEmpty()) {
if (_invertOrder) {
_last.setFocus();
@ -1169,7 +1171,7 @@ _saveTitleRequestId(0), _saveDescriptionRequestId(0) {
updateMaxHeight();
connect(&_description, SIGNAL(resized()), this, SLOT(onDescriptionResized()));
connect(&_description, SIGNAL(submitted(bool)), this, SLOT(onNext()));
connect(&_description, SIGNAL(submitted(bool)), this, SLOT(onSave()));
connect(&_description, SIGNAL(cancelled()), this, SLOT(onClose()));
connect(&_save, SIGNAL(clicked()), this, SLOT(onSave()));
@ -1251,7 +1253,7 @@ void EditChannelBox::resizeEvent(QResizeEvent *e) {
void EditChannelBox::onSave() {
if (_saveTitleRequestId || _saveDescriptionRequestId) return;
QString title = _title.getLastText().trimmed(), description = _description.getLastText().trimmed();
QString title = prepareSentText(_title.getLastText()), description = prepareSentText(_description.getLastText());
if (title.isEmpty()) {
_title.setFocus();
_title.showError();

View File

@ -121,7 +121,7 @@ void ConfirmBox::updateHover() {
QPoint m(mapFromGlobal(_lastMousePos));
bool wasMy = (_myLink == textlnkOver());
textstyleSet(&st::boxTextStyle);
_myLink = _text.link(m.x() - st::boxPadding.left(), m.y() - st::boxPadding.top(), _textWidth, (_text.maxWidth() < width()) ? style::al_center : style::al_left);
_myLink = _text.linkLeft(m.x() - st::boxPadding.left(), m.y() - st::boxPadding.top(), _textWidth, width(), (_text.maxWidth() < width()) ? style::al_center : style::al_left);
textstyleRestore();
if (_myLink != textlnkOver()) {
if (wasMy || _myLink || rect().contains(m)) {
@ -165,7 +165,7 @@ void ConfirmBox::paintEvent(QPaintEvent *e) {
// draw box title / text
p.setPen(st::black->p);
textstyleSet(&st::boxTextStyle);
_text.drawElided(p, st::boxPadding.left(), st::boxPadding.top(), _textWidth, 16, style::al_left);
_text.drawLeftElided(p, st::boxPadding.left(), st::boxPadding.top(), _textWidth, width(), 16, style::al_left);
textstyleRestore();
}
@ -259,7 +259,7 @@ void MaxInviteBox::paintEvent(QPaintEvent *e) {
// draw box title / text
p.setPen(st::black->p);
_text.drawElided(p, st::boxPadding.left(), st::boxPadding.top(), _textWidth, 16, style::al_left);
_text.drawLeftElided(p, st::boxPadding.left(), st::boxPadding.top(), _textWidth, width(), 16, style::al_left);
QTextOption option(style::al_left);
option.setWrapMode(QTextOption::WrapAnywhere);

View File

@ -341,7 +341,7 @@ void ContactsInner::paintDialog(Painter &p, PeerData *peer, ContactData *data, b
namew -= st::verifiedCheck.pxWidth() + st::verifiedCheckPos.x();
p.drawSpriteLeft(namex + qMin(data->name.maxWidth(), namew) + st::verifiedCheckPos.x(), st::contactsPadding.top() + st::contactsNameTop + st::verifiedCheckPos.y(), width(), st::verifiedCheck);
}
data->name.drawElided(p, namex, st::contactsPadding.top() + st::contactsNameTop, namew);
data->name.drawLeftElided(p, namex, st::contactsPadding.top() + st::contactsNameTop, namew, width());
if (_chat || (_creating != CreatingGroupNone && (!_channel || _channelFilter != MembersFilterAdmins))) {
if (sel || data->check) {
@ -1641,7 +1641,7 @@ void MembersInner::paintDialog(Painter &p, PeerData *peer, MemberData *data, boo
namew -= st::verifiedCheck.pxWidth() + st::verifiedCheckPos.x();
p.drawSpriteLeft(namex + qMin(data->name.maxWidth(), namew) + st::verifiedCheckPos.x(), st::contactsPadding.top() + st::contactsNameTop + st::verifiedCheckPos.y(), width(), st::verifiedCheck);
}
data->name.drawElided(p, namex, st::contactsPadding.top() + st::contactsNameTop, namew);
data->name.drawLeftElided(p, namex, st::contactsPadding.top() + st::contactsNameTop, namew, width());
if (data->canKick) {
p.setFont((kickSel ? st::linkOverFont : st::linkFont)->f);

View File

@ -35,7 +35,7 @@ PasscodeBox::PasscodeBox(bool turningOff) : AbstractBox(st::boxWidth)
, _hasRecovery(false)
, _skipEmailWarning(false)
, _aboutHeight(0)
, _about(st::boxWidth - st::boxPadding.left() - st::boxPadding.right())
, _about(st::boxWidth - st::boxPadding.left() * 1.5)
, _saveButton(this, lang(_turningOff ? lng_passcode_remove_button : lng_settings_save), st::defaultBoxButton)
, _cancelButton(this, lang(lng_cancel), st::cancelBoxButton)
, _oldPasscode(this, st::defaultInputField, lang(lng_passcode_enter_old))
@ -58,7 +58,7 @@ PasscodeBox::PasscodeBox(const QByteArray &newSalt, const QByteArray &curSalt, b
, _hasRecovery(hasRecovery)
, _skipEmailWarning(false)
, _aboutHeight(0)
, _about(st::boxWidth - st::boxPadding.left() - st::boxPadding.right())
, _about(st::boxWidth - st::boxPadding.left() * 1.5)
, _saveButton(this, lang(_turningOff ? lng_passcode_remove_button : lng_settings_save), st::defaultBoxButton)
, _cancelButton(this, lang(lng_cancel), st::cancelBoxButton)
, _oldPasscode(this, st::defaultInputField, lang(lng_cloud_password_enter_old))
@ -79,7 +79,7 @@ void PasscodeBox::init() {
textstyleSet(&st::usernameTextStyle);
_about.setRichText(st::normalFont, lang(_cloudPwd ? lng_cloud_password_about : lng_passcode_about));
_aboutHeight = _about.countHeight(st::boxWidth - st::boxPadding.left() - st::boxPadding.right());
_aboutHeight = _about.countHeight(st::boxWidth - st::boxPadding.left() * 1.5);
textstyleRestore();
if (_turningOff) {
_oldPasscode.show();
@ -213,29 +213,29 @@ void PasscodeBox::paintEvent(QPaintEvent *e) {
textstyleSet(&st::usernameTextStyle);
int32 w = width() - st::boxPadding.left() - st::boxPadding.right();
int32 w = st::boxWidth - st::boxPadding.left() * 1.5;
int32 abouty = (_passwordHint.isHidden() ? (_reenterPasscode.isHidden() ? (_oldPasscode.y() + (_hasRecovery && !_hintText.isEmpty() ? st::passcodeSkip : 0)) : _reenterPasscode.y()) + st::passcodeSkip : _passwordHint.y() + st::contactSkip) + _oldPasscode.height();
p.setPen(st::black);
_about.draw(p, st::boxPadding.left(), abouty, w);
_about.drawLeft(p, st::boxPadding.left(), abouty, w, width());
if (!_hintText.isEmpty() && _oldError.isEmpty()) {
p.setPen(st::black->p);
_hintText.drawElided(p, st::boxPadding.left(), _oldPasscode.y() + _oldPasscode.height() + ((st::passcodeSkip - st::normalFont->height) / 2), w, 1, style::al_topleft);
_hintText.drawLeftElided(p, st::boxPadding.left(), _oldPasscode.y() + _oldPasscode.height() + ((st::passcodeSkip - st::normalFont->height) / 2), w, width(), 1, style::al_topleft);
}
if (!_oldError.isEmpty()) {
p.setPen(st::setErrColor->p);
p.drawText(QRect(st::boxPadding.left(), _oldPasscode.y() + _oldPasscode.height(), width() - st::boxPadding.left() - st::boxPadding.right(), st::passcodeSkip), _oldError, style::al_left);
p.drawText(QRect(st::boxPadding.left(), _oldPasscode.y() + _oldPasscode.height(), w, st::passcodeSkip), _oldError, style::al_left);
}
if (!_newError.isEmpty()) {
p.setPen(st::setErrColor->p);
p.drawText(QRect(st::boxPadding.left(), _reenterPasscode.y() + _reenterPasscode.height(), width() - st::boxPadding.left() - st::boxPadding.right(), st::passcodeSkip), _newError, style::al_left);
p.drawText(QRect(st::boxPadding.left(), _reenterPasscode.y() + _reenterPasscode.height(), w, st::passcodeSkip), _newError, style::al_left);
}
if (!_emailError.isEmpty()) {
p.setPen(st::setErrColor->p);
p.drawText(QRect(st::boxPadding.left(), _recoverEmail.y() + _recoverEmail.height(), width() - st::boxPadding.left() - st::boxPadding.right(), st::passcodeSkip), _emailError, style::al_left);
p.drawText(QRect(st::boxPadding.left(), _recoverEmail.y() + _recoverEmail.height(), w, st::passcodeSkip), _emailError, style::al_left);
}
textstyleRestore();
@ -243,7 +243,7 @@ void PasscodeBox::paintEvent(QPaintEvent *e) {
void PasscodeBox::resizeEvent(QResizeEvent *e) {
bool has = _cloudPwd ? (!_curSalt.isEmpty()) : cHasPasscode();
int32 w = width() - st::boxPadding.left() - st::boxPadding.right();
int32 w = st::boxWidth - st::boxPadding.left() - st::boxPadding.right();
_oldPasscode.resize(w, _oldPasscode.height());
_oldPasscode.moveToLeft(st::boxPadding.left(), st::boxTitleHeight + st::passcodePadding.top());
_newPasscode.resize(w, _newPasscode.height());
@ -498,7 +498,7 @@ bool PasscodeBox::recoverStartFail(const RPCError &error) {
RecoverBox::RecoverBox(const QString &pattern) : AbstractBox(st::boxWidth)
, _submitRequest(0)
, _pattern(st::normalFont->elided(lng_signin_recover_hint(lt_recover_email, pattern), st::boxWidth - st::boxPadding.left() - st::boxPadding.right()))
, _pattern(st::normalFont->elided(lng_signin_recover_hint(lt_recover_email, pattern), st::boxWidth - st::boxPadding.left() * 1.5))
, _saveButton(this, lang(lng_passcode_submit), st::defaultBoxButton)
, _cancelButton(this, lang(lng_cancel), st::cancelBoxButton)
, _recoverCode(this, st::defaultInputField, lang(lng_signin_code)) {
@ -537,7 +537,7 @@ void RecoverBox::paintEvent(QPaintEvent *e) {
p.setFont(st::normalFont);
p.setPen(st::black);
int32 w = width() - st::boxPadding.left() - st::boxPadding.right();
int32 w = st::boxWidth - st::boxPadding.left() * 1.5;
p.drawText(QRect(st::boxPadding.left(), _recoverCode.y() - st::passcodeSkip - st::passcodePadding.top(), w, st::passcodePadding.top() + st::passcodeSkip), _pattern, style::al_left);
if (!_error.isEmpty()) {
@ -547,7 +547,8 @@ void RecoverBox::paintEvent(QPaintEvent *e) {
}
void RecoverBox::resizeEvent(QResizeEvent *e) {
_recoverCode.setGeometry(st::boxPadding.left(), st::boxTitleHeight + st::passcodePadding.top() + st::passcodeSkip, width() - st::boxPadding.left() - st::boxPadding.right(), _recoverCode.height());
_recoverCode.resize(st::boxWidth - st::boxPadding.left() - st::boxPadding.right(), _recoverCode.height());
_recoverCode.moveToLeft(st::boxPadding.left(), st::boxTitleHeight + st::passcodePadding.top() + st::passcodeSkip);
_saveButton.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _saveButton.height());
_cancelButton.moveToRight(st::boxButtonPadding.right() + _saveButton.width() + st::boxButtonPadding.left(), _saveButton.y());

View File

@ -267,7 +267,7 @@ void PhotoSendBox::onSend(bool ctrlShiftEnter) {
}
if (_compressed.isHidden() || _compressed.checked()) {
_img->ctrlShiftEnter = ctrlShiftEnter;
_img->caption = _caption.isHidden() ? QString() : _caption.getLastText();
_img->caption = _caption.isHidden() ? QString() : prepareSentText(_caption.getLastText());
if (App::main()) App::main()->confirmSendImage(*_img);
} else {
if (App::main()) App::main()->confirmSendImageUncompressed(ctrlShiftEnter, _replyTo);

View File

@ -102,8 +102,8 @@ void UsernameBox::paintEvent(QPaintEvent *e) {
}
p.setPen(st::black);
textstyleSet(&st::usernameTextStyle);
int32 availw = st::boxWidth - st::usernamePadding.left(), h = _about.countHeight(availw);
_about.draw(p, st::usernamePadding.left(), _username.y() + _username.height() + st::usernameSkip, availw);
int32 availw = st::boxWidth - st::usernamePadding.left() - st::usernamePadding.right(), h = _about.countHeight(availw);
_about.drawLeft(p, st::usernamePadding.left(), _username.y() + _username.height() + st::usernameSkip, availw, width());
textstyleRestore();
int32 linky = _username.y() + _username.height() + st::usernameSkip + h + st::usernameTextStyle.lineHeight + ((st::usernameTextStyle.lineHeight - st::boxTextFont->height) / 2);
@ -121,7 +121,7 @@ void UsernameBox::resizeEvent(QResizeEvent *e) {
_username.moveToLeft(st::usernamePadding.left(), st::boxTitleHeight + st::usernamePadding.top());
textstyleSet(&st::usernameTextStyle);
int32 availw = st::boxWidth - st::usernamePadding.left(), h = _about.countHeight(availw);
int32 availw = st::boxWidth - st::usernamePadding.left() - st::usernamePadding.right(), h = _about.countHeight(availw);
textstyleRestore();
int32 linky = _username.y() + _username.height() + st::usernameSkip + h + st::usernameTextStyle.lineHeight + ((st::usernameTextStyle.lineHeight - st::boxTextFont->height) / 2);
_link.moveToLeft(st::usernamePadding.left(), linky + st::usernameTextStyle.lineHeight + ((st::usernameTextStyle.lineHeight - st::boxTextFont->height) / 2));

View File

@ -439,7 +439,7 @@ void DialogsInner::createDialog(History *history) {
if (creating) {
refresh();
} else if (_state == DefaultState && movedFrom != movedTo) {
update(0, qMin(movedFrom, movedTo) * st::dlgHeight, fullWidth(), qAbs(movedFrom - movedTo) * st::dlgHeight);
update(0, qMin(movedFrom, movedTo) * st::dlgHeight, fullWidth(), (qAbs(movedFrom - movedTo) + 1) * st::dlgHeight);
}
}

View File

@ -209,5 +209,16 @@ inline QString replaceEmojis(const QString &text) {
return result;
}
inline QString prepareSentText(QString result) {
result = result.replace('\t', qsl(" "));
result = result.replace(" --", QString::fromUtf8(" \xe2\x80\x94"));
result = result.replace("-- ", QString::fromUtf8("\xe2\x80\x94 "));
result = result.replace("<<", QString::fromUtf8("\xc2\xab"));
result = result.replace(">>", QString::fromUtf8("\xc2\xbb"));
return (cReplaceEmojis() ? replaceEmojis(result) : result).trimmed();
}
int emojiPackCount(DBIEmojiTab tab);
EmojiPack emojiPack(DBIEmojiTab tab);

View File

@ -589,14 +589,14 @@ _correcting(false) {
_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()));
setCursor(style::cur_text);
heightAutoupdated();
_inner.document()->clearUndoRedoStacks();
}
void InputArea::onTouchTimer() {
@ -631,6 +631,8 @@ void InputArea::checkContentHeight() {
}
InputArea::InputAreaInner::InputAreaInner(InputArea *parent, const QString &val) : QTextEdit(parent) {
connect(document(), SIGNAL(contentsChange(int, int, int)), parent, SLOT(onDocumentContentsChange(int, int, int)));
connect(document(), SIGNAL(contentsChanged()), parent, SLOT(onDocumentContentsChanged()));
if (!val.isEmpty()) {
setPlainText(val);
}
@ -1258,13 +1260,12 @@ _correcting(false) {
_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()));
setCursor(style::cur_text);
_inner.document()->clearUndoRedoStacks();
}
void InputField::onTouchTimer() {
@ -1272,6 +1273,8 @@ void InputField::onTouchTimer() {
}
InputField::InputFieldInner::InputFieldInner(InputField *parent, const QString &val) : QTextEdit(parent) {
connect(document(), SIGNAL(contentsChange(int, int, int)), parent, SLOT(onDocumentContentsChange(int, int, int)));
connect(document(), SIGNAL(contentsChanged()), parent, SLOT(onDocumentContentsChanged()));
if (!val.isEmpty()) {
setPlainText(val);
}

View File

@ -548,10 +548,31 @@ public:
void draw(QPainter &p, int32 left, int32 top, int32 width, style::align align = style::al_left, int32 yFrom = 0, int32 yTo = -1, uint16 selectedFrom = 0, uint16 selectedTo = 0) const;
void drawElided(QPainter &p, int32 left, int32 top, int32 width, int32 lines = 1, style::align align = style::al_left, int32 yFrom = 0, int32 yTo = -1, int32 removeFromEnd = 0) const;
void drawLeft(QPainter &p, int32 left, int32 top, int32 width, int32 outerw, style::align align = style::al_left, int32 yFrom = 0, int32 yTo = -1, uint16 selectedFrom = 0, uint16 selectedTo = 0) const {
draw(p, rtl() ? (outerw - left - width) : left, top, width, align, yFrom, yTo, selectedFrom, selectedTo);
}
void drawLeftElided(QPainter &p, int32 left, int32 top, int32 width, int32 outerw, int32 lines = 1, style::align align = style::al_left, int32 yFrom = 0, int32 yTo = -1, int32 removeFromEnd = 0) const {
drawElided(p, rtl() ? (outerw - left - width) : left, top, width, lines, align, yFrom, yTo, removeFromEnd);
}
void drawRight(QPainter &p, int32 right, int32 top, int32 width, int32 outerw, style::align align = style::al_left, int32 yFrom = 0, int32 yTo = -1, uint16 selectedFrom = 0, uint16 selectedTo = 0) const {
draw(p, rtl() ? right : (outerw - right - width), top, width, align, yFrom, yTo, selectedFrom, selectedTo);
}
void drawRightElided(QPainter &p, int32 right, int32 top, int32 width, int32 outerw, int32 lines = 1, style::align align = style::al_left, int32 yFrom = 0, int32 yTo = -1, int32 removeFromEnd = 0) const {
drawElided(p, rtl() ? right : (outerw - right - width), top, width, lines, align, yFrom, yTo, removeFromEnd);
}
const TextLinkPtr &link(int32 x, int32 y, int32 width, style::align align = style::al_left) const;
const TextLinkPtr &linkLeft(int32 x, int32 y, int32 width, int32 outerw, style::align align = style::al_left) const {
return link(rtl() ? (outerw - x - width) : x, y, width, align);
}
void getState(TextLinkPtr &lnk, bool &inText, int32 x, int32 y, int32 width, style::align align = style::al_left) const;
void getStateLeft(TextLinkPtr &lnk, bool &inText, int32 x, int32 y, int32 width, int32 outerw, style::align align = style::al_left) const {
return getState(lnk, inText, rtl() ? (outerw - x - width) : x, y, width, align);
}
void getSymbol(uint16 &symbol, bool &after, bool &upon, int32 x, int32 y, int32 width, style::align align = style::al_left) const;
void getSymbolLeft(uint16 &symbol, bool &after, bool &upon, int32 x, int32 y, int32 width, int32 outerw, style::align align = style::al_left) const {
return getSymbol(symbol, after, upon, rtl() ? (outerw - x - width) : x, y, width, align);
}
uint32 adjustSelection(uint16 from, uint16 to, TextSelectType selectType) const;
bool isEmpty() const {

View File

@ -2326,6 +2326,7 @@ void History::setLastMessage(HistoryItem *msg) {
} else {
lastMsg = 0;
}
if (!dialogs.isEmpty() && App::main()) App::main()->dlgUpdated(dialogs[0]);
}
void History::setPosInDialogsDate(const QDateTime &date) {

View File

@ -1662,11 +1662,36 @@ void MessageField::dropEvent(QDropEvent *e) {
}
bool MessageField::canInsertFromMimeData(const QMimeData *source) const {
if (source->hasUrls()) {
int32 files = 0;
for (int32 i = 0; i < source->urls().size(); ++i) {
if (source->urls().at(i).isLocalFile()) {
++files;
}
}
if (files > 1) return false;
}
if (source->hasImage()) return true;
return FlatTextarea::canInsertFromMimeData(source);
}
void MessageField::insertFromMimeData(const QMimeData *source) {
if (source->hasUrls()) {
int32 files = 0;
QUrl url;
for (int32 i = 0; i < source->urls().size(); ++i) {
if (source->urls().at(i).isLocalFile()) {
url = source->urls().at(i);
++files;
}
}
if (files > 1) return;
if (files) {
QString file(url.toLocalFile());
history->uploadFile(file);
return;
}
}
if (source->hasImage()) {
QImage img = qvariant_cast<QImage>(source->imageData());
if (!img.isNull()) {
@ -3738,17 +3763,6 @@ void HistoryWidget::onVisibleChanged() {
QTimer::singleShot(0, this, SLOT(onListScroll()));
}
QString HistoryWidget::prepareMessage(QString result) {
result = result.replace('\t', qsl(" "));
result = result.replace(" --", QString::fromUtf8(" \xe2\x80\x94"));
result = result.replace("-- ", QString::fromUtf8("\xe2\x80\x94 "));
result = result.replace("<<", QString::fromUtf8("\xc2\xab"));
result = result.replace(">>", QString::fromUtf8("\xc2\xbb"));
return (cReplaceEmojis() ? replaceEmojis(result) : result).trimmed();
}
void HistoryWidget::onHistoryToEnd() {
if (_replyReturn) {
showPeerHistory(_peer->id, _replyReturn->id);
@ -3777,7 +3791,7 @@ void HistoryWidget::onSend(bool ctrlShiftEnter, MsgId replyTo) {
if (!_history) return;
bool lastKeyboardUsed = lastForceReplyReplied(FullMsgId(_channel, replyTo));
QString text = prepareMessage(_field.getLastText());
QString text = prepareSentText(_field.getLastText());
if (!text.isEmpty()) {
App::main()->readServerHistory(_history, false);
fastShowAtEnd(_history);
@ -4112,6 +4126,8 @@ void HistoryWidget::onPhotoSelect() {
if (filedialogGetOpenFiles(files, file, lang(lng_choose_images), filter)) {
if (!file.isEmpty()) {
uploadMedia(file, ToPreparePhoto);
//} else if (files.size() == 1) {
// uploadWithConfirm(files.at(0), false, true);
} else if (!files.isEmpty()) {
uploadMedias(files, ToPreparePhoto);
}
@ -4140,6 +4156,8 @@ void HistoryWidget::onDocumentSelect() {
if (filedialogGetOpenFiles(files, file, lang(lng_choose_images), filter)) {
if (!file.isEmpty()) {
uploadMedia(file, ToPrepareDocument);
//} else if (files.size() == 1) {
// uploadWithConfirm(files.at(0), false, false);
} else if (!files.isEmpty()) {
uploadMedias(files, ToPrepareDocument);
}
@ -4439,17 +4457,22 @@ void HistoryWidget::dropEvent(QDropEvent *e) {
void HistoryWidget::onPhotoDrop(const QMimeData *data) {
if (!_history) return;
if (data->hasImage()) {
QImage image = qvariant_cast<QImage>(data->imageData());
if (image.isNull()) return;
QStringList files = getMediasFromMime(data);
if (files.isEmpty()) {
if (data->hasImage()) {
QImage image = qvariant_cast<QImage>(data->imageData());
if (image.isNull()) return;
uploadImage(image, false, data->text());
} else {
QStringList files = getMediasFromMime(data);
if (files.isEmpty()) return;
uploadMedias(files, ToPreparePhoto);
uploadImage(image, false, data->text());
}
return;
}
//if (files.size() == 1) {
// uploadWithConfirm(files.at(0), false, true);
//} else {
uploadMedias(files, ToPreparePhoto);
//}
}
void HistoryWidget::onDocumentDrop(const QMimeData *data) {
@ -4458,21 +4481,30 @@ void HistoryWidget::onDocumentDrop(const QMimeData *data) {
QStringList files = getMediasFromMime(data);
if (files.isEmpty()) return;
uploadMedias(files, ToPrepareDocument);
//if (files.size() == 1) {
// uploadWithConfirm(files.at(0), false, false);
//} else {
uploadMedias(files, ToPrepareDocument);
//}
}
void HistoryWidget::onFilesDrop(const QMimeData *data) {
if (data->hasImage()) {
QImage image = qvariant_cast<QImage>(data->imageData());
if (image.isNull()) return;
QStringList files = getMediasFromMime(data);
if (files.isEmpty()) {
if (data->hasImage()) {
QImage image = qvariant_cast<QImage>(data->imageData());
if (image.isNull()) return;
uploadImage(image, false, data->text());
} else {
QStringList files = getMediasFromMime(data);
if (files.isEmpty()) return;
uploadMedias(files, ToPrepareAuto);
uploadImage(image, false, data->text());
}
return;
}
//if (files.size() == 1) {
// uploadWithConfirm(files.at(0), false, true);
//} else {
uploadMedias(files, ToPrepareAuto);
//}
}
void HistoryWidget::onKbToggle(bool manual) {

View File

@ -475,8 +475,6 @@ public:
bool touchScroll(const QPoint &delta);
QString prepareMessage(QString text);
uint64 animActiveTime(MsgId id) const;
void stopAnimActive();

View File

@ -1227,7 +1227,7 @@ void MainWidget::sendMessage(History *hist, const QString &text, MsgId replyTo,
int32 fixInScrollMsgTop = 0;
hist->getReadyFor(ShowAtTheEndMsgId, fixInScrollMsgId, fixInScrollMsgTop);
readServerHistory(hist, false);
sendPreparedText(hist, history.prepareMessage(text), replyTo, broadcast);
sendPreparedText(hist, prepareSentText(text), replyTo, broadcast);
}
void MainWidget::saveRecentHashtags(const QString &text) {
@ -2378,6 +2378,7 @@ void MainWidget::showPeerHistory(quint64 peerId, qint32 showAtMsgId, bool back)
overview = 0;
}
clearBotStartToken(_peerInStack);
dlgUpdated();
_peerInStack = 0;
_msgIdInStack = 0;
_stack.clear();
@ -2503,8 +2504,10 @@ void MainWidget::showMediaOverview(PeerData *peer, MediaOverviewType type, bool
} else if (profile) {
_stack.push_back(new StackItemProfile(profile->peer(), profile->lastScrollTop()));
} else if (history.peer()) {
dlgUpdated();
_peerInStack = history.peer();
_msgIdInStack = history.msgId();
dlgUpdated();
_stack.push_back(new StackItemHistory(_peerInStack, _msgIdInStack, history.replyReturns(), history.kbWasHidden()));
}
}
@ -2557,8 +2560,10 @@ void MainWidget::showPeerProfile(PeerData *peer, bool back, int32 lastScrollTop)
} else if (profile) {
_stack.push_back(new StackItemProfile(profile->peer(), profile->lastScrollTop()));
} else {
dlgUpdated();
_peerInStack = history.peer();
_msgIdInStack = history.msgId();
dlgUpdated();
_stack.push_back(new StackItemHistory(_peerInStack, _msgIdInStack, history.replyReturns(), history.kbWasHidden()));
}
}
@ -2599,12 +2604,14 @@ void MainWidget::showBackFromStack() {
StackItem *item = _stack.back();
_stack.pop_back();
if (item->type() == HistoryStackItem) {
dlgUpdated();
_peerInStack = 0;
_msgIdInStack = 0;
for (int32 i = _stack.size(); i > 0;) {
if (_stack.at(--i)->type() == HistoryStackItem) {
_peerInStack = static_cast<StackItemHistory*>(_stack.at(i))->peer;
_msgIdInStack = static_cast<StackItemHistory*>(_stack.at(i))->msgId;
dlgUpdated();
break;
}
}
@ -2638,8 +2645,11 @@ QRect MainWidget::historyRect() const {
}
void MainWidget::dlgUpdated(DialogRow *row) {
if (!row) return;
dialogs.dlgUpdated(row);
if (row) {
dialogs.dlgUpdated(row);
} else if (_peerInStack) {
dialogs.dlgUpdated(App::history(_peerInStack->id), _msgIdInStack);
}
}
void MainWidget::dlgUpdated(History *row, MsgId msgId) {

View File

@ -221,7 +221,7 @@ public:
void activate();
void createDialog(History *history);
void dlgUpdated(DialogRow *row);
void dlgUpdated(DialogRow *row = 0);
void dlgUpdated(History *row, MsgId msgId);
void windowShown();