improved custom keyboard

This commit is contained in:
John Preston 2015-06-19 15:39:33 +03:00
parent 052e0b827a
commit e7914ac468
8 changed files with 75 additions and 21 deletions

View file

@ -1053,7 +1053,7 @@ textRectMargins: margins(-2px, -1px, -2px, -1px);
taMsgField: flatTextarea(taDefFlat) { taMsgField: flatTextarea(taDefFlat) {
font: msgFont; font: msgFont;
} }
maxFieldHeight: 223px; maxFieldHeight: 243px;
newMsgSound: ':/gui/art/newmsg.wav'; newMsgSound: ':/gui/art/newmsg.wav';
@ -1926,6 +1926,11 @@ mentionPadding: margins(8px, 5px, 8px, 5px);
mentionTop: 11px; mentionTop: 11px;
mentionFont: linkFont; mentionFont: linkFont;
mentionPhotoSize: msgPhotoSize; mentionPhotoSize: msgPhotoSize;
mentionBgOver: #f5f5f5;
mentionFg: #777;
mentionFgOver: #707070;
mentionFgActive: #0080c0;
mentionFgOverActive: #0077b3;
botCommandFont: font(fsize semibold); botCommandFont: font(fsize semibold);
botDescFont: font(fsize italic); botDescFont: font(fsize italic);

View file

@ -104,7 +104,7 @@ void DialogsListWidget::paintEvent(QPaintEvent *e) {
for (; from < to; ++from) { for (; from < to; ++from) {
bool selected = (from == hashtagSel); bool selected = (from == hashtagSel);
if (selected) { if (selected) {
p.fillRect(0, 0, w, st::mentionHeight, st::dlgHoverBG->b); p.fillRect(0, 0, w, st::mentionHeight, st::mentionBgOver->b);
int skip = (st::mentionHeight - st::notifyClose.icon.pxHeight()) / 2; int skip = (st::mentionHeight - st::notifyClose.icon.pxHeight()) / 2;
p.drawPixmap(QPoint(w - st::notifyClose.icon.pxWidth() - skip, skip), App::sprite(), st::notifyClose.icon); p.drawPixmap(QPoint(w - st::notifyClose.icon.pxWidth() - skip, skip), App::sprite(), st::notifyClose.icon);
} }
@ -122,11 +122,11 @@ void DialogsListWidget::paintEvent(QPaintEvent *e) {
p.setFont(st::mentionFont->f); p.setFont(st::mentionFont->f);
if (!first.isEmpty()) { if (!first.isEmpty()) {
p.setPen(st::profileOnlineColor->p); p.setPen((selected ? st::mentionFgOverActive : st::mentionFgActive)->p);
p.drawText(st::dlgPaddingHor, st::mentionTop + st::mentionFont->ascent, first); p.drawText(st::dlgPaddingHor, st::mentionTop + st::mentionFont->ascent, first);
} }
if (!second.isEmpty()) { if (!second.isEmpty()) {
p.setPen(st::profileOfflineColor->p); p.setPen((selected ? st::mentionFgOver : st::mentionFg)->p);
p.drawText(st::dlgPaddingHor + firstwidth, st::mentionTop + st::mentionFont->ascent, second); p.drawText(st::dlgPaddingHor + firstwidth, st::mentionTop + st::mentionFont->ascent, second);
} }
p.translate(0, st::mentionHeight); p.translate(0, st::mentionHeight);

View file

@ -2433,8 +2433,9 @@ void MentionsInner::paintEvent(QPaintEvent *e) {
for (int32 i = from; i < to; ++i) { for (int32 i = from; i < to; ++i) {
if (i >= last) break; if (i >= last) break;
if (i == _sel) { bool selected = (i == _sel);
p.fillRect(0, i * st::mentionHeight, width(), st::mentionHeight, st::dlgHoverBG->b); if (selected) {
p.fillRect(0, i * st::mentionHeight, width(), st::mentionHeight, st::mentionBgOver->b);
int skip = (st::mentionHeight - st::notifyClose.icon.pxHeight()) / 2; int skip = (st::mentionHeight - st::notifyClose.icon.pxHeight()) / 2;
if (!_hrows->isEmpty()) p.drawPixmap(QPoint(width() - st::notifyClose.icon.pxWidth() - skip, i * st::mentionHeight + skip), App::sprite(), st::notifyClose.icon); if (!_hrows->isEmpty()) p.drawPixmap(QPoint(width() - st::notifyClose.icon.pxWidth() - skip, i * st::mentionHeight + skip), App::sprite(), st::notifyClose.icon);
} }
@ -2462,10 +2463,10 @@ void MentionsInner::paintEvent(QPaintEvent *e) {
user->nameText.drawElided(p, 2 * st::mentionPadding.left() + st::mentionPhotoSize, i * st::mentionHeight + st::mentionTop, namewidth); user->nameText.drawElided(p, 2 * st::mentionPadding.left() + st::mentionPhotoSize, i * st::mentionHeight + st::mentionTop, namewidth);
p.setFont(st::mentionFont->f); p.setFont(st::mentionFont->f);
p.setPen(st::profileOnlineColor->p); p.setPen((selected ? st::mentionFgOverActive : st::mentionFgActive)->p);
p.drawText(2 * st::mentionPadding.left() + st::mentionPhotoSize + namewidth + st::mentionPadding.right(), i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, first); p.drawText(2 * st::mentionPadding.left() + st::mentionPhotoSize + namewidth + st::mentionPadding.right(), i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, first);
if (!second.isEmpty()) { if (!second.isEmpty()) {
p.setPen(st::profileOfflineColor->p); p.setPen((selected ? st::mentionFgOver : st::mentionFg)->p);
p.drawText(2 * st::mentionPadding.left() + st::mentionPhotoSize + namewidth + st::mentionPadding.right() + firstwidth, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, second); p.drawText(2 * st::mentionPadding.left() + st::mentionPhotoSize + namewidth + st::mentionPadding.right() + firstwidth, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, second);
} }
} else if (!_hrows->isEmpty()) { } else if (!_hrows->isEmpty()) {
@ -2483,11 +2484,11 @@ void MentionsInner::paintEvent(QPaintEvent *e) {
p.setFont(st::mentionFont->f); p.setFont(st::mentionFont->f);
if (!first.isEmpty()) { if (!first.isEmpty()) {
p.setPen(st::profileOnlineColor->p); p.setPen((selected ? st::mentionFgOverActive : st::mentionFgActive)->p);
p.drawText(htagleft, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, first); p.drawText(htagleft, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, first);
} }
if (!second.isEmpty()) { if (!second.isEmpty()) {
p.setPen(st::profileOfflineColor->p); p.setPen((selected ? st::mentionFgOver : st::mentionFg)->p);
p.drawText(htagleft + firstwidth, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, second); p.drawText(htagleft + firstwidth, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, second);
} }
} else { } else {
@ -2517,11 +2518,11 @@ void MentionsInner::paintEvent(QPaintEvent *e) {
} }
p.setFont(st::botCommandFont->f); p.setFont(st::botCommandFont->f);
if (!first.isEmpty()) { if (!first.isEmpty()) {
p.setPen(st::profileOnlineColor->p); p.setPen((selected ? st::mentionFgOverActive : st::mentionFgActive)->p);
p.drawText(htagleft, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, first); p.drawText(htagleft, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, first);
} }
if (!second.isEmpty()) { if (!second.isEmpty()) {
p.setPen(st::profileOfflineColor->p); p.setPen((selected ? st::mentionFgOver : st::mentionFg)->p);
p.drawText(htagleft + firstwidth, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, second); p.drawText(htagleft + firstwidth, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, second);
} }
addleft += firstwidth + secondwidth + st::mentionPadding.left(); addleft += firstwidth + secondwidth + st::mentionPadding.left();
@ -2534,7 +2535,7 @@ void MentionsInner::paintEvent(QPaintEvent *e) {
if (widthleft < paramswidth) { if (widthleft < paramswidth) {
params = st::mentionFont->m.elidedText(params, Qt::ElideRight, widthleft); params = st::mentionFont->m.elidedText(params, Qt::ElideRight, widthleft);
} }
p.setPen(st::profileOfflineColor->p); p.setPen((selected ? st::mentionFgOver : st::mentionFg)->p);
p.drawText(htagleft + addleft, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, params); p.drawText(htagleft + addleft, i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, params);
addleft += paramswidth + st::mentionPadding.left(); addleft += paramswidth + st::mentionPadding.left();
@ -2548,7 +2549,7 @@ void MentionsInner::paintEvent(QPaintEvent *e) {
description = st::botDescFont->m.elidedText(description, Qt::ElideRight, widthleft); description = st::botDescFont->m.elidedText(description, Qt::ElideRight, widthleft);
descwidth = st::botDescFont->m.width(description); descwidth = st::botDescFont->m.width(description);
} }
p.setPen(st::profileOfflineColor->p); p.setPen((selected ? st::mentionFgOver : st::mentionFg)->p);
p.drawText(htagleft + addleft + (widthleft - descwidth), i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, description); p.drawText(htagleft + addleft + (widthleft - descwidth), i * st::mentionHeight + st::mentionTop + st::mentionFont->ascent, description);
} }
} }

View file

@ -744,7 +744,7 @@ namespace {
void TextLink::onClick(Qt::MouseButton button) const { void TextLink::onClick(Qt::MouseButton button) const {
if (button == Qt::LeftButton || button == Qt::MiddleButton) { if (button == Qt::LeftButton || button == Qt::MiddleButton) {
QString url = TextLink::encoded(); QString url = TextLink::encoded();
QRegularExpressionMatch telegramMeUser = QRegularExpression(qsl("^https?://telegram\\.me/([a-zA-Z0-9\\.\\_]+)(\\?|$)"), QRegularExpression::CaseInsensitiveOption).match(url); QRegularExpressionMatch telegramMeUser = QRegularExpression(qsl("^https?://telegram\\.me/([a-zA-Z0-9\\.\\_]+)/?(\\?|$)"), QRegularExpression::CaseInsensitiveOption).match(url);
QRegularExpressionMatch telegramMeGroup = QRegularExpression(qsl("^https?://telegram\\.me/joinchat/([a-zA-Z0-9\\.\\_\\-]+)(\\?|$)"), QRegularExpression::CaseInsensitiveOption).match(url); QRegularExpressionMatch telegramMeGroup = QRegularExpression(qsl("^https?://telegram\\.me/joinchat/([a-zA-Z0-9\\.\\_\\-]+)(\\?|$)"), QRegularExpression::CaseInsensitiveOption).match(url);
QRegularExpressionMatch telegramMeStickers = QRegularExpression(qsl("^https?://telegram\\.me/addstickers/([a-zA-Z0-9\\.\\_]+)(\\?|$)"), QRegularExpression::CaseInsensitiveOption).match(url); QRegularExpressionMatch telegramMeStickers = QRegularExpression(qsl("^https?://telegram\\.me/addstickers/([a-zA-Z0-9\\.\\_]+)(\\?|$)"), QRegularExpression::CaseInsensitiveOption).match(url);
if (telegramMeUser.hasMatch()) { if (telegramMeUser.hasMatch()) {

View file

@ -2557,6 +2557,30 @@ void HistoryWidget::calcNextReplyReturn() {
if (!_replyReturn) updateControlsVisibility(); if (!_replyReturn) updateControlsVisibility();
} }
bool HistoryWidget::kbWasHidden() {
return _kbWasHidden;
}
void HistoryWidget::setKbWasHidden() {
if (_kbWasHidden || !_keyboard.hasMarkup()) return;
_kbWasHidden = true;
if (!_showAnim.animating()) {
_kbScroll.hide();
_attachEmoji.show();
_kbHide.hide();
_kbShow.show();
}
_field.setMaxHeight(st::maxFieldHeight);
_kbShown = false;
_kbReplyTo = 0;
if (!App::main()->hasForwardingItems() && (!_previewData || _previewData->pendingTill < 0) && !_replyToId) {
_replyForwardPreviewCancel.hide();
}
resizeEvent(0);
update();
}
void HistoryWidget::showPeer(const PeerId &peer, MsgId msgId, bool force, bool leaveActive) { void HistoryWidget::showPeer(const PeerId &peer, MsgId msgId, bool force, bool leaveActive) {
if (App::main()->selectingPeer() && !force) { if (App::main()->selectingPeer() && !force) {
hiderOffered = true; hiderOffered = true;
@ -2810,6 +2834,7 @@ void HistoryWidget::updateControlsVisibility() {
if (_botStart.isHidden()) { if (_botStart.isHidden()) {
_botStart.clearState(); _botStart.clearState();
_botStart.show(); _botStart.show();
_kbShown = false;
} }
_send.hide(); _send.hide();
_field.hide(); _field.hide();
@ -3291,6 +3316,12 @@ void HistoryWidget::onBotStart() {
MTP::send(MTPmessages_StartBot(histPeer->asUser()->inputUser, MTP_int(0), MTP_long(randomId), MTP_string(token)), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::addParticipantFail, histPeer->asUser())); MTP::send(MTPmessages_StartBot(histPeer->asUser()->inputUser, MTP_int(0), MTP_long(randomId), MTP_string(token)), App::main()->rpcDone(&MainWidget::sentUpdatesReceived), App::main()->rpcFail(&MainWidget::addParticipantFail, histPeer->asUser()));
histPeer->asUser()->botInfo->startToken = QString(); histPeer->asUser()->botInfo->startToken = QString();
if (_keyboard.hasMarkup()) {
if (_keyboard.singleUse() && _keyboard.forMsgId() == hist->lastKeyboardId && hist->lastKeyboardUsed) _kbWasHidden = true;
if (!_kbWasHidden) _kbShown = true;
}
updateControlsVisibility();
resizeEvent(0);
} }
} }
@ -4325,7 +4356,7 @@ void HistoryWidget::resizeEvent(QResizeEvent *e) {
_replyForwardPreviewCancel.move(width() - _replyForwardPreviewCancel.width(), _field.y() - st::sendPadding - _replyForwardPreviewCancel.height()); _replyForwardPreviewCancel.move(width() - _replyForwardPreviewCancel.width(), _field.y() - st::sendPadding - _replyForwardPreviewCancel.height());
updateListSize(); updateListSize();
_field.resize(width() - _send.width() - _attachDocument.width() - _attachEmoji.width() - (_kbShow.isHidden() ? 0 : _kbShow.width()), _field.height()); _field.resize(width() - _send.width() - _attachDocument.width() - _attachEmoji.width() - ((_kbShown || !_keyboard.hasMarkup()) ? 0 : _kbShow.width()), _field.height());
_toHistoryEnd.move((width() - _toHistoryEnd.width()) / 2, _scroll.y() + _scroll.height() - _toHistoryEnd.height() - st::historyToEndSkip); _toHistoryEnd.move((width() - _toHistoryEnd.width()) / 2, _scroll.y() + _scroll.height() - _toHistoryEnd.height() - st::historyToEndSkip);

View file

@ -440,6 +440,9 @@ public:
void setReplyReturns(PeerId peer, const QList<MsgId> &replyReturns); void setReplyReturns(PeerId peer, const QList<MsgId> &replyReturns);
void calcNextReplyReturn(); void calcNextReplyReturn();
bool kbWasHidden();
void setKbWasHidden();
void updatePreview(); void updatePreview();
void previewCancel(); void previewCancel();

View file

@ -1902,7 +1902,7 @@ void MainWidget::showMediaOverview(PeerData *peer, MediaOverviewType type, bool
} else if (profile) { } else if (profile) {
_stack.push_back(new StackItemProfile(profile->peer(), profile->lastScrollTop(), profile->allMediaShown())); _stack.push_back(new StackItemProfile(profile->peer(), profile->lastScrollTop(), profile->allMediaShown()));
} else { } else {
_stack.push_back(new StackItemHistory(history.peer(), history.lastWidth(), history.lastScrollTop(), history.replyReturns())); _stack.push_back(new StackItemHistory(history.peer(), history.lastWidth(), history.lastScrollTop(), history.replyReturns(), history.kbWasHidden()));
} }
} }
if (overview) { if (overview) {
@ -1949,7 +1949,7 @@ void MainWidget::showPeerProfile(PeerData *peer, bool back, int32 lastScrollTop,
} else if (profile) { } else if (profile) {
_stack.push_back(new StackItemProfile(profile->peer(), profile->lastScrollTop(), profile->allMediaShown())); _stack.push_back(new StackItemProfile(profile->peer(), profile->lastScrollTop(), profile->allMediaShown()));
} else { } else {
_stack.push_back(new StackItemHistory(history.peer(), history.lastWidth(), history.lastScrollTop(), history.replyReturns())); _stack.push_back(new StackItemHistory(history.peer(), history.lastWidth(), history.lastScrollTop(), history.replyReturns(), history.kbWasHidden()));
} }
} }
if (overview) { if (overview) {
@ -1987,6 +1987,7 @@ void MainWidget::showBackFromStack() {
StackItemHistory *histItem = static_cast<StackItemHistory*>(item); StackItemHistory *histItem = static_cast<StackItemHistory*>(item);
showPeer(histItem->peer->id, App::main()->activeMsgId(), true); showPeer(histItem->peer->id, App::main()->activeMsgId(), true);
history.setReplyReturns(histItem->peer->id, histItem->replyReturns); history.setReplyReturns(histItem->peer->id, histItem->replyReturns);
if (histItem->kbWasHidden) history.setKbWasHidden();
} else if (item->type() == ProfileStackItem) { } else if (item->type() == ProfileStackItem) {
StackItemProfile *profItem = static_cast<StackItemProfile*>(item); StackItemProfile *profItem = static_cast<StackItemProfile*>(item);
showPeerProfile(profItem->peer, true, profItem->lastScrollTop, profItem->allMediaShown); showPeerProfile(profItem->peer, true, profItem->lastScrollTop, profItem->allMediaShown);
@ -2581,7 +2582,13 @@ void MainWidget::openUserByName(const QString &username, bool toProfile, const Q
showPeerProfile(user); showPeerProfile(user);
} }
} else { } else {
if (user->botInfo) user->botInfo->startToken = startToken; if (user->botInfo) {
user->botInfo->startToken = startToken;
if (user == history.peer()) {
history.updateControlsVisibility();
history.resizeEvent(0);
}
}
emit showPeerAsync(user->id, 0, false, true); emit showPeerAsync(user->id, 0, false, true);
} }
} else { } else {
@ -2617,7 +2624,13 @@ void MainWidget::usernameResolveDone(QPair<bool, QString> toProfileStartToken, c
showPeerProfile(user); showPeerProfile(user);
} }
} else { } else {
if (user->botInfo) user->botInfo->startToken = toProfileStartToken.second; if (user->botInfo) {
user->botInfo->startToken = toProfileStartToken.second;
if (user == history.peer()) {
history.updateControlsVisibility();
history.resizeEvent(0);
}
}
showPeer(user->id, 0, false, true); showPeer(user->id, 0, false, true);
} }
} }

View file

@ -110,13 +110,14 @@ public:
class StackItemHistory : public StackItem { class StackItemHistory : public StackItem {
public: public:
StackItemHistory(PeerData *peer, int32 lastWidth, int32 lastScrollTop, QList<MsgId> replyReturns) : StackItem(peer), replyReturns(replyReturns), lastWidth(lastWidth), lastScrollTop(lastScrollTop) { StackItemHistory(PeerData *peer, int32 lastWidth, int32 lastScrollTop, QList<MsgId> replyReturns, bool kbWasHidden) : StackItem(peer), replyReturns(replyReturns), lastWidth(lastWidth), lastScrollTop(lastScrollTop), kbWasHidden(kbWasHidden) {
} }
StackItemType type() const { StackItemType type() const {
return HistoryStackItem; return HistoryStackItem;
} }
QList<MsgId> replyReturns; QList<MsgId> replyReturns;
int32 lastWidth, lastScrollTop; int32 lastWidth, lastScrollTop;
bool kbWasHidden;
}; };
class StackItemProfile : public StackItem { class StackItemProfile : public StackItem {