Pass modifiers inside InputField submitted signal.

Also use non-MOC connections for all InputFields.
Also use Ctrl/Cmd + Enter to submit fast share box.
Fixes #4769.
This commit is contained in:
John Preston 2018-05-31 15:20:28 +03:00
parent b3059248d4
commit bfc748cd31
36 changed files with 272 additions and 332 deletions

View File

@ -122,9 +122,9 @@ void AddContactBox::prepare() {
}
updateButtons();
connect(_first, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
connect(_last, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
connect(_phone, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
connect(_first, &Ui::InputField::submitted, [=] { submit(); });
connect(_last, &Ui::InputField::submitted, [=] { submit(); });
connect(_phone, &Ui::PhoneInput::submitted, [=] { submit(); });
setDimensions(st::boxWideWidth, st::contactPadding.top() + _first->height() + st::contactSkip + _last->height() + st::contactPhoneSkip + _phone->height() + st::contactPadding.bottom() + st::boxPadding.bottom());
}
@ -170,21 +170,21 @@ void AddContactBox::resizeEvent(QResizeEvent *e) {
}
}
void AddContactBox::onSubmit() {
void AddContactBox::submit() {
if (_first->hasFocus()) {
_last->setFocus();
} else if (_last->hasFocus()) {
if (_phone->isEnabled()) {
_phone->setFocus();
} else {
onSave();
save();
}
} else if (_phone->hasFocus()) {
onSave();
save();
}
}
void AddContactBox::onSave() {
void AddContactBox::save() {
if (_addRequest) return;
auto firstName = TextUtilities::PrepareForSending(_first->getLastText());
@ -274,7 +274,7 @@ void AddContactBox::onSaveUserDone(const MTPcontacts_ImportedContacts &res) {
closeBox();
}
void AddContactBox::onRetry() {
void AddContactBox::retry() {
_addRequest = 0;
_contactId = 0;
showChildren();
@ -291,9 +291,9 @@ void AddContactBox::onRetry() {
void AddContactBox::updateButtons() {
clearButtons();
if (_retrying) {
addButton(langFactory(lng_try_other_contact), [this] { onRetry(); });
addButton(langFactory(lng_try_other_contact), [this] { retry(); });
} else {
addButton(langFactory(_user ? lng_settings_save : lng_add_contact), [this] { onSave(); });
addButton(langFactory(_user ? lng_settings_save : lng_add_contact), [this] { save(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
}
}
@ -335,14 +335,14 @@ void GroupInfoBox::prepare() {
_description->setInstantReplacesEnabled(
Global::ReplaceEmojiValue());
connect(_description, SIGNAL(resized()), this, SLOT(onDescriptionResized()));
connect(_description, SIGNAL(submitted(bool)), this, SLOT(onNext()));
connect(_description, SIGNAL(cancelled()), this, SLOT(onClose()));
connect(_description, &Ui::InputField::resized, [=] { descriptionResized(); });
connect(_description, &Ui::InputField::submitted, [=] { submit(); });
connect(_description, &Ui::InputField::cancelled, [=] { closeBox(); });
}
connect(_title, SIGNAL(submitted(bool)), this, SLOT(onNameSubmit()));
connect(_title, &Ui::InputField::submitted, [=] { submitName(); });
addButton(langFactory(_creating == CreatingGroupChannel ? lng_create_group_create : lng_create_group_next), [this] { onNext(); });
addButton(langFactory(_creating == CreatingGroupChannel ? lng_create_group_create : lng_create_group_next), [this] { submit(); });
addButton(langFactory(_fromTypeChoose ? lng_create_group_back : lng_cancel), [this] { closeBox(); });
updateMaxHeight();
@ -373,14 +373,14 @@ void GroupInfoBox::resizeEvent(QResizeEvent *e) {
}
}
void GroupInfoBox::onNameSubmit() {
void GroupInfoBox::submitName() {
if (_title->getLastText().trimmed().isEmpty()) {
_title->setFocus();
_title->showError();
} else if (_description) {
_description->setFocus();
} else {
onNext();
submit();
}
}
@ -460,7 +460,7 @@ void GroupInfoBox::createGroup(not_null<PeerListBox*> selectUsersBox, const QStr
}).send();
}
void GroupInfoBox::onNext() {
void GroupInfoBox::submit() {
if (_creationRequestId) return;
auto title = TextUtilities::PrepareForSending(_title->getLastText());
@ -560,7 +560,7 @@ void GroupInfoBox::createChannel(const QString &title, const QString &descriptio
}).send();
}
void GroupInfoBox::onDescriptionResized() {
void GroupInfoBox::descriptionResized() {
updateMaxHeight();
update();
}
@ -598,14 +598,14 @@ void SetupChannelBox::prepare() {
_checkRequestId = MTP::send(MTPchannels_CheckUsername(_channel->inputChannel, MTP_string("preston")), RPCDoneHandlerPtr(), rpcFail(&SetupChannelBox::onFirstCheckFail));
addButton(langFactory(lng_settings_save), [this] { onSave(); });
addButton(langFactory(_existing ? lng_cancel : lng_create_group_skip), [this] { closeBox(); });
addButton(langFactory(lng_settings_save), [=] { save(); });
addButton(langFactory(_existing ? lng_cancel : lng_create_group_skip), [=] { closeBox(); });
connect(_link, SIGNAL(changed()), this, SLOT(onChange()));
connect(_link, &Ui::MaskedInputField::changed, [=] { handleChange(); });
_link->setVisible(_privacyGroup->value() == Privacy::Public);
_checkTimer.setSingleShot(true);
connect(&_checkTimer, SIGNAL(timeout()), this, SLOT(onCheck()));
connect(&_checkTimer, &QTimer::timeout, [=] { check(); });
_privacyGroup->setChangedCallback([this](Privacy value) { privacyChanged(value); });
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::InviteLinkChanged, [this](const Notify::PeerUpdate &update) {
@ -644,7 +644,7 @@ void SetupChannelBox::keyPressEvent(QKeyEvent *e) {
_link->setFocus();
_link->showError();
} else {
onSave();
save();
}
}
} else {
@ -733,7 +733,7 @@ void SetupChannelBox::updateSelected(const QPoint &cursorGlobalPosition) {
}
}
void SetupChannelBox::onSave() {
void SetupChannelBox::save() {
if (_privacyGroup->value() == Privacy::Private) {
if (_existing) {
_sentUsername = QString();
@ -756,7 +756,7 @@ void SetupChannelBox::onSave() {
_saveRequestId = MTP::send(MTPchannels_UpdateUsername(_channel->inputChannel, MTP_string(_sentUsername)), rpcDone(&SetupChannelBox::onUpdateDone), rpcFail(&SetupChannelBox::onUpdateFail));
}
void SetupChannelBox::onChange() {
void SetupChannelBox::handleChange() {
QString name = _link->text().trimmed();
if (name.isEmpty()) {
if (!_errorText.isEmpty() || !_goodText.isEmpty()) {
@ -793,7 +793,7 @@ void SetupChannelBox::onChange() {
}
}
void SetupChannelBox::onCheck() {
void SetupChannelBox::check() {
if (_checkRequestId) {
MTP::cancel(_checkRequestId);
}
@ -816,7 +816,7 @@ void SetupChannelBox::privacyChanged(Privacy value) {
Ui::show(Box<RevokePublicLinkBox>(base::lambda_guarded(this, [this] {
_tooMuchUsernames = false;
_privacyGroup->setValue(Privacy::Public);
onCheck();
check();
})), LayerOption::KeepOther);
return;
}
@ -952,16 +952,16 @@ void EditNameBox::prepare() {
newHeight += st::boxPadding.bottom() + st::contactPadding.bottom();
setDimensions(st::boxWideWidth, newHeight);
addButton(langFactory(lng_settings_save), [this] { save(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
addButton(langFactory(lng_settings_save), [=] { save(); });
addButton(langFactory(lng_cancel), [=] { closeBox(); });
if (_invertOrder) {
setTabOrder(_last, _first);
}
_first->setMaxLength(kMaxGroupChannelTitle);
_last->setMaxLength(kMaxGroupChannelTitle);
connect(_first, &Ui::InputField::submitted, this, [this] { submit(); });
connect(_last, &Ui::InputField::submitted, this, [this] { submit(); });
connect(_first, &Ui::InputField::submitted, [=] { submit(); });
connect(_last, &Ui::InputField::submitted, [=] { submit(); });
}
void EditNameBox::setInnerFocus() {
@ -1081,9 +1081,9 @@ void EditBioBox::prepare() {
auto cursor = _bio->textCursor();
cursor.setPosition(_bio->getLastText().size());
_bio->setTextCursor(cursor);
connect(_bio, &Ui::InputField::submitted, this, [this](bool ctrlShiftEnter) { save(); });
connect(_bio, &Ui::InputField::resized, this, [this] { updateMaxHeight(); });
connect(_bio, &Ui::InputField::changed, this, [this] { handleBioUpdated(); });
connect(_bio, &Ui::InputField::submitted, [=] { save(); });
connect(_bio, &Ui::InputField::resized, [=] { updateMaxHeight(); });
connect(_bio, &Ui::InputField::changed, [=] { handleBioUpdated(); });
_bio->setInstantReplaces(Ui::InstantReplaces::Default());
_bio->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
handleBioUpdated();
@ -1154,7 +1154,7 @@ EditChannelBox::EditChannelBox(QWidget*, not_null<ChannelData*> channel)
void EditChannelBox::prepare() {
setTitle(langFactory(_channel->isMegagroup() ? lng_edit_group : lng_edit_channel_title));
addButton(langFactory(lng_settings_save), [this] { onSave(); });
addButton(langFactory(lng_settings_save), [this] { save(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::NameChanged, [this](const Notify::PeerUpdate &update) {
@ -1172,11 +1172,11 @@ void EditChannelBox::prepare() {
_description->setInstantReplaces(Ui::InstantReplaces::Default());
_description->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
connect(_description, SIGNAL(resized()), this, SLOT(onDescriptionResized()));
connect(_description, SIGNAL(submitted(bool)), this, SLOT(onSave()));
connect(_description, SIGNAL(cancelled()), this, SLOT(onClose()));
connect(_description, &Ui::InputField::resized, [=] { descriptionResized(); });
connect(_description, &Ui::InputField::submitted, [=] { save(); });
connect(_description, &Ui::InputField::cancelled, [=] { closeBox(); });
connect(_publicLink, SIGNAL(clicked()), this, SLOT(onPublicLink()));
_publicLink->addClickHandler([=] { setupPublicLink(); });
_publicLink->setVisible(_channel->canEditUsername());
_sign->setVisible(canEditSignatures());
_inviteEverybody->setVisible(canEditInvites());
@ -1192,7 +1192,7 @@ void EditChannelBox::setInnerFocus() {
void EditChannelBox::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
if (_title->hasFocus()) {
onSave();
save();
}
} else {
BoxContent::keyPressEvent(e);
@ -1204,7 +1204,7 @@ void EditChannelBox::handleChannelNameChange() {
_sign->setChecked(_channel->addsSignature());
}
void EditChannelBox::onDescriptionResized() {
void EditChannelBox::descriptionResized() {
updateMaxHeight();
update();
}
@ -1268,7 +1268,7 @@ void EditChannelBox::paintEvent(QPaintEvent *e) {
}
}
void EditChannelBox::onSave() {
void EditChannelBox::save() {
if (_saveTitleRequestId || _saveDescriptionRequestId || _saveSignRequestId || _saveInvitesRequestId) return;
auto title = TextUtilities::PrepareForSending(_title->getLastText());
@ -1287,7 +1287,7 @@ void EditChannelBox::onSave() {
}
}
void EditChannelBox::onPublicLink() {
void EditChannelBox::setupPublicLink() {
Ui::show(
Box<SetupChannelBox>(_channel, true),
LayerOption::KeepOther);

View File

@ -36,8 +36,6 @@ enum class PeerFloodType {
QString PeerFloodErrorText(PeerFloodType type);
class AddContactBox : public BoxContent, public RPCSender {
Q_OBJECT
public:
AddContactBox(QWidget*, QString fname = QString(), QString lname = QString(), QString phone = QString());
AddContactBox(QWidget*, UserData *user);
@ -50,12 +48,10 @@ protected:
void setInnerFocus() override;
private slots:
void onSubmit();
void onSave();
void onRetry();
private:
void submit();
void retry();
void save();
void updateButtons();
void onImportDone(const MTPcontacts_ImportedContacts &res);
@ -79,8 +75,6 @@ private:
};
class GroupInfoBox : public BoxContent, private MTP::Sender {
Q_OBJECT
public:
GroupInfoBox(QWidget*, CreatingGroupType creating, bool fromTypeChoose);
@ -90,18 +84,13 @@ protected:
void resizeEvent(QResizeEvent *e) override;
private slots:
void onNext();
void onNameSubmit();
void onDescriptionResized();
void onClose() {
closeBox();
}
private:
void createChannel(const QString &title, const QString &description);
void createGroup(not_null<PeerListBox*> selectUsersBox, const QString &title, const std::vector<not_null<PeerData*>> &users);
void submitName();
void submit();
void descriptionResized();
void updateMaxHeight();
void updateSelected(const QPoint &cursorGlobalPosition);
@ -119,8 +108,6 @@ private:
};
class SetupChannelBox : public BoxContent, public RPCSender {
Q_OBJECT
public:
SetupChannelBox(QWidget*, ChannelData *channel, bool existing = false);
@ -136,11 +123,6 @@ protected:
void mousePressEvent(QMouseEvent *e) override;
void leaveEventHook(QEvent *e) override;
private slots:
void onSave();
void onChange();
void onCheck();
private:
enum class Privacy {
Public,
@ -149,6 +131,9 @@ private:
void privacyChanged(Privacy value);
void updateSelected(const QPoint &cursorGlobalPosition);
void showAddContactsToChannelBox() const;
void handleChange();
void check();
void save();
void onUpdateDone(const MTPBool &result);
bool onUpdateFail(const RPCError &error);
@ -239,8 +224,6 @@ private:
};
class EditChannelBox : public BoxContent, public RPCSender {
Q_OBJECT
public:
EditChannelBox(QWidget*, not_null<ChannelData*> channel);
@ -252,19 +235,14 @@ protected:
void resizeEvent(QResizeEvent *e) override;
void paintEvent(QPaintEvent *e) override;
private slots:
void onSave();
void onDescriptionResized();
void onPublicLink();
void onClose() {
closeBox();
}
private:
void updateMaxHeight();
bool canEditSignatures() const;
bool canEditInvites() const;
void handleChannelNameChange();
void descriptionResized();
void setupPublicLink();
void save();
void onSaveTitleDone(const MTPUpdates &result);
void onSaveDescriptionDone(const MTPBool &result);

View File

@ -125,7 +125,7 @@ void ChangePhoneBox::EnterPhone::prepare() {
_phone->resize(st::boxWidth - 2 * st::boxPadding.left(), _phone->height());
_phone->moveToLeft(st::boxPadding.left(), st::boxLittleSkip);
connect(_phone, &Ui::PhoneInput::submitted, this, [this] { submit(); });
connect(_phone, &Ui::PhoneInput::submitted, [=] { submit(); });
auto description = object_ptr<Ui::FlatLabel>(this, lang(lng_change_phone_new_description), Ui::FlatLabel::InitType::Simple, st::changePhoneLabel);
auto errorSkip = st::boxLittleSkip + st::changePhoneError.style.font->height;
@ -225,12 +225,12 @@ void ChangePhoneBox::EnterCode::prepare() {
auto phoneValue = QString();
_code.create(this, st::defaultInputField, langFactory(lng_change_phone_code_title), phoneValue);
_code->setAutoSubmit(_codeLength, [this] { submit(); });
_code->setChangedCallback([this] { hideError(); });
_code->setAutoSubmit(_codeLength, [=] { submit(); });
_code->setChangedCallback([=] { hideError(); });
_code->resize(st::boxWidth - 2 * st::boxPadding.left(), _code->height());
_code->moveToLeft(st::boxPadding.left(), description->bottomNoMargins());
connect(_code, &Ui::InputField::submitted, this, [this] { submit(); });
connect(_code, &Ui::InputField::submitted, [=] { submit(); });
setDimensions(st::boxWidth, countHeight());
@ -239,8 +239,8 @@ void ChangePhoneBox::EnterCode::prepare() {
updateCall();
}
addButton(langFactory(lng_change_phone_new_submit), [this] { submit(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
addButton(langFactory(lng_change_phone_new_submit), [=] { submit(); });
addButton(langFactory(lng_cancel), [=] { closeBox(); });
}
int ChangePhoneBox::EnterCode::countHeight() {

View File

@ -198,17 +198,17 @@ void ConfirmPhoneBox::prepare() {
_about->setMarkedText(aboutText);
_code.create(this, st::confirmPhoneCodeField, langFactory(lng_code_ph));
_code->setAutoSubmit(_sentCodeLength, [this] { onSendCode(); });
_code->setChangedCallback([this] { showError(QString()); });
_code->setAutoSubmit(_sentCodeLength, [=] { sendCode(); });
_code->setChangedCallback([=] { showError(QString()); });
setTitle(langFactory(lng_confirm_phone_title));
addButton(langFactory(lng_confirm_phone_send), [this] { onSendCode(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
addButton(langFactory(lng_confirm_phone_send), [=] { sendCode(); });
addButton(langFactory(lng_cancel), [=] { closeBox(); });
setDimensions(st::boxWidth, st::usernamePadding.top() + _code->height() + st::usernameSkip + _about->height() + st::usernameSkip);
connect(_code, SIGNAL(submitted(bool)), this, SLOT(onSendCode()));
connect(_code, &Ui::InputField::submitted, [=] { sendCode(); });
showChildren();
}
@ -217,7 +217,7 @@ void ConfirmPhoneBox::callDone(const MTPauth_SentCode &result) {
_call.callDone();
}
void ConfirmPhoneBox::onSendCode() {
void ConfirmPhoneBox::sendCode() {
if (_sendCodeRequestId) {
return;
}

View File

@ -82,16 +82,11 @@ private:
};
class ConfirmPhoneBox : public BoxContent, public RPCSender {
Q_OBJECT
public:
static void start(const QString &phone, const QString &hash);
~ConfirmPhoneBox();
private slots:
void onSendCode();
protected:
void prepare() override;
void setInnerFocus() override;
@ -103,6 +98,7 @@ private:
ConfirmPhoneBox(QWidget*, const QString &phone, const QString &hash);
friend class object_ptr<ConfirmPhoneBox>;
void sendCode();
void sendCall();
void checkPhoneAndHash();

View File

@ -194,13 +194,9 @@ void EditCaptionBox::prepare() {
addButton(langFactory(lng_cancel), [this] { closeBox(); });
updateBoxSize();
connect(_field, &Ui::InputField::submitted, this, [this] { save(); });
connect(_field, &Ui::InputField::cancelled, this, [this] {
closeBox();
});
connect(_field, &Ui::InputField::resized, this, [this] {
captionResized();
});
connect(_field, &Ui::InputField::submitted, [=] { save(); });
connect(_field, &Ui::InputField::cancelled, [=] { closeBox(); });
connect(_field, &Ui::InputField::resized, [=] { captionResized(); });
auto cursor = _field->textCursor();
cursor.movePosition(QTextCursor::End);

View File

@ -630,34 +630,36 @@ EditColorBox::EditColorBox(QWidget*, const QString &title, QColor current) : Box
}
void EditColorBox::prepare() {
setTitle([this] { return _title; });
setTitle([=] { return _title; });
connect(_hueField, SIGNAL(changed()), this, SLOT(onFieldChanged()));
connect(_saturationField, SIGNAL(changed()), this, SLOT(onFieldChanged()));
connect(_brightnessField, SIGNAL(changed()), this, SLOT(onFieldChanged()));
connect(_redField, SIGNAL(changed()), this, SLOT(onFieldChanged()));
connect(_greenField, SIGNAL(changed()), this, SLOT(onFieldChanged()));
connect(_blueField, SIGNAL(changed()), this, SLOT(onFieldChanged()));
connect(_result, SIGNAL(changed()), this, SLOT(onFieldChanged()));
const auto changed = [=] { fieldChanged(); };
connect(_hueField, &Ui::MaskedInputField::changed, changed);
connect(_saturationField, &Ui::MaskedInputField::changed, changed);
connect(_brightnessField, &Ui::MaskedInputField::changed, changed);
connect(_redField, &Ui::MaskedInputField::changed, changed);
connect(_greenField, &Ui::MaskedInputField::changed, changed);
connect(_blueField, &Ui::MaskedInputField::changed, changed);
connect(_result, &Ui::MaskedInputField::changed, changed);
connect(_hueField, SIGNAL(submitted(bool)), this, SLOT(onFieldSubmitted()));
connect(_saturationField, SIGNAL(submitted(bool)), this, SLOT(onFieldSubmitted()));
connect(_brightnessField, SIGNAL(submitted(bool)), this, SLOT(onFieldSubmitted()));
connect(_redField, SIGNAL(submitted(bool)), this, SLOT(onFieldSubmitted()));
connect(_greenField, SIGNAL(submitted(bool)), this, SLOT(onFieldSubmitted()));
connect(_blueField, SIGNAL(submitted(bool)), this, SLOT(onFieldSubmitted()));
connect(_result, SIGNAL(submitted(bool)), this, SLOT(onFieldSubmitted()));
const auto submitted = [=] { fieldSubmitted(); };
connect(_hueField, &Ui::MaskedInputField::submitted, submitted);
connect(_saturationField, &Ui::MaskedInputField::submitted, submitted);
connect(_brightnessField, &Ui::MaskedInputField::submitted, submitted);
connect(_redField, &Ui::MaskedInputField::submitted, submitted);
connect(_greenField, &Ui::MaskedInputField::submitted, submitted);
connect(_blueField, &Ui::MaskedInputField::submitted, submitted);
connect(_result, &Ui::MaskedInputField::submitted, submitted);
addButton(langFactory(lng_settings_save), [this] { saveColor(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
addButton(langFactory(lng_settings_save), [=] { saveColor(); });
addButton(langFactory(lng_cancel), [=] { closeBox(); });
auto height = st::colorEditSkip + st::colorPickerSize + st::colorEditSkip + st::colorSliderWidth + st::colorEditSkip;
setDimensions(st::colorEditWidth, height);
subscribe(_picker->changed(), [this] { updateFromControls(); });
subscribe(_hueSlider->changed(), [this] { updateFromControls(); });
subscribe(_opacitySlider->changed(), [this] { updateFromControls(); });
subscribe(boxClosing, [this] {
subscribe(_picker->changed(), [=] { updateFromControls(); });
subscribe(_hueSlider->changed(), [=] { updateFromControls(); });
subscribe(_opacitySlider->changed(), [=] { updateFromControls(); });
subscribe(boxClosing, [=] {
if (_cancelCallback) {
_cancelCallback();
}
@ -670,7 +672,7 @@ void EditColorBox::setInnerFocus() {
_result->selectAll();
}
void EditColorBox::onFieldChanged() {
void EditColorBox::fieldChanged() {
auto emitter = sender();
auto checkHSVSender = [this, emitter](QObject *field) {
if (emitter == field) {
@ -693,7 +695,7 @@ void EditColorBox::onFieldChanged() {
}
}
void EditColorBox::onFieldSubmitted() {
void EditColorBox::fieldSubmitted() {
Ui::MaskedInputField *fields[] = {
_hueField,
_saturationField,

View File

@ -10,8 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/abstract_box.h"
class EditColorBox : public BoxContent {
Q_OBJECT
public:
EditColorBox(QWidget*, const QString &title, QColor current = QColor(255, 255, 255));
@ -37,12 +35,10 @@ protected:
void setInnerFocus() override;
private slots:
void onFieldChanged();
void onFieldSubmitted();
private:
void saveColor();
void fieldChanged();
void fieldSubmitted();
void updateFromColor(QColor color);
void updateControlsFromColor();

View File

@ -43,8 +43,8 @@ PasscodeBox::PasscodeBox(QWidget*, const QByteArray &newSalt, const QByteArray &
}
void PasscodeBox::prepare() {
addButton(langFactory(_turningOff ? lng_passcode_remove_button : lng_settings_save), [this] { onSave(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
addButton(langFactory(_turningOff ? lng_passcode_remove_button : lng_settings_save), [=] { save(); });
addButton(langFactory(lng_cancel), [=] { closeBox(); });
_about.setRichText(st::passcodeTextStyle, lang(_cloudPwd ? lng_cloud_password_about : lng_passcode_about));
_aboutHeight = _about.countHeight(st::boxWidth - st::boxPadding.left() * 1.5);
@ -65,19 +65,20 @@ void PasscodeBox::prepare() {
}
}
connect(_oldPasscode, SIGNAL(changed()), this, SLOT(onOldChanged()));
connect(_newPasscode, SIGNAL(changed()), this, SLOT(onNewChanged()));
connect(_reenterPasscode, SIGNAL(changed()), this, SLOT(onNewChanged()));
connect(_passwordHint, SIGNAL(changed()), this, SLOT(onNewChanged()));
connect(_recoverEmail, SIGNAL(changed()), this, SLOT(onEmailChanged()));
connect(_oldPasscode, &Ui::MaskedInputField::changed, [=] { oldChanged(); });
connect(_newPasscode, &Ui::MaskedInputField::changed, [=] { newChanged(); });
connect(_reenterPasscode, &Ui::MaskedInputField::changed, [=] { newChanged(); });
connect(_passwordHint, &Ui::InputField::changed, [=] { newChanged(); });
connect(_recoverEmail, &Ui::InputField::changed, [=] { emailChanged(); });
connect(_oldPasscode, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
connect(_newPasscode, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
connect(_reenterPasscode, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
connect(_passwordHint, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
connect(_recoverEmail, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
const auto fieldSubmit = [=] { submit(); };
connect(_oldPasscode, &Ui::MaskedInputField::submitted, fieldSubmit);
connect(_newPasscode, &Ui::MaskedInputField::submitted, fieldSubmit);
connect(_reenterPasscode, &Ui::MaskedInputField::submitted, fieldSubmit);
connect(_passwordHint, &Ui::InputField::submitted, fieldSubmit);
connect(_recoverEmail, &Ui::InputField::submitted, fieldSubmit);
connect(_recover, SIGNAL(clicked()), this, SLOT(onRecoverByEmail()));
_recover->addClickHandler([=] { recoverByEmail(); });
bool has = _cloudPwd ? (!_curSalt.isEmpty()) : Global::LocalPasscode();
_oldPasscode->setVisible(_turningOff || has);
@ -88,11 +89,11 @@ void PasscodeBox::prepare() {
_recoverEmail->setVisible(!_turningOff && _cloudPwd && _curSalt.isEmpty());
}
void PasscodeBox::onSubmit() {
void PasscodeBox::submit() {
bool has = _cloudPwd ? (!_curSalt.isEmpty()) : Global::LocalPasscode();
if (_oldPasscode->hasFocus()) {
if (_turningOff) {
onSave();
save();
} else {
_newPasscode->setFocus();
}
@ -110,16 +111,16 @@ void PasscodeBox::onSubmit() {
} else if (!_passwordHint->isHidden()) {
_passwordHint->setFocus();
} else {
onSave();
save();
}
} else if (_passwordHint->hasFocus()) {
if (_recoverEmail->isHidden()) {
onSave();
save();
} else {
_recoverEmail->setFocus();
}
} else if (_recoverEmail->hasFocus()) {
onSave();
save();
}
}
@ -226,7 +227,7 @@ bool PasscodeBox::setPasswordFail(const RPCError &error) {
emit reloadPassword();
closeBox();
} else {
onBadOldPasscode();
badOldPasscode();
}
} else if (err == qstr("NEW_PASSWORD_BAD")) {
_newPasscode->setFocus();
@ -248,7 +249,7 @@ bool PasscodeBox::setPasswordFail(const RPCError &error) {
return true;
}
void PasscodeBox::onSave(bool force) {
void PasscodeBox::save(bool force) {
if (_setRequest) return;
QString old = _oldPasscode->text(), pwd = _newPasscode->text(), conf = _reenterPasscode->text();
@ -268,7 +269,7 @@ void PasscodeBox::onSave(bool force) {
} else {
cSetPasscodeBadTries(cPasscodeBadTries() + 1);
cSetPasscodeLastTry(getms(true));
onBadOldPasscode();
badOldPasscode();
return;
}
}
@ -306,7 +307,7 @@ void PasscodeBox::onSave(bool force) {
if (!_recoverEmail->isHidden() && email.isEmpty() && !force) {
_skipEmailWarning = true;
_replacedBy = Ui::show(Box<ConfirmBox>(lang(lng_cloud_password_about_recover), lang(lng_cloud_password_skip_email), st::attentionBoxButton, base::lambda_guarded(this, [this] {
onSave(true);
save(true);
})), LayerOption::KeepOther);
} else {
QByteArray newPasswordData = pwd.isEmpty() ? QByteArray() : (_newSalt + pwd.toUtf8() + _newSalt);
@ -337,7 +338,7 @@ void PasscodeBox::onSave(bool force) {
}
}
void PasscodeBox::onBadOldPasscode() {
void PasscodeBox::badOldPasscode() {
_oldPasscode->selectAll();
_oldPasscode->setFocus();
_oldPasscode->showError();
@ -348,7 +349,7 @@ void PasscodeBox::onBadOldPasscode() {
update();
}
void PasscodeBox::onOldChanged() {
void PasscodeBox::oldChanged() {
if (!_oldError.isEmpty()) {
_oldError = QString();
if (_hasRecovery && _hintText.isEmpty()) {
@ -358,21 +359,21 @@ void PasscodeBox::onOldChanged() {
}
}
void PasscodeBox::onNewChanged() {
void PasscodeBox::newChanged() {
if (!_newError.isEmpty()) {
_newError = QString();
update();
}
}
void PasscodeBox::onEmailChanged() {
void PasscodeBox::emailChanged() {
if (!_emailError.isEmpty()) {
_emailError = QString();
update();
}
}
void PasscodeBox::onRecoverByEmail() {
void PasscodeBox::recoverByEmail() {
if (_pattern.isEmpty()) {
_pattern = "-";
MTP::send(MTPauth_RequestPasswordRecovery(), rpcDone(&PasscodeBox::recoverStarted), rpcFail(&PasscodeBox::recoverStartFail));
@ -381,18 +382,19 @@ void PasscodeBox::onRecoverByEmail() {
}
}
void PasscodeBox::onRecoverExpired() {
void PasscodeBox::recoverExpired() {
_pattern = QString();
}
void PasscodeBox::recover() {
if (_pattern == "-") return;
_replacedBy = Ui::show(
const auto box = Ui::show(
Box<RecoverBox>(_pattern),
LayerOption::KeepOther);
connect(_replacedBy, SIGNAL(reloadPassword()), this, SIGNAL(reloadPassword()));
connect(_replacedBy, SIGNAL(recoveryExpired()), this, SLOT(onRecoverExpired()));
connect(box, &RecoverBox::reloadPassword, this, &PasscodeBox::reloadPassword);
connect(box, &RecoverBox::recoveryExpired, this, &PasscodeBox::recoverExpired);
_replacedBy = box;
}
void PasscodeBox::recoverStarted(const MTPauth_PasswordRecovery &result) {
@ -416,13 +418,13 @@ RecoverBox::RecoverBox(QWidget*, const QString &pattern)
void RecoverBox::prepare() {
setTitle(langFactory(lng_signin_recover_title));
addButton(langFactory(lng_passcode_submit), [this] { onSubmit(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
addButton(langFactory(lng_passcode_submit), [=] { submit(); });
addButton(langFactory(lng_cancel), [=] { closeBox(); });
setDimensions(st::boxWidth, st::passcodePadding.top() + st::passcodePadding.bottom() + st::passcodeTextLine + _recoverCode->height() + st::passcodeTextLine);
connect(_recoverCode, SIGNAL(changed()), this, SLOT(onCodeChanged()));
connect(_recoverCode, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
connect(_recoverCode, &Ui::InputField::changed, [=] { codeChanged(); });
connect(_recoverCode, &Ui::InputField::submitted, [=] { submit(); });
}
void RecoverBox::paintEvent(QPaintEvent *e) {
@ -452,7 +454,7 @@ void RecoverBox::setInnerFocus() {
_recoverCode->setFocusFast();
}
void RecoverBox::onSubmit() {
void RecoverBox::submit() {
if (_submitRequest) return;
QString code = _recoverCode->getLastText().trimmed();
@ -465,7 +467,7 @@ void RecoverBox::onSubmit() {
_submitRequest = MTP::send(MTPauth_RecoverPassword(MTP_string(code)), rpcDone(&RecoverBox::codeSubmitDone, true), rpcFail(&RecoverBox::codeSubmitFail));
}
void RecoverBox::onCodeChanged() {
void RecoverBox::codeChanged() {
_error = QString();
update();
}

View File

@ -22,16 +22,6 @@ public:
PasscodeBox(QWidget*, bool turningOff);
PasscodeBox(QWidget*, const QByteArray &newSalt, const QByteArray &curSalt, bool hasRecovery, const QString &hint, bool turningOff = false);
private slots:
void onSave(bool force = false);
void onBadOldPasscode();
void onOldChanged();
void onNewChanged();
void onEmailChanged();
void onRecoverByEmail();
void onRecoverExpired();
void onSubmit();
signals:
void reloadPassword();
@ -43,7 +33,15 @@ protected:
void resizeEvent(QResizeEvent *e) override;
private:
void submit();
void closeReplacedBy();
void oldChanged();
void newChanged();
void emailChanged();
void save(bool force = false);
void badOldPasscode();
void recoverByEmail();
void recoverExpired();
void setPasswordDone(const MTPBool &result);
bool setPasswordFail(const RPCError &error);
@ -84,10 +82,6 @@ class RecoverBox : public BoxContent, public RPCSender {
public:
RecoverBox(QWidget*, const QString &pattern);
public slots:
void onSubmit();
void onCodeChanged();
signals:
void reloadPassword();
void recoveryExpired();
@ -100,6 +94,8 @@ protected:
void resizeEvent(QResizeEvent *e) override;
private:
void submit();
void codeChanged();
void codeSubmitDone(bool recover, const MTPauth_Authorization &result);
bool codeSubmitFail(const RPCError &error);

View File

@ -46,7 +46,7 @@ void PeerListBox::createMultiSelect() {
) | rpl::start_with_next(
[this] { updateScrollSkips(); },
lifetime());
_select->entity()->setSubmittedCallback([this](bool chtrlShiftEnter) { content()->submitted(); });
_select->entity()->setSubmittedCallback([this](Qt::KeyboardModifiers) { content()->submitted(); });
_select->entity()->setQueryChangedCallback([this](const QString &query) { searchQueryChanged(query); });
_select->entity()->setItemRemovedCallback([this](uint64 itemId) {
if (auto peer = App::peerLoaded(itemId)) {

View File

@ -308,7 +308,7 @@ object_ptr<Ui::RpWidget> Controller::createTitleEdit() {
QObject::connect(
result->entity(),
&Ui::InputField::submitted,
[this] { submitTitle(); });
[=] { submitTitle(); });
_controls.title = result->entity();
return std::move(result);
@ -339,7 +339,7 @@ object_ptr<Ui::RpWidget> Controller::createDescriptionEdit() {
QObject::connect(
result->entity(),
&Ui::InputField::submitted,
[this] { submitDescription(); });
[=] { submitDescription(); });
_controls.description = result->entity();
return std::move(result);

View File

@ -60,7 +60,7 @@ void RateCallBox::ratingChanged(int value) {
Expects(value > 0 && value <= kMaxRating);
if (!_rating) {
clearButtons();
addButton(langFactory(lng_send_button), [this] { onSend(); });
addButton(langFactory(lng_send_button), [this] { send(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
}
_rating = value;
@ -82,9 +82,9 @@ void RateCallBox::ratingChanged(int value) {
_comment->resize(width() - (st::callRatingPadding.left() + st::callRatingPadding.right()), _comment->height());
updateMaxHeight();
connect(_comment, SIGNAL(resized()), this, SLOT(onCommentResized()));
connect(_comment, SIGNAL(submitted(bool)), this, SLOT(onSend()));
connect(_comment, SIGNAL(cancelled()), this, SLOT(onClose()));
connect(_comment, &Ui::InputField::resized, [=] { commentResized(); });
connect(_comment, &Ui::InputField::submitted, [=] { send(); });
connect(_comment, &Ui::InputField::cancelled, [=] { closeBox(); });
}
_comment->setFocusFast();
} else if (_comment) {
@ -101,13 +101,14 @@ void RateCallBox::setInnerFocus() {
}
}
void RateCallBox::onCommentResized() {
void RateCallBox::commentResized() {
updateMaxHeight();
update();
}
void RateCallBox::onSend() {
void RateCallBox::send() {
Expects(_rating > 0 && _rating <= kMaxRating);
if (_requestId) {
return;
}

View File

@ -17,18 +17,9 @@ class IconButton;
} // namespace Ui
class RateCallBox : public BoxContent, private MTP::Sender {
Q_OBJECT
public:
RateCallBox(QWidget*, uint64 callId, uint64 callAccessHash);
private slots:
void onSend();
void onCommentResized();
void onClose() {
closeBox();
}
protected:
void prepare() override;
void setInnerFocus() override;
@ -38,6 +29,8 @@ protected:
private:
void updateMaxHeight();
void ratingChanged(int value);
void send();
void commentResized();
uint64 _callId = 0;
uint64 _callAccessHash = 0;

View File

@ -39,8 +39,8 @@ void ReportBox::prepare() {
}
}()));
addButton(langFactory(lng_report_button), [this] { onReport(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
addButton(langFactory(lng_report_button), [=] { report(); });
addButton(langFactory(lng_cancel), [=] { closeBox(); });
_reasonGroup = std::make_shared<Ui::RadioenumGroup<Reason>>(
Reason::Spam);
@ -93,9 +93,9 @@ void ReportBox::reasonChanged(Reason reason) {
_reasonOtherText->resize(width() - (st::boxPadding.left() + st::boxOptionListPadding.left() + st::boxPadding.right()), _reasonOtherText->height());
updateMaxHeight();
connect(_reasonOtherText, SIGNAL(resized()), this, SLOT(onReasonResized()));
connect(_reasonOtherText, SIGNAL(submitted(bool)), this, SLOT(onReport()));
connect(_reasonOtherText, SIGNAL(cancelled()), this, SLOT(onClose()));
connect(_reasonOtherText, &Ui::InputField::resized, [=] { reasonResized(); });
connect(_reasonOtherText, &Ui::InputField::submitted, [=] { report(); });
connect(_reasonOtherText, &Ui::InputField::cancelled, [=] { closeBox(); });
}
_reasonOtherText->setFocusFast();
} else if (_reasonOtherText) {
@ -112,12 +112,12 @@ void ReportBox::setInnerFocus() {
}
}
void ReportBox::onReasonResized() {
void ReportBox::reasonResized() {
updateMaxHeight();
update();
}
void ReportBox::onReport() {
void ReportBox::report() {
if (_requestId) return;
if (_reasonOtherText && _reasonOtherText->getLastText().trimmed().isEmpty()) {

View File

@ -18,19 +18,10 @@ class InputField;
} // namespace Ui
class ReportBox : public BoxContent, public RPCSender {
Q_OBJECT
public:
ReportBox(QWidget*, not_null<PeerData*> peer);
ReportBox(QWidget*, not_null<PeerData*> peer, MessageIdsList ids);
private slots:
void onReport();
void onReasonResized();
void onClose() {
closeBox();
}
protected:
void prepare() override;
void setInnerFocus() override;
@ -45,7 +36,9 @@ private:
Other,
};
void reasonChanged(Reason reason);
void reasonResized();
void updateMaxHeight();
void report();
void reportDone(const MTPBool &result);
bool reportFail(const RPCError &error);

View File

@ -1558,17 +1558,18 @@ void SendFilesBox::applyAlbumOrder() {
void SendFilesBox::setupCaption() {
_caption->setMaxLength(MaxPhotoCaption);
_caption->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
connect(_caption, &Ui::InputField::resized, this, [this] {
connect(_caption, &Ui::InputField::resized, [=] {
captionResized();
});
connect(_caption, &Ui::InputField::submitted, this, [this](
bool ctrlShiftEnter) {
connect(_caption, &Ui::InputField::submitted, [=](
Qt::KeyboardModifiers modifiers) {
const auto ctrlShiftEnter = modifiers.testFlag(Qt::ShiftModifier)
&& (modifiers.testFlag(Qt::ControlModifier)
|| modifiers.testFlag(Qt::MetaModifier));
send(ctrlShiftEnter);
});
connect(_caption, &Ui::InputField::cancelled, this, [this] {
closeBox();
});
_caption->setMimeDataHook([this](
connect(_caption, &Ui::InputField::cancelled, [=] { closeBox(); });
_caption->setMimeDataHook([=](
not_null<const QMimeData*> data,
Ui::InputField::MimeAction action) {
if (action == Ui::InputField::MimeAction::Check) {

View File

@ -61,7 +61,14 @@ void ShareBox::prepare() {
}
});
_select->setResizedCallback([this] { updateScrollSkips(); });
_select->setSubmittedCallback([this](bool) { _inner->onSelectActive(); });
_select->setSubmittedCallback([this](Qt::KeyboardModifiers modifiers) {
if (modifiers.testFlag(Qt::ControlModifier)
|| modifiers.testFlag(Qt::MetaModifier)) {
onSubmit();
} else {
_inner->onSelectActive();
}
});
connect(_inner, SIGNAL(searchByUsername()), this, SLOT(onNeedSearchByUsername()));
_inner->setPeerSelectedChangedCallback([this](PeerData *peer, bool checked) {
onPeerSelectedChanged(peer, checked);

View File

@ -610,14 +610,14 @@ StickersBox::Inner::Inner(QWidget *parent, not_null<ChannelData*> megagroup) : T
connect(
_megagroupSetField,
&Ui::MaskedInputField::changed,
[this] {
[=] {
_megagroupSetAddressChangedTimer.callOnce(
kHandleMegagroupSetAddressChangeTimeout);
});
connect(
_megagroupSetField,
&Ui::MaskedInputField::submitted,
[this] {
[=] {
_megagroupSetAddressChangedTimer.cancel();
handleMegagroupSetAddressChange();
});

View File

@ -35,18 +35,18 @@ void UsernameBox::prepare() {
setTitle(langFactory(lng_username_title));
addButton(langFactory(lng_settings_save), [this] { onSave(); });
addButton(langFactory(lng_cancel), [this] { closeBox(); });
addButton(langFactory(lng_settings_save), [=] { save(); });
addButton(langFactory(lng_cancel), [=] { closeBox(); });
connect(_username, SIGNAL(changed()), this, SLOT(onChanged()));
connect(_username, SIGNAL(submitted(bool)), this, SLOT(onSave()));
connect(_link, SIGNAL(clicked()), this, SLOT(onLinkClick()));
connect(_username, &Ui::MaskedInputField::changed, [=] { changed(); });
connect(_username, &Ui::MaskedInputField::submitted, [=] { save(); });
_link->addClickHandler([=] { linkClick(); });
_about.setRichText(st::usernameTextStyle, lang(lng_username_about));
setDimensions(st::boxWidth, st::usernamePadding.top() + _username->height() + st::usernameSkip + _about.countHeight(st::boxWidth - st::usernamePadding.left()) + 3 * st::usernameTextStyle.lineHeight + st::usernamePadding.bottom());
_checkTimer->setSingleShot(true);
connect(_checkTimer, SIGNAL(timeout()), this, SLOT(onCheck()));
connect(_checkTimer, &QTimer::timeout, [=] { check(); });
updateLinkText();
}
@ -96,14 +96,14 @@ void UsernameBox::resizeEvent(QResizeEvent *e) {
_link->moveToLeft(st::usernamePadding.left(), linky + st::usernameTextStyle.lineHeight + ((st::usernameTextStyle.lineHeight - st::boxTextFont->height) / 2));
}
void UsernameBox::onSave() {
void UsernameBox::save() {
if (_saveRequestId) return;
_sentUsername = getName();
_saveRequestId = MTP::send(MTPaccount_UpdateUsername(MTP_string(_sentUsername)), rpcDone(&UsernameBox::onUpdateDone), rpcFail(&UsernameBox::onUpdateFail));
}
void UsernameBox::onCheck() {
void UsernameBox::check() {
if (_checkRequestId) {
MTP::cancel(_checkRequestId);
}
@ -118,7 +118,7 @@ void UsernameBox::onCheck() {
}
}
void UsernameBox::onChanged() {
void UsernameBox::changed() {
updateLinkText();
QString name = getName();
if (name.isEmpty()) {
@ -156,7 +156,7 @@ void UsernameBox::onChanged() {
}
}
void UsernameBox::onLinkClick() {
void UsernameBox::linkClick() {
Application::clipboard()->setText(Messenger::Instance().createInternalLinkFull(getName()));
Ui::Toast::Show(lang(lng_username_copied));
}

View File

@ -15,8 +15,6 @@ class LinkButton;
} // namespace Ui
class UsernameBox : public BoxContent, public RPCSender {
Q_OBJECT
public:
UsernameBox(QWidget*);
@ -27,14 +25,6 @@ protected:
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
private slots:
void onSave();
void onCheck();
void onChanged();
void onLinkClick();
private:
void onUpdateDone(const MTPUser &result);
bool onUpdateFail(const RPCError &error);
@ -42,6 +32,13 @@ private:
void onCheckDone(const MTPBool &result);
bool onCheckFail(const RPCError &error);
void save();
void check();
void changed();
void linkClick();
QString getName() const;
void updateLinkText();

View File

@ -63,23 +63,23 @@ GifsListWidget::Footer::Footer(not_null<GifsListWidget*> parent) : InnerFooter(p
, _pan(parent)
, _field(this, st::gifsSearchField, langFactory(lng_gifs_search))
, _cancel(this, st::gifsSearchCancel) {
connect(_field, &Ui::InputField::submitted, this, [this](bool ctrlShiftEnter) {
connect(_field, &Ui::InputField::submitted, [=] {
_pan->sendInlineRequest();
});
connect(_field, &Ui::InputField::cancelled, this, [this] {
connect(_field, &Ui::InputField::cancelled, [=] {
if (_field->getLastText().isEmpty()) {
emit _pan->cancelled();
} else {
_field->setText(QString());
}
});
connect(_field, &Ui::InputField::changed, this, [this] {
connect(_field, &Ui::InputField::changed, [=] {
_cancel->toggle(
!_field->getLastText().isEmpty(),
anim::type::normal);
_pan->searchForGifs(_field->getLastText());
});
_cancel->setClickedCallback([this] {
_cancel->setClickedCallback([=] {
_field->setText(QString());
});
}

View File

@ -195,11 +195,11 @@ void StickersListWidget::Footer::initSearch() {
_searchField->setText(QString());
}
};
connect(_searchField, &Ui::InputField::submitted, this, [this](bool ctrlShiftEnter) {
connect(_searchField, &Ui::InputField::submitted, [=] {
_pan->sendSearchRequest();
});
connect(_searchField, &Ui::InputField::cancelled, this, cancelSearch);
connect(_searchField, &Ui::InputField::changed, this, [this] {
connect(_searchField, &Ui::InputField::cancelled, cancelSearch);
connect(_searchField, &Ui::InputField::changed, [=] {
_pan->searchForSets(_searchField->getLastText());
});
_searchCancel->setClickedCallback(cancelSearch);

View File

@ -106,15 +106,15 @@ FixedBar::FixedBar(
, _cancel(this, st::historyAdminLogCancelSearch)
, _filter(this, langFactory(lng_admin_log_filter), st::topBarButton) {
_backButton->moveToLeft(0, 0);
_backButton->setClickedCallback([this] { goBack(); });
_filter->setClickedCallback([this] { showFilterSignal.notify(); });
_search->setClickedCallback([this] { showSearch(); });
_cancel->setClickedCallback([this] { cancelSearch(); });
_backButton->setClickedCallback([=] { goBack(); });
_filter->setClickedCallback([=] { showFilterSignal.notify(); });
_search->setClickedCallback([=] { showSearch(); });
_cancel->setClickedCallback([=] { cancelSearch(); });
_field->hide();
connect(_field, &Ui::FlatInput::cancelled, this, [this] { cancelSearch(); });
connect(_field, &Ui::FlatInput::changed, this, [this] { searchUpdated(); });
connect(_field, &Ui::FlatInput::submitted, this, [this] { applySearch(); });
_searchTimer.setCallback([this] { applySearch(); });
connect(_field, &Ui::FlatInput::cancelled, [=] { cancelSearch(); });
connect(_field, &Ui::FlatInput::changed, [=] { searchUpdated(); });
connect(_field, &Ui::FlatInput::submitted, [=] { applySearch(); });
_searchTimer.setCallback([=] { applySearch(); });
_cancel->hide(anim::type::instant);
}

View File

@ -455,7 +455,7 @@ HistoryWidget::HistoryWidget(
connect(_botStart, SIGNAL(clicked()), this, SLOT(onBotStart()));
connect(_joinChannel, SIGNAL(clicked()), this, SLOT(onJoinChannel()));
connect(_muteUnmute, SIGNAL(clicked()), this, SLOT(onMuteUnmute()));
connect(_field, SIGNAL(submitted(bool)), this, SLOT(onSend()));
connect(_field, &Ui::InputField::submitted, [=] { send(); });
connect(_field, SIGNAL(cancelled()), this, SLOT(onCancel()));
connect(_field, SIGNAL(tabbed()), this, SLOT(onFieldTabbed()));
connect(_field, SIGNAL(resized()), this, SLOT(onFieldResize()));
@ -2989,7 +2989,7 @@ void HistoryWidget::hideSelectorControlsAnimated() {
}
}
void HistoryWidget::onSend() {
void HistoryWidget::send() {
if (!_history) return;
if (_editMsgId) {
@ -3254,7 +3254,7 @@ void HistoryWidget::sendButtonClicked() {
if (type == Ui::SendButton::Type::Cancel) {
onInlineBotCancel();
} else if (type != Ui::SendButton::Type::Record) {
onSend();
send();
}
}

View File

@ -433,8 +433,6 @@ public slots:
void preloadHistoryIfNeeded();
private slots:
void onSend();
void onHashtagOrBotCommandInsert(QString str, FieldAutocomplete::ChooseMethod method);
void onMentionInsert(UserData *user);
void onInlineBotCancel();
@ -449,6 +447,7 @@ private:
using TabbedSelector = ChatHelpers::TabbedSelector;
using DragState = Storage::MimeDataState;
void send();
void handlePendingHistoryUpdate();
void fullPeerUpdated(PeerData *peer);
void toggleTabbedSelectorMode();

View File

@ -23,16 +23,16 @@ PasscodeWidget::PasscodeWidget(QWidget *parent) : TWidget(parent)
, _passcode(this, st::passcodeInput, langFactory(lng_passcode_ph))
, _submit(this, langFactory(lng_passcode_submit), st::passcodeSubmit)
, _logout(this, lang(lng_passcode_logout)) {
connect(_passcode, SIGNAL(changed()), this, SLOT(onChanged()));
connect(_passcode, SIGNAL(submitted(bool)), this, SLOT(onSubmit()));
connect(_passcode, &Ui::MaskedInputField::changed, [=] { changed(); });
connect(_passcode, &Ui::MaskedInputField::submitted, [=] { submit(); });
_submit->setClickedCallback([this] { onSubmit(); });
_submit->setClickedCallback([=] { submit(); });
_logout->setClickedCallback([] { App::wnd()->onLogout(); });
show();
}
void PasscodeWidget::onSubmit() {
void PasscodeWidget::submit() {
if (_passcode->text().isEmpty()) {
_passcode->showError();
return;
@ -51,7 +51,7 @@ void PasscodeWidget::onSubmit() {
} else {
cSetPasscodeBadTries(cPasscodeBadTries() + 1);
cSetPasscodeLastTry(getms(true));
onError();
error();
return;
}
} else {
@ -67,20 +67,20 @@ void PasscodeWidget::onSubmit() {
} else {
cSetPasscodeBadTries(cPasscodeBadTries() + 1);
cSetPasscodeLastTry(getms(true));
onError();
error();
return;
}
}
}
void PasscodeWidget::onError() {
void PasscodeWidget::error() {
_error = lang(lng_passcode_wrong);
_passcode->selectAll();
_passcode->showError();
update();
}
void PasscodeWidget::onChanged() {
void PasscodeWidget::changed() {
if (!_error.isEmpty()) {
_error = QString();
update();

View File

@ -14,8 +14,6 @@ class RoundButton;
} // namespace Ui
class PasscodeWidget : public TWidget {
Q_OBJECT
public:
PasscodeWidget(QWidget *parent);
@ -27,13 +25,11 @@ protected:
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
public slots:
void onError();
void onChanged();
void onSubmit();
private:
void animationCallback();
void changed();
void submit();
void error();
void showAll();
void hideAll();

View File

@ -208,7 +208,7 @@ void CountrySelectBox::prepare() {
_select->resizeToWidth(st::boxWidth);
_select->setQueryChangedCallback([this](const QString &query) { onFilterUpdate(query); });
_select->setSubmittedCallback([this](bool) { onSubmit(); });
_select->setSubmittedCallback([this](Qt::KeyboardModifiers) { onSubmit(); });
_inner = setInnerWidget(object_ptr<Inner>(this), st::countriesScroll, _select->height());

View File

@ -1010,7 +1010,7 @@ void FlatInput::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Escape) {
emit cancelled();
} else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
emit submitted(ctrl && shift);
emit submitted(e->modifiers());
#ifdef Q_OS_MAC
} else if (e->key() == Qt::Key_E && e->modifiers().testFlag(Qt::ControlModifier)) {
auto selected = selectedText();
@ -2249,7 +2249,7 @@ void InputField::keyPressEventInner(QKeyEvent *e) {
&& revertFormatReplace()) {
e->accept();
} else if (enter && enterSubmit) {
emit submitted(ctrl && shift);
emit submitted(e->modifiers());
} else if (e->key() == Qt::Key_Escape) {
e->ignore();
emit cancelled();
@ -3505,7 +3505,7 @@ void MaskedInputField::keyPressEvent(QKeyEvent *e) {
e->ignore();
emit cancelled();
} else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
emit submitted(ctrl && shift);
emit submitted(e->modifiers());
#ifdef Q_OS_MAC
} else if (e->key() == Qt::Key_E && e->modifiers().testFlag(Qt::ControlModifier)) {
auto selected = selectedText();

View File

@ -67,7 +67,7 @@ public slots:
signals:
void changed();
void cancelled();
void submitted(bool ctrlShiftEnter);
void submitted(Qt::KeyboardModifiers);
void focused();
void blurred();
@ -298,7 +298,7 @@ private slots:
signals:
void changed();
void submitted(bool ctrlShiftEnter);
void submitted(Qt::KeyboardModifiers);
void cancelled();
void tabbed();
void focused();
@ -518,7 +518,7 @@ public slots:
signals:
void changed();
void cancelled();
void submitted(bool ctrlShiftEnter);
void submitted(Qt::KeyboardModifiers);
void focused();
void blurred();

View File

@ -289,7 +289,7 @@ void MultiSelect::setQueryChangedCallback(base::lambda<void(const QString &query
_queryChangedCallback = std::move(callback);
}
void MultiSelect::setSubmittedCallback(base::lambda<void(bool ctrlShiftEnter)> callback) {
void MultiSelect::setSubmittedCallback(base::lambda<void(Qt::KeyboardModifiers)> callback) {
_inner->setSubmittedCallback(std::move(callback));
}
@ -359,17 +359,17 @@ MultiSelect::Inner::Inner(QWidget *parent, const style::MultiSelect &st, base::l
, _field(this, _st.field, std::move(placeholder))
, _cancel(this, _st.fieldCancel) {
_field->customUpDown(true);
connect(_field, SIGNAL(focused()), this, SLOT(onFieldFocused()));
connect(_field, SIGNAL(changed()), this, SLOT(onQueryChanged()));
connect(_field, SIGNAL(submitted(bool)), this, SLOT(onSubmitted(bool)));
_cancel->setClickedCallback([this] {
connect(_field, &Ui::InputField::focused, [=] { fieldFocused(); });
connect(_field, &Ui::InputField::changed, [=] { queryChanged(); });
connect(_field, &Ui::InputField::submitted, this, &Inner::submitted);
_cancel->setClickedCallback([=] {
clearQuery();
_field->setFocus();
});
setMouseTracking(true);
}
void MultiSelect::Inner::onQueryChanged() {
void MultiSelect::Inner::queryChanged() {
auto query = getQuery();
_cancel->toggle(!query.isEmpty(), anim::type::normal);
updateFieldGeometry();
@ -400,7 +400,8 @@ void MultiSelect::Inner::setQueryChangedCallback(base::lambda<void(const QString
_queryChangedCallback = std::move(callback);
}
void MultiSelect::Inner::setSubmittedCallback(base::lambda<void(bool ctrlShiftEnter)> callback) {
void MultiSelect::Inner::setSubmittedCallback(
base::lambda<void(Qt::KeyboardModifiers)> callback) {
_submittedCallback = std::move(callback);
}
@ -563,7 +564,13 @@ void MultiSelect::Inner::keyPressEvent(QKeyEvent *e) {
}
}
void MultiSelect::Inner::onFieldFocused() {
void MultiSelect::Inner::submitted(Qt::KeyboardModifiers modifiers) {
if (_submittedCallback) {
_submittedCallback(modifiers);
}
}
void MultiSelect::Inner::fieldFocused() {
setActiveItem(-1, ChangeActiveWay::SkipSetFocus);
}

View File

@ -25,7 +25,7 @@ public:
void clearQuery();
void setQueryChangedCallback(base::lambda<void(const QString &query)> callback);
void setSubmittedCallback(base::lambda<void(bool ctrlShiftEnter)> callback);
void setSubmittedCallback(base::lambda<void(Qt::KeyboardModifiers)> callback);
void setResizedCallback(base::lambda<void()> callback);
enum class AddItemWay {
@ -79,7 +79,7 @@ public:
void clearQuery();
void setQueryChangedCallback(base::lambda<void(const QString &query)> callback);
void setSubmittedCallback(base::lambda<void(bool ctrlShiftEnter)> callback);
void setSubmittedCallback(base::lambda<void(Qt::KeyboardModifiers)> callback);
void addItemInBunch(std::unique_ptr<Item> item);
void finishItemsBunch(AddItemWay way);
@ -105,16 +105,10 @@ protected:
void mousePressEvent(QMouseEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
private slots:
void onQueryChanged();
void onSubmitted(bool ctrlShiftEnter) {
if (_submittedCallback) {
_submittedCallback(ctrlShiftEnter);
}
}
void onFieldFocused();
private:
void submitted(Qt::KeyboardModifiers modifiers);
void queryChanged();
void fieldFocused();
void computeItemsGeometry(int newWidth);
void updateItemsGeometry();
void updateFieldGeometry();
@ -159,7 +153,7 @@ private:
Animation _height;
base::lambda<void(const QString &query)> _queryChangedCallback;
base::lambda<void(bool ctrlShiftEnter)> _submittedCallback;
base::lambda<void(Qt::KeyboardModifiers)> _submittedCallback;
base::lambda<void(uint64 itemId)> _itemRemovedCallback;
base::lambda<void(int heightDelta)> _resizedCallback;

View File

@ -495,7 +495,7 @@ Notification::Notification(Manager *manager, History *history, PeerData *peer, P
updateNotifyDisplay();
_hideTimer.setSingleShot(true);
connect(&_hideTimer, SIGNAL(timeout()), this, SLOT(onHideByTimer()));
connect(&_hideTimer, &QTimer::timeout, [=] { startHiding(); });
_close->setClickedCallback([this] {
unlinkHistoryInManager();
@ -576,15 +576,11 @@ bool Notification::checkLastInput(bool hasReplyingNotifications) {
return false;
}
void Notification::onReplyResize() {
void Notification::replyResized() {
changeHeight(st::notifyMinHeight + _replyArea->height() + st::notifyBorderWidth);
}
void Notification::onReplySubmit(bool ctrlShiftEnter) {
sendReply();
}
void Notification::onReplyCancel() {
void Notification::replyCancel() {
unlinkHistoryInManager();
}
@ -777,9 +773,9 @@ void Notification::showReplyField() {
// Catch mouse press event to activate the window.
QCoreApplication::instance()->installEventFilter(this);
connect(_replyArea, SIGNAL(resized()), this, SLOT(onReplyResize()));
connect(_replyArea, SIGNAL(submitted(bool)), this, SLOT(onReplySubmit(bool)));
connect(_replyArea, SIGNAL(cancelled()), this, SLOT(onReplyCancel()));
connect(_replyArea, &Ui::InputField::resized, [=] { replyResized(); });
connect(_replyArea, &Ui::InputField::submitted, [=] { sendReply(); });
connect(_replyArea, &Ui::InputField::cancelled, [=] { replyCancel(); });
_replySend.create(this, st::notifySendReply);
_replySend->moveToRight(st::notifyBorderWidth, st::notifyMinHeight);
@ -788,7 +784,7 @@ void Notification::showReplyField() {
toggleActionButtons(false);
onReplyResize();
replyResized();
update();
}
@ -868,10 +864,6 @@ void Notification::stopHiding() {
Widget::hideStop();
}
void Notification::onHideByTimer() {
startHiding();
}
HideAllButton::HideAllButton(Manager *manager, QPoint startPosition, int shift, Direction shiftDirection) : Widget(manager, startPosition, shift, shiftDirection) {
setCursor(style::cur_pointer);

View File

@ -164,8 +164,6 @@ protected:
};
class Notification : public Widget {
Q_OBJECT
public:
Notification(Manager *manager, History *history, PeerData *peer, PeerData *author, HistoryItem *item, int forwardedCount, QPoint startPosition, int shift, Direction shiftDirection);
@ -194,16 +192,12 @@ protected:
void mousePressEvent(QMouseEvent *e) override;
bool eventFilter(QObject *o, QEvent *e) override;
private slots:
void onHideByTimer();
void onReplyResize();
void onReplySubmit(bool ctrlShiftEnter);
void onReplyCancel();
private:
void refreshLang();
void updateReplyGeometry();
bool canReply() const;
void replyResized();
void replyCancel();
void unlinkHistoryInManager();
void toggleActionButtons(bool visible);

View File

@ -720,7 +720,7 @@ Editor::Editor(QWidget*, const QString &path)
_select->resizeToWidth(st::windowMinWidth);
_select->setQueryChangedCallback([this](const QString &query) { _inner->filterRows(query); _scroll->scrollToY(0); });
_select->setSubmittedCallback([this](bool) { _inner->chooseRow(); });
_select->setSubmittedCallback([this](Qt::KeyboardModifiers) { _inner->chooseRow(); });
_inner->prepare();
resizeToWidth(st::windowMinWidth);