From e693a98bd4518cec09db355fe53610d08f0e106f Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 4 Nov 2016 22:50:35 +0300 Subject: [PATCH] Passcode lock button added to DialogsWidget. --- Telegram/Resources/colors.palette | 10 +- Telegram/Resources/icons/dialogs_lock.png | Bin 0 -> 285 bytes Telegram/Resources/icons/dialogs_lock@2x.png | Bin 0 -> 408 bytes Telegram/Resources/icons/dialogs_unlock.png | Bin 0 -> 287 bytes .../Resources/icons/dialogs_unlock@2x.png | Bin 0 -> 430 bytes Telegram/Resources/sample.tdesktop-theme | 7 +- Telegram/SourceFiles/apiwrap.cpp | 4 +- Telegram/SourceFiles/app.cpp | 2 +- Telegram/SourceFiles/application.cpp | 6 +- Telegram/SourceFiles/boxes/boxes.style | 7 +- Telegram/SourceFiles/data/data_drafts.h | 4 +- Telegram/SourceFiles/dialogs/dialogs.style | 7 +- Telegram/SourceFiles/dialogswidget.cpp | 46 +- Telegram/SourceFiles/dialogswidget.h | 5 +- Telegram/SourceFiles/historywidget.cpp | 436 +++++++++--------- Telegram/SourceFiles/historywidget.h | 16 +- Telegram/SourceFiles/intro/intro.style | 24 +- Telegram/SourceFiles/intro/introcode.cpp | 179 +++---- Telegram/SourceFiles/intro/introcode.h | 46 +- Telegram/SourceFiles/intro/introphone.cpp | 174 ++++--- Telegram/SourceFiles/intro/introphone.h | 32 +- Telegram/SourceFiles/intro/intropwdcheck.cpp | 212 +++++---- Telegram/SourceFiles/intro/intropwdcheck.h | 29 +- Telegram/SourceFiles/intro/introsignup.cpp | 122 ++--- Telegram/SourceFiles/intro/introsignup.h | 26 +- Telegram/SourceFiles/intro/introstart.cpp | 24 +- Telegram/SourceFiles/intro/introstart.h | 14 +- Telegram/SourceFiles/intro/introwidget.cpp | 2 +- Telegram/SourceFiles/mainwindow.cpp | 27 +- Telegram/SourceFiles/mainwindow.h | 6 +- Telegram/SourceFiles/passcodewidget.cpp | 67 ++- Telegram/SourceFiles/passcodewidget.h | 14 +- Telegram/SourceFiles/shortcuts.cpp | 2 +- Telegram/SourceFiles/structs.h | 31 +- Telegram/SourceFiles/window/main_window.cpp | 4 +- Telegram/SourceFiles/window/window_theme.cpp | 4 +- 36 files changed, 812 insertions(+), 777 deletions(-) create mode 100644 Telegram/Resources/icons/dialogs_lock.png create mode 100644 Telegram/Resources/icons/dialogs_lock@2x.png create mode 100644 Telegram/Resources/icons/dialogs_unlock.png create mode 100644 Telegram/Resources/icons/dialogs_unlock@2x.png diff --git a/Telegram/Resources/colors.palette b/Telegram/Resources/colors.palette index da55dde33..8ed27047e 100644 --- a/Telegram/Resources/colors.palette +++ b/Telegram/Resources/colors.palette @@ -33,9 +33,6 @@ imageBg: #000000; imageBgTransparent: #ffffff; // widgets -cancelIconFg: #a2a2a2; -cancelIconFgOver: #808080; - activeButtonBg: windowActiveFill; activeButtonBgOver: #46b4eb | activeButtonBg; activeButtonFg: #ffffff; @@ -48,7 +45,9 @@ lightButtonBgOver: #f2f7fa | lightButtonBg; lightButtonFg: #2b99d5; lightButtonFgOver: lightButtonFg; -menuIconFg: #808080 | windowSubTextFg; +menuIconFg: windowSubTextFg; + +dialogsMenuIconFg: menuIconFg; // custom title bar for Windows titleBg: windowOverBg; @@ -69,6 +68,9 @@ trayCounterFgMacInvert: #ffffff01; // layers layerBg: #0000007f; +cancelIconFg: #a2a2a2; +cancelIconFgOver: #808080; + // boxes boxBg: windowBg; boxTextFg: windowTextFg; diff --git a/Telegram/Resources/icons/dialogs_lock.png b/Telegram/Resources/icons/dialogs_lock.png new file mode 100644 index 0000000000000000000000000000000000000000..5067efdfe7cca0a4774cb00b6f738847bb3f51f4 GIT binary patch literal 285 zcmV+&0pk9NP)20002wNkl?0004BNkl1Viz7k2j+X z)ibp8iSMoYIozVEJHbN+`0>93yh`z3ZB#0iz-TlA-EJ4uYBg{;9Kd`&2jlS=T(4JT z$Y>(v84V^Eiv?&j8ZY&2HXG3CbdVvVsn2Mb$zXE3-Gaej0M_d@Xf~T*I-P#15B-@j zn);0Hb~{k7*Fme*0;|>P+xm994VKF#*zfnqjec;u-9VvG0L9|3V{yOVzpW2-p)b_s zMgxz>=jD?m`K!Ln7|nymCJ!2$r>8!=8)vf_D3{AoHojagpx5i+;~n}t-pAz*XU1si-}SM`jL|%3Y<>bJQ)Hk4KC;OG000020002yNklnosap;rg8Z^x z9yP7CqN6NvX7$ZH!7_ruN@4Z*Qp{f9+lyJ^5jw8-FQc3`* z>Un6+8Gvb;HokKXfSmJrXlo4sW6Z`k#sJV-y9*tzwY!`5G|%&XP@i9NR9^#o;-H=fx~}Ufz_Kh|f3prD1WGA~ l)~S?22;unO|B3!&rmr#?0004XNklKOTpE=^lq%jr6e6C&BS~iZsX6r^start(); - } + Window::Theme::Background()->start(); connect(&_webPagesTimer, SIGNAL(timeout()), this, SLOT(resolveWebPages())); connect(&_draftsSaveTimer, SIGNAL(timeout()), this, SLOT(saveDraftsToCloud())); diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 8974fe8ba..f5cce4723 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -199,7 +199,7 @@ namespace { if (auto w = wnd()) { w->tempDirDelete(Local::ClearManagerAll); w->notifyClearFast(); - w->setupIntro(true); + w->setupIntro(); } MTP::setAuthedId(0); Local::reset(); diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index 0a50e4629..159a844b7 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -750,12 +750,12 @@ AppClass::AppClass() : QObject() { DEBUG_LOG(("Application Info: showing.")); if (state == Local::ReadMapPassNeeded) { - _window->setupPasscode(false); + _window->setupPasscode(); } else { if (MTP::authedId()) { - _window->setupMain(false); + _window->setupMain(); } else { - _window->setupIntro(false); + _window->setupIntro(); } } _window->firstShow(); diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index ac9b071f3..ff7d14d7b 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -246,13 +246,8 @@ passcodeHeaderFont: font(19px); passcodeHeaderHeight: 80px; passcodeInput: flatInput(inpIntroPhone) { } -passcodeSubmit: flatButton(introNextButton) { - textTop: 15px; - overTextTop: 15px; - downTextTop: 16px; +passcodeSubmit: RoundButton(introNextButton) { width: 225px; - font: font(19px); - overFont: font(19px); } passcodeSubmitSkip: 40px; passcodePadding: margins(0px, 22px, 0px, 3px); diff --git a/Telegram/SourceFiles/data/data_drafts.h b/Telegram/SourceFiles/data/data_drafts.h index b40aa1c51..858207248 100644 --- a/Telegram/SourceFiles/data/data_drafts.h +++ b/Telegram/SourceFiles/data/data_drafts.h @@ -35,8 +35,8 @@ struct Draft { , previewCancelled(previewCancelled) , saveRequestId(saveRequestId) { } - Draft(const FlatTextarea &field, MsgId msgId, bool previewCancelled, mtpRequestId saveRequestId = 0) - : textWithTags(field.getTextWithTags()) + Draft(const FlatTextarea *field, MsgId msgId, bool previewCancelled, mtpRequestId saveRequestId = 0) + : textWithTags(field->getTextWithTags()) , msgId(msgId) , cursor(field) , previewCancelled(previewCancelled) { diff --git a/Telegram/SourceFiles/dialogs/dialogs.style b/Telegram/SourceFiles/dialogs/dialogs.style index cf7470bef..cc84abd45 100644 --- a/Telegram/SourceFiles/dialogs/dialogs.style +++ b/Telegram/SourceFiles/dialogs/dialogs.style @@ -87,10 +87,15 @@ dialogsMenuToggle: IconButton { width: 32px; height: 32px; - icon: icon {{ "dialogs_menu", #999999 }}; + icon: icon {{ "dialogs_menu", dialogsMenuIconFg }}; iconPosition: point(6px, 6px); iconPositionDown: point(6px, 6px); } +dialogsLock: IconButton(dialogsMenuToggle) { + icon: icon {{ "dialogs_lock", dialogsMenuIconFg }}; +} +dialogsUnlockIcon: icon {{ "dialogs_unlock", dialogsMenuIconFg }}; + dialogsFilter: flatInput(inpDefGray) { font: font(fsize); bgColor: #f2f2f2; diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index c08c99a85..0342e855f 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -1028,10 +1028,6 @@ void DialogsInner::dialogsReceived(const QVector &added) { } } Notify::unreadCounterUpdated(); - if (!_sel && !shownDialogs()->isEmpty()) { - _sel = *shownDialogs()->cbegin(); - _importantSwitchSel = false; - } refresh(); } @@ -1776,6 +1772,7 @@ DialogsWidget::DialogsWidget(QWidget *parent) : TWidget(parent) , _mainMenuToggle(this, st::dialogsMenuToggle) , _filter(this, st::dialogsFilter, lang(lng_dlg_filter)) , _cancelSearch(this, st::dialogsCancelSearch) +, _lockUnlock(this, st::dialogsLock) , _scroll(this, st::dialogsScroll) , _inner(&_scroll, parent) , _a_show(animation(this, &DialogsWidget::step_show)) { @@ -1793,8 +1790,15 @@ DialogsWidget::DialogsWidget(QWidget *parent) : TWidget(parent) connect(_filter, SIGNAL(cancelled()), this, SLOT(onCancel())); connect(_filter, SIGNAL(changed()), this, SLOT(onFilterUpdate())); connect(_filter, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(onFilterCursorMoved(int,int))); - connect(_cancelSearch, SIGNAL(clicked()), this, SLOT(onCancelSearch())); + _cancelSearch->setClickedCallback([this] { onCancelSearch(); }); + _lockUnlock->setVisible(Global::LocalPasscode()); + subscribe(Global::RefLocalPasscodeChanged(), [this] { updateLockUnlockVisibility(); }); + _lockUnlock->setClickedCallback([this] { + _lockUnlock->setIcon(&st::dialogsUnlockIcon); + App::wnd()->setupPasscode(); + _lockUnlock->setIcon(nullptr); + }); _mainMenuToggle->setClickedCallback([this] { showMainMenu(); }); _chooseByDragTimer.setSingleShot(true); @@ -1851,8 +1855,10 @@ void DialogsWidget::showAnimated(Window::SlideDirection direction, const Window: _a_show.stop(); _scroll.hide(); + _mainMenuToggle->hide(); _filter->hide(); _cancelSearch->hide(); + _lockUnlock->hide(); int delta = st::slideShift; if (direction == Window::SlideDirection::FromLeft) { @@ -1880,7 +1886,9 @@ void DialogsWidget::step_show(float64 ms, bool timer) { _cacheUnder = _cacheOver = QPixmap(); _scroll.show(); + _mainMenuToggle->show(); _filter->show(); + updateLockUnlockVisibility(); _a_show.stop(); onFilterUpdate(); @@ -2440,17 +2448,15 @@ void DialogsWidget::onCompleteHashtag(QString tag) { } void DialogsWidget::resizeEvent(QResizeEvent *e) { - int32 w = width(); - _filter->setGeometryToLeft(st::dialogsFilterPadding.x() * 2 + _mainMenuToggle->width(), st::dialogsFilterPadding.y(), w - 3 * st::dialogsFilterPadding.x() - _mainMenuToggle->width(), _filter->height()); - _mainMenuToggle->moveToLeft(st::dialogsFilterPadding.x(), _filter->y()); - _cancelSearch->moveToRight(st::dialogsFilterPadding.x(), _filter->y()); + updateControlsGeometry(); + _scroll.move(0, _filter->height() + 2 * st::dialogsFilterPadding.y()); updateMainMenuGeometry(); int32 addToY = App::main() ? App::main()->contentScrollAddToY() : 0; int32 newScrollY = _scroll.scrollTop() + addToY; - _scroll.resize(w, height() - _filter->y() - _filter->height() - st::dialogsFilterPadding.y() - st::dialogsPadding.y()); + _scroll.resize(width(), height() - _filter->y() - _filter->height() - st::dialogsFilterPadding.y() - st::dialogsPadding.y()); if (addToY) { _scroll.scrollToY(newScrollY); } else { @@ -2458,6 +2464,26 @@ void DialogsWidget::resizeEvent(QResizeEvent *e) { } } +void DialogsWidget::updateLockUnlockVisibility() { + if (!_a_show.animating()) { + _lockUnlock->setVisible(Global::LocalPasscode()); + } + updateControlsGeometry(); +} + +void DialogsWidget::updateControlsGeometry() { + auto filterLeft = st::dialogsFilterPadding.x() * 2 + _mainMenuToggle->width(); + auto filterWidth = width() - 2 * st::dialogsFilterPadding.x(); + filterWidth -= st::dialogsFilterPadding.x() + _mainMenuToggle->width(); + if (Global::LocalPasscode()) { + filterWidth -= st::dialogsFilterPadding.x() + _lockUnlock->width(); + } + _filter->setGeometryToLeft(filterLeft, st::dialogsFilterPadding.y(), filterWidth, _filter->height()); + _mainMenuToggle->moveToLeft(st::dialogsFilterPadding.x(), _filter->y()); + _lockUnlock->moveToRight(st::dialogsFilterPadding.x(), _filter->y()); + _cancelSearch->moveToLeft(filterLeft + filterWidth - _cancelSearch->width(), _filter->y()); +} + void DialogsWidget::updateMainMenuGeometry() { if (!_mainMenu) return; diff --git a/Telegram/SourceFiles/dialogswidget.h b/Telegram/SourceFiles/dialogswidget.h index 68a5a2b30..7778e6ab0 100644 --- a/Telegram/SourceFiles/dialogswidget.h +++ b/Telegram/SourceFiles/dialogswidget.h @@ -233,7 +233,7 @@ private: }; -class DialogsWidget : public TWidget, public RPCSender { +class DialogsWidget : public TWidget, public RPCSender, private base::Subscriber { Q_OBJECT public: @@ -315,6 +315,8 @@ public slots: private: void showMainMenu(); + void updateLockUnlockVisibility(); + void updateControlsGeometry(); void updateMainMenuGeometry(); bool _dragInScroll = false; @@ -338,6 +340,7 @@ private: ChildWidget _mainMenu = { nullptr }; ChildWidget _filter; ChildWidget _cancelSearch; + ChildWidget _lockUnlock; ScrollArea _scroll; DialogsInner _inner; diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index b28f1914f..6768ad035 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -2380,41 +2380,41 @@ ReportSpamPanel::ReportSpamPanel(HistoryWidget *parent) : TWidget(parent), _report(this, lang(lng_report_spam), st::reportSpamHide), _hide(this, lang(lng_report_spam_hide), st::reportSpamHide), _clear(this, lang(lng_profile_delete_conversation)) { - resize(parent->width(), _hide.height() + st::lineWidth); + resize(parent->width(), _hide->height() + st::lineWidth); - connect(&_report, SIGNAL(clicked()), this, SIGNAL(reportClicked())); - connect(&_hide, SIGNAL(clicked()), this, SIGNAL(hideClicked())); - connect(&_clear, SIGNAL(clicked()), this, SIGNAL(clearClicked())); + connect(_report, SIGNAL(clicked()), this, SIGNAL(reportClicked())); + connect(_hide, SIGNAL(clicked()), this, SIGNAL(hideClicked())); + connect(_clear, SIGNAL(clicked()), this, SIGNAL(clearClicked())); - _clear.hide(); + _clear->hide(); } void ReportSpamPanel::resizeEvent(QResizeEvent *e) { - _report.resize(width() - (_hide.width() + st::reportSpamSeparator) * 2, _report.height()); - _report.moveToLeft(_hide.width() + st::reportSpamSeparator, 0); - _hide.moveToRight(0, 0); - _clear.move((width() - _clear.width()) / 2, height() - _clear.height() - ((height() - st::msgFont->height - _clear.height()) / 2)); + _report->resize(width() - (_hide->width() + st::reportSpamSeparator) * 2, _report->height()); + _report->moveToLeft(_hide->width() + st::reportSpamSeparator, 0); + _hide->moveToRight(0, 0); + _clear->move((width() - _clear->width()) / 2, height() - _clear->height() - ((height() - st::msgFont->height - _clear->height()) / 2)); } void ReportSpamPanel::paintEvent(QPaintEvent *e) { Painter p(this); p.fillRect(QRect(0, 0, width(), height() - st::lineWidth), st::reportSpamBg); p.fillRect(Adaptive::OneColumn() ? 0 : st::lineWidth, height() - st::lineWidth, width() - (Adaptive::OneColumn() ? 0 : st::lineWidth), st::lineWidth, st::shadowColor->b); - if (!_clear.isHidden()) { + if (!_clear->isHidden()) { p.setPen(st::reportSpamFg); p.setFont(st::msgFont); - p.drawText(QRect(_report.x(), (_clear.y() - st::msgFont->height) / 2, _report.width(), st::msgFont->height), lang(lng_report_spam_thanks), style::al_top); + p.drawText(QRect(_report->x(), (_clear->y() - st::msgFont->height) / 2, _report->width(), st::msgFont->height), lang(lng_report_spam_thanks), style::al_top); } } void ReportSpamPanel::setReported(bool reported, PeerData *onPeer) { if (reported) { - _report.hide(); - _clear.setText(lang(onPeer->isChannel() ? (onPeer->isMegagroup() ? lng_profile_leave_group : lng_profile_leave_channel) : lng_profile_delete_conversation)); - _clear.show(); + _report->hide(); + _clear->setText(lang(onPeer->isChannel() ? (onPeer->isMegagroup() ? lng_profile_leave_group : lng_profile_leave_channel) : lng_profile_delete_conversation)); + _clear->show(); } else { - _report.show(); - _clear.hide(); + _report->show(); + _clear->hide(); } update(); } @@ -2699,8 +2699,8 @@ HistoryHider::HistoryHider(MainWidget *parent, const QString &url, const QString } void HistoryHider::init() { - connect(&_send, SIGNAL(clicked()), this, SLOT(forward())); - connect(&_cancel, SIGNAL(clicked()), this, SLOT(startHide())); + connect(_send, SIGNAL(clicked()), this, SLOT(forward())); + connect(_cancel, SIGNAL(clicked()), this, SLOT(startHide())); _chooseWidth = st::forwardFont->width(lang(_botAndQuery.isEmpty() ? lng_forward_choose : lng_inline_switch_choose)); @@ -2788,8 +2788,8 @@ void HistoryHider::startHide() { if (_offered) _cacheForAnim = myGrab(this, _box); if (_forwardRequest) MTP::cancel(_forwardRequest); a_opacity.start(0); - _send.hide(); - _cancel.hide(); + _send->hide(); + _cancel->hide(); _a_appearance.start(); } } @@ -2824,18 +2824,18 @@ void HistoryHider::resizeEvent(QResizeEvent *e) { int32 w = st::boxWidth, h = st::boxPadding.top() + st::boxPadding.bottom(); if (_offered) { if (!_hiding) { - _send.show(); - _cancel.show(); + _send->show(); + _cancel->show(); } - h += st::boxTextFont->height + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom(); + h += st::boxTextFont->height + st::boxButtonPadding.top() + _send->height() + st::boxButtonPadding.bottom(); } else { h += st::forwardFont->height; - _send.hide(); - _cancel.hide(); + _send->hide(); + _cancel->hide(); } _box = QRect((width() - w) / 2, (height() - h) / 2, w, h); - _send.moveToRight(width() - (_box.x() + _box.width()) + st::boxButtonPadding.right(), _box.y() + h - st::boxButtonPadding.bottom() - _send.height()); - _cancel.moveToRight(width() - (_box.x() + _box.width()) + st::boxButtonPadding.right() + _send.width() + st::boxButtonPadding.left(), _send.y()); + _send->moveToRight(width() - (_box.x() + _box.width()) + st::boxButtonPadding.right(), _box.y() + h - st::boxButtonPadding.bottom() - _send->height()); + _cancel->moveToRight(width() - (_box.x() + _box.width()) + st::boxButtonPadding.right() + _send->width() + st::boxButtonPadding.left(), _send->y()); } bool HistoryHider::offerPeer(PeerId peer) { @@ -3030,25 +3030,25 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent) connect(&_reportSpamPanel, SIGNAL(clearClicked()), this, SLOT(onReportSpamClear())); connect(_historyToEnd, SIGNAL(clicked()), this, SLOT(onHistoryToEnd())); connect(_fieldBarCancel, SIGNAL(clicked()), this, SLOT(onFieldBarCancel())); - connect(&_send, SIGNAL(clicked()), this, SLOT(onSend())); - connect(&_unblock, SIGNAL(clicked()), this, SLOT(onUnblock())); - connect(&_botStart, SIGNAL(clicked()), this, SLOT(onBotStart())); - connect(&_joinChannel, SIGNAL(clicked()), this, SLOT(onJoinChannel())); - connect(&_muteUnmute, SIGNAL(clicked()), this, SLOT(onMuteUnmute())); + connect(_send, SIGNAL(clicked()), this, SLOT(onSend())); + connect(_unblock, SIGNAL(clicked()), this, SLOT(onUnblock())); + connect(_botStart, SIGNAL(clicked()), this, SLOT(onBotStart())); + connect(_joinChannel, SIGNAL(clicked()), this, SLOT(onJoinChannel())); + connect(_muteUnmute, SIGNAL(clicked()), this, SLOT(onMuteUnmute())); connect(_silent, SIGNAL(clicked()), this, SLOT(onBroadcastSilentChange())); connect(_attachDocument, SIGNAL(clicked()), this, SLOT(onDocumentSelect())); connect(_attachPhoto, SIGNAL(clicked()), this, SLOT(onPhotoSelect())); - connect(&_field, SIGNAL(submitted(bool)), this, SLOT(onSend(bool))); - connect(&_field, SIGNAL(cancelled()), this, SLOT(onCancel())); - connect(&_field, SIGNAL(tabbed()), this, SLOT(onFieldTabbed())); - connect(&_field, SIGNAL(resized()), this, SLOT(onFieldResize())); - connect(&_field, SIGNAL(focused()), this, SLOT(onFieldFocused())); - connect(&_field, SIGNAL(changed()), this, SLOT(onTextChange())); - connect(&_field, SIGNAL(spacedReturnedPasted()), this, SLOT(onPreviewParse())); - connect(&_field, SIGNAL(linksChanged()), this, SLOT(onPreviewCheck())); + connect(_field, SIGNAL(submitted(bool)), this, SLOT(onSend(bool))); + connect(_field, SIGNAL(cancelled()), this, SLOT(onCancel())); + connect(_field, SIGNAL(tabbed()), this, SLOT(onFieldTabbed())); + connect(_field, SIGNAL(resized()), this, SLOT(onFieldResize())); + connect(_field, SIGNAL(focused()), this, SLOT(onFieldFocused())); + connect(_field, SIGNAL(changed()), this, SLOT(onTextChange())); + connect(_field, SIGNAL(spacedReturnedPasted()), this, SLOT(onPreviewParse())); + connect(_field, SIGNAL(linksChanged()), this, SLOT(onPreviewCheck())); connect(App::wnd()->windowHandle(), SIGNAL(visibleChanged(bool)), this, SLOT(onWindowVisibleChanged())); connect(&_scrollTimer, SIGNAL(timeout()), this, SLOT(onScrollTimer())); - connect(_emojiPan, SIGNAL(emojiSelected(EmojiPtr)), &_field, SLOT(onEmojiInsert(EmojiPtr))); + connect(_emojiPan, SIGNAL(emojiSelected(EmojiPtr)), _field, SLOT(onEmojiInsert(EmojiPtr))); connect(_emojiPan, SIGNAL(stickerSelected(DocumentData*)), this, SLOT(onStickerSend(DocumentData*))); connect(_emojiPan, SIGNAL(photoSelected(PhotoData*)), this, SLOT(onPhotoSend(PhotoData*))); connect(_emojiPan, SIGNAL(inlineResultSelected(InlineBots::Result*,UserData*)), this, SLOT(onInlineResultSend(InlineBots::Result*,UserData*))); @@ -3078,9 +3078,9 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent) connect(&_saveDraftTimer, SIGNAL(timeout()), this, SLOT(onDraftSave())); _saveCloudDraftTimer.setSingleShot(true); connect(&_saveCloudDraftTimer, SIGNAL(timeout()), this, SLOT(onCloudDraftSave())); - connect(_field.verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(onDraftSaveDelayed())); - connect(&_field, SIGNAL(cursorPositionChanged()), this, SLOT(onDraftSaveDelayed())); - connect(&_field, SIGNAL(cursorPositionChanged()), this, SLOT(onCheckFieldAutocomplete()), Qt::QueuedConnection); + connect(_field->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(onDraftSaveDelayed())); + connect(_field, SIGNAL(cursorPositionChanged()), this, SLOT(onDraftSaveDelayed())); + connect(_field, SIGNAL(cursorPositionChanged()), this, SLOT(onCheckFieldAutocomplete()), Qt::QueuedConnection); _fieldBarCancel->hide(); @@ -3101,16 +3101,16 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent) connect(_fieldAutocomplete, SIGNAL(botCommandChosen(QString,FieldAutocomplete::ChooseMethod)), this, SLOT(onHashtagOrBotCommandInsert(QString,FieldAutocomplete::ChooseMethod))); connect(_fieldAutocomplete, SIGNAL(stickerChosen(DocumentData*,FieldAutocomplete::ChooseMethod)), this, SLOT(onStickerSend(DocumentData*))); connect(_fieldAutocomplete, SIGNAL(moderateKeyActivate(int,bool*)), this, SLOT(onModerateKeyActivate(int,bool*))); - _field.installEventFilter(_fieldAutocomplete); - _field.setTagMimeProcessor(std_::make_unique()); + _field->installEventFilter(_fieldAutocomplete); + _field->setTagMimeProcessor(std_::make_unique()); updateFieldSubmitSettings(); - _field.hide(); - _send.hide(); - _unblock.hide(); - _botStart.hide(); - _joinChannel.hide(); - _muteUnmute.hide(); + _field->hide(); + _send->hide(); + _unblock->hide(); + _botStart->hide(); + _joinChannel->hide(); + _muteUnmute->hide(); _reportSpamPanel.move(0, 0); _reportSpamPanel.hide(); @@ -3177,23 +3177,23 @@ void HistoryWidget::onMentionInsert(UserData *user) { } else { replacement = '@' + user->username; } - _field.insertTag(replacement, entityTag); + _field->insertTag(replacement, entityTag); } void HistoryWidget::onHashtagOrBotCommandInsert(QString str, FieldAutocomplete::ChooseMethod method) { // Send bot command at once, if it was not inserted by pressing Tab. if (str.at(0) == '/' && method != FieldAutocomplete::ChooseMethod::ByTab) { App::sendBotCommand(_peer, nullptr, str); - setFieldText(_field.getTextWithTagsPart(_field.textCursor().position())); + setFieldText(_field->getTextWithTagsPart(_field->textCursor().position())); } else { - _field.insertTag(str); + _field->insertTag(str); } } void HistoryWidget::updateInlineBotQuery() { UserData *bot = nullptr; QString inlineBotUsername; - QString query = _field.getInlineBotQuery(&bot, &inlineBotUsername); + QString query = _field->getInlineBotQuery(&bot, &inlineBotUsername); if (inlineBotUsername != _inlineBotUsername) { _inlineBotUsername = inlineBotUsername; if (_inlineBotResolveRequestId) { @@ -3239,7 +3239,7 @@ void HistoryWidget::applyInlineBotQuery(UserData *bot, const QString &query) { void HistoryWidget::updateStickersByEmoji() { int len = 0; if (!_editMsgId) { - auto &text = _field.getTextWithTags().text; + auto &text = _field->getTextWithTags().text; if (auto emoji = emojiFromText(text, &len)) { if (text.size() > len) { len = 0; @@ -3264,13 +3264,13 @@ void HistoryWidget::onTextChange() { } if (cHasAudioCapture()) { - if (!_field.hasSendText() && !readyToForward() && !_editMsgId) { + if (!_field->hasSendText() && !readyToForward() && !_editMsgId) { _previewCancelled = false; - _send.hide(); + _send->hide(); updateMouseTracking(); mouseMoveEvent(0); - } else if (!_field.isHidden() && _send.isHidden()) { - _send.show(); + } else if (!_field->isHidden() && _send->isHidden()) { + _send->show(); updateMouseTracking(); _a_record.stop(); _inRecord = _inField = false; @@ -3292,7 +3292,7 @@ void HistoryWidget::onTextChange() { void HistoryWidget::onDraftSaveDelayed() { if (!_peer || !(_textUpdateEvents.testFlag(TextUpdateEvent::SaveDraft))) return; - if (!_field.textCursor().anchor() && !_field.textCursor().position() && !_field.verticalScrollBar()->value()) { + if (!_field->textCursor().anchor() && !_field->textCursor().position() && !_field->verticalScrollBar()->value()) { if (!Local::hasDraftCursors(_peer->id)) { return; } @@ -3320,7 +3320,7 @@ void HistoryWidget::saveFieldToHistoryLocalDraft() { if (_editMsgId) { _history->setEditDraft(std_::make_unique(_field, _editMsgId, _previewCancelled, _saveEditMsgRequestId)); } else { - if (_replyToId || !_field.isEmpty()) { + if (_replyToId || !_field->isEmpty()) { _history->setLocalDraft(std_::make_unique(_field, _replyToId, _previewCancelled)); } else { _history->clearLocalDraft(); @@ -3350,14 +3350,14 @@ void HistoryWidget::writeDrafts(Data::Draft **localDraft, Data::Draft **editDraf storedLocalDraft = Local::MessageDraft((*localDraft)->msgId, (*localDraft)->textWithTags, (*localDraft)->previewCancelled); } } else { - storedLocalDraft = Local::MessageDraft(_replyToId, _field.getTextWithTags(), _previewCancelled); + storedLocalDraft = Local::MessageDraft(_replyToId, _field->getTextWithTags(), _previewCancelled); } if (editDraft) { if (*editDraft) { storedEditDraft = Local::MessageDraft((*editDraft)->msgId, (*editDraft)->textWithTags, (*editDraft)->previewCancelled); } } else if (_editMsgId) { - storedEditDraft = Local::MessageDraft(_editMsgId, _field.getTextWithTags(), _previewCancelled); + storedEditDraft = Local::MessageDraft(_editMsgId, _field->getTextWithTags(), _previewCancelled); } Local::writeDrafts(_peer->id, storedLocalDraft, storedEditDraft); if (_migrated) { @@ -3480,7 +3480,7 @@ void HistoryWidget::setInnerFocus() { if (_selCount || (_list && _list->wasSelectedText()) || _recording || isBotStart() || isBlocked() || !_canSendMessages) { _list->setFocus(); } else { - _field.setFocus(); + _field->setFocus(); } } } @@ -4084,7 +4084,7 @@ void HistoryWidget::applyDraft(bool parseLinks) { auto draft = _history ? _history->draft() : nullptr; if (!draft || !canWriteMessage()) { clearFieldText(); - _field.setFocus(); + _field->setFocus(); _replyEditMsg = nullptr; _editMsgId = _replyToId = 0; return; @@ -4092,7 +4092,7 @@ void HistoryWidget::applyDraft(bool parseLinks) { _textUpdateEvents = 0; setFieldText(draft->textWithTags); - _field.setFocus(); + _field->setFocus(); draft->cursor.applyTo(_field); _textUpdateEvents = TextUpdateEvent::SaveDraft | TextUpdateEvent::SendTyping; _previewCancelled = draft->previewCancelled; @@ -4226,7 +4226,7 @@ void HistoryWidget::showHistory(const PeerId &peerId, MsgId showAtMsgId, bool re _canSendMessages = canSendMessages(_peer); if (_peer && _peer->isChannel()) { _peer->asChannel()->updateFull(); - _joinChannel.setText(lang(_peer->isMegagroup() ? lng_group_invite_join : lng_channel_join)); + _joinChannel->setText(lang(_peer->isMegagroup() ? lng_group_invite_join : lng_channel_join)); } _unblockRequest = _reportSpamRequest = 0; @@ -4360,13 +4360,13 @@ void HistoryWidget::updateFieldSubmitSettings() { } else if (cCtrlEnter()) { settings = FlatTextarea::SubmitSettings::CtrlEnter; } - _field.setSubmitSettings(settings); + _field->setSubmitSettings(settings); } void HistoryWidget::updateNotifySettings() { if (!_peer || !_peer->isChannel()) return; - _muteUnmute.setText(lang(_history->mute() ? lng_channel_unmute : lng_channel_mute)); + _muteUnmute->setText(lang(_history->mute() ? lng_channel_unmute : lng_channel_mute)); if (_peer->notify != UnknownNotifySettings) { _silent->setChecked(_peer->notify != EmptyNotifySettings && (_peer->notify->flags & MTPDpeerNotifySettings::Flag::f_silent)); if (_silent->isHidden() && hasSilentToggle()) { @@ -4496,14 +4496,14 @@ void HistoryWidget::updateControlsVisibility() { _reportSpamPanel.hide(); _scroll.hide(); _kbScroll.hide(); - _send.hide(); + _send->hide(); if (_inlineBotCancel) _inlineBotCancel->hide(); - _unblock.hide(); - _botStart.hide(); - _joinChannel.hide(); - _muteUnmute.hide(); + _unblock->hide(); + _botStart->hide(); + _joinChannel->hide(); + _muteUnmute->hide(); _fieldAutocomplete->hide(); - _field.hide(); + _field->hide(); _fieldBarCancel->hide(); _attachDocument->hide(); _attachPhoto->hide(); @@ -4538,32 +4538,32 @@ void HistoryWidget::updateControlsVisibility() { } if (isBlocked() || isJoinChannel() || isMuteUnmute()) { if (isBlocked()) { - _joinChannel.hide(); - _muteUnmute.hide(); - if (_unblock.isHidden()) { - _unblock.clearState(); - _unblock.show(); + _joinChannel->hide(); + _muteUnmute->hide(); + if (_unblock->isHidden()) { + _unblock->clearState(); + _unblock->show(); } } else if (isJoinChannel()) { - _unblock.hide(); - _muteUnmute.hide(); - if (_joinChannel.isHidden()) { - _joinChannel.clearState(); - _joinChannel.show(); + _unblock->hide(); + _muteUnmute->hide(); + if (_joinChannel->isHidden()) { + _joinChannel->clearState(); + _joinChannel->show(); } } else if (isMuteUnmute()) { - _unblock.hide(); - _joinChannel.hide(); - if (_muteUnmute.isHidden()) { - _muteUnmute.clearState(); - _muteUnmute.show(); + _unblock->hide(); + _joinChannel->hide(); + if (_muteUnmute->isHidden()) { + _muteUnmute->clearState(); + _muteUnmute->show(); } } _kbShown = false; _fieldAutocomplete->hide(); - _send.hide(); + _send->hide(); if (_inlineBotCancel) _inlineBotCancel->hide(); - _botStart.hide(); + _botStart->hide(); _attachDocument->hide(); _attachPhoto->hide(); _silent->hide(); @@ -4577,25 +4577,25 @@ void HistoryWidget::updateControlsVisibility() { _botCommandStart->hide(); _attachType->hide(); _emojiPan->hide(); - if (!_field.isHidden()) { - _field.hide(); + if (!_field->isHidden()) { + _field->hide(); resizeEvent(0); update(); } } else if (_canSendMessages) { onCheckFieldAutocomplete(); if (isBotStart()) { - _unblock.hide(); - _joinChannel.hide(); - _muteUnmute.hide(); - if (_botStart.isHidden()) { - _botStart.clearState(); - _botStart.show(); + _unblock->hide(); + _joinChannel->hide(); + _muteUnmute->hide(); + if (_botStart->isHidden()) { + _botStart->clearState(); + _botStart->show(); } _kbShown = false; - _send.hide(); + _send->hide(); if (_inlineBotCancel) _inlineBotCancel->hide(); - _field.hide(); + _field->hide(); _attachEmoji->hide(); _botKeyboardShow->hide(); _botKeyboardHide->hide(); @@ -4606,25 +4606,25 @@ void HistoryWidget::updateControlsVisibility() { _kbScroll.hide(); _fieldBarCancel->hide(); } else { - _unblock.hide(); - _botStart.hide(); - _joinChannel.hide(); - _muteUnmute.hide(); - if (cHasAudioCapture() && !_field.hasSendText() && !readyToForward()) { - _send.hide(); + _unblock->hide(); + _botStart->hide(); + _joinChannel->hide(); + _muteUnmute->hide(); + if (cHasAudioCapture() && !_field->hasSendText() && !readyToForward()) { + _send->hide(); mouseMoveEvent(0); } else { if (_inlineBotCancel) { _inlineBotCancel->show(); - _send.hide(); + _send->hide(); } else { - _send.show(); + _send->show(); } _a_record.stop(); _inRecord = _inField = false; } if (_recording) { - _field.hide(); + _field->hide(); _attachEmoji->hide(); _botKeyboardShow->hide(); _botKeyboardHide->hide(); @@ -4638,7 +4638,7 @@ void HistoryWidget::updateControlsVisibility() { _kbScroll.hide(); } } else { - _field.show(); + _field->show(); if (_kbShown) { _kbScroll.show(); _attachEmoji->hide(); @@ -4693,12 +4693,12 @@ void HistoryWidget::updateControlsVisibility() { } } else { _fieldAutocomplete->hide(); - _send.hide(); + _send->hide(); if (_inlineBotCancel) _inlineBotCancel->hide(); - _unblock.hide(); - _botStart.hide(); - _joinChannel.hide(); - _muteUnmute.hide(); + _unblock->hide(); + _botStart->hide(); + _joinChannel->hide(); + _muteUnmute->hide(); _attachDocument->hide(); _attachPhoto->hide(); _silent->hide(); @@ -4713,8 +4713,8 @@ void HistoryWidget::updateControlsVisibility() { _attachType->hide(); _emojiPan->hide(); _kbScroll.hide(); - if (!_field.isHidden()) { - _field.hide(); + if (!_field->isHidden()) { + _field->hide(); resizeEvent(0); update(); } @@ -4723,7 +4723,7 @@ void HistoryWidget::updateControlsVisibility() { } void HistoryWidget::updateMouseTracking() { - bool trackMouse = !_fieldBarCancel->isHidden() || _pinnedBar || (cHasAudioCapture() && _send.isHidden() && !_field.isHidden()); + bool trackMouse = !_fieldBarCancel->isHidden() || _pinnedBar || (cHasAudioCapture() && _send->isHidden() && !_field->isHidden()); setMouseTracking(trackMouse); } @@ -5132,7 +5132,7 @@ void HistoryWidget::preloadHistoryIfNeeded() { } void HistoryWidget::onInlineBotCancel() { - auto &textWithTags = _field.getTextWithTags(); + auto &textWithTags = _field->getTextWithTags(); if (textWithTags.text.size() > _inlineBotUsername.size() + 2) { setFieldText({ '@' + _inlineBotUsername + ' ', TextWithTags::Tags() }, TextUpdateEvent::SaveDraft, FlatTextarea::AddToUndoHistory); } else { @@ -5159,14 +5159,14 @@ void HistoryWidget::saveEditMsg() { WebPageId webPageId = _previewCancelled ? CancelledWebPageId : ((_previewData && _previewData->pendingTill >= 0) ? _previewData->id : 0); - auto &textWithTags = _field.getTextWithTags(); + auto &textWithTags = _field->getTextWithTags(); auto prepareFlags = itemTextOptions(_history, App::self()).flags; EntitiesInText sendingEntities, leftEntities = entitiesFromTextTags(textWithTags.tags); QString sendingText, leftText = prepareTextWithEntities(textWithTags.text, prepareFlags, &leftEntities); if (!textSplit(sendingText, sendingEntities, leftText, leftEntities, MaxMessageSize)) { - _field.selectAll(); - _field.setFocus(); + _field->selectAll(); + _field->setFocus(); return; } else if (!leftText.isEmpty()) { Ui::showLayer(new InformBox(lang(lng_edit_too_long))); @@ -5217,8 +5217,8 @@ bool HistoryWidget::saveEditMsgFail(History *history, const RPCError &error, mtp } else if (err == qstr("MESSAGE_NOT_MODIFIED")) { cancelEdit(); } else if (err == qstr("MESSAGE_EMPTY")) { - _field.selectAll(); - _field.setFocus(); + _field->selectAll(); + _field->setFocus(); } else { Ui::showLayer(new InformBox(lang(lng_edit_error))); } @@ -5246,7 +5246,7 @@ void HistoryWidget::onSend(bool ctrlShiftEnter, MsgId replyTo) { MainWidget::MessageToSend message; message.history = _history; - message.textWithTags = _field.getTextWithTags(); + message.textWithTags = _field->getTextWithTags(); message.replyTo = replyTo; message.silent = _silent->checked(); message.webPageId = webPageId; @@ -5261,7 +5261,7 @@ void HistoryWidget::onSend(bool ctrlShiftEnter, MsgId replyTo) { if (replyTo < 0) cancelReply(lastKeyboardUsed); if (_previewData && _previewData->pendingTill) previewCancel(); - _field.setFocus(); + _field->setFocus(); if (!_keyboard.hasMarkup() && _keyboard.forceReply() && !_kbReplyTo) onKbToggle(); } @@ -5467,14 +5467,14 @@ void HistoryWidget::showAnimated(Window::SlideDirection direction, const Window: _botKeyboardShow->hide(); _botKeyboardHide->hide(); _botCommandStart->hide(); - _field.hide(); + _field->hide(); _fieldBarCancel->hide(); - _send.hide(); + _send->hide(); if (_inlineBotCancel) _inlineBotCancel->hide(); - _unblock.hide(); - _botStart.hide(); - _joinChannel.hide(); - _muteUnmute.hide(); + _unblock->hide(); + _botStart->hide(); + _joinChannel->hide(); + _muteUnmute->hide(); if (_pinnedBar) { _pinnedBar->shadow->hide(); _pinnedBar->cancel->hide(); @@ -5549,7 +5549,7 @@ void HistoryWidget::animStop() { void HistoryWidget::step_record(float64 ms, bool timer) { float64 dt = ms / st::btnSend.duration; - if (dt >= 1 || !_send.isHidden() || isBotStart() || isBlocked()) { + if (dt >= 1 || !_send->isHidden() || isBotStart() || isBlocked()) { _a_record.stop(); a_recordDown.finish(); a_recordCancel.finish(); @@ -5561,7 +5561,7 @@ void HistoryWidget::step_record(float64 ms, bool timer) { if (_recording) { updateField(); } else { - update(_send.geometry()); + update(_send->geometry()); } } } @@ -5664,13 +5664,13 @@ void HistoryWidget::leaveEvent(QEvent *e) { void HistoryWidget::mouseMoveEvent(QMouseEvent *e) { QPoint pos(e ? e->pos() : mapFromGlobal(QCursor::pos())); - bool inRecord = _send.geometry().contains(pos); + bool inRecord = _send->geometry().contains(pos); bool inField = pos.y() >= (_scroll.y() + _scroll.height()) && pos.y() < height() && pos.x() >= 0 && pos.x() < width(); - bool inReplyEdit = QRect(st::historyReplySkip, _field.y() - st::sendPadding - st::historyReplyHeight, width() - st::historyReplySkip - _fieldBarCancel->width(), st::historyReplyHeight).contains(pos) && (_editMsgId || replyToId()); + bool inReplyEdit = QRect(st::historyReplySkip, _field->y() - st::sendPadding - st::historyReplyHeight, width() - st::historyReplySkip - _fieldBarCancel->width(), st::historyReplyHeight).contains(pos) && (_editMsgId || replyToId()); bool inPinnedMsg = QRect(0, 0, width(), st::historyReplyHeight).contains(pos) && _pinnedBar; if (inRecord != _inRecord) { _inRecord = inRecord; - update(_send.geometry()); + update(_send->geometry()); } if (inField != _inField && _recording) { _inField = inField; @@ -5695,7 +5695,7 @@ void HistoryWidget::leaveToChildEvent(QEvent *e, QWidget *child) { // e -- from void HistoryWidget::mouseReleaseEvent(QMouseEvent *e) { if (_replyForwardPressed) { _replyForwardPressed = false; - update(0, _field.y() - st::sendPadding - st::historyReplyHeight, width(), st::historyReplyHeight); + update(0, _field->y() - st::sendPadding - st::historyReplyHeight, width(), st::historyReplyHeight); } if (_attachDrag != DragStateNone || !_attachDragPhoto->isHidden() || !_attachDragDocument->isHidden()) { _attachDrag = DragStateNone; @@ -5760,7 +5760,7 @@ void HistoryWidget::sendBotCommand(PeerData *peer, UserData *bot, const QString } } - _field.setFocus(); + _field->setFocus(); } void HistoryWidget::app_sendBotCallback(const HistoryMessageReplyMarkup::Button *button, const HistoryItem *msg, int row, int col) { @@ -5863,7 +5863,7 @@ bool HistoryWidget::insertBotCommand(const QString &cmd, bool specialGif) { toInsert += ' '; if (!insertingInlineBot) { - auto &textWithTags = _field.getTextWithTags(); + auto &textWithTags = _field->getTextWithTags(); if (specialGif) { if (textWithTags.text.trimmed() == '@' + cInlineGifBotUsername() && textWithTags.text.at(0) == '@') { clearFieldText(TextUpdateEvent::SaveDraft, FlatTextarea::AddToUndoHistory); @@ -5872,7 +5872,7 @@ bool HistoryWidget::insertBotCommand(const QString &cmd, bool specialGif) { TextWithTags textWithTagsToSet; QRegularExpressionMatch m = QRegularExpression(qsl("^/[A-Za-z_0-9]{0,64}(@[A-Za-z_0-9]{0,32})?(\\s|$)")).match(textWithTags.text); if (m.hasMatch()) { - textWithTagsToSet = _field.getTextWithTagsPart(m.capturedLength()); + textWithTagsToSet = _field->getTextWithTagsPart(m.capturedLength()); } else { textWithTagsToSet = textWithTags; } @@ -5880,16 +5880,16 @@ bool HistoryWidget::insertBotCommand(const QString &cmd, bool specialGif) { for (auto &tag : textWithTagsToSet.tags) { tag.offset += toInsert.size(); } - _field.setTextWithTags(textWithTagsToSet); + _field->setTextWithTags(textWithTagsToSet); - QTextCursor cur(_field.textCursor()); + QTextCursor cur(_field->textCursor()); cur.movePosition(QTextCursor::End); - _field.setTextCursor(cur); + _field->setTextCursor(cur); } } else { - if (!specialGif || _field.isEmpty()) { + if (!specialGif || _field->isEmpty()) { setFieldText({ toInsert, TextWithTags::Tags() }, TextUpdateEvent::SaveDraft, FlatTextarea::AddToUndoHistory); - _field.setFocus(); + _field->setFocus(); return true; } } @@ -5953,7 +5953,7 @@ DragState HistoryWidget::getDragState(const QMimeData *d) { } void HistoryWidget::updateDragAreas() { - _field.setAcceptDrops(!_attachDrag); + _field->setAcceptDrops(!_attachDrag); switch (_attachDrag) { case DragStateNone: _attachDragDocument->otherLeave(); @@ -6008,7 +6008,7 @@ void HistoryWidget::inlineBotResolveDone(const MTPcontacts_ResolvedPeer &result) UserData *bot = nullptr; QString inlineBotUsername; - auto query = _field.getInlineBotQuery(&bot, &inlineBotUsername); + auto query = _field->getInlineBotQuery(&bot, &inlineBotUsername); if (inlineBotUsername == _inlineBotUsername) { if (bot == LookingUpInlineBot) { bot = resolvedBot; @@ -6055,7 +6055,7 @@ bool HistoryWidget::updateCmdStartShown() { bool cmdStartShown = false; if (_history && _peer && ((_peer->isChat() && _peer->asChat()->botStatus > 0) || (_peer->isMegagroup() && _peer->asChannel()->mgInfo->botStatus > 0) || (_peer->isUser() && _peer->asUser()->botInfo))) { if (!isBotStart() && !isBlocked() && !_keyboard.hasMarkup() && !_keyboard.forceReply()) { - if (!_field.hasSendText()) { + if (!_field->hasSendText()) { cmdStartShown = true; } } @@ -6141,7 +6141,7 @@ void HistoryWidget::onKbToggle(bool manual) { _kbScroll.hide(); _kbShown = false; - _field.setMaxHeight(st::historyComposeFieldMaxHeight); + _field->setMaxHeight(st::historyComposeFieldMaxHeight); _kbReplyTo = 0; if (!readyToForward() && (!_previewData || _previewData->pendingTill < 0) && !_editMsgId && !_replyToId) { @@ -6164,7 +6164,7 @@ void HistoryWidget::onKbToggle(bool manual) { _kbScroll.hide(); _kbShown = false; - _field.setMaxHeight(st::historyComposeFieldMaxHeight); + _field->setMaxHeight(st::historyComposeFieldMaxHeight); _kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard.forceReply()) ? App::histItemById(_keyboard.forMsgId()) : 0; if (_kbReplyTo && !_editMsgId && !_replyToId && fieldEnabled) { @@ -6183,7 +6183,7 @@ void HistoryWidget::onKbToggle(bool manual) { _kbShown = true; int32 maxh = qMin(_keyboard.height(), st::historyComposeFieldMaxHeight - (st::historyComposeFieldMaxHeight / 2)); - _field.setMaxHeight(st::historyComposeFieldMaxHeight - maxh); + _field->setMaxHeight(st::historyComposeFieldMaxHeight - maxh); _kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard.forceReply()) ? App::histItemById(_keyboard.forMsgId()) : 0; if (_kbReplyTo && !_editMsgId && !_replyToId) { @@ -6426,7 +6426,7 @@ void HistoryWidget::updateOnlineDisplayTimer() { void HistoryWidget::moveFieldControls() { int w = width(), h = height(), right = w, bottom = h, keyboardHeight = 0; - int maxKeyboardHeight = st::historyComposeFieldMaxHeight - _field.height(); + int maxKeyboardHeight = st::historyComposeFieldMaxHeight - _field->height(); _keyboard.resizeToWidth(width(), maxKeyboardHeight); if (_kbShown) { keyboardHeight = qMin(_keyboard.height(), maxKeyboardHeight); @@ -6441,10 +6441,10 @@ void HistoryWidget::moveFieldControls() { int buttonsBottom = bottom - _attachDocument->height(); _attachDocument->move(0, buttonsBottom); _attachPhoto->move(0, buttonsBottom); - _field.move(_attachDocument->width(), bottom - _field.height() - st::sendPadding); - _send.move(right - _send.width(), buttonsBottom); - if (_inlineBotCancel) _inlineBotCancel->move(_send.pos()); - right -= _send.width(); + _field->move(_attachDocument->width(), bottom - _field->height() - st::sendPadding); + _send->move(right - _send->width(), buttonsBottom); + if (_inlineBotCancel) _inlineBotCancel->move(_send->pos()); + right -= _send->width(); _attachEmoji->move(right - _attachEmoji->width(), buttonsBottom); _botKeyboardHide->move(right - _botKeyboardHide->width(), buttonsBottom); right -= _attachEmoji->width(); @@ -6453,27 +6453,27 @@ void HistoryWidget::moveFieldControls() { _silent->move(right - _silent->width(), buttonsBottom); right = w; - _fieldBarCancel->move(right - _fieldBarCancel->width(), _field.y() - st::sendPadding - _fieldBarCancel->height()); + _fieldBarCancel->move(right - _fieldBarCancel->width(), _field->y() - st::sendPadding - _fieldBarCancel->height()); _attachType->move(0, _attachDocument->y() - _attachType->height()); _emojiPan->moveBottom(_attachEmoji->y()); - _botStart.setGeometry(0, bottom - _botStart.height(), w, _botStart.height()); - _unblock.setGeometry(0, bottom - _unblock.height(), w, _unblock.height()); - _joinChannel.setGeometry(0, bottom - _joinChannel.height(), w, _joinChannel.height()); - _muteUnmute.setGeometry(0, bottom - _muteUnmute.height(), w, _muteUnmute.height()); + _botStart->setGeometry(0, bottom - _botStart->height(), w, _botStart->height()); + _unblock->setGeometry(0, bottom - _unblock->height(), w, _unblock->height()); + _joinChannel->setGeometry(0, bottom - _joinChannel->height(), w, _joinChannel->height()); + _muteUnmute->setGeometry(0, bottom - _muteUnmute->height(), w, _muteUnmute->height()); } void HistoryWidget::updateFieldSize() { bool kbShowShown = _history && !_kbShown && _keyboard.hasMarkup(); int fieldWidth = width() - _attachDocument->width(); - fieldWidth -= _send.width(); + fieldWidth -= _send->width(); fieldWidth -= _attachEmoji->width(); if (kbShowShown) fieldWidth -= _botKeyboardShow->width(); if (_cmdStartShown) fieldWidth -= _botCommandStart->width(); if (hasSilentToggle()) fieldWidth -= _silent->width(); - if (_field.width() != fieldWidth) { - _field.resize(fieldWidth, _field.height()); + if (_field->width() != fieldWidth) { + _field->resize(fieldWidth, _field->height()); } else { moveFieldControls(); } @@ -6483,7 +6483,7 @@ void HistoryWidget::clearInlineBot() { if (_inlineBot) { _inlineBot = nullptr; inlineBotChanged(); - _field.finishPlaceholder(); + _field->finishPlaceholder(); } _emojiPan->clearInlineBot(); onCheckFieldAutocomplete(); @@ -6494,7 +6494,7 @@ void HistoryWidget::inlineBotChanged() { if (isInlineBot && !_inlineBotCancel) { _inlineBotCancel = std_::make_unique(this, st::historyInlineBotCancel); connect(_inlineBotCancel.get(), SIGNAL(clicked()), this, SLOT(onInlineBotCancel())); - _inlineBotCancel->setGeometry(_send.geometry()); + _inlineBotCancel->setGeometry(_send->geometry()); _attachEmoji->raise(); updateFieldSubmitSettings(); updateControlsVisibility(); @@ -6521,7 +6521,7 @@ void HistoryWidget::onCheckFieldAutocomplete() { bool start = false; bool isInlineBot = _inlineBot && (_inlineBot != LookingUpInlineBot); - QString query = isInlineBot ? QString() : _field.getMentionHashtagBotCommandPart(start); + QString query = isInlineBot ? QString() : _field->getMentionHashtagBotCommandPart(start); if (!query.isEmpty()) { if (query.at(0) == '#' && cRecentWriteHashtags().isEmpty() && cRecentSearchHashtags().isEmpty()) Local::readRecentHashtagsAndBots(); if (query.at(0) == '@' && cRecentInlineBots().isEmpty()) Local::readRecentHashtagsAndBots(); @@ -6532,15 +6532,15 @@ void HistoryWidget::onCheckFieldAutocomplete() { void HistoryWidget::updateFieldPlaceholder() { if (_editMsgId) { - _field.setPlaceholder(lang(lng_edit_message_text)); - _send.setText(lang(lng_settings_save)); + _field->setPlaceholder(lang(lng_edit_message_text)); + _send->setText(lang(lng_settings_save)); } else { if (_inlineBot && _inlineBot != LookingUpInlineBot) { - _field.setPlaceholder(_inlineBot->botInfo->inlinePlaceholder.mid(1), _inlineBot->username.size() + 2); + _field->setPlaceholder(_inlineBot->botInfo->inlinePlaceholder.mid(1), _inlineBot->username.size() + 2); } else { - _field.setPlaceholder(lang((_history && _history->isChannel() && !_history->isMegagroup()) ? (_silent->checked() ? lng_broadcast_silent_ph : lng_broadcast_ph) : lng_message_ph)); + _field->setPlaceholder(lang((_history && _history->isChannel() && !_history->isMegagroup()) ? (_silent->checked() ? lng_broadcast_silent_ph : lng_broadcast_ph) : lng_message_ph)); } - _send.setText(lang(lng_send_button)); + _send->setText(lang(lng_send_button)); } } @@ -6665,7 +6665,7 @@ void HistoryWidget::cancelSendFile(const FileLoadResultPtr &file) { _confirmWithTextId = 0; } if (!file->originalText.isEmpty()) { - _field.textCursor().insertText(file->originalText); + _field->textCursor().insertText(file->originalText); } } @@ -6909,10 +6909,10 @@ void HistoryWidget::peerMessagesUpdated(PeerId peer) { updateBotKeyboard(); if (!_scroll.isHidden()) { bool unblock = isBlocked(), botStart = isBotStart(), joinChannel = isJoinChannel(), muteUnmute = isMuteUnmute(); - bool upd = (_unblock.isHidden() == unblock); - if (!upd && !unblock) upd = (_botStart.isHidden() == botStart); - if (!upd && !unblock && !botStart) upd = (_joinChannel.isHidden() == joinChannel); - if (!upd && !unblock && !botStart && !joinChannel) upd = (_muteUnmute.isHidden() == muteUnmute); + bool upd = (_unblock->isHidden() == unblock); + if (!upd && !unblock) upd = (_botStart->isHidden() == botStart); + if (!upd && !unblock && !botStart) upd = (_joinChannel->isHidden() == joinChannel); + if (!upd && !unblock && !botStart && !joinChannel) upd = (_muteUnmute->isHidden() == muteUnmute); if (upd) { updateControlsVisibility(); updateControlsGeometry(); @@ -7102,10 +7102,10 @@ void HistoryWidget::updateListSize(bool initial, bool loadedDown, const ScrollCh int newScrollHeight = height(); if (isBlocked() || isBotStart() || isJoinChannel() || isMuteUnmute()) { - newScrollHeight -= _unblock.height(); + newScrollHeight -= _unblock->height(); } else { if (_canSendMessages) { - newScrollHeight -= (_field.height() + 2 * st::sendPadding); + newScrollHeight -= (_field->height() + 2 * st::sendPadding); } if (_editMsgId || replyToId() || readyToForward() || (_previewData && _previewData->pendingTill >= 0)) { newScrollHeight -= st::historyReplyHeight; @@ -7312,7 +7312,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { if (_keyboard.singleUse() && _keyboard.hasMarkup() && _keyboard.forMsgId() == FullMsgId(_channel, _history->lastKeyboardId) && _history->lastKeyboardUsed) { _history->lastKeyboardHiddenId = _history->lastKeyboardId; } - if (!isBotStart() && !isBlocked() && _canSendMessages && (wasVisible || (_replyToId && _replyEditMsg) || (!_field.hasSendText() && !kbWasHidden()))) { + if (!isBotStart() && !isBlocked() && _canSendMessages && (wasVisible || (_replyToId && _replyEditMsg) || (!_field->hasSendText() && !kbWasHidden()))) { if (!_a_show.animating()) { if (hasMarkup) { _kbScroll.show(); @@ -7327,7 +7327,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { _botCommandStart->hide(); } int32 maxh = hasMarkup ? qMin(_keyboard.height(), st::historyComposeFieldMaxHeight - (st::historyComposeFieldMaxHeight / 2)) : 0; - _field.setMaxHeight(st::historyComposeFieldMaxHeight - maxh); + _field->setMaxHeight(st::historyComposeFieldMaxHeight - maxh); _kbShown = hasMarkup; _kbReplyTo = (_peer->isChat() || _peer->isChannel() || _keyboard.forceReply()) ? App::histItemById(_keyboard.forMsgId()) : 0; if (_kbReplyTo && !_replyToId) { @@ -7344,7 +7344,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { _botKeyboardShow->show(); _botCommandStart->hide(); } - _field.setMaxHeight(st::historyComposeFieldMaxHeight); + _field->setMaxHeight(st::historyComposeFieldMaxHeight); _kbShown = false; _kbReplyTo = 0; if (!readyToForward() && (!_previewData || _previewData->pendingTill < 0) && !_replyToId) { @@ -7360,7 +7360,7 @@ void HistoryWidget::updateBotKeyboard(History *h, bool force) { _botKeyboardShow->hide(); _botCommandStart->show(); } - _field.setMaxHeight(st::historyComposeFieldMaxHeight); + _field->setMaxHeight(st::historyComposeFieldMaxHeight); _kbShown = false; _kbReplyTo = 0; if (!readyToForward() && (!_previewData || _previewData->pendingTill < 0) && !_replyToId && !_editMsgId) { @@ -7408,7 +7408,7 @@ void HistoryWidget::updateToEndVisibility() { } void HistoryWidget::mousePressEvent(QMouseEvent *e) { - _replyForwardPressed = QRect(0, _field.y() - st::sendPadding - st::historyReplyHeight, st::historyReplySkip, st::historyReplyHeight).contains(e->pos()); + _replyForwardPressed = QRect(0, _field->y() - st::sendPadding - st::historyReplyHeight, st::historyReplySkip, st::historyReplyHeight).contains(e->pos()); if (_replyForwardPressed && !_fieldBarCancel->isHidden()) { updateField(); } else if (_inRecord && cHasAudioCapture()) { @@ -7449,7 +7449,7 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) { } else if (e->key() == Qt::Key_Up) { if (!(e->modifiers() & (Qt::ShiftModifier | Qt::MetaModifier | Qt::ControlModifier))) { if (_history && _history->lastSentMsg && _history->lastSentMsg->canEdit(::date(unixtime()))) { - if (_field.isEmpty() && !_editMsgId && !_replyToId) { + if (_field->isEmpty() && !_editMsgId && !_replyToId) { App::contextItem(_history->lastSentMsg); onEditMessage(); return; @@ -7545,7 +7545,7 @@ void HistoryWidget::onInlineResultSend(InlineBots::Result *result, UserData *bot hideSelectorControlsAnimated(); - _field.setFocus(); + _field->setFocus(); } HistoryWidget::PinnedBar::PinnedBar(MsgId msgId, HistoryWidget *parent) @@ -7711,7 +7711,7 @@ bool HistoryWidget::sendExistingDocument(DocumentData *doc, const QString &capti hideSelectorControlsAnimated(); - _field.setFocus(); + _field->setFocus(); return true; } @@ -7756,13 +7756,13 @@ void HistoryWidget::sendExistingPhoto(PhotoData *photo, const QString &caption) hideSelectorControlsAnimated(); - _field.setFocus(); + _field->setFocus(); } void HistoryWidget::setFieldText(const TextWithTags &textWithTags, TextUpdateEvents events, FlatTextarea::UndoHistoryAction undoHistoryAction) { _textUpdateEvents = events; - _field.setTextWithTags(textWithTags, undoHistoryAction); - _field.moveCursor(QTextCursor::End); + _field->setTextWithTags(textWithTags, undoHistoryAction); + _field->moveCursor(QTextCursor::End); _textUpdateEvents = TextUpdateEvent::SaveDraft | TextUpdateEvent::SendTyping; _previewCancelled = false; @@ -7775,7 +7775,7 @@ void HistoryWidget::setFieldText(const TextWithTags &textWithTags, TextUpdateEve } void HistoryWidget::onReplyToMessage() { - HistoryItem *to = App::contextItem(); + auto to = App::contextItem(); if (!to || to->id <= 0 || !_canSendMessages) return; if (to->history() == _migrated) { @@ -7811,7 +7811,7 @@ void HistoryWidget::onReplyToMessage() { updateBotKeyboard(); - if (!_field.isHidden()) _fieldBarCancel->show(); + if (!_field->isHidden()) _fieldBarCancel->show(); updateMouseTracking(); updateReplyToName(); resizeEvent(0); @@ -7822,7 +7822,7 @@ void HistoryWidget::onReplyToMessage() { _saveDraftStart = getms(); onDraftSave(); - _field.setFocus(); + _field->setFocus(); } void HistoryWidget::onEditMessage() { @@ -7836,7 +7836,7 @@ void HistoryWidget::onEditMessage() { delete box; if (!_editMsgId) { - if (_replyToId || !_field.isEmpty()) { + if (_replyToId || !_field->isEmpty()) { _history->setLocalDraft(std_::make_unique(_field, _replyToId, _previewCancelled)); } else { _history->clearLocalDraft(); @@ -7864,7 +7864,7 @@ void HistoryWidget::onEditMessage() { updateBotKeyboard(); - if (!_field.isHidden()) _fieldBarCancel->show(); + if (!_field->isHidden()) _fieldBarCancel->show(); updateFieldPlaceholder(); updateMouseTracking(); updateReplyToName(); @@ -7875,7 +7875,7 @@ void HistoryWidget::onEditMessage() { _saveDraftStart = getms(); onDraftSave(); - _field.setFocus(); + _field->setFocus(); } } @@ -8089,12 +8089,12 @@ void HistoryWidget::previewCancel() { void HistoryWidget::onPreviewParse() { if (_previewCancelled) return; - _field.parseLinks(); + _field->parseLinks(); } void HistoryWidget::onPreviewCheck() { if (_previewCancelled) return; - QStringList linksList = _field.linksList(); + QStringList linksList = _field->linksList(); QString newLinks = linksList.join(' '); if (newLinks != _previewLinks) { MTP::cancel(_previewRequest); @@ -8207,7 +8207,7 @@ void HistoryWidget::onCancel() { auto editText = textApplyEntities(original.text, original.entities); auto editTags = textTagsFromEntities(original.entities); TextWithTags editData = { editText, editTags }; - if (_replyEditMsg && editData != _field.getTextWithTags()) { + if (_replyEditMsg && editData != _field->getTextWithTags()) { auto box = new ConfirmBox(lang(lng_cancel_edit_post_sure), lang(lng_cancel_edit_post_yes), st::defaultBoxButton, lang(lng_cancel_edit_post_no)); connect(box, SIGNAL(confirmed()), this, SLOT(onFieldBarCancel())); Ui::showLayer(box); @@ -8239,7 +8239,7 @@ void HistoryWidget::onFullPeerUpdated(PeerData *data) { if (updateCmdStartShown()) { updateControlsVisibility(); updateControlsGeometry(); - } else if (!_scroll.isHidden() && _unblock.isHidden() == isBlocked()) { + } else if (!_scroll.isHidden() && _unblock->isHidden() == isBlocked()) { updateControlsVisibility(); updateControlsGeometry(); } @@ -8274,7 +8274,7 @@ void HistoryWidget::peerUpdated(PeerData *data) { } } if (!_a_show.animating()) { - if (_unblock.isHidden() == isBlocked() || (!isBlocked() && _joinChannel.isHidden() == isJoinChannel())) { + if (_unblock->isHidden() == isBlocked() || (!isBlocked() && _joinChannel->isHidden() == isJoinChannel())) { resize = true; } bool newCanSendMessages = canSendMessages(_peer); @@ -8365,7 +8365,7 @@ void HistoryWidget::onListEscapePressed() { } void HistoryWidget::onListEnterPressed() { - if (!_botStart.isHidden()) { + if (!_botStart->isHidden()) { onBotStart(); } } @@ -8422,7 +8422,7 @@ void HistoryWidget::updateTopBarSelection() { if (_selCount || (_list && _list->wasSelectedText()) || _recording || isBotStart() || isBlocked() || !_canSendMessages) { _list->setFocus(); } else { - _field.setFocus(); + _field->setFocus(); } } App::main()->topBar()->update(); @@ -8453,7 +8453,7 @@ void HistoryWidget::updateReplyEditTexts(bool force) { updateBotKeyboard(); - if (!_field.isHidden() || _recording) { + if (!_field->isHidden() || _recording) { _fieldBarCancel->show(); updateMouseTracking(); } @@ -8489,7 +8489,7 @@ void HistoryWidget::updateField() { } void HistoryWidget::drawField(Painter &p, const QRect &rect) { - int32 backy = _field.y() - st::sendPadding, backh = _field.height() + 2 * st::sendPadding; + int32 backy = _field->y() - st::sendPadding, backh = _field->height() + 2 * st::sendPadding; Text *from = 0, *text = 0; bool serviceColor = false, hasForward = readyToForward(); ImagePtr preview; @@ -8639,10 +8639,10 @@ void HistoryWidget::drawRecordButton(Painter &p) { } return &st::historyRecordVoice; }; - fastIcon()->paintInCenter(p, _send.geometry()); + fastIcon()->paintInCenter(p, _send->geometry()); if (down > 0. && down < 1.) { p.setOpacity(down); - st::historyRecordVoiceActive.paintInCenter(p, _send.geometry()); + st::historyRecordVoiceActive.paintInCenter(p, _send->geometry()); p.setOpacity(1.); } } @@ -8662,8 +8662,8 @@ void HistoryWidget::drawRecording(Painter &p) { p.setPen(st::historyRecordDurationFg); p.drawText(_attachPhoto->x() + _attachEmoji->width(), _attachPhoto->y() + st::historyRecordTextTop + st::historyRecordFont->ascent, duration); - int32 left = _attachPhoto->x() + _attachEmoji->width() + st::historyRecordFont->width(duration) + ((_send.width() - st::historyRecordVoice.width()) / 2); - int32 right = width() - _send.width(); + int32 left = _attachPhoto->x() + _attachEmoji->width() + st::historyRecordFont->width(duration) + ((_send->width() - st::historyRecordVoice.width()) / 2); + int32 right = width() - _send->width(); p.setPen(a_recordCancel.current()); p.drawText(left + (right - left - _recordCancelWidth) / 2, _attachPhoto->y() + st::historyRecordTextTop + st::historyRecordFont->ascent, lang(lng_record_cancel)); @@ -8763,9 +8763,9 @@ void HistoryWidget::paintEvent(QPaintEvent *e) { } if (_list) { - if (!_field.isHidden() || _recording) { + if (!_field->isHidden() || _recording) { drawField(p, r); - if (_send.isHidden()) { + if (_send->isHidden()) { drawRecordButton(p); if (_recording) drawRecording(p); } @@ -8775,12 +8775,12 @@ void HistoryWidget::paintEvent(QPaintEvent *e) { } if (_scroll.isHidden()) { p.setClipRect(_scroll.geometry()); - HistoryLayout::paintEmpty(p, width(), height() - _field.height() - 2 * st::sendPadding); + HistoryLayout::paintEmpty(p, width(), height() - _field->height() - 2 * st::sendPadding); } } else { style::font font(st::msgServiceFont); int32 w = font->width(lang(lng_willbe_history)) + st::msgPadding.left() + st::msgPadding.right(), h = font->height + st::msgServicePadding.top() + st::msgServicePadding.bottom() + 2; - QRect tr((width() - w) / 2, (height() - _field.height() - 2 * st::sendPadding - h) / 2, w, h); + QRect tr((width() - w) / 2, (height() - _field->height() - 2 * st::sendPadding - h) / 2, w, h); HistoryLayout::ServiceMessagePainter::paintBubble(p, tr.x(), tr.y(), tr.width(), tr.height()); p.setPen(st::msgServiceColor->p); diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index 8b508b9c7..2ba364b92 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -351,8 +351,9 @@ protected: void paintEvent(QPaintEvent *e) override; private: - FlatButton _report, _hide; - LinkButton _clear; + ChildWidget _report; + ChildWidget _hide; + ChildWidget _clear; }; @@ -489,7 +490,8 @@ private: QString _shareUrl, _shareText; QString _botAndQuery; - BoxButton _send, _cancel; + ChildWidget _send; + ChildWidget _cancel; PeerData *_offered = nullptr; anim::fvalue a_opacity; @@ -1098,7 +1100,11 @@ private: ReportSpamPanel _reportSpamPanel; - FlatButton _send, _unblock, _botStart, _joinChannel, _muteUnmute; + ChildWidget _send; + ChildWidget _unblock; + ChildWidget _botStart; + ChildWidget _joinChannel; + ChildWidget _muteUnmute; mtpRequestId _unblockRequest = 0; mtpRequestId _reportSpamRequest = 0; ChildWidget _attachDocument; @@ -1109,7 +1115,7 @@ private: ChildWidget _botCommandStart; ChildWidget _silent; bool _cmdStartShown = false; - MessageField _field; + ChildWidget _field; Animation _a_record, _a_recording; bool _recording = false; bool _inRecord = false; diff --git a/Telegram/SourceFiles/intro/intro.style b/Telegram/SourceFiles/intro/intro.style index a751a9088..1a7d836f0 100644 --- a/Telegram/SourceFiles/intro/intro.style +++ b/Telegram/SourceFiles/intro/intro.style @@ -74,28 +74,14 @@ introTextSize: size(400px, 93px); introCallSkip: 15px; introPwdTextSize: size(400px, 73px); -introNextButton: flatButton { - duration: 200; - cursor: cursor(pointer); - - color: #ffffff; - overColor: #ffffff; - downColor: #ffffff; - bgColor: #2fa9e2; - overBgColor: #279ad0; - downBgColor: #279ad0; - - textTop: 16px; - overTextTop: 16px; - downTextTop: 17px; - - font: font(17px); - overFont: font(17px); - +introNextButton: RoundButton(defaultActiveButton) { width: 300px; height: 56px; - radius: buttonRadius; + textTop: 16px; + downTextTop: 17px; + + font: font(17px); } introPhoneTop: 8px; diff --git a/Telegram/SourceFiles/intro/introcode.cpp b/Telegram/SourceFiles/intro/introcode.cpp index b60211d97..0c403eb5a 100644 --- a/Telegram/SourceFiles/intro/introcode.cpp +++ b/Telegram/SourceFiles/intro/introcode.cpp @@ -25,6 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "application.h" #include "intro/introsignup.h" #include "intro/intropwdcheck.h" +#include "ui/buttons/round_button.h" #include "styles/style_intro.h" CodeInput::CodeInput(QWidget *parent, const style::flatInput &st, const QString &ph) : FlatInput(parent, st, ph) { @@ -75,26 +76,28 @@ void CodeInput::correctValue(const QString &was, QString &now) { IntroCode::IntroCode(IntroWidget *parent) : IntroStep(parent) , a_errorAlpha(0) , _a_error(animation(this, &IntroCode::step_error)) -, next(this, lang(lng_intro_next), st::introNextButton) +, _next(this, lang(lng_intro_next), st::introNextButton) , _desc(st::introTextSize.width()) , _noTelegramCode(this, lang(lng_code_no_telegram), st::introLink) , _noTelegramCodeRequestId(0) -, code(this, st::inpIntroCode, lang(lng_code_ph)) -, sentRequest(0) -, callStatus(intro()->getCallStatus()) { +, _code(this, st::inpIntroCode, lang(lng_code_ph)) +, _callTimer(this) +, _callStatus(intro()->getCallStatus()) +, _checkRequest(this) { setGeometry(parent->innerRect()); - connect(&next, SIGNAL(clicked()), this, SLOT(onSubmitCode())); - connect(&code, SIGNAL(changed()), this, SLOT(onInputChange())); - connect(&callTimer, SIGNAL(timeout()), this, SLOT(onSendCall())); - connect(&checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); - connect(&_noTelegramCode, SIGNAL(clicked()), this, SLOT(onNoTelegramCode())); + _next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); + connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitCode())); + connect(_code, SIGNAL(changed()), this, SLOT(onInputChange())); + connect(_callTimer, SIGNAL(timeout()), this, SLOT(onSendCall())); + connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); + connect(_noTelegramCode, SIGNAL(clicked()), this, SLOT(onNoTelegramCode())); updateDescText(); if (!intro()->codeByTelegram()) { - if (callStatus.type == IntroWidget::CallWaiting) { - callTimer.start(1000); + if (_callStatus.type == IntroWidget::CallWaiting) { + _callTimer->start(1000); } } } @@ -102,13 +105,13 @@ IntroCode::IntroCode(IntroWidget *parent) : IntroStep(parent) void IntroCode::updateDescText() { _desc.setRichText(st::introFont, lang(intro()->codeByTelegram() ? lng_code_telegram : lng_code_desc)); if (intro()->codeByTelegram()) { - _noTelegramCode.show(); - callTimer.stop(); + _noTelegramCode->show(); + _callTimer->stop(); } else { - _noTelegramCode.hide(); - callStatus = intro()->getCallStatus(); - if (callStatus.type == IntroWidget::CallWaiting && !callTimer.isActive()) { - callTimer.start(1000); + _noTelegramCode->hide(); + _callStatus = intro()->getCallStatus(); + if (_callStatus.type == IntroWidget::CallWaiting && !_callTimer->isActive()) { + _callTimer->start(1000); } } update(); @@ -122,21 +125,21 @@ void IntroCode::paintEvent(QPaintEvent *e) { p.setClipRect(e->rect()); } bool codeByTelegram = intro()->codeByTelegram(); - if (trivial || e->rect().intersects(textRect)) { + if (trivial || e->rect().intersects(_textRect)) { p.setFont(st::introHeaderFont->f); - p.drawText(textRect, intro()->getPhone(), style::al_top); + p.drawText(_textRect, intro()->getPhone(), style::al_top); p.setFont(st::introFont->f); - _desc.draw(p, textRect.x(), textRect.y() + textRect.height() - 2 * st::introFont->height, textRect.width(), style::al_top); + _desc.draw(p, _textRect.x(), _textRect.y() + _textRect.height() - 2 * st::introFont->height, _textRect.width(), style::al_top); } if (codeByTelegram) { } else { QString callText; - switch (callStatus.type) { + switch (_callStatus.type) { case IntroWidget::CallWaiting: { - if (callStatus.timeout >= 3600) { - callText = lng_code_call(lt_minutes, qsl("%1:%2").arg(callStatus.timeout / 3600).arg((callStatus.timeout / 60) % 60, 2, 10, QChar('0')), lt_seconds, qsl("%1").arg(callStatus.timeout % 60, 2, 10, QChar('0'))); + if (_callStatus.timeout >= 3600) { + callText = lng_code_call(lt_minutes, qsl("%1:%2").arg(_callStatus.timeout / 3600).arg((_callStatus.timeout / 60) % 60, 2, 10, QChar('0')), lt_seconds, qsl("%1").arg(_callStatus.timeout % 60, 2, 10, QChar('0'))); } else { - callText = lng_code_call(lt_minutes, QString::number(callStatus.timeout / 60), lt_seconds, qsl("%1").arg(callStatus.timeout % 60, 2, 10, QChar('0'))); + callText = lng_code_call(lt_minutes, QString::number(_callStatus.timeout / 60), lt_seconds, qsl("%1").arg(_callStatus.timeout % 60, 2, 10, QChar('0'))); } } break; @@ -149,32 +152,32 @@ void IntroCode::paintEvent(QPaintEvent *e) { } break; } if (!callText.isEmpty()) { - p.drawText(QRect(textRect.left(), code.y() + code.height() + st::introCallSkip, st::introTextSize.width(), st::introErrorHeight), callText, style::al_center); + p.drawText(QRect(_textRect.left(), _code->y() + _code->height() + st::introCallSkip, st::introTextSize.width(), st::introErrorHeight), callText, style::al_center); } } - if (_a_error.animating() || error.length()) { + if (_a_error.animating() || _error.length()) { p.setOpacity(a_errorAlpha.current()); p.setFont(st::introErrorFont); p.setPen(st::introErrorFg); - p.drawText(QRect(textRect.left(), next.y() + next.height() + st::introErrorTop, st::introTextSize.width(), st::introErrorHeight), error, style::al_center); + p.drawText(QRect(_textRect.left(), _next->y() + _next->height() + st::introErrorTop, st::introTextSize.width(), st::introErrorHeight), _error, style::al_center); } } void IntroCode::resizeEvent(QResizeEvent *e) { if (e->oldSize().width() != width()) { - next.move((width() - next.width()) / 2, st::introBtnTop); - code.move((width() - code.width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top); + _next->move((width() - _next->width()) / 2, st::introBtnTop); + _code->move((width() - _code->width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top); } - textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height()); - _noTelegramCode.move(textRect.left() + (st::introTextSize.width() - _noTelegramCode.width()) / 2, code.y() + code.height() + st::introCallSkip + (st::introErrorHeight - _noTelegramCode.height()) / 2); + _textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height()); + _noTelegramCode->move(_textRect.left() + (st::introTextSize.width() - _noTelegramCode->width()) / 2, _code->y() + _code->height() + st::introCallSkip + (st::introErrorHeight - _noTelegramCode->height()) / 2); } -void IntroCode::showError(const QString &err) { - if (!err.isEmpty()) code.notaBene(); - if (!_a_error.animating() && err == error) return; +void IntroCode::showError(const QString &error) { + if (!error.isEmpty()) _code->notaBene(); + if (!_a_error.animating() && error == _error) return; - if (err.length()) { - error = err; + if (error.length()) { + _error = error; a_errorAlpha.start(1); } else { a_errorAlpha.start(0); @@ -189,7 +192,7 @@ void IntroCode::step_error(float64 ms, bool timer) { _a_error.stop(); a_errorAlpha.finish(); if (!a_errorAlpha.current()) { - error.clear(); + _error.clear(); } } else { a_errorAlpha.update(dt, anim::linear); @@ -199,59 +202,57 @@ void IntroCode::step_error(float64 ms, bool timer) { void IntroCode::activate() { IntroStep::activate(); - code.setFocus(); + _code->setFocus(); } void IntroCode::finished() { IntroStep::finished(); - error.clear(); + _error.clear(); a_errorAlpha = anim::fvalue(0); - sentCode.clear(); - code.setDisabled(false); + _sentCode.clear(); + _code->setDisabled(false); - callTimer.stop(); - code.setText(QString()); + _callTimer->stop(); + _code->setText(QString()); rpcClear(); } void IntroCode::cancelled() { - if (sentRequest) { - MTP::cancel(sentRequest); - sentRequest = 0; + if (_sentRequest) { + MTP::cancel(base::take(_sentRequest)); } MTP::send(MTPauth_CancelCode(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash()))); } void IntroCode::stopCheck() { - checkRequest.stop(); + _checkRequest->stop(); } void IntroCode::onCheckRequest() { - int32 status = MTP::state(sentRequest); + int32 status = MTP::state(_sentRequest); if (status < 0) { int32 leftms = -status; if (leftms >= 1000) { - if (sentRequest) { - MTP::cancel(sentRequest); - sentRequest = 0; - sentCode.clear(); + if (_sentRequest) { + MTP::cancel(base::take(_sentRequest)); + _sentCode.clear(); } - if (!code.isEnabled()) { - code.setDisabled(false); - code.setFocus(); + if (!_code->isEnabled()) { + _code->setDisabled(false); + _code->setFocus(); } } } - if (!sentRequest && status == MTP::RequestSent) { + if (!_sentRequest && status == MTP::RequestSent) { stopCheck(); } } void IntroCode::codeSubmitDone(const MTPauth_Authorization &result) { stopCheck(); - sentRequest = 0; - code.setDisabled(false); + _sentRequest = 0; + _code->setDisabled(false); const auto &d(result.c_auth_authorization()); if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf? showError(lang(lng_server_error)); @@ -264,34 +265,34 @@ void IntroCode::codeSubmitDone(const MTPauth_Authorization &result) { bool IntroCode::codeSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { stopCheck(); - sentRequest = 0; + _sentRequest = 0; showError(lang(lng_flood_error)); - code.setDisabled(false); - code.setFocus(); + _code->setDisabled(false); + _code->setFocus(); return true; } if (MTP::isDefaultHandledError(error)) return false; stopCheck(); - sentRequest = 0; - code.setDisabled(false); + _sentRequest = 0; + _code->setDisabled(false); const QString &err = error.type(); if (err == qstr("PHONE_NUMBER_INVALID") || err == qstr("PHONE_CODE_EXPIRED")) { // show error intro()->onBack(); return true; } else if (err == qstr("PHONE_CODE_EMPTY") || err == qstr("PHONE_CODE_INVALID")) { showError(lang(lng_bad_code)); - code.notaBene(); + _code->notaBene(); return true; } else if (err == qstr("PHONE_NUMBER_UNOCCUPIED")) { // success, need to signUp - intro()->setCode(sentCode); + intro()->setCode(_sentCode); intro()->replaceStep(new IntroSignup(intro())); return true; } else if (err == qstr("SESSION_PASSWORD_NEEDED")) { - intro()->setCode(sentCode); - code.setDisabled(false); - checkRequest.start(1000); - sentRequest = MTP::send(MTPaccount_GetPassword(), rpcDone(&IntroCode::gotPassword), rpcFail(&IntroCode::codeSubmitFail)); + intro()->setCode(_sentCode); + _code->setDisabled(false); + _checkRequest->start(1000); + _sentRequest = MTP::send(MTPaccount_GetPassword(), rpcDone(&IntroCode::gotPassword), rpcFail(&IntroCode::codeSubmitFail)); return true; } if (cDebug()) { // internal server error @@ -299,43 +300,43 @@ bool IntroCode::codeSubmitFail(const RPCError &error) { } else { showError(lang(lng_server_error)); } - code.setFocus(); + _code->setFocus(); return false; } void IntroCode::onInputChange() { showError(QString()); - if (code.text().length() == 5) onSubmitCode(); + if (_code->text().length() == 5) onSubmitCode(); } void IntroCode::onSendCall() { - if (callStatus.type == IntroWidget::CallWaiting) { - if (--callStatus.timeout <= 0) { - callStatus.type = IntroWidget::CallCalling; - callTimer.stop(); + if (_callStatus.type == IntroWidget::CallWaiting) { + if (--_callStatus.timeout <= 0) { + _callStatus.type = IntroWidget::CallCalling; + _callTimer->stop(); MTP::send(MTPauth_ResendCode(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash())), rpcDone(&IntroCode::callDone)); } else { - intro()->setCallStatus(callStatus); + intro()->setCallStatus(_callStatus); } } update(); } void IntroCode::callDone(const MTPauth_SentCode &v) { - if (callStatus.type == IntroWidget::CallCalling) { - callStatus.type = IntroWidget::CallCalled; - intro()->setCallStatus(callStatus); + if (_callStatus.type == IntroWidget::CallCalling) { + _callStatus.type = IntroWidget::CallCalled; + intro()->setCallStatus(_callStatus); update(); } } void IntroCode::gotPassword(const MTPaccount_Password &result) { stopCheck(); - sentRequest = 0; - code.setDisabled(false); + _sentRequest = 0; + _code->setDisabled(false); switch (result.type()) { case mtpc_account_noPassword: // should not happen - code.setFocus(); + _code->setFocus(); break; case mtpc_account_password: { @@ -349,20 +350,20 @@ void IntroCode::gotPassword(const MTPaccount_Password &result) { } void IntroCode::onSubmitCode() { - if (sentRequest) return; + if (_sentRequest) return; - code.setDisabled(true); + _code->setDisabled(true); setFocus(); showError(QString()); - checkRequest.start(1000); + _checkRequest->start(1000); - sentCode = code.text(); + _sentCode = _code->text(); intro()->setPwdSalt(QByteArray()); intro()->setHasRecovery(false); intro()->setPwdHint(QString()); - sentRequest = MTP::send(MTPauth_SignIn(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash()), MTP_string(sentCode)), rpcDone(&IntroCode::codeSubmitDone), rpcFail(&IntroCode::codeSubmitFail)); + _sentRequest = MTP::send(MTPauth_SignIn(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash()), MTP_string(_sentCode)), rpcDone(&IntroCode::codeSubmitDone), rpcFail(&IntroCode::codeSubmitFail)); } void IntroCode::onNoTelegramCode() { @@ -395,7 +396,7 @@ void IntroCode::noTelegramCodeDone(const MTPauth_SentCode &result) { bool IntroCode::noTelegramCodeFail(const RPCError &error) { if (MTP::isFloodError(error)) { showError(lang(lng_flood_error)); - code.setFocus(); + _code->setFocus(); return true; } if (MTP::isDefaultHandledError(error)) return false; @@ -405,7 +406,7 @@ bool IntroCode::noTelegramCodeFail(const RPCError &error) { } else { showError(lang(lng_server_error)); } - code.setFocus(); + _code->setFocus(); return false; } diff --git a/Telegram/SourceFiles/intro/introcode.h b/Telegram/SourceFiles/intro/introcode.h index ab62224ca..49e049bcd 100644 --- a/Telegram/SourceFiles/intro/introcode.h +++ b/Telegram/SourceFiles/intro/introcode.h @@ -25,6 +25,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/flatinput.h" #include "intro/introwidget.h" +namespace Ui { +class RoundButton; +} // namespace Ui + class CodeInput final : public FlatInput { Q_OBJECT @@ -43,7 +47,6 @@ class IntroCode final : public IntroStep { Q_OBJECT public: - IntroCode(IntroWidget *parent); void paintEvent(QPaintEvent *e) override; @@ -65,7 +68,6 @@ public: void updateDescText(); public slots: - void onSubmitCode(); void onNoTelegramCode(); void onInputChange(); @@ -73,32 +75,32 @@ public slots: void onCheckRequest(); private: - void showError(const QString &err); void callDone(const MTPauth_SentCode &v); void gotPassword(const MTPaccount_Password &result); - void stopCheck(); - - QString error; - anim::fvalue a_errorAlpha; - Animation _a_error; - - FlatButton next; - - Text _desc; - LinkButton _noTelegramCode; - mtpRequestId _noTelegramCodeRequestId; - QRect textRect; - void noTelegramCodeDone(const MTPauth_SentCode &result); bool noTelegramCodeFail(const RPCError &result); - CodeInput code; - QString sentCode; - mtpRequestId sentRequest; - QTimer callTimer; - IntroWidget::CallStatus callStatus; + void stopCheck(); + + QString _error; + anim::fvalue a_errorAlpha; + Animation _a_error; + + ChildWidget _next; + + Text _desc; + ChildWidget _noTelegramCode; + mtpRequestId _noTelegramCodeRequestId; + QRect _textRect; + + ChildWidget _code; + QString _sentCode; + mtpRequestId _sentRequest = 0; + ChildObject _callTimer; + IntroWidget::CallStatus _callStatus; + + ChildObject _checkRequest; - QTimer checkRequest; }; diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index b9aaf1f99..9f68aacd5 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -25,6 +25,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "application.h" #include "intro/introcode.h" #include "styles/style_intro.h" +#include "ui/buttons/round_button.h" namespace { class SignUpClickHandler : public LeftButtonClickHandler { @@ -46,38 +47,37 @@ namespace { IntroPhone::IntroPhone(IntroWidget *parent) : IntroStep(parent) , a_errorAlpha(0) , _a_error(animation(this, &IntroPhone::step_error)) -, changed(false) -, next(this, lang(lng_intro_next), st::introNextButton) -, country(this, st::introCountry) -, phone(this, st::inpIntroPhone) -, code(this, st::inpIntroCountryCode) +, _next(this, lang(lng_intro_next), st::introNextButton) +, _country(this, st::introCountry) +, _phone(this, st::inpIntroPhone) +, _code(this, st::inpIntroCountryCode) , _signup(this, lng_phone_notreg(lt_signup_start, textcmdStartLink(1), lt_signup_end, textcmdStopLink()), FlatLabel::InitType::Rich, st::introErrorLabel, st::introErrorLabelTextStyle) -, _showSignup(false) -, sentRequest(0) { +, _checkRequest(this) { setVisible(false); setGeometry(parent->innerRect()); - connect(&next, SIGNAL(clicked()), this, SLOT(onSubmitPhone())); - connect(&phone, SIGNAL(voidBackspace(QKeyEvent*)), &code, SLOT(startErasing(QKeyEvent*))); - connect(&country, SIGNAL(codeChanged(const QString &)), &code, SLOT(codeSelected(const QString &))); - connect(&code, SIGNAL(codeChanged(const QString &)), &country, SLOT(onChooseCode(const QString &))); - connect(&code, SIGNAL(codeChanged(const QString &)), &phone, SLOT(onChooseCode(const QString &))); - connect(&country, SIGNAL(codeChanged(const QString &)), &phone, SLOT(onChooseCode(const QString &))); - connect(&code, SIGNAL(addedToNumber(const QString &)), &phone, SLOT(addedToNumber(const QString &))); - connect(&phone, SIGNAL(changed()), this, SLOT(onInputChange())); - connect(&code, SIGNAL(changed()), this, SLOT(onInputChange())); + _next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); + connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitPhone())); + connect(_phone, SIGNAL(voidBackspace(QKeyEvent*)), _code, SLOT(startErasing(QKeyEvent*))); + connect(_country, SIGNAL(codeChanged(const QString &)), _code, SLOT(codeSelected(const QString &))); + connect(_code, SIGNAL(codeChanged(const QString &)), _country, SLOT(onChooseCode(const QString &))); + connect(_code, SIGNAL(codeChanged(const QString &)), _phone, SLOT(onChooseCode(const QString &))); + connect(_country, SIGNAL(codeChanged(const QString &)), _phone, SLOT(onChooseCode(const QString &))); + connect(_code, SIGNAL(addedToNumber(const QString &)), _phone, SLOT(addedToNumber(const QString &))); + connect(_phone, SIGNAL(changed()), this, SLOT(onInputChange())); + connect(_code, SIGNAL(changed()), this, SLOT(onInputChange())); connect(intro(), SIGNAL(countryChanged()), this, SLOT(countryChanged())); - connect(&checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); + connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); - _signup.setLink(1, MakeShared(this)); - _signup.hide(); + _signup->setLink(1, MakeShared(this)); + _signup->hide(); - _signupCache = myGrab(&_signup); + _signupCache = myGrab(_signup); - if (!country.onChooseCountry(intro()->currentCountry())) { - country.onChooseCountry(qsl("US")); + if (!_country->onChooseCountry(intro()->currentCountry())) { + _country->onChooseCountry(qsl("US")); } - changed = false; + _changed = false; } void IntroPhone::paintEvent(QPaintEvent *e) { @@ -87,52 +87,52 @@ void IntroPhone::paintEvent(QPaintEvent *e) { if (!trivial) { p.setClipRect(e->rect()); } - if (trivial || e->rect().intersects(textRect)) { + if (trivial || e->rect().intersects(_textRect)) { p.setFont(st::introHeaderFont->f); - p.drawText(textRect, lang(lng_phone_title), style::al_top); + p.drawText(_textRect, lang(lng_phone_title), style::al_top); p.setFont(st::introFont->f); - p.drawText(textRect, lang(lng_phone_desc), style::al_bottom); + p.drawText(_textRect, lang(lng_phone_desc), style::al_bottom); } - if (_a_error.animating() || error.length()) { - int32 errorY = _showSignup ? ((phone.y() + phone.height() + next.y() - st::introErrorFont->height) / 2) : (next.y() + next.height() + st::introErrorTop); + if (_a_error.animating() || _error.length()) { + int32 errorY = _showSignup ? ((_phone->y() + _phone->height() + _next->y() - st::introErrorFont->height) / 2) : (_next->y() + _next->height() + st::introErrorTop); p.setOpacity(a_errorAlpha.current()); p.setFont(st::introErrorFont); p.setPen(st::introErrorFg); - p.drawText(QRect(textRect.x(), errorY, textRect.width(), st::introErrorFont->height), error, style::al_top); + p.drawText(QRect(_textRect.x(), errorY, _textRect.width(), st::introErrorFont->height), _error, style::al_top); - if (_signup.isHidden() && _showSignup) { - p.drawPixmap(_signup.x(), _signup.y(), _signupCache); + if (_signup->isHidden() && _showSignup) { + p.drawPixmap(_signup->x(), _signup->y(), _signupCache); } } } void IntroPhone::resizeEvent(QResizeEvent *e) { if (e->oldSize().width() != width()) { - next.move((width() - next.width()) / 2, st::introBtnTop); - country.move((width() - country.width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top); - int phoneTop = country.y() + country.height() + st::introPhoneTop; - phone.move((width() - country.width()) / 2 + country.width() - st::inpIntroPhone.width, phoneTop); - code.move((width() - country.width()) / 2, phoneTop); + _next->move((width() - _next->width()) / 2, st::introBtnTop); + _country->move((width() - _country->width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top); + int phoneTop = _country->y() + _country->height() + st::introPhoneTop; + _phone->move((width() - _country->width()) / 2 + _country->width() - st::inpIntroPhone.width, phoneTop); + _code->move((width() - _country->width()) / 2, phoneTop); } - _signup.move((width() - _signup.width()) / 2, next.y() + next.height() + st::introErrorTop - ((st::introErrorLabelTextStyle.lineHeight - st::introErrorFont->height) / 2)); - textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height()); + _signup->move((width() - _signup->width()) / 2, _next->y() + _next->height() + st::introErrorTop - ((st::introErrorLabelTextStyle.lineHeight - st::introErrorFont->height) / 2)); + _textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height()); } -void IntroPhone::showError(const QString &err, bool signUp) { - if (!err.isEmpty()) { - phone.notaBene(); +void IntroPhone::showError(const QString &error, bool signUp) { + if (!error.isEmpty()) { + _phone->notaBene(); _showSignup = signUp; } - if (!_a_error.animating() && err == error) return; + if (!_a_error.animating() && error == _error) return; - if (err.length()) { - error = err; + if (error.length()) { + _error = error; a_errorAlpha.start(1); } else { a_errorAlpha.start(0); } - _signup.hide(); + _signup->hide(); _a_error.start(); } @@ -143,10 +143,10 @@ void IntroPhone::step_error(float64 ms, bool timer) { _a_error.stop(); a_errorAlpha.finish(); if (!a_errorAlpha.current()) { - error.clear(); - _signup.hide(); - } else if (!error.isEmpty() && _showSignup) { - _signup.show(); + _error.clear(); + _signup->hide(); + } else if (!_error.isEmpty() && _showSignup) { + _signup->show(); } } else { a_errorAlpha.update(dt, anim::linear); @@ -155,65 +155,64 @@ void IntroPhone::step_error(float64 ms, bool timer) { } void IntroPhone::countryChanged() { - if (!changed) { + if (!_changed) { selectCountry(intro()->currentCountry()); } } void IntroPhone::onInputChange() { - changed = true; + _changed = true; showError(QString()); } void IntroPhone::disableAll() { - next.setDisabled(true); - phone.setDisabled(true); - country.setDisabled(true); - code.setDisabled(true); + _next->setDisabled(true); + _phone->setDisabled(true); + _country->setDisabled(true); + _code->setDisabled(true); setFocus(); } void IntroPhone::enableAll(bool failed) { - next.setDisabled(false); - phone.setDisabled(false); - country.setDisabled(false); - code.setDisabled(false); - if (failed) phone.setFocus(); + _next->setDisabled(false); + _phone->setDisabled(false); + _country->setDisabled(false); + _code->setDisabled(false); + if (failed) _phone->setFocus(); } void IntroPhone::onSubmitPhone() { - if (sentRequest || isHidden()) return; + if (_sentRequest || isHidden()) return; if (!App::isValidPhone(fullNumber())) { showError(lang(lng_bad_phone)); - phone.setFocus(); + _phone->setFocus(); return; } disableAll(); showError(QString()); - checkRequest.start(1000); + _checkRequest->start(1000); - sentPhone = fullNumber(); - sentRequest = MTP::send(MTPauth_CheckPhone(MTP_string(sentPhone)), rpcDone(&IntroPhone::phoneCheckDone), rpcFail(&IntroPhone::phoneSubmitFail)); + _sentPhone = fullNumber(); + _sentRequest = MTP::send(MTPauth_CheckPhone(MTP_string(_sentPhone)), rpcDone(&IntroPhone::phoneCheckDone), rpcFail(&IntroPhone::phoneSubmitFail)); } void IntroPhone::stopCheck() { - checkRequest.stop(); + _checkRequest->stop(); } void IntroPhone::onCheckRequest() { - int32 status = MTP::state(sentRequest); + int32 status = MTP::state(_sentRequest); if (status < 0) { int32 leftms = -status; if (leftms >= 1000) { - MTP::cancel(sentRequest); - sentRequest = 0; - if (!phone.isEnabled()) enableAll(true); + MTP::cancel(base::take(_sentRequest)); + if (!_phone->isEnabled()) enableAll(true); } } - if (!sentRequest && status == MTP::RequestSent) { + if (!_sentRequest && status == MTP::RequestSent) { stopCheck(); } } @@ -226,20 +225,20 @@ void IntroPhone::phoneCheckDone(const MTPauth_CheckedPhone &result) { disableAll(); showError(QString()); - checkRequest.start(1000); + _checkRequest->start(1000); MTPauth_SendCode::Flags flags = 0; - sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(flags), MTP_string(sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail)); + _sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(flags), MTP_string(_sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail)); } else { showError(lang(lng_bad_phone_noreg), true); enableAll(true); - sentRequest = 0; + _sentRequest = 0; } } void IntroPhone::phoneSubmitDone(const MTPauth_SentCode &result) { stopCheck(); - sentRequest = 0; + _sentRequest = 0; enableAll(true); if (result.type() != mtpc_auth_sentCode) { @@ -254,7 +253,7 @@ void IntroPhone::phoneSubmitDone(const MTPauth_SentCode &result) { case mtpc_auth_sentCodeTypeCall: intro()->setCodeByTelegram(false); break; case mtpc_auth_sentCodeTypeFlashCall: LOG(("Error: should not be flashcall!")); break; } - intro()->setPhone(sentPhone, d.vphone_code_hash.c_string().v.c_str(), d.is_phone_registered()); + intro()->setPhone(_sentPhone, d.vphone_code_hash.c_string().v.c_str(), d.is_phone_registered()); if (d.has_next_type() && d.vnext_type.type() == mtpc_auth_codeTypeCall) { intro()->setCallStatus({ IntroWidget::CallWaiting, d.has_timeout() ? d.vtimeout.v : 60 }); } else { @@ -267,16 +266,16 @@ void IntroPhone::toSignUp() { disableAll(); showError(QString()); - checkRequest.start(1000); + _checkRequest->start(1000); MTPauth_SendCode::Flags flags = 0; - sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(flags), MTP_string(sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail)); + _sentRequest = MTP::send(MTPauth_SendCode(MTP_flags(flags), MTP_string(_sentPhone), MTPBool(), MTP_int(ApiId), MTP_string(ApiHash)), rpcDone(&IntroPhone::phoneSubmitDone), rpcFail(&IntroPhone::phoneSubmitFail)); } bool IntroPhone::phoneSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { stopCheck(); - sentRequest = 0; + _sentRequest = 0; showError(lang(lng_flood_error)); enableAll(true); return true; @@ -284,7 +283,7 @@ bool IntroPhone::phoneSubmitFail(const RPCError &error) { if (MTP::isDefaultHandledError(error)) return false; stopCheck(); - sentRequest = 0; + _sentRequest = 0; const QString &err = error.type(); if (err == qstr("PHONE_NUMBER_INVALID")) { // show error showError(lang(lng_bad_phone)); @@ -301,32 +300,31 @@ bool IntroPhone::phoneSubmitFail(const RPCError &error) { } QString IntroPhone::fullNumber() const { - return code.text() + phone.text(); + return _code->text() + _phone->text(); } void IntroPhone::selectCountry(const QString &c) { - country.onChooseCountry(c); + _country->onChooseCountry(c); } void IntroPhone::activate() { IntroStep::activate(); - phone.setFocus(); + _phone->setFocus(); } void IntroPhone::finished() { IntroStep::finished(); - checkRequest.stop(); + _checkRequest->stop(); rpcClear(); - error.clear(); + _error.clear(); a_errorAlpha = anim::fvalue(0); enableAll(true); } void IntroPhone::cancelled() { - if (sentRequest) { - MTP::cancel(sentRequest); - sentRequest = 0; + if (_sentRequest) { + MTP::cancel(base::take(_sentRequest)); } } diff --git a/Telegram/SourceFiles/intro/introphone.h b/Telegram/SourceFiles/intro/introphone.h index 8c53bc6b4..cf4786e73 100644 --- a/Telegram/SourceFiles/intro/introphone.h +++ b/Telegram/SourceFiles/intro/introphone.h @@ -25,11 +25,14 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "ui/flatlabel.h" #include "intro/introwidget.h" +namespace Ui { +class RoundButton; +} // namespace Ui + class IntroPhone final : public IntroStep { Q_OBJECT public: - IntroPhone(IntroWidget *parent); void paintEvent(QPaintEvent *e) override; @@ -51,14 +54,12 @@ public: void toSignUp(); public slots: - void countryChanged(); void onInputChange(); void onSubmitPhone(); void onCheckRequest(); private: - QString fullNumber() const; void disableAll(); void enableAll(bool failed); @@ -66,25 +67,26 @@ private: void showError(const QString &err, bool signUp = false); - QString error; + QString _error; anim::fvalue a_errorAlpha; Animation _a_error; - bool changed; - FlatButton next; + bool _changed = false; + ChildWidget _next; - QRect textRect; + QRect _textRect; - CountryInput country; - PhonePartInput phone; - CountryCodeInput code; + ChildWidget _country; + ChildWidget _phone; + ChildWidget _code; - FlatLabel _signup; + ChildWidget _signup; QPixmap _signupCache; - bool _showSignup; + bool _showSignup = false; - QString sentPhone; - mtpRequestId sentRequest; + QString _sentPhone; + mtpRequestId _sentRequest = 0; + + ChildObject _checkRequest; - QTimer checkRequest; }; diff --git a/Telegram/SourceFiles/intro/intropwdcheck.cpp b/Telegram/SourceFiles/intro/intropwdcheck.cpp index c603206aa..d04c3dadd 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.cpp +++ b/Telegram/SourceFiles/intro/intropwdcheck.cpp @@ -27,6 +27,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "lang.h" #include "application.h" #include "intro/introsignup.h" +#include "ui/buttons/round_button.h" IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStep(parent) , a_errorAlpha(0) @@ -40,27 +41,28 @@ IntroPwdCheck::IntroPwdCheck(IntroWidget *parent) : IntroStep(parent) , _toRecover(this, lang(lng_signin_recover)) , _toPassword(this, lang(lng_signin_try_password)) , _reset(this, lang(lng_signin_reset_account), st::btnRedLink) -, sentRequest(0) { +, _checkRequest(this) { setVisible(false); setGeometry(parent->innerRect()); - connect(&_next, SIGNAL(clicked()), this, SLOT(onSubmitPwd())); - connect(&checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); - connect(&_toRecover, SIGNAL(clicked()), this, SLOT(onToRecover())); - connect(&_toPassword, SIGNAL(clicked()), this, SLOT(onToPassword())); - connect(&_pwdField, SIGNAL(changed()), this, SLOT(onInputChange())); - connect(&_codeField, SIGNAL(changed()), this, SLOT(onInputChange())); - connect(&_reset, SIGNAL(clicked()), this, SLOT(onReset())); + _next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); + connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitPwd())); + connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); + connect(_toRecover, SIGNAL(clicked()), this, SLOT(onToRecover())); + connect(_toPassword, SIGNAL(clicked()), this, SLOT(onToPassword())); + connect(_pwdField, SIGNAL(changed()), this, SLOT(onInputChange())); + connect(_codeField, SIGNAL(changed()), this, SLOT(onInputChange())); + connect(_reset, SIGNAL(clicked()), this, SLOT(onReset())); - _pwdField.setEchoMode(QLineEdit::Password); + _pwdField->setEchoMode(QLineEdit::Password); if (!_hint.isEmpty()) { _hintText.setText(st::introFont, lng_signin_hint(lt_password_hint, _hint)); } - _codeField.hide(); - _toPassword.hide(); - _toRecover.show(); - _reset.hide(); + _codeField->hide(); + _toPassword->hide(); + _toRecover->show(); + _reset->hide(); setMouseTracking(true); } @@ -72,26 +74,26 @@ void IntroPwdCheck::paintEvent(QPaintEvent *e) { if (!trivial) { p.setClipRect(e->rect()); } - if (trivial || e->rect().intersects(textRect)) { + if (trivial || e->rect().intersects(_textRect)) { p.setFont(st::introHeaderFont->f); - p.drawText(textRect, lang(lng_signin_title), style::al_top); + p.drawText(_textRect, lang(lng_signin_title), style::al_top); p.setFont(st::introFont->f); - p.drawText(textRect, lang(_pwdField.isHidden() ? lng_signin_recover_desc : lng_signin_desc), style::al_bottom); + p.drawText(_textRect, lang(_pwdField->isHidden() ? lng_signin_recover_desc : lng_signin_desc), style::al_bottom); } - if (_pwdField.isHidden()) { + if (_pwdField->isHidden()) { if (!_emailPattern.isEmpty()) { - p.drawText(QRect(textRect.x(), _pwdField.y() + _pwdField.height() + st::introFinishSkip, textRect.width(), st::introFont->height), _emailPattern, style::al_top); + p.drawText(QRect(_textRect.x(), _pwdField->y() + _pwdField->height() + st::introFinishSkip, _textRect.width(), st::introFont->height), _emailPattern, style::al_top); } } else if (!_hint.isEmpty()) { - _hintText.drawElided(p, _pwdField.x(), _pwdField.y() + _pwdField.height() + st::introFinishSkip, _pwdField.width(), 1, style::al_top); + _hintText.drawElided(p, _pwdField->x(), _pwdField->y() + _pwdField->height() + st::introFinishSkip, _pwdField->width(), 1, style::al_top); } - if (_a_error.animating() || error.length()) { + if (_a_error.animating() || _error.length()) { p.setOpacity(a_errorAlpha.current()); - QRect errRect((width() - st::introErrorWidth) / 2, (_pwdField.y() + _pwdField.height() + st::introFinishSkip + st::introFont->height + _next.y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight); + QRect errRect((width() - st::introErrorWidth) / 2, (_pwdField->y() + _pwdField->height() + st::introFinishSkip + st::introFont->height + _next->y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight); p.setFont(st::introErrorFont); p.setPen(st::introErrorFg); - p.drawText(errRect, error, QTextOption(style::al_center)); + p.drawText(errRect, _error, QTextOption(style::al_center)); p.setOpacity(1); } @@ -99,21 +101,21 @@ void IntroPwdCheck::paintEvent(QPaintEvent *e) { void IntroPwdCheck::resizeEvent(QResizeEvent *e) { if (e->oldSize().width() != width()) { - _next.move((width() - _next.width()) / 2, st::introBtnTop); - _pwdField.move((width() - _pwdField.width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top); - _codeField.move((width() - _codeField.width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top); - _toRecover.move(_next.x() + (_pwdField.width() - _toRecover.width()) / 2, _next.y() + _next.height() + st::introFinishSkip); - _toPassword.move(_next.x() + (_pwdField.width() - _toPassword.width()) / 2, _next.y() + _next.height() + st::introFinishSkip); - _reset.move((width() - _reset.width()) / 2, _toRecover.y() + _toRecover.height() + st::introFinishSkip); + _next->move((width() - _next->width()) / 2, st::introBtnTop); + _pwdField->move((width() - _pwdField->width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top); + _codeField->move((width() - _codeField->width()) / 2, st::introTextTop + st::introTextSize.height() + st::introCountry.top); + _toRecover->move(_next->x() + (_pwdField->width() - _toRecover->width()) / 2, _next->y() + _next->height() + st::introFinishSkip); + _toPassword->move(_next->x() + (_pwdField->width() - _toPassword->width()) / 2, _next->y() + _next->height() + st::introFinishSkip); + _reset->move((width() - _reset->width()) / 2, _toRecover->y() + _toRecover->height() + st::introFinishSkip); } - textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height()); + _textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height()); } -void IntroPwdCheck::showError(const QString &err) { - if (!_a_error.animating() && err == error) return; +void IntroPwdCheck::showError(const QString &error) { + if (!_a_error.animating() && error == _error) return; - if (err.length()) { - error = err; + if (error.length()) { + _error = error; a_errorAlpha.start(1); } else { a_errorAlpha.start(0); @@ -128,7 +130,7 @@ void IntroPwdCheck::step_error(float64 ms, bool timer) { _a_error.stop(); a_errorAlpha.finish(); if (!a_errorAlpha.current()) { - error.clear(); + _error.clear(); } } else { a_errorAlpha.update(dt, anim::linear); @@ -138,51 +140,49 @@ void IntroPwdCheck::step_error(float64 ms, bool timer) { void IntroPwdCheck::activate() { IntroStep::activate(); - if (_pwdField.isHidden()) { - _codeField.setFocus(); + if (_pwdField->isHidden()) { + _codeField->setFocus(); } else { - _pwdField.setFocus(); + _pwdField->setFocus(); } } void IntroPwdCheck::cancelled() { - if (sentRequest) { - MTP::cancel(sentRequest); - sentRequest = 0; + if (_sentRequest) { + MTP::cancel(base::take(_sentRequest)); } } void IntroPwdCheck::stopCheck() { - checkRequest.stop(); + _checkRequest->stop(); } void IntroPwdCheck::onCheckRequest() { - int32 status = MTP::state(sentRequest); + int32 status = MTP::state(_sentRequest); if (status < 0) { int32 leftms = -status; if (leftms >= 1000) { - MTP::cancel(sentRequest); - sentRequest = 0; - if (!_pwdField.isEnabled()) { - _pwdField.setDisabled(false); - _codeField.setDisabled(false); + MTP::cancel(base::take(_sentRequest)); + if (!_pwdField->isEnabled()) { + _pwdField->setDisabled(false); + _codeField->setDisabled(false); activate(); } } } - if (!sentRequest && status == MTP::RequestSent) { + if (!_sentRequest && status == MTP::RequestSent) { stopCheck(); } } void IntroPwdCheck::pwdSubmitDone(bool recover, const MTPauth_Authorization &result) { - sentRequest = 0; + _sentRequest = 0; stopCheck(); if (recover) { cSetPasswordRecovered(true); } - _pwdField.setDisabled(false); - _codeField.setDisabled(false); + _pwdField->setDisabled(false); + _codeField->setDisabled(false); const auto &d(result.c_auth_authorization()); if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf? showError(lang(lng_server_error)); @@ -193,25 +193,25 @@ void IntroPwdCheck::pwdSubmitDone(bool recover, const MTPauth_Authorization &res bool IntroPwdCheck::pwdSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { - sentRequest = 0; + _sentRequest = 0; stopCheck(); - _codeField.setDisabled(false); + _codeField->setDisabled(false); showError(lang(lng_flood_error)); - _pwdField.setDisabled(false); - _pwdField.notaBene(); + _pwdField->setDisabled(false); + _pwdField->notaBene(); return true; } if (MTP::isDefaultHandledError(error)) return false; - sentRequest = 0; + _sentRequest = 0; stopCheck(); - _pwdField.setDisabled(false); - _codeField.setDisabled(false); + _pwdField->setDisabled(false); + _codeField->setDisabled(false); const QString &err = error.type(); if (err == qstr("PASSWORD_HASH_INVALID")) { showError(lang(lng_signin_bad_password)); - _pwdField.selectAll(); - _pwdField.notaBene(); + _pwdField->selectAll(); + _pwdField->notaBene(); return true; } else if (err == qstr("PASSWORD_EMPTY")) { intro()->onBack(); @@ -221,22 +221,22 @@ bool IntroPwdCheck::pwdSubmitFail(const RPCError &error) { } else { showError(lang(lng_server_error)); } - _pwdField.setFocus(); + _pwdField->setFocus(); return false; } bool IntroPwdCheck::codeSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { showError(lang(lng_flood_error)); - _codeField.notaBene(); + _codeField->notaBene(); return true; } if (MTP::isDefaultHandledError(error)) return false; - sentRequest = 0; + _sentRequest = 0; stopCheck(); - _pwdField.setDisabled(false); - _codeField.setDisabled(false); + _pwdField->setDisabled(false); + _codeField->setDisabled(false); const QString &err = error.type(); if (err == qstr("PASSWORD_EMPTY")) { intro()->onBack(); @@ -250,8 +250,8 @@ bool IntroPwdCheck::codeSubmitFail(const RPCError &error) { return true; } else if (err == qstr("CODE_INVALID")) { showError(lang(lng_signin_wrong_code)); - _codeField.selectAll(); - _codeField.notaBene(); + _codeField->selectAll(); + _codeField->notaBene(); return true; } if (cDebug()) { // internal server error @@ -259,22 +259,22 @@ bool IntroPwdCheck::codeSubmitFail(const RPCError &error) { } else { showError(lang(lng_server_error)); } - _codeField.setFocus(); + _codeField->setFocus(); return false; } void IntroPwdCheck::recoverStarted(const MTPauth_PasswordRecovery &result) { - _emailPattern = st::introFont->elided(lng_signin_recover_hint(lt_recover_email, qs(result.c_auth_passwordRecovery().vemail_pattern)), textRect.width()); + _emailPattern = st::introFont->elided(lng_signin_recover_hint(lt_recover_email, qs(result.c_auth_passwordRecovery().vemail_pattern)), _textRect.width()); update(); } bool IntroPwdCheck::recoverStartFail(const RPCError &error) { stopCheck(); - _pwdField.setDisabled(false); - _codeField.setDisabled(false); - _pwdField.show(); - _codeField.hide(); - _pwdField.setFocus(); + _pwdField->setDisabled(false); + _codeField->setDisabled(false); + _pwdField->show(); + _codeField->hide(); + _pwdField->setFocus(); update(); showError(QString()); return true; @@ -282,17 +282,16 @@ bool IntroPwdCheck::recoverStartFail(const RPCError &error) { void IntroPwdCheck::onToRecover() { if (_hasRecovery) { - if (sentRequest) { - MTP::cancel(sentRequest); - sentRequest = 0; + if (_sentRequest) { + MTP::cancel(base::take(_sentRequest)); } showError(QString()); - _toRecover.hide(); - _toPassword.show(); - _pwdField.hide(); - _pwdField.setText(QString()); - _codeField.show(); - _codeField.setFocus(); + _toRecover->hide(); + _toPassword->show(); + _pwdField->hide(); + _pwdField->setText(QString()); + _codeField->show(); + _codeField->setFocus(); if (_emailPattern.isEmpty()) { MTP::send(MTPauth_RequestPasswordRecovery(), rpcDone(&IntroPwdCheck::recoverStarted), rpcFail(&IntroPwdCheck::recoverStartFail)); } @@ -311,36 +310,35 @@ void IntroPwdCheck::onToPassword() { } void IntroPwdCheck::onToReset() { - if (sentRequest) { - MTP::cancel(sentRequest); - sentRequest = 0; + if (_sentRequest) { + MTP::cancel(base::take(_sentRequest)); } - _toRecover.show(); - _toPassword.hide(); - _pwdField.show(); - _codeField.hide(); - _codeField.setText(QString()); - _pwdField.setFocus(); - _reset.show(); + _toRecover->show(); + _toPassword->hide(); + _pwdField->show(); + _codeField->hide(); + _codeField->setText(QString()); + _pwdField->setFocus(); + _reset->show(); update(); } void IntroPwdCheck::onReset() { - if (sentRequest) return; + if (_sentRequest) return; ConfirmBox *box = new ConfirmBox(lang(lng_signin_sure_reset), lang(lng_signin_reset), st::attentionBoxButton); connect(box, SIGNAL(confirmed()), this, SLOT(onResetSure())); Ui::showLayer(box); } void IntroPwdCheck::onResetSure() { - if (sentRequest) return; - sentRequest = MTP::send(MTPaccount_DeleteAccount(MTP_string("Forgot password")), rpcDone(&IntroPwdCheck::deleteDone), rpcFail(&IntroPwdCheck::deleteFail)); + if (_sentRequest) return; + _sentRequest = MTP::send(MTPaccount_DeleteAccount(MTP_string("Forgot password")), rpcDone(&IntroPwdCheck::deleteDone), rpcFail(&IntroPwdCheck::deleteFail)); } bool IntroPwdCheck::deleteFail(const RPCError &error) { if (MTP::isDefaultHandledError(error)) return false; - sentRequest = 0; + _sentRequest = 0; auto type = error.type(); if (type.startsWith(qstr("2FA_CONFIRM_WAIT_"))) { @@ -376,27 +374,27 @@ void IntroPwdCheck::onInputChange() { } void IntroPwdCheck::onSubmitPwd(bool force) { - if (sentRequest) return; - if (_pwdField.isHidden()) { - if (!force && !_codeField.isEnabled()) return; - QString code = _codeField.text().trimmed(); + if (_sentRequest) return; + if (_pwdField->isHidden()) { + if (!force && !_codeField->isEnabled()) return; + QString code = _codeField->text().trimmed(); if (code.isEmpty()) { - _codeField.notaBene(); + _codeField->notaBene(); return; } - sentRequest = MTP::send(MTPauth_RecoverPassword(MTP_string(code)), rpcDone(&IntroPwdCheck::pwdSubmitDone, true), rpcFail(&IntroPwdCheck::codeSubmitFail)); + _sentRequest = MTP::send(MTPauth_RecoverPassword(MTP_string(code)), rpcDone(&IntroPwdCheck::pwdSubmitDone, true), rpcFail(&IntroPwdCheck::codeSubmitFail)); } else { - if (!force && !_pwdField.isEnabled()) return; + if (!force && !_pwdField->isEnabled()) return; - _pwdField.setDisabled(true); + _pwdField->setDisabled(true); setFocus(); showError(QString()); - QByteArray pwdData = _salt + _pwdField.text().toUtf8() + _salt, pwdHash(32, Qt::Uninitialized); + QByteArray pwdData = _salt + _pwdField->text().toUtf8() + _salt, pwdHash(32, Qt::Uninitialized); hashSha256(pwdData.constData(), pwdData.size(), pwdHash.data()); - sentRequest = MTP::send(MTPauth_CheckPassword(MTP_bytes(pwdHash)), rpcDone(&IntroPwdCheck::pwdSubmitDone, false), rpcFail(&IntroPwdCheck::pwdSubmitFail)); + _sentRequest = MTP::send(MTPauth_CheckPassword(MTP_bytes(pwdHash)), rpcDone(&IntroPwdCheck::pwdSubmitDone, false), rpcFail(&IntroPwdCheck::pwdSubmitFail)); } } diff --git a/Telegram/SourceFiles/intro/intropwdcheck.h b/Telegram/SourceFiles/intro/intropwdcheck.h index 580e0080b..01c37b7cf 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.h +++ b/Telegram/SourceFiles/intro/intropwdcheck.h @@ -20,16 +20,17 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include -#include "ui/flatbutton.h" #include "ui/flatinput.h" #include "intro/introwidget.h" +namespace Ui { +class RoundButton; +} // namespace Ui + class IntroPwdCheck final : public IntroStep { Q_OBJECT public: - IntroPwdCheck(IntroWidget *parent); void paintEvent(QPaintEvent *e) override; @@ -49,7 +50,6 @@ public: void recoverStarted(const MTPauth_PasswordRecovery &result); public slots: - void onSubmitPwd(bool force = false); void onToRecover(); void onToPassword(); @@ -60,32 +60,35 @@ public slots: void onResetSure(); private: - - void showError(const QString &err); + void showError(const QString &error); void stopCheck(); void deleteDone(const MTPBool &result); bool deleteFail(const RPCError &error); - QString error; + QString _error; anim::fvalue a_errorAlpha; Animation _a_error; - FlatButton _next; + ChildWidget _next; - QRect textRect; + QRect _textRect; QByteArray _salt; bool _hasRecovery; QString _hint, _emailPattern; - FlatInput _pwdField, _codeField; - LinkButton _toRecover, _toPassword, _reset; - mtpRequestId sentRequest; + ChildWidget _pwdField; + ChildWidget _codeField; + ChildWidget _toRecover; + ChildWidget _toPassword; + ChildWidget _reset; + mtpRequestId _sentRequest = 0; Text _hintText; QByteArray _pwdSalt; - QTimer checkRequest; + ChildObject _checkRequest; + }; diff --git a/Telegram/SourceFiles/intro/introsignup.cpp b/Telegram/SourceFiles/intro/introsignup.cpp index 4fa4f795b..0f674e5d5 100644 --- a/Telegram/SourceFiles/intro/introsignup.cpp +++ b/Telegram/SourceFiles/intro/introsignup.cpp @@ -27,25 +27,27 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "boxes/photocropbox.h" #include "lang.h" #include "application.h" +#include "ui/buttons/round_button.h" IntroSignup::IntroSignup(IntroWidget *parent) : IntroStep(parent) , a_errorAlpha(0) , a_photoOver(0) , _a_error(animation(this, &IntroSignup::step_error)) , _a_photo(animation(this, &IntroSignup::step_photo)) -, next(this, lang(lng_intro_finish), st::introNextButton) -, first(this, st::inpIntroName, lang(lng_signup_firstname)) -, last(this, st::inpIntroName, lang(lng_signup_lastname)) -, sentRequest(0) -, _invertOrder(langFirstNameGoesSecond()) { +, _next(this, lang(lng_intro_finish), st::introNextButton) +, _first(this, st::inpIntroName, lang(lng_signup_firstname)) +, _last(this, st::inpIntroName, lang(lng_signup_lastname)) +, _invertOrder(langFirstNameGoesSecond()) +, _checkRequest(this) { setVisible(false); setGeometry(parent->innerRect()); - connect(&next, SIGNAL(clicked()), this, SLOT(onSubmitName())); - connect(&checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); + _next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); + connect(_next, SIGNAL(clicked()), this, SLOT(onSubmitName())); + connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); if (_invertOrder) { - setTabOrder(&last, &first); + setTabOrder(_last, _first); } setMouseTracking(true); @@ -102,20 +104,20 @@ void IntroSignup::paintEvent(QPaintEvent *e) { if (!trivial) { p.setClipRect(e->rect()); } - if (trivial || e->rect().intersects(textRect)) { + if (trivial || e->rect().intersects(_textRect)) { p.setFont(st::introHeaderFont->f); - p.drawText(textRect, lang(lng_signup_title), style::al_top); + p.drawText(_textRect, lang(lng_signup_title), style::al_top); p.setFont(st::introFont->f); - p.drawText(textRect, lang(lng_signup_desc), style::al_bottom); + p.drawText(_textRect, lang(lng_signup_desc), style::al_bottom); } if (_a_error.animating() || error.length()) { p.setOpacity(a_errorAlpha.current()); QRect errRect; if (_invertOrder) { - errRect = QRect((width() - st::introErrorWidth) / 2, (first.y() + first.height() + next.y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight); + errRect = QRect((width() - st::introErrorWidth) / 2, (_first->y() + _first->height() + _next->y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight); } else { - errRect = QRect((width() - st::introErrorWidth) / 2, (last.y() + last.height() + next.y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight); + errRect = QRect((width() - st::introErrorWidth) / 2, (_last->y() + _last->height() + _next->y() - st::introErrorHeight) / 2, st::introErrorWidth, st::introErrorHeight); } p.setFont(st::introErrorFont); p.setPen(st::introErrorFg); @@ -147,19 +149,19 @@ void IntroSignup::paintEvent(QPaintEvent *e) { } void IntroSignup::resizeEvent(QResizeEvent *e) { - _phLeft = (width() - next.width()) / 2; + _phLeft = (width() - _next->width()) / 2; _phTop = st::introTextTop + st::introTextSize.height() + st::introCountry.top; if (e->oldSize().width() != width()) { - next.move((width() - next.width()) / 2, st::introBtnTop); + _next->move((width() - _next->width()) / 2, st::introBtnTop); if (_invertOrder) { - last.move((width() - next.width()) / 2 + next.width() - last.width(), _phTop); - first.move((width() - next.width()) / 2 + next.width() - first.width(), last.y() + st::introCountry.height + st::introCountry.ptrSize.height() + st::introPhoneTop); + _last->move((width() - _next->width()) / 2 + _next->width() - _last->width(), _phTop); + _first->move((width() - _next->width()) / 2 + _next->width() - _first->width(), _last->y() + st::introCountry.height + st::introCountry.ptrSize.height() + st::introPhoneTop); } else { - first.move((width() - next.width()) / 2 + next.width() - first.width(), _phTop); - last.move((width() - next.width()) / 2 + next.width() - last.width(), first.y() + st::introCountry.height + st::introCountry.ptrSize.height() + st::introPhoneTop); + _first->move((width() - _next->width()) / 2 + _next->width() - _first->width(), _phTop); + _last->move((width() - _next->width()) / 2 + _next->width() - _last->width(), _first->y() + st::introCountry.height + st::introCountry.ptrSize.height() + st::introPhoneTop); } } - textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height()); + _textRect = QRect((width() - st::introTextSize.width()) / 2, st::introTextTop, st::introTextSize.width(), st::introTextSize.height()); } void IntroSignup::showError(const QString &err) { @@ -204,42 +206,40 @@ void IntroSignup::step_photo(float64 ms, bool timer) { void IntroSignup::activate() { IntroStep::activate(); if (_invertOrder) { - last.setFocus(); + _last->setFocus(); } else { - first.setFocus(); + _first->setFocus(); } } void IntroSignup::cancelled() { - if (sentRequest) { - MTP::cancel(sentRequest); - sentRequest = 0; + if (_sentRequest) { + MTP::cancel(base::take(_sentRequest)); } } void IntroSignup::stopCheck() { - checkRequest.stop(); + _checkRequest->stop(); } void IntroSignup::onCheckRequest() { - int32 status = MTP::state(sentRequest); + int32 status = MTP::state(_sentRequest); if (status < 0) { int32 leftms = -status; if (leftms >= 1000) { - MTP::cancel(sentRequest); - sentRequest = 0; - if (!first.isEnabled()) { - first.setDisabled(false); - last.setDisabled(false); + MTP::cancel(base::take(_sentRequest)); + if (!_first->isEnabled()) { + _first->setDisabled(false); + _last->setDisabled(false); if (_invertOrder) { - first.setFocus(); + _first->setFocus(); } else { - last.setFocus(); + _last->setFocus(); } } } } - if (!sentRequest && status == MTP::RequestSent) { + if (!_sentRequest && status == MTP::RequestSent) { stopCheck(); } } @@ -252,8 +252,8 @@ void IntroSignup::onPhotoReady(const QImage &img) { void IntroSignup::nameSubmitDone(const MTPauth_Authorization &result) { stopCheck(); - first.setDisabled(false); - last.setDisabled(false); + _first->setDisabled(false); + _last->setDisabled(false); const auto &d(result.c_auth_authorization()); if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf? showError(lang(lng_server_error)); @@ -265,21 +265,21 @@ void IntroSignup::nameSubmitDone(const MTPauth_Authorization &result) { bool IntroSignup::nameSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { stopCheck(); - first.setDisabled(false); - last.setDisabled(false); + _first->setDisabled(false); + _last->setDisabled(false); showError(lang(lng_flood_error)); if (_invertOrder) { - first.setFocus(); + _first->setFocus(); } else { - last.setFocus(); + _last->setFocus(); } return true; } if (MTP::isDefaultHandledError(error)) return false; stopCheck(); - first.setDisabled(false); - last.setDisabled(false); + _first->setDisabled(false); + _last->setDisabled(false); const QString &err = error.type(); if (err == qstr("PHONE_NUMBER_INVALID") || err == qstr("PHONE_CODE_EXPIRED") || err == qstr("PHONE_CODE_EMPTY") || err == qstr("PHONE_CODE_INVALID") || @@ -288,11 +288,11 @@ bool IntroSignup::nameSubmitFail(const RPCError &error) { return true; } else if (err == "FIRSTNAME_INVALID") { showError(lang(lng_bad_name)); - first.setFocus(); + _first->setFocus(); return true; } else if (err == "LASTNAME_INVALID") { showError(lang(lng_bad_name)); - last.setFocus(); + _last->setFocus(); return true; } if (cDebug()) { // internal server error @@ -301,9 +301,9 @@ bool IntroSignup::nameSubmitFail(const RPCError &error) { showError(lang(lng_server_error)); } if (_invertOrder) { - last.setFocus(); + _last->setFocus(); } else { - first.setFocus(); + _first->setFocus(); } return false; } @@ -314,33 +314,33 @@ void IntroSignup::onInputChange() { void IntroSignup::onSubmitName(bool force) { if (_invertOrder) { - if ((last.hasFocus() || last.text().trimmed().length()) && !first.text().trimmed().length()) { - first.setFocus(); + if ((_last->hasFocus() || _last->text().trimmed().length()) && !_first->text().trimmed().length()) { + _first->setFocus(); return; - } else if (!last.text().trimmed().length()) { - last.setFocus(); + } else if (!_last->text().trimmed().length()) { + _last->setFocus(); return; } } else { - if ((first.hasFocus() || first.text().trimmed().length()) && !last.text().trimmed().length()) { - last.setFocus(); + if ((_first->hasFocus() || _first->text().trimmed().length()) && !_last->text().trimmed().length()) { + _last->setFocus(); return; - } else if (!first.text().trimmed().length()) { - first.setFocus(); + } else if (!_first->text().trimmed().length()) { + _first->setFocus(); return; } } - if (!force && !first.isEnabled()) return; + if (!force && !_first->isEnabled()) return; - first.setDisabled(true); - last.setDisabled(true); + _first->setDisabled(true); + _last->setDisabled(true); setFocus(); showError(QString()); - firstName = first.text().trimmed(); - lastName = last.text().trimmed(); - sentRequest = MTP::send(MTPauth_SignUp(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash()), MTP_string(intro()->getCode()), MTP_string(firstName), MTP_string(lastName)), rpcDone(&IntroSignup::nameSubmitDone), rpcFail(&IntroSignup::nameSubmitFail)); + _firstName = _first->text().trimmed(); + _lastName = _last->text().trimmed(); + _sentRequest = MTP::send(MTPauth_SignUp(MTP_string(intro()->getPhone()), MTP_string(intro()->getPhoneHash()), MTP_string(intro()->getCode()), MTP_string(_firstName), MTP_string(_lastName)), rpcDone(&IntroSignup::nameSubmitDone), rpcFail(&IntroSignup::nameSubmitFail)); } void IntroSignup::onSubmit() { diff --git a/Telegram/SourceFiles/intro/introsignup.h b/Telegram/SourceFiles/intro/introsignup.h index 2d9a00c21..3b7535ec8 100644 --- a/Telegram/SourceFiles/intro/introsignup.h +++ b/Telegram/SourceFiles/intro/introsignup.h @@ -20,16 +20,18 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -#include #include "ui/flatbutton.h" #include "ui/flatinput.h" #include "intro/introwidget.h" +namespace Ui { +class RoundButton; +} // namespace Ui + class IntroSignup final : public IntroStep { Q_OBJECT public: - IntroSignup(IntroWidget *parent); void paintEvent(QPaintEvent *e) override; @@ -48,14 +50,12 @@ public: bool nameSubmitFail(const RPCError &error); public slots: - void onSubmitName(bool force = false); void onInputChange(); void onCheckRequest(); void onPhotoReady(const QImage &img); private: - void showError(const QString &err); void stopCheck(); @@ -64,20 +64,22 @@ private: Animation _a_error; Animation _a_photo; - FlatButton next; + ChildWidget _next; - QRect textRect; + QRect _textRect; - bool _photoOver; + bool _photoOver = false; QImage _photoBig; QPixmap _photoSmall; int32 _phLeft, _phTop; - FlatInput first, last; - QString firstName, lastName; - mtpRequestId sentRequest; + ChildWidget _first; + ChildWidget _last; + QString _firstName, _lastName; + mtpRequestId _sentRequest = 0; - bool _invertOrder; + bool _invertOrder = false; + + ChildObject _checkRequest; - QTimer checkRequest; }; diff --git a/Telegram/SourceFiles/intro/introstart.cpp b/Telegram/SourceFiles/intro/introstart.cpp index 60a7117b6..6c24ab9e8 100644 --- a/Telegram/SourceFiles/intro/introstart.cpp +++ b/Telegram/SourceFiles/intro/introstart.cpp @@ -25,36 +25,38 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "application.h" #include "intro/introphone.h" #include "langloaderplain.h" +#include "ui/buttons/round_button.h" IntroStart::IntroStart(IntroWidget *parent) : IntroStep(parent) , _intro(this, lang(lng_intro), FlatLabel::InitType::Rich, st::introLabel, st::introLabelTextStyle) , _changeLang(this, QString()) , _next(this, lang(lng_start_msgs), st::introNextButton) { - _changeLang.hide(); + _changeLang->hide(); if (cLang() == languageDefault) { int32 l = Sandbox::LangSystem(); if (l != languageDefault) { LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[l].c_str() + qsl(".strings"), langLoaderRequest(lng_switch_to_this)); QString text = loader.found().value(lng_switch_to_this); if (!text.isEmpty()) { - _changeLang.setText(text); + _changeLang->setText(text); parent->langChangeTo(l); - _changeLang.show(); + _changeLang->show(); } } } else { - _changeLang.setText(langOriginal(lng_switch_to_this)); + _changeLang->setText(langOriginal(lng_switch_to_this)); parent->langChangeTo(languageDefault); - _changeLang.show(); + _changeLang->show(); } _headerWidth = st::introHeaderFont->width(qsl("Telegram Desktop")); setGeometry(parent->innerRect()); - connect(&_next, SIGNAL(clicked()), parent, SLOT(onStepSubmit())); + _next->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); + connect(_next, SIGNAL(clicked()), parent, SLOT(onStepSubmit())); - connect(&_changeLang, SIGNAL(clicked()), parent, SLOT(onChangeLang())); + connect(_changeLang, SIGNAL(clicked()), parent, SLOT(onChangeLang())); setMouseTracking(true); } @@ -66,7 +68,7 @@ void IntroStart::paintEvent(QPaintEvent *e) { if (!trivial) { p.setClipRect(e->rect()); } - int32 hy = _intro.y() - st::introHeaderFont->height - st::introHeaderSkip + st::introHeaderFont->ascent; + int32 hy = _intro->y() - st::introHeaderFont->height - st::introHeaderSkip + st::introHeaderFont->ascent; p.setFont(st::introHeaderFont); p.setPen(st::introHeaderFg); @@ -77,9 +79,9 @@ void IntroStart::paintEvent(QPaintEvent *e) { void IntroStart::resizeEvent(QResizeEvent *e) { if (e->oldSize().width() != width()) { - _next.move((width() - _next.width()) / 2, st::introBtnTop); - _intro.move((width() - _intro.width()) / 2, _next.y() - _intro.height() - st::introSkip); - _changeLang.move((width() - _changeLang.width()) / 2, _next.y() + _next.height() + _changeLang.height()); + _next->move((width() - _next->width()) / 2, st::introBtnTop); + _intro->move((width() - _intro->width()) / 2, _next->y() - _intro->height() - st::introSkip); + _changeLang->move((width() - _changeLang->width()) / 2, _next->y() + _next->height() + _changeLang->height()); } } diff --git a/Telegram/SourceFiles/intro/introstart.h b/Telegram/SourceFiles/intro/introstart.h index c9665476e..9ad5733b6 100644 --- a/Telegram/SourceFiles/intro/introstart.h +++ b/Telegram/SourceFiles/intro/introstart.h @@ -23,9 +23,12 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "intro/introwidget.h" #include "ui/flatlabel.h" +namespace Ui { +class RoundButton; +} // namespace Ui + class IntroStart final : public IntroStep { public: - IntroStart(IntroWidget *parent); void paintEvent(QPaintEvent *e) override; @@ -34,11 +37,12 @@ public: void onSubmit() override; private: + ChildWidget _intro; - FlatLabel _intro; + ChildWidget _changeLang; - LinkButton _changeLang; + ChildWidget _next; + + int32 _headerWidth = 0; - FlatButton _next; - int32 _headerWidth; }; diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index 5a225e54a..58c63c048 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -338,7 +338,7 @@ void IntroWidget::resizeEvent(QResizeEvent *e) { } void IntroWidget::finish(const MTPUser &user, const QImage &photo) { - App::wnd()->setupMain(true, &user); + App::wnd()->setupMain(&user); if (!photo.isNull()) { App::app()->uploadProfilePhoto(photo, MTP::authedId()); } diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index c91a2b906..37a9c943c 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -255,9 +255,9 @@ void MainWindow::clearPasscode() { } } -void MainWindow::setupPasscode(bool anim) { - auto bg = grabInner(); - +void MainWindow::setupPasscode() { + auto animated = (_main || _intro); + auto bg = animated ? grabInner() : QPixmap(); if (_passcode) { _passcode->stop_show(); _passcode.destroyDelayed(); @@ -270,7 +270,7 @@ void MainWindow::setupPasscode(bool anim) { _settings.destroyDelayed(); } if (_intro) _intro->hide(); - if (anim) { + if (animated) { _passcode->animShow(bg); } else { setInnerFocus(); @@ -294,14 +294,14 @@ void MainWindow::checkAutoLock() { App::app()->checkLocalTime(); uint64 ms = getms(true), idle = psIdleTime(), should = Global::AutoLock() * 1000ULL; if (idle >= should || (_shouldLockAt > 0 && ms > _shouldLockAt + 3000ULL)) { - setupPasscode(true); + setupPasscode(); } else { _shouldLockAt = ms + (should - idle); _autoLockTimer.start(should - idle); } } -void MainWindow::setupIntro(bool anim) { +void MainWindow::setupIntro() { cSetContactsReceived(false); cSetDialogsReceived(false); if (_intro && !_intro->isHidden() && !_main) return; @@ -311,14 +311,17 @@ void MainWindow::setupIntro(bool anim) { } Ui::hideSettingsAndLayer(true); - QPixmap bg = anim ? grabInner() : QPixmap(); + auto animated = (_main || _passcode); + auto bg = animated ? grabInner() : QPixmap(); clearWidgets(); _intro.create(bodyWidget()); updateControlsGeometry(); - if (anim) { + if (animated) { _intro->animShow(bg); + } else { + setInnerFocus(); } fixOrder(); @@ -361,13 +364,15 @@ void MainWindow::sendServiceHistoryRequest() { _serviceHistoryRequest = MTP::send(MTPmessages_GetHistory(user->input, MTP_int(0), MTP_int(0), MTP_int(0), MTP_int(1), MTP_int(0), MTP_int(0)), _main->rpcDone(&MainWidget::serviceHistoryDone), _main->rpcFail(&MainWidget::serviceHistoryFail)); } -void MainWindow::setupMain(bool anim, const MTPUser *self) { - QPixmap bg = anim ? grabInner() : QPixmap(); +void MainWindow::setupMain(const MTPUser *self) { + auto animated = (_intro || _passcode); + auto bg = animated ? grabInner() : QPixmap(); + clearWidgets(); _main.create(bodyWidget()); updateControlsGeometry(); - if (anim) { + if (animated) { _main->animShow(bg); } else { _main->activate(); diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 39874f2c5..e9f5995e4 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -85,11 +85,11 @@ public: void inactivePress(bool inactive); bool inactivePress() const; - void setupPasscode(bool anim); + void setupPasscode(); void clearPasscode(); void checkAutoLockIn(int msec); - void setupIntro(bool anim); - void setupMain(bool anim, const MTPUser *user = 0); + void setupIntro(); + void setupMain(const MTPUser *user = 0); void serviceNotification(const QString &msg, const MTPMessageMedia &media = MTP_messageMediaEmpty(), bool force = false); void sendServiceHistoryRequest(); void showDelayedServiceMsgs(); diff --git a/Telegram/SourceFiles/passcodewidget.cpp b/Telegram/SourceFiles/passcodewidget.cpp index a31ed5301..3e63025cc 100644 --- a/Telegram/SourceFiles/passcodewidget.cpp +++ b/Telegram/SourceFiles/passcodewidget.cpp @@ -26,6 +26,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "mainwindow.h" #include "application.h" #include "ui/text/text.h" +#include "ui/buttons/round_button.h" #include "styles/style_boxes.h" PasscodeWidget::PasscodeWidget(QWidget *parent) : TWidget(parent) @@ -33,32 +34,32 @@ PasscodeWidget::PasscodeWidget(QWidget *parent) : TWidget(parent) , _passcode(this, st::passcodeInput) , _submit(this, lang(lng_passcode_submit), st::passcodeSubmit) , _logout(this, lang(lng_passcode_logout)) { - _passcode.setEchoMode(QLineEdit::Password); - connect(&_submit, SIGNAL(clicked()), this, SLOT(onSubmit())); + _passcode->setEchoMode(QLineEdit::Password); + connect(_passcode, SIGNAL(changed()), this, SLOT(onChanged())); + connect(_passcode, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); - connect(&_passcode, SIGNAL(changed()), this, SLOT(onChanged())); - connect(&_passcode, SIGNAL(submitted(bool)), this, SLOT(onSubmit())); - - connect(&_logout, SIGNAL(clicked()), App::wnd(), SLOT(onLogout())); + _submit->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); + _submit->setClickedCallback([this] { onSubmit(); }); + _logout->setClickedCallback([] { App::wnd()->onLogout(); }); show(); - _passcode.setFocus(); + _passcode->setFocus(); } void PasscodeWidget::onSubmit() { - if (_passcode.text().isEmpty()) { - _passcode.notaBene(); + if (_passcode->text().isEmpty()) { + _passcode->notaBene(); return; } if (!passcodeCanTry()) { _error = lang(lng_flood_error); - _passcode.notaBene(); + _passcode->notaBene(); update(); return; } if (App::main()) { - if (Local::checkPasscode(_passcode.text().toUtf8())) { + if (Local::checkPasscode(_passcode->text().toUtf8())) { cSetPasscodeBadTries(0); App::wnd()->clearPasscode(); } else { @@ -68,14 +69,14 @@ void PasscodeWidget::onSubmit() { return; } } else { - if (Local::readMap(_passcode.text().toUtf8()) != Local::ReadMapPassNeeded) { + if (Local::readMap(_passcode->text().toUtf8()) != Local::ReadMapPassNeeded) { cSetPasscodeBadTries(0); MTP::start(); if (MTP::authedId()) { - App::wnd()->setupMain(true); + App::wnd()->setupMain(); } else { - App::wnd()->setupIntro(true); + App::wnd()->setupIntro(); } App::app()->checkMapVersion(); @@ -90,8 +91,8 @@ void PasscodeWidget::onSubmit() { void PasscodeWidget::onError() { _error = lang(lng_passcode_wrong); - _passcode.selectAll(); - _passcode.notaBene(); + _passcode->selectAll(); + _passcode->notaBene(); update(); } @@ -151,15 +152,15 @@ void PasscodeWidget::stop_show() { } void PasscodeWidget::showAll() { - _passcode.show(); - _submit.show(); - _logout.show(); + _passcode->show(); + _submit->show(); + _logout->show(); } void PasscodeWidget::hideAll() { - _passcode.hide(); - _submit.hide(); - _logout.hide(); + _passcode->hide(); + _submit->hide(); + _logout->hide(); } void PasscodeWidget::paintEvent(QPaintEvent *e) { @@ -186,32 +187,22 @@ void PasscodeWidget::paintEvent(QPaintEvent *e) { p.setFont(st::passcodeHeaderFont); p.setPen(st::windowTextFg); - p.drawText(QRect(0, _passcode.y() - st::passcodeHeaderHeight, width(), st::passcodeHeaderHeight), lang(lng_passcode_enter), style::al_center); + p.drawText(QRect(0, _passcode->y() - st::passcodeHeaderHeight, width(), st::passcodeHeaderHeight), lang(lng_passcode_enter), style::al_center); if (!_error.isEmpty()) { p.setFont(st::boxTextFont); p.setPen(st::boxTextFgError); - p.drawText(QRect(0, _passcode.y() + _passcode.height(), width(), st::passcodeSubmitSkip), _error, style::al_center); + p.drawText(QRect(0, _passcode->y() + _passcode->height(), width(), st::passcodeSubmitSkip), _error, style::al_center); } } } void PasscodeWidget::resizeEvent(QResizeEvent *e) { - _passcode.move((width() - _passcode.width()) / 2, (height() / 3)); - _submit.move(_passcode.x(), _passcode.y() + _passcode.height() + st::passcodeSubmitSkip); - _logout.move(_passcode.x() + (_passcode.width() - _logout.width()) / 2, _submit.y() + _submit.height() + st::linkFont->ascent); -} - -void PasscodeWidget::mousePressEvent(QMouseEvent *e) { - -} - -void PasscodeWidget::keyPressEvent(QKeyEvent *e) { + _passcode->move((width() - _passcode->width()) / 2, (height() / 3)); + _submit->move(_passcode->x(), _passcode->y() + _passcode->height() + st::passcodeSubmitSkip); + _logout->move(_passcode->x() + (_passcode->width() - _logout->width()) / 2, _submit->y() + _submit->height() + st::linkFont->ascent); } void PasscodeWidget::setInnerFocus() { - _passcode.setFocus(); -} - -PasscodeWidget::~PasscodeWidget() { + _passcode->setFocus(); } diff --git a/Telegram/SourceFiles/passcodewidget.h b/Telegram/SourceFiles/passcodewidget.h index 3f7e6d36a..6b682ddcc 100644 --- a/Telegram/SourceFiles/passcodewidget.h +++ b/Telegram/SourceFiles/passcodewidget.h @@ -20,6 +20,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once +namespace Ui { +class RoundButton; +} // namespace Ui + class PasscodeWidget : public TWidget { Q_OBJECT @@ -32,13 +36,9 @@ public: void step_show(float64 ms, bool timer); void stop_show(); - ~PasscodeWidget(); - protected: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; - void mousePressEvent(QMouseEvent *e) override; - void keyPressEvent(QKeyEvent *e) override; public slots: void onError(); @@ -54,9 +54,9 @@ private: anim::ivalue a_coordUnder, a_coordOver; anim::fvalue a_shadow; - FlatInput _passcode; - FlatButton _submit; - LinkButton _logout; + ChildWidget _passcode; + ChildWidget _submit; + ChildWidget _logout; QString _error; }; diff --git a/Telegram/SourceFiles/shortcuts.cpp b/Telegram/SourceFiles/shortcuts.cpp index 643f0634d..729f4d601 100644 --- a/Telegram/SourceFiles/shortcuts.cpp +++ b/Telegram/SourceFiles/shortcuts.cpp @@ -38,7 +38,7 @@ bool lock_telegram() { w->passcodeWidget()->onSubmit(); return true; } else if (Global::LocalPasscode()) { - w->setupPasscode(true); + w->setupPasscode(); return true; } } diff --git a/Telegram/SourceFiles/structs.h b/Telegram/SourceFiles/structs.h index 0af012287..432f67c49 100644 --- a/Telegram/SourceFiles/structs.h +++ b/Telegram/SourceFiles/structs.h @@ -1394,29 +1394,32 @@ QString saveFileName(const QString &title, const QString &filter, const QString MsgId clientMsgId(); struct MessageCursor { - MessageCursor() : position(0), anchor(0), scroll(QFIXED_MAX) { - } + MessageCursor() = default; MessageCursor(int position, int anchor, int scroll) : position(position), anchor(anchor), scroll(scroll) { } - MessageCursor(const QTextEdit &edit) { + MessageCursor(const QTextEdit *edit) { fillFrom(edit); } - void fillFrom(const QTextEdit &edit) { - QTextCursor c = edit.textCursor(); + void fillFrom(const QTextEdit *edit) { + QTextCursor c = edit->textCursor(); position = c.position(); anchor = c.anchor(); - QScrollBar *s = edit.verticalScrollBar(); + QScrollBar *s = edit->verticalScrollBar(); scroll = (s && (s->value() != s->maximum())) ? s->value() : QFIXED_MAX; } - void applyTo(QTextEdit &edit) { - QTextCursor c = edit.textCursor(); - c.setPosition(anchor, QTextCursor::MoveAnchor); - c.setPosition(position, QTextCursor::KeepAnchor); - edit.setTextCursor(c); - QScrollBar *s = edit.verticalScrollBar(); - if (s) s->setValue(scroll); + void applyTo(QTextEdit *edit) { + auto cursor = edit->textCursor(); + cursor.setPosition(anchor, QTextCursor::MoveAnchor); + cursor.setPosition(position, QTextCursor::KeepAnchor); + edit->setTextCursor(cursor); + if (auto scrollbar = edit->verticalScrollBar()) { + scrollbar->setValue(scroll); + } } - int position, anchor, scroll; + int position = 0; + int anchor = 0; + int scroll = QFIXED_MAX; + }; inline bool operator==(const MessageCursor &a, const MessageCursor &b) { diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 02aef33b2..2e0b1c931 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -126,12 +126,12 @@ void MainWindow::savePosition(Qt::WindowState state) { if (state == Qt::WindowActive) state = windowHandle()->windowState(); if (state == Qt::WindowMinimized || !positionInited()) return; - TWindowPos pos(cWindowPos()), curPos = pos; + auto pos = cWindowPos(), curPos = pos; if (state == Qt::WindowMaximized) { curPos.maximized = 1; } else { - QRect r(geometry()); + auto r = geometry(); curPos.x = r.x(); curPos.y = r.y(); curPos.w = r.width(); diff --git a/Telegram/SourceFiles/window/window_theme.cpp b/Telegram/SourceFiles/window/window_theme.cpp index 67ced2a08..6a107cb8c 100644 --- a/Telegram/SourceFiles/window/window_theme.cpp +++ b/Telegram/SourceFiles/window/window_theme.cpp @@ -419,7 +419,9 @@ void ChatBackground::setThemeData(QImage &&themeImage, bool themeTile) { void ChatBackground::start() { if (_id == internal::kUninitializedBackground) { - setImage(kThemeBackground); + if (!Local::readBackground()) { + setImage(kThemeBackground); + } } }